KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derby > impl > db > BasicDatabase


1 /*
2
3    Derby - Class org.apache.derby.impl.db.BasicDatabase
4
5    Licensed to the Apache Software Foundation (ASF) under one or more
6    contributor license agreements. See the NOTICE file distributed with
7    this work for additional information regarding copyright ownership.
8    The ASF licenses this file to you under the Apache License, Version 2.0
9    (the "License"); you may not use this file except in compliance with
10    the License. You may obtain a copy of the License at
11
12       http://www.apache.org/licenses/LICENSE-2.0
13
14    Unless required by applicable law or agreed to in writing, software
15    distributed under the License is distributed on an "AS IS" BASIS,
16    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17    See the License for the specific language governing permissions and
18    limitations under the License.
19
20  */

21
22 package org.apache.derby.impl.db;
23
24 import org.apache.derby.iapi.error.PublicAPI;
25
26 import org.apache.derby.iapi.reference.Property;
27 import org.apache.derby.iapi.reference.SQLState;
28 import org.apache.derby.iapi.reference.EngineType;
29 import org.apache.derby.iapi.util.DoubleProperties;
30 import org.apache.derby.iapi.util.IdUtil;
31 import org.apache.derby.iapi.services.info.JVMInfo;
32
33 import org.apache.derby.iapi.services.property.PropertyUtil;
34 import org.apache.derby.iapi.services.loader.ClassFactory;
35 import org.apache.derby.iapi.services.loader.JarReader;
36 import org.apache.derby.iapi.services.context.ContextManager;
37 import org.apache.derby.iapi.services.context.ContextService;
38 import org.apache.derby.iapi.services.daemon.Serviceable;
39 import org.apache.derby.iapi.services.monitor.ModuleControl;
40 import org.apache.derby.iapi.services.monitor.ModuleSupportable;
41 import org.apache.derby.iapi.services.monitor.Monitor;
42 import org.apache.derby.iapi.services.monitor.ModuleFactory;
43 import org.apache.derby.iapi.services.sanity.SanityManager;
44 import org.apache.derby.iapi.services.property.PersistentSet;
45 import org.apache.derby.iapi.db.Database;
46 import org.apache.derby.iapi.db.DatabaseContext;
47 import org.apache.derby.iapi.error.StandardException;
48 import org.apache.derby.iapi.sql.execute.ExecutionFactory;
49 import org.apache.derby.iapi.types.DataValueFactory;
50 import org.apache.derby.iapi.sql.compile.OptimizerFactory;
51 import org.apache.derby.iapi.sql.conn.LanguageConnectionContext;
52 import org.apache.derby.iapi.sql.conn.ConnectionUtil;
53
54 import org.apache.derby.iapi.sql.conn.LanguageConnectionFactory;
55
56 import org.apache.derby.iapi.sql.dictionary.DataDictionary;
57 import org.apache.derby.iapi.sql.dictionary.DataDictionaryContext;
58 import org.apache.derby.iapi.sql.dictionary.FileInfoDescriptor;
59 import org.apache.derby.iapi.sql.dictionary.SchemaDescriptor;
60 import org.apache.derby.iapi.sql.dictionary.SPSDescriptor;
61
62 import org.apache.derby.iapi.sql.depend.DependencyManager;
63 import org.apache.derby.iapi.reference.SQLState;
64 import org.apache.derby.iapi.sql.LanguageFactory;
65 import org.apache.derby.iapi.sql.ResultSet;
66 import org.apache.derby.iapi.store.access.AccessFactory;
67 import org.apache.derby.iapi.store.access.FileResource;
68 import org.apache.derby.iapi.services.property.PropertyFactory;
69 import org.apache.derby.iapi.services.property.PropertySetCallback;
70 import org.apache.derby.iapi.store.access.TransactionController;
71 import org.apache.derby.iapi.jdbc.AuthenticationService;
72 import org.apache.derby.iapi.services.uuid.UUIDFactory;
73 import org.apache.derby.catalog.UUID;
74
75 import java.io.InputStream JavaDoc;
76 import java.io.OutputStream JavaDoc;
77 import java.io.Serializable JavaDoc;
78 import java.io.File JavaDoc;
79 import java.sql.Date JavaDoc;
80 import java.sql.Timestamp JavaDoc;
81 import java.sql.SQLException JavaDoc;
82 import java.util.Properties JavaDoc;
83 import java.util.Dictionary JavaDoc;
84 import java.util.Enumeration JavaDoc;
85 import java.util.Hashtable JavaDoc;
86 import java.util.Locale JavaDoc;
87 import java.lang.reflect.Method JavaDoc;
88 import java.text.Collator JavaDoc;
89 import java.text.RuleBasedCollator JavaDoc;
90 import java.text.DateFormat JavaDoc;
91
92 /**
93  * The Database interface provides control over the physical database
94  * (that is, the stored data and the files the data are stored in),
95  * connections to the database, operations on the database such as
96  * backup and recovery, and all other things that are associated
97  * with the database itself.
98  * <p>
99  * The Database interface does not provide control over things that are part of
100  * the Domain, such as users.
101  * <p>
102  * I'm not sure what this will hold in a real system, for now
103  * it simply provides connection-creation for us. Perhaps when it boots,
104  * it creates the datadictionary object for the database, which all users
105  * will then interact with?
106  *
107  * @author ames
108  */

109
110 public class BasicDatabase implements ModuleControl, ModuleSupportable, PropertySetCallback, Database, JarReader
111 {
112     private boolean active;
113     private AuthenticationService authenticationService;
114     protected AccessFactory af;
115     protected PropertyFactory pf;
116     protected ClassFactory cfDB; // classFactory but only set when per-database
117
protected LanguageConnectionFactory lcf;
118     protected LanguageFactory lf;
119     // hold resourceAdapter in an Object instead of a ResourceAdapter
120
// so that XA class use can be isolated to XA modules.
121
protected Object JavaDoc resourceAdapter;
122     private Locale JavaDoc databaseLocale;
123     private RuleBasedCollator JavaDoc ruleBasedCollator;
124     private int spaceInt;
125     private boolean spaceIntSet;
126     private DateFormat JavaDoc dateFormat;
127     private DateFormat JavaDoc timeFormat;
128     private DateFormat JavaDoc timestampFormat;
129     private UUID myUUID;
130     private boolean normalizeToUpper = true;
131
132     protected boolean lastToBoot; // is this class last to boot
133

134     /*
135      * ModuleControl interface
136      */

137
138     public boolean canSupport(Properties startParams) {
139
140         return Monitor.isDesiredCreateType(startParams, org.apache.derby.iapi.reference.EngineType.NONE);
141
142     }
143
144     protected Properties allParams; // properties to be used *only* while booting.
145

146     public void boot(boolean create, Properties startParams)
147         throws StandardException
148     {
149         ModuleFactory monitor = Monitor.getMonitor();
150         if (create)
151         {
152             if (startParams.getProperty(Property.CREATE_WITH_NO_LOG) == null)
153                 startParams.put(Property.CREATE_WITH_NO_LOG, "true");
154
155             String JavaDoc localeID = startParams.getProperty(org.apache.derby.iapi.reference.Attribute.TERRITORY);
156
157             if (localeID == null) {
158                 localeID = Locale.getDefault().toString();
159             }
160             databaseLocale = monitor.setLocale(startParams, localeID);
161
162         } else {
163             databaseLocale = monitor.getLocale(this);
164         }
165         setLocale(databaseLocale);
166
167         normalizeToUpper = true;
168         
169
170         // boot the validation needed to do property validation, now property
171
// validation is separated from AccessFactory, therefore from store
172
bootValidation(create, startParams);
173         
174         // boot the type factpry before store to ensure any dynamically
175
// registered types (DECIMAL) are there before logical undo recovery might need them.
176
Monitor.bootServiceModule(create, this,
177                     org.apache.derby.iapi.reference.ClassName.DataValueFactory, startParams);
178
179         bootStore(create, startParams);
180
181         // create a database ID if one doesn't already exist
182
myUUID = makeDatabaseID(create, startParams);
183
184
185         allParams = new DoubleProperties(getAllDatabaseProperties(), startParams);
186
187         if (pf != null)
188             pf.addPropertySetNotification(this);
189
190             // Boot the ClassFactory, will be per-database or per-system.
191
// reget the tc in case someone inadverdently destroyed it
192
bootClassFactory(create, allParams);
193
194         lcf = (LanguageConnectionFactory) Monitor.bootServiceModule(create, this, LanguageConnectionFactory.MODULE, allParams);
195         lf = (LanguageFactory) Monitor.bootServiceModule(create, this, LanguageFactory.MODULE, allParams);
196
197         bootResourceAdapter(create, startParams);
198
199
200         // may also want to set up a check that we are a singleton,
201
// or that there isn't already a database object in the system
202
// for the same database?
203

204
205         //
206
// We boot the authentication service. There should at least be one
207
// per database (even if authentication is turned off) .
208
//
209
authenticationService = bootAuthenticationService(create, allParams);
210         if (SanityManager.DEBUG) {
211             SanityManager.ASSERT(authenticationService != null,
212                                  "Failed to set the Authentication service for the database");
213         }
214
215         // Lastly, let store knows that database creation is done and turn
216
// on logging
217
if (create && lastToBoot &&
218             (startParams.getProperty(Property.CREATE_WITH_NO_LOG) != null))
219         {
220             createFinished();
221         }
222
223         active = true;
224
225         if (lastToBoot)
226             allParams = null; // should not be used anymore
227
}
228
229     public void stop() {
230         active = false;
231     }
232
233     /*
234     ** Methods related to ModuleControl
235     */

236
237     /*
238      * Database interface
239      */

240
241     /**
242       * @return one of the values from EngineType.java:
243       *
244       */

245     public int getEngineType() { return org.apache.derby.iapi.reference.EngineType.NONE; }
246
247     public boolean isReadOnly()
248     {
249         //
250
//Notice if no full users?
251
//RESOLVE: (Make access factory check?)
252
return af.isReadOnly();
253     }
254
255     public LanguageConnectionContext setupConnection(ContextManager cm, String JavaDoc user, String JavaDoc drdaID, String JavaDoc dbname)
256         throws StandardException {
257
258         TransactionController tc = getConnectionTransaction(cm);
259
260         cm.setLocaleFinder(this);
261         pushDbContext(cm);
262
263         // push a database shutdown context
264
// we also need to push a language connection context.
265
LanguageConnectionContext lctx = lcf.newLanguageConnectionContext(cm, tc, lf, this, user, drdaID, dbname);
266
267         // push the context that defines our class factory
268
pushClassFactoryContext(cm, lcf.getClassFactory());
269
270         // we also need to push an execution context.
271
ExecutionFactory ef = lcf.getExecutionFactory();
272
273         ef.newExecutionContext(cm);
274         //
275
//Initialize our language connection context. Note: This is
276
//a bit of a hack. Unfortunately, we can't initialize this
277
//when we push it. We first must push a few more contexts.
278
lctx.initialize(true);
279
280         // Need to commit this to release locks gotten in initialize.
281
// Commit it but make sure transaction not have any updates.
282
lctx.internalCommitNoSync(
283             TransactionController.RELEASE_LOCKS |
284             TransactionController.READONLY_TRANSACTION_INITIALIZATION);
285
286         return lctx;
287
288     }
289
290     public void pushDbContext(ContextManager cm)
291     {
292         /* We cache the locale in the DatabaseContext
293          * so that the Datatypes can get to it easily.
294          */

295         DatabaseContext dc = new DatabaseContextImpl(cm, this);
296     }
297
298     public final AuthenticationService getAuthenticationService() {
299
300         // Expected to find one - Sanity check being done at
301
// DB boot-up.
302

303         // We should have a Authentication Service
304
//
305
if (SanityManager.DEBUG)
306         {
307             SanityManager.ASSERT(this.authenticationService != null,
308                 "Unexpected - There is no valid authentication service for the database!");
309         }
310         return this.authenticationService;
311     }
312
313     public void freeze() throws SQLException JavaDoc
314     {
315         try {
316             af.freeze();
317         } catch (StandardException se) {
318             throw PublicAPI.wrapStandardException(se);
319         }
320     }
321
322     public void unfreeze() throws SQLException JavaDoc
323     {
324         try {
325             af.unfreeze();
326         } catch (StandardException se) {
327             throw PublicAPI.wrapStandardException(se);
328         }
329     }
330
331
332     public void backup(String JavaDoc backupDir, boolean wait)
333         throws SQLException JavaDoc
334     {
335         try {
336             af.backup(backupDir, wait);
337         } catch (StandardException se) {
338             throw PublicAPI.wrapStandardException(se);
339         }
340     }
341
342
343     public void backupAndEnableLogArchiveMode(String JavaDoc backupDir,
344                                               boolean deleteOnlineArchivedLogFiles,
345                                               boolean wait)
346         throws SQLException JavaDoc
347     {
348         try {
349             af.backupAndEnableLogArchiveMode(backupDir,
350                                              deleteOnlineArchivedLogFiles,
351                                              wait);
352         } catch (StandardException se) {
353             throw PublicAPI.wrapStandardException(se);
354         }
355     }
356
357     
358     public void disableLogArchiveMode(boolean deleteOnlineArchivedLogFiles)
359         throws SQLException JavaDoc
360     {
361         try{
362             af.disableLogArchiveMode(deleteOnlineArchivedLogFiles);
363         }catch (StandardException se) {
364             throw PublicAPI.wrapStandardException(se);
365         }
366     }
367
368
369     public void checkpoint() throws SQLException JavaDoc
370     {
371         try {
372             af.checkpoint();
373         } catch (StandardException se) {
374             throw PublicAPI.wrapStandardException(se);
375         }
376     }
377
378     /* Methods from org.apache.derby.database.Database */
379     public Locale JavaDoc getLocale() {
380         return databaseLocale;
381     }
382
383
384     /**
385         Return the UUID of this database.
386     */

387     public final UUID getId() {
388         return myUUID;
389     }
390
391     /* LocaleFinder methods */
392
393     /** @exception StandardException Thrown on error */
394     public Locale JavaDoc getCurrentLocale() throws StandardException {
395         if (databaseLocale != null)
396             return databaseLocale;
397         throw noLocale();
398     }
399
400     /** @exception StandardException Thrown on error */
401     public RuleBasedCollator JavaDoc getCollator() throws StandardException {
402         RuleBasedCollator JavaDoc retval = ruleBasedCollator;
403
404         if (retval == null) {
405             if (databaseLocale != null) {
406                 retval = ruleBasedCollator =
407                     (RuleBasedCollator JavaDoc) Collator.getInstance(databaseLocale);
408             } else {
409                 throw noLocale();
410             }
411         }
412
413         return retval;
414     }
415
416
417     /** @exception StandardException Thrown on error */
418     public DateFormat JavaDoc getDateFormat() throws StandardException {
419         if (databaseLocale != null) {
420             if (dateFormat == null) {
421                 dateFormat = DateFormat.getDateInstance(DateFormat.LONG,
422                                                                 databaseLocale);
423             }
424
425             return dateFormat;
426         }
427
428         throw noLocale();
429     }
430
431     /** @exception StandardException Thrown on error */
432     public DateFormat JavaDoc getTimeFormat() throws StandardException {
433         if (databaseLocale != null) {
434             if (timeFormat == null) {
435                 timeFormat = DateFormat.getTimeInstance(DateFormat.LONG,
436                                                                 databaseLocale);
437             }
438
439             return timeFormat;
440         }
441
442         throw noLocale();
443     }
444
445     /** @exception StandardException Thrown on error */
446     public DateFormat JavaDoc getTimestampFormat() throws StandardException {
447         if (databaseLocale != null) {
448             if (timestampFormat == null) {
449                 timestampFormat = DateFormat.getDateTimeInstance(
450                                                             DateFormat.LONG,
451                                                             DateFormat.LONG,
452                                                             databaseLocale);
453             }
454
455             return timestampFormat;
456         }
457
458         throw noLocale();
459     }
460
461     private static StandardException noLocale() {
462         return StandardException.newException(SQLState.NO_LOCALE);
463     }
464
465     public void setLocale(Locale JavaDoc locale) {
466         databaseLocale = locale;
467
468         dateFormat = null;
469         timeFormat = null;
470         timestampFormat = null;
471     }
472
473     /**
474         Is the database active (open).
475     */

476     public boolean isActive() {
477         return active;
478     }
479
480     /*
481      * class interface
482      */

483     public BasicDatabase() {
484         lastToBoot = true;
485     }
486
487
488     protected UUID makeDatabaseID(boolean create, Properties startParams)
489         throws StandardException
490     {
491         
492         TransactionController tc = af.getTransaction(
493                 ContextService.getFactory().getCurrentContextManager());
494
495         String JavaDoc upgradeID = null;
496         UUID databaseID;
497
498         if ((databaseID = (UUID) tc.getProperty(DataDictionary.DATABASE_ID)) == null) {
499
500             // no property defined in the Transaction set
501
// this could be an upgrade, see if it's stored in the service set
502

503             UUIDFactory uuidFactory = Monitor.getMonitor().getUUIDFactory();
504
505             
506             upgradeID = startParams.getProperty(DataDictionary.DATABASE_ID);
507             if (upgradeID == null )
508             {
509                 // just create one
510
databaseID = uuidFactory.createUUID();
511             } else {
512                 databaseID = uuidFactory.recreateUUID(upgradeID);
513             }
514
515             tc.setProperty(DataDictionary.DATABASE_ID, databaseID, true);
516         }
517
518         // Remove the database identifier from the service.properties
519
// file only if we upgraded it to be stored in the transactional
520
// property set.
521
if (upgradeID != null)
522             startParams.remove(DataDictionary.DATABASE_ID);
523
524         tc.commit();
525         tc.destroy();
526
527         return databaseID;
528     }
529
530     /**
531      * Drop all Stored Prepared Statements that
532      * have been created for JDBC MetaData queries.
533      * Does NOT commit the current transaction
534      * upon completation.
535      *
536      * @exception SQLException on error, most likely
537      * a deadlock or timeout.
538      */

539     public void dropAllJDBCMetaDataSPSes() throws SQLException JavaDoc
540     {
541         try
542         {
543             LanguageConnectionContext lcc = ConnectionUtil.getCurrentLCC();
544
545             DataDictionary dd = lcc.getDataDictionary();
546
547             TransactionController tc = lcc.getTransactionExecute();
548
549             /*
550             ** Inform the data dictionary we are going
551             ** to perform some DDL
552             */

553             dd.startWriting(lcc);
554
555             for (java.util.ListIterator JavaDoc li = dd.getAllSPSDescriptors().listIterator(); li.hasNext(); )
556             {
557                 SPSDescriptor spsd = (SPSDescriptor) li.next();
558
559                 /*
560                 ** Is it in SYS? if so, zap it. Can't drop metadata SPS in SYSIBM, JCC depends on it.
561                 */

562                 if (spsd.getSchemaDescriptor().isSystemSchema() && !spsd.getSchemaDescriptor().isSYSIBM())
563                 {
564                     dd.dropSPSDescriptor(spsd, tc);
565                     dd.dropDependentsStoredDependencies(spsd.getUUID(), tc);
566                 }
567             }
568         } catch (StandardException se)
569         {
570             throw PublicAPI.wrapStandardException(se);
571         }
572     }
573
574     /*
575     ** Return an Object instead of a ResourceAdapter
576     ** so that XA classes are only used where needed;
577     ** caller must cast to ResourceAdapter.
578     */

579     public Object JavaDoc getResourceAdapter()
580     {
581         return resourceAdapter;
582     }
583
584     /*
585     ** Methods of PropertySetCallback
586     */

587     public void init(boolean dbOnly, Dictionary p) {
588         // not called yet ...
589
}
590
591     /**
592       @see PropertySetCallback#validate
593       @exception StandardException Thrown on error.
594     */

595     public boolean validate(String JavaDoc key,
596                          Serializable JavaDoc value,
597                          Dictionary p)
598         throws StandardException
599     {
600         //
601
//Disallow setting static creation time only configuration properties
602
if (key.equals(EngineType.PROPERTY))
603             throw StandardException.newException(SQLState.PROPERTY_UNSUPPORTED_CHANGE, key, value);
604     
605         // only interested in the classpath
606
if (!key.equals(Property.DATABASE_CLASSPATH)) return false;
607
608         String JavaDoc newClasspath = (String JavaDoc) value;
609         String JavaDoc[][] dbcp = null; //The parsed dbclasspath
610

611         if (newClasspath != null) {
612             // parse it when it is set to ensure only valid values
613
// are written to the actual conglomerate.
614
dbcp = IdUtil.parseDbClassPath(newClasspath, normalizeToUpper);
615         }
616
617         DataDictionaryContext ddc =
618             (DataDictionaryContext)ContextService.getContext(DataDictionaryContext.CONTEXT_ID);
619         if (SanityManager.DEBUG)
620             if (ddc == null) SanityManager.THROWASSERT("Class path change with no connection");
621         DataDictionary dd = ddc.getDataDictionary();
622
623         //
624
//Verify that all jar files on the database classpath are in the data dictionary.
625
if (dbcp != null)
626         {
627             for (int ix=0;ix<dbcp.length;ix++)
628             {
629                 SchemaDescriptor sd = dd.getSchemaDescriptor(dbcp[ix][IdUtil.DBCP_SCHEMA_NAME], null, false);
630
631                 FileInfoDescriptor fid = null;
632                 if (sd != null)
633                     fid = dd.getFileInfoDescriptor(sd,dbcp[ix][IdUtil.DBCP_SQL_JAR_NAME]);
634
635                 if (fid == null){
636                     throw StandardException.newException(SQLState.LANG_DB_CLASS_PATH_HAS_MISSING_JAR , IdUtil.mkQualifiedName(dbcp[ix]));
637                 }
638             }
639         }
640
641         return true;
642     }
643     /**
644       @see PropertySetCallback#apply
645       @exception StandardException Thrown on error.
646     */

647     public Serviceable apply(String JavaDoc key, Serializable JavaDoc value, Dictionary p)
648         throws StandardException
649     {
650         // only interested in the classpath
651
if (!key.equals(Property.DATABASE_CLASSPATH)) return null;
652
653         // only do the change dynamically if we are already
654
// a per-database classapath.
655
if (cfDB != null) {
656             DataDictionaryContext ddc =
657                 (DataDictionaryContext)ContextService.getContext(DataDictionaryContext.CONTEXT_ID);
658             if (SanityManager.DEBUG)
659                 if (ddc == null) SanityManager.THROWASSERT("Class path change with no connection");
660             DataDictionary dd = ddc.getDataDictionary();
661
662             //
663
// Invalidate stored plans.
664
dd.invalidateAllSPSPlans();
665         
666             String JavaDoc newClasspath = (String JavaDoc) value;
667             if (newClasspath == null) newClasspath = "";
668             cfDB.notifyModifyClasspath(newClasspath);
669         }
670         return null;
671     }
672     /**
673       @see PropertySetCallback#map
674     */

675     public Serializable JavaDoc map(String JavaDoc key,Serializable JavaDoc value,Dictionary p)
676     {
677         return null;
678     }
679
680     /*
681      * methods specific to this class
682      */

683     protected void createFinished() throws StandardException
684     {
685         // find the access factory and tell it that database creation has
686
// finished
687
af.createFinished();
688     }
689
690     protected String JavaDoc getClasspath(Properties startParams) {
691         String JavaDoc cp = PropertyUtil.getPropertyFromSet(startParams, Property.DATABASE_CLASSPATH);
692         if (cp == null)
693             cp = PropertyUtil.getSystemProperty(Property.DATABASE_CLASSPATH, "");
694         return cp;
695     }
696
697
698     protected void bootClassFactory(boolean create,
699                                   Properties startParams)
700          throws StandardException
701     {
702             String JavaDoc classpath = getClasspath(startParams);
703
704             // parse the class path and allow 2 part names.
705
boolean normalizeToUpper = true;
706             String JavaDoc[][] elements =
707                 IdUtil.parseDbClassPath(classpath, normalizeToUpper);
708
709             startParams.put(Property.BOOT_DB_CLASSPATH, classpath);
710             cfDB = (ClassFactory) Monitor.bootServiceModule(create, this,
711                     org.apache.derby.iapi.reference.Module.ClassFactory, startParams);
712     }
713
714
715     /*
716     ** Methods to allow sub-classes to offer alternate implementations.
717     */

718
719     protected TransactionController getConnectionTransaction(ContextManager cm)
720         throws StandardException {
721
722         // start a local transaction
723
return af.getTransaction(cm);
724     }
725
726     protected AuthenticationService bootAuthenticationService(boolean create, Properties props) throws StandardException {
727         return (AuthenticationService)
728                 Monitor.bootServiceModule(create, this, AuthenticationService.MODULE, props);
729     }
730
731     protected void bootValidation(boolean create, Properties startParams)
732         throws StandardException {
733         pf = (PropertyFactory) Monitor.bootServiceModule(create, this,
734             org.apache.derby.iapi.reference.Module.PropertyFactory, startParams);
735     }
736
737     protected void bootStore(boolean create, Properties startParams)
738         throws StandardException {
739         af = (AccessFactory) Monitor.bootServiceModule(create, this, AccessFactory.MODULE, startParams);
740     }
741
742     protected Properties getAllDatabaseProperties()
743         throws StandardException {
744
745         TransactionController tc = af.getTransaction(
746                     ContextService.getFactory().getCurrentContextManager());
747         Properties dbProps = tc.getProperties();
748         tc.commit();
749         tc.destroy();
750
751         return dbProps;
752     }
753
754     protected void bootResourceAdapter(boolean create, Properties startParams) {
755
756         // Boot resource adapter - only if we are running Java 2 or
757
// beyondwith JDBC20 extension, JTA and JNDI classes in the classpath
758
//
759
// assume if it doesn't boot it was because the required
760
// classes were missing, and continue without it.
761
// Done this way to work around Chai's need to preload
762
// classes.
763
// Assume both of these classes are in the class path.
764
// Assume we may need a ResourceAdapter since we don't know how
765
// this database is going to be used.
766
try
767         {
768             resourceAdapter =
769                 Monitor.bootServiceModule(create, this,
770                                          org.apache.derby.iapi.reference.Module.ResourceAdapter,
771                                          allParams);
772         }
773         catch (StandardException mse)
774         {
775             // OK, resourceAdapter is an optional module
776
}
777     }
778
779     protected void pushClassFactoryContext(ContextManager cm, ClassFactory cf) {
780         new StoreClassFactoryContext(cm, cf, af, this);
781     }
782
783     /*
784     ** Methods of JarReader
785     */

786     public Object JavaDoc readJarFile(String JavaDoc schemaName, String JavaDoc sqlName)
787         throws StandardException {
788
789         DataDictionaryContext ddc =
790             (DataDictionaryContext) ContextService.getContext(DataDictionaryContext.CONTEXT_ID);
791         DataDictionary dd = ddc.getDataDictionary();
792
793         SchemaDescriptor sd = dd.getSchemaDescriptor(schemaName, null, true);
794         FileInfoDescriptor fid = dd.getFileInfoDescriptor(sd,sqlName);
795         if (fid == null)
796             throw StandardException.newException(SQLState.LANG_FILE_DOES_NOT_EXIST, sqlName,schemaName);
797
798         long generationId = fid.getGenerationId();
799
800         FileResource fr = af.getTransaction(ddc.getContextManager()).getFileHandler();
801
802         String JavaDoc externalName = org.apache.derby.impl.sql.execute.JarDDL.mkExternalName(schemaName, sqlName, fr.getSeparatorChar());
803
804         Object JavaDoc f = fr.getAsFile(externalName, generationId);
805         if (f instanceof java.io.File JavaDoc)
806             return f;
807
808         try {
809             return fr.getAsStream(externalName, generationId);
810         } catch (java.io.IOException JavaDoc ioe) {
811             throw StandardException.newException(SQLState.LANG_FILE_ERROR, ioe, ioe.toString());
812         }
813     }
814
815 }
816
Popular Tags