Author: asmuts Date: Fri Dec 5 12:06:25 2008 New Revision: 723841 URL: http://svn.apache.org/viewvc?rev=723841&view=rev Log: Fixed a bug in the MySQL Table Optimizer. It was unable to get a connection to the database when the disk cache was configured to use a shared pool.
Added: jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/jdbc/JDBCDiskCachePoolAccessFactory.java Modified: jakarta/jcs/trunk/src/java/org/apache/jcs/access/CacheAccess.java jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/AbstractDiskCache.java jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/jdbc/JDBCDiskCache.java jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/jdbc/JDBCDiskCacheAttributes.java jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/jdbc/JDBCDiskCachePoolAccessAttributes.java jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/jdbc/JDBCDiskCachePoolAccessManager.java jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/jdbc/mysql/MySQLDiskCache.java jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/jdbc/mysql/MySQLDiskCacheFactory.java jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/jdbc/mysql/MySQLDiskCacheManager.java jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/jdbc/mysql/MySQLTableOptimizer.java jakarta/jcs/trunk/src/java/org/apache/jcs/engine/CacheEventQueue.java jakarta/jcs/trunk/src/java/org/apache/jcs/engine/CacheListeners.java jakarta/jcs/trunk/src/java/org/apache/jcs/engine/CacheWatchRepairable.java jakarta/jcs/trunk/src/java/org/apache/jcs/engine/control/CompositeCache.java jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/jdbc/mysql/MySQLTableOptimizerManualTester.java jakarta/jcs/trunk/xdocs/changes.xml Modified: jakarta/jcs/trunk/src/java/org/apache/jcs/access/CacheAccess.java URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/java/org/apache/jcs/access/CacheAccess.java?rev=723841&r1=723840&r2=723841&view=diff ============================================================================== --- jakarta/jcs/trunk/src/java/org/apache/jcs/access/CacheAccess.java (original) +++ jakarta/jcs/trunk/src/java/org/apache/jcs/access/CacheAccess.java Fri Dec 5 12:06:25 2008 @@ -47,7 +47,7 @@ * An instance of this class is tied to a specific cache region. Static methods are provided to get * such instances. * <p> - * Using this class you can retrieve an item, the item's wrapper, the element configuration, put an + * Using this class you can retrieve an item, the item's wrapper, and the element's configuration. You can also put an * item in the cache, remove an item, and clear a region. * <p> * The JCS class is the preferred way to access these methods. @@ -58,9 +58,7 @@ /** The logger. */ private static final Log log = LogFactory.getLog( CacheAccess.class ); - /** - * Cache manager use by the various forms of defineRegion and getAccess - */ + /** Cache manager use by the various forms of defineRegion and getAccess */ private static CompositeCacheManager cacheMgr; /** @@ -280,7 +278,7 @@ * <p> * The last access time in the ElementAttributes should be current. * <p> - * @param pattern key search patern + * @param pattern key search pattern * @return a map of Object key to ICacheElement element, or empty map if no keys match the pattern */ public Map getMatchingCacheElements( String pattern ) @@ -326,7 +324,7 @@ } /** - * Constructs a cache element with these attribures, and puts it into the cache. + * Constructs a cache element with these attributes, and puts it into the cache. * <p> * If the key or the value is null, and InvalidArgumentException is thrown. * <p> @@ -363,7 +361,7 @@ } /** - * Destory the region and all objects within it. After calling this method, the Cache object can + * Destroy the region and all objects within it. After calling this method, the Cache object can * no longer be used as it will be closed. * <p> * @exception CacheException @@ -440,14 +438,14 @@ /** * ResetAttributes allows for some of the attributes of a region to be reset in particular - * expiration time attriubtes, time to live, default time to live and idle time, and event + * expiration time attributes, time to live, default time to live and idle time, and event * handlers. Changing default settings on groups and regions will not affect existing objects. * Only object loaded after the reset will use the new defaults. If no name argument is * provided, the reset is applied to the region. * <p> * NOTE: this method is does not reset the attributes for items already in the cache. It could * potentially do this for items in memory, and maybe on disk (which would be slow) but not - * remote items. Rather than have unpredicatble behavior, this method just sets the default + * remote items. Rather than have unpredictable behavior, this method just sets the default * attributes. * <p> * TODO is should be renamed "setDefaultElementAttributes" @@ -467,7 +465,7 @@ /** * This method is does not reset the attributes for items already in the cache. It could * potentially do this for items in memory, and maybe on disk (which would be slow) but not - * remote items. Rather than have unpredicatble behavior, this method just sets the default + * remote items. Rather than have unpredictable behavior, this method just sets the default * attributes. Items subsequently put into the cache will use these defaults if they do not * specify specific attributes. * <p> Modified: jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/AbstractDiskCache.java URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/AbstractDiskCache.java?rev=723841&r1=723840&r2=723841&view=diff ============================================================================== --- jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/AbstractDiskCache.java (original) +++ jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/AbstractDiskCache.java Fri Dec 5 12:06:25 2008 @@ -496,7 +496,7 @@ } catch ( InterruptedException ex ) { - log.error( ex ); + log.error( "The Shutdown Spool Process was interrupted.", ex ); } log.info( "In dispose, destroying event queue." ); Modified: jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/jdbc/JDBCDiskCache.java URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/jdbc/JDBCDiskCache.java?rev=723841&r1=723840&r2=723841&view=diff ============================================================================== --- jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/jdbc/JDBCDiskCache.java (original) +++ jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/jdbc/JDBCDiskCache.java Fri Dec 5 12:06:25 2008 @@ -135,7 +135,7 @@ } // This initializes the pool access. - initializePoolAccess( cattr, compositeCacheManager ); + setPoolAccess( initializePoolAccess( cattr, compositeCacheManager ) ); // Initialization finished successfully, so set alive to true. alive = true; @@ -151,6 +151,7 @@ protected JDBCDiskCachePoolAccess initializePoolAccess( JDBCDiskCacheAttributes cattr, ICompositeCacheManager compositeCacheManager ) { + JDBCDiskCachePoolAccess poolAccess = null; if ( cattr.getConnectionPoolName() != null ) { JDBCDiskCachePoolAccessManager manager = JDBCDiskCachePoolAccessManager.getInstance( compositeCacheManager @@ -161,22 +162,7 @@ { try { - try - { - // org.gjt.mm.mysql.Driver - Class.forName( cattr.getDriverClassName() ); - } - catch ( ClassNotFoundException e ) - { - log.error( "Couldn't find class for driver [" + cattr.getDriverClassName() + "]", e ); - } - - poolAccess = new JDBCDiskCachePoolAccess( cattr.getName() ); - - poolAccess.setupDriver( cattr.getUrl() + cattr.getDatabase(), cattr.getUserName(), cattr.getPassword(), - cattr.getMaxActive() ); - - poolAccess.logDriverStats(); + poolAccess = JDBCDiskCachePoolAccessFactory.createPoolAccess( cattr ); } catch ( Exception e ) { @@ -207,7 +193,7 @@ Connection con; try { - con = poolAccess.getConnection(); + con = getPoolAccess().getConnection(); } catch ( SQLException e ) { @@ -413,7 +399,7 @@ } catch ( SQLException e2 ) { - log.error( "e2 sql [" + sqlU + "] Exception: ", e2 ); + log.error( "e2 sql [" + sqlU + "] Exception: ", e2 ); } } @@ -430,7 +416,7 @@ Connection con; try { - con = poolAccess.getConnection(); + con = getPoolAccess().getConnection(); } catch ( SQLException e ) { @@ -525,7 +511,7 @@ String selectString = "select ELEMENT from " + getJdbcDiskCacheAttributes().getTableName() + " where REGION = ? and CACHE_KEY = ?"; - Connection con = poolAccess.getConnection(); + Connection con = getPoolAccess().getConnection(); try { PreparedStatement psSelect = null; @@ -630,7 +616,7 @@ String selectString = "select CACHE_KEY, ELEMENT from " + getJdbcDiskCacheAttributes().getTableName() + " where REGION = ? and CACHE_KEY like ?"; - Connection con = poolAccess.getConnection(); + Connection con = getPoolAccess().getConnection(); try { PreparedStatement psSelect = null; @@ -716,13 +702,13 @@ { pattern = pattern.replaceAll( "\\.\\+", "%" ); pattern = pattern.replaceAll( "\\.", "_" ); - + if ( log.isDebugEnabled() ) { log.debug( "pattern = [" + pattern + "]" ); } - - return pattern; + + return pattern; } /** @@ -748,7 +734,7 @@ + " where REGION = ? and CACHE_KEY like ?"; partial = true; } - Connection con = poolAccess.getConnection(); + Connection con = getPoolAccess().getConnection(); PreparedStatement psSelect = null; try { @@ -769,7 +755,7 @@ } catch ( SQLException e ) { - log.error( "Problem creating statement. sql [" + sql+ "]", e ); + log.error( "Problem creating statement. sql [" + sql + "]", e ); alive = false; } finally @@ -809,7 +795,7 @@ try { String sql = "delete from " + getJdbcDiskCacheAttributes().getTableName() + " where REGION = ?"; - Connection con = poolAccess.getConnection(); + Connection con = getPoolAccess().getConnection(); PreparedStatement psDelete = null; try { @@ -878,7 +864,7 @@ String sql = "delete from " + getJdbcDiskCacheAttributes().getTableName() + " where IS_ETERNAL = ? and REGION = ? and ? > SYSTEM_EXPIRE_TIME_SECONDS"; - Connection con = poolAccess.getConnection(); + Connection con = getPoolAccess().getConnection(); PreparedStatement psDelete = null; try { @@ -945,7 +931,7 @@ { try { - poolAccess.shutdownDriver(); + getPoolAccess().shutdownDriver(); } catch ( Exception e ) { @@ -974,7 +960,7 @@ Connection con; try { - con = poolAccess.getConnection(); + con = getPoolAccess().getConnection(); } catch ( SQLException e1 ) { @@ -1093,7 +1079,7 @@ { getMatchingCount++; } - + /** * @param jdbcDiskCacheAttributes The jdbcDiskCacheAttributes to set. */ @@ -1155,12 +1141,12 @@ se = new StatElement(); se.setName( "Active DB Connections" ); - se.setData( "" + poolAccess.getNumActiveInPool() ); + se.setData( "" + getPoolAccess().getNumActiveInPool() ); elems.add( se ); se = new StatElement(); se.setName( "Idle DB Connections" ); - se.setData( "" + poolAccess.getNumIdleInPool() ); + se.setData( "" + getPoolAccess().getNumIdleInPool() ); elems.add( se ); se = new StatElement(); @@ -1223,6 +1209,23 @@ } /** + * @param poolAccess the poolAccess to set + */ + protected void setPoolAccess( JDBCDiskCachePoolAccess poolAccess ) + { + this.poolAccess = poolAccess; + } + + /** + * Public so managers can access it. + * @return the poolAccess + */ + public JDBCDiskCachePoolAccess getPoolAccess() + { + return poolAccess; + } + + /** * For debugging. * <p> * @return this.getStats(); Modified: jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/jdbc/JDBCDiskCacheAttributes.java URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/jdbc/JDBCDiskCacheAttributes.java?rev=723841&r1=723840&r2=723841&view=diff ============================================================================== --- jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/jdbc/JDBCDiskCacheAttributes.java (original) +++ jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/jdbc/JDBCDiskCacheAttributes.java Fri Dec 5 12:06:25 2008 @@ -76,11 +76,11 @@ * separate section as follows. Assuming the name is "MyPool": * * <pre> - * jcs.connectionpool.MyPool.attributes.userName=MyUserName - * jcs.connectionpool.MyPool.attributes.password=MyPassword - * jcs.connectionpool.MyPool.attributes.url=MyUrl - * jcs.connectionpool.MyPool.attributes.maxActive=MyMaxActive - * jcs.connectionpool.MyPool.attributes.driverClassName=MyDriverClassName + * jcs.jdbcconnectionpool.MyPool.attributes.userName=MyUserName + * jcs.jdbcconnectionpool.MyPool.attributes.password=MyPassword + * jcs.jdbcconnectionpool.MyPool.attributes.url=MyUrl + * jcs.jdbcconnectionpool.MyPool.attributes.maxActive=MyMaxActive + * jcs.jdbcconnectionpool.MyPool.attributes.driverClassName=MyDriverClassName * </pre> */ private String connectionPoolName; @@ -184,7 +184,8 @@ /** * If this is true then the disk cache will check to see if the item already exists in the - * database. If it is false, it will try to insert. If the isnert fails it will try to update. + * database. If it is false, it will try to insert. If the insert fails it will try to update. + * <p> * @param testBeforeInsert The testBeforeInsert to set. */ public void setTestBeforeInsert( boolean testBeforeInsert ) Modified: jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/jdbc/JDBCDiskCachePoolAccessAttributes.java URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/jdbc/JDBCDiskCachePoolAccessAttributes.java?rev=723841&r1=723840&r2=723841&view=diff ============================================================================== --- jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/jdbc/JDBCDiskCachePoolAccessAttributes.java (original) +++ jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/jdbc/JDBCDiskCachePoolAccessAttributes.java Fri Dec 5 12:06:25 2008 @@ -150,6 +150,7 @@ buf.append( "\nJDBCDiskCachePoolAccessAttributes" ); buf.append( "\n UserName [" + getUserName() + "]" ); buf.append( "\n Url [" + getUrl() + "]" ); + buf.append( "\n PoolName [" + getPoolName() + "]" ); buf.append( "\n Database [" + getDatabase() + "]" ); buf.append( "\n DriverClassName [" + getDriverClassName() + "]" ); buf.append( "\n MaxActive [" + getMaxActive() + "]" ); Added: jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/jdbc/JDBCDiskCachePoolAccessFactory.java URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/jdbc/JDBCDiskCachePoolAccessFactory.java?rev=723841&view=auto ============================================================================== --- jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/jdbc/JDBCDiskCachePoolAccessFactory.java (added) +++ jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/jdbc/JDBCDiskCachePoolAccessFactory.java Fri Dec 5 12:06:25 2008 @@ -0,0 +1,85 @@ +package org.apache.jcs.auxiliary.disk.jdbc; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +/** This is just a helper util. */ +public class JDBCDiskCachePoolAccessFactory +{ + /** The local logger. */ + private final static Log log = LogFactory.getLog( JDBCDiskCachePoolAccessFactory.class ); + + /** + * Creates a JDBCDiskCachePoolAccess object from the JDBCDiskCachePoolAccessAttributes. This is + * used by the connection pool manager. + * <p> + * @param poolAttributes + * @return JDBCDiskCachePoolAccess + * @throws Exception + */ + public static JDBCDiskCachePoolAccess createPoolAccess( JDBCDiskCachePoolAccessAttributes poolAttributes ) + throws Exception + { + return createPoolAccess( poolAttributes.getDriverClassName(), poolAttributes.getPoolName(), poolAttributes + .getUrl() + + poolAttributes.getDatabase(), poolAttributes.getUserName(), poolAttributes.getPassword(), poolAttributes + .getMaxActive() ); + } + + /** + * Creates a JDBCDiskCachePoolAccess object from the JDBCDiskCacheAttributes. Use this when not + * using the connection pool manager. + * <p> + * @param cattr + * @return JDBCDiskCachePoolAccess + * @throws Exception + */ + public static JDBCDiskCachePoolAccess createPoolAccess( JDBCDiskCacheAttributes cattr ) + throws Exception + { + return createPoolAccess( cattr.getDriverClassName(), cattr.getName(), cattr.getUrl() + cattr.getDatabase(), + cattr.getUserName(), cattr.getPassword(), cattr.getMaxActive() ); + } + + /** + * Creates a pool access object and registers the driver. + * <p> + * @param driverClassName + * @param poolName + * @param fullURL = (url + database) + * @param userName + * @param password + * @param maxActive + * @return JDBCDiskCachePoolAccess + * @throws Exception + */ + public static JDBCDiskCachePoolAccess createPoolAccess( String driverClassName, String poolName, String fullURL, + String userName, String password, int maxActive ) + throws Exception + { + JDBCDiskCachePoolAccess poolAccess = null; + + try + { + // org.gjt.mm.mysql.Driver + Class.forName( driverClassName ); + } + catch ( ClassNotFoundException e ) + { + log.error( "Couldn't find class for driver [" + driverClassName + "]", e ); + } + + poolAccess = new JDBCDiskCachePoolAccess( poolName ); + + poolAccess.setupDriver( fullURL, userName, password, maxActive ); + + poolAccess.logDriverStats(); + + if ( log.isInfoEnabled() ) + { + log.info( "Created: " + poolAccess ); + } + + return poolAccess; + } +} Modified: jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/jdbc/JDBCDiskCachePoolAccessManager.java URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/jdbc/JDBCDiskCachePoolAccessManager.java?rev=723841&r1=723840&r2=723841&view=diff ============================================================================== --- jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/jdbc/JDBCDiskCachePoolAccessManager.java (original) +++ jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/jdbc/JDBCDiskCachePoolAccessManager.java Fri Dec 5 12:06:25 2008 @@ -83,34 +83,25 @@ JDBCDiskCachePoolAccessAttributes poolAttributes = configurePoolAccessAttributes( poolName ); try { - try - { - // org.gjt.mm.mysql.Driver - Class.forName( poolAttributes.getDriverClassName() ); - } - catch ( ClassNotFoundException e ) + poolAccess = JDBCDiskCachePoolAccessFactory.createPoolAccess( poolAttributes ); + + if ( log.isInfoEnabled() ) { - log.error( "Couldn't find class for driver [" + poolAttributes.getDriverClassName() + "]", e ); + log.info( "Created shared pooled access for pool name [" + poolName + "]." ); } - - poolAccess = new JDBCDiskCachePoolAccess( poolAttributes.getPoolName() ); - - poolAccess.setupDriver( poolAttributes.getUrl() + poolAttributes.getDatabase(), poolAttributes - .getUserName(), poolAttributes.getPassword(), poolAttributes.getMaxActive() ); - - poolAccess.logDriverStats(); - pools.put( poolName, poolAccess ); } catch ( Exception e ) { - log.error( "Problem creating connection pool.", e ); + log.error( "Problem creating connection poolfor pool name [" + poolName + "].", e ); } } return poolAccess; } + + /** * Configures the attributes using the properties. * <p> Modified: jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/jdbc/mysql/MySQLDiskCache.java URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/jdbc/mysql/MySQLDiskCache.java?rev=723841&r1=723840&r2=723841&view=diff ============================================================================== --- jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/jdbc/mysql/MySQLDiskCache.java (original) +++ jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/jdbc/mysql/MySQLDiskCache.java Fri Dec 5 12:06:25 2008 @@ -47,7 +47,7 @@ private final static Log log = LogFactory.getLog( MySQLDiskCache.class ); /** config attributes */ - MySQLDiskCacheAttributes mySQLDiskCacheAttributes; + private MySQLDiskCacheAttributes mySQLDiskCacheAttributes; /** * Delegates to the super and makes use of the MySQL specific parameters used for scheduled Modified: jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/jdbc/mysql/MySQLDiskCacheFactory.java URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/jdbc/mysql/MySQLDiskCacheFactory.java?rev=723841&r1=723840&r2=723841&view=diff ============================================================================== --- jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/jdbc/mysql/MySQLDiskCacheFactory.java (original) +++ jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/jdbc/mysql/MySQLDiskCacheFactory.java Fri Dec 5 12:06:25 2008 @@ -35,7 +35,7 @@ implements AuxiliaryCacheFactory { /** name of the factory */ - private String name = "JDBCDiskCacheFactory"; + private String name = "MySQLDiskCacheFactory"; /** * This factory method should create an instance of the mysqlcache. Modified: jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/jdbc/mysql/MySQLDiskCacheManager.java URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/jdbc/mysql/MySQLDiskCacheManager.java?rev=723841&r1=723840&r2=723841&view=diff ============================================================================== --- jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/jdbc/mysql/MySQLDiskCacheManager.java (original) +++ jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/jdbc/mysql/MySQLDiskCacheManager.java Fri Dec 5 12:06:25 2008 @@ -28,6 +28,7 @@ import org.apache.jcs.auxiliary.AuxiliaryCache; import org.apache.jcs.auxiliary.disk.jdbc.JDBCDiskCacheAttributes; import org.apache.jcs.auxiliary.disk.jdbc.JDBCDiskCacheManagerAbstractTemplate; +import org.apache.jcs.auxiliary.disk.jdbc.JDBCDiskCachePoolAccess; import org.apache.jcs.auxiliary.disk.jdbc.TableState; import org.apache.jcs.auxiliary.disk.jdbc.mysql.util.ScheduleFormatException; import org.apache.jcs.auxiliary.disk.jdbc.mysql.util.ScheduleParser; @@ -143,11 +144,11 @@ */ protected AuxiliaryCache createJDBCDiskCache( JDBCDiskCacheAttributes cattr, TableState tableState ) { - AuxiliaryCache raf = new MySQLDiskCache( (MySQLDiskCacheAttributes) cattr, tableState, getCompositeCacheManager() ); + MySQLDiskCache diskCache = new MySQLDiskCache( (MySQLDiskCacheAttributes) cattr, tableState, getCompositeCacheManager() ); - scheduleOptimizations( (MySQLDiskCacheAttributes) cattr, tableState ); + scheduleOptimizations( (MySQLDiskCacheAttributes) cattr, tableState, diskCache.getPoolAccess() ); - return raf; + return diskCache; } /** @@ -168,10 +169,11 @@ /** * For each time in the optimization schedule, this calls schedule Optimizaiton. * <p> - * @param attributes - * @param tableState + * @param attributes configuration propeties. + * @param tableState for noting optimization in progress, etc. + * @param poolAccess access to the pool */ - protected void scheduleOptimizations( MySQLDiskCacheAttributes attributes, TableState tableState ) + protected void scheduleOptimizations( MySQLDiskCacheAttributes attributes, TableState tableState, JDBCDiskCachePoolAccess poolAccess ) { if ( attributes != null ) { @@ -183,7 +185,7 @@ + "] on schdule [" + attributes.getOptimizationSchedule() + "]" ); } - MySQLTableOptimizer optimizer = new MySQLTableOptimizer( attributes, tableState ); + MySQLTableOptimizer optimizer = new MySQLTableOptimizer( attributes, tableState, poolAccess ); // loop through the dates. try Modified: jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/jdbc/mysql/MySQLTableOptimizer.java URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/jdbc/mysql/MySQLTableOptimizer.java?rev=723841&r1=723840&r2=723841&view=diff ============================================================================== --- jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/jdbc/mysql/MySQLTableOptimizer.java (original) +++ jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/jdbc/mysql/MySQLTableOptimizer.java Fri Dec 5 12:06:25 2008 @@ -26,13 +26,12 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.apache.jcs.auxiliary.disk.jdbc.JDBCDiskCacheAttributes; import org.apache.jcs.auxiliary.disk.jdbc.JDBCDiskCachePoolAccess; import org.apache.jcs.auxiliary.disk.jdbc.TableState; /** * The MySQL Table Optimizer can optimize MySQL tables. It knows how to optimize for MySQL datbases - * in particular and how to repari the table if it is corrupted in the process. + * in particular and how to repair the table if it is corrupted in the process. * <p> * We will probably be able to abstract out a generic optimizer interface from this class in the * future. @@ -58,46 +57,16 @@ * <p> * @param attributes * @param tableState We mark the table status as optimizing when this is happening. + * @param poolAccess access to the database */ - public MySQLTableOptimizer( MySQLDiskCacheAttributes attributes, TableState tableState ) + public MySQLTableOptimizer( MySQLDiskCacheAttributes attributes, TableState tableState, + JDBCDiskCachePoolAccess poolAccess ) { setTableName( attributes.getTableName() ); this.tableState = tableState; - /** - * This initializes the pool access. - */ - initializePoolAccess( attributes ); - } - /** - * Register the driver and create a pool. - * <p> - * @param cattr - */ - protected void initializePoolAccess( JDBCDiskCacheAttributes cattr ) - { - try - { - try - { - // org.gjt.mm.mysql.Driver - Class.forName( cattr.getDriverClassName() ); - } - catch ( ClassNotFoundException e ) - { - log.error( "Couldn't find class for driver [" + cattr.getDriverClassName() + "]", e ); - } - - poolAccess = new JDBCDiskCachePoolAccess( cattr.getName() ); - - poolAccess.setupDriver( cattr.getUrl() + cattr.getDatabase(), cattr.getUserName(), cattr.getPassword(), - cattr.getMaxActive() ); - } - catch ( Exception e ) - { - log.error( "Problem getting connection.", e ); - } + this.poolAccess = poolAccess; } /** @@ -162,7 +131,7 @@ tableState.setState( TableState.OPTIMIZATION_RUNNING ); if ( log.isInfoEnabled() ) { - log.debug( "Optimizing table [" + this.getTableName() + "]" ); + log.info( "Optimizing table [" + this.getTableName() + "]" ); } Connection con; Modified: jakarta/jcs/trunk/src/java/org/apache/jcs/engine/CacheEventQueue.java URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/java/org/apache/jcs/engine/CacheEventQueue.java?rev=723841&r1=723840&r2=723841&view=diff ============================================================================== --- jakarta/jcs/trunk/src/java/org/apache/jcs/engine/CacheEventQueue.java (original) +++ jakarta/jcs/trunk/src/java/org/apache/jcs/engine/CacheEventQueue.java Fri Dec 5 12:06:25 2008 @@ -129,7 +129,7 @@ /** * Initializes the queue. - * <,p> + * <p> * @param listener * @param listenerId * @param cacheName @@ -251,7 +251,7 @@ log.info( "Destroying queue, stats = " + getStatistics() ); } - // sychronize on queue so the thread will not wait forever, + // Synchronize on queue so the thread will not wait forever, // and then interrupt the QueueProcessor if ( processorThread != null ) @@ -278,7 +278,7 @@ } /** - * This adds a put event ot the queue. When it is processed, the element will be put to the + * This adds a put event to the queue. When it is processed, the element will be put to the * listener. * <p> * @param ce The feature to be added to the PutEvent attribute @@ -445,10 +445,10 @@ } /** - * This method returns semi structured data on this queue. + * This method returns semi-structured data on this queue. * <p> - * (non-Javadoc) * @see org.apache.jcs.engine.behavior.ICacheEventQueue#getStatistics() + * @return information on the status and history of the queue */ public IStats getStatistics() { Modified: jakarta/jcs/trunk/src/java/org/apache/jcs/engine/CacheListeners.java URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/java/org/apache/jcs/engine/CacheListeners.java?rev=723841&r1=723840&r2=723841&view=diff ============================================================================== --- jakarta/jcs/trunk/src/java/org/apache/jcs/engine/CacheListeners.java (original) +++ jakarta/jcs/trunk/src/java/org/apache/jcs/engine/CacheListeners.java Fri Dec 5 12:06:25 2008 @@ -30,7 +30,7 @@ */ public class CacheListeners { - /** Description of the Field */ + /** The cache using the queue. */ public final ICache cache; /** Map ICacheListener to ICacheEventQueue */ Modified: jakarta/jcs/trunk/src/java/org/apache/jcs/engine/CacheWatchRepairable.java URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/java/org/apache/jcs/engine/CacheWatchRepairable.java?rev=723841&r1=723840&r2=723841&view=diff ============================================================================== --- jakarta/jcs/trunk/src/java/org/apache/jcs/engine/CacheWatchRepairable.java (original) +++ jakarta/jcs/trunk/src/java/org/apache/jcs/engine/CacheWatchRepairable.java Fri Dec 5 12:06:25 2008 @@ -35,7 +35,7 @@ * Intercepts the requests to the underlying ICacheObserver object so that the * listeners can be recorded locally for remote connection recovery purposes. * (Durable subscription like those in JMS is not implemented at this stage for - * it can be too expensive on the runtime.) + * it can be too expensive.) */ public class CacheWatchRepairable implements ICacheObserver @@ -95,8 +95,7 @@ throws IOException { // Record the added cache listener locally, regardless of whether the - // remote add-listener - // operation succeeds or fails. + // remote add-listener operation succeeds or fails. synchronized ( cacheMap ) { Set listenerSet = (Set) cacheMap.get( cacheName ); @@ -122,8 +121,7 @@ throws IOException { // Record the added cache listener locally, regardless of whether the - // remote add-listener - // operation succeeds or fails. + // remote add-listener operation succeeds or fails. synchronized ( cacheMap ) { for ( Iterator itr = cacheMap.values().iterator(); itr.hasNext(); ) @@ -150,8 +148,7 @@ log.info( "removeCacheListener, cacheName [" + cacheName + "]" ); } // Record the removal locally, regardless of whether the remote - // remove-listener - // operation succeeds or fails. + // remove-listener operation succeeds or fails. synchronized ( cacheMap ) { Set listenerSet = (Set) cacheMap.get( cacheName ); Modified: jakarta/jcs/trunk/src/java/org/apache/jcs/engine/control/CompositeCache.java URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/java/org/apache/jcs/engine/control/CompositeCache.java?rev=723841&r1=723840&r2=723841&view=diff ============================================================================== --- jakarta/jcs/trunk/src/java/org/apache/jcs/engine/control/CompositeCache.java (original) +++ jakarta/jcs/trunk/src/java/org/apache/jcs/engine/control/CompositeCache.java Fri Dec 5 12:06:25 2008 @@ -309,12 +309,9 @@ } if ( cacheAttr.getUseLateral() && cacheElement.getElementAttributes().getIsLateral() && !localOnly ) { - // later if we want a multicast, possibly delete abnormal - // broadcaster // DISTRIBUTE LATERALLY // Currently always multicast even if the value is - // unchanged, - // just to cause the cache item to move to the front. + // unchanged, to cause the cache item to move to the front. aux.update( cacheElement ); if ( log.isDebugEnabled() ) { @@ -344,8 +341,8 @@ } /** - * Writes the specified element to any disk auxilliaries. Might want to rename this "overflow" - * incase the hub wants to do something else. + * Writes the specified element to any disk auxiliaries. Might want to rename this "overflow" in + * case the hub wants to do something else. * <p> * If JCS is not configured to use the disk as a swap, that is if the the * CompositeCacheAttribute diskUsagePattern is not SWAP_ONLY, then the item will not be spooled. @@ -904,7 +901,7 @@ log.debug( "Attempting to get from aux [" + aux.getCacheName() + "] which is of type: " + cacheType ); } - + try { elementsFromAuxiliary.putAll( aux.getMatching( pattern ) ); @@ -913,7 +910,7 @@ { log.error( "Error getting from aux", e ); } - + if ( log.isDebugEnabled() ) { log.debug( "Got CacheElements: " + elementsFromAuxiliary ); @@ -957,7 +954,7 @@ missCountExpired++; - // This will tell the remotes to remove the item + // This will tell the remote caches to remove the item // based on the element's expiration policy. The elements attributes // associated with the item when it created govern its behavior // everywhere. @@ -982,8 +979,8 @@ } /** - * Copies the item to memory if the memory size is greater than 0. Only spool if the memory cache - * size is greater than 0, else the item will immediately get put into purgatory. + * Copies the item to memory if the memory size is greater than 0. Only spool if the memory + * cache size is greater than 0, else the item will immediately get put into purgatory. * <p> * @param element * @throws IOException @@ -1743,7 +1740,7 @@ } /** - * Rerturns the key matcher used by get matching. + * Returns the key matcher used by get matching. * <p> * @return keyMatcher */ @@ -1787,8 +1784,7 @@ /** * This returns the stats. * <p> - * (non-Javadoc) - * @see java.lang.Object#toString() + * @return getStats() */ public String toString() { Modified: jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/jdbc/mysql/MySQLTableOptimizerManualTester.java URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/jdbc/mysql/MySQLTableOptimizerManualTester.java?rev=723841&r1=723840&r2=723841&view=diff ============================================================================== --- jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/jdbc/mysql/MySQLTableOptimizerManualTester.java (original) +++ jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/jdbc/mysql/MySQLTableOptimizerManualTester.java Fri Dec 5 12:06:25 2008 @@ -19,10 +19,11 @@ * under the License. */ -import org.apache.jcs.auxiliary.disk.jdbc.TableState; - import junit.framework.TestCase; +import org.apache.jcs.auxiliary.disk.jdbc.JDBCDiskCachePoolAccessFactory; +import org.apache.jcs.auxiliary.disk.jdbc.TableState; + /** * Hand run tests for the MySQL table optimizer. * <p> @@ -31,12 +32,15 @@ public class MySQLTableOptimizerManualTester extends TestCase { - /** * Run the optimization against live a table. + * <p> + * @throws Exception */ public void testBasicOptimization() + throws Exception { + // SETUP MySQLDiskCacheAttributes attributes = new MySQLDiskCacheAttributes(); attributes.setUserName( "java" ); attributes.setPassword( "letmein" ); @@ -44,18 +48,24 @@ attributes.setDriverClassName( "org.gjt.mm.mysql.Driver" ); String tableName = "JCS_STORE_FLIGHT_OPTION_ITINERARY"; attributes.setTableName( tableName ); - TableState tableState = new TableState( tableName); + TableState tableState = new TableState( tableName ); - MySQLTableOptimizer optimizer = new MySQLTableOptimizer( attributes, tableState ); + MySQLTableOptimizer optimizer = new MySQLTableOptimizer( attributes, tableState, JDBCDiskCachePoolAccessFactory + .createPoolAccess( attributes ) ); + // DO WORK optimizer.optimizeTable(); } /** * Run the optimization against live a table. + * <p> + * @throws Exception */ public void testBasicOptimizationUnknownTable() + throws Exception { + // SETUP MySQLDiskCacheAttributes attributes = new MySQLDiskCacheAttributes(); attributes.setUserName( "java" ); attributes.setPassword( "letmein" ); @@ -63,11 +73,12 @@ attributes.setDriverClassName( "org.gjt.mm.mysql.Driver" ); String tableName = "DOESNTEXIST"; attributes.setTableName( tableName ); - TableState tableState = new TableState( tableName); + TableState tableState = new TableState( tableName ); - MySQLTableOptimizer optimizer = new MySQLTableOptimizer( attributes, tableState ); + MySQLTableOptimizer optimizer = new MySQLTableOptimizer( attributes, tableState, JDBCDiskCachePoolAccessFactory + .createPoolAccess( attributes ) ); + // DO WORK optimizer.optimizeTable(); } - } Modified: jakarta/jcs/trunk/xdocs/changes.xml URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/xdocs/changes.xml?rev=723841&r1=723840&r2=723841&view=diff ============================================================================== --- jakarta/jcs/trunk/xdocs/changes.xml (original) +++ jakarta/jcs/trunk/xdocs/changes.xml Fri Dec 5 12:06:25 2008 @@ -21,15 +21,19 @@ <body> <release version="1.4-dev" date="in SVN"> </release> + <release version="1.3.2.7" date="2008-12-05" description="tempbuild"> + <action dev="asmuts" type="fix">Fixed bug in the MySQLDiskCache + optimizer. It can now use a shared pool.</action> + </release> <release version="1.3.2.6" date="2008-12-01" description="tempbuild"> - <action dev="asmuts" type="fix">Fixed balking bug in getMatching( String pattern ) API. - </action> - <action dev="asmuts" type="fix">Fixed event naming bug in getMatching( String pattern ) API. - </action> + <action dev="asmuts" type="fix">Fixed balking bug in + getMatching( String pattern ) API.</action> + <action dev="asmuts" type="fix">Fixed event naming bug in + getMatching( String pattern ) API.</action> </release> <release version="1.3.2.5" date="2008-11-20" description="tempbuild"> - <action dev="asmuts" type="update">Added a getMatching( String pattern ) API. - </action> + <action dev="asmuts" type="update">Added a getMatching( String + pattern ) API.</action> </release> <release version="1.3.2.4" date="2008-?" description="tempbuild"> <action dev="asmuts" type="update">Added the ability to inject a --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]