Skip to content

Commit

Permalink
Fix #476
Browse files Browse the repository at this point in the history
  • Loading branch information
babyfish-ct committed Mar 24, 2024
1 parent 293faad commit 03d9fa6
Show file tree
Hide file tree
Showing 20 changed files with 55 additions and 60 deletions.
2 changes: 1 addition & 1 deletion project/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
allprojects {
group = "org.babyfish.jimmer"
version = "0.8.113"
version = "0.8.114"
}
1 change: 1 addition & 0 deletions project/jimmer-apt/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ repositories {
dependencies {

implementation("javax.validation:validation-api:2.0.1.Final")
implementation("jakarta.validation:jakarta.validation-api:2.0.2")
implementation("org.springframework:spring-core:5.3.20")
implementation("com.intellij:annotations:12.0")
implementation("com.squareup:javapoet:1.13.0")
Expand Down
1 change: 1 addition & 0 deletions project/jimmer-core-kotlin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ dependencies {

testAnnotationProcessor(project(":jimmer-apt"))
testImplementation(kotlin("test"))
testImplementation("javax.validation:validation-api:2.0.1.Final")

testImplementation("org.mapstruct:mapstruct:1.5.3.Final")

Expand Down
3 changes: 2 additions & 1 deletion project/jimmer-core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@ repositories {

dependencies {

api("javax.validation:validation-api:2.0.1.Final")
implementation("javax.validation:validation-api:2.0.1.Final")
api("com.fasterxml.jackson.core:jackson-databind:2.15.2")
api("org.jetbrains.kotlin:kotlin-reflect:1.7.10")
implementation("com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.15.2")
implementation("org.apache.commons:commons-lang3:3.12.0")
implementation("org.jetbrains.kotlin:kotlin-stdlib:1.7.10")
compileOnly("org.mapstruct:mapstruct:1.5.3.Final")

testImplementation("javax.validation:validation-api:2.0.1.Final")
testImplementation("org.junit.jupiter:junit-jupiter-api:5.8.2")
testImplementation("org.mapstruct:mapstruct:1.5.3.Final")
testImplementation("org.projectlombok:lombok:1.18.30")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
public class JimmerVersion {

public static final JimmerVersion CURRENT =
new JimmerVersion(0, 8, 113);
new JimmerVersion(0, 8, 114);

private final int major;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,7 @@ private void conflict(Class<?> annotationType1, Class<?> annotationType2) {
for (Class<? extends Annotation> annotationType : sqlTypes) {
annotationMap.put(annotationType.getName(), annotationType);
}

annotationMap.put(javax.validation.constraints.Null.class.getName(), javax.validation.constraints.Null.class);
annotationMap.put(org.jetbrains.annotations.Nullable.class.getName(), org.jetbrains.annotations.Nullable.class);
annotationMap.put(javax.validation.constraints.NotNull.class.getName(), javax.validation.constraints.NotNull.class);
Expand Down
3 changes: 3 additions & 0 deletions project/jimmer-ksp/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ dependencies {
implementation("com.squareup:kotlinpoet:1.12.0")
implementation("com.squareup:kotlinpoet-ksp:1.12.0")

implementation("javax.validation:validation-api:2.0.1.Final")
implementation("jakarta.validation:jakarta.validation-api:2.0.2")

dokkaHtmlPlugin("org.jetbrains.dokka:dokka-base:1.6.0")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ protected JSqlClient.Builder createBuilder() {
builder.setDefaultBatchSize(properties.getDefaultBatchSize());
builder.setDefaultListBatchSize(properties.getDefaultListBatchSize());
builder.setOffsetOptimizingThreshold(properties.getOffsetOptimizingThreshold());
builder.setDefaultLockMode(properties.getDefaultLockMode());
builder.setForeignKeyEnabledByDefault(properties.isForeignKeyEnabledByDefault());
builder.setSaveCommandPessimisticLock(properties.isSaveCommandPessimisticLock());
builder.setExecutorContextPrefixes(properties.getExecutorContextPrefixes());
if (properties.isShowSql()) {
builder.setExecutor(Executor.log(executor));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.babyfish.jimmer.client.generator.ts.NullRenderMode;
import org.babyfish.jimmer.sql.EnumType;
import org.babyfish.jimmer.sql.JSqlClient;
import org.babyfish.jimmer.sql.ast.mutation.LockMode;
import org.babyfish.jimmer.sql.dialect.DefaultDialect;
import org.babyfish.jimmer.sql.dialect.Dialect;
import org.babyfish.jimmer.sql.event.TriggerType;
Expand Down Expand Up @@ -55,9 +56,9 @@ public class JimmerProperties {

private final int offsetOptimizingThreshold;

private final boolean isForeignKeyEnabledByDefault;
private final LockMode defaultLockMode;

private final boolean saveCommandPessimisticLock;
private final boolean isForeignKeyEnabledByDefault;

private final Collection<String> executorContextPrefixes;

Expand Down Expand Up @@ -86,8 +87,8 @@ public JimmerProperties(
@Nullable Integer defaultBatchSize,
@Nullable Integer defaultListBatchSize,
@Nullable Integer offsetOptimizingThreshold,
@Nullable LockMode defaultLockMode,
@Nullable Boolean isForeignKeyEnabledByDefault, // Default value is true, so use `Boolean`
boolean saveCommandPessimisticLock,
@Nullable Collection<String> executorContextPrefixes,
@Nullable String microServiceName,
@Nullable ErrorTranslator errorTranslator,
Expand Down Expand Up @@ -202,7 +203,7 @@ public JimmerProperties(
isForeignKeyEnabledByDefault != null ?
isForeignKeyEnabledByDefault :
true;
this.saveCommandPessimisticLock = saveCommandPessimisticLock;
this.defaultLockMode = defaultLockMode != null ? defaultLockMode : LockMode.OPTIMISTIC;
this.executorContextPrefixes = executorContextPrefixes;
this.microServiceName =
microServiceName != null ?
Expand Down Expand Up @@ -301,6 +302,10 @@ public int getOffsetOptimizingThreshold() {
return offsetOptimizingThreshold;
}

public LockMode getDefaultLockMode() {
return defaultLockMode;
}

/**
* This configuration is only useful for {@link org.babyfish.jimmer.sql.JoinColumn}
* of local associations (not remote associations across microservice boundaries)
Expand All @@ -319,10 +324,6 @@ public boolean isForeignKeyEnabledByDefault() {
return isForeignKeyEnabledByDefault;
}

public boolean isSaveCommandPessimisticLock() {
return saveCommandPessimisticLock;
}

/**
* If this option is configured, when jimmer calls back
* `org.babyfish.jimmer.sql.runtime.Executor.execute` before executing SQL,
Expand Down
1 change: 1 addition & 0 deletions project/jimmer-sql-kotlin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ dependencies {
testAnnotationProcessor(project(":jimmer-ksp"))

testImplementation("com.h2database:h2:2.1.212")
testImplementation("javax.validation:validation-api:2.0.1.Final")
dokkaHtmlPlugin("org.jetbrains.dokka:dokka-base:1.6.0")
testImplementation("com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.15.2")
testImplementation("org.postgresql:postgresql:42.3.6")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,10 +214,6 @@ class KSqlClientDsl constructor(
javaBuilder.setIdOnlyTargetCheckingLevel(checkingLevel)
}

fun setSaveCommandPessimisticLock(lock: Boolean = true) {
javaBuilder.setSaveCommandPessimisticLock(lock)
}

fun addDraftInterceptor(interceptor: DraftInterceptor<*, *>) {
javaBuilder.addDraftInterceptor(interceptor)
}
Expand Down
6 changes: 5 additions & 1 deletion project/jimmer-sql/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ dependencies {
implementation("com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.15.2")
compileOnly("org.postgresql:postgresql:42.3.6")
compileOnly("com.fasterxml.jackson.module:jackson-module-kotlin:2.15.2")
antlr("org.antlr:antlr4:4.13.0")

antlr("org.antlr:antlr4:4.13.0") {
exclude("com.ibm.icu", "icu4j")
}

testAnnotationProcessor(project(":jimmer-apt"))

Expand All @@ -44,6 +47,7 @@ dependencies {
testImplementation("mysql:mysql-connector-java:8.0.29")
testImplementation("org.postgresql:postgresql:42.3.6")
testImplementation("org.apache.kafka:connect-api:0.10.0.0")
testImplementation("javax.validation:validation-api:2.0.1.Final")
// testImplementation(files("/Users/chentao/Downloads/ojdbc8-21.9.0.0.jar"))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,10 @@ interface Builder {
@OldChain
Builder setOffsetOptimizingThreshold(int threshold);

/**
* Set deault lock mode of save command
* @param lockMode
*/
@OldChain
Builder setDefaultLockMode(LockMode lockMode);

Expand Down Expand Up @@ -414,12 +418,6 @@ interface Builder {
@OldChain
Builder setIdOnlyTargetCheckingLevel(IdOnlyTargetCheckingLevel checkingLevel);

@OldChain
Builder setSaveCommandPessimisticLock();

@OldChain
Builder setSaveCommandPessimisticLock(boolean lock);

@OldChain
Builder addDraftInterceptor(DraftInterceptor<?, ?> interceptor);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,6 @@ class JSqlClientImpl implements JSqlClientImplementor {

private final IdOnlyTargetCheckingLevel idOnlyTargetCheckingLevel;

private final boolean saveCommandPessimisticLock;

private final DraftInterceptorManager draftInterceptorManager;

private final String microServiceName;
Expand All @@ -117,8 +115,6 @@ class JSqlClientImpl implements JSqlClientImplementor {

private final ReaderManager readerManager = new ReaderManager(this);

private final ReadWriteLock initializationLock = new ReentrantReadWriteLock();

private SqlClientInitializer sqlClientInitializer;

private JSqlClientImpl(
Expand Down Expand Up @@ -147,7 +143,6 @@ private JSqlClientImpl(
TransientResolverManager transientResolverManager,
boolean defaultDissociationActionCheckable,
IdOnlyTargetCheckingLevel idOnlyTargetCheckingLevel,
boolean saveCommandPessimisticLock,
DraftInterceptorManager draftInterceptorManager,
String microServiceName,
MicroServiceExchange microServiceExchange,
Expand Down Expand Up @@ -196,7 +191,6 @@ private JSqlClientImpl(
this.transientResolverManager = transientResolverManager;
this.defaultDissociationActionCheckable = defaultDissociationActionCheckable;
this.idOnlyTargetCheckingLevel = idOnlyTargetCheckingLevel;
this.saveCommandPessimisticLock = saveCommandPessimisticLock;
this.draftInterceptorManager = draftInterceptorManager;
this.microServiceName = microServiceName;
this.microServiceExchange = microServiceExchange;
Expand Down Expand Up @@ -481,7 +475,6 @@ public JSqlClientImplementor caches(Consumer<CacheDisableConfig> block) {
transientResolverManager,
defaultDissociationActionCheckable,
idOnlyTargetCheckingLevel,
saveCommandPessimisticLock,
draftInterceptorManager,
microServiceName,
microServiceExchange,
Expand Down Expand Up @@ -525,7 +518,6 @@ public JSqlClientImplementor filters(Consumer<FilterConfig> block) {
transientResolverManager,
defaultDissociationActionCheckable,
idOnlyTargetCheckingLevel,
saveCommandPessimisticLock,
draftInterceptorManager,
microServiceName,
microServiceExchange,
Expand Down Expand Up @@ -564,7 +556,6 @@ public JSqlClientImplementor disableSlaveConnectionManager() {
transientResolverManager,
defaultDissociationActionCheckable,
idOnlyTargetCheckingLevel,
saveCommandPessimisticLock,
draftInterceptorManager,
microServiceName,
microServiceExchange,
Expand Down Expand Up @@ -606,7 +597,6 @@ public JSqlClientImplementor executor(Executor executor) {
transientResolverManager,
defaultDissociationActionCheckable,
idOnlyTargetCheckingLevel,
saveCommandPessimisticLock,
draftInterceptorManager,
microServiceName,
microServiceExchange,
Expand Down Expand Up @@ -1171,17 +1161,6 @@ public Builder setIdOnlyTargetCheckingLevel(IdOnlyTargetCheckingLevel checkingLe
return this;
}

@Override
public Builder setSaveCommandPessimisticLock() {
return setSaveCommandPessimisticLock(true);
}

@Override
public Builder setSaveCommandPessimisticLock(boolean lock) {
saveCommandPessimisticLock = lock;
return this;
}

@Override
public Builder addDraftInterceptor(DraftInterceptor<?, ?> interceptor) {
return addDraftInterceptors(Collections.singletonList(interceptor));
Expand Down Expand Up @@ -1442,7 +1421,6 @@ public JSqlClient build() {
transientResolverManager,
defaultDissociationActionCheckable,
idOnlyTargetCheckingLevel,
saveCommandPessimisticLock,
new DraftInterceptorManager(interceptors),
microServiceName,
microServiceExchange,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ private void renderEmbedded(
}
} else {
for (Field field : childFetcher.getFieldMap().values()) {
if (field.getProp().isFormula()) {
ImmutableProp prop = field.getProp();
if (prop.isFormula() && prop.getSqlTemplate() == null) {
continue;
}
String propName = field.getProp().getName();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

import org.babyfish.jimmer.sql.ast.Executable;
import org.babyfish.jimmer.sql.runtime.ExecutionException;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import javax.validation.constraints.NotNull;
import java.sql.Connection;
import java.util.List;
import java.util.Optional;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,11 @@
import org.babyfish.jimmer.meta.ImmutableProp;
import org.babyfish.jimmer.meta.TargetLevel;
import org.babyfish.jimmer.sql.DissociateAction;
import org.babyfish.jimmer.sql.ManyToOne;
import org.babyfish.jimmer.sql.OneToOne;
import org.babyfish.jimmer.sql.meta.MetadataStrategy;
import org.babyfish.jimmer.sql.meta.MiddleTable;
import org.babyfish.jimmer.sql.meta.Storage;
import org.jetbrains.annotations.NotNull;

import javax.validation.constraints.NotNull;
import java.lang.annotation.Annotation;
import java.util.List;
import java.util.Objects;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

class DynamicEmbeddedReader implements Reader<Object> {
Expand All @@ -26,20 +27,24 @@ class DynamicEmbeddedReader implements Reader<Object> {
@Override
public Object read(ResultSet rs, Context ctx) throws SQLException {
DraftSpi spi = (DraftSpi) type.getDraftFactory().apply(ctx.draftContext(), null);
boolean returnNull = false;
try {
int size = readers.size();
for (int i = 0; i < size; i++) {
Object value = readers.get(i).read(rs, ctx);
ImmutableProp prop = props.get(i);
if (value == null && !prop.isNullable()) {
return null;
if (!returnNull) {
ImmutableProp prop = props.get(i);
if (value == null && !prop.isNullable()) {
returnNull = true;
} else {
spi.__set(prop.getId(), value);
}
}
spi.__set(prop.getId(), value);
}
} catch (Throwable ex) {
throw DraftConsumerUncheckedException.rethrow(ex);
}
return ctx.resolve(spi);
return returnNull ? null : ctx.resolve(spi);
}

@Override
Expand Down
Loading

0 comments on commit 03d9fa6

Please sign in to comment.