postgresql-jdbc.git / summary / log / commit / refs
commit 4ad2df328d1202cb9516b8a8e382e4fef4db6441
Author: Mathias Fußenegger <mfussenegger@users.noreply.github.com>
Commit: Vladimir Sitnikov <sitnikov.vladimir@gmail.com>
Date: Tue Jul 26 15:13:55 2016 +0000
perf: add json type info to Client (#610)
This is a very minor performance improvement. It adds `json` type info
to the client in order to avoid the execution of a query to retrieve the
oid of the `json` type.
pgjdbc/src/main/java/org/postgresql/core/Oid.java | 2 ++
.../java/org/postgresql/jdbc/TypeInfoCache.java | 1 +
.../java/org/postgresql/test/jdbc4/ArrayTest.java | 24 ++++++++++++++++++++++
3 files changed, 27 insertions(+)
diff --git a/pgjdbc/src/main/java/org/postgresql/core/Oid.java b/pgjdbc/src/main/java/org/postgresql/core/Oid.java
index 6ee71ff7..a75644c5 100644
--- a/pgjdbc/src/main/java/org/postgresql/core/Oid.java
+++ b/pgjdbc/src/main/java/org/postgresql/core/Oid.java
@@ -73,6 +73,8 @@ public class Oid {
public static final int POINT = 600;
public static final int BOX = 603;
public static final int JSONB_ARRAY = 3807;
+ public static final int JSON = 114;
+ public static final int JSON_ARRAY = 199;
/**
* Returns the name of the oid as string.
diff --git a/pgjdbc/src/main/java/org/postgresql/jdbc/TypeInfoCache.java b/pgjdbc/src/main/java/org/postgresql/jdbc/TypeInfoCache.java
index d80a58cf..73ffad81 100644
--- a/pgjdbc/src/main/java/org/postgresql/jdbc/TypeInfoCache.java
+++ b/pgjdbc/src/main/java/org/postgresql/jdbc/TypeInfoCache.java
@@ -92,6 +92,7 @@ public class TypeInfoCache implements TypeInfo {
{"timestamp", Oid.TIMESTAMP, Types.TIMESTAMP, "java.sql.Timestamp", Oid.TIMESTAMP_ARRAY},
{"timestamptz", Oid.TIMESTAMPTZ, Types.TIMESTAMP, "java.sql.Timestamp",
Oid.TIMESTAMPTZ_ARRAY},
+ {"json", Oid.JSON, Types.VARCHAR, "java.lang.String", Oid.JSON_ARRAY}
};
/**
diff --git a/pgjdbc/src/test/java/org/postgresql/test/jdbc4/ArrayTest.java b/pgjdbc/src/test/java/org/postgresql/test/jdbc4/ArrayTest.java
index 5bc63142..42ac7930 100644
--- a/pgjdbc/src/test/java/org/postgresql/test/jdbc4/ArrayTest.java
+++ b/pgjdbc/src/test/java/org/postgresql/test/jdbc4/ArrayTest.java
@@ -113,6 +113,30 @@ public class ArrayTest extends BaseTest4 {
Assert.assertEquals("\"\\'z", out[1][1]);
}
+ @Test
+ public void testCreateArrayOfMultiJson() throws SQLException {
+ PreparedStatement pstmt = _conn.prepareStatement("SELECT ?::json[]");
+ PGobject p1 = new PGobject();
+ p1.setType("json");
+ p1.setValue("{\"x\": 10}");
+
+ PGobject p2 = new PGobject();
+ p2.setType("json");
+ p2.setValue("{\"x\": 20}");
+ PGobject in[] = new PGobject[] { p1, p2 };
+ pstmt.setArray(1, _conn.createArrayOf("json", in));
+
+ ResultSet rs = pstmt.executeQuery();
+ Assert.assertTrue(rs.next());
+ Array arr = rs.getArray(1);
+ ResultSet arrRs = arr.getResultSet();
+ Assert.assertTrue(arrRs.next());
+ Assert.assertEquals(in[0].getValue(), arrRs.getObject(2));
+
+ Assert.assertTrue(arrRs.next());
+ Assert.assertEquals(in[1].getValue(), arrRs.getObject(2));
+ }
+
@Test
public void testCreateArrayWithNonStandardDelimiter() throws SQLException {
PGbox in[] = new PGbox[2];
[parent: c09be96c9455]