Search in sources :

Example 1 with JDBC_CONNECTION_PROPERTIES

use of com.oracle.adbaoverjdbc.JdbcConnectionProperties.JDBC_CONNECTION_PROPERTIES 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());
    }
}
Also used : DataSourceFactory(jdk.incubator.sql2.DataSourceFactory) BeforeClass(org.junit.BeforeClass) RowOperation(jdk.incubator.sql2.RowOperation) CompletableFuture(java.util.concurrent.CompletableFuture) ArrayList(java.util.ArrayList) SqlException(jdk.incubator.sql2.SqlException) OperationGroup(jdk.incubator.sql2.OperationGroup) Flow(java.util.concurrent.Flow) BiConsumer(java.util.function.BiConsumer) Collector(java.util.stream.Collector) Session(jdk.incubator.sql2.Session) AfterClass(org.junit.AfterClass) Properties(java.util.Properties) JDBC_CONNECTION_PROPERTIES(com.oracle.adbaoverjdbc.JdbcConnectionProperties.JDBC_CONNECTION_PROPERTIES) AdbaType(jdk.incubator.sql2.AdbaType) Test(org.junit.Test) RowPublisherOperation(jdk.incubator.sql2.RowPublisherOperation) TransactionCompletion(jdk.incubator.sql2.TransactionCompletion) Date(java.sql.Date) TimeUnit(java.util.concurrent.TimeUnit) DataSource(jdk.incubator.sql2.DataSource) List(java.util.List) CompletionStage(java.util.concurrent.CompletionStage) Result(jdk.incubator.sql2.Result) RowCountOperation(jdk.incubator.sql2.RowCountOperation) ForkJoinPool(java.util.concurrent.ForkJoinPool) MultiOperation(jdk.incubator.sql2.MultiOperation) Assert(org.junit.Assert) Submission(jdk.incubator.sql2.Submission) DataSourceFactory(jdk.incubator.sql2.DataSourceFactory) Properties(java.util.Properties) RowOperation(jdk.incubator.sql2.RowOperation) SqlException(jdk.incubator.sql2.SqlException) DataSource(jdk.incubator.sql2.DataSource) Result(jdk.incubator.sql2.Result) MultiOperation(jdk.incubator.sql2.MultiOperation) Session(jdk.incubator.sql2.Session) Test(org.junit.Test)

Example 2 with JDBC_CONNECTION_PROPERTIES

use of com.oracle.adbaoverjdbc.JdbcConnectionProperties.JDBC_CONNECTION_PROPERTIES in project oracle-db-examples by oracle-samples.

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());
    }
}
Also used : DataSourceFactory(jdk.incubator.sql2.DataSourceFactory) BeforeClass(org.junit.BeforeClass) RowOperation(jdk.incubator.sql2.RowOperation) CompletableFuture(java.util.concurrent.CompletableFuture) ArrayList(java.util.ArrayList) SqlException(jdk.incubator.sql2.SqlException) OperationGroup(jdk.incubator.sql2.OperationGroup) Flow(java.util.concurrent.Flow) BiConsumer(java.util.function.BiConsumer) Collector(java.util.stream.Collector) Session(jdk.incubator.sql2.Session) AfterClass(org.junit.AfterClass) Properties(java.util.Properties) JDBC_CONNECTION_PROPERTIES(com.oracle.adbaoverjdbc.JdbcConnectionProperties.JDBC_CONNECTION_PROPERTIES) AdbaType(jdk.incubator.sql2.AdbaType) Test(org.junit.Test) RowPublisherOperation(jdk.incubator.sql2.RowPublisherOperation) TransactionCompletion(jdk.incubator.sql2.TransactionCompletion) Date(java.sql.Date) TimeUnit(java.util.concurrent.TimeUnit) DataSource(jdk.incubator.sql2.DataSource) List(java.util.List) CompletionStage(java.util.concurrent.CompletionStage) Result(jdk.incubator.sql2.Result) RowCountOperation(jdk.incubator.sql2.RowCountOperation) ForkJoinPool(java.util.concurrent.ForkJoinPool) MultiOperation(jdk.incubator.sql2.MultiOperation) Assert(org.junit.Assert) Submission(jdk.incubator.sql2.Submission) DataSourceFactory(jdk.incubator.sql2.DataSourceFactory) Properties(java.util.Properties) RowOperation(jdk.incubator.sql2.RowOperation) SqlException(jdk.incubator.sql2.SqlException) DataSource(jdk.incubator.sql2.DataSource) Result(jdk.incubator.sql2.Result) MultiOperation(jdk.incubator.sql2.MultiOperation) Session(jdk.incubator.sql2.Session) Test(org.junit.Test)

Aggregations

JDBC_CONNECTION_PROPERTIES (com.oracle.adbaoverjdbc.JdbcConnectionProperties.JDBC_CONNECTION_PROPERTIES)2 Date (java.sql.Date)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Properties (java.util.Properties)2 CompletableFuture (java.util.concurrent.CompletableFuture)2 CompletionStage (java.util.concurrent.CompletionStage)2 Flow (java.util.concurrent.Flow)2 ForkJoinPool (java.util.concurrent.ForkJoinPool)2 TimeUnit (java.util.concurrent.TimeUnit)2 BiConsumer (java.util.function.BiConsumer)2 Collector (java.util.stream.Collector)2 AdbaType (jdk.incubator.sql2.AdbaType)2 DataSource (jdk.incubator.sql2.DataSource)2 DataSourceFactory (jdk.incubator.sql2.DataSourceFactory)2 MultiOperation (jdk.incubator.sql2.MultiOperation)2 OperationGroup (jdk.incubator.sql2.OperationGroup)2 Result (jdk.incubator.sql2.Result)2 RowCountOperation (jdk.incubator.sql2.RowCountOperation)2 RowOperation (jdk.incubator.sql2.RowOperation)2