⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 basedatafilefactory.java

📁 derby database source code.good for you.
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
/*   Derby - Class org.apache.derby.impl.store.raw.data.BaseDataFileFactory   Copyright 1998, 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.store.raw.data;import org.apache.derby.iapi.reference.SQLState;import org.apache.derby.iapi.reference.MessageId;import org.apache.derby.impl.store.raw.data.AllocationActions;import org.apache.derby.impl.store.raw.data.BaseContainerHandle;import org.apache.derby.impl.store.raw.data.BasePage;import org.apache.derby.impl.store.raw.data.DirectActions;import org.apache.derby.impl.store.raw.data.LoggableActions;import org.apache.derby.impl.store.raw.data.PageActions;import org.apache.derby.impl.store.raw.data.RecordId;import org.apache.derby.impl.store.raw.data.ReclaimSpace;import org.apache.derby.iapi.services.info.ProductVersionHolder;import org.apache.derby.iapi.services.info.ProductGenusNames;import org.apache.derby.iapi.services.cache.CacheFactory;import org.apache.derby.iapi.services.cache.CacheManager;import org.apache.derby.iapi.services.cache.Cacheable;import org.apache.derby.iapi.services.cache.CacheableFactory;import org.apache.derby.iapi.services.context.ContextManager;import org.apache.derby.iapi.services.daemon.DaemonService;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.PersistentService;import org.apache.derby.iapi.services.diag.Performance;import org.apache.derby.iapi.services.sanity.SanityManager;import org.apache.derby.iapi.services.io.FormatIdUtil;import org.apache.derby.iapi.services.stream.HeaderPrintWriter;import org.apache.derby.iapi.error.StandardException;import org.apache.derby.iapi.services.i18n.MessageService;import org.apache.derby.iapi.store.access.AccessFactoryGlobals;import org.apache.derby.iapi.store.access.FileResource;import org.apache.derby.iapi.store.access.TransactionController;import org.apache.derby.iapi.store.raw.data.DataFactory;import org.apache.derby.iapi.store.raw.data.RawContainerHandle;import org.apache.derby.iapi.store.raw.log.LogFactory;import org.apache.derby.iapi.store.raw.log.LogInstant;import org.apache.derby.iapi.store.raw.ContainerHandle;import org.apache.derby.iapi.store.raw.ContainerKey;import org.apache.derby.iapi.store.raw.LockingPolicy;import org.apache.derby.iapi.store.raw.Page;import org.apache.derby.iapi.store.raw.RawStoreFactory;import org.apache.derby.iapi.store.raw.RecordHandle;import org.apache.derby.iapi.store.raw.StreamContainerHandle;import org.apache.derby.iapi.store.raw.Transaction;import org.apache.derby.iapi.store.raw.xact.RawTransaction;import org.apache.derby.iapi.store.access.RowSource;import org.apache.derby.io.StorageFactory;import org.apache.derby.io.WritableStorageFactory;import org.apache.derby.io.StorageFile;import org.apache.derby.io.StorageRandomAccessFile;import org.apache.derby.iapi.services.uuid.UUIDFactory;import org.apache.derby.catalog.UUID;import org.apache.derby.iapi.reference.Attribute;import org.apache.derby.iapi.reference.Property;import org.apache.derby.iapi.reference.SQLState;import org.apache.derby.iapi.util.ByteArray;import org.apache.derby.iapi.services.io.FileUtil;import org.apache.derby.iapi.util.CheapDateFormatter;import org.apache.derby.iapi.util.ReuseFactory;import org.apache.derby.iapi.services.property.PropertyUtil;import java.util.Properties;import java.util.Hashtable;import java.util.Enumeration;import java.io.File;import java.io.FilePermission;import java.io.OutputStream;import java.io.IOException;import java.security.AccessController;import java.security.PrivilegedAction;import java.security.PrivilegedExceptionAction;import java.security.PrivilegedActionException;/**Provides the abstract class with most of the implementation of DataFactory andModuleControl shared by all the different filesystem implementations.<p>RESOLVE (mikem - 2/19/98) -Currently only getContainerClass() is abstract, there are probably more routines which should be abstract.  Also the other implementations should probably inherit from the abstract class, rather than from the DataFileFactoryclass.  Also there probably should be a generic directory and the rest of thefilesystem implementations parallel to it.I wanted to limit the changes going into the branch and then fix inheritance stuff in main.<p>The code in this class was moved over from DataFileFactory.java and thenthat file was made to inherit from this one.**/public final class BaseDataFileFactory    implements DataFactory, CacheableFactory, ModuleControl, ModuleSupportable, PrivilegedExceptionAction{    private String subSubProtocol;    StorageFactory storageFactory;    /* writableStorageFactory == (WritableStorageFactory) storageFactory if storageFactory also     * implements WritableStorageFactory, null if the storageFactory is read-only.     */    WritableStorageFactory writableStorageFactory;	private     long		    nextContainerId = System.currentTimeMillis();	private     boolean         databaseEncrypted;	private     CacheManager	pageCache;	private     CacheManager	containerCache;	private     LogFactory	    logFactory;	private     ProductVersionHolder jbmsVersion;	private     RawStoreFactory	rawStoreFactory; // associated raw store factory	private     String			dataDirectory;	 // root directory of files.    private     boolean         throwDBlckException; // if true throw db.lck                                                 // exception, even on systems                                                 // where lock file is not                                                 // guaranteed.	private     UUID            identifier;      // unique id for locking 	private     Object          freezeSemaphore;    // is the data store frozen - protected by freezeSemaphore	private     boolean         isFrozen;	         // how many writers are currently active in the data store -     // protected by freezeSemaphore	private     int             writersInProgress; 	private boolean removeStubsOK;	private boolean isCorrupt;    // the database is being created, no logging	private boolean inCreateNoLog;		// lock against other JBMS opening the same database	private StorageRandomAccessFile fileLockOnDB;	private StorageFile exFileLock; //file handle to get exclusive lock	private HeaderPrintWriter istream;	private static final String LINE =         "----------------------------------------------------------------";    // disable syncing of data during page allocation.    boolean dataNotSyncedAtAllocation = false;    // disable syncing of data during checkpoint.    boolean dataNotSyncedAtCheckpoint = false;	// these fields can be accessed directly by subclasses if it needs a	// different set of actions	private PageActions       loggablePageActions; 	private AllocationActions loggableAllocActions;	private boolean		    readOnly; 		// is this a read only data store    private boolean supportsRandomAccess;	private FileResource	    fileHandler;	// my file handler, set by a                                                 // sub-class in its boot method.	//hash table to keep track of information about dropped containers stubs	private Hashtable droppedTableStubInfo;	private Hashtable postRecoveryRemovedFiles;    // PrivilegedAction actions    private int actionCode;    private static final int GET_TEMP_DIRECTORY_ACTION = 1;    private static final int REMOVE_TEMP_DIRECTORY_ACTION = 2;    private static final int GET_CONTAINER_PATH_ACTION = 3;    private ContainerKey containerId;    private boolean stub;    private static final int GET_ALTERNATE_CONTAINER_PATH_ACTION = 4;    private static final int FIND_MAX_CONTAINER_ID_ACTION = 5;    private static final int DELETE_IF_EXISTS_ACTION = 6;    private static final int GET_PATH_ACTION = 7;    private static final int POST_RECOVERY_REMOVE_ACTION = 8;    private static final int REMOVE_STUBS_ACTION = 9;    private StorageFile actionFile;    private static final int BOOT_ACTION = 10;    private static final int GET_LOCK_ON_DB_ACTION = 11;    private UUID myUUID;    private UUIDFactory uuidFactory;    private String databaseDirectory;    private static final int RELEASE_LOCK_ON_DB_ACTION = 12;    private static final int RESTORE_DATA_DIRECTORY_ACTION = 13;    private String backupPath;    private File backupRoot;    private String[] bfilelist;	/*	** Constructor	*/	public BaseDataFileFactory() {	}	/*	** Methods of ModuleControl	*/	public boolean canSupport(Properties startParams) {		String serviceType = startParams.getProperty(PersistentService.TYPE);		if (serviceType == null)			return false;		if (!handleServiceType(startParams, serviceType))			return false;		if (startParams.getProperty(PersistentService.ROOT) == null)			return false;		return true;	}	public void	boot(boolean create, Properties startParams) throws StandardException {		jbmsVersion = Monitor.getMonitor().getEngineVersion();		dataDirectory = startParams.getProperty(PersistentService.ROOT);		UUIDFactory uf = Monitor.getMonitor().getUUIDFactory();		identifier = uf.createUUID();        PersistentService ps = Monitor.getMonitor().getServiceType(this);        try        {            storageFactory =            ps.getStorageFactoryInstance( true,                                          dataDirectory,                                          startParams.getProperty(Property.STORAGE_TEMP_DIRECTORY,                                                                  PropertyUtil.getSystemProperty(Property.STORAGE_TEMP_DIRECTORY)),                                          identifier.toANSIidentifier());        }        catch( IOException ioe)        {            if( create)                throw StandardException.newException( SQLState.SERVICE_DIRECTORY_CREATE_ERROR, dataDirectory, ioe);            else                throw StandardException.newException( SQLState.DATABASE_NOT_FOUND, ioe, dataDirectory);        }        if( storageFactory instanceof WritableStorageFactory)            writableStorageFactory = (WritableStorageFactory) storageFactory;        actionCode = BOOT_ACTION;        try{            AccessController.doPrivileged( this);        }        catch( PrivilegedActionException pae) { } // BOOT_ACTION does not throw any exceptions.                String value =            startParams.getProperty(Property.FORCE_DATABASE_LOCK,                PropertyUtil.getSystemProperty(Property.FORCE_DATABASE_LOCK));        throwDBlckException =            Boolean.valueOf(                (value != null ? value.trim() : value)).booleanValue();		if (!isReadOnly())		// read only db, not interested in filelock			getJBMSLockOnDB(identifier, uf, dataDirectory);		// restoreFrom and createFrom operations also need to know if database is encrypted		String dataEncryption = startParams.getProperty(Attribute.DATA_ENCRYPTION);		databaseEncrypted = Boolean.valueOf(dataEncryption).booleanValue();		//If the database is being restored/created from backup		//the restore the data directory(seg*) from backup		String restoreFrom =null;		restoreFrom = startParams.getProperty(Attribute.CREATE_FROM);		if(restoreFrom == null)			restoreFrom = startParams.getProperty(Attribute.RESTORE_FROM);		if(restoreFrom == null)			restoreFrom = startParams.getProperty(Attribute.ROLL_FORWARD_RECOVERY_FROM);		if(restoreFrom !=null)		{			try{				restoreDataDirectory(restoreFrom);			}catch(StandardException se)			{				releaseJBMSLockOnDB();				throw se;			}		}		logMsg(LINE);		long bootTime = System.currentTimeMillis();		logMsg(CheapDateFormatter.formatDate(bootTime) +			   MessageService.getTextMessage(MessageId.STORE_BOOT_MSG,			   									jbmsVersion,												identifier,												dataDirectory));		uf = null;		CacheFactory cf = (CacheFactory) Monitor.startSystemModule(org.apache.derby.iapi.reference.Module.CacheFactory);	    int pageCacheSize = getIntParameter(					RawStoreFactory.PAGE_CACHE_SIZE_PARAMETER,                    null,                    RawStoreFactory.PAGE_CACHE_SIZE_DEFAULT,                    RawStoreFactory.PAGE_CACHE_SIZE_MINIMUM,                    RawStoreFactory.PAGE_CACHE_SIZE_MAXIMUM);		pageCache =				cf.newCacheManager(this,                    "PageCache",                    pageCacheSize / 2,                    pageCacheSize);	    int fileCacheSize = getIntParameter(					"derby.storage.fileCacheSize",                    null,                    100,                    2,                    100);		containerCache = cf.newCacheManager(this, "ContainerCache", fileCacheSize / 2, fileCacheSize);		if (create)		{			String noLog =				startParams.getProperty(Property.CREATE_WITH_NO_LOG);			inCreateNoLog = (noLog != null && Boolean.valueOf(noLog).booleanValue());		}		freezeSemaphore = new Object();		droppedTableStubInfo = new Hashtable();        // If derby.system.durability=test then set flags to disable sync of        // data pages at allocation when file is grown, disable sync of data        // writes during checkpoint        if (Property.DURABILITY_TESTMODE_NO_SYNC.equalsIgnoreCase(            PropertyUtil.getSystemProperty(Property.DURABILITY_PROPERTY)))        {            // - disable syncing of data during checkpoint.            dataNotSyncedAtCheckpoint = true;            // - disable syncing of data during page allocation.            dataNotSyncedAtAllocation = true;            // log message stating that derby.system.durability            // is set to a mode, where syncs wont be forced and the            // possible consequences of setting this mode            Monitor.logMessage(MessageService.getTextMessage(            	MessageId.STORE_DURABILITY_TESTMODE_NO_SYNC,            	Property.DURABILITY_PROPERTY,                Property.DURABILITY_TESTMODE_NO_SYNC));		}        fileHandler = new RFResource( this);	} // end of boot	public void	stop() {		boolean OK = false;		if (rawStoreFactory != null)		{			DaemonService rawStoreDaemon = rawStoreFactory.getDaemon();			if (rawStoreDaemon != null)				rawStoreDaemon.stop();		}		long shutdownTime = System.currentTimeMillis();		logMsg("\n" + CheapDateFormatter.formatDate(shutdownTime) +                MessageService.getTextMessage(                    MessageId.STORE_SHUTDOWN_MSG,                    getIdentifier()));		istream.println(LINE);		if (!isCorrupt) {			try {				if (pageCache != null && containerCache != null) {					pageCache.shutdown();					containerCache.shutdown();

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -