-
Notifications
You must be signed in to change notification settings - Fork 819
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Define binary transfer for custom types dynamically/automatical…
…ly (Issue #2554) (#2556) The driver would automatically register types for binary transfer when calling con.unwrap(PGConnection.class).addDataType(String, Class) Fixes #2554
- Loading branch information
1 parent
f51c68e
commit cb78d0e
Showing
7 changed files
with
504 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
pgjdbc/src/test/java/org/postgresql/test/core/QueryExecutorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* | ||
* Copyright (c) 2023, PostgreSQL Global Development Group | ||
* See the LICENSE file in the project root for more information. | ||
*/ | ||
|
||
package org.postgresql.test.core; | ||
|
||
import org.postgresql.core.BaseConnection; | ||
import org.postgresql.core.QueryExecutor; | ||
import org.postgresql.test.jdbc2.BaseTest4; | ||
|
||
import org.junit.Test; | ||
|
||
import java.sql.SQLException; | ||
import java.util.Set; | ||
|
||
/** | ||
* TestCase to test handling of binary types. | ||
*/ | ||
public class QueryExecutorTest extends BaseTest4 { | ||
/** | ||
* Make sure the functions for adding binary transfer OIDs for custom types are correct. | ||
* | ||
* @throws SQLException if a database error occurs | ||
*/ | ||
@Test | ||
public void testBinaryTransferOids() throws SQLException { | ||
QueryExecutor queryExecutor = con.unwrap(BaseConnection.class).getQueryExecutor(); | ||
// get current OIDs (make a copy of them) | ||
@SuppressWarnings("deprecation") | ||
Set<? extends Integer> oidsReceive = queryExecutor.getBinaryReceiveOids(); | ||
@SuppressWarnings("deprecation") | ||
Set<? extends Integer> oidsSend = queryExecutor.getBinarySendOids(); | ||
// add a new OID to be transferred as binary data | ||
int customTypeOid = 91716; | ||
assertBinaryForReceive(customTypeOid, false, | ||
() -> "Custom type OID should not be binary for receive by default"); | ||
// first for receiving | ||
queryExecutor.addBinaryReceiveOid(customTypeOid); | ||
// Verify | ||
assertBinaryForReceive(customTypeOid, true, | ||
() -> "Just added oid via addBinaryReceiveOid"); | ||
assertBinaryForSend(customTypeOid, false, | ||
() -> "Just added oid via addBinaryReceiveOid"); | ||
for (int oid : oidsReceive) { | ||
assertBinaryForReceive(oid, true, | ||
() -> "Previously registered BinaryReceiveOids should be intact after " | ||
+ "addBinaryReceiveOid(" + customTypeOid + ")"); | ||
} | ||
for (int oid : oidsSend) { | ||
assertBinaryForSend(oid, true, | ||
() -> "Previously registered BinarySendOids should be intact after " | ||
+ "addBinaryReceiveOid(" + customTypeOid + ")"); | ||
} | ||
// then for sending | ||
queryExecutor.addBinarySendOid(customTypeOid); | ||
// check new OID | ||
assertBinaryForReceive(customTypeOid, true, () -> "added oid via addBinaryReceiveOid and " | ||
+ "addBinarySendOid"); | ||
assertBinaryForSend(customTypeOid, true, () -> "added oid via addBinaryReceiveOid and " | ||
+ "addBinarySendOid"); | ||
for (int oid : oidsReceive) { | ||
assertBinaryForReceive(oid, true, () -> "Previously registered BinaryReceiveOids should be " | ||
+ "intact after addBinaryReceiveOid(" + customTypeOid + ") and addBinarySendOid(" + customTypeOid + ")"); | ||
} | ||
for (int oid : oidsSend) { | ||
assertBinaryForSend(oid, true, () -> "Previously registered BinarySendOids should be intact" | ||
+ " after addBinaryReceiveOid(" + customTypeOid + ")"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
This will cause a query roundtrip to the database for each new connection that is created to check whether the type
box
exists. The reason for this is that:box
is aPGBinaryObject
.box
is added to the set of object types here:pgjdbc/pgjdbc/src/main/java/org/postgresql/jdbc/PgConnection.java
Line 772 in cb78d0e
box
is not part of the standard type cache here:pgjdbc/pgjdbc/src/main/java/org/postgresql/jdbc/TypeInfoCache.java
Line 109 in 2956b74
Is that intentional / WAI?
The query that is executed for each connection is