在java中我有一个自定义类,我按如下方式排序:
public static void sortList(List<FishCategory> categories) {
Collections.sort(categories, new Comparator<FishCategory>(){
public int compare(FishCategory s1, FishCategory s2) {
return s1.getName().compareTo(s2.getName());
}
});
}
Run Code Online (Sandbox Code Playgroud)
但是像sql一样,你可以这样做:
select * from mytable
order by id, name
Run Code Online (Sandbox Code Playgroud)
我想在java中进行双重排序.我想按此排序(注意:我正在使用getParentId)作为第一种排序,然后我想按上面排序.
public static void sortList(List<FishCategory> categories) {
Collections.sort(categories, new Comparator<FishCategory>(){
public int compare(FishCategory s1, FishCategory s2) {
return s1.getParentId().compareTo(s2.getParentId());
}
});
}
Run Code Online (Sandbox Code Playgroud)
我不能在下一个原因之后立即运行两个函数,这将取消第一个排序.我需要按照sql的方式排序(即对排序的组进行排序).
所以我想先排序.getParentId(),然后.getName().
有谁知道一个很容易做到这一点的好方法?
谢谢
在SQL中,我可以执行类型的查询:
SELECT cost > 1000 AS above_k, name FROM products;
Run Code Online (Sandbox Code Playgroud)
给我一个清单:
+---------+--------+
| above_k | name |
+---------+--------+
| true | Gold |
| false | Silver |
+---------+--------+
Run Code Online (Sandbox Code Playgroud)
如何使用jooq?建模类似的查询?我不能这样做(显然):
ctx.select(Tables.PRODUCTS.COST.gt(1000))
Run Code Online (Sandbox Code Playgroud)
既然,没有方法select(Condition condition).或者,如果我只是想:
SELECT cost*0.9 AS discounted_cost FROM products;
Run Code Online (Sandbox Code Playgroud)
有没有办法用jooq做到这一点?
请建议JOOQ DSL来查询布尔表达式的结果
在SQL中我会写:
SELECT sum(apples.quantity) > sum(bananas.quantity)
FROM ...
Run Code Online (Sandbox Code Playgroud) 请考虑以下代码:
create sequence "s" cache 50;
select "s".nextval from dual;
Run Code Online (Sandbox Code Playgroud)
当我执行上述一次时,我得到了
NEXTVAL
-------
1
Run Code Online (Sandbox Code Playgroud)
当我执行两次语句时,除了DDL语句中的明显错误消息之外,我得到了
drop sequence "s";
create sequence "s" cache 50;
select "s".nextval from dual;
create sequence "s" cache 50;
select "s".nextval from dual;
NEXTVAL
-------
51
Run Code Online (Sandbox Code Playgroud)
运行语句三次以获得:
drop sequence "s";
create sequence "s" cache 50;
select "s".nextval from dual;
create sequence "s" cache 50;
select "s".nextval from dual;
create sequence "s" cache 50;
select "s".nextval from dual;
NEXTVAL
-------
101
Run Code Online (Sandbox Code Playgroud)
该文件写道:
如果发生系统故障,则所有未在已提交的DML语句中使用的高速缓存序列值都将丢失.
但是,失败的DDL语句是否有资格成为系统故障?这种行为的原因是什么?
我正在使用Maven和kotlin-maven-plugin编译代码.
<plugin>
<artifactId>kotlin-maven-plugin</artifactId>
<groupId>org.jetbrains.kotlin</groupId>
<version>${kotlin.version}</version>
<executions>
<execution>
<id>compile</id>
<phase>process-sources</phase>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<sourceDirs>
<source>src/main/kotlin</source>
<source>src/main/resources</source>
<source>target/generated-sources/jooq-h2</source>
</sourceDirs>
</configuration>
</execution>
<execution>
<id>test-compile</id>
<phase>process-test-sources</phase>
<goals>
<goal>test-compile</goal>
</goals>
<configuration>
<sourceDirs>
<source>src/test/kotlin</source>
</sourceDirs>
</configuration>
</execution>
</executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)
该target/generated-sources/jooq-h2目录包含Java源文件.我正在遵循Kotlin手册以及其他人的建议,将Kotlin comprate放入<phase>process-sources</phase>而不是<phase>compile</phase>.我(可能是错误的?)假设Kotlin编译器也负责为我编译这些Java文件.
但是,在某些服务器(例如Jenkins CI)上,我收到了奇怪的编译错误消息,例如:
[ERROR] /var/lib/jenkins/jobs/jooq-build/workspace/jOOQ-examples/jOOQ-kotlin-example/target/generated-sources/jooq-h2/org/jooq/example/db/h2/tables/Author.java:[35,37]
error: generics are not supported in -source 1.3
Run Code Online (Sandbox Code Playgroud)
这是为什么?
我将springBoot与JOOQ一起使用,并希望记录生成的SQL。
像在JOOQ文档(http://www.jooq.org/doc/latest/manual/sql-execution/logging/)中一样,我将slf4J添加到了我的maven依赖项和log4j.xml中。但是当jooq执行一些查询时,我的控制台中看不到任何日志。
我也在Google中搜索此问题,但找不到任何内容。SpringBoot使用logBack,所以我的路径中有logBack和slf4J。是否可以对JOOQ使用logBack?我没有在JOOQ网站上获得任何有关此内容的指示。
我正在加入jOOQ中的一些表格,我想使用a RecordMapper将结果解析为我的pojo AType.
final List<AType> typeList = dsl.select()
.from(TABLEA)
.join(TABLEB).on(TABLEA.ID.equal(TABLEB.ID))
.fetch()
.map((RecordMapper<Record, AType>) record -> {
//Extract field values from Record
return new AType(....);
});
Run Code Online (Sandbox Code Playgroud)
正如我在评论中解释的那样,我想知道如何将Field对象从Record包含的值转换为包含的值.
我正在使用3.5 jooq版本
我知道jooq不支持DATE_FORMAT函数,但是有什么替代方法
这是我要使用JOOQ创建的查询
SELECT DATE_FORMAT(`date_create`, '%d/%m/%Y') AS date_create FROM users
GROUP BY DATE_FORMAT(`date_create`, '%d/%m/%Y')
Run Code Online (Sandbox Code Playgroud) 我有一个非常通用的 API,可以使用 JOOQ 将内容插入到某些表中:
void insert(@NonNull final Table<?> table,
@NonNull final Collection<Field<?>> columns,
@NonNull final Collection<Object> values) {
dslContext.insertInto(table)
.columns(columns)
.values(values)
.execute();
}
Run Code Online (Sandbox Code Playgroud)
有没有办法返回插入的记录的ID?我的数据库中表的所有主键都命名为“id”,因此我可以对它进行 ahrdcode,但我找不到返回它并转换为 Integer / Long 的方法。我正在使用 JOOQ 3.9.5。
编辑:我在下面使用 MSSQL。
for (int i = 0; i < s.length(); ++i)
{
if (s.charAt(i) >= 'A' && s.charAt(i) <= 'Z')
{
++array[s.charAt(i) - 'A'];
}
}
Run Code Online (Sandbox Code Playgroud)
我理解For循环.s.length()是26,确切地说是int [26].所以这个循环将发生26次,0-25.如果i,0-25处的Char在或者是AZ之间它将继续进行++array[s.charAt(i) - 'A'];从我看到它每个循环添加一次数组,或者每个循环添加一次数组的值,对于char i的String,所以第一个将是0秒将是2,因为数组从0开始.因此在位置添加数组i -'A'是我感到困惑的地方.