pgjdbc / pgadba

Implementation of Java 10 sql2 spec for PostgreSQL
BSD 2-Clause "Simplified" License
70 stars 10 forks source link

RowCountOperation.apply(…) does not consider extractor function #32

Closed mp911de closed 5 years ago

mp911de commented 5 years ago

Invoking a RowCountOperation operation and applying an extractor function results in a ClassCastException. The extractor function is not applied.

Reproducible via CREATE TABLE foo (id INT) and INSERT INTO foo (id) values(42) to trigger the insert statement.

Postgres version: PostgreSQL 10.4 on x86_64-apple-darwin14.5.0, compiled by Apple LLVM version 7.0.0 (clang-700.1.76), 64-bit

Reproducer:

    private DataSource dataSource() {

        return DataSourceFactory.newFactory("org.postgresql.adba.PgDataSourceFactory")
                .builder()
                .url("jdbc:postgresql://localhost:5432/postgres")
                .username("postgres")
                .password("")
                .build();
    }

    @Test
    public void shouldCount() {

        DataSource ds = dataSource();

        CompletableFuture<Long> t;
        try (Session session = ds.getSession()) {

            // Create table beforehand with: CREATE TABLE foo (id  INT);

            Submission<Long> count = session
                    .<Long>rowCountOperation("INSERT INTO foo (id) values(42)")
                    .apply(Result.RowCount::getCount)
                    .submit();

            t = count.getCompletionStage().toCompletableFuture();
        }

        t.join();

        assertThat(t.join()).isEqualTo(1L);

        ds.close();
    }
java.lang.ClassCastException: class org.postgresql.adba.util.PgCount cannot be cast to class java.lang.Long (org.postgresql.adba.util.PgCount is in unnamed module of loader 'app'; java.lang.Long is in module java.base of loader 'bootstrap')