From bff2f0e145d6552a4ae90a21952143c1f5a1ddec Mon Sep 17 00:00:00 2001 From: babyfish-ct Date: Mon, 11 Nov 2024 04:19:17 +0800 Subject: [PATCH] #769 --- .../spring/transaction/JTransactionalSqlClient.java | 10 ++++++++++ .../jimmer/sql/ast/impl/mutation/PreHandler.java | 12 +++++++----- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/project/jimmer-spring-boot-starter/src/main/java/org/babyfish/jimmer/spring/transaction/JTransactionalSqlClient.java b/project/jimmer-spring-boot-starter/src/main/java/org/babyfish/jimmer/spring/transaction/JTransactionalSqlClient.java index 4878c5f4e4..5835a88a4d 100644 --- a/project/jimmer-spring-boot-starter/src/main/java/org/babyfish/jimmer/spring/transaction/JTransactionalSqlClient.java +++ b/project/jimmer-spring-boot-starter/src/main/java/org/babyfish/jimmer/spring/transaction/JTransactionalSqlClient.java @@ -6,6 +6,8 @@ class JTransactionalSqlClient extends AbstractJSqlClientDelegate { + private static final EntityManager EMPTY_ENTITY_MANAGER = new EntityManager(); + @Override protected JSqlClientImplementor sqlClient() { JSqlClient sqlClient = JimmerTransactionManager.sqlClient(); @@ -19,4 +21,12 @@ protected JSqlClientImplementor sqlClient() { } return (JSqlClientImplementor) sqlClient; } + + @Override + public void initialize() {} + + @Override + public EntityManager getEntityManager() { + return EMPTY_ENTITY_MANAGER; + } } diff --git a/project/jimmer-sql/src/main/java/org/babyfish/jimmer/sql/ast/impl/mutation/PreHandler.java b/project/jimmer-sql/src/main/java/org/babyfish/jimmer/sql/ast/impl/mutation/PreHandler.java index 3e1488a2ee..77a4d5d8bf 100644 --- a/project/jimmer-sql/src/main/java/org/babyfish/jimmer/sql/ast/impl/mutation/PreHandler.java +++ b/project/jimmer-sql/src/main/java/org/babyfish/jimmer/sql/ast/impl/mutation/PreHandler.java @@ -295,7 +295,8 @@ final QueryReason queryReason(boolean hasId, Collection drafts) { return QueryReason.INTERCEPTOR; } JSqlClientImplementor sqlClient = ctx.options.getSqlClient(); - if (!hasId && ctx.options.getMode() != SaveMode.UPDATE_ONLY) { + SaveMode saveMode = ctx.options.getMode(); + if (!hasId && saveMode != SaveMode.UPDATE_ONLY) { IdGenerator idGenerator = ctx.options.getSqlClient().getIdGenerator(ctx.path.getType().getJavaClass()); if (idGenerator == null) { ctx.throwNoIdGenerator(); @@ -309,15 +310,16 @@ final QueryReason queryReason(boolean hasId, Collection drafts) { } } if (!hasId && ctx.options.isInvestigateKeyBasedUpdate() && - ctx.options.getMode() != SaveMode.INSERT_ONLY && - ctx.options.getMode() != SaveMode.INSERT_IF_ABSENT) { + saveMode != SaveMode.INSERT_ONLY && + saveMode != SaveMode.INSERT_IF_ABSENT) { return QueryReason.PREPARE_TO_INVESTIGATE_KEY_BASED_UPDATE; } - if (ctx.options.getMode() == SaveMode.UPSERT) { + if (saveMode != SaveMode.INSERT_ONLY && saveMode != SaveMode.UPDATE_ONLY) { if (!sqlClient.getDialect().isUpsertSupported()) { return QueryReason.UPSERT_NOT_SUPPORTED; } - if (!sqlClient.getDialect().isUpsertWithOptimisticLockSupported()) { + if (saveMode != SaveMode.INSERT_IF_ABSENT && + !sqlClient.getDialect().isUpsertWithOptimisticLockSupported()) { UserOptimisticLock userLock = ctx.options.getUserOptimisticLock(ctx.path.getType()); boolean useOptimisticLock = userLock != null ||