KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > dods > cache > TableConfiguration


1 /*
2  * Enhydra Java Application Server Project
3  *
4  * The contents of this file are subject to the Enhydra Public License
5  * Version 1.1 (the "License"); you may not use this file except in
6  * compliance with the License. You may obtain a copy of the License on
7  * the Enhydra web site ( http://www.enhydra.org/ ).
8  *
9  * Software distributed under the License is distributed on an "AS IS"
10  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
11  * the License for the specific terms governing rights and limitations
12  * under the License.
13  *
14  * The Initial Developer of the Enhydra Application Server is Lutris
15  * Technologies, Inc. The Enhydra Application Server and portions created
16  * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
17  * All Rights Reserved.
18  *
19  */

20 package org.enhydra.dods.cache;
21
22 import java.sql.ResultSet JavaDoc;
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 /**
37  * TableConfiguration contains parameters about table configuration. It reads
38  * these parameters from application's configuration file, sets them to new
39  * values or returns their current values.
40  *
41  * @author Tanja Jovanovic
42  * @author Nenad Vico
43  * @author Zorica Suvajdzin
44  * @version 2.0 15.06.2003.
45  */

46  
47 public class TableConfiguration implements CacheConstants, DriverSpecificConstants {
48     
49     /**
50      * If table is read-only, parameter readOnly is true, otherwise false.
51      * Default value is false.
52      */

53     private boolean readOnly = ((StandardDatabaseManager)DODS.getDatabaseManager()).getAllReadOnly();
54
55
56     /**
57      * If table is caseSensitive, parameter caseSensitive is true, otherwise false.
58      * Default value is false.
59      */

60     private boolean caseSensitive = CacheConstants.DEFAULT_CASE_SENSITIVE;
61
62
63     /**
64      * If table is read-only, parameter readOnly is true, otherwise false.
65      * Default value is false.
66      */

67     private boolean originalAllReadOnly = ((StandardDatabaseManager)DODS.getDatabaseManager()).getAllReadOnly();
68
69     /**
70      * If table supports lazy-loading, parameter lazyLoading is true, otherwise
71      * false.
72      * Default value is false.
73      */

74     private boolean lazyLoading = CacheConstants.DEFAULT_LAZY_LOADING;
75     
76     /**
77      * Maximal time in miliseconds for Event log.
78      * If query is executed longer that this time, its select statement and
79      * execution time are written to Event log for future analyzes.
80      */

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 JavaDoc initCachesResultSetType = null;
90     
91     private String JavaDoc initCachesResultSetConcurrency = null;
92     
93     private Integer JavaDoc queryTimeLimit = CommonConstants.DEFAULT_QUERY_TIME_LIMIT;
94
95     /**
96      * Optional select statement - used with mass Updates and/or deletes .
97      * Default value is false.
98      */

99     private boolean selectOids = CacheConstants.DEFAULT_SELECT_OIDS;
100     
101     /**
102      * Increment versions during mass Updates.
103      * Default value is true.
104      */

105     private boolean incrementVersions = CacheConstants.DEFAULT_INCREMENT_VERSIONS;
106
107     /**
108      * Returns readOnly parameter.
109      *
110      * @return true if the table is read-only, otherwise false.
111      */

112     public boolean isReadOnly() {
113         return readOnly;
114     }
115     
116     /**
117      * Sets readOnly parameter to value newReadOnly.
118      *
119      * @param newReadOnly New read-only value.
120      * @exception AssertionDataObjectException If new value of read-only is
121      * false, but all application's tables are read-only.
122      */

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     /**
135      * Return value of InitCachesResultSetType property
136      * @return Value of InitCachesResultSetType property
137      */

138     public int getInitCachesResultSetType() {
139         String JavaDoc 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 JavaDoc ex) {
154             DODS.getLogChannel().write(Logger.DEBUG,"Use default value for InitCachesResultSetType parameter ");
155             return ResultSet.TYPE_FORWARD_ONLY;
156         }
157     }
158
159     /**
160      * Return value of InitCachesResultSetConcurrency property
161      * @return Value of InitCachesResultSetConcurrency property
162      */

163     public int getInitCachesResultSetConcurrency() {
164         String JavaDoc 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 JavaDoc ex) {
177             DODS.getLogChannel().write(Logger.DEBUG,"Use default value for InitCachesResultSetConcurrency parameter ");
178             return ResultSet.CONCUR_READ_ONLY;
179         }
180     }
181   
182     /**
183      * @param string
184      */

185     public void setInitCachesResultSetConcurrency(String JavaDoc string) {
186         initCachesResultSetConcurrency = string;
187     }
188
189     /**
190      * @param string
191      */

192     public void setInitCachesResultSetType(String JavaDoc string) {
193         initCachesResultSetType = string;
194     }
195
196     /**
197      * Returns lazyLoading parameter.
198      *
199      * @return true if the table supports lazy-loading, otherwise false.
200      */

201     public boolean isLazyLoading() {
202         return lazyLoading;
203     }
204     
205     /**
206      * Sets readOnly parameter to value newlazyLoading.
207      *
208      * @param newlazyLoading New lazy-loading value.
209      */

210     protected void setLazyLoading(boolean newlazyLoading) {
211         lazyLoading = newlazyLoading;
212     }
213
214     /**
215      * Returns maxExecuteTime parameter.
216      *
217      * @return Maximal time in miliseconds for Event log.
218      */

219     public int getMaxExecuteTime() {
220         return maxExecuteTime;
221     }
222     
223     /**
224      * Sets maxExecuteTime parameter to value newMaxExecuteTime.
225      *
226      * @param newMaxExecuteTime New maxExecuteTime value.
227      */

228     protected void setMaxExecuteTime(int newMaxExecuteTime) {
229         maxExecuteTime = newMaxExecuteTime;
230     }
231
232     /**
233      * Returns DefaultFetchSize parameter.
234      *
235      * @return DefaultFetchSize parameter value.
236      */

237     public int getDefaultFetchSize() {
238         return defaultFetchSize;
239     }
240     
241     /**
242      * Sets DefaultFetchSize parameter to value newValue.
243      *
244      * @param newValue New DefaultFetchSize value.
245      */

246     private void setDefaultFetchSize(int newValue) {
247         defaultFetchSize = newValue;
248         QueryBuilder.setDefaultFetchSize(defaultFetchSize);
249     }
250     
251     /**
252      * Returns QueryTimeout parameter.
253      *
254      * @return QueryTimeout parameter value.
255      */

256     public int getQueryTimeout() {
257         return queryTimeout;
258     }
259     
260     /**
261      * Sets QueryTimeout parameter to value newValue.
262      *
263      * @param newValue New QueryTimeout value.
264      */

265     private void setQueryTimeout(int newValue) {
266         queryTimeout = newValue;
267         QueryBuilder.setDefaultQueryTimeout(queryTimeout);
268     }
269
270     /**
271      * Returns selectOids parameter.
272      *
273      * @return selectOids parameter value.
274      */

275     public boolean getSelectOids() {
276         return selectOids;
277     }
278     
279     /**
280      * Sets selectOids parameter.
281      *
282      * @param newValue New selectOids value.
283      */

284     private void setSelectOids(boolean newValue) {
285         selectOids = newValue;
286     }
287     
288     
289     /**
290      * Returns CaseSensitive parameter.
291      *
292      * @return value of CaseSensitive parameter.
293      */

294     public boolean isCaseSensitive() {
295         return caseSensitive;
296     }
297
298     /**
299      * Set CaseSensitive parameter to newValue value.
300      *
301      * @param newValue New value for CaseSensitive parameter
302      */

303     public void setCaseSensitive(boolean newValue) {
304         caseSensitive = newValue;
305     }
306
307
308     /**
309      * Returns IncrementVersions parameter.
310      *
311      * @return IncrementVersions parameter value.
312      */

313     public boolean getIncrementVersions() {
314         return incrementVersions;
315     }
316     
317     /**
318      * Sets IncrementVersions parameter.
319      *
320      * @param newValue New IncrementVersions value.
321      */

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     /**
335      * @return Returns the queryTimeLimit.
336      */

337     public Integer JavaDoc getQueryTimeLimit() {
338         return queryTimeLimit;
339     }
340     /**
341      * @param queryTimeLimit The queryTimeLimit to set.
342      */

343     public void setQueryTimeLimit(Integer JavaDoc queryTimeLimit) {
344         this.queryTimeLimit = queryTimeLimit;
345     }
346     
347     
348     /**
349      * Reads table configuration parameters.
350      *
351      * @param tableConfig Configuration file from which the parameters are read.
352      */

353     public void readTableConfiguration(Config tableConfig, String JavaDoc dbName) {
354         
355         DatabaseConfiguration defaultDatabaseConfig = null;
356         
357         try {
358             defaultDatabaseConfig = ((StandardLogicalDatabase) (DODS.getDatabaseManager().findLogicalDatabase(dbName))).getDatabaseConfiguration();
359             
360         } catch (Exception JavaDoc ex) {}
361         if (defaultDatabaseConfig != null) {
362
363             try {
364                 readOnly = defaultDatabaseConfig.isAllReadOnly();
365                 originalAllReadOnly = readOnly;
366             } catch (Exception JavaDoc e) {}
367             try {
368                 lazyLoading = defaultDatabaseConfig.isLazyLoading();
369             } catch (Exception JavaDoc e) {}
370             try {
371                 caseSensitive = defaultDatabaseConfig.getCaseSensitive();
372             } catch (Exception JavaDoc e) {}
373             try {
374                 maxExecuteTime = defaultDatabaseConfig.getMaxExecuteTime();
375             } catch (Exception JavaDoc e) {}
376             try {
377                 defaultFetchSize = defaultDatabaseConfig.getDefaultFetchSize();
378             } catch (Exception JavaDoc e) {}
379             try {
380                 queryTimeout = defaultDatabaseConfig.getQueryTimeout();
381             } catch (Exception JavaDoc e) {}
382             try {
383                 selectOids = defaultDatabaseConfig.getSelectOids();
384             } catch (Exception JavaDoc e) {}
385             try {
386                 incrementVersions = defaultDatabaseConfig.getIncrementVersions();
387             } catch (Exception JavaDoc e) {}
388             try {
389                 fullCacheCountLimit = defaultDatabaseConfig.getFullCacheCountLimit();
390             } catch (Exception JavaDoc e) {}
391             try {
392                 initCachesResultSetType = defaultDatabaseConfig.getInitCachesResultSetType();
393             } catch (Exception JavaDoc e) {}
394             try {
395                 initCachesResultSetConcurrency = defaultDatabaseConfig.getInitCachesResultSetConcurrency();
396             } catch (Exception JavaDoc e) {}
397             try {
398                 queryTimeLimit = defaultDatabaseConfig.getQueryTimeLimit();
399             } catch (Exception JavaDoc 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 JavaDoc e) {}
414             try {
415                 lazyLoading = tableConfig.getBoolean(CacheConstants.PARAMNAME_LAZY_LOADING);
416             } catch (Exception JavaDoc e) {}
417             try {
418                 maxExecuteTime = tableConfig.getInt(CacheConstants.PARAMNAME_MAX_EXECUTE_TIME);
419             } catch (Exception JavaDoc e) {}
420             try {
421                 defaultFetchSize = tableConfig.getInt(CacheConstants.PARAMNAME_DEFAULT_FETCH_SIZE);
422             } catch (Exception JavaDoc e) {}
423             try {
424                 queryTimeout = tableConfig.getInt(CacheConstants.PARAMNAME_QUERY_TIMEOUT);
425             } catch (Exception JavaDoc e) {}
426             try {
427                 selectOids = tableConfig.getBoolean(CacheConstants.PARAMNAME_SELECT_OIDS);
428             } catch (Exception JavaDoc e) {}
429             try {
430                 incrementVersions = tableConfig.getBoolean(CacheConstants.PARAMNAME_INCREMENT_VERSIONS);
431             } catch (Exception JavaDoc e) {}
432             try {
433                 caseSensitive = tableConfig.getBoolean(CacheConstants.PARAMNAME_CASE_SENSITIVE);
434             } catch (Exception JavaDoc e) {}
435             try {
436                 fullCacheCountLimit = tableConfig.getInt(CacheConstants.FULL_CACHE_COUNT_LIMIT);
437             } catch (Exception JavaDoc e) {}
438             try {
439                 initCachesResultSetType = tableConfig.getString(CommonConstants.INIT_CACHES_RESULT_SET_TYPE);
440             } catch (Exception JavaDoc e) {}
441             try {
442                 initCachesResultSetConcurrency = tableConfig.getString(CommonConstants.INIT_CACHES_RESULT_SET_CONCURRENCY);
443             } catch (Exception JavaDoc e) {}
444             try {
445                 queryTimeLimit = new Integer JavaDoc(tableConfig.getInt(CommonConstants.QUERY_TIME_LIMIT));
446             } catch (Exception JavaDoc e) {}
447         }
448         setQueryTimeout(queryTimeout);
449         setDefaultFetchSize(defaultFetchSize);
450     }
451     
452 }
453
Popular Tags