Skip to content

Commit

Permalink
Merge pull request #133 from kbss-cvut/development
Browse files Browse the repository at this point in the history
[0.20.1] Release
  • Loading branch information
ledsoft authored Feb 7, 2023
2 parents f9641aa + 339e79d commit 1f5331c
Show file tree
Hide file tree
Showing 33 changed files with 187 additions and 139 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
# JOPA - Release Notes

## 0.20.1 - 2023-02-07
- Allow building a restricted metamodel from a set of entity classes (will be used by static metamodel generator).

## 0.20.0 - 2023-01-26
- Allow editing inferred attributes (see Wiki for details) (Feature #121),
- Allow editing inferred attributes (see Wiki for details) (Feature #121).
- Support for `IN`, `NOT LIKE`, `<>` (`!=`) operators in SOQL (and the corresponding operators in Criteria API). (Enhancement #123, #129).

## 0.19.3 - 2022-12-13
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>0.20.0</version>
<version>0.20.1</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>0.20.0</version>
<version>0.20.1</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,14 @@ public class DefaultPersistenceProviderResolver implements PersistenceProviderRe
private static final Logger LOG = LoggerFactory.getLogger(DefaultPersistenceProviderResolver.class);

/**
* Cached list of available providers cached by CacheKey to ensure
* there is not potential for provider visibility issues.
* Queue for reference objects referring to class loaders or persistence providers.
*/
private final HashMap<CacheKey, PersistenceProviderReference> providers = new HashMap<>();
private static final ReferenceQueue<?> referenceQueue = new ReferenceQueue<>();

/**
* Queue for reference objects referring to class loaders or persistence providers.
* Available providers cached by CacheKey to ensure there is no potential for provider visibility issues.
*/
private static final ReferenceQueue<?> referenceQueue = new ReferenceQueue<>();
private final HashMap<CacheKey, PersistenceProviderReference> providers = new HashMap<>();

public List<PersistenceProvider> getPersistenceProviders() {
// Before we do the real loading work, see whether we need to
Expand All @@ -69,11 +68,11 @@ public List<PersistenceProvider> getPersistenceProviders() {
PersistenceProvider pp = ipp.next();
loadedProviders.add(pp);
} catch (ServiceConfigurationError sce) {
LOG.trace("Unable to load PersistenceProvider implementation via service loader.", sce);
LOG.warn("Unable to load PersistenceProvider implementation via service loader.", sce);
}
}
} catch (ServiceConfigurationError sce) {
LOG.trace("Unable to load PersistenceProvider implementation via service loader.", sce);
LOG.warn("Unable to load PersistenceProvider implementation via service loader.", sce);
}

if (loadedProviders.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
/**
* Interface implemented by the persistence provider.
* <p>
* It is invoked by the container in Java EE environments and by the Persistence class in Java SE environments to create
* an EntityManagerFactory and/or to cause schema generation to occur.
* It is invoked by the Persistence class in Java SE environments to create an EntityManagerFactory and/or to cause
* schema generation to occur.
*/
public interface PersistenceProvider {

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>0.20.0</version>
<version>0.20.1</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>0.20.0</version>
<version>0.20.1</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public void afterSetter(JoinPoint thisJoinPoint) {
}
}

private FieldSpecification<?, ?> getFieldSpecification(Object entity, String fieldName,
private static FieldSpecification<?, ?> getFieldSpecification(Object entity, String fieldName,
UnitOfWorkImpl persistenceContext) {
final EntityType<?> et = persistenceContext.getMetamodel().entity(entity.getClass());
assert et != null;
Expand Down
32 changes: 27 additions & 5 deletions jopa-impl/src/main/java/cz/cvut/kbss/jopa/model/MetamodelImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ public MetamodelImpl(Configuration configuration) {
}

/**
* Builds the metamodel for entities discovered by the specified entity loader.
* Builds the metamodel for classes (entity classes, attribute converters etc.) discovered by the specified {@link
* PersistenceUnitClassFinder}.
*
* @param classFinder Finder of PU classes
*/
Expand Down Expand Up @@ -92,20 +93,41 @@ private static void checkForWeaver() {
}
}

/**
* Builds a reduced metamodel for the specified set of entity classes.
* <p>
* The result of calling this method is not equivalent to {@link #build(PersistenceUnitClassFinder)} as it does not
* process result set mappings, attribute converters, named queries etc. It only builds metamodel for the specified
* entity classes.
* <p>
* Also, no additional processing (like initializing static metamodel) is done.
*
* @param entityClasses Entity classes to initialize the metamodel with
*/
public void build(Set<Class<?>> entityClasses) {
Objects.requireNonNull(entityClasses);
LOG.debug("Building reduced metamodel from entity classes {}...", entityClasses);
final MetamodelBuilder metamodelBuilder = new MetamodelBuilder(configuration);
metamodelBuilder.buildMetamodel(entityClasses);

this.typeMap = metamodelBuilder.getTypeMap();
this.entities = metamodelBuilder.getEntities();
this.inferredClasses = metamodelBuilder.getInferredClasses();
this.typeReferenceMap = metamodelBuilder.getTypeReferenceMap();
}

@Override
public <X> EntityTypeImpl<X> entity(Class<X> cls) {
if (!isEntityType(cls)) {
throw new IllegalArgumentException(
"Class " + cls.getName() + " is not a known entity in this persistence unit.");
throw new IllegalArgumentException(cls.getName() + " is not a known entity in this persistence unit.");
}
return (EntityTypeImpl<X>) entities.get(cls);
}

@Override
public Set<EntityType<?>> getMappedEntities(String classIri) {
Objects.requireNonNull(classIri);
return entities.values().stream()
.filter(et -> Objects.equals(et.getIRI().toString(), classIri))
return entities.values().stream().filter(et -> Objects.equals(et.getIRI().toString(), classIri))
.collect(Collectors.toSet());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ public class QueryHintsHandler {

private static final Logger LOG = LoggerFactory.getLogger(QueryHintsHandler.class);

private QueryHintsHandler() {
throw new AssertionError();
}

/**
* Gets query hints supported by this implementation.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ private void resolveEntityListeners() {
resolveEntityListenerCallbacks(listener, listenerType);
} catch (cz.cvut.kbss.jopa.exception.InstantiationException e) {
throw new MetamodelInitializationException("Unable to instantiate entity listener of type "
+ listenerType + ". The listener has to have a public no-arg constructor.");
+ listenerType + ". The listener has to have a public no-arg constructor.", e);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,24 @@ public MetamodelBuilder(Configuration configuration) {
* @param classFinder Holder of information about classes relevant for persistence unit building
*/
public void buildMetamodel(PersistenceUnitClassFinder classFinder) {
assert classFinder != null;
classFinder.getAttributeConverters().forEach(converterResolver::registerConverter);
classFinder.getEntities().forEach(this::processOWLClass);
classFinder.getResultSetMappings().forEach(mappingProcessor::buildMapper);
}

/**
* Builds persistence unit metamodel based on the specified entity classes.
* <p>
* No additional metamodel features (e.g., custom attribute converters, query result mappers) are built.
*
* @param entityClasses Entity classes to build metamodel for
*/
public void buildMetamodel(Set<Class<?>> entityClasses) {
assert entityClasses != null;
entityClasses.forEach(this::processOWLClass);
}

private <X> void processOWLClass(final Class<X> cls) {
if (typeMap.containsKey(cls)) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import cz.cvut.kbss.jopa.oom.exceptions.EntityDeconstructionException;
import cz.cvut.kbss.ontodriver.model.NamedResource;

import java.lang.reflect.Field;
import java.net.URI;

class EntityDeconstructor {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,13 @@ public ObjectOntologyMapperImpl(UnitOfWorkImpl uow, Connection connection) {
this.entityBreaker = new EntityDeconstructor(this);

this.defaultInstanceLoader = DefaultInstanceLoader.builder().connection(storageConnection)
.metamodel(uow.getMetamodel())
.descriptorFactory(descriptorFactory)
.entityBuilder(entityBuilder).cache(cache).build();
.metamodel(uow.getMetamodel())
.descriptorFactory(descriptorFactory)
.entityBuilder(entityBuilder).cache(cache).build();
this.twoStepInstanceLoader = TwoStepInstanceLoader.builder().connection(storageConnection)
.metamodel(uow.getMetamodel())
.descriptorFactory(descriptorFactory)
.entityBuilder(entityBuilder).cache(cache).build();
.metamodel(uow.getMetamodel())
.descriptorFactory(descriptorFactory)
.entityBuilder(entityBuilder).cache(cache).build();
}

@Override
Expand All @@ -83,7 +83,7 @@ public <T> boolean containsEntity(Class<T> cls, URI identifier, Descriptor descr
final EntityType<T> et = getEntityType(cls);
final NamedResource classUri = NamedResource.create(et.getIRI().toURI());
final Axiom<NamedResource> ax = new AxiomImpl<>(NamedResource.create(identifier),
Assertion.createClassAssertion(false), new Value<>(classUri));
Assertion.createClassAssertion(false), new Value<>(classUri));
try {
return storageConnection.contains(ax, descriptor.getContexts());
} catch (OntoDriverException e) {
Expand Down Expand Up @@ -280,19 +280,20 @@ public <T> void removeEntity(URI identifier, Class<T> cls, Descriptor descriptor
}

@Override
public <T> void updateFieldValue(T entity, FieldSpecification<? super T, ?> fieldSpec, Descriptor entityDescriptor) {
public <T> void updateFieldValue(T entity, FieldSpecification<? super T, ?> fieldSpec,
Descriptor entityDescriptor) {
@SuppressWarnings("unchecked") final EntityType<T> et = (EntityType<T>) getEntityType(entity.getClass());
final URI pkUri = EntityPropertiesUtils.getIdentifier(entity, et);

entityBreaker.setReferenceSavingResolver(new ReferenceSavingResolver(this));
// It is OK to do it like this, because if necessary, the mapping will re-register a pending assertion
removePendingAssertions(et, fieldSpec, pkUri);
final AxiomValueGatherer axiomBuilder = entityBreaker
.mapFieldToAxioms(pkUri, entity, fieldSpec, et, entityDescriptor);
removePendingAssertions(fieldSpec, pkUri);
final AxiomValueGatherer axiomBuilder =
entityBreaker.mapFieldToAxioms(pkUri, entity, fieldSpec, et, entityDescriptor);
axiomBuilder.update(storageConnection);
}

private <T> void removePendingAssertions(EntityType<T> et, FieldSpecification<? super T, ?> fs, URI identifier) {
private <T> void removePendingAssertions(FieldSpecification<? super T, ?> fs, URI identifier) {
if (fs instanceof Attribute) {
final Attribute<?, ?> att = (Attribute<?, ?>) fs;
// We care only about object property assertions, others are never pending
Expand Down Expand Up @@ -325,7 +326,8 @@ public Configuration getConfiguration() {
}

@Override
public <T> Set<Axiom<?>> getAttributeAxioms(T entity, FieldSpecification<? super T, ?> fieldSpec, Descriptor entityDescriptor) {
public <T> Set<Axiom<?>> getAttributeAxioms(T entity, FieldSpecification<? super T, ?> fieldSpec,
Descriptor entityDescriptor) {
final EntityType<T> et = (EntityType<T>) getEntityType(entity.getClass());
return FieldStrategy.createFieldStrategy(et, fieldSpec, entityDescriptor, this).buildAxiomsFromInstance(entity);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public void addValueFromTypedQuery(TypedQuery<?> typedQuery) {
LOG.trace("Query \"{}\" for attribute {} did not return any result.", attribute.getQuery(), attribute);
return;
} catch (NoUniqueResultException e2) {
LOG.trace("Query \"{}\" for attribute {} does not have a unique result.", attribute.getQuery(), attribute);
LOG.warn("Query \"{}\" for attribute {} does not have a unique result.", attribute.getQuery(), attribute);
return;
}

Expand Down
Loading

0 comments on commit 1f5331c

Please sign in to comment.