Author: manik.surtani(a)jboss.com
Date: 2009-08-18 06:43:24 -0400 (Tue, 18 Aug 2009)
New Revision: 8191
Modified:
core/trunk/src/main/java/org/jboss/cache/loader/AdjListJDBCCacheLoader.java
core/trunk/src/main/java/org/jboss/cache/loader/AdjListJDBCCacheLoaderConfig.java
Log:
[JBCACHE-1533] (JDBCCacheLoader does not honour the create/drop false property for the
jbosscache_D table) Patch submitted by Andrew Duckworth
Modified: core/trunk/src/main/java/org/jboss/cache/loader/AdjListJDBCCacheLoader.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/loader/AdjListJDBCCacheLoader.java 2009-08-18
09:36:45 UTC (rev 8190)
+++ core/trunk/src/main/java/org/jboss/cache/loader/AdjListJDBCCacheLoader.java 2009-08-18
10:43:24 UTC (rev 8191)
@@ -306,37 +306,48 @@
cf.close(con);
}
- createDummyTableIfNeeded();
+ if (config.getCreateTable())
+ {
+ createDummyTableIfNeeded();
+ }
}
private void createDummyTableIfNeeded() throws Exception
{
Connection conn = null;
PreparedStatement ps = null;
- try
+
+ if (config.getDropTable())
{
- conn = cf.getConnection();
- ps = prepareAndLogStatement(conn, config.getDummyTableRemovalDDL());
- ps.execute();
+ try
+ {
+ conn = cf.getConnection();
+ ps = prepareAndLogStatement(conn, config.getDummyTableRemovalDDL());
+ ps.execute();
+ }
+ catch (Exception e)
+ {
+ if (getLogger().isTraceEnabled())
+ getLogger().trace("No need to drop tables!");
+ }
+ finally
+ {
+ safeClose(ps);
+ cf.close(conn);
+ }
}
- catch (Exception e)
- {
- if (getLogger().isTraceEnabled()) getLogger().trace("No need to drop
tables!");
- }
- finally
- {
- safeClose(ps);
- cf.close(conn);
- }
-
+
try
{
conn = cf.getConnection();
- ps = prepareAndLogStatement(conn, config.getDummyTableCreationDDL());
- ps.execute();
- safeClose(ps);
- ps = prepareAndLogStatement(conn, config.getDummyTablePopulationSql());
- ps.execute();
+ if (!tableExists(config.getDummyTable(), conn))
+ {
+ ps = prepareAndLogStatement(conn, config.getDummyTableCreationDDL());
+ ps.execute();
+ safeClose(ps);
+ ps = prepareAndLogStatement(conn, config.getDummyTablePopulationSql());
+ ps.execute();
+ }
}
finally
{
@@ -392,6 +403,8 @@
*/
public boolean exists(Fqn name) throws Exception
{
+ if (getLogger().isTraceEnabled())
+ getLogger().trace("exists name=" + name);
lock.acquireLock(name, false);
Connection conn = null;
PreparedStatement ps = null;
@@ -401,7 +414,10 @@
conn = cf.getConnection();
ps = prepareAndLogStatement(conn, config.getExistsSql(), name.toString());
rs = ps.executeQuery();
- return rs.next();
+ boolean res = rs.next();
+ if (getLogger().isTraceEnabled())
+ getLogger().trace("exists name=" + name + " is " +
res);
+ return res;
}
finally
{
@@ -422,6 +438,8 @@
*/
public Object remove(Fqn name, Object key) throws Exception
{
+ if (getLogger().isTraceEnabled())
+ getLogger().trace("remove name=" + name);
lock.acquireLock(name, true);
try
{
@@ -459,6 +477,8 @@
@SuppressWarnings("unchecked")
protected Map<Object, Object> loadNode(Fqn name)
{
+ if (getLogger().isTraceEnabled())
+ getLogger().trace("loadNode name=" + name);
boolean rowExists = false;
Connection con = null;
PreparedStatement ps = null;
@@ -515,6 +535,8 @@
*/
protected void insertNode(Fqn name, Map dataMap, boolean rowMayExist)
{
+ if (getLogger().isTraceEnabled())
+ getLogger().trace("insertNode name=" + name + " dataMap="
+ dataMap);
Connection con = null;
PreparedStatement ps = null;
try
@@ -598,6 +620,8 @@
*/
protected void updateNode(Fqn name, Map<Object, Object> node)
{
+ if (getLogger().isTraceEnabled())
+ getLogger().trace("updateNode name=" + name);
Connection con = null;
PreparedStatement ps = null;
try
Modified:
core/trunk/src/main/java/org/jboss/cache/loader/AdjListJDBCCacheLoaderConfig.java
===================================================================
---
core/trunk/src/main/java/org/jboss/cache/loader/AdjListJDBCCacheLoaderConfig.java 2009-08-18
09:36:45 UTC (rev 8190)
+++
core/trunk/src/main/java/org/jboss/cache/loader/AdjListJDBCCacheLoaderConfig.java 2009-08-18
10:43:24 UTC (rev 8191)
@@ -251,6 +251,11 @@
this.table = table;
}
+ public String getDummyTable()
+ {
+ return table + "_D";
+ }
+
public String getUpdateTableSql()
{
return updateTableSql;
Show replies by date