1 20 package org.enhydra.dods.cache; 21 22 import java.sql.ResultSet ; 23 24 import com.lutris.util.Config; 25 26 import org.enhydra.dods.CommonConstants; 27 import org.enhydra.dods.DODS; 28 import org.enhydra.dods.exceptions.AssertionDataObjectException; 29 import com.lutris.appserver.server.sql.StandardDatabaseManager; 30 import com.lutris.logging.Logger; 31 import com.lutris.dods.builder.generator.query.QueryBuilder; 32 import com.lutris.appserver.server.sql.standard.DatabaseConfiguration; 33 import com.lutris.appserver.server.sql.standard.DriverSpecificConstants; 34 import com.lutris.appserver.server.sql.standard.StandardLogicalDatabase; 35 36 46 47 public class TableConfiguration implements CacheConstants, DriverSpecificConstants { 48 49 53 private boolean readOnly = ((StandardDatabaseManager)DODS.getDatabaseManager()).getAllReadOnly(); 54 55 56 60 private boolean caseSensitive = CacheConstants.DEFAULT_CASE_SENSITIVE; 61 62 63 67 private boolean originalAllReadOnly = ((StandardDatabaseManager)DODS.getDatabaseManager()).getAllReadOnly(); 68 69 74 private boolean lazyLoading = CacheConstants.DEFAULT_LAZY_LOADING; 75 76 81 private int maxExecuteTime = CacheConstants.DEFAULT_MAX_EXECUTE_TIME; 82 83 private int defaultFetchSize = CacheConstants.DEFAULT_DEFAULT_FETCH_SIZE; 84 85 private int queryTimeout = CacheConstants.DEFAULT_QUERY_TIMEOUT; 86 87 private int fullCacheCountLimit = CacheConstants.DEFAULT_FULL_CACHE_COUNT_LIMIT; 88 89 private String initCachesResultSetType = null; 90 91 private String initCachesResultSetConcurrency = null; 92 93 private Integer queryTimeLimit = CommonConstants.DEFAULT_QUERY_TIME_LIMIT; 94 95 99 private boolean selectOids = CacheConstants.DEFAULT_SELECT_OIDS; 100 101 105 private boolean incrementVersions = CacheConstants.DEFAULT_INCREMENT_VERSIONS; 106 107 112 public boolean isReadOnly() { 113 return readOnly; 114 } 115 116 123 protected void setReadOnly(boolean newReadOnly) throws AssertionDataObjectException { 124 if (newReadOnly == false) { 125 if (originalAllReadOnly) { 126 throw new AssertionDataObjectException("Can't set read-only table to false: all tables are read-only"); 127 } else { 128 Wrapper.getInstance().removeAllComplexQueries(); 129 } 130 } 131 readOnly = newReadOnly; 132 } 133 134 138 public int getInitCachesResultSetType() { 139 String tmpUCrN = initCachesResultSetType; 140 try { 141 if (tmpUCrN==null) 142 return ResultSet.TYPE_FORWARD_ONLY; 143 if(tmpUCrN.equalsIgnoreCase("TYPE_SCROLL_SENSITIVE")) 144 return ResultSet.TYPE_SCROLL_SENSITIVE; 145 else if (tmpUCrN.equalsIgnoreCase("TYPE_SCROLL_INSENSITIVE")) 146 return ResultSet.TYPE_SCROLL_INSENSITIVE; 147 else if (tmpUCrN.equalsIgnoreCase("TYPE_FORWARD_ONLY")) 148 return ResultSet.TYPE_FORWARD_ONLY; 149 else { 150 DODS.getLogChannel().write(Logger.DEBUG,"Invalid value for InitCachesResultSetType parameter :"+tmpUCrN); 151 return ResultSet.TYPE_FORWARD_ONLY; 152 } 153 }catch(Exception ex) { 154 DODS.getLogChannel().write(Logger.DEBUG,"Use default value for InitCachesResultSetType parameter "); 155 return ResultSet.TYPE_FORWARD_ONLY; 156 } 157 } 158 159 163 public int getInitCachesResultSetConcurrency() { 164 String tmpUCrN = initCachesResultSetConcurrency; 165 try{ 166 if (tmpUCrN==null) 167 return ResultSet.CONCUR_READ_ONLY; 168 if(tmpUCrN.equalsIgnoreCase("CONCUR_READ_ONLY")) 169 return ResultSet.CONCUR_READ_ONLY; 170 else if (tmpUCrN.equalsIgnoreCase("CONCUR_UPDATABLE")) 171 return ResultSet.CONCUR_UPDATABLE; 172 else { 173 DODS.getLogChannel().write(Logger.DEBUG,"Invalid value for InitCachesResultSetConcurrency parameter :"+tmpUCrN); 174 return ResultSet.CONCUR_READ_ONLY; 175 } 176 }catch(Exception ex) { 177 DODS.getLogChannel().write(Logger.DEBUG,"Use default value for InitCachesResultSetConcurrency parameter "); 178 return ResultSet.CONCUR_READ_ONLY; 179 } 180 } 181 182 185 public void setInitCachesResultSetConcurrency(String string) { 186 initCachesResultSetConcurrency = string; 187 } 188 189 192 public void setInitCachesResultSetType(String string) { 193 initCachesResultSetType = string; 194 } 195 196 201 public boolean isLazyLoading() { 202 return lazyLoading; 203 } 204 205 210 protected void setLazyLoading(boolean newlazyLoading) { 211 lazyLoading = newlazyLoading; 212 } 213 214 219 public int getMaxExecuteTime() { 220 return maxExecuteTime; 221 } 222 223 228 protected void setMaxExecuteTime(int newMaxExecuteTime) { 229 maxExecuteTime = newMaxExecuteTime; 230 } 231 232 237 public int getDefaultFetchSize() { 238 return defaultFetchSize; 239 } 240 241 246 private void setDefaultFetchSize(int newValue) { 247 defaultFetchSize = newValue; 248 QueryBuilder.setDefaultFetchSize(defaultFetchSize); 249 } 250 251 256 public int getQueryTimeout() { 257 return queryTimeout; 258 } 259 260 265 private void setQueryTimeout(int newValue) { 266 queryTimeout = newValue; 267 QueryBuilder.setDefaultQueryTimeout(queryTimeout); 268 } 269 270 275 public boolean getSelectOids() { 276 return selectOids; 277 } 278 279 284 private void setSelectOids(boolean newValue) { 285 selectOids = newValue; 286 } 287 288 289 294 public boolean isCaseSensitive() { 295 return caseSensitive; 296 } 297 298 303 public void setCaseSensitive(boolean newValue) { 304 caseSensitive = newValue; 305 } 306 307 308 313 public boolean getIncrementVersions() { 314 return incrementVersions; 315 } 316 317 322 private void setIncrementVersions(boolean newValue) { 323 incrementVersions = newValue; 324 } 325 326 public int getFullCacheCountLimit() { 327 return fullCacheCountLimit; 328 } 329 public void setFullCacheCountLimit(int i) { 330 fullCacheCountLimit = i; 331 } 332 333 334 337 public Integer getQueryTimeLimit() { 338 return queryTimeLimit; 339 } 340 343 public void setQueryTimeLimit(Integer queryTimeLimit) { 344 this.queryTimeLimit = queryTimeLimit; 345 } 346 347 348 353 public void readTableConfiguration(Config tableConfig, String dbName) { 354 355 DatabaseConfiguration defaultDatabaseConfig = null; 356 357 try { 358 defaultDatabaseConfig = ((StandardLogicalDatabase) (DODS.getDatabaseManager().findLogicalDatabase(dbName))).getDatabaseConfiguration(); 359 360 } catch (Exception ex) {} 361 if (defaultDatabaseConfig != null) { 362 363 try { 364 readOnly = defaultDatabaseConfig.isAllReadOnly(); 365 originalAllReadOnly = readOnly; 366 } catch (Exception e) {} 367 try { 368 lazyLoading = defaultDatabaseConfig.isLazyLoading(); 369 } catch (Exception e) {} 370 try { 371 caseSensitive = defaultDatabaseConfig.getCaseSensitive(); 372 } catch (Exception e) {} 373 try { 374 maxExecuteTime = defaultDatabaseConfig.getMaxExecuteTime(); 375 } catch (Exception e) {} 376 try { 377 defaultFetchSize = defaultDatabaseConfig.getDefaultFetchSize(); 378 } catch (Exception e) {} 379 try { 380 queryTimeout = defaultDatabaseConfig.getQueryTimeout(); 381 } catch (Exception e) {} 382 try { 383 selectOids = defaultDatabaseConfig.getSelectOids(); 384 } catch (Exception e) {} 385 try { 386 incrementVersions = defaultDatabaseConfig.getIncrementVersions(); 387 } catch (Exception e) {} 388 try { 389 fullCacheCountLimit = defaultDatabaseConfig.getFullCacheCountLimit(); 390 } catch (Exception e) {} 391 try { 392 initCachesResultSetType = defaultDatabaseConfig.getInitCachesResultSetType(); 393 } catch (Exception e) {} 394 try { 395 initCachesResultSetConcurrency = defaultDatabaseConfig.getInitCachesResultSetConcurrency(); 396 } catch (Exception e) {} 397 try { 398 queryTimeLimit = defaultDatabaseConfig.getQueryTimeLimit(); 399 } catch (Exception e) {} 400 401 402 } 403 if (tableConfig != null) { 404 try { 405 if (!readOnly) { 406 readOnly = tableConfig.getBoolean(CacheConstants.PARAMNAME_READ_ONLY); 407 } else { 408 if (!tableConfig.getBoolean(CacheConstants.PARAMNAME_READ_ONLY)) { 409 DODS.getLogChannel().write(Logger.WARNING, 410 "Single table has readOnly=false property in config file, but AllReadOnly=true "); 411 } 412 } 413 } catch (Exception e) {} 414 try { 415 lazyLoading = tableConfig.getBoolean(CacheConstants.PARAMNAME_LAZY_LOADING); 416 } catch (Exception e) {} 417 try { 418 maxExecuteTime = tableConfig.getInt(CacheConstants.PARAMNAME_MAX_EXECUTE_TIME); 419 } catch (Exception e) {} 420 try { 421 defaultFetchSize = tableConfig.getInt(CacheConstants.PARAMNAME_DEFAULT_FETCH_SIZE); 422 } catch (Exception e) {} 423 try { 424 queryTimeout = tableConfig.getInt(CacheConstants.PARAMNAME_QUERY_TIMEOUT); 425 } catch (Exception e) {} 426 try { 427 selectOids = tableConfig.getBoolean(CacheConstants.PARAMNAME_SELECT_OIDS); 428 } catch (Exception e) {} 429 try { 430 incrementVersions = tableConfig.getBoolean(CacheConstants.PARAMNAME_INCREMENT_VERSIONS); 431 } catch (Exception e) {} 432 try { 433 caseSensitive = tableConfig.getBoolean(CacheConstants.PARAMNAME_CASE_SENSITIVE); 434 } catch (Exception e) {} 435 try { 436 fullCacheCountLimit = tableConfig.getInt(CacheConstants.FULL_CACHE_COUNT_LIMIT); 437 } catch (Exception e) {} 438 try { 439 initCachesResultSetType = tableConfig.getString(CommonConstants.INIT_CACHES_RESULT_SET_TYPE); 440 } catch (Exception e) {} 441 try { 442 initCachesResultSetConcurrency = tableConfig.getString(CommonConstants.INIT_CACHES_RESULT_SET_CONCURRENCY); 443 } catch (Exception e) {} 444 try { 445 queryTimeLimit = new Integer (tableConfig.getInt(CommonConstants.QUERY_TIME_LIMIT)); 446 } catch (Exception e) {} 447 } 448 setQueryTimeout(queryTimeout); 449 setDefaultFetchSize(defaultFetchSize); 450 } 451 452 } 453 | Popular Tags |