KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > lutris > appserver > server > sql > standard > StandardLogicalDatabase


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  * Contributor(s):
20  *
21  * $Id: StandardLogicalDatabase.java,v 1.10 2005/05/26 08:08:10 predrag Exp $
22  */

23 package com.lutris.appserver.server.sql.standard;
24
25 import java.lang.reflect.Constructor JavaDoc;
26 import java.sql.Driver JavaDoc;
27 import java.sql.ResultSet JavaDoc;
28 import java.sql.SQLException JavaDoc;
29 import java.util.Date JavaDoc;
30
31 import org.enhydra.dods.Common;
32 import org.enhydra.dods.CommonConstants;
33 import org.enhydra.dods.DODS;
34 import org.enhydra.dods.DriverDependencies;
35 import org.enhydra.dods.cache.CacheConstants;
36
37 import com.lutris.appserver.server.sql.AbstractDBTransactionFactory;
38 import com.lutris.appserver.server.sql.ConnectionAllocator;
39 import com.lutris.appserver.server.sql.DBConnection;
40 import com.lutris.appserver.server.sql.DBQuery;
41 import com.lutris.appserver.server.sql.DBTransaction;
42 import com.lutris.appserver.server.sql.DBTransactionFactoryCreator;
43 import com.lutris.appserver.server.sql.DatabaseManagerConfiguration;
44 import com.lutris.appserver.server.sql.ExtendedDBConnection;
45 import com.lutris.appserver.server.sql.LogicalDatabase;
46 import com.lutris.appserver.server.sql.ObjectId;
47 import com.lutris.appserver.server.sql.ObjectIdAllocator;
48 import com.lutris.appserver.server.sql.ObjectIdException;
49 import com.lutris.dods.builder.generator.query.RDBColumn;
50 import com.lutris.logging.Logger;
51 import com.lutris.util.Config;
52 import com.lutris.util.ConfigException;
53 import com.lutris.util.KeywordValueException;
54 /**
55  * Represents a logical database. Each logical database has a connection
56  * allocator and a object id allocator. The standard implementation of
57  * a local database is used when the database is described as of
58  * type <I>Standard</I> in
59  * <CODE>DatabaseManager.DB.<I>dbname</I>.ClassType</CODE>
60  * <P>
61  * The configuration data is specified in the section:
62  * <CODE>DatabaseManager.DB.<I>dbName</I></CODE>
63  * <P>
64  * The following is a description of the sub fields:
65  * <UL>
66  * <LI> <B><CODE>JdbcDriver</CODE></B> -
67  * The JDBC driver to use to access that database. Manditory.
68  * E.g. "intersolv.jdbc.sequelink.SequeLinkDriver"
69  * <LI> <B><CODE>Connection</CODE></B> -
70  * This <I>section</I> is passed onto the connection allocator. See
71  * <A HREF="com.lutris.appserver.server.sql.StandardConnectionAllocator"</A>
72  * for details on connection allocator sub fields.
73  * <LI> <B><CODE>ObjectId</CODE></B> -
74  * This <I>section</I> is passed onto the object id allocator. See
75  * <A HREF="com.lutris.appserver.server.sql.ObjectIdAllocator"</A>
76  * for details on object id allocator sub fields.
77  * </UL>
78  *
79  * @author Paul Morgan
80  * @author Kyle Clark
81  * @since LBS1.8
82  * @version $Revision: 1.10 $
83  */

84 public class StandardLogicalDatabase implements LogicalDatabase, CacheConstants, DriverSpecificConstants {
85
86     public static final String JavaDoc PARAMNAME_DRIV_DEP_CLASS = "DriverDependenciesClass";
87
88     /**
89      * Database Manager Transaction Factory.
90      */

91     protected AbstractDBTransactionFactory transactionFactory;
92
93     /**
94      * Database connection allocator.
95      */

96     protected ConnectionAllocator connectionAllocator;
97
98     /**
99      * Object id manager.
100      */

101     protected ObjectIdAllocator objectIdAllocator;
102     
103
104
105     /**
106      * Driver object object. Important: a reference to this must be
107      * maintained or the driver class might be garbage collected out from
108      * under us.
109      */

110     protected Driver JavaDoc driver;
111
112     /**
113      * DriverClassName
114      */

115     protected String JavaDoc driverClassName;
116
117
118     /**
119      * The symbolic name of this logical database.
120      */

121     protected String JavaDoc dbName;
122
123     /**
124      * The database vendor type.
125      */

126     protected String JavaDoc dbType;
127
128     /**
129      * The database configuration
130      */

131     private DatabaseConfiguration dbConf;
132     private DriverDependencies drivDepsInstance;
133
134     /**
135      * Default constructor to configure a single logical database.
136      * Note that the <CODE>init()</CODE> method must be called to
137      * configure the database.
138      */

139     public StandardLogicalDatabase() {}
140
141     /**
142      * Creates and configures a single logical database.
143      *
144      * @param dbName
145      * The logical name of the database. Used to
146      * @param dbConfig
147      * The configuration object for this logical database.
148      * get config parameters.
149      * @exception ConfigException
150      * If there is an error in the configuration file.
151      * @exception SQLException
152      * If a SQL error occurs.
153      */

154     public StandardLogicalDatabase(String JavaDoc dbName, Config dbConfig)
155         throws ConfigException, SQLException JavaDoc {
156         this.init(dbName, dbConfig);
157     }
158
159     /**
160      * Creates and configures a single logical database.
161      *
162      * @param dbName
163      * The logical name of the database. Used to
164      * @param dbConfig
165      * The configuration object for this logical database.
166      * get config parameters.
167      * @param DbManagerConf
168      * The configuration object of DatabaseManager
169      * @exception ConfigException
170      * If there is an error in the configuration file.
171      * @exception SQLException
172      * If a SQL error occurs.
173      */

174     public StandardLogicalDatabase(String JavaDoc dbName, Config dbConfig, DatabaseManagerConfiguration DbManagerConf)
175         throws ConfigException, SQLException JavaDoc {
176         this.init(dbName, dbConfig, DbManagerConf);
177     }
178
179
180     public void init(String JavaDoc dbName, Config dbConfig)
181         throws ConfigException, SQLException JavaDoc {
182         dbConf = new DatabaseConfiguration(dbName);
183         initConf( dbName, dbConfig);
184
185     }
186
187     public void init(String JavaDoc dbName, Config dbConfig, DatabaseManagerConfiguration DbManagerConf)
188         throws ConfigException, SQLException JavaDoc {
189         dbConf = new DatabaseConfiguration(dbName, DbManagerConf);
190         initConf( dbName, dbConfig);
191
192     }
193
194
195     /**
196      * Initialize a single logical database. Used after the default
197      * constructor is called.
198      *
199      * @param dbName The logical name of the database.
200      * @param dbConfig The configuration object for this logical database.
201      *
202      * @exception ConfigException If there is an error in
203      * the configuration file.
204      * @exception SQLException If a SQL error occurs.
205      */

206     private void initConf(String JavaDoc dbName, Config dbConfig)
207         throws ConfigException, SQLException JavaDoc {
208
209         this.dbName = dbName;
210
211
212         // Read configuration information.
213
Config objIdConfig, connectionConfig;
214
215         try {
216             String JavaDoc changeAutocommit = dbConfig.getString("ChangeAutocommit", "true");
217             if (changeAutocommit.equalsIgnoreCase("false")){
218                 Common.setChangeAutocommit(dbName, false);
219             }else if (changeAutocommit.equalsIgnoreCase("true")){
220                 Common.setChangeAutocommit(dbName, true);
221             }else{
222                 throw new ConfigException("invalid value for ChangeAutocommit parameter");
223             }
224         } catch (ConfigException e) {
225             throw new ConfigException("Error reading ChangeAutocommit : "+e.getMessage());
226         }
227
228         try {
229             objIdConfig = (Config) dbConfig.getSection("ObjectId");
230             connectionConfig = (Config) dbConfig.getSection("Connection");
231         } catch (KeywordValueException except) {
232             throw new ConfigException("Invalid ObjectId or Connection sections in config file.");
233         }
234  
235         Object JavaDoc dataSource;
236         try {
237            dataSource = connectionConfig.getDataSource("DataSourceName");
238         }
239         catch (Exception JavaDoc ex){
240             dataSource = null;
241         }
242         if (dataSource==null){
243         this.driverClassName = dbConfig.getString("JdbcDriver");
244         String JavaDoc jdbcDriver = this.driverClassName ;
245
246         // Load JDBC driver; report an SQLException on failure.
247
// No-op if already loaded.
248
try {
249             // We must use the applications class loader to load JDBC classes.
250
Class JavaDoc driverClass = Class.forName(jdbcDriver);
251
252             driver = (Driver JavaDoc) driverClass.newInstance();
253         } catch (java.lang.ClassNotFoundException JavaDoc except) {
254             throw new SQLException JavaDoc("can't load JDBC driver class: "
255                                        + except.getMessage());
256         } catch (java.lang.InstantiationException JavaDoc except) {
257             throw new SQLException JavaDoc("can't instantiate JDBC driver class: "
258                                        + except.getMessage());
259         } catch (java.lang.IllegalAccessException JavaDoc except) {
260             throw new SQLException JavaDoc("can't instantiate JDBC driver class: "
261                                        + except.getMessage());
262         }
263             try {
264                 this.dbType = dbConfig.getString("ClassType");
265             }catch(Exception JavaDoc e1){
266                 this.dbType = Common.getDatabaseVendor(jdbcDriver);
267             }
268         }
269         
270     try {
271         dbConf.setDBConnectionFactoryName(dbConfig.getString(CommonConstants.CONNECTION_FACTORY));
272        } catch (Exception JavaDoc ex) {}
273
274        try {
275        dbConf.setConnectionAllocatorName(dbConfig.getString(CommonConstants.CONNECTION_ALLOCATOR));
276       } catch (Exception JavaDoc ex) {}
277
278         ConnectionAllocator connectionAllocator = loadConnectionAllocator(connectionConfig);
279         ObjectIdAllocator objectIdAllocator = loadObjectIdAllocator(objIdConfig);
280
281         this.connectionAllocator = connectionAllocator;
282         this.objectIdAllocator = objectIdAllocator;
283         if(dataSource!=null){
284             String JavaDoc databaseType=null;
285             String JavaDoc fullDriverClassName=null;
286             try{
287                 ExtendedDBConnection tempConnection = (ExtendedDBConnection)connectionAllocator.allocate();
288                 String JavaDoc driverName=tempConnection.getConnection().getMetaData().getDriverName();
289                 tempConnection.release();
290                 databaseType=Common.getDatabaseVendorFromDriverName(driverName);
291                 fullDriverClassName=Common.getDatabaseDriverClassFromDriverName(driverName);
292             }catch(Exception JavaDoc e){
293                 try {
294                     databaseType = dbConfig.getString("ClassType");
295                     fullDriverClassName = dbConfig.getString("JdbcDriver",null);
296                 }catch(Exception JavaDoc e1){
297                     databaseType = Common.getDatabaseVendor(dbConfig.getString("JdbcDriver",null));
298                 }
299             }
300             this.dbType=databaseType;
301             this.driverClassName = fullDriverClassName;
302         }
303
304         this.initDisableFetchSizeWithMaxRows();
305         this.initResultSetConcurrency();
306         this.initResultSetType();
307
308         
309         try {
310             dbConf.setDBTransactionFactoryName(dbConfig.getString(CommonConstants.TRANSACTION_FACTORY));
311         } catch (Exception JavaDoc ex) {}
312 // try {
313
transactionFactory = DBTransactionFactoryCreator.getDBTransactionFactory(dbConf.getDBTransactionFactoryName(),this);
314 // } catch (RuntimeException e) {
315
// throw new SQLException("can't create Transaction Factory Object: "+ e.getMessage());
316
// }
317
Config defaultsConfig = dbConfig;
318
319         if (defaultsConfig != null) {
320             try {
321                 dbConf.setLazyLoading(defaultsConfig.getBoolean(PARAMNAME_LAZY_LOADING));
322             } catch (Exception JavaDoc ex) {}
323             try {
324                 dbConf.setCaseSensitive(defaultsConfig.getBoolean(PARAMNAME_CASE_SENSITIVE));
325             } catch (Exception JavaDoc ex) {}
326
327             try {
328                 dbConf.setMaxExecuteTime(defaultsConfig.getInt(PARAMNAME_MAX_EXECUTE_TIME));
329             } catch (Exception JavaDoc ex) {}
330             try {
331                 dbConf.setTransactionCheck(defaultsConfig.getBoolean(PARAMNAME_TRANSACTION_CHECK));
332             } catch (Exception JavaDoc ex) {}
333             try {
334                 dbConf.setDeleteCheckVersion(defaultsConfig.getBoolean(PARAMNAME_DELETE_CHECK_VERSION));
335             } catch (Exception JavaDoc ex) {}
336             try {
337                 dbConf.setAutoSave(defaultsConfig.getBoolean(PARAMNAME_AUTO_SAVE));
338             } catch (Exception JavaDoc ex) {}
339             try {
340                 dbConf.setAutoSaveCreateVirgin(defaultsConfig.getBoolean(PARAMNAME_AUTO_SAVE_CREATE_VIRGIN));
341             } catch (Exception JavaDoc ex) {}
342             try {
343                 dbConf.setAutoWrite(defaultsConfig.getBoolean(PARAMNAME_AUTO_WRITE));
344             } catch (Exception JavaDoc ex) {}
345             try {
346                 dbConf.setTransactionCaches(defaultsConfig.getBoolean(PARAMNAME_TRANSACTION_CACHES));
347             } catch (Exception JavaDoc ex) {}
348             try {
349                 dbConf.setDeadlockWaitTime(defaultsConfig.getInt(PARAMNAME_DEADLOCK_READ_TIME));
350             } catch (Exception JavaDoc ex) {}
351             try {
352                 dbConf.setDeadlockRetryCount(defaultsConfig.getInt(PARAMNAME_DEADLOCK_RETRY_NUMBER));
353             } catch (Exception JavaDoc ex) {}
354             try {
355                 dbConf.setReadOnly(defaultsConfig.getBoolean(PARAMNAME_ALL_READ_ONLY));
356             } catch (Exception JavaDoc ex) {}
357             try {
358                 dbConf.setDefaultFetchSize(defaultsConfig.getInt(PARAMNAME_DEFAULT_FETCH_SIZE));
359             } catch (Exception JavaDoc ex) {}
360             try {
361                 dbConf.setQueryTimeout(defaultsConfig.getInt(PARAMNAME_QUERY_TIMEOUT));
362             } catch (Exception JavaDoc ex) {}
363             try {
364                 dbConf.setSelectOids(defaultsConfig.getBoolean(PARAMNAME_SELECT_OIDS));
365             } catch (Exception JavaDoc ex) {}
366             try {
367                 dbConf.setIncrementVersions(defaultsConfig.getBoolean(PARAMNAME_INCREMENT_VERSIONS));
368             } catch (Exception JavaDoc ex) {}
369             try {
370                 boolean tmpSCrN = defaultsConfig.getBoolean(PARAMNAME_USE_CURSOR_NAME);
371                 dbConf.setUseCursorName(tmpSCrN);
372             } catch (Exception JavaDoc ex) {}
373             try {
374                 dbConf.setFullCacheCountLimit(defaultsConfig.getInt(CacheConstants.FULL_CACHE_COUNT_LIMIT));
375             } catch (Exception JavaDoc ex) {}
376             try {
377                 dbConf.setQueryCacheImplClass(defaultsConfig.getString(CommonConstants.QUERY_CACAHE_IMPL_CLASS));
378             } catch (Exception JavaDoc ex) {}
379             try {
380                 dbConf.setInitCachesResultSetType(defaultsConfig.getString(CommonConstants.INIT_CACHES_RESULT_SET_TYPE));
381             } catch (Exception JavaDoc ex) {}
382             try {
383                 dbConf.setInitCachesResultSetConcurrency(defaultsConfig.getString(CommonConstants.INIT_CACHES_RESULT_SET_CONCURRENCY));
384             } catch (Exception JavaDoc ex) {}
385             try {
386                 dbConf.setSqlBatch(defaultsConfig.getBoolean(CommonConstants.SQL_BATCH));
387             } catch (Exception JavaDoc ex) {}
388             try {
389                 dbConf.setQueryTimeLimit(new Integer JavaDoc(defaultsConfig.getInt(CommonConstants.QUERY_TIME_LIMIT)));
390             } catch (Exception JavaDoc ex) {}
391
392             // -XA
393

394             try {
395                 dbConf.setXaDefaultTimeout(defaultsConfig.getInt(CommonConstants.XA_DEFAULT_TIMEOUT));
396             } catch (Exception JavaDoc ex) {}
397             try {
398                 dbConf.setXaTransactonManagerLookupName(defaultsConfig.getString(CommonConstants.XA_TM_LOOKUP_NAME));
399                 
400             } catch (Exception JavaDoc ex) {}
401             try {
402                 dbConf.setXaUsageCase(defaultsConfig.getInt(CommonConstants.XA_USAGE_CASE));
403             } catch (Exception JavaDoc ex) {}
404             try {
405                 dbConf.setXaWrappedTransImplFactory(defaultsConfig.getString(CommonConstants.XA_WRAPPED_TRANS_IMPL_FACTORY));
406             } catch (Exception JavaDoc ex) {}
407             try {
408                 dbConf.setXaUserTransactonLookupName(defaultsConfig.getString(CommonConstants.XA_USER_TRANSACTION_LOOKUP_NAME));
409             } catch (Exception JavaDoc e) { }
410             try {
411                 dbConf.setXaJtaSupport(defaultsConfig.getString(CommonConstants.XA_JTA_SUPPORT));
412             } catch (Exception JavaDoc e) { }
413             
414             // -XA
415
}
416         try {
417             defaultsConfig = (Config) dbConfig.getSection("cache");
418         } catch (KeywordValueException except) {
419             throw new ConfigException("No DatabaseManager.defaults defined in config file.");
420         }
421         if (defaultsConfig != null) {
422             try {
423                 dbConf.setReserveFactor(defaultsConfig.getDouble(PARAMNAME_RESERVE_FACTOR));
424             } catch (Exception JavaDoc ex) {}
425             try {
426                 dbConf.setCachePercentage(defaultsConfig.getDouble(PARAMNAME_CACHE_PERCENTAGE));
427             } catch (Exception JavaDoc ex) {}
428             try {
429                 dbConf.setMaxCacheSize(defaultsConfig.getInt(PARAMNAME_MAX_CACHE_SIZE));
430             } catch (Exception JavaDoc ex) {}
431             try {
432                 dbConf.setMaxSimpleCacheSize(defaultsConfig.getInt(PARAMNAME_MAX_SIMPLE_CACHE_SIZE));
433             } catch (Exception JavaDoc ex) {}
434             try {
435                 dbConf.setMaxComplexCacheSize(defaultsConfig.getInt(PARAMNAME_MAX_COMPLEX_CACHE_SIZE));
436             } catch (Exception JavaDoc ex) {}
437             try {
438                 dbConf.setMaxMultiJoinCacheSize(defaultsConfig.getInt(PARAMNAME_MAX_MULTI_JOIN_CACHE_SIZE));
439             } catch (Exception JavaDoc ex) {}
440             try {
441                 dbConf.setInitialCacheFetchSize(defaultsConfig.getInt(PARAMNAME_INITIAL_CACHE_FETCH_SIZE));
442             } catch (Exception JavaDoc ex) {}
443             try {
444                 dbConf.setInitialDSCacheSize(defaultsConfig.getInt(PARAMNAME_INITIAL_DS_CACHE_SIZE));
445             } catch (Exception JavaDoc ex) {}
446             try {
447                 dbConf.setDodsCacheFactory(defaultsConfig.getString(PARAMNAME_DODS_CACHE_FACTORY));
448             } catch (Exception JavaDoc ex) {}
449             
450
451         }
452
453     }
454
455     /**
456      * Check does oid belong to Object id's range [minOId, currentOId]
457      *
458      * @param oid
459      * oid which will be checked.
460      * @exception ObjectIdException
461      * If a oid does't belong to range.
462      */

463     public void checkOId(ObjectId oid) throws ObjectIdException {
464         objectIdAllocator.checkOId(oid);
465     }
466
467     /**
468      * Return the connection allocator.
469      *
470      * @param connectionConfig
471      * The configuration object for the connection allocator.
472      * @exception ConfigException
473      * If there is an error in the configuration file.
474      * @return
475      * The connection allocator.
476      */

477     public ConnectionAllocator loadConnectionAllocator(Config connectionConfig)
478         throws ConfigException {
479         Class JavaDoc connectionAllocatorClass = null;
480         Constructor JavaDoc connectionAllocatorConstructor = null;
481         Class JavaDoc[] methodTypes={LogicalDatabase.class,connectionConfig.getClass()};
482         Object JavaDoc[] methodArgs={this,connectionConfig};
483         ConnectionAllocator allocator = null;
484         if (dbConf.getConnectionAllocatorName()!=null){
485             try{
486                 connectionAllocatorClass = Class.forName(dbConf.getConnectionAllocatorName());
487                 connectionAllocatorConstructor = connectionAllocatorClass.getConstructor(methodTypes);
488                 allocator = (ConnectionAllocator)connectionAllocatorConstructor.newInstance(methodArgs);
489             }catch(Exception JavaDoc e){
490                 DODS.getLogChannel().write(Logger.ERROR,"Failed to make Connection Allocator :"+dbConf.getConnectionAllocatorName()+" creating StandardConnectionAllocator insted");
491                 allocator = null;
492             }
493         }
494         if (dbConf.getConnectionAllocatorName()==null || allocator == null){
495             //allocator = new StandardConnectionAllocator(this, connectionConfig);
496
try{
497             connectionAllocatorClass = Class.forName("com.lutris.appserver.server.sql.standard.StandardConnectionAllocator");
498             connectionAllocatorConstructor = connectionAllocatorClass.getConstructor(methodTypes);
499             allocator = (ConnectionAllocator)connectionAllocatorConstructor.newInstance(methodArgs);
500           }catch(Exception JavaDoc e){
501             String JavaDoc str = "Failed to make Standard Connection Allocator : com.lutris.appserver.server.sql.standard.StandardConnectionAllocator";
502                 DODS.getLogChannel().write(Logger.CRITICAL,str);
503             throw new Error JavaDoc(str);
504          }
505         }
506         return allocator;
507     }
508
509     /**
510      * Return the object id allocator.
511      *
512      * @param objIdConfig
513      * The configuration object for the object id allocator.
514      * @exception ConfigException
515      * If there is an error in the configuration file.
516      * @return
517      * The object id allocator.
518      */

519     public ObjectIdAllocator loadObjectIdAllocator(Config objIdConfig)
520         throws ConfigException {
521         return new StandardObjectIdAllocator(this, objIdConfig);
522     }
523
524     /**
525      * Return the connection allocator object associated with this
526      * logical database.
527      *
528      * @return
529      * The connection allocator.
530      * @exception SQLException
531      * if SQL error occurs allocating connection.
532      */

533     public DBConnection allocateConnection()
534         throws SQLException JavaDoc {
535         return connectionAllocator.allocate();
536     }
537
538     /**
539      * Return an object id for this logical database.
540      *
541      * @return
542      * The object id.
543      * @exception ObjectIdException
544      * if an error occurs allocating an object id.
545      */

546     public ObjectId allocateObjectId()
547         throws ObjectIdException {
548         return objectIdAllocator.allocate();
549     }
550
551     /**
552      * Return a transaction for use on this logical database.
553      *
554      * @return The transaction object.
555      * @exception SQLException
556      * if a SQL error occurs.
557      */

558     public DBTransaction createTransaction()
559         throws SQLException JavaDoc {
560         return transactionFactory.getTransaction(connectionAllocator.allocate());
561     }
562
563     /**
564      * Return a query for use on this logical database.
565      *
566      * @return The query object.
567      * @exception SQLException
568      * if a SQL error occurs.
569      */

570     public DBQuery createQuery()
571         throws SQLException JavaDoc {
572         return new StandardDBQuery(connectionAllocator.allocate());
573     }
574
575     /**
576      * Immediately shutdown the logical database. This is
577      * normally only called by the database manager on shutdown.
578      */

579     public void shutdown() {
580         connectionAllocator.dropAllNow();
581         driver = null;
582     }
583
584     /**
585      * Return the symbolic name of this logical database.
586      *
587      * @return The symbolic name.
588      */

589     public String JavaDoc getName() {
590         return dbName;
591     }
592
593     /**
594      * Return a description of the logical database type.
595      *
596      * @return The type.
597      */

598     public String JavaDoc getType() {
599         return dbType;
600     }
601
602     /**
603      * Return a driver class of the logical database.
604      *
605      * @return Driver Class Name.
606      */

607     public String JavaDoc getDriverClassName() {
608         return this.driverClassName;
609     }
610
611
612
613     /**
614      * Return a driver property from database vendor configutation file.
615      *
616      * @param paramName Parameter Name
617      * @return Driver Class Name.
618      */

619     public String JavaDoc getDriverProperty(String JavaDoc paramName) {
620         String JavaDoc key ="Drivers/"+driverClassName+"/"+paramName;
621         return Common.getDodsConfProperty(key,dbType);
622     }
623
624
625
626
627     /**
628      * Return the number of currently active connections.
629      *
630      * @return The number of connections.
631      */

632     public int getActiveConnectionCount() {
633         return connectionAllocator.getActiveCount();
634     }
635
636     /**
637      * Return the maximum number of connections active at one time.
638      *
639      * @return The number of connections.
640      */

641     public int getMaxConnectionCount() {
642         return connectionAllocator.getMaxCount();
643     }
644
645     /**
646      * Return the time when the maximum connection count occured.
647      *
648      * @return The <CODE>Date</CODE> when the maximum connection
649      * count occured.
650      */

651     public Date JavaDoc getMaxConnectionCountDate() {
652         return connectionAllocator.getMaxCountDate();
653     }
654
655     /**
656      * Reset the maximum connection count and date.
657      */

658     public void resetMaxConnectionCount() {
659         connectionAllocator.resetMaxCount();
660     }
661
662     /**
663      * Return the number of database requests.
664      *
665      * @return The number of database requests (queries or transactions).
666      */

667     public long getRequestCount() {
668         return connectionAllocator.getRequestCount();
669     }
670
671     /**
672      * Return conf parameters for current database
673      *
674      * @return values for DODS default values for current database
675      */

676     public DatabaseConfiguration getDatabaseConfiguration() {
677         return dbConf;
678     }
679
680
681     /**
682      * Return value of DisableFetchSizeWithMaxRows property
683      * @return Value of DisableFetchSizeWithMaxRows property
684      */

685
686     public boolean getDisableFetchSizeWithMaxRows(){
687         return dbConf.getDisableFetchSizeWithMaxRows();
688     }
689
690     /**
691      * Init value of DisableFetchSizeWithMaxRows property
692      *
693      */

694     private void initDisableFetchSizeWithMaxRows() {
695         String JavaDoc tmpDFSWMR = getDriverProperty(PARAMNAME_DISABLE_FETCH_SIZE_WITH_MAX_ROWS);
696         if (tmpDFSWMR==null){
697             dbConf.setDisableFetchSizeWithMaxRows(DEFAULT_DISABLE_FETCH_SIZE_WITH_MAX_ROWS);
698         }else{
699             if (tmpDFSWMR.equalsIgnoreCase("true")){
700                 dbConf.setDisableFetchSizeWithMaxRows(true);
701             }else if (tmpDFSWMR.equalsIgnoreCase("false")){
702                 dbConf.setDisableFetchSizeWithMaxRows(false);
703             }else{
704                 DODS.getLogChannel().write(Logger.DEBUG,"Invalid value for DisableFetchSizeWithMaxRows parameter :"+tmpDFSWMR);
705                 dbConf.setDisableFetchSizeWithMaxRows(DEFAULT_DISABLE_FETCH_SIZE_WITH_MAX_ROWS);
706             }
707         }
708     }
709
710
711     /**
712      * Return value of UseCursorName property
713      * @return Value of UseCursorName property
714      */

715     public boolean getUseCursorName() {
716         if (dbConf.getUseCursorName()==null){
717             String JavaDoc tmpUCrN = getDriverProperty(PARAMNAME_USE_CURSOR_NAME);
718             if (tmpUCrN==null){
719                 return DEFAULT_USE_CURSOR_NAME;
720             }else{
721                 if (tmpUCrN.equalsIgnoreCase("true")) {
722                     setUseCursorName(true);
723                     return true;
724                 }else if (tmpUCrN.equalsIgnoreCase("false")){
725                     setUseCursorName(false);
726                     return false;
727                 }else{
728                     DODS.getLogChannel().write(Logger.DEBUG,"Invalid value for UseCursorName parameter :"+tmpUCrN);
729                     return DEFAULT_USE_CURSOR_NAME;
730                 }
731             }
732         }else{
733             return dbConf.getUseCursorName().booleanValue();
734         }
735     }
736
737
738     /**
739      * Change value of UseCursorName property
740      * @param use
741      */

742     public void setUseCursorName(boolean use) {
743         dbConf.setUseCursorName(use);
744     }
745
746
747     /**
748      * Change value of UseCursorName property
749      * @param use
750      */

751     public void setUseCursorName(Boolean JavaDoc use) {
752         dbConf.setUseCursorName(use);
753     }
754
755
756     /**
757      * Return value of ResultSetType property
758      * @return Value of ResultSetType property
759      */

760     private void initResultSetType() {
761         String JavaDoc tmpUCrN = getDriverProperty(PARAMNAME_RESULT_SET_TYPE);
762         try {
763             if (tmpUCrN==null)
764                 dbConf.setResultSetType(DEFAULT_RESULT_SET_TYPE);
765             if(tmpUCrN.equalsIgnoreCase("TYPE_SCROLL_SENSITIVE"))
766                 dbConf.setResultSetType(ResultSet.TYPE_SCROLL_SENSITIVE);
767             else if (tmpUCrN.equalsIgnoreCase("TYPE_SCROLL_INSENSITIVE"))
768                 dbConf.setResultSetType(ResultSet.TYPE_SCROLL_INSENSITIVE);
769             else if (tmpUCrN.equalsIgnoreCase("TYPE_FORWARD_ONLY"))
770                 dbConf.setResultSetType(ResultSet.TYPE_FORWARD_ONLY);
771             else {
772                 DODS.getLogChannel().write(Logger.DEBUG,"Invalid value for ResultSetType parameter :"+tmpUCrN);
773                 dbConf.setResultSetType(DEFAULT_RESULT_SET_TYPE);
774             }
775         }catch(Exception JavaDoc ex) {
776             DODS.getLogChannel().write(Logger.DEBUG,"Use default value for ResultSetType parameter ");
777         }
778     }
779
780
781     /**
782      * Return value of ResultSetType property
783      * @return Value of ResultSetType property
784      */

785
786     public int getResultSetType(){
787         return dbConf.getResultSetType();
788     }
789
790
791     /**
792      * Return value of ResultSetConcurrency property
793      * @return Value of ResultSetConcurrency property
794      */

795     private void initResultSetConcurrency() {
796         String JavaDoc tmpUCrN = getDriverProperty(PARAMNAME_RESULT_SET_CONCURRENCY);
797         try{
798             if (tmpUCrN==null)
799                 dbConf.setResultSetConcurrency(DEFAULT_RESULT_SET_CONCURRENCY);
800             if(tmpUCrN.equalsIgnoreCase("CONCUR_READ_ONLY"))
801                 dbConf.setResultSetConcurrency(ResultSet.CONCUR_READ_ONLY);
802             else if (tmpUCrN.equalsIgnoreCase("CONCUR_UPDATABLE"))
803                 dbConf.setResultSetConcurrency(ResultSet.CONCUR_UPDATABLE);
804             else {
805                 DODS.getLogChannel().write(Logger.DEBUG,"Invalid value for ResultSetConcurrency parameter :"+tmpUCrN);
806                 dbConf.setResultSetConcurrency(DEFAULT_RESULT_SET_CONCURRENCY);
807             }
808         }catch(Exception JavaDoc ex) {
809             DODS.getLogChannel().write(Logger.DEBUG,"Use default value for ResultSetType parameter ");
810         }
811     }
812
813     /**
814      * Return value of ResultSetType property
815      * @return Value of ResultSetType property
816      */

817     public int getResultSetConcurrency(){
818         return dbConf.getResultSetConcurrency();
819     }
820
821     /**
822      * Method getDriverDependencies
823      *
824      * @return a DriverDependencies
825      */

826     public DriverDependencies getDriverDependencies() {
827         if (null == drivDepsInstance) {
828             String JavaDoc className = getDriverProperty(PARAMNAME_DRIV_DEP_CLASS);
829             try {
830                 if (null != className) {
831                     drivDepsInstance = (DriverDependencies)
832                         Class.forName(className)
833                         .newInstance();
834                 }
835             } catch (Exception JavaDoc e) {
836                 DODS.getLogChannel()
837                     .write(Logger.ERROR,
838                            "Didn't instantiated DriverDepenencies "
839                                + className,
840                            e);
841             } finally {
842                 if (null == drivDepsInstance)
843                     drivDepsInstance = new DriverDependencies() {
844                         public boolean isBlobAccessSpecial() { return false;}
845                         public byte[] readBlob(ResultSet JavaDoc rs, String JavaDoc c){ return null;}
846                         public void insertBlob(DBConnection conn,
847                                                byte[] cont,
848                                                RDBColumn primary,
849                                                RDBColumn blobColumn,
850                                                String JavaDoc handle){}
851                     };
852             }
853         }
854         return drivDepsInstance;
855     }
856 }
857
Popular Tags