use of org.jooq.example.db.h2.tables.pojos.Author in project jOOQ by jOOQ.
the class Example_2_1_ActiveRecords method run.
@Test
public void run() throws SQLException {
Connection connection = connection();
DSLContext dsl = DSL.using(connection);
AuthorRecord author;
try {
Tools.title("Loading and changing active records");
author = dsl.selectFrom(AUTHOR).where(AUTHOR.ID.eq(1)).fetchOne();
author.setDateOfBirth(Date.valueOf("2000-01-01"));
author.store();
Tools.print(author);
Tools.title("Creating a new active record");
author = dsl.newRecord(AUTHOR);
author.setId(3);
author.setFirstName("Alfred");
author.setLastName("Hitchcock");
author.store();
Tools.print(author);
Tools.title("Refreshing an active record");
author = dsl.newRecord(AUTHOR);
author.setId(3);
author.refresh();
Tools.print(author);
Tools.title("Updating an active record");
author.setDateOfBirth(Date.valueOf("1899-08-13"));
author.store();
Tools.print(author);
Tools.title("Deleting an active record");
author.delete();
Tools.print(dsl.selectFrom(AUTHOR).fetch());
} finally // Don't store the changes
{
connection.rollback();
}
}
use of org.jooq.example.db.h2.tables.pojos.Author in project jOOQ by jOOQ.
the class Example_3_2_ResultSets method run.
@Test
public void run() {
Connection connection = connection();
Tools.title("Using jOOQ Results in foreach loops");
for (Record record : DSL.using(connection).select().from(AUTHOR).fetch()) {
System.out.println(record);
}
Tools.title("Using jOOQ Results with Java 8 streams");
DSL.using(connection).select().from(AUTHOR).fetch().stream().flatMap(record -> Arrays.stream(record.intoArray())).forEach(System.out::println);
}
use of org.jooq.example.db.h2.tables.pojos.Author in project jOOQ by jOOQ.
the class Example_4_4_ExecuteListener method run.
@Test
public void run() {
Tools.title("Displaying execution time using a custom ExecuteListener");
ExecuteListener listener = new CallbackExecuteListener().onStart(ctx -> {
ctx.data("time", System.nanoTime());
}).onEnd(ctx -> {
Long time = (Long) ctx.data("time");
System.out.println("Execution time : " + ((System.nanoTime() - time) / 1000 / 1000.0) + "ms. Query : " + ctx.sql());
});
DSL.using(new DefaultConfiguration().set(SQLDialect.H2).set(new DefaultConnectionProvider(connection())).set(new DefaultExecuteListenerProvider(listener))).select(AUTHOR.ID).from(AUTHOR).fetch();
}
Aggregations