Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JNG-4561 add app variable to presicion and scale #154

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@

import static hu.blackbelt.judo.runtime.core.bootstrap.dao.rdbms.RdbmsDAOProvider.RDBMS_DAO_MARK_SELECTED_RANGE_ITEMS;
import static hu.blackbelt.judo.runtime.core.bootstrap.dao.rdbms.RdbmsDAOProvider.RDBMS_DAO_OPTIMISTIC_LOCK_ENABLED;
import static hu.blackbelt.judo.runtime.core.bootstrap.dao.rdbms.RdbmsBuilderProvider.RDBMS_DAO_FLOATING_POINT_TYPE_MAX_PRECISION;
import static hu.blackbelt.judo.runtime.core.bootstrap.dao.rdbms.RdbmsBuilderProvider.RDBMS_DAO_FLOATING_POINT_TYPE_MAX_SCALE;
import static hu.blackbelt.judo.runtime.core.bootstrap.dispatcher.DefaultDispatcherProvider.*;
import static hu.blackbelt.judo.runtime.core.bootstrap.dispatcher.DefaultIdentifierSignerProvider.IDENTIFIER_SIGNER_SECRET;
import static hu.blackbelt.judo.runtime.core.bootstrap.dispatcher.DefaultMetricsCollectorProvider.*;
Expand Down Expand Up @@ -164,6 +166,8 @@ protected void configure() {
bind(Boolean.class).annotatedWith(Names.named(RDBMS_DAO_OPTIMISTIC_LOCK_ENABLED)).toInstance(true);
bind(Integer.class).annotatedWith(Names.named(RDBMS_DAO_MARK_SELECTED_RANGE_ITEMS)).toInstance(1000);
bind(Boolean.class).annotatedWith(Names.named(RDBMS_DAO_MARK_SELECTED_RANGE_ITEMS)).toInstance(false);
bind(Integer.class).annotatedWith(Names.named(RDBMS_DAO_FLOATING_POINT_TYPE_MAX_PRECISION)).toInstance(15);
bind(Integer.class).annotatedWith(Names.named(RDBMS_DAO_FLOATING_POINT_TYPE_MAX_SCALE)).toInstance(4);

bind(ActorResolver.class).toProvider(DefaultActorResolverProvider.class).in(Singleton.class);
bind(Boolean.class).annotatedWith(Names.named(ACTOR_RESOLVER_CHECK_MAPPED_ACTORS)).toInstance(Boolean.FALSE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

import com.google.inject.Inject;
import com.google.inject.Provider;
import com.google.inject.name.Named;
import hu.blackbelt.judo.dao.api.IdentifierProvider;
import hu.blackbelt.judo.dispatcher.api.VariableResolver;
import hu.blackbelt.judo.meta.asm.runtime.AsmModel;
Expand All @@ -38,9 +39,15 @@
import hu.blackbelt.mapper.api.Coercer;
import org.eclipse.emf.ecore.EClass;

import javax.annotation.Nullable;

@SuppressWarnings("rawtypes")
public class RdbmsBuilderProvider implements Provider<RdbmsBuilder> {


public static final String RDBMS_DAO_FLOATING_POINT_TYPE_MAX_PRECISION = "rdbmsDaoFloatingTypeMaxPrecision";
public static final String RDBMS_DAO_FLOATING_POINT_TYPE_MAX_SCALE = "rdbmsDaoFloatingTypeMaxScale";

@Inject
AsmModel asmModel;

Expand Down Expand Up @@ -68,6 +75,16 @@ public class RdbmsBuilderProvider implements Provider<RdbmsBuilder> {
@Inject
Dialect dialect;

@Inject(optional = true)
@Named(RDBMS_DAO_FLOATING_POINT_TYPE_MAX_PRECISION)
@Nullable
private int precision = 15;

@Inject(optional = true)
@Named(RDBMS_DAO_FLOATING_POINT_TYPE_MAX_SCALE)
@Nullable
private int scale = 4;
Madmat8 marked this conversation as resolved.
Show resolved Hide resolved

@SuppressWarnings({ "unchecked" })
@Override
public RdbmsBuilder get() {
Expand All @@ -85,6 +102,8 @@ public RdbmsBuilder get() {
.variableResolver(variableResolver)
.mapperFactory(mapperFactory)
.dialect(dialect)
.precision(precision)
.scale(scale)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,12 @@ public class RdbmsBuilder<ID> {

private final ThreadLocal<Map<String, Collection<? extends RdbmsField>>> CONSTANT_FIELDS = new ThreadLocal<>();

@Getter
private int precision;

@Getter
private int scale;

@Builder
public RdbmsBuilder(
@NonNull RdbmsResolver rdbmsResolver,
Expand All @@ -107,7 +113,9 @@ public RdbmsBuilder(
@NonNull RdbmsModel rdbmsModel,
@NonNull AsmUtils asmUtils,
@NonNull MapperFactory<ID> mapperFactory,
@NonNull Dialect dialect) {
@NonNull Dialect dialect,
final int precision,
final int scale) {
this.rdbmsResolver = rdbmsResolver;
this.parameterMapper = parameterMapper;
this.identifierProvider = identifierProvider;
Expand All @@ -119,6 +127,8 @@ public RdbmsBuilder(
this.asmUtils = asmUtils;
this.dialect = dialect;
this.mappers = mapperFactory.getMappers(this);
this.precision = precision;
this.scale = scale;
this.rules = rdbmsModel.getResource().getContents().stream()
.filter(Rules.class::isInstance)
.map(Rules.class::cast)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ public Stream<RdbmsColumn> map(final Attribute attribute, RdbmsBuilderContext bu
.targetAttribute(t.getTargetAttribute())
.alias(t.getAlias())
.sourceDomainConstraints(RdbmsField.getDomainConstraints(attribute.getSourceAttribute()))
.precision(rdbmsBuilder.getPrecision())
.scale(rdbmsBuilder.getScale())
.build());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ private Stream<? extends RdbmsField> getFields(RdbmsBuilderContext builderContex
.target(t.getTarget())
.targetAttribute(t.getTargetAttribute())
.alias(t.getAlias())
.precision(rdbmsBuilder.getPrecision())
.scale(rdbmsBuilder.getScale())
.build());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -306,8 +306,11 @@ public FunctionMapper(@NonNull RdbmsBuilder rdbmsBuilder) {

functionBuilderMap.put(FunctionSignature.TYPE_OF, c ->
c.builder.pattern("EXISTS (SELECT 1 FROM {1} WHERE " + StatementExecutor.ID_COLUMN_NAME + " = {0} AND " + StatementExecutor.ENTITY_TYPE_COLUMN_NAME + " = {2})")
.parameters(List.of(c.parameters.get(ParameterName.INSTANCE), c.parameters.get(ParameterName.TYPE), RdbmsConstant.builder()
.parameter(rdbmsBuilder.getParameterMapper().createParameter(AsmUtils.getClassifierFQName(((RdbmsEntityTypeName) c.parameters.get(ParameterName.TYPE)).getType()), null))
.parameters(List.of(c.parameters.get(ParameterName.INSTANCE), c.parameters.get(ParameterName.TYPE),
RdbmsConstant.builder()
.parameter(rdbmsBuilder.getParameterMapper()
.createParameter(AsmUtils.getClassifierFQName(
((RdbmsEntityTypeName) c.parameters.get(ParameterName.TYPE)).getType()), null))
.index(rdbmsBuilder.getConstantCounter().getAndIncrement())
.build())));

Expand Down Expand Up @@ -504,6 +507,8 @@ public Stream<? extends RdbmsField> map(final Function function, RdbmsBuilderCon
RdbmsFunction.RdbmsFunctionBuilder builder = RdbmsFunction.builder()
.target(t.getTarget())
.targetAttribute(t.getTargetAttribute())
.scale(builderContext.getRdbmsBuilder().getScale())
.precision(builderContext.getRdbmsBuilder().getPrecision())
.alias(t.getAlias());

java.util.function.Function<FunctionContext, RdbmsFunction.RdbmsFunctionBuilder> func = functionBuilderMap.get(function.getSignature());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
import hu.blackbelt.judo.runtime.core.dao.rdbms.executors.StatementExecutor;
import hu.blackbelt.judo.runtime.core.dao.rdbms.query.RdbmsBuilderContext;
import hu.blackbelt.judo.runtime.core.dao.rdbms.query.model.RdbmsColumn;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.common.util.EMap;
Expand All @@ -39,6 +41,7 @@
@Slf4j
public class IdAttributeMapper extends RdbmsMapper<IdAttribute> {


@Override
public Stream<RdbmsColumn> map(final IdAttribute idAttribute, RdbmsBuilderContext builderContext) {
final EMap<Node, EList<EClass>> ancestors = builderContext.getAncestors();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ public Stream<RdbmsField> map(final SubSelectFeature feature, RdbmsBuilderContex
.partnerTable(feature.getSubSelect())
.columnName(getTargets(feature.getFeature()).map(tt -> tt.getAlias() + (tt.getTarget() != null ? "_" + tt.getTarget().getIndex() : "")).findAny().get())
.pattern(pattern)
.scale(builderContext.getRdbmsBuilder().getScale())
.precision(builderContext.getRdbmsBuilder().getPrecision())
.alias(t.getAlias())
.build());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,13 @@ private RdbmsCount(
conditions.add(RdbmsFunction.builder()
.pattern("{0} IN ({1})")
.parameters(Arrays.asList(
RdbmsColumn.builder().partnerTable(query.getSelect()).columnName(StatementExecutor.ID_COLUMN_NAME).build(),
RdbmsColumn.builder()
.partnerTable(query.getSelect())
.columnName(StatementExecutor.ID_COLUMN_NAME)
.build(),
RdbmsParameter.builder().parameterName(RdbmsAliasUtil.getInstanceIdsKey(query.getSelect())).build()
)).build());
))
.build());
}

final boolean addJoinOfFilterFeature =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,8 @@
@NoArgsConstructor
public abstract class RdbmsField {

// TODO: JNG-4561: Floating point type's max precision and scale should be configured with environment/application variable
private static final int FLOATING_POINT_TYPE_MAX_PRECISION = 15;
private static final int FLOATING_POINT_TYPE_MAX_SCALE = 4;
protected int precision;
protected int scale;

protected String alias;

Expand Down Expand Up @@ -117,8 +116,8 @@ protected String cast(final String sql, final String typeName, final EAttribute
if (domainConstraints != null &&
domainConstraints.getPrecision() != null &&
domainConstraints.getScale() != null &&
(domainConstraints.getPrecision() > FLOATING_POINT_TYPE_MAX_PRECISION ||
domainConstraints.getScale() > FLOATING_POINT_TYPE_MAX_SCALE ||
(domainConstraints.getPrecision() > precision ||
domainConstraints.getScale() > scale ||
domainConstraints.getScale() == 0)) {
String defaultType = new RdbmsDecimalType().toSql();
if (domainConstraints.getScale() == 0) {
Expand Down Expand Up @@ -152,3 +151,4 @@ public String toString() {
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EClass;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Conditional;
import org.springframework.context.annotation.Configuration;
Expand Down Expand Up @@ -127,6 +128,12 @@ public class JudoDefaultSpringConfiguration {
@Autowired
private Sequence sequence;

@Value("${judo.floatingTypeMaxPrecision:}")
private int floatingTypeMaxPrecision;

@Value("${judo.floatingTypeMaxScale:}")
private int floatingTypeMaxScale;

@Autowired
private RdbmsParameterMapper rdbmsParameterMapper;

Expand Down Expand Up @@ -194,6 +201,8 @@ public RdbmsBuilder getRdbmsBuilder(RdbmsResolver rdbmsResolver,
.variableResolver(variableResolver)
.mapperFactory(mapperFactory)
.dialect(dialect)
.precision(floatingTypeMaxPrecision)
.scale(floatingTypeMaxScale)
.build();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
judo.floatingTypeMaxPrecision=15
judo.floatingTypeMaxScale=4