Top Description Inners Fields Constructors Methods
org.h2.engine

public final Class SessionLocal

extends Session
implements RollbackListener
Class Inheritance
All Implemented Interfaces
org.h2.mvstore.tx.TransactionStore.RollbackListener
Imports
java.time.Instant, java.util.ArrayList, .BitSet, .Collections, .HashMap, .HashSet, .Iterator, .LinkedList, .List, .Map, .Random, .Set, .WeakHashMap, java.util.concurrent.atomic.AtomicReference, org.h2.api.ErrorCode, .JavaObjectSerializer, org.h2.command.Command, .CommandInterface, .Parser, .ParserBase, .Prepared, .QueryScope, org.h2.command.ddl.Analyze, org.h2.command.query.Query, org.h2.constraint.Constraint, org.h2.index.Index, .QueryExpressionIndex, org.h2.jdbc.JdbcConnection, org.h2.jdbc.meta.DatabaseMeta, .DatabaseMetaLocal, org.h2.message.DbException, .Trace, .TraceSystem, org.h2.mvstore.MVMap, org.h2.mvstore.db.MVIndex, .MVTable, .Store, org.h2.mvstore.tx.Transaction, .TransactionStore, org.h2.result.Row, org.h2.schema.Schema, .Sequence, org.h2.store.DataHandler, .InDoubtTransaction, .LobStorageFrontend, org.h2.table.Table, org.h2.util.DateTimeUtils, .HasSQL, .NetworkConnectionInfo, .SmallLRUCache, .TimeZoneProvider, .Utils, org.h2.value.CompareMode, .Value, .ValueLob, .ValueNull, .ValueTimestampTimeZone, .ValueVarchar, .VersionedValue, org.h2.value.lob.LobData, .LobDataDatabase, .LobDataInMemory

A session represents an embedded database connection. When using the server mode, this object resides on the server side and communicates with a SessionRemote object on the client side.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
public static class
SessionLocal.Savepoint

Represents a savepoint (a position in a transaction to where one can roll back to).

private static class
public static enum
public static class
SessionLocal.TimeoutValue

An LOB object with a timeout.

Field Summary

Modifier and TypeField and Description
private boolean
private boolean
private boolean
private volatile long
private Instant
private boolean
private int
private Command
private String
private ValueTimestampTimeZone
private String
private WeakHashMap<Sequence, Value>
private Database
private HashMap<Object, QueryExpressionIndex>
private final int
private BitSet
idsToRelease

Set of database object ids to be released at the end of transaction

private IsolationLevel
isolationLevel

Isolation level.

private Value
private long
private boolean
private HashMap<String, Constraint>
private HashMap<String, Index>
private HashMap<String, Table>
private final ArrayList<Table>
private int
private int
private long
private NetworkConnectionInfo
private static int
private HashMap<SessionLocal.SequenceAndPrepared, SessionLocal.RowNumberAndValue>
private BitSet
private int
private boolean
oldInformationSchema

Whether INFORMATION_SCHEMA contains old-style tables.

private HashMap<String, Procedure>
private SmallLRUCache<String, Command>
private final int
private int
private boolean
quirksMode

Whether commands are executed in quirks mode to support scripts from older versions of H2.

private Random
private HashMap<String, ValueLob>
private HashMap<String, SessionLocal.Savepoint>
private String[]
private final int
private final ValueTimestampTimeZone
private long
snapshotDataModificationId

The snapshot data modification id. If isolation level doesn't allow non-repeatable reads the session uses a snapshot versions of data.

private long
private final AtomicReference<SessionLocal.State>
private long
private static final String
SYSTEM_IDENTIFIER_PREFIX

The prefix of generated identifiers.

private int
private HashSet<Table>
tablesToAnalyze

Tables marked for ANALYZE after the current transaction is committed.

private ArrayList<ValueLob>
temporaryLobs

The temporary LOBs that need to be removed on commit.

private LinkedList<SessionLocal.TimeoutValue>
temporaryResultLobs

Temporary LOBs from result sets.

private static final ThreadLocal<Session>
THREAD_LOCAL_SESSION

Thread local session for comparison operations between different data types.

private int
private TimeZoneProvider
private Trace
private Transaction
private boolean
truncateLargeLength

Whether length in definitions of data types is truncated.

private User
private boolean
variableBinary

Whether BINARY is parsed as VARBINARY.

private HashMap<String, Value>
private volatile SmallLRUCache<Object, QueryExpressionIndex>
private Table
private Thread
Inherited from org.h2.engine.Session:
sessionStateChangedstaticSettings

Constructor Summary

AccessConstructor and Description
public
SessionLocal(Database database, User user, int id)

Method Summary

Modifier and TypeMethod and Description
public void
addLocalTempTable(Table
the table to add
table
)

Add a local temporary table to this session.

public void
addLocalTempTableConstraint(Constraint
the constraint to add
constraint
)

Add a local temporary constraint to this session.

public void
addLocalTempTableIndex(Index
the index to add
index
)

Add a local temporary index to this session.

public void
addProcedure(Procedure
the procedure to add
procedure
)

Add a procedure to this session.

public void
addSavepoint(String
the savepoint name
name
)

Create a savepoint that is linked to the current log position.

private static void
private static void
public ValueLob
addTemporaryLob(ValueLob
the value
v
)

Implements abstract org.h2.engine.Session.addTemporaryLob.

Add a temporary LOB, which is closed when the session commits.

private void
public boolean

Returns:

true if both objects are equal
areEqual
(Value
the first value
a
,
Value
the second value
b
)

Check if two values are equal with the current comparison mode.

private void
public void
begin()

Begin a transaction.

public void
cancel()

Implements abstract org.h2.engine.Session.cancel.

Cancel the current or next command (called when closing a connection).

public void
checkCanceled()

Check if the current transaction is canceled by calling Statement.cancel() or because a session timeout was set and expired.

private boolean
private void
cleanTempTables(boolean closeSession)

public void
clearViewIndexCache()

Clear the view cache for this session.

public void
close()

Implements abstract org.h2.engine.Session.close.

Implements java.lang.AutoCloseable.close.

Roll back pending transactions and close the session.

public void
commit(boolean
if the statement was a data definition statement
ddl
)

Commit the current transaction.

public int

Returns:

0 if both values are equal, -1 if the first value is smaller, and 1 otherwise
compare
(Value
the first value
a
,
Value
the second value
b
)

Compare two values with the current comparison mode.

public int

Returns:

0 if both values are equal, -1 if the first value is smaller, and 1 otherwise
compareTypeSafe
(Value
the first value
a
,
Value
the second value
b
)

Compare two values with the current comparison mode.

public int

Returns:

0 if both values are equal, -1 if the first value is smaller, 1 if the second value is larger, Integer#MIN_VALUE if order is not defined due to NULL comparison
compareWithNull
(Value
the first value
a
,
Value
the second value
b
,
boolean
perform only check for equality (= or <>)
forEquality
)

Compare two values with the current comparison mode.

public boolean

Returns:

true if yes
containsUncommitted
()

Whether the session contains any uncommitted changes.

public JdbcConnection

Returns:

the internal connection
createConnection
(boolean
if the url should be 'jdbc:columnlist:connection'
columnList
)

Create an internal connection.

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.

public void
endStatement()

Mark the statement as completed.

private void
public Table

Returns:

the table, or null
findLocalTempTable
(String
the table name
name
)

Get the local temporary table if one exists with that name, or null if not.

public Constraint

Returns:

the constraint, or null
findLocalTempTableConstraint
(String
the constraint name
name
)

Get the local temporary constraint if one exists with that name, or null if not.

public Index

Returns:

the table, or null
findLocalTempTableIndex
(String
the table name
name
)

Get the local temporary index if one exists with that name, or null if not.

public boolean
public boolean
getAutoCommit()

Implements abstract org.h2.engine.Session.getAutoCommit.

Check if this session is in auto-commit mode.

public int
public long

Returns:

the time or 0 if not set
getCancel
()

Get the cancel time.

public ArrayList<String>
getClusterServers()

Implements abstract org.h2.engine.Session.getClusterServers.

Get the list of the cluster servers for this session.

public ValueTimestampTimeZone
private CompareMode
public Command
public String
getCurrentSchemaName()

Implements abstract org.h2.engine.Session.getCurrentSchemaName.

Get current schema.

public Value

Returns:

the current value of the sequence in this session
getCurrentValueFor
(Sequence
the sequence
sequence
)

Returns the current value of the sequence in this session.

public Database
public DatabaseMeta
getDatabaseMeta()

Implements abstract org.h2.engine.Session.getDatabaseMeta.

Returns database meta information.

public DataHandler
getDataHandler()

Implements abstract org.h2.engine.Session.getDataHandler.

Get the data handler object.

public Session.DynamicSettings
getDynamicSettings()

Implements abstract org.h2.engine.Session.getDynamicSettings.

Returns dynamic settings.

public int
public IsolationLevel
getIsolationLevel()

Implements abstract org.h2.engine.Session.getIsolationLevel.

Returns the isolation level.

public JavaObjectSerializer
getJavaObjectSerializer()

Implements org.h2.engine.CastDataProvider.getJavaObjectSerializer.

Returns the custom Java object serializer, or null.

public Value
public HashMap<String, Constraint>

Returns:

the map of constraints, or null
getLocalTempTableConstraints
()

Get the map of constraints for all constraints on local, temporary tables, if any.

public HashMap<String, Index>
public List<Table>
public Set<Table>
public int
public Mode
getMode()

Implements org.h2.engine.CastDataProvider.getMode.

Returns the database mode.

public int
public NetworkConnectionInfo

Returns:

the network connection information, or null
getNetworkConnectionInfo
()

Returns the network connection information, or null.

public String

Returns:

the new identifier
getNextSystemIdentifier
(String
the SQL statement
sql
)

Get the next system generated identifiers.

public Value

Returns:

the next value of the sequence in this session
getNextValueFor
(Sequence
the sequence
sequence
,
Prepared
current prepared command, select, or null
prepared
)

Returns the next value of the sequence in this session.

public BitSet

Returns:

set of non-keywords, or null
getNonKeywords
()

Gets bit set of non-keywords.

public Procedure

Returns:

the procedure or null
getProcedure
(String
the procedure name
name
)

Get the procedure with the given name, or null if none exists.

public int
public Random
public String[]
public ValueTimestampTimeZone
public long

Returns:

the data modification id of transaction's snapshot, or 0
getSnapshotDataModificationId
()

Returns the data modification id of transaction's snapshot, or 0 if isolation level doesn't use snapshots.

public SessionLocal.State
public long

Returns:

database data modification id on start of the current command
getStatementModificationDataId
()

Returns database data modification id on start of the current command.

private long
public Session.StaticSettings
getStaticSettings()

Implements abstract org.h2.engine.Session.getStaticSettings.

Returns static settings.

pack-priv static Session
public Trace
getTrace()

Implements abstract org.h2.engine.Session.getTrace.

Get the trace object

public Transaction

Returns:

the transaction
getTransaction
()

Get the transaction to use for this session.

public Value
public User
public Value

Returns:

the value, or NULL
getVariable
(String
the variable name
name
)

Get the value of the specified user defined variable.

public String[]

Returns:

the list of names
getVariableNames
()

Get the list of variable names that are set for this session.

public Map<Object, QueryExpressionIndex>

Returns:

the view cache or derived table cache
getViewIndexCache
(boolean
true to get the cache of derived tables
derivedTable
)

Get the view cache for this session.

public Table
public Thread
public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.

public boolean
hasPendingTransaction()

Implements abstract org.h2.engine.Session.hasPendingTransaction.

Check whether this session has a pending transaction.

public boolean

Returns:

true if there is a prepared transaction, false otherwise
hasPreparedTransaction
()

Checks presence of prepared transaction in this session.

private boolean
private void
public boolean
isClosed()

Implements abstract org.h2.engine.Session.isClosed.

Check if close was called.

public boolean
public boolean
isOldInformationSchema()

Implements abstract org.h2.engine.Session.isOldInformationSchema.

Returns whether INFORMATION_SCHEMA contains old-style tables.

public boolean
public boolean
public boolean

Returns:

true if database is starting or quirks mode was enabled explicitly, false otherwise
isQuirksMode
()

Returns whether quirks mode is enabled explicitly or implicitly.

public boolean
isRemote()

Implements abstract org.h2.engine.Session.isRemote.

Check if this session is remote or embedded.

public boolean

Returns:

true if large length is truncated, false if an exception is thrown
isTruncateLargeLength
()

Returns parsing mode of data types with too large length.

public boolean

Returns:

true if BINARY should be parsed as VARBINARY, false if it should be parsed as is
isVariableBinary
()

Returns BINARY data type parsing mode.

public void
markTableForAnalyze(Table
the table
table
)

Mark that the given table needs to be analyzed on commit.

private void
private <T> HashMap<String, T>
public int

Returns:

the next object id
nextObjectId
()

Get the next object id.

public void
onRollback(MVMap<Object, VersionedValue<Object>>
modified
map
,
Object
of the modified entry
key
,
VersionedValue<Object>
value in the map (null if delete is rolled back)
existingValue
,
VersionedValue<Object>
value to be restored (null if add is rolled back)
restoredValue
)

Implements org.h2.mvstore.tx.TransactionStore.RollbackListener.onRollback.

Notified of a single map change (add/update/remove)

public Prepared

Returns:

the prepared statement
prepare
(String
the SQL statement
sql
)

Parse and prepare the given SQL statement.

public Prepared

Returns:

the prepared statement
prepare
(String
the SQL statement
sql
,
boolean
true if the rights have already been checked
rightsChecked
,
boolean
true if the sql string has already been checked for literals (only used if ALLOW_LITERALS NONE is set).
literalsChecked
,
QueryScope
the scope of this query, or null
queryScope
)

Parse and prepare the given SQL statement.

public CommandInterface
prepareCommand(String
the SQL statement
sql
,
int
the number of rows to fetch in one step
fetchSize
)

Implements abstract org.h2.engine.Session.prepareCommand.

Parse a command and prepare it for execution.

public void
prepareCommit(String
the name of the transaction
transactionName
)

Prepare the given transaction.

public Command

Returns:

the prepared statement
prepareLocal
(String
the SQL statement
sql
)

Parse and prepare the given SQL statement.

public Query

Returns:

the prepared statement
prepareQueryExpression
(String
the SQL statement
sql
,
QueryScope
the scope of this query, or null
queryScope
)

Parse a query and prepare its expressions.

public void
registerTableAsLocked(Table
the table that is locked
table
)

Register table as locked within current transaction.

public void
registerTableAsUpdated(Table
to register
table
)

Register table as updated within current transaction.

public void
removeAtCommit(ValueLob
the value
v
)

Remember that the given LOB value must be removed at commit.

public void
removeAtCommitStop(ValueLob
the value
v
)

Do not remove this LOB value at commit any longer.

public void
removeLocalTempTable(Table
the table
table
)

Drop and remove the given local temporary table from this session.

pack-priv void
removeLocalTempTableConstraint(Constraint
the constraint
constraint
)

Drop and remove the given local temporary constraint from this session.

public void
removeLocalTempTableIndex(Index
the index
index
)

Drop and remove the given local temporary index from this session.

public void
removeProcedure(String
the name of the procedure to remove
name
)

Remove a procedure from this session.

private void
removeTemporaryLobs(boolean onTimeout)

public void
resetThreadLocalSession(Session
the old thread local session, or null
oldSession
)

Overrides org.h2.engine.Session.resetThreadLocalSession.

Resets old thread local session.

public void
rollback()

Fully roll back the current transaction.

public void
rollbackTo(SessionLocal.Savepoint
the savepoint to which should be rolled back
savepoint
)

Partially roll back the current transaction.

public void
rollbackToSavepoint(String
the savepoint name
name
)

Undo all operations back to the log position of the given savepoint.

pack-priv void
scheduleDatabaseObjectIdForRelease(int
to be scheduled
id
)

Arranges for the specified database object id to be released at the end of the current transaction.

public void
setAllowLiterals(boolean b)

public void
setAutoCommit(boolean
the new value
b
)

Implements abstract org.h2.engine.Session.setAutoCommit.

Set the auto-commit mode.

public boolean
private void
setCurrentCommand(Command
the command
command
)

Set the current command of this session.

public void
public void
setCurrentSchemaName(String
the schema name
schemaName
)

Implements abstract org.h2.engine.Session.setCurrentSchemaName.

Set current schema.

public void
setIsolationLevel(IsolationLevel
the isolation level to set
isolationLevel
)

Implements abstract org.h2.engine.Session.setIsolationLevel.

Sets the isolation level.

public void
public void
setLazyQueryExecution(boolean lazyQueryExecution)

public void
setLockTimeout(int lockTimeout)

public void
setNetworkConnectionInfo(NetworkConnectionInfo
the network connection information
networkConnectionInfo
)

Implements abstract org.h2.engine.Session.setNetworkConnectionInfo.

Sets the network connection information if possible.

public void
setNonKeywords(BitSet
set of non-keywords, or null
nonKeywords
)

Sets bit set of non-keywords.

public void
setOldInformationSchema(boolean
true to have old-style tables in INFORMATION_SCHEMA, false to have modern tables
oldInformationSchema
)

Changes INFORMATION_SCHEMA content.

public void
setParsingCreateView(boolean
true if this method is called before parsing of view definition, false if it is called after it.
parsingView
)

This method is called before and after parsing of view definition and may be called recursively.

public void
setPreparedTransaction(String
the name of the transaction
transactionName
,
boolean
true for commit, false for rollback
commit
)

Commit or roll back the given transaction.

public void
setQueryTimeout(int queryTimeout)

public void
setQuirksMode(boolean
whether quirks mode should be enabled
quirksMode
)

Enables or disables the quirks mode.

public SessionLocal.Savepoint

Returns:

the savepoint
setSavepoint
()

Create a savepoint to allow rolling back to this state.

public void
public Session
setThreadLocalSession()

Overrides org.h2.engine.Session.setThreadLocalSession.

Sets this session as thread local session, if this session is a local session.

public void
setThrottle(int throttle)

public void
setTimeZone(TimeZoneProvider
time zone
timeZone
)

Sets current time zone.

public void
setTruncateLargeLength(boolean
true to truncate to valid bound, false to throw an exception
truncateLargeLength
)

Changes parsing mode of data types with too large length.

public void
setVariable(String
the name of the variable (may not be null)
name
,
Value
the new value (may not be null)
value
)

Set the value of the given variable for this session.

public void
setVariableBinary(boolean
true to parse BINARY as VARBINARY, false to parse it as is
variableBinary
)

Changes parsing of a BINARY data type.

public void
setWaitForLock(Table
the table
waitForLock
,
Thread
the current thread (the one that is waiting)
waitForLockThread
)

Set the table this session is waiting for, and the thread that is waiting.

public void
startStatementWithinTransaction(Command
about to be started
command
)

Start a new statement within a transaction.

pack-priv void
suspend()

Cancel the transaction and close the session if needed.

public void
throttle()

Wait for some time if this session is throttled (slowed down).

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

private SessionLocal.State
transitionToState(SessionLocal.State targetState, boolean checkSuspended)

pack-priv void
unlock(Table
the table to unlock
t
)

Unlock just this table.

private void
public void
waitIfExclusiveModeEnabled()

Wait if the exclusive mode has been enabled for another session.

public boolean
zeroBasedEnums()

Implements org.h2.engine.CastDataProvider.zeroBasedEnums.

Returns are ENUM values 0-based.

Inherited from org.h2.engine.Session:
isLockedByCurrentThreadlockreadSessionStaterecreateSessionStateunlock