[jboss-cvs] JBossCache/src/org/jboss/cache/loader ...
Manik Surtani
manik at jboss.org
Mon Mar 12 14:13:48 EDT 2007
User: msurtani
Date: 07/03/12 14:13:48
Modified: src/org/jboss/cache/loader AdjListJDBCCacheLoader.java
JDBCCacheLoaderOld.java CacheLoaderManager.java
Log:
JBCACHE-1005
Revision Changes Path
1.3 +723 -701 JBossCache/src/org/jboss/cache/loader/AdjListJDBCCacheLoader.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: AdjListJDBCCacheLoader.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/loader/AdjListJDBCCacheLoader.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- AdjListJDBCCacheLoader.java 7 Mar 2007 23:32:06 -0000 1.2
+++ AdjListJDBCCacheLoader.java 12 Mar 2007 18:13:47 -0000 1.3
@@ -1,16 +1,30 @@
package org.jboss.cache.loader;
+import org.apache.commons.logging.Log;
import org.jboss.cache.Fqn;
import org.jboss.cache.Modification;
-import org.jboss.cache.util.Util;
import org.jboss.cache.config.CacheLoaderConfig;
-import org.apache.commons.logging.Log;
+import org.jboss.cache.util.Util;
-import java.util.*;
-import java.sql.*;
-import java.io.InputStream;
-import java.io.IOException;
import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.sql.Connection;
+import java.sql.DatabaseMetaData;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.sql.Types;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
/**
* Adjacency List Model is the model of persisting trees in which each children holds a reference to its parent.
@@ -49,10 +63,11 @@
getLogger().error("Connectionn factory class could not be loaded", e);
throw new IllegalStateException("Connectionn factory class could not be loaded", e);
}
- } else
+ }
+ else
{
/* We create the ManagedConnectionFactory instance but the JNDI lookup is no done until
- the start method is called, since that's when its registered in its lifecycle */
+the start method is called, since that's when its registered in its lifecycle */
cf = new ManagedConnectionFactory();
}
/* Regardless of the type of connection factory, we set the configuration */
@@ -297,7 +312,8 @@
if (node.isEmpty())
{
updateNode(name, null);
- } else
+ }
+ else
{
updateNode(name, node);
}
@@ -407,14 +423,16 @@
byte[] byteStream = getMarshaller().objectToByteBuffer(node);
ByteArrayInputStream bais = new ByteArrayInputStream(byteStream);
ps.setBinaryStream(2, bais, byteStream.length);
- } else
+ }
+ else
{
// a hack to handles the incomp. of SQL server jdbc driver prior to SQL SERVER 2005
if (driverName != null && (driverName.contains("SQLSERVER")
|| driverName.contains("POSTGRESQL")))
{
ps.setNull(2, Types.LONGVARBINARY);
- } else
+ }
+ else
{
ps.setNull(2, Types.BLOB);
}
@@ -424,9 +442,10 @@
if (name.size() == 0)
{
ps.setNull(3, Types.VARCHAR);
- } else
+ }
+ else
{
- ps.setString(3, name.getFqnChild(name.size() - 1).toString());
+ ps.setString(3, name.getAncestor(name.size() - 1).toString());
}
int rows = ps.executeUpdate();
@@ -555,16 +574,19 @@
if (dmd.storesLowerCaseQuotedIdentifiers())
{
tableName = toLowerCase(tableName);
- } else if (dmd.storesUpperCaseQuotedIdentifiers())
+ }
+ else if (dmd.storesUpperCaseQuotedIdentifiers())
{
tableName = toUpperCase(tableName);
}
- } else
+ }
+ else
{
if (dmd.storesLowerCaseIdentifiers())
{
tableName = toLowerCase(tableName);
- } else if (dmd.storesUpperCaseIdentifiers())
+ }
+ else if (dmd.storesUpperCaseIdentifiers())
{
tableName = toUpperCase(tableName);
}
1.3 +236 -231 JBossCache/src/org/jboss/cache/loader/JDBCCacheLoaderOld.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: JDBCCacheLoaderOld.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/loader/JDBCCacheLoaderOld.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- JDBCCacheLoaderOld.java 5 Mar 2007 21:10:43 -0000 1.2
+++ JDBCCacheLoaderOld.java 12 Mar 2007 18:13:47 -0000 1.3
@@ -61,7 +61,7 @@
* @author <a href="mailto:alex at jboss.org">Alexey Loubyansky</a>
* @author <a href="mailto:hmesha at novell.com">Hany Mesha </a>
* @author <a href="mailto:galder.zamarreno at jboss.com">Galder Zamarreno</a>
- * @version <tt>$Revision: 1.2 $</tt>
+ * @version <tt>$Revision: 1.3 $</tt>
* @deprecated please use the
*/
public class JDBCCacheLoaderOld extends AdjListJDBCCacheLoader
@@ -76,7 +76,8 @@
if (config instanceof AdjListJDBCCacheLoaderConfig)
{
config = (AdjListJDBCCacheLoaderConfig) base;
- } else
+ }
+ else
{
config = new AdjListJDBCCacheLoaderConfig(base);
}
@@ -110,7 +111,8 @@
if (oldNode == null || oldNode == NULL_NODE_IN_ROW)
{
node = new HashMap();
- } else
+ }
+ else
{
node = oldNode;
}
@@ -119,13 +121,14 @@
if (oldNode != null)
{
updateNode(name, node);
- } else
+ }
+ else
{
if (name.size() > 1)
{
for (int i = 1; i < name.size(); ++i)
{
- final Fqn parent = name.getFqnChild(i);
+ final Fqn parent = name.getAncestor(i);
if (!exists(parent))
{
insertNode(parent, null);
@@ -179,7 +182,8 @@
{
log.debug("total rows deleted: " + deletedRows);
}
- } else
+ }
+ else
{
StringBuffer sql = new StringBuffer(300);
sql.append("delete from ").append(config.getTable()).append(" where fqn in (");
@@ -200,7 +204,8 @@
con = cf.getConnection();
ps = con.prepareStatement(config.getDeleteNodeSql());
ps.setString(1, name.toString());
- } else
+ }
+ else
{
if (log.isDebugEnabled())
{
@@ -234,8 +239,6 @@
}
}
-
-
// Private
private void addChildrenToDeleteSql(String name, StringBuffer sql, List fqns)
@@ -271,7 +274,8 @@
if (fqns.size() == 0)
{
sql.append("?");
- } else
+ }
+ else
{
sql.append(", ?");
}
@@ -298,13 +302,14 @@
attrs.putAll(oldNode);
}
updateNode(name, attrs);
- } else
+ }
+ else
{
if (name.size() > 1)
{
for (int i = 1; i < name.size(); ++i)
{
- final Fqn parent = name.getFqnChild(i);
+ final Fqn parent = name.getAncestor(i);
if (!exists(parent))
{
insertNode(parent, null);
1.30 +40 -17 JBossCache/src/org/jboss/cache/loader/CacheLoaderManager.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: CacheLoaderManager.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/loader/CacheLoaderManager.java,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -b -r1.29 -r1.30
--- CacheLoaderManager.java 4 Jan 2007 05:35:37 -0000 1.29
+++ CacheLoaderManager.java 12 Mar 2007 18:13:47 -0000 1.30
@@ -8,6 +8,7 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.jboss.cache.CacheException;
import org.jboss.cache.CacheListener;
import org.jboss.cache.CacheSPI;
import org.jboss.cache.Fqn;
@@ -67,14 +68,21 @@
*
* @param config
* @param cache
- * @throws Exception
+ * @throws CacheException
*/
- public void setConfig(CacheLoaderConfig config, CacheSPI cache) throws Exception
+ public void setConfig(CacheLoaderConfig config, CacheSPI cache) throws CacheException
{
this.config = config == null ? new CacheLoaderConfig() : config;
this.cache = cache;
+ try
+ {
loader = createCacheLoader();
}
+ catch (Exception e)
+ {
+ throw new CacheException("Unable to create cache loaders", e);
+ }
+ }
/**
* Creates the cache loader based on a cache loader config passed in.
@@ -201,7 +209,7 @@
*
* @throws Exception
*/
- public void preloadCache() throws Exception
+ public void preloadCache() throws CacheException
{
if (config.getPreload() == null || config.getPreload().equals("")) return;
if (log.isDebugEnabled()) log.debug("preloading transient state from cache loader " + loader);
@@ -232,9 +240,9 @@
* @param fqn fqn to preload
* @param preloadParents whether we preload parents
* @param preloadChildren whether we preload children
- * @throws Exception
+ * @throws CacheException if we are unable to preload
*/
- public void preload(Fqn fqn, boolean preloadParents, boolean preloadChildren) throws Exception
+ public void preload(Fqn fqn, boolean preloadParents, boolean preloadChildren) throws CacheException
{
// 1. Load the attributes first
@@ -255,12 +263,20 @@
if (preloadChildren)
{
// 3. Then recursively for all child nodes, preload them as well
- Set children = loader.getChildrenNames(fqn);
+ Set children = null;
+ try
+ {
+ children = loader.getChildrenNames(fqn);
+ }
+ catch (Exception e)
+ {
+ throw new CacheException("Unable to preload from cache loader", e);
+ }
if (children != null)
{
- for (Iterator it = children.iterator(); it.hasNext();)
+ for (Object aChildren : children)
{
- String child_name = (String) it.next();
+ String child_name = (String) aChildren;
Fqn child_fqn = new Fqn(fqn, child_name);
preload(child_fqn, false, true);
}
@@ -319,9 +335,11 @@
loader.destroy();
}
- public void startCacheLoader() throws Exception
+ public void startCacheLoader() throws CacheException
{
if (loader == null) throw new RuntimeException("Improperly configured cache loader - cache loader is null!");
+ try
+ {
// create the cache loader
loader.create();
// start the cache loader
@@ -329,6 +347,11 @@
purgeLoaders(false);
}
+ catch (Exception e)
+ {
+ throw new CacheException("Unable to start cache loaders", e);
+ }
+ }
public void purgeLoaders(boolean force) throws Exception
{
More information about the jboss-cvs-commits
mailing list