1 package org.apache.commons.jcs.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.jcs.auxiliary.disk.jdbc.JDBCDiskCache;
26 import org.apache.commons.jcs.auxiliary.disk.jdbc.TableState;
27 import org.apache.commons.jcs.auxiliary.disk.jdbc.dsfactory.DataSourceFactory;
28 import org.apache.commons.jcs.engine.behavior.ICacheElement;
29 import org.apache.commons.jcs.engine.behavior.ICompositeCacheManager;
30 import org.apache.commons.logging.Log;
31 import org.apache.commons.logging.LogFactory;
32
33
34
35
36
37
38
39
40
41 public class MySQLDiskCache<K, V>
42 extends JDBCDiskCache<K, V>
43 {
44
45 private static final Log log = LogFactory.getLog( MySQLDiskCache.class );
46
47
48 private final MySQLDiskCacheAttributes mySQLDiskCacheAttributes;
49
50
51
52
53
54
55
56
57
58
59
60 public MySQLDiskCache( MySQLDiskCacheAttributes attributes, DataSourceFactory dsFactory,
61 TableState tableState, ICompositeCacheManager compositeCacheManager ) throws SQLException
62 {
63 super( attributes, dsFactory, tableState, compositeCacheManager );
64
65 mySQLDiskCacheAttributes = attributes;
66
67 if ( log.isDebugEnabled() )
68 {
69 log.debug( "MySQLDiskCacheAttributes = " + attributes );
70 }
71 }
72
73
74
75
76
77
78
79
80 @Override
81 protected ICacheElement<K, V> processGet( K key )
82 {
83 if ( this.getTableState().getState() == TableState.OPTIMIZATION_RUNNING )
84 {
85 if ( this.mySQLDiskCacheAttributes.isBalkDuringOptimization() )
86 {
87 return null;
88 }
89 }
90 return super.processGet( key );
91 }
92
93
94
95
96
97
98
99
100 @Override
101 protected Map<K, ICacheElement<K, V>> processGetMatching( String pattern )
102 {
103 if ( this.getTableState().getState() == TableState.OPTIMIZATION_RUNNING )
104 {
105 if ( this.mySQLDiskCacheAttributes.isBalkDuringOptimization() )
106 {
107 return null;
108 }
109 }
110 return super.processGetMatching( pattern );
111 }
112
113
114
115
116
117 @Override
118 public String constructLikeParameterFromPattern( String pattern )
119 {
120 String likePattern = pattern.replaceAll( "\\.\\+", "%" );
121 likePattern = likePattern.replaceAll( "\\.", "_" );
122
123 if ( log.isDebugEnabled() )
124 {
125 log.debug( "pattern = [" + likePattern + "]" );
126 }
127
128 return likePattern;
129 }
130
131
132
133
134
135
136
137 @Override
138 protected void processUpdate( ICacheElement<K, V> element )
139 {
140 if ( this.getTableState().getState() == TableState.OPTIMIZATION_RUNNING )
141 {
142 if ( this.mySQLDiskCacheAttributes.isBalkDuringOptimization() )
143 {
144 return;
145 }
146 }
147 super.processUpdate( element );
148 }
149
150
151
152
153
154
155
156
157
158
159 @Override
160 protected int deleteExpired()
161 {
162 if ( this.getTableState().getState() == TableState.OPTIMIZATION_RUNNING )
163 {
164 if ( this.mySQLDiskCacheAttributes.isBalkDuringOptimization() )
165 {
166 return -1;
167 }
168 }
169 return super.deleteExpired();
170 }
171 }