Search in sources :

Example 1 with AuthorsRecord

use of io.zero88.sample.data.pgsql.tables.records.AuthorsRecord in project jooqx by zero88.

the class PgReABatchTest method test_batch_insert_and_returning_count.

@Test
void test_batch_insert_and_returning_count(VertxTestContext ctx) {
    final Checkpoint flag = ctx.checkpoint();
    final Authors table = schema().AUTHORS;
    AuthorsRecord rec1 = new AuthorsRecord().setName("abc").setCountry("AU");
    AuthorsRecord rec2 = new AuthorsRecord().setName("haha");
    final BindBatchValues bindValues = new BindBatchValues().register(table.NAME).registerValue(table.COUNTRY, "VN").add(rec1, rec2);
    final InsertSetMoreStep<AuthorsRecord> insert = jooqx.dsl().insertInto(table).set(bindValues.getDummyValues());
    jooqx.batch(insert, bindValues, ar -> ctx.verify(() -> {
        final BatchResult result = assertSuccess(ctx, ar);
        Assertions.assertEquals(2, result.getTotal());
        Assertions.assertEquals(2, result.getSuccesses());
        jooqx.execute(jooqx.dsl().selectFrom(table), DSLAdapter.fetchJsonRecords(table), ar2 -> {
            assertResultSize(ctx, ar2, 10);
            flag.flag();
        });
    }));
}
Also used : VertxTestContext(io.vertx.junit5.VertxTestContext) Books(io.zero88.sample.data.pgsql.tables.Books) BeforeEach(org.junit.jupiter.api.BeforeEach) Arrays(java.util.Arrays) Json(io.vertx.core.json.Json) DSL(org.jooq.impl.DSL) InsertResultStep(org.jooq.InsertResultStep) PgUseJooqType(io.zero88.integtest.jooqx.pg.PostgreSQLHelper.PgUseJooqType) PgSQLJooqxTest(io.zero88.jooqx.spi.pg.PgSQLJooqxTest) JsonRecord(io.zero88.jooqx.JsonRecord) Authors(io.zero88.sample.data.pgsql.tables.Authors) Record1(org.jooq.Record1) BatchResult(io.zero88.jooqx.BatchResult) DSLAdapter(io.zero88.jooqx.DSLAdapter) AsyncResult(io.vertx.core.AsyncResult) BindBatchValues(io.zero88.jooqx.BindBatchValues) Vertx(io.vertx.core.Vertx) PgPool(io.vertx.pgclient.PgPool) BooksRecord(io.zero88.sample.data.pgsql.tables.records.BooksRecord) InsertSetMoreStep(org.jooq.InsertSetMoreStep) PgPoolProvider(io.zero88.jooqx.spi.pg.PgPoolProvider) Collectors(java.util.stream.Collectors) Test(org.junit.jupiter.api.Test) List(java.util.List) SQLStateClass(org.jooq.exception.SQLStateClass) Assertions(org.junit.jupiter.api.Assertions) BatchReturningResult(io.zero88.jooqx.BatchReturningResult) Checkpoint(io.vertx.junit5.Checkpoint) AuthorsRecord(io.zero88.sample.data.pgsql.tables.records.AuthorsRecord) PgSQLErrorConverterProvider(io.zero88.jooqx.spi.pg.PgSQLErrorConverterProvider) Handler(io.vertx.core.Handler) Checkpoint(io.vertx.junit5.Checkpoint) BindBatchValues(io.zero88.jooqx.BindBatchValues) Authors(io.zero88.sample.data.pgsql.tables.Authors) BatchResult(io.zero88.jooqx.BatchResult) AuthorsRecord(io.zero88.sample.data.pgsql.tables.records.AuthorsRecord) PgSQLJooqxTest(io.zero88.jooqx.spi.pg.PgSQLJooqxTest) Test(org.junit.jupiter.api.Test)

Example 2 with AuthorsRecord

use of io.zero88.sample.data.pgsql.tables.records.AuthorsRecord in project jooqx by zero88.

the class PgReABatchTest method transaction_batch_success.

@Test
void transaction_batch_success(VertxTestContext context) {
    final Checkpoint flag = context.checkpoint();
    final Authors table = schema().AUTHORS;
    jooqx.transaction().run(tx -> {
        AuthorsRecord rec1 = new AuthorsRecord().setName("abc").setCountry("AU");
        AuthorsRecord rec2 = new AuthorsRecord().setName("haha");
        final BindBatchValues bindValues = new BindBatchValues().register(table.NAME).registerValue(table.COUNTRY, "VN").add(rec1, rec2);
        final InsertSetMoreStep<AuthorsRecord> insert = jooqx.dsl().insertInto(table).set(bindValues.getDummyValues());
        return tx.batch(insert, bindValues);
    }, ar -> context.verify(() -> {
        final BatchResult result = assertSuccess(context, ar);
        Assertions.assertNotNull(result);
        Assertions.assertEquals(2, result.getSuccesses());
        Assertions.assertEquals(2, result.getTotal());
        jooqx.execute(jooqx.dsl().selectFrom(table), DSLAdapter.fetchMany(table), ar2 -> {
            assertResultSize(context, ar2, 10);
            flag.flag();
        });
    }));
}
Also used : VertxTestContext(io.vertx.junit5.VertxTestContext) Books(io.zero88.sample.data.pgsql.tables.Books) BeforeEach(org.junit.jupiter.api.BeforeEach) Arrays(java.util.Arrays) Json(io.vertx.core.json.Json) DSL(org.jooq.impl.DSL) InsertResultStep(org.jooq.InsertResultStep) PgUseJooqType(io.zero88.integtest.jooqx.pg.PostgreSQLHelper.PgUseJooqType) PgSQLJooqxTest(io.zero88.jooqx.spi.pg.PgSQLJooqxTest) JsonRecord(io.zero88.jooqx.JsonRecord) Authors(io.zero88.sample.data.pgsql.tables.Authors) Record1(org.jooq.Record1) BatchResult(io.zero88.jooqx.BatchResult) DSLAdapter(io.zero88.jooqx.DSLAdapter) AsyncResult(io.vertx.core.AsyncResult) BindBatchValues(io.zero88.jooqx.BindBatchValues) Vertx(io.vertx.core.Vertx) PgPool(io.vertx.pgclient.PgPool) BooksRecord(io.zero88.sample.data.pgsql.tables.records.BooksRecord) InsertSetMoreStep(org.jooq.InsertSetMoreStep) PgPoolProvider(io.zero88.jooqx.spi.pg.PgPoolProvider) Collectors(java.util.stream.Collectors) Test(org.junit.jupiter.api.Test) List(java.util.List) SQLStateClass(org.jooq.exception.SQLStateClass) Assertions(org.junit.jupiter.api.Assertions) BatchReturningResult(io.zero88.jooqx.BatchReturningResult) Checkpoint(io.vertx.junit5.Checkpoint) AuthorsRecord(io.zero88.sample.data.pgsql.tables.records.AuthorsRecord) PgSQLErrorConverterProvider(io.zero88.jooqx.spi.pg.PgSQLErrorConverterProvider) Handler(io.vertx.core.Handler) Checkpoint(io.vertx.junit5.Checkpoint) BindBatchValues(io.zero88.jooqx.BindBatchValues) Authors(io.zero88.sample.data.pgsql.tables.Authors) BatchResult(io.zero88.jooqx.BatchResult) AuthorsRecord(io.zero88.sample.data.pgsql.tables.records.AuthorsRecord) PgSQLJooqxTest(io.zero88.jooqx.spi.pg.PgSQLJooqxTest) Test(org.junit.jupiter.api.Test)

Example 3 with AuthorsRecord

use of io.zero88.sample.data.pgsql.tables.records.AuthorsRecord in project jooqx by zero88.

the class PgReAComplexQueryTest method test_join_2_tables_then_map_to_another_table.

@Test
void test_join_2_tables_then_map_to_another_table(VertxTestContext ctx) {
    final Checkpoint flag = ctx.checkpoint();
    final DSLContext dsl = jooqx.dsl();
    final Public schema = schema().PUBLIC;
    final SelectConditionStep<Record> query = dsl.select(schema.AUTHORS.asterisk(), schema.BOOKS_AUTHORS.BOOK_ID).from(schema.AUTHORS).join(schema.BOOKS_AUTHORS).onKey().where(schema.AUTHORS.ID.eq(4));
    jooqx.execute(query, DSLAdapter.fetchMany(query.asTable(), schema.AUTHORS), ar -> ctx.verify(() -> {
        final List<AuthorsRecord> records = assertResultSize(ctx, ar, 1);
        final AuthorsRecord authorsRecord = records.get(0);
        Assertions.assertEquals(4, authorsRecord.getId());
        Assertions.assertEquals("Scott Hanselman", authorsRecord.getName());
        Assertions.assertEquals("USA", authorsRecord.getCountry());
        flag.flag();
    }));
}
Also used : Checkpoint(io.vertx.junit5.Checkpoint) DSLContext(org.jooq.DSLContext) Record(org.jooq.Record) BooksRecord(io.zero88.sample.data.pgsql.tables.records.BooksRecord) JsonRecord(io.zero88.jooqx.JsonRecord) BooksAuthorsRecord(io.zero88.sample.data.pgsql.tables.records.BooksAuthorsRecord) AuthorsRecord(io.zero88.sample.data.pgsql.tables.records.AuthorsRecord) List(java.util.List) Public(io.zero88.sample.data.pgsql.Public) BooksAuthorsRecord(io.zero88.sample.data.pgsql.tables.records.BooksAuthorsRecord) AuthorsRecord(io.zero88.sample.data.pgsql.tables.records.AuthorsRecord) PgSQLJooqxTest(io.zero88.jooqx.spi.pg.PgSQLJooqxTest) Test(org.junit.jupiter.api.Test)

Example 4 with AuthorsRecord

use of io.zero88.sample.data.pgsql.tables.records.AuthorsRecord in project jooqx by zero88.

the class PgReARelationTest method test_select_one_convert_by_table.

@Test
void test_select_one_convert_by_table(VertxTestContext ctx) {
    final Checkpoint flag = ctx.checkpoint();
    final io.zero88.sample.data.pgsql.tables.Authors table = schema().AUTHORS;
    final SelectConditionStep<AuthorsRecord> query = jooqx.dsl().selectFrom(table).where(table.COUNTRY.eq("UK"));
    jooqx.execute(query, DSLAdapter.fetchOne(table), ar -> ctx.verify(() -> {
        Assertions.assertTrue(ar.succeeded());
        final AuthorsRecord authors = ar.result();
        Assertions.assertEquals(3, authors.getId());
        Assertions.assertEquals("Jane Austen", authors.getName());
        Assertions.assertEquals("UK", authors.getCountry());
        flag.flag();
    }));
}
Also used : Checkpoint(io.vertx.junit5.Checkpoint) AuthorsRecord(io.zero88.sample.data.pgsql.tables.records.AuthorsRecord) PgSQLJooqxTest(io.zero88.jooqx.spi.pg.PgSQLJooqxTest) Test(org.junit.jupiter.api.Test)

Example 5 with AuthorsRecord

use of io.zero88.sample.data.pgsql.tables.records.AuthorsRecord in project jooqx by zero88.

the class PgReARelationTest method test_select_one_but_give_query_that_returns_many.

@Test
void test_select_one_but_give_query_that_returns_many(VertxTestContext ctx) {
    final Checkpoint flag = ctx.checkpoint();
    final io.zero88.sample.data.pgsql.tables.Authors table = schema().AUTHORS;
    final SelectForUpdateStep<AuthorsRecord> q = jooqx.dsl().selectFrom(table).where(table.COUNTRY.eq("USA")).orderBy(table.ID.desc());
    jooqx.execute(q, DSLAdapter.fetchJsonRecord(q.asTable()), ar -> ctx.verify(() -> {
        final JsonRecord<?> result = ar.result();
        Assertions.assertNotNull(result);
        Assertions.assertEquals(new JsonObject("{\"id\":8,\"name\":\"Christian Wenz\",\"country\":\"USA\"}"), result.toJson());
        flag.flag();
    }));
}
Also used : Checkpoint(io.vertx.junit5.Checkpoint) JsonObject(io.vertx.core.json.JsonObject) JsonRecord(io.zero88.jooqx.JsonRecord) AuthorsRecord(io.zero88.sample.data.pgsql.tables.records.AuthorsRecord) PgSQLJooqxTest(io.zero88.jooqx.spi.pg.PgSQLJooqxTest) Test(org.junit.jupiter.api.Test)

Aggregations

AuthorsRecord (io.zero88.sample.data.pgsql.tables.records.AuthorsRecord)14 Checkpoint (io.vertx.junit5.Checkpoint)11 Test (org.junit.jupiter.api.Test)11 PgSQLJooqxTest (io.zero88.jooqx.spi.pg.PgSQLJooqxTest)10 JsonRecord (io.zero88.jooqx.JsonRecord)9 PgPool (io.vertx.pgclient.PgPool)6 BindBatchValues (io.zero88.jooqx.BindBatchValues)6 BooksRecord (io.zero88.sample.data.pgsql.tables.records.BooksRecord)6 List (java.util.List)6 Vertx (io.vertx.core.Vertx)5 VertxTestContext (io.vertx.junit5.VertxTestContext)5 PgUseJooqType (io.zero88.integtest.jooqx.pg.PostgreSQLHelper.PgUseJooqType)5 DSLAdapter (io.zero88.jooqx.DSLAdapter)5 PgPoolProvider (io.zero88.jooqx.spi.pg.PgPoolProvider)5 Authors (io.zero88.sample.data.pgsql.tables.Authors)5 Assertions (org.junit.jupiter.api.Assertions)5 BeforeEach (org.junit.jupiter.api.BeforeEach)5 AsyncResult (io.vertx.core.AsyncResult)4 Handler (io.vertx.core.Handler)4 Json (io.vertx.core.json.Json)4