Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Oracle Collections implementation #1425

Draft
wants to merge 2 commits into
base: 4.x
Choose a base branch
from

Conversation

blafond
Copy link

@blafond blafond commented Mar 8, 2024

Motivation:

Potential fix and test for #1392 : Support for Oracle Collections

ORM's recent support for Oracle arrays has added a custom array method to wrap an OracleConnection.

Hibernate Reactive uses vertx-sql-client to execute queries and does not use actual db client connections. This PR proposes a change in the vertx-sql-client to add a similar change to your OracleConnection interface and implementation to provide Hibernate Reactive access to the correct oracle array info/structure.

Commits include the proposed changes to the Oracle sql client and a test that currently fails

Caused by: java.sql.SQLException: ORA-17074: Invalid name pattern: StringArrayType
https://docs.oracle.com/error-help/db/ora-17074/
	at oracle.jdbc.oracore.OracleTypeADT.initMetadata12(OracleTypeADT.java:636)
	at oracle.jdbc.oracore.OracleTypeADT.initMetadata(OracleTypeADT.java:571)
	at oracle.jdbc.oracore.OracleTypeADT.init(OracleTypeADT.java:500)
	at oracle.sql.ArrayDescriptor.initPickler(ArrayDescriptor.java:1722)
	at oracle.sql.ArrayDescriptor.<init>(ArrayDescriptor.java:381)
	at oracle.sql.ArrayDescriptor.<init>(ArrayDescriptor.java:357)
	at oracle.sql.ArrayDescriptor.createDescriptor(ArrayDescriptor.java:217)
	at oracle.sql.ArrayDescriptor.createDescriptor(ArrayDescriptor.java:102)
	at oracle.jdbc.driver.PhysicalConnection.createARRAY(PhysicalConnection.java:7755)
	at io.vertx.oracleclient.impl.OracleJdbcConnection.createArray(OracleJdbcConnection.java:62)
	... 30 more

@blafond blafond marked this pull request as draft March 8, 2024 15:15
@vietj vietj added this to the 4.5.5 milestone Mar 9, 2024
@tsegismont
Copy link
Contributor

Thank you @blafond , I'll come back to you asap

@tsegismont
Copy link
Contributor

@blafond the test passes with a couple of changes:

Index: vertx-oracle-client/src/test/java/io/vertx/oracleclient/test/OracleArrayTest.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/vertx-oracle-client/src/test/java/io/vertx/oracleclient/test/OracleArrayTest.java b/vertx-oracle-client/src/test/java/io/vertx/oracleclient/test/OracleArrayTest.java
--- a/vertx-oracle-client/src/test/java/io/vertx/oracleclient/test/OracleArrayTest.java	(revision 50ccabcc771b6c68ba27cda9d3d746efca1ecd42)
+++ b/vertx-oracle-client/src/test/java/io/vertx/oracleclient/test/OracleArrayTest.java	(date 1710258134775)
@@ -37,8 +37,8 @@
   public void testStringArray(TestContext ctx) {
     String[] elements = {"str1", "str2", "str3"};
     pool.withConnection(conn -> {
-      Object stringsArray = ((OracleConnection)conn).createArray( "StringArrayType", elements );
-      String insertSql = "INSERT INTO StringsArrayTable( id, stringsArray) VALUES (?, ?)";
+      Object stringsArray = ((OracleConnection)conn).createArray( "STRINGARRAYTYPE", elements );
+      String insertSql = "INSERT INTO StringsArrayTable( id, stringarrayelement) VALUES (?, ?)";
       return conn.preparedQuery( insertSql ).execute( Tuple.of(1, stringsArray) );
     }).onComplete( ctx.asyncAssertSuccess() );
   }
  1. The array type name must be uppercase
  2. The column name is stringarrayelement

Copy link
Contributor

@tsegismont tsegismont left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @blafond , this goes in a good direction

I've commented in the PR about how to fix the test. I assume you are going to expand the test class?

In addition to the Javadoc, can you please also update the module doc vertx-oracle-client/src/main/asciidoc/index.adoc ?

@@ -64,6 +64,8 @@ static Future<OracleConnection> connect(Vertx vertx, String connectionUri) {
return connect(vertx, fromUri(connectionUri));
}

Object createArray(String typeName, Object elements);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please add some Javadoc to this method?

@tsegismont tsegismont changed the title 4.x oracle array test Oracle Collections implementation Mar 12, 2024
@blafond
Copy link
Author

blafond commented Mar 13, 2024

@tsegismont I tried your changes above and it just changed the case of the error:

+      Object stringsArray = ((OracleConnection)conn).createArray( "STRINGARRAYTYPE", elements );
+      String insertSql = "INSERT INTO StringsArrayTable( id, stringarrayelement) VALUES (?, ?)";
java.lang.RuntimeException: java.sql.SQLException: ORA-17074: Invalid name pattern: STRINGARRAYTYPE
https://docs.oracle.com/error-help/db/ora-17074/

Did the test work for you?

@tsegismont
Copy link
Contributor

Did the test work for you?

Yes it did

@tsegismont
Copy link
Contributor

@blafond I could reproduce your problem but still not able to fix it. I'll keep you informed

@tsegismont
Copy link
Contributor

So it doesn't work when the collection and dependent table are created in the init sql file. It does work if both are created with the Oracle client...

I failed to understand to why so I reported my problem.

I'll keep you informed

@DavideD
Copy link
Contributor

DavideD commented Apr 11, 2024

Interesting, but I don't think in Hibernate Reactive we are creating then entries using the init sql.

@blafond switched to a new role, I'm going to have another look at this as soon as I have some time.

@tsegismont
Copy link
Contributor

For the tests, in this PR, we do create the collection type and dependent table in the init sql file

@DavideD
Copy link
Contributor

DavideD commented Apr 12, 2024

For the tests, in this PR, we do create the collection type and dependent table in the init sql file

Yes, but it means that it should work in HR. I need to retest it there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants