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);
}
}
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;
}
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();
}
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);
}
}
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);
}
}
Aggregations