jakarta-jcs-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Alistair Forbes" <forbes...@googlemail.com>
Subject JDBC cache
Date Tue, 04 Jul 2006 11:07:26 GMT
Hi,

I tried out the JDBC cache. The assumption is that the key is always a
String, and will always result in a class cast exception if this is not the
case.

I think it would be better to use key.toString() instead of (String) key, so
that more complex key objects (other than String) can be used with the JDBC
cache. This change should be compatible with existing implementations.

===================================================================
--- src/java/org/apache/jcs/auxiliary/disk/jdbc/JDBCDiskCache.java
(revision 418978)
+++ src/java/org/apache/jcs/auxiliary/disk/jdbc/JDBCDiskCache.java
(working copy)
@@ -239,7 +239,7 @@
                         + " values (?, ?, ?, ?, ?, ?, ?, ?)";

                     PreparedStatement psInsert = con.prepareStatement( sqlI
);
-                    psInsert.setString( 1, (String) ce.getKey() );
+                    psInsert.setString( 1, ce.getKey().toString() );
                     psInsert.setString( 2, this.getCacheName() );
                     psInsert.setBytes( 3, element );
                     psInsert.setLong( 4,
ce.getElementAttributes().getMaxLifeSeconds()
);
@@ -305,7 +305,7 @@
                     long expireTime = now + ce.getElementAttributes
().getMaxLifeSeconds();
                     psUpdate.setLong( 4, expireTime );

-                    psUpdate.setString( 5, (String) ce.getKey() );
+                    psUpdate.setString( 5, ce.getKey().toString() );
                     psUpdate.setString( 6, this.getCacheName() );
                     psUpdate.execute();
                     psUpdate.close();
@@ -371,7 +371,7 @@

             // don't select the element, since we want this to be fast.
             String sqlS = "select CACHE_KEY from " +
getJdbcDiskCacheAttributes().getTableName() + " where REGION = '"
-                + this.getCacheName() + "' and CACHE_KEY = '" + (String)
ce.getKey() + "'";
+                + this.getCacheName() + "' and CACHE_KEY = '" +
ce.getKey().toString()
+ "'";

             if ( log.isDebugEnabled() )
             {
@@ -457,7 +457,7 @@
                 {
                     psSelect = con.prepareStatement( selectString );
                     psSelect.setString( 1, this.getCacheName() );
-                    psSelect.setString( 2, (String) key );
+                    psSelect.setString( 2, key.toString() );
                     ResultSet rs = null;

                     rs = psSelect.executeQuery();
@@ -537,7 +537,7 @@
     public boolean doRemove( Serializable key )
     {
         // remove single item.
-        String sql = "delete from " +
getJdbcDiskCacheAttributes().getTableName() + " where CACHE_KEY = '" + key
+        String sql = "delete from " +
getJdbcDiskCacheAttributes().getTableName() + " where CACHE_KEY = '" +
key.toString()
             + "' and REGION = '" + this.getCacheName() + "'";

         try

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message