jooq

JOOQ Oracle Number precision and java number mapping

我是研究僧i 提交于 2019-12-11 02:59:42
问题 Can anyone tell me or provide a ref to the mapping between oracle number precisions and java types ie at what point does a number(x) get mapped to a short, int, long BigInteger etc 回答1: Java's integer types are not a perfect match for Oracle's NUMBER types. Essentially, there are two ways to map between the worlds, both imperfect: The status quo: strictly less than NUMBER(3) -> Byte . This guarantees that a SQL value can always be read to its Java type. Some Java value might not be writable

Add count as select field using jooq SelectQuery

扶醉桌前 提交于 2019-12-11 01:44:18
问题 Most of the existing posts I can find dealing with my learning jook are outdated. I'm trying to build dynamically so that I can use conditions for certain changes. I'm trying to find how to add COUNT(*) to an existing list of fields SelectQuery query = create().selectQuery(); query.addSelect(TABLE.FIELD); // add COUNT(*)? I'm not seeing any methods or API help on how to do this when building the query dynamically. 回答1: Just use DSL.count() query.addSelect(count()); The above is assuming a

Jooq custom binding registration in Java

折月煮酒 提交于 2019-12-10 22:16:38
问题 I have a custom binding written to convert from custom type to Postgres json type. This part of the documentation mentions how to register using xml but I'm using Java. I have tried to search to find how to do that but in vain. Any help is appreciated. 回答1: If by "I'm using Java", you mean using programmatic code generator configuration using Java: There's a manual section about programmatic code generator configuration here: http://www.jooq.org/doc/latest/manual/code-generation/codegen

Using PosgreSQL array_agg with join alias in JOOQ DSL

*爱你&永不变心* 提交于 2019-12-10 18:55:04
问题 I want to convert this SQL query to JOOQ DSL. select "p".*, array_agg("pmu") as projectmemberusers from "Projects" as "p" join "ProjectMemberUsers" as "pmu" on "pmu"."projectId" = "p"."id" group by "p"."id"; Currently i have tried doing something like this using JOOQ: val p = PROJECTS.`as`("p") val pmu = PROJECTMEMBERUSERS.`as`("pmu") val query = db.select(p.asterisk(), DSL.arrayAgg(pmu)) .from(p.join(pmu).on(p.ID.eq(pmu.PROJECTID))) .groupBy(p.ID) This does not work because DSL.arrayAgg

Mysql streaming result set and jOOQ fetchLazy

∥☆過路亽.° 提交于 2019-12-10 17:12:18
问题 Normally when I want to query large result set using Mysql I write this (taken from this answer): stmt = conn.createStatement(java.sql.ResultSet.TYPE_FORWARD_ONLY, java.sql.ResultSet.CONCUR_READ_ONLY); stmt.setFetchSize(Integer.MIN_VALUE); Now I'm using jOOQ 2.0.5 and I can't achieve the same result. I've tried calling fetchLazy with no luck, it loads the entire result set in memory: Cursor<Record> result = query.fetchLazy(Integer.MIN_VALUE); As a workaround I can get the sql query using

SQLite 64bit integers recognized as ints in jooq

会有一股神秘感。 提交于 2019-12-10 16:51:49
问题 I have an SQLite database that I am using with jOOQ. When I use jOOQ's code generation tool, it builds all of the table and record classes as expected. However, all of the SQLite INTEGER columns turn into java.lang.Integer fields in the generated code. The problem is that SQLite INTEGER's can store up to a 64 bit signed integer, where java.lang.Integer is only a 32 bit signed integer. Is it possible to tell jOOQ to use java.lang.Long (which is 64 bit signed) for these columns? 回答1: In fact,

Using the MockDataProvider of JOOQ, how do I set the lastId() that gets returned?

孤街醉人 提交于 2019-12-10 15:55:39
问题 Note: I am not using the code generator of Jooq In the DAO unit test, the DAO is tested to ensure that after a object has been inserted that the DAO sets the Id as returned by the last_insert_id() from the database. No actual database is contacted since I'm using the MockConnection and MockDataProvider of JOOQ. When the following is executed by the DAO: DSLContext ctx = DSL.using(connection, SQLDialect.MYSQL); //insert //get id BigInteger id = ctx.lastId(); JOOQ executes the following query:

Jooq binding for “timestamp with time zone” type in postgres

允我心安 提交于 2019-12-10 15:34:25
问题 Jooq currently does not support JSR 310 types and support will not come until v3.8. Using simple converters generally works, except for certain types, such as postgres' TIMESTAMP WITH TIME ZONE , which requires a custom binding. So I have tried to write one but the generated XxxRecord classes still use a Timestamp data type for the TIMESTAMP WITH TIME ZONE fields in my DB. What do I need to change in my code below to see postgres' TIMESTAMP WITH TIME ZONE as an Instant in jooq's generated

JOOQ ignoring database columns with default values

浪子不回头ぞ 提交于 2019-12-10 15:29:33
问题 It seems that JOOQ is completely ignoring the default values of database columns. Neither gets the ActiveRecord object updated nor does it skip this column on INSERT. Instead it tries to set it to NULL which fails on NOT NULL columns. Example: CREATE TABLE bug ( foo int, bar int not null default 42 ); BugRecord b = jooq.newRecord(BUG); b.setFoo(3); b.store(); assertNotNull(b.getBar()); // fails Record r = jooq.select().from(BUG).fetchOne(); assertEquals(new Integer(-1), r.getValue(BUG.BAR));

Retrieving the value of selectCount in jooq

三世轮回 提交于 2019-12-10 13:30:45
问题 I have some code that looks like this: Record record = jooq .selectCount() .from(USERS) .fetchOne(); Currently I'm doing the following to get the count: Integer count = (Integer) record.getValue(0); But it seems like there must be a better solution (that's type-safe...since that's the whole point of using jooq). Any suggestions? 回答1: Unfortunately, for this particular query, there aren't many "better" ways to typesafely get the count() value. What you could do, to add type-safety, is this: