[libpostgresql-jdbc-java] 87/93: Added caching for ResultSetMetaData from Christophe Canovas

Emmanuel Bourg ebourg-guest at moszumanska.debian.org
Mon Jan 9 10:18:56 UTC 2017


This is an automated email from the git hooks/post-receive script.

ebourg-guest pushed a commit to annotated tag REL9_3_1102
in repository libpostgresql-jdbc-java.

commit 95954d2e49b9e0f0e4ff52404bdc9a54390b5c92
Author: Dave Cramer <davecramer at gmail.com>
Date:   Tue Jul 8 11:20:38 2014 -0400

    Added caching for ResultSetMetaData from Christophe Canovas
---
 org/postgresql/jdbc2/CacheMetadata.java | 76 +++++++++++++++++++++++++++++++++
 1 file changed, 76 insertions(+)

diff --git a/org/postgresql/jdbc2/CacheMetadata.java b/org/postgresql/jdbc2/CacheMetadata.java
new file mode 100644
index 0000000..1796b5b
--- /dev/null
+++ b/org/postgresql/jdbc2/CacheMetadata.java
@@ -0,0 +1,76 @@
+package org.postgresql.jdbc2;
+
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+
+import org.postgresql.core.Field;
+
+public class CacheMetadata {
+  private static Map<String, List<CacheMetadataField>> _cache =
+      new HashMap<String, List<CacheMetadataField>>();
+
+  protected boolean isCached(String idFields) {
+    return _cache.containsKey(idFields);
+  }
+  
+  protected void getCache(String idFields, Field[] fields) {
+    List<CacheMetadataField> liste = _cache.get(idFields);
+    if (liste != null) {
+      int no = 0;
+      for (CacheMetadataField c : liste) {
+        c.get(fields[no++]);
+      }
+    }
+  }
+  
+  protected void setCache(String idFields, Field[] fields) {
+    List<CacheMetadataField> liste = new LinkedList<CacheMetadataField>();
+    
+    for (int i = 0 ; i < fields.length ; i++) {
+      CacheMetadataField c = new CacheMetadataField(fields[i]);
+      liste.add(c);
+    }
+    
+    _cache.put(idFields, liste);
+  }
+  
+  protected String getIdFields(Field[] fields) {
+    StringBuffer sb = new StringBuffer();
+    
+    for (int i = 0 ; i < fields.length ; i++) {
+      sb.append(getIdField(fields[i])).append('/');
+    }
+    
+    return sb.toString();
+  }
+  
+  private String getIdField(Field f) {
+    return f.getTableOid() + "." + f.getPositionInTable();
+  }
+}
+
+class CacheMetadataField {
+  private String colName;
+  private String tabName;
+  private String schemaName;
+  private int nullable;
+  private boolean auto;
+  
+  protected CacheMetadataField(Field f) {
+    colName = f.getColumnName();
+    tabName = f.getTableName();
+    schemaName = f.getSchemaName();
+    nullable = f.getNullable();
+    auto = f.getAutoIncrement();
+  }
+  
+  protected void get(Field f) {
+    f.setColumnName(colName);
+    f.setTableName(tabName);
+    f.setSchemaName(schemaName);
+    f.setNullable(nullable);
+    f.setAutoIncrement(auto);
+  }
+}

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-java/libpostgresql-jdbc-java.git



More information about the pkg-java-commits mailing list