Package com.mysql.cj
Class NativeSession
java.lang.Object
com.mysql.cj.CoreSession
com.mysql.cj.NativeSession
- All Implemented Interfaces:
Session
,java.io.Serializable
public class NativeSession extends CoreSession implements java.io.Serializable
- See Also:
- Serialized Form
-
Nested Class Summary
Nested classes/interfaces inherited from interface com.mysql.cj.Session
Session.SessionEventListener
-
Field Summary
Fields inherited from class com.mysql.cj.CoreSession
autoReconnect, autoReconnectForPools, cacheServerConfiguration, characterEncoding, connectionCreationTimeMillis, disconnectOnExpiredPasswords, exceptionInterceptor, gatherPerfMetrics, hostInfo, log, maintainTimeStats, messageBuilder, NULL_LOGGER, propertySet, protocol, sessionMaxRows
-
Constructor Summary
Constructors Constructor Description NativeSession(HostInfo hostInfo, PropertySet propSet)
-
Method Summary
Modifier and Type Method Description void
addListener(Session.SessionEventListener l)
Add listener for this session status changes.void
buildCollationMapping()
Builds the map needed for 4.1.0 and newer servers that maps field-level charset/collation info to a java character encoding name.void
checkClosed()
void
checkForCharsetMismatch()
Determines if the database charset is the same as the platform charsetvoid
clearInputStream()
boolean
configureClientCharacterSet(boolean dontCheckServerMatch)
Sets up client character set.void
connect(HostInfo hi, java.lang.String user, java.lang.String password, java.lang.String database, int loginTimeout, TransactionEventHandler transactionManager)
void
disableMultiQueries()
void
dumpPacketRingBuffer()
void
enableMultiQueries()
<T extends Resultset>
TexecSQL(Query callingQuery, java.lang.String query, int maxRows, NativePacketPayload packet, boolean streamResults, ProtocolEntityFactory<T,NativePacketPayload> resultSetFactory, ColumnDefinition cachedMetadata, boolean isBatch)
Send a query to the server.void
forceClose()
Clobbers the physical network connection and marks this session as closed.java.util.Timer
getCancelTimer()
int
getCommandCount()
long
getConnectionCreationTimeMillis()
long
getCurrentTimeNanosOrMillis()
java.lang.Throwable
getForceClosedReason()
java.lang.String
getIdentifierQuoteString()
long
getIdleFor()
java.io.InputStream
getLocalInfileInputStream()
NetworkResources
getNetworkResources()
java.lang.String
getProcessHost()
NativeProtocol
getProtocol()
java.net.SocketAddress
getRemoteSocketAddress()
boolean
getRequiresEscapingEncoder()
int
getSessionMaxRows()
NativePacketPayload
getSharedSendPacket()
Returns the packet used for sending data (used by PreparedStatement) with position set to 0.long
getSlowQueryThreshold()
int
getSocketTimeout()
boolean
hadWarnings()
void
invokeCleanupListeners(java.lang.Throwable whyCleanedUp)
protected void
invokeNormalCloseListeners()
<T extends Resultset>
TinvokeQueryInterceptorsPost(java.util.function.Supplier<java.lang.String> sql, Query interceptedQuery, T originalResultSet, boolean forceExecute)
<T extends Resultset>
TinvokeQueryInterceptorsPre(java.util.function.Supplier<java.lang.String> sql, Query interceptedQuery, boolean forceExecute)
protected void
invokeReconnectListeners()
boolean
isClosed()
boolean
isNeedsPing()
boolean
isServerLocal(Session sess)
boolean
isSetNeededForAutoCommitMode(boolean autoCommitFlag)
boolean
isSSLEstablished()
void
loadServerVariables(java.lang.Object syncMutex, java.lang.String version)
Loads the result of 'SHOW VARIABLES' into the serverVariables field so that the driver can configure itself.void
ping(boolean checkForClosedConnection, int timeoutMillis)
java.lang.String
queryServerVariable(java.lang.String varName)
Get the variable value from server.void
quit()
Log-off of the MySQL server and close the socket.void
removeListener(Session.SessionEventListener listener)
Remove session listener.NativePacketPayload
sendCommand(NativePacketPayload queryPacket, boolean skipCheck, int timeoutMillis)
void
setConnectionCreationTimeMillis(long connectionCreationTimeMillis)
void
setForceClosedReason(java.lang.Throwable forceClosedReason)
void
setLocalInfileInputStream(java.io.InputStream stream)
void
setNeedsPing(boolean needsPing)
void
setQueryInterceptors(java.util.List<QueryInterceptor> queryInterceptors)
void
setSessionMaxRows(int sessionMaxRows)
void
setSessionVariables()
void
setSocketTimeout(int milliseconds)
boolean
shouldIntercept()
void
shutdownServer()
Used by MiniAdmin to shutdown a MySQL serverMethods inherited from class com.mysql.cj.CoreSession
changeUser, getDataStoreMetadata, getExceptionInterceptor, getHostInfo, getLog, getMessageBuilder, getProfilerEventHandler, getPropertySet, getQueryTimingUnits, getServerSession, getThreadId, setExceptionInterceptor, versionMeetsMinimum
-
Constructor Details
-
Method Details
-
connect
public void connect(HostInfo hi, java.lang.String user, java.lang.String password, java.lang.String database, int loginTimeout, TransactionEventHandler transactionManager) throws java.io.IOException- Throws:
java.io.IOException
-
getProtocol
-
quit
public void quit()Description copied from interface:Session
Log-off of the MySQL server and close the socket.- Specified by:
quit
in interfaceSession
- Overrides:
quit
in classCoreSession
-
forceClose
public void forceClose()Description copied from interface:Session
Clobbers the physical network connection and marks this session as closed.- Specified by:
forceClose
in interfaceSession
- Overrides:
forceClose
in classCoreSession
-
enableMultiQueries
public void enableMultiQueries() -
disableMultiQueries
public void disableMultiQueries() -
isSetNeededForAutoCommitMode
public boolean isSetNeededForAutoCommitMode(boolean autoCommitFlag)- Specified by:
isSetNeededForAutoCommitMode
in interfaceSession
- Overrides:
isSetNeededForAutoCommitMode
in classCoreSession
-
getSessionMaxRows
public int getSessionMaxRows() -
setSessionMaxRows
public void setSessionMaxRows(int sessionMaxRows) -
setQueryInterceptors
-
isServerLocal
-
shutdownServer
public void shutdownServer()Used by MiniAdmin to shutdown a MySQL server -
setSocketTimeout
public void setSocketTimeout(int milliseconds) -
getSocketTimeout
public int getSocketTimeout() -
checkForCharsetMismatch
public void checkForCharsetMismatch()Determines if the database charset is the same as the platform charset -
getSharedSendPacket
Returns the packet used for sending data (used by PreparedStatement) with position set to 0. Guarded by external synchronization on a mutex.- Returns:
- A packet to send data with
-
dumpPacketRingBuffer
public void dumpPacketRingBuffer() -
invokeQueryInterceptorsPre
-
invokeQueryInterceptorsPost
-
shouldIntercept
public boolean shouldIntercept() -
getCurrentTimeNanosOrMillis
public long getCurrentTimeNanosOrMillis() -
sendCommand
public final NativePacketPayload sendCommand(NativePacketPayload queryPacket, boolean skipCheck, int timeoutMillis) -
getSlowQueryThreshold
public long getSlowQueryThreshold() -
hadWarnings
public boolean hadWarnings() -
clearInputStream
public void clearInputStream() -
getNetworkResources
-
isSSLEstablished
public boolean isSSLEstablished()- Specified by:
isSSLEstablished
in interfaceSession
- Overrides:
isSSLEstablished
in classCoreSession
-
getCommandCount
public int getCommandCount() -
getRemoteSocketAddress
public java.net.SocketAddress getRemoteSocketAddress()- Specified by:
getRemoteSocketAddress
in interfaceSession
- Overrides:
getRemoteSocketAddress
in classCoreSession
-
getLocalInfileInputStream
public java.io.InputStream getLocalInfileInputStream() -
setLocalInfileInputStream
public void setLocalInfileInputStream(java.io.InputStream stream) -
configureClientCharacterSet
public boolean configureClientCharacterSet(boolean dontCheckServerMatch)Sets up client character set. This must be done before any further communication with the server!- Parameters:
dontCheckServerMatch
- if true then send the SET NAMES query even if server charset already matches the new value- Returns:
- true if this routine actually configured the client character set, or false if the driver needs to use 'older' methods to detect the character set, as it is connected to a MySQL server older than 4.1.0
- Throws:
CJException
- if an exception happens while sending 'SET NAMES' to the server, or the server sends character set information that the client doesn't know about.
-
getRequiresEscapingEncoder
public boolean getRequiresEscapingEncoder() -
loadServerVariables
public void loadServerVariables(java.lang.Object syncMutex, java.lang.String version)Loads the result of 'SHOW VARIABLES' into the serverVariables field so that the driver can configure itself.- Parameters:
syncMutex
- synchronization mutexversion
- driver version string
-
setSessionVariables
public void setSessionVariables() -
buildCollationMapping
public void buildCollationMapping()Builds the map needed for 4.1.0 and newer servers that maps field-level charset/collation info to a java character encoding name. -
getProcessHost
public java.lang.String getProcessHost()- Specified by:
getProcessHost
in interfaceSession
-
queryServerVariable
public java.lang.String queryServerVariable(java.lang.String varName)Get the variable value from server.- Parameters:
varName
- server variable name- Returns:
- server variable value
-
execSQL
public <T extends Resultset> T execSQL(Query callingQuery, java.lang.String query, int maxRows, NativePacketPayload packet, boolean streamResults, ProtocolEntityFactory<T,NativePacketPayload> resultSetFactory, ColumnDefinition cachedMetadata, boolean isBatch)Send a query to the server. Returns one of the ResultSet objects. To ensure that Statement's queries are serialized, calls to this method should be enclosed in a connection mutex synchronized block.- Type Parameters:
T
- extendsResultset
- Parameters:
callingQuery
-Query
objectquery
- the SQL statement to be executedmaxRows
- rows limitpacket
-NativePacketPayload
streamResults
- whether a stream result should be createdresultSetFactory
-ProtocolEntityFactory
cachedMetadata
- use this metadata instead of the one provided on wireisBatch
- is it a batch query- Returns:
- a ResultSet holding the results
-
getIdleFor
public long getIdleFor() -
isNeedsPing
public boolean isNeedsPing() -
setNeedsPing
public void setNeedsPing(boolean needsPing) -
ping
public void ping(boolean checkForClosedConnection, int timeoutMillis) -
getConnectionCreationTimeMillis
public long getConnectionCreationTimeMillis() -
setConnectionCreationTimeMillis
public void setConnectionCreationTimeMillis(long connectionCreationTimeMillis) -
isClosed
public boolean isClosed() -
checkClosed
public void checkClosed() -
getForceClosedReason
public java.lang.Throwable getForceClosedReason() -
setForceClosedReason
public void setForceClosedReason(java.lang.Throwable forceClosedReason) -
addListener
Description copied from interface:Session
Add listener for this session status changes.- Specified by:
addListener
in interfaceSession
- Overrides:
addListener
in classCoreSession
- Parameters:
l
-Session.SessionEventListener
instance.
-
removeListener
Description copied from interface:Session
Remove session listener.- Specified by:
removeListener
in interfaceSession
- Overrides:
removeListener
in classCoreSession
- Parameters:
listener
-Session.SessionEventListener
instance.
-
invokeNormalCloseListeners
protected void invokeNormalCloseListeners() -
invokeReconnectListeners
protected void invokeReconnectListeners() -
invokeCleanupListeners
public void invokeCleanupListeners(java.lang.Throwable whyCleanedUp) -
getIdentifierQuoteString
public java.lang.String getIdentifierQuoteString()- Specified by:
getIdentifierQuoteString
in interfaceSession
- Overrides:
getIdentifierQuoteString
in classCoreSession
-
getCancelTimer
public java.util.Timer getCancelTimer()
-