Skip to content
Merged
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 @@ -1444,6 +1444,25 @@ public static class ProgrammingModel {
* have been indicated as deprecated will simply be ignored/excluded from the metamodel.
*/
private boolean ignoreDeprecated = false;


/**
* If set, then {@link Digits#fraction()}, the JDO <code>@Column#scale</code> and the JPA {@link Column#scale()}
* should be used for the <code>MinFractionalFacet</code> as well as the <code>MaxFractionalFacet</code>.
*
* <p>
* What this means in practice is that a numeric values will be rendered to the same number of fractional digits,
* irrespective of whether they are whole numbers. For example, with a scale of 2, then
* &quot;123.45&quot; and also &quot;123.00&quot;.
* </p>
*
* <p>
* If set to <code>false</code>, then these values would be rendered as &quot;123.45&quot;,
* but for the whole integer instead just &quot;123&quot; (that is, the shortest textual
* representation).
* </p>
*/
private boolean useScaleForMinFractionalFacet = true;
}

private final Introspector introspector = new Introspector();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
package org.apache.causeway.core.metamodel.facets.objectvalue.digits;

import javax.persistence.Column;
import javax.validation.constraints.Digits;

import org.apache.causeway.applib.annotation.ValueSemantics;
Expand All @@ -33,6 +34,15 @@
* <li><tt>12345</tt> has a total of 5 digits</li>
* <li><tt>12345.0</tt> has a total of 6 digits</li>
* </ul>
*
* <p>
* In JPA's {@link javax.persistence.Column}, this corresponds to {@link Column#precision()}.
*
* <p>
* In JDO's <code>@Column</code> annotation, this corresponds to <code>@Column#length</code>.
*
* <p>
* For {@link Digits}, corresponds to sum of {@link Digits#integer()} and {@link Digits#fraction()}.
*/
public interface MaxTotalDigitsFacet
extends Facet {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,11 @@ public class MaxTotalDigitsFacetFromValueSemanticsAnnotation
extends MaxTotalDigitsFacetAbstract {

public static Optional<MaxTotalDigitsFacet> create(
final Optional<ValueSemantics> digitsIfAny,
final Optional<ValueSemantics> valueSemanticsIfAny,
final FacetHolder holder) {

return digitsIfAny
.map(digits->{
return new MaxTotalDigitsFacetFromValueSemanticsAnnotation(
digits.maxTotalDigits(), holder);
});
return valueSemanticsIfAny
.map(digits-> new MaxTotalDigitsFacetFromValueSemanticsAnnotation(digits.maxTotalDigits(), holder));
}

private MaxTotalDigitsFacetFromValueSemanticsAnnotation(
Expand Down
1 change: 1 addition & 0 deletions persistence/commons/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
module org.apache.causeway.persistence.commons {
exports org.apache.causeway.persistence.jpa.integration.changetracking;
exports org.apache.causeway.persistence.commons;
exports org.apache.causeway.persistence.commons.metamodel.facets.prop.column;

requires java.annotation;
requires java.desktop;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package org.apache.causeway.persistence.commons.metamodel.facets.prop.column;

import lombok.experimental.UtilityClass;

import org.apache.causeway.core.metamodel.facets.objectvalue.digits.MaxFractionalDigitsFacet;
import org.apache.causeway.core.metamodel.facets.objectvalue.digits.MaxTotalDigitsFacet;
import org.apache.causeway.core.metamodel.spec.feature.ObjectAssociation;
import org.apache.causeway.core.metamodel.specloader.validator.ValidationFailure;

@UtilityClass
public class BigDecimalFromXxxColumnAnnotationMetaModelRefinerUtil {

public static void validateBigDecimalValueFacet(final ObjectAssociation association) {

association.lookupFacet(MaxTotalDigitsFacet.class)
.map(MaxTotalDigitsFacet::getSharedFacetRankingElseFail)
.ifPresent(facetRanking->facetRanking
.visitTopRankPairsSemanticDiffering(MaxTotalDigitsFacet.class, (a, b)->{

ValidationFailure.raiseFormatted(
association,
"%s: inconsistent MaxTotalDigits semantics specified in %s and %s.",
association.getFeatureIdentifier().toString(),
a.getClass().getSimpleName(),
b.getClass().getSimpleName());
}));

association.lookupFacet(MaxFractionalDigitsFacet.class)
.map(MaxFractionalDigitsFacet::getSharedFacetRankingElseFail)
.ifPresent(facetRanking->facetRanking
.visitTopRankPairsSemanticDiffering(MaxFractionalDigitsFacet.class, (a, b)->{

ValidationFailure.raiseFormatted(
association,
"%s: inconsistent MaxFractionalDigits semantics specified in %s and %s.",
association.getFeatureIdentifier().toString(),
a.getClass().getSimpleName(),
b.getClass().getSimpleName());
}));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package org.apache.causeway.persistence.commons.metamodel.facets.prop.column;

import lombok.experimental.UtilityClass;

import org.apache.causeway.core.metamodel.facets.objectvalue.mandatory.MandatoryFacet;
import org.apache.causeway.core.metamodel.spec.feature.ObjectAssociation;
import org.apache.causeway.core.metamodel.specloader.validator.ValidationFailure;

@UtilityClass
public class MandatoryFromXxxColumnAnnotationMetaModelRefinerUtil {

public static void validateMandatoryFacet(final ObjectAssociation association) {

association.lookupFacet(MandatoryFacet.class)
.map(MandatoryFacet::getSharedFacetRankingElseFail)
.ifPresent(facetRanking->facetRanking
.visitTopRankPairsSemanticDiffering(MandatoryFacet.class, (a, b)->{

ValidationFailure.raiseFormatted(
association,
"%s: inconsistent Mandatory/Optional semantics specified in %s and %s.",
association.getFeatureIdentifier().toString(),
a.getClass().getSimpleName(),
b.getClass().getSimpleName());
}));

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package org.apache.causeway.persistence.commons.metamodel.facets.prop.column;

import lombok.experimental.UtilityClass;

import org.apache.causeway.core.metamodel.facets.objectvalue.maxlen.MaxLengthFacet;
import org.apache.causeway.core.metamodel.spec.feature.ObjectAssociation;
import org.apache.causeway.core.metamodel.specloader.validator.ValidationFailure;

@UtilityClass
public class MaxLengthFromXxxColumnAnnotationMetaModelRefinerUtil {
public static void validateMaxLengthFacet(ObjectAssociation association) {
association.lookupFacet(MaxLengthFacet.class)
.map(MaxLengthFacet::getSharedFacetRankingElseFail)
.ifPresent(facetRanking->facetRanking
.visitTopRankPairsSemanticDiffering(MaxLengthFacet.class, (a, b)->{

ValidationFailure.raiseFormatted(
association,
"%s: inconsistent MaxLength semantics specified in %s and %s.",
association.getFeatureIdentifier().toString(),
a.getClass().getSimpleName(),
b.getClass().getSimpleName());
}));
}
}
31 changes: 18 additions & 13 deletions persistence/jdo/metamodel/pom.xml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor
license agreements. See the NOTICE file distributed with this work for additional
information regarding copyright ownership. The ASF licenses this file to
you under the Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the License. You may obtain a copy of
the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required
by applicable law or agreed to in writing, software distributed under the
License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
OF ANY KIND, either express or implied. See the License for the specific
<!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor
license agreements. See the NOTICE file distributed with this work for additional
information regarding copyright ownership. The ASF licenses this file to
you under the Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the License. You may obtain a copy of
the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required
by applicable law or agreed to in writing, software distributed under the
License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
OF ANY KIND, either express or implied. See the License for the specific
language governing permissions and limitations under the License. -->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
Expand Down Expand Up @@ -37,26 +37,31 @@
<groupId>org.apache.causeway.persistence</groupId>
<artifactId>causeway-persistence-jdo-applib</artifactId>
</dependency>

<dependency>
<groupId>org.apache.causeway.persistence</groupId>
<artifactId>causeway-persistence-jdo-provider</artifactId>
</dependency>

<dependency>
<dependency>
<groupId>org.apache.causeway.persistence</groupId>
<artifactId>causeway-persistence-commons</artifactId>
</dependency>

<dependency>
<groupId>org.apache.causeway.core</groupId>
<artifactId>causeway-core-runtime</artifactId>
</dependency>

<!-- TESTING -->

<dependency>
<groupId>org.apache.causeway.core</groupId>
<artifactId>causeway-core-internaltestsupport</artifactId>
<scope>test</scope>
</dependency>

</dependencies>
</dependencies>


</project>
1 change: 1 addition & 0 deletions persistence/jdo/metamodel/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
requires javax.jdo;
requires org.apache.causeway.security.api;
requires org.datanucleus.store.rdbms;
requires org.apache.causeway.persistence.commons;

exports org.apache.causeway.persistence.jdo.metamodel;
exports org.apache.causeway.persistence.jdo.metamodel.facets.object.persistencecapable;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@
import org.apache.causeway.persistence.jdo.metamodel.facets.object.persistencecapable.JdoPersistenceCapableFacetFactory;
import org.apache.causeway.persistence.jdo.metamodel.facets.object.query.JdoQueryAnnotationFacetFactory;
import org.apache.causeway.persistence.jdo.metamodel.facets.object.version.JdoVersionAnnotationFacetFactory;
import org.apache.causeway.persistence.jdo.metamodel.facets.prop.column.BigDecimalFromColumnAnnotationFacetFactory;
import org.apache.causeway.persistence.jdo.metamodel.facets.prop.column.MandatoryFromColumnAnnotationFacetFactory;
import org.apache.causeway.persistence.jdo.metamodel.facets.prop.column.BigDecimalFromJdoColumnAnnotationFacetFactory;
import org.apache.causeway.persistence.jdo.metamodel.facets.prop.column.MandatoryFromJdoColumnAnnotationFacetFactory;
import org.apache.causeway.persistence.jdo.metamodel.facets.prop.column.MaxLengthFromJdoColumnAnnotationFacetFactory;
import org.apache.causeway.persistence.jdo.metamodel.facets.prop.notpersistent.JdoNotPersistentAnnotationFacetFactory;
import org.apache.causeway.persistence.jdo.metamodel.facets.prop.primarykey.JdoPrimaryKeyAnnotationFacetFactory;
Expand Down Expand Up @@ -82,12 +82,12 @@ public void refineProgrammingModel(final ProgrammingModel pm) {

pm.addFactory(step2, new JdoQueryAnnotationFacetFactory(mmc, jdoFacetContext), Marker.JDO);

pm.addFactory(step2, new BigDecimalFromColumnAnnotationFacetFactory(mmc), Marker.JDO);
pm.addFactory(step2, new BigDecimalFromJdoColumnAnnotationFacetFactory(mmc), Marker.JDO);
pm.addFactory(step2, new MaxLengthFromJdoColumnAnnotationFacetFactory(mmc), Marker.JDO);
// must appear after JdoPrimaryKeyAnnotationFacetFactory (above)
// and also MandatoryFacetOnPropertyMandatoryAnnotationFactory
// and also PropertyAnnotationFactory
pm.addFactory(step2, new MandatoryFromColumnAnnotationFacetFactory(mmc, jdoFacetContext), Marker.JDO);
pm.addFactory(step2, new MandatoryFromJdoColumnAnnotationFacetFactory(mmc, jdoFacetContext), Marker.JDO);


// -- validators
Expand Down

This file was deleted.

Loading