[infinispan-commits] Infinispan SVN: r1949 - branches/4.1.x/cachestore/jdbc/src/main/java/org/infinispan/loaders/jdbc.

infinispan-commits at lists.jboss.org infinispan-commits at lists.jboss.org
Thu Jul 1 07:52:46 EDT 2010


Author: manik.surtani at jboss.com
Date: 2010-07-01 07:52:46 -0400 (Thu, 01 Jul 2010)
New Revision: 1949

Added:
   branches/4.1.x/cachestore/jdbc/src/main/java/org/infinispan/loaders/jdbc/AbstractJdbcCacheStoreConfig.java
   branches/4.1.x/cachestore/jdbc/src/main/java/org/infinispan/loaders/jdbc/AbstractNonDelegatingJdbcCacheStoreConfig.java
Log:
[ISPN-368] (Remove code duplication in certain JDBC configuration classes)

Added: branches/4.1.x/cachestore/jdbc/src/main/java/org/infinispan/loaders/jdbc/AbstractJdbcCacheStoreConfig.java
===================================================================
--- branches/4.1.x/cachestore/jdbc/src/main/java/org/infinispan/loaders/jdbc/AbstractJdbcCacheStoreConfig.java	                        (rev 0)
+++ branches/4.1.x/cachestore/jdbc/src/main/java/org/infinispan/loaders/jdbc/AbstractJdbcCacheStoreConfig.java	2010-07-01 11:52:46 UTC (rev 1949)
@@ -0,0 +1,70 @@
+package org.infinispan.loaders.jdbc;
+
+import org.infinispan.loaders.AbstractCacheStoreConfig;
+import org.infinispan.loaders.LockSupportCacheStoreConfig;
+import org.infinispan.loaders.jdbc.connectionfactory.ConnectionFactoryConfig;
+
+/**
+ * This is an abstract configuration class containing common elements for all JDBC cache store types.
+ *
+ * @author Manik Surtani
+ * @version 4.1
+ */
+public abstract class AbstractJdbcCacheStoreConfig extends LockSupportCacheStoreConfig {
+
+   protected ConnectionFactoryConfig connectionFactoryConfig = new ConnectionFactoryConfig();
+
+   public void setConnectionFactoryClass(String connectionFactoryClass) {
+      testImmutability("connectionFactoryConfig");
+      this.connectionFactoryConfig.setConnectionFactoryClass(connectionFactoryClass);
+   }
+
+   public ConnectionFactoryConfig getConnectionFactoryConfig() {
+      return connectionFactoryConfig;
+   }
+
+   /**
+    * Jdbc connection string for connecting to the database. Mandatory.
+    */
+   public void setConnectionUrl(String connectionUrl) {
+      testImmutability("connectionFactoryConfig");
+      this.connectionFactoryConfig.setConnectionUrl(connectionUrl);
+   }
+
+   /**
+    * Database username.
+    */
+   public void setUserName(String userName) {
+      testImmutability("connectionFactoryConfig");
+      this.connectionFactoryConfig.setUserName(userName);
+   }
+
+   public void setDatasourceJndiLocation(String location) {
+      testImmutability("datasourceJndiLocation");
+      this.connectionFactoryConfig.setDatasourceJndiLocation(location);
+   }
+
+   /**
+    * Database username's password.
+    */
+   public void setPassword(String password) {
+      testImmutability("connectionFactoryConfig");
+      this.connectionFactoryConfig.setPassword(password);
+   }
+
+   /**
+    * 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) {
+      testImmutability("connectionFactoryConfig");
+      this.connectionFactoryConfig.setDriverClass(driverClassName);
+   }
+
+   @Override
+   public AbstractJdbcCacheStoreConfig clone() {
+      AbstractJdbcCacheStoreConfig result = (AbstractJdbcCacheStoreConfig) super.clone();
+      result.connectionFactoryConfig = connectionFactoryConfig.clone();
+      return result;
+   }
+}


Property changes on: branches/4.1.x/cachestore/jdbc/src/main/java/org/infinispan/loaders/jdbc/AbstractJdbcCacheStoreConfig.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF

Added: branches/4.1.x/cachestore/jdbc/src/main/java/org/infinispan/loaders/jdbc/AbstractNonDelegatingJdbcCacheStoreConfig.java
===================================================================
--- branches/4.1.x/cachestore/jdbc/src/main/java/org/infinispan/loaders/jdbc/AbstractNonDelegatingJdbcCacheStoreConfig.java	                        (rev 0)
+++ branches/4.1.x/cachestore/jdbc/src/main/java/org/infinispan/loaders/jdbc/AbstractNonDelegatingJdbcCacheStoreConfig.java	2010-07-01 11:52:46 UTC (rev 1949)
@@ -0,0 +1,164 @@
+package org.infinispan.loaders.jdbc;
+
+import org.infinispan.loaders.LockSupportCacheStoreConfig;
+
+/**
+ * An abstract configuration for JDBC cache stores which have support for locking.
+ *
+ * @author Manik Surtani
+ * @version 4.1
+ */
+public abstract class AbstractNonDelegatingJdbcCacheStoreConfig extends AbstractJdbcCacheStoreConfig {
+   private static final long serialVersionUID = 842757200078048889L;
+
+   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;
+
+   protected TableManipulation tableManipulation = new TableManipulation();
+   protected boolean manageConnectionFactory = true;
+
+   /**
+    * Sets the name of the table where data will be stored.
+    */
+   public void setCacheName(String cacheName) {
+      testImmutability("tableManipulation");
+      this.tableManipulation.setCacheName(cacheName);
+   }
+
+   /**
+    * Sets the name of the column where the id will be stored. The id is obtained through:
+    * <pre>
+    *   key2StringMapper.getStringMapping(storedEntry.getKey());
+    * </pre>
+    * Mandatory.
+    */
+   public void setIdColumnName(String idColumnName) {
+      testImmutability("tableManipulation");
+      this.tableManipulation.setIdColumnName(idColumnName);
+   }
+
+   /**
+    * Sets the name of the column where the StoredEntry will be binary stored. Mandatory.
+    */
+   public void setDataColumnName(String dataColumnName) {
+      testImmutability("tableManipulation");
+      this.tableManipulation.setDataColumnName(dataColumnName);
+   }
+
+   /**
+    * Sets the name of the column where the timestamp (Long in java) will be stored. Mandatory.
+    */
+   public void setTimestampColumnName(String timestampColumnName) {
+      testImmutability("tableManipulation");
+      this.tableManipulation.setTimestampColumnName(timestampColumnName);
+   }
+
+   /**
+    * Sets the prefix for the name of the table where the data will be stored. "_<cache name>" will be appended
+    * to this prefix in order to enforce unique table names for each cache.
+    */
+   public void setTimestampColumnType(String timestampColumnType) {
+      testImmutability("tableManipulation");
+      this.tableManipulation.setTimestampColumnType(timestampColumnType);
+   }
+
+   public TableManipulation getTableManipulation() {
+      return tableManipulation;
+   }
+
+   /**
+    * sql equivalent for java's String. Mandatory.
+    */
+   public void setIdColumnType(String idColumnType) {
+      testImmutability("tableManipulation");
+      this.tableManipulation.setIdColumnType(idColumnType);
+   }
+
+   /**
+    * Sets the type of the column where data will be binary stored. BLOB-like type, DBMS dependent. Mandatory.
+    */
+   public void setDataColumnType(String dataColumnType) {
+      testImmutability("tableManipulation");
+      this.tableManipulation.setDataColumnType(dataColumnType);
+   }
+
+   public void setDropTableOnExit(boolean dropTableOnExit) {
+      testImmutability("tableManipulation");
+      this.tableManipulation.setDropTableOnExit(dropTableOnExit);
+   }
+
+   public void setCreateTableOnStart(boolean createTableOnStart) {
+      testImmutability("tableManipulation");
+      this.tableManipulation.setCreateTableOnStart(createTableOnStart);
+   }
+
+   /**
+    * If this method returns false, then the connection factory should not be created by the {@link
+    * org.infinispan.loaders.jdbc.stringbased.JdbcStringBasedCacheStore}, but will be injected through {@link
+    * org.infinispan.loaders.jdbc.stringbased.JdbcStringBasedCacheStore#doConnectionFactoryInitialization(org.infinispan.loaders.jdbc.connectionfactory.ConnectionFactory)}
+    */
+   public boolean isManageConnectionFactory() {
+      return manageConnectionFactory;
+   }
+
+   public void setTableManipulation(TableManipulation tableManipulation) {
+      testImmutability("tableManipulation");
+      this.tableManipulation = tableManipulation;
+   }
+
+   /**
+    * @see org.infinispan.loaders.jdbc.TableManipulation#getFetchSize()
+    */
+   public void setFetchSize(int fetchSize) {
+      testImmutability("tableManipulation");
+      this.tableManipulation.setFetchSize(fetchSize);
+   }
+
+   /**
+    * @see org.infinispan.loaders.jdbc.TableManipulation#getBatchSize()
+    */
+   public void setBatchSize(int batchSize) {
+      testImmutability("tableManipulation");
+      this.tableManipulation.setBatchSize(batchSize);
+   }
+
+   /**
+    * @see org.infinispan.loaders.jdbc.TableManipulation#getFetchSize()
+    */
+   public int getFetchSize() {
+      return this.tableManipulation.getFetchSize();
+   }
+
+   /**
+    * @see org.infinispan.loaders.jdbc.TableManipulation#getBatchSize()
+    */
+   public int getBatchSize() {
+      return this.tableManipulation.getBatchSize();
+   }
+
+   public String getDatabaseType() {
+      return this.tableManipulation.databaseType == null ? "" : this.tableManipulation.databaseType.toString();
+   }
+
+   /**
+    * Sets the database dialect.  Valid types are reflected in the DatabaseType enum.  If unspecified, will attempt to
+    * "guess" appropriate dialect from the JDBC driver specified.
+    *
+    * @param dbType
+    */
+   public void setDatabaseType(String dbType) {
+      if (dbType != null)
+         this.tableManipulation.databaseType = DatabaseType.valueOf(dbType.toUpperCase().trim());
+   }
+
+
+   @Override
+   public AbstractNonDelegatingJdbcCacheStoreConfig clone() {
+      AbstractNonDelegatingJdbcCacheStoreConfig result = (AbstractNonDelegatingJdbcCacheStoreConfig) super.clone();
+      result.tableManipulation = tableManipulation.clone();
+      return result;
+   }
+}


Property changes on: branches/4.1.x/cachestore/jdbc/src/main/java/org/infinispan/loaders/jdbc/AbstractNonDelegatingJdbcCacheStoreConfig.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF



More information about the infinispan-commits mailing list