001package org.apache.commons.jcs3.auxiliary.disk.jdbc;
002
003/*
004 * Licensed to the Apache Software Foundation (ASF) under one
005 * or more contributor license agreements.  See the NOTICE file
006 * distributed with this work for additional information
007 * regarding copyright ownership.  The ASF licenses this file
008 * to you under the Apache License, Version 2.0 (the
009 * "License"); you may not use this file except in compliance
010 * with the License.  You may obtain a copy of the License at
011 *
012 *   http://www.apache.org/licenses/LICENSE-2.0
013 *
014 * Unless required by applicable law or agreed to in writing,
015 * software distributed under the License is distributed on an
016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017 * KIND, either express or implied.  See the License for the
018 * specific language governing permissions and limitations
019 * under the License.
020 */
021
022import org.apache.commons.jcs3.auxiliary.disk.AbstractDiskCacheAttributes;
023
024/**
025 * The configurator will set these values based on what is in the cache.ccf file.
026 */
027public class JDBCDiskCacheAttributes
028    extends AbstractDiskCacheAttributes
029{
030    /** Don't change */
031    private static final long serialVersionUID = -6535808344813320062L;
032
033    /** default */
034    private static final String DEFAULT_TABLE_NAME = "JCS_STORE";
035
036    /** DB username */
037    private String userName;
038
039    /** DB password */
040    private String password;
041
042    /** URL for the db */
043    private String url;
044
045    /** The name of the database. */
046    private String database = "";
047
048    /** The driver */
049    private String driverClassName;
050
051    /** The JNDI path. */
052    private String jndiPath;
053
054    /** The time between two JNDI lookups */
055    private long jndiTTL;
056
057    /** The table name */
058    private String tableName = DEFAULT_TABLE_NAME;
059
060    /** If false we will insert and if it fails we will update. */
061    private boolean testBeforeInsert = true;
062
063    /** This is the default limit on the maximum number of active connections. */
064    public static final int DEFAULT_MAX_TOTAL = 10;
065
066    /** Max connections allowed */
067    private int maxTotal = DEFAULT_MAX_TOTAL;
068
069    /** This is the default setting for the cleanup routine. */
070    public static final int DEFAULT_SHRINKER_INTERVAL_SECONDS = 300;
071
072    /** How often should we remove expired. */
073    private int shrinkerIntervalSeconds = DEFAULT_SHRINKER_INTERVAL_SECONDS;
074
075    /** Should we remove expired in the background. */
076    private boolean useDiskShrinker = true;
077
078    /** The default Pool Name to which the connection pool will be keyed. */
079    public static final String DEFAULT_POOL_NAME = "jcs";
080
081    /**
082     * If a pool name is supplied, the manager will attempt to load it. It should be configured in a
083     * separate section as follows. Assuming the name is "MyPool":
084     *
085     * <pre>
086     * jcs.jdbcconnectionpool.MyPool.attributes.userName=MyUserName
087     * jcs.jdbcconnectionpool.MyPool.attributes.password=MyPassword
088     * jcs.jdbcconnectionpool.MyPool.attributes.url=MyUrl
089     * jcs.jdbcconnectionpool.MyPool.attributes.maxActive=MyMaxActive
090     * jcs.jdbcconnectionpool.MyPool.attributes.driverClassName=MyDriverClassName
091     * </pre>
092     */
093    private String connectionPoolName;
094
095    /**
096     * @param userName The userName to set.
097     */
098    public void setUserName( final String userName )
099    {
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}