Top Description Fields Constructors Methods
org.h2.engine

public final Class Database

extends Object
implements DataHandler, CastDataProvider
Class Inheritance
All Implemented Interfaces
org.h2.engine.CastDataProvider, org.h2.store.DataHandler
Imports
java.sql.SQLException, java.util.ArrayList, .BitSet, .Collection, .Collections, .HashMap, .HashSet, .Map, .Objects, .Set, java.util.concurrent.ConcurrentHashMap, java.util.concurrent.atomic.AtomicInteger, .AtomicLong, .AtomicReference, org.h2.api.DatabaseEventListener, .ErrorCode, .JavaObjectSerializer, .TableEngine, org.h2.command.CommandInterface, .Prepared, org.h2.command.ddl.CreateTableData, org.h2.command.dml.SetTypes, org.h2.constraint.Constraint, .Constraint.Type, org.h2.engine.Mode.ModeEnum, org.h2.index.Cursor, .Index, .IndexType, org.h2.message.DbException, .Trace, .TraceSystem, org.h2.mode.DefaultNullOrdering, .PgCatalogSchema, org.h2.mvstore.MVStoreException, org.h2.mvstore.db.LobStorageMap, .Store, org.h2.result.Row, .RowFactory, .SearchRow, org.h2.schema.InformationSchema, .Schema, .SchemaObject, .Sequence, .TriggerObject, org.h2.security.auth.Authenticator, org.h2.store.DataHandler, .FileLock, .FileLockMethod, .FileStore, .InDoubtTransaction, .LobStorageInterface, org.h2.store.fs.FileUtils, org.h2.store.fs.encrypt.FileEncrypt, org.h2.table.Column, .IndexColumn, .Table, .TableLinkConnection, .TableSynonym, .TableType, .TableView, org.h2.tools.DeleteDbFiles, .Server, org.h2.util.JdbcUtils, .MathUtils, .NetUtils, .NetworkConnectionInfo, .SmallLRUCache, .SourceCompiler, .StringUtils, .TempFileDeleter, .TimeZoneProvider, .Utils, org.h2.value.CaseInsensitiveConcurrentMap, .CaseInsensitiveMap, .CompareMode, .TypeInfo, .ValueInteger, .ValueTimestampTimeZone

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

Modifier and TypeField and Description
private boolean
private int
private static final boolean
private Authenticator
private final boolean
private final int
private final AtomicReference<DbException>
private final String
private final String
private final boolean
private volatile int
private volatile boolean
private String
private final ConcurrentHashMap<String, Comment>
private int
private CompareMode
private SourceCompiler
private final String
private final String
private final String
private final DbSettings
private DefaultNullOrdering
private int
private DelayedDatabaseCloser
private boolean
private static final SessionLocal[]
private DatabaseEventListener
private final AtomicReference<SessionLocal>
private final FileLockMethod
private final byte[]
private boolean
private boolean
private final Schema
private static int
private JavaObjectSerializer
private volatile boolean
private String
private HashMap<TableLinkConnection, TableLinkConnection>
private SmallLRUCache<String, String[]>
private SessionLocal
private final LobStorageInterface
private final Object
private FileLock
private int
private final Schema
private int
private int
private int
private final Table
private static final ThreadLocal<SessionLocal>
private static final ThreadLocal<Database>
private static final ThreadLocal<Throwable>
private final Index
private Mode
private final AtomicLong
private final AtomicLong
private int
private final AtomicInteger
private final BitSet
private boolean
private final int
private final boolean
private final Schema
private int
private final Role
private volatile boolean
private QueryStatisticsData
private int
private boolean
private boolean
private final AtomicLong
remoteSettingsId

Used to trigger the client side to reload some of the settings.

private final ConcurrentHashMap<String, Right>
private RowFactory
private final ConcurrentHashMap<String, Schema>
private Server
private final ConcurrentHashMap<String, Setting>
private volatile boolean
private final Store
private static final String
SYSTEM_USER_NAME

The default name of the system user.

private SessionLocal
private final User
private final HashMap<String, TableEngine>
private final TempFileDeleter
private final Trace
private final TraceSystem
private final ConcurrentHashMap<String, RightOwner>
private final Set<SessionLocal>

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public synchronized void
addDatabaseObject(SessionLocal
the session
session
,
DbObject
the object to add
obj
)

Add an object to the database.

private void
public void
addSchemaObject(SessionLocal
the session
session
,
SchemaObject
the object to add
obj
)

Add a schema object to the database.

public int

Returns:

the id
allocateObjectId
()

Allocate a new object id.

private void
checkMetaFree(SessionLocal session, int id)

public void
checkpoint()

Flush all changes and open a new transaction log.

public void
checkPowerOff()

Implements org.h2.store.DataHandler.checkPowerOff.

Check if the simulated power failure occurred.

private void
public void
checkWritingAllowed()

Implements org.h2.store.DataHandler.checkWritingAllowed.

Check if writing is allowed.

pack-priv void
close()

Close the database.

private void
close(boolean
true if this method is called from the shutdown hook
fromShutdownHook
)

Close the database.

private synchronized void
private synchronized void
private void
closeImpl(boolean fromShutdownHook)

private synchronized void
closeOpenFilesAndUnlock()

Close all open files and unlock the database.

pack-priv synchronized SessionLocal

Returns:

the session, or null if the database is currently closing
createSession
(User
the user
user
,
NetworkConnectionInfo
the network connection information, or null
networkConnectionInfo
)

Create a session for the given user.

private SessionLocal
private CreateTableData
public ValueTimestampTimeZone
currentTimestamp()

Implements org.h2.engine.CastDataProvider.currentTimestamp.

Returns the current timestamp with maximum resolution.

public TimeZoneProvider
currentTimeZone()

Implements org.h2.engine.CastDataProvider.currentTimeZone.

Returns the current time zone.

private void
public boolean

Returns:

true if they match
equalsIdentifiers
(String
the first identifier
a
,
String
the second identifier
b
)

Compare two identifiers (table names, column names,...) and verify they are equal.

public void
exceptionThrown(SQLException
the exception
e
,
String
the SQL statement
sql
)

This method is called after an exception occurred, to inform the database event listener (if one is set).

private void
private void
public Comment

Returns:

the comment or null
findComment
(DbObject
the database object
object
)

Get the comment for the given database object if one exists, or null if not.

public Role

Returns:

the role or null
findRole
(String
the name of the role
roleName
)

Get the role if it exists, or null if not.

public Schema

Returns:

the schema or null
findSchema
(String
the name of the schema
schemaName
)

Get the schema if it exists, or null if not.

public Setting

Returns:

the setting or null
findSetting
(String
the name of the setting
name
)

Get the setting if it exists, or null if not.

public User

Returns:

the user or null
findUser
(String
the name of the user
name
)

Get the user if it exists, or null if not.

public RightOwner

Returns:

the user, the role, or null
findUserOrRole
(String
the name of the user or role
name
)

Get the user or role if it exists, or null if not.

public synchronized void
flush()

Flush all pending changes to the transaction log.

public ArrayList<Comment>
public int
public ArrayList<Right>
public Collection<Schema>
public Collection<Schema>
public Collection<Setting>
public ArrayList<TableSynonym>

Returns:

all objects of that type
getAllSynonyms
()

Get all synonyms.

public ArrayList<Table>

Returns:

all objects of that type
getAllTablesAndViews
()

Get all tables and views.

public Collection<RightOwner>
public Authenticator

Returns:

authenticator set for database
getAuthenticator
()

get authenticator for database users

public Throwable
public String
public String
public CompareMode
getCompareMode()

Implements org.h2.store.DataHandler.getCompareMode.

Return compare mode.

public SourceCompiler
public String
getDatabasePath()

Implements org.h2.store.DataHandler.getDatabasePath.

Get the database path.

public DefaultNullOrdering
public int
public Table

Returns:

the first dependent table, or null
getDependentTable
(SchemaObject
the object to find
obj
,
Table
the table to exclude (or null)
except
)

Get the first table that depends on this object.

public SessionLocal
public Table

Returns:

the table or null if no table is defined
getFirstUserTable
()

Get the first user defined table, excluding the LOB_BLOCKS table that the Recover tool creates.

public boolean
public boolean
public ArrayList<InDoubtTransaction>

Returns:

the list
getInDoubtTransactions
()

Get the list of in-doubt transactions.

public JavaObjectSerializer
getJavaObjectSerializer()

Implements org.h2.engine.CastDataProvider.getJavaObjectSerializer.

Returns the custom Java object serializer, or null.

public TableLinkConnection

Returns:

the connection
getLinkConnection
(String
the database driver or null
driver
,
String
the database URL
url
,
String
the user name
user
,
String
the password
password
)

Open a new connection or get an existing connection to another database.

public SmallLRUCache<String, String[]>
getLobFileListCache()

Implements org.h2.store.DataHandler.getLobFileListCache.

Get the lob file list cache if it is used.

public SessionLocal
public LobStorageInterface
getLobStorage()

Implements org.h2.store.DataHandler.getLobStorage.

Get the lob storage mechanism to use.

public Object
getLobSyncObject()

Implements org.h2.store.DataHandler.getLobSyncObject.

Get the synchronization object for lob operations.

public int
public int
public Schema

Returns:

main schema (usually PUBLIC)
getMainSchema
()

Returns main schema (usually PUBLIC).

private ConcurrentHashMap<String, DbObject>
getMap(int type)

public int
getMaxLengthInplaceLob()

Implements org.h2.store.DataHandler.getMaxLengthInplaceLob.

Get the maximum length of a in-place large object

public int
public int
public Mode
getMode()

Implements org.h2.engine.CastDataProvider.getMode.

Returns the database mode.

public long
public long
public String
public long
public long
public long
public boolean
public int
public int
public Role
public boolean
public QueryStatisticsData
public boolean
public long
public int
public RowFactory
public Schema

Returns:

the schema
getSchema
(String
the name of the schema
schemaName
)

Get the schema.

public int
public SessionLocal[]

Returns:

the list of sessions
getSessions
(boolean
if the system session should also be included
includingSystemSession
)

Get all sessions that are currently connected to the database.

public DbSettings
public String
public Store
public SessionLocal
public User

Returns:

system user
getSystemUser
()

Returns system user.

public TableEngine

Returns:

the class
getTableEngine
(String
the table engine name
tableEngine
)

Get the table engine class, loading it if needed.

public TempFileDeleter
getTempFileDeleter()

Implements org.h2.store.DataHandler.getTempFileDeleter.

Get the temp file deleter mechanism.

public String

Returns:

a unique name
getTempTableName
(String
the prefix of the returned name
baseName
,
SessionLocal
the session
session
)

Get a unique temporary table name.

public Trace

Returns:

the trace object
getTrace
(int
the module id
moduleId
)

Get the trace object for the given module id.

public TraceSystem
public User

Returns:

the user
getUser
(String
the user name
name
)

Get user with the given name.

public int
private void
public boolean
public boolean

Returns:

true if the database is closing
isClosing
()

Check if the database is in the process of closing.

public boolean

Returns:

true if it is disk-based, false if it is in-memory only.
isPersistent
()

Check if this database is disk-based.

public boolean
public boolean

Returns:

true if the database is still starting
isStarting
()

Check if the database is currently opening.

public boolean

Returns:

true if it is currently locked
isSysTableLocked
()

Checks if the system table (containing the catalog) is locked.

public boolean

Returns:

true if it is currently locked
isSysTableLockedBy
(SessionLocal
the session
session
)

Checks if the system table (containing the catalog) is locked by the given session.

private static boolean
pack-priv boolean
public boolean

Returns:

whether it was already locked before by this session
lockMeta
(SessionLocal
the session
session
)

Lock the metadata table for updates.

private void
public <
the value type
V
>
ConcurrentHashMap<String, V>

Returns:

the hash map
newConcurrentStringMap
()

Create a new hash map.

public <
the value type
V
>
HashMap<String, V>

Returns:

the hash map
newStringMap
()

Create a new hash map.

public <
the value type
V
>
HashMap<String, V>

Returns:

the hash map
newStringMap
(int
the initial capacity
initialCapacity
)

Create a new hash map.

pack-priv void
onShutdown()

Invoked by shutdown hook.

pack-priv void
opened()

Called after the database has been opened and initialized.

public FileStore
openFile(String
the file name
name
,
String
the mode
openMode
,
boolean
whether the file must already exist
mustExist
)

Implements org.h2.store.DataHandler.openFile.

Open a file at the given location.

private String
pack-priv synchronized void
prepareCommit(SessionLocal
the session
session
,
String
the name of the transaction
transaction
)

Prepare a transaction.

public int
readLob(long
the lob id
lobId
,
byte[]
the message authentication code
hmac
,
long
the offset within the lob
offset
,
byte[]
the target buffer
buff
,
int
the offset within the target buffer
off
,
int
the number of bytes to read
length
)

Implements org.h2.store.DataHandler.readLob.

Read from a lob.

private void
public void
releaseDatabaseObjectIds(BitSet
the ids to release
idsToRelease
)

Mark some database ids as unused.

public synchronized void
removeDatabaseObject(SessionLocal
the session
session
,
DbObject
the object to remove
obj
)

Remove the object from the database.

public void
removeMeta(SessionLocal
the session
session
,
int
the id of the object to remove
id
)

Remove the given object from the meta data.

public void
removeSchemaObject(SessionLocal
the session
session
,
SchemaObject
the object to be removed
obj
)

Remove an object from the system table.

public synchronized void
removeSession(SessionLocal
the session
session
)

Remove a session.

public synchronized void
renameDatabaseObject(SessionLocal
the session
session
,
DbObject
the object
obj
,
String
the new name
newName
)

Rename a database object.

public synchronized void
renameSchemaObject(SessionLocal
the session
session
,
SchemaObject
the object
obj
,
String
the new name
newName
)

Rename a schema object.

public void
public void
setAllowLiterals(int value)

public void
setAuthenticator(Authenticator
= authenticator to set, null to revert to the Internal authenticator
authenticator
)

Set current database authenticator

public void
public synchronized void
setCacheSize(int kb)

public void
setCloseDelay(int value)

public void
setCluster(String cluster)

public void
setCompactMode(int compactMode)

public void
public void
public void
setDefaultTableType(int defaultTableType)

public synchronized void
public void
public void
public boolean

Returns:

true if success or if database is in exclusive mode set by this session already, false otherwise
setExclusiveSession
(SessionLocal
the session
session
,
boolean
whether other sessions are closed
closeOthers
)

Set the session that can exclusively access the database.

public void
setIgnoreCase(boolean b)

public void
setIgnoreCatalogs(boolean b)

public static void
public void
public void
setLockMode(int lockMode)

public synchronized void
public void
public void
setMaxMemoryRows(int value)

public void
setMaxOperationMemory(int maxOperationMemory)

public void
setMode(Mode mode)

public void
public void
setPowerOffCount(int count)

public void
setProgress(int state, String
the object name
name
,
long
the current position
x
,
long
the highest value or 0 if unknown
max
)

Set the progress of a long running operation.

public void
setQueryStatistics(boolean b)

public void
public void
setReadOnly(boolean
the new value
readOnly
)

Switch the database to read-only mode.

public void
public void
setRetentionTime(int value)

public void
public void
setWriteDelay(int value)

public void
shutdownImmediately()

Immediately close the database.

private void
private void
public synchronized void
sync()

Synchronize the files with the file system.

public String

Returns:

identifier in upper or lower case
sysIdentifier
(String
identifier in the upper case
upperName
)

Returns identifier in upper or lower case depending on database settings.

pack-priv void
throwLastBackgroundException()

If there is a background store thread, and if there wasn an exception in that thread, throw it now.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

public void
unlockMeta(SessionLocal
the session
session
)

Unlock the metadata table.

pack-priv static void
unlockMetaDebug(SessionLocal
the session
session
)

This method doesn't actually unlock the metadata table, all it does it reset the debugging flags.

public boolean

Returns:

true if success or if database is in non-exclusive mode already, false otherwise
unsetExclusiveSession
(SessionLocal
the session
session
)

Stop exclusive access the database by provided session.

public void
updateMeta(SessionLocal
the session
session
,
DbObject
the database object
obj
)

Update an object in the system table.

private synchronized void
pack-priv boolean

Returns:

true if the cipher algorithm and the password match
validateFilePasswordHash
(String
the cipher algorithm
testCipher
,
byte[]
the hash code
testHash
)

Check if the file password hash is correct.

public void
verifyMetaLocked(SessionLocal
the session
session
)

Verify the meta table is locked.

public boolean
zeroBasedEnums()

Implements org.h2.engine.CastDataProvider.zeroBasedEnums.

Returns are ENUM values 0-based.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait