@@ -222,9 +222,9 @@ Java::
222
222
223
223
public TestItemStoredProcedure(DataSource dataSource) {
224
224
// ...
225
- declareParameter(new SqlOutParameter("item", OracleTypes .STRUCT, "ITEM_TYPE",
225
+ declareParameter(new SqlOutParameter("item", Types .STRUCT, "ITEM_TYPE",
226
226
(CallableStatement cs, int colIndx, int sqlType, String typeName) -> {
227
- STRUCT struct = (STRUCT ) cs.getObject(colIndx);
227
+ Struct struct = (Struct ) cs.getObject(colIndx);
228
228
Object[] attr = struct.getAttributes();
229
229
TestItem item = new TestItem();
230
230
item.setId(((Number) attr[0]).longValue());
@@ -258,8 +258,8 @@ Kotlin::
258
258
You can use `SqlTypeValue` to pass the value of a Java object (such as `TestItem`) to a
259
259
stored procedure. The `SqlTypeValue` interface has a single method (named
260
260
`createTypeValue`) that you must implement. The active connection is passed in, and you
261
- can use it to create database-specific objects, such as `StructDescriptor ` instances
262
- or `ArrayDescriptor ` instances. The following example creates a `StructDescriptor ` instance:
261
+ can use it to create database-specific objects, such as `java.sql.Struct ` instances
262
+ or `java.sql.Array ` instances. The following example creates a `java.sql.Struct ` instance:
263
263
264
264
[tabs]
265
265
======
@@ -272,14 +272,12 @@ Java::
272
272
273
273
SqlTypeValue value = new AbstractSqlTypeValue() {
274
274
protected Object createTypeValue(Connection conn, int sqlType, String typeName) throws SQLException {
275
- StructDescriptor itemDescriptor = new StructDescriptor(typeName, conn);
276
- Struct item = new STRUCT(itemDescriptor, conn,
277
- new Object[] {
275
+ var item = new Object[] {
278
276
testItem.getId(),
279
277
testItem.getDescription(),
280
278
new java.sql.Date(testItem.getExpirationDate().getTime())
281
- }) ;
282
- return item;
279
+ };
280
+ return connection.createStruct(typeName, item) ;
283
281
}
284
282
};
285
283
----
@@ -307,7 +305,7 @@ You can now add this `SqlTypeValue` to the `Map` that contains the input paramet
307
305
Another use for the `SqlTypeValue` is passing in an array of values to an Oracle stored
308
306
procedure. Oracle has its own internal `ARRAY` class that must be used in this case, and
309
307
you can use the `SqlTypeValue` to create an instance of the Oracle `ARRAY` and populate
310
- it with values from the Java `ARRAY `, as the following example shows:
308
+ it with values from the Java `java.sql.Array `, as the following example shows:
311
309
312
310
[tabs]
313
311
======
@@ -319,9 +317,7 @@ Java::
319
317
320
318
SqlTypeValue value = new AbstractSqlTypeValue() {
321
319
protected Object createTypeValue(Connection conn, int sqlType, String typeName) throws SQLException {
322
- ArrayDescriptor arrayDescriptor = new ArrayDescriptor(typeName, conn);
323
- ARRAY idArray = new ARRAY(arrayDescriptor, conn, ids);
324
- return idArray;
320
+ return conn.unwrap(OracleConnection.class).createOracleArray(typeName, ids);
325
321
}
326
322
};
327
323
----
@@ -345,5 +341,8 @@ Kotlin::
345
341
----
346
342
======
347
343
348
-
344
+ [NOTE]
345
+ ====
346
+ Use `unwrap(OracleConnection.class)` method if connection is not an OracleConnection's instance
347
+ ====
349
348
0 commit comments