[jbosscache-commits] JBoss Cache SVN: r7848 - in core/branches/flat/src: main/java/org/horizon/loader/jdbc/binary and 2 other directories.

jbosscache-commits at lists.jboss.org jbosscache-commits at lists.jboss.org
Wed Mar 4 12:02:56 EST 2009


Author: mircea.markus
Date: 2009-03-04 12:02:56 -0500 (Wed, 04 Mar 2009)
New Revision: 7848

Added:
   core/branches/flat/src/main/java/org/horizon/loader/jdbc/JdbcCacheStore.java
   core/branches/flat/src/main/java/org/horizon/loader/jdbc/JdbcCacheStoreConfig.java
   core/branches/flat/src/test/java/org/horizon/loader/jdbc/JdbcCacheStoreTest.java
Modified:
   core/branches/flat/src/main/java/org/horizon/loader/jdbc/binary/JdbcBinaryCacheStore.java
   core/branches/flat/src/main/java/org/horizon/loader/jdbc/binary/JdbcBinaryCacheStoreConfig.java
   core/branches/flat/src/main/java/org/horizon/loader/jdbc/stringbased/JdbcStringBasedCacheStore.java
   core/branches/flat/src/main/java/org/horizon/loader/jdbc/stringbased/JdbcStringBasedCacheStoreConfig.java
   core/branches/flat/src/test/java/org/horizon/loader/jdbc/JdbcBinaryCacheStoreTest.java
   core/branches/flat/src/test/java/org/horizon/loader/jdbc/JdbcStringBasedCacheStoreTest.java
Log:
ongoing jdbc cache store work

Added: core/branches/flat/src/main/java/org/horizon/loader/jdbc/JdbcCacheStore.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/loader/jdbc/JdbcCacheStore.java	                        (rev 0)
+++ core/branches/flat/src/main/java/org/horizon/loader/jdbc/JdbcCacheStore.java	2009-03-04 17:02:56 UTC (rev 7848)
@@ -0,0 +1,106 @@
+package org.horizon.loader.jdbc;
+
+import org.horizon.Cache;
+import org.horizon.loader.AbstractCacheStore;
+import org.horizon.loader.CacheLoaderConfig;
+import org.horizon.loader.CacheLoaderException;
+import org.horizon.loader.CacheStore;
+import org.horizon.loader.StoredEntry;
+import org.horizon.loader.jdbc.binary.JdbcBinaryCacheStore;
+import org.horizon.loader.jdbc.connectionfactory.ConnectionFactory;
+import org.horizon.loader.jdbc.connectionfactory.ConnectionFactoryConfig;
+import org.horizon.loader.jdbc.stringbased.JdbcStringBasedCacheStore;
+import org.horizon.marshall.Marshaller;
+
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.util.Set;
+
+/**
+ * // TODO: Mircea: Document this!
+ *
+ * @author
+ */
+public class JdbcCacheStore extends AbstractCacheStore {
+
+   private JdbcCacheStoreConfig config;
+   private JdbcBinaryCacheStore binaryCacheStore = new JdbcBinaryCacheStore();
+   private JdbcStringBasedCacheStore stringBasedCacheStore = new JdbcStringBasedCacheStore();
+   private ConnectionFactory sharedConnectionFactory;
+
+   @Override
+   public void init(CacheLoaderConfig config, Cache cache, Marshaller m) {
+      super.init(config, cache, m);
+      this.config = (JdbcCacheStoreConfig) config;
+      binaryCacheStore.init(this.config.getBinaryCacheStoreConfig(), cache, m);
+      stringBasedCacheStore.init(this.config.getStringCacheStoreConfig(), cache, m);
+   }
+
+   @Override
+   public void start() throws CacheLoaderException {
+      super.start();
+      ConnectionFactoryConfig factoryConfig = config.getConnectionFactoryConfig();
+      sharedConnectionFactory = ConnectionFactory.getConnectionFactory(factoryConfig.getConnectionFactoryClass());
+      sharedConnectionFactory.start(factoryConfig);
+      binaryCacheStore.start();
+      binaryCacheStore.doConnectionFactoryInitialization(sharedConnectionFactory);
+      stringBasedCacheStore.start();
+      stringBasedCacheStore.doConnectionFactoryInitialization(sharedConnectionFactory);
+   }
+
+   @Override
+   public void stop() throws CacheLoaderException {
+      super.stop();
+      binaryCacheStore.stop();
+      stringBasedCacheStore.stop();
+      sharedConnectionFactory.stop();
+   }
+
+   @Override
+   protected void purgeInternal() throws CacheLoaderException {
+      binaryCacheStore.purgeExpired();
+      stringBasedCacheStore.purgeExpired();
+   }
+
+   public StoredEntry load(Object key) throws CacheLoaderException {
+      return getCacheStore(key).load(key);
+   }
+
+   public Set<StoredEntry> loadAll() throws CacheLoaderException {
+      Set<StoredEntry> fromBuckets = binaryCacheStore.loadAll();
+      Set<StoredEntry> fromStrings = stringBasedCacheStore.loadAll();
+      fromBuckets.addAll(fromStrings);
+      return fromBuckets;
+   }
+
+   public void store(StoredEntry ed) throws CacheLoaderException {
+      getCacheStore(ed.getKey()).store(ed);
+   }
+
+   public void fromStream(ObjectInput inputStream) throws CacheLoaderException {
+      binaryCacheStore.fromStream(inputStream);
+      stringBasedCacheStore.fromStream(inputStream);
+   }
+
+   public void toStream(ObjectOutput outputStream) throws CacheLoaderException {
+      binaryCacheStore.toStream(outputStream);
+      stringBasedCacheStore.toStream(outputStream);
+   }
+
+   public boolean remove(Object key) throws CacheLoaderException {
+      return getCacheStore(key).remove(key);
+   }
+
+   public void clear() throws CacheLoaderException {
+      binaryCacheStore.clear();
+      stringBasedCacheStore.clear();
+   }
+
+   public Class<? extends CacheLoaderConfig> getConfigurationClass() {
+      return JdbcCacheStoreConfig.class;
+   }
+
+   private CacheStore getCacheStore(Object key) {
+      return stringBasedCacheStore.supportsKey(key) ? stringBasedCacheStore : binaryCacheStore;
+   }
+}


Property changes on: core/branches/flat/src/main/java/org/horizon/loader/jdbc/JdbcCacheStore.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF

Added: core/branches/flat/src/main/java/org/horizon/loader/jdbc/JdbcCacheStoreConfig.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/loader/jdbc/JdbcCacheStoreConfig.java	                        (rev 0)
+++ core/branches/flat/src/main/java/org/horizon/loader/jdbc/JdbcCacheStoreConfig.java	2009-03-04 17:02:56 UTC (rev 7848)
@@ -0,0 +1,139 @@
+package org.horizon.loader.jdbc;
+
+import org.horizon.loader.AbstractCacheStoreConfig;
+import org.horizon.loader.jdbc.binary.JdbcBinaryCacheStoreConfig;
+import org.horizon.loader.jdbc.connectionfactory.ConnectionFactoryConfig;
+import org.horizon.loader.jdbc.stringbased.JdbcStringBasedCacheStoreConfig;
+
+/**
+ * // TODO: Mircea: Document this!
+ *
+ * @author
+ */
+public class JdbcCacheStoreConfig extends AbstractCacheStoreConfig {
+
+   private ConnectionFactoryConfig connectionFactoryConfig = new ConnectionFactoryConfig();
+   private TableManipulation binaryTableManipulation = new TableManipulation();
+   private TableManipulation stringsTableManipulation = new TableManipulation();
+
+
+   public JdbcCacheStoreConfig() {
+      this.className = JdbcCacheStore.class.getName();
+   }
+
+   public void setConnectionFactoryConfig(ConnectionFactoryConfig connectionFactoryConfig) {
+      this.connectionFactoryConfig = connectionFactoryConfig;
+   }
+
+   public void setBinaryTableManipulation(TableManipulation binaryTableManipulation) {
+      this.binaryTableManipulation = binaryTableManipulation;
+   }
+
+   public void setStringsTableManipulation(TableManipulation stringsTableManipulation) {
+      this.stringsTableManipulation = stringsTableManipulation;
+   }
+
+   JdbcBinaryCacheStoreConfig getBinaryCacheStoreConfig() {
+      JdbcBinaryCacheStoreConfig cacheStoreConfig = new JdbcBinaryCacheStoreConfig(false);
+      cacheStoreConfig.setTableManipulation(binaryTableManipulation);
+      return cacheStoreConfig;
+   }
+
+   JdbcStringBasedCacheStoreConfig getStringCacheStoreConfig() {
+      JdbcStringBasedCacheStoreConfig config = new JdbcStringBasedCacheStoreConfig(false);
+      config.setTableManipulation(stringsTableManipulation);
+      return config;
+   }
+
+   public void setIdColumnNameForStrings(String idColumnNameForStrings) {
+      this.stringsTableManipulation.setIdColumnName(idColumnNameForStrings);
+   }
+
+   public void setIdColumnTypeForStrings(String idColumnTypeForStrings) {
+      this.stringsTableManipulation.setIdColumnType(idColumnTypeForStrings);
+   }
+
+   public void setTableNameForStrings(String tableNameForStrings) {
+      this.stringsTableManipulation.setTableName(tableNameForStrings);
+   }
+
+   public void setDataColumnNameForStrings(String dataColumnNameForStrings) {
+      this.stringsTableManipulation.setDataColumnName(dataColumnNameForStrings);
+   }
+
+   public void setDataColumnTypeForStrings(String dataColumnTypeForStrings) {
+      this.stringsTableManipulation.setDataColumnType(dataColumnTypeForStrings);
+   }
+
+   public void setTimestampColumnNameForStrings(String timestampColumnNameForStrings) {
+      this.stringsTableManipulation.setTimestampColumnName(timestampColumnNameForStrings);
+   }
+
+   public void setTimestampColumnTypeForStrings(String timestampColumnTypeForStrings) {
+      this.stringsTableManipulation.setTimestampColumnType(timestampColumnTypeForStrings);
+   }
+
+   public void setCreateTableOnStartForStrings(boolean createTableOnStartForStrings) {
+      this.stringsTableManipulation.setCreateTableOnStart(createTableOnStartForStrings);
+   }
+
+   public void setDropTableOnExitForStrings(boolean dropTableOnExitForStrings) {
+      this.stringsTableManipulation.setDropTableOnExit(dropTableOnExitForStrings);
+   }
+
+   public void setIdColumnNameForBinary(String idColumnNameForBinary) {
+      this.binaryTableManipulation.setIdColumnName(idColumnNameForBinary);
+   }
+
+   public void setIdColumnTypeForBinary(String idColumnTypeForBinary) {
+      this.binaryTableManipulation.setIdColumnType(idColumnTypeForBinary);
+   }
+
+   public void setTableNameForBinary(String tableNameForBinary) {
+      this.binaryTableManipulation.setTableName(tableNameForBinary);
+   }
+
+   public void setDataColumnNameForBinary(String dataColumnNameForBinary) {
+      this.binaryTableManipulation.setDataColumnName(dataColumnNameForBinary);
+   }
+
+   public void setDataColumnTypeForBinary(String dataColumnTypeForBinary) {
+      this.binaryTableManipulation.setDataColumnType(dataColumnTypeForBinary);
+   }
+
+   public void setTimestampColumnNameForBinary(String timestampColumnNameForBinary) {
+      this.binaryTableManipulation.setTimestampColumnName(timestampColumnNameForBinary);
+   }
+
+   public void setTimestampColumnTypeForBinary(String timestampColumnTypeForBinary) {
+      this.binaryTableManipulation.setTimestampColumnType(timestampColumnTypeForBinary);
+   }
+
+   public void setCreateTableOnStartForBinary(boolean createTableOnStartForBinary) {
+      this.binaryTableManipulation.setCreateTableOnStart(createTableOnStartForBinary);
+   }
+
+   public void setDropTableOnExitForBinary(boolean dropTableOnExitForBinary) {
+      this.binaryTableManipulation.setDropTableOnExit(dropTableOnExitForBinary);
+   }
+
+   public void setDriverClass(String driverClass) {
+      this.connectionFactoryConfig.setDriverClass(driverClass);
+   }
+
+   public void setConnectionUrl(String connectionUrl) {
+      this.connectionFactoryConfig.setConnectionUrl(connectionUrl);
+   }
+
+   public void setUserName(String userName) {
+      this.connectionFactoryConfig.setUserName(userName);
+   }
+
+   public void setPassword(String password) {
+      this.connectionFactoryConfig.setPassword(password);
+   }
+
+   public ConnectionFactoryConfig getConnectionFactoryConfig() {
+      return connectionFactoryConfig;
+   }
+}


Property changes on: core/branches/flat/src/main/java/org/horizon/loader/jdbc/JdbcCacheStoreConfig.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF

Modified: core/branches/flat/src/main/java/org/horizon/loader/jdbc/binary/JdbcBinaryCacheStore.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/loader/jdbc/binary/JdbcBinaryCacheStore.java	2009-03-04 13:32:42 UTC (rev 7847)
+++ core/branches/flat/src/main/java/org/horizon/loader/jdbc/binary/JdbcBinaryCacheStore.java	2009-03-04 17:02:56 UTC (rev 7848)
@@ -62,15 +62,18 @@
    public void start() throws CacheLoaderException {
       super.start();
       String connectionFactoryClass = config.getConnectionFactoryConfig().getConnectionFactoryClass();
-      this.connectionFactory = ConnectionFactory.getConnectionFactory(connectionFactoryClass);
-      connectionFactory.start(config.getConnectionFactoryConfig());
-      tableManipulation = config.getTableManipulation();
-      tableManipulation.start(connectionFactory);
+      if (config.isManageConnectionFatory()) {
+         ConnectionFactory factory = ConnectionFactory.getConnectionFactory(connectionFactoryClass);
+         factory.start(config.getConnectionFactoryConfig());
+         doConnectionFactoryInitialization(factory);
+      }
    }
 
    public void stop() throws CacheLoaderException {
       tableManipulation.stop();
-      connectionFactory.stop();
+      if (config.isManageConnectionFatory()) {
+         connectionFactory.stop();
+      }
    }
 
    protected void insertBucket(Bucket bucket) throws CacheLoaderException {
@@ -404,4 +407,20 @@
       log.error(message, e);
       throw new CacheLoaderException(message, e);
    }
+
+   public ConnectionFactory getConnectionFactory() {
+      return connectionFactory;
+   }
+
+   /**
+    * Keeps a reference to the connection factory for further use. Also initializes the {@link
+    * org.horizon.loader.jdbc.TableManipulation} that needs connections. This method should be called when you don't
+    * want the store to manage the connection factory, perhaps because it is using an shared connection factory: see
+    * {@link org.horizon.loader.jdbc.JdbcCacheStore} for such an example of this.
+    */
+   public void doConnectionFactoryInitialization(ConnectionFactory connectionFactory) throws CacheLoaderException {
+      this.connectionFactory = connectionFactory;
+      tableManipulation = config.getTableManipulation();
+      tableManipulation.start(connectionFactory);
+   }
 }

Modified: core/branches/flat/src/main/java/org/horizon/loader/jdbc/binary/JdbcBinaryCacheStoreConfig.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/loader/jdbc/binary/JdbcBinaryCacheStoreConfig.java	2009-03-04 13:32:42 UTC (rev 7847)
+++ core/branches/flat/src/main/java/org/horizon/loader/jdbc/binary/JdbcBinaryCacheStoreConfig.java	2009-03-04 17:02:56 UTC (rev 7848)
@@ -13,8 +13,14 @@
 
    private ConnectionFactoryConfig connectionFactoryConfig = new ConnectionFactoryConfig();
    private TableManipulation tableManipulation = new TableManipulation();
+   private boolean createConnectionFatory = true;
 
+   public JdbcBinaryCacheStoreConfig(boolean createConnectionFatory) {
+      this.createConnectionFatory = createConnectionFatory;
+   }
+
    public JdbcBinaryCacheStoreConfig(ConnectionFactoryConfig connectionFactoryConfig, TableManipulation tm) {
+      this();
       this.connectionFactoryConfig = connectionFactoryConfig;
       this.tableManipulation = tm;
    }
@@ -23,6 +29,10 @@
       className = JdbcBinaryCacheStore.class.getName();
    }
 
+   boolean isManageConnectionFatory() {
+      return createConnectionFatory;
+   }
+
    /**
     * If true, and the table is missing it will be created when starting the cache store. Default to <tt>true</tt>.
     */
@@ -131,4 +141,8 @@
    public TableManipulation getTableManipulation() {
       return tableManipulation;
    }
+
+   public void setTableManipulation(TableManipulation tableManipulation) {
+      this.tableManipulation = tableManipulation;
+   }
 }

Modified: core/branches/flat/src/main/java/org/horizon/loader/jdbc/stringbased/JdbcStringBasedCacheStore.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/loader/jdbc/stringbased/JdbcStringBasedCacheStore.java	2009-03-04 13:32:42 UTC (rev 7847)
+++ core/branches/flat/src/main/java/org/horizon/loader/jdbc/stringbased/JdbcStringBasedCacheStore.java	2009-03-04 17:02:56 UTC (rev 7848)
@@ -60,17 +60,20 @@
    @Override
    public void start() throws CacheLoaderException {
       super.start();
-      String connectionFactoryClass = config.getConnectionFactoryConfig().getConnectionFactoryClass();
-      connectionFactory = ConnectionFactory.getConnectionFactory(connectionFactoryClass);
-      connectionFactory.start(config.getConnectionFactoryConfig());
-      this.tableManipulation = config.getTableManipulation();
-      tableManipulation.start(connectionFactory);
+      if (config.isManageConnectionFactory()) {
+         String connectionFactoryClass = config.getConnectionFactoryConfig().getConnectionFactoryClass();
+         ConnectionFactory connectionFactory = ConnectionFactory.getConnectionFactory(connectionFactoryClass);
+         connectionFactory.start(config.getConnectionFactoryConfig());
+         doConnectionFactoryInitialization(connectionFactory);
+      }
       this.key2StringMapper = config.getKey2StringMapper();
    }
 
    public void stop() throws CacheLoaderException {
       tableManipulation.stop();
-      connectionFactory.stop();
+      if (config.isManageConnectionFactory()) {
+         connectionFactory.stop();
+      }
    }
 
    protected String getLockFromKey(Object key) throws CacheLoaderException {
@@ -307,4 +310,24 @@
       log.error(message, e);
       throw new CacheLoaderException(message, e);
    }
+
+   public boolean supportsKey(Object obj) {
+      return key2StringMapper.isSupportedType(obj);
+   }
+
+   /**
+    * Keeps a reference to the connection factory for further use. Also initializes the {@link
+    * org.horizon.loader.jdbc.TableManipulation} that needs connections. This method should be called when you don't
+    * want the store to manage the connection factory, perhaps because it is using an shared connection factory: see
+    * {@link org.horizon.loader.jdbc.JdbcCacheStore} for such an example of this.
+    */
+   public void doConnectionFactoryInitialization(ConnectionFactory connectionFactory) throws CacheLoaderException {
+      this.connectionFactory = connectionFactory;
+      tableManipulation = config.getTableManipulation();
+      tableManipulation.start(connectionFactory);
+   }
+
+   public Object getConnectionFactory() {
+      return connectionFactory;
+   }
 }

Modified: core/branches/flat/src/main/java/org/horizon/loader/jdbc/stringbased/JdbcStringBasedCacheStoreConfig.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/loader/jdbc/stringbased/JdbcStringBasedCacheStoreConfig.java	2009-03-04 13:32:42 UTC (rev 7847)
+++ core/branches/flat/src/main/java/org/horizon/loader/jdbc/stringbased/JdbcStringBasedCacheStoreConfig.java	2009-03-04 17:02:56 UTC (rev 7848)
@@ -17,8 +17,10 @@
 
    private ConnectionFactoryConfig connectionFactoryConfig = new ConnectionFactoryConfig();
    private TableManipulation tableManipulation = new TableManipulation();
+   private boolean manageConnectionFactory = true;
 
    public JdbcStringBasedCacheStoreConfig(ConnectionFactoryConfig connectionFactoryConfig, TableManipulation tableManipulation) {
+      this();
       this.connectionFactoryConfig = connectionFactoryConfig;
       this.tableManipulation = tableManipulation;
    }
@@ -27,6 +29,11 @@
       className = JdbcStringBasedCacheStore.class.getName();
    }
 
+   public JdbcStringBasedCacheStoreConfig(boolean manageConnectionFactory) {
+      this();
+      this.manageConnectionFactory = manageConnectionFactory;
+   }
+
    public Key2StringMapper getKey2StringMapper() {
       if (key2StringMapper == null) {
          try {
@@ -117,8 +124,8 @@
    }
 
    /**
-    * The name of the driver used for connecting to the database. Mandatory, will be loaded before initiating the
-    * first connection.
+    * The name of the driver used for connecting to the database. Mandatory, will be loaded before initiating the first
+    * connection.
     */
    public void setDriverClass(String driverClassName) {
       this.connectionFactoryConfig.setDriverClass(driverClassName);
@@ -137,4 +144,25 @@
    public void setDataColumnType(String dataColumnType) {
       this.tableManipulation.setDataColumnType(dataColumnType);
    }
+
+   public void setDropTableOnExit(boolean dropTableOnExit) {
+      this.tableManipulation.setDropTableOnExit(dropTableOnExit);
+   }
+
+   public void setCreateTableOnStart(boolean createTableOnStart) {
+      this.tableManipulation.setCreateTableOnStart(createTableOnStart);
+   }
+
+   /**
+    * If this method returns false, then the connection factory should not be created by the {@link
+    * org.horizon.loader.jdbc.stringbased.JdbcStringBasedCacheStore}, but will be injected through {@link
+    * org.horizon.loader.jdbc.stringbased.JdbcStringBasedCacheStore#doConnectionFactoryInitialization(org.horizon.loader.jdbc.connectionfactory.ConnectionFactory)}
+    */
+   public boolean isManageConnectionFactory() {
+      return manageConnectionFactory;
+   }
+
+   public void setTableManipulation(TableManipulation tableManipulation) {
+      this.tableManipulation = tableManipulation;
+   }
 }

Modified: core/branches/flat/src/test/java/org/horizon/loader/jdbc/JdbcBinaryCacheStoreTest.java
===================================================================
--- core/branches/flat/src/test/java/org/horizon/loader/jdbc/JdbcBinaryCacheStoreTest.java	2009-03-04 13:32:42 UTC (rev 7847)
+++ core/branches/flat/src/test/java/org/horizon/loader/jdbc/JdbcBinaryCacheStoreTest.java	2009-03-04 17:02:56 UTC (rev 7848)
@@ -4,10 +4,11 @@
 import org.horizon.loader.CacheStore;
 import org.horizon.loader.jdbc.binary.JdbcBinaryCacheStore;
 import org.horizon.loader.jdbc.binary.JdbcBinaryCacheStoreConfig;
+import org.horizon.loader.jdbc.connectionfactory.ConnectionFactory;
 import org.horizon.loader.jdbc.connectionfactory.ConnectionFactoryConfig;
 import org.horizon.marshall.ObjectStreamMarshaller;
-import org.horizon.loader.jdbc.UnitTestDatabaseManager;
 import org.testng.annotations.Test;
+import static org.easymock.classextension.EasyMock.*;
 
 /**
  * Tester class for {@link JdbcBinaryCacheStore}
@@ -24,6 +25,33 @@
       JdbcBinaryCacheStore jdbcBucketCacheStore = new JdbcBinaryCacheStore();
       jdbcBucketCacheStore.init(config, null, new ObjectStreamMarshaller());
       jdbcBucketCacheStore.start();
+      assert jdbcBucketCacheStore.getConnectionFactory() != null;
       return jdbcBucketCacheStore;
    }
+
+   public void testNotCreateConnectionFactory() throws Exception {
+      JdbcBinaryCacheStore jdbcBucketCacheStore = new JdbcBinaryCacheStore();
+      JdbcBinaryCacheStoreConfig config = new JdbcBinaryCacheStoreConfig(false);
+      config.setCreateTableOnStart(false);
+      jdbcBucketCacheStore.init(config, null, new ObjectStreamMarshaller());
+      jdbcBucketCacheStore.start();
+      assert jdbcBucketCacheStore.getConnectionFactory() == null;
+
+      /* this will make sure that if a method like stop is called on the connection then it will barf an exception */
+      ConnectionFactory connectionFactory = createMock(ConnectionFactory.class);
+      TableManipulation tableManipulation = createMock(TableManipulation.class);
+      config.setTableManipulation(tableManipulation);
+
+      tableManipulation.start(connectionFactory);
+      replay(tableManipulation);
+      jdbcBucketCacheStore.doConnectionFactoryInitialization(connectionFactory);
+      verify(tableManipulation);
+
+      //stop should be called even if this is an externally managed connection   
+      reset(tableManipulation, connectionFactory);
+      tableManipulation.stop();
+      replay(tableManipulation, connectionFactory);
+      jdbcBucketCacheStore.stop();
+      verify(tableManipulation, connectionFactory);
+   }
 }

Added: core/branches/flat/src/test/java/org/horizon/loader/jdbc/JdbcCacheStoreTest.java
===================================================================
--- core/branches/flat/src/test/java/org/horizon/loader/jdbc/JdbcCacheStoreTest.java	                        (rev 0)
+++ core/branches/flat/src/test/java/org/horizon/loader/jdbc/JdbcCacheStoreTest.java	2009-03-04 17:02:56 UTC (rev 7848)
@@ -0,0 +1,33 @@
+package org.horizon.loader.jdbc;
+
+import org.horizon.loader.BaseCacheStoreTest;
+import org.horizon.loader.CacheStore;
+import org.horizon.loader.jdbc.connectionfactory.ConnectionFactoryConfig;
+import org.testng.annotations.Test;
+
+/**
+ * // TODO: Mircea: Document this!
+ *
+ * @author
+ */
+ at Test(groups = "functional", testName = "loader.jdbc.JdbcCacheStoreTest")
+public class JdbcCacheStoreTest extends BaseCacheStoreTest {
+
+   protected CacheStore createCacheStore() throws Exception {
+      JdbcCacheStoreConfig jdbcCacheStoreConfig = new JdbcCacheStoreConfig();
+      TableManipulation stringsTm = UnitTestDatabaseManager.buildDefaultTableManipulation();
+      stringsTm.setTableName("STRINGS_TABLE");
+      TableManipulation binaryTm = UnitTestDatabaseManager.buildDefaultTableManipulation();
+      binaryTm.setTableName("BINARY_TABLE");
+
+      ConnectionFactoryConfig cfc = UnitTestDatabaseManager.getUniqueConnectionFactoryConfig();
+      jdbcCacheStoreConfig.setConnectionFactoryConfig(cfc);
+      jdbcCacheStoreConfig.setStringsTableManipulation(stringsTm);
+      jdbcCacheStoreConfig.setBinaryTableManipulation(binaryTm);
+
+      JdbcCacheStore cacheStore = new JdbcCacheStore();
+      cacheStore.init(jdbcCacheStoreConfig, null, getMarshaller());
+      cacheStore.start();
+      return cacheStore;
+   }
+}


Property changes on: core/branches/flat/src/test/java/org/horizon/loader/jdbc/JdbcCacheStoreTest.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF

Modified: core/branches/flat/src/test/java/org/horizon/loader/jdbc/JdbcStringBasedCacheStoreTest.java
===================================================================
--- core/branches/flat/src/test/java/org/horizon/loader/jdbc/JdbcStringBasedCacheStoreTest.java	2009-03-04 13:32:42 UTC (rev 7847)
+++ core/branches/flat/src/test/java/org/horizon/loader/jdbc/JdbcStringBasedCacheStoreTest.java	2009-03-04 17:02:56 UTC (rev 7848)
@@ -2,12 +2,15 @@
 
 import org.horizon.loader.BaseCacheStoreTest;
 import org.horizon.loader.CacheStore;
+import org.horizon.loader.jdbc.connectionfactory.ConnectionFactory;
 import org.horizon.loader.jdbc.connectionfactory.ConnectionFactoryConfig;
 import org.horizon.loader.jdbc.stringbased.JdbcStringBasedCacheStore;
 import org.horizon.loader.jdbc.stringbased.JdbcStringBasedCacheStoreConfig;
 import org.horizon.marshall.ObjectStreamMarshaller;
-import org.horizon.loader.jdbc.UnitTestDatabaseManager;
 import org.testng.annotations.Test;
+import static org.easymock.classextension.EasyMock.*;
+import static org.easymock.classextension.EasyMock.replay;
+import static org.easymock.classextension.EasyMock.verify;
 
 /**
  * Tester class  for {@link org.horizon.loader.jdbc.stringbased.JdbcStringBasedCacheStore}.
@@ -26,4 +29,30 @@
       jdbcBucketCacheStore.start();
       return jdbcBucketCacheStore;
    }
+
+   public void testNotCreateConnectionFactory() throws Exception {
+      JdbcStringBasedCacheStore stringBasedCacheStore = new JdbcStringBasedCacheStore();
+      JdbcStringBasedCacheStoreConfig config = new JdbcStringBasedCacheStoreConfig(false);
+      config.setCreateTableOnStart(false);
+      stringBasedCacheStore.init(config, null, new ObjectStreamMarshaller());
+      stringBasedCacheStore.start();
+      assert stringBasedCacheStore.getConnectionFactory() == null;
+
+      /* this will make sure that if a method like stop is called on the connection then it will barf an exception */
+      ConnectionFactory connectionFactory = createMock(ConnectionFactory.class);
+      TableManipulation tableManipulation = createMock(TableManipulation.class);
+      config.setTableManipulation(tableManipulation);
+
+      tableManipulation.start(connectionFactory);
+      replay(tableManipulation);
+      stringBasedCacheStore.doConnectionFactoryInitialization(connectionFactory);
+      verify(tableManipulation);
+
+      //stop should be called even if this is an external
+      reset(tableManipulation, connectionFactory);
+      tableManipulation.stop();
+      replay(tableManipulation, connectionFactory);
+      stringBasedCacheStore.stop();
+      verify(tableManipulation, connectionFactory);
+   }
 }




More information about the jbosscache-commits mailing list