Package org.h2.engine
Class Database
- java.lang.Object
-
- org.h2.engine.Database
-
- All Implemented Interfaces:
CastDataProvider
,DataHandler
public final class Database extends java.lang.Object implements DataHandler, CastDataProvider
There is one database object per open database. The format of the meta data table is: id int, 0, objectType int, sql varchar- Since:
- 2004-04-15 22:49
-
-
Field Summary
Fields Modifier and Type Field Description private boolean
allowBuiltinAliasOverride
private int
allowLiterals
private static boolean
ASSERT
private Authenticator
authenticator
private boolean
autoServerMode
private int
autoServerPort
private java.util.concurrent.atomic.AtomicReference<DbException>
backgroundException
private java.lang.String
cacheType
private java.lang.String
cipher
private int
closeDelay
private boolean
closing
private java.lang.String
cluster
private java.util.concurrent.ConcurrentHashMap<java.lang.String,Comment>
comments
private int
compactMode
private CompareMode
compareMode
private SourceCompiler
compiler
private java.lang.String
databaseName
private java.lang.String
databaseShortName
private java.lang.String
databaseURL
private DbSettings
dbSettings
private DefaultNullOrdering
defaultNullOrdering
private int
defaultTableType
private DelayedDatabaseCloser
delayedCloser
private boolean
deleteFilesOnDisconnect
private static SessionLocal[]
EMPTY_SESSION_ARRAY
private DatabaseEventListener
eventListener
private java.util.concurrent.atomic.AtomicReference<SessionLocal>
exclusiveSession
private byte[]
fileEncryptionKey
private FileLockMethod
fileLockMethod
private byte[]
filePasswordHash
private boolean
ignoreCase
private boolean
ignoreCatalogs
private Schema
infoSchema
private static int
initialPowerOffCount
private JavaObjectSerializer
javaObjectSerializer
private boolean
javaObjectSerializerInitialized
private java.lang.String
javaObjectSerializerName
private java.util.HashMap<TableLinkConnection,TableLinkConnection>
linkConnections
private SmallLRUCache<java.lang.String,java.lang.String[]>
lobFileListCache
private SessionLocal
lobSession
private LobStorageInterface
lobStorage
private java.lang.Object
lobSyncObject
private FileLock
lock
private int
lockMode
private Schema
mainSchema
private int
maxLengthInplaceLob
private int
maxMemoryRows
private int
maxOperationMemory
private Table
meta
private static java.lang.ThreadLocal<SessionLocal>
META_LOCK_DEBUGGING
private static java.lang.ThreadLocal<Database>
META_LOCK_DEBUGGING_DB
private static java.lang.ThreadLocal<java.lang.Throwable>
META_LOCK_DEBUGGING_STACK
private Index
metaIdIndex
private Mode
mode
private java.util.concurrent.atomic.AtomicLong
modificationDataId
private java.util.concurrent.atomic.AtomicLong
modificationMetaId
private int
nextSessionId
private int
nextTempTableId
private java.util.BitSet
objectIds
private boolean
optimizeReuseResults
private int
pageSize
private boolean
persistent
private Schema
pgCatalogSchema
private int
powerOffCount
private Role
publicRole
private boolean
queryStatistics
private QueryStatisticsData
queryStatisticsData
private int
queryStatisticsMaxEntries
private boolean
readOnly
private boolean
referentialIntegrity
private java.util.concurrent.atomic.AtomicLong
remoteSettingsId
Used to trigger the client side to reload some of the settings.private java.util.concurrent.ConcurrentHashMap<java.lang.String,Right>
rights
private RowFactory
rowFactory
private java.util.concurrent.ConcurrentHashMap<java.lang.String,Schema>
schemas
private Server
server
private java.util.concurrent.ConcurrentHashMap<java.lang.String,Setting>
settings
private boolean
starting
private Store
store
private static java.lang.String
SYSTEM_USER_NAME
The default name of the system user.private SessionLocal
systemSession
private User
systemUser
private java.util.HashMap<java.lang.String,TableEngine>
tableEngines
private TempFileDeleter
tempFileDeleter
private Trace
trace
private TraceSystem
traceSystem
private java.util.concurrent.ConcurrentHashMap<java.lang.String,RightOwner>
usersAndRoles
private java.util.Set<SessionLocal>
userSessions
-
Constructor Summary
Constructors Constructor Description Database(ConnectionInfo ci, java.lang.String cipher)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addDatabaseObject(SessionLocal session, DbObject obj)
Add an object to the database.private void
addMeta(SessionLocal session, DbObject obj)
void
addSchemaObject(SessionLocal session, SchemaObject obj)
Add a schema object to the database.int
allocateObjectId()
Allocate a new object id.private void
checkMetaFree(SessionLocal session, int id)
void
checkpoint()
Flush all changes and open a new transaction log.void
checkPowerOff()
Check if the simulated power failure occurred.private void
checkPowerOff2()
void
checkWritingAllowed()
Check if writing is allowed.(package private) void
close(boolean fromShutdownHook)
Close the database.private void
closeAllSessionsExcept(SessionLocal except)
private void
closeFiles()
private void
closeImpl(boolean fromShutdownHook)
private void
closeOpenFilesAndUnlock()
Close all open files and unlock the database.private SessionLocal
createSession(User user)
(package private) SessionLocal
createSession(User user, NetworkConnectionInfo networkConnectionInfo)
Create a session for the given user.private CreateTableData
createSysTableData()
ValueTimestampTimeZone
currentTimestamp()
Returns the current timestamp with maximum resolution.TimeZoneProvider
currentTimeZone()
Returns the current time zone.private void
deleteOldTempFiles()
boolean
equalsIdentifiers(java.lang.String a, java.lang.String b)
Compare two identifiers (table names, column names,...) and verify they are equal.void
exceptionThrown(java.sql.SQLException e, java.lang.String sql)
This method is called after an exception occurred, to inform the database event listener (if one is set).private void
executeMeta()
private void
executeMeta(java.util.ArrayList<MetaRecord> records)
Comment
findComment(DbObject object)
Get the comment for the given database object if one exists, or null if not.Role
findRole(java.lang.String roleName)
Get the role if it exists, or null if not.Schema
findSchema(java.lang.String schemaName)
Get the schema if it exists, or null if not.Setting
findSetting(java.lang.String name)
Get the setting if it exists, or null if not.User
findUser(java.lang.String name)
Get the user if it exists, or null if not.RightOwner
findUserOrRole(java.lang.String name)
Get the user or role if it exists, ornull
if not.void
flush()
Flush all pending changes to the transaction log.java.util.ArrayList<Comment>
getAllComments()
int
getAllowLiterals()
java.util.ArrayList<Right>
getAllRights()
java.util.Collection<Schema>
getAllSchemas()
java.util.Collection<Schema>
getAllSchemasNoMeta()
java.util.Collection<Setting>
getAllSettings()
java.util.ArrayList<TableSynonym>
getAllSynonyms()
Get all synonyms.java.util.ArrayList<Table>
getAllTablesAndViews()
Get all tables and views.java.util.Collection<RightOwner>
getAllUsersAndRoles()
Authenticator
getAuthenticator()
get authenticator for database usersjava.lang.Throwable
getBackgroundException()
java.lang.String
getCacheType()
java.lang.String
getCluster()
CompareMode
getCompareMode()
Return compare mode.SourceCompiler
getCompiler()
java.lang.String
getDatabasePath()
Get the database path.DefaultNullOrdering
getDefaultNullOrdering()
int
getDefaultTableType()
Table
getDependentTable(SchemaObject obj, Table except)
Get the first table that depends on this object.SessionLocal
getExclusiveSession()
byte[]
getFileEncryptionKey()
Table
getFirstUserTable()
Get the first user defined table, excluding the LOB_BLOCKS table that the Recover tool creates.boolean
getIgnoreCase()
boolean
getIgnoreCatalogs()
java.util.ArrayList<InDoubtTransaction>
getInDoubtTransactions()
Get the list of in-doubt transactions.JavaObjectSerializer
getJavaObjectSerializer()
Returns the custom Java object serializer, ornull
.TableLinkConnection
getLinkConnection(java.lang.String driver, java.lang.String url, java.lang.String user, java.lang.String password)
Open a new connection or get an existing connection to another database.SmallLRUCache<java.lang.String,java.lang.String[]>
getLobFileListCache()
Get the lob file list cache if it is used.SessionLocal
getLobSession()
LobStorageInterface
getLobStorage()
Get the lob storage mechanism to use.java.lang.Object
getLobSyncObject()
Get the synchronization object for lob operations.int
getLockMode()
int
getLockTimeout()
Schema
getMainSchema()
Returns main schema (usually PUBLIC).private java.util.Map<java.lang.String,DbObject>
getMap(int type)
int
getMaxLengthInplaceLob()
Get the maximum length of a in-place large objectint
getMaxMemoryRows()
int
getMaxOperationMemory()
Mode
getMode()
Returns the database mode.long
getModificationDataId()
long
getModificationMetaId()
java.lang.String
getName()
long
getNextModificationDataId()
long
getNextModificationMetaId()
long
getNextRemoteSettingsId()
boolean
getOptimizeReuseResults()
int
getPageSize()
int
getPowerOffCount()
Role
getPublicRole()
boolean
getQueryStatistics()
QueryStatisticsData
getQueryStatisticsData()
boolean
getReferentialIntegrity()
long
getRemoteSettingsId()
int
getRetentionTime()
RowFactory
getRowFactory()
Schema
getSchema(java.lang.String schemaName)
Get the schema.int
getSessionCount()
SessionLocal[]
getSessions(boolean includingSystemSession)
Get all sessions that are currently connected to the database.DbSettings
getSettings()
java.lang.String
getShortName()
Store
getStore()
SessionLocal
getSystemSession()
User
getSystemUser()
Returns system user.TableEngine
getTableEngine(java.lang.String tableEngine)
Get the table engine class, loading it if needed.TempFileDeleter
getTempFileDeleter()
Get the temp file deleter mechanism.java.lang.String
getTempTableName(java.lang.String baseName, SessionLocal session)
Get a unique temporary table name.Trace
getTrace(int moduleId)
Get the trace object for the given module id.TraceSystem
getTraceSystem()
User
getUser(java.lang.String name)
Get user with the given name.private void
initJavaObjectSerializer()
boolean
isAllowBuiltinAliasOverride()
boolean
isClosing()
Check if the database is in the process of closing.boolean
isPersistent()
Check if this database is disk-based.boolean
isReadOnly()
boolean
isStarting()
Check if the database is currently opening.boolean
isSysTableLocked()
Checks if the system table (containing the catalog) is locked.boolean
isSysTableLockedBy(SessionLocal session)
Checks if the system table (containing the catalog) is locked by the given session.private static boolean
isUpperSysIdentifier(java.lang.String upperName)
(package private) boolean
isUserSession(SessionLocal session)
boolean
lockMeta(SessionLocal session)
Lock the metadata table for updates.private void
lockMetaAssertion(SessionLocal session)
<V> java.util.concurrent.ConcurrentHashMap<java.lang.String,V>
newConcurrentStringMap()
Create a new hash map.<V> java.util.HashMap<java.lang.String,V>
newStringMap()
Create a new hash map.<V> java.util.HashMap<java.lang.String,V>
newStringMap(int initialCapacity)
Create a new hash map.(package private) void
opened()
Called after the database has been opened and initialized.FileStore
openFile(java.lang.String name, java.lang.String openMode, boolean mustExist)
Open a file at the given location.private java.lang.String
parseDatabaseShortName()
(package private) void
prepareCommit(SessionLocal session, java.lang.String transaction)
Prepare a transaction.int
readLob(long lobId, byte[] hmac, long offset, byte[] buff, int off, int length)
Read from a lob.private void
recompileInvalidViews()
void
releaseDatabaseObjectIds(java.util.BitSet idsToRelease)
Mark some database ids as unused.void
removeDatabaseObject(SessionLocal session, DbObject obj)
Remove the object from the database.void
removeMeta(SessionLocal session, int id)
Remove the given object from the meta data.private void
removeOrphanedLobs()
void
removeSchemaObject(SessionLocal session, SchemaObject obj)
Remove an object from the system table.void
removeSession(SessionLocal session)
Remove a session.void
renameDatabaseObject(SessionLocal session, DbObject obj, java.lang.String newName)
Rename a database object.void
renameSchemaObject(SessionLocal session, SchemaObject obj, java.lang.String newName)
Rename a schema object.void
setAllowBuiltinAliasOverride(boolean b)
void
setAllowLiterals(int value)
void
setAuthenticator(Authenticator authenticator)
Set current database authenticatorvoid
setBackgroundException(DbException e)
void
setCacheSize(int kb)
void
setCloseDelay(int value)
void
setCluster(java.lang.String cluster)
void
setCompactMode(int compactMode)
void
setCompareMode(CompareMode compareMode)
void
setDefaultNullOrdering(DefaultNullOrdering defaultNullOrdering)
void
setDefaultTableType(int defaultTableType)
void
setDeleteFilesOnDisconnect(boolean b)
void
setEventListener(DatabaseEventListener eventListener)
void
setEventListenerClass(java.lang.String className)
boolean
setExclusiveSession(SessionLocal session, boolean closeOthers)
Set the session that can exclusively access the database.void
setIgnoreCase(boolean b)
void
setIgnoreCatalogs(boolean b)
static void
setInitialPowerOffCount(int count)
void
setJavaObjectSerializerName(java.lang.String serializerName)
void
setLockMode(int lockMode)
void
setMasterUser(User user)
void
setMaxLengthInplaceLob(int value)
void
setMaxMemoryRows(int value)
void
setMaxOperationMemory(int maxOperationMemory)
void
setMode(Mode mode)
void
setOptimizeReuseResults(boolean b)
void
setPowerOffCount(int count)
void
setProgress(int state, java.lang.String name, long x, long max)
Set the progress of a long running operation.void
setQueryStatistics(boolean b)
void
setQueryStatisticsMaxEntries(int n)
void
setReadOnly(boolean readOnly)
Switch the database to read-only mode.void
setReferentialIntegrity(boolean b)
void
setRetentionTime(int value)
void
setRowFactory(RowFactory rowFactory)
void
setWriteDelay(int value)
void
shutdownImmediately()
Immediately close the database.private void
startServer(java.lang.String key)
private void
stopServer()
void
sync()
Synchronize the files with the file system.java.lang.String
sysIdentifier(java.lang.String upperName)
Returns identifier in upper or lower case depending on database settings.(package private) void
throwLastBackgroundException()
If there is a background store thread, and if there wasn an exception in that thread, throw it now.java.lang.String
toString()
void
unlockMeta(SessionLocal session)
Unlock the metadata table.(package private) static void
unlockMetaDebug(SessionLocal session)
This method doesn't actually unlock the metadata table, all it does it reset the debugging flags.boolean
unsetExclusiveSession(SessionLocal session)
Stop exclusive access the database by provided session.void
updateMeta(SessionLocal session, DbObject obj)
Update an object in the system table.private void
updateMetaAndFirstLevelChildren(SessionLocal session, DbObject obj)
(package private) boolean
validateFilePasswordHash(java.lang.String testCipher, byte[] testHash)
Check if the file password hash is correct.void
verifyMetaLocked(SessionLocal session)
Verify the meta table is locked.boolean
zeroBasedEnums()
Returns are ENUM values 0-based.
-
-
-
Field Detail
-
initialPowerOffCount
private static int initialPowerOffCount
-
ASSERT
private static final boolean ASSERT
-
META_LOCK_DEBUGGING
private static final java.lang.ThreadLocal<SessionLocal> META_LOCK_DEBUGGING
-
META_LOCK_DEBUGGING_DB
private static final java.lang.ThreadLocal<Database> META_LOCK_DEBUGGING_DB
-
META_LOCK_DEBUGGING_STACK
private static final java.lang.ThreadLocal<java.lang.Throwable> META_LOCK_DEBUGGING_STACK
-
EMPTY_SESSION_ARRAY
private static final SessionLocal[] EMPTY_SESSION_ARRAY
-
SYSTEM_USER_NAME
private static final java.lang.String SYSTEM_USER_NAME
The default name of the system user. This name is only used as long as there is no administrator user registered.- See Also:
- Constant Field Values
-
persistent
private final boolean persistent
-
databaseName
private final java.lang.String databaseName
-
databaseShortName
private final java.lang.String databaseShortName
-
databaseURL
private final java.lang.String databaseURL
-
cipher
private final java.lang.String cipher
-
filePasswordHash
private final byte[] filePasswordHash
-
fileEncryptionKey
private final byte[] fileEncryptionKey
-
usersAndRoles
private final java.util.concurrent.ConcurrentHashMap<java.lang.String,RightOwner> usersAndRoles
-
settings
private final java.util.concurrent.ConcurrentHashMap<java.lang.String,Setting> settings
-
schemas
private final java.util.concurrent.ConcurrentHashMap<java.lang.String,Schema> schemas
-
rights
private final java.util.concurrent.ConcurrentHashMap<java.lang.String,Right> rights
-
comments
private final java.util.concurrent.ConcurrentHashMap<java.lang.String,Comment> comments
-
tableEngines
private final java.util.HashMap<java.lang.String,TableEngine> tableEngines
-
userSessions
private final java.util.Set<SessionLocal> userSessions
-
exclusiveSession
private final java.util.concurrent.atomic.AtomicReference<SessionLocal> exclusiveSession
-
objectIds
private final java.util.BitSet objectIds
-
lobSyncObject
private final java.lang.Object lobSyncObject
-
mainSchema
private final Schema mainSchema
-
infoSchema
private final Schema infoSchema
-
pgCatalogSchema
private final Schema pgCatalogSchema
-
nextSessionId
private int nextSessionId
-
nextTempTableId
private int nextTempTableId
-
systemUser
private final User systemUser
-
systemSession
private SessionLocal systemSession
-
lobSession
private SessionLocal lobSession
-
meta
private final Table meta
-
metaIdIndex
private final Index metaIdIndex
-
lock
private FileLock lock
-
starting
private volatile boolean starting
-
traceSystem
private final TraceSystem traceSystem
-
trace
private final Trace trace
-
fileLockMethod
private final FileLockMethod fileLockMethod
-
publicRole
private final Role publicRole
-
modificationDataId
private final java.util.concurrent.atomic.AtomicLong modificationDataId
-
modificationMetaId
private final java.util.concurrent.atomic.AtomicLong modificationMetaId
-
remoteSettingsId
private final java.util.concurrent.atomic.AtomicLong remoteSettingsId
Used to trigger the client side to reload some of the settings.
-
compareMode
private CompareMode compareMode
-
cluster
private java.lang.String cluster
-
readOnly
private boolean readOnly
-
eventListener
private DatabaseEventListener eventListener
-
maxMemoryRows
private int maxMemoryRows
-
lockMode
private int lockMode
-
maxLengthInplaceLob
private int maxLengthInplaceLob
-
allowLiterals
private int allowLiterals
-
powerOffCount
private int powerOffCount
-
closeDelay
private volatile int closeDelay
-
delayedCloser
private DelayedDatabaseCloser delayedCloser
-
closing
private volatile boolean closing
-
ignoreCase
private boolean ignoreCase
-
deleteFilesOnDisconnect
private boolean deleteFilesOnDisconnect
-
optimizeReuseResults
private boolean optimizeReuseResults
-
cacheType
private final java.lang.String cacheType
-
referentialIntegrity
private boolean referentialIntegrity
-
mode
private Mode mode
-
defaultNullOrdering
private DefaultNullOrdering defaultNullOrdering
-
maxOperationMemory
private int maxOperationMemory
-
lobFileListCache
private SmallLRUCache<java.lang.String,java.lang.String[]> lobFileListCache
-
autoServerMode
private final boolean autoServerMode
-
autoServerPort
private final int autoServerPort
-
server
private Server server
-
linkConnections
private java.util.HashMap<TableLinkConnection,TableLinkConnection> linkConnections
-
tempFileDeleter
private final TempFileDeleter tempFileDeleter
-
compactMode
private int compactMode
-
compiler
private SourceCompiler compiler
-
lobStorage
private final LobStorageInterface lobStorage
-
pageSize
private final int pageSize
-
defaultTableType
private int defaultTableType
-
dbSettings
private final DbSettings dbSettings
-
store
private final Store store
-
allowBuiltinAliasOverride
private boolean allowBuiltinAliasOverride
-
backgroundException
private final java.util.concurrent.atomic.AtomicReference<DbException> backgroundException
-
javaObjectSerializer
private JavaObjectSerializer javaObjectSerializer
-
javaObjectSerializerName
private java.lang.String javaObjectSerializerName
-
javaObjectSerializerInitialized
private volatile boolean javaObjectSerializerInitialized
-
queryStatistics
private boolean queryStatistics
-
queryStatisticsMaxEntries
private int queryStatisticsMaxEntries
-
queryStatisticsData
private QueryStatisticsData queryStatisticsData
-
rowFactory
private RowFactory rowFactory
-
ignoreCatalogs
private boolean ignoreCatalogs
-
authenticator
private Authenticator authenticator
-
-
Constructor Detail
-
Database
public Database(ConnectionInfo ci, java.lang.String cipher)
-
-
Method Detail
-
getLockTimeout
public int getLockTimeout()
-
getRowFactory
public RowFactory getRowFactory()
-
setRowFactory
public void setRowFactory(RowFactory rowFactory)
-
setInitialPowerOffCount
public static void setInitialPowerOffCount(int count)
-
setPowerOffCount
public void setPowerOffCount(int count)
-
getStore
public Store getStore()
-
getModificationDataId
public long getModificationDataId()
-
getNextModificationDataId
public long getNextModificationDataId()
-
getModificationMetaId
public long getModificationMetaId()
-
getNextModificationMetaId
public long getNextModificationMetaId()
-
getRemoteSettingsId
public long getRemoteSettingsId()
-
getNextRemoteSettingsId
public long getNextRemoteSettingsId()
-
getPowerOffCount
public int getPowerOffCount()
-
checkPowerOff
public void checkPowerOff()
Description copied from interface:DataHandler
Check if the simulated power failure occurred. This call will decrement the countdown.- Specified by:
checkPowerOff
in interfaceDataHandler
-
checkPowerOff2
private void checkPowerOff2()
-
getTrace
public Trace getTrace(int moduleId)
Get the trace object for the given module id.- Parameters:
moduleId
- the module id- Returns:
- the trace object
-
openFile
public FileStore openFile(java.lang.String name, java.lang.String openMode, boolean mustExist)
Description copied from interface:DataHandler
Open a file at the given location.- Specified by:
openFile
in interfaceDataHandler
- Parameters:
name
- the file nameopenMode
- the modemustExist
- whether the file must already exist- Returns:
- the file
-
validateFilePasswordHash
boolean validateFilePasswordHash(java.lang.String testCipher, byte[] testHash)
Check if the file password hash is correct.- Parameters:
testCipher
- the cipher algorithmtestHash
- the hash code- Returns:
- true if the cipher algorithm and the password match
-
parseDatabaseShortName
private java.lang.String parseDatabaseShortName()
-
createSysTableData
private CreateTableData createSysTableData()
-
executeMeta
private void executeMeta()
-
executeMeta
private void executeMeta(java.util.ArrayList<MetaRecord> records)
-
startServer
private void startServer(java.lang.String key)
-
stopServer
private void stopServer()
-
recompileInvalidViews
private void recompileInvalidViews()
-
addMeta
private void addMeta(SessionLocal session, DbObject obj)
-
verifyMetaLocked
public void verifyMetaLocked(SessionLocal session)
Verify the meta table is locked.- Parameters:
session
- the session
-
lockMeta
public boolean lockMeta(SessionLocal session)
Lock the metadata table for updates.- Parameters:
session
- the session- Returns:
- whether it was already locked before by this session
-
lockMetaAssertion
private void lockMetaAssertion(SessionLocal session)
-
unlockMeta
public void unlockMeta(SessionLocal session)
Unlock the metadata table.- Parameters:
session
- the session
-
unlockMetaDebug
static void unlockMetaDebug(SessionLocal session)
This method doesn't actually unlock the metadata table, all it does it reset the debugging flags.- Parameters:
session
- the session
-
removeMeta
public void removeMeta(SessionLocal session, int id)
Remove the given object from the meta data.- Parameters:
session
- the sessionid
- the id of the object to remove
-
releaseDatabaseObjectIds
public void releaseDatabaseObjectIds(java.util.BitSet idsToRelease)
Mark some database ids as unused.- Parameters:
idsToRelease
- the ids to release
-
getMap
private java.util.Map<java.lang.String,DbObject> getMap(int type)
-
addSchemaObject
public void addSchemaObject(SessionLocal session, SchemaObject obj)
Add a schema object to the database.- Parameters:
session
- the sessionobj
- the object to add
-
addDatabaseObject
public void addDatabaseObject(SessionLocal session, DbObject obj)
Add an object to the database.- Parameters:
session
- the sessionobj
- the object to add
-
findComment
public Comment findComment(DbObject object)
Get the comment for the given database object if one exists, or null if not.- Parameters:
object
- the database object- Returns:
- the comment or null
-
findRole
public Role findRole(java.lang.String roleName)
Get the role if it exists, or null if not.- Parameters:
roleName
- the name of the role- Returns:
- the role or null
-
findSchema
public Schema findSchema(java.lang.String schemaName)
Get the schema if it exists, or null if not.- Parameters:
schemaName
- the name of the schema- Returns:
- the schema or null
-
findSetting
public Setting findSetting(java.lang.String name)
Get the setting if it exists, or null if not.- Parameters:
name
- the name of the setting- Returns:
- the setting or null
-
findUser
public User findUser(java.lang.String name)
Get the user if it exists, or null if not.- Parameters:
name
- the name of the user- Returns:
- the user or null
-
getUser
public User getUser(java.lang.String name)
Get user with the given name. This method throws an exception if the user does not exist.- Parameters:
name
- the user name- Returns:
- the user
- Throws:
DbException
- if the user does not exist
-
findUserOrRole
public RightOwner findUserOrRole(java.lang.String name)
Get the user or role if it exists, ornull
if not.- Parameters:
name
- the name of the user or role- Returns:
- the user, the role, or
null
-
createSession
SessionLocal createSession(User user, NetworkConnectionInfo networkConnectionInfo)
Create a session for the given user.- Parameters:
user
- the usernetworkConnectionInfo
- the network connection information, ornull
- Returns:
- the session, or null if the database is currently closing
- Throws:
DbException
- if the database is in exclusive mode
-
createSession
private SessionLocal createSession(User user)
-
removeSession
public void removeSession(SessionLocal session)
Remove a session. This method is called after the user has disconnected.- Parameters:
session
- the session
-
isUserSession
boolean isUserSession(SessionLocal session)
-
closeAllSessionsExcept
private void closeAllSessionsExcept(SessionLocal except)
-
close
void close(boolean fromShutdownHook)
Close the database.- Parameters:
fromShutdownHook
- true if this method is called from the shutdown hook
-
closeImpl
private void closeImpl(boolean fromShutdownHook)
-
removeOrphanedLobs
private void removeOrphanedLobs()
-
closeOpenFilesAndUnlock
private void closeOpenFilesAndUnlock()
Close all open files and unlock the database.
-
closeFiles
private void closeFiles()
-
checkMetaFree
private void checkMetaFree(SessionLocal session, int id)
-
allocateObjectId
public int allocateObjectId()
Allocate a new object id.- Returns:
- the id
-
getSystemUser
public User getSystemUser()
Returns system user.- Returns:
- system user
-
getMainSchema
public Schema getMainSchema()
Returns main schema (usually PUBLIC).- Returns:
- main schema (usually PUBLIC)
-
getAllComments
public java.util.ArrayList<Comment> getAllComments()
-
getAllowLiterals
public int getAllowLiterals()
-
getAllRights
public java.util.ArrayList<Right> getAllRights()
-
getAllTablesAndViews
public java.util.ArrayList<Table> getAllTablesAndViews()
Get all tables and views. Meta data tables may be excluded.- Returns:
- all objects of that type
-
getAllSynonyms
public java.util.ArrayList<TableSynonym> getAllSynonyms()
Get all synonyms.- Returns:
- all objects of that type
-
getAllSchemas
public java.util.Collection<Schema> getAllSchemas()
-
getAllSchemasNoMeta
public java.util.Collection<Schema> getAllSchemasNoMeta()
-
getAllSettings
public java.util.Collection<Setting> getAllSettings()
-
getAllUsersAndRoles
public java.util.Collection<RightOwner> getAllUsersAndRoles()
-
getCacheType
public java.lang.String getCacheType()
-
getCluster
public java.lang.String getCluster()
-
getCompareMode
public CompareMode getCompareMode()
Description copied from interface:DataHandler
Return compare mode.- Specified by:
getCompareMode
in interfaceDataHandler
- Returns:
- Compare mode.
-
getDatabasePath
public java.lang.String getDatabasePath()
Description copied from interface:DataHandler
Get the database path.- Specified by:
getDatabasePath
in interfaceDataHandler
- Returns:
- the database path
-
getShortName
public java.lang.String getShortName()
-
getName
public java.lang.String getName()
-
getSessions
public SessionLocal[] getSessions(boolean includingSystemSession)
Get all sessions that are currently connected to the database.- Parameters:
includingSystemSession
- if the system session should also be included- Returns:
- the list of sessions
-
updateMeta
public void updateMeta(SessionLocal session, DbObject obj)
Update an object in the system table.- Parameters:
session
- the sessionobj
- the database object
-
renameSchemaObject
public void renameSchemaObject(SessionLocal session, SchemaObject obj, java.lang.String newName)
Rename a schema object.- Parameters:
session
- the sessionobj
- the objectnewName
- the new name
-
updateMetaAndFirstLevelChildren
private void updateMetaAndFirstLevelChildren(SessionLocal session, DbObject obj)
-
renameDatabaseObject
public void renameDatabaseObject(SessionLocal session, DbObject obj, java.lang.String newName)
Rename a database object.- Parameters:
session
- the sessionobj
- the objectnewName
- the new name
-
deleteOldTempFiles
private void deleteOldTempFiles()
-
getSchema
public Schema getSchema(java.lang.String schemaName)
Get the schema. If the schema does not exist, an exception is thrown.- Parameters:
schemaName
- the name of the schema- Returns:
- the schema
- Throws:
DbException
- no schema with that name exists
-
removeDatabaseObject
public void removeDatabaseObject(SessionLocal session, DbObject obj)
Remove the object from the database.- Parameters:
session
- the sessionobj
- the object to remove
-
getDependentTable
public Table getDependentTable(SchemaObject obj, Table except)
Get the first table that depends on this object.- Parameters:
obj
- the object to findexcept
- the table to exclude (or null)- Returns:
- the first dependent table, or null
-
removeSchemaObject
public void removeSchemaObject(SessionLocal session, SchemaObject obj)
Remove an object from the system table.- Parameters:
session
- the sessionobj
- the object to be removed
-
isPersistent
public boolean isPersistent()
Check if this database is disk-based.- Returns:
- true if it is disk-based, false if it is in-memory only.
-
getTraceSystem
public TraceSystem getTraceSystem()
-
setCacheSize
public void setCacheSize(int kb)
-
setMasterUser
public void setMasterUser(User user)
-
getPublicRole
public Role getPublicRole()
-
getTempTableName
public java.lang.String getTempTableName(java.lang.String baseName, SessionLocal session)
Get a unique temporary table name.- Parameters:
baseName
- the prefix of the returned namesession
- the session- Returns:
- a unique name
-
setCompareMode
public void setCompareMode(CompareMode compareMode)
-
setCluster
public void setCluster(java.lang.String cluster)
-
checkWritingAllowed
public void checkWritingAllowed()
Description copied from interface:DataHandler
Check if writing is allowed.- Specified by:
checkWritingAllowed
in interfaceDataHandler
-
isReadOnly
public boolean isReadOnly()
-
setWriteDelay
public void setWriteDelay(int value)
-
getRetentionTime
public int getRetentionTime()
-
setRetentionTime
public void setRetentionTime(int value)
-
setAllowBuiltinAliasOverride
public void setAllowBuiltinAliasOverride(boolean b)
-
isAllowBuiltinAliasOverride
public boolean isAllowBuiltinAliasOverride()
-
getInDoubtTransactions
public java.util.ArrayList<InDoubtTransaction> getInDoubtTransactions()
Get the list of in-doubt transactions.- Returns:
- the list
-
prepareCommit
void prepareCommit(SessionLocal session, java.lang.String transaction)
Prepare a transaction.- Parameters:
session
- the sessiontransaction
- the name of the transaction
-
throwLastBackgroundException
void throwLastBackgroundException()
If there is a background store thread, and if there wasn an exception in that thread, throw it now.
-
setBackgroundException
public void setBackgroundException(DbException e)
-
getBackgroundException
public java.lang.Throwable getBackgroundException()
-
flush
public void flush()
Flush all pending changes to the transaction log.
-
setEventListener
public void setEventListener(DatabaseEventListener eventListener)
-
setEventListenerClass
public void setEventListenerClass(java.lang.String className)
-
setProgress
public void setProgress(int state, java.lang.String name, long x, long max)
Set the progress of a long running operation. This method calls theDatabaseEventListener
if one is registered.- Parameters:
state
- theDatabaseEventListener
statename
- the object namex
- the current positionmax
- the highest value or 0 if unknown
-
exceptionThrown
public void exceptionThrown(java.sql.SQLException e, java.lang.String sql)
This method is called after an exception occurred, to inform the database event listener (if one is set).- Parameters:
e
- the exceptionsql
- the SQL statement
-
sync
public void sync()
Synchronize the files with the file system. This method is called when executing the SQL statement CHECKPOINT SYNC.
-
getMaxMemoryRows
public int getMaxMemoryRows()
-
setMaxMemoryRows
public void setMaxMemoryRows(int value)
-
setLockMode
public void setLockMode(int lockMode)
-
getLockMode
public int getLockMode()
-
setCloseDelay
public void setCloseDelay(int value)
-
getSystemSession
public SessionLocal getSystemSession()
-
isClosing
public boolean isClosing()
Check if the database is in the process of closing.- Returns:
- true if the database is closing
-
setMaxLengthInplaceLob
public void setMaxLengthInplaceLob(int value)
-
getMaxLengthInplaceLob
public int getMaxLengthInplaceLob()
Description copied from interface:DataHandler
Get the maximum length of a in-place large object- Specified by:
getMaxLengthInplaceLob
in interfaceDataHandler
- Returns:
- the maximum size
-
setIgnoreCase
public void setIgnoreCase(boolean b)
-
getIgnoreCase
public boolean getIgnoreCase()
-
setIgnoreCatalogs
public void setIgnoreCatalogs(boolean b)
-
getIgnoreCatalogs
public boolean getIgnoreCatalogs()
-
setDeleteFilesOnDisconnect
public void setDeleteFilesOnDisconnect(boolean b)
-
setAllowLiterals
public void setAllowLiterals(int value)
-
getOptimizeReuseResults
public boolean getOptimizeReuseResults()
-
setOptimizeReuseResults
public void setOptimizeReuseResults(boolean b)
-
getLobSyncObject
public java.lang.Object getLobSyncObject()
Description copied from interface:DataHandler
Get the synchronization object for lob operations.- Specified by:
getLobSyncObject
in interfaceDataHandler
- Returns:
- the synchronization object
-
getSessionCount
public int getSessionCount()
-
setReferentialIntegrity
public void setReferentialIntegrity(boolean b)
-
getReferentialIntegrity
public boolean getReferentialIntegrity()
-
setQueryStatistics
public void setQueryStatistics(boolean b)
-
getQueryStatistics
public boolean getQueryStatistics()
-
setQueryStatisticsMaxEntries
public void setQueryStatisticsMaxEntries(int n)
-
getQueryStatisticsData
public QueryStatisticsData getQueryStatisticsData()
-
isStarting
public boolean isStarting()
Check if the database is currently opening. This is true until all stored SQL statements have been executed.- Returns:
- true if the database is still starting
-
opened
void opened()
Called after the database has been opened and initialized. This method notifies the event listener if one has been set.
-
setMode
public void setMode(Mode mode)
-
getMode
public Mode getMode()
Description copied from interface:CastDataProvider
Returns the database mode.- Specified by:
getMode
in interfaceCastDataProvider
- Returns:
- the database mode
-
setDefaultNullOrdering
public void setDefaultNullOrdering(DefaultNullOrdering defaultNullOrdering)
-
getDefaultNullOrdering
public DefaultNullOrdering getDefaultNullOrdering()
-
setMaxOperationMemory
public void setMaxOperationMemory(int maxOperationMemory)
-
getMaxOperationMemory
public int getMaxOperationMemory()
-
getExclusiveSession
public SessionLocal getExclusiveSession()
-
setExclusiveSession
public boolean setExclusiveSession(SessionLocal session, boolean closeOthers)
Set the session that can exclusively access the database.- Parameters:
session
- the sessioncloseOthers
- whether other sessions are closed- Returns:
- true if success or if database is in exclusive mode set by this session already, false otherwise
-
unsetExclusiveSession
public boolean unsetExclusiveSession(SessionLocal session)
Stop exclusive access the database by provided session.- Parameters:
session
- the session- Returns:
- true if success or if database is in non-exclusive mode already, false otherwise
-
getLobFileListCache
public SmallLRUCache<java.lang.String,java.lang.String[]> getLobFileListCache()
Description copied from interface:DataHandler
Get the lob file list cache if it is used.- Specified by:
getLobFileListCache
in interfaceDataHandler
- Returns:
- the cache or null
-
isSysTableLocked
public boolean isSysTableLocked()
Checks if the system table (containing the catalog) is locked.- Returns:
- true if it is currently locked
-
isSysTableLockedBy
public boolean isSysTableLockedBy(SessionLocal session)
Checks if the system table (containing the catalog) is locked by the given session.- Parameters:
session
- the session- Returns:
- true if it is currently locked
-
getLinkConnection
public TableLinkConnection getLinkConnection(java.lang.String driver, java.lang.String url, java.lang.String user, java.lang.String password)
Open a new connection or get an existing connection to another database.- Parameters:
driver
- the database driver or nullurl
- the database URLuser
- the user namepassword
- the password- Returns:
- the connection
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
shutdownImmediately
public void shutdownImmediately()
Immediately close the database.
-
getTempFileDeleter
public TempFileDeleter getTempFileDeleter()
Description copied from interface:DataHandler
Get the temp file deleter mechanism.- Specified by:
getTempFileDeleter
in interfaceDataHandler
- Returns:
- the temp file deleter
-
getFirstUserTable
public Table getFirstUserTable()
Get the first user defined table, excluding the LOB_BLOCKS table that the Recover tool creates.- Returns:
- the table or null if no table is defined
-
checkpoint
public void checkpoint()
Flush all changes and open a new transaction log.
-
setReadOnly
public void setReadOnly(boolean readOnly)
Switch the database to read-only mode.- Parameters:
readOnly
- the new value
-
setCompactMode
public void setCompactMode(int compactMode)
-
getCompiler
public SourceCompiler getCompiler()
-
getLobStorage
public LobStorageInterface getLobStorage()
Description copied from interface:DataHandler
Get the lob storage mechanism to use.- Specified by:
getLobStorage
in interfaceDataHandler
- Returns:
- the lob storage mechanism
-
getLobSession
public SessionLocal getLobSession()
-
getDefaultTableType
public int getDefaultTableType()
-
setDefaultTableType
public void setDefaultTableType(int defaultTableType)
-
getSettings
public DbSettings getSettings()
-
newStringMap
public <V> java.util.HashMap<java.lang.String,V> newStringMap()
Create a new hash map. Depending on the configuration, the key is case sensitive or case insensitive.- Type Parameters:
V
- the value type- Returns:
- the hash map
-
newStringMap
public <V> java.util.HashMap<java.lang.String,V> newStringMap(int initialCapacity)
Create a new hash map. Depending on the configuration, the key is case sensitive or case insensitive.- Type Parameters:
V
- the value type- Parameters:
initialCapacity
- the initial capacity- Returns:
- the hash map
-
newConcurrentStringMap
public <V> java.util.concurrent.ConcurrentHashMap<java.lang.String,V> newConcurrentStringMap()
Create a new hash map. Depending on the configuration, the key is case sensitive or case insensitive.- Type Parameters:
V
- the value type- Returns:
- the hash map
-
equalsIdentifiers
public boolean equalsIdentifiers(java.lang.String a, java.lang.String b)
Compare two identifiers (table names, column names,...) and verify they are equal. Case sensitivity depends on the configuration.- Parameters:
a
- the first identifierb
- the second identifier- Returns:
- true if they match
-
sysIdentifier
public java.lang.String sysIdentifier(java.lang.String upperName)
Returns identifier in upper or lower case depending on database settings.- Parameters:
upperName
- identifier in the upper case- Returns:
- identifier in upper or lower case
-
isUpperSysIdentifier
private static boolean isUpperSysIdentifier(java.lang.String upperName)
-
readLob
public int readLob(long lobId, byte[] hmac, long offset, byte[] buff, int off, int length)
Description copied from interface:DataHandler
Read from a lob.- Specified by:
readLob
in interfaceDataHandler
- Parameters:
lobId
- the lob idhmac
- the message authentication codeoffset
- the offset within the lobbuff
- the target bufferoff
- the offset within the target bufferlength
- the number of bytes to read- Returns:
- the number of bytes read
-
getFileEncryptionKey
public byte[] getFileEncryptionKey()
-
getPageSize
public int getPageSize()
-
getJavaObjectSerializer
public JavaObjectSerializer getJavaObjectSerializer()
Description copied from interface:CastDataProvider
Returns the custom Java object serializer, ornull
.- Specified by:
getJavaObjectSerializer
in interfaceCastDataProvider
- Returns:
- the custom Java object serializer, or
null
-
initJavaObjectSerializer
private void initJavaObjectSerializer()
-
setJavaObjectSerializerName
public void setJavaObjectSerializerName(java.lang.String serializerName)
-
getTableEngine
public TableEngine getTableEngine(java.lang.String tableEngine)
Get the table engine class, loading it if needed.- Parameters:
tableEngine
- the table engine name- Returns:
- the class
-
getAuthenticator
public Authenticator getAuthenticator()
get authenticator for database users- Returns:
- authenticator set for database
-
setAuthenticator
public void setAuthenticator(Authenticator authenticator)
Set current database authenticator- Parameters:
authenticator
- = authenticator to set, null to revert to the Internal authenticator
-
currentTimestamp
public ValueTimestampTimeZone currentTimestamp()
Description copied from interface:CastDataProvider
Returns the current timestamp with maximum resolution. The value must be the same within a transaction or within execution of a command.- Specified by:
currentTimestamp
in interfaceCastDataProvider
- Returns:
- the current timestamp for CURRENT_TIMESTAMP(9)
-
currentTimeZone
public TimeZoneProvider currentTimeZone()
Description copied from interface:CastDataProvider
Returns the current time zone.- Specified by:
currentTimeZone
in interfaceCastDataProvider
- Returns:
- the current time zone
-
zeroBasedEnums
public boolean zeroBasedEnums()
Description copied from interface:CastDataProvider
Returns are ENUM values 0-based.- Specified by:
zeroBasedEnums
in interfaceCastDataProvider
- Returns:
- are ENUM values 0-based
-
-