Author: manik.surtani(a)jboss.com
Date: 2008-09-26 07:20:35 -0400 (Fri, 26 Sep 2008)
New Revision: 6801
Modified:
core/branches/2.2.X/src/main/java/org/jboss/cache/loader/AdjListJDBCCacheLoader.java
core/branches/2.2.X/src/main/java/org/jboss/cache/loader/AdjListJDBCCacheLoaderConfig.java
Log:
JBCACHE-1414: inefficient exists() in JDBCCacheLoader
Modified:
core/branches/2.2.X/src/main/java/org/jboss/cache/loader/AdjListJDBCCacheLoader.java
===================================================================
---
core/branches/2.2.X/src/main/java/org/jboss/cache/loader/AdjListJDBCCacheLoader.java 2008-09-25
17:24:21 UTC (rev 6800)
+++
core/branches/2.2.X/src/main/java/org/jboss/cache/loader/AdjListJDBCCacheLoader.java 2008-09-26
11:20:35 UTC (rev 6801)
@@ -287,14 +287,23 @@
public boolean exists(Fqn name) throws Exception
{
lock.acquireLock(name, false);
+ Connection conn = null;
+ PreparedStatement ps = null;
+ ResultSet rs = null;
try
{
- final Map node = loadNode(name);
- return node != null;// && node != NULL_NODE_IN_ROW;
+ conn = cf.getConnection();
+ ps = conn.prepareStatement(config.getExistsSql());
+ ps.setString(1, name.toString());
+ rs = ps.executeQuery();
+ return rs.next();
}
finally
{
lock.releaseLock(name);
+ safeClose(rs);
+ safeClose(ps);
+ cf.close(conn);
}
}
Modified:
core/branches/2.2.X/src/main/java/org/jboss/cache/loader/AdjListJDBCCacheLoaderConfig.java
===================================================================
---
core/branches/2.2.X/src/main/java/org/jboss/cache/loader/AdjListJDBCCacheLoaderConfig.java 2008-09-25
17:24:21 UTC (rev 6800)
+++
core/branches/2.2.X/src/main/java/org/jboss/cache/loader/AdjListJDBCCacheLoaderConfig.java 2008-09-26
11:20:35 UTC (rev 6801)
@@ -18,7 +18,7 @@
* The serialVersionUID
*/
private static final long serialVersionUID = -8371846151643130281L;
-
+
private static final boolean CREATE_TABLE_DEFAULT = true;
private static final boolean DROP_TABLE_DEFAULT = false;
private static final String PARENT_COLUMN_DEFAULT = "parent";
@@ -27,8 +27,8 @@
private static final String FQN_TYPE_DEFAULT = "varchar(255)";
private static final String FQN_COLUMN_DEFAULT = "fqn";
private static final String PRIMARY_KEY_DEFAULT = "jbosscache_pk";
- private static final String TABLE_DEFAULT = "jbosscache";
-
+ private static final String TABLE_DEFAULT = "jbosscache";
+
private boolean createTable = CREATE_TABLE_DEFAULT;
private String createTableDDL;
private String datasourceName;
@@ -46,6 +46,7 @@
private String selectNodeSql;
private String updateNodeSql;
private String updateTableSql;
+ private String existsSql;
private String connectionFactoryClass;
private String primaryKey = PRIMARY_KEY_DEFAULT;
private String fqnType = FQN_TYPE_DEFAULT;
@@ -167,6 +168,21 @@
return insertNodeSql;
}
+ public String getExistsSql()
+ {
+ if (existsSql == null)
+ {
+ setExistsSql(constructExistsSql());
+ }
+ return existsSql;
+ }
+
+ public void setExistsSql(String existsSql)
+ {
+ testImmutability("existsSql");
+ this.existsSql = existsSql;
+ }
+
public void setInsertNodeSql(String insertNodeSql)
{
testImmutability("insertNodeSql");
@@ -313,7 +329,7 @@
testImmutability("connectionFactoryClass");
this.connectionFactoryClass = connectionFactoryClass;
}
-
+
public String getPrimaryKey()
{
return primaryKey;
@@ -556,6 +572,11 @@
return "select " + fqnColumn + " from " + table + " where
" + parentColumn + "=?";
}
+ private String constructExistsSql()
+ {
+ return "select '1' from " + table + " where " +
fqnColumn + "=?";
+ }
+
private String constructInsertNodeSql()
{
return "insert into " +
@@ -567,5 +588,5 @@
", " +
parentColumn +
") values (?, ?, ?)";
- }
+ }
}
\ No newline at end of file
Show replies by date