Search in sources :

Example 6 with ParameterInterface

use of com.wplatform.ddal.command.expression.ParameterInterface in project jdbc-shards by wplatform.

the class JdbcPreparedStatement method executeBatch.

/**
 * Executes the batch.
 * If one of the batched statements fails, this database will continue.
 *
 * @return the array of update counts
 */
@Override
public int[] executeBatch() throws SQLException {
    try {
        debugCodeCall("executeBatch");
        if (batchParameters == null) {
            // TODO batch: check what other database do if no parameters are
            // set
            batchParameters = New.arrayList();
        }
        int size = batchParameters.size();
        int[] result = new int[size];
        boolean error = false;
        SQLException next = null;
        checkClosedForWrite();
        try {
            for (int i = 0; i < size; i++) {
                Value[] set = batchParameters.get(i);
                ArrayList<? extends ParameterInterface> parameters = command.getParameters();
                for (int j = 0; j < set.length; j++) {
                    Value value = set[j];
                    ParameterInterface param = parameters.get(j);
                    param.setValue(value, false);
                }
                try {
                    result[i] = executeUpdateInternal();
                } catch (Exception re) {
                    SQLException e = logAndConvert(re);
                    if (next == null) {
                        next = e;
                    } else {
                        e.setNextException(next);
                        next = e;
                    }
                    result[i] = Statement.EXECUTE_FAILED;
                    error = true;
                }
            }
            batchParameters = null;
            if (error) {
                JdbcBatchUpdateException e = new JdbcBatchUpdateException(next, result);
                throw e;
            }
            return result;
        } finally {
            afterWriting();
        }
    } catch (Exception e) {
        throw logAndConvert(e);
    }
}
Also used : ParameterInterface(com.wplatform.ddal.command.expression.ParameterInterface) DbException(com.wplatform.ddal.message.DbException)

Example 7 with ParameterInterface

use of com.wplatform.ddal.command.expression.ParameterInterface in project jdbc-shards by wplatform.

the class JdbcPreparedStatement method clearParameters.

/**
 * Clears all parameters.
 *
 * @throws SQLException if this object is closed or invalid
 */
@Override
public void clearParameters() throws SQLException {
    try {
        debugCodeCall("clearParameters");
        checkClosed();
        ArrayList<? extends ParameterInterface> parameters = command.getParameters();
        for (int i = 0, size = parameters.size(); i < size; i++) {
            ParameterInterface param = parameters.get(i);
            // can only delete old temp files if they are not in the batch
            param.setValue(null, batchParameters == null);
        }
    } catch (Exception e) {
        throw logAndConvert(e);
    }
}
Also used : ParameterInterface(com.wplatform.ddal.command.expression.ParameterInterface) DbException(com.wplatform.ddal.message.DbException)

Example 8 with ParameterInterface

use of com.wplatform.ddal.command.expression.ParameterInterface in project jdbc-shards by wplatform.

the class Command method reuse.

/**
 * The command is now re-used, therefore reset the canReuse flag, and the
 * parameter values.
 */
public void reuse() {
    canReuse = false;
    ArrayList<? extends ParameterInterface> parameters = getParameters();
    for (int i = 0, size = parameters.size(); i < size; i++) {
        ParameterInterface param = parameters.get(i);
        param.setValue(null, true);
    }
}
Also used : ParameterInterface(com.wplatform.ddal.command.expression.ParameterInterface)

Example 9 with ParameterInterface

use of com.wplatform.ddal.command.expression.ParameterInterface in project jdbc-shards by wplatform.

the class JdbcCallableStatement method registerOutParameter.

private void registerOutParameter(int parameterIndex) throws SQLException {
    try {
        checkClosed();
        if (outParameters == null) {
            maxOutParameters = Math.min(getParameterMetaData().getParameterCount(), getCheckedMetaData().getColumnCount());
            outParameters = new BitField();
        }
        checkIndexBounds(parameterIndex);
        ParameterInterface param = command.getParameters().get(--parameterIndex);
        if (!param.isValueSet()) {
            param.setValue(ValueNull.INSTANCE, false);
        }
        outParameters.set(parameterIndex);
    } catch (Exception e) {
        throw logAndConvert(e);
    }
}
Also used : ParameterInterface(com.wplatform.ddal.command.expression.ParameterInterface) BitField(com.wplatform.ddal.util.BitField) DbException(com.wplatform.ddal.message.DbException)

Example 10 with ParameterInterface

use of com.wplatform.ddal.command.expression.ParameterInterface in project jdbc-shards by wplatform.

the class JdbcPreparedStatement method setParameter.

// =============================================================
private void setParameter(int parameterIndex, Value value) {
    checkClosed();
    parameterIndex--;
    ArrayList<? extends ParameterInterface> parameters = command.getParameters();
    if (parameterIndex < 0 || parameterIndex >= parameters.size()) {
        throw DbException.getInvalidValueException("parameterIndex", parameterIndex + 1);
    }
    ParameterInterface param = parameters.get(parameterIndex);
    // can only delete old temp files if they are not in the batch
    param.setValue(value, batchParameters == null);
}
Also used : ParameterInterface(com.wplatform.ddal.command.expression.ParameterInterface)

Aggregations

ParameterInterface (com.wplatform.ddal.command.expression.ParameterInterface)13 DbException (com.wplatform.ddal.message.DbException)9 SQLException (java.sql.SQLException)5 BitField (com.wplatform.ddal.util.BitField)1 StatementBuilder (com.wplatform.ddal.util.StatementBuilder)1 Value (com.wplatform.ddal.value.Value)1