use of jdk.incubator.sql2.DataSourceFactory in project oracle-db-examples by oracle.
the class MultiOperationTest method multiOutOperationTest.
// @Test TODO: Test suite needs procedural SQL for any database
public void multiOutOperationTest() {
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.toString()))) {
final int empno = 7369;
invokeOutOpProc(session, empno);
}
ForkJoinPool.commonPool().awaitQuiescence(1, TimeUnit.MINUTES);
}
use of jdk.incubator.sql2.DataSourceFactory 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.DataSourceFactory in project oracle-db-examples by oracle.
the class MultiOperationTest method multiRowCountOperationWithCountHandler.
@Test
public void multiRowCountOperationWithCountHandler() 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);
BiConsumer<Integer, RowCountOperation<Long>> countHandler = (resNum, cntOp) -> {
assertTrue(resNum > 0);
cntOp.apply(c -> {
long count = c.getCount();
if (count != 1L)
fail("updated wrong number of rows");
return count;
}).onError(t -> fail(t.toString())).submit().getCompletionStage().thenAccept(c -> {
assertTrue(c > 0);
});
};
MultiOperation multiOp = session.multiOperation("update forum_user" + " set city_id = ?" + " where id = ?").set("1", 40, AdbaType.INTEGER).set("2", 7782, AdbaType.INTEGER).onError(t -> {
fail(t.toString());
});
multiOp.onCount(countHandler).submit();
session.catchErrors();
session.rollback().toCompletableFuture().get(TestConfig.getTimeout().toMillis(), TimeUnit.MILLISECONDS);
}
}
use of jdk.incubator.sql2.DataSourceFactory in project oracle-db-examples by oracle.
the class MultiOperationTest method multiRowOperationWithRowHandler.
/**
* Execute a query returning a single result.
*/
@Test
public void multiRowOperationWithRowHandler() {
fail("TODO: Fix this test");
Properties props = new Properties();
DataSourceFactory factory = DataSourceFactory.newFactory(FACTORY_NAME);
try (DataSource ds = factory.builder().url(URL).username(USER).password(PASSWORD).sessionProperty(JDBC_CONNECTION_PROPERTIES, props).build();
Session session = ds.getSession(t -> fail("ERROR: " + t.getMessage()))) {
assertNotNull(session);
MultiOperation multiOp = session.multiOperation("select * from forum_user").onError(t -> {
fail(t.toString());
});
BiConsumer<Integer, RowOperation<Integer>> rowHandler = (resNum, rowOp) -> {
assertTrue(resNum > 0);
rowOp.collect(Collector.<Result.RowColumn, int[], Integer>of(() -> new int[1], (int[] a, Result.RowColumn r) -> {
a[0] = a[0] + r.at("sal").get(Integer.class);
}, (l, r) -> l, a -> (Integer) a[0])).onError(t -> {
fail(t.toString());
}).submit().getCompletionStage().thenAccept(n -> {
assertTrue((long) n > 0);
}).toCompletableFuture();
};
multiOp.onRows(rowHandler).submit().getCompletionStage().toCompletableFuture().get(TestConfig.getTimeout().toMillis(), TimeUnit.MILLISECONDS);
} catch (Exception e) {
fail(e.getMessage());
}
}
use of jdk.incubator.sql2.DataSourceFactory in project oracle-db-examples by oracle.
the class RowCountOperationTestWithDMLReturning method transaction.
/**
* Do something that approximates real work. Do a transaction. Uses
* TransactionCompletion, CompletionStage args, and catch Operation.
*/
@Test
public void transaction() throws Exception {
DataSourceFactory factory = DataSourceFactory.newFactory(FACTORY_NAME);
try (DataSource ds = factory.builder().url(URL).username(USER).password(PASSWORD).build();
Session session = ds.getSession(t -> System.out.println("ERROR: " + t.toString()))) {
ParameterizedRowCountOperation<Long> countOpReturning = session.<Long>rowCountOperation("insert into " + TEST_TABLE + "(C11) values (1)");
countOpReturning.returning(new String[] { "C12" }).collect(Collector.of(() -> null, (a, r) -> assertEquals(1, r.at(1).get(Integer.class).intValue()), (l, r) -> null)).onError(t -> fail(t.getMessage())).submit();
ParameterizedRowCountOperation<Long> countOpApplying = session.<Long>rowCountOperation("insert into " + TEST_TABLE + "(C11) values (1)");
countOpApplying.apply(Result.RowCount::getCount).onError(t -> fail(t.getMessage())).submit().getCompletionStage().thenAccept(c -> assertEquals(1L, c.longValue()));
session.catchErrors();
session.rollback().toCompletableFuture().get(TestConfig.getTimeout().toMillis(), TimeUnit.MILLISECONDS);
}
}
Aggregations