Search in sources :

Example 1 with ISqlStyle

use of org.eclipse.scout.rt.server.jdbc.style.ISqlStyle in project scout.rt by eclipse.

the class AbstractSqlService method commit.

@Override
public void commit() {
    try {
        getTransaction().commit();
        ISqlStyle style = getSqlStyle();
        if (style != null) {
            style.commit();
        }
    } catch (SQLException e) {
        throw new ProcessingException("Failed to commit", e);
    }
}
Also used : ISqlStyle(org.eclipse.scout.rt.server.jdbc.style.ISqlStyle) SQLException(java.sql.SQLException) ProcessingException(org.eclipse.scout.rt.platform.exception.ProcessingException)

Example 2 with ISqlStyle

use of org.eclipse.scout.rt.server.jdbc.style.ISqlStyle in project scout.rt by eclipse.

the class StatementProcessor method processResultRow.

protected Object[] processResultRow(ResultSet rs) throws SQLException {
    ISqlStyle sqlStyle = m_callerService.getSqlStyle();
    ResultSetMetaData meta = rs.getMetaData();
    int colCount = meta.getColumnCount();
    Object[] row = new Object[colCount];
    for (int i = 0; i < colCount; i++) {
        int type = meta.getColumnType(i + 1);
        row[i] = sqlStyle.readBind(rs, meta, type, i + 1);
    }
    return row;
}
Also used : ResultSetMetaData(java.sql.ResultSetMetaData) ISqlStyle(org.eclipse.scout.rt.server.jdbc.style.ISqlStyle)

Example 3 with ISqlStyle

use of org.eclipse.scout.rt.server.jdbc.style.ISqlStyle in project scout.rt by eclipse.

the class StatementProcessor method prepareInputStatementAndBinds.

private void prepareInputStatementAndBinds() {
    // bind inputs and set replace token on inputs
    m_currentInputBindMap = new TreeMap<Integer, SqlBind>();
    ISqlStyle sqlStyle = m_callerService.getSqlStyle();
    for (IBindInput in : m_inputList) {
        SqlBind bind = in.produceSqlBindAndSetReplaceToken(sqlStyle);
        assert (bind != null) == in.isJdbcBind(sqlStyle);
        if (bind != null) {
            m_currentInputBindMap.put(in.getJdbcBindIndex(), bind);
        }
    }
    // set replace token on outputs
    for (IBindOutput out : m_outputList) {
        out.setReplaceToken(sqlStyle);
    }
    m_currentInputStm = m_bindModel.getFilteredStatement();
}
Also used : SqlBind(org.eclipse.scout.rt.server.jdbc.SqlBind) ISqlStyle(org.eclipse.scout.rt.server.jdbc.style.ISqlStyle)

Example 4 with ISqlStyle

use of org.eclipse.scout.rt.server.jdbc.style.ISqlStyle in project scout.rt by eclipse.

the class StatementProcessor method processSelectStreaming.

@SuppressWarnings({ "resource", "squid:S2095" })
@Override
public void processSelectStreaming(Connection conn, IStatementCache cache, ISelectStreamHandler handler) {
    PreparedStatement ps = null;
    ResultSet rs = null;
    ISqlStyle sqlStyle = m_callerService.getSqlStyle();
    try {
        int rowCount = 0;
        while (hasNextInputBatch()) {
            nextInputBatch();
            prepareInputStatementAndBinds();
            dump();
            ps = cache.getPreparedStatement(conn, m_currentInputStm);
            bindBatch(ps);
            registerActiveStatement(ps);
            try {
                rs = ps.executeQuery();
                ResultSetMetaData meta = rs.getMetaData();
                int colCount = meta.getColumnCount();
                while (rs.next()) {
                    ArrayList<SqlBind> row = new ArrayList<SqlBind>(colCount);
                    for (int i = 0; i < colCount; i++) {
                        int type = meta.getColumnType(i + 1);
                        Object value = sqlStyle.readBind(rs, meta, type, i + 1);
                        row.add(new SqlBind(type, value));
                    }
                    handler.handleRow(conn, ps, rs, rowCount, row);
                    rowCount++;
                    if (m_maxRowCount > 0 && rowCount >= m_maxRowCount) {
                        break;
                    }
                }
            } finally {
                unregisterActiveStatement(ps);
                /*
           * The PreparedStatement and the ResultSet of the last input batch are not allowed to be closed
           * yet because the handler could do finishing work.
           * Closing the last PreparedStatement and its ResultSet is done in the outer finally block.
           */
                if (hasNextInputBatch()) {
                    releasePreparedStatementAndResultSet(ps, cache, rs);
                }
            }
        }
        finishOutputBatch();
        handler.finished(conn, ps, rs, rowCount);
    } catch (SQLException | RuntimeException e) {
        throw BEANS.get(PlatformExceptionTranslator.class).translate(e).withContextInfo("statement", createSqlDump(true, false));
    } finally {
        releasePreparedStatementAndResultSet(ps, cache, rs);
    }
}
Also used : SqlBind(org.eclipse.scout.rt.server.jdbc.SqlBind) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) PreparedStatement(java.sql.PreparedStatement) ResultSetMetaData(java.sql.ResultSetMetaData) ISqlStyle(org.eclipse.scout.rt.server.jdbc.style.ISqlStyle) ResultSet(java.sql.ResultSet) PlatformExceptionTranslator(org.eclipse.scout.rt.platform.exception.PlatformExceptionTranslator)

Example 5 with ISqlStyle

use of org.eclipse.scout.rt.server.jdbc.style.ISqlStyle in project scout.rt by eclipse.

the class AbstractSqlService method rollback.

/**
 * When the service completes work with an exception, a xa rollback is done on ALL used service request resources
 *
 * @see AbstractSqlService#commit()
 */
@Override
public void rollback() {
    try {
        getTransaction().rollback();
        ISqlStyle style = getSqlStyle();
        if (style != null) {
            style.rollback();
        }
    } catch (SQLException e) {
        throw new ProcessingException("Failed to rollback", e);
    }
}
Also used : ISqlStyle(org.eclipse.scout.rt.server.jdbc.style.ISqlStyle) SQLException(java.sql.SQLException) ProcessingException(org.eclipse.scout.rt.platform.exception.ProcessingException)

Aggregations

ISqlStyle (org.eclipse.scout.rt.server.jdbc.style.ISqlStyle)6 SQLException (java.sql.SQLException)3 SqlBind (org.eclipse.scout.rt.server.jdbc.SqlBind)3 ResultSetMetaData (java.sql.ResultSetMetaData)2 ProcessingException (org.eclipse.scout.rt.platform.exception.ProcessingException)2 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 ArrayList (java.util.ArrayList)1 PlatformExceptionTranslator (org.eclipse.scout.rt.platform.exception.PlatformExceptionTranslator)1 NVPair (org.eclipse.scout.rt.platform.holders.NVPair)1 ISqlService (org.eclipse.scout.rt.server.jdbc.ISqlService)1