use of jdk.incubator.sql2.Session.Validation in project oracle-db-examples by oracle.
the class DataSourceTest method testGetSessionError.
@Test
public void testGetSessionError() throws Exception {
// Use an invalid URL to get an error message
String url = "jdbc:oracle:not_thin:localhost:5521";
String user = getUser();
String password = getPassword();
try (DataSource ds = dsFactory.builder().url(url).username(user).password(password).build()) {
AtomicReference<Throwable> errConsumer = new AtomicReference<>();
ExecutionException validEx = null;
try (Session session = ds.getSession(errConsumer::set)) {
session.validationOperation(Validation.COMPLETE).timeout(getTimeout()).submit().getCompletionStage().toCompletableFuture().get();
} catch (ExecutionException exeEx) {
// Expecting exceptional completion of the validation operation
validEx = exeEx;
}
// Verify that the errConsumer was invoked, and that the validation
// operation completed with the same error.
Throwable attachEx = errConsumer.get();
assertTrue(attachEx instanceof CompletionException);
assertNotNull(validEx);
// TODO: If attach operation fails, should the validation operation
// complete with SqlSkipped?
// assertTrue(validEx.getCause() instanceof SqlSkippedException);
// assertEquals(attachEx.getCause(), validEx.getCause().getCause());
assertEquals(attachEx.getCause(), validEx.getCause());
}
}
use of jdk.incubator.sql2.Session.Validation in project oracle-db-examples by oracle-samples.
the class Session method jdbcValidate.
private Void jdbcValidate(com.oracle.adbaoverjdbc.Operation<Void> op, Validation depth) {
try {
switch(depth) {
case COMPLETE:
case SERVER:
int timeoutSeconds = (int) (op.getTimeoutMillis() / 1000L);
// DEBUG
group.logger.log(Level.FINE, () -> "Session.isValid(" + timeoutSeconds + ")");
if (!jdbcConnection.isValid(timeoutSeconds)) {
throw new SqlException("validation failure", null, null, -1, null, -1);
}
break;
case NETWORK:
case SOCKET:
case LOCAL:
case NONE:
// DEBUG
group.logger.log(Level.FINE, () -> "Session.isClosed");
if (jdbcConnection.isClosed()) {
throw new SqlException("validation failure", null, null, -1, null, -1);
}
}
return null;
} catch (SQLException ex) {
throw new SqlException(ex.getMessage(), ex, ex.getSQLState(), ex.getErrorCode(), null, -1);
}
}
use of jdk.incubator.sql2.Session.Validation in project oracle-db-examples by oracle-samples.
the class DataSourceTest method testGetSessionError.
@Test
public void testGetSessionError() throws Exception {
// Use an invalid URL to get an error message
String url = "jdbc:oracle:not_thin:localhost:5521";
String user = getUser();
String password = getPassword();
try (DataSource ds = dsFactory.builder().url(url).username(user).password(password).build()) {
AtomicReference<Throwable> errConsumer = new AtomicReference<>();
ExecutionException validEx = null;
try (Session session = ds.getSession(errConsumer::set)) {
session.validationOperation(Validation.COMPLETE).timeout(getTimeout()).submit().getCompletionStage().toCompletableFuture().get();
} catch (ExecutionException exeEx) {
// Expecting exceptional completion of the validation operation
validEx = exeEx;
}
// Verify that the errConsumer was invoked, and that the validation
// operation completed with the same error.
Throwable attachEx = errConsumer.get();
assertTrue(attachEx instanceof CompletionException);
assertNotNull(validEx);
// TODO: If attach operation fails, should the validation operation
// complete with SqlSkipped?
// assertTrue(validEx.getCause() instanceof SqlSkippedException);
// assertEquals(attachEx.getCause(), validEx.getCause().getCause());
assertEquals(attachEx.getCause(), validEx.getCause());
}
}
use of jdk.incubator.sql2.Session.Validation in project oracle-db-examples by oracle.
the class Session method jdbcValidate.
private Void jdbcValidate(com.oracle.adbaoverjdbc.Operation<Void> op, Validation depth) {
try {
switch(depth) {
case COMPLETE:
case SERVER:
int timeoutSeconds = (int) (op.getTimeoutMillis() / 1000L);
// DEBUG
group.logger.log(Level.FINE, () -> "Session.isValid(" + timeoutSeconds + ")");
if (!jdbcConnection.isValid(timeoutSeconds)) {
throw new SqlException("validation failure", null, null, -1, null, -1);
}
break;
case NETWORK:
case SOCKET:
case LOCAL:
case NONE:
// DEBUG
group.logger.log(Level.FINE, () -> "Session.isClosed");
if (jdbcConnection.isClosed()) {
throw new SqlException("validation failure", null, null, -1, null, -1);
}
}
return null;
} catch (SQLException ex) {
throw new SqlException(ex.getMessage(), ex, ex.getSQLState(), ex.getErrorCode(), null, -1);
}
}
Aggregations