You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jcs-dev@jakarta.apache.org by tv...@apache.org on 2007/05/10 18:04:27 UTC

svn commit: r536904 [15/38] - in /jakarta/jcs/trunk: ./ auxiliary-builds/javagroups/ auxiliary-builds/javagroups/src/java/org/apache/jcs/auxiliary/javagroups/ auxiliary-builds/javagroups/src/test/org/apache/jcs/auxiliary/javagroups/ auxiliary-builds/jd...

Modified: jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/jdbc/JDBCDiskCacheManagerAbstractTemplate.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/jdbc/JDBCDiskCacheManagerAbstractTemplate.java?view=diff&rev=536904&r1=536903&r2=536904
==============================================================================
--- jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/jdbc/JDBCDiskCacheManagerAbstractTemplate.java (original)
+++ jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/jdbc/JDBCDiskCacheManagerAbstractTemplate.java Thu May 10 09:03:42 2007
@@ -1,220 +1,228 @@
-package org.apache.jcs.auxiliary.disk.jdbc;
-
-/*
- * Copyright 2001-2004 The Apache Software Foundation. Licensed under the Apache
- * License, Version 2.0 (the "License") you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law
- * or agreed to in writing, software distributed under the License is
- * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the specific language
- * governing permissions and limitations under the License.
- */
-
-import java.util.Enumeration;
-import java.util.Hashtable;
-import java.util.Map;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.jcs.auxiliary.AuxiliaryCache;
-import org.apache.jcs.auxiliary.AuxiliaryCacheManager;
-
-import EDU.oswego.cs.dl.util.concurrent.ClockDaemon;
-import EDU.oswego.cs.dl.util.concurrent.ThreadFactory;
-
-/**
- * This class serves as an abstract template for JDBCDiskCache Manager. The
- * MySQL JDBC Disk Cache needs many of the same features as the generic maanger.
- * <p>
- * @author Aaron Smuts
- */
-public abstract class JDBCDiskCacheManagerAbstractTemplate
-    implements AuxiliaryCacheManager
-{
-    private static final Log log = LogFactory.getLog( JDBCDiskCacheManagerAbstractTemplate.class );
-
-    /**
-     * Incremented on getIntance, decremented on release.
-     */
-    protected static int clients;
-
-    /**
-     * A map of JDBCDiskCache objects to region names.
-     */
-    protected static Hashtable caches = new Hashtable();
-
-    /**
-     * A map of TableState objects to table names. Each cache has a table state
-     * object, which is used to determin if any long processes such as deletes
-     * or optimizations are running.
-     */
-    protected static Hashtable tableStates = new Hashtable();
-
-    /**
-     * The background disk shrinker, one for all regions.
-     */
-    private ClockDaemon shrinkerDaemon;
-
-    /**
-     * A map of table name to shrinker threads. This allows each table to have a
-     * different setting. It assumes that there is only one jdbc disk cache
-     * auxiliary defined per table.
-     */
-    private Map shrinkerThreadMap = new Hashtable();
-
-    /**
-     * Children must implement this method.
-     * <p>
-     * @param cattr
-     * @param tableState An object used by multiple processes to indicate state.
-     * @return AuxiliaryCache -- a JDBCDiskCache
-     */
-    protected abstract AuxiliaryCache createJDBCDiskCache( JDBCDiskCacheAttributes cattr, TableState tableState );
-
-    /**
-     * Creates a JDBCDiskCache for the region if one doesn't exist, else it
-     * returns the precreated instance. It also adds the region to the shrinker
-     * thread if needed.
-     * <p>
-     * @param cattr
-     * @return The cache value
-     */
-    public AuxiliaryCache getCache( JDBCDiskCacheAttributes cattr )
-    {
-        AuxiliaryCache diskCache = null;
-
-        log.debug( "cacheName = " + cattr.getCacheName() );
-
-        synchronized ( caches )
-        {
-            diskCache = (AuxiliaryCache) caches.get( cattr.getCacheName() );
-                    
-            if ( diskCache == null )
-            {
-                TableState tableState = (TableState)tableStates.get( cattr.getTableName() );
-                
-                if ( tableState == null )
-                {
-                    tableState = new TableState( cattr.getTableName() );
-                }
-                
-                diskCache = createJDBCDiskCache( cattr, tableState );
-
-                caches.put( cattr.getCacheName(), diskCache );
-            }
-        }
-
-        if ( log.isDebugEnabled() )
-        {
-            log.debug( "JDBC cache = " + diskCache );
-        }
-
-        // create a shrinker if we need it.
-        createShrinkerWhenNeeded( cattr, diskCache );
-
-        return diskCache;
-    }
-
-    /**
-     * If UseDiskShrinker is true then we will create a shrinker daemon if
-     * necessary.
-     * <p>
-     * @param cattr
-     * @param raf
-     */
-    protected void createShrinkerWhenNeeded( JDBCDiskCacheAttributes cattr, AuxiliaryCache raf )
-    {
-        // add cache to shrinker.
-        if ( cattr.isUseDiskShrinker() )
-        {
-            if ( shrinkerDaemon == null )
-            {
-                shrinkerDaemon = new ClockDaemon();
-                shrinkerDaemon.setThreadFactory( new MyThreadFactory() );
-            }
-
-            ShrinkerThread shrinkerThread = (ShrinkerThread) shrinkerThreadMap.get( cattr.getTableName() );
-            if ( shrinkerThread == null )
-            {
-                shrinkerThread = new ShrinkerThread();
-                shrinkerThreadMap.put( cattr.getTableName(), shrinkerThread );
-
-                long intervalMillis = Math.max( 999, cattr.getShrinkerIntervalSeconds() * 1000 );
-                if ( log.isInfoEnabled() )
-                {
-                    log.info( "Setting the shrinker to run every [" + intervalMillis + "] ms. for table ["
-                        + cattr.getTableName() + "]" );
-                }
-                shrinkerDaemon.executePeriodically( intervalMillis, shrinkerThread, false );
-            }
-            shrinkerThread.addDiskCacheToShrinkList( (JDBCDiskCache) raf );
-        }
-    }
-
-    /**
-     * @param name
-     */
-    public void freeCache( String name )
-    {
-        JDBCDiskCache raf = (JDBCDiskCache) caches.get( name );
-        if ( raf != null )
-        {
-            raf.dispose();
-        }
-    }
-
-    /**
-     * Gets the cacheType attribute of the HSQLCacheManager object
-     * <p>
-     * @return The cacheType value
-     */
-    public int getCacheType()
-    {
-        return DISK_CACHE;
-    }
-
-    /** Disposes of all regions. */
-    public void release()
-    {
-        // Wait until called by the last client
-        if ( --clients != 0 )
-        {
-            return;
-        }
-        synchronized ( caches )
-        {
-            Enumeration allCaches = caches.elements();
-
-            while ( allCaches.hasMoreElements() )
-            {
-                JDBCDiskCache raf = (JDBCDiskCache) allCaches.nextElement();
-                if ( raf != null )
-                {
-                    raf.dispose();
-                }
-            }
-        }
-    }
-
-    /**
-     * Allows us to set the daemon status on the clockdaemon
-     * <p>
-     * @author aaronsm
-     */
-    class MyThreadFactory
-        implements ThreadFactory
-    {
-        /*
-         * (non-Javadoc)
-         * @see EDU.oswego.cs.dl.util.concurrent.ThreadFactory#newThread(java.lang.Runnable)
-         */
-        public Thread newThread( Runnable runner )
-        {
-            Thread t = new Thread( runner );
-            t.setDaemon( true );
-            t.setPriority( Thread.MIN_PRIORITY );
-            return t;
-        }
-    }
-}
+package org.apache.jcs.auxiliary.disk.jdbc;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.Enumeration;
+import java.util.Hashtable;
+import java.util.Map;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.jcs.auxiliary.AuxiliaryCache;
+import org.apache.jcs.auxiliary.AuxiliaryCacheManager;
+
+import EDU.oswego.cs.dl.util.concurrent.ClockDaemon;
+import EDU.oswego.cs.dl.util.concurrent.ThreadFactory;
+
+/**
+ * This class serves as an abstract template for JDBCDiskCache Manager. The
+ * MySQL JDBC Disk Cache needs many of the same features as the generic maanger.
+ * <p>
+ * @author Aaron Smuts
+ */
+public abstract class JDBCDiskCacheManagerAbstractTemplate
+    implements AuxiliaryCacheManager
+{
+    private static final Log log = LogFactory.getLog( JDBCDiskCacheManagerAbstractTemplate.class );
+
+    /**
+     * Incremented on getIntance, decremented on release.
+     */
+    protected static int clients;
+
+    /**
+     * A map of JDBCDiskCache objects to region names.
+     */
+    protected static Hashtable caches = new Hashtable();
+
+    /**
+     * A map of TableState objects to table names. Each cache has a table state
+     * object, which is used to determin if any long processes such as deletes
+     * or optimizations are running.
+     */
+    protected static Hashtable tableStates = new Hashtable();
+
+    /**
+     * The background disk shrinker, one for all regions.
+     */
+    private ClockDaemon shrinkerDaemon;
+
+    /**
+     * A map of table name to shrinker threads. This allows each table to have a
+     * different setting. It assumes that there is only one jdbc disk cache
+     * auxiliary defined per table.
+     */
+    private Map shrinkerThreadMap = new Hashtable();
+
+    /**
+     * Children must implement this method.
+     * <p>
+     * @param cattr
+     * @param tableState An object used by multiple processes to indicate state.
+     * @return AuxiliaryCache -- a JDBCDiskCache
+     */
+    protected abstract AuxiliaryCache createJDBCDiskCache( JDBCDiskCacheAttributes cattr, TableState tableState );
+
+    /**
+     * Creates a JDBCDiskCache for the region if one doesn't exist, else it
+     * returns the precreated instance. It also adds the region to the shrinker
+     * thread if needed.
+     * <p>
+     * @param cattr
+     * @return The cache value
+     */
+    public AuxiliaryCache getCache( JDBCDiskCacheAttributes cattr )
+    {
+        AuxiliaryCache diskCache = null;
+
+        log.debug( "cacheName = " + cattr.getCacheName() );
+
+        synchronized ( caches )
+        {
+            diskCache = (AuxiliaryCache) caches.get( cattr.getCacheName() );
+
+            if ( diskCache == null )
+            {
+                TableState tableState = (TableState)tableStates.get( cattr.getTableName() );
+
+                if ( tableState == null )
+                {
+                    tableState = new TableState( cattr.getTableName() );
+                }
+
+                diskCache = createJDBCDiskCache( cattr, tableState );
+
+                caches.put( cattr.getCacheName(), diskCache );
+            }
+        }
+
+        if ( log.isDebugEnabled() )
+        {
+            log.debug( "JDBC cache = " + diskCache );
+        }
+
+        // create a shrinker if we need it.
+        createShrinkerWhenNeeded( cattr, diskCache );
+
+        return diskCache;
+    }
+
+    /**
+     * If UseDiskShrinker is true then we will create a shrinker daemon if
+     * necessary.
+     * <p>
+     * @param cattr
+     * @param raf
+     */
+    protected void createShrinkerWhenNeeded( JDBCDiskCacheAttributes cattr, AuxiliaryCache raf )
+    {
+        // add cache to shrinker.
+        if ( cattr.isUseDiskShrinker() )
+        {
+            if ( shrinkerDaemon == null )
+            {
+                shrinkerDaemon = new ClockDaemon();
+                shrinkerDaemon.setThreadFactory( new MyThreadFactory() );
+            }
+
+            ShrinkerThread shrinkerThread = (ShrinkerThread) shrinkerThreadMap.get( cattr.getTableName() );
+            if ( shrinkerThread == null )
+            {
+                shrinkerThread = new ShrinkerThread();
+                shrinkerThreadMap.put( cattr.getTableName(), shrinkerThread );
+
+                long intervalMillis = Math.max( 999, cattr.getShrinkerIntervalSeconds() * 1000 );
+                if ( log.isInfoEnabled() )
+                {
+                    log.info( "Setting the shrinker to run every [" + intervalMillis + "] ms. for table ["
+                        + cattr.getTableName() + "]" );
+                }
+                shrinkerDaemon.executePeriodically( intervalMillis, shrinkerThread, false );
+            }
+            shrinkerThread.addDiskCacheToShrinkList( (JDBCDiskCache) raf );
+        }
+    }
+
+    /**
+     * @param name
+     */
+    public void freeCache( String name )
+    {
+        JDBCDiskCache raf = (JDBCDiskCache) caches.get( name );
+        if ( raf != null )
+        {
+            raf.dispose();
+        }
+    }
+
+    /**
+     * Gets the cacheType attribute of the HSQLCacheManager object
+     * <p>
+     * @return The cacheType value
+     */
+    public int getCacheType()
+    {
+        return DISK_CACHE;
+    }
+
+    /** Disposes of all regions. */
+    public void release()
+    {
+        // Wait until called by the last client
+        if ( --clients != 0 )
+        {
+            return;
+        }
+        synchronized ( caches )
+        {
+            Enumeration allCaches = caches.elements();
+
+            while ( allCaches.hasMoreElements() )
+            {
+                JDBCDiskCache raf = (JDBCDiskCache) allCaches.nextElement();
+                if ( raf != null )
+                {
+                    raf.dispose();
+                }
+            }
+        }
+    }
+
+    /**
+     * Allows us to set the daemon status on the clockdaemon
+     * <p>
+     * @author aaronsm
+     */
+    class MyThreadFactory
+        implements ThreadFactory
+    {
+        /*
+         * (non-Javadoc)
+         * @see EDU.oswego.cs.dl.util.concurrent.ThreadFactory#newThread(java.lang.Runnable)
+         */
+        public Thread newThread( Runnable runner )
+        {
+            Thread t = new Thread( runner );
+            t.setDaemon( true );
+            t.setPriority( Thread.MIN_PRIORITY );
+            return t;
+        }
+    }
+}

Modified: jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/jdbc/JDBCDiskCachePoolAccess.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/jdbc/JDBCDiskCachePoolAccess.java?view=diff&rev=536904&r1=536903&r2=536904
==============================================================================
--- jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/jdbc/JDBCDiskCachePoolAccess.java (original)
+++ jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/jdbc/JDBCDiskCachePoolAccess.java Thu May 10 09:03:42 2007
@@ -1,250 +1,269 @@
-package org.apache.jcs.auxiliary.disk.jdbc;
-
-import java.sql.Connection;
-import java.sql.DriverManager;
-import java.sql.SQLException;
-
-import org.apache.commons.dbcp.ConnectionFactory;
-import org.apache.commons.dbcp.DriverManagerConnectionFactory;
-import org.apache.commons.dbcp.PoolableConnectionFactory;
-import org.apache.commons.dbcp.PoolingDriver;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.commons.pool.ObjectPool;
-import org.apache.commons.pool.impl.GenericObjectPool;
-
-/**
- * This class provides access to the connection pool. It ensures that the
- * various resources that need to access the tables will be able to use the same
- * pool.
- * <p>
- * @author Aaron Smuts
- */
-public class JDBCDiskCachePoolAccess
-{
-    private final static Log log = LogFactory.getLog( JDBCDiskCachePoolAccess.class );
-
-    /** The defualt Pool Name to which the connetion pool will be keyed. */
-    public static final String DEFAULT_POOL_NAME = "jcs";
-
-    private String poolName = DEFAULT_POOL_NAME;
-
-    private static final String DRIVER_NAME = "jdbc:apache:commons:dbcp:";
-
-    // WE SHOULD HAVE A DIFFERENT POOL FOR EACH DB NO REGION
-    // THE SAME TABLE CAN BE USED BY MULTIPLE REGIONS
-    // this.setPoolName( jdbcDiskCacheAttributes.getCacheName() );
-    
-    /**
-     * Configures the pool name to use for the pool access.
-     * <p>
-     * This pool name should be unique to the database. It is used as part of
-     * the URL each time we lookup a conection from the driver manager.
-     * <p>
-     * @param poolName
-     * @param driverName
-     */
-    public JDBCDiskCachePoolAccess( String poolName )
-    {
-        // we can default to jcs if there is only one database in use.
-        if ( poolName != null )
-        {
-            setPoolName( poolName );
-        }
-        else
-        {
-            if ( log.isInfoEnabled() )
-            {
-                log.info( "The pool name supplied was null.  Using default instead." );
-            }
-        }
-    }
-        
-
-    /**
-     * Gets a connection from the pool.
-     * <p>
-     * @return Connection
-     * @throws SQLException
-     */
-    public Connection getConnection()
-        throws SQLException
-    {
-        Connection con;
-        try
-        {
-            con = DriverManager.getConnection( getPoolUrl() );
-        }
-        catch ( SQLException e )
-        {
-            log.error( "Problem getting conenction.", e );
-            throw e;
-        }
-
-        return con;
-    }
-
-    /**
-     * How many are idle in the pool.
-     * <p>
-     * @return
-     */
-    public int getNumIdleInPool()
-    {
-        int numIdle = 0;
-        try
-        {
-            PoolingDriver driver = (PoolingDriver) DriverManager.getDriver( DRIVER_NAME );
-            ObjectPool connectionPool = driver.getConnectionPool( this.getPoolName() );
-
-            if ( log.isDebugEnabled() )
-            {
-                log.debug( connectionPool );
-            }
-            numIdle = connectionPool.getNumIdle();
-        }
-        catch ( Exception e )
-        {
-            log.error( e );
-        }
-        return numIdle;
-    }
-
-    /**
-     * How many are active in the pool.
-     * <p>
-     * @return
-     */
-    public int getNumActiveInPool()
-    {
-        int numActive = 0;
-        try
-        {
-            PoolingDriver driver = (PoolingDriver) DriverManager.getDriver( DRIVER_NAME );
-            ObjectPool connectionPool = driver.getConnectionPool( this.getPoolName() );
-
-            if ( log.isDebugEnabled() )
-            {
-                log.debug( connectionPool );
-            }
-            numActive = connectionPool.getNumActive();
-        }
-        catch ( Exception e )
-        {
-            log.error( e );
-        }
-        return numActive;
-    }
-
-    /**
-     * @throws Exception
-     */
-    public void shutdownDriver()
-        throws Exception
-    {
-        PoolingDriver driver = (PoolingDriver) DriverManager.getDriver( DRIVER_NAME );
-        driver.closePool( this.getPoolName() );
-    }
-
-    /**
-     * @return Returns the poolUrl.
-     */
-    public String getPoolUrl()
-    {
-        return DRIVER_NAME + this.getPoolName();
-    }
-
-    /**
-     * @param poolName
-     *            The poolName to set.
-     */
-    public void setPoolName( String poolName )
-    {
-        this.poolName = poolName;
-    }
-
-    /**
-     * @return Returns the poolName.
-     */
-    public String getPoolName()
-    {
-        return poolName;
-    }
-
-    /**
-     * @param connectURI
-     * @param userName
-     * @param password
-     * @param maxActive
-     *            max connetions
-     * @throws Exception
-     */
-    public void setupDriver( String connectURI, String userName, String password, int maxActive )
-        throws Exception
-    {
-        // First, we'll need a ObjectPool that serves as the
-        // actual pool of connections.
-        // We'll use a GenericObjectPool instance, although
-        // any ObjectPool implementation will suffice.
-        ObjectPool connectionPool = new GenericObjectPool( null, maxActive );
-
-        // TODO make configurable
-        // By dfault the size is 8!!!!!!!
-        ( (GenericObjectPool) connectionPool ).setMaxIdle( -1 );
-
-        // Next, we'll create a ConnectionFactory that the
-        // pool will use to create Connections.
-        // We'll use the DriverManagerConnectionFactory,
-        // using the connect string passed in the command line
-        // arguments.
-        // Properties props = new Properties();
-        // props.setProperty( "user", userName );
-        // props.setProperty( "password", password );
-        ConnectionFactory connectionFactory = new DriverManagerConnectionFactory( connectURI, userName, password );
-
-        // Now we'll create the PoolableConnectionFactory, which wraps
-        // the "real" Connections created by the ConnectionFactory with
-        // the classes that implement the pooling functionality.
-        // PoolableConnectionFactory poolableConnectionFactory =
-        new PoolableConnectionFactory( connectionFactory, connectionPool, null, null, false, true );
-
-        // Finally, we create the PoolingDriver itself...
-        Class.forName( "org.apache.commons.dbcp.PoolingDriver" );
-        PoolingDriver driver = (PoolingDriver) DriverManager.getDriver( DRIVER_NAME );
-
-        // ...and register our pool with it.
-        driver.registerPool( this.getPoolName(), connectionPool );
-
-        // Now we can just use the connect string
-        // "jdbc:apache:commons:dbcp:jcs"
-        // to access our pool of Connections.
-    }
-
-    /**
-     * @throws Exception
-     */
-    public void logDriverStats()
-        throws Exception
-    {
-        PoolingDriver driver = (PoolingDriver) DriverManager.getDriver( DRIVER_NAME );
-        ObjectPool connectionPool = driver.getConnectionPool( this.getPoolName() );
-
-        if ( connectionPool != null )
-        {
-            if ( log.isDebugEnabled() )
-            {
-                log.debug( connectionPool );
-            }
-
-            if ( log.isInfoEnabled() )
-            {
-                log.info( "NumActive: " + getNumActiveInPool() );
-                log.info( "NumIdle: " + getNumIdleInPool() );
-            }
-        }
-        else
-        {
-            log.warn( "Could not find pool." );
-        }
-    }
-}
+package org.apache.jcs.auxiliary.disk.jdbc;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.SQLException;
+
+import org.apache.commons.dbcp.ConnectionFactory;
+import org.apache.commons.dbcp.DriverManagerConnectionFactory;
+import org.apache.commons.dbcp.PoolableConnectionFactory;
+import org.apache.commons.dbcp.PoolingDriver;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.commons.pool.ObjectPool;
+import org.apache.commons.pool.impl.GenericObjectPool;
+
+/**
+ * This class provides access to the connection pool. It ensures that the
+ * various resources that need to access the tables will be able to use the same
+ * pool.
+ * <p>
+ * @author Aaron Smuts
+ */
+public class JDBCDiskCachePoolAccess
+{
+    private final static Log log = LogFactory.getLog( JDBCDiskCachePoolAccess.class );
+
+    /** The defualt Pool Name to which the connetion pool will be keyed. */
+    public static final String DEFAULT_POOL_NAME = "jcs";
+
+    private String poolName = DEFAULT_POOL_NAME;
+
+    private static final String DRIVER_NAME = "jdbc:apache:commons:dbcp:";
+
+    // WE SHOULD HAVE A DIFFERENT POOL FOR EACH DB NO REGION
+    // THE SAME TABLE CAN BE USED BY MULTIPLE REGIONS
+    // this.setPoolName( jdbcDiskCacheAttributes.getCacheName() );
+
+    /**
+     * Configures the pool name to use for the pool access.
+     * <p>
+     * This pool name should be unique to the database. It is used as part of
+     * the URL each time we lookup a conection from the driver manager.
+     * <p>
+     * @param poolName
+     * @param driverName
+     */
+    public JDBCDiskCachePoolAccess( String poolName )
+    {
+        // we can default to jcs if there is only one database in use.
+        if ( poolName != null )
+        {
+            setPoolName( poolName );
+        }
+        else
+        {
+            if ( log.isInfoEnabled() )
+            {
+                log.info( "The pool name supplied was null.  Using default instead." );
+            }
+        }
+    }
+
+
+    /**
+     * Gets a connection from the pool.
+     * <p>
+     * @return Connection
+     * @throws SQLException
+     */
+    public Connection getConnection()
+        throws SQLException
+    {
+        Connection con;
+        try
+        {
+            con = DriverManager.getConnection( getPoolUrl() );
+        }
+        catch ( SQLException e )
+        {
+            log.error( "Problem getting conenction.", e );
+            throw e;
+        }
+
+        return con;
+    }
+
+    /**
+     * How many are idle in the pool.
+     * <p>
+     * @return
+     */
+    public int getNumIdleInPool()
+    {
+        int numIdle = 0;
+        try
+        {
+            PoolingDriver driver = (PoolingDriver) DriverManager.getDriver( DRIVER_NAME );
+            ObjectPool connectionPool = driver.getConnectionPool( this.getPoolName() );
+
+            if ( log.isDebugEnabled() )
+            {
+                log.debug( connectionPool );
+            }
+            numIdle = connectionPool.getNumIdle();
+        }
+        catch ( Exception e )
+        {
+            log.error( e );
+        }
+        return numIdle;
+    }
+
+    /**
+     * How many are active in the pool.
+     * <p>
+     * @return
+     */
+    public int getNumActiveInPool()
+    {
+        int numActive = 0;
+        try
+        {
+            PoolingDriver driver = (PoolingDriver) DriverManager.getDriver( DRIVER_NAME );
+            ObjectPool connectionPool = driver.getConnectionPool( this.getPoolName() );
+
+            if ( log.isDebugEnabled() )
+            {
+                log.debug( connectionPool );
+            }
+            numActive = connectionPool.getNumActive();
+        }
+        catch ( Exception e )
+        {
+            log.error( e );
+        }
+        return numActive;
+    }
+
+    /**
+     * @throws Exception
+     */
+    public void shutdownDriver()
+        throws Exception
+    {
+        PoolingDriver driver = (PoolingDriver) DriverManager.getDriver( DRIVER_NAME );
+        driver.closePool( this.getPoolName() );
+    }
+
+    /**
+     * @return Returns the poolUrl.
+     */
+    public String getPoolUrl()
+    {
+        return DRIVER_NAME + this.getPoolName();
+    }
+
+    /**
+     * @param poolName
+     *            The poolName to set.
+     */
+    public void setPoolName( String poolName )
+    {
+        this.poolName = poolName;
+    }
+
+    /**
+     * @return Returns the poolName.
+     */
+    public String getPoolName()
+    {
+        return poolName;
+    }
+
+    /**
+     * @param connectURI
+     * @param userName
+     * @param password
+     * @param maxActive
+     *            max connetions
+     * @throws Exception
+     */
+    public void setupDriver( String connectURI, String userName, String password, int maxActive )
+        throws Exception
+    {
+        // First, we'll need a ObjectPool that serves as the
+        // actual pool of connections.
+        // We'll use a GenericObjectPool instance, although
+        // any ObjectPool implementation will suffice.
+        ObjectPool connectionPool = new GenericObjectPool( null, maxActive );
+
+        // TODO make configurable
+        // By dfault the size is 8!!!!!!!
+        ( (GenericObjectPool) connectionPool ).setMaxIdle( -1 );
+
+        // Next, we'll create a ConnectionFactory that the
+        // pool will use to create Connections.
+        // We'll use the DriverManagerConnectionFactory,
+        // using the connect string passed in the command line
+        // arguments.
+        // Properties props = new Properties();
+        // props.setProperty( "user", userName );
+        // props.setProperty( "password", password );
+        ConnectionFactory connectionFactory = new DriverManagerConnectionFactory( connectURI, userName, password );
+
+        // Now we'll create the PoolableConnectionFactory, which wraps
+        // the "real" Connections created by the ConnectionFactory with
+        // the classes that implement the pooling functionality.
+        // PoolableConnectionFactory poolableConnectionFactory =
+        new PoolableConnectionFactory( connectionFactory, connectionPool, null, null, false, true );
+
+        // Finally, we create the PoolingDriver itself...
+        Class.forName( "org.apache.commons.dbcp.PoolingDriver" );
+        PoolingDriver driver = (PoolingDriver) DriverManager.getDriver( DRIVER_NAME );
+
+        // ...and register our pool with it.
+        driver.registerPool( this.getPoolName(), connectionPool );
+
+        // Now we can just use the connect string
+        // "jdbc:apache:commons:dbcp:jcs"
+        // to access our pool of Connections.
+    }
+
+    /**
+     * @throws Exception
+     */
+    public void logDriverStats()
+        throws Exception
+    {
+        PoolingDriver driver = (PoolingDriver) DriverManager.getDriver( DRIVER_NAME );
+        ObjectPool connectionPool = driver.getConnectionPool( this.getPoolName() );
+
+        if ( connectionPool != null )
+        {
+            if ( log.isDebugEnabled() )
+            {
+                log.debug( connectionPool );
+            }
+
+            if ( log.isInfoEnabled() )
+            {
+                log.info( "NumActive: " + getNumActiveInPool() );
+                log.info( "NumIdle: " + getNumIdleInPool() );
+            }
+        }
+        else
+        {
+            log.warn( "Could not find pool." );
+        }
+    }
+}

Modified: jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/jdbc/ShrinkerThread.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/jdbc/ShrinkerThread.java?view=diff&rev=536904&r1=536903&r2=536904
==============================================================================
--- jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/jdbc/ShrinkerThread.java (original)
+++ jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/jdbc/ShrinkerThread.java Thu May 10 09:03:42 2007
@@ -1,134 +1,153 @@
-package org.apache.jcs.auxiliary.disk.jdbc;
-
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Set;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-/**
- * Calls delete expired on the disk caches. The shrinker is run by a clock
- * daemon. The shrinker calls delete on each region. It pauses between calls.
- * <p>
- * @author Aaron Smuts
- */
-public class ShrinkerThread
-    implements Runnable
-{
-    private final static Log log = LogFactory.getLog( ShrinkerThread.class );
-
-    /** A set of JDBCDiskCache objects to call deleteExpired on. */
-    private Set shrinkSet = Collections.synchronizedSet( new HashSet() );
-
-    /**
-     * How long should we wait between calls to deleteExpired when we are
-     * iterating through the list of regions. Delete can lock the table. We want
-     * to give clients a chance to get some work done.
-     */
-    private static final long DEFAULT_PAUSE_BETWEEN_REGION_CALLS_MILLIS = 5000;
-
-    private long pauseBetweenRegionCallsMillis = DEFAULT_PAUSE_BETWEEN_REGION_CALLS_MILLIS;
-
-    /**
-     * Does nothing special.
-     * <p>
-     * @param diskCache
-     */
-    protected ShrinkerThread()
-    {
-        super();
-    }
-
-    /**
-     * Adds a JDBC disk cache to the set of disk cache to shrink.
-     * <p>
-     * @param diskCache
-     */
-    public void addDiskCacheToShrinkList( JDBCDiskCache diskCache )
-    {
-        // the set will prevent dupes.
-        // we could also just add these to a hasmap by region name
-        // but that might cause a problem if you wanted to use two different
-        // jbdc disk caches for the same region.
-        shrinkSet.add( diskCache );
-    }
-
-    /**
-     * Calls deleteExpired on each item in the set. It pauses between each call.
-     */
-    public void run()
-    {
-        if ( log.isInfoEnabled() )
-        {
-            log.info( "Running JDBC disk cache shrinker.  Number of regions [" + shrinkSet.size() + "]" );
-        }
-
-        Object[] caches = null;
-
-        synchronized ( shrinkSet )
-        {
-            caches = this.shrinkSet.toArray();
-        }
-
-        if ( caches != null )
-        {
-            for ( int i = 0; i < caches.length; i++ )
-            {
-                JDBCDiskCache cache = (JDBCDiskCache) caches[i];
-
-                long start = System.currentTimeMillis();
-                int deleted = cache.deleteExpired();
-                long end = System.currentTimeMillis();
-
-                if ( log.isInfoEnabled() )
-                {
-                    log.info( "Deleted [" + deleted + "] expired for region [" + cache.getCacheName() + "] for table ["
-                        + cache.getTableName() + "] in " + ( end - start ) + " ms." );
-                }
-
-                // don't pause after the last call to delete expired.
-                if ( i < caches.length - 1 )
-                {
-                    if ( log.isInfoEnabled() )
-                    {
-                        log.info( "Pausing for [" + this.getPauseBetweenRegionCallsMillis()
-                            + "] ms. before shinker the next region." );
-                    }
-
-                    try
-                    {
-                        Thread.sleep( this.getPauseBetweenRegionCallsMillis() );
-                    }
-                    catch ( InterruptedException e )
-                    {
-                        log.warn( "Interrupted while waiting to delete expired for the enxt region." );
-                    }
-                }
-            }
-        }
-    }
-
-    /**
-     * How long should we wait between calls to deleteExpired when we are
-     * iterating through the list of regions.
-     * <p>
-     * @param pauseBetweenRegionCallsMillis
-     *            The pauseBetweenRegionCallsMillis to set.
-     */
-    public void setPauseBetweenRegionCallsMillis( long pauseBetweenRegionCallsMillis )
-    {
-        this.pauseBetweenRegionCallsMillis = pauseBetweenRegionCallsMillis;
-    }
-
-    /**
-     * How long should we wait between calls to deleteExpired when we are
-     * iterating through the list of regions.
-     * <p>
-     * @return Returns the pauseBetweenRegionCallsMillis.
-     */
-    public long getPauseBetweenRegionCallsMillis()
-    {
-        return pauseBetweenRegionCallsMillis;
-    }
-}
+package org.apache.jcs.auxiliary.disk.jdbc;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * Calls delete expired on the disk caches. The shrinker is run by a clock
+ * daemon. The shrinker calls delete on each region. It pauses between calls.
+ * <p>
+ * @author Aaron Smuts
+ */
+public class ShrinkerThread
+    implements Runnable
+{
+    private final static Log log = LogFactory.getLog( ShrinkerThread.class );
+
+    /** A set of JDBCDiskCache objects to call deleteExpired on. */
+    private Set shrinkSet = Collections.synchronizedSet( new HashSet() );
+
+    /**
+     * How long should we wait between calls to deleteExpired when we are
+     * iterating through the list of regions. Delete can lock the table. We want
+     * to give clients a chance to get some work done.
+     */
+    private static final long DEFAULT_PAUSE_BETWEEN_REGION_CALLS_MILLIS = 5000;
+
+    private long pauseBetweenRegionCallsMillis = DEFAULT_PAUSE_BETWEEN_REGION_CALLS_MILLIS;
+
+    /**
+     * Does nothing special.
+     * <p>
+     * @param diskCache
+     */
+    protected ShrinkerThread()
+    {
+        super();
+    }
+
+    /**
+     * Adds a JDBC disk cache to the set of disk cache to shrink.
+     * <p>
+     * @param diskCache
+     */
+    public void addDiskCacheToShrinkList( JDBCDiskCache diskCache )
+    {
+        // the set will prevent dupes.
+        // we could also just add these to a hasmap by region name
+        // but that might cause a problem if you wanted to use two different
+        // jbdc disk caches for the same region.
+        shrinkSet.add( diskCache );
+    }
+
+    /**
+     * Calls deleteExpired on each item in the set. It pauses between each call.
+     */
+    public void run()
+    {
+        if ( log.isInfoEnabled() )
+        {
+            log.info( "Running JDBC disk cache shrinker.  Number of regions [" + shrinkSet.size() + "]" );
+        }
+
+        Object[] caches = null;
+
+        synchronized ( shrinkSet )
+        {
+            caches = this.shrinkSet.toArray();
+        }
+
+        if ( caches != null )
+        {
+            for ( int i = 0; i < caches.length; i++ )
+            {
+                JDBCDiskCache cache = (JDBCDiskCache) caches[i];
+
+                long start = System.currentTimeMillis();
+                int deleted = cache.deleteExpired();
+                long end = System.currentTimeMillis();
+
+                if ( log.isInfoEnabled() )
+                {
+                    log.info( "Deleted [" + deleted + "] expired for region [" + cache.getCacheName() + "] for table ["
+                        + cache.getTableName() + "] in " + ( end - start ) + " ms." );
+                }
+
+                // don't pause after the last call to delete expired.
+                if ( i < caches.length - 1 )
+                {
+                    if ( log.isInfoEnabled() )
+                    {
+                        log.info( "Pausing for [" + this.getPauseBetweenRegionCallsMillis()
+                            + "] ms. before shinker the next region." );
+                    }
+
+                    try
+                    {
+                        Thread.sleep( this.getPauseBetweenRegionCallsMillis() );
+                    }
+                    catch ( InterruptedException e )
+                    {
+                        log.warn( "Interrupted while waiting to delete expired for the enxt region." );
+                    }
+                }
+            }
+        }
+    }
+
+    /**
+     * How long should we wait between calls to deleteExpired when we are
+     * iterating through the list of regions.
+     * <p>
+     * @param pauseBetweenRegionCallsMillis
+     *            The pauseBetweenRegionCallsMillis to set.
+     */
+    public void setPauseBetweenRegionCallsMillis( long pauseBetweenRegionCallsMillis )
+    {
+        this.pauseBetweenRegionCallsMillis = pauseBetweenRegionCallsMillis;
+    }
+
+    /**
+     * How long should we wait between calls to deleteExpired when we are
+     * iterating through the list of regions.
+     * <p>
+     * @return Returns the pauseBetweenRegionCallsMillis.
+     */
+    public long getPauseBetweenRegionCallsMillis()
+    {
+        return pauseBetweenRegionCallsMillis;
+    }
+}

Modified: jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/jdbc/TableState.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/jdbc/TableState.java?view=diff&rev=536904&r1=536903&r2=536904
==============================================================================
--- jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/jdbc/TableState.java (original)
+++ jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/jdbc/TableState.java Thu May 10 09:03:42 2007
@@ -1,105 +1,113 @@
-package org.apache.jcs.auxiliary.disk.jdbc;
-
-/*
- * Copyright 2001-2004 The Apache Software Foundation. Licensed under the Apache
- * License, Version 2.0 (the "License") you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law
- * or agreed to in writing, software distributed under the License is
- * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the specific language
- * governing permissions and limitations under the License.
- */
-
-import java.io.Serializable;
-
-/**
- * This is used by various elemetns of the JDBC disk cache to indicate the
- * status of a table. The MySQL disk cache, for instance, marks the status as
- * optimizing when a scheduled optimizatio is taking place. This allows the
- * cache to balk rather than block during long running optimizations.
- * <p>
- * @author Aaron Smuts
- */
-public class TableState
-    implements Serializable
-{
-    private static final long serialVersionUID = -6625081552084964885L;
-
-    private String tableName;
-
-    /**
-     * The table is free. It can be accessed and no potentially table locking
-     * jobs are running.
-     */
-    public static final int FREE = 0;
-
-    /** A potentially table locking deletion is running */
-    public static final int DELETE_RUNNING = 1;
-
-    /** A table locking optimization is running. */
-    public static final int OPTIMIZATION_RUNNING = 2;
-
-    // we might want to add error
-
-    private int state = FREE;
-
-    /**
-     * Construct a usable table state.
-     * <p>
-     * @param tableName
-     */
-    public TableState( String tableName )
-    {
-        this.setTableName( tableName );
-    }
-
-    /**
-     * @param tableName
-     *            The tableName to set.
-     */
-    public void setTableName( String tableName )
-    {
-        this.tableName = tableName;
-    }
-
-    /**
-     * @return Returns the tableName.
-     */
-    public String getTableName()
-    {
-        return tableName;
-    }
-
-    /**
-     * @param state
-     *            The state to set.
-     */
-    public void setState( int state )
-    {
-        this.state = state;
-    }
-
-    /**
-     * @return Returns the state.
-     */
-    public int getState()
-    {
-        return state;
-    }
-
-    /**
-     * Write out the values for debugging purposes.
-     * <p>
-     * @return String
-     */
-    public String toString()
-    {
-        StringBuffer str = new StringBuffer();
-        str.append( "TableState " );
-        str.append( "\n TableName = " + getTableName() );
-        str.append( "\n State = " + getState() );
-        return str.toString();
-    }
-
-}
+package org.apache.jcs.auxiliary.disk.jdbc;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.io.Serializable;
+
+/**
+ * This is used by various elemetns of the JDBC disk cache to indicate the
+ * status of a table. The MySQL disk cache, for instance, marks the status as
+ * optimizing when a scheduled optimizatio is taking place. This allows the
+ * cache to balk rather than block during long running optimizations.
+ * <p>
+ * @author Aaron Smuts
+ */
+public class TableState
+    implements Serializable
+{
+    private static final long serialVersionUID = -6625081552084964885L;
+
+    private String tableName;
+
+    /**
+     * The table is free. It can be accessed and no potentially table locking
+     * jobs are running.
+     */
+    public static final int FREE = 0;
+
+    /** A potentially table locking deletion is running */
+    public static final int DELETE_RUNNING = 1;
+
+    /** A table locking optimization is running. */
+    public static final int OPTIMIZATION_RUNNING = 2;
+
+    // we might want to add error
+
+    private int state = FREE;
+
+    /**
+     * Construct a usable table state.
+     * <p>
+     * @param tableName
+     */
+    public TableState( String tableName )
+    {
+        this.setTableName( tableName );
+    }
+
+    /**
+     * @param tableName
+     *            The tableName to set.
+     */
+    public void setTableName( String tableName )
+    {
+        this.tableName = tableName;
+    }
+
+    /**
+     * @return Returns the tableName.
+     */
+    public String getTableName()
+    {
+        return tableName;
+    }
+
+    /**
+     * @param state
+     *            The state to set.
+     */
+    public void setState( int state )
+    {
+        this.state = state;
+    }
+
+    /**
+     * @return Returns the state.
+     */
+    public int getState()
+    {
+        return state;
+    }
+
+    /**
+     * Write out the values for debugging purposes.
+     * <p>
+     * @return String
+     */
+    public String toString()
+    {
+        StringBuffer str = new StringBuffer();
+        str.append( "TableState " );
+        str.append( "\n TableName = " + getTableName() );
+        str.append( "\n State = " + getState() );
+        return str.toString();
+    }
+
+}

Modified: jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/jdbc/hsql/HSQLDiskCacheFactory.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/jdbc/hsql/HSQLDiskCacheFactory.java?view=diff&rev=536904&r1=536903&r2=536904
==============================================================================
--- jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/jdbc/hsql/HSQLDiskCacheFactory.java (original)
+++ jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/jdbc/hsql/HSQLDiskCacheFactory.java Thu May 10 09:03:42 2007
@@ -1,208 +1,216 @@
-package org.apache.jcs.auxiliary.disk.jdbc.hsql;
-
-/*
- * Copyright 2001-2004 The Apache Software Foundation. Licensed under the Apache
- * License, Version 2.0 (the "License") you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law
- * or agreed to in writing, software distributed under the License is
- * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the specific language
- * governing permissions and limitations under the License.
- */
-
-import java.sql.Connection;
-import java.sql.DriverManager;
-import java.sql.SQLException;
-import java.sql.Statement;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Set;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.jcs.auxiliary.AuxiliaryCache;
-import org.apache.jcs.auxiliary.AuxiliaryCacheAttributes;
-import org.apache.jcs.auxiliary.AuxiliaryCacheFactory;
-import org.apache.jcs.auxiliary.disk.jdbc.JDBCDiskCacheAttributes;
-import org.apache.jcs.auxiliary.disk.jdbc.JDBCDiskCacheManager;
-import org.apache.jcs.engine.behavior.ICompositeCacheManager;
-
-/**
- * This factory should create mysql disk caches.
- * <p>
- * @author Aaron Smuts
- */
-public class HSQLDiskCacheFactory
-    implements AuxiliaryCacheFactory
-{
-    private final static Log log = LogFactory.getLog( HSQLDiskCacheFactory.class );
-
-    private String name = "HSQLDiskCacheFactory";
-
-    private Set databases = Collections.synchronizedSet( new HashSet() );
-
-    /**
-     * This factory method should create an instance of the mysqlcache.
-     */
-    public AuxiliaryCache createCache( AuxiliaryCacheAttributes rawAttr, ICompositeCacheManager arg1 )
-    {
-        JDBCDiskCacheManager mgr = JDBCDiskCacheManager.getInstance( (JDBCDiskCacheAttributes) rawAttr );
-        try
-        {
-            setupDatabase( (JDBCDiskCacheAttributes) rawAttr );
-        }
-        catch ( Exception e )
-        {
-            // TODO we may not want to try and get the cache at this point.
-            log.error( "Problem setting up database.", e );
-        }
-        return mgr.getCache( (JDBCDiskCacheAttributes) rawAttr );
-    }
-
-    /**
-     * The name of the factory.
-     */
-    public void setName( String nameArg )
-    {
-        name = nameArg;
-    }
-
-    /**
-     * Returns the display name
-     */
-    public String getName()
-    {
-        return name;
-    }
-
-    /**
-     * Creates the database if it doesn't exist, registers the driver class,
-     * etc.
-     * <p>
-     * @param attributes
-     * @throws Exception
-     */
-    protected void setupDatabase( JDBCDiskCacheAttributes attributes )
-        throws Exception
-    {
-        if ( attributes == null )
-        {
-            throw new Exception( "The attributes are null." );
-        }
-
-        // url should start with "jdbc:hsqldb:"
-        String database = attributes.getUrl() + attributes.getDatabase();
-
-        if ( databases.contains( database ) )
-        {
-            if ( log.isInfoEnabled() )
-            {
-                log.info( "We already setup database [" + database + "]" );
-            }
-            return;
-        }
-
-        // TODO get this from the attributes.
-        System.setProperty( "hsqldb.cache_scale", "8" );
-
-        // "org.hsqldb.jdbcDriver"
-        String driver = attributes.getDriverClassName();
-        // "sa"
-        String user = attributes.getUserName();
-        // ""
-        String password = attributes.getPassword();
-
-        new org.hsqldb.jdbcDriver();
-        try
-        {
-            Class.forName( driver ).newInstance();
-
-            Connection cConn = DriverManager.getConnection( database, user, password );
-
-            setupTABLE( cConn, attributes.getTableName() );
-
-            if ( log.isInfoEnabled() )
-            {
-                log.info( "Finished setting up database [" + database + "]" );
-            }
-
-            databases.add( database );
-        }
-        catch ( Exception e )
-        {
-            log.error( "Fatal problem setting up the database.", e );
-        }
-    }
-
-    /**
-     * SETUP TABLE FOR CACHE
-     * <p>
-     * @param cConn
-     * @param tableName
-     */
-    private void setupTABLE( Connection cConn, String tableName )
-    {
-        boolean newT = true;
-
-        // TODO make the cached nature of the table configurable
-        StringBuffer createSql = new StringBuffer();
-        createSql.append( "CREATE CACHED TABLE " + tableName );
-        createSql.append( "( " );
-        createSql.append( "CACHE_KEY             VARCHAR(250)          NOT NULL, " );
-        createSql.append( "REGION                VARCHAR(250)          NOT NULL, " );
-        createSql.append( "ELEMENT               BINARY, " );
-        createSql.append( "CREATE_TIME           DATE, " );
-        createSql.append( "CREATE_TIME_SECONDS   BIGINT, " );
-        createSql.append( "MAX_LIFE_SECONDS      BIGINT, " );
-        createSql.append( "SYSTEM_EXPIRE_TIME_SECONDS      BIGINT, " );
-        createSql.append( "IS_ETERNAL            CHAR(1), " );
-        createSql.append( "PRIMARY KEY (CACHE_KEY, REGION) " );
-        createSql.append( ");" );
-
-        Statement sStatement = null;
-        try
-        {
-            sStatement = cConn.createStatement();
-        }
-        catch ( SQLException e )
-        {
-            log.error( "problem creating a statement.", e );
-        }
-
-        try
-        {
-            sStatement.executeQuery( createSql.toString() );
-            sStatement.close();
-        }
-        catch ( SQLException e )
-        {
-            if ( e.toString().indexOf( "already exists" ) != -1 )
-            {
-                newT = false;
-            }
-            else
-            {
-                log.error( "Problem creating table.", e );
-            }
-        }
-
-        // TODO create an index on SYSTEM_EXPIRE_TIME_SECONDS
-        String setupData[] = { "create index iKEY on " + tableName + " (CACHE_KEY, REGION)" };
-
-        if ( newT )
-        {
-            for ( int i = 1; i < setupData.length; i++ )
-            {
-                try
-                {
-                    sStatement.executeQuery( setupData[i] );
-                }
-                catch ( SQLException e )
-                {
-                    log.error( "Exception caught when creating index." + e );
-                }
-            }
-        }
-    }
-}
+package org.apache.jcs.auxiliary.disk.jdbc.hsql;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.jcs.auxiliary.AuxiliaryCache;
+import org.apache.jcs.auxiliary.AuxiliaryCacheAttributes;
+import org.apache.jcs.auxiliary.AuxiliaryCacheFactory;
+import org.apache.jcs.auxiliary.disk.jdbc.JDBCDiskCacheAttributes;
+import org.apache.jcs.auxiliary.disk.jdbc.JDBCDiskCacheManager;
+import org.apache.jcs.engine.behavior.ICompositeCacheManager;
+
+/**
+ * This factory should create mysql disk caches.
+ * <p>
+ * @author Aaron Smuts
+ */
+public class HSQLDiskCacheFactory
+    implements AuxiliaryCacheFactory
+{
+    private final static Log log = LogFactory.getLog( HSQLDiskCacheFactory.class );
+
+    private String name = "HSQLDiskCacheFactory";
+
+    private Set databases = Collections.synchronizedSet( new HashSet() );
+
+    /**
+     * This factory method should create an instance of the mysqlcache.
+     */
+    public AuxiliaryCache createCache( AuxiliaryCacheAttributes rawAttr, ICompositeCacheManager arg1 )
+    {
+        JDBCDiskCacheManager mgr = JDBCDiskCacheManager.getInstance( (JDBCDiskCacheAttributes) rawAttr );
+        try
+        {
+            setupDatabase( (JDBCDiskCacheAttributes) rawAttr );
+        }
+        catch ( Exception e )
+        {
+            // TODO we may not want to try and get the cache at this point.
+            log.error( "Problem setting up database.", e );
+        }
+        return mgr.getCache( (JDBCDiskCacheAttributes) rawAttr );
+    }
+
+    /**
+     * The name of the factory.
+     */
+    public void setName( String nameArg )
+    {
+        name = nameArg;
+    }
+
+    /**
+     * Returns the display name
+     */
+    public String getName()
+    {
+        return name;
+    }
+
+    /**
+     * Creates the database if it doesn't exist, registers the driver class,
+     * etc.
+     * <p>
+     * @param attributes
+     * @throws Exception
+     */
+    protected void setupDatabase( JDBCDiskCacheAttributes attributes )
+        throws Exception
+    {
+        if ( attributes == null )
+        {
+            throw new Exception( "The attributes are null." );
+        }
+
+        // url should start with "jdbc:hsqldb:"
+        String database = attributes.getUrl() + attributes.getDatabase();
+
+        if ( databases.contains( database ) )
+        {
+            if ( log.isInfoEnabled() )
+            {
+                log.info( "We already setup database [" + database + "]" );
+            }
+            return;
+        }
+
+        // TODO get this from the attributes.
+        System.setProperty( "hsqldb.cache_scale", "8" );
+
+        // "org.hsqldb.jdbcDriver"
+        String driver = attributes.getDriverClassName();
+        // "sa"
+        String user = attributes.getUserName();
+        // ""
+        String password = attributes.getPassword();
+
+        new org.hsqldb.jdbcDriver();
+        try
+        {
+            Class.forName( driver ).newInstance();
+
+            Connection cConn = DriverManager.getConnection( database, user, password );
+
+            setupTABLE( cConn, attributes.getTableName() );
+
+            if ( log.isInfoEnabled() )
+            {
+                log.info( "Finished setting up database [" + database + "]" );
+            }
+
+            databases.add( database );
+        }
+        catch ( Exception e )
+        {
+            log.error( "Fatal problem setting up the database.", e );
+        }
+    }
+
+    /**
+     * SETUP TABLE FOR CACHE
+     * <p>
+     * @param cConn
+     * @param tableName
+     */
+    private void setupTABLE( Connection cConn, String tableName )
+    {
+        boolean newT = true;
+
+        // TODO make the cached nature of the table configurable
+        StringBuffer createSql = new StringBuffer();
+        createSql.append( "CREATE CACHED TABLE " + tableName );
+        createSql.append( "( " );
+        createSql.append( "CACHE_KEY             VARCHAR(250)          NOT NULL, " );
+        createSql.append( "REGION                VARCHAR(250)          NOT NULL, " );
+        createSql.append( "ELEMENT               BINARY, " );
+        createSql.append( "CREATE_TIME           DATE, " );
+        createSql.append( "CREATE_TIME_SECONDS   BIGINT, " );
+        createSql.append( "MAX_LIFE_SECONDS      BIGINT, " );
+        createSql.append( "SYSTEM_EXPIRE_TIME_SECONDS      BIGINT, " );
+        createSql.append( "IS_ETERNAL            CHAR(1), " );
+        createSql.append( "PRIMARY KEY (CACHE_KEY, REGION) " );
+        createSql.append( ");" );
+
+        Statement sStatement = null;
+        try
+        {
+            sStatement = cConn.createStatement();
+        }
+        catch ( SQLException e )
+        {
+            log.error( "problem creating a statement.", e );
+        }
+
+        try
+        {
+            sStatement.executeQuery( createSql.toString() );
+            sStatement.close();
+        }
+        catch ( SQLException e )
+        {
+            if ( e.toString().indexOf( "already exists" ) != -1 )
+            {
+                newT = false;
+            }
+            else
+            {
+                log.error( "Problem creating table.", e );
+            }
+        }
+
+        // TODO create an index on SYSTEM_EXPIRE_TIME_SECONDS
+        String setupData[] = { "create index iKEY on " + tableName + " (CACHE_KEY, REGION)" };
+
+        if ( newT )
+        {
+            for ( int i = 1; i < setupData.length; i++ )
+            {
+                try
+                {
+                    sStatement.executeQuery( setupData[i] );
+                }
+                catch ( SQLException e )
+                {
+                    log.error( "Exception caught when creating index." + e );
+                }
+            }
+        }
+    }
+}

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?view=diff&rev=536904&r1=536903&r2=536904
==============================================================================
--- 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 Thu May 10 09:03:42 2007
@@ -1,104 +1,123 @@
-package org.apache.jcs.auxiliary.disk.jdbc.mysql;
-
-import java.io.Serializable;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.jcs.auxiliary.disk.jdbc.JDBCDiskCache;
-import org.apache.jcs.auxiliary.disk.jdbc.TableState;
-import org.apache.jcs.engine.behavior.ICacheElement;
-
-/**
- * The MySQLDiskCache extends the core JDBCDiskCache.
- * <p>
- * Although the generic JDBC Disk Cache can be used for MySQL, the MySQL JDBC Disk Cache has
- * additional features, such as table optimization that are particular to MySQL.
- * <p>
- * @author Aaron Smuts
- */
-public class MySQLDiskCache
-    extends JDBCDiskCache
-{
-    private static final long serialVersionUID = -7169488308515823491L;
-
-    private final static Log log = LogFactory.getLog( MySQLDiskCache.class );
-
-    MySQLDiskCacheAttributes mySQLDiskCacheAttributes;
-
-    /**
-     * Delegates to the super and makes use of the MySQL specific parameters used for scheduled
-     * optimization.
-     * <p>
-     * @param attributes
-     * @param tableState
-     */
-    public MySQLDiskCache( MySQLDiskCacheAttributes attributes, TableState tableState )
-    {
-        super( attributes, tableState );
-
-        mySQLDiskCacheAttributes = attributes;
-
-        if ( log.isDebugEnabled() )
-        {
-            log.debug( "MySQLDiskCacheAttributes = " + attributes );
-        }
-    }
-
-    /**
-     * This delegates to the generic JDBC disk cache. If we are currently optimizing, then this
-     * method will balk and return null.
-     * <p>
-     * @param key Key to locate value for.
-     * @return An object matching key, or null.
-     */
-    public ICacheElement doGet( Serializable key )
-    {
-        if ( this.getTableState().getState() == TableState.OPTIMIZATION_RUNNING )
-        {
-            if ( this.mySQLDiskCacheAttributes.isBalkDuringOptimization() )
-            {
-                return null;
-            }
-        }
-        return super.doGet( key );
-    }
-
-    /**
-     * This delegates to the generic JDBC disk cache. If we are currently optimizing, then this
-     * method will balk and do nothing.
-     * <p>
-     * @param element
-     */
-    public void doUpdate( ICacheElement element )
-    {
-        if ( this.getTableState().getState() == TableState.OPTIMIZATION_RUNNING )
-        {
-            if ( this.mySQLDiskCacheAttributes.isBalkDuringOptimization() )
-            {
-                return;
-            }
-        }
-        super.doUpdate( element );
-    }
-
-    /**
-     * Removed the expired. (now - create time) > max life seconds * 1000
-     * <p>
-     * If we are currently optimizing, then this method will balk and do nothing.
-     * <p>
-     * TODO consider blocking and trying again.
-     * <p>
-     * @return the number deleted
-     */
-    protected int deleteExpired()
-    {
-        if ( this.getTableState().getState() == TableState.OPTIMIZATION_RUNNING )
-        {
-            if ( this.mySQLDiskCacheAttributes.isBalkDuringOptimization() )
-            {
-                return -1;
-            }
-        }
-        return super.deleteExpired();
-    }
-}
+package org.apache.jcs.auxiliary.disk.jdbc.mysql;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.io.Serializable;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.jcs.auxiliary.disk.jdbc.JDBCDiskCache;
+import org.apache.jcs.auxiliary.disk.jdbc.TableState;
+import org.apache.jcs.engine.behavior.ICacheElement;
+
+/**
+ * The MySQLDiskCache extends the core JDBCDiskCache.
+ * <p>
+ * Although the generic JDBC Disk Cache can be used for MySQL, the MySQL JDBC Disk Cache has
+ * additional features, such as table optimization that are particular to MySQL.
+ * <p>
+ * @author Aaron Smuts
+ */
+public class MySQLDiskCache
+    extends JDBCDiskCache
+{
+    private static final long serialVersionUID = -7169488308515823491L;
+
+    private final static Log log = LogFactory.getLog( MySQLDiskCache.class );
+
+    MySQLDiskCacheAttributes mySQLDiskCacheAttributes;
+
+    /**
+     * Delegates to the super and makes use of the MySQL specific parameters used for scheduled
+     * optimization.
+     * <p>
+     * @param attributes
+     * @param tableState
+     */
+    public MySQLDiskCache( MySQLDiskCacheAttributes attributes, TableState tableState )
+    {
+        super( attributes, tableState );
+
+        mySQLDiskCacheAttributes = attributes;
+
+        if ( log.isDebugEnabled() )
+        {
+            log.debug( "MySQLDiskCacheAttributes = " + attributes );
+        }
+    }
+
+    /**
+     * This delegates to the generic JDBC disk cache. If we are currently optimizing, then this
+     * method will balk and return null.
+     * <p>
+     * @param key Key to locate value for.
+     * @return An object matching key, or null.
+     */
+    public ICacheElement doGet( Serializable key )
+    {
+        if ( this.getTableState().getState() == TableState.OPTIMIZATION_RUNNING )
+        {
+            if ( this.mySQLDiskCacheAttributes.isBalkDuringOptimization() )
+            {
+                return null;
+            }
+        }
+        return super.doGet( key );
+    }
+
+    /**
+     * This delegates to the generic JDBC disk cache. If we are currently optimizing, then this
+     * method will balk and do nothing.
+     * <p>
+     * @param element
+     */
+    public void doUpdate( ICacheElement element )
+    {
+        if ( this.getTableState().getState() == TableState.OPTIMIZATION_RUNNING )
+        {
+            if ( this.mySQLDiskCacheAttributes.isBalkDuringOptimization() )
+            {
+                return;
+            }
+        }
+        super.doUpdate( element );
+    }
+
+    /**
+     * Removed the expired. (now - create time) > max life seconds * 1000
+     * <p>
+     * If we are currently optimizing, then this method will balk and do nothing.
+     * <p>
+     * TODO consider blocking and trying again.
+     * <p>
+     * @return the number deleted
+     */
+    protected int deleteExpired()
+    {
+        if ( this.getTableState().getState() == TableState.OPTIMIZATION_RUNNING )
+        {
+            if ( this.mySQLDiskCacheAttributes.isBalkDuringOptimization() )
+            {
+                return -1;
+            }
+        }
+        return super.deleteExpired();
+    }
+}

Modified: jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/jdbc/mysql/MySQLDiskCacheAttributes.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/jdbc/mysql/MySQLDiskCacheAttributes.java?view=diff&rev=536904&r1=536903&r2=536904
==============================================================================
--- jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/jdbc/mysql/MySQLDiskCacheAttributes.java (original)
+++ jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/jdbc/mysql/MySQLDiskCacheAttributes.java Thu May 10 09:03:42 2007
@@ -1,84 +1,103 @@
-package org.apache.jcs.auxiliary.disk.jdbc.mysql;
-
-import org.apache.jcs.auxiliary.disk.jdbc.JDBCDiskCacheAttributes;
-
-/**
- * This has additional attributes that are particular to the MySQL disk cache.
- * <p>
- * @author Aaron Smuts
- */
-public class MySQLDiskCacheAttributes
-    extends JDBCDiskCacheAttributes
-{
-    private static final long serialVersionUID = -6535808344813320061L;    
-    
-    /**
-     * For now this is a simple comma delimited list of HH:MM:SS times to optimize
-     * the table. If none is supplied, then no optimizations will be performed.
-     * <p>
-     * In the future we can add a chron like scheduling system. This is to meet
-     * a pressing current need.
-     * <p>
-     * 03:01,15:00 will cause the optimizer to run at 3 am and at 3 pm.
-     */
-    private String optimizationSchedule = null;
-    
-    /**
-     * If true, we will balk, that is return null during optimization rather than block.
-     */
-    public static final boolean DEFAULT_BALK_DURING_OPTIMIZATION = true;
-    
-    /**
-     * If true, we will balk, that is return null during optimization rather than block.
-     * <p>
-     * <a href="http://en.wikipedia.org/wiki/Balking_pattern">Balking</a>
-     */
-    private boolean balkDuringOptimization = DEFAULT_BALK_DURING_OPTIMIZATION;
-
-    /**
-     * @param optimizationSchedule The optimizationSchedule to set.
-     */
-    public void setOptimizationSchedule( String optimizationSchedule )
-    {
-        this.optimizationSchedule = optimizationSchedule;
-    }
-
-    /**
-     * @return Returns the optimizationSchedule.
-     */
-    public String getOptimizationSchedule()
-    {
-        return optimizationSchedule;
-    }
-
-    /**
-     * @param balkDuringOptimization The balkDuringOptimization to set.
-     */
-    public void setBalkDuringOptimization( boolean balkDuringOptimization )
-    {
-        this.balkDuringOptimization = balkDuringOptimization;
-    }
-
-    /**
-     * Should we return null while optimizing the table.
-     * <p>
-     * @return Returns the balkDuringOptimization.
-     */
-    public boolean isBalkDuringOptimization()
-    {
-        return balkDuringOptimization;
-    }
-    
-    /**
-     * For debugging.
-     */
-    public String toString()
-    {
-        StringBuffer buf = new StringBuffer();
-        buf.append( "\nMySQLDiskCacheAttributes" );
-        buf.append( "\n OptimizationSchedule [" + getOptimizationSchedule() + "]" );
-        buf.append( "\n BalkDuringOptimization [" + isBalkDuringOptimization() + "]" );
-        buf.append( super.toString() );
-        return buf.toString();
-    }    
-}
+package org.apache.jcs.auxiliary.disk.jdbc.mysql;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.jcs.auxiliary.disk.jdbc.JDBCDiskCacheAttributes;
+
+/**
+ * This has additional attributes that are particular to the MySQL disk cache.
+ * <p>
+ * @author Aaron Smuts
+ */
+public class MySQLDiskCacheAttributes
+    extends JDBCDiskCacheAttributes
+{
+    private static final long serialVersionUID = -6535808344813320061L;
+
+    /**
+     * For now this is a simple comma delimited list of HH:MM:SS times to optimize
+     * the table. If none is supplied, then no optimizations will be performed.
+     * <p>
+     * In the future we can add a chron like scheduling system. This is to meet
+     * a pressing current need.
+     * <p>
+     * 03:01,15:00 will cause the optimizer to run at 3 am and at 3 pm.
+     */
+    private String optimizationSchedule = null;
+
+    /**
+     * If true, we will balk, that is return null during optimization rather than block.
+     */
+    public static final boolean DEFAULT_BALK_DURING_OPTIMIZATION = true;
+
+    /**
+     * If true, we will balk, that is return null during optimization rather than block.
+     * <p>
+     * <a href="http://en.wikipedia.org/wiki/Balking_pattern">Balking</a>
+     */
+    private boolean balkDuringOptimization = DEFAULT_BALK_DURING_OPTIMIZATION;
+
+    /**
+     * @param optimizationSchedule The optimizationSchedule to set.
+     */
+    public void setOptimizationSchedule( String optimizationSchedule )
+    {
+        this.optimizationSchedule = optimizationSchedule;
+    }
+
+    /**
+     * @return Returns the optimizationSchedule.
+     */
+    public String getOptimizationSchedule()
+    {
+        return optimizationSchedule;
+    }
+
+    /**
+     * @param balkDuringOptimization The balkDuringOptimization to set.
+     */
+    public void setBalkDuringOptimization( boolean balkDuringOptimization )
+    {
+        this.balkDuringOptimization = balkDuringOptimization;
+    }
+
+    /**
+     * Should we return null while optimizing the table.
+     * <p>
+     * @return Returns the balkDuringOptimization.
+     */
+    public boolean isBalkDuringOptimization()
+    {
+        return balkDuringOptimization;
+    }
+
+    /**
+     * For debugging.
+     */
+    public String toString()
+    {
+        StringBuffer buf = new StringBuffer();
+        buf.append( "\nMySQLDiskCacheAttributes" );
+        buf.append( "\n OptimizationSchedule [" + getOptimizationSchedule() + "]" );
+        buf.append( "\n BalkDuringOptimization [" + isBalkDuringOptimization() + "]" );
+        buf.append( super.toString() );
+        return buf.toString();
+    }
+}

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?view=diff&rev=536904&r1=536903&r2=536904
==============================================================================
--- 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 Thu May 10 09:03:42 2007
@@ -1,53 +1,61 @@
-package org.apache.jcs.auxiliary.disk.jdbc.mysql;
-
-/*
- * Copyright 2001-2004 The Apache Software Foundation. Licensed under the Apache
- * License, Version 2.0 (the "License") you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law
- * or agreed to in writing, software distributed under the License is
- * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the specific language
- * governing permissions and limitations under the License.
- */
-
-import org.apache.jcs.auxiliary.AuxiliaryCache;
-import org.apache.jcs.auxiliary.AuxiliaryCacheAttributes;
-import org.apache.jcs.auxiliary.AuxiliaryCacheFactory;
-import org.apache.jcs.engine.behavior.ICompositeCacheManager;
-
-/**
- * This factory should create mysql disk caches.
- * <p>
- * @author Aaron Smuts
- */
-public class MySQLDiskCacheFactory
-    implements AuxiliaryCacheFactory
-{
-    private String name = "JDBCDiskCacheFactory";
-
-    /**
-     * This factory method should create an instance of the mysqlcache.
-     */
-    public AuxiliaryCache createCache( AuxiliaryCacheAttributes rawAttr, ICompositeCacheManager arg1 )
-    {
-        MySQLDiskCacheManager mgr = MySQLDiskCacheManager.getInstance( (MySQLDiskCacheAttributes) rawAttr );
-        return mgr.getCache( (MySQLDiskCacheAttributes) rawAttr );
-    }
-
-    /**
-     * The name of the factory.
-     */
-    public void setName( String nameArg )
-    {
-        name = nameArg;
-    }
-
-    /**
-     * Returns the display name
-     */
-    public String getName()
-    {
-        return name;
-    }
-}
+package org.apache.jcs.auxiliary.disk.jdbc.mysql;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.jcs.auxiliary.AuxiliaryCache;
+import org.apache.jcs.auxiliary.AuxiliaryCacheAttributes;
+import org.apache.jcs.auxiliary.AuxiliaryCacheFactory;
+import org.apache.jcs.engine.behavior.ICompositeCacheManager;
+
+/**
+ * This factory should create mysql disk caches.
+ * <p>
+ * @author Aaron Smuts
+ */
+public class MySQLDiskCacheFactory
+    implements AuxiliaryCacheFactory
+{
+    private String name = "JDBCDiskCacheFactory";
+
+    /**
+     * This factory method should create an instance of the mysqlcache.
+     */
+    public AuxiliaryCache createCache( AuxiliaryCacheAttributes rawAttr, ICompositeCacheManager arg1 )
+    {
+        MySQLDiskCacheManager mgr = MySQLDiskCacheManager.getInstance( (MySQLDiskCacheAttributes) rawAttr );
+        return mgr.getCache( (MySQLDiskCacheAttributes) rawAttr );
+    }
+
+    /**
+     * The name of the factory.
+     */
+    public void setName( String nameArg )
+    {
+        name = nameArg;
+    }
+
+    /**
+     * Returns the display name
+     */
+    public String getName()
+    {
+        return name;
+    }
+}



---------------------------------------------------------------------
To unsubscribe, e-mail: jcs-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jcs-dev-help@jakarta.apache.org