Class BasicDatabase
- All Implemented Interfaces:
Database
,Database
,LocaleFinder
,JarReader
,ModuleControl
,ModuleSupportable
,PropertySetCallback
- Direct Known Subclasses:
SlaveDatabase
The Database interface does not provide control over things that are part of the Domain, such as users.
I'm not sure what this will hold in a real system, for now it simply provides connection-creation for us. Perhaps when it boots, it creates the datadictionary object for the database, which all users will then interact with?
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected boolean
protected AccessFactory
private AuthenticationService
protected ClassFactory
private Locale
private DateFormat
private DataDictionary
DataDictionary for this database.protected boolean
protected LanguageConnectionFactory
protected LanguageFactory
private UUID
protected PropertyFactory
protected Object
private DateFormat
private DateFormat
Fields inherited from interface org.apache.derby.database.Database
LUCENE_DIR
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionapply
(String key, Serializable value, Dictionary p) Apply a property change.void
Backup the database to a backup directory.void
backupAndEnableLogArchiveMode
(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.private void
backupLucene
(String backupDir) Backup Lucene indexes to the backup directory.void
boot
(boolean create, Properties startParams) Boot this module with the given properties.protected AuthenticationService
bootAuthenticationService
(boolean create, Properties props) protected void
bootClassFactory
(boolean create, Properties startParams) protected void
bootResourceAdapter
(boolean create, Properties allParams) private static Object
bootServiceModule
(boolean create, Object serviceModule, String factoryInterface, Properties properties) Privileged startup.protected void
bootStore
(boolean create, Properties startParams) protected void
bootValidation
(boolean create, Properties startParams) boolean
canSupport
(Properties startParams) See if this implementation can support any attributes that are listed in properties.void
Checkpoints the database, that is, flushes all dirty data to disk.protected void
void
disableLogArchiveMode
(boolean deleteOnlineArchivedLogFiles) Disables the log archival process, i.e No old log files will be kept around for a roll-forward recovery.void
Start failover for the given database.private static Object
findServiceModule
(Object serviceModule, String factoryInterface) Privileged startup.void
freeze()
Freeze the database temporarily so a backup can be taken.protected Properties
Get the set of database properties from the set stored on disk outside of service.properties.This method returns the authentication service handle for the database.protected String
getClasspath
(Properties startParams) protected TransactionController
private static ContextService
Privileged lookup of the ContextService.final DataDictionary
Return the DataDictionary for this database, set up at boot time.Get a formatter for formatting dates.int
Return the engine type that this Database implementation supports.final UUID
getId()
Deprecated.getJarFile
(String schemaName, String sqlName) Get the StorageFile for an installed jar file.Get the Locale for this database.private StorageFile
Get the location of the Lucene indexesprivate static ModuleFactory
Privileged Monitor lookup.Get a Resource Adapter - only used by XA system.private StorageFactory
Get the database StorageFactory.Get a formatter for formatting times.Get a formatter for formatting timestamps.void
init
(boolean dbOnly, Dictionary p) Initialize the properties for this callback.boolean
isActive()
Is the database active (open).boolean
Used to indicated whether the database is in the replication slave mode.boolean
Tells whether the Database is configured as read-only, or the Database was started in read-only mode.private boolean
Return true if the Lucene plugin is loaded.protected UUID
makeDatabaseID
(boolean create, Properties startParams) map
(String key, Serializable value, Dictionary p) Map a proposed new value for a property to an official value.private static StandardException
noLocale()
protected void
void
Push a DbContext onto the provided context stack.void
Set the Locale that is returned by this LocaleFindersetupConnection
(ContextManager cm, String user, String drdaID, String dbname) Sets up a connection to the Database, owned by the given user.void
startReplicationMaster
(String dbmaster, String host, int port, String replicationMode) Start the replication master role for this databasevoid
stop()
Stop the module.void
Stop the replication master role for this database.void
Only a SlaveDatabase can be in replication slave mode.void
unfreeze()
Unfreeze the database after a backup has been taken.boolean
validate
(String key, Serializable value, Dictionary p) Validate a property change.
-
Field Details
-
active
protected boolean active -
authenticationService
-
af
-
pf
-
cfDB
-
dd
DataDictionary for this database. -
lcf
-
lf
-
resourceAdapter
-
databaseLocale
-
dateFormat
-
timeFormat
-
timestampFormat
-
myUUID
-
lastToBoot
protected boolean lastToBoot
-
-
Constructor Details
-
BasicDatabase
public BasicDatabase()
-
-
Method Details
-
canSupport
Description copied from interface:ModuleSupportable
See if this implementation can support any attributes that are listed in properties. This call may be made on a newly created instance before the boot() method has been called, or after the boot method has been called for a running module.The module can check for attributes in the properties to see if it can fulfill the required behaviour. E.g. the raw store may define an attribute called RawStore.Recoverable. If a temporary raw store is required the property RawStore.recoverable=false would be added to the properties before calling bootServiceModule. If a raw store cannot support this attribute its canSupport method would return null. Also see the Monitor class's prologue to see how the identifier is used in looking up properties.
Actually a better way maybe to have properties of the form RawStore.Attributes.mandatory=recoverable,smallfootprint and RawStore.Attributes.requested=oltp,fast- Specified by:
canSupport
in interfaceModuleSupportable
- Returns:
- true if this instance can be used, false otherwise.
-
boot
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 interfaceModuleControl
- Throws:
StandardException
- Module cannot be started.- See Also:
-
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 interfaceModuleControl
- See Also:
-
getEngineType
public int getEngineType()Return the engine type that this Database implementation supports. This implementation supports the standard database.- Specified by:
getEngineType
in interfaceDatabase
-
isReadOnly
public boolean isReadOnly()Description copied from interface:Database
Tells whether the Database is configured as read-only, or the Database was started in read-only mode.- Specified by:
isReadOnly
in interfaceDatabase
- Returns:
- TRUE means the Database is read-only, FALSE means it is not read-only.
-
setupConnection
public LanguageConnectionContext setupConnection(ContextManager cm, String user, String drdaID, String dbname) throws StandardException Description copied from interface:Database
Sets up a connection to the Database, owned by the given user. The JDBC version of getConnection takes a URL. The purpose of the URL is to tell the driver where the database system is. By the time we get here, we have found the database system (that's how we're making this method call), so the URL is not necessary to establish the connection here. The driver should remember the URL that was used to establish the connection, so it can implement the DatabaseMetaData.getURL() method.- Specified by:
setupConnection
in interfaceDatabase
- Parameters:
user
- The UserID of the user getting the connectiondrdaID
- The drda id of the connection (from network server)dbname
- The database name- Returns:
- A new LanguageConnectionContext
- Throws:
StandardException
- thrown if unable to create the connection.
-
getDataDictionary
Return the DataDictionary for this database, set up at boot time.- Specified by:
getDataDictionary
in interfaceDatabase
-
pushDbContext
Description copied from interface:Database
Push a DbContext onto the provided context stack. This conext will shut down the database in case of a DatabaseException being cleaned up.- Specified by:
pushDbContext
in interfaceDatabase
-
getAuthenticationService
Description copied from interface:Database
This method returns the authentication service handle for the database. NOTE: There is always a Authentication Service per database and at the system level.- Specified by:
getAuthenticationService
in interfaceDatabase
- Returns:
- The authentication service handle for the database
- Throws:
StandardException
- standard Derby exception policy
-
startReplicationMaster
public void startReplicationMaster(String dbmaster, String host, int port, String replicationMode) throws SQLException Start the replication master role for this database- Specified by:
startReplicationMaster
in interfaceDatabase
- Parameters:
dbmaster
- The master database that is being replicated.host
- The hostname for the slaveport
- The port the slave is listening onreplicationMode
- The type of replication contract. Currently only asynchronous replication is supported, but 1-safe/2-safe/very-safe modes may be added later.- Throws:
SQLException
- Thrown on error
-
stopReplicationMaster
Stop the replication master role for this database.- Specified by:
stopReplicationMaster
in interfaceDatabase
- Throws:
SQLException
- Thrown on error
-
stopReplicationSlave
Only a SlaveDatabase can be in replication slave mode. Always throws an exception- Specified by:
stopReplicationSlave
in interfaceDatabase
- Throws:
SQLException
- Always thrown because BasicDatabase cannot be in replication slave mode
-
isInSlaveMode
public boolean isInSlaveMode()Description copied from interface:Database
Used to indicated whether the database is in the replication slave mode.- Specified by:
isInSlaveMode
in interfaceDatabase
- Returns:
- true if this database is in replication slave mode, false otherwise.
-
failover
Description copied from interface:Database
Start failover for the given database.- Specified by:
failover
in interfaceDatabase
- Parameters:
dbname
- the replication database that is being failed over.- Throws:
StandardException
- 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:
-
freeze
Description copied from interface:Database
Freeze the database temporarily so a backup can be taken.Please see the Derby documentation on backup and restore.
- Specified by:
freeze
in interfaceDatabase
- Throws:
SQLException
- Thrown on error
-
unfreeze
Description copied from interface:Database
Unfreeze the database after a backup has been taken.Please see the Derby documentation on backup and restore.
- Specified by:
unfreeze
in interfaceDatabase
- Throws:
SQLException
- Thrown on error
-
backup
Description copied from interface:Database
Backup the database to a backup directory. See online documentation for more detail about how to use this feature.- Specified by:
backup
in interfaceDatabase
- Parameters:
backupDir
- the directory name where the database backup should go. This directory will be created if not it does not exist.wait
- if true, waits for all the backup blocking operations in progress to finish.- Throws:
SQLException
- Thrown on error
-
backupAndEnableLogArchiveMode
public void backupAndEnableLogArchiveMode(String backupDir, boolean deleteOnlineArchivedLogFiles, boolean wait) throws SQLException Description copied from interface:Database
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 interfaceDatabase
- Parameters:
backupDir
- The directory name where the database backup should go. This directory will be created if it does not exist.deleteOnlineArchivedLogFiles
- If true deletes online archived log files that exist before this backup; otherwise they will not be deleted. Deletion will occur only after backup is complete.wait
- if true, waits for all the backup blocking operations in progress to finish.- Throws:
SQLException
- Thrown on error
-
disableLogArchiveMode
Description copied from interface:Database
Disables the log archival process, i.e No old log files will be kept around for a roll-forward recovery. Only restore that can be performed after disabling log archive mode is version recovery.- Specified by:
disableLogArchiveMode
in interfaceDatabase
- Parameters:
deleteOnlineArchivedLogFiles
- If true deletes all online archived log files that exist before this call immediately; otherwise they will not be deleted.- Throws:
SQLException
- Thrown on error
-
checkpoint
Description copied from interface:Database
Checkpoints the database, that is, flushes all dirty data to disk. Records a checkpoint in the transaction log, if there is a log.- Specified by:
checkpoint
in interfaceDatabase
- Throws:
SQLException
- Thrown on error
-
getLocale
Description copied from interface:Database
Get the Locale for this database. -
getId
Deprecated.Return the UUID of this database. -
getCurrentLocale
- Specified by:
getCurrentLocale
in interfaceLocaleFinder
- Throws:
StandardException
- Thrown on error
-
getDateFormat
Description copied from interface:LocaleFinder
Get a formatter for formatting dates. The implementation may cache this value, since it never changes for a given Locale.- Specified by:
getDateFormat
in interfaceLocaleFinder
- Throws:
StandardException
- Thrown on error
-
getTimeFormat
Description copied from interface:LocaleFinder
Get a formatter for formatting times. The implementation may cache this value, since it never changes for a given Locale.- Specified by:
getTimeFormat
in interfaceLocaleFinder
- Throws:
StandardException
- Thrown on error
-
getTimestampFormat
Description copied from interface:LocaleFinder
Get a formatter for formatting timestamps. The implementation may cache this value, since it never changes for a given Locale.- Specified by:
getTimestampFormat
in interfaceLocaleFinder
- Throws:
StandardException
- Thrown on error
-
noLocale
-
setLocale
Description copied from interface:Database
Set the Locale that is returned by this LocaleFinder -
isActive
public boolean isActive()Is the database active (open). -
makeDatabaseID
- Throws:
StandardException
-
getResourceAdapter
Description copied from interface:Database
Get a Resource Adapter - only used by XA system. There is one and only one resource adapter per Derby database.- Specified by:
getResourceAdapter
in interfaceDatabase
- Returns:
- the resource Adapter for the database, null if no resource adapter is available for this database. Returned as an Object so that non-XA aggressive JVMs such as Chai don't get ClassNotFound. caller must cast result to ResourceAdapter.
-
init
Description copied from interface:PropertySetCallback
Initialize the properties for this callback. Called when addPropertySetNotification() is called with a non-null transaction controller. This allows code to set read its initial property values at boot time.Code within an init() method should use the 3 argument PropertyUtil method getPropertyFromSet() to obtain a property's value.
- Specified by:
init
in interfacePropertySetCallback
- Parameters:
dbOnly
- true if only per-database properties are to be looked atp
- the complete set of per-database properties.
-
validate
Description copied from interface:PropertySetCallback
Validate a property change.- Specified by:
validate
in interfacePropertySetCallback
- Parameters:
key
- Property key for the property being setvalue
- proposed new value for the property being set or null if the property is being dropped.p
- Property set before the change. SettingProperty may read but must never change p.- Returns:
- true if this object was interested in this property, false otherwise.
- Throws:
StandardException
- Thrown on error.- See Also:
-
apply
Description copied from interface:PropertySetCallback
Apply a property change. Will only be called after validate has been called and only if validate returned true. If this method is called then the new value is the value to be used, ie. the property is not set in the overriding JVM system set.- Specified by:
apply
in interfacePropertySetCallback
- Parameters:
key
- Property key for the property being setvalue
- proposed new value for the property being set or null if the property is being dropped.p
- Property set before the change. SettingProperty may read but must never change p.- Returns:
- post commit work for the property change.
- Throws:
StandardException
- Thrown on error.- See Also:
-
map
Description copied from interface:PropertySetCallback
Map a proposed new value for a property to an official value. Will only be called after apply() has been called.- Specified by:
map
in interfacePropertySetCallback
- Parameters:
key
- Property key for the property being setvalue
- proposed new value for the property being set or null if the property is being dropped.p
- Property set before the change. SettingProperty may read but must never change p.- Returns:
- new value for the change
- See Also:
-
createFinished
- Throws:
StandardException
-
getClasspath
-
bootClassFactory
- Throws:
StandardException
-
getConnectionTransaction
protected TransactionController getConnectionTransaction(ContextManager cm) throws StandardException - Throws:
StandardException
-
bootAuthenticationService
protected AuthenticationService bootAuthenticationService(boolean create, Properties props) throws StandardException - Throws:
StandardException
-
bootValidation
- Throws:
StandardException
-
bootStore
- Throws:
StandardException
-
getAllDatabaseProperties
Get the set of database properties from the set stored on disk outside of service.properties.- Throws:
StandardException
-
bootResourceAdapter
-
pushClassFactoryContext
-
getJarFile
Description copied from interface:JarReader
Get the StorageFile for an installed jar file.- Specified by:
getJarFile
in interfaceJarReader
- Throws:
StandardException
-
luceneLoaded
Return true if the Lucene plugin is loaded.
- Throws:
StandardException
-
getLuceneDir
Get the location of the Lucene indexes- Throws:
StandardException
-
getStorageFactory
Get the database StorageFactory.
- Throws:
StandardException
-
backupLucene
Backup Lucene indexes to the backup directory. This assumes that the rest of the database has been backup up and sanity checks have been run.
- Throws:
StandardException
-
getContextService
Privileged lookup of the ContextService. Must be private so that user code can't call this entry point. -
getMonitor
Privileged Monitor lookup. Must be private so that user code can't call this entry point. -
bootServiceModule
private static Object bootServiceModule(boolean create, Object serviceModule, String factoryInterface, Properties properties) throws StandardException Privileged startup. Must be private so that user code can't call this entry point.- Throws:
StandardException
-
findServiceModule
private static Object findServiceModule(Object serviceModule, String factoryInterface) throws StandardException Privileged startup. Must be private so that user code can't call this entry point.- Throws:
StandardException
-