Search in sources :

Example 1 with CommandInterface

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

the class JdbcStatement method executeInternal.

private boolean executeInternal(String sql) throws SQLException {
    int id = getNextId(TraceObject.RESULT_SET);
    checkClosedForWrite();
    try {
        closeOldResultSet();
        sql = JdbcConnection.translateSQL(sql, escapeProcessing);
        CommandInterface command = conn.prepareCommand(sql, fetchSize);
        boolean returnsResultSet;
        synchronized (session) {
            setExecutingStatement(command);
            try {
                if (command.isQuery()) {
                    returnsResultSet = true;
                    boolean scrollable = resultSetType != ResultSet.TYPE_FORWARD_ONLY;
                    boolean updatable = resultSetConcurrency == ResultSet.CONCUR_UPDATABLE;
                    ResultInterface result = command.executeQuery(maxRows, scrollable);
                    resultSet = new JdbcResultSet(conn, this, result, id, closedByResultSet, scrollable, updatable);
                } else {
                    returnsResultSet = false;
                    updateCount = command.executeUpdate();
                }
            } finally {
                setExecutingStatement(null);
            }
        }
        command.close();
        return returnsResultSet;
    } finally {
        afterWriting();
    }
}
Also used : ResultInterface(com.wplatform.ddal.result.ResultInterface) CommandInterface(com.wplatform.ddal.command.CommandInterface)

Example 2 with CommandInterface

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

the class JdbcStatement method executeUpdateInternal.

private int executeUpdateInternal(String sql) throws SQLException {
    checkClosedForWrite();
    try {
        closeOldResultSet();
        sql = JdbcConnection.translateSQL(sql, escapeProcessing);
        CommandInterface command = conn.prepareCommand(sql, fetchSize);
        synchronized (session) {
            setExecutingStatement(command);
            try {
                updateCount = command.executeUpdate();
            } finally {
                setExecutingStatement(null);
            }
        }
        command.close();
        return updateCount;
    } finally {
        afterWriting();
    }
}
Also used : CommandInterface(com.wplatform.ddal.command.CommandInterface)

Example 3 with CommandInterface

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

the class JdbcConnection method getCatalog.

/**
 * Gets the current catalog name.
 *
 * @return the catalog name
 * @throws SQLException if the connection is closed
 */
@Override
public String getCatalog() throws SQLException {
    try {
        debugCodeCall("getCatalog");
        checkClosed();
        if (catalog == null) {
            CommandInterface cat = prepareCommand("CALL DATABASE()", Integer.MAX_VALUE);
            ResultInterface result = cat.executeQuery(0, false);
            result.next();
            catalog = result.currentRow()[0].getString();
            cat.close();
        }
        return catalog;
    } catch (Exception e) {
        throw logAndConvert(e);
    }
}
Also used : ResultInterface(com.wplatform.ddal.result.ResultInterface) CommandInterface(com.wplatform.ddal.command.CommandInterface) SQLClientInfoException(java.sql.SQLClientInfoException) SQLException(java.sql.SQLException) DbException(com.wplatform.ddal.message.DbException)

Example 4 with CommandInterface

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

the class JdbcConnection method setSavepoint.

/**
 * Creates a new named savepoint.
 *
 * @param name the savepoint name
 * @return the new savepoint
 */
@Override
public Savepoint setSavepoint(String name) throws SQLException {
    try {
        int id = getNextId(TraceObject.SAVEPOINT);
        if (isDebugEnabled()) {
            debugCodeAssign("Savepoint", TraceObject.SAVEPOINT, id, "setSavepoint(" + quote(name) + ")");
        }
        checkClosed();
        CommandInterface set = prepareCommand("SAVEPOINT " + JdbcSavepoint.getName(name, 0), Integer.MAX_VALUE);
        set.executeUpdate();
        JdbcSavepoint savepoint = new JdbcSavepoint(this, 0, name, trace, id);
        return savepoint;
    } catch (Exception e) {
        throw logAndConvert(e);
    }
}
Also used : CommandInterface(com.wplatform.ddal.command.CommandInterface) Savepoint(java.sql.Savepoint) SQLClientInfoException(java.sql.SQLClientInfoException) SQLException(java.sql.SQLException) DbException(com.wplatform.ddal.message.DbException)

Example 5 with CommandInterface

use of com.wplatform.ddal.command.CommandInterface 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)

Aggregations

CommandInterface (com.wplatform.ddal.command.CommandInterface)7 DbException (com.wplatform.ddal.message.DbException)5 ResultInterface (com.wplatform.ddal.result.ResultInterface)3 SQLClientInfoException (java.sql.SQLClientInfoException)3 SQLException (java.sql.SQLException)3 Savepoint (java.sql.Savepoint)2