Package org.h2.engine
Class Session
java.lang.Object
org.h2.engine.Session
- All Implemented Interfaces:
AutoCloseable,CastDataProvider
- Direct Known Subclasses:
SessionLocal,SessionRemote
A local or remote session. A session represents a database connection.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classDynamic settings.static final classStatic settings. -
Method Summary
Modifier and TypeMethodDescriptionabstract org.h2.value.ValueLobaddTemporaryLob(org.h2.value.ValueLob v) Add a temporary LOB, which is closed when the session commits.abstract voidcancel()Cancel the current or next command (called when closing a connection).abstract voidclose()Roll back pending transactions and close the session.abstract booleanCheck if this session is in auto-commit mode.Get the list of the cluster servers for this session.abstract StringGet current schema.abstract org.h2.jdbc.meta.DatabaseMetaReturns database meta information.abstract org.h2.store.DataHandlerGet the data handler object.abstract Session.DynamicSettingsReturns dynamic settings.abstract IsolationLevelReturns the isolation level.abstract Session.StaticSettingsReturns static settings.abstract org.h2.message.TracegetTrace()Get the trace objectabstract booleanCheck whether this session has a pending transaction.abstract booleanisClosed()Check if close was called.final booleanReturns whether this session is locked by the current thread.abstract booleanReturns whether INFORMATION_SCHEMA contains old-style tables.abstract booleanisRemote()Check if this session is remote or embedded.final voidlock()Locks this session with a reentrant lock.abstract org.h2.command.CommandInterfaceprepareCommand(String sql) Parse a command and prepare it for execution.voidresetThreadLocalSession(Session oldSession) Resets old thread local session.abstract voidsetAutoCommit(boolean autoCommit) Set the auto-commit mode.abstract voidsetCurrentSchemaName(String schema) Set current schema.abstract voidsetIsolationLevel(IsolationLevel isolationLevel) Sets the isolation level.abstract voidsetNetworkConnectionInfo(org.h2.util.NetworkConnectionInfo networkConnectionInfo) Sets the network connection information if possible.Sets this session as thread local session, if this session is a local session.final voidunlock()Unlocks this session.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.h2.engine.CastDataProvider
currentTimestamp, currentTimeZone, getJavaObjectSerializer, getMode, zeroBasedEnums
-
Method Details
-
lock
public final void lock()Locks this session with a reentrant lock.final Session session = ...; session.lock(); try { ... } finally { session.unlock(); } -
unlock
public final void unlock()Unlocks this session.- See Also:
-
isLockedByCurrentThread
public final boolean isLockedByCurrentThread()Returns whether this session is locked by the current thread.- Returns:
trueif it locked by the current thread,falseif it is locked by another thread or is not locked at all
-
getClusterServers
Get the list of the cluster servers for this session.- Returns:
- A list of "ip:port" strings for the cluster servers in this session.
-
prepareCommand
Parse a command and prepare it for execution.- Parameters:
sql- the SQL statement- Returns:
- the prepared command
-
close
public abstract void close()Roll back pending transactions and close the session.- Specified by:
closein interfaceAutoCloseable
-
getTrace
public abstract org.h2.message.Trace getTrace()Get the trace object- Returns:
- the trace object
-
isClosed
public abstract boolean isClosed()Check if close was called.- Returns:
- if the session has been closed
-
getDataHandler
public abstract org.h2.store.DataHandler getDataHandler()Get the data handler object.- Returns:
- the data handler
-
hasPendingTransaction
public abstract boolean hasPendingTransaction()Check whether this session has a pending transaction.- Returns:
- true if it has
-
cancel
public abstract void cancel()Cancel the current or next command (called when closing a connection). -
getAutoCommit
public abstract boolean getAutoCommit()Check if this session is in auto-commit mode.- Returns:
- true if the session is in auto-commit mode
-
setAutoCommit
public abstract void setAutoCommit(boolean autoCommit) Set the auto-commit mode. This call doesn't commit the current transaction.- Parameters:
autoCommit- the new value
-
addTemporaryLob
public abstract org.h2.value.ValueLob addTemporaryLob(org.h2.value.ValueLob v) Add a temporary LOB, which is closed when the session commits.- Parameters:
v- the value- Returns:
- the specified value
-
isRemote
public abstract boolean isRemote()Check if this session is remote or embedded.- Returns:
- true if this session is remote
-
setCurrentSchemaName
Set current schema.- Parameters:
schema- the schema name
-
getCurrentSchemaName
Get current schema.- Returns:
- the current schema name
-
setNetworkConnectionInfo
public abstract void setNetworkConnectionInfo(org.h2.util.NetworkConnectionInfo networkConnectionInfo) Sets the network connection information if possible.- Parameters:
networkConnectionInfo- the network connection information
-
getIsolationLevel
Returns the isolation level.- Returns:
- the isolation level
-
setIsolationLevel
Sets the isolation level.- Parameters:
isolationLevel- the isolation level to set
-
getStaticSettings
Returns static settings. These settings cannot be changed during lifecycle of session.- Returns:
- static settings
-
getDynamicSettings
Returns dynamic settings. These settings can be changed during lifecycle of session.- Returns:
- dynamic settings
-
getDatabaseMeta
public abstract org.h2.jdbc.meta.DatabaseMeta getDatabaseMeta()Returns database meta information.- Returns:
- database meta information
-
isOldInformationSchema
public abstract boolean isOldInformationSchema()Returns whether INFORMATION_SCHEMA contains old-style tables.- Returns:
- whether INFORMATION_SCHEMA contains old-style tables
-
setThreadLocalSession
Sets this session as thread local session, if this session is a local session.- Returns:
- old thread local session, or
null
-
resetThreadLocalSession
Resets old thread local session.- Parameters:
oldSession- the old thread local session, ornull
-