org.apache.derby.impl.store.raw
Class RawStore

java.lang.Object
  extended by org.apache.derby.impl.store.raw.RawStore
All Implemented Interfaces:
java.security.PrivilegedExceptionAction, ModuleControl, ModuleSupportable, Corruptable, RawStoreFactory

public final class RawStore
extends java.lang.Object
implements RawStoreFactory, ModuleControl, ModuleSupportable, java.security.PrivilegedExceptionAction

A Raw store that implements the RawStoreFactory module by delegating all the work to the lower modules TransactionFactory, LogFactory and DataFactory.

        String TransactionFactoryId=
        

Class is final as it has methods with privilege blocks and implements PrivilegedExceptionAction.


Field Summary
private  boolean actionAppend
           
private  byte[] actionBuffer
           
private  int actionCode
           
private  boolean actionCopySubDirs
           
private  java.lang.String[] actionFilter
           
private  java.io.File actionRegularFile
           
private  java.io.File actionRegularFile2
           
private  StorageFile actionStorageFile
           
private  StorageFile actionToStorageFile
           
private static java.lang.String BACKUP_HISTORY
           
private static int COPY_REGULAR_DIRECTORY_TO_STORAGE_ACTION
           
private static int COPY_REGULAR_FILE_TO_STORAGE_ACTION
           
private static int COPY_STORAGE_DIRECTORY_TO_REGULAR_ACTION
           
private static int COPY_STORAGE_FILE_TO_REGULAR_ACTION
           
private static int COPY_STORAGE_FILE_TO_STORAGE_ACTION
           
private  int counter_decrypt
           
private  int counter_encrypt
           
private  CipherFactory currentCipherFactory
           
private  boolean databaseEncrypted
           
(package private)  java.lang.String dataDirectory
           
protected  DataFactory dataFactory
           
private  CipherProvider decryptionEngine
           
private  boolean encryptDatabase
           
private  int encryptionBlockSize
           
private  CipherProvider encryptionEngine
           
private static int FILE_WRITER_ACTION
           
protected  LogFactory logFactory
           
private  CipherFactory newCipherFactory
           
private  CipherProvider newDecryptionEngine
           
private  CipherProvider newEncryptionEngine
           
private  java.security.SecureRandom random
           
protected  DaemonService rawStoreDaemon
           
private static int REGULAR_FILE_DELETE_ACTION
           
private static int REGULAR_FILE_EXISTS_ACTION
           
private static int REGULAR_FILE_GET_CANONICALPATH_ACTION
           
private static int REGULAR_FILE_IS_DIRECTORY_ACTION
           
private static int REGULAR_FILE_LIST_DIRECTORY_ACTION
           
private static int REGULAR_FILE_MKDIRS_ACTION
           
private static int REGULAR_FILE_REMOVE_DIRECTORY_ACTION
           
private static int REGULAR_FILE_RENAME_TO_ACTION
           
private  SlaveFactory slaveFactory
           
private static int STORAGE_FILE_DELETE_ACTION
           
private static int STORAGE_FILE_EXISTS_ACTION
           
private static int STORAGE_FILE_GET_CANONICALPATH_ACTION
           
private static int STORAGE_FILE_LIST_DIRECTORY_ACTION
           
private  StorageFactory storageFactory
           
static java.lang.String TEST_REENCRYPT_CRASH_AFTER_CHECKPOINT
           
static java.lang.String TEST_REENCRYPT_CRASH_AFTER_COMMT
           
static java.lang.String TEST_REENCRYPT_CRASH_AFTER_RECOVERY_UNDO_LOGFILE_DELETE
           
static java.lang.String TEST_REENCRYPT_CRASH_AFTER_RECOVERY_UNDO_REVERTING_KEY
           
static java.lang.String TEST_REENCRYPT_CRASH_AFTER_SWITCH_TO_NEWKEY
           
static java.lang.String TEST_REENCRYPT_CRASH_BEFORE_COMMT
          (re) encryption testing debug flags that are used to simulate error/crash conditions for testing purposes.
static java.lang.String TEST_REENCRYPT_CRASH_BEFORE_RECOVERY_FINAL_CLEANUP
           
protected  TransactionFactory xactFactory
           
 
Fields inherited from interface org.apache.derby.iapi.store.raw.RawStoreFactory
CONTAINER_CACHE_SIZE_DEFAULT, CONTAINER_CACHE_SIZE_MAXIMUM, CONTAINER_CACHE_SIZE_MINIMUM, CONTAINER_CACHE_SIZE_PARAMETER, CONTAINER_INITIAL_PAGES, CRYPTO_OLD_EXTERNAL_KEY_VERIFY_FILE, DATA_ENCRYPT_ALGORITHM_VERSION, DB_ENCRYPTION_IN_CLEANUP, DB_ENCRYPTION_IN_PROGRESS, DB_ENCRYPTION_IN_UNDO, DB_ENCRYPTION_STATUS, DEFAULT_ENCRYPTION_BLOCKSIZE, DERBY_STORE_MAJOR_VERSION_10, DERBY_STORE_MINOR_VERSION_1, DERBY_STORE_MINOR_VERSION_2, DERBY_STORE_MINOR_VERSION_3, DERBY_STORE_MINOR_VERSION_4, ENCRYPTED_KEY, ENCRYPTION_ALIGNMENT, ENCRYPTION_BLOCKSIZE, KEEP_TRANSACTION_LOG, LOG_ENCRYPT_ALGORITHM_VERSION, MAX_CONTAINER_INITIAL_PAGES, MINIMUM_RECORD_SIZE_DEFAULT, MINIMUM_RECORD_SIZE_MINIMUM, MINIMUM_RECORD_SIZE_PARAMETER, MODULE, OLD_ENCRYPTED_KEY, PAGE_CACHE_SIZE_DEFAULT, PAGE_CACHE_SIZE_MAXIMUM, PAGE_CACHE_SIZE_MINIMUM, PAGE_CACHE_SIZE_PARAMETER, PAGE_RESERVED_SPACE_PARAMETER, PAGE_RESERVED_ZERO_SPACE_STRING, PAGE_REUSABLE_RECORD_ID, PAGE_SIZE_DEFAULT, PAGE_SIZE_MINIMUM, PAGE_SIZE_STRING, PATCH_INITPAGE_RECOVER_ERROR, PRE_ALLOCATE_PAGE, STREAM_FILE_BUFFER_SIZE_DEFAULT, STREAM_FILE_BUFFER_SIZE_MAXIMUM, STREAM_FILE_BUFFER_SIZE_MINIMUM, STREAM_FILE_BUFFER_SIZE_PARAMETER
 
Constructor Summary
RawStore()
           
 
Method Summary
 void backup(java.lang.String backupDir, boolean wait)
          Backup the database to a backup directory.
 void backup(Transaction t, java.io.File backupDir)
           
 void backupAndEnableLogArchiveMode(java.lang.String backupDir, boolean deleteOnlineArchivedLogFiles, boolean wait)
          Backup the database to a backup directory and enable the log archive mode that will keep the archived log files required for roll-forward from this version backup.
 void boot(boolean create, java.util.Properties properties)
          Boot this module with the given properties.
private  void canEncryptDatabase(boolean reEncrypt)
          checks if the database is in the right state to (re)encrypt it.
 boolean canSupport(java.util.Properties startParams)
          We use this RawStore for all databases.
 java.io.Serializable changeBootPassword(java.util.Properties properties, java.io.Serializable changePassword)
          Change the boot password.
 void checkpoint()
          Checkpoint the database.
 boolean checkVersion(int requiredMajorVersion, int requiredMinorVersion, java.lang.String feature)
          Check to see if a database has been upgraded to the required level in order to use a store feature.
 void configureDatabaseForEncryption(java.util.Properties properties, CipherFactory newCipherFactory)
           
private  void crashOnDebugFlag(java.lang.String debugFlag, boolean reEncrypt)
          when the input debug flag is set, an expception is throw when run in the debug mode.
 void createFinished()
           
 int decrypt(byte[] ciphertext, int offset, int length, byte[] cleartext, int outputOffset)
          Decrypt cleartext from ciphertext.
 void disableLogArchiveMode(boolean deleteOnlineArchivedLogFiles)
          disables the log archival process, i.e No old log files will be kept around for a roll-forward recovery.
 int encrypt(byte[] cleartext, int offset, int length, byte[] ciphertext, int outputOffset, boolean newEngine)
          Encrypt cleartext into ciphertext.
 void failover(java.lang.String dbname)
          Start failover for this database.
 Transaction findUserTransaction(ContextManager contextMgr, java.lang.String transName)
          Find a user transaction in the context manager, which must be the current context manager.
 void freeze()
          Freeze the database temporarily so a backup can be taken.
 void freezePersistentStore()
          Freeze persistent store.
 DaemonService getDaemon()
          If this raw store has a daemon that services its need, return the daemon.
 java.lang.String getDataFactoryModule()
           
 int getEncryptionBlockSize()
          Returns the encryption block size used by the algorithm at time of creation of an encrypted database
private  java.lang.String getFilePath(java.io.File file)
           
private  java.lang.String getFilePath(StorageFile file)
           
 LockFactory getLockFactory()
          Get the LockFactory to use with this store.
 java.lang.String getLogFactoryModule()
           
 java.lang.String getMasterFactoryModule()
           
 long getMaxContainerId()
          Return an id which can be used to create a container.
 void getRawStoreProperties(PersistentSet set)
          Get JBMS properties relavent to raw store
 java.lang.String getSlaveFactoryModule()
           
 java.lang.String getTransactionFactoryModule()
           
 TransactionInfo[] getTransactionInfo()
           
 TransactionFactory getXactFactory()
          Get the Transaction Factory to use with this store.
 java.lang.Object getXAResourceManager()
           
 void handleIncompleteDatabaseEncryption(java.util.Properties properties)
          Engine might have crashed during encryption of un-encrypted datbase or while re-encryptin an already encrypted database with a new key after all the containers or (re) encrypted.
 void idle()
          Idle the raw store as much as possible.
 boolean isReadOnly()
          Is the store read-only.
private  void logHistory(java.io.OutputStreamWriter historyFile, java.lang.String msg)
           
 StandardException markCorrupt(StandardException originalError)
          Mark the module as corrupt.
 ScanHandle openFlushedScan(DatabaseInstant start, int groupsIWant)
          Get a flushed scan.
protected  boolean privCopyDirectory(java.io.File from, StorageFile to)
           
private  boolean privCopyDirectory(java.io.File from, StorageFile to, byte[] buffer, java.lang.String[] filter)
           
protected  boolean privCopyDirectory(StorageFile from, java.io.File to)
           
private  boolean privCopyDirectory(StorageFile from, java.io.File to, byte[] buffer, java.lang.String[] filter, boolean copySubdirs)
           
private  boolean privCopyFile(java.io.File from, StorageFile to)
           
private  boolean privCopyFile(StorageFile from, java.io.File to)
           
private  boolean privCopyFile(StorageFile from, StorageFile to)
           
private  boolean privDelete(java.io.File file)
           
private  boolean privDelete(StorageFile file)
           
private  boolean privExists(java.io.File file)
           
private  boolean privExists(StorageFile file)
           
private  java.io.OutputStreamWriter privFileWriter(StorageFile fileName, boolean append)
           
private  java.lang.String privGetCanonicalPath(java.io.File file)
           
private  java.lang.String privGetCanonicalPath(StorageFile file)
           
private  boolean privIsDirectory(java.io.File file)
           
private  java.lang.String[] privList(java.io.File file)
           
private  java.lang.String[] privList(StorageFile file)
           
private  boolean privMkdirs(java.io.File file)
           
private  boolean privRemoveDirectory(java.io.File file)
           
private  boolean privRenameTo(java.io.File file1, java.io.File file2)
           
 int random()
          Returns a secure random number for this raw store - if database is not encrypted, returns 0.
private  void restoreRemainingFromBackup(java.lang.String backupPath)
           
 java.lang.Object run()
           
private  void setupEncryptionEngines(boolean create, java.util.Properties properties)
           
 Transaction startGlobalTransaction(ContextManager contextMgr, int format_id, byte[] global_id, byte[] branch_id)
          Create a global user transaction, almost all work within the raw store is performed in the context of a transaction.
 Transaction startInternalTransaction(ContextManager contextMgr)
          Create an internal transaction.
 Transaction startNestedReadOnlyUserTransaction(CompatibilitySpace compatibilitySpace, ContextManager contextMgr, java.lang.String transName)
          Create a nested user transaction, almost all work within the raw store is performed in the context of a transaction.
 Transaction startNestedUpdateUserTransaction(ContextManager contextMgr, java.lang.String transName)
          Create a nested user transaction, almost all work within the raw store is performed in the context of a transaction.
 void startReplicationMaster(java.lang.String dbmaster, java.lang.String host, int port, java.lang.String replicationMode)
          Start the replication master role for this database
 Transaction startTransaction(ContextManager contextMgr, java.lang.String transName)
          Create a user transaction, almost all work within the raw store is performed in the context of a transaction.
 void stop()
          Stop the module.
 void stopReplicationMaster()
          Stop the replication master role for this database.
 void unfreeze()
          Unfreeze the database after a backup has been taken.
 void unfreezePersistentStore()
          Freeze persistent store.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

BACKUP_HISTORY

private static final java.lang.String BACKUP_HISTORY
See Also:
Constant Field Values

xactFactory

protected TransactionFactory xactFactory

dataFactory

protected DataFactory dataFactory

logFactory

protected LogFactory logFactory

slaveFactory

private SlaveFactory slaveFactory

storageFactory

private StorageFactory storageFactory

random

private java.security.SecureRandom random

databaseEncrypted

private boolean databaseEncrypted

encryptDatabase

private boolean encryptDatabase

encryptionEngine

private CipherProvider encryptionEngine

decryptionEngine

private CipherProvider decryptionEngine

newEncryptionEngine

private CipherProvider newEncryptionEngine

newDecryptionEngine

private CipherProvider newDecryptionEngine

currentCipherFactory

private CipherFactory currentCipherFactory

newCipherFactory

private CipherFactory newCipherFactory

counter_encrypt

private int counter_encrypt

counter_decrypt

private int counter_decrypt

encryptionBlockSize

private int encryptionBlockSize

dataDirectory

java.lang.String dataDirectory

rawStoreDaemon

protected DaemonService rawStoreDaemon

actionCode

private int actionCode

FILE_WRITER_ACTION

private static final int FILE_WRITER_ACTION
See Also:
Constant Field Values

actionStorageFile

private StorageFile actionStorageFile

actionToStorageFile

private StorageFile actionToStorageFile

actionAppend

private boolean actionAppend

REGULAR_FILE_EXISTS_ACTION

private static final int REGULAR_FILE_EXISTS_ACTION
See Also:
Constant Field Values

actionRegularFile

private java.io.File actionRegularFile

STORAGE_FILE_EXISTS_ACTION

private static final int STORAGE_FILE_EXISTS_ACTION
See Also:
Constant Field Values

REGULAR_FILE_DELETE_ACTION

private static final int REGULAR_FILE_DELETE_ACTION
See Also:
Constant Field Values

REGULAR_FILE_MKDIRS_ACTION

private static final int REGULAR_FILE_MKDIRS_ACTION
See Also:
Constant Field Values

REGULAR_FILE_IS_DIRECTORY_ACTION

private static final int REGULAR_FILE_IS_DIRECTORY_ACTION
See Also:
Constant Field Values

REGULAR_FILE_REMOVE_DIRECTORY_ACTION

private static final int REGULAR_FILE_REMOVE_DIRECTORY_ACTION
See Also:
Constant Field Values

REGULAR_FILE_RENAME_TO_ACTION

private static final int REGULAR_FILE_RENAME_TO_ACTION
See Also:
Constant Field Values

actionRegularFile2

private java.io.File actionRegularFile2

COPY_STORAGE_DIRECTORY_TO_REGULAR_ACTION

private static final int COPY_STORAGE_DIRECTORY_TO_REGULAR_ACTION
See Also:
Constant Field Values

actionBuffer

private byte[] actionBuffer

actionFilter

private java.lang.String[] actionFilter

actionCopySubDirs

private boolean actionCopySubDirs

COPY_REGULAR_DIRECTORY_TO_STORAGE_ACTION

private static final int COPY_REGULAR_DIRECTORY_TO_STORAGE_ACTION
See Also:
Constant Field Values

COPY_REGULAR_FILE_TO_STORAGE_ACTION

private static final int COPY_REGULAR_FILE_TO_STORAGE_ACTION
See Also:
Constant Field Values

REGULAR_FILE_LIST_DIRECTORY_ACTION

private static final int REGULAR_FILE_LIST_DIRECTORY_ACTION
See Also:
Constant Field Values

STORAGE_FILE_LIST_DIRECTORY_ACTION

private static final int STORAGE_FILE_LIST_DIRECTORY_ACTION
See Also:
Constant Field Values

COPY_STORAGE_FILE_TO_REGULAR_ACTION

private static final int COPY_STORAGE_FILE_TO_REGULAR_ACTION
See Also:
Constant Field Values

REGULAR_FILE_GET_CANONICALPATH_ACTION

private static final int REGULAR_FILE_GET_CANONICALPATH_ACTION
See Also:
Constant Field Values

STORAGE_FILE_GET_CANONICALPATH_ACTION

private static final int STORAGE_FILE_GET_CANONICALPATH_ACTION
See Also:
Constant Field Values

COPY_STORAGE_FILE_TO_STORAGE_ACTION

private static final int COPY_STORAGE_FILE_TO_STORAGE_ACTION
See Also:
Constant Field Values

STORAGE_FILE_DELETE_ACTION

private static final int STORAGE_FILE_DELETE_ACTION
See Also:
Constant Field Values

TEST_REENCRYPT_CRASH_BEFORE_COMMT

public static final java.lang.String TEST_REENCRYPT_CRASH_BEFORE_COMMT
(re) encryption testing debug flags that are used to simulate error/crash conditions for testing purposes. When any one of the following flags are set to true in the debug mode, re-encryption will fail at that point.


TEST_REENCRYPT_CRASH_AFTER_COMMT

public static final java.lang.String TEST_REENCRYPT_CRASH_AFTER_COMMT

TEST_REENCRYPT_CRASH_AFTER_SWITCH_TO_NEWKEY

public static final java.lang.String TEST_REENCRYPT_CRASH_AFTER_SWITCH_TO_NEWKEY

TEST_REENCRYPT_CRASH_AFTER_CHECKPOINT

public static final java.lang.String TEST_REENCRYPT_CRASH_AFTER_CHECKPOINT

TEST_REENCRYPT_CRASH_AFTER_RECOVERY_UNDO_LOGFILE_DELETE

public static final java.lang.String TEST_REENCRYPT_CRASH_AFTER_RECOVERY_UNDO_LOGFILE_DELETE

TEST_REENCRYPT_CRASH_AFTER_RECOVERY_UNDO_REVERTING_KEY

public static final java.lang.String TEST_REENCRYPT_CRASH_AFTER_RECOVERY_UNDO_REVERTING_KEY

TEST_REENCRYPT_CRASH_BEFORE_RECOVERY_FINAL_CLEANUP

public static final java.lang.String TEST_REENCRYPT_CRASH_BEFORE_RECOVERY_FINAL_CLEANUP
Constructor Detail

RawStore

public RawStore()
Method Detail

canSupport

public boolean canSupport(java.util.Properties startParams)
We use this RawStore for all databases.

Specified by:
canSupport in interface ModuleSupportable
Returns:
true if this instance can be used, false otherwise.

boot

public void boot(boolean create,
                 java.util.Properties properties)
          throws StandardException
Description copied from interface: ModuleControl
Boot this module with the given properties. Creates a module instance that can be found using the findModule() methods of Monitor. The module can only be found using one of these findModule() methods once this method has returned.

An implementation's boot method can throw StandardException. If it is thrown the module is not registered by the monitor and therefore cannot be found through a findModule(). In this case the module's stop() method is not called, thus throwing this exception must free up any resources.

When create is true the contents of the properties object will be written to the service.properties of the persistent service. Thus any code that requires an entry in service.properties must explicitly place the value in this properties set using the put method.
Typically the properties object contains one or more default properties sets, which are not written out to service.properties. These default sets are how callers modify the create process. In a JDBC connection database create the first set of defaults is a properties object that contains the attributes that were set on the jdbc:derby: URL. This attributes properties set has the second default properties set as its default. This set (which could be null) contains the properties that the user set on their DriverManager.getConnection() call, and are thus not owned by Derby code, and thus must not be modified by Derby code.

When create is false the properties object contains all the properties set in the service.properties file plus a limited number of attributes from the JDBC URL attributes or connection properties set. This avoids properties set by the user compromising the boot process. An example of a property passed in from the JDBC world is the bootPassword for encrypted databases.

Code should not hold onto the passed in properties reference after boot time as its contents may change underneath it. At least after the complete boot is completed, the links to all the default sets will be removed.

Specified by:
boot in interface ModuleControl
Throws:
StandardException - Module cannot be started.
See Also:
Monitor, ModuleFactory

stop

public void stop()
Description copied from interface: ModuleControl
Stop the module. The module may be found via a findModule() method until some time after this method returns. Therefore the factory must be prepared to reject requests to it once it has been stopped. In addition other modules may cache a reference to the module and make requests of it after it has been stopped, these requests should be rejected as well.

Specified by:
stop in interface ModuleControl
See Also:
Monitor, ModuleFactory

isReadOnly

public boolean isReadOnly()
Is the store read-only.

Specified by:
isReadOnly in interface RawStoreFactory
See Also:
RawStoreFactory.isReadOnly()

getLockFactory

public LockFactory getLockFactory()
Description copied from interface: RawStoreFactory
Get the LockFactory to use with this store.

Specified by:
getLockFactory in interface RawStoreFactory

getXactFactory

public TransactionFactory getXactFactory()
Get the Transaction Factory to use with this store.

Specified by:
getXactFactory in interface RawStoreFactory

getXAResourceManager

public java.lang.Object getXAResourceManager()
                                      throws StandardException
Specified by:
getXAResourceManager in interface RawStoreFactory
Throws:
StandardException

startGlobalTransaction

public Transaction startGlobalTransaction(ContextManager contextMgr,
                                          int format_id,
                                          byte[] global_id,
                                          byte[] branch_id)
                                   throws StandardException
Description copied from interface: RawStoreFactory
Create a global user transaction, almost all work within the raw store is performed in the context of a transaction.

The (format_id, global_id, branch_id) triplet is meant to come exactly from a javax.transaction.xa.Xid. We don't use Xid so that the system can be delivered on a non-1.2 vm system and not require the javax classes in the path.

Starting a transaction always performs the following steps.

  1. Create an raw store transaction context
  2. Create a new idle transaction and then link it to the context. Only one user transaction can be active in a context at any one time. After a commit the transaction may be re-used.

    Raw Store Transaction Context Behaviour
    The cleanupOnError() method of this context behaves as follows:

    • If error is an instance of StandardException that has a severity less than ExceptionSeverity.TRANSACTION_SEVERITY then no action is taken.
    • If error is an instance of StandardException that has a severity equal to ExceptionSeverity.TRANSACTION_SEVERITY then the context's transaction is aborted, and the transaction returned to the idle state.
    • If error is an instance of StandardException that has a severity greater than ExceptionSeverity.TRANSACTION_SEVERITY then the context's transaction is aborted, the transaction closed, and the context is popped off the stack.
    • If error is not an instance of StandardException then the context's transaction is aborted, the transaction closed, and the context is popped off the stack.

    Specified by:
    startGlobalTransaction in interface RawStoreFactory
    Parameters:
    contextMgr - is the context manager to use. An exception will be thrown if context is not the current context.
    format_id - the format id part of the Xid - ie. Xid.getFormatId().
    global_id - the global transaction identifier part of XID - ie. Xid.getGlobalTransactionId().
    branch_id - The branch qualifier of the Xid - ie. Xid.getBranchQaulifier()
    Throws:
    StandardException - Standard Derby error policy
    See Also:
    Transaction, Context, StandardException

startTransaction

public Transaction startTransaction(ContextManager contextMgr,
                                    java.lang.String transName)
                             throws StandardException
Description copied from interface: RawStoreFactory
Create a user transaction, almost all work within the raw store is performed in the context of a transaction.

Starting a transaction always performs the following steps.

  1. Create an raw store transaction context
  2. Create a new idle transaction and then link it to the context. Only one user transaction and one nested user transaction can be active in a context at any one time. After a commit the transaction may be re-used.

    Raw Store Transaction Context Behaviour
    The cleanupOnError() method of this context behaves as follows:

    • If error is an instance of StandardException that has a severity less than ExceptionSeverity.TRANSACTION_SEVERITY then no action is taken.
    • If error is an instance of StandardException that has a severity equal to ExceptionSeverity.TRANSACTION_SEVERITY then the context's transaction is aborted, and the transaction returned to the idle state.
    • If error is an instance of StandardException that has a severity greater than ExceptionSeverity.TRANSACTION_SEVERITY then the context's transaction is aborted, the transaction closed, and the context is popped off the stack.
    • If error is not an instance of StandardException then the context's transaction is aborted, the transaction closed, and the context is popped off the stack.

    Specified by:
    startTransaction in interface RawStoreFactory
    Parameters:
    contextMgr - is the context manager to use. An exception will be thrown if context is not the current context.
    transName - is the name of the transaction. Thsi name will be displayed by the transactiontable VTI.
    Throws:
    StandardException - Standard Derby error policy
    See Also:
    Transaction, Context, StandardException

startNestedReadOnlyUserTransaction

public Transaction startNestedReadOnlyUserTransaction(CompatibilitySpace compatibilitySpace,
                                                      ContextManager contextMgr,
                                                      java.lang.String transName)
                                               throws StandardException
Description copied from interface: RawStoreFactory
Create a nested user transaction, almost all work within the raw store is performed in the context of a transaction.

A nested user transaction is exactly the same as a user transaction, except that one can specify a compatibility space to associate with the transaction. Starting a transaction always performs the following steps.

  1. Create an raw store transaction context
  2. Create a new idle transaction and then link it to the context. Only one user transaction and one nested user transaction can be active in a context at any one time. After a commit the transaction may be re-used.

    Raw Store Transaction Context Behaviour
    The cleanupOnError() method of this context behaves as follows:

    • If error is an instance of StandardException that has a severity less than ExceptionSeverity.TRANSACTION_SEVERITY then no action is taken.
    • If error is an instance of StandardException that has a severity equal to ExceptionSeverity.TRANSACTION_SEVERITY then the context's transaction is aborted, and the transaction returned to the idle state. If a user transaction exists on the context stack then that transaction is aborted also.
    • If error is an instance of StandardException that has a severity greater than ExceptionSeverity.TRANSACTION_SEVERITY then the context's transaction is aborted, the transaction closed, and the context is popped off the stack.
    • If error is not an instance of StandardException then the context's transaction is aborted, the transaction closed, and the context is popped off the stack.

    Specified by:
    startNestedReadOnlyUserTransaction in interface RawStoreFactory
    Parameters:
    compatibilitySpace - compatibility space to use for locks.
    contextMgr - is the context manager to use. An exception will be thrown if context is not the current context.
    transName - is the name of the transaction. This name will be displayed by the transactiontable VTI.
    Throws:
    StandardException - Standard Derby error policy
    See Also:
    Transaction, Context, StandardException

startNestedUpdateUserTransaction

public Transaction startNestedUpdateUserTransaction(ContextManager contextMgr,
                                                    java.lang.String transName)
                                             throws StandardException
Description copied from interface: RawStoreFactory
Create a nested user transaction, almost all work within the raw store is performed in the context of a transaction.

A nested user transaction is exactly the same as a user transaction, except that one can specify a compatibility space to associate with the transaction. Starting a transaction always performs the following steps.

  1. Create an raw store transaction context
  2. Create a new idle transaction and then link it to the context. Only one user transaction and one nested user transaction can be active in a context at any one time. After a commit the transaction may be re-used.

    Raw Store Transaction Context Behaviour
    The cleanupOnError() method of this context behaves as follows:

    • If error is an instance of StandardException that has a severity less than ExceptionSeverity.TRANSACTION_SEVERITY then no action is taken.
    • If error is an instance of StandardException that has a severity equal to ExceptionSeverity.TRANSACTION_SEVERITY then the context's transaction is aborted, and the transaction returned to the idle state. If a user transaction exists on the context stack then that transaction is aborted also.
    • If error is an instance of StandardException that has a severity greater than ExceptionSeverity.TRANSACTION_SEVERITY then the context's transaction is aborted, the transaction closed, and the context is popped off the stack.
    • If error is not an instance of StandardException then the context's transaction is aborted, the transaction closed, and the context is popped off the stack.

    Specified by:
    startNestedUpdateUserTransaction in interface RawStoreFactory
    Parameters:
    contextMgr - is the context manager to use. An exception will be thrown if context is not the current context.
    transName - is the name of the transaction. This name will be displayed by the transactiontable VTI.
    Throws:
    StandardException - Standard Derby error policy
    See Also:
    Transaction, Context, StandardException

findUserTransaction

public Transaction findUserTransaction(ContextManager contextMgr,
                                       java.lang.String transName)
                                throws StandardException
Description copied from interface: RawStoreFactory
Find a user transaction in the context manager, which must be the current context manager. If a user transaction does not already exist, then create one @see #startTransaction

Specified by:
findUserTransaction in interface RawStoreFactory
Parameters:
contextMgr - the context manager to use. An exception will be thrown if context is not the current context.
transName - If a new transaction is started, it will be given this name. The name is displayed in the transactiontable VTI.
Throws:
StandardException - Standard Derby error policy
See Also:
RawStoreFactory.startTransaction(org.apache.derby.iapi.services.context.ContextManager, java.lang.String)

startInternalTransaction

public Transaction startInternalTransaction(ContextManager contextMgr)
                                     throws StandardException
Description copied from interface: RawStoreFactory
Create an internal transaction.

Starting an internal transaction always performs the following steps.

  1. Create an raw store internal transaction context
  2. Create a new idle internal transaction and then link it to the context.

    AN internal transaction is identical to a user transaction with the exception that

    • Logical operations are not supported
    • Savepoints are not supported
    • Containers are not closed when commit() is called.
    • Pages are not unlatched (since containers are not closed) when commit() is called.
    • During recovery time internal transactions are rolled back before user transactions.
    Only one internal transaction can be active in a context at any one time. After a commit the transaction may be re-used.

    Raw Store Internal Transaction Context Behaviour
    The cleanupOnError() method of this context behaves as follows:

    • If error is an instance of StandardException that has a severity less than ExceptionSeverity.TRANSACTION_SEVERITY then the internal transaction is aborted, the internal transaction is closed, the context is popped off the stack, and an exception of severity Transaction exception is re-thrown.
    • If error is an instance of StandardException that has a severity greater than or equal to ExceptionSeverity.TRANSACTION_SEVERITY then the context's internal transaction is aborted, the internal transaction is closed and the context is popped off the stack.
    • If error is not an instance of StandardException then the context's internal transaction is aborted, the internal transaction is closed and the context is popped off the stack.

    Specified by:
    startInternalTransaction in interface RawStoreFactory
    Throws:
    StandardException - Standard Derby error policy
    See Also:
    Transaction, Context, StandardException

checkpoint

public void checkpoint()
                throws StandardException
Description copied from interface: RawStoreFactory
Checkpoint the database. The raw store will wait for any current checkpoints to complete. It will start a new checkpoint and not return until that checkpoint completes.

Specified by:
checkpoint in interface RawStoreFactory
Throws:
StandardException - Standard Derby error policy

startReplicationMaster

public void startReplicationMaster(java.lang.String dbmaster,
                                   java.lang.String host,
                                   int port,
                                   java.lang.String replicationMode)
                            throws StandardException
Start the replication master role for this database

Specified by:
startReplicationMaster in interface RawStoreFactory
Parameters:
dbmaster - The master database that is being replicated.
host - The hostname for the slave
port - The port the slave is listening on
replicationMode - The type of replication contract. Currently only asynchronous replication is supported, but 1-safe/2-safe/very-safe modes may be added later.
Throws:
StandardException - 1) If replication is started on a read-only database 2) If replication is started when unlogged operations are running 3) If an error occurs while trying to boot the master.

stopReplicationMaster

public void stopReplicationMaster()
                           throws StandardException
Stop the replication master role for this database.

Specified by:
stopReplicationMaster in interface RawStoreFactory
Throws:
StandardException - Standard Derby exception policy, thrown on error.

failover

public void failover(java.lang.String dbname)
              throws StandardException
Description copied from interface: RawStoreFactory
Start failover for this database.

Specified by:
failover in interface RawStoreFactory
Parameters:
dbname - the replication database that is being failed over.
Throws:
StandardException - Standard Derby exception policy, 1) If the failover succeeds, an exception is thrown to indicate that the master database was shutdown after a successful failover 2) If a failure occurs during network communication with slave.
See Also:
RawStoreFactory.failover(String dbname).

freeze

public void freeze()
            throws StandardException
Description copied from interface: RawStoreFactory
Freeze the database temporarily so a backup can be taken.

Please see Derby on line documentation on backup and restore.

Specified by:
freeze in interface RawStoreFactory
Throws:
StandardException - Thrown on error

unfreeze

public void unfreeze()
              throws StandardException
Description copied from interface: RawStoreFactory
Unfreeze the database after a backup has been taken.

Please see Derby on line documentation on backup and restore.

Specified by:
unfreeze in interface RawStoreFactory
Throws:
StandardException - Thrown on error

backup

public void backup(java.lang.String backupDir,
                   boolean wait)
            throws StandardException
Backup the database to a backup directory.

Specified by:
backup in interface RawStoreFactory
Parameters:
backupDir - the name of the directory where the backup should be stored. This directory will be created if it does not exist.
wait - if true, waits for all the backup blocking operations in progress to finish.
Throws:
StandardException - thrown on error

backup

public void backup(Transaction t,
                   java.io.File backupDir)
            throws StandardException
Throws:
StandardException

backupAndEnableLogArchiveMode

public void backupAndEnableLogArchiveMode(java.lang.String backupDir,
                                          boolean deleteOnlineArchivedLogFiles,
                                          boolean wait)
                                   throws StandardException
Backup the database to a backup directory and enable the log archive mode that will keep the archived log files required for roll-forward from this version backup.

Specified by:
backupAndEnableLogArchiveMode in interface RawStoreFactory
Parameters:
backupDir - the name of the directory where the backup should be stored. This directory will be created if it does not exist.
deleteOnlineArchivedLogFiles - If true deletes online archived log files that exist before this backup, delete will occur only after the backup is complete.
wait - if true, waits for all the backup blocking operations in progress to finish.
Throws:
StandardException - thrown on error.

disableLogArchiveMode

public void disableLogArchiveMode(boolean deleteOnlineArchivedLogFiles)
                           throws StandardException
Description copied from interface: RawStoreFactory
disables the log archival process, i.e No old log files will be kept around for a roll-forward recovery.

Specified by:
disableLogArchiveMode in interface RawStoreFactory
Parameters:
deleteOnlineArchivedLogFiles - If true deletes all online archived log files that exist before this call immediately; Only restore that can be performed after disabling log archive mode is version recovery.
Throws:
StandardException - Thrown on error

restoreRemainingFromBackup

private void restoreRemainingFromBackup(java.lang.String backupPath)
                                 throws StandardException
Throws:
StandardException

idle

public void idle()
          throws StandardException
Description copied from interface: RawStoreFactory
Idle the raw store as much as possible.

Specified by:
idle in interface RawStoreFactory
Throws:
StandardException - Standard Derby error policy

getTransactionInfo

public TransactionInfo[] getTransactionInfo()
Specified by:
getTransactionInfo in interface RawStoreFactory
See Also:
AccessFactory.getTransactionInfo()

openFlushedScan

public ScanHandle openFlushedScan(DatabaseInstant start,
                                  int groupsIWant)
                           throws StandardException
Description copied from interface: RawStoreFactory
Get a flushed scan.

Specified by:
openFlushedScan in interface RawStoreFactory
Parameters:
start - The instant for the beginning of the scan.
groupsIWant - log record groups the caller wants to scan.
Throws:
StandardException - StandardDerby error policy

getDaemon

public DaemonService getDaemon()
Description copied from interface: RawStoreFactory
If this raw store has a daemon that services its need, return the daemon. If not, return null

Specified by:
getDaemon in interface RawStoreFactory

createFinished

public void createFinished()
                    throws StandardException
Specified by:
createFinished in interface RawStoreFactory
Throws:
StandardException

getRawStoreProperties

public void getRawStoreProperties(PersistentSet set)
                           throws StandardException
Get JBMS properties relavent to raw store

Specified by:
getRawStoreProperties in interface RawStoreFactory
Throws:
StandardException - Standard Derby Error Policy

freezePersistentStore

public void freezePersistentStore()
                           throws StandardException
Freeze persistent store. Reads can still happen, only cannot write.

Specified by:
freezePersistentStore in interface RawStoreFactory
Throws:
StandardException - Standard Derby Error Policy

unfreezePersistentStore

public void unfreezePersistentStore()
                             throws StandardException
Freeze persistent store. Reads can still happen, only cannot write.

Specified by:
unfreezePersistentStore in interface RawStoreFactory
Throws:
StandardException - Standard Derby Error Policy

setupEncryptionEngines

private void setupEncryptionEngines(boolean create,
                                    java.util.Properties properties)
                             throws StandardException
Throws:
StandardException

encrypt

public int encrypt(byte[] cleartext,
                   int offset,
                   int length,
                   byte[] ciphertext,
                   int outputOffset,
                   boolean newEngine)
            throws StandardException
Encrypt cleartext into ciphertext.

Specified by:
encrypt in interface RawStoreFactory
Throws:
StandardException - Standard Derby Error Policy
See Also:
CipherProvider.encrypt(byte[], int, int, byte[], int)

decrypt

public int decrypt(byte[] ciphertext,
                   int offset,
                   int length,
                   byte[] cleartext,
                   int outputOffset)
            throws StandardException
Decrypt cleartext from ciphertext.

Specified by:
decrypt in interface RawStoreFactory
Throws:
StandardException - Standard Derby Error Policy
See Also:
CipherProvider.decrypt(byte[], int, int, byte[], int)

getEncryptionBlockSize

public int getEncryptionBlockSize()
Returns the encryption block size used by the algorithm at time of creation of an encrypted database

Specified by:
getEncryptionBlockSize in interface RawStoreFactory

random

public int random()
Description copied from interface: RawStoreFactory
Returns a secure random number for this raw store - if database is not encrypted, returns 0.

Specified by:
random in interface RawStoreFactory

changeBootPassword

public java.io.Serializable changeBootPassword(java.util.Properties properties,
                                               java.io.Serializable changePassword)
                                        throws StandardException
Description copied from interface: RawStoreFactory
Change the boot password. Return the encrypted form of the secret key. The new value must be a String of the form: oldBootPassword, newBootPassword

Specified by:
changeBootPassword in interface RawStoreFactory
Throws:
StandardException - Standard Derby Error Policy

crashOnDebugFlag

private void crashOnDebugFlag(java.lang.String debugFlag,
                              boolean reEncrypt)
                       throws StandardException
when the input debug flag is set, an expception is throw when run in the debug mode.

Throws:
StandardException

configureDatabaseForEncryption

public void configureDatabaseForEncryption(java.util.Properties properties,
                                           CipherFactory newCipherFactory)
                                    throws StandardException
Throws:
StandardException

handleIncompleteDatabaseEncryption

public void handleIncompleteDatabaseEncryption(java.util.Properties properties)
                                        throws StandardException
Engine might have crashed during encryption of un-encrypted datbase or while re-encryptin an already encrypted database with a new key after all the containers or (re) encrypted. If crash has occured before all containers are encrypted, recovery wil un-do re-encryption using the transaction log, nothing to be done here. If crash has occured after database encryption status flag (RawStoreFactory.DB_ENCRYPTION_STATUS) is set, this method will do any cleanup necessary for the recovery to correctly perform the rollback if required.

Parameters:
properties - properties related to this database.
Throws:
StandardException - Standard Derby Error Policy

canEncryptDatabase

private void canEncryptDatabase(boolean reEncrypt)
                         throws StandardException
checks if the database is in the right state to (re)encrypt it.

Parameters:
reEncrypt - true if the database getting encrypted with new password/key.
Throws:
StandardException - if there is global transaction in the prepared state or if the database is not at the version 10.2 or above, this feature is not supported or if the log is archived for the database.

markCorrupt

public StandardException markCorrupt(StandardException originalError)
Description copied from interface: Corruptable
Mark the module as corrupt. It is safe to call this multiple times.

Specified by:
markCorrupt in interface Corruptable
Returns:
Must always return its parameter.

getTransactionFactoryModule

public java.lang.String getTransactionFactoryModule()
Specified by:
getTransactionFactoryModule in interface RawStoreFactory

getSlaveFactoryModule

public java.lang.String getSlaveFactoryModule()

getMasterFactoryModule

public java.lang.String getMasterFactoryModule()

getDataFactoryModule

public java.lang.String getDataFactoryModule()
Specified by:
getDataFactoryModule in interface RawStoreFactory

getLogFactoryModule

public java.lang.String getLogFactoryModule()
Specified by:
getLogFactoryModule in interface RawStoreFactory

logHistory

private void logHistory(java.io.OutputStreamWriter historyFile,
                        java.lang.String msg)
                 throws java.io.IOException
Throws:
java.io.IOException

getFilePath

private java.lang.String getFilePath(StorageFile file)

getFilePath

private java.lang.String getFilePath(java.io.File file)

privCopyDirectory

protected boolean privCopyDirectory(StorageFile from,
                                    java.io.File to)

privCopyDirectory

protected boolean privCopyDirectory(java.io.File from,
                                    StorageFile to)

getMaxContainerId

public long getMaxContainerId()
                       throws StandardException
Return an id which can be used to create a container.

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.

Specified by:
getMaxContainerId in interface RawStoreFactory
Returns:
The an id which can be used to create a container.
Throws:
StandardException - Standard exception policy.

checkVersion

public boolean checkVersion(int requiredMajorVersion,
                            int requiredMinorVersion,
                            java.lang.String feature)
                     throws StandardException
Check to see if a database has been upgraded to the required level in order to use a store feature.

Specified by:
checkVersion in interface RawStoreFactory
Parameters:
requiredMajorVersion - required database Engine major version
requiredMinorVersion - required database Engine minor version
feature - Non-null to throw an exception, null to return the state of the version match.
Returns:
true if the database has been upgraded to the required level, false otherwise.
Throws:
StandardException - if the database is not at the require version when feature feature is not null .

privFileWriter

private java.io.OutputStreamWriter privFileWriter(StorageFile fileName,
                                                  boolean append)
                                           throws java.io.IOException
Throws:
java.io.IOException

privExists

private boolean privExists(java.io.File file)

privExists

private boolean privExists(StorageFile file)

privDelete

private boolean privDelete(java.io.File file)

privDelete

private boolean privDelete(StorageFile file)

privMkdirs

private boolean privMkdirs(java.io.File file)

privIsDirectory

private boolean privIsDirectory(java.io.File file)

privRemoveDirectory

private boolean privRemoveDirectory(java.io.File file)

privRenameTo

private boolean privRenameTo(java.io.File file1,
                             java.io.File file2)

privCopyDirectory

private boolean privCopyDirectory(StorageFile from,
                                  java.io.File to,
                                  byte[] buffer,
                                  java.lang.String[] filter,
                                  boolean copySubdirs)

privCopyDirectory

private boolean privCopyDirectory(java.io.File from,
                                  StorageFile to,
                                  byte[] buffer,
                                  java.lang.String[] filter)

privCopyFile

private boolean privCopyFile(java.io.File from,
                             StorageFile to)

privCopyFile

private boolean privCopyFile(StorageFile from,
                             java.io.File to)

privCopyFile

private boolean privCopyFile(StorageFile from,
                             StorageFile to)

privList

private java.lang.String[] privList(java.io.File file)

privList

private java.lang.String[] privList(StorageFile file)

privGetCanonicalPath

private java.lang.String privGetCanonicalPath(StorageFile file)

privGetCanonicalPath

private java.lang.String privGetCanonicalPath(java.io.File file)

run

public final java.lang.Object run()
                           throws java.io.IOException
Specified by:
run in interface java.security.PrivilegedExceptionAction
Throws:
java.io.IOException

Built on Thu 2010-12-23 20:49:13+0000, from revision ???

Apache Derby V10.6 Internals - Copyright © 2004,2007 The Apache Software Foundation. All Rights Reserved.