use of jdk.incubator.sql2.SqlException in project oracle-db-examples by oracle.
the class MultiOperationTest method multiRowCountOperation.
/**
* Do something that approximates real work. Do a transaction. Uses
* TransactionCompletion, CompletionStage args, and catch Operation.
*/
@Test
public void multiRowCountOperation() throws Exception {
fail("TODO: Fix this test");
DataSourceFactory factory = DataSourceFactory.newFactory(FACTORY_NAME);
try (DataSource ds = factory.builder().url(URL).username(USER).password(PASSWORD).build();
Session session = ds.getSession(t -> fail("ERROR: " + t.getMessage()))) {
assertNotNull(session);
TransactionCompletion trans = session.transactionCompletion();
MultiOperation multiOp = session.multiOperation("update forum_user set city_id = ?" + " where id = ?").set("1", 40, AdbaType.INTEGER).set("2", 7782, AdbaType.INTEGER).onError(t -> {
System.out.println(t.toString());
});
RowCountOperation<Long> cntOp = multiOp.<Long>rowCountOperation();
multiOp.submit();
cntOp.apply(c -> {
long count = c.getCount();
if (count != 1L)
throw new SqlException("updated wrong number of rows", null, null, -1, null, -1);
return count;
}).onError(t -> t.printStackTrace()).submit().getCompletionStage().thenAccept(c -> {
assertTrue((long) c > 0);
});
session.catchErrors();
session.rollback().toCompletableFuture().get(TestConfig.getTimeout().toMillis(), TimeUnit.MILLISECONDS);
}
}
use of jdk.incubator.sql2.SqlException in project oracle-db-examples by oracle.
the class RowBaseOperation method initRowOperationResultSet.
protected void initRowOperationResultSet(PreparedStatement jdbcStatement, ResultSet resultSet) {
try {
this.jdbcStatement = jdbcStatement;
initFetchSize();
this.resultSet = resultSet;
resultSetMetaData = this.resultSet.getMetaData();
rowsRemain = true;
rowCount = 0;
} catch (SQLException ex) {
throw new SqlException(ex.getMessage(), ex, ex.getSQLState(), ex.getErrorCode(), sqlString, -1);
}
}
use of jdk.incubator.sql2.SqlException in project oracle-db-examples by oracle.
the class RowBaseOperation method executeJdbcQuery.
protected void executeJdbcQuery() {
checkCanceled();
try {
jdbcStatement = session.prepareStatement(sqlString);
initFetchSize();
setParameters.forEach((String k, ParameterValue v) -> {
v.set(jdbcStatement, k);
});
group.logger.log(Level.FINE, () -> "executeQuery(\"" + sqlString + "\")");
resultSet = jdbcStatement.executeQuery();
resultSetMetaData = resultSet.getMetaData();
rowsRemain = true;
rowCount = 0;
} catch (SQLException ex) {
throw new SqlException(ex.getMessage(), ex, ex.getSQLState(), ex.getErrorCode(), sqlString, -1);
}
}
use of jdk.incubator.sql2.SqlException in project oracle-db-examples by oracle.
the class Session method jdbcConnect.
// JDBC operations. These are all blocking
private Void jdbcConnect(com.oracle.adbaoverjdbc.Operation<Void> op) {
try {
Properties info = (Properties) properties.get(JdbcConnectionProperties.JDBC_CONNECTION_PROPERTIES);
info = (Properties) (info == null ? JdbcConnectionProperties.JDBC_CONNECTION_PROPERTIES.defaultValue() : info.clone());
Properties sensitiveInfo = (Properties) properties.get(JdbcConnectionProperties.SENSITIVE_JDBC_CONNECTION_PROPERTIES);
if (sensitiveInfo != null)
info.putAll(sensitiveInfo);
String user = (String) properties.get(AdbaSessionProperty.USER);
if (user != null)
info.setProperty("user", user);
String password = (String) properties.get(AdbaSessionProperty.PASSWORD);
if (password != null)
info.setProperty("password", password);
String url = (String) properties.get(AdbaSessionProperty.URL);
Properties p = info;
group.logger.log(Level.FINE, () -> "DriverManager.getSession(\"" + url + "\", " + p + ")");
jdbcConnection = DriverManager.getConnection(url, info);
jdbcConnection.setAutoCommit(false);
if (sessionLifecycle == Lifecycle.ABORTING)
closeImmediate();
else
setLifecycle(Session.Lifecycle.ATTACHED);
return null;
} catch (SQLException ex) {
setLifecycle(Session.Lifecycle.CLOSED);
throw new SqlException(ex.getMessage(), ex, ex.getSQLState(), ex.getErrorCode(), null, -1);
}
}
use of jdk.incubator.sql2.SqlException in project oracle-db-examples by oracle.
the class Session method jdbcEndTransaction.
TransactionOutcome jdbcEndTransaction(SimpleOperation<TransactionOutcome> op, TransactionCompletion trans) {
try {
if (trans.endWithCommit(this)) {
// DEBUG
group.logger.log(Level.FINE, () -> "commit");
jdbcConnection.commit();
return TransactionOutcome.COMMIT;
} else {
// DEBUG
group.logger.log(Level.FINE, () -> "rollback");
jdbcConnection.rollback();
return TransactionOutcome.ROLLBACK;
}
} catch (SQLException ex) {
throw new SqlException(ex.getMessage(), ex, ex.getSQLState(), ex.getErrorCode(), null, -1);
}
}
Aggregations