Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Renamed ObjectToVertexMapper to DefaultClassMapper, extracted interfa…

…ce for it and IdResolver.

Signed-off-by: gburgett <gordon.burgett@gmail.com>
  • Loading branch information...
commit 85495297d2919c3b67827a487fecebb2ee5b7efc 1 parent 5f67f33
@gburgett gburgett authored
View
87 ...ons/src/main/java/org/springframework/data/orientdb/graph/core/OrientGraphOperations.java
@@ -8,15 +8,18 @@
import com.orientechnologies.orient.core.id.ORID;
import com.orientechnologies.orient.core.id.ORecordId;
import com.orientechnologies.orient.core.record.impl.ODocument;
+import com.orientechnologies.orient.core.sql.OCommandSQL;
import com.orientechnologies.orient.core.sql.query.OSQLSynchQuery;
import com.orientechnologies.orient.core.tx.OTransactionNoTx;
import java.util.Collections;
+import java.util.Iterator;
import java.util.List;
import java.util.Set;
import org.springframework.data.mapping.model.MappingException;
import org.springframework.data.orientdb.core.OrientDbManager;
+import org.springframework.data.orientdb.graph.mapper.ClassMapper;
+import org.springframework.data.orientdb.graph.mapper.DefaultClassMapper;
import org.springframework.data.orientdb.graph.mapper.EdgeRelationMapper;
-import org.springframework.data.orientdb.graph.mapper.ObjectToVertexMapper;
/**
* An implementation of GraphOperations that wraps an {@link OGraphDatabase}.
@@ -42,7 +45,7 @@ public ODocument insertSingleVertex(Object vertex) {
if(vertex == null)
throw new IllegalArgumentException("vertex cannot be null");
- ObjectToVertexMapper mapper = ObjectToVertexMapper.forClass(vertex.getClass());
+ ClassMapper mapper = DefaultClassMapper.forClass(vertex.getClass());
if(!mapper.isVertex()){
throw new IllegalArgumentException("object must be annotated as a vertex");
}
@@ -55,7 +58,7 @@ public ODocument insertSingleVertex(Object vertex) {
return internalCreateVertex(vertex, mapper, id);
}
- private ODocument internalCreateVertex(Object vertex, ObjectToVertexMapper mapper, ORID id){
+ private ODocument internalCreateVertex(Object vertex, ClassMapper mapper, ORID id){
OGraphDatabase db = this.dbManager.getCurrentDatabase();
ODocument record;
@@ -86,7 +89,7 @@ public ODocument insertSingleEdge(Object edge) {
if(edge == null)
throw new IllegalArgumentException("vertex cannot be null");
- ObjectToVertexMapper mapper = ObjectToVertexMapper.forClass(edge.getClass());
+ ClassMapper mapper = DefaultClassMapper.forClass(edge.getClass());
if(mapper.isVertex()){
throw new IllegalArgumentException("object must be annotated as an Edge");
}
@@ -142,7 +145,7 @@ public ODocument createEdge(ODocument in, ODocument out, String label){
public <T> T getSingleVertex(Object id, Class<T> clazz, boolean deepRefresh) {
ORID oId = toOrientId(id);
- ObjectToVertexMapper<T> mapper = ObjectToVertexMapper.forClass(clazz);
+ ClassMapper<T> mapper = DefaultClassMapper.forClass(clazz);
if(!mapper.isVertex()){
throw new IllegalArgumentException("Expected to unmarshal class as a Vertex, but "+ clazz + " is an Edge");
}
@@ -182,7 +185,7 @@ public ODocument createEdge(ODocument in, ODocument out, String label){
public <T> T getSingleEdge(Object id, Class<T> clazz, boolean deepRefresh) {
ORID oId = toOrientId(id);
- ObjectToVertexMapper<T> mapper = ObjectToVertexMapper.forClass(clazz);
+ ClassMapper<T> mapper = DefaultClassMapper.forClass(clazz);
if(mapper.isVertex()){
throw new IllegalArgumentException("Expected to unmarshal class as an Edge, but "+ clazz + " is a Vertex");
}
@@ -218,7 +221,7 @@ public ODocument updateSingleVertex(final Object vertex) {
if(vertex == null)
throw new IllegalArgumentException("vertex cannot be null");
- final ObjectToVertexMapper mapper = ObjectToVertexMapper.forClass(vertex.getClass());
+ final ClassMapper mapper = DefaultClassMapper.forClass(vertex.getClass());
if(!mapper.isVertex()){
throw new IllegalArgumentException("object must be annotated as a vertex");
}
@@ -231,7 +234,7 @@ public ODocument updateSingleVertex(final Object vertex) {
return internalUpdateRecord(vertex, mapper, id);
}
- private ODocument internalUpdateRecord(final Object vertex, final ObjectToVertexMapper mapper, final ORID id){
+ private ODocument internalUpdateRecord(final Object vertex, final ClassMapper mapper, final ORID id){
OGraphDatabase db = this.dbManager.getCurrentDatabase();
return this.doInTransaction(db, new Function1<OGraphDatabase, ODocument>() {
@@ -273,7 +276,7 @@ public ODocument updateSingleEdge(final Object edge) {
if(edge == null)
throw new IllegalArgumentException("edge cannot be null");
- final ObjectToVertexMapper mapper = ObjectToVertexMapper.forClass(edge.getClass());
+ final ClassMapper mapper = DefaultClassMapper.forClass(edge.getClass());
if(mapper.isVertex()){
throw new IllegalArgumentException("object must be annotated as an edge");
}
@@ -293,7 +296,7 @@ public ODocument saveSingleVertex(final Object vertex){
if(vertex == null)
throw new IllegalArgumentException("vertex cannot be null");
- final ObjectToVertexMapper mapper = ObjectToVertexMapper.forClass(vertex.getClass());
+ final ClassMapper mapper = DefaultClassMapper.forClass(vertex.getClass());
if(!mapper.isVertex()){
throw new IllegalArgumentException("object must be annotated as a vertex");
}
@@ -303,7 +306,7 @@ public ODocument saveSingleVertex(final Object vertex){
return internalCreateVertex(vertex, mapper, id);
}
- return this.doInTransaction(this.dbManager.getCurrentDatabase(), new Function1<OGraphDatabase, ODocument>() {
+ return OrientGraphOperations.doInTransaction(this.dbManager.getCurrentDatabase(), new Function1<OGraphDatabase, ODocument>() {
@Override
public ODocument apply(OGraphDatabase db) {
ODocument record = db.load(id);
@@ -344,7 +347,7 @@ public ODocument apply(OGraphDatabase db) {
@Override
public void deleteSingleVertex(Object vertex) {
- ObjectToVertexMapper mapper = ObjectToVertexMapper.forClass(vertex.getClass());
+ ClassMapper mapper = DefaultClassMapper.forClass(vertex.getClass());
if(!mapper.isVertex()){
throw new IllegalArgumentException("Expected a Vertex, but "+ vertex.getClass() + " is annotated as an Edge");
}
@@ -357,7 +360,7 @@ public void deleteSingleVertex(Object vertex) {
deleteInternal(id, mapper);
}
- private void deleteInternal(ORID id, final ObjectToVertexMapper<?> mapper) {
+ private void deleteInternal(ORID id, final ClassMapper<?> mapper) {
OGraphDatabase database = this.dbManager.getCurrentDatabase();
@@ -391,7 +394,7 @@ public Object apply(OGraphDatabase db) {
@Override
public void deleteSingleEdge(Object edge) {
- final ObjectToVertexMapper mapper = ObjectToVertexMapper.forClass(edge.getClass());
+ final ClassMapper mapper = DefaultClassMapper.forClass(edge.getClass());
if(!mapper.isEdge()){
throw new IllegalArgumentException("Expected an Edge, but "+ edge.getClass() + " is annotated as a Vertex");
}
@@ -452,24 +455,68 @@ private static ORID toOrientId(Object id){
OGraphDatabase db = this.dbManager.getCurrentDatabase();
- ObjectToVertexMapper<T> mapper =
- clazz == null ? null : ObjectToVertexMapper.forClass(clazz);
+ ClassMapper<T> mapper =
+ clazz == null ? null : DefaultClassMapper.forClass(clazz);
List<ODocument> results = db.query(new OSQLSynchQuery<ODocument>(sql), args);
if(results == null || mapper == null)
return Collections.EMPTY_LIST;
- return mapper.convertingIterable(results);
+ return convertingIterable(clazz, mapper, results);
}
+
@Override
public void ensureDatabaseClassExists(Class<?> clazz) {
- ObjectToVertexMapper<?> mapper = ObjectToVertexMapper.forClass(clazz);
+ ClassMapper<?> mapper = DefaultClassMapper.forClass(clazz);
mapper.createClass(this.dbManager.getCurrentDatabase().getMetadata().getSchema());
}
+ /**
+ * Creates an Iterable that, when iterated, will unmarshal each document
+ * in the given document iteration and return it in order.
+ * @param documents The source document iterable.
+ * @return A converting, wrapping iterator.
+ */
+ private <T> Iterable<T> convertingIterable(final Class<T> clazz, final ClassMapper<T> mapper, final Iterable<ODocument> documents){
+ return new Iterable<T>(){
+ @Override
+ public Iterator<T> iterator() {
+ return new Iterator<T>(){
+ final Iterator<ODocument> source = documents.iterator();
+
+ @Override
+ public boolean hasNext() {
+ return source.hasNext();
+ }
+
+ @Override
+ public T next() {
+ ODocument next = source.next();
+ T ret;
+ try {
+ ret = clazz.newInstance();
+ } catch ( InstantiationException | IllegalAccessException ex) {
+ throw new MappingException("Unable to unmarshal " + clazz, ex);
+ }
+
+ mapper.copyPropertiesToObject(next, ret);
+ mapper.getIdResolver().setId(ret, next.getIdentity());
+
+ return ret;
+ }
+
+ @Override
+ public void remove() {
+ source.remove();
+ }
+ };
+ }
+ };
+ }
+
- private static <U> U doInTransaction(OGraphDatabase db, Function1<OGraphDatabase, U> action){
+ public static <U> U doInTransaction(OGraphDatabase db, Function1<OGraphDatabase, U> action){
boolean didOpenTx = false;
try{
@@ -497,7 +544,7 @@ public void ensureDatabaseClassExists(Class<?> clazz) {
- private static interface Function1<T, U>{
+ public static interface Function1<T, U>{
public U apply(T db);
}
}
View
35 ...tdb-commons/src/main/java/org/springframework/data/orientdb/graph/mapper/ClassMapper.java
@@ -0,0 +1,35 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package org.springframework.data.orientdb.graph.mapper;
+
+import com.orientechnologies.orient.core.id.ORID;
+import com.orientechnologies.orient.core.metadata.schema.OClass;
+import com.orientechnologies.orient.core.metadata.schema.OSchema;
+import com.orientechnologies.orient.core.record.impl.ODocument;
+import java.util.Set;
+
+/**
+ *
+ * @author Gordon
+ */
+public interface ClassMapper<T> {
+
+ public boolean isVertex();
+
+ public IdResolver getIdResolver();
+
+ public String getClassName();
+
+ public OClass createClass(OSchema schema);
+
+ public void copyPropertiesToRecord(T object, ODocument record);
+
+ public void copyPropertiesToObject(ODocument record, T object);
+
+ public boolean isEdge();
+
+ public Set<ORID> getEmbeddedDocumentIDs(ODocument doc);
+
+}
View
67 ...db/graph/mapper/ObjectToVertexMapper.java → ...ntdb/graph/mapper/DefaultClassMapper.java
@@ -8,6 +8,7 @@
import com.orientechnologies.orient.core.id.ORID;
import com.orientechnologies.orient.core.metadata.schema.OClass;
import com.orientechnologies.orient.core.metadata.schema.OSchema;
+import com.orientechnologies.orient.core.metadata.schema.OType;
import com.orientechnologies.orient.core.record.impl.ODocument;
import java.beans.BeanInfo;
import java.beans.IntrospectionException;
@@ -34,7 +35,7 @@
* manage any relations, it only copies specifically annotated properties.
* @author Gordon
*/
-public class ObjectToVertexMapper<T> {
+public class DefaultClassMapper<T> implements ClassMapper<T> {
private final Class<T> clazz;
@@ -83,11 +84,11 @@ public String getClassName(){
private List<AbstractMapper<T>> properties;
- protected ObjectToVertexMapper(Class<T> clazz){
+ protected DefaultClassMapper(Class<T> clazz){
this.clazz = clazz;
}
- private static ConcurrentHashMap<String, ObjectToVertexMapper<?>> cachedMappers =
+ private static ConcurrentHashMap<String, DefaultClassMapper<?>> cachedMappers =
new ConcurrentHashMap<>();
/**
@@ -98,13 +99,13 @@ protected ObjectToVertexMapper(Class<T> clazz){
* @return The object to vertex mapper for the class
* @throws ClassNotFoundException if the class could not be loaded.
*/
- public static ObjectToVertexMapper<?> forClass(String clazz) throws ClassNotFoundException{
- ObjectToVertexMapper<?> ret = cachedMappers.get(clazz);
+ public static ClassMapper<?> forClass(String clazz) throws ClassNotFoundException{
+ DefaultClassMapper<?> ret = cachedMappers.get(clazz);
if(ret != null){
return ret;
}
- Class<?> cl = ObjectToVertexMapper.class.getClassLoader().loadClass(clazz);
+ Class<?> cl = DefaultClassMapper.class.getClassLoader().loadClass(clazz);
return forClass(cl);
}
@@ -115,18 +116,18 @@ protected ObjectToVertexMapper(Class<T> clazz){
* @param clazz The class to build a mapper for.
* @return An ObjectToVertexMapper for the given class, either cached or new.
*/
- public static <U> ObjectToVertexMapper<U> forClass(Class<U> clazz){
+ public static <U> ClassMapper<U> forClass(Class<U> clazz){
if(clazz.isPrimitive() ||
String.class.equals(clazz)){
return null;
}
- ObjectToVertexMapper<U> ret = (ObjectToVertexMapper<U>)cachedMappers.get(clazz.getName());
+ DefaultClassMapper<U> ret = (DefaultClassMapper<U>)cachedMappers.get(clazz.getName());
if(ret != null){
return ret;
}
- ret = new ObjectToVertexMapper<>(clazz);
+ ret = new DefaultClassMapper<>(clazz);
Vertex vertexAnnotation = clazz.getAnnotation(Vertex.class);
@@ -164,7 +165,7 @@ protected ObjectToVertexMapper(Class<T> clazz){
ret.vertexAnnotation = vertexAnnotation;
ret.edgeAnnotation = edgeAnnotation;
- ret.idResolver = IdResolver.forClass(clazz);
+ ret.idResolver = DefaultIdResolver.forClass(clazz);
cachedMappers.putIfAbsent(clazz.getName(), ret);
@@ -301,6 +302,7 @@ public void copyPropertiesToObject(ODocument oElement, T object) {
* @param object The object to persist.
* @param oElement The vertex or edge retrieved from or created in the database.
*/
+ @Override
public void copyPropertiesToRecord(T object, ODocument oElement) {
try {
@@ -319,6 +321,7 @@ public void copyPropertiesToRecord(T object, ODocument oElement) {
* @return The class that was created, or the existing class if it already
* exists.
*/
+ @Override
public OClass createClass(OSchema schema) {
if(className == null || "".equals(className)){
throw new UnsupportedOperationException("Cannot create class when the Vertex or Edge has not been annotated with a class name.");
@@ -373,48 +376,7 @@ public OClass createClass(OSchema schema) {
}
}
- /**
- * Creates an Iterable that, when iterated, will unmarshal each document
- * in the given document iteration and return it in order.
- * @param documents The source document iterable.
- * @return A converting, wrapping iterator.
- */
- public Iterable<T> convertingIterable(final Iterable<ODocument> documents){
- return new Iterable<T>(){
- @Override
- public Iterator<T> iterator() {
- return new Iterator<T>(){
- final Iterator<ODocument> source = documents.iterator();
-
- @Override
- public boolean hasNext() {
- return source.hasNext();
- }
-
- @Override
- public T next() {
- ODocument next = source.next();
- T ret;
- try {
- ret = clazz.newInstance();
- } catch ( InstantiationException | IllegalAccessException ex) {
- throw new MappingException("Unable to unmarshal " + clazz, ex);
- }
- copyPropertiesToObject(next, ret);
- getIdResolver().setId(ret, next.getIdentity());
-
- return ret;
- }
-
- @Override
- public void remove() {
- source.remove();
- }
- };
- }
- };
- }
/**
* Gets a set of all the IDs of embedded objects within the document.
@@ -422,8 +384,11 @@ public void remove() {
* @return The set of all IDs that the embedded document has, or null
* if no embedded documents exist in the document.
*/
+ @Override
public Set<ORID> getEmbeddedDocumentIDs(ODocument doc){
Set<ORID> ret = null;
+
+ //go through the properties for any annotated @Embedded (this can include collections)
for(AbstractMapper<T> mapper : properties){
if(mapper instanceof EmbeddedMapper){
try {
View
160 ...mmons/src/main/java/org/springframework/data/orientdb/graph/mapper/DefaultIdResolver.java
@@ -0,0 +1,160 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package org.springframework.data.orientdb.graph.mapper;
+
+import com.orientechnologies.orient.core.id.OImmutableRecordId;
+import com.orientechnologies.orient.core.id.ORID;
+import com.orientechnologies.orient.core.id.ORecordId;
+import java.beans.IntrospectionException;
+import java.lang.reflect.Field;
+import java.lang.reflect.Modifier;
+import java.util.ArrayList;
+import java.util.List;
+import org.springframework.data.mapping.model.MappingException;
+import org.springframework.data.annotation.Id;
+
+/**
+ *
+ * @author Gordon
+ */
+public abstract class DefaultIdResolver<T> implements IdResolver<T> {
+
+ protected final Class<T> clazz;
+
+ protected final Field idField;
+
+ protected DefaultIdResolver(Class<T> clazz, Field field){
+ this.clazz = clazz;
+ this.idField = field;
+ }
+
+ /**
+ * Creates an object that can get or set the ID property or field of the given class
+ * reflectively.
+ * @param <U>
+ * @param clazz The class that is being mapped.
+ * @return A new IdResolver.
+ */
+ static <U> DefaultIdResolver<U> forClass(Class<U> clazz){
+ if(clazz.isPrimitive() ||
+ String.class.equals(clazz)){
+ throw new MappingException("Cannot determine ID property of class " + clazz.getName());
+ }
+
+ try{
+ Field idField = getIdField(clazz);
+ if(idField == null){
+ throw new MappingException("Cannot determine ID property of class " + clazz.getName());
+ }
+
+ idField.setAccessible(true);
+
+ if(idField.getType().isAssignableFrom(ORID.class)){
+ return new DefaultIdResolver<U>(clazz, idField){
+ @Override
+ public ORecordId getId(U instance) throws MappingException {
+ try {
+ Object id = idField.get(instance);
+ return id == null ? null : new ORecordId(id.toString());
+ } catch ( IllegalArgumentException | IllegalAccessException ex) {
+ throw new MappingException("unable to get Id", ex);
+ }
+ }
+
+ @Override
+ public void setId(U instance, ORID id) throws MappingException {
+ try {
+ idField.set(instance, id);
+ } catch ( IllegalArgumentException | IllegalAccessException ex) {
+ throw new MappingException("unable to set Id", ex);
+ }
+ }
+ };
+ }
+ else if(String.class.equals(idField.getType())){
+ return new DefaultIdResolver<U>(clazz, idField){
+ @Override
+ public ORecordId getId(U instance) throws MappingException {
+ try {
+ String ret = (String)idField.get(instance);
+ return ret == null ? null : new ORecordId(ret);
+ } catch ( IllegalArgumentException | IllegalAccessException ex) {
+ throw new MappingException("unable to get Id", ex);
+ }
+ }
+
+ @Override
+ public void setId(U instance, ORID id) throws MappingException {
+ try {
+ Object idObj = id == null ? null : id.toString();
+ idField.set(instance, idObj);
+ } catch ( IllegalArgumentException | IllegalAccessException ex) {
+ throw new MappingException("unable to set Id", ex);
+ }
+ }
+ };
+ }
+
+ throw new MappingException("ID property of class " + clazz.getName() + " must be of type ORID, Object, or String");
+ }
+ catch(IntrospectionException ex){
+ throw new MappingException("Cannot determine ID property of class " + clazz.getName(), ex);
+ }
+ }
+
+ public Class<?> getIdClass() {
+ return idField.getType();
+ }
+
+ /**
+ * Gets the value of the ID as an ORID, or null if it is not set.
+ * @param instance The object whose ID is needed.
+ * @return the ORID, or null.
+ * @throws MappingException if an access error occurred.
+ */
+ @Override
+ public abstract ORecordId getId(T instance) throws MappingException;
+
+
+ /**
+ * Sets the value of the ID, converting it as necessary.
+ * @param instance The object whose ID should be set.
+ * @param id The ORID to set, or null to unset.
+ * @throws MappingException if an access error occurred.
+ */
+ @Override
+ public abstract void setId(T instance, ORID id) throws MappingException;
+
+ private static Field getIdField(Class<?> pojoType) throws IntrospectionException{
+
+ List<Field> fields = new ArrayList<>();
+
+ while(!Object.class.equals(pojoType)){
+ for(Field f : pojoType.getDeclaredFields()){
+ if(Object.class.equals(f.getDeclaringClass()))
+ continue;
+
+ if((f.getModifiers() & Modifier.STATIC) == Modifier.STATIC ||
+ (f.getModifiers() & Modifier.FINAL) == Modifier.FINAL)
+ continue;
+
+ fields.add(f);
+ }
+ pojoType = pojoType.getSuperclass();
+ }
+
+ //try fields marked with ID attribute
+ for(Field f : fields){
+ if(f.getAnnotation(Id.class) != null){
+ return f;
+ }
+ }
+
+ return null;
+ }
+
+
+
+}
View
20 ...-commons/src/main/java/org/springframework/data/orientdb/graph/mapper/EmbeddedMapper.java
@@ -50,7 +50,7 @@ public void copyTo(T object, ODocument doc) throws IllegalArgumentException, Ill
protected void copyProp(Object o, ODocument doc){
ODocument existing = doc.field(name);
- ObjectToVertexMapper mapper = ObjectToVertexMapper.forClass(o.getClass());
+ ClassMapper mapper = DefaultClassMapper.forClass(o.getClass());
if(existing == null){
ODocument newDoc = new ODocument();
mapper.copyPropertiesToRecord(o, newDoc);
@@ -96,7 +96,7 @@ protected void copyCollection(Collection coll, ODocument doc){
List<ODocument> newDocs = new ArrayList<>();
for(Object newObj : coll){
- ObjectToVertexMapper mapper = ObjectToVertexMapper.forClass(newObj.getClass());
+ ClassMapper mapper = DefaultClassMapper.forClass(newObj.getClass());
ORecordId id = mapper.getIdResolver().getId(newObj);
ODocument toUpdate;
@@ -137,7 +137,7 @@ protected Collection unmarshalCollection(ODocument doc) throws ClassNotFoundExce
Class<?> clazz = getClass().getClassLoader().loadClass((String)embedded.field("@discriminator"));
Object toAdd = clazz.newInstance();
- ObjectToVertexMapper mapper = ObjectToVertexMapper.forClass(clazz);
+ ClassMapper mapper = DefaultClassMapper.forClass(clazz);
mapper.copyPropertiesToObject(embedded, toAdd);
ORID id = embedded.getIdentity();
@@ -172,7 +172,7 @@ protected Object unmarshalValue(ODocument embedded) throws InstantiationExceptio
Object value = type.newInstance();
- ObjectToVertexMapper mapper = ObjectToVertexMapper.forClass(type);
+ ClassMapper mapper = DefaultClassMapper.forClass(type);
mapper.copyPropertiesToObject(embedded, value);
mapper.getIdResolver().setId(value, ((ODocument)embedded).getIdentity());
@@ -203,10 +203,10 @@ protected Object unmarshalValue(ODocument embedded) throws InstantiationExceptio
for(ODocument doc : coll){
ret.add(doc.getIdentity());
- ObjectToVertexMapper recursive;
+ ClassMapper recursive;
String clazz = doc.field("@discriminator");
if(clazz != null){
- recursive = ObjectToVertexMapper.forClass(clazz);
+ recursive = DefaultClassMapper.forClass(clazz);
}
else{
throw new MappingException("Embedded document in collection has no discriminator: " + doc.toJSON());
@@ -224,7 +224,7 @@ protected Object unmarshalValue(ODocument embedded) throws InstantiationExceptio
Set<ORID> ret = new HashSet<>();
ret.add(embedded.getIdentity());
- ObjectToVertexMapper recursive = getMapper(embedded);
+ ClassMapper recursive = getMapper(embedded);
Set<ORID> recursed = recursive.getEmbeddedDocumentIDs(embedded);
if(recursed != null)
@@ -243,17 +243,17 @@ protected Object unmarshalValue(ODocument embedded) throws InstantiationExceptio
*/
protected abstract Object getValue(T object) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException;
- private ObjectToVertexMapper getMapper(ODocument discriminatedDoc){
+ private ClassMapper getMapper(ODocument discriminatedDoc){
String disc = discriminatedDoc.field("@discriminator");
if(disc != null){
try {
- return ObjectToVertexMapper.forClass(disc);
+ return DefaultClassMapper.forClass(disc);
} catch (ClassNotFoundException ex) {
throw new MappingException("Cannot load discriminated class " + disc);
}
}
else{
- return ObjectToVertexMapper.forClass(propertyType);
+ return DefaultClassMapper.forClass(propertyType);
}
}
View
132 ...ntdb-commons/src/main/java/org/springframework/data/orientdb/graph/mapper/IdResolver.java
@@ -4,109 +4,14 @@
*/
package org.springframework.data.orientdb.graph.mapper;
-import com.orientechnologies.orient.core.id.OImmutableRecordId;
import com.orientechnologies.orient.core.id.ORID;
import com.orientechnologies.orient.core.id.ORecordId;
-import java.beans.IntrospectionException;
-import java.lang.reflect.Field;
-import java.lang.reflect.Modifier;
-import java.util.ArrayList;
-import java.util.List;
-import org.springframework.data.mapping.model.MappingException;
-import org.springframework.data.annotation.Id;
/**
*
* @author Gordon
*/
-public abstract class IdResolver<T> {
-
- protected final Class<T> clazz;
-
- protected final Field idField;
-
- protected IdResolver(Class<T> clazz, Field field){
- this.clazz = clazz;
- this.idField = field;
- }
-
- /**
- * Creates an object that can get or set the ID property or field of the given class
- * reflectively.
- * @param <U>
- * @param clazz The class that is being mapped.
- * @return A new IdResolver.
- */
- static <U> IdResolver<U> forClass(Class<U> clazz){
- if(clazz.isPrimitive() ||
- String.class.equals(clazz)){
- throw new MappingException("Cannot determine ID property of class " + clazz.getName());
- }
-
- try{
- Field idField = getIdField(clazz);
- if(idField == null){
- throw new MappingException("Cannot determine ID property of class " + clazz.getName());
- }
-
- idField.setAccessible(true);
-
- if(idField.getType().isAssignableFrom(ORID.class)){
- return new IdResolver<U>(clazz, idField){
- @Override
- public ORecordId getId(U instance) throws MappingException {
- try {
- Object id = idField.get(instance);
- return id == null ? null : new ORecordId(id.toString());
- } catch ( IllegalArgumentException | IllegalAccessException ex) {
- throw new MappingException("unable to get Id", ex);
- }
- }
-
- @Override
- public void setId(U instance, ORID id) throws MappingException {
- try {
- idField.set(instance, id);
- } catch ( IllegalArgumentException | IllegalAccessException ex) {
- throw new MappingException("unable to set Id", ex);
- }
- }
- };
- }
- else if(String.class.equals(idField.getType())){
- return new IdResolver<U>(clazz, idField){
- @Override
- public ORecordId getId(U instance) throws MappingException {
- try {
- String ret = (String)idField.get(instance);
- return ret == null ? null : new ORecordId(ret);
- } catch ( IllegalArgumentException | IllegalAccessException ex) {
- throw new MappingException("unable to get Id", ex);
- }
- }
-
- @Override
- public void setId(U instance, ORID id) throws MappingException {
- try {
- Object idObj = id == null ? null : id.toString();
- idField.set(instance, idObj);
- } catch ( IllegalArgumentException | IllegalAccessException ex) {
- throw new MappingException("unable to set Id", ex);
- }
- }
- };
- }
-
- throw new MappingException("ID property of class " + clazz.getName() + " must be of type ORID, Object, or String");
- }
- catch(IntrospectionException ex){
- throw new MappingException("Cannot determine ID property of class " + clazz.getName(), ex);
- }
- }
-
- public Class<?> getIdClass() {
- return idField.getType();
- }
+public interface IdResolver<T> {
/**
* Gets the value of the ID as an ORID, or null if it is not set.
@@ -114,8 +19,7 @@ public void setId(U instance, ORID id) throws MappingException {
* @return the ORID, or null.
* @throws MappingException if an access error occurred.
*/
- public abstract ORecordId getId(T instance) throws MappingException;
-
+ public ORecordId getId(T o);
/**
* Sets the value of the ID, converting it as necessary.
@@ -123,36 +27,6 @@ public void setId(U instance, ORID id) throws MappingException {
* @param id The ORID to set, or null to unset.
* @throws MappingException if an access error occurred.
*/
- public abstract void setId(T instance, ORID id) throws MappingException;
-
- private static Field getIdField(Class<?> pojoType) throws IntrospectionException{
-
- List<Field> fields = new ArrayList<>();
-
- while(!Object.class.equals(pojoType)){
- for(Field f : pojoType.getDeclaredFields()){
- if(Object.class.equals(f.getDeclaringClass()))
- continue;
-
- if((f.getModifiers() & Modifier.STATIC) == Modifier.STATIC ||
- (f.getModifiers() & Modifier.FINAL) == Modifier.FINAL)
- continue;
-
- fields.add(f);
- }
- pojoType = pojoType.getSuperclass();
- }
-
- //try fields marked with ID attribute
- for(Field f : fields){
- if(f.getAnnotation(Id.class) != null){
- return f;
- }
- }
-
- return null;
- }
-
-
+ public void setId(T o, ORID id);
}
View
19 ...va/org/springframework/data/orientdb/graph/core/OrientGraphOperationsIntegrationTest.java
@@ -23,7 +23,8 @@
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.orientdb.core.OrientDbManager;
-import org.springframework.data.orientdb.graph.mapper.ObjectToVertexMapper;
+import org.springframework.data.orientdb.graph.mapper.ClassMapper;
+import org.springframework.data.orientdb.graph.mapper.DefaultClassMapper;
import org.springframework.data.orientdb.testdata.Bar;
import org.springframework.data.orientdb.testdata.Baz;
import org.springframework.data.orientdb.testdata.EmbeddedQux;
@@ -96,7 +97,7 @@ public void testInsertSingleVertex_ClassExists_InsertsWithoutCreating() throws E
foo.addFooInt(17);
foo.setFooString("junk");
- ObjectToVertexMapper<Foo> mapper = ObjectToVertexMapper.forClass(Foo.class);
+ ClassMapper<Foo> mapper = DefaultClassMapper.forClass(Foo.class);
mapper.createClass(graphOperations.getUnderlyingGraph().getMetadata().getSchema());
//act
@@ -214,7 +215,7 @@ public void testGetSingleVertex_InvalidId_ThrowsException() throws Exception {
public void testGetSingleVertex_DocumentExists_UnmarshalledAsClass() throws Exception {
System.out.println("testGetSingleVertex_DocumentExists_UnmarshalledAsClass");
- ObjectToVertexMapper.forClass(Foo.class).createClass(graphOperations.getUnderlyingGraph().getMetadata().getSchema());
+ DefaultClassMapper.forClass(Foo.class).createClass(graphOperations.getUnderlyingGraph().getMetadata().getSchema());
ODocument vDoc = graphOperations.getUnderlyingGraph().createVertex("foo");
vDoc.field("ints", Arrays.asList(17, 4, 8));
@@ -235,7 +236,7 @@ public void testGetSingleEdge_EdgeExists_UnmarshalsAsEdgeClass() throws Exceptio
System.out.println("testGetSingleEdge_EdgeExists_UnmarshalsAsEdgeClass");
OGraphDatabase underlying = graphOperations.getUnderlyingGraph();
- ObjectToVertexMapper.forClass(Foo.class).createClass(underlying.getMetadata().getSchema());
+ DefaultClassMapper.forClass(Foo.class).createClass(underlying.getMetadata().getSchema());
ODocument foo1 = underlying.createVertex("foo");
ODocument foo2 = underlying.createVertex("foo");
@@ -256,7 +257,7 @@ public void testUpdateSingleEdge_EdgeExists_MarshalsChange() throws Exception {
System.out.println("testUpdateSingleEdge_EdgeExists_MarshalsChange");
OGraphDatabase underlying = graphOperations.getUnderlyingGraph();
- ObjectToVertexMapper.forClass(Foo.class).createClass(underlying.getMetadata().getSchema());
+ DefaultClassMapper.forClass(Foo.class).createClass(underlying.getMetadata().getSchema());
ODocument foo1 = underlying.createVertex("foo");
ODocument foo2 = underlying.createVertex("foo");
@@ -282,7 +283,7 @@ public void testUpdateSingleVertex_VertexExists_MarshalsChanges() throws Excepti
System.out.println("testUpdateSingleVertex_VertexExists_MarshalsChanges");
OGraphDatabase underlying = graphOperations.getUnderlyingGraph();
- ObjectToVertexMapper.forClass(Foo.class).createClass(underlying.getMetadata().getSchema());
+ DefaultClassMapper.forClass(Foo.class).createClass(underlying.getMetadata().getSchema());
ODocument vDoc = graphOperations.getUnderlyingGraph().createVertex("foo");
vDoc.field("ints", Arrays.asList(17, 4, 8));
@@ -312,7 +313,7 @@ public void testDeleteVertexByObject_VertexExists_VertexIsDeleted() throws Excep
System.out.println("testDeleteVertexByObject_VertexExists_VertexIsDeleted");
OGraphDatabase underlying = graphOperations.getUnderlyingGraph();
- ObjectToVertexMapper.forClass(Foo.class).createClass(underlying.getMetadata().getSchema());
+ DefaultClassMapper.forClass(Foo.class).createClass(underlying.getMetadata().getSchema());
ODocument fooDoc = underlying.createVertex("foo");
fooDoc.field("ints", Arrays.asList(17, 4, 8));
@@ -357,7 +358,7 @@ public void testDeleteVertexByObject_InTransaction_EntireDeleteCanBeRolledBack()
System.out.println("testDeleteVertexByObject_InTransaction_EntireDeleteCanBeRolledBack");
OGraphDatabase underlying = graphOperations.getUnderlyingGraph();
- ObjectToVertexMapper.forClass(Foo.class).createClass(underlying.getMetadata().getSchema());
+ DefaultClassMapper.forClass(Foo.class).createClass(underlying.getMetadata().getSchema());
ODocument fooDoc = underlying.createVertex("foo");
fooDoc.field("ints", Arrays.asList(17, 4, 8));
@@ -399,7 +400,7 @@ public void testDeleteEdgeByObject_EdgeExists_EdgeIsDeleted() throws Exception {
System.out.println("testDeleteEdgeByObject_EdgeExists_EdgeIsDeleted");
OGraphDatabase underlying = graphOperations.getUnderlyingGraph();
- ObjectToVertexMapper.forClass(Foo.class).createClass(underlying.getMetadata().getSchema());
+ DefaultClassMapper.forClass(Foo.class).createClass(underlying.getMetadata().getSchema());
ODocument foo1 = underlying.createVertex("foo");
ODocument foo2 = underlying.createVertex("foo");
View
54 ...raph/mapper/ObjectToVertexMapperTest.java → .../graph/mapper/DefaultClassMapperTest.java
@@ -25,14 +25,14 @@
*
* @author Gordon
*/
-public class ObjectToVertexMapperTest {
+public class DefaultClassMapperTest {
//<editor-fold desc="properties" defaultstate="collapsed" >
@Test
public void testSimpleProperty_StringValue_MapsToDocument() throws Exception {
System.out.println("testSimpleProperty_StringValue_MapsToDocument");
- ObjectToVertexMapper<Foo> mapper = ObjectToVertexMapper.forClass(Foo.class);
+ ClassMapper<Foo> mapper = DefaultClassMapper.forClass(Foo.class);
Foo foo = new Foo();
foo.setFooString("junk");
@@ -50,7 +50,7 @@ public void testSimpleProperty_StringValue_MapsToDocument() throws Exception {
public void testListOfPrimitives_EmptyList_EmptyListInDocument() throws Exception {
System.out.println("testListOfPrimitives_EmptyList_EmptyListInDocument");
- ObjectToVertexMapper<Foo> mapper = ObjectToVertexMapper.forClass(Foo.class);
+ ClassMapper<Foo> mapper = DefaultClassMapper.forClass(Foo.class);
Foo foo = new Foo();
@@ -68,7 +68,7 @@ public void testListOfPrimitives_EmptyList_EmptyListInDocument() throws Exceptio
public void testListOfPrimitives_HasValues_ValuesMappedToDocument() throws Exception {
System.out.println("testListOfPrimitives_HasValues_ValuesMappedToDocument");
- ObjectToVertexMapper<Foo> mapper = ObjectToVertexMapper.forClass(Foo.class);
+ ClassMapper<Foo> mapper = DefaultClassMapper.forClass(Foo.class);
Foo foo = new Foo();
foo.addFooInt(2);
foo.addFooInt(7);
@@ -89,7 +89,7 @@ public void testListOfPrimitives_HasValues_ValuesMappedToDocument() throws Excep
public void testUnboxedPrimitive_Double_ValueMappedToDocument() throws Exception {
System.out.println("testUnboxedPrimitive_Double_ValueMappedToDocument");
- ObjectToVertexMapper<Bar> mapper = ObjectToVertexMapper.forClass(Bar.class);
+ ClassMapper<Bar> mapper = DefaultClassMapper.forClass(Bar.class);
Bar bar = new Bar();
bar.barDouble = 42.8;
@@ -107,7 +107,7 @@ public void testUnboxedPrimitive_Double_ValueMappedToDocument() throws Exception
public void testEnum_HasValue_ValueMappedToDocument() throws Exception {
System.out.println("testEnum_HasValue_ValueMappedToDocument");
- ObjectToVertexMapper<Bar> mapper = ObjectToVertexMapper.forClass(Bar.class);
+ ClassMapper<Bar> mapper = DefaultClassMapper.forClass(Bar.class);
Bar bar = new Bar();
bar.barEnum = BarEnum.BAR_1;
@@ -126,7 +126,7 @@ public void testEnum_HasValue_ValueMappedToDocument() throws Exception {
public void testSimpleProperty_StringValue_MapsToObject() throws Exception {
System.out.println("testSimpleProperty_StringValue_MapsToObject");
- ObjectToVertexMapper<Foo> mapper = ObjectToVertexMapper.forClass(Foo.class);
+ ClassMapper<Foo> mapper = DefaultClassMapper.forClass(Foo.class);
ODocument doc = new ODocument();
doc.field("fooString", "some junk");
@@ -143,7 +143,7 @@ public void testSimpleProperty_StringValue_MapsToObject() throws Exception {
public void testListOfPrimitives_EmptyListInDocument_EmptyListInObject() throws Exception {
System.out.println("testListOfPrimitives_EmptyListInDocument_EmptyListInObject");
- ObjectToVertexMapper<Foo> mapper = ObjectToVertexMapper.forClass(Foo.class);
+ ClassMapper<Foo> mapper = DefaultClassMapper.forClass(Foo.class);
ODocument doc = new ODocument();
List<Integer> iList = new ArrayList<>();
@@ -162,7 +162,7 @@ public void testListOfPrimitives_EmptyListInDocument_EmptyListInObject() throws
public void testListOfPrimitives_HasValues_ValuesMappedToObject() throws Exception {
System.out.println("testListOfPrimitives_HasValues_ValuesMappedToObject");
- ObjectToVertexMapper<Foo> mapper = ObjectToVertexMapper.forClass(Foo.class);
+ ClassMapper<Foo> mapper = DefaultClassMapper.forClass(Foo.class);
ODocument doc = new ODocument();
List<Integer> iList = Arrays.asList(17, 4, 23);
@@ -182,7 +182,7 @@ public void testListOfPrimitives_HasValues_ValuesMappedToObject() throws Excepti
public void testUnboxedPrimitive_Double_ValueMappedToObject() throws Exception {
System.out.println("testUnboxedPrimitive_Double_ValueMappedToObject");
- ObjectToVertexMapper<Bar> mapper = ObjectToVertexMapper.forClass(Bar.class);
+ ClassMapper<Bar> mapper = DefaultClassMapper.forClass(Bar.class);
ODocument doc = new ODocument();
doc.field("barDouble", 23.7);
@@ -199,7 +199,7 @@ public void testUnboxedPrimitive_Double_ValueMappedToObject() throws Exception {
public void testEnum_HasValue_ValueMappedToObject() throws Exception {
System.out.println("testEnum_HasValue_ValueMappedToObject");
- ObjectToVertexMapper<Bar> mapper = ObjectToVertexMapper.forClass(Bar.class);
+ ClassMapper<Bar> mapper = DefaultClassMapper.forClass(Bar.class);
ODocument doc = new ODocument();
doc.field("barEnum", BarEnum.BAR_2);
@@ -219,7 +219,7 @@ public void testValueWithAdapter_HasValue_AdapterMarshalsValue() throws Exceptio
Bar bar = new Bar();
bar.reverseMe = "Hello World!";
- ObjectToVertexMapper<Bar> mapper = ObjectToVertexMapper.forClass(Bar.class);
+ ClassMapper<Bar> mapper = DefaultClassMapper.forClass(Bar.class);
//act
ODocument doc = new ODocument();
@@ -235,7 +235,7 @@ public void testValueWithAdapter_HasValue_AdapterMarshalsValue() throws Exceptio
public void testValueWithAdapter_DocumentHasValue_AdapterUnmarshalsValue() throws Exception {
System.out.println("testValueWithAdapter_DocumentHasValue_AdapterUnmarshalsValue");
- ObjectToVertexMapper<Bar> mapper = ObjectToVertexMapper.forClass(Bar.class);
+ ClassMapper<Bar> mapper = DefaultClassMapper.forClass(Bar.class);
ODocument doc = new ODocument();
doc.field("rvs", "!dlroW olleH");
@@ -256,7 +256,7 @@ public void testValueWithAdapter_DocumentHasValue_AdapterUnmarshalsValue() throw
public void testEmbeddedObject_ObjectIsNull_NoValueMappedToDocument() throws Exception {
System.out.println("testEmbeddedObject_ObjectIsNull_NoValueMappedToDocument");
- ObjectToVertexMapper<Bar> mapper = ObjectToVertexMapper.forClass(Bar.class);
+ ClassMapper<Bar> mapper = DefaultClassMapper.forClass(Bar.class);
ODocument doc = new ODocument();
@@ -273,7 +273,7 @@ public void testEmbeddedObject_ObjectIsNull_NoValueMappedToDocument() throws Exc
public void testEmbeddedObject_ObjectIsNotNull_NewODocumentMappedToDocument() throws Exception {
System.out.println("testEmbeddedObject_ObjectIsNotNull_NewODocumentMappedToDocument");
- ObjectToVertexMapper<Bar> mapper = ObjectToVertexMapper.forClass(Bar.class);
+ ClassMapper<Bar> mapper = DefaultClassMapper.forClass(Bar.class);
ODocument doc = new ODocument();
@@ -294,7 +294,7 @@ public void testEmbeddedObject_ObjectIsNotNull_NewODocumentMappedToDocument() th
public void testEmbeddedObject_DocHadEmbeddedDocument_EmbeddedDocIsUpdated() throws Exception {
System.out.println("testEmbeddedObject_DocHadEmbeddedDocument_EmbeddedDocIsUpdated");
- ObjectToVertexMapper<Bar> mapper = ObjectToVertexMapper.forClass(Bar.class);
+ ClassMapper<Bar> mapper = DefaultClassMapper.forClass(Bar.class);
ODocument doc = new ODocument();
ODocument embedded = new ODocument();
@@ -318,7 +318,7 @@ public void testEmbeddedObject_DocHadEmbeddedDocument_EmbeddedDocIsUpdated() thr
public void testEmbeddedObject_DocHadEmbeddedObject_EmbeddedObjectIsCleared() throws Exception {
System.out.println("testEmbeddedObject_DocHadEmbeddedObject_EmbeddedObjectIsCleared");
- ObjectToVertexMapper<Bar> mapper = ObjectToVertexMapper.forClass(Bar.class);
+ ClassMapper<Bar> mapper = DefaultClassMapper.forClass(Bar.class);
ODocument doc = new ODocument();
ODocument embedded = new ODocument();
@@ -341,7 +341,7 @@ public void testEmbeddedObject_DocHadEmbeddedObject_EmbeddedObjectIsCleared() th
public void testEmbeddedObject_DocHasNoValue_UnmarshalledToNull() throws Exception {
System.out.println("testEmbeddedObject_DocHasNoValue_UnmarshalledToNull");
- ObjectToVertexMapper<Bar> mapper = ObjectToVertexMapper.forClass(Bar.class);
+ ClassMapper<Bar> mapper = DefaultClassMapper.forClass(Bar.class);
ODocument doc = new ODocument();
@@ -359,7 +359,7 @@ public void testEmbeddedObject_DocHasNoValue_UnmarshalledToNull() throws Excepti
public void testEmbeddedObject_DocHasValueForField_NewObjectCreatedAndSet() throws Exception {
System.out.println("testEmbeddedObject_ObjectIsNotNull_NewODocumentMappedToDocument");
- ObjectToVertexMapper<Bar> mapper = ObjectToVertexMapper.forClass(Bar.class);
+ ClassMapper<Bar> mapper = DefaultClassMapper.forClass(Bar.class);
ODocument doc = new ODocument();
@@ -388,7 +388,7 @@ public void testEmbeddedCollection_CollectionIsEmpty_EmptyListInDocument() throw
Baz baz = new Baz();
- ObjectToVertexMapper<Baz> mapper = ObjectToVertexMapper.forClass(Baz.class);
+ ClassMapper<Baz> mapper = DefaultClassMapper.forClass(Baz.class);
//act
ODocument doc = new ODocument();
@@ -410,7 +410,7 @@ public void testEmbeddedCollection_OneItem_OneDocumentInList() throws Exception
q.quxInt = 9;
baz.getQuxes().add(q);
- ObjectToVertexMapper<Baz> mapper = ObjectToVertexMapper.forClass(Baz.class);
+ ClassMapper<Baz> mapper = DefaultClassMapper.forClass(Baz.class);
//act
ODocument doc = new ODocument();
@@ -456,7 +456,7 @@ public void testEmbeddedCollection_MultipleItemsInDocumentAlready_DocumentIsUpda
ODocument doc = new ODocument();
doc.field("Q", new ArrayList<>(Arrays.asList(q1doc, q3doc)));
- ObjectToVertexMapper<Baz> mapper = ObjectToVertexMapper.forClass(Baz.class);
+ ClassMapper<Baz> mapper = DefaultClassMapper.forClass(Baz.class);
//act
mapper.copyPropertiesToRecord(baz, doc);
@@ -484,7 +484,7 @@ public void testEmbeddedCollection_NullValueInDocument_ClearsList() throws Excep
ODocument doc = new ODocument();
- ObjectToVertexMapper<Baz> mapper = ObjectToVertexMapper.forClass(Baz.class);
+ ClassMapper<Baz> mapper = DefaultClassMapper.forClass(Baz.class);
Baz baz = new Baz();
baz.getQuxes().add(new EmbeddedQux()); //add something that should be cleared
@@ -515,7 +515,7 @@ public void testEmbeddedCollection_DocumentHasMultipleValues_AddsToList() throws
doc.field("Q", new ArrayList<>(Arrays.asList(q1doc, q2doc)));
- ObjectToVertexMapper<Baz> mapper = ObjectToVertexMapper.forClass(Baz.class);
+ ClassMapper<Baz> mapper = DefaultClassMapper.forClass(Baz.class);
Baz baz = new Baz();
baz.getQuxes().add(new EmbeddedQux()); //add something that should be cleared
@@ -544,7 +544,7 @@ public void testGetEmbeddedDocumentIDs_NoEmbeddedDocuments_ReturnsNull() throws
ODocument doc = new ODocument();
- ObjectToVertexMapper<Baz> mapper = ObjectToVertexMapper.forClass(Baz.class);
+ ClassMapper<Baz> mapper = DefaultClassMapper.forClass(Baz.class);
//act
Set<ORID> ids = mapper.getEmbeddedDocumentIDs(doc);
@@ -564,7 +564,7 @@ public void testGetEmbeddedDocumentIDs_OneEmbeddedDocument_ReturnsItsID() throws
doc.field("barQux", qDoc);
- ObjectToVertexMapper<Bar> mapper = ObjectToVertexMapper.forClass(Bar.class);
+ ClassMapper<Bar> mapper = DefaultClassMapper.forClass(Bar.class);
//act
Set<ORID> ids = mapper.getEmbeddedDocumentIDs(doc);
@@ -592,7 +592,7 @@ public void testGetEmbeddedDocumentIDs_OneEmbeddedListOfDocuments_ReturnsAllIDs(
doc.field("Q", new ArrayList<>(Arrays.asList(q1Doc, q2Doc)));
- ObjectToVertexMapper<Baz> mapper = ObjectToVertexMapper.forClass(Baz.class);
+ ClassMapper<Baz> mapper = DefaultClassMapper.forClass(Baz.class);
//act
Set<ORID> ids = mapper.getEmbeddedDocumentIDs(doc);
View
19 ...orientdb/graph/mapper/IdResolverTest.java → ...b/graph/mapper/DefaultIdResolverTest.java
@@ -6,9 +6,8 @@
import com.orientechnologies.orient.core.id.ORID;
import com.orientechnologies.orient.core.id.ORecordId;
-import org.junit.Test;
import static org.junit.Assert.*;
-import org.springframework.data.orientdb.testdata.Bar;
+import org.junit.Test;
import org.springframework.data.orientdb.testdata.Baz;
import org.springframework.data.orientdb.testdata.Foo;
@@ -16,14 +15,14 @@
*
* @author Gordon
*/
-public class IdResolverTest {
+public class DefaultIdResolverTest {
@Test
public void testForClass_ClassHasObjectId_ResolverExists() throws Exception {
System.out.println("testForClass_ClassHasObjectId_ResolverExists");
//act
- IdResolver<Foo> resolver = IdResolver.forClass(Foo.class);
+ DefaultIdResolver<Foo> resolver = DefaultIdResolver.forClass(Foo.class);
//assert
assertNotNull("Foo should have an ID", resolver);
@@ -33,7 +32,7 @@ public void testForClass_ClassHasObjectId_ResolverExists() throws Exception {
public void testGetIdClass_ClassIsObject_ReturnsObject() throws Exception {
System.out.println("testGetIdClass_ClassIsObject_ReturnsObject");
- IdResolver<Foo> resolver = IdResolver.forClass(Foo.class);
+ DefaultIdResolver<Foo> resolver = DefaultIdResolver.forClass(Foo.class);
//act
Class<?> clazz = resolver.getIdClass();
@@ -46,7 +45,7 @@ public void testGetIdClass_ClassIsObject_ReturnsObject() throws Exception {
public void testGetIdClass_IdIsProperty_ReturnsProperClass() throws Exception {
System.out.println("testGetIdClass_IdIsProperty_ReturnsProperClass");
- IdResolver<Baz> resolver = IdResolver.forClass(Baz.class);
+ DefaultIdResolver<Baz> resolver = DefaultIdResolver.forClass(Baz.class);
//act
Class<?> clazz = resolver.getIdClass();
@@ -61,7 +60,7 @@ public void testGetValue_ObjectId_GetsValue() throws Exception {
ORID idObj = new ORecordId();
Foo foo = new Foo(idObj);
- IdResolver<Foo> resolver = IdResolver.forClass(Foo.class);
+ DefaultIdResolver<Foo> resolver = DefaultIdResolver.forClass(Foo.class);
//act
Object id = resolver.getId(foo);
@@ -75,7 +74,7 @@ public void testGetValue_StringId_GetsValue() throws Exception {
System.out.println("testGetValue_StringId_GetsValue");
Baz baz = new Baz("#14:2");
- IdResolver<Baz> resolver = IdResolver.forClass(Baz.class);
+ DefaultIdResolver<Baz> resolver = DefaultIdResolver.forClass(Baz.class);
//act
Object id = resolver.getId(baz);
@@ -90,7 +89,7 @@ public void testSetValue_ObjectId_SetsValue() throws Exception {
Foo foo = new Foo(new Object());
- IdResolver<Foo> resolver = IdResolver.forClass(Foo.class);
+ DefaultIdResolver<Foo> resolver = DefaultIdResolver.forClass(Foo.class);
//act
ORID idObj = new ORecordId();
@@ -105,7 +104,7 @@ public void testSetValue_StringId_SetsValue() throws Exception {
System.out.println("testSetValue_StringId_SetsValue");
Baz baz = new Baz("junk");
- IdResolver<Baz> resolver = IdResolver.forClass(Baz.class);
+ DefaultIdResolver<Baz> resolver = DefaultIdResolver.forClass(Baz.class);
//act
resolver.setId(baz, new ORecordId("#2:7"));
Please sign in to comment.
Something went wrong with that request. Please try again.