001package org.apache.commons.jcs.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.jcs.auxiliary.disk.AbstractDiskCacheAttributes; 023 024/** 025 * The configurator will set these values based on what is in the cache.ccf file. 026 * <p> 027 * @author Aaron Smuts 028 */ 029public class JDBCDiskCacheAttributes 030 extends AbstractDiskCacheAttributes 031{ 032 /** Don't change */ 033 private static final long serialVersionUID = -6535808344813320062L; 034 035 /** default */ 036 private static final String DEFAULT_TABLE_NAME = "JCS_STORE"; 037 038 /** DB username */ 039 private String userName; 040 041 /** DB password */ 042 private String password; 043 044 /** URL for the db */ 045 private String url; 046 047 /** The name of the database. */ 048 private String database = ""; 049 050 /** The driver */ 051 private String driverClassName; 052 053 /** The JNDI path. */ 054 private String jndiPath; 055 056 /** The time between two JNDI lookups */ 057 private long jndiTTL = 0L; 058 059 /** The table name */ 060 private String tableName = DEFAULT_TABLE_NAME; 061 062 /** If false we will insert and if it fails we will update. */ 063 private boolean testBeforeInsert = true; 064 065 /** This is the default limit on the maximum number of active connections. */ 066 public static final int DEFAULT_MAX_ACTIVE = 10; 067 068 /** Max connections allowed */ 069 private int maxActive = DEFAULT_MAX_ACTIVE; 070 071 /** This is the default setting for the cleanup routine. */ 072 public static final int DEFAULT_SHRINKER_INTERVAL_SECONDS = 300; 073 074 /** How often should we remove expired. */ 075 private int shrinkerIntervalSeconds = DEFAULT_SHRINKER_INTERVAL_SECONDS; 076 077 /** Should we remove expired in the background. */ 078 private boolean useDiskShrinker = true; 079 080 /** The default Pool Name to which the connection pool will be keyed. */ 081 public static final String DEFAULT_POOL_NAME = "jcs"; 082 083 /** 084 * If a pool name is supplied, the manager will attempt to load it. It should be configured in a 085 * separate section as follows. Assuming the name is "MyPool": 086 * 087 * <pre> 088 * jcs.jdbcconnectionpool.MyPool.attributes.userName=MyUserName 089 * jcs.jdbcconnectionpool.MyPool.attributes.password=MyPassword 090 * jcs.jdbcconnectionpool.MyPool.attributes.url=MyUrl 091 * jcs.jdbcconnectionpool.MyPool.attributes.maxActive=MyMaxActive 092 * jcs.jdbcconnectionpool.MyPool.attributes.driverClassName=MyDriverClassName 093 * </pre> 094 */ 095 private String connectionPoolName; 096 097 /** 098 * @param userName The userName to set. 099 */ 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}