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