1 package org.apache.commons.jcs.auxiliary.disk.jdbc;
2
3 /*
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
19 * under the License.
20 */
21
22 import org.apache.commons.jcs.auxiliary.disk.AbstractDiskCacheAttributes;
23
24 /**
25 * The configurator will set these values based on what is in the cache.ccf file.
26 * <p>
27 * @author Aaron Smuts
28 */
29 public class JDBCDiskCacheAttributes
30 extends AbstractDiskCacheAttributes
31 {
32 /** Don't change */
33 private static final long serialVersionUID = -6535808344813320062L;
34
35 /** default */
36 private static final String DEFAULT_TABLE_NAME = "JCS_STORE";
37
38 /** DB username */
39 private String userName;
40
41 /** DB password */
42 private String password;
43
44 /** URL for the db */
45 private String url;
46
47 /** The name of the database. */
48 private String database = "";
49
50 /** The driver */
51 private String driverClassName;
52
53 /** The JNDI path. */
54 private String jndiPath;
55
56 /** The time between two JNDI lookups */
57 private long jndiTTL = 0L;
58
59 /** The table name */
60 private String tableName = DEFAULT_TABLE_NAME;
61
62 /** If false we will insert and if it fails we will update. */
63 private boolean testBeforeInsert = true;
64
65 /** This is the default limit on the maximum number of active connections. */
66 public static final int DEFAULT_MAX_ACTIVE = 10;
67
68 /** Max connections allowed */
69 private int maxActive = DEFAULT_MAX_ACTIVE;
70
71 /** This is the default setting for the cleanup routine. */
72 public static final int DEFAULT_SHRINKER_INTERVAL_SECONDS = 300;
73
74 /** How often should we remove expired. */
75 private int shrinkerIntervalSeconds = DEFAULT_SHRINKER_INTERVAL_SECONDS;
76
77 /** Should we remove expired in the background. */
78 private boolean useDiskShrinker = true;
79
80 /** The default Pool Name to which the connection pool will be keyed. */
81 public static final String DEFAULT_POOL_NAME = "jcs";
82
83 /**
84 * If a pool name is supplied, the manager will attempt to load it. It should be configured in a
85 * separate section as follows. Assuming the name is "MyPool":
86 *
87 * <pre>
88 * jcs.jdbcconnectionpool.MyPool.attributes.userName=MyUserName
89 * jcs.jdbcconnectionpool.MyPool.attributes.password=MyPassword
90 * jcs.jdbcconnectionpool.MyPool.attributes.url=MyUrl
91 * jcs.jdbcconnectionpool.MyPool.attributes.maxActive=MyMaxActive
92 * jcs.jdbcconnectionpool.MyPool.attributes.driverClassName=MyDriverClassName
93 * </pre>
94 */
95 private String connectionPoolName;
96
97 /**
98 * @param userName The userName to set.
99 */
100 public void setUserName( String userName )
101 {
102 this.userName = userName;
103 }
104
105 /**
106 * @return Returns the userName.
107 */
108 public String getUserName()
109 {
110 return userName;
111 }
112
113 /**
114 * @param password The password to set.
115 */
116 public void setPassword( String password )
117 {
118 this.password = password;
119 }
120
121 /**
122 * @return Returns the password.
123 */
124 public String getPassword()
125 {
126 return password;
127 }
128
129 /**
130 * @param url The url to set.
131 */
132 public void setUrl( String url )
133 {
134 this.url = url;
135 }
136
137 /**
138 * @return Returns the url.
139 */
140 public String getUrl()
141 {
142 return url;
143 }
144
145 /**
146 * This is appended to the url.
147 * @param database The database to set.
148 */
149 public void setDatabase( String database )
150 {
151 this.database = database;
152 }
153
154 /**
155 * @return Returns the database.
156 */
157 public String getDatabase()
158 {
159 return database;
160 }
161
162 /**
163 * @param driverClassName The driverClassName to set.
164 */
165 public void setDriverClassName( String driverClassName )
166 {
167 this.driverClassName = driverClassName;
168 }
169
170 /**
171 * @return Returns the driverClassName.
172 */
173 public String getDriverClassName()
174 {
175 return driverClassName;
176 }
177
178 /**
179 * @return the jndiPath
180 */
181 public String getJndiPath()
182 {
183 return jndiPath;
184 }
185
186 /**
187 * @param jndiPath the jndiPath to set
188 */
189 public void setJndiPath(String jndiPath)
190 {
191 this.jndiPath = jndiPath;
192 }
193
194 /**
195 * @return the jndiTTL
196 */
197 public long getJndiTTL()
198 {
199 return jndiTTL;
200 }
201
202 /**
203 * @param jndiTTL the jndiTTL to set
204 */
205 public void setJndiTTL(long jndiTTL)
206 {
207 this.jndiTTL = jndiTTL;
208 }
209
210 /**
211 * @param tableName The tableName to set.
212 */
213 public void setTableName( String tableName )
214 {
215 this.tableName = tableName;
216 }
217
218 /**
219 * @return Returns the tableName.
220 */
221 public String getTableName()
222 {
223 return tableName;
224 }
225
226 /**
227 * If this is true then the disk cache will check to see if the item already exists in the
228 * database. If it is false, it will try to insert. If the insert fails it will try to update.
229 * <p>
230 * @param testBeforeInsert The testBeforeInsert to set.
231 */
232 public void setTestBeforeInsert( boolean testBeforeInsert )
233 {
234 this.testBeforeInsert = testBeforeInsert;
235 }
236
237 /**
238 * @return Returns the testBeforeInsert.
239 */
240 public boolean isTestBeforeInsert()
241 {
242 return testBeforeInsert;
243 }
244
245 /**
246 * @param maxActive The maxActive to set.
247 */
248 public void setMaxActive( int maxActive )
249 {
250 this.maxActive = maxActive;
251 }
252
253 /**
254 * @return Returns the maxActive.
255 */
256 public int getMaxActive()
257 {
258 return maxActive;
259 }
260
261 /**
262 * @param shrinkerIntervalSecondsArg The shrinkerIntervalSeconds to set.
263 */
264 public void setShrinkerIntervalSeconds( int shrinkerIntervalSecondsArg )
265 {
266 this.shrinkerIntervalSeconds = shrinkerIntervalSecondsArg;
267 }
268
269 /**
270 * @return Returns the shrinkerIntervalSeconds.
271 */
272 public int getShrinkerIntervalSeconds()
273 {
274 return shrinkerIntervalSeconds;
275 }
276
277 /**
278 * @param useDiskShrinker The useDiskShrinker to set.
279 */
280 public void setUseDiskShrinker( boolean useDiskShrinker )
281 {
282 this.useDiskShrinker = useDiskShrinker;
283 }
284
285 /**
286 * @return Returns the useDiskShrinker.
287 */
288 public boolean isUseDiskShrinker()
289 {
290 return useDiskShrinker;
291 }
292
293 /**
294 * @param connectionPoolName the connectionPoolName to set
295 */
296 public void setConnectionPoolName( String connectionPoolName )
297 {
298 this.connectionPoolName = connectionPoolName;
299 }
300
301 /**
302 * @return the connectionPoolName
303 */
304 public String getConnectionPoolName()
305 {
306 return connectionPoolName;
307 }
308
309 /**
310 * For debugging.
311 * <p>
312 * @return debug string with most of the properties.
313 */
314 @Override
315 public String toString()
316 {
317 StringBuilder buf = new StringBuilder();
318 buf.append( "\nJDBCCacheAttributes" );
319 buf.append( "\n UserName [" + getUserName() + "]" );
320 buf.append( "\n Url [" + getUrl() + "]" );
321 buf.append( "\n Database [" + getDatabase() + "]" );
322 buf.append( "\n DriverClassName [" + getDriverClassName() + "]" );
323 buf.append( "\n TableName [" + getTableName() + "]" );
324 buf.append( "\n TestBeforeInsert [" + isTestBeforeInsert() + "]" );
325 buf.append( "\n MaxActive [" + getMaxActive() + "]" );
326 buf.append( "\n AllowRemoveAll [" + isAllowRemoveAll() + "]" );
327 buf.append( "\n ShrinkerIntervalSeconds [" + getShrinkerIntervalSeconds() + "]" );
328 buf.append( "\n useDiskShrinker [" + isUseDiskShrinker() + "]" );
329 return buf.toString();
330 }
331 }