Skip to content

Commit

Permalink
Merge pull request #273 from kbss-cvut/development
Browse files Browse the repository at this point in the history
[2.1.0] Release
  • Loading branch information
ledsoft authored Oct 16, 2024
2 parents 4c400cd + ba940a3 commit 72c16eb
Show file tree
Hide file tree
Showing 112 changed files with 3,951 additions and 334 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# JOPA - Change Log

## 2.1.0 - 2024-10-16
- Add support for RDF containers (Task #52).
[Wiki](https://github.com/kbss-cvut/jopa/wiki/Object-ontological-Mapping#collection-mapping) contains info on collection mapping in general.
- Add support for Jena TDB2 storage.
- Dependency updates: Jena 5.2.0, OWL API 5.5.1, SLF4J 2.0.16.

## 2.0.5 - 2024-09-03
- Modify target ontology selection in queries (use only query hints) to prevent RDF4J driver from spanning application log.

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.5</version>
<version>2.1.0</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.5</version>
<version>2.1.0</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
import java.lang.ref.ReferenceQueue;
import java.lang.ref.SoftReference;
import java.lang.ref.WeakReference;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
Expand Down Expand Up @@ -61,7 +59,7 @@ public List<PersistenceProvider> getPersistenceProviders() {
// information from the cache.
processQueue();

final ClassLoader loader = getContextClassLoader();
final ClassLoader loader = Thread.currentThread().getContextClassLoader();
final CacheKey cacheKey = new CacheKey(loader);
PersistenceProviderReference providersReferent = providers.get(cacheKey);

Expand Down Expand Up @@ -107,18 +105,6 @@ private void processQueue() {
}
}

/**
* Wraps <code>Thread.currentThread().getContextClassLoader()</code> into a doPrivileged block if security manager is present
*/
private static ClassLoader getContextClassLoader() {
if (System.getSecurityManager() == null) {
return Thread.currentThread().getContextClassLoader();
} else {
return AccessController.doPrivileged((PrivilegedAction<ClassLoader>) () -> Thread.currentThread()
.getContextClassLoader());
}
}

/**
* Clear all cached providers
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,6 @@ public interface PersistenceProvider {
*/
EntityManagerFactory createEntityManagerFactory(String emName, Map<String, String> map);

// TODO JPA 2.0
// public EntityManagerFactory
// createContainerEntityManagerFactory(PersistenceUnitInfo info, Map map);

/**
* Return the utility interface implemented by the persistence provider.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package cz.cvut.kbss.jopa.model.annotations;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
* Specifies mapping of an <a href="https://www.w3.org/TR/rdf12-schema/#ch_containervocab">RDF container</a>.
* <p>
* RDF containers are resources used to represent collections. In contrast to RDF collections, they are not closed, so
* it is possible to add new items to them without having to reattach the container ending element.
* <p>
* Three types of RDF containers are defined, each with different convention-based semantics.
*
* @see RDFContainerType
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.FIELD, ElementType.METHOD})
public @interface RDFContainer {

/**
* The type of the container.
*
* @return Type of the container
*/
RDFContainerType type();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package cz.cvut.kbss.jopa.model.annotations;

/**
* Types of RDF containers, as defined by <a href="https://www.w3.org/TR/rdf12-schema/#ch_containervocab">Section
* 5.1</a> of the RDF Schema vocabulary.
*/
public enum RDFContainerType {

/**
* The {@literal rdf:Alt} class is the class of RDF 'Alternative' containers.
* <p>
* While not formalized, it is conventionally used to indicate that the container is a list of alternatives and only
* one of the will be used.
*/
ALT,
/**
* The {@literal rdf:Bag} class is the class of RDF 'Bag' containers.
* <p>
* While not formalized, it is conventionally used to indicate that the container is unordered.
*/
BAG,
/**
* The {@literal rdf:Seq} class is the class of RDF 'Sequence' containers.
* <p>
* While not formalized, it is conventionally used to indicate that the numerical ordering of the container
* membership properties is intended to be significant.
*/
SEQ
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,13 @@ public static CollectionType fromClass(Class<?> cls) {
}
throw new IllegalArgumentException("Unsupported collection type " + cls);
}

/**
* Gets the Java class that represents this collection type.
*
* @return the Java class
*/
public Class<?> getCollectionClass() {
return collectionClass;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,5 +73,5 @@ public interface ListAttribute<X, E> extends PluralAttribute<X, java.util.List<E
* @see cz.cvut.kbss.jopa.model.annotations.RDFCollection
*/
@NonJPA
boolean isRDFCollection();
default boolean isRDFCollection() { return false; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,11 @@
package cz.cvut.kbss.jopa.model.metamodel;

/**
* Instances of the type PluralAttribute represent persistent collection-valued
* attributes.
* Instances of the type PluralAttribute represent persistent collection-valued attributes.
*
* @param <X>
* The type the represented collection belongs to
* @param <C>
* The type of the represented collection
* @param <E>
* The element type of the represented collection
* @param <X> The type the represented collection belongs to
* @param <C> The type of the represented collection
* @param <E> The element type of the represented collection
*/
public interface PluralAttribute<X, C, E> extends Attribute<X, C>, Bindable<E> {

Expand All @@ -43,4 +39,12 @@ public interface PluralAttribute<X, C, E> extends Attribute<X, C>, Bindable<E> {
* @return element type
*/
Type<E> getElementType();

/**
* Checks whether this attribute represents an <a href="https://www.w3.org/TR/rdf-schema/#ch_containervocab">RDF
* container</a>.
*
* @return {@code true} if this plural attribute is an RDF container, {@code false} otherwise
*/
default boolean isRdfContainer() {return false;}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package cz.cvut.kbss.jopa.model.metamodel;

import cz.cvut.kbss.jopa.NonJPA;
import cz.cvut.kbss.jopa.model.annotations.RDFContainerType;

/**
* Instances of the type {@code RDFContainerAttribute} represent attributes mapped to RDF containers.
* <p>
* RDF containers may be represented by different collections, depending on the type of the container. While a
* {@literal rdf:Seq} is likely to be represented by a {@link java.util.List}, as it allows duplicates but is ordered, a
* {@literal rdf:Alt} represents a set of alternatives and will thus probably be represented by a {@link java.util.Set},
* possibly an implementation preserving order. A {@literal rdf:Bag} allows duplicates and is unordered, but will likely
* be represented also by a {@link java.util.List}.
*
* @param <X> The type the represented collection belongs to
* @param <C> Type of the collection
* @param <E> The element type of the represented collection
*/
@NonJPA
public interface RDFContainerAttribute<X, C, E> extends PluralAttribute<X, C, E> {

/**
* Type of the RDF container represented by this attribute.
*
* @return RDF container type
*/
@NonJPA
RDFContainerType getContainerType();

@Override
default boolean isRdfContainer() {
return true;
}
}
17 changes: 16 additions & 1 deletion jopa-api/src/main/java/cz/cvut/kbss/jopa/vocabulary/RDF.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,25 @@ public final class RDF {
public static final String REST = NAMESPACE + "rest";

/**
* The {@code rdf:nil} object representing an empty RDF list (used to mark the end of a RDF list).
* The {@code rdf:nil} object representing an empty RDF list (used to mark the end of an RDF list).
*/
public static final String NIL = NAMESPACE + "nil";

/**
* The {@code rdf:Bag} class is the class of RDF 'Bag' containers.
*/
public static final String BAG = NAMESPACE + "Bag";

/**
* The {@code rdf:Seq} class is the class of RDF 'Sequence' containers.
*/
public static final String SEQ = NAMESPACE + "Seq";

/**
* The {@code rdf:Alt} class is the class of RDF 'Alternative' containers.
*/
public static final String ALT = NAMESPACE + "Alt";

private RDF() {
throw new AssertionError();
}
Expand Down
20 changes: 18 additions & 2 deletions jopa-api/src/main/java/cz/cvut/kbss/jopa/vocabulary/RDFS.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public final class RDFS {
public static final String RESOURCE = NAMESPACE + "Resource";

/**
* The class {@code rdfs:Literal} represents the self-denoting nodes called the 'literals' in the RDF graph
* The {@code rdfs:Literal} class represents the self-denoting nodes called the 'literals' in the RDF graph
* structure.
* <p>
* Property values such as textual strings are examples of RDF literals.
Expand All @@ -78,11 +78,27 @@ public final class RDFS {
public static final String SUB_CLASS_OF = NAMESPACE + "subClassOf";

/**
* The property {@code rdfs:subPropertyOf} is an instance of {@code rdf:Property} that is used to specify that one
* The {@code rdfs:subPropertyOf} property is an instance of {@code rdf:Property} that is used to specify that one
* property is a specialization of another.
*/
public static final String SUB_PROPERTY_OF = NAMESPACE + "subPropertyOf";

/**
* The {@code rdfs:Container} class represents a collection.
*/
public static final String CONTAINER = NAMESPACE + "Container";

/**
* The {@code rdfs:member} property is an instance of {@code rdf:Property} that is a super-property of all container
* membership properties.
*/
public static final String MEMBER = NAMESPACE + "member";

/**
* The {@code rdfs:ContainerMembershipProperty} class has as instances the properties {@code rdf:_1}, {@code rdf:_2}, etc.
*/
public static final String CONTAINER_MEMBERSHIP_PROPERTY = NAMESPACE + "ContainerMembershipProperty";

private RDFS() {
throw new AssertionError();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,25 @@

import cz.cvut.kbss.jopa.model.metamodel.FieldSpecification;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.mockito.junit.jupiter.MockitoExtension;

import java.net.URI;
import java.util.stream.Stream;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

@ExtendWith(MockitoExtension.class)
class FieldDescriptorTest {

private static final URI CONTEXT_ONE = URI.create("http://krizik.felk.cvut.cz/ontologies/jopa/contextOne");
Expand All @@ -49,7 +55,6 @@ static Stream<Arguments> dataGenerator() {

@BeforeEach
void setUp() throws Exception {
MockitoAnnotations.openMocks(this);
when(stringAtt.getJavaField()).thenReturn(TestClass.stringAttField());
}

Expand All @@ -66,4 +71,17 @@ void testEquality(URI contextOne, URI contextTwo, String langOne, String langTwo
assertNotEquals(dOne, dTwo);
}
}

@Test
void getAttributeDescriptorReturnsThisInstanceWhenAttributeMatches() {
final Descriptor d = new FieldDescriptor(stringAtt);
assertSame(d, d.getAttributeDescriptor(stringAtt));
}

@Test
void getAttributeDescriptorThrowsIllegalArgumentWhenRequestedAttributeIsNotRepresentedByThisDescriptor() {
final Descriptor d = new FieldDescriptor(stringAtt);
final FieldSpecification<TestClass, Integer> intAtt = mock(FieldSpecification.class);
assertThrows(IllegalArgumentException.class, () -> d.getAttributeDescriptor(intAtt));
}
}
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.5</version>
<version>2.1.0</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.5</version>
<version>2.1.0</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
Loading

0 comments on commit 72c16eb

Please sign in to comment.