Skip to content
Permalink
Browse files

Add core type delimiters into cache for array type OIDs. (#1416)

* Add core type delimiters into cache for array type OIDs.

In addition to caching the underlying core type mapped to a comma,
cache their array equivalent types to avoid querying from the server.

Fixes #1415.

* Initialize TypeInfoCache maps by anticipated size.
  • Loading branch information...
doxavore authored and davecramer committed Feb 22, 2019
1 parent ddb38e5 commit 6a0960a66981a03577221e2d742865526cb2325d
Showing with 8 additions and 7 deletions.
  1. +8 −7 pgjdbc/src/main/java/org/postgresql/jdbc/TypeInfoCache.java
@@ -114,16 +114,16 @@
public TypeInfoCache(BaseConnection conn, int unknownLength) {
this.conn = conn;
this.unknownLength = unknownLength;
oidToPgName = new HashMap<Integer, String>();
pgNameToOid = new HashMap<String, Integer>();
pgNameToJavaClass = new HashMap<String, String>();
pgNameToPgObject = new HashMap<String, Class<? extends PGobject>>();
pgArrayToPgType = new HashMap<Integer, Integer>();
arrayOidToDelimiter = new HashMap<Integer, Character>();
oidToPgName = new HashMap<Integer, String>((int) Math.round(types.length * 1.5));
pgNameToOid = new HashMap<String, Integer>((int) Math.round(types.length * 1.5));
pgNameToJavaClass = new HashMap<String, String>((int) Math.round(types.length * 1.5));
pgNameToPgObject = new HashMap<String, Class<? extends PGobject>>((int) Math.round(types.length * 1.5));
pgArrayToPgType = new HashMap<Integer, Integer>((int) Math.round(types.length * 1.5));
arrayOidToDelimiter = new HashMap<Integer, Character>((int) Math.round(types.length * 2.5));

// needs to be synchronized because the iterator is returned
// from getPGTypeNamesWithSQLTypes()
pgNameToSQLType = Collections.synchronizedMap(new HashMap<String, Integer>());
pgNameToSQLType = Collections.synchronizedMap(new HashMap<String, Integer>((int) Math.round(types.length * 1.5)));

for (Object[] type : types) {
String pgTypeName = (String) type[0];
@@ -152,6 +152,7 @@ public synchronized void addCoreType(String pgTypeName, Integer oid, Integer sql
//
Character delim = ',';
arrayOidToDelimiter.put(oid, delim);
arrayOidToDelimiter.put(arrayOid, delim);

String pgArrayTypeName = pgTypeName + "[]";
pgNameToJavaClass.put(pgArrayTypeName, "java.sql.Array");

0 comments on commit 6a0960a

Please sign in to comment.
You can’t perform that action at this time.