Search in sources :

Example 1 with ParameterInterface

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

the class JdbcParameterMetaData method getScale.

/**
     * Returns the parameter scale.
     * The value 0 is returned if the scale is not known.
     *
     * @param param the column index (1,2,...)
     * @return the scale
     */
@Override
public int getScale(int param) throws SQLException {
    try {
        debugCodeCall("getScale", param);
        ParameterInterface p = getParameter(param);
        return p.getScale();
    } catch (Exception e) {
        throw logAndConvert(e);
    }
}
Also used : ParameterInterface(com.wplatform.ddal.command.expression.ParameterInterface) SQLException(java.sql.SQLException) DbException(com.wplatform.ddal.message.DbException)

Example 2 with ParameterInterface

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

the class JdbcParameterMetaData method getParameterType.

/**
     * Returns the parameter type.
     * java.sql.Types.VARCHAR is returned if the data type is not known.
     *
     * @param param the column index (1,2,...)
     * @return the data type
     */
@Override
public int getParameterType(int param) throws SQLException {
    try {
        debugCodeCall("getParameterType", param);
        ParameterInterface p = getParameter(param);
        int type = p.getType();
        if (type == Value.UNKNOWN) {
            type = Value.STRING;
        }
        return DataType.getDataType(type).sqlType;
    } catch (Exception e) {
        throw logAndConvert(e);
    }
}
Also used : ParameterInterface(com.wplatform.ddal.command.expression.ParameterInterface) SQLException(java.sql.SQLException) DbException(com.wplatform.ddal.message.DbException)

Example 3 with ParameterInterface

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

the class JdbcParameterMetaData method getParameterClassName.

/**
     * Returns the Java class name of the parameter.
     * "java.lang.String" is returned if the type is not known.
     *
     * @param param the column index (1,2,...)
     * @return the Java class name
     */
@Override
public String getParameterClassName(int param) throws SQLException {
    try {
        debugCodeCall("getParameterClassName", param);
        ParameterInterface p = getParameter(param);
        int type = p.getType();
        if (type == Value.UNKNOWN) {
            type = Value.STRING;
        }
        return DataType.getTypeClassName(type);
    } catch (Exception e) {
        throw logAndConvert(e);
    }
}
Also used : ParameterInterface(com.wplatform.ddal.command.expression.ParameterInterface) SQLException(java.sql.SQLException) DbException(com.wplatform.ddal.message.DbException)

Example 4 with ParameterInterface

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

the class JdbcParameterMetaData method getPrecision.

/**
     * Returns the parameter precision.
     * The value 0 is returned if the precision is not known.
     *
     * @param param the column index (1,2,...)
     * @return the precision
     */
@Override
public int getPrecision(int param) throws SQLException {
    try {
        debugCodeCall("getPrecision", param);
        ParameterInterface p = getParameter(param);
        return MathUtils.convertLongToInt(p.getPrecision());
    } catch (Exception e) {
        throw logAndConvert(e);
    }
}
Also used : ParameterInterface(com.wplatform.ddal.command.expression.ParameterInterface) SQLException(java.sql.SQLException) DbException(com.wplatform.ddal.message.DbException)

Example 5 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)

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