Search in sources :

Example 11 with ResultInterface

use of com.wplatform.ddal.result.ResultInterface in project jdbc-shards by wplatform.

the class CommandList method query.

@Override
public ResultInterface query(int maxrows) {
    ResultInterface result = command.query(maxrows);
    executeRemaining();
    return result;
}
Also used : ResultInterface(com.wplatform.ddal.result.ResultInterface)

Example 12 with ResultInterface

use of com.wplatform.ddal.result.ResultInterface in project jdbc-shards by wplatform.

the class ReplaceExecutor method executeUpdate.

@Override
public int executeUpdate() {
    Column[] columns = prepared.getColumns();
    TableMate table = castTableMate(prepared.getTable());
    ArrayList<Expression[]> list = prepared.getList();
    table.check();
    int count;
    session.getUser().checkRight(table, Right.INSERT);
    session.getUser().checkRight(table, Right.UPDATE);
    prepared.setCurrentRowNumber(0);
    if (list.size() > 0) {
        count = 0;
        for (int x = 0, size = list.size(); x < size; x++) {
            prepared.setCurrentRowNumber(x + 1);
            Expression[] expr = list.get(x);
            Row newRow = table.getTemplateRow();
            for (int i = 0, len = columns.length; i < len; i++) {
                Column c = columns[i];
                int index = c.getColumnId();
                Expression e = expr[i];
                if (e != null) {
                    // e can be null (DEFAULT)
                    try {
                        Value v = c.convert(e.getValue(session));
                        newRow.setValue(index, v);
                    } catch (DbException ex) {
                        throw prepared.setRow(ex, count, Prepared.getSQL(expr));
                    }
                }
            }
            replace(newRow);
            count++;
        }
    } else {
        Query query = prepared.getQuery();
        ResultInterface rows = query.query(0);
        count = 0;
        while (rows.next()) {
            count++;
            Value[] r = rows.currentRow();
            Row newRow = table.getTemplateRow();
            prepared.setCurrentRowNumber(count);
            for (int j = 0; j < columns.length; j++) {
                Column c = columns[j];
                int index = c.getColumnId();
                try {
                    Value v = c.convert(r[j]);
                    newRow.setValue(index, v);
                } catch (DbException ex) {
                    throw prepared.setRow(ex, count, Prepared.getSQL(r));
                }
            }
            replace(newRow);
        }
        rows.close();
    }
    return count;
}
Also used : ResultInterface(com.wplatform.ddal.result.ResultInterface) Query(com.wplatform.ddal.command.dml.Query) DbException(com.wplatform.ddal.message.DbException) Column(com.wplatform.ddal.dbobject.table.Column) Expression(com.wplatform.ddal.command.expression.Expression) Value(com.wplatform.ddal.value.Value) TableMate(com.wplatform.ddal.dbobject.table.TableMate) Row(com.wplatform.ddal.result.Row) SearchRow(com.wplatform.ddal.result.SearchRow)

Example 13 with ResultInterface

use of com.wplatform.ddal.result.ResultInterface in project jdbc-shards by wplatform.

the class JdbcPreparedStatement method getMetaData.

/**
     * Gets the result set metadata of the query returned when the statement is
     * executed. If this is not a query, this method returns null.
     *
     * @return the meta data or null if this is not a query
     * @throws SQLException if this object is closed
     */
@Override
public ResultSetMetaData getMetaData() throws SQLException {
    try {
        debugCodeCall("getMetaData");
        checkClosed();
        ResultInterface result = command.getMetaData();
        if (result == null) {
            return null;
        }
        int id = getNextId(TraceObject.RESULT_SET_META_DATA);
        if (isDebugEnabled()) {
            debugCodeAssign("ResultSetMetaData", TraceObject.RESULT_SET_META_DATA, id, "getMetaData()");
        }
        String catalog = conn.getCatalog();
        JdbcResultSetMetaData meta = new JdbcResultSetMetaData(null, this, result, catalog, session.getTrace(), id);
        return meta;
    } catch (Exception e) {
        throw logAndConvert(e);
    }
}
Also used : ResultInterface(com.wplatform.ddal.result.ResultInterface) DbException(com.wplatform.ddal.message.DbException)

Example 14 with ResultInterface

use of com.wplatform.ddal.result.ResultInterface in project jdbc-shards by wplatform.

the class JdbcStatement method executeQuery.

/**
     * Executes a query (select statement) and returns the result set.
     * If another result set exists for this statement, this will be closed
     * (even if this statement fails).
     *
     * @param sql the SQL statement to execute
     * @return the result set
     */
@Override
public ResultSet executeQuery(String sql) throws SQLException {
    try {
        int id = getNextId(TraceObject.RESULT_SET);
        if (isDebugEnabled()) {
            debugCodeAssign("ResultSet", TraceObject.RESULT_SET, id, "executeQuery(" + quote(sql) + ")");
        }
        synchronized (session) {
            checkClosed();
            closeOldResultSet();
            sql = JdbcConnection.translateSQL(sql, escapeProcessing);
            CommandInterface command = conn.prepareCommand(sql, fetchSize);
            ResultInterface result;
            boolean scrollable = resultSetType != ResultSet.TYPE_FORWARD_ONLY;
            boolean updatable = resultSetConcurrency == ResultSet.CONCUR_UPDATABLE;
            setExecutingStatement(command);
            try {
                result = command.executeQuery(maxRows, scrollable);
            } finally {
                setExecutingStatement(null);
            }
            command.close();
            resultSet = new JdbcResultSet(conn, this, result, id, closedByResultSet, scrollable, updatable);
        }
        return resultSet;
    } catch (Exception e) {
        throw logAndConvert(e);
    }
}
Also used : ResultInterface(com.wplatform.ddal.result.ResultInterface) CommandInterface(com.wplatform.ddal.command.CommandInterface) DbException(com.wplatform.ddal.message.DbException)

Example 15 with ResultInterface

use of com.wplatform.ddal.result.ResultInterface in project jdbc-shards by wplatform.

the class JdbcConnection method getQueryTimeout.

/**
     * INTERNAL
     */
int getQueryTimeout() throws SQLException {
    try {
        if (queryTimeoutCache == -1) {
            checkClosed();
            getQueryTimeout = prepareCommand("SELECT VALUE FROM INFORMATION_SCHEMA.SETTINGS " + "WHERE NAME=?", getQueryTimeout);
            getQueryTimeout.getParameters().get(0).setValue(ValueString.get("QUERY_TIMEOUT"), false);
            ResultInterface result = getQueryTimeout.executeQuery(0, false);
            result.next();
            int queryTimeout = result.currentRow()[0].getInt();
            result.close();
            if (queryTimeout != 0) {
                // round to the next second, otherwise 999 millis would
                // return 0 seconds
                queryTimeout = (queryTimeout + 999) / 1000;
            }
            queryTimeoutCache = queryTimeout;
        }
        return queryTimeoutCache;
    } catch (Exception e) {
        throw logAndConvert(e);
    }
}
Also used : ResultInterface(com.wplatform.ddal.result.ResultInterface) Savepoint(java.sql.Savepoint) SQLClientInfoException(java.sql.SQLClientInfoException) SQLException(java.sql.SQLException) DbException(com.wplatform.ddal.message.DbException)

Aggregations

ResultInterface (com.wplatform.ddal.result.ResultInterface)15 DbException (com.wplatform.ddal.message.DbException)9 Value (com.wplatform.ddal.value.Value)5 Column (com.wplatform.ddal.dbobject.table.Column)4 SearchRow (com.wplatform.ddal.result.SearchRow)4 CommandInterface (com.wplatform.ddal.command.CommandInterface)3 Query (com.wplatform.ddal.command.dml.Query)3 Expression (com.wplatform.ddal.command.expression.Expression)3 TableMate (com.wplatform.ddal.dbobject.table.TableMate)3 Row (com.wplatform.ddal.result.Row)3 SQLClientInfoException (java.sql.SQLClientInfoException)2 SQLException (java.sql.SQLException)2 IndexCondition (com.wplatform.ddal.dbobject.index.IndexCondition)1 ResultSet (java.sql.ResultSet)1 Savepoint (java.sql.Savepoint)1 List (java.util.List)1