Skip to content
Browse files

Query now performs no conversion if the requested return type is ODoc…

…ument

Signed-off-by: gburgett <gordon.burgett@gmail.com>
  • Loading branch information...
1 parent da58368 commit 383db8a8d3585114329fc7459d99c321211b1917 @gburgett gburgett committed
View
60 ...ons/src/main/java/org/springframework/data/orientdb/graph/core/OrientGraphOperations.java
@@ -55,12 +55,14 @@ public ODocument insertSingleVertex(Object vertex) {
throw new IllegalArgumentException("vertex already exists at ID " + id);
}
- return internalCreateVertex(vertex, mapper, id);
+ return internalCreateVertex(vertex, mapper);
}
- private ODocument internalCreateVertex(Object vertex, ClassMapper mapper, ORID id){
+ private ODocument internalCreateVertex(Object vertex, ClassMapper mapper){
OGraphDatabase db = this.dbManager.getCurrentDatabase();
+ ORID id;
+
ODocument record;
try{
record = db.createVertex(mapper.getOClassName());
@@ -69,7 +71,7 @@ private ODocument internalCreateVertex(Object vertex, ClassMapper mapper, ORID i
if(ex.getMessage().startsWith("The class ") && ex.getMessage().endsWith(" was not found")){
mapper.createClass(db.getMetadata().getSchema());
//try again
- return internalCreateVertex(vertex, mapper, id);
+ return internalCreateVertex(vertex, mapper);
}
//else
throw ex;
@@ -89,23 +91,23 @@ public ODocument insertSingleEdge(Object edge) {
if(edge == null)
throw new IllegalArgumentException("vertex cannot be null");
- ClassMapper mapper = ClassMapperFactory.instance().getMapper(edge.getClass());
- if(mapper.isVertex()){
- throw new IllegalArgumentException("object must be annotated as an Edge");
- }
-
- ORID id = mapper.getIdResolver().getId(edge);
- if(id != null){
- throw new IllegalArgumentException("vertex already exists at ID " + id);
- }
-
- EdgeRelationMapper relMapper = EdgeRelationMapper.forClass(edge.getClass());
-
- Object inVertex = relMapper.getInVertex();
- Object outVertex = relMapper.getOutVertex();
- if(inVertex == null || outVertex == null)
- throw new IllegalArgumentException("The edge to insert must be associated to two vertices");
-
+// ClassMapper mapper = ClassMapperFactory.instance().getMapper(edge.getClass());
+// if(mapper.isVertex()){
+// throw new IllegalArgumentException("object must be annotated as an Edge");
+// }
+//
+// ORID id = mapper.getIdResolver().getId(edge);
+// if(id != null){
+// throw new IllegalArgumentException("vertex already exists at ID " + id);
+// }
+//
+// EdgeRelationMapper relMapper = EdgeRelationMapper.forClass(edge.getClass());
+//
+// Object inVertex = relMapper.getInVertex();
+// Object outVertex = relMapper.getOutVertex();
+// if(inVertex == null || outVertex == null)
+// throw new IllegalArgumentException("The edge to insert must be associated to two vertices");
+//
//TODO: make sure this is actually possible before I do anything more on it.
throw new UnsupportedOperationException("Not supported yet");
@@ -223,7 +225,7 @@ public ODocument updateSingleVertex(final Object vertex) {
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>() {
+ return OrientGraphOperations.doInTransaction(db, new Function1<OGraphDatabase, ODocument>() {
@Override
public ODocument apply(OGraphDatabase db) {
ODocument record = db.load(id);
@@ -289,7 +291,7 @@ public ODocument saveSingleVertex(final Object vertex){
final ORID id = mapper.getIdResolver().getId(vertex);
if(id == null){
- return internalCreateVertex(vertex, mapper, id);
+ return internalCreateVertex(vertex, mapper);
}
return OrientGraphOperations.doInTransaction(this.dbManager.getCurrentDatabase(), new Function1<OGraphDatabase, ODocument>() {
@@ -323,7 +325,7 @@ public ODocument apply(OGraphDatabase db) {
}
}
else{
- return internalCreateVertex(vertex, mapper, id);
+ return internalCreateVertex(vertex, mapper);
}
return record;
@@ -438,16 +440,22 @@ private static ORID toOrientId(Object id){
@Override
public <T> Iterable<T> query(String sql, Class<T> clazz, Object... args){
+ if(clazz == null)
+ throw new IllegalArgumentException("clazz cannot be null");
OGraphDatabase db = this.dbManager.getCurrentDatabase();
- ClassMapper<T> mapper =
- clazz == null ? null : ClassMapperFactory.instance().getMapper(clazz);
+ ClassMapper<T> mapper = null;
+ if(!ODocument.class.equals(clazz))
+ mapper = ClassMapperFactory.instance().getMapper(clazz);
List<ODocument> results = db.query(new OSQLSynchQuery<ODocument>(sql), args);
- if(results == null || mapper == null)
+ if(results == null)
return Collections.EMPTY_LIST;
+ if(ODocument.class.equals(clazz))
+ return (Iterable<T>)results;
+
return convertingIterable(clazz, mapper, results);
}
View
6 ...ons/src/main/java/org/springframework/data/orientdb/graph/mapper/AbstractClassMapper.java
@@ -181,6 +181,12 @@ else if(!this.clazz.isAssignableFrom(toCreate)){
}
+ /**
+ * Gets the discriminator convention for the mapped class and
+ * subclasses. The discriminator convention knows how to create
+ * instances of subclasses for given ODocuments.
+ * @return A discriminator convention instance, cannot be null.
+ */
public DiscriminatorConvention getDiscriminatorConvention() {
return discriminator;
}
View
11 ...tdb-commons/src/main/java/org/springframework/data/orientdb/graph/mapper/ClassMapper.java
@@ -62,14 +62,13 @@
*/
public void marshalToRecord(T object, ODocument record);
- public T unmarshal(ODocument record);
-
/**
- * Gets the discriminator convention for the mapped class and
- * subclasses. The discriminator convention knows how to create
- * instances of subclasses for given ODocuments.
- * @return A discriminator convention instance, cannot be null.
+ * Unmarshals the given ODocument as a new instance of the mapped class.
+ * @param record The record to unmarshal.
+ * @return A new instance of the object.
*/
+ public T unmarshal(ODocument record);
+
/**
* Gets the set of the IDs of all the embedded documents in the given database

0 comments on commit 383db8a

Please sign in to comment.
Something went wrong with that request. Please try again.