Skip to content

Commit 7b4ba85

Browse files
Merge branch 'main' of github.com:oracle/oracle-r2dbc into json-duality-test
2 parents 1dbbb35 + ea73e9f commit 7b4ba85

File tree

1 file changed

+111
-0
lines changed

1 file changed

+111
-0
lines changed

src/test/java/oracle/r2dbc/impl/OracleStatementImplTest.java

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
import io.r2dbc.spi.Connection;
2525
import io.r2dbc.spi.ConnectionFactories;
26+
import io.r2dbc.spi.OutParameters;
2627
import io.r2dbc.spi.Parameters;
2728
import io.r2dbc.spi.R2dbcException;
2829
import io.r2dbc.spi.R2dbcNonTransientException;
@@ -2982,6 +2983,116 @@ public void testInOutObjectCall() {
29822983
}
29832984
}
29842985

2986+
/**
2987+
* Verifies OUT parameter binds in a RETURNING INTO clause.
2988+
*/
2989+
@Test
2990+
public void testReturnParameter() {
2991+
Connection connection = awaitOne(sharedConnection());
2992+
try {
2993+
awaitExecution(connection.createStatement(
2994+
"CREATE TABLE testReturnParameter(id NUMBER, value VARCHAR(100))"));
2995+
2996+
TestRow insertRow = new TestRow(1, "a");
2997+
Statement returnStatement = connection.createStatement(
2998+
"BEGIN" +
2999+
" INSERT INTO testReturnParameter" +
3000+
" VALUES (?, ?)" +
3001+
" RETURNING id, value" +
3002+
" INTO ?, ?;" +
3003+
" END;");
3004+
returnStatement.bind(0, insertRow.id);
3005+
returnStatement.bind(1, insertRow.value);
3006+
returnStatement.bind(2, Parameters.out(R2dbcType.NUMERIC));
3007+
returnStatement.bind(3, Parameters.out(R2dbcType.VARCHAR));
3008+
3009+
Result returnResult = awaitOne(returnStatement.execute());
3010+
TestRow returnRow = awaitOne(returnResult.map(outParameters ->
3011+
new TestRow(
3012+
outParameters.get(0, Integer.class),
3013+
outParameters.get(1, String.class))));
3014+
assertEquals(insertRow, returnRow);
3015+
}
3016+
finally {
3017+
tryAwaitExecution(connection.createStatement(
3018+
"DROP TABLE testReturnParameter"));
3019+
tryAwaitNone(connection.close());
3020+
}
3021+
}
3022+
3023+
/**
3024+
* Verifies OUT parameter binds in a RETURNING INTO clause with a JSON
3025+
* Duality View.
3026+
*/
3027+
@Test
3028+
public void testReturnParameterJsonDualityView() {
3029+
// JSON Duality Views were introduced in Oracle Database version 23c, so
3030+
// this test is skipped if the version is older than 23c.
3031+
assumeTrue(databaseVersion() >= 23,
3032+
"JSON Duality Views are not supported by database versions older than" +
3033+
" 23");
3034+
3035+
Connection connection = awaitOne(sharedConnection());
3036+
try {
3037+
awaitExecution(connection.createStatement(
3038+
"CREATE TABLE testReturnParameterJsonDualityViewTable(" +
3039+
"id NUMBER PRIMARY KEY, value VARCHAR(100))"));
3040+
awaitExecution(connection.createStatement(
3041+
"CREATE JSON DUALITY VIEW testReturnParameterJsonDualityView AS" +
3042+
" SELECT JSON {'id' : t.id, 'value' : t.value}" +
3043+
" FROM testReturnParameterJsonDualityViewTable t" +
3044+
" WITH INSERT UPDATE DELETE"));
3045+
3046+
// Verify returning the "data" column
3047+
OracleJsonObject insertObject = new OracleJsonFactory().createObject();
3048+
insertObject.put("id", 1);
3049+
insertObject.put("value", "a");
3050+
Statement returnStatement = connection.createStatement(
3051+
"BEGIN" +
3052+
" INSERT INTO testReturnParameterJsonDualityView" +
3053+
" VALUES (?)" +
3054+
" RETURNING data" +
3055+
" INTO ?;" +
3056+
" END;");
3057+
returnStatement.bind(0, insertObject);
3058+
returnStatement.bind(1, Parameters.out(OracleR2dbcTypes.JSON));
3059+
3060+
Result returnResult = awaitOne(returnStatement.execute());
3061+
OracleJsonObject returnObject =
3062+
awaitOne(returnResult.map(outParameters ->
3063+
outParameters.get(0, OracleJsonObject.class)));
3064+
insertObject.put("_metadata", returnObject.get("_metadata"));
3065+
assertEquals(insertObject, returnObject);
3066+
3067+
// Verify returning a JSON_VALUE expression
3068+
OracleJsonObject insertObjectB = new OracleJsonFactory().createObject();
3069+
insertObjectB.put("id", 2);
3070+
insertObjectB.put("value", "b");
3071+
Statement returnStatementB = connection.createStatement(
3072+
"BEGIN" +
3073+
" INSERT INTO testReturnParameterJsonDualityView" +
3074+
" VALUES (?)" +
3075+
" RETURNING JSON_VALUE(DATA, '$.id')" +
3076+
" INTO ?;" +
3077+
" END;");
3078+
returnStatementB.bind(0, insertObjectB);
3079+
returnStatementB.bind(1, Parameters.out(R2dbcType.NUMERIC));
3080+
3081+
Result returnResultB = awaitOne(returnStatementB.execute());
3082+
int returnId =
3083+
awaitOne(returnResultB.map(outParameters ->
3084+
outParameters.get(0, Integer.class)));
3085+
assertEquals(insertObjectB.getInt("id"), returnId);
3086+
}
3087+
finally {
3088+
tryAwaitExecution(connection.createStatement(
3089+
"DROP TABLE testReturnParameterJsonDualityViewTable"));
3090+
tryAwaitExecution(connection.createStatement(
3091+
"DROP VIEW testReturnParameterJsonDualityView"));
3092+
tryAwaitNone(connection.close());
3093+
}
3094+
}
3095+
29853096
/**
29863097
* Verifies inserts and queries with a JSON Duality View.
29873098
*/

0 commit comments

Comments
 (0)