Package org.h2.engine
Class SessionLocal
- java.lang.Object
-
- org.h2.engine.Session
-
- org.h2.engine.SessionLocal
-
- All Implemented Interfaces:
java.lang.AutoCloseable,CastDataProvider,TransactionStore.RollbackListener
public final class SessionLocal extends Session implements TransactionStore.RollbackListener
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 Class Summary
Nested Classes Modifier and Type Class Description private static classSessionLocal.RowNumberAndValuestatic classSessionLocal.SavepointRepresents a savepoint (a position in a transaction to where one can roll back to).private static classSessionLocal.SequenceAndPreparedstatic classSessionLocal.Statestatic classSessionLocal.TimeoutValueAn LOB object with a timeout.-
Nested classes/interfaces inherited from class org.h2.engine.Session
Session.DynamicSettings, Session.StaticSettings
-
-
Field Summary
Fields Modifier and Type Field Description private booleanallowLiteralsprivate booleanautoCommitprivate booleanautoCommitAtTransactionEndprivate longcancelAtNsprivate java.time.InstantcommandStartOrEndprivate booleancommitOrRollbackDisabledprivate intcreateViewLevelprivate CommandcurrentCommandprivate java.lang.StringcurrentSchemaNameprivate ValueTimestampTimeZonecurrentTimestampprivate java.lang.StringcurrentTransactionNameprivate java.util.WeakHashMap<Sequence,Value>currentValueForprivate Databasedatabaseprivate intidprivate java.util.BitSetidsToReleaseSet of database object ids to be released at the end of transactionprivate IsolationLevelisolationLevelIsolation level.private ValuelastIdentityprivate longlastThrottleNsprivate booleanlazyQueryExecutionprivate java.util.HashMap<java.lang.String,Constraint>localTempTableConstraintsprivate java.util.HashMap<java.lang.String,Index>localTempTableIndexesprivate java.util.HashMap<java.lang.String,Table>localTempTablesprivate java.util.ArrayList<Table>locksprivate intlockTimeoutprivate intmodificationIdprivate longmodificationMetaIDprivate NetworkConnectionInfonetworkConnectionInfoprivate static intnextSerialIdprivate java.util.HashMap<SessionLocal.SequenceAndPrepared,SessionLocal.RowNumberAndValue>nextValueForprivate java.util.BitSetnonKeywordsprivate intobjectIdprivate booleanoldInformationSchemaWhether INFORMATION_SCHEMA contains old-style tables.private java.util.HashMap<java.lang.String,Procedure>proceduresprivate SmallLRUCache<java.lang.String,Command>queryCacheprivate intqueryCacheSizeprivate intqueryTimeoutprivate booleanquirksModeWhether commands are executed in quirks mode to support scripts from older versions of H2.private java.util.Randomrandomprivate java.util.HashMap<java.lang.String,ValueLob>removeLobMapprivate java.util.HashMap<java.lang.String,SessionLocal.Savepoint>savepointsprivate java.lang.String[]schemaSearchPathprivate intserialIdprivate ValueTimestampTimeZonesessionStartprivate longsnapshotDataModificationIdThe snapshot data modification id.private longstartStatementprivate java.util.concurrent.atomic.AtomicReference<SessionLocal.State>stateprivate java.util.HashMap<java.lang.Object,ViewIndex>subQueryIndexCacheprivate static java.lang.StringSYSTEM_IDENTIFIER_PREFIXThe prefix of generated identifiers.private intsystemIdentifierprivate java.util.HashSet<Table>tablesToAnalyzeTables marked for ANALYZE after the current transaction is committed.private java.util.ArrayList<ValueLob>temporaryLobsThe temporary LOBs that need to be removed on commit.private java.util.LinkedList<SessionLocal.TimeoutValue>temporaryResultLobsTemporary LOBs from result sets.private static java.lang.ThreadLocal<Session>THREAD_LOCAL_SESSIONThread local session for comparison operations between different data types.private intthrottleMsprivate TimeZoneProvidertimeZoneprivate Tracetraceprivate Transactiontransactionprivate booleantruncateLargeLengthWhether length in definitions of data types is truncated.private Useruserprivate booleanvariableBinaryWhether BINARY is parsed as VARBINARY.private java.util.HashMap<java.lang.String,Value>variablesprivate SmallLRUCache<java.lang.Object,ViewIndex>viewIndexCacheprivate TablewaitForLockprivate java.lang.ThreadwaitForLockThread-
Fields inherited from class org.h2.engine.Session
sessionStateChanged, staticSettings
-
-
Constructor Summary
Constructors Constructor Description SessionLocal(Database database, User user, int id)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddLocalTempTable(Table table)Add a local temporary table to this session.voidaddLocalTempTableConstraint(Constraint constraint)Add a local temporary constraint to this session.voidaddLocalTempTableIndex(Index index)Add a local temporary index to this session.voidaddProcedure(Procedure procedure)Add a procedure to this session.voidaddSavepoint(java.lang.String name)Create a savepoint that is linked to the current log position.private static voidaddTableToDependencies(MVTable table, java.util.HashSet<MVMap<java.lang.Object,VersionedValue<java.lang.Object>>> maps)private static voidaddTableToDependencies(MVTable table, java.util.HashSet<MVMap<java.lang.Object,VersionedValue<java.lang.Object>>> maps, java.util.HashSet<MVTable> processed)ValueLobaddTemporaryLob(ValueLob v)Add a temporary LOB, which is closed when the session commits.private voidanalyzeTables()booleanareEqual(Value a, Value b)Check if two values are equal with the current comparison mode.private voidbeforeCommitOrRollback()voidbegin()Begin a transaction.voidcancel()Cancel the current or next command (called when closing a connection).voidcheckCanceled()Check if the current transaction is canceled by calling Statement.cancel() or because a session timeout was set and expired.private booleancheckSuspended(SessionLocal.State currentState)private voidcleanTempTables(boolean closeSession)voidclearViewIndexCache()Clear the view cache for this session.voidclose()Roll back pending transactions and close the session.voidcommit(boolean ddl)Commit the current transaction.intcompare(Value a, Value b)Compare two values with the current comparison mode.intcompareTypeSafe(Value a, Value b)Compare two values with the current comparison mode.intcompareWithNull(Value a, Value b, boolean forEquality)Compare two values with the current comparison mode.booleancontainsUncommitted()Whether the session contains any uncommitted changes.JdbcConnectioncreateConnection(boolean columnList)Create an internal connection.ValueTimestampTimeZonecurrentTimestamp()Returns the current timestamp with maximum resolution.TimeZoneProvidercurrentTimeZone()Returns the current time zone.voidendStatement()Mark the statement as completed.private voidendTransaction()TablefindLocalTempTable(java.lang.String name)Get the local temporary table if one exists with that name, or null if not.ConstraintfindLocalTempTableConstraint(java.lang.String name)Get the local temporary constraint if one exists with that name, or null if not.IndexfindLocalTempTableIndex(java.lang.String name)Get the local temporary index if one exists with that name, or null if not.booleangetAllowLiterals()booleangetAutoCommit()Check if this session is in auto-commit mode.intgetBlockingSessionId()longgetCancel()Get the cancel time.java.util.ArrayList<java.lang.String>getClusterServers()Get the list of the cluster servers for this session.ValueTimestampTimeZonegetCommandStartOrEnd()CommandgetCurrentCommand()java.lang.StringgetCurrentSchemaName()Get current schema.ValuegetCurrentValueFor(Sequence sequence)Returns the current value of the sequence in this session.DatabasegetDatabase()DatabaseMetagetDatabaseMeta()Returns database meta information.DataHandlergetDataHandler()Get the data handler object.Session.DynamicSettingsgetDynamicSettings()Returns dynamic settings.intgetId()IsolationLevelgetIsolationLevel()Returns the isolation level.JavaObjectSerializergetJavaObjectSerializer()Returns the custom Java object serializer, ornull.ValuegetLastIdentity()java.util.HashMap<java.lang.String,Constraint>getLocalTempTableConstraints()Get the map of constraints for all constraints on local, temporary tables, if any.java.util.HashMap<java.lang.String,Index>getLocalTempTableIndexes()java.util.List<Table>getLocalTempTables()java.util.Set<Table>getLocks()intgetLockTimeout()ModegetMode()Returns the database mode.intgetModificationId()NetworkConnectionInfogetNetworkConnectionInfo()Returns the network connection information, ornull.java.lang.StringgetNextSystemIdentifier(java.lang.String sql)Get the next system generated identifiers.ValuegetNextValueFor(Sequence sequence, Prepared prepared)Returns the next value of the sequence in this session.java.util.BitSetgetNonKeywords()Gets bit set of non-keywords.ProceduregetProcedure(java.lang.String name)Get the procedure with the given name, or null if none exists.intgetQueryTimeout()java.util.RandomgetRandom()java.lang.String[]getSchemaSearchPath()ValueTimestampTimeZonegetSessionStart()longgetSnapshotDataModificationId()Returns the data modification id of transaction's snapshot, or 0 if isolation level doesn't use snapshots.SessionLocal.StategetState()private longgetStatementSavepoint()Session.StaticSettingsgetStaticSettings()Returns static settings.(package private) static SessiongetThreadLocalSession()TracegetTrace()Get the trace objectTransactiongetTransaction()Get the transaction to use for this session.ValuegetTransactionId()UsergetUser()ValuegetVariable(java.lang.String name)Get the value of the specified user defined variable.java.lang.String[]getVariableNames()Get the list of variable names that are set for this session.java.util.Map<java.lang.Object,ViewIndex>getViewIndexCache(boolean subQuery)Get the view cache for this session.TablegetWaitForLock()java.lang.ThreadgetWaitForLockThread()inthashCode()booleanhasPendingTransaction()Check whether this session has a pending transaction.booleanhasPreparedTransaction()Checks presence of prepared transaction in this session.private booleanhasTransaction()private voidinitVariables()booleanisClosed()Check if close was called.booleanisLazyQueryExecution()booleanisOldInformationSchema()Returns whether INFORMATION_SCHEMA contains old-style tables.booleanisOpen()booleanisParsingCreateView()booleanisQuirksMode()Returns whether quirks mode is enabled explicitly or implicitly.booleanisRemote()Check if this session is remote or embedded.booleanisTruncateLargeLength()Returns parsing mode of data types with too large length.booleanisVariableBinary()Returns BINARY data type parsing mode.voidmarkTableForAnalyze(Table table)Mark that the given table needs to be analyzed on commit.private voidmarkUsedTablesAsUpdated()intnextObjectId()Get the next object id.voidonRollback(MVMap<java.lang.Object,VersionedValue<java.lang.Object>> map, java.lang.Object key, VersionedValue<java.lang.Object> existingValue, VersionedValue<java.lang.Object> restoredValue)Notified of a single map change (add/update/remove)Preparedprepare(java.lang.String sql)Parse and prepare the given SQL statement.Preparedprepare(java.lang.String sql, boolean rightsChecked, boolean literalsChecked)Parse and prepare the given SQL statement.CommandInterfaceprepareCommand(java.lang.String sql, int fetchSize)Parse a command and prepare it for execution.voidprepareCommit(java.lang.String transactionName)Prepare the given transaction.CommandprepareLocal(java.lang.String sql)Parse and prepare the given SQL statement.voidregisterTableAsLocked(Table table)Register table as locked within current transaction.voidregisterTableAsUpdated(Table table)Register table as updated within current transaction.voidremoveAtCommit(ValueLob v)Remember that the given LOB value must be removed at commit.voidremoveAtCommitStop(ValueLob v)Do not remove this LOB value at commit any longer.voidremoveLocalTempTable(Table table)Drop and remove the given local temporary table from this session.(package private) voidremoveLocalTempTableConstraint(Constraint constraint)Drop and remove the given local temporary constraint from this session.voidremoveLocalTempTableIndex(Index index)Drop and remove the given local temporary index from this session.voidremoveProcedure(java.lang.String name)Remove a procedure from this session.private voidremoveTemporaryLobs(boolean onTimeout)voidresetThreadLocalSession(Session oldSession)Resets old thread local session.voidrollback()Fully roll back the current transaction.voidrollbackTo(SessionLocal.Savepoint savepoint)Partially roll back the current transaction.voidrollbackToSavepoint(java.lang.String name)Undo all operations back to the log position of the given savepoint.protected voidscheduleDatabaseObjectIdForRelease(int id)Arranges for the specified database object id to be released at the end of the current transaction.voidsetAllowLiterals(boolean b)voidsetAutoCommit(boolean b)Set the auto-commit mode.booleansetCommitOrRollbackDisabled(boolean x)private voidsetCurrentCommand(Command command)Set the current command of this session.voidsetCurrentSchema(Schema schema)voidsetCurrentSchemaName(java.lang.String schemaName)Set current schema.voidsetIsolationLevel(IsolationLevel isolationLevel)Sets the isolation level.voidsetLastIdentity(Value last)voidsetLazyQueryExecution(boolean lazyQueryExecution)voidsetLockTimeout(int lockTimeout)voidsetNetworkConnectionInfo(NetworkConnectionInfo networkConnectionInfo)Sets the network connection information if possible.voidsetNonKeywords(java.util.BitSet nonKeywords)Sets bit set of non-keywords.voidsetOldInformationSchema(boolean oldInformationSchema)Changes INFORMATION_SCHEMA content.voidsetParsingCreateView(boolean parsingView)This method is called before and after parsing of view definition and may be called recursively.voidsetPreparedTransaction(java.lang.String transactionName, boolean commit)Commit or roll back the given transaction.voidsetQueryTimeout(int queryTimeout)voidsetQuirksMode(boolean quirksMode)Enables or disables the quirks mode.SessionLocal.SavepointsetSavepoint()Create a savepoint to allow rolling back to this state.voidsetSchemaSearchPath(java.lang.String[] schemas)SessionsetThreadLocalSession()Sets this session as thread local session, if this session is a local session.voidsetThrottle(int throttle)voidsetTimeZone(TimeZoneProvider timeZone)Sets current time zone.voidsetTruncateLargeLength(boolean truncateLargeLength)Changes parsing mode of data types with too large length.voidsetVariable(java.lang.String name, Value value)Set the value of the given variable for this session.voidsetVariableBinary(boolean variableBinary)Changes parsing of a BINARY data type.voidsetWaitForLock(Table waitForLock, java.lang.Thread waitForLockThread)Set the table this session is waiting for, and the thread that is waiting.voidstartStatementWithinTransaction(Command command)Start a new statement within a transaction.(package private) voidsuspend()Cancel the transaction and close the session if needed.voidthrottle()Wait for some time if this session is throttled (slowed down).java.lang.StringtoString()private SessionLocal.StatetransitionToState(SessionLocal.State targetState, boolean checkSuspended)(package private) voidunlock(Table t)Unlock just this table.private voidunlockAll()voidwaitIfExclusiveModeEnabled()Wait if the exclusive mode has been enabled for another session.booleanzeroBasedEnums()Returns are ENUM values 0-based.-
Methods inherited from class org.h2.engine.Session
readSessionState, recreateSessionState
-
-
-
-
Field Detail
-
SYSTEM_IDENTIFIER_PREFIX
private static final java.lang.String SYSTEM_IDENTIFIER_PREFIX
The prefix of generated identifiers. It may not have letters, because they are case sensitive.- See Also:
- Constant Field Values
-
nextSerialId
private static int nextSerialId
-
THREAD_LOCAL_SESSION
private static final java.lang.ThreadLocal<Session> THREAD_LOCAL_SESSION
Thread local session for comparison operations between different data types.
-
serialId
private final int serialId
-
database
private final Database database
-
user
private final User user
-
id
private final int id
-
networkConnectionInfo
private NetworkConnectionInfo networkConnectionInfo
-
locks
private final java.util.ArrayList<Table> locks
-
autoCommit
private boolean autoCommit
-
random
private java.util.Random random
-
lockTimeout
private int lockTimeout
-
nextValueFor
private java.util.HashMap<SessionLocal.SequenceAndPrepared,SessionLocal.RowNumberAndValue> nextValueFor
-
lastIdentity
private Value lastIdentity
-
savepoints
private java.util.HashMap<java.lang.String,SessionLocal.Savepoint> savepoints
-
localTempTables
private java.util.HashMap<java.lang.String,Table> localTempTables
-
localTempTableIndexes
private java.util.HashMap<java.lang.String,Index> localTempTableIndexes
-
localTempTableConstraints
private java.util.HashMap<java.lang.String,Constraint> localTempTableConstraints
-
throttleMs
private int throttleMs
-
lastThrottleNs
private long lastThrottleNs
-
currentCommand
private Command currentCommand
-
allowLiterals
private boolean allowLiterals
-
currentSchemaName
private java.lang.String currentSchemaName
-
schemaSearchPath
private java.lang.String[] schemaSearchPath
-
trace
private Trace trace
-
removeLobMap
private java.util.HashMap<java.lang.String,ValueLob> removeLobMap
-
systemIdentifier
private int systemIdentifier
-
procedures
private java.util.HashMap<java.lang.String,Procedure> procedures
-
autoCommitAtTransactionEnd
private boolean autoCommitAtTransactionEnd
-
currentTransactionName
private java.lang.String currentTransactionName
-
cancelAtNs
private volatile long cancelAtNs
-
sessionStart
private final ValueTimestampTimeZone sessionStart
-
commandStartOrEnd
private java.time.Instant commandStartOrEnd
-
currentTimestamp
private ValueTimestampTimeZone currentTimestamp
-
variables
private java.util.HashMap<java.lang.String,Value> variables
-
queryTimeout
private int queryTimeout
-
commitOrRollbackDisabled
private boolean commitOrRollbackDisabled
-
waitForLock
private Table waitForLock
-
waitForLockThread
private java.lang.Thread waitForLockThread
-
modificationId
private int modificationId
-
objectId
private int objectId
-
queryCacheSize
private final int queryCacheSize
-
queryCache
private SmallLRUCache<java.lang.String,Command> queryCache
-
modificationMetaID
private long modificationMetaID
-
createViewLevel
private int createViewLevel
-
viewIndexCache
private volatile SmallLRUCache<java.lang.Object,ViewIndex> viewIndexCache
-
subQueryIndexCache
private java.util.HashMap<java.lang.Object,ViewIndex> subQueryIndexCache
-
lazyQueryExecution
private boolean lazyQueryExecution
-
nonKeywords
private java.util.BitSet nonKeywords
-
timeZone
private TimeZoneProvider timeZone
-
tablesToAnalyze
private java.util.HashSet<Table> tablesToAnalyze
Tables marked for ANALYZE after the current transaction is committed. Prevents us calling ANALYZE repeatedly in large transactions.
-
temporaryResultLobs
private java.util.LinkedList<SessionLocal.TimeoutValue> temporaryResultLobs
Temporary LOBs from result sets. Those are kept for some time. The problem is that transactions are committed before the result is returned, and in some cases the next transaction is already started before the result is read (for example when using the server mode, when accessing metadata methods). We can't simply free those values up when starting the next transaction, because they would be removed too early.
-
temporaryLobs
private java.util.ArrayList<ValueLob> temporaryLobs
The temporary LOBs that need to be removed on commit.
-
transaction
private Transaction transaction
-
state
private final java.util.concurrent.atomic.AtomicReference<SessionLocal.State> state
-
startStatement
private long startStatement
-
isolationLevel
private IsolationLevel isolationLevel
Isolation level.
-
snapshotDataModificationId
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. After commit or rollback these snapshots are discarded and cached results of queries may became invalid. Commit and rollback allocate a new data modification id and store it here to forbid usage of older results.
-
idsToRelease
private java.util.BitSet idsToRelease
Set of database object ids to be released at the end of transaction
-
truncateLargeLength
private boolean truncateLargeLength
Whether length in definitions of data types is truncated.
-
variableBinary
private boolean variableBinary
Whether BINARY is parsed as VARBINARY.
-
oldInformationSchema
private boolean oldInformationSchema
Whether INFORMATION_SCHEMA contains old-style tables.
-
quirksMode
private boolean quirksMode
Whether commands are executed in quirks mode to support scripts from older versions of H2.
-
-
Method Detail
-
getThreadLocalSession
static Session getThreadLocalSession()
-
setLazyQueryExecution
public void setLazyQueryExecution(boolean lazyQueryExecution)
-
isLazyQueryExecution
public boolean isLazyQueryExecution()
-
setParsingCreateView
public void setParsingCreateView(boolean parsingView)
This method is called before and after parsing of view definition and may be called recursively.- Parameters:
parsingView-trueif this method is called before parsing of view definition,falseif it is called after it.
-
isParsingCreateView
public boolean isParsingCreateView()
-
getClusterServers
public java.util.ArrayList<java.lang.String> getClusterServers()
Description copied from class:SessionGet the list of the cluster servers for this session.- Specified by:
getClusterServersin classSession- Returns:
- A list of "ip:port" strings for the cluster servers in this session.
-
setCommitOrRollbackDisabled
public boolean setCommitOrRollbackDisabled(boolean x)
-
initVariables
private void initVariables()
-
setVariable
public void setVariable(java.lang.String name, Value value)Set the value of the given variable for this session.- Parameters:
name- the name of the variable (may not be null)value- the new value (may not be null)
-
getVariable
public Value getVariable(java.lang.String name)
Get the value of the specified user defined variable. This method always returns a value; it returns ValueNull.INSTANCE if the variable doesn't exist.- Parameters:
name- the variable name- Returns:
- the value, or NULL
-
getVariableNames
public java.lang.String[] getVariableNames()
Get the list of variable names that are set for this session.- Returns:
- the list of names
-
findLocalTempTable
public Table findLocalTempTable(java.lang.String name)
Get the local temporary table if one exists with that name, or null if not.- Parameters:
name- the table name- Returns:
- the table, or null
-
getLocalTempTables
public java.util.List<Table> getLocalTempTables()
-
addLocalTempTable
public void addLocalTempTable(Table table)
Add a local temporary table to this session.- Parameters:
table- the table to add- Throws:
DbException- if a table with this name already exists
-
removeLocalTempTable
public void removeLocalTempTable(Table table)
Drop and remove the given local temporary table from this session.- Parameters:
table- the table
-
findLocalTempTableIndex
public Index findLocalTempTableIndex(java.lang.String name)
Get the local temporary index if one exists with that name, or null if not.- Parameters:
name- the table name- Returns:
- the table, or null
-
getLocalTempTableIndexes
public java.util.HashMap<java.lang.String,Index> getLocalTempTableIndexes()
-
addLocalTempTableIndex
public void addLocalTempTableIndex(Index index)
Add a local temporary index to this session.- Parameters:
index- the index to add- Throws:
DbException- if a index with this name already exists
-
removeLocalTempTableIndex
public void removeLocalTempTableIndex(Index index)
Drop and remove the given local temporary index from this session.- Parameters:
index- the index
-
findLocalTempTableConstraint
public Constraint findLocalTempTableConstraint(java.lang.String name)
Get the local temporary constraint if one exists with that name, or null if not.- Parameters:
name- the constraint name- Returns:
- the constraint, or null
-
getLocalTempTableConstraints
public java.util.HashMap<java.lang.String,Constraint> getLocalTempTableConstraints()
Get the map of constraints for all constraints on local, temporary tables, if any. The map's keys are the constraints' names.- Returns:
- the map of constraints, or null
-
addLocalTempTableConstraint
public void addLocalTempTableConstraint(Constraint constraint)
Add a local temporary constraint to this session.- Parameters:
constraint- the constraint to add- Throws:
DbException- if a constraint with the same name already exists
-
removeLocalTempTableConstraint
void removeLocalTempTableConstraint(Constraint constraint)
Drop and remove the given local temporary constraint from this session.- Parameters:
constraint- the constraint
-
getAutoCommit
public boolean getAutoCommit()
Description copied from class:SessionCheck if this session is in auto-commit mode.- Specified by:
getAutoCommitin classSession- Returns:
- true if the session is in auto-commit mode
-
getUser
public User getUser()
-
setAutoCommit
public void setAutoCommit(boolean b)
Description copied from class:SessionSet the auto-commit mode. This call doesn't commit the current transaction.- Specified by:
setAutoCommitin classSession- Parameters:
b- the new value
-
getLockTimeout
public int getLockTimeout()
-
setLockTimeout
public void setLockTimeout(int lockTimeout)
-
prepareCommand
public CommandInterface prepareCommand(java.lang.String sql, int fetchSize)
Description copied from class:SessionParse a command and prepare it for execution.- Specified by:
prepareCommandin classSession- Parameters:
sql- the SQL statementfetchSize- the number of rows to fetch in one step- Returns:
- the prepared command
-
prepare
public Prepared prepare(java.lang.String sql)
Parse and prepare the given SQL statement. This method also checks the rights.- Parameters:
sql- the SQL statement- Returns:
- the prepared statement
-
prepare
public Prepared prepare(java.lang.String sql, boolean rightsChecked, boolean literalsChecked)
Parse and prepare the given SQL statement.- Parameters:
sql- the SQL statementrightsChecked- true if the rights have already been checkedliteralsChecked- true if the sql string has already been checked for literals (only used if ALLOW_LITERALS NONE is set).- Returns:
- the prepared statement
-
prepareLocal
public Command prepareLocal(java.lang.String sql)
Parse and prepare the given SQL statement. This method also checks if the connection has been closed.- Parameters:
sql- the SQL statement- Returns:
- the prepared statement
-
scheduleDatabaseObjectIdForRelease
protected void scheduleDatabaseObjectIdForRelease(int id)
Arranges for the specified database object id to be released at the end of the current transaction.- Parameters:
id- to be scheduled
-
getDatabase
public Database getDatabase()
-
commit
public void commit(boolean ddl)
Commit the current transaction. If the statement was not a data definition statement, and if there are temporary tables that should be dropped or truncated at commit, this is done as well.- Parameters:
ddl- if the statement was a data definition statement
-
markUsedTablesAsUpdated
private void markUsedTablesAsUpdated()
-
analyzeTables
private void analyzeTables()
-
removeTemporaryLobs
private void removeTemporaryLobs(boolean onTimeout)
-
beforeCommitOrRollback
private void beforeCommitOrRollback()
-
endTransaction
private void endTransaction()
-
getSnapshotDataModificationId
public long getSnapshotDataModificationId()
Returns the data modification id of transaction's snapshot, or 0 if isolation level doesn't use snapshots.- Returns:
- the data modification id of transaction's snapshot, or 0
-
rollback
public void rollback()
Fully roll back the current transaction.
-
rollbackTo
public void rollbackTo(SessionLocal.Savepoint savepoint)
Partially roll back the current transaction.- Parameters:
savepoint- the savepoint to which should be rolled back
-
hasPendingTransaction
public boolean hasPendingTransaction()
Description copied from class:SessionCheck whether this session has a pending transaction.- Specified by:
hasPendingTransactionin classSession- Returns:
- true if it has
-
setSavepoint
public SessionLocal.Savepoint setSavepoint()
Create a savepoint to allow rolling back to this state.- Returns:
- the savepoint
-
getId
public int getId()
-
cancel
public void cancel()
Description copied from class:SessionCancel the current or next command (called when closing a connection).
-
suspend
void suspend()
Cancel the transaction and close the session if needed.
-
close
public void close()
Description copied from class:SessionRoll back pending transactions and close the session.
-
registerTableAsLocked
public void registerTableAsLocked(Table table)
Register table as locked within current transaction. Table is unlocked on commit or rollback. It also assumes that table will be modified by transaction.- Parameters:
table- the table that is locked
-
registerTableAsUpdated
public void registerTableAsUpdated(Table table)
Register table as updated within current transaction. This is used instead of table locking when lock mode is LOCK_MODE_OFF.- Parameters:
table- to register
-
unlock
void unlock(Table t)
Unlock just this table.- Parameters:
t- the table to unlock
-
hasTransaction
private boolean hasTransaction()
-
unlockAll
private void unlockAll()
-
cleanTempTables
private void cleanTempTables(boolean closeSession)
-
getRandom
public java.util.Random getRandom()
-
getNextValueFor
public Value getNextValueFor(Sequence sequence, Prepared prepared)
Returns the next value of the sequence in this session.- Parameters:
sequence- the sequenceprepared- current prepared command, select, ornull- Returns:
- the next value of the sequence in this session
-
getCurrentValueFor
public Value getCurrentValueFor(Sequence sequence)
Returns the current value of the sequence in this session.- Parameters:
sequence- the sequence- Returns:
- the current value of the sequence in this session
- Throws:
DbException- if current value is not defined
-
setLastIdentity
public void setLastIdentity(Value last)
-
getLastIdentity
public Value getLastIdentity()
-
containsUncommitted
public boolean containsUncommitted()
Whether the session contains any uncommitted changes.- Returns:
- true if yes
-
addSavepoint
public void addSavepoint(java.lang.String name)
Create a savepoint that is linked to the current log position.- Parameters:
name- the savepoint name
-
rollbackToSavepoint
public void rollbackToSavepoint(java.lang.String name)
Undo all operations back to the log position of the given savepoint.- Parameters:
name- the savepoint name
-
prepareCommit
public void prepareCommit(java.lang.String transactionName)
Prepare the given transaction.- Parameters:
transactionName- the name of the transaction
-
hasPreparedTransaction
public boolean hasPreparedTransaction()
Checks presence of prepared transaction in this session.- Returns:
trueif there is a prepared transaction,falseotherwise
-
setPreparedTransaction
public void setPreparedTransaction(java.lang.String transactionName, boolean commit)Commit or roll back the given transaction.- Parameters:
transactionName- the name of the transactioncommit- true for commit, false for rollback
-
isClosed
public boolean isClosed()
Description copied from class:SessionCheck if close was called.
-
isOpen
public boolean isOpen()
-
setThrottle
public void setThrottle(int throttle)
-
throttle
public void throttle()
Wait for some time if this session is throttled (slowed down).
-
setCurrentCommand
private void setCurrentCommand(Command command)
Set the current command of this session. This is done just before executing the statement.- Parameters:
command- the command
-
transitionToState
private SessionLocal.State transitionToState(SessionLocal.State targetState, boolean checkSuspended)
-
checkSuspended
private boolean checkSuspended(SessionLocal.State currentState)
-
checkCanceled
public void checkCanceled()
Check if the current transaction is canceled by calling Statement.cancel() or because a session timeout was set and expired.- Throws:
DbException- if the transaction is canceled
-
getCancel
public long getCancel()
Get the cancel time.- Returns:
- the time or 0 if not set
-
getCurrentCommand
public Command getCurrentCommand()
-
getCommandStartOrEnd
public ValueTimestampTimeZone getCommandStartOrEnd()
-
getAllowLiterals
public boolean getAllowLiterals()
-
setAllowLiterals
public void setAllowLiterals(boolean b)
-
setCurrentSchema
public void setCurrentSchema(Schema schema)
-
getCurrentSchemaName
public java.lang.String getCurrentSchemaName()
Description copied from class:SessionGet current schema.- Specified by:
getCurrentSchemaNamein classSession- Returns:
- the current schema name
-
setCurrentSchemaName
public void setCurrentSchemaName(java.lang.String schemaName)
Description copied from class:SessionSet current schema.- Specified by:
setCurrentSchemaNamein classSession- Parameters:
schemaName- the schema name
-
createConnection
public JdbcConnection createConnection(boolean columnList)
Create an internal connection. This connection is used when initializing triggers, and when calling user defined functions.- Parameters:
columnList- if the url should be 'jdbc:columnlist:connection'- Returns:
- the internal connection
-
getDataHandler
public DataHandler getDataHandler()
Description copied from class:SessionGet the data handler object.- Specified by:
getDataHandlerin classSession- Returns:
- the data handler
-
removeAtCommit
public void removeAtCommit(ValueLob v)
Remember that the given LOB value must be removed at commit.- Parameters:
v- the value
-
removeAtCommitStop
public void removeAtCommitStop(ValueLob v)
Do not remove this LOB value at commit any longer.- Parameters:
v- the value
-
getNextSystemIdentifier
public java.lang.String getNextSystemIdentifier(java.lang.String sql)
Get the next system generated identifiers. The identifier returned does not occur within the given SQL statement.- Parameters:
sql- the SQL statement- Returns:
- the new identifier
-
addProcedure
public void addProcedure(Procedure procedure)
Add a procedure to this session.- Parameters:
procedure- the procedure to add
-
removeProcedure
public void removeProcedure(java.lang.String name)
Remove a procedure from this session.- Parameters:
name- the name of the procedure to remove
-
getProcedure
public Procedure getProcedure(java.lang.String name)
Get the procedure with the given name, or null if none exists.- Parameters:
name- the procedure name- Returns:
- the procedure or null
-
setSchemaSearchPath
public void setSchemaSearchPath(java.lang.String[] schemas)
-
getSchemaSearchPath
public java.lang.String[] getSchemaSearchPath()
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
begin
public void begin()
Begin a transaction.
-
getSessionStart
public ValueTimestampTimeZone getSessionStart()
-
getLocks
public java.util.Set<Table> getLocks()
-
waitIfExclusiveModeEnabled
public void waitIfExclusiveModeEnabled()
Wait if the exclusive mode has been enabled for another session. This method returns as soon as the exclusive mode has been disabled.
-
getViewIndexCache
public java.util.Map<java.lang.Object,ViewIndex> getViewIndexCache(boolean subQuery)
Get the view cache for this session. There are two caches: the subquery cache (which is only use for a single query, has no bounds, and is cleared after use), and the cache for regular views.- Parameters:
subQuery- true to get the subquery cache- Returns:
- the view cache
-
setQueryTimeout
public void setQueryTimeout(int queryTimeout)
-
getQueryTimeout
public int getQueryTimeout()
-
setWaitForLock
public void setWaitForLock(Table waitForLock, java.lang.Thread waitForLockThread)
Set the table this session is waiting for, and the thread that is waiting.- Parameters:
waitForLock- the tablewaitForLockThread- the current thread (the one that is waiting)
-
getWaitForLock
public Table getWaitForLock()
-
getWaitForLockThread
public java.lang.Thread getWaitForLockThread()
-
getModificationId
public int getModificationId()
-
getTransactionId
public Value getTransactionId()
-
nextObjectId
public int nextObjectId()
Get the next object id.- Returns:
- the next object id
-
getTransaction
public Transaction getTransaction()
Get the transaction to use for this session.- Returns:
- the transaction
-
getStatementSavepoint
private long getStatementSavepoint()
-
startStatementWithinTransaction
public void startStatementWithinTransaction(Command command)
Start a new statement within a transaction.- Parameters:
command- about to be started
-
addTableToDependencies
private static void addTableToDependencies(MVTable table, java.util.HashSet<MVMap<java.lang.Object,VersionedValue<java.lang.Object>>> maps)
-
addTableToDependencies
private static void addTableToDependencies(MVTable table, java.util.HashSet<MVMap<java.lang.Object,VersionedValue<java.lang.Object>>> maps, java.util.HashSet<MVTable> processed)
-
endStatement
public void endStatement()
Mark the statement as completed. This also close all temporary result set, and deletes all temporary files held by the result sets.
-
clearViewIndexCache
public void clearViewIndexCache()
Clear the view cache for this session.
-
addTemporaryLob
public ValueLob addTemporaryLob(ValueLob v)
Description copied from class:SessionAdd a temporary LOB, which is closed when the session commits.- Specified by:
addTemporaryLobin classSession- Parameters:
v- the value- Returns:
- the specified value
-
isRemote
public boolean isRemote()
Description copied from class:SessionCheck if this session is remote or embedded.
-
markTableForAnalyze
public void markTableForAnalyze(Table table)
Mark that the given table needs to be analyzed on commit.- Parameters:
table- the table
-
getState
public SessionLocal.State getState()
-
getBlockingSessionId
public int getBlockingSessionId()
-
onRollback
public void onRollback(MVMap<java.lang.Object,VersionedValue<java.lang.Object>> map, java.lang.Object key, VersionedValue<java.lang.Object> existingValue, VersionedValue<java.lang.Object> restoredValue)
Description copied from interface:TransactionStore.RollbackListenerNotified of a single map change (add/update/remove)- Specified by:
onRollbackin interfaceTransactionStore.RollbackListener- Parameters:
map- modifiedkey- of the modified entryexistingValue- value in the map (null if delete is rolled back)restoredValue- value to be restored (null if add is rolled back)
-
getNetworkConnectionInfo
public NetworkConnectionInfo getNetworkConnectionInfo()
Returns the network connection information, ornull.- Returns:
- the network connection information, or
null
-
setNetworkConnectionInfo
public void setNetworkConnectionInfo(NetworkConnectionInfo networkConnectionInfo)
Description copied from class:SessionSets the network connection information if possible.- Specified by:
setNetworkConnectionInfoin classSession- Parameters:
networkConnectionInfo- the network connection information
-
currentTimestamp
public ValueTimestampTimeZone currentTimestamp()
Description copied from interface:CastDataProviderReturns the current timestamp with maximum resolution. The value must be the same within a transaction or within execution of a command.- Specified by:
currentTimestampin interfaceCastDataProvider- Returns:
- the current timestamp for CURRENT_TIMESTAMP(9)
-
getMode
public Mode getMode()
Description copied from interface:CastDataProviderReturns the database mode.- Specified by:
getModein interfaceCastDataProvider- Returns:
- the database mode
-
getJavaObjectSerializer
public JavaObjectSerializer getJavaObjectSerializer()
Description copied from interface:CastDataProviderReturns the custom Java object serializer, ornull.- Specified by:
getJavaObjectSerializerin interfaceCastDataProvider- Returns:
- the custom Java object serializer, or
null
-
getIsolationLevel
public IsolationLevel getIsolationLevel()
Description copied from class:SessionReturns the isolation level.- Specified by:
getIsolationLevelin classSession- Returns:
- the isolation level
-
setIsolationLevel
public void setIsolationLevel(IsolationLevel isolationLevel)
Description copied from class:SessionSets the isolation level.- Specified by:
setIsolationLevelin classSession- Parameters:
isolationLevel- the isolation level to set
-
getNonKeywords
public java.util.BitSet getNonKeywords()
Gets bit set of non-keywords.- Returns:
- set of non-keywords, or
null
-
setNonKeywords
public void setNonKeywords(java.util.BitSet nonKeywords)
Sets bit set of non-keywords.- Parameters:
nonKeywords- set of non-keywords, ornull
-
getStaticSettings
public Session.StaticSettings getStaticSettings()
Description copied from class:SessionReturns static settings. These settings cannot be changed during lifecycle of session.- Specified by:
getStaticSettingsin classSession- Returns:
- static settings
-
getDynamicSettings
public Session.DynamicSettings getDynamicSettings()
Description copied from class:SessionReturns dynamic settings. These settings can be changed during lifecycle of session.- Specified by:
getDynamicSettingsin classSession- Returns:
- dynamic settings
-
currentTimeZone
public TimeZoneProvider currentTimeZone()
Description copied from interface:CastDataProviderReturns the current time zone.- Specified by:
currentTimeZonein interfaceCastDataProvider- Returns:
- the current time zone
-
setTimeZone
public void setTimeZone(TimeZoneProvider timeZone)
Sets current time zone.- Parameters:
timeZone- time zone
-
areEqual
public boolean areEqual(Value a, Value b)
Check if two values are equal with the current comparison mode.- Parameters:
a- the first valueb- the second value- Returns:
- true if both objects are equal
-
compare
public int compare(Value a, Value b)
Compare two values with the current comparison mode. The values may have different data types including NULL.- Parameters:
a- the first valueb- the second value- Returns:
- 0 if both values are equal, -1 if the first value is smaller, and 1 otherwise
-
compareWithNull
public int compareWithNull(Value a, Value b, boolean forEquality)
Compare two values with the current comparison mode. The values may have different data types including NULL.- Parameters:
a- the first valueb- the second valueforEquality- perform only check for equality (= or <>)- Returns:
- 0 if both values are equal, -1 if the first value is smaller, 1
if the second value is larger,
Integer.MIN_VALUEif order is not defined due to NULL comparison
-
compareTypeSafe
public int compareTypeSafe(Value a, Value b)
Compare two values with the current comparison mode. The values must be of the same type.- Parameters:
a- the first valueb- the second value- Returns:
- 0 if both values are equal, -1 if the first value is smaller, and 1 otherwise
-
setTruncateLargeLength
public void setTruncateLargeLength(boolean truncateLargeLength)
Changes parsing mode of data types with too large length.- Parameters:
truncateLargeLength-trueto truncate to valid bound,falseto throw an exception
-
isTruncateLargeLength
public boolean isTruncateLargeLength()
Returns parsing mode of data types with too large length.- Returns:
trueif large length is truncated,falseif an exception is thrown
-
setVariableBinary
public void setVariableBinary(boolean variableBinary)
Changes parsing of a BINARY data type.- Parameters:
variableBinary-trueto parse BINARY as VARBINARY,falseto parse it as is
-
isVariableBinary
public boolean isVariableBinary()
Returns BINARY data type parsing mode.- Returns:
trueif BINARY should be parsed as VARBINARY,falseif it should be parsed as is
-
setOldInformationSchema
public void setOldInformationSchema(boolean oldInformationSchema)
Changes INFORMATION_SCHEMA content.- Parameters:
oldInformationSchema-trueto have old-style tables in INFORMATION_SCHEMA,falseto have modern tables
-
isOldInformationSchema
public boolean isOldInformationSchema()
Description copied from class:SessionReturns whether INFORMATION_SCHEMA contains old-style tables.- Specified by:
isOldInformationSchemain classSession- Returns:
- whether INFORMATION_SCHEMA contains old-style tables
-
getDatabaseMeta
public DatabaseMeta getDatabaseMeta()
Description copied from class:SessionReturns database meta information.- Specified by:
getDatabaseMetain classSession- Returns:
- database meta information
-
zeroBasedEnums
public boolean zeroBasedEnums()
Description copied from interface:CastDataProviderReturns are ENUM values 0-based.- Specified by:
zeroBasedEnumsin interfaceCastDataProvider- Returns:
- are ENUM values 0-based
-
setQuirksMode
public void setQuirksMode(boolean quirksMode)
Enables or disables the quirks mode.- Parameters:
quirksMode- whether quirks mode should be enabled
-
isQuirksMode
public boolean isQuirksMode()
Returns whether quirks mode is enabled explicitly or implicitly.- Returns:
trueif database is starting or quirks mode was enabled explicitly,falseotherwise
-
setThreadLocalSession
public Session setThreadLocalSession()
Description copied from class:SessionSets this session as thread local session, if this session is a local session.- Overrides:
setThreadLocalSessionin classSession- Returns:
- old thread local session, or
null
-
resetThreadLocalSession
public void resetThreadLocalSession(Session oldSession)
Description copied from class:SessionResets old thread local session.- Overrides:
resetThreadLocalSessionin classSession- Parameters:
oldSession- the old thread local session, ornull
-
-