Package org.mariadb.jdbc
Class ServerSidePreparedStatement
- java.lang.Object
-
- org.mariadb.jdbc.MariaDbStatement
-
- org.mariadb.jdbc.BasePrepareStatement
-
- org.mariadb.jdbc.ServerSidePreparedStatement
-
- All Implemented Interfaces:
java.lang.AutoCloseable
,java.lang.Cloneable
,java.sql.PreparedStatement
,java.sql.Statement
,java.sql.Wrapper
- Direct Known Subclasses:
CallableProcedureStatement
public class ServerSidePreparedStatement extends BasePrepareStatement implements java.lang.Cloneable
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.Map<java.lang.Integer,ParameterHolder>
currentParameterHolder
private static Logger
logger
private MariaDbResultSetMetaData
metadata
private boolean
mustExecuteOnMaster
protected int
parameterCount
private MariaDbParameterMetaData
parameterMetaData
private java.util.List<ParameterHolder[]>
queryParameters
private ServerPrepareResult
serverPrepareResult
private java.lang.String
sql
-
Fields inherited from class org.mariadb.jdbc.BasePrepareStatement
autoGeneratedKeys, hasLongData, SPEC_ISO_ZONED_DATE_TIME
-
Fields inherited from class org.mariadb.jdbc.MariaDbStatement
canUseServerTimeout, closed, connection, exceptionFactory, executing, fetchSize, lock, maxRows, options, protocol, queryTimeout, results, resultSetConcurrency, resultSetScrollType
-
-
Constructor Summary
Constructors Constructor Description ServerSidePreparedStatement(MariaDbConnection connection, java.lang.String sql, int resultSetScrollType, int resultSetConcurrency, int autoGeneratedKeys, ExceptionFactory exceptionFactory)
Constructor for creating Server prepared statement.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addBatch()
void
addBatch(java.lang.String sql)
Add batch.void
clearBatch()
Empties thisStatement
object's current list of SQL send.void
clearParameters()
ServerSidePreparedStatement
clone(MariaDbConnection connection)
Clone statement.void
close()
Releases thisStatement
object's database and JDBC resources immediately instead of waiting for this to happen when it is automatically closed.boolean
execute()
int[]
executeBatch()
Submits a batch of send to the database for execution and if all send execute successfully, returns an array of update counts.private void
executeBatchInternal(int queryParameterSize)
protected boolean
executeInternal(int fetchSize)
long[]
executeLargeBatch()
Execute batch, like executeBatch(), with returning results with long[].java.sql.ResultSet
executeQuery()
private void
executeQueryPrologue(ServerPrepareResult serverPrepareResult)
int
executeUpdate()
Executes the SQL statement in thisPreparedStatement
object, which must be an SQL Data Manipulation Language (DML) statement, such asINSERT
,UPDATE
orDELETE
; or an SQL statement that returns nothing, such as a DDL statement.java.sql.ResultSetMetaData
getMetaData()
protected int
getParameterCount()
java.sql.ParameterMetaData
getParameterMetaData()
Retrieves the number, types and properties of thisPreparedStatement
object's parameters.long
getServerThreadId()
Permit to retrieve current connection thread id, or -1 if unknown.private void
prepare(java.lang.String sql)
private void
setMetaFromResult()
void
setParameter(int parameterIndex, ParameterHolder holder)
java.lang.String
toString()
Return sql String value.protected void
validParameters()
-
Methods inherited from class org.mariadb.jdbc.BasePrepareStatement
executeLargeUpdate, setArray, setAsciiStream, setAsciiStream, setAsciiStream, setBigDecimal, setBinaryStream, setBinaryStream, setBinaryStream, setBlob, setBlob, setBlob, setBoolean, setByte, setBytes, setCharacterStream, setCharacterStream, setCharacterStream, setClob, setClob, setClob, setDate, setDate, setDouble, setFloat, setInt, setLong, setNCharacterStream, setNCharacterStream, setNClob, setNClob, setNClob, setNString, setNull, setNull, setNull, setObject, setObject, setObject, setObject, setObject, setRef, setRowId, setShort, setSQLXML, setString, setTime, setTime, setTimestamp, setTimestamp, setUnicodeStream, setURL
-
Methods inherited from class org.mariadb.jdbc.MariaDbStatement
cancel, checkClose, checkCloseOnCompletion, clearWarnings, closeOnCompletion, enquoteIdentifier, enquoteLiteral, enquoteNCharLiteral, execute, execute, execute, execute, executeBatchEpilogue, executeBatchExceptionEpilogue, executeEpilogue, executeExceptionEpilogue, executeLargeUpdate, executeLargeUpdate, executeLargeUpdate, executeLargeUpdate, executeQuery, executeQueryPrologue, executeUpdate, executeUpdate, executeUpdate, executeUpdate, getConnection, getFetchDirection, getFetchSize, getGeneratedKeys, getLargeMaxRows, getLargeUpdateCount, getMaxFieldSize, getMaxRows, getMoreResults, getMoreResults, getQueryTimeout, getResultSet, getResultSetConcurrency, getResultSetHoldability, getResultSetType, getUpdateCount, getWarnings, isClosed, isCloseOnCompletion, isPoolable, isSimpleIdentifier, isWrapperFor, setCursorName, setEscapeProcessing, setFetchDirection, setFetchSize, setLargeMaxRows, setLocalInfileInputStream, setMaxFieldSize, setMaxRows, setPoolable, setQueryTimeout, setTimerTask, skipMoreResults, testExecute, unwrap
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.sql.Statement
cancel, clearWarnings, closeOnCompletion, enquoteIdentifier, enquoteLiteral, enquoteNCharLiteral, execute, execute, execute, execute, executeLargeUpdate, executeLargeUpdate, executeLargeUpdate, executeLargeUpdate, executeQuery, executeUpdate, executeUpdate, executeUpdate, executeUpdate, getConnection, getFetchDirection, getFetchSize, getGeneratedKeys, getLargeMaxRows, getLargeUpdateCount, getMaxFieldSize, getMaxRows, getMoreResults, getMoreResults, getQueryTimeout, getResultSet, getResultSetConcurrency, getResultSetHoldability, getResultSetType, getUpdateCount, getWarnings, isClosed, isCloseOnCompletion, isPoolable, isSimpleIdentifier, setCursorName, setEscapeProcessing, setFetchDirection, setFetchSize, setLargeMaxRows, setMaxFieldSize, setMaxRows, setPoolable, setQueryTimeout
-
-
-
-
Field Detail
-
logger
private static final Logger logger
-
parameterCount
protected int parameterCount
-
sql
private java.lang.String sql
-
serverPrepareResult
private ServerPrepareResult serverPrepareResult
-
metadata
private MariaDbResultSetMetaData metadata
-
parameterMetaData
private MariaDbParameterMetaData parameterMetaData
-
currentParameterHolder
private java.util.Map<java.lang.Integer,ParameterHolder> currentParameterHolder
-
queryParameters
private java.util.List<ParameterHolder[]> queryParameters
-
mustExecuteOnMaster
private boolean mustExecuteOnMaster
-
-
Constructor Detail
-
ServerSidePreparedStatement
public ServerSidePreparedStatement(MariaDbConnection connection, java.lang.String sql, int resultSetScrollType, int resultSetConcurrency, int autoGeneratedKeys, ExceptionFactory exceptionFactory) throws java.sql.SQLException
Constructor for creating Server prepared statement.- Parameters:
connection
- current connectionsql
- Sql String to prepareresultSetScrollType
- one of the followingResultSet
constants:ResultSet.TYPE_FORWARD_ONLY
,ResultSet.TYPE_SCROLL_INSENSITIVE
, orResultSet.TYPE_SCROLL_SENSITIVE
resultSetConcurrency
- a concurrency type; one ofResultSet.CONCUR_READ_ONLY
orResultSet.CONCUR_UPDATABLE
autoGeneratedKeys
- a flag indicating whether auto-generated keys should be returned; one ofStatement.RETURN_GENERATED_KEYS
orStatement.NO_GENERATED_KEYS
exceptionFactory
- Exception factory- Throws:
java.sql.SQLException
- exception
-
-
Method Detail
-
clone
public ServerSidePreparedStatement clone(MariaDbConnection connection) throws java.lang.CloneNotSupportedException
Clone statement.- Overrides:
clone
in classBasePrepareStatement
- Parameters:
connection
- connection- Returns:
- Clone statement.
- Throws:
java.lang.CloneNotSupportedException
- if any error occur.
-
prepare
private void prepare(java.lang.String sql) throws java.sql.SQLException
- Throws:
java.sql.SQLException
-
setMetaFromResult
private void setMetaFromResult()
-
setParameter
public void setParameter(int parameterIndex, ParameterHolder holder) throws java.sql.SQLException
- Specified by:
setParameter
in classBasePrepareStatement
- Throws:
java.sql.SQLException
-
addBatch
public void addBatch() throws java.sql.SQLException
- Specified by:
addBatch
in interfacejava.sql.PreparedStatement
- Throws:
java.sql.SQLException
-
addBatch
public void addBatch(java.lang.String sql) throws java.sql.SQLException
Add batch.- Specified by:
addBatch
in interfacejava.sql.Statement
- Overrides:
addBatch
in classMariaDbStatement
- Parameters:
sql
- typically this is a SQLINSERT
orUPDATE
statement- Throws:
java.sql.SQLException
- every time since that method is forbidden on prepareStatement- See Also:
MariaDbStatement.executeBatch()
,DatabaseMetaData.supportsBatchUpdates()
-
clearBatch
public void clearBatch()
Description copied from class:MariaDbStatement
Empties thisStatement
object's current list of SQL send.- Specified by:
clearBatch
in interfacejava.sql.Statement
- Overrides:
clearBatch
in classMariaDbStatement
- See Also:
MariaDbStatement.addBatch(java.lang.String)
,DatabaseMetaData.supportsBatchUpdates()
-
getParameterMetaData
public java.sql.ParameterMetaData getParameterMetaData() throws java.sql.SQLException
Description copied from class:BasePrepareStatement
Retrieves the number, types and properties of thisPreparedStatement
object's parameters.- Specified by:
getParameterMetaData
in interfacejava.sql.PreparedStatement
- Specified by:
getParameterMetaData
in classBasePrepareStatement
- Returns:
- a
ParameterMetaData
object that contains information about the number, types and properties for each parameter marker of thisPreparedStatement
object - Throws:
java.sql.SQLException
- if a database access error occurs or this method is called on a closedPreparedStatement
- See Also:
ParameterMetaData
-
getMetaData
public java.sql.ResultSetMetaData getMetaData() throws java.sql.SQLException
- Specified by:
getMetaData
in interfacejava.sql.PreparedStatement
- Throws:
java.sql.SQLException
-
executeBatch
public int[] executeBatch() throws java.sql.SQLException
Submits a batch of send to the database for execution and if all send execute successfully, returns an array of update counts. Theint
elements of the array that is returned are ordered to correspond to the send in the batch, which are ordered according to the order in which they were added to the batch. The elements in the array returned by the methodexecuteBatch
may be one of the following:- A number greater than or equal to zero -- indicates that the command was processed successfully and is an update count giving the number of rows in the database that were affected by the command's execution
- A value of
SUCCESS_NO_INFO
-- indicates that the command was processed successfully but that the number of rows affected is unknown. If one of the send in a batch update fails to execute properly, this method throws aBatchUpdateException
, and a JDBC driver may or may not continue to process the remaining send in the batch. However, the driver's behavior must be consistent with a particular DBMS, either always continuing to process send or never continuing to process send. If the driver continues processing after a failure, the array returned by the methodBatchUpdateException.getUpdateCounts
will contain as many elements as there are send in the batch, and at least one of the elements will be the following: - A value of
EXECUTE_FAILED
-- indicates that the command failed to execute successfully and occurs only if a driver continues to process send after a command fails
The possible implementations and return values have been modified in the Java 2 SDK, Standard Edition, version 1.3 to accommodate the option of continuing to proccess send in a batch update after a
BatchUpdateException
object has been thrown.- Specified by:
executeBatch
in interfacejava.sql.Statement
- Overrides:
executeBatch
in classMariaDbStatement
- Returns:
- an array of update counts containing one element for each command in the batch. The elements of the array are ordered according to the order in which send were added to the batch.
- Throws:
java.sql.SQLException
- if a database access error occurs, this method is called on a closedStatement
or the driver does not support batch statements. ThrowsBatchUpdateException
(a subclass ofSQLException
) if one of the send sent to the database fails to execute properly or attempts to return a result set.- Since:
- 1.3
- See Also:
addBatch()
,DatabaseMetaData.supportsBatchUpdates()
-
executeLargeBatch
public long[] executeLargeBatch() throws java.sql.SQLException
Execute batch, like executeBatch(), with returning results with long[]. For when row count may exceed Integer.MAX_VALUE.- Specified by:
executeLargeBatch
in interfacejava.sql.Statement
- Overrides:
executeLargeBatch
in classMariaDbStatement
- Returns:
- an array of update counts (one element for each command in the batch)
- Throws:
java.sql.SQLException
- if a database error occur.
-
executeBatchInternal
private void executeBatchInternal(int queryParameterSize) throws java.sql.SQLException
- Throws:
java.sql.SQLException
-
executeQueryPrologue
private void executeQueryPrologue(ServerPrepareResult serverPrepareResult) throws java.sql.SQLException
- Throws:
java.sql.SQLException
-
executeQuery
public java.sql.ResultSet executeQuery() throws java.sql.SQLException
- Specified by:
executeQuery
in interfacejava.sql.PreparedStatement
- Throws:
java.sql.SQLException
-
executeUpdate
public int executeUpdate() throws java.sql.SQLException
Executes the SQL statement in thisPreparedStatement
object, which must be an SQL Data Manipulation Language (DML) statement, such asINSERT
,UPDATE
orDELETE
; or an SQL statement that returns nothing, such as a DDL statement. Result-set are permitted for historical reason, even if spec indicate to throw exception.- Specified by:
executeUpdate
in interfacejava.sql.PreparedStatement
- Returns:
- either (1) the row count for SQL Data Manipulation Language (DML) statements or (2) 0 for SQL statements that return nothing
- Throws:
java.sql.SQLException
- if a database access error occurs; this method is called on a closedPreparedStatement
-
clearParameters
public void clearParameters()
- Specified by:
clearParameters
in interfacejava.sql.PreparedStatement
-
execute
public boolean execute() throws java.sql.SQLException
- Specified by:
execute
in interfacejava.sql.PreparedStatement
- Throws:
java.sql.SQLException
-
validParameters
protected void validParameters() throws java.sql.SQLException
- Throws:
java.sql.SQLException
-
executeInternal
protected boolean executeInternal(int fetchSize) throws java.sql.SQLException
- Specified by:
executeInternal
in classBasePrepareStatement
- Throws:
java.sql.SQLException
-
close
public void close() throws java.sql.SQLException
Releases thisStatement
object's database and JDBC resources immediately instead of waiting for this to happen when it is automatically closed. It is generally good practice to release resources as soon as you are finished with them to avoid tying up database resources.Calling the method
close
on aStatement
object that is already closed has no effect.Note:When a
Statement
object is closed, its currentResultSet
object, if one exists, is also closed.- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.sql.Statement
- Overrides:
close
in classMariaDbStatement
- Throws:
java.sql.SQLException
- if a database access error occurs
-
getParameterCount
protected int getParameterCount()
-
toString
public java.lang.String toString()
Return sql String value.- Overrides:
toString
in classjava.lang.Object
- Returns:
- String representation
-
getServerThreadId
public long getServerThreadId()
Permit to retrieve current connection thread id, or -1 if unknown.- Returns:
- current connection thread id.
-
-