Created
September 28, 2019 15:49
-
-
Save io7m/8fb4d8c8b3905234d837f68f0b6c4320 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.apache.derby.jdbc.EmbeddedConnectionPoolDataSource; | |
import org.jooq.SQLDialect; | |
import org.jooq.impl.DSL; | |
import java.sql.SQLException; | |
public final class SchemaIssue | |
{ | |
private SchemaIssue() | |
{ | |
} | |
public static void main(final String[] args) | |
throws SQLException | |
{ | |
final var dataSource = new EmbeddedConnectionPoolDataSource(); | |
dataSource.setDatabaseName("/tmp/example0"); | |
dataSource.setCreateDatabase("true"); | |
dataSource.setConnectionAttributes("create=true"); | |
final var connection = dataSource.getConnection(); | |
connection.setAutoCommit(false); | |
try (var statement = connection.prepareStatement("create schema core")) { | |
statement.execute(); | |
} | |
try (var statement = connection.prepareStatement("create table core.example (x int)")) { | |
statement.execute(); | |
} | |
try (var statement = connection.prepareStatement("insert into core.example values (23)")) { | |
statement.execute(); | |
} | |
try (var statement = connection.prepareStatement("insert into core.example values (24)")) { | |
statement.execute(); | |
} | |
try (var statement = connection.prepareStatement("insert into core.example values (25)")) { | |
statement.execute(); | |
} | |
connection.commit(); | |
try (var statement = connection.prepareStatement("select x from core.example")) { | |
try (var results = statement.executeQuery()) { | |
while (results.next()) { | |
System.out.printf("raw: %d\n", Integer.valueOf(results.getInt(1))); | |
} | |
} | |
} | |
final var context = DSL.using(connection, SQLDialect.DERBY); | |
try (var result = | |
context.select(DSL.field(DSL.name("x"), Integer.class)) | |
.from(DSL.table(DSL.name("core", "example"))) | |
.fetchStream() | |
.map(record -> record.value1()) | |
.map(x -> System.out.printf("jooq: %d\n", x))) { | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment