Package org.mariadb.jdbc.client.context
Class BaseContext
- java.lang.Object
-
- org.mariadb.jdbc.client.context.BaseContext
-
- All Implemented Interfaces:
Context
- Direct Known Subclasses:
RedoContext
public class BaseContext extends java.lang.Object implements Context
Context (current connection state) of a connection
-
-
Field Summary
Fields Modifier and Type Field Description private java.lang.LongautoIncrementprivate booleancanUseTransactionIsolationprivate java.lang.Stringcharsetprivate longclientCapabilitiesprivate java.util.function.Function<ReadableByteBuf,ColumnDecoder>columnDecoderFunctionprivate Configurationconfprivate java.lang.RunnableconnectionCloserprivate java.util.TimeZoneconnectionTimeZoneprivate java.lang.StringdatabaseServer current databaseprivate booleaneofDeprecatedprivate ExceptionFactoryexceptionFactoryprivate HostAddresshostAddressprivate booleaninitializedprivate java.lang.BooleanloopbackAddressprivate java.lang.StringmaxscaleVersionprivate PrepareCacheprepareCacheLRU prepare cache objectprivate java.lang.StringredirectUrlprivate byte[]seedprivate longserverCapabilitiesprivate booleanserverReadOnlyRead-only state currently applied on the server sessionprotected intserverStatusServer status contextprivate booleanskipMetaprivate intstateFlagConnection state use flagprivate longthreadIdprivate java.lang.IntegertransactionIsolationLevelServer current transaction isolation levelprivate ServerVersionversionprivate intwarningServer current warning count
-
Constructor Summary
Constructors Constructor Description BaseContext(HostAddress hostAddress, InitialHandshakePacket handshake, long clientCapabilities, Configuration conf, ExceptionFactory exceptionFactory, PrepareCache prepareCache, java.lang.Boolean loopbackAddress, java.lang.Runnable connectionCloser)Constructor of connection context
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddStateFlag(int state)Indicate connection state (for pooling)booleancanSkipMeta()Can server skip prepared statement metadatabooleancanUseTransactionIsolation()Can rely on transaction_isolation or keep using deprecated tx_isolation variablejava.lang.LonggetAutoIncrement()Get server current auto_increment valuejava.lang.StringgetCharset()Retrieve current charset if session state get itjava.util.function.Function<ReadableByteBuf,ColumnDecoder>getColumnDecoderFunction()Column decoder functionConfigurationgetConf()Get connection configurationjava.util.TimeZonegetConnectionTimeZone()Get current connection timezonejava.lang.StringgetDatabase()Get current connection databasejava.util.CalendargetDefaultCalendar()Get calendar depending on configurationExceptionFactorygetExceptionFactory()Get connection exception factoryjava.lang.StringgetMaxscaleVersion()Retrieve maxscaleVersion or null if not the casePreparegetPrepareCacheCmd(java.lang.String sql, BasePreparedStatement preparedStatement)Return cached prepare if key matchjava.lang.StringgetRedirectUrl()get redirect Url if server indicate reconnection urlbyte[]getSeed()Get connection initial seedintgetServerStatus()Get server connection stateintgetStateFlag()return connection current state change flaglonggetThreadId()return current thread idjava.lang.IntegergetTransactionIsolationLevel()Get connection transaction isolation levelServerVersiongetVersion()Retrieve server version informationintgetWarning()has server warningsbooleanhasClientCapability(long flag)has client capabilitybooleanhasServerCapability(long flag)has server capabilitybooleanisEofDeprecated()does protocol remove EOF in exchangesjava.lang.BooleanisLoopbackAddress()return if host is a local addressbooleanisServerReadOnly()Read-only state currently applied on the server session, i.e.booleanpermitPipeline()Does server and client permit pipelinePrepareputPrepareCacheCmd(java.lang.String sql, Prepare result, BasePreparedStatement preparedStatement)Put prepare result in cacheprivate voidrejectNonUtf8(java.lang.String what, java.lang.String charset)voidresetPrepareCache()Reset prepare cache (after a failover)voidresetStateFlag()reset connection state change flagvoidsetAutoIncrement(long autoIncrement)Set server autoincrement valuevoidsetCharset(java.lang.String charset)Indicate server charset change.voidsetCharsetResults(java.lang.String charset)Indicate server character_set_results change.voidsetConnectionTimeZone(java.util.TimeZone connectionTimeZone)Set current connection timezonevoidsetDatabase(java.lang.String database)set current database contextvoidsetInitialized()Indicate that connection is initialized and ready to handle commands.voidsetMaxscaleVersion(java.lang.String maxscaleVersion)Set Maxscale version.voidsetRedirectUrl(java.lang.String redirectUrl)Set server redirection urlvoidsetServerReadOnly(boolean serverReadOnly)Record the read-only state currently applied on the server session.voidsetServerStatus(int serverStatus)Set server connection statevoidsetThreadId(long connectionId)Indicate server connection Id (not truncated)voidsetTransactionIsolationLevel(java.lang.Integer transactionIsolationLevel)Set current connection transaction isolation levelvoidsetTreadsConnected(long threadsConnected)Indicate the number of connection on this servervoidsetWarning(int warning)set server state warning number
-
-
-
Field Detail
-
serverCapabilities
private final long serverCapabilities
-
clientCapabilities
private final long clientCapabilities
-
seed
private final byte[] seed
-
version
private final ServerVersion version
-
eofDeprecated
private final boolean eofDeprecated
-
skipMeta
private final boolean skipMeta
-
columnDecoderFunction
private final java.util.function.Function<ReadableByteBuf,ColumnDecoder> columnDecoderFunction
-
conf
private final Configuration conf
-
exceptionFactory
private final ExceptionFactory exceptionFactory
-
canUseTransactionIsolation
private final boolean canUseTransactionIsolation
-
loopbackAddress
private final java.lang.Boolean loopbackAddress
-
prepareCache
private final PrepareCache prepareCache
LRU prepare cache object
-
hostAddress
private final HostAddress hostAddress
-
serverStatus
protected int serverStatus
Server status context
-
autoIncrement
private java.lang.Long autoIncrement
-
maxscaleVersion
private java.lang.String maxscaleVersion
-
threadId
private long threadId
-
charset
private java.lang.String charset
-
initialized
private boolean initialized
-
connectionCloser
private final java.lang.Runnable connectionCloser
-
database
private java.lang.String database
Server current database
-
transactionIsolationLevel
private java.lang.Integer transactionIsolationLevel
Server current transaction isolation level
-
warning
private int warning
Server current warning count
-
stateFlag
private int stateFlag
Connection state use flag
-
serverReadOnly
private boolean serverReadOnly
Read-only state currently applied on the server session
-
redirectUrl
private java.lang.String redirectUrl
-
connectionTimeZone
private java.util.TimeZone connectionTimeZone
-
-
Constructor Detail
-
BaseContext
public BaseContext(HostAddress hostAddress, InitialHandshakePacket handshake, long clientCapabilities, Configuration conf, ExceptionFactory exceptionFactory, PrepareCache prepareCache, java.lang.Boolean loopbackAddress, java.lang.Runnable connectionCloser)
Constructor of connection context- Parameters:
hostAddress- host addresshandshake- server handshakeclientCapabilities- client capabilitiesconf- connection configurationexceptionFactory- connection exception factoryprepareCache- LRU prepare cacheloopbackAddress- is local address
-
-
Method Detail
-
isLoopbackAddress
public java.lang.Boolean isLoopbackAddress()
Description copied from interface:Contextreturn if host is a local address- Specified by:
isLoopbackAddressin interfaceContext- Returns:
- true if host is local
-
getThreadId
public long getThreadId()
Description copied from interface:Contextreturn current thread id- Specified by:
getThreadIdin interfaceContext- Returns:
- current server thread id
-
setThreadId
public void setThreadId(long connectionId)
Description copied from interface:ContextIndicate server connection Id (not truncated)- Specified by:
setThreadIdin interfaceContext- Parameters:
connectionId- connection id
-
getSeed
public byte[] getSeed()
Description copied from interface:ContextGet connection initial seed
-
hasServerCapability
public boolean hasServerCapability(long flag)
Description copied from interface:Contexthas server capability- Specified by:
hasServerCapabilityin interfaceContext- Parameters:
flag- capability to check- Returns:
- true if server has capability
-
hasClientCapability
public boolean hasClientCapability(long flag)
Description copied from interface:Contexthas client capability- Specified by:
hasClientCapabilityin interfaceContext- Parameters:
flag- capability to check- Returns:
- true if client has capability
-
permitPipeline
public boolean permitPipeline()
Description copied from interface:ContextDoes server and client permit pipeline- Specified by:
permitPipelinein interfaceContext- Returns:
- true if permitted
-
getServerStatus
public int getServerStatus()
Description copied from interface:ContextGet server connection state- Specified by:
getServerStatusin interfaceContext- Returns:
- server status
-
setServerStatus
public void setServerStatus(int serverStatus)
Description copied from interface:ContextSet server connection state- Specified by:
setServerStatusin interfaceContext- Parameters:
serverStatus- server status
-
getDatabase
public java.lang.String getDatabase()
Description copied from interface:ContextGet current connection database- Specified by:
getDatabasein interfaceContext- Returns:
- database
-
setMaxscaleVersion
public void setMaxscaleVersion(java.lang.String maxscaleVersion)
Description copied from interface:ContextSet Maxscale version.- Specified by:
setMaxscaleVersionin interfaceContext- Parameters:
maxscaleVersion- maxscale version
-
setDatabase
public void setDatabase(java.lang.String database)
Description copied from interface:Contextset current database context- Specified by:
setDatabasein interfaceContext- Parameters:
database- database
-
getMaxscaleVersion
public java.lang.String getMaxscaleVersion()
Description copied from interface:ContextRetrieve maxscaleVersion or null if not the case- Specified by:
getMaxscaleVersionin interfaceContext- Returns:
- maxscale version
-
getVersion
public ServerVersion getVersion()
Description copied from interface:ContextRetrieve server version information- Specified by:
getVersionin interfaceContext- Returns:
- server version
-
isEofDeprecated
public boolean isEofDeprecated()
Description copied from interface:Contextdoes protocol remove EOF in exchanges- Specified by:
isEofDeprecatedin interfaceContext- Returns:
- if EOF packet are deprecated
-
getColumnDecoderFunction
public java.util.function.Function<ReadableByteBuf,ColumnDecoder> getColumnDecoderFunction()
Description copied from interface:ContextColumn decoder function- Specified by:
getColumnDecoderFunctionin interfaceContext- Returns:
- Column decoder function
-
canSkipMeta
public boolean canSkipMeta()
Description copied from interface:ContextCan server skip prepared statement metadata- Specified by:
canSkipMetain interfaceContext- Returns:
- true if possible
-
getWarning
public int getWarning()
Description copied from interface:Contexthas server warnings- Specified by:
getWarningin interfaceContext- Returns:
- has warnings
-
setWarning
public void setWarning(int warning)
Description copied from interface:Contextset server state warning number- Specified by:
setWarningin interfaceContext- Parameters:
warning- warning number
-
getExceptionFactory
public ExceptionFactory getExceptionFactory()
Description copied from interface:ContextGet connection exception factory- Specified by:
getExceptionFactoryin interfaceContext- Returns:
- exception factory
-
getConf
public Configuration getConf()
Description copied from interface:ContextGet connection configuration
-
getTransactionIsolationLevel
public java.lang.Integer getTransactionIsolationLevel()
Description copied from interface:ContextGet connection transaction isolation level- Specified by:
getTransactionIsolationLevelin interfaceContext- Returns:
- connection transaction isolation level
-
setTransactionIsolationLevel
public void setTransactionIsolationLevel(java.lang.Integer transactionIsolationLevel)
Description copied from interface:ContextSet current connection transaction isolation level- Specified by:
setTransactionIsolationLevelin interfaceContext- Parameters:
transactionIsolationLevel- new connection transaction isolation level
-
getPrepareCacheCmd
public Prepare getPrepareCacheCmd(java.lang.String sql, BasePreparedStatement preparedStatement)
Description copied from interface:ContextReturn cached prepare if key match- Specified by:
getPrepareCacheCmdin interfaceContext- Parameters:
sql- sql commandpreparedStatement- current statement- Returns:
- Prepare if found, null if not
-
putPrepareCacheCmd
public Prepare putPrepareCacheCmd(java.lang.String sql, Prepare result, BasePreparedStatement preparedStatement)
Description copied from interface:ContextPut prepare result in cache- Specified by:
putPrepareCacheCmdin interfaceContext- Parameters:
sql- sql commandresult- prepare resultpreparedStatement- current statement- Returns:
- Prepare if was already cached
-
resetPrepareCache
public void resetPrepareCache()
Description copied from interface:ContextReset prepare cache (after a failover)- Specified by:
resetPrepareCachein interfaceContext
-
getStateFlag
public int getStateFlag()
Description copied from interface:Contextreturn connection current state change flag- Specified by:
getStateFlagin interfaceContext- Returns:
- connection current state change flag
-
resetStateFlag
public void resetStateFlag()
Description copied from interface:Contextreset connection state change flag- Specified by:
resetStateFlagin interfaceContext
-
addStateFlag
public void addStateFlag(int state)
Description copied from interface:ContextIndicate connection state (for pooling)- Specified by:
addStateFlagin interfaceContext- Parameters:
state- indicate that some connection state has changed
-
isServerReadOnly
public boolean isServerReadOnly()
Description copied from interface:ContextRead-only state currently applied on the server session, i.e. whether the last effectiveSET SESSION TRANSACTION READ ONLY / READ WRITEleft the session read-only. Used with thereadOnlyPropagatesToServeroption to avoid issuing redundant statements and to replay the state on failover.- Specified by:
isServerReadOnlyin interfaceContext- Returns:
- true if the server session is currently in read-only mode
-
setServerReadOnly
public void setServerReadOnly(boolean serverReadOnly)
Description copied from interface:ContextRecord the read-only state currently applied on the server session.- Specified by:
setServerReadOnlyin interfaceContext- Parameters:
serverReadOnly- true if the server session is read-only
-
setTreadsConnected
public void setTreadsConnected(long threadsConnected)
Description copied from interface:ContextIndicate the number of connection on this server- Specified by:
setTreadsConnectedin interfaceContext- Parameters:
threadsConnected- number of connected threads
-
getAutoIncrement
public java.lang.Long getAutoIncrement()
Description copied from interface:ContextGet server current auto_increment value- Specified by:
getAutoIncrementin interfaceContext- Returns:
- server auto increment
-
setAutoIncrement
public void setAutoIncrement(long autoIncrement)
Description copied from interface:ContextSet server autoincrement value- Specified by:
setAutoIncrementin interfaceContext- Parameters:
autoIncrement- current server autoincrement value
-
getCharset
public java.lang.String getCharset()
Description copied from interface:ContextRetrieve current charset if session state get it- Specified by:
getCharsetin interfaceContext- Returns:
- current charset
-
setCharset
public void setCharset(java.lang.String charset) throws java.sql.SQLNonTransientConnectionExceptionDescription copied from interface:ContextIndicate server charset change. Throws when the new charset isn't compatible with the driver's UTF-8 assumption (only utf8 / utf8mb3 / utf8mb4 are accepted post-init).- Specified by:
setCharsetin interfaceContext- Parameters:
charset- server charset- Throws:
java.sql.SQLNonTransientConnectionException
-
setCharsetResults
public void setCharsetResults(java.lang.String charset) throws java.sql.SQLNonTransientConnectionExceptionDescription copied from interface:ContextIndicate server character_set_results change. Throws when the new charset isn't compatible with the driver's UTF-8 result decoding (only utf8 / utf8mb3 / utf8mb4, or no conversion, are accepted post-init).- Specified by:
setCharsetResultsin interfaceContext- Parameters:
charset- results charset, empty when results are sent without conversion- Throws:
java.sql.SQLNonTransientConnectionException
-
rejectNonUtf8
private void rejectNonUtf8(java.lang.String what, java.lang.String charset) throws java.sql.SQLNonTransientConnectionException- Throws:
java.sql.SQLNonTransientConnectionException
-
setInitialized
public void setInitialized()
Description copied from interface:ContextIndicate that connection is initialized and ready to handle commands. Used to avoid accepting server- Specified by:
setInitializedin interfaceContext
-
getRedirectUrl
public java.lang.String getRedirectUrl()
Description copied from interface:Contextget redirect Url if server indicate reconnection url- Specified by:
getRedirectUrlin interfaceContext- Returns:
- null if no redirection required, value if so
-
canUseTransactionIsolation
public boolean canUseTransactionIsolation()
Description copied from interface:ContextCan rely on transaction_isolation or keep using deprecated tx_isolation variable- Specified by:
canUseTransactionIsolationin interfaceContext- Returns:
- true if you can use transaction_isolation
-
setRedirectUrl
public void setRedirectUrl(java.lang.String redirectUrl)
Description copied from interface:ContextSet server redirection url- Specified by:
setRedirectUrlin interfaceContext- Parameters:
redirectUrl- redirect url
-
getConnectionTimeZone
public java.util.TimeZone getConnectionTimeZone()
Description copied from interface:ContextGet current connection timezone- Specified by:
getConnectionTimeZonein interfaceContext- Returns:
- connection timezone
-
setConnectionTimeZone
public void setConnectionTimeZone(java.util.TimeZone connectionTimeZone)
Description copied from interface:ContextSet current connection timezone- Specified by:
setConnectionTimeZonein interfaceContext- Parameters:
connectionTimeZone- connection timezone
-
getDefaultCalendar
public java.util.Calendar getDefaultCalendar()
Description copied from interface:ContextGet calendar depending on configuration- Specified by:
getDefaultCalendarin interfaceContext- Returns:
- calendar
-
-