-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Plural datatype property support - OOM implementation.
- Loading branch information
Showing
17 changed files
with
468 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
jopa-impl/src/main/java/cz/cvut/kbss/jopa/oom/DataPropertyFieldStrategy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package cz.cvut.kbss.jopa.oom; | ||
|
||
import cz.cvut.kbss.jopa.model.descriptors.Descriptor; | ||
import cz.cvut.kbss.jopa.model.metamodel.Attribute; | ||
import cz.cvut.kbss.jopa.model.metamodel.EntityType; | ||
import cz.cvut.kbss.ontodriver.model.Assertion; | ||
|
||
abstract class DataPropertyFieldStrategy<X> extends FieldStrategy<Attribute<? super X, ?>, X> { | ||
|
||
DataPropertyFieldStrategy(EntityType<X> et, Attribute<? super X, ?> att, Descriptor attributeDescriptor, | ||
EntityMappingHelper mapper) { | ||
super(et, att, attributeDescriptor, mapper); | ||
} | ||
|
||
boolean isValidRange(Object value) { | ||
return attribute.getJavaType().isAssignableFrom(value.getClass()) || isFieldEnum(); | ||
} | ||
|
||
boolean isFieldEnum() { | ||
final Class<?> cls = attribute.getJavaField().getType(); | ||
return cls.isEnum(); | ||
} | ||
|
||
Object resolveEnumValue(Object value) { | ||
final Class cls = attribute.getJavaField().getType(); | ||
return Enum.valueOf(cls, value.toString()); | ||
} | ||
|
||
@Override | ||
Assertion createAssertion() { | ||
return Assertion.createDataPropertyAssertion(attribute.getIRI().toURI(), attribute.isInferred()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
jopa-impl/src/main/java/cz/cvut/kbss/jopa/oom/PluralDataPropertyStrategy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package cz.cvut.kbss.jopa.oom; | ||
|
||
import cz.cvut.kbss.jopa.model.descriptors.Descriptor; | ||
import cz.cvut.kbss.jopa.model.metamodel.EntityType; | ||
import cz.cvut.kbss.jopa.model.metamodel.PluralAttribute; | ||
import cz.cvut.kbss.jopa.utils.CollectionFactory; | ||
import cz.cvut.kbss.ontodriver.model.Axiom; | ||
import cz.cvut.kbss.ontodriver.model.Value; | ||
|
||
import java.util.Collection; | ||
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
|
||
public class PluralDataPropertyStrategy<X> extends DataPropertyFieldStrategy<X> { | ||
|
||
private PluralAttribute<? super X, ?, ?> pluralAtt; | ||
|
||
private Collection<Object> values; | ||
|
||
PluralDataPropertyStrategy(EntityType<X> et, PluralAttribute<? super X, ?, ?> att, Descriptor attributeDescriptor, | ||
EntityMappingHelper mapper) { | ||
super(et, att, attributeDescriptor, mapper); | ||
this.pluralAtt = att; | ||
this.values = CollectionFactory.createDefaultCollection(pluralAtt.getCollectionType()); | ||
} | ||
|
||
@Override | ||
void addValueFromAxiom(Axiom<?> ax) { | ||
final Object value = ax.getValue().getValue(); | ||
if (isValidRange(value)) { | ||
this.values.add(value); | ||
} | ||
} | ||
|
||
boolean isValidRange(Object value) { | ||
return pluralAtt.getElementType().getJavaType().isAssignableFrom(value.getClass()); | ||
} | ||
|
||
@Override | ||
void buildInstanceFieldValue(Object instance) throws IllegalAccessException { | ||
if (!values.isEmpty()) { | ||
setValueOnInstance(instance, values); | ||
} | ||
} | ||
|
||
@Override | ||
void buildAxiomValuesFromInstance(X instance, AxiomValueGatherer valueBuilder) throws IllegalAccessException { | ||
final Object value = extractFieldValueFromInstance(instance); | ||
assert value instanceof Collection || value == null; | ||
final Collection<?> valueCollection = (Collection<?>) value; | ||
if (valueCollection == null || valueCollection.isEmpty()) { | ||
valueBuilder.addValue(createAssertion(), Value.nullValue(), getAttributeContext()); | ||
} else { | ||
final Set<Value<?>> assertionValues = valueCollection.stream().map(Value::new).collect(Collectors.toSet()); | ||
valueBuilder.addValues(createAssertion(), assertionValues, getAttributeContext()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.