Skip to content

Commit

Permalink
0.9.21
Browse files Browse the repository at this point in the history
  • Loading branch information
babyfish-ct committed Nov 26, 2024
1 parent ceb72f0 commit 4d3662a
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 25 deletions.
2 changes: 1 addition & 1 deletion project/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
group=org.babyfish.jimmer
version=0.9.20
version=0.9.21
Original file line number Diff line number Diff line change
Expand Up @@ -970,11 +970,9 @@ public Dialect.UpsertContext appendInsertedColumns(String prefix) {

@Override
public Dialect.UpsertContext appendConflictColumns() {
builder.enter(AbstractSqlBuilder.ScopeType.COMMA);
for (PropertyGetter getter : conflictGetters) {
builder.separator().sql(getter);
}
builder.leave();
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import org.babyfish.jimmer.sql.runtime.SqlBuilder;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.sql.Connection;
import java.util.ArrayList;
Expand All @@ -27,6 +29,8 @@ public class ConfigurableRootQueryImpl<T extends Table<?>, R>
extends AbstractConfigurableTypedQueryImpl
implements ConfigurableRootQuery<T, R>, TypedRootQueryImplementor<R> {

private static final Logger LOGGER = LoggerFactory.getLogger(ConfigurableRootQueryImpl.class);

ConfigurableRootQueryImpl(
TypedQueryData data,
MutableRootQueryImpl<T> baseQuery
Expand All @@ -43,6 +47,12 @@ public MutableRootQueryImpl<T> getBaseQuery() {
@Override
public <P> @NotNull P fetchPage(int pageIndex, int pageSize, Connection con, PageFactory<R, P> pageFactory) {
if (pageSize == 0 || pageSize == -1 || pageSize == Integer.MAX_VALUE) {
if (LOGGER.isInfoEnabled()) {
LOGGER.info(
"For meaningless pageSize {}, avoid pagination and fetch all rows directly",
pageSize
);
}
List<R> rows = execute(con);
return pageFactory.create(
rows,
Expand All @@ -51,6 +61,7 @@ public MutableRootQueryImpl<T> getBaseQuery() {
);
}
if (pageIndex < 0) {
LOGGER.info("pageIndex is negative, returns empty list directly");
return pageFactory.create(
Collections.emptyList(),
0,
Expand All @@ -64,6 +75,14 @@ public MutableRootQueryImpl<T> getBaseQuery() {
}
long total = fetchUnlimitedCount(con);
if (offset >= total) {
if (LOGGER.isInfoEnabled()) {
LOGGER.info(
"pageIndex(starts from 0) is {} but the total page count is {}, " +
"returns empty list directly",
pageIndex,
(total + pageSize - 1) / pageSize
);
}
return pageFactory.create(
Collections.emptyList(),
total,
Expand All @@ -73,6 +92,7 @@ public MutableRootQueryImpl<T> getBaseQuery() {

ConfigurableRootQuery<?, R> reversedQuery = null;
if (offset + pageSize / 2 > total / 2) {
LOGGER.info("Enable reverse sorting optimization, all sorting behaviors will be reversed");
reversedQuery = reverseSorting();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ public enum ScopeType {
LIST("(\n", ",?", "\n)"),
COMMA(null, ",?", null),
TUPLE("(", ", ", ")"),
MULTIPLE_LINE_TUPLE("(\n", ", ", "\n)"),
AND(null, "?and?", null, false),
OR(null, "?or?", null, false),
SMART_OR(null, "?or?", null, false),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,14 @@ public void upsert(UpsertContext ctx) {
if (!ctx.isUpdateIgnored()) {
ctx.sql("merge into ")
.appendTableName()
.enter(AbstractSqlBuilder.ScopeType.LIST)
.enter(AbstractSqlBuilder.ScopeType.MULTIPLE_LINE_TUPLE)
.appendInsertedColumns("")
.leave()
.sql(" key(")
.sql(" key")
.enter(AbstractSqlBuilder.ScopeType.MULTIPLE_LINE_TUPLE)
.appendConflictColumns()
.sql(") values")
.leave()
.sql(" values")
.enter(AbstractSqlBuilder.ScopeType.LIST)
.appendInsertingValues()
.leave();
Expand All @@ -151,7 +153,7 @@ public void upsert(UpsertContext ctx) {
.leave()
.leave()
.sql(" tb_2_")
.enter(AbstractSqlBuilder.ScopeType.LIST)
.enter(AbstractSqlBuilder.ScopeType.MULTIPLE_LINE_TUPLE)
.appendInsertedColumns("")
.leave()
.sql(" on ");
Expand All @@ -176,11 +178,11 @@ public void upsert(UpsertContext ctx) {
ctx.sql(cheapestGetter).sql(" = tb_2_.").sql(cheapestGetter);
}
ctx.sql(" when not matched then insert")
.enter(AbstractSqlBuilder.ScopeType.LIST)
.enter(AbstractSqlBuilder.ScopeType.MULTIPLE_LINE_TUPLE)
.appendInsertedColumns("")
.leave()
.enter(AbstractSqlBuilder.ScopeType.VALUES)
.enter(AbstractSqlBuilder.ScopeType.LIST)
.enter(AbstractSqlBuilder.ScopeType.MULTIPLE_LINE_TUPLE)
.appendInsertedColumns("tb_2_.")
.leave()
.leave();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,22 +41,21 @@ public void upsert(UpsertContext ctx) {
if (ctx.isUpdateIgnored() || (!ctx.hasUpdatedColumns() && !ctx.hasGeneratedId())) {
ctx.sql("insert ignore into ")
.appendTableName()
.enter(AbstractSqlBuilder.ScopeType.LIST)
.enter(AbstractSqlBuilder.ScopeType.MULTIPLE_LINE_TUPLE)
.appendInsertedColumns("")
.leave()
.enter(AbstractSqlBuilder.ScopeType.VALUES)
.enter(AbstractSqlBuilder.ScopeType.LIST)
.sql(" values")
.enter(AbstractSqlBuilder.ScopeType.MULTIPLE_LINE_TUPLE)
.appendInsertingValues()
.leave()
.leave();
} else {
ctx.sql("insert into ")
.appendTableName()
.enter(AbstractSqlBuilder.ScopeType.LIST)
.enter(AbstractSqlBuilder.ScopeType.MULTIPLE_LINE_TUPLE)
.appendInsertedColumns("")
.leave()
.enter(AbstractSqlBuilder.ScopeType.VALUES)
.enter(AbstractSqlBuilder.ScopeType.LIST)
.enter(AbstractSqlBuilder.ScopeType.MULTIPLE_LINE_TUPLE)
.appendInsertingValues()
.leave()
.leave()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,16 +206,15 @@ public void update(UpdateContext ctx) {
public void upsert(UpsertContext ctx) {
ctx.sql("insert into ")
.appendTableName()
.enter(AbstractSqlBuilder.ScopeType.LIST)
.enter(AbstractSqlBuilder.ScopeType.MULTIPLE_LINE_TUPLE)
.appendInsertedColumns("")
.leave()
.enter(AbstractSqlBuilder.ScopeType.VALUES)
.enter(AbstractSqlBuilder.ScopeType.LIST)
.sql(" values")
.enter(AbstractSqlBuilder.ScopeType.MULTIPLE_LINE_TUPLE)
.appendInsertingValues()
.leave()
.leave()
.sql(" on conflict")
.enter(AbstractSqlBuilder.ScopeType.LIST)
.enter(AbstractSqlBuilder.ScopeType.MULTIPLE_LINE_TUPLE)
.appendConflictColumns()
.leave();
if (ctx.isUpdateIgnored()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,15 @@ public boolean isUpsertSupported() {
public void upsert(UpsertContext ctx) {
ctx.sql("insert into ")
.appendTableName()
.enter(AbstractSqlBuilder.ScopeType.LIST)
.enter(AbstractSqlBuilder.ScopeType.MULTIPLE_LINE_TUPLE)
.appendInsertedColumns("")
.leave()
.enter(AbstractSqlBuilder.ScopeType.VALUES)
.enter(AbstractSqlBuilder.ScopeType.LIST)
.sql(" values")
.enter(AbstractSqlBuilder.ScopeType.MULTIPLE_LINE_TUPLE)
.appendInsertingValues()
.leave()
.leave()
.sql(" on conflict")
.enter(AbstractSqlBuilder.ScopeType.LIST)
.enter(AbstractSqlBuilder.ScopeType.MULTIPLE_LINE_TUPLE)
.appendConflictColumns()
.leave();
if (ctx.isUpdateIgnored()) {
Expand Down

0 comments on commit 4d3662a

Please sign in to comment.