Database
, Database
, LocaleFinder
, JarReader
, ModuleControl
, ModuleSupportable
, PropertySetCallback
SlaveDatabase
public class BasicDatabase extends java.lang.Object implements ModuleControl, ModuleSupportable, PropertySetCallback, Database, JarReader
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?
Modifier and Type | Field | Description |
---|---|---|
protected boolean |
active |
|
protected AccessFactory |
af |
|
private AuthenticationService |
authenticationService |
|
protected ClassFactory |
cfDB |
|
private java.util.Locale |
databaseLocale |
|
private java.text.DateFormat |
dateFormat |
|
private DataDictionary |
dd |
DataDictionary for this database.
|
protected boolean |
lastToBoot |
|
protected LanguageConnectionFactory |
lcf |
|
protected LanguageFactory |
lf |
|
private UUID |
myUUID |
|
protected PropertyFactory |
pf |
|
protected java.lang.Object |
resourceAdapter |
|
private java.text.DateFormat |
timeFormat |
|
private java.text.DateFormat |
timestampFormat |
LUCENE_DIR
Constructor | Description |
---|---|
BasicDatabase() |
Modifier and Type | Method | Description |
---|---|---|
Serviceable |
apply(java.lang.String key,
java.io.Serializable value,
java.util.Dictionary p) |
Apply a property change.
|
void |
backup(java.lang.String backupDir,
boolean wait) |
Backup the database to a backup directory.
|
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.
|
private void |
backupLucene(java.lang.String backupDir) |
Backup Lucene indexes to the backup directory.
|
void |
boot(boolean create,
java.util.Properties startParams) |
Boot this module with the given properties.
|
protected AuthenticationService |
bootAuthenticationService(boolean create,
java.util.Properties props) |
|
protected void |
bootClassFactory(boolean create,
java.util.Properties startParams) |
|
protected void |
bootResourceAdapter(boolean create,
java.util.Properties allParams) |
|
private static java.lang.Object |
bootServiceModule(boolean create,
java.lang.Object serviceModule,
java.lang.String factoryInterface,
java.util.Properties properties) |
Privileged startup.
|
protected void |
bootStore(boolean create,
java.util.Properties startParams) |
|
protected void |
bootValidation(boolean create,
java.util.Properties startParams) |
|
boolean |
canSupport(java.util.Properties startParams) |
See if this implementation can support any attributes that are listed in properties.
|
void |
checkpoint() |
Checkpoints the database, that is, flushes all dirty data to disk.
|
protected void |
createFinished() |
|
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 |
failover(java.lang.String dbname) |
Start failover for the given database.
|
private static java.lang.Object |
findServiceModule(java.lang.Object serviceModule,
java.lang.String factoryInterface) |
Privileged startup.
|
void |
freeze() |
Freeze the database temporarily so a backup can be taken.
|
protected java.util.Properties |
getAllDatabaseProperties() |
Get the set of database properties from the set stored
on disk outside of service.properties.
|
AuthenticationService |
getAuthenticationService() |
This method returns the authentication service handle for the
database.
|
protected java.lang.String |
getClasspath(java.util.Properties startParams) |
|
protected TransactionController |
getConnectionTransaction(ContextManager cm) |
|
private static ContextService |
getContextService() |
Privileged lookup of the ContextService.
|
java.util.Locale |
getCurrentLocale() |
|
DataDictionary |
getDataDictionary() |
Return the DataDictionary for this database, set up at boot time.
|
java.text.DateFormat |
getDateFormat() |
Get a formatter for formatting dates.
|
int |
getEngineType() |
Return the engine type that this Database implementation
supports.
|
UUID |
getId() |
Deprecated.
|
StorageFile |
getJarFile(java.lang.String schemaName,
java.lang.String sqlName) |
Get the StorageFile for an installed jar file.
|
java.util.Locale |
getLocale() |
Get the Locale for this database.
|
private StorageFile |
getLuceneDir() |
Get the location of the Lucene indexes
|
private static ModuleFactory |
getMonitor() |
Privileged Monitor lookup.
|
java.lang.Object |
getResourceAdapter() |
Get a Resource Adapter - only used by XA system.
|
private StorageFactory |
getStorageFactory() |
Get the database StorageFactory.
|
java.text.DateFormat |
getTimeFormat() |
Get a formatter for formatting times.
|
java.text.DateFormat |
getTimestampFormat() |
Get a formatter for formatting timestamps.
|
void |
init(boolean dbOnly,
java.util.Dictionary p) |
Initialize the properties for this callback.
|
boolean |
isActive() |
Is the database active (open).
|
boolean |
isInSlaveMode() |
Used to indicated whether the database is in the replication
slave mode.
|
boolean |
isReadOnly() |
Tells whether the Database is configured as read-only, or the
Database was started in read-only mode.
|
private boolean |
luceneLoaded() |
Return true if the Lucene plugin is loaded.
|
protected UUID |
makeDatabaseID(boolean create,
java.util.Properties startParams) |
|
java.io.Serializable |
map(java.lang.String key,
java.io.Serializable value,
java.util.Dictionary p) |
Map a proposed new value for a property to an official value.
|
private static StandardException |
noLocale() |
|
protected void |
pushClassFactoryContext(ContextManager cm,
ClassFactory cf) |
|
void |
pushDbContext(ContextManager cm) |
Push a DbContext onto the provided context stack.
|
void |
setLocale(java.util.Locale locale) |
Set the Locale that is returned by this LocaleFinder
|
LanguageConnectionContext |
setupConnection(ContextManager cm,
java.lang.String user,
java.lang.String drdaID,
java.lang.String dbname) |
Sets up a connection to the Database, owned by the given user.
|
void |
startReplicationMaster(java.lang.String dbmaster,
java.lang.String host,
int port,
java.lang.String replicationMode) |
Start the replication master role for this database
|
void |
stop() |
Stop the module.
|
void |
stopReplicationMaster() |
Stop the replication master role for this database.
|
void |
stopReplicationSlave() |
Only a SlaveDatabase can be in replication slave mode.
|
void |
unfreeze() |
Unfreeze the database after a backup has been taken.
|
boolean |
validate(java.lang.String key,
java.io.Serializable value,
java.util.Dictionary p) |
Validate a property change.
|
protected boolean active
private AuthenticationService authenticationService
protected AccessFactory af
protected PropertyFactory pf
protected ClassFactory cfDB
private DataDictionary dd
protected LanguageConnectionFactory lcf
protected LanguageFactory lf
protected java.lang.Object resourceAdapter
private java.util.Locale databaseLocale
private java.text.DateFormat dateFormat
private java.text.DateFormat timeFormat
private java.text.DateFormat timestampFormat
private UUID myUUID
protected boolean lastToBoot
public boolean canSupport(java.util.Properties startParams)
ModuleSupportable
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
canSupport
in interface ModuleSupportable
public void boot(boolean create, java.util.Properties startParams) throws StandardException
ModuleControl
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.
boot
in interface ModuleControl
StandardException
- Module cannot be started.Monitor
,
ModuleFactory
public void stop()
ModuleControl
stop
in interface ModuleControl
Monitor
,
ModuleFactory
public int getEngineType()
getEngineType
in interface Database
public boolean isReadOnly()
Database
isReadOnly
in interface Database
public LanguageConnectionContext setupConnection(ContextManager cm, java.lang.String user, java.lang.String drdaID, java.lang.String dbname) throws StandardException
Database
setupConnection
in interface Database
user
- The UserID of the user getting the connectiondrdaID
- The drda id of the connection (from network server)dbname
- The database nameStandardException
- thrown if unable to create the connection.public final DataDictionary getDataDictionary()
getDataDictionary
in interface Database
public void pushDbContext(ContextManager cm)
Database
pushDbContext
in interface Database
public AuthenticationService getAuthenticationService() throws StandardException
Database
getAuthenticationService
in interface Database
StandardException
- standard Derby exception policypublic void startReplicationMaster(java.lang.String dbmaster, java.lang.String host, int port, java.lang.String replicationMode) throws java.sql.SQLException
startReplicationMaster
in interface Database
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.java.sql.SQLException
- Thrown on errorpublic void stopReplicationMaster() throws java.sql.SQLException
stopReplicationMaster
in interface Database
java.sql.SQLException
- Thrown on errorpublic void stopReplicationSlave() throws java.sql.SQLException
stopReplicationSlave
in interface Database
java.sql.SQLException
- Always thrown because BasicDatabase cannot
be in replication slave modepublic boolean isInSlaveMode()
Database
isInSlaveMode
in interface Database
public void failover(java.lang.String dbname) throws StandardException
Database
failover
in interface Database
dbname
- the replication database that is being failed over.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.Database.failover(String)
public void freeze() throws java.sql.SQLException
Database
Please see the Derby documentation on backup and restore.
public void unfreeze() throws java.sql.SQLException
Database
Please see the Derby documentation on backup and restore.
public void backup(java.lang.String backupDir, boolean wait) throws java.sql.SQLException
Database
backup
in interface Database
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.java.sql.SQLException
- Thrown on errorpublic void backupAndEnableLogArchiveMode(java.lang.String backupDir, boolean deleteOnlineArchivedLogFiles, boolean wait) throws java.sql.SQLException
Database
backupAndEnableLogArchiveMode
in interface Database
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.java.sql.SQLException
- Thrown on errorpublic void disableLogArchiveMode(boolean deleteOnlineArchivedLogFiles) throws java.sql.SQLException
Database
disableLogArchiveMode
in interface Database
deleteOnlineArchivedLogFiles
- If true deletes all online archived
log files that exist before this
call immediately; otherwise they
will not be deleted.java.sql.SQLException
- Thrown on errorpublic void checkpoint() throws java.sql.SQLException
Database
checkpoint
in interface Database
java.sql.SQLException
- Thrown on errorpublic java.util.Locale getLocale()
Database
public final UUID getId()
public java.util.Locale getCurrentLocale() throws StandardException
getCurrentLocale
in interface LocaleFinder
StandardException
- Thrown on errorpublic java.text.DateFormat getDateFormat() throws StandardException
LocaleFinder
getDateFormat
in interface LocaleFinder
StandardException
- Thrown on errorpublic java.text.DateFormat getTimeFormat() throws StandardException
LocaleFinder
getTimeFormat
in interface LocaleFinder
StandardException
- Thrown on errorpublic java.text.DateFormat getTimestampFormat() throws StandardException
LocaleFinder
getTimestampFormat
in interface LocaleFinder
StandardException
- Thrown on errorprivate static StandardException noLocale()
public void setLocale(java.util.Locale locale)
Database
public boolean isActive()
protected UUID makeDatabaseID(boolean create, java.util.Properties startParams) throws StandardException
StandardException
public java.lang.Object getResourceAdapter()
Database
getResourceAdapter
in interface Database
public void init(boolean dbOnly, java.util.Dictionary p)
PropertySetCallback
Code within an init() method should use the 3 argument PropertyUtil method getPropertyFromSet() to obtain a property's value.
init
in interface PropertySetCallback
dbOnly
- true if only per-database properties are to be looked atp
- the complete set of per-database properties.public boolean validate(java.lang.String key, java.io.Serializable value, java.util.Dictionary p) throws StandardException
PropertySetCallback
validate
in interface PropertySetCallback
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.StandardException
- Thrown on error.PropertySetCallback.validate(java.lang.String, java.io.Serializable, java.util.Dictionary)
public Serviceable apply(java.lang.String key, java.io.Serializable value, java.util.Dictionary p) throws StandardException
PropertySetCallback
apply
in interface PropertySetCallback
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.StandardException
- Thrown on error.PropertySetCallback.apply(java.lang.String, java.io.Serializable, java.util.Dictionary)
public java.io.Serializable map(java.lang.String key, java.io.Serializable value, java.util.Dictionary p)
PropertySetCallback
map
in interface PropertySetCallback
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.PropertySetCallback.map(java.lang.String, java.io.Serializable, java.util.Dictionary)
protected void createFinished() throws StandardException
StandardException
protected java.lang.String getClasspath(java.util.Properties startParams)
protected void bootClassFactory(boolean create, java.util.Properties startParams) throws StandardException
StandardException
protected TransactionController getConnectionTransaction(ContextManager cm) throws StandardException
StandardException
protected AuthenticationService bootAuthenticationService(boolean create, java.util.Properties props) throws StandardException
StandardException
protected void bootValidation(boolean create, java.util.Properties startParams) throws StandardException
StandardException
protected void bootStore(boolean create, java.util.Properties startParams) throws StandardException
StandardException
protected java.util.Properties getAllDatabaseProperties() throws StandardException
StandardException
protected void bootResourceAdapter(boolean create, java.util.Properties allParams)
protected void pushClassFactoryContext(ContextManager cm, ClassFactory cf)
public StorageFile getJarFile(java.lang.String schemaName, java.lang.String sqlName) throws StandardException
JarReader
getJarFile
in interface JarReader
StandardException
private boolean luceneLoaded() throws StandardException
Return true if the Lucene plugin is loaded.
StandardException
private StorageFile getLuceneDir() throws StandardException
StandardException
private StorageFactory getStorageFactory() throws StandardException
Get the database StorageFactory.
StandardException
private void backupLucene(java.lang.String backupDir) throws StandardException
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.
StandardException
private static ContextService getContextService()
private static ModuleFactory getMonitor()
private static java.lang.Object bootServiceModule(boolean create, java.lang.Object serviceModule, java.lang.String factoryInterface, java.util.Properties properties) throws StandardException
StandardException
private static java.lang.Object findServiceModule(java.lang.Object serviceModule, java.lang.String factoryInterface) throws StandardException
StandardException
Apache Derby V10.14 Internals - Copyright © 2004,2018 The Apache Software Foundation. All Rights Reserved.