Skip to content

Commit

Permalink
Merge pull request #268 from kbss-cvut/development
Browse files Browse the repository at this point in the history
[2.0.4] Release
  • Loading branch information
ledsoft authored Aug 15, 2024
2 parents b2c6d9e + f65deb2 commit 515e038
Show file tree
Hide file tree
Showing 25 changed files with 210 additions and 33 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# JOPA - Change Log

## 2.0.4 - 2024-08-15
- Fix an issue with cloning instances of `AbstractImmutableMap` (produced by `Map.of`) (Bug #264).
- Ensure changes done by `@PreUpdate` callback inherited by entity are propagated to repository (Bug #265).
- Dependency updates: RDF4J 5.0.2.

## 2.0.3 - 2024-07-22
- Fix an issue with generating static metamodel under JDK 21 (Bug #257).
- Support using URI/URL as data property values (as RDF simple literal) (Enhancement #256).
Expand Down
2 changes: 1 addition & 1 deletion datatype/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<artifactId>jopa-all</artifactId>
<groupId>cz.cvut.kbss.jopa</groupId>
<version>2.0.3</version>
<version>2.0.4</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion jopa-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>cz.cvut.kbss.jopa</groupId>
<artifactId>jopa-all</artifactId>
<version>2.0.3</version>
<version>2.0.4</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion jopa-distribution/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>cz.cvut.kbss.jopa</groupId>
<artifactId>jopa-all</artifactId>
<version>2.0.3</version>
<version>2.0.4</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion jopa-impl/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>cz.cvut.kbss.jopa</groupId>
<artifactId>jopa-all</artifactId>
<version>2.0.3</version>
<version>2.0.4</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class EntityLifecycleListenerManager {

private static final EntityLifecycleListenerManager EMPTY = new EntityLifecycleListenerManager();

private Set<EntityLifecycleListenerManager> parents = new HashSet<>();
private final Set<EntityLifecycleListenerManager> parents = new HashSet<>();

private final Map<LifecycleEvent, Method> lifecycleCallbacks = new EnumMap<>(LifecycleEvent.class);

Expand Down Expand Up @@ -225,11 +225,6 @@ public void invokePostRemoveCallbacks(Object instance) {
invokeCallbacks(instance, LifecycleEvent.POST_REMOVE);
}

void setParents(Set<EntityLifecycleListenerManager> parents) {
assert parents != null;
this.parents = parents;
}

void addParent(EntityLifecycleListenerManager parent) {
assert parent != null;
this.parents.add(parent);
Expand Down Expand Up @@ -264,11 +259,17 @@ Map<LifecycleEvent, Method> getLifecycleCallbacks() {
}

boolean hasEntityLifecycleCallback(LifecycleEvent event) {
return lifecycleCallbacks.containsKey(event);
return lifecycleCallbacks.containsKey(event) || parents.stream()
.anyMatch(parent -> parent.hasEntityLifecycleCallback(event));
}

List<Object> getEntityListeners() {
return entityListeners != null ? Collections.unmodifiableList(entityListeners) : Collections.emptyList();
final List<Object> allListeners = new ArrayList<>(parents.stream().flatMap(parent -> parent.getEntityListeners()
.stream()).toList());
if (entityListeners != null) {
allListeners.addAll(entityListeners);
}
return allListeners;
}

Map<Object, Map<LifecycleEvent, Method>> getEntityListenerCallbacks() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import cz.cvut.kbss.jopa.proxy.change.ChangeTrackingIndirectMap;
import cz.cvut.kbss.jopa.sessions.util.CloneConfiguration;
import cz.cvut.kbss.jopa.sessions.util.CloneRegistrationDescriptor;
import cz.cvut.kbss.jopa.utils.CollectionFactory;
import cz.cvut.kbss.jopa.utils.EntityPropertiesUtils;

import java.lang.reflect.Constructor;
Expand All @@ -37,6 +38,7 @@
class MapInstanceBuilder extends AbstractInstanceBuilder {

private static final Class<?> singletonMapClass = Collections.singletonMap(null, null).getClass();
private static final Class<?> map1Class = Map.of(new Object(), new Object()).getClass();

MapInstanceBuilder(CloneBuilder builder, UnitOfWork uow) {
super(builder, uow);
Expand All @@ -55,12 +57,13 @@ Object buildClone(Object cloneOwner, Field field, Object original, CloneConfigur
Map<?, ?> clone;
clone = cloneUsingDefaultConstructor(cloneOwner, field, origCls, orig, configuration);
if (clone == null) {
if (singletonMapClass.isInstance(orig)) {
if (singletonMapClass.isInstance(orig) || map1Class.isInstance(orig)) {
clone = buildSingletonClone(cloneOwner, field, orig, configuration);
} else if (Collections.emptyMap().equals(orig)) {
clone = orig;
} else {
throw new IllegalArgumentException("Unsupported map type " + origCls);
clone = CollectionFactory.createDefaultMap();
cloneMapContent(cloneOwner, field, orig, clone, configuration);
}
}
clone = new ChangeTrackingIndirectMap<>(cloneOwner, field, uow, clone);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ public void resolveCreatesInstanceOfEntityListenerDeclaredBySpecifiedEntityType(
final AbstractIdentifiableType<OWLClassS> et = typeFor(OWLClassS.class);
final EntityLifecycleListenerManager result = resolve(et);
assertEquals(1, result.getEntityListeners().size());
assertTrue(result.getEntityListeners().get(0) instanceof ParentListener);
assertInstanceOf(ParentListener.class, result.getEntityListeners().get(0));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ void prePersist() {
@PostLoad
void postLoad() {
}

@PreUpdate
void preUpdate() {
}
}

@EntityListeners({ChildListener.class, AnotherChildListener.class})
Expand Down Expand Up @@ -219,7 +223,6 @@ void preUpdate() {
@Test
void hasLifecycleCallbackReturnsTrueWhenEntityHasMatchingLifecycleCallback() throws Exception {
manager.addLifecycleCallback(LifecycleEvent.PRE_PERSIST, Child.class.getDeclaredMethod("prePersistChild"));
final Child instance = spy(new Child());
assertTrue(manager.hasLifecycleCallback(LifecycleEvent.PRE_PERSIST));
}

Expand All @@ -229,7 +232,14 @@ void hasLifecycleCallbackReturnsTrueWhenEntityHasListenerWithMatchingLifecycleCa
manager.addEntityListener(listener);
manager.addEntityListenerCallback(listener, LifecycleEvent.POST_LOAD,
ParentListener.class.getDeclaredMethod("postLoad", Parent.class));
final Parent instance = new Parent();
assertTrue(manager.hasLifecycleCallback(LifecycleEvent.POST_LOAD));
}

@Test
void hasLifecycleCallbackReturnsTrueForInheritedPreUpdateCallback() throws Exception {
final EntityLifecycleListenerManager parentManager = new EntityLifecycleListenerManager();
parentManager.addLifecycleCallback(LifecycleEvent.PRE_UPDATE, Parent.class.getDeclaredMethod("preUpdate"));
manager.addParent(parentManager);
assertTrue(manager.hasLifecycleCallback(LifecycleEvent.PRE_UPDATE));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package cz.cvut.kbss.jopa.sessions;

import cz.cvut.kbss.jopa.environment.OWLClassB;
import cz.cvut.kbss.jopa.model.descriptors.Descriptor;
import cz.cvut.kbss.jopa.model.descriptors.EntityDescriptor;
import cz.cvut.kbss.jopa.sessions.util.CloneConfiguration;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;

import java.util.Collections;
import java.util.Map;

import static org.junit.jupiter.api.Assertions.*;

@ExtendWith(MockitoExtension.class)
class MapInstanceBuilderTest {

@Mock
private AbstractUnitOfWork uow;

private Descriptor descriptor;

private MapInstanceBuilder sut;

@BeforeEach
public void setUp() {
CloneBuilder cloneBuilder = new CloneBuilder(uow);
this.sut = new MapInstanceBuilder(cloneBuilder, uow);
this.descriptor = new EntityDescriptor();
}

@Test
void buildCloneOfSingletonMapReturnsSingletonMap() throws Exception {
Map<String, String> map = Collections.singletonMap("key", "value");
Map<String, String> clone = (Map<String, String>) sut.buildClone(new OWLClassB(), OWLClassB.getPropertiesField(), map, new CloneConfiguration(descriptor, false));
assertEquals(map, clone);
assertNotSame(map, clone);
}

@Test
void buildCloneOfMapOfOneReturnsSingletonMap() throws Exception {
Map<String, String> map = Map.of("key", "value");
Map<String, String> clone = (Map<String, String>) sut.buildClone(new OWLClassB(), OWLClassB.getPropertiesField(), map, new CloneConfiguration(descriptor, false));
assertEquals(map, clone);
assertNotSame(map, clone);
}

@Test
void buildCloneOfEmptyMapReturnsEmptyMap() throws Exception {
Map<String, String> map = Map.of();
Map<String, String> clone = (Map<String, String>) sut.buildClone(new OWLClassB(), OWLClassB.getPropertiesField(), map, new CloneConfiguration(descriptor, false));
assertEquals(map, clone);
assertNotSame(map, clone);
}

@Test
void buildCloneOfMapOfNReturnsDefaultMap() throws Exception {
final Map<String, String> map = Map.of("key1", "value1", "key2", "value2");
final Map<String, String> clone = (Map<String, String>) sut.buildClone(new OWLClassB(), OWLClassB.getPropertiesField(), map, new CloneConfiguration(descriptor, false));
assertEquals(map, clone);
assertNotSame(map, clone);
}
}
2 changes: 1 addition & 1 deletion jopa-integration-tests-jena/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>cz.cvut.kbss.jopa</groupId>
<artifactId>jopa-all</artifactId>
<version>2.0.3</version>
<version>2.0.4</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion jopa-integration-tests-owlapi/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>cz.cvut.kbss.jopa</groupId>
<artifactId>jopa-all</artifactId>
<version>2.0.3</version>
<version>2.0.4</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion jopa-integration-tests-rdf4j/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>cz.cvut.kbss.jopa</groupId>
<artifactId>jopa-all</artifactId>
<version>2.0.3</version>
<version>2.0.4</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>jopa-integration-tests-rdf4j</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion jopa-integration-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>cz.cvut.kbss.jopa</groupId>
<artifactId>jopa-all</artifactId>
<version>2.0.3</version>
<version>2.0.4</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,22 @@

import cz.cvut.kbss.jopa.model.annotations.Id;
import cz.cvut.kbss.jopa.model.annotations.OWLClass;
import cz.cvut.kbss.jopa.model.annotations.OWLDataProperty;
import cz.cvut.kbss.jopa.model.annotations.PreUpdate;
import cz.cvut.kbss.jopa.vocabulary.DC;

import java.net.URI;
import java.time.Instant;

@OWLClass(iri = Vocabulary.C_OWL_CLASS_S_PARENT)
public abstract class OWLClassSParent implements HasUri {

@Id(generated = true)
private URI uri;

@OWLDataProperty(iri = DC.Terms.MODIFIED)
private Instant modified;

@Override
public URI getUri() {
return uri;
Expand All @@ -36,4 +43,17 @@ public URI getUri() {
public void setUri(URI uri) {
this.uri = uri;
}

public Instant getModified() {
return modified;
}

public void setModified(Instant modified) {
this.modified = modified;
}

@PreUpdate
void preUpdate() {
setModified(Instant.now());
}
}
Loading

0 comments on commit 515e038

Please sign in to comment.