Skip to content

Commit 292e8a2

Browse files
Support OBJECT types
1 parent d0694d5 commit 292e8a2

9 files changed

+875
-122
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package oracle.r2dbc;
2+
3+
public interface OracleR2dbcObject extends io.r2dbc.spi.Readable {
4+
5+
OracleR2dbcObjectMetadata getMetadata();
6+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package oracle.r2dbc;
2+
3+
import io.r2dbc.spi.ReadableMetadata;
4+
5+
import java.util.List;
6+
import java.util.NoSuchElementException;
7+
8+
public interface OracleR2dbcObjectMetadata {
9+
10+
/**
11+
* Returns the {@link ReadableMetadata} for one attribute.
12+
*
13+
* @param index the attribute index starting at 0
14+
* @return the {@link ReadableMetadata} for one attribute. Not null.
15+
* @throws IndexOutOfBoundsException if {@code index} is out of range
16+
* (negative or equals/exceeds {@code getParameterMetadatas().size()})
17+
*/
18+
ReadableMetadata getAttributeMetadata(int index);
19+
20+
/**
21+
* Returns the {@link ReadableMetadata} for one attribute.
22+
*
23+
* @param name the name of the attribute. Not null. Parameter names are
24+
* case-insensitive.
25+
* @return the {@link ReadableMetadata} for one attribute. Not null.
26+
* @throws IllegalArgumentException if {@code name} is {@code null}
27+
* @throws NoSuchElementException if there is no attribute with the
28+
* {@code name}
29+
*/
30+
ReadableMetadata getAttributeMetadata(String name);
31+
32+
/**
33+
* Returns the {@link ReadableMetadata} for all attributes.
34+
*
35+
* @return the {@link ReadableMetadata} for all attributes. Not null.
36+
*/
37+
List<? extends ReadableMetadata> getAttributeMetadatas();
38+
}

src/main/java/oracle/r2dbc/OracleR2dbcTypes.java

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,12 @@ private OracleR2dbcTypes() {}
103103
public static final Type REF_CURSOR =
104104
new TypeImpl(Result.class, "SYS_REFCURSOR");
105105

106+
/**
107+
* A user defined OBJECT type.
108+
*/
109+
public static final Type OBJECT =
110+
new TypeImpl(OracleR2dbcObject.class, "OBJECT");
111+
106112
/**
107113
* <p>
108114
* Creates an {@link ArrayType} representing a user defined {@code ARRAY}
@@ -137,6 +143,10 @@ public static ArrayType arrayType(String name) {
137143
return new ArrayTypeImpl(Objects.requireNonNull(name, "name is null"));
138144
}
139145

146+
public static ObjectType objectType(String name) {
147+
return new ObjectTypeImpl(Objects.requireNonNull(name, "name is null"));
148+
}
149+
140150
/**
141151
* Extension of the standard {@link Type} interface used to represent user
142152
* defined ARRAY types. An instance of {@code ArrayType} must be used when
@@ -179,6 +189,31 @@ public interface ArrayType extends Type {
179189
String getName();
180190
}
181191

192+
public interface ObjectType extends Type {
193+
194+
/**
195+
* {@inheritDoc}
196+
* Returns {@code Object[].class}, which is the standard mapping for
197+
* {@link R2dbcType#COLLECTION}. The true default type mapping is the array
198+
* variant of the default mapping for the element type of the {@code ARRAY}.
199+
* For instance, an {@code ARRAY} of {@code VARCHAR} maps to a
200+
* {@code String[]} by default.
201+
*/
202+
@Override
203+
Class<?> getJavaType();
204+
205+
/**
206+
* {@inheritDoc}
207+
* Returns the name of this user defined {@code ARRAY} type. For instance,
208+
* this method returns "MY_ARRAY" if the type is declared as:
209+
* <pre>{@code
210+
* CREATE TYPE MY_ARRAY AS ARRAY(8) OF NUMBER
211+
* }</pre>
212+
*/
213+
@Override
214+
String getName();
215+
}
216+
182217
/** Concrete implementation of the {@code ArrayType} interface */
183218
private static final class ArrayTypeImpl
184219
extends TypeImpl implements ArrayType {
@@ -195,6 +230,23 @@ private static final class ArrayTypeImpl
195230
}
196231
}
197232

233+
/** Concrete implementation of the {@code ObjectType} interface */
234+
private static final class ObjectTypeImpl
235+
extends TypeImpl implements ObjectType {
236+
237+
/**
238+
* Constructs an ARRAY type with the given {@code name}. The constructed
239+
* {@code ObjectType} as a default Java type mapping of
240+
* {@code Object[].class}. This is consistent with the standard
241+
* {@link R2dbcType#COLLECTION} type.
242+
* @param name User defined name of the type. Not null.
243+
*/
244+
ObjectTypeImpl(String name) {
245+
// TODO: Consider defining Readable.class as the default type mapping.
246+
super(Object.class, name);
247+
}
248+
}
249+
198250
/**
199251
* Implementation of the {@link Type} SPI.
200252
*/

0 commit comments

Comments
 (0)