1 package org.jboss.cache.loader; 2 3 import org.jboss.cache.config.CacheLoaderConfig.IndividualCacheLoaderConfig; 4 5 import java.util.Properties ; 6 7 public class JDBCCacheLoaderConfig extends IndividualCacheLoaderConfig 8 { 9 12 private static final long serialVersionUID = -5923661816427361643L; 13 14 private boolean createTable; 15 private String createTableDDL; 16 private String datasourceName; 17 private String deleteAllSql; 18 private String deleteNodeSql; 19 private boolean dropTable; 20 private String dropTableDDL; 21 private String driverClass; 22 private String insertNodeSql; 23 private String jdbcURL; 24 private String jdbcUser; 25 private String jdbcPassword; 26 private String selectChildFqnsSql; 27 private String selectChildNamesSql; 28 private String selectNodeSql; 29 private String table; 30 private String updateNodeSql; 31 private String updateTableSql; 32 33 public JDBCCacheLoaderConfig() 34 { 35 setClassName(JDBCCacheLoader.class.getName()); 36 } 37 38 43 JDBCCacheLoaderConfig(IndividualCacheLoaderConfig base) 44 { 45 setClassName(JDBCCacheLoader.class.getName()); 46 populateFromBaseConfig(base); 47 } 48 49 public boolean getCreateTable() 50 { 51 return createTable; 52 } 53 54 public void setCreateTable(boolean createTable) 55 { 56 testImmutability("createTable"); 57 this.createTable = createTable; 58 } 59 60 public String getCreateTableDDL() 61 { 62 return createTableDDL; 63 } 64 65 public void setCreateTableDDL(String createTableDDL) 66 { 67 testImmutability("createTableDDL"); 68 this.createTableDDL = createTableDDL; 69 } 70 71 public String getDatasourceName() 72 { 73 return datasourceName; 74 } 75 76 public void setDatasourceName(String datasourceName) 77 { 78 testImmutability("datasourceName"); 79 this.datasourceName = datasourceName; 80 } 81 82 public String getDeleteAllSql() 83 { 84 return deleteAllSql; 85 } 86 87 public void setDeleteAllSql(String deleteAllSql) 88 { 89 testImmutability("deleteAllSql"); 90 this.deleteAllSql = deleteAllSql; 91 } 92 93 public String getDeleteNodeSql() 94 { 95 return deleteNodeSql; 96 } 97 98 public void setDeleteNodeSql(String deleteNodeSql) 99 { 100 testImmutability("deleteNodeSql"); 101 this.deleteNodeSql = deleteNodeSql; 102 } 103 104 public String getDriverClass() 105 { 106 return driverClass; 107 } 108 109 public void setDriverClass(String driverClass) 110 { 111 testImmutability("driverClass"); 112 this.driverClass = driverClass; 113 } 114 115 public boolean getDropTable() 116 { 117 return dropTable; 118 } 119 120 public void setDropTable(boolean dropTable) 121 { 122 testImmutability("dropTable"); 123 this.dropTable = dropTable; 124 } 125 126 public String getInsertNodeSql() 127 { 128 return insertNodeSql; 129 } 130 131 public void setInsertNodeSql(String insertNodeSql) 132 { 133 testImmutability("insertNodeSql"); 134 this.insertNodeSql = insertNodeSql; 135 } 136 137 public String getSelectChildFqnsSql() 138 { 139 return selectChildFqnsSql; 140 } 141 142 public void setSelectChildFqnsSql(String selectChildFqnsSql) 143 { 144 testImmutability("selectChildFqnsSql"); 145 this.selectChildFqnsSql = selectChildFqnsSql; 146 } 147 148 public String getSelectNodeSql() 149 { 150 return selectNodeSql; 151 } 152 153 public void setSelectNodeSql(String selectNodeSql) 154 { 155 testImmutability("selectNodeSql"); 156 this.selectNodeSql = selectNodeSql; 157 } 158 159 public String getTable() 160 { 161 return table; 162 } 163 164 public void setTable(String table) 165 { 166 testImmutability("table"); 167 this.table = table; 168 } 169 170 public String getUpdateTableSql() 171 { 172 return updateTableSql; 173 } 174 175 public void setUpdateTableSql(String updateTableSql) 176 { 177 testImmutability("updateTableSql"); 178 this.updateTableSql = updateTableSql; 179 } 180 181 public String getDropTableDDL() 182 { 183 return dropTableDDL; 184 } 185 186 public void setDropTableDDL(String dropTableDDL) 187 { 188 testImmutability("dropTableDDL"); 189 this.dropTableDDL = dropTableDDL; 190 } 191 192 public String getSelectChildNamesSql() 193 { 194 return selectChildNamesSql; 195 } 196 197 public void setSelectChildNamesSql(String selectChildNamesSql) 198 { 199 testImmutability("selectChildNamesSql"); 200 this.selectChildNamesSql = selectChildNamesSql; 201 } 202 203 public String getUpdateNodeSql() 204 { 205 return updateNodeSql; 206 } 207 208 public void setUpdateNodeSql(String updateNodeSql) 209 { 210 testImmutability("updateNodeSql"); 211 this.updateNodeSql = updateNodeSql; 212 } 213 214 public String getJdbcPassword() 215 { 216 return jdbcPassword; 217 } 218 219 public void setJdbcPassword(String jdbcPassword) 220 { 221 testImmutability("jdbcPassword"); 222 this.jdbcPassword = jdbcPassword; 223 } 224 225 public String getJdbcURL() 226 { 227 return jdbcURL; 228 } 229 230 public void setJdbcURL(String jdbcURL) 231 { 232 testImmutability("jdbcURL"); 233 this.jdbcURL = jdbcURL; 234 } 235 236 public String getJdbcUser() 237 { 238 return jdbcUser; 239 } 240 241 public void setJdbcUser(String jdbcUser) 242 { 243 testImmutability("jdbcUser"); 244 this.jdbcUser = jdbcUser; 245 } 246 247 public void setProperties(Properties props) 248 { 249 super.setProperties(props); 250 datasourceName = props.getProperty("cache.jdbc.datasource"); 251 if (datasourceName == null) 252 { 253 this.driverClass = JDBCCacheLoader.getRequiredProperty(props, "cache.jdbc.driver"); 254 this.jdbcURL = JDBCCacheLoader.getRequiredProperty(props, "cache.jdbc.url"); 255 this.jdbcUser = JDBCCacheLoader.getRequiredProperty(props, "cache.jdbc.user"); 256 this.jdbcPassword = JDBCCacheLoader.getRequiredProperty(props, "cache.jdbc.password"); 257 258 if (log.isDebugEnabled()) 259 { 260 log.debug("Properties: " + 261 "cache.jdbc.url=" + 262 jdbcURL + 263 ", cache.jdbc.driver=" + 264 driverClass + 265 ", cache.jdbc.user=" + 266 jdbcUser + 267 ", cache.jdbc.password=" + 268 jdbcPassword + 269 ", cache.jdbc.table=" + table); 270 } 271 } 272 273 String prop = props.getProperty("cache.jdbc.table.create"); 274 this.createTable = (prop == null || Boolean.valueOf(prop)); 275 prop = props.getProperty("cache.jdbc.table.drop"); 276 this.dropTable = (prop == null || Boolean.valueOf(prop)); 277 278 this.table = props.getProperty("cache.jdbc.table.name", "jbosscache"); 279 String primaryKey = props.getProperty("cache.jdbc.table.primarykey", "jbosscache_pk"); 280 String fqnColumn = props.getProperty("cache.jdbc.fqn.column", "fqn"); 281 String fqnType = props.getProperty("cache.jdbc.fqn.type", "varchar(255)"); 282 String nodeColumn = props.getProperty("cache.jdbc.node.column", "node"); 283 String nodeType = props.getProperty("cache.jdbc.node.type", "blob"); 284 String parentColumn = props.getProperty("cache.jdbc.parent.column", "parent"); 285 286 selectChildNamesSql = "select " + fqnColumn + " from " + table + " where " + parentColumn + "=?"; 287 deleteNodeSql = "delete from " + table + " where " + fqnColumn + "=?"; 288 deleteAllSql = "delete from " + table; 289 selectChildFqnsSql = "select " + fqnColumn + " from " + table + " where " + parentColumn + "=?"; 290 insertNodeSql = "insert into " + 291 table + 292 " (" + 293 fqnColumn + 294 ", " + 295 nodeColumn + 296 ", " + 297 parentColumn + 298 ") values (?, ?, ?)"; 299 updateNodeSql = "update " + table + " set " + nodeColumn + "=? where " + fqnColumn + "=?"; 300 selectNodeSql = "select " + nodeColumn + " from " + table + " where " + fqnColumn + "=?"; 301 302 createTableDDL = "create table " + 303 table + 304 "(" + 305 fqnColumn + 306 " " + 307 fqnType + 308 " not null, " + 309 nodeColumn + 310 " " + 311 nodeType + 312 ", " + 313 parentColumn + 314 " " + 315 fqnType + 316 ", constraint " + primaryKey + " primary key (" + fqnColumn + "))"; 317 318 dropTableDDL = "drop table " + table; 319 } 320 321 public boolean equals(Object obj) 322 { 323 if (obj instanceof JDBCCacheLoaderConfig && equalsExcludingProperties(obj)) 324 { 325 JDBCCacheLoaderConfig other = (JDBCCacheLoaderConfig) obj; 326 327 return (this.createTable == other.createTable) 328 && safeEquals(createTableDDL, other.createTableDDL) 329 && safeEquals(datasourceName, other.datasourceName) 330 && safeEquals(deleteAllSql, other.deleteAllSql) 331 && safeEquals(deleteNodeSql, other.deleteNodeSql) 332 && safeEquals(driverClass, other.driverClass) 333 && (dropTable == other.dropTable) 334 && safeEquals(dropTableDDL, other.dropTableDDL) 335 && safeEquals(insertNodeSql, other.insertNodeSql) 336 && safeEquals(jdbcPassword, other.jdbcPassword) 337 && safeEquals(jdbcURL, other.jdbcURL) 338 && safeEquals(jdbcUser, other.jdbcUser) 339 && safeEquals(selectChildFqnsSql, other.selectChildFqnsSql) 340 && safeEquals(selectChildNamesSql, other.selectChildNamesSql) 341 && safeEquals(selectNodeSql, other.selectNodeSql) 342 && safeEquals(table, other.table) 343 && safeEquals(updateNodeSql, other.updateNodeSql) 344 && safeEquals(updateTableSql, other.updateTableSql); 345 } 346 347 return false; 348 } 349 350 public int hashCode() 351 { 352 int result = hashCodeExcludingProperties(); 353 result = 31 * result + (createTable ? 0 : 1); 354 result = 31 * result + (createTableDDL == null ? 0 : createTableDDL.hashCode()); 355 result = 31 * result + (datasourceName == null ? 0 : datasourceName.hashCode()); 356 result = 31 * result + (deleteAllSql == null ? 0 : deleteAllSql.hashCode()); 357 result = 31 * result + (deleteNodeSql == null ? 0 : deleteNodeSql.hashCode()); 358 result = 31 * result + (driverClass == null ? 0 : driverClass.hashCode()); 359 result = 31 * result + (dropTable ? 0 : 1); 360 result = 31 * result + (dropTableDDL == null ? 0 : dropTableDDL.hashCode()); 361 result = 31 * result + (insertNodeSql == null ? 0 : insertNodeSql.hashCode()); 362 result = 31 * result + (jdbcPassword == null ? 0 : jdbcPassword.hashCode()); 363 result = 31 * result + (jdbcUser == null ? 0 : jdbcUser.hashCode()); 364 result = 31 * result + (jdbcURL == null ? 0 : jdbcURL.hashCode()); 365 result = 31 * result + (selectChildFqnsSql == null ? 0 : selectChildFqnsSql.hashCode()); 366 result = 31 * result + (selectChildNamesSql == null ? 0 : selectChildNamesSql.hashCode()); 367 result = 31 * result + (selectNodeSql == null ? 0 : selectNodeSql.hashCode()); 368 result = 31 * result + (table == null ? 0 : table.hashCode()); 369 result = 31 * result + (updateNodeSql == null ? 0 : updateNodeSql.hashCode()); 370 result = 31 * result + (updateTableSql == null ? 0 : updateTableSql.hashCode()); 371 372 return result; 373 } 374 375 } | Popular Tags |