📄 basicdatabase.java
字号:
/* Derby - Class org.apache.derby.impl.db.BasicDatabase Copyright 1997, 2004 The Apache Software Foundation or its licensors, as applicable. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */package org.apache.derby.impl.db;import org.apache.derby.iapi.error.PublicAPI;import org.apache.derby.iapi.reference.Property;import org.apache.derby.iapi.reference.SQLState;import org.apache.derby.iapi.reference.EngineType;import org.apache.derby.iapi.util.DoubleProperties;import org.apache.derby.iapi.util.IdUtil;import org.apache.derby.iapi.services.info.JVMInfo;import org.apache.derby.iapi.services.property.PropertyUtil;import org.apache.derby.iapi.services.loader.ClassFactory;import org.apache.derby.iapi.services.loader.JarReader;import org.apache.derby.iapi.services.context.ContextManager;import org.apache.derby.iapi.services.context.ContextService;import org.apache.derby.iapi.services.daemon.Serviceable;import org.apache.derby.iapi.services.monitor.ModuleControl;import org.apache.derby.iapi.services.monitor.ModuleSupportable;import org.apache.derby.iapi.services.monitor.Monitor;import org.apache.derby.iapi.services.monitor.ModuleFactory;import org.apache.derby.iapi.services.sanity.SanityManager;import org.apache.derby.iapi.services.property.PersistentSet;import org.apache.derby.iapi.db.Database;import org.apache.derby.iapi.db.DatabaseContext;import org.apache.derby.iapi.error.StandardException;import org.apache.derby.iapi.sql.execute.ExecutionFactory;import org.apache.derby.iapi.types.DataValueFactory;import org.apache.derby.iapi.sql.compile.OptimizerFactory;import org.apache.derby.iapi.sql.conn.LanguageConnectionContext;import org.apache.derby.iapi.sql.conn.ConnectionUtil;import org.apache.derby.iapi.sql.conn.LanguageConnectionFactory;import org.apache.derby.iapi.sql.dictionary.DataDictionary;import org.apache.derby.iapi.sql.dictionary.DataDictionaryContext;import org.apache.derby.iapi.sql.dictionary.FileInfoDescriptor;import org.apache.derby.iapi.sql.dictionary.SchemaDescriptor;import org.apache.derby.iapi.sql.dictionary.SPSDescriptor;import org.apache.derby.iapi.sql.depend.DependencyManager;import org.apache.derby.iapi.reference.SQLState;import org.apache.derby.iapi.sql.LanguageFactory;import org.apache.derby.iapi.sql.ResultSet;import org.apache.derby.iapi.store.access.AccessFactory;import org.apache.derby.iapi.store.access.FileResource;import org.apache.derby.iapi.services.property.PropertyFactory;import org.apache.derby.iapi.services.property.PropertySetCallback;import org.apache.derby.iapi.store.access.TransactionController;import org.apache.derby.iapi.jdbc.AuthenticationService;import org.apache.derby.iapi.services.uuid.UUIDFactory;import org.apache.derby.catalog.UUID;import java.io.InputStream;import java.io.OutputStream;import java.io.Serializable;import java.io.File;import java.sql.Date;import java.sql.Timestamp;import java.sql.SQLException;import java.util.Properties;import java.util.Dictionary;import java.util.Enumeration;import java.util.Hashtable;import java.util.Locale;import java.lang.reflect.Method;import java.text.Collator;import java.text.RuleBasedCollator;import java.text.DateFormat;/** * The Database interface provides control over the physical database * (that is, the stored data and the files the data are stored in), * connections to the database, operations on the database such as * backup and recovery, and all other things that are associated * with the database itself. * <p> * The Database interface does not provide control over things that are part of * the Domain, such as users. * <p> * I'm not sure what this will hold in a real system, for now * it simply provides connection-creation for us. Perhaps when it boots, * it creates the datadictionary object for the database, which all users * will then interact with? * * @author ames */public class BasicDatabase implements ModuleControl, ModuleSupportable, PropertySetCallback, Database, JarReader{ private boolean active; private AuthenticationService authenticationService; protected AccessFactory af; protected PropertyFactory pf; protected ClassFactory cfDB; // classFactory but only set when per-database protected LanguageConnectionFactory lcf; protected LanguageFactory lf; // hold resourceAdapter in an Object instead of a ResourceAdapter // so that XA class use can be isolated to XA modules. protected Object resourceAdapter; private Locale databaseLocale; private RuleBasedCollator ruleBasedCollator; private int spaceInt; private boolean spaceIntSet; private DateFormat dateFormat; private DateFormat timeFormat; private DateFormat timestampFormat; private UUID myUUID; private boolean normalizeToUpper = true; protected boolean lastToBoot; // is this class last to boot /* * ModuleControl interface */ public boolean canSupport(Properties startParams) { return Monitor.isDesiredCreateType(startParams, org.apache.derby.iapi.reference.EngineType.NONE); } protected Properties allParams; // properties to be used *only* while booting. public void boot(boolean create, Properties startParams) throws StandardException { ModuleFactory monitor = Monitor.getMonitor(); if (create) { if (startParams.getProperty(Property.CREATE_WITH_NO_LOG) == null) startParams.put(Property.CREATE_WITH_NO_LOG, "true"); String localeID = startParams.getProperty(org.apache.derby.iapi.reference.Attribute.TERRITORY); if (localeID == null) { localeID = Locale.getDefault().toString(); } databaseLocale = monitor.setLocale(startParams, localeID); } else { databaseLocale = monitor.getLocale(this); } setLocale(databaseLocale); normalizeToUpper = true; // boot the validation needed to do property validation, now property // validation is separated from AccessFactory, therefore from store bootValidation(create, startParams); // boot the type factpry before store to ensure any dynamically // registered types (DECIMAL) are there before logical undo recovery might need them. Monitor.bootServiceModule(create, this, org.apache.derby.iapi.reference.ClassName.DataValueFactory, startParams); bootStore(create, startParams); // create a database ID if one doesn't already exist myUUID = makeDatabaseID(create, startParams); allParams = new DoubleProperties(getAllDatabaseProperties(), startParams); if (pf != null) pf.addPropertySetNotification(this); // Boot the ClassFactory, will be per-database or per-system. // reget the tc in case someone inadverdently destroyed it bootClassFactory(create, allParams); lcf = (LanguageConnectionFactory) Monitor.bootServiceModule(create, this, LanguageConnectionFactory.MODULE, allParams); lf = (LanguageFactory) Monitor.bootServiceModule(create, this, LanguageFactory.MODULE, allParams); bootResourceAdapter(create, startParams); // may also want to set up a check that we are a singleton, // or that there isn't already a database object in the system // for the same database? // // We boot the authentication service. There should at least be one // per database (even if authentication is turned off) . // authenticationService = bootAuthenticationService(create, allParams); if (SanityManager.DEBUG) { SanityManager.ASSERT(authenticationService != null, "Failed to set the Authentication service for the database"); } // Lastly, let store knows that database creation is done and turn // on logging if (create && lastToBoot && (startParams.getProperty(Property.CREATE_WITH_NO_LOG) != null)) { createFinished(); } active = true; if (lastToBoot) allParams = null; // should not be used anymore } public void stop() { active = false; } /* ** Methods related to ModuleControl */ /* * Database interface */ /** * @return one of the values from EngineType.java: * */ public int getEngineType() { return org.apache.derby.iapi.reference.EngineType.NONE; } public boolean isReadOnly() { // //Notice if no full users? //RESOLVE: (Make access factory check?) return af.isReadOnly(); } public LanguageConnectionContext setupConnection(ContextManager cm, String user, String drdaID, String dbname) throws StandardException { TransactionController tc = getConnectionTransaction(cm); cm.setLocaleFinder(this); pushDbContext(cm); // push a database shutdown context // we also need to push a language connection context. LanguageConnectionContext lctx = lcf.newLanguageConnectionContext(cm, tc, lf, this, user, drdaID, dbname); // push the context that defines our class factory pushClassFactoryContext(cm, lcf.getClassFactory()); // we also need to push an execution context. ExecutionFactory ef = lcf.getExecutionFactory(); ef.newExecutionContext(cm); // //Initialize our language connection context. Note: This is //a bit of a hack. Unfortunately, we can't initialize this //when we push it. We first must push a few more contexts. lctx.initialize(true); // Need to commit this to release locks gotten in initialize. // Commit it but make sure transaction not have any updates. lctx.internalCommitNoSync( TransactionController.RELEASE_LOCKS | TransactionController.READONLY_TRANSACTION_INITIALIZATION); return lctx; } public void pushDbContext(ContextManager cm) { /* We cache the locale in the DatabaseContext * so that the Datatypes can get to it easily. */ DatabaseContext dc = new DatabaseContextImpl(cm, this); } public final AuthenticationService getAuthenticationService() { // Expected to find one - Sanity check being done at // DB boot-up. // We should have a Authentication Service // if (SanityManager.DEBUG) { SanityManager.ASSERT(this.authenticationService != null, "Unexpected - There is no valid authentication service for the database!"); } return this.authenticationService; } public void freeze() throws SQLException { try { af.freeze(); } catch (StandardException se) { throw PublicAPI.wrapStandardException(se); } } public void unfreeze() throws SQLException { try { af.unfreeze(); } catch (StandardException se) { throw PublicAPI.wrapStandardException(se); } } public void backup(String backupDir) throws SQLException { try { af.backup(backupDir); } catch (StandardException se) { throw PublicAPI.wrapStandardException(se); } } public void backup(File backupDir) throws SQLException { try { af.backup(backupDir); } catch (StandardException se) { throw PublicAPI.wrapStandardException(se); } } public void backupAndEnableLogArchiveMode(String backupDir, boolean deleteOnlineArchivedLogFiles) throws SQLException { try { af.backupAndEnableLogArchiveMode(backupDir, deleteOnlineArchivedLogFiles); } catch (StandardException se) { throw PublicAPI.wrapStandardException(se); } } public void backupAndEnableLogArchiveMode(File backupDir, boolean deleteOnlineArchivedLogFiles) throws SQLException { try { af.backupAndEnableLogArchiveMode(backupDir, deleteOnlineArchivedLogFiles); } catch (StandardException se) { throw PublicAPI.wrapStandardException(se); } } public void disableLogArchiveMode(boolean deleteOnlineArchivedLogFiles) throws SQLException { try{ af.disableLogArchiveMode(deleteOnlineArchivedLogFiles); }catch (StandardException se) { throw PublicAPI.wrapStandardException(se); } } public void checkpoint() throws SQLException { try { af.checkpoint(); } catch (StandardException se) { throw PublicAPI.wrapStandardException(se); } } /* Methods from org.apache.derby.database.Database */ public Locale getLocale() { return databaseLocale; } /** Return the UUID of this database. */ public final UUID getId() { return myUUID; } /* LocaleFinder methods */ /** @exception StandardException Thrown on error */ public Locale getCurrentLocale() throws StandardException { if (databaseLocale != null) return databaseLocale; throw noLocale(); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -