Skip to content

Commit

Permalink
Try to fix #876, not sure
Browse files Browse the repository at this point in the history
  • Loading branch information
babyfish-ct committed Jan 12, 2025
1 parent 4c21907 commit 93ddb05
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,10 @@ public void insert(Batch<DraftSpi> batch) {
}

MetadataStrategy strategy = sqlClient.getMetadataStrategy();
BatchSqlBuilder builder = new BatchSqlBuilder(sqlClient, ctx.options.isBatchForbidden());
BatchSqlBuilder builder = new BatchSqlBuilder(
sqlClient,
batch.entities().size() < 2 || ctx.options.isBatchForbidden()
);
builder.sql("insert into ")
.sql(ctx.path.getType().getTableName(strategy))
.enter(BatchSqlBuilder.ScopeType.TUPLE);
Expand Down Expand Up @@ -280,7 +283,10 @@ public void update(
return;
}
}
BatchSqlBuilder builder = new BatchSqlBuilder(sqlClient, ctx.options.isBatchForbidden());
BatchSqlBuilder builder = new BatchSqlBuilder(
sqlClient,
batch.entities().size() < 2 || ctx.options.isBatchForbidden()
);
Dialect.UpdateContext updateContext = new UpdateContextImpl(
builder,
shape,
Expand Down Expand Up @@ -481,7 +487,10 @@ public void upsert(Batch<DraftSpi> batch, boolean ignoreUpdate) {
Predicate userOptimisticLockPredicate = userLockOptimisticPredicate();
PropertyGetter versionGetter = batch.shape().getVersionGetter();

BatchSqlBuilder builder = new BatchSqlBuilder(sqlClient, ctx.options.isBatchForbidden());
BatchSqlBuilder builder = new BatchSqlBuilder(
sqlClient,
batch.entities().size() < 2 || ctx.options.isBatchForbidden()
);
UpsertContextImpl upsertContext = new UpsertContextImpl(
builder,
batch.shape().getIdGetters().isEmpty() ? batch.shape().getType().getIdProp() : null,
Expand Down Expand Up @@ -628,7 +637,6 @@ private boolean isForcedOneByOne(
return false;
}
PropId idPropId = shape.getType().getIdProp().getId();
EntityCollection<DraftSpi> separated = null;
Iterator<EntityCollection.Item<DraftSpi>> itr = entities.items().iterator();
while (itr.hasNext()) {
EntityCollection.Item<DraftSpi> item = itr.next();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,12 @@ public BatchSqlBuilder(JSqlClientImplementor sqlClient) {
this(sqlClient, true);
}

public BatchSqlBuilder(JSqlClientImplementor sqlClient, boolean dumbBatchAcceptable) {
public BatchSqlBuilder(
JSqlClientImplementor sqlClient,
boolean recordPosition
) {
this.sqlClient = sqlClient;
if (dumbBatchAcceptable && sqlClient.getSqlFormatter().isPretty()) {
if (recordPosition && sqlClient.getSqlFormatter().isPretty()) {
this.variablePositions = new ArrayList<>();
} else {
this.variablePositions = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -359,9 +359,6 @@ private int[] prettyLog(BiFunction<SQLException, ExceptionTranslator.Args, Excep
);
int size = variableMatrix.size();
for (int i = 0; i < size; i++) {
if (i != 0) {
builder.append(", ");
}
builder.append("batch-").append(i).append(": ");
builder.append(variableMatrix.get(i)).append('\n');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ abstract class PrettySqlAppender {

private static final Comment DEAULT_COMMENT = new Comment(DEFAULT_MAX_VARIABLE_LENGTH);

private static final Inline INLINE = new Inline();

public abstract void append(
StringBuilder builder,
String sql,
Expand All @@ -35,7 +33,7 @@ public static PrettySqlAppender comment(int maxVariableLength) {
}

public static PrettySqlAppender inline() {
return INLINE;
return Inline.INSTANCE;
}

private static class Comment extends PrettySqlAppender {
Expand Down Expand Up @@ -125,6 +123,8 @@ public String toString() {

private static class Inline extends PrettySqlAppender {

static final Inline INSTANCE = new Inline();

private static final Map<Class<?>, VariableAppender<?>> APPENDER_MAP;

private static final DateTimeFormatter DATE_FORMATTER =
Expand Down

0 comments on commit 93ddb05

Please sign in to comment.