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

jbosscache-commits at lists.jboss.org jbosscache-commits at lists.jboss.org
Thu Mar 5 08:47:19 EST 2009


Author: mircea.markus
Date: 2009-03-05 08:47:19 -0500 (Thu, 05 Mar 2009)
New Revision: 7857

Added:
   core/branches/flat/src/main/java/org/horizon/loader/jdbc/mixed/
   core/branches/flat/src/main/java/org/horizon/loader/jdbc/mixed/JdbcMixedCacheStore.java
   core/branches/flat/src/main/java/org/horizon/loader/jdbc/mixed/JdbcMixedCacheStoreConfig.java
   core/branches/flat/src/test/java/org/horizon/loader/jdbc/mixed/
   core/branches/flat/src/test/java/org/horizon/loader/jdbc/mixed/JdbcMixedCacheStoreConfigTest.java
   core/branches/flat/src/test/java/org/horizon/loader/jdbc/mixed/JdbcMixedCacheStoreTest.java
   core/branches/flat/src/test/java/org/horizon/loader/jdbc/mixed/JdbcMixedCacheStoreTest2.java
Removed:
   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/AbstractCacheStore.java
   core/branches/flat/src/main/java/org/horizon/loader/LockSupportCacheStoreConfig.java
   core/branches/flat/src/main/java/org/horizon/loader/jdbc/TableManipulation.java
   core/branches/flat/src/main/java/org/horizon/loader/jdbc/binary/JdbcBinaryCacheStore.java
   core/branches/flat/src/main/java/org/horizon/loader/jdbc/stringbased/JdbcStringBasedCacheStore.java
   core/branches/flat/src/test/java/org/horizon/loader/jdbc/UnitTestDatabaseManager.java
   core/branches/flat/src/test/java/org/horizon/loader/jdbc/stringbased/JdbcStringBasedCacheStoreTest2.java
   core/branches/flat/src/test/java/org/horizon/loader/jdbc/stringbased/Person.java
Log:
ongoing jdbc cache store work

Modified: core/branches/flat/src/main/java/org/horizon/loader/AbstractCacheStore.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/loader/AbstractCacheStore.java	2009-03-05 12:24:26 UTC (rev 7856)
+++ core/branches/flat/src/main/java/org/horizon/loader/AbstractCacheStore.java	2009-03-05 13:47:19 UTC (rev 7857)
@@ -61,7 +61,7 @@
             try {
                purgeInternal();
             } catch (CacheLoaderException e) {
-               log.info("Problems encountered while purging expired", e);
+               log.error("Problems encountered while purging expired", e);
             }
          }
       });

Modified: core/branches/flat/src/main/java/org/horizon/loader/LockSupportCacheStoreConfig.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/loader/LockSupportCacheStoreConfig.java	2009-03-05 12:24:26 UTC (rev 7856)
+++ core/branches/flat/src/main/java/org/horizon/loader/LockSupportCacheStoreConfig.java	2009-03-05 13:47:19 UTC (rev 7857)
@@ -6,9 +6,12 @@
  * @author Mircea.Markus at jboss.com
  */
 public class LockSupportCacheStoreConfig extends AbstractCacheStoreConfig {
-   private int lockConcurrencyLevel = 2048;
-   private long lockAcquistionTimeout = 60000;
+   public static final int DEFAULT_CONCURRENCY_LEVEL = 2048;
+   public static final int DEFAULT_LOCK_ACQUISITION_TIMEOUT = 60000;
 
+   private int lockConcurrencyLevel = DEFAULT_CONCURRENCY_LEVEL;
+   private long lockAcquistionTimeout = DEFAULT_LOCK_ACQUISITION_TIMEOUT;
+
    /**
     * Returns number of threads expected to use this class concurrently.
     */

Deleted: core/branches/flat/src/main/java/org/horizon/loader/jdbc/JdbcCacheStore.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/loader/jdbc/JdbcCacheStore.java	2009-03-05 12:24:26 UTC (rev 7856)
+++ core/branches/flat/src/main/java/org/horizon/loader/jdbc/JdbcCacheStore.java	2009-03-05 13:47:19 UTC (rev 7857)
@@ -1,106 +0,0 @@
-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.getClass()) ? stringBasedCacheStore : binaryCacheStore;
-   }
-}

Deleted: core/branches/flat/src/main/java/org/horizon/loader/jdbc/JdbcCacheStoreConfig.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/loader/jdbc/JdbcCacheStoreConfig.java	2009-03-05 12:24:26 UTC (rev 7856)
+++ core/branches/flat/src/main/java/org/horizon/loader/jdbc/JdbcCacheStoreConfig.java	2009-03-05 13:47:19 UTC (rev 7857)
@@ -1,139 +0,0 @@
-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;
-   }
-}

Modified: core/branches/flat/src/main/java/org/horizon/loader/jdbc/TableManipulation.java
===================================================================
--- core/branches/flat/src/main/java/org/horizon/loader/jdbc/TableManipulation.java	2009-03-05 12:24:26 UTC (rev 7856)
+++ core/branches/flat/src/main/java/org/horizon/loader/jdbc/TableManipulation.java	2009-03-05 13:47:19 UTC (rev 7857)
@@ -44,8 +44,8 @@
    private String deleteRowSql;
    private String loadAllRowsSql;
    private String deleteAllRows;
-   private String selectExpiredBucketsSql;
-   private String deleteExpiredBucketsSql;
+   private String selectExpiredRowsSql;
+   private String deleteExpiredRowsSql;
 
    public TableManipulation(String idColumnName, String idColumnType, String tableName, String dataColumnName,
                             String dataColumnType, String timestampColumnName, String timestampColumnType) {
@@ -278,17 +278,17 @@
    }
 
    public String getSelectExpiredRowsSql() {
-      if (selectExpiredBucketsSql == null) {
-         selectExpiredBucketsSql = getLoadAllRowsSql() + " WHERE " + timestampColumnName + "< ?";
+      if (selectExpiredRowsSql == null) {
+         selectExpiredRowsSql = getLoadAllRowsSql() + " WHERE " + timestampColumnName + "< ?";
       }
-      return selectExpiredBucketsSql;
+      return selectExpiredRowsSql;
    }
 
    public String getDeleteExpiredRowsSql() {
-      if (deleteExpiredBucketsSql == null) {
-         deleteExpiredBucketsSql = "DELETE FROM" + tableName + " WHERE " + timestampColumnName + "< ?";
+      if (deleteExpiredRowsSql == null) {
+         deleteExpiredRowsSql = "DELETE FROM " + tableName + " WHERE " + timestampColumnName + "< ? AND " + timestampColumnName + "> 0";
       }
-      return deleteExpiredBucketsSql;
+      return deleteExpiredRowsSql;
    }
 
    @Override
@@ -307,4 +307,28 @@
    public boolean tableExists(Connection connection) throws CacheLoaderException {
       return tableExists(connection, tableName);
    }
+
+   public String getIdColumnName() {
+      return idColumnName;
+   }
+
+   public String getIdColumnType() {
+      return idColumnType;
+   }
+
+   public String getDataColumnName() {
+      return dataColumnName;
+   }
+
+   public String getDataColumnType() {
+      return dataColumnType;
+   }
+
+   public String getTimestampColumnName() {
+      return timestampColumnName;
+   }
+
+   public String getTimestampColumnType() {
+      return timestampColumnType;
+   }
 }

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-05 12:24:26 UTC (rev 7856)
+++ core/branches/flat/src/main/java/org/horizon/loader/jdbc/binary/JdbcBinaryCacheStore.java	2009-03-05 13:47:19 UTC (rev 7857)
@@ -279,7 +279,7 @@
       }
    }
 
-   protected void purgeInternal() throws CacheLoaderException {
+   public void purgeInternal() throws CacheLoaderException {
       Connection conn = null;
       PreparedStatement ps = null;
       ResultSet rs = null;
@@ -416,7 +416,7 @@
     * 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.
+    * {@link org.horizon.loader.jdbc.mixed.JdbcMixedCacheStore} for such an example of this.
     */
    public void doConnectionFactoryInitialization(ConnectionFactory connectionFactory) throws CacheLoaderException {
       this.connectionFactory = connectionFactory;

Copied: core/branches/flat/src/main/java/org/horizon/loader/jdbc/mixed/JdbcMixedCacheStore.java (from rev 7854, core/branches/flat/src/main/java/org/horizon/loader/jdbc/JdbcCacheStore.java)
===================================================================
--- core/branches/flat/src/main/java/org/horizon/loader/jdbc/mixed/JdbcMixedCacheStore.java	                        (rev 0)
+++ core/branches/flat/src/main/java/org/horizon/loader/jdbc/mixed/JdbcMixedCacheStore.java	2009-03-05 13:47:19 UTC (rev 7857)
@@ -0,0 +1,130 @@
+package org.horizon.loader.jdbc.mixed;
+
+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;
+
+/**
+ * Cache store that combines functionality of {@link JdbcBinaryCacheStore} and {@link JdbcStringBasedCacheStore}. It
+ * aggregates an instance of JdbcBinaryCacheStore and JdbcStringBasedCacheStore, delegating work to one of them
+ * (sometimes both, see below) based on the passed in key. In order to determine which store to use it will rely on the
+ * configured {@link org.horizon.loader.jdbc.stringbased.Key2StringMapper} )(see configuration).
+ * <p/>
+ * The advantage it brings is the possibility of effeciently storing string(able) keyd {@link
+ * org.horizon.loader.StoredEntry}s, and at the same time being able to store any other keys, a la {@link
+ * org.horizon.loader.jdbc.binary.JdbcBinaryCacheStore}.
+ * <p/>
+ * There will only be a performance cost for the aggregate operations: loadAll, fromStream, toStream and clear. For
+ * these operations there will be two distinct database call, one for each JdbcStore implementation. Most of application
+ * are only using these operations at lifecycles changes (e.g. fromStram and toStream at cluster join time, loadAll at
+ * startup for warm caches), so performance drawback shouldn't be significant (again, most of the cases).
+ * <p/>
+ * Resource sharing - both aggregated cache loaders have locks and connection pools. The locking is not shared, each
+ * loader keeping its own {@link org.horizon.lock.StripedLock} instace. Also the tables (even though similar as
+ * definition) are different in order to avoid key collision. On the other hand, the connection pooling is a shared
+ * resource.
+ *
+ * @author Mircea.Markus at jboss.com
+ * @see org.horizon.loader.jdbc.mixed.JdbcMixedCacheStoreConfig
+ * @see org.horizon.loader.jdbc.binary.JdbcBinaryCacheStore
+ * @see org.horizon.loader.jdbc.stringbased.JdbcStringBasedCacheStore
+ */
+public class JdbcMixedCacheStore extends AbstractCacheStore {
+
+   private JdbcMixedCacheStoreConfig 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 = (JdbcMixedCacheStoreConfig) 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.purgeInternal();
+      stringBasedCacheStore.purgeInternal();
+   }
+
+   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 JdbcMixedCacheStoreConfig.class;
+   }
+
+   private CacheStore getCacheStore(Object key) {
+      return stringBasedCacheStore.supportsKey(key.getClass()) ? stringBasedCacheStore : binaryCacheStore;
+   }
+
+   public ConnectionFactory getConnectionFactory() {
+      return sharedConnectionFactory;
+   }
+}


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

Copied: core/branches/flat/src/main/java/org/horizon/loader/jdbc/mixed/JdbcMixedCacheStoreConfig.java (from rev 7854, core/branches/flat/src/main/java/org/horizon/loader/jdbc/JdbcCacheStoreConfig.java)
===================================================================
--- core/branches/flat/src/main/java/org/horizon/loader/jdbc/mixed/JdbcMixedCacheStoreConfig.java	                        (rev 0)
+++ core/branches/flat/src/main/java/org/horizon/loader/jdbc/mixed/JdbcMixedCacheStoreConfig.java	2009-03-05 13:47:19 UTC (rev 7857)
@@ -0,0 +1,182 @@
+package org.horizon.loader.jdbc.mixed;
+
+import org.horizon.loader.AbstractCacheStoreConfig;
+import org.horizon.loader.LockSupportCacheStoreConfig;
+import org.horizon.loader.jdbc.binary.JdbcBinaryCacheStoreConfig;
+import org.horizon.loader.jdbc.connectionfactory.ConnectionFactoryConfig;
+import org.horizon.loader.jdbc.stringbased.JdbcStringBasedCacheStoreConfig;
+import org.horizon.loader.jdbc.TableManipulation;
+
+/**
+ * Configureation for {@link org.horizon.loader.jdbc.mixed.JdbcMixedCacheStore}.
+ *
+ * @author Mircea.Markus at jboss.com
+ */
+public class JdbcMixedCacheStoreConfig extends AbstractCacheStoreConfig {
+
+   private ConnectionFactoryConfig connectionFactoryConfig = new ConnectionFactoryConfig();
+   private TableManipulation binaryTableManipulation = new TableManipulation();
+   private TableManipulation stringsTableManipulation = new TableManipulation();
+   private String key2StringMapper;
+   private int binaryConcurrencyLevel = LockSupportCacheStoreConfig.DEFAULT_CONCURRENCY_LEVEL / 2;
+   private int stringsConcurrencyLevel = LockSupportCacheStoreConfig.DEFAULT_CONCURRENCY_LEVEL / 2;
+   private int lockAcquistionTimeout = LockSupportCacheStoreConfig.DEFAULT_LOCK_ACQUISITION_TIMEOUT;
+
+
+   public JdbcMixedCacheStoreConfig(ConnectionFactoryConfig connectionFactoryConfig, TableManipulation binaryTableManipulation, TableManipulation stringsTableManipulation) {
+      this.connectionFactoryConfig = connectionFactoryConfig;
+      this.binaryTableManipulation = binaryTableManipulation;
+      this.stringsTableManipulation = stringsTableManipulation;
+   }
+
+   public JdbcMixedCacheStoreConfig() {
+      this.className = JdbcMixedCacheStore.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);
+      cacheStoreConfig.setPurgeSynchronously(true);//just to make sure we don't create another thread
+      cacheStoreConfig.setLockConcurrencyLevel(binaryConcurrencyLevel);
+      cacheStoreConfig.setLockAcquistionTimeout(lockAcquistionTimeout);
+      return cacheStoreConfig;
+   }
+
+   JdbcStringBasedCacheStoreConfig getStringCacheStoreConfig() {
+      JdbcStringBasedCacheStoreConfig config = new JdbcStringBasedCacheStoreConfig(false);
+      config.setTableManipulation(stringsTableManipulation);
+      config.setPurgeSynchronously(true); //just to make sure we don't create another thread
+      config.setLockConcurrencyLevel(stringsConcurrencyLevel);
+      config.setLockAcquistionTimeout(lockAcquistionTimeout);
+      if (key2StringMapper != null) config.setKey2StringMapperClass(key2StringMapper);
+      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) {
+      if (tableNameForStrings == null) throw new IllegalArgumentException("Null table name not allowed.");
+      if (tableNameForStrings.equals(this.binaryTableManipulation.getTableName())) {
+         throw new IllegalArgumentException("Same table name is used for both cache loaders, this is not allowed!");
+      }
+      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) {
+      if (tableNameForBinary == null) throw new IllegalArgumentException("Null table name not allowed.");
+      if (tableNameForBinary.equals(this.stringsTableManipulation.getTableName())) {
+         throw new IllegalArgumentException("Same table name is used for both cache loaders, this is not allowed!");
+      }
+      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;
+   }
+
+   public void setKey2StringMapperClass(String name) {
+       this.key2StringMapper = name;
+   }
+
+   public void setLockConcurrencyLevelForStrings(int concurrencyLevel) {
+      this.stringsConcurrencyLevel = concurrencyLevel;
+   }
+
+   public void setLockConcurrencyLevelForBinary(int concurrencyLevel) {
+      this.binaryConcurrencyLevel = concurrencyLevel;
+   }
+
+   public void setLockAcquistionTimeout(int lockAcquistionTimeout) {
+      this.lockAcquistionTimeout = lockAcquistionTimeout;
+   }
+}


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

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-05 12:24:26 UTC (rev 7856)
+++ core/branches/flat/src/main/java/org/horizon/loader/jdbc/stringbased/JdbcStringBasedCacheStore.java	2009-03-05 13:47:19 UTC (rev 7857)
@@ -223,13 +223,14 @@
    }
 
    @Override
-   protected void purgeInternal() throws CacheLoaderException {
+   public void purgeInternal() throws CacheLoaderException {
       Connection conn = null;
       PreparedStatement ps = null;
       try {
          String sql = tableManipulation.getDeleteExpiredRowsSql();
          conn = connectionFactory.getConnection();
          ps = conn.prepareStatement(sql);
+         ps.setLong(1, System.currentTimeMillis());
          int result = ps.executeUpdate();
          if (log.isTraceEnabled())
             log.trace("Successfully purged " + result + " rows.");
@@ -319,7 +320,7 @@
     * 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.
+    * {@link org.horizon.loader.jdbc.mixed.JdbcMixedCacheStore} for such an example of this.
     */
    public void doConnectionFactoryInitialization(ConnectionFactory connectionFactory) throws CacheLoaderException {
       this.connectionFactory = connectionFactory;

Deleted: core/branches/flat/src/test/java/org/horizon/loader/jdbc/JdbcCacheStoreTest.java
===================================================================
--- core/branches/flat/src/test/java/org/horizon/loader/jdbc/JdbcCacheStoreTest.java	2009-03-05 12:24:26 UTC (rev 7856)
+++ core/branches/flat/src/test/java/org/horizon/loader/jdbc/JdbcCacheStoreTest.java	2009-03-05 13:47:19 UTC (rev 7857)
@@ -1,33 +0,0 @@
-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;
-   }
-}

Modified: core/branches/flat/src/test/java/org/horizon/loader/jdbc/UnitTestDatabaseManager.java
===================================================================
--- core/branches/flat/src/test/java/org/horizon/loader/jdbc/UnitTestDatabaseManager.java	2009-03-05 12:24:26 UTC (rev 7856)
+++ core/branches/flat/src/test/java/org/horizon/loader/jdbc/UnitTestDatabaseManager.java	2009-03-05 13:47:19 UTC (rev 7857)
@@ -2,6 +2,7 @@
 
 import org.horizon.loader.jdbc.connectionfactory.ConnectionFactoryConfig;
 import org.horizon.loader.jdbc.connectionfactory.PooledConnectionFactory;
+import org.horizon.loader.jdbc.connectionfactory.ConnectionFactory;
 import org.horizon.test.TestingUtil;
 
 import java.io.File;
@@ -9,6 +10,8 @@
 import java.sql.DriverManager;
 import java.sql.SQLException;
 import java.sql.Statement;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
 import java.util.Properties;
 import java.util.StringTokenizer;
 import java.util.concurrent.atomic.AtomicInteger;
@@ -118,4 +121,28 @@
       return new TableManipulation("ID_COLUMN", "VARCHAR(255)", "HORIZON_JDBC", "DATA_COLUMN",
                                    "BINARY", "TIMESTAMP_COLUMN", "BIGINT");
    }
+
+   /**
+    * Counts the number of rows in the given table.
+    */
+   public static int rowCount(ConnectionFactory connectionFactory, String tableName) {
+      Connection conn = null;
+      PreparedStatement statement = null;
+      ResultSet resultSet = null;
+      try {
+         conn = connectionFactory.getConnection();
+         String sql = "SELECT count(*) FROM " + tableName;
+         statement = conn.prepareStatement(sql);
+         resultSet = statement.executeQuery();
+         resultSet.next();
+         return resultSet.getInt(1);
+      } catch (Exception ex) {
+         throw new RuntimeException(ex);
+      }
+      finally {
+         JdbcUtil.safeClose(resultSet);
+         JdbcUtil.safeClose(statement);
+         connectionFactory.releaseConnection(conn);
+      }
+   }
 }

Added: core/branches/flat/src/test/java/org/horizon/loader/jdbc/mixed/JdbcMixedCacheStoreConfigTest.java
===================================================================
--- core/branches/flat/src/test/java/org/horizon/loader/jdbc/mixed/JdbcMixedCacheStoreConfigTest.java	                        (rev 0)
+++ core/branches/flat/src/test/java/org/horizon/loader/jdbc/mixed/JdbcMixedCacheStoreConfigTest.java	2009-03-05 13:47:19 UTC (rev 7857)
@@ -0,0 +1,90 @@
+package org.horizon.loader.jdbc.mixed;
+
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+import org.horizon.loader.jdbc.stringbased.PersonKey2StringMapper;
+import org.horizon.loader.LockSupportCacheStoreConfig;
+
+/**
+ * Tester class for {@link JdbcMixedCacheStoreConfig}.
+ *
+ * @author Mircea.Markus at jboss.com
+ */
+ at Test(groups = "unit", testName = "loader.jdbc.mixed.JdbcMixedCacheStoreConfigTest")
+public class JdbcMixedCacheStoreConfigTest {
+   private JdbcMixedCacheStoreConfig config;
+
+   @BeforeMethod
+   public void createConfig() {
+      config = new JdbcMixedCacheStoreConfig();
+   }
+
+   /**
+    * Just take some random props and check their corectness.
+    */
+   public void simpleTest() {
+      config = new JdbcMixedCacheStoreConfig();
+      config.setConnectionUrl("url");
+      config.setCreateTableOnStartForBinary(false);
+      config.setCreateTableOnStartForStrings(true);
+      config.setDataColumnNameForBinary("binary_dc");
+      config.setDataColumnNameForStrings("strings_dc");
+      config.setDataColumnTypeForBinary("binary_dct");
+      config.setDataColumnTypeForStrings("strings_dct");
+      config.setDriverClass("driver");
+
+      //some checks
+      assert !config.getBinaryCacheStoreConfig().getTableManipulation().isCreateTableOnStart();
+      assert config.getStringCacheStoreConfig().getTableManipulation().isCreateTableOnStart();
+      assert config.getConnectionFactoryConfig().getDriverClass().equals("driver");
+      assert config.getBinaryCacheStoreConfig().getTableManipulation().getDataColumnName().equals("binary_dc");
+      assert config.getBinaryCacheStoreConfig().getTableManipulation().getDataColumnType().equals("binary_dct");
+      assert config.getStringCacheStoreConfig().getTableManipulation().getDataColumnName().equals("strings_dc");
+      assert config.getStringCacheStoreConfig().getTableManipulation().getDataColumnType().equals("strings_dct");
+   }
+
+   public void testSameTableName() {
+      config.setTableNameForBinary("table");
+      try {
+         config.setTableNameForStrings("table");
+         assert false: "expection expected as same table name is not allowed for both cache stores";
+      } catch (Exception e) {
+         //expected
+      }
+      //and the other way around
+      config.setTableNameForStrings("table2");
+      try {
+         config.setTableNameForBinary("table2");
+         assert false: "expection expected as same table name is not allowed for both cache stores";
+      } catch (Exception e) {
+         //expected
+      }
+   }
+
+   public void testKey2StringMapper() {
+      config.setKey2StringMapperClass(PersonKey2StringMapper.class.getName());
+      assert config.getStringCacheStoreConfig().getKey2StringMapper().getClass().equals(PersonKey2StringMapper.class);
+   }
+
+   public void testConcurrencyLevel() {
+      assert config.getStringCacheStoreConfig().getLockConcurrencyLevel() == LockSupportCacheStoreConfig.DEFAULT_CONCURRENCY_LEVEL / 2;
+      assert config.getBinaryCacheStoreConfig().getLockConcurrencyLevel() == LockSupportCacheStoreConfig.DEFAULT_CONCURRENCY_LEVEL / 2;
+      config.setLockConcurrencyLevelForStrings(11);
+      config.setLockConcurrencyLevelForBinary(12);
+      assert config.getStringCacheStoreConfig().getLockConcurrencyLevel() == 11;
+      assert config.getBinaryCacheStoreConfig().getLockConcurrencyLevel() == 12;
+   }
+
+   public void testEnforcedSyncPurging() {
+      assert config.getBinaryCacheStoreConfig().isPurgeSynchronously();
+      assert config.getStringCacheStoreConfig().isPurgeSynchronously();
+   }
+
+   public void voidTestLockAquisitionTimeout() {
+      assert config.getStringCacheStoreConfig().getLockAcquistionTimeout() == LockSupportCacheStoreConfig.DEFAULT_LOCK_ACQUISITION_TIMEOUT;
+      assert config.getBinaryCacheStoreConfig().getLockAcquistionTimeout() == LockSupportCacheStoreConfig.DEFAULT_LOCK_ACQUISITION_TIMEOUT;
+      config.setLockAcquistionTimeout(13);
+      assert config.getStringCacheStoreConfig().getLockAcquistionTimeout() == 13;
+      assert config.getBinaryCacheStoreConfig().getLockAcquistionTimeout() == 13;
+   }
+}


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

Added: core/branches/flat/src/test/java/org/horizon/loader/jdbc/mixed/JdbcMixedCacheStoreTest.java
===================================================================
--- core/branches/flat/src/test/java/org/horizon/loader/jdbc/mixed/JdbcMixedCacheStoreTest.java	                        (rev 0)
+++ core/branches/flat/src/test/java/org/horizon/loader/jdbc/mixed/JdbcMixedCacheStoreTest.java	2009-03-05 13:47:19 UTC (rev 7857)
@@ -0,0 +1,193 @@
+package org.horizon.loader.jdbc.mixed;
+
+import org.horizon.loader.CacheLoaderException;
+import org.horizon.loader.CacheStore;
+import org.horizon.loader.StoredEntry;
+import org.horizon.loader.jdbc.TableManipulation;
+import org.horizon.loader.jdbc.UnitTestDatabaseManager;
+import org.horizon.loader.jdbc.connectionfactory.ConnectionFactory;
+import org.horizon.loader.jdbc.connectionfactory.ConnectionFactoryConfig;
+import org.horizon.loader.jdbc.stringbased.DefaultKey2StringMapper;
+import org.horizon.loader.jdbc.stringbased.Person;
+import org.horizon.marshall.ObjectStreamMarshaller;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.AfterTest;
+import org.testng.annotations.BeforeTest;
+import org.testng.annotations.Test;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.util.Set;
+
+/**
+ * Tester class for {@link JdbcMixedCacheStore}
+ *
+ * @author Mircea.Markus at jboss.com
+ */
+ at Test(groups = "functional", testName = "loader.jdbc.JdbcMixedCacheStoreTest")
+public class JdbcMixedCacheStoreTest {
+
+   private CacheStore cacheStore;
+   private TableManipulation stringsTm;
+   private TableManipulation binaryTm;
+   private ConnectionFactoryConfig cfc;
+
+   private static final Person MIRCEA = new Person("Mircea", "Markus", 28);
+   private static final Person MANIK = new Person("Manik", "Surtani", 18);
+
+
+   @BeforeTest
+   public void createCacheStore() throws CacheLoaderException {
+      stringsTm = UnitTestDatabaseManager.buildDefaultTableManipulation();
+      stringsTm.setTableName("STRINGS_TABLE");
+      binaryTm = UnitTestDatabaseManager.buildDefaultTableManipulation();
+      binaryTm.setTableName("BINARY_TABLE");
+      cfc = UnitTestDatabaseManager.getUniqueConnectionFactoryConfig();
+      JdbcMixedCacheStoreConfig cacheStoreConfig = new JdbcMixedCacheStoreConfig(cfc, binaryTm, stringsTm);
+      cacheStoreConfig.setPurgeSynchronously(true);
+
+      cacheStoreConfig.setKey2StringMapperClass(DefaultKey2StringMapper.class.getName());
+      cacheStore = new JdbcMixedCacheStore();
+      cacheStore.init(cacheStoreConfig, null, new ObjectStreamMarshaller());
+      cacheStore.start();
+   }
+
+   @AfterMethod
+   public void clearStore() throws Exception {
+      cacheStore.clear();
+      assertBinaryRowCount(0);
+      assertStringsRowCount(0);
+   }
+
+   @AfterTest
+   public void destroyStore() throws CacheLoaderException {
+      cacheStore.stop();
+      UnitTestDatabaseManager.shutdownInMemoryDatabase(cfc);
+   }
+
+   public void testMixedStore() throws Exception {
+      cacheStore.store(new StoredEntry("String", "someValue"));
+      assertStringsRowCount(1);
+      assertBinaryRowCount(0);
+      cacheStore.store(new StoredEntry(MIRCEA, "value"));
+      assertStringsRowCount(1);
+      assertStringsRowCount(1);
+      assert cacheStore.load(MIRCEA).getValue().equals("value");
+      assert cacheStore.load("String").getValue().equals("someValue");
+   }
+
+   public void testMultipleEntriesWithSameHashCode() throws Exception {
+      Person one = new Person("Mircea", "Markus", 28);
+      Person two = new Person("Manik", "Surtani", 28);
+      one.setHashCode(100);
+      two.setHashCode(100);
+      cacheStore.store(new StoredEntry(one, "value"));
+      assertBinaryRowCount(1);
+      assertStringsRowCount(0);
+      cacheStore.store(new StoredEntry(two, "otherValue"));
+      assertBinaryRowCount(1); //both go to same bucket
+      assertStringsRowCount(0);
+      assert cacheStore.load(one).getValue().equals("value");
+      assert cacheStore.load(two).getValue().equals("otherValue");
+   }
+
+   public void testClear() throws Exception {
+      cacheStore.store(new StoredEntry("String", "someValue"));
+      assertRowCounts(0, 1);
+      cacheStore.store(new StoredEntry(MIRCEA, "value"));
+      assertRowCounts(1, 1);
+      cacheStore.clear();
+      assertRowCounts(0,0);
+   }
+
+   public void testMixedFromAndToStream() throws Exception {
+      cacheStore.store(new StoredEntry("String", "someValue"));
+      cacheStore.store(new StoredEntry("String2", "someValue"));
+      cacheStore.store(new StoredEntry(MIRCEA, "value1"));
+      cacheStore.store(new StoredEntry(MANIK, "value2"));
+      assertRowCounts(2,2);
+      ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
+      ObjectOutputStream objectOutputStream = new ObjectOutputStream(byteArrayOutputStream);
+      cacheStore.toStream(objectOutputStream);
+      cacheStore.clear();
+      assertRowCounts(0,0);
+      cacheStore.fromStream(new ObjectInputStream(new ByteArrayInputStream(byteArrayOutputStream.toByteArray())));
+      assertRowCounts(2,2);
+      assert cacheStore.load("String").getValue().equals("someValue");
+      assert cacheStore.load("String2").getValue().equals("someValue");
+      assert cacheStore.load(MIRCEA).getValue().equals("value1");
+      assert cacheStore.load(MANIK).getValue().equals("value2");
+   }
+
+   public void testLoadAll() throws Exception {
+      StoredEntry first = new StoredEntry("String", "someValue");
+      StoredEntry second = new StoredEntry("String2", "someValue");
+      StoredEntry third = new StoredEntry(MIRCEA, "value1");
+      StoredEntry forth = new StoredEntry(MANIK, "value2");
+      cacheStore.store(first);
+      cacheStore.store(second);
+      cacheStore.store(third);
+      cacheStore.store(forth);
+      assertRowCounts(2,2);
+      Set<StoredEntry> entries = cacheStore.loadAll();
+      assert entries.size() == 4;
+      assert entries.contains(first);
+      assert entries.contains(second);
+      assert entries.contains(third);
+      assert entries.contains(forth);
+   }
+
+   public void testPurgeExpired() throws Exception {
+      StoredEntry first = new StoredEntry("String", "someValue", 1000);
+      StoredEntry second = new StoredEntry(MIRCEA, "value1", 1000);
+      cacheStore.store(first);
+      cacheStore.store(second);
+      assertRowCounts(1,1);
+      Thread.sleep(1200);
+      cacheStore.purgeExpired();
+      assertRowCounts(0,0);
+   }
+
+   public void testPurgeExpiredWithRemainingEntries() throws Exception {
+      StoredEntry first = new StoredEntry("String", "someValue", 1000);
+      StoredEntry second = new StoredEntry("String2", "someValue");
+      StoredEntry third = new StoredEntry(MIRCEA, "value1", 1000);
+      StoredEntry forth = new StoredEntry(MANIK, "value1");
+      cacheStore.store(first);
+      cacheStore.store(second);
+      cacheStore.store(third);
+      cacheStore.store(forth);
+      assertRowCounts(2,2);
+      Thread.sleep(1200);
+      cacheStore.purgeExpired();
+      assertRowCounts(1,1);
+   }
+
+   public void testTableConflict() {
+
+   }
+
+   private void assertRowCounts(int binary, int strings) {
+      assertBinaryRowCount(binary);
+      assertStringsRowCount(strings);
+   }
+
+   private void assertStringsRowCount(int rowCount) {
+      JdbcMixedCacheStore store = (JdbcMixedCacheStore) cacheStore;
+      ConnectionFactory connectionFactory = store.getConnectionFactory();
+      String tableName = stringsTm.getTableName();
+      int value = UnitTestDatabaseManager.rowCount(connectionFactory, tableName);
+      assert value == rowCount : "Expected " + rowCount + " rows, actual value is " + value;
+   }
+
+   private void assertBinaryRowCount(int rowCount) {
+      JdbcMixedCacheStore store = (JdbcMixedCacheStore) cacheStore;
+      ConnectionFactory connectionFactory = store.getConnectionFactory();
+      String tableName = binaryTm.getTableName();
+      int value = UnitTestDatabaseManager.rowCount(connectionFactory, tableName);
+      assert value == rowCount : "Expected " + rowCount + " rows, actual value is " + value;
+
+   }
+}


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

Copied: core/branches/flat/src/test/java/org/horizon/loader/jdbc/mixed/JdbcMixedCacheStoreTest2.java (from rev 7854, core/branches/flat/src/test/java/org/horizon/loader/jdbc/JdbcCacheStoreTest.java)
===================================================================
--- core/branches/flat/src/test/java/org/horizon/loader/jdbc/mixed/JdbcMixedCacheStoreTest2.java	                        (rev 0)
+++ core/branches/flat/src/test/java/org/horizon/loader/jdbc/mixed/JdbcMixedCacheStoreTest2.java	2009-03-05 13:47:19 UTC (rev 7857)
@@ -0,0 +1,35 @@
+package org.horizon.loader.jdbc.mixed;
+
+import org.horizon.loader.BaseCacheStoreTest;
+import org.horizon.loader.CacheStore;
+import org.horizon.loader.jdbc.TableManipulation;
+import org.horizon.loader.jdbc.UnitTestDatabaseManager;
+import org.horizon.loader.jdbc.connectionfactory.ConnectionFactoryConfig;
+import org.testng.annotations.Test;
+
+/**
+ * // TODO: Mircea: Document this!
+ *
+ * @author
+ */
+ at Test(groups = "functional", testName = "loader.jdbc.JdbcMixedCacheStoreTest2")
+public class JdbcMixedCacheStoreTest2 extends BaseCacheStoreTest {
+
+   protected CacheStore createCacheStore() throws Exception {
+      JdbcMixedCacheStoreConfig jdbcCacheStoreConfig = new JdbcMixedCacheStoreConfig();
+      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);
+
+      JdbcMixedCacheStore cacheStore = new JdbcMixedCacheStore();
+      cacheStore.init(jdbcCacheStoreConfig, null, getMarshaller());
+      cacheStore.start();
+      return cacheStore;
+   }
+}


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

Modified: core/branches/flat/src/test/java/org/horizon/loader/jdbc/stringbased/JdbcStringBasedCacheStoreTest2.java
===================================================================
--- core/branches/flat/src/test/java/org/horizon/loader/jdbc/stringbased/JdbcStringBasedCacheStoreTest2.java	2009-03-05 12:24:26 UTC (rev 7856)
+++ core/branches/flat/src/test/java/org/horizon/loader/jdbc/stringbased/JdbcStringBasedCacheStoreTest2.java	2009-03-05 13:47:19 UTC (rev 7857)
@@ -3,9 +3,9 @@
 import org.horizon.loader.CacheLoaderException;
 import org.horizon.loader.CacheStore;
 import org.horizon.loader.StoredEntry;
-import org.horizon.loader.jdbc.JdbcUtil;
 import org.horizon.loader.jdbc.TableManipulation;
 import org.horizon.loader.jdbc.UnitTestDatabaseManager;
+import org.horizon.loader.jdbc.connectionfactory.ConnectionFactory;
 import org.horizon.loader.jdbc.connectionfactory.ConnectionFactoryConfig;
 import org.horizon.marshall.ObjectStreamMarshaller;
 import org.testng.annotations.AfterMethod;
@@ -13,12 +13,9 @@
 import org.testng.annotations.BeforeTest;
 import org.testng.annotations.Test;
 
-import java.sql.Connection;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
 import java.util.Collections;
+import java.util.HashSet;
 import java.util.Set;
-import java.util.HashSet;
 
 /**
  * Tester for {@link JdbcStringBasedCacheStore} with an alternative {@link org.horizon.loader.jdbc.stringbased.Key2StringMapper}.
@@ -40,6 +37,7 @@
       cfc = UnitTestDatabaseManager.getUniqueConnectionFactoryConfig();
       JdbcStringBasedCacheStoreConfig config = new JdbcStringBasedCacheStoreConfig(cfc, tableManipulation);
       config.setKey2StringMapperClass(PersonKey2StringMapper.class.getName());
+      config.setPurgeSynchronously(true);
       cacheStore = new JdbcStringBasedCacheStore();
       cacheStore.init(config, null, new ObjectStreamMarshaller());
       cacheStore.start();
@@ -111,27 +109,38 @@
       assert rowCount() == 0;
    }
 
+   public void testPurgeExpired() throws Exception {
+      StoredEntry first = new StoredEntry(MIRCEA, "val",1000);
+      StoredEntry second = new StoredEntry(MANIK, "val2");
+      cacheStore.store(first);
+      cacheStore.store(second);
+      assert rowCount() == 2;
+      Thread.sleep(1100);
+//      printTableContent();
+      cacheStore.purgeExpired();
+      assert rowCount() == 1;
+      assert cacheStore.load(MANIK).getValue().equals("val2");
+   }
+
+//   private void printTableContent() throws Exception {
+//      String sql = "SELECT TIMESTAMP_COLUMN FROM HORIZON_JDBC";
+//      ConnectionFactory connectionFactory = getConnection();
+//      Connection conn = connectionFactory.getConnection();
+//      ResultSet rs = conn.createStatement().executeQuery(sql);
+//      while (rs.next()) {
+//         System.out.println(rs.getLong(1));
+//      }
+//   }
+
    private int rowCount() {
+      ConnectionFactory connectionFactory = getConnection();
+      String tableName = tableManipulation.getTableName();
+      return UnitTestDatabaseManager.rowCount(connectionFactory, tableName);
+   }
+
+   private ConnectionFactory getConnection() {
       JdbcStringBasedCacheStore store = (JdbcStringBasedCacheStore) cacheStore;
-      Connection conn = null;
-      PreparedStatement statement = null;
-      ResultSet resultSet = null;
-      try {
-         conn = store.getConnectionFactory().getConnection();
-         String tableName = tableManipulation.getTableName();
-         String sql = "SELECT count(*) FROM " + tableName;
-         statement = conn.prepareStatement(sql);
-         resultSet = statement.executeQuery();
-         resultSet.next();
-         return resultSet.getInt(1);
-      } catch (Exception ex) {
-         throw new RuntimeException(ex);
-      }
-      finally {
-         JdbcUtil.safeClose(resultSet);
-         JdbcUtil.safeClose(statement);
-         store.getConnectionFactory().releaseConnection(conn);
-      }
+      return store.getConnectionFactory();
    }
 
    private StoredEntry newStoredEntry(Object key, Object value) {

Modified: core/branches/flat/src/test/java/org/horizon/loader/jdbc/stringbased/Person.java
===================================================================
--- core/branches/flat/src/test/java/org/horizon/loader/jdbc/stringbased/Person.java	2009-03-05 12:24:26 UTC (rev 7856)
+++ core/branches/flat/src/test/java/org/horizon/loader/jdbc/stringbased/Person.java	2009-03-05 13:47:19 UTC (rev 7857)
@@ -11,6 +11,7 @@
    private String name;
    private String surname;
    private int age;
+   private int hashCode = -1;
 
    public Person(String name, String surname, int age) {
       this.name = name;
@@ -30,6 +31,10 @@
       return age;
    }
 
+   public void setHashCode(int hashCode) {
+      this.hashCode = hashCode;
+   }
+
    @Override
    public boolean equals(Object o) {
       if (this == o) return true;
@@ -46,6 +51,9 @@
 
    @Override
    public int hashCode() {
+      if (hashCode != -1) {
+         return hashCode;
+      }
       int result = name != null ? name.hashCode() : 0;
       result = 31 * result + (surname != null ? surname.hashCode() : 0);
       result = 31 * result + age;




More information about the jbosscache-commits mailing list