Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[CONJ-915] javadoc addition
  • Loading branch information
diego Dupin committed Jan 19, 2022
1 parent 0a96772 commit e8cf7ee
Show file tree
Hide file tree
Showing 175 changed files with 4,287 additions and 138 deletions.
37 changes: 37 additions & 0 deletions src/main/java/org/mariadb/jdbc/BaseCallableStatement.java
Expand Up @@ -17,14 +17,40 @@
import org.mariadb.jdbc.codec.Parameter;
import org.mariadb.jdbc.export.ExceptionFactory;

/** Common methods for function/stored procedure */
public abstract class BaseCallableStatement extends ServerPreparedStatement
implements CallableStatement {

/** Database name */
protected final String databaseName;

/** Procedure name */
protected final String procedureName;

/** parameter metadata */
protected CallableParameterMetaData parameterMetaData = null;

/** Declared output parameters */
protected final Set<Integer> outputParameters = new HashSet<>();

/** output parameter result */
private Result outputResult = null;

/**
* Constructor
*
* @param sql sql command
* @param con connection
* @param lock thread safe lock
* @param databaseName database name
* @param procedureName procedure name
* @param canUseServerTimeout indicate if server support server timeout
* @param canUseServerMaxRows indicate if server support server max rows
* @param resultSetType resultset type
* @param resultSetConcurrency resultset concurrency
* @param defaultFetchSize default fetch size
* @throws SQLException if prepare fails
*/
public BaseCallableStatement(
String sql,
Connection con,
Expand All @@ -51,8 +77,19 @@ public BaseCallableStatement(
this.procedureName = procedureName;
}

/**
* Indicate if callable statement is a function or a stored procedure
*
* @return indicate if is a function
*/
public abstract boolean isFunction();

/**
* Output result without output parameters
*
* @param i index
* @throws SQLException if any exception
*/
protected void outputResultFromRes(int i) throws SQLException {
this.outputResult = (Result) this.results.remove(this.results.size() - i);
this.outputResult.next();
Expand Down
50 changes: 48 additions & 2 deletions src/main/java/org/mariadb/jdbc/BasePreparedStatement.java
Expand Up @@ -22,12 +22,34 @@
import org.mariadb.jdbc.plugin.codec.*;
import org.mariadb.jdbc.util.ParameterList;

/** Common methods for prepare statement, for client and server prepare statement. */
public abstract class BasePreparedStatement extends Statement implements PreparedStatement {

/** parameters */
protected Parameters parameters;

/** batching parameters */
protected List<Parameters> batchParameters;

/** prepare statement sql command */
protected final String sql;

/** PREPARE command result */
protected Prepare prepareResult = null;

/**
* Constructor
*
* @param sql sql command
* @param con connection
* @param lock thread safe lock
* @param canUseServerTimeout indicate if server can support server timeout
* @param canUseServerMaxRows indicate if server can support max rows
* @param autoGeneratedKeys indicate if automatif generated key retrival is required
* @param resultSetType resultset type
* @param resultSetConcurrency resultset concurrency
* @param defaultFetchSize default fetch size
*/
public BasePreparedStatement(
String sql,
Connection con,
Expand All @@ -50,14 +72,29 @@ public BasePreparedStatement(
this.sql = sql;
}

/**
* Set PREPARE result
*
* @param prepareResult prepare result
*/
public void setPrepareResult(Prepare prepareResult) {
this.prepareResult = prepareResult;
}

/**
* Get cached metadata list
*
* @return metadata list
*/
public Column[] getMeta() {
return this.prepareResult.getColumns();
}

/**
* update cached metadata list
*
* @param ci metadata columns
*/
public void updateMeta(Column[] ci) {
this.prepareResult.setColumns(ci);
}
Expand All @@ -76,10 +113,21 @@ public void updateMeta(Column[] ci) {

public abstract ParameterMetaData getParameterMetaData() throws SQLException;

/**
* Set all parameters
*
* @param parameters parameters
*/
public void setParameters(Parameters parameters) {
this.parameters = parameters;
}

/**
* Set parameter
*
* @param index parameter index
* @param param parameter
*/
public void setParameter(int index, org.mariadb.jdbc.client.util.Parameter param) {
parameters.set(index, param);
}
Expand Down Expand Up @@ -955,8 +1003,6 @@ public void setNClob(int parameterIndex, Reader reader, long length) throws SQLE
* Sets the designated parameter to the given <code>java.sql.SQLXML</code> object. The driver
* converts this to an SQL <code>XML</code> value when it sends it to the database.
*
* <p>
*
* @param parameterIndex index of the first parameter is 1, the second is 2, ...
* @param xmlObject a <code>SQLXML</code> object that maps an SQL <code>XML</code> value
* @throws SQLException if parameterIndex does not correspond to a parameter marker in the SQL
Expand Down
20 changes: 18 additions & 2 deletions src/main/java/org/mariadb/jdbc/CallableParameterMetaData.java
Expand Up @@ -9,11 +9,22 @@
import java.util.BitSet;
import java.util.Locale;

/**
* Callable parameter metadata. Server doesn't give detailled information about parameter, so even
* if driver return those information, they are not completely accurate.
*/
public class CallableParameterMetaData implements java.sql.ParameterMetaData {
private final ResultSet rs;
private final int parameterCount;
private final boolean isFunction;

/**
* Constructor
*
* @param rs parameter result-set
* @param isFunction is command a function or a stored procedure
* @throws SQLException if any error occurs
*/
public CallableParameterMetaData(ResultSet rs, boolean isFunction) throws SQLException {
this.rs = rs;
int count = 0;
Expand Down Expand Up @@ -85,7 +96,6 @@ public boolean isSigned(int index) throws SQLException {
* @param index the first parameter is 1, the second is 2, ...
* @return precision
* @throws SQLException if a database access error occurs
* @since 1.4
*/
@Override
public int getPrecision(int index) throws SQLException {
Expand All @@ -102,14 +112,20 @@ public int getPrecision(int index) throws SQLException {
* @param index the first parameter is 1, the second is 2, ...
* @return scale
* @throws SQLException if a database access error occurs
* @since 1.4
*/
@Override
public int getScale(int index) throws SQLException {
setIndex(index);
return rs.getInt("NUMERIC_SCALE");
}

/**
* Return the parameter name corresponding to index.
*
* @param index index
* @return parameter name
* @throws SQLException if wrong index
*/
public String getParameterName(int index) throws SQLException {
setIndex(index);
return rs.getString("PARAMETER_NAME");
Expand Down
26 changes: 26 additions & 0 deletions src/main/java/org/mariadb/jdbc/ClientPreparedStatement.java
Expand Up @@ -23,9 +23,25 @@
import org.mariadb.jdbc.util.constants.Capabilities;
import org.mariadb.jdbc.util.constants.ServerStatus;

/**
* Client side prepare statement. Question mark will be replaced by escaped parameters, client side
*/
public class ClientPreparedStatement extends BasePreparedStatement {
private final ClientParser parser;

/**
* Client prepare statement constructor
*
* @param sql command
* @param con connection
* @param lock thread safe lock
* @param canUseServerTimeout can server use timeout
* @param canUseServerMaxRows can server use max rows
* @param autoGeneratedKeys must command return automatically generated keys
* @param resultSetType resultset type
* @param resultSetConcurrency resultset concurrency
* @param defaultFetchSize default fetch size
*/
public ClientPreparedStatement(
String sql,
Connection con,
Expand Down Expand Up @@ -53,6 +69,11 @@ public ClientPreparedStatement(
parameters = new ParameterList(parser.getParamCount());
}

/**
* use additional part for timeout if possible
*
* @return pre command for handling timeout
*/
protected String preSqlCmd() {
if (queryTimeout != 0 && canUseServerTimeout) {
return "SET STATEMENT max_statement_time=" + queryTimeout + " FOR ";
Expand Down Expand Up @@ -327,6 +348,11 @@ public void addBatch() throws SQLException {
parameters = parameters.clone();
}

/**
* Validate parameter number according to expected parameter.
*
* @throws SQLException if doesn't correspond
*/
protected void validParameters() throws SQLException {
for (int i = 0; i < parser.getParamCount(); i++) {
if (!parameters.containsKey(i)) {
Expand Down

0 comments on commit e8cf7ee

Please sign in to comment.