Permalink
Browse files

improve graph connection recognition for repositories

  • Loading branch information...
xvik committed Aug 13, 2015
1 parent f519fca commit e9c8f79cf666b92f9db40ae5dbfb8678e6721c6f
View
@@ -1,3 +1,5 @@
+* Improve graph connection recognition on repository methods: recognize all graph types implementing Vertex or Edge (e.g. OrientVertex, OrientEdge)
+
### 3.1.0 (2015-07-04)
* Add @RidElVar parameter extension to bind rid directly into query from any source (string, object, document, vertex or collections).
* Add @CaseInsensitive scheme field extension: sets collate ci for case insensitive fields comparison in queries. Also should be used for creation of ci indexes.
@@ -1,6 +1,5 @@
package ru.vyarus.guice.persist.orient.repository.core.executor.impl;
-import com.google.common.collect.ImmutableList;
import com.google.inject.Provider;
import com.orientechnologies.orient.core.command.OCommandRequest;
import com.tinkerpop.blueprints.Edge;
@@ -11,7 +10,6 @@
import javax.inject.Inject;
import javax.inject.Singleton;
-import java.util.List;
/**
* Graph connection repository executor.
@@ -22,7 +20,6 @@
@Singleton
public class GraphRepositoryExecutor implements RepositoryExecutor {
- private static final List<Class> ACCEPT_TYPES = ImmutableList.<Class>of(Vertex.class, Edge.class);
private final Provider<OrientBaseGraph> provider;
@Inject
@@ -32,7 +29,7 @@ public GraphRepositoryExecutor(final Provider<OrientBaseGraph> provider) {
@Override
public boolean accept(final Class<?> returnType) {
- return ACCEPT_TYPES.contains(returnType);
+ return Edge.class.isAssignableFrom(returnType) || Vertex.class.isAssignableFrom(returnType);
}
@Override
@@ -4,6 +4,7 @@ import com.google.inject.Inject
import com.orientechnologies.orient.core.record.impl.ODocument
import com.orientechnologies.orient.object.db.OObjectDatabaseTx
import com.tinkerpop.blueprints.Vertex
+import com.tinkerpop.blueprints.impls.orient.OrientVertex
import ru.vyarus.guice.persist.orient.AbstractTest
import ru.vyarus.guice.persist.orient.db.transaction.template.SpecificTxAction
import ru.vyarus.guice.persist.orient.db.transaction.template.TxAction
@@ -53,6 +54,11 @@ class DbRecognitionExecutionTest extends AbstractTest {
List<Vertex> resVert = dao.selectAllAsVertex();
then:
resVert.size() == 1
+
+ when: "graph select"
+ List<OrientVertex> resOVert = dao.selectAllAsOrientVertex();
+ then:
+ resVert.size() == 1
}
def "Select without type"() {
@@ -2,6 +2,7 @@ package ru.vyarus.guice.persist.orient.repository.command.descriptor
import com.orientechnologies.orient.core.record.impl.ODocument
import com.tinkerpop.blueprints.Vertex
+import com.tinkerpop.blueprints.impls.orient.OrientVertex
import ru.vyarus.guice.persist.orient.repository.core.AbstractRepositoryDefinitionTest
import ru.vyarus.guice.persist.orient.repository.core.executor.impl.DocumentRepositoryExecutor
import ru.vyarus.guice.persist.orient.repository.core.executor.impl.GraphRepositoryExecutor
@@ -60,6 +61,13 @@ class DbTypeRecognitionTest extends AbstractRepositoryDefinitionTest {
desc.result.returnType == ResultType.COLLECTION
desc.result.entityType == Vertex
+ when: "graph db method, detection by list generic with derivative type"
+ desc = lookup(DbRecognitionCases.getMethod("selectAllAsOrientVertex"))
+ then: "graph provider recognized"
+ desc.executor.class == GraphRepositoryExecutor
+ desc.result.returnType == ResultType.COLLECTION
+ desc.result.entityType == OrientVertex
+
when: "no return type, default document"
desc = lookup(DbRecognitionCases.getMethod("update"))
then: "document provider recognized"
@@ -3,8 +3,10 @@ package ru.vyarus.guice.persist.orient.repository.command.support
import com.google.inject.ProvidedBy
import com.google.inject.internal.DynamicSingletonProvider
import com.google.inject.persist.Transactional
+import com.orientechnologies.orient.core.Orient
import com.orientechnologies.orient.core.record.impl.ODocument
import com.tinkerpop.blueprints.Vertex
+import com.tinkerpop.blueprints.impls.orient.OrientVertex
import ru.vyarus.guice.persist.orient.db.DbType
import ru.vyarus.guice.persist.orient.repository.command.query.Query
import ru.vyarus.guice.persist.orient.support.model.Model
@@ -39,6 +41,10 @@ interface DbRecognitionCases {
@Query("select from Model")
List<Vertex> selectAllAsVertex()
+ // check derivative types recognition
+ @Query("select from Model")
+ List<OrientVertex> selectAllAsOrientVertex()
+
// document db by default
@Query("update Model set name='changed'")
void update()

0 comments on commit e9c8f79

Please sign in to comment.