| 1 |
package org.apache.commons.jcs3.auxiliary.disk.jdbc.mysql; |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
import java.sql.SQLException; |
| 23 |
import java.util.Map; |
| 24 |
|
| 25 |
import org.apache.commons.jcs3.auxiliary.disk.jdbc.JDBCDiskCache; |
| 26 |
import org.apache.commons.jcs3.auxiliary.disk.jdbc.TableState; |
| 27 |
import org.apache.commons.jcs3.auxiliary.disk.jdbc.dsfactory.DataSourceFactory; |
| 28 |
import org.apache.commons.jcs3.engine.behavior.ICacheElement; |
| 29 |
import org.apache.commons.jcs3.log.Log; |
| 30 |
import org.apache.commons.jcs3.log.LogManager; |
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
public class MySQLDiskCache<K, V> |
| 40 |
extends JDBCDiskCache<K, V> |
| 41 |
{ |
| 42 |
|
| 43 |
private static final Log log = LogManager.getLog( MySQLDiskCache.class ); |
| 44 |
|
| 45 |
|
| 46 |
private final MySQLDiskCacheAttributes mySQLDiskCacheAttributes; |
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
public MySQLDiskCache( final MySQLDiskCacheAttributes attributes, final DataSourceFactory dsFactory, |
| 58 |
final TableState tableState) throws SQLException |
| 59 |
{ |
| 60 |
super( attributes, dsFactory, tableState); |
| 61 |
|
| 62 |
mySQLDiskCacheAttributes = attributes; |
| 63 |
|
| 64 |
log.debug( "MySQLDiskCacheAttributes = {0}", attributes ); |
| 65 |
} |
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
@Override |
| 75 |
protected ICacheElement<K, V> processGet( final K key ) |
| 76 |
{ |
| 77 |
if (this.getTableState().getState() == TableState.OPTIMIZATION_RUNNING && |
| 78 |
this.mySQLDiskCacheAttributes.isBalkDuringOptimization()) |
| 79 |
{ |
| 80 |
return null; |
| 81 |
} |
| 82 |
return super.processGet( key ); |
| 83 |
} |
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
@Override |
| 93 |
protected Map<K, ICacheElement<K, V>> processGetMatching( final String pattern ) |
| 94 |
{ |
| 95 |
if (this.getTableState().getState() == TableState.OPTIMIZATION_RUNNING && |
| 96 |
this.mySQLDiskCacheAttributes.isBalkDuringOptimization()) |
| 97 |
{ |
| 98 |
return null; |
| 99 |
} |
| 100 |
return super.processGetMatching( pattern ); |
| 101 |
} |
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
@Override |
| 108 |
public String constructLikeParameterFromPattern( final String pattern ) |
| 109 |
{ |
| 110 |
String likePattern = pattern.replace( ".+", "%" ); |
| 111 |
likePattern = likePattern.replace( ".", "_" ); |
| 112 |
|
| 113 |
log.debug( "pattern = [{0}]", likePattern ); |
| 114 |
|
| 115 |
return likePattern; |
| 116 |
} |
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
@Override |
| 125 |
protected void processUpdate( final ICacheElement<K, V> element ) |
| 126 |
{ |
| 127 |
if (this.getTableState().getState() == TableState.OPTIMIZATION_RUNNING && |
| 128 |
this.mySQLDiskCacheAttributes.isBalkDuringOptimization()) |
| 129 |
{ |
| 130 |
return; |
| 131 |
} |
| 132 |
super.processUpdate( element ); |
| 133 |
} |
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
@Override |
| 145 |
protected int deleteExpired() |
| 146 |
{ |
| 147 |
if (this.getTableState().getState() == TableState.OPTIMIZATION_RUNNING && |
| 148 |
this.mySQLDiskCacheAttributes.isBalkDuringOptimization()) |
| 149 |
{ |
| 150 |
return -1; |
| 151 |
} |
| 152 |
return super.deleteExpired(); |
| 153 |
} |
| 154 |
} |