BaseDataFileFactory.java

Index Score
org.apache.derby.impl.store.raw.data
Apache Derby

View: Reasons, Metrics, Source Code

These are the metrics that contribute to the Enerjy Score for this file, ranked by impact. So the metrics listed at the top influence the score to a greater extent that the metrics listed at the bottom.

MetricDescription
LINE_COMMENTNumber of line comments
EXEC_COMMENTSComments in executable code
SIZESize of the file in bytes
LINESNumber of lines in the source file
LOCLines of code
JAVA0034JAVA0034 Missing braces in if statement
ELOCEffective lines of code
CYCLOMATICCyclomatic complexity
RETURNSNumber of return points from functions
BLOCKSNumber of blocks
COMMENTSComment lines
INTERFACE_COMPLEXITYInterface complexity
OPERATORSNumber of operators
LOGICAL_LINESNumber of statements
PROGRAM_LENGTHHalstead program length
EXITSProcedure exits
OPERANDSNumber of operands
UNIQUE_OPERANDSNumber of unique operands
DECL_COMMENTSComments in declarations
COMPARISONSNumber of comparison operators
PROGRAM_VOCABHalstead program vocabulary
WHITESPACENumber of whitespace lines
PARAMSNumber of formal parameter declarations
DOC_COMMENTNumber of javadoc comment lines
FUNCTIONSNumber of function declarations
JAVA0108JAVA0108 Incorrect javadoc: no @param tag for 'parameter'
JAVA0075JAVA0075 Method parameter hides field
JAVA0110JAVA0110 Incorrect javadoc: no @return tag
JAVA0143JAVA0143 Synchronized method
JAVA0106JAVA0106 Unnecessary import from current package
JAVA0145JAVA0145 Tab character used in source file
JAVA0179JAVA0179 Local variable hides visible field
LOOPSNumber of loops
JAVA0177JAVA0177 Variable declaration missing initializer
JAVA0041JAVA0041 Nested synchronized block
JAVA0049JAVA0049 Nested block at depth N (maximum: M)
JAVA0174JAVA0174 Assigned local variable never used
JAVA0160JAVA0160 Method does not throw specified exception
BLOCK_COMMENTNumber of block comment lines
JAVA0173JAVA0173 Unused method parameter
NEST_DEPTHMaximum nesting depth
JAVA0270JAVA0270 Use Java 5.0 enhanced for loop construct to iterate over all elements in an array
UNIQUE_OPERATORSNumber of unique operators
JAVA0130JAVA0130 Non-static method does not use instance fields
JAVA0081JAVA0081 Boolean literal in comparison
JAVA0166JAVA0166 Generic exception caught
JAVA0080JAVA0080 Import declaration not used
JAVA0123JAVA0123 Use all three components of for loop
JAVA0285JAVA0285 Dereference of potentially null variable
JAVA0040JAVA0040 Switch statement contains N cases (maximum: M)
JAVA0029JAVA0029 Private method not used
JAVA0170JAVA0170 Caught exception not derived from java.lang.Exception
JAVA0115JAVA0115 Incorrect javadoc: no @throws or @exception tag for 'exception'
PROGRAM_VOLUMEHalstead program volume
JAVA0136JAVA0136 N methods defined in class (maximum: M)
JAVA0032JAVA0032 Switch statement missing default
JAVA0138JAVA0138 N parameters defined for method (maximum: M)
JAVA0126JAVA0126 Method declares unchecked exception in throws
JAVA0171JAVA0171 Unused local variable
JAVA0265JAVA0265 Use of Throwable.printStackTrace()
JAVA0100JAVA0100 Class contains N non-final fields (maximum: M)
JAVA0267JAVA0267 Use of System.err
/* Derby - Class org.apache.derby.impl.store.raw.data.BaseDataFileFactory Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you 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.PrivilegedFileOps; 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 and ModuleControl 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 DataFileFactory class. Also there probably should be a generic directory and the rest of the filesystem 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 then that file was made to inherit from this one. **/ public class BaseDataFileFactory implements DataFactory, CacheableFactory, ModuleControl, ModuleSupportable, PrivilegedExceptionAction { 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. DERBY-888 changes // the system to not require data syncing at allocation. boolean dataNotSyncedAtAllocation = true; // 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; private EncryptData containerEncrypter; // 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 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 static final int BOOT_ACTION = 10; private static final int GET_LOCK_ON_DB_ACTION = 11; private static final int RELEASE_LOCK_ON_DB_ACTION = 12; private static final int RESTORE_DATA_DIRECTORY_ACTION = 13; private static final int GET_CONTAINER_NAMES_ACTION = 14; private ContainerKey containerId; private boolean stub; private StorageFile actionFile; private UUID myUUID; private UUIDFactory uuidFactory; private String databaseDirectory; 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(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, ioe, dataDirectory); } 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); //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 { // restoreFrom and createFrom operations also need to know if database // is encrypted String dataEncryption = startParams.getProperty(Attribute.DATA_ENCRYPTION); databaseEncrypted = Boolean.valueOf(dataEncryption).booleanValue(); restoreDataDirectory(restoreFrom); } catch(StandardException se) { releaseJBMSLockOnDB(); throw se; } } logMsg(LINE); long bootTime = System.currentTimeMillis(); String readOnlyMsg = (isReadOnly()) ? MessageService.getTextMessage(MessageId.STORE_BOOT_READONLY_MSG) : ""; logMsg(CheapDateFormatter.formatDate(bootTime) + MessageService.getTextMessage(MessageId.STORE_BOOT_MSG, jbmsVersion, identifier, dataDirectory, readOnlyMsg)); uf = null; CacheFactory cf = (CacheFactory) Monitor.startSystemModule( org.apache.derby.iapi.reference.Module.CacheFactory); // Initialize the page cache 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); // Initialize the container cache int fileCacheSize = getIntParameter( RawStoreFactory.CONTAINER_CACHE_SIZE_PARAMETER, null, RawStoreFactory.CONTAINER_CACHE_SIZE_DEFAULT, RawStoreFactory.CONTAINER_CACHE_SIZE_MINIMUM, RawStoreFactory.CONTAINER_CACHE_SIZE_MAXIMUM); 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; // 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)); } else if (Performance.MEASURE) { // development build only feature, must by hand set the // Performance.MEASURE variable and rebuild. Useful during // development to compare/contrast effect of syncing, release // users can use the above relaxed durability option to disable // all syncing. // debug only flag - disable syncing of data during checkpoint. dataNotSyncedAtCheckpoint = PropertyUtil.getSystemBoolean( Property.STORAGE_DATA_NOT_SYNCED_AT_CHECKPOINT); if (dataNotSyncedAtCheckpoint) Monitor.logMessage( "Warning: " + Property.STORAGE_DATA_NOT_SYNCED_AT_CHECKPOINT + "set to true."); } 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(); OK = true; } } catch (StandardException se) { se.printStackTrace(istream.getPrintWriter()); } } removeTempDirectory(); if (isReadOnly()) // do enough to close all files, then return { storageFactory.shutdown(); return; } // re-enable stub removal until a better method can be found. // only remove stub if caches are cleaned if (removeStubsOK && OK) removeStubs(); releaseJBMSLockOnDB(); writableStorageFactory.shutdown(); } // end of stop /* ** CacheableFactory */ public Cacheable newCacheable(CacheManager cm) { if (cm == pageCache) { StoredPage sp = new StoredPage(); sp.setFactory(this); return sp; } // container cache return newContainerObject(); } /** Database creation finished @exception StandardException Standard Derby exception policy. */ public void createFinished() throws StandardException { if (!inCreateNoLog) { throw StandardException.newException( SQLState.FILE_DATABASE_NOT_IN_CREATE); } // the changes in cache are not logged, they have to be flushed to disk checkpoint(); inCreateNoLog = false; } /* ** Methods of DataFactory */ public ContainerHandle openContainer( RawTransaction t, ContainerKey containerId, LockingPolicy locking, int mode) throws StandardException { return openContainer( t, containerId, locking, mode, false /* is not dropped */); } /** @see DataFactory#openDroppedContainer @exception StandardException Standard Derby error policy */ public RawContainerHandle openDroppedContainer( RawTransaction t, ContainerKey containerId, LockingPolicy locking, int mode) throws StandardException { // since we are opening a possible dropped container // lets not add any actions that will take palce on a commit. mode |= ContainerHandle.MODE_NO_ACTIONS_ON_COMMIT; return openContainer( t, containerId, locking, mode, true /* droppedOK */); } /** @see DataFactory#openContainer @exception StandardException Standard Derby error policy */ private RawContainerHandle openContainer( RawTransaction t, ContainerKey identity, LockingPolicy locking, int mode, boolean droppedOK) throws StandardException { if (SanityManager.DEBUG) { if ((mode & (ContainerHandle.MODE_READONLY | ContainerHandle.MODE_FORUPDATE)) == (ContainerHandle.MODE_READONLY | ContainerHandle.MODE_FORUPDATE)) { SanityManager.THROWASSERT("update and readonly mode specified"); } } boolean waitForLock = ((mode & ContainerHandle.MODE_LOCK_NOWAIT) == 0); if ((mode & ContainerHandle.MODE_OPEN_FOR_LOCK_ONLY) != 0) { // Open a container for lock only, we don't care if it exists, is // deleted or anything about it. The container handle we return is // closed and cannot be used for fetch or update etc. BaseContainerHandle lockOnlyHandle = new BaseContainerHandle( getIdentifier(), t, identity, locking, mode); if (lockOnlyHandle.useContainer(true, waitForLock)) return lockOnlyHandle; else return null; } BaseContainerHandle c; // see if the container exists FileContainer container = (FileContainer) containerCache.find(identity); if (container == null) return null; if (identity.getSegmentId() == ContainerHandle.TEMPORARY_SEGMENT) { if (SanityManager.DEBUG) { SanityManager.ASSERT(container instanceof TempRAFContainer); } if ((mode & ContainerHandle.MODE_TEMP_IS_KEPT) == ContainerHandle.MODE_TEMP_IS_KEPT) { // if the mode is kept, then, we do not want to truncate mode |= ContainerHandle.MODE_UNLOGGED; } else { // this should be OK even if the table was opened read-only mode |= (ContainerHandle.MODE_UNLOGGED | ContainerHandle.MODE_TRUNCATE_ON_ROLLBACK); } locking = t.newLockingPolicy( LockingPolicy.MODE_NONE, TransactionController.ISOLATION_NOLOCK, true); } else { // real tables if (inCreateNoLog) { mode |= (ContainerHandle.MODE_UNLOGGED | ContainerHandle.MODE_CREATE_UNLOGGED); } else { // make sure everything is logged if logArchived is turn on // clear all UNLOGGED flag if (logFactory.logArchived() || logFactory.inReplicationMasterMode()) { mode &= ~(ContainerHandle.MODE_UNLOGGED | ContainerHandle.MODE_CREATE_UNLOGGED); } else { // block the online backup if the container is being // opened in unlogged mode, if the backup is already // running then convert all unlogged opens to logged ones, // otherwise online backup copy will be inconsistent. if (((mode & ContainerHandle.MODE_UNLOGGED) == ContainerHandle.MODE_UNLOGGED) || ((mode & ContainerHandle.MODE_CREATE_UNLOGGED) == ContainerHandle.MODE_CREATE_UNLOGGED)) { if (!t.blockBackup(false)) { // when a backup is in progress transaction can not // block the backup, so convert unlogged opens // to logged mode. mode &= ~(ContainerHandle.MODE_UNLOGGED | ContainerHandle.MODE_CREATE_UNLOGGED); } } } } // if mode is UNLOGGED but not CREATE_UNLOGGED, then force the // container from cache when the transaction commits. For // CREATE_UNLOGGED, client has the responsibility of forcing the // cache. if (((mode & ContainerHandle.MODE_UNLOGGED) == ContainerHandle.MODE_UNLOGGED) && ((mode & ContainerHandle.MODE_CREATE_UNLOGGED) == 0)) { mode |= ContainerHandle.MODE_FLUSH_ON_COMMIT; } } PageActions pageActions = null; AllocationActions allocActions = null; if ((mode & ContainerHandle.MODE_FORUPDATE) == ContainerHandle.MODE_FORUPDATE) { if ((mode & ContainerHandle.MODE_UNLOGGED) == 0) { // get the current loggable actions pageActions = getLoggablePageActions(); allocActions = getLoggableAllocationActions(); } else { // unlogged pageActions = new DirectActions(); allocActions = new DirectAllocActions(); } } c = new BaseContainerHandle( getIdentifier(), t, pageActions, allocActions, locking, container, mode); // see if we can use the container try { if (!c.useContainer(droppedOK, waitForLock)) { containerCache.release(container); return null; } } catch (StandardException se) { containerCache.release(container); throw se; } return c; } /** Add a container with a specified page size to a segment. @exception StandardException Standard Derby error policy */ public long addContainer( RawTransaction t, long segmentId, long input_containerid, int mode, Properties tableProperties, int temporaryFlag) throws StandardException { if (SanityManager.DEBUG) { if ((mode & ContainerHandle.MODE_CREATE_UNLOGGED) != 0) SanityManager.ASSERT( (mode & ContainerHandle.MODE_UNLOGGED) != 0, "cannot have CREATE_UNLOGGED set but UNLOGGED not set"); } // If client has provided a containerid then use it, else use the // internally generated one from getNextId(). long containerId = ((input_containerid != ContainerHandle.DEFAULT_ASSIGN_ID) ? input_containerid : getNextId()); ContainerKey identity = new ContainerKey(segmentId, containerId); boolean tmpContainer = (segmentId == ContainerHandle.TEMPORARY_SEGMENT); ContainerHandle ch = null; LockingPolicy cl = null; if (!tmpContainer) { // lock the container before we create it. if (isReadOnly()) { throw StandardException.newException( SQLState.DATA_CONTAINER_READ_ONLY); } cl = t.newLockingPolicy(LockingPolicy.MODE_CONTAINER, TransactionController.ISOLATION_SERIALIZABLE, true); if (SanityManager.DEBUG) SanityManager.ASSERT(cl != null); ch = t.openContainer(identity, cl, (ContainerHandle.MODE_FORUPDATE | ContainerHandle.MODE_OPEN_FOR_LOCK_ONLY)); } FileContainer container = (FileContainer) containerCache.create(identity, tableProperties); // create the first alloc page and the first user page, // if this fails for any reason the transaction // will roll back and the container will be dropped (removed) ContainerHandle containerHdl = null; Page firstPage = null; try { // if opening a temporary container with IS_KEPT flag set, // make sure to open it with IS_KEPT too. if (tmpContainer && ((temporaryFlag & TransactionController.IS_KEPT) == TransactionController.IS_KEPT)) { mode |= ContainerHandle.MODE_TEMP_IS_KEPT; } // open no-locking as we already have the container locked containerHdl = t.openContainer( identity, null, (ContainerHandle.MODE_FORUPDATE | mode)); // we just added it, containerHdl should not be null if (SanityManager.DEBUG) SanityManager.ASSERT(containerHdl != null); if (!tmpContainer) { // make it persistent (in concept if not in reality) RawContainerHandle rch = (RawContainerHandle)containerHdl; ContainerOperation lop = new ContainerOperation(rch, ContainerOperation.CREATE); // mark the container as pre-dirtied so that if a checkpoint // happens after the log record is sent to the log stream, the // cache cleaning will wait for this change. rch.preDirty(true); try { t.logAndDo(lop); // flush the log to reduce the window between where // the container is created & synced and the log record // for it makes it to disk. If we fail in this // window we will leave a stranded container file. flush(t.getLastLogInstant()); } finally { // in case logAndDo fail, make sure the container is not // stuck in preDirty state. rch.preDirty(false); } } firstPage = containerHdl.addPage(); } finally { if (firstPage != null) { firstPage.unlatch(); firstPage = null; } containerCache.release(container); if (containerHdl != null) { containerHdl.close(); containerHdl = null; } if (!tmpContainer) { // this should do nothing, since we requested isolation 3 // but we can't assume that, so call the policy correctly. cl.unlockContainer(t, ch); } } return containerId; } /** Add and load a stream container @exception StandardException Standard Derby error policy */ public long addAndLoadStreamContainer( RawTransaction t, long segmentId, Properties tableProperties, RowSource rowSource) throws StandardException { long containerId = getNextId(); ContainerKey identity = new ContainerKey(segmentId, containerId); // create and load the stream container StreamFileContainer sContainer = new StreamFileContainer(identity, this, tableProperties); sContainer.load(rowSource); return containerId; } /** open an exsisting streamContainer @see DataFactory#openStreamContainer @exception StandardException Standard Derby error policy */ public StreamContainerHandle openStreamContainer( RawTransaction t, long segmentId, long containerId, boolean hold) throws StandardException { ContainerKey identity = new ContainerKey(segmentId, containerId); StreamFileContainerHandle c; // open the container with the identity StreamFileContainer container = new StreamFileContainer(identity, this); container = container.open(false); if (container == null) return null; c = new StreamFileContainerHandle(getIdentifier(), t, container, hold); // see if we can use the container if (c.useContainer()) return c; else return null; } /** Drop a stream container. <P><B>Synchronisation</B> <P> This call will remove the container. @exception StandardException Standard Derby error policy */ public void dropStreamContainer( RawTransaction t, long segmentId, long containerId) throws StandardException { boolean tmpContainer = (segmentId == ContainerHandle.TEMPORARY_SEGMENT); StreamContainerHandle containerHdl = null; try { ContainerKey ckey = new ContainerKey(segmentId, containerId); // close all open containers and 'onCommit' objects of the container t.notifyObservers(ckey); containerHdl = t.openStreamContainer(segmentId, containerId, false); if (tmpContainer && (containerHdl != null)) { containerHdl.removeContainer(); return; } } finally { if (containerHdl != null) containerHdl.close(); } } /** re-Create a container during redo recovery. called ONLY during recovery load tran. @exception StandardException Standard Derby Error policy */ public void reCreateContainerForRedoRecovery( RawTransaction t, long segmentId, long containerId, ByteArray containerInfo) throws StandardException { if (SanityManager.DEBUG) SanityManager.ASSERT(segmentId != ContainerHandle.TEMPORARY_SEGMENT, "Cannot recreate temp container during load tran"); ContainerKey identity = new ContainerKey(segmentId, containerId); // no need to lock container during load tran // no need to create any page for the container, they will be created // as their log records are encountered later in load tran FileContainer container = (FileContainer)containerCache.create(identity, containerInfo); containerCache.release(container); } /** Drop a container. <P><B>Synchronisation</B> <P> This call will mark the container as dropped and then obtain an CX lock (table level exclusive lock) on the container. Once a container has been marked as dropped it cannot be retrieved by an openContainer() call unless explicitly with droppedOK. <P> Once the exclusive lock has been obtained the container is removed and all its pages deallocated. The container will be fully removed at the commit time of the transaction. @exception StandardException Standard Derby error policy */ public void dropContainer( RawTransaction t, ContainerKey ckey) throws StandardException { boolean tmpContainer = (ckey.getSegmentId() == ContainerHandle.TEMPORARY_SEGMENT); LockingPolicy cl = null; if (!tmpContainer) { if (isReadOnly()) { throw StandardException.newException( SQLState.DATA_CONTAINER_READ_ONLY); } cl = t.newLockingPolicy( LockingPolicy.MODE_CONTAINER, TransactionController.ISOLATION_SERIALIZABLE, true); if (SanityManager.DEBUG) SanityManager.ASSERT(cl != null); } // close all open containers and 'onCommit' objects of this container t.notifyObservers(ckey); RawContainerHandle containerHdl = (RawContainerHandle) t.openContainer(ckey, cl, ContainerHandle.MODE_FORUPDATE); // If container is already dropped or is no longer there, throw // containerVanished exception unless container is temporary, in that // case just return. Upper layer is supposed to prevent such from // happening thru some means other than the lock we are getting here. try { if (containerHdl == null || containerHdl.getContainerStatus() != RawContainerHandle.NORMAL) { // If we are a temp container, don't worry about it. if (tmpContainer) { if (containerHdl != null) containerHdl.removeContainer((LogInstant)null); return; } else { throw StandardException.newException( SQLState.DATA_CONTAINER_VANISHED, ckey); } } // Container exist, is updatable and we got the lock. if (tmpContainer) { containerHdl.dropContainer((LogInstant)null, true); containerHdl.removeContainer((LogInstant)null); } else { ContainerOperation lop = new ContainerOperation( containerHdl, ContainerOperation.DROP); // mark the container as pre-dirtied so that if a checkpoint // happens after the log record is sent to the log stream, the // cache cleaning will wait for this change. containerHdl.preDirty(true); try { t.logAndDo(lop); } finally { // in case logAndDo fail, make sure the container is not // stuck in preDirty state. containerHdl.preDirty(false); } // remember this as a post commit work item Serviceable p = new ReclaimSpace( ReclaimSpace.CONTAINER, ckey, this, true /* service ASAP */); if (SanityManager.DEBUG) { if (SanityManager.DEBUG_ON(DaemonService.DaemonTrace)) { SanityManager.DEBUG( DaemonService.DaemonTrace, "Add post commit work " + p); } } t.addPostCommitWork(p); } } finally { if (containerHdl != null) containerHdl.close(); } } /** * Implement checkpoint operation, write/sync all pages in cache. * <p> * The derby write ahead log algorithm uses checkpoint of the data * cache to determine points of the log no longer required by * restart recovery. * <p> * This implementation uses the 2 cache interfaces to force all dirty * pages to disk: * * WRITE DIRTY PAGES TO OS: * In the first step all pages in the page cache * are written, but not synced (pagecache.cleanAll). The cachemanager * cleanAll() interface guarantees that every dirty page that exists * when this call is first made will have it's clean() method called. * The data cache (CachedPage.clean()), will call writePage but not * sync the page. * By using the java write then sync, the checkpoint is * usually doing async I/O, allowing the OS to schedule multiple I/O's * to the file as efficiently as it can. * Note that it has been observed that checkpoints * can flood the I/O system because these writes are not synced, see * DERBY-799 - checkpoint should probably somehow restrict the rate * it sends out those I/O's - it was observed a simple sleep every * N writes fixed most of the problem. * * FORCE THOSE DIRTY WRITES TO DISK: * To force the I/O's to disk, the system calls each open dirty file * and uses the java interface to sync any outstanding dirty pages to * disk (containerCache.cleanAll()). The open container cache does * this work in RAFContainer.clean() by writing it's header out and * syncing the file. (Note if any change is made to checkpoint to * sync the writes vs. syncing the file, one probably still needs to * write the container header out and sync it). * * @exception StandardException Standard exception policy. **/ public void checkpoint() throws StandardException { pageCache.cleanAll(); containerCache.cleanAll(); } public void idle() throws StandardException { pageCache.ageOut(); containerCache.ageOut(); } public void setRawStoreFactory( RawStoreFactory rsf, boolean create, Properties startParams) throws StandardException { rawStoreFactory = rsf; /* * boot the log factory here because different implementation of the * data factory wants different types of log factory */ bootLogFactory(create, startParams); } /** Return my unique identifier @see DataFactory#getIdentifier */ public UUID getIdentifier() { return identifier; } /* ** Called by post commit daemon, calling ReclaimSpace.performWork() */ public int reclaimSpace( Serviceable work, ContextManager contextMgr) throws StandardException { if (work == null) return Serviceable.DONE; Transaction tran = rawStoreFactory.findUserTransaction( contextMgr, AccessFactoryGlobals.SYS_TRANS_NAME); if (SanityManager.DEBUG) { SanityManager.ASSERT(tran != null, "null transaction"); if (SanityManager.DEBUG_ON(DaemonService.DaemonTrace)) SanityManager.DEBUG(DaemonService.DaemonTrace, "Performing post commit work " + work); } return ReclaimSpaceHelper.reclaimSpace(this, (RawTransaction)tran, (ReclaimSpace)work); } /** Really this is just a convience routine for callers that might not have access to a log factory. */ public StandardException markCorrupt(StandardException originalError) { boolean firsttime = !isCorrupt; isCorrupt = true; if (getLogFactory() != null) getLogFactory().markCorrupt(originalError); // if firsttime markCorrupt is called, release the JBMS lock so user // can move the database if so desired. if (firsttime) { // get rid of everything from the cache without first cleaning them if (pageCache != null) pageCache.discard(null); if (containerCache != null) containerCache.discard(null); // don't read in any more pages pageCache = null; containerCache = null; releaseJBMSLockOnDB(); } return originalError; } public FileResource getFileHandler() { return fileHandler; } public void removeStubsOK() { removeStubsOK = true; } /* ** Implementation specific methods */ public int getIntParameter( String parameterName, Properties properties, int defaultValue, int minimumValue, int maximumValue) { int newValue; String parameter = null; if (properties != null) parameter = properties.getProperty(parameterName); if (parameter == null) parameter = PropertyUtil.getSystemProperty(parameterName); if (parameter != null) { try { newValue = Integer.parseInt(parameter); if ((newValue >= minimumValue) && (newValue <= maximumValue)) return newValue; } catch (NumberFormatException nfe) { // just leave the size at the default. } } return defaultValue; } CacheManager getContainerCache() { return containerCache; } CacheManager getPageCache() { return pageCache; } /** Ask the log factory to flush up to this log instant. @exception StandardException cannot sync log file */ void flush(LogInstant instant) throws StandardException { getLogFactory().flush(instant); } /** Ask the log factory to flush the side log up to this bip location Not implemented in this class - subclass who deals with side log must override this. @exception StandardException Derby Standard Error Policy */ private void syncSideLog(long bipLocation) throws StandardException { return; } LogFactory getLogFactory() { return logFactory; } RawStoreFactory getRawStoreFactory() { return rawStoreFactory; } /** Get the root directory of the data storage area. Is always guaranteed to be an absolute path. */ public String getRootDirectory() { return dataDirectory; } /** * Produces new container objects. * <p> * Concrete implementations of a DataFactory must implement this routine * to indicate what kind of containers are produced. This class produces * file-based containers - RAFContainer objects for files that support * random access and InputStreamContainer object for others, such as data * files in JARs. * <p> * @return A new file container object. * **/ Cacheable newContainerObject() { if( supportsRandomAccess) return newRAFContainer(this); else return new InputStreamContainer( this); } /** * Creates a RAFContainer object. * This method is overridden in BaseDataFileFactoryJ4 to produce * RAFContainer4 objects instead of RAFContainer objects. */ protected Cacheable newRAFContainer(BaseDataFileFactory factory) { return new RAFContainer(factory); } /** * This page is going from clean to dirty, this is a chance for the * sub class to do something if so desired * * @exception StandardException Standard Derby Error Policy */ private void pageToDirty(RawTransaction t, StoredPage page) throws StandardException { return; // this implementation does nothing } /* * Get the loggable page action that is associated with this implementation * * @return the PageActions * @exception StandardExceptions Standard Derby Error Policy */ private PageActions getLoggablePageActions() throws StandardException { if (loggablePageActions == null) loggablePageActions = new LoggableActions(); return loggablePageActions; } /** * Get the loggable allocation action associated with this implementation * * @return the PageActions */ private AllocationActions getLoggableAllocationActions() { if (loggableAllocActions == null) loggableAllocActions = new LoggableAllocActions(); return loggableAllocActions; } synchronized StorageFile getTempDirectory() { actionCode = GET_TEMP_DIRECTORY_ACTION; try { return (StorageFile) AccessController.doPrivileged( this); } catch (PrivilegedActionException pae) { // getTempDirectory does not actually throw an exception return null; } } private synchronized void removeTempDirectory() { if( storageFactory != null) { actionCode = REMOVE_TEMP_DIRECTORY_ACTION; try { AccessController.doPrivileged( this); } catch (PrivilegedActionException pae) { // removeTempDirectory does not throw an exception } } } /** * Return the path to a container file. * <p> * Return the path to a container file that is relative to the root * directory. * <p> * The format of the name of an existing container file is: * segNNN/cXXX.dat * The format of the name of a stub describing a dropped container file is: * segNNN/dXXX.dat * * NNN = segment number, currently 0 is where normal db files are found. * XXX = The hex representation of the container number * * The store will always create containers with this format name, but * the store will also recognize the following two formats when attempting * to open files - as some copy tools have uppercased our filesnames when * moving across operating systems: * * The format of the name of an existing container file is: * segNNN/CXXX.DAT * The format of the name of a stub describing a dropped container file is: * segNNN/DXXX.DAT * <p> * * * @param containerId The container being opened/created * @param stub True if the file name for the stub is requested, * otherwise the file name for the data file * * @return The StorageFile representing path to container relative to root. * **/ public StorageFile getContainerPath( ContainerKey containerId, boolean stub) { return getContainerPath(containerId, stub, GET_CONTAINER_PATH_ACTION); } private synchronized StorageFile getContainerPath( ContainerKey containerId, boolean stub, int code) { actionCode = code; try { this.containerId = containerId; this.stub = stub; try { return (StorageFile) AccessController.doPrivileged( this); } catch (PrivilegedActionException pae) { // getContainerPath does not throw an exception return null; } } finally { this.containerId = null; } } /** Return an alternate path to container file relative to the root directory. The alternate path uses upper case 'C','D', and 'DAT' instead of lower case - there have been cases of people copying the database and somehow upper casing all the file names. The intended use is as a bug fix for track 3444. @param containerId The container being opened/created @param stub True if the file name for the stub is requested, otherwise the file name for the data file */ public StorageFile getAlternateContainerPath( ContainerKey containerId, boolean stub) { return getContainerPath( containerId, stub, GET_ALTERNATE_CONTAINER_PATH_ACTION); } /** Remove stubs in this database. Stubs are committed deleted containers */ private synchronized void removeStubs() { actionCode = REMOVE_STUBS_ACTION; try { AccessController.doPrivileged( this); } catch (PrivilegedActionException pae) { // removeStubs does not throw an exception } } /** * keeps track of information about the stub files of the committed deleted * containers. We use the info to delete them at checkpoints. * In addition to the file info , we also keep track of the identity of the * container; which helps to remove entry in the cache and the log instant * when the stub was created, which helps us to figure out whether we * require the stub file for the crash recovery. * We maintain the information in a hashtable: * key(LOG INSTANT) Values: File handle , and ContainerIdentity. **/ public void stubFileToRemoveAfterCheckPoint( StorageFile file, LogInstant logInstant, Object identity) { if(droppedTableStubInfo != null) { Object[] removeInfo = new Object[2]; removeInfo[0] = file; removeInfo[1] = identity; droppedTableStubInfo.put(logInstant, removeInfo); } } /** * Delete the stub files that are not required for recovery. A stub file * is not required to be around if the recovery is not going to see * any log record that belongs to that container. Since the stub files * are created as a post commit operation, they are not necessary during * undo operation of the recovery. * * To remove a stub file we have to be sure that it was created before the * redoLWM in the check point record. We can be sure that the stub is not * required if the log instant when it was created is less than the redoLWM. */ public void removeDroppedContainerFileStubs( LogInstant redoLWM) throws StandardException { if (droppedTableStubInfo != null) { synchronized(droppedTableStubInfo) { for (Enumeration e = droppedTableStubInfo.keys(); e.hasMoreElements(); ) { LogInstant logInstant = (LogInstant) e.nextElement(); if(logInstant.lessThan(redoLWM)) { Object[] removeInfo = (Object[]) droppedTableStubInfo.get(logInstant); Object identity = removeInfo[1]; //delete the entry in the container cache. Cacheable ccentry = containerCache.findCached(identity); if(ccentry!=null) containerCache.remove(ccentry); //delete the stub we don't require it during recovery synchronized( this) { actionFile = (StorageFile)removeInfo[0]; actionCode = DELETE_IF_EXISTS_ACTION; try { if (AccessController.doPrivileged(this) != null) { //if we successfuly delete the file remove //it from the hash table. droppedTableStubInfo.remove(logInstant); } } catch (PrivilegedActionException pae) { // DELETE_IF_EXISTS does not throw an exception } } } } } } } /** * Find the largest containerid is seg 0. * <p> * Do a file list of the files in seg0 and return the highest numbered * file found. * <p> * Until I figure out some reliable place to store this information across * a boot of the system, this is what is used following a boot to assign * the next conglomerate id when a new conglomerate is created. It is * only called at most once, and then the value is cached by calling store * code. * <p> * * @return The largest containerid in seg0. **/ private synchronized long findMaxContainerId() { actionCode = FIND_MAX_CONTAINER_ID_ACTION; try { return ((Long) AccessController.doPrivileged( this)).longValue(); } catch (PrivilegedActionException pae) { // findMaxContainerId does not throw an exception return 0; } } private void bootLogFactory( boolean create, Properties startParams) throws StandardException { if (isReadOnly()) { startParams.put( LogFactory.RUNTIME_ATTRIBUTES, LogFactory.RT_READONLY); } logFactory = (LogFactory) Monitor.bootServiceModule( create, this, rawStoreFactory.getLogFactoryModule(), startParams); } /** Does this factory support this service type. */ private boolean handleServiceType( String type) { try { PersistentService ps = Monitor.getMonitor().getServiceProvider(type); return ps != null && ps.hasStorageFactory(); } catch (StandardException se) { return false; } } /** check to see if we are the only JBMS opened against this database. <BR>This method does nothing if this database is read only or we cannot access files directly on the database directory. <BR>We first see if a file named db.lck exists on the top database directory (i.e., the directory where service.properties lives). If it doesn't exist, we create it and write to it our identity which is generated per boot of the JBMS. <BR>If the db.lck file already exists when we boot this database, we try to delete it first, assuming that an opened RandomAccessFile can act as a file lock against delete. If that succeeds, we may hold a file lock against subsequent JBMS that tries to attach to this database before we exit. <BR>We test to see if we think an opened file will prevent it from being deleted, if so, we will hold on to the open file descriptor and use it as a filelock. If not, and we started out deleting an existing db.lck file, we issue a warning message to the info stream that we are about to attached to a database which may already have another JBMS attached to it. Then we overwrite that db.lck file with our identity. <BR>Upon shutdown, we delete the db.lck file. If the system crash instead of shutdown cleanly, it will be cleaned up the next time the system boots @exception StandardException another JBMS is already attached to the database at this directory */ private void getJBMSLockOnDB( UUID myUUID, UUIDFactory uuidFactory, String databaseDirectory) throws StandardException { if (fileLockOnDB != null) // I already got the lock! return; if (isReadOnly()) return; if (SanityManager.DEBUG) { if (myUUID == null) SanityManager.THROWASSERT("myUUID == null"); } synchronized( this) { actionCode = GET_LOCK_ON_DB_ACTION; this.myUUID = myUUID; this.uuidFactory = uuidFactory; this.databaseDirectory = databaseDirectory; try { AccessController.doPrivileged( this); } catch (PrivilegedActionException pae) { throw (StandardException) pae.getException(); } finally { this.myUUID = null; this.uuidFactory = null; this.databaseDirectory = null; } } // OK file lock is reliable, we think... keep the fileLockOnDB file // descriptor open to prevent other JBMS from booting // fileLockOnDB is not null in this case } // Called from within a privilege block private void privGetJBMSLockOnDB() throws StandardException { boolean fileLockExisted = false; String blownUUID = null; StorageFile fileLock = storageFactory.newStorageFile( DB_LOCKFILE_NAME); try { // assume we are not read only // SECURITY PERMISSION MP1 if (fileLock.exists()) { fileLockExisted = true; // see what it says in case we cannot count on delete failing // when someone else have an opened file descriptor. // I may be blowing this JBMS's lock away // SECURITY PERMISSION MP1 // SECURITY PERMISSION OP4 fileLockOnDB = fileLock.getRandomAccessFile( "rw"); try { blownUUID = fileLockOnDB.readUTF(); } catch (IOException ioe) { // The previous owner of the lock may have died before // finish writing its UUID down. fileLockExisted = false; } fileLockOnDB.close(); fileLockOnDB = null; // SECURITY PERMISSION OP5 if (!fileLock.delete()) { throw StandardException.newException( SQLState.DATA_MULTIPLE_JBMS_ON_DB, databaseDirectory); } } // if file does not exists, we grab it immediately - there is a // possibility that some other JBMS got to it sooner than we do, // check the UUID after we write it to make sure // SECURITY PERMISSION MP1 // SECURITY PERMISSION OP5 fileLockOnDB = fileLock.getRandomAccessFile( "rw"); // write it out for future reference fileLockOnDB.writeUTF(myUUID.toString()); fileLockOnDB.sync( false); fileLockOnDB.seek(0); // check the UUID UUID checkUUID = uuidFactory.recreateUUID(fileLockOnDB.readUTF()); if (!checkUUID.equals(myUUID)) { throw StandardException.newException( SQLState.DATA_MULTIPLE_JBMS_ON_DB, databaseDirectory); } } catch (IOException ioe) { // probably a read only db, don't do anything more readOnly = true; try { if (fileLockOnDB != null) fileLockOnDB.close(); } catch (IOException ioe2) { /* did the best I could */ } fileLockOnDB = null; return; } if (fileLock.delete()) { // if I can delete it while I am holding a opened file descriptor, // then the file lock is unreliable - send out a warning if I // have blown off another JBMS's lock on the DB Object[] args = new Object[3]; args[0] = myUUID; args[1] = databaseDirectory; args[2] = blownUUID; //Try the exlcusive file lock method approach available in jdk1.4 or //above jvms where delete machanism does not reliably prevent //double booting of derby databases. If we don't get a reliable //exclusive lock still we send out a warning. int exLockStatus = StorageFile.NO_FILE_LOCK_SUPPORT ; //If user has chosen to force lock option don't bother //about applying exclusive file lock mechanism if(!throwDBlckException) { exFileLock = storageFactory.newStorageFile( DB_EX_LOCKFILE_NAME); exLockStatus = exFileLock.getExclusiveFileLock(); } if (exLockStatus == StorageFile.NO_FILE_LOCK_SUPPORT) { if (fileLockExisted && !throwDBlckException) { StandardException multipleJBMSWarning = StandardException.newException( SQLState.DATA_MULTIPLE_JBMS_WARNING, args); String warningMsg = MessageService.getCompleteMessage( SQLState.DATA_MULTIPLE_JBMS_WARNING, args); logMsg(warningMsg); // RESOLVE - need warning support. Output to // system.err.println rather than just send warning // message to derby.log. System.err.println(warningMsg); } } // filelock is unreliable, but we should at least leave a file // there to warn the next person try { // the existing fileLockOnDB file descriptor may already be // deleted by the delete call, close it and create the file // again if(fileLockOnDB != null) fileLockOnDB.close(); fileLockOnDB = fileLock.getRandomAccessFile( "rw"); // write it out for future reference fileLockOnDB.writeUTF(myUUID.toString()); fileLockOnDB.sync( false); fileLockOnDB.close(); } catch (IOException ioe) { try { fileLockOnDB.close(); } catch (IOException ioe2) { /* did the best I could */ } } finally { fileLockOnDB = null; } if (fileLockExisted && throwDBlckException) { // user has chosen that we always throw exception, throw it // now that we have reinstated the lock file. throw StandardException.newException( SQLState.DATA_MULTIPLE_JBMS_FORCE_LOCK, args); } if(exLockStatus == StorageFile.EXCLUSIVE_FILE_LOCK_NOT_AVAILABLE) { throw StandardException.newException( SQLState.DATA_MULTIPLE_JBMS_ON_DB, databaseDirectory); } } } // end of privGetJBMSLockOnDB private void releaseJBMSLockOnDB() { if (isReadOnly()) return; synchronized( this) { actionCode = RELEASE_LOCK_ON_DB_ACTION; try { AccessController.doPrivileged( this); } catch (PrivilegedActionException pae) { // do nothing - it may be read only medium, who knows what the // problem is } finally { fileLockOnDB = null; } } } private void privReleaseJBMSLockOnDB() throws IOException { if (fileLockOnDB != null) fileLockOnDB.close(); if (storageFactory != null) { StorageFile fileLock = storageFactory.newStorageFile(DB_LOCKFILE_NAME); fileLock.delete(); } //release the lock that is acquired using tryLock() to prevent //multiple jvm booting the same database on Unix environments. if(exFileLock != null) exFileLock.releaseExclusiveFileLock(); return; } // end of privReleaseJBMSLockOnDB private void logMsg(String msg) { if (istream == null) { istream = Monitor.getStream(); } istream.println(msg); } public final boolean databaseEncrypted() { return databaseEncrypted; } public void setDatabaseEncrypted() { databaseEncrypted = true; } public int encrypt( byte[] cleartext, int offset, int length, byte[] ciphertext, int outputOffset, boolean newEngine) throws StandardException { return rawStoreFactory.encrypt( cleartext, offset, length, ciphertext, outputOffset, newEngine); } public int decrypt( byte[] ciphertext, int offset, int length, byte[] cleartext, int outputOffset) throws StandardException { return rawStoreFactory.decrypt( ciphertext, offset, length, cleartext, outputOffset); } public void encryptAllContainers(RawTransaction t) throws StandardException { containerEncrypter = new EncryptData(this); // encrypt all the conatiners in the databse containerEncrypter.encryptAllContainers(t); } /* * Remover old versions of the containers after (re)encryption * of the database. * @param inRecovery <code> true </code>, if cleanup is * happening during recovery. */ public void removeOldVersionOfContainers(boolean inRecovery) throws StandardException { // check if old containers are being during recovery // because of a crash after successful completion of // (re)encryption of the dataabase, but before the // (re)encryption cleanup was complete. if (inRecovery) { containerEncrypter = new EncryptData(this); } containerEncrypter.removeOldVersionOfContainers(inRecovery); containerEncrypter = null; } /** Returns the encryption block size used by the algorithm at time of creation of an encrypted database */ public int getEncryptionBlockSize() { return rawStoreFactory.getEncryptionBlockSize(); } public String getVersionedName(String name, long generationId) { return name.concat(".G".concat(Long.toString(generationId))); } /** * Return an id which can be used to create a container. * <p> * Return an id number with is greater than any existing container * in the current database. Caller will use this to allocate future * container numbers - most likely caching the value and then incrementing * it as it is used. * <p> * * @return The an id which can be used to create a container. * * @exception StandardException Standard exception policy. **/ public long getMaxContainerId() throws StandardException { return(findMaxContainerId()); } synchronized long getNextId() { return nextContainerId++; } /** return a secure random number */ int random() { return databaseEncrypted ? rawStoreFactory.random() : 0; } /** Add a file to the list of files to be removed post recovery. */ void fileToRemove( StorageFile file, boolean remove) { if (postRecoveryRemovedFiles == null) postRecoveryRemovedFiles = new Hashtable(); String path = null; synchronized( this) { actionCode = GET_PATH_ACTION; actionFile = file; try { path = (String) AccessController.doPrivileged( this); } catch (PrivilegedActionException pae) { // GET_PATH does not throw an exception } finally { actionFile = null; } } if (remove) // to be removed postRecoveryRemovedFiles.put(path, file); else postRecoveryRemovedFiles.remove(path); } /** Called after recovery is performed. @exception StandardException Standard Derby Error Policy */ public void postRecovery() throws StandardException { DaemonService daemon = rawStoreFactory.getDaemon(); if (daemon == null) return; if (postRecoveryRemovedFiles != null) { synchronized( this) { actionCode = POST_RECOVERY_REMOVE_ACTION; try { AccessController.doPrivileged( this); } catch (PrivilegedActionException pae) { // POST_RECOVERY_REMOVE does not throw an exception } } postRecoveryRemovedFiles = null; } } /** * Set up the cache cleaner for the container cache and the page cache. */ public void setupCacheCleaner(DaemonService daemon) { containerCache.useDaemonService(daemon); pageCache.useDaemonService(daemon); } public void freezePersistentStore() throws StandardException { synchronized(freezeSemaphore) { if (isFrozen) { throw StandardException.newException( SQLState.RAWSTORE_NESTED_FREEZE); } // set this to true first to stop all writes from starting after // this. isFrozen = true; // wait for all in progress write to finish try { while(writersInProgress > 0) { try { freezeSemaphore.wait(); } catch (InterruptedException ie) { // make sure we are not stuck in frozen state if we // caught an interrupt exception and the calling // thread may not have a chance to call unfreeze isFrozen = false; freezeSemaphore.notifyAll(); throw StandardException.interrupt(ie); } } } catch (RuntimeException rte) { // make sure we are not stuck in frozen state if we // caught a run time exception and the calling thread may not // have a chance to call unfreeze isFrozen = false; freezeSemaphore.notifyAll(); throw rte; // rethrow run time exception } if (SanityManager.DEBUG) SanityManager.ASSERT(writersInProgress == 0 && isFrozen == true, "data store is not properly frozen"); } } public void unfreezePersistentStore() { synchronized(freezeSemaphore) { isFrozen = false; freezeSemaphore.notifyAll(); } } public void writeInProgress() throws StandardException { synchronized(freezeSemaphore) { // do not start write, the persistent store is frozen while(isFrozen) { try { freezeSemaphore.wait(); } catch (InterruptedException ie) { throw StandardException.interrupt(ie); } } // store is not frozen, proceed to write - do this last writersInProgress++; } } public void writeFinished() { synchronized(freezeSemaphore) { if (SanityManager.DEBUG) SanityManager.ASSERT(writersInProgress > 0, "no writers in progress"); writersInProgress--; freezeSemaphore.notifyAll(); // wake up the freezer } } /* * Find all the all the containers stored in the seg0 directory and * backup each container to the specified backup location. */ public void backupDataFiles(Transaction rt, File backupDir) throws StandardException { /* * List of containers that needs to be backed up are identified by * simply reading the list of files in seg0. * All container that are created after the container list is created * when backup is in progress are recreated on restore using the * transaction log. */ String[] files = getContainerNames(); if (files != null) { // No user visible locks are acquired to backup the database. A stable backup // is made by latching the pages and internal synchronization // mechanisms. LockingPolicy lockPolicy = rt.newLockingPolicy(LockingPolicy.MODE_NONE, TransactionController.ISOLATION_NOLOCK, false); long segmentId = 0; // loop through all the files in seg0 and backup all valid containers. for (int f = files.length-1; f >= 0 ; f--) { long containerId; try { containerId = Long.parseLong(files[f].substring(1, (files[f].length() -4)), 16); } catch (Throwable t) { // ignore errors from parse, it just means that someone put // a file in seg0 that we didn't expect. Continue with the // next one. continue; } ContainerKey identity = new ContainerKey(segmentId, containerId); /* Not necessary to get the container thru the transaction. * Backup opens in container in read only mode , No need to * transition the transaction to active state. * * dropped container stubs also has to be backed up * for restore to work correctly. That is * why we are using a open call that let us * open dropped containers. */ ContainerHandle containerHdl = openDroppedContainer((RawTransaction)rt, identity, lockPolicy, ContainerHandle.MODE_READONLY); /* * Note 1: * If a container creation is in progress , open call will wait * until it is complete; It will never return a handle to a * container that is partially created. (see cache manager code * for more details) * * Note 2: * if a container creation failed in the middle after the list * of the names are read from seg0, it will not exist in * the database any more, so nothing to backup. Attempt * to open such container will return null. * */ if( containerHdl != null) { containerHdl.backupContainer(backupDir.getPath()); containerHdl.close(); } } } else { if (SanityManager.DEBUG) SanityManager.THROWASSERT("backup process is unable to read container names in seg0"); } } /** * get all the names of the files in seg 0. * MT - This method needs to be synchronized to avoid conflicts * with other privileged actions execution in this class. * @return An array of all the file names in seg0. **/ synchronized String[] getContainerNames() { actionCode = GET_CONTAINER_NAMES_ACTION; try{ return (String[]) AccessController.doPrivileged( this); } catch( PrivilegedActionException pae){ return null;} } /** * removes the data directory(seg*) from database home directory and * restores it from backup location. * This function gets called only when any of the folling attributes * are specified on connection URL: * Attribute.CREATE_FROM (Create database from backup if it does not exist) * Attribute.RESTORE_FROM (Delete the whole database if it exists and * then restore * it from backup) * Attribute.ROLL_FORWARD_RECOVERY_FROM:(Perform Rollforward Recovery; * except for the log directory everthing else is replced by the copy from * backup. log files in the backup are copied to the existing online log * directory. * * In all the cases, data directory(seg*) is replaced by the data directory * directory from backup when this function is called. */ private void restoreDataDirectory(String backupPath) throws StandardException { File bsegdir; //segment directory in the backup File backupRoot = new java.io.File(backupPath); //root dir of backup db /* To be safe we first check if the backup directory exist and it has * atleast one seg* directory before removing the current data directory. * * This will fail with a security exception unless the database engine * and all its callers have permission to read the backup directory. */ String[] bfilelist = PrivilegedFileOps.list(backupRoot); if(bfilelist !=null) { boolean segmentexist = false; for (int i = 0; i < bfilelist.length; i++) { //check if it is a seg* directory if(bfilelist[i].startsWith("seg")) { bsegdir = new File(backupRoot , bfilelist[i]); if(PrivilegedFileOps.exists(bsegdir) && PrivilegedFileOps.isDirectory(bsegdir)) { segmentexist = true; break; } } } if(!segmentexist) { throw StandardException.newException( SQLState.DATA_DIRECTORY_NOT_FOUND_IN_BACKUP, backupRoot); } } else { throw StandardException.newException( SQLState.DATA_DIRECTORY_NOT_FOUND_IN_BACKUP, backupRoot); } synchronized (this) { actionCode = RESTORE_DATA_DIRECTORY_ACTION; this.backupPath = backupPath; this.backupRoot = backupRoot; this.bfilelist = bfilelist; try { AccessController.doPrivileged( this); } catch (PrivilegedActionException pae) { throw (StandardException) pae.getException(); } finally { this.backupPath = null; this.backupRoot = null; this.bfilelist = null; } } } private void privRestoreDataDirectory() throws StandardException { StorageFile csegdir; //segment directory in the current db home StorageFile dataRoot = storageFactory.newStorageFile( null); //root dir of db //Remove the seg* directories in the current database home directory String[] cfilelist = dataRoot.list(); if(cfilelist!=null) { for (int i = 0; i < cfilelist.length; i++) { //delete only the seg* directories in the database home if(cfilelist[i].startsWith("seg")) { csegdir = storageFactory.newStorageFile( cfilelist[i]); if(!csegdir.deleteAll()) { throw StandardException.newException( SQLState.UNABLE_TO_REMOVE_DATA_DIRECTORY, csegdir); } } } } //copy the seg* directories from backup to current database home for (int i = 0; i < bfilelist.length; i++) { //copy only the seg* directories and copy them from backup if (bfilelist[i].startsWith("seg")) { csegdir = storageFactory.newStorageFile( bfilelist[i]); File bsegdir1 = new java.io.File(backupRoot, bfilelist[i]); if (!FileUtil.copyDirectory( writableStorageFactory, bsegdir1, csegdir)) { throw StandardException.newException( SQLState.UNABLE_TO_COPY_DATA_DIRECTORY, bsegdir1, csegdir); } } else if (databaseEncrypted && bfilelist[i].startsWith( Attribute.CRYPTO_EXTERNAL_KEY_VERIFY_FILE)) { // Case of encrypted database and usage of an external // encryption key, there is an extra file with name given by // Attribute.CRYPTO_EXTERNAL_KEY_VERIFY_FILE that needs to be // copied over during createFrom/restore operations. //copy the file File fromFile = new File(backupRoot,bfilelist[i]); StorageFile toFile = storageFactory.newStorageFile(bfilelist[i]); if (!FileUtil.copyFile(writableStorageFactory,fromFile,toFile)) { throw StandardException.newException( SQLState.UNABLE_TO_COPY_DATA_DIRECTORY, bfilelist[i], toFile); } } } } // end of privRestoreDataDirectory /** Is the store read-only. */ public boolean isReadOnly() { // return what the baseDataFileFactory thinks return readOnly; } /** * @return The StorageFactory used by this dataFactory */ public StorageFactory getStorageFactory() { return storageFactory; } // PrivilegedExceptionAction method public final Object run() throws Exception { switch( actionCode) { case BOOT_ACTION: readOnly = storageFactory.isReadOnlyDatabase(); supportsRandomAccess = storageFactory.supportsRandomAccess(); return null; case GET_TEMP_DIRECTORY_ACTION: return storageFactory.getTempDir(); case REMOVE_TEMP_DIRECTORY_ACTION: StorageFile tempDir = storageFactory.getTempDir(); if( tempDir != null) tempDir.deleteAll(); return null; case GET_CONTAINER_PATH_ACTION: case GET_ALTERNATE_CONTAINER_PATH_ACTION: { StringBuffer sb = new StringBuffer("seg"); sb.append(containerId.getSegmentId()); sb.append(storageFactory.getSeparator()); if( actionCode == GET_CONTAINER_PATH_ACTION) { sb.append(stub ? 'd' : 'c'); sb.append(Long.toHexString(containerId.getContainerId())); sb.append(".dat"); } else { sb.append(stub ? 'D' : 'C'); sb.append(Long.toHexString(containerId.getContainerId())); sb.append(".DAT"); } return storageFactory.newStorageFile( sb.toString()); } // end of cases GET_CONTAINER_PATH_ACTION & GET_ALTERNATE_CONTAINER_PATH_ACTION case REMOVE_STUBS_ACTION: { char separator = storageFactory.getSeparator(); StorageFile root = storageFactory.newStorageFile( null); // get all the non-temporary data segment, they start with "seg" String[] segs = root.list(); for (int s = segs.length-1; s >= 0; s--) { if (segs[s].startsWith("seg")) { StorageFile seg = storageFactory.newStorageFile(root, segs[s]); if (seg.exists() && seg.isDirectory()) { String[] files = seg.list(); for (int f = files.length-1; f >= 0 ; f--) { // stub if (files[f].startsWith("D") || files[f].startsWith("d")) { StorageFile stub = storageFactory.newStorageFile( root, segs[s] + separator + files[f]); boolean delete_status = stub.delete(); if (SanityManager.DEBUG) { // delete should always work, code which // created the StorageFactory already // checked for existence. if (!delete_status) { SanityManager.THROWASSERT( "delete of stub (" + stub + ") failed."); } } } } } } } break; } // end of case REMOVE_STUBS_ACTION case FIND_MAX_CONTAINER_ID_ACTION: { long maxnum = 1; StorageFile seg = storageFactory.newStorageFile( "seg0"); if (seg.exists() && seg.isDirectory()) { // create an array with names of all files in seg0 String[] files = seg.list(); // loop through array looking for maximum containerid. for (int f = files.length-1; f >= 0 ; f--) { try { long fileNumber = Long.parseLong( files[f].substring( 1, (files[f].length() -4)), 16); if (fileNumber > maxnum) maxnum = fileNumber; } catch (Throwable t) { // ignore errors from parse, it just means that someone // put a file in seg0 that we didn't expect. Continue // with the next one. } } } return ReuseFactory.getLong( maxnum); } // end of case FIND_MAX_CONTAINER_ID_ACTION case DELETE_IF_EXISTS_ACTION: { boolean ret = actionFile.exists() && actionFile.delete(); actionFile = null; return ret ? this : null; } // end of case DELETE_IF_EXISTS_ACTION case GET_PATH_ACTION: { String path = actionFile.getPath(); actionFile = null; return path; } // end of case GET_PATH_ACTION case POST_RECOVERY_REMOVE_ACTION: { for (Enumeration e = postRecoveryRemovedFiles.elements(); e.hasMoreElements(); ) { StorageFile f = (StorageFile) e.nextElement(); if (f.exists()) { boolean delete_status = f.delete(); if (SanityManager.DEBUG) { // delete should always work, code which // created the StorageFactory already // checked for existence. if (!delete_status) { SanityManager.THROWASSERT( "delete of stub (" + stub + ") failed."); } } } } return null; } case GET_LOCK_ON_DB_ACTION: privGetJBMSLockOnDB(); return null; case RELEASE_LOCK_ON_DB_ACTION: privReleaseJBMSLockOnDB(); return null; case RESTORE_DATA_DIRECTORY_ACTION: privRestoreDataDirectory(); return null; case GET_CONTAINER_NAMES_ACTION: { StorageFile seg = storageFactory.newStorageFile( "seg0"); if (seg.exists() && seg.isDirectory()) { // return the names of all files in seg0 return seg.list(); } return null; } // end of case GET_CONTAINER_NAMES_ACTION } return null; } // end of run }

The table below shows all metrics for BaseDataFileFactory.java.

MetricValueDescription
BLOCKS281.00Number of blocks
BLOCK_COMMENT99.00Number of block comment lines
COMMENTS658.00Comment lines
COMMENT_DENSITY 0.54Comment density
COMPARISONS151.00Number of comparison operators
CYCLOMATIC298.00Cyclomatic complexity
DECL_COMMENTS62.00Comments in declarations
DOC_COMMENT340.00Number of javadoc comment lines
ELOC1224.00Effective lines of code
EXEC_COMMENTS116.00Comments in executable code
EXITS179.00Procedure exits
FUNCTIONS77.00Number of function declarations
HALSTEAD_DIFFICULTY119.27Halstead difficulty
HALSTEAD_EFFORT 0.00Halstead effort
INTERFACE_COMPLEXITY285.00Interface complexity
JAVA0001 0.00JAVA0001 Package name does not contain only lower case letters
JAVA0002 0.00JAVA0002 Package name does not begin with a top level domain name or country code
JAVA0003 0.00JAVA0003 Minimize use of on-demand (.*) imports
JAVA0004 0.00JAVA0004 Unnecessary import from java.lang
JAVA0005 1.00JAVA0005 Imports not in specified order
JAVA0006 0.00JAVA0006 Empty finally block
JAVA0007 0.00JAVA0007 Should not declare public field
JAVA0008 0.00JAVA0008 Empty catch block
JAVA0009 0.00JAVA0009 Protected member in final class
JAVA0010 0.00JAVA0010 Non-instantiable class does not contain a non-private static member
JAVA0011 0.00JAVA0011 Abstract class does not contain an abstract method
JAVA0012 0.00JAVA0012 Non-constructor method with same name as declaring class
JAVA0013 0.00JAVA0013 Non-blank final field is not static
JAVA0014 0.00JAVA0014 Class with only static members has non-private constructor
JAVA0015 0.00JAVA0015 Package class contains public nested type
JAVA0016 0.00JAVA0016 Abstract class contains public constructor
JAVA0017 0.00JAVA0017 Class name does not have required form
JAVA0018 0.00JAVA0018 Method name does not have required form
JAVA0019 0.00JAVA0019 Interface name does not have required form
JAVA0020 0.00JAVA0020 Field name does not have required form
JAVA0021 0.00JAVA0021 Interface method name does not have required form
JAVA0022 0.00JAVA0022 Static final field name does not have required form
JAVA0023 0.00JAVA0023 Empty finalize method
JAVA0024 0.00JAVA0024 Empty class
JAVA0025 0.00JAVA0025 Method override is empty
JAVA0026 0.00JAVA0026 Finalize method with parameters
JAVA0029 2.00JAVA0029 Private method not used
JAVA0030 0.00JAVA0030 Private field not used
JAVA0031 0.00JAVA0031 Case statement not properly closed
JAVA0032 1.00JAVA0032 Switch statement missing default
JAVA0033 0.00JAVA0033 default: not last case in switch statement
JAVA003454.00JAVA0034 Missing braces in if statement
JAVA0035 0.00JAVA0035 Missing braces in for statement
JAVA0036 0.00JAVA0036 Missing braces in while statement
JAVA0038 0.00JAVA0038 Non-case label in switch statement
JAVA0039 0.00JAVA0039 Break statement with label
JAVA0040 1.00JAVA0040 Switch statement contains N cases (maximum: M)
JAVA0041 1.00JAVA0041 Nested synchronized block
JAVA0042 0.00JAVA0042 Empty synchronized statement
JAVA0043 0.00JAVA0043 Inner class does not use outer class
JAVA0044 0.00JAVA0044 Serializable class with no instance variables
JAVA0045 0.00JAVA0045 Serializable class with only transient fields
JAVA0046 0.00JAVA0046 Name of class not derived from Exception ends with 'Exception'
JAVA0047 0.00JAVA0047 Serializable class derives from invalid base class
JAVA0048 0.00JAVA0048 Name of class derived from Exception does not end with 'Exception'
JAVA0049 4.00JAVA0049 Nested block at depth N (maximum: M)
JAVA0050 0.00JAVA0050 Class derives from java.lang.Error
JAVA0051 0.00JAVA0051 Class derives from java.lang.RuntimeException
JAVA0052 0.00JAVA0052 Class derives from java.lang.Throwable
JAVA0053 0.00JAVA0053 Unused label
JAVA0054 0.00JAVA0054 Inheritance depth N exceeds maximum M
JAVA0055 0.00JAVA0055 Class should be interface
JAVA0056 0.00JAVA0056 Unnecessary abstract modifier for interface or annotation
JAVA0057 1.00JAVA0057 Unnecessary default constructor
JAVA0058 0.00JAVA0058 Constructor calls super()
JAVA0059 0.00JAVA0059 Method override only calls super()
JAVA0061 0.00JAVA0061 Inaccessible member in anonymous class
JAVA0062 0.00JAVA0062 Public class missing public member or protected constructor
JAVA0063 0.00JAVA0063 Identifier name should not contain '$'
JAVA0064 0.00JAVA0064 N variations of identifier name (maximum: M)
JAVA0065 0.00JAVA0065 Unnecessary final modifier for method in final class
JAVA0066 0.00JAVA0066 Unnecessary modifier for interface nested type
JAVA0067 0.00JAVA0067 Array descriptor on identifier name
JAVA0068 0.00JAVA0068 Modifiers not declared in recommended order
JAVA0071 0.00JAVA0071 Strings compared with ==
JAVA0073 0.00JAVA0073 Integer division in floating-point context
JAVA0074 0.00JAVA0074 Use of Object.notify()
JAVA007515.00JAVA0075 Method parameter hides field
JAVA0076 2.00JAVA0076 Use of magic number
JAVA0077 0.00JAVA0077 Private field not used in declaring class
JAVA0078 0.00JAVA0078 Floating point values compared with ==
JAVA0079 0.00JAVA0079 Use of instance to reference static member
JAVA0080 8.00JAVA0080 Import declaration not used
JAVA0081 1.00JAVA0081 Boolean literal in comparison
JAVA0082 0.00JAVA0082 Unnecessary widening cast
JAVA0083 0.00JAVA0083 Unnecessary instanceof test
JAVA0084 0.00JAVA0084 Should use compound assignment operator
JAVA0085 0.00JAVA0085 Use of sun.* class
JAVA0087 0.00JAVA0087 Use of Thread.sleep()
JAVA0089 0.00JAVA0089 Use of restricted package
JAVA0092 0.00JAVA0092 Use of restricted type
JAVA0093 0.00JAVA0093 Redundant assignment
JAVA0094 0.00JAVA0094 Field hides a superclass field
JAVA0095 0.00JAVA0095 Uninitialized private field
JAVA0096 0.00JAVA0096 Field in nested class hides outer field
JAVA0098 0.00JAVA0098 Minimize use of implicit field initializers
JAVA0100 1.00JAVA0100 Class contains N non-final fields (maximum: M)
JAVA0101 0.00JAVA0101 Unnecessary modifier for field in interface
JAVA0102 0.00JAVA0102 Last statement in finalize() not super.finalize()
JAVA0103 0.00JAVA0103 Explicit call to finalize()
JAVA0104 0.00JAVA0104 finalize() only calls super.finalize()
JAVA0105 1.00JAVA0105 Duplicate import declaration
JAVA0106 8.00JAVA0106 Unnecessary import from current package
JAVA010820.00JAVA0108 Incorrect javadoc: no @param tag for 'parameter'
JAVA0109 0.00JAVA0109 Incorrect javadoc: no parameter 'parameter'
JAVA011014.00JAVA0110 Incorrect javadoc: no @return tag
JAVA0111 0.00JAVA0111 Incorrect javadoc: @return tag for void method
JAVA0112 0.00JAVA0112 Incorrect javadoc: no exception 'exception' in throws
JAVA0113 1.00JAVA0113 Incorrect javadoc: no @author tag
JAVA0114 1.00JAVA0114 Incorrect javadoc: no @version tag
JAVA0115 2.00JAVA0115 Incorrect javadoc: no @throws or @exception tag for 'exception'
JAVA0116 0.00JAVA0116 Missing javadoc: field 'field'
JAVA0117 3.00JAVA0117 Missing javadoc: method 'method'
JAVA0118 0.00JAVA0118 Missing javadoc: type 'type'
JAVA0119 0.00JAVA0119 Control variable changed within body of for loop
JAVA0123 2.00JAVA0123 Use all three components of for loop
JAVA0125 0.00JAVA0125 Continue statement with label
JAVA0126 0.00JAVA0126 Method declares unchecked exception in throws
JAVA0128 0.00JAVA0128 Public constructor in non-public class
JAVA0130 3.00JAVA0130 Non-static method does not use instance fields
JAVA0131 0.00JAVA0131 Compatible method does not override base
JAVA0132 0.00JAVA0132 Method overload with compatible signature
JAVA0133 0.00JAVA0133 Non-synchronized method overrides synchronized method
JAVA0135 0.00JAVA0135 Only one of Object.equals and Object.hashCode defined: missing 'method'
JAVA0136 1.00JAVA0136 N methods defined in class (maximum: M)
JAVA0137 0.00JAVA0137 Non-abstract class missing constructor
JAVA0138 2.00JAVA0138 N parameters defined for method (maximum: M)
JAVA0139 0.00JAVA0139 Definition of main other than public static void main(java.lang.String[])
JAVA0141 0.00JAVA0141 Unnecessary modifier for method in interface
JAVA0143 7.00JAVA0143 Synchronized method
JAVA0144 0.00JAVA0144 Line exceeds maximum M characters
JAVA01452789.00JAVA0145 Tab character used in source file
JAVA0150 0.00JAVA0150 java.lang.Error (or subclass) thrown
JAVA0153 0.00JAVA0153 Inefficient conversion of integer to string
JAVA0159 0.00JAVA0159 Inefficient conversion of string to integer
JAVA0160 3.00JAVA0160 Method does not throw specified exception
JAVA0161 0.00JAVA0161 Conditional wait() not in loop
JAVA0163 0.00JAVA0163 Empty statement
JAVA0165 0.00JAVA0165 Conflicting return statement in finally block
JAVA0166 3.00JAVA0166 Generic exception caught
JAVA0167 0.00JAVA0167 ThreadDeath not rethrown
JAVA0169 0.00JAVA0169 Unnecessary catch block: exception 'exception'
JAVA0170 2.00JAVA0170 Caught exception not derived from java.lang.Exception
JAVA0171 1.00JAVA0171 Unused local variable
JAVA0173 3.00JAVA0173 Unused method parameter
JAVA0174 3.00JAVA0174 Assigned local variable never used
JAVA0175 0.00JAVA0175 Successive assignment to variable
JAVA0176 0.00JAVA0176 Local variable name does not have required form
JAVA0177 6.00JAVA0177 Variable declaration missing initializer
JAVA0179 6.00JAVA0179 Local variable hides visible field
JAVA0233 0.00JAVA0233 Definition of serialVersionUID other than 'private static final long serialVersionUID'
JAVA0234 0.00JAVA0234 Class is Serializable but does not define serialVersionUID
JAVA0235 0.00JAVA0235 Class defines serialVersionUID but does not implement Serializable
JAVA0236 0.00JAVA0236 Attempt to clone an object which does not implement Cloneable
JAVA0237 0.00JAVA0237 Class implements Cloneable but does not have public clone method
JAVA0238 0.00JAVA0238 Clone method does not call super.clone()
JAVA0239 0.00JAVA0239 Class declares 'readObject' or 'writeObject' but does not implement Serializable
JAVA0240 0.00JAVA0240 Serializable class which declares readObject or writeObject but not both
JAVA0241 0.00JAVA0241 'readObject' or 'writeObject' should be declared private in Serializable class
JAVA0242 0.00JAVA0242 Transient field in non-Serializable class
JAVA0243 0.00JAVA0243 'readResolve' or 'writeReplace' should be declared private or protected
JAVA0244 0.00JAVA0244 Field or method name in subclass differs only by case from inherited field or method
JAVA0245 0.00JAVA0245 JUnit TestCase with non-trivial constructor
JAVA0246 0.00JAVA0246 JUnit assertXXX statement missing message parameter
JAVA0247 0.00JAVA0247 JUnit 'setUp()' and 'tearDown()' should call super method
JAVA0248 0.00JAVA0248 JUnit method 'setUp' or 'tearDown' with incorrect signature
JAVA0249 0.00JAVA0249 JUnit TestCase 'suite()' should be declared static
JAVA0250 0.00JAVA0250 JUnit TestCase declares testXXX method with incorrect signature
JAVA0251 0.00JAVA0251 Use '%n' for line breaks in printf/format for platform independence
JAVA0252 0.00JAVA0252 'enum' is a Java 1.5 reserved word
JAVA0253 0.00JAVA0253 Not all enum constants consumed in switch statement
JAVA0254 0.00JAVA0254 Use enhanced for loop construct instead of Iterator
JAVA0255 0.00JAVA0255 Result of method invocation not used
JAVA0256 0.00JAVA0256 Assignment of external collection/array to field
JAVA0257 0.00JAVA0257 Use of 'Constant Interface' anti-pattern
JAVA0258 0.00JAVA0258 Implement Iterable for foreach compatibility
JAVA0259 0.00JAVA0259 Return of collection/array field
JAVA0260 0.00JAVA0260 Use 'enum' instead of Enumerated Type pattern
JAVA0261 0.00JAVA0261 Use specialized Enum collection types
JAVA0262 0.00JAVA0262 Use of char in integer context
JAVA0263 0.00JAVA0263 Long literal ends with 'l' instead of 'L'
JAVA0264 0.00JAVA0264 Integer math in long context - check for overflow
JAVA0265 1.00JAVA0265 Use of Throwable.printStackTrace()
JAVA0266 0.00JAVA0266 Use of System.out
JAVA0267 1.00JAVA0267 Use of System.err
JAVA0269 0.00JAVA0269 Contents of StringBuffer never used
JAVA0270 3.00JAVA0270 Use Java 5.0 enhanced for loop construct to iterate over all elements in an array
JAVA0271 0.00JAVA0271 Minimize use of on-demand (.*) static imports
JAVA0272 0.00JAVA0272 Thread.run() called
JAVA0273 0.00JAVA0273 Non-final derivative of Thread calls start() in constructor
JAVA0274 0.00JAVA0274 Serializable class has a synchronized readObject()
JAVA0275 0.00JAVA0275 Serializable class has a synchronized writeObject() and no other synchronized methods
JAVA0276 0.00JAVA0276 Unnecessary use of String constructor
JAVA0277 0.00JAVA0277 Iterator.next() implementation does not throw NoSuchElementException
JAVA0278 0.00JAVA0278 Unnecessary use of Boolean constructor
JAVA0279 0.00JAVA0279 Serialization method readObject or readObjectNoData calls an overridable method
JAVA0280 0.00JAVA0280 IllegalMonitorStateException caught
JAVA0281 0.00JAVA0281 Iterator.next() not called in loop
JAVA0282 0.00JAVA0282 Call to Iterator.next() in loop which does not test Iterator.hasNext()
JAVA0283 0.00JAVA0283 Control variable not updated in loop body
JAVA0284 0.00JAVA0284 Explicit garbage collection
JAVA0285 2.00JAVA0285 Dereference of potentially null variable
JAVA0286 0.00JAVA0286 Dereference of null variable
JAVA0287 0.00JAVA0287 Unnecessary null check
JAVA0288 0.00JAVA0288 Inconsistent null check
LINES2811.00Number of lines in the source file
LINE_COMMENT219.00Number of line comments
LOC1758.00Lines of code
LOGICAL_LINES610.00Number of statements
LOOPS11.00Number of loops
NEST_DEPTH 9.00Maximum nesting depth
OPERANDS2752.00Number of operands
OPERATORS5298.00Number of operators
PARAMS95.00Number of formal parameter declarations
PROGRAM_LENGTH8050.00Halstead program length
PROGRAM_VOCAB840.00Halstead program vocabulary
PROGRAM_VOLUME 0.00Halstead program volume
RETURNS190.00Number of return points from functions
SIZE86618.00Size of the file in bytes
UNIQUE_OPERANDS773.00Number of unique operands
UNIQUE_OPERATORS67.00Number of unique operators
WHITESPACE395.00Number of whitespace lines