Skip to content

Commit

Permalink
[#667] Add DeltaSpike 1.9 support, fix JDK10+ builds and add validati…
Browse files Browse the repository at this point in the history
…on for JPA managed types
  • Loading branch information
beikov committed Sep 30, 2018
1 parent d8c0d29 commit e4b3674
Show file tree
Hide file tree
Showing 25 changed files with 541 additions and 79 deletions.
11 changes: 4 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -450,15 +450,15 @@ matrix:
before_install:
- wget https://raw.githubusercontent.com/sormuras/bach/master/install-jdk.sh
- . ./install-jdk.sh -F 12 -L GPL
- env: JPAPROVIDER=hibernate-5.2 RDBMS=h2 JDK=10 BUILD_JDK=10
- env: JPAPROVIDER=hibernate-5.2 RDBMS=h2 JDK=10 BUILD_JDK=10 DELTASPIKE=deltaspike-1.9
before_install:
- wget https://raw.githubusercontent.com/sormuras/bach/master/install-jdk.sh
- . ./install-jdk.sh -F 10 -L GPL
- env: JPAPROVIDER=hibernate-5.2 RDBMS=h2 JDK=11 BUILD_JDK=11
- env: JPAPROVIDER=hibernate-5.2 RDBMS=h2 JDK=11 BUILD_JDK=11 DELTASPIKE=deltaspike-1.9
before_install:
- wget https://raw.githubusercontent.com/sormuras/bach/master/install-jdk.sh
- . ./install-jdk.sh -F 11 -L BCL
- env: JPAPROVIDER=hibernate-5.2 RDBMS=h2 JDK=12 BUILD_JDK=12
- env: JPAPROVIDER=hibernate-5.2 RDBMS=h2 JDK=12 BUILD_JDK=12 DELTASPIKE=deltaspike-1.9
before_install:
- wget https://raw.githubusercontent.com/sormuras/bach/master/install-jdk.sh
- . ./install-jdk.sh -F 12 -L GPL
Expand Down Expand Up @@ -506,10 +506,7 @@ matrix:
# - wget https://raw.githubusercontent.com/sormuras/bach/master/install-jdk.sh
# - . ./install-jdk.sh -F 9 -L GPL
allow_failures:
- env: JPAPROVIDER=hibernate-5.2 RDBMS=h2 JDK=10 BUILD_JDK=10
- env: JPAPROVIDER=hibernate-5.2 RDBMS=h2 JDK=11 BUILD_JDK=11
- env: JPAPROVIDER=hibernate-5.2 RDBMS=h2 JDK=11
- env: JPAPROVIDER=hibernate-5.2 RDBMS=h2 JDK=12 BUILD_JDK=12
- env: JPAPROVIDER=hibernate-5.2 RDBMS=h2 JDK=12 BUILD_JDK=12 DELTASPIKE=deltaspike-1.9
- env: JPAPROVIDER=hibernate-5.2 RDBMS=h2 JDK=12
# - env: JPAPROVIDER=datanucleus-5.1 RDBMS=h2 JDK=9
# before_install:
Expand Down
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,19 @@ Not yet released
* Support for binding associations mapped by compound or foreign keys
* Using a comparator with `List` and `Collection` types in entity views will sort the collection after load
* Add option to force deduplication of elements in non-sets to `@CollectionMapping`
* Properly implement dirty state transfer when converting one entity view to another
* Added validation for `equals`/`hashCode` implementations of JPA managed types that are used within entity views which can be disabled with the property `com.blazebit.persistence.view.managed_type_validation_disabled`
* Add support for DeltaSpike Data 1.9

### Bug fixes

* Using non-bags in entity views will now properly deduplicate elements
* Fix support for exists repository methods in Spring Data repositories
* Fix problems with count queries that require parameters in Spring Data repositories
* Properly set parent id on converted creatable subviews contained in inverse collections
* Properly set parent id on converted creatable subviews contained in inverse collections
* Fix entity view build time validation error with certain inheritance mappings
* Fix problems with objects of wrong types being returned from standard repository methods with Spring Data 2.0+
* Fix various little issues related to embeddable handling in updatable entity views

### Backwards-incompatible changes

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ Blaze-Persistence DeltaSpike Data integration
</dependency>
```

Blaze-Persistence DeltaSpike Data 1.8 integration
Blaze-Persistence DeltaSpike Data 1.9 and 1.8 integration

```xml
<dependency>
Expand Down
2 changes: 1 addition & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ if [ "$TRAVIS_REPO_SLUG" == "Blazebit/blaze-persistence" ] &&
[ "$TRAVIS_BRANCH" == "master" ] &&
[ "$JPAPROVIDER" == "hibernate-5.2" ] &&
[ "$RDBMS" == "h2" ]; then
exec mvn -P ${JPAPROVIDER},${RDBMS},${SPRING_DATA:-spring-data-1.11.x},${DELTASPIKE:-deltaspike-1.7} clean install -V $PROPERTIES
exec mvn -B -P ${JPAPROVIDER},${RDBMS},${SPRING_DATA:-spring-data-1.11.x},${DELTASPIKE:-deltaspike-1.7} clean install -V $PROPERTIES
else
if [ "$TRAVIS_REPO_SLUG" == "Blazebit/blaze-persistence" ] &&
[ "$TRAVIS_BRANCH" == "master" ] &&
Expand Down
33 changes: 9 additions & 24 deletions core/impl/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,31 +65,16 @@
</dependencies>

<build>
<resources>
<resource>
<filtering>true</filtering>
<includes>
<include>META-INF/blaze-persistence.properties</include>
</includes>
<directory>src/main/resources</directory>
</resource>
</resources>
<plugins>
<plugin>
<groupId>de.m3y.maven</groupId>
<artifactId>inject-maven-plugin</artifactId>
<executions>
<execution>
<phase>process-classes</phase>
<goals>
<goal>inject</goal>
</goals>
</execution>
</executions>
<configuration>
<injections>
<injection>
<value>${project.version}</value>
<pointCut>com.blazebit.persistence.impl.Version$Injected.getVersion</pointCut>
</injection>
<injection>
<value>${blaze-persistence.codename}</value>
<pointCut>com.blazebit.persistence.impl.Version$Injected.getCodename</pointCut>
</injection>
</injections>
</configuration>
</plugin>
<plugin>
<groupId>org.moditect</groupId>
<artifactId>moditect-maven-plugin</artifactId>
Expand Down
44 changes: 25 additions & 19 deletions core/impl/src/main/java/com/blazebit/persistence/impl/Version.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,39 +16,45 @@

package com.blazebit.persistence.impl;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

/**
* @author Christian Beikov
* @since 1.0.0
*/
public class Version {

public static final String PROJECT_NAME = "Blaze-Persistence";
private static final String VERSION;
private static final String CODENAME;

static {
Properties properties = new Properties();
InputStream propertiesStream = Version.class.getClassLoader().getResourceAsStream("META-INF/blaze-persistence.properties");
if (propertiesStream == null) {
VERSION = "0.0.0-SNAPSHOT";
CODENAME = "";
} else {
try {
properties.load(propertiesStream);
VERSION = properties.getProperty("version");
CODENAME = properties.getProperty("codename");
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}

private Version() {
}

public static String getVersion() {
return Injected.getVersion();
return VERSION;
}

public static String printVersion() {
return PROJECT_NAME + " '" + Injected.getCodename() + "' " + Injected.getVersion();
}

/**
* @author Christian Beikov
* @since 1.0.0
*/
static class Injected {

static String getVersion() {
// Will be replaced by the Maven Injection plugin
return "0.0.0-SNAPSHOT";
}

static String getCodename() {
// Will be replaced by the Maven Injection plugin
return "";
}
return PROJECT_NAME + " '" + CODENAME + "' " + VERSION;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
version = ${project.version}
codename = ${blaze-persistence.codename}
Original file line number Diff line number Diff line change
Expand Up @@ -162,4 +162,22 @@ public void setParent(PrimitiveDocument parent) {
this.parent = parent;
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (!(o instanceof PrimitiveDocument)) {
return false;
}

PrimitiveDocument that = (PrimitiveDocument) o;

return getId() == that.getId();
}

@Override
public int hashCode() {
return (int) (getId() ^ (getId() >>> 32));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,5 +87,23 @@ public Set<PrimitiveDocument> getOwnedDocuments() {
public void setOwnedDocuments(Set<PrimitiveDocument> ownedDocuments) {
this.ownedDocuments = ownedDocuments;
}


@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (!(o instanceof PrimitivePerson)) {
return false;
}

PrimitivePerson that = (PrimitivePerson) o;

return getId() == that.getId();
}

@Override
public int hashCode() {
return (int) (getId() ^ (getId() >>> 32));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ In addition, the following Maven dependencies are required:
</dependency>
----

If you still work with DeltaSpike Data 1.7 you will have to use a different integration as DeltaSpike Data 1.8 changed quite a bit.
This will also work for DeltaSpike Data 1.9.

If you still work with DeltaSpike Data 1.7 you will have to use a different integration as DeltaSpike Data 1.9 and 1.8 changed quite a bit.

[source,xml]
----
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,4 +188,23 @@ public interface EntityViewConfiguration {
*/
public EntityViewConfiguration setProperty(String propertyName, String value);

/**
* Returns all type test values that should be used for checking the equals/hashCode implementation of JPA types.
*
* @return All type test values
* @since 1.3.0
*/
public Map<Class<?>, Object> getTypeTestValues();

/**
* Sets the given value as type test value for the given type.
*
* @param type The type for which to register the value
* @param value The value which is used for testing
* @param <T> The type
* @return this for method chaining
* @since 1.3.0
*/
public <T> EntityViewConfiguration setTypeTestValue(Class<T> type, T value);

}
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,14 @@ public final class ConfigurationProperties {
* @since 1.1.0
*/
public static final String EXPRESSION_VALIDATION_DISABLED = "com.blazebit.persistence.view.expression_validation_disabled";
/**
* A boolean flag to make it possible to disable the managed type validation.
* By default the managed type validation is enabled, but since the validation is not bullet proof, it can be disabled.
* Valid values for this property are <code>true</code> or <code>false</code>.
*
* @since 1.3.0
*/
public static final String MANAGED_TYPE_VALIDATION_DISABLED = "com.blazebit.persistence.view.managed_type_validation_disabled";
/**
* An integer value that defines the default batch size for entity view attributes.
* By default the value is 1 and can be overridden either via {@linkplain com.blazebit.persistence.view.BatchFetch#size()}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,17 @@
import com.blazebit.persistence.view.spi.type.TypeConverter;

import javax.persistence.EntityManagerFactory;
import java.io.Serializable;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.sql.Time;
import java.sql.Timestamp;
import java.util.Calendar;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
Expand All @@ -45,6 +54,7 @@ public class EntityViewConfigurationImpl implements EntityViewConfiguration {
private final MutableBasicUserTypeRegistry userTypeRegistry = new MutableBasicUserTypeRegistry();
private final MetamodelBootContext bootContext = new MetamodelBootContextImpl();
private final ViewMappingReader annotationViewMappingReader = new AnnotationViewMappingReader(bootContext);
private final Map<Class<?>, Object> typeTestValues = new HashMap<>();
private Properties properties = new Properties();

public EntityViewConfigurationImpl() {
Expand All @@ -54,6 +64,38 @@ public EntityViewConfigurationImpl() {
private void loadDefaultProperties() {
properties.put(ConfigurationProperties.PROXY_EAGER_LOADING, "false");
properties.put(ConfigurationProperties.PROXY_UNSAFE_ALLOWED, "true");
properties.put(ConfigurationProperties.MANAGED_TYPE_VALIDATION_DISABLED, "false");

typeTestValues.put(boolean.class, true);
typeTestValues.put(byte.class, Byte.MAX_VALUE);
typeTestValues.put(short.class, Short.MAX_VALUE);
typeTestValues.put(char.class, Character.MAX_VALUE);
typeTestValues.put(int.class, Integer.MAX_VALUE);
typeTestValues.put(long.class, Long.MAX_VALUE);
typeTestValues.put(float.class, Float.MAX_VALUE);
typeTestValues.put(double.class, Double.MAX_VALUE);
typeTestValues.put(Boolean.class, true);
typeTestValues.put(Byte.class, Byte.MAX_VALUE);
typeTestValues.put(Short.class, Short.MAX_VALUE);
typeTestValues.put(Character.class, Character.MAX_VALUE);
typeTestValues.put(Integer.class, Integer.MAX_VALUE);
typeTestValues.put(Long.class, Long.MAX_VALUE);
typeTestValues.put(Float.class, Float.MAX_VALUE);
typeTestValues.put(Double.class, Double.MAX_VALUE);
typeTestValues.put(String.class, "-");
typeTestValues.put(Date.class, new Date(1));
typeTestValues.put(java.sql.Date.class, new java.sql.Date(1));
typeTestValues.put(Time.class, new Time(1000));
typeTestValues.put(Timestamp.class, new Timestamp(1));
typeTestValues.put(Calendar.class, Calendar.getInstance());
typeTestValues.put(GregorianCalendar.class, new GregorianCalendar());
typeTestValues.put(byte[].class, new byte[]{ Byte.MAX_VALUE });
typeTestValues.put(Byte[].class, new Byte[] { Byte.MAX_VALUE });
typeTestValues.put(char[].class, new char[] { Character.MAX_VALUE });
typeTestValues.put(Character[].class, new Character[] { Character.MAX_VALUE });
typeTestValues.put(BigInteger.class, BigInteger.TEN);
typeTestValues.put(BigDecimal.class, BigDecimal.TEN);
typeTestValues.put(Serializable.class, "-");
}

@Override
Expand Down Expand Up @@ -160,4 +202,15 @@ public EntityViewConfiguration setProperty(String propertyName, String value) {
properties.setProperty(propertyName, value);
return this;
}

@Override
public Map<Class<?>, Object> getTypeTestValues() {
return typeTestValues;
}

@Override
public <T> EntityViewConfiguration setTypeTestValue(Class<T> type, T value) {
typeTestValues.put(type, value);
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ public EntityViewManagerImpl(EntityViewConfigurationImpl config, CriteriaBuilder
this.unsafeDisabled = !Boolean.valueOf(String.valueOf(config.getProperty(ConfigurationProperties.PROXY_UNSAFE_ALLOWED)));
this.proxyFactory = new ProxyFactory(unsafeDisabled, packageOpener);

boolean validateManagedTypes = !Boolean.valueOf(String.valueOf(config.getProperty(ConfigurationProperties.MANAGED_TYPE_VALIDATION_DISABLED)));
boolean validateExpressions = !Boolean.valueOf(String.valueOf(config.getProperty(ConfigurationProperties.EXPRESSION_VALIDATION_DISABLED)));

Set<String> errors = config.getBootContext().getErrors();
Expand All @@ -154,9 +155,10 @@ public EntityViewManagerImpl(EntityViewConfigurationImpl config, CriteriaBuilder

ViewMetamodelImpl viewMetamodel = null;
RuntimeException exception = null;
Map<Class<?>, Object> typeTestValues = config.getTypeTestValues();

try {
viewMetamodel = new ViewMetamodelImpl(entityMetamodel, context, validateExpressions);
viewMetamodel = new ViewMetamodelImpl(entityMetamodel, context, typeTestValues, validateManagedTypes, validateExpressions);
} catch (RuntimeException ex) {
exception = ex;
}
Expand Down
Loading

0 comments on commit e4b3674

Please sign in to comment.