├── .gitignore ├── README.md ├── build.gradle ├── settings.gradle ├── spring-data-gremlin-core ├── build.gradle └── src │ ├── main │ └── java │ │ └── org │ │ └── springframework │ │ └── data │ │ └── gremlin │ │ ├── annotation │ │ ├── Dynamic.java │ │ ├── Edge.java │ │ ├── Embed.java │ │ ├── Embeddable.java │ │ ├── Enumerated.java │ │ ├── EnumeratedCollection.java │ │ ├── FromVertex.java │ │ ├── Id.java │ │ ├── Ignore.java │ │ ├── Index.java │ │ ├── Link.java │ │ ├── LinkVia.java │ │ ├── Property.java │ │ ├── PropertyOverride.java │ │ ├── Query.java │ │ ├── ToVertex.java │ │ └── Vertex.java │ │ ├── config │ │ ├── EnableGremlinRepositories.java │ │ ├── GremlinRepositoryConfigExtension.java │ │ └── GremlinRepositoryRegistrar.java │ │ ├── query │ │ ├── AbstractGremlinQuery.java │ │ ├── AbstractNativeGremlinQuery.java │ │ ├── CompositeResult.java │ │ ├── GremlinQueryCreator.java │ │ ├── GremlinQueryLookupStrategy.java │ │ ├── GremlinQueryMethod.java │ │ ├── PartTreeGremlinQuery.java │ │ ├── StringBasedGremlinQuery.java │ │ └── execution │ │ │ ├── AbstractGremlinExecution.java │ │ │ ├── CollectionExecution.java │ │ │ ├── CompositeExecution.java │ │ │ ├── CountExecution.java │ │ │ ├── MapExecution.java │ │ │ ├── ModifyExecution.java │ │ │ └── SingleEntityExecution.java │ │ ├── repository │ │ ├── GremlinGraphAdapter.java │ │ ├── GremlinRepository.java │ │ ├── GremlinRepositoryContext.java │ │ ├── GremlinRepositoryWithNativeSupport.java │ │ └── SimpleGremlinRepository.java │ │ ├── schema │ │ ├── GremlinBeanPostProcessor.java │ │ ├── GremlinDynamicSchema.java │ │ ├── GremlinEdgeSchema.java │ │ ├── GremlinSchema.java │ │ ├── GremlinSchemaFactory.java │ │ ├── GremlinVertexSchema.java │ │ ├── generator │ │ │ ├── AnnotatedSchemaGenerator.java │ │ │ ├── BasicSchemaGenerator.java │ │ │ ├── DefaultSchemaGenerator.java │ │ │ ├── SchemaGenerator.java │ │ │ └── SchemaGeneratorException.java │ │ ├── property │ │ │ ├── GremlinAdjacentProperty.java │ │ │ ├── GremlinCollectionProperty.java │ │ │ ├── GremlinCollectionViaProperty.java │ │ │ ├── GremlinDynamicProperty.java │ │ │ ├── GremlinLinkProperty.java │ │ │ ├── GremlinLinkViaProperty.java │ │ │ ├── GremlinProperty.java │ │ │ ├── GremlinPropertyFactory.java │ │ │ ├── GremlinRelatedProperty.java │ │ │ ├── accessor │ │ │ │ ├── AbstractGremlinFieldPropertyAccessor.java │ │ │ │ ├── GremlinDynamicMapPropertyAccessor.java │ │ │ │ ├── GremlinEnumOrdinalFieldPropertyAccessor.java │ │ │ │ ├── GremlinEnumStringCollectionFieldPropertyAccessor.java │ │ │ │ ├── GremlinEnumStringFieldPropertyAccessor.java │ │ │ │ ├── GremlinFieldPropertyAccessor.java │ │ │ │ ├── GremlinIdFieldPropertyAccessor.java │ │ │ │ ├── GremlinIdMapPropertyAccessor.java │ │ │ │ ├── GremlinIdPropertyAccessor.java │ │ │ │ ├── GremlinJSONFieldPropertyAccessor.java │ │ │ │ ├── GremlinMapPropertyAccessor.java │ │ │ │ ├── GremlinPropertyAccessor.java │ │ │ │ ├── GremlinPropertyFieldAccessor.java │ │ │ │ └── GremlinSerializableFieldPropertyAccessor.java │ │ │ ├── encoder │ │ │ │ └── GremlinPropertyEncoder.java │ │ │ └── mapper │ │ │ │ ├── GremlinAdjacentPropertyMapper.java │ │ │ │ ├── GremlinCollectionPropertyMapper.java │ │ │ │ ├── GremlinCollectionViaPropertyMapper.java │ │ │ │ ├── GremlinEncodedPropertyMapper.java │ │ │ │ ├── GremlinLinkPropertyMapper.java │ │ │ │ ├── GremlinLinkViaPropertyMapper.java │ │ │ │ ├── GremlinObjectMapperException.java │ │ │ │ ├── GremlinPropertyMapper.java │ │ │ │ └── GremlinStandardPropertyMapper.java │ │ └── writer │ │ │ ├── AbstractSchemaWriter.java │ │ │ ├── SchemaWriter.java │ │ │ └── SchemaWriterException.java │ │ ├── support │ │ ├── GremlinMetamodelEntityInformation.java │ │ ├── GremlinRepositoryFactory.java │ │ └── GremlinRepositoryFactoryBean.java │ │ ├── tx │ │ ├── AbstractGremlinGraphFactory.java │ │ ├── GremlinGraphFactory.java │ │ ├── GremlinTransaction.java │ │ └── GremlinTransactionManager.java │ │ └── utils │ │ └── GenericsUtil.java │ └── test │ ├── java │ └── org │ │ └── springframework │ │ └── data │ │ └── gremlin │ │ └── schema │ │ ├── GremlinEnumCollectionSetFieldAccessorTest.java │ │ ├── GremlinEnumOrdinalFieldAccessorTest.java │ │ ├── GremlinEnumStringFieldAccessorTest.java │ │ ├── GremlinFieldAccessorTest.java │ │ └── property │ │ ├── accessor │ │ ├── GremlinJSONFieldPropertyAccessorTest.java │ │ ├── Rectangle.java │ │ └── RectangleMixIn.java │ │ └── mapper │ │ └── GremlinLinkToPropertyMapperTest.java │ └── resources │ └── application.properties ├── spring-data-gremlin-orientdb ├── build.gradle └── src │ ├── main │ └── java │ │ └── org │ │ └── springframework │ │ └── data │ │ └── gremlin │ │ ├── query │ │ └── orientdb │ │ │ └── NativeOrientdbGremlinQuery.java │ │ ├── repository │ │ └── orientdb │ │ │ ├── OrientDBGraphAdapter.java │ │ │ └── OrientDBGremlinRepository.java │ │ ├── schema │ │ ├── property │ │ │ └── encoder │ │ │ │ └── orientdb │ │ │ │ └── OrientDbIdEncoder.java │ │ └── writer │ │ │ └── orientdb │ │ │ └── OrientDbSchemaWriter.java │ │ └── tx │ │ └── orientdb │ │ └── OrientDBGremlinGraphFactory.java │ └── test │ └── java │ └── org │ └── springframework │ └── data │ └── gremlin │ ├── object │ └── tests │ │ └── orientdb │ │ ├── core │ │ ├── OrientDB_Core_AddressRepositoryTest.java │ │ ├── OrientDB_Core_EdgeRepositoryTest.java │ │ ├── OrientDB_Core_PersonRepositoryTest.java │ │ ├── OrientDB_Core_SpatialRepositoryTest.java │ │ ├── OrientDB_Core_TestConfiguration.java │ │ └── OrientDB_Core_TransactionRepositoryTest.java │ │ ├── jpa │ │ ├── OrientDB_JPA_AddressRepositoryTest.java │ │ ├── OrientDB_JPA_PersonRepositoryTest.java │ │ ├── OrientDB_JPA_SpatialRepositoryTest.java │ │ ├── OrientDB_JPA_TestConfiguration.java │ │ └── OrientDB_JPA_TransactionRepositoryTest.java │ │ └── neo4j │ │ ├── OrientDB_Neo4j_AddressRepositoryTest.java │ │ ├── OrientDB_Neo4j_EdgeRepositoryTest.java │ │ ├── OrientDB_Neo4j_PersonRepositoryTest.java │ │ ├── OrientDB_Neo4j_SpatialRepositoryTest.java │ │ ├── OrientDB_Neo4j_TestConfiguration.java │ │ └── OrientDB_Neo4j_TransactionRepositoryTest.java │ ├── schema │ └── writer │ │ └── orientdb │ │ └── OrientDbSchemaWriterTest.java │ └── tx │ └── orientdb │ └── OrientDBGremlinGraphFactoryTest.java ├── spring-data-gremlin-schemagen-jpa ├── build.gradle └── src │ ├── main │ └── java │ │ └── org │ │ └── springframework │ │ └── data │ │ └── gremlin │ │ └── schema │ │ └── generator │ │ └── jpa │ │ ├── JpaGremlinPropertyFactory.java │ │ └── JpaSchemaGenerator.java │ └── test │ └── java │ └── org │ └── springframework │ └── data │ └── gremlin │ └── schema │ └── generator │ └── jpa │ └── JpaSchemaGeneratorTest.java ├── spring-data-gremlin-schemagen-neo4j ├── build.gradle └── src │ └── main │ └── java │ └── org │ └── springframework │ └── data │ └── gremlin │ └── schema │ └── generator │ └── Neo4jSchemaGenerator.java ├── spring-data-gremlin-test ├── build.gradle └── src │ └── main │ └── java │ └── org │ └── springframework │ └── data │ └── gremlin │ ├── object │ ├── core │ │ ├── TestService.java │ │ ├── domain │ │ │ ├── Address.java │ │ │ ├── Animal.java │ │ │ ├── Area.java │ │ │ ├── Bipod.java │ │ │ ├── Country.java │ │ │ ├── House.java │ │ │ ├── Likes.java │ │ │ ├── Located.java │ │ │ ├── Location.java │ │ │ ├── Meeting.java │ │ │ ├── Person.java │ │ │ ├── Pet.java │ │ │ ├── PetMxin.java │ │ │ └── Place.java │ │ └── repository │ │ │ ├── AbstractAddressRepositoryTest.java │ │ │ ├── AbstractEdgeRepositoryTest.java │ │ │ ├── AbstractLocationRepositoryTest.java │ │ │ ├── AbstractPersonRepositoryTest.java │ │ │ ├── AbstractTransactionRepositoryTest.java │ │ │ ├── AddressRepository.java │ │ │ ├── BaseRepositoryTest.java │ │ │ ├── LikesRepository.java │ │ │ ├── LocatedRepository.java │ │ │ ├── LocationRepository.java │ │ │ ├── NativeLocationRepository.java │ │ │ ├── NativePersonRepository.java │ │ │ └── PersonRepository.java │ ├── jpa │ │ ├── TestService.java │ │ ├── domain │ │ │ ├── Address.java │ │ │ ├── Area.java │ │ │ ├── Country.java │ │ │ ├── Employee.java │ │ │ ├── House.java │ │ │ ├── Location.java │ │ │ ├── Person.java │ │ │ └── Pet.java │ │ └── repository │ │ │ ├── AbstractAddressRepositoryTest.java │ │ │ ├── AbstractLocationRepositoryTest.java │ │ │ ├── AbstractPersonRepositoryTest.java │ │ │ ├── AbstractTransactionRepositoryTest.java │ │ │ ├── AddressRepository.java │ │ │ ├── BaseRepositoryTest.java │ │ │ ├── LocationRepository.java │ │ │ ├── NativeLocationRepository.java │ │ │ ├── NativePersonRepository.java │ │ │ └── PersonRepository.java │ └── neo4j │ │ ├── TestService.java │ │ ├── domain │ │ ├── Address.java │ │ ├── Area.java │ │ ├── Employee.java │ │ ├── House.java │ │ ├── Likes.java │ │ ├── Located.java │ │ ├── Location.java │ │ ├── Person.java │ │ └── Pet.java │ │ └── repository │ │ ├── AbstractAddressRepositoryTest.java │ │ ├── AbstractEdgeRepositoryTest.java │ │ ├── AbstractLocationRepositoryTest.java │ │ ├── AbstractPersonRepositoryTest.java │ │ ├── AbstractTransactionRepositoryTest.java │ │ ├── AddressRepository.java │ │ ├── BaseRepositoryTest.java │ │ ├── LikesRepository.java │ │ ├── LocatedRepository.java │ │ ├── LocationRepository.java │ │ ├── NativeLocationRepository.java │ │ ├── NativePersonRepository.java │ │ └── PersonRepository.java │ └── schema │ ├── EmbeddedTestEntity.java │ ├── LinkedTestEntity.java │ ├── MultiEmbeddedTestEntity.java │ └── TestEntity.java ├── spring-data-gremlin-tinker ├── build.gradle └── src │ ├── main │ └── java │ │ └── org │ │ └── springframework │ │ └── data │ │ └── gremlin │ │ ├── repository │ │ └── tinker │ │ │ ├── TinkerGraphAdapter.java │ │ │ └── TinkerGremlinRepository.java │ │ └── tx │ │ └── tinker │ │ └── TinkerGremlinGraphFactory.java │ └── test │ └── java │ └── org │ └── springframework │ └── data │ └── gremlin │ └── object │ └── tests │ └── tinker │ ├── core │ ├── Tinker_Core_AddressRepositoryTest.java │ ├── Tinker_Core_EdgeRepositoryTest.java │ ├── Tinker_Core_PersonRepositoryTest.java │ └── Tinker_Core_TestConfiguration.java │ ├── jpa │ ├── Tinker_JPA_AddressRepositoryTest.java │ ├── Tinker_JPA_PersonRepositoryTest.java │ └── Tinker_JPA_TestConfiguration.java │ └── neo4j │ ├── Tinker_Neo4j_AddressRepositoryTest.java │ ├── Tinker_Neo4j_EdgeRepositoryTest.java │ ├── Tinker_Neo4j_PersonRepositoryTest.java │ └── Tinker_Neo4j_TestConfiguration.java └── spring-data-gremlin-titan ├── build.gradle └── src ├── main └── java │ └── org │ └── springframework │ └── data │ └── gremlin │ ├── repository │ └── titan │ │ ├── TitanGraphAdapter.java │ │ └── TitanGremlinRepository.java │ ├── schema │ └── writer │ │ └── titan │ │ └── TitanSchemaWriter.java │ └── tx │ └── titan │ └── TitanGremlinGraphFactory.java └── test └── java └── org └── springframework └── data └── gremlin └── object └── tests └── titan ├── core ├── Titan_Core_AddressRepositoryTest.java ├── Titan_Core_EdgeRepositoryTest.java ├── Titan_Core_PersonRepositoryTest.java ├── Titan_Core_TestConfiguration.java └── Titan_Core_TransactionRepositoryTest.java ├── jpa ├── Titan_JPA_AddressRepositoryTest.java ├── Titan_JPA_PersonRepositoryTest.java ├── Titan_JPA_TestConfiguration.java └── Titan_JPA_TransactionRepositoryTest.java └── neo4j ├── Titan_Neo4j_AddressRepositoryTest.java ├── Titan_Neo4j_PersonRepositoryTest.java ├── Titan_Neo4j_TestConfiguration.java └── Titan_Neo4j_TransactionRepositoryTest.java /.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include 'spring-data-gremlin-core', 'spring-data-gremlin-test', 'spring-data-gremlin-schemagen-jpa', 'spring-data-gremlin-schemagen-neo4j', 'spring-data-gremlin-orientdb', 'spring-data-gremlin-tinker', 'spring-data-gremlin-titan' 2 | rootProject.name = 'spring-data-gremlin' 3 | 4 | -------------------------------------------------------------------------------- /spring-data-gremlin-core/build.gradle: -------------------------------------------------------------------------------- 1 | task testJar(type: Jar, dependsOn: testClasses) { 2 | baseName = "test-${project.archivesBaseName}" 3 | from sourceSets.test.output 4 | } 5 | 6 | configurations { 7 | tests 8 | } 9 | 10 | artifacts { 11 | tests testJar 12 | } 13 | -------------------------------------------------------------------------------- /spring-data-gremlin-core/src/main/java/org/springframework/data/gremlin/annotation/Dynamic.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.annotation; 2 | 3 | import java.lang.annotation.*; 4 | 5 | /** 6 | * Created by gman on 12/08/15. 7 | */ 8 | @Retention(RetentionPolicy.RUNTIME) 9 | @Target(ElementType.FIELD) 10 | @Inherited 11 | public @interface Dynamic { 12 | 13 | /** 14 | * The type/name of the Vertex. If left blank the name of the Class is used. 15 | * @return 16 | */ 17 | String value() default ""; 18 | 19 | /** 20 | * pseudonym for value(). 21 | * @return 22 | */ 23 | String name() default ""; 24 | 25 | 26 | /** 27 | * pseudonym for value(). 28 | * @return 29 | */ 30 | String linkName() default ""; 31 | 32 | } 33 | -------------------------------------------------------------------------------- /spring-data-gremlin-core/src/main/java/org/springframework/data/gremlin/annotation/Edge.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.annotation; 2 | 3 | import java.lang.annotation.*; 4 | 5 | /** 6 | * Created by gman on 12/08/15. 7 | */ 8 | @Retention(RetentionPolicy.RUNTIME) 9 | @Target(ElementType.TYPE) 10 | public @interface Edge { 11 | 12 | /** 13 | * The name of the Edge. If left blank the name of the Class is used. 14 | * @return 15 | */ 16 | String value() default ""; 17 | 18 | /** 19 | * pseudonym for value(). 20 | * @return 21 | */ 22 | String name() default ""; 23 | 24 | } 25 | -------------------------------------------------------------------------------- /spring-data-gremlin-core/src/main/java/org/springframework/data/gremlin/annotation/Embed.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.annotation; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | /** 9 | * Created by gman on 12/08/15. 10 | */ 11 | @Retention(RetentionPolicy.RUNTIME) 12 | @Target({ ElementType.METHOD, ElementType.FIELD }) 13 | public @interface Embed { 14 | 15 | /** 16 | * The list of @Property to override 17 | * @return 18 | */ 19 | PropertyOverride[] propertyOverrides() default {}; 20 | 21 | } 22 | -------------------------------------------------------------------------------- /spring-data-gremlin-core/src/main/java/org/springframework/data/gremlin/annotation/Embeddable.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.annotation; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | /** 9 | * Created by gman on 12/08/15. 10 | */ 11 | @Retention(RetentionPolicy.RUNTIME) 12 | @Target(ElementType.TYPE) 13 | public @interface Embeddable { 14 | 15 | } 16 | -------------------------------------------------------------------------------- /spring-data-gremlin-core/src/main/java/org/springframework/data/gremlin/annotation/Enumerated.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.annotation; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | import java.util.Collection; 8 | import java.util.HashSet; 9 | 10 | import static org.springframework.data.gremlin.annotation.Enumerated.EnumeratedType.ORDINAL; 11 | 12 | /** 13 | * Created by gman on 12/08/15. 14 | */ 15 | @Retention(RetentionPolicy.RUNTIME) 16 | @Target({ ElementType.METHOD, ElementType.FIELD }) 17 | public @interface Enumerated { 18 | 19 | /** 20 | * (Optional) The type used in mapping an enum type. 21 | */ 22 | EnumeratedType value() default ORDINAL; 23 | 24 | enum EnumeratedType { 25 | 26 | ORDINAL(Integer.class), 27 | STRING(String.class); 28 | 29 | private final Class type; 30 | 31 | EnumeratedType(Class type) { 32 | this.type = type; 33 | } 34 | 35 | public Class getType() { 36 | return type; 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /spring-data-gremlin-core/src/main/java/org/springframework/data/gremlin/annotation/EnumeratedCollection.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.annotation; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | import java.util.Collection; 8 | import java.util.HashSet; 9 | 10 | import static org.springframework.data.gremlin.annotation.Enumerated.EnumeratedType.ORDINAL; 11 | 12 | /** 13 | * Created by gman on 12/08/15. 14 | */ 15 | @Retention(RetentionPolicy.RUNTIME) 16 | @Target({ ElementType.METHOD, ElementType.FIELD }) 17 | public @interface EnumeratedCollection { 18 | 19 | Class value() default HashSet.class; 20 | 21 | } 22 | -------------------------------------------------------------------------------- /spring-data-gremlin-core/src/main/java/org/springframework/data/gremlin/annotation/FromVertex.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.annotation; 2 | 3 | import java.lang.annotation.*; 4 | 5 | /** 6 | * Created by gman on 12/08/15. 7 | */ 8 | @Retention(RetentionPolicy.RUNTIME) 9 | @Target({ ElementType.METHOD, ElementType.FIELD }) 10 | public @interface FromVertex { } 11 | -------------------------------------------------------------------------------- /spring-data-gremlin-core/src/main/java/org/springframework/data/gremlin/annotation/Id.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.annotation; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | /** 9 | * Created by gman on 12/08/15. 10 | */ 11 | @Retention(RetentionPolicy.RUNTIME) 12 | @Target({ ElementType.METHOD, ElementType.FIELD }) 13 | public @interface Id { } 14 | -------------------------------------------------------------------------------- /spring-data-gremlin-core/src/main/java/org/springframework/data/gremlin/annotation/Ignore.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.annotation; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | /** 9 | * Created by gman on 12/08/15. 10 | */ 11 | @Retention(RetentionPolicy.RUNTIME) 12 | @Target({ ElementType.METHOD, ElementType.FIELD }) 13 | public @interface Ignore { } 14 | -------------------------------------------------------------------------------- /spring-data-gremlin-core/src/main/java/org/springframework/data/gremlin/annotation/Index.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.annotation; 2 | 3 | import java.lang.annotation.*; 4 | 5 | /** 6 | * An Index annotation used by the schema generator to define a property with an index; unique or non-unique. 7 | * 8 | * @author Gman 9 | */ 10 | @Documented 11 | @Target(ElementType.FIELD) 12 | @Retention(RetentionPolicy.RUNTIME) 13 | public @interface Index { 14 | /** 15 | * Defines the name of the index 16 | */ 17 | String[] value() default ""; 18 | 19 | /** 20 | * Defines the type of index 21 | * 22 | * @return 23 | */ 24 | IndexType type() default IndexType.NON_UNIQUE; 25 | 26 | enum IndexType { 27 | NONE, 28 | UNIQUE, 29 | NON_UNIQUE, 30 | SPATIAL_LATITUDE, 31 | SPATIAL_LONGITUDE 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /spring-data-gremlin-core/src/main/java/org/springframework/data/gremlin/annotation/Link.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.annotation; 2 | 3 | import com.tinkerpop.blueprints.Direction; 4 | 5 | import java.lang.annotation.*; 6 | 7 | /** 8 | * Created by gman on 12/08/15. 9 | */ 10 | @Retention(RetentionPolicy.RUNTIME) 11 | @Target({ ElementType.METHOD, ElementType.FIELD }) 12 | public @interface Link { 13 | 14 | String value() default ""; 15 | 16 | String name() default ""; 17 | 18 | Direction direction() default Direction.OUT; 19 | } 20 | -------------------------------------------------------------------------------- /spring-data-gremlin-core/src/main/java/org/springframework/data/gremlin/annotation/LinkVia.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.annotation; 2 | 3 | import com.tinkerpop.blueprints.Direction; 4 | 5 | import java.lang.annotation.ElementType; 6 | import java.lang.annotation.Retention; 7 | import java.lang.annotation.RetentionPolicy; 8 | import java.lang.annotation.Target; 9 | 10 | /** 11 | * Created by gman on 12/08/15. 12 | */ 13 | @Retention(RetentionPolicy.RUNTIME) 14 | @Target({ ElementType.METHOD, ElementType.FIELD }) 15 | public @interface LinkVia { 16 | 17 | String value() default ""; 18 | 19 | String name() default ""; 20 | 21 | Direction direction() default Direction.OUT; 22 | } 23 | -------------------------------------------------------------------------------- /spring-data-gremlin-core/src/main/java/org/springframework/data/gremlin/annotation/Property.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.annotation; 2 | 3 | import java.io.Serializable; 4 | import java.lang.annotation.ElementType; 5 | import java.lang.annotation.Retention; 6 | import java.lang.annotation.RetentionPolicy; 7 | import java.lang.annotation.Target; 8 | 9 | import static org.springframework.data.gremlin.annotation.Enumerated.EnumeratedType.ORDINAL; 10 | import static org.springframework.data.gremlin.annotation.Property.SerialisableType.STANDARD; 11 | 12 | /** 13 | * Created by gman on 12/08/15. 14 | */ 15 | @Retention(RetentionPolicy.RUNTIME) 16 | @Target({ ElementType.METHOD, ElementType.FIELD }) 17 | public @interface Property { 18 | 19 | /** 20 | * The name of the Property. If left blank the name of the field is used. 21 | * @return 22 | */ 23 | String value() default ""; 24 | 25 | /** 26 | * pseudonym for value(). 27 | * @return 28 | */ 29 | String name() default ""; 30 | 31 | /** 32 | * If the SerialisableType is JSON, then a mixin class can be provided. 33 | * @return 34 | */ 35 | Class jsonMixin() default Void.class; 36 | 37 | /** 38 | * (Optional) The type used when serialising the property. 39 | */ 40 | SerialisableType type() default STANDARD; 41 | 42 | enum SerialisableType { 43 | STANDARD, 44 | SERIALIZABLE, 45 | JSON 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /spring-data-gremlin-core/src/main/java/org/springframework/data/gremlin/annotation/PropertyOverride.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.annotation; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | /** 9 | * Created by gman on 12/08/15. 10 | */ 11 | @Retention(RetentionPolicy.RUNTIME) 12 | @Target({ ElementType.ANNOTATION_TYPE }) 13 | public @interface PropertyOverride { 14 | 15 | /** 16 | * The name of the property to override 17 | * @return 18 | */ 19 | String name() default ""; 20 | 21 | /** 22 | * Override the property with this parameter 23 | * @return 24 | */ 25 | Property property(); 26 | } 27 | -------------------------------------------------------------------------------- /spring-data-gremlin-core/src/main/java/org/springframework/data/gremlin/annotation/Query.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.annotation; 2 | 3 | import java.lang.annotation.*; 4 | 5 | /** 6 | * The annotation to declare custom queries directly on repository methods. 7 | * 8 | * @author Gman 9 | */ 10 | @Documented 11 | @Target(ElementType.METHOD) 12 | @Retention(RetentionPolicy.RUNTIME) 13 | public @interface Query { 14 | 15 | /** 16 | * Defines the Gremlin query to be executed when the annotated method` is called. 17 | */ 18 | String value() default ""; 19 | 20 | /** 21 | * Defines a count query that returns the number of elements in a query result. 22 | */ 23 | boolean count() default false; 24 | 25 | /** 26 | * Defines a modification query which results in a modification of the database, returning the number of elements modified. 27 | */ 28 | boolean modify() default false; 29 | 30 | /** 31 | * Instructs the interpreter that this is a native query for the underlying graph database. 32 | */ 33 | boolean nativeQuery() default false; 34 | } 35 | -------------------------------------------------------------------------------- /spring-data-gremlin-core/src/main/java/org/springframework/data/gremlin/annotation/ToVertex.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.annotation; 2 | 3 | import java.lang.annotation.*; 4 | 5 | /** 6 | * Created by gman on 12/08/15. 7 | */ 8 | @Retention(RetentionPolicy.RUNTIME) 9 | @Target({ ElementType.METHOD, ElementType.FIELD }) 10 | public @interface ToVertex { } 11 | -------------------------------------------------------------------------------- /spring-data-gremlin-core/src/main/java/org/springframework/data/gremlin/annotation/Vertex.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.annotation; 2 | 3 | import java.lang.annotation.*; 4 | 5 | /** 6 | * Created by gman on 12/08/15. 7 | */ 8 | @Retention(RetentionPolicy.RUNTIME) 9 | @Target(ElementType.TYPE) 10 | @Inherited 11 | public @interface Vertex { 12 | 13 | /** 14 | * The type/name of the Vertex. If left blank the name of the Class is used. 15 | * @return 16 | */ 17 | String value() default ""; 18 | 19 | /** 20 | * pseudonym for value(). 21 | * @return 22 | */ 23 | String name() default ""; 24 | 25 | } 26 | -------------------------------------------------------------------------------- /spring-data-gremlin-core/src/main/java/org/springframework/data/gremlin/config/GremlinRepositoryConfigExtension.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.config; 2 | 3 | import org.springframework.data.gremlin.support.GremlinRepositoryFactoryBean; 4 | import org.springframework.data.repository.config.RepositoryConfigurationExtensionSupport; 5 | 6 | /** 7 | * {@link org.springframework.data.repository.config.RepositoryConfigurationExtension} for Gremlin. 8 | * 9 | * @author Gman 10 | */ 11 | public class GremlinRepositoryConfigExtension extends RepositoryConfigurationExtensionSupport { 12 | 13 | /* (non-Javadoc) 14 | * @see org.springframework.data.repository.config.RepositoryConfigurationExtension#getRepositoryFactoryClassName() 15 | */ 16 | public String getRepositoryFactoryClassName() { 17 | return GremlinRepositoryFactoryBean.class.getName(); 18 | } 19 | 20 | /* (non-Javadoc) 21 | * @see org.springframework.data.repository.config.RepositoryConfigurationExtensionSupport#getModulePrefix() 22 | */ 23 | @Override 24 | protected String getModulePrefix() { 25 | return "gremlin"; 26 | } 27 | 28 | 29 | } 30 | -------------------------------------------------------------------------------- /spring-data-gremlin-core/src/main/java/org/springframework/data/gremlin/config/GremlinRepositoryRegistrar.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.config; 2 | 3 | import org.springframework.data.repository.config.RepositoryBeanDefinitionRegistrarSupport; 4 | import org.springframework.data.repository.config.RepositoryConfigurationExtension; 5 | 6 | import java.lang.annotation.Annotation; 7 | 8 | /** 9 | * {@link org.springframework.context.annotation.ImportBeanDefinitionRegistrar} to enable {@link EnableGremlinRepositories} annotation. 10 | * 11 | * @author Gman 12 | */ 13 | public class GremlinRepositoryRegistrar extends RepositoryBeanDefinitionRegistrarSupport { 14 | 15 | @Override 16 | protected Class getAnnotation() { 17 | return EnableGremlinRepositories.class; 18 | } 19 | 20 | @Override 21 | protected RepositoryConfigurationExtension getExtension() { 22 | return new GremlinRepositoryConfigExtension(); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /spring-data-gremlin-core/src/main/java/org/springframework/data/gremlin/query/AbstractNativeGremlinQuery.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.query; 2 | 3 | import org.springframework.data.gremlin.repository.GremlinGraphAdapter; 4 | import org.springframework.data.gremlin.schema.GremlinSchemaFactory; 5 | import org.springframework.data.gremlin.tx.GremlinGraphFactory; 6 | 7 | /** 8 | * Native query abstraction for {@link AbstractGremlinQuery}s. 9 | * 10 | * @author Gman 11 | */ 12 | public abstract class AbstractNativeGremlinQuery extends AbstractGremlinQuery { 13 | 14 | /** The query method. */ 15 | protected final GremlinGraphFactory dbf; 16 | protected final GremlinQueryMethod method; 17 | protected final GremlinSchemaFactory schemaFactory; 18 | protected final GremlinGraphAdapter graphAdapter; 19 | protected final String query; 20 | private boolean countQuery; 21 | private boolean modifyingQuery; 22 | 23 | public AbstractNativeGremlinQuery(GremlinGraphFactory dbf, GremlinQueryMethod method, GremlinSchemaFactory schemaFactory, GremlinGraphAdapter graphAdapter, String query) { 24 | super(schemaFactory, method, graphAdapter); 25 | 26 | this.dbf = dbf; 27 | this.method = method; 28 | this.schemaFactory = schemaFactory; 29 | this.graphAdapter = graphAdapter; 30 | this.query = query; 31 | this.countQuery = method.hasAnnotatedQuery() && method.getQueryAnnotation().count(); 32 | this.modifyingQuery = method.hasAnnotatedQuery() && method.getQueryAnnotation().modify(); 33 | } 34 | 35 | public GremlinGraphFactory getDbf() { 36 | return dbf; 37 | } 38 | 39 | public GremlinQueryMethod getMethod() { 40 | return method; 41 | } 42 | 43 | public GremlinSchemaFactory getSchemaFactory() { 44 | return schemaFactory; 45 | } 46 | 47 | public GremlinGraphAdapter getGraphAdapter() { 48 | return graphAdapter; 49 | } 50 | 51 | public String getQuery() { 52 | return query; 53 | } 54 | 55 | @Override 56 | protected boolean isCountQuery() { 57 | return countQuery; 58 | } 59 | 60 | @Override 61 | protected boolean isModifyingQuery() { 62 | return modifyingQuery; 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /spring-data-gremlin-core/src/main/java/org/springframework/data/gremlin/query/CompositeResult.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.query; 2 | 3 | import java.util.Map; 4 | 5 | /** 6 | * A query result object containing the mapped entity along with any external properties requested in the query. 7 | * 8 | * @author Gman 9 | */ 10 | public class CompositeResult { 11 | 12 | private V entity; 13 | private Map properties; 14 | 15 | public CompositeResult(V entity, Map properties) { 16 | this.entity = entity; 17 | this.properties = properties; 18 | } 19 | 20 | public V getEntity() { 21 | return entity; 22 | } 23 | 24 | public Map getProperties() { 25 | return properties; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /spring-data-gremlin-core/src/main/java/org/springframework/data/gremlin/query/GremlinQueryMethod.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.query; 2 | 3 | import org.springframework.core.annotation.AnnotationUtils; 4 | import org.springframework.data.gremlin.annotation.Query; 5 | import org.springframework.data.repository.core.RepositoryMetadata; 6 | import org.springframework.data.repository.query.QueryMethod; 7 | import org.springframework.util.StringUtils; 8 | 9 | import java.lang.reflect.Method; 10 | 11 | /** 12 | * Gremlin specific extension of {@link QueryMethod} providing the {@link Method} and {@link Query} annotaiton. 13 | * 14 | * @author Gman 15 | */ 16 | public final class GremlinQueryMethod extends QueryMethod { 17 | 18 | /** The method. */ 19 | private final Method method; 20 | 21 | /** 22 | * Instantiates a new {@link GremlinQueryMethod}. 23 | * 24 | * @param method the method 25 | * @param metadata the metadata 26 | */ 27 | public GremlinQueryMethod(Method method, RepositoryMetadata metadata) { 28 | super(method, metadata); 29 | this.method = method; 30 | } 31 | 32 | /** 33 | * Gets the target method. 34 | * 35 | * @return the method 36 | */ 37 | public Method getMethod() { 38 | return method; 39 | } 40 | 41 | /** 42 | * Returns whether the method has an annotated query. 43 | * 44 | * @return 45 | */ 46 | public boolean hasAnnotatedQuery() { 47 | return getAnnotatedQuery() != null; 48 | } 49 | 50 | /** 51 | * Returns the query string declared in a {@link Query} annotation or {@literal null} if neither the annotation found 52 | * nor the attribute was specified. 53 | * 54 | * @return the query 55 | */ 56 | String getAnnotatedQuery() { 57 | String query = (String) AnnotationUtils.getValue(getQueryAnnotation()); 58 | return StringUtils.hasText(query) ? query : null; 59 | } 60 | 61 | /** 62 | * Returns the {@link Query} annotation that is applied to the method or {@code null} if none available. 63 | * 64 | * @return 65 | */ 66 | Query getQueryAnnotation() { 67 | return method.getAnnotation(Query.class); 68 | } 69 | 70 | } 71 | -------------------------------------------------------------------------------- /spring-data-gremlin-core/src/main/java/org/springframework/data/gremlin/query/execution/CompositeExecution.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.query.execution; 2 | 3 | import com.tinkerpop.blueprints.Vertex; 4 | import org.springframework.data.gremlin.query.AbstractGremlinQuery; 5 | import org.springframework.data.gremlin.query.CompositeResult; 6 | import org.springframework.data.gremlin.repository.GremlinGraphAdapter; 7 | import org.springframework.data.gremlin.schema.GremlinSchema; 8 | import org.springframework.data.gremlin.schema.GremlinSchemaFactory; 9 | import org.springframework.data.repository.query.DefaultParameters; 10 | 11 | import java.util.HashMap; 12 | import java.util.Iterator; 13 | import java.util.Map; 14 | 15 | /** 16 | * Executes the query to return a Map of properties. 17 | * 18 | * @author Gman 19 | */ 20 | @SuppressWarnings("unchecked") 21 | public class CompositeExecution extends AbstractGremlinExecution { 22 | 23 | /** 24 | * Instantiates a new {@link CountExecution}. 25 | */ 26 | public CompositeExecution(GremlinSchemaFactory schemaFactory, DefaultParameters parameters, GremlinGraphAdapter graphAdapter) { 27 | super(schemaFactory, parameters, graphAdapter); 28 | } 29 | 30 | @Override 31 | protected Object doExecute(AbstractGremlinQuery query, Object[] values) { 32 | 33 | Iterator result = ((Iterable) query.runQuery(parameters, values)).iterator(); 34 | Vertex vertex = result.next(); 35 | if (vertex == null) { 36 | return null; 37 | } 38 | if (result.hasNext()) { 39 | throw new IllegalArgumentException("The query resulted in multiple Vertices. Expected only one result for this Execution."); 40 | } 41 | 42 | Map map = new HashMap(); 43 | for (String key : vertex.getPropertyKeys()) { 44 | map.put(key, vertex.getProperty(key)); 45 | } 46 | 47 | Class mappedType = query.getQueryMethod().getReturnedObjectType(); 48 | GremlinSchema mapper = schemaFactory.getSchema(mappedType); 49 | Object entity = mapper.loadFromGraph(graphAdapter, vertex); 50 | 51 | return new CompositeResult(entity, map); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /spring-data-gremlin-core/src/main/java/org/springframework/data/gremlin/query/execution/CountExecution.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.query.execution; 2 | 3 | import com.tinkerpop.blueprints.Vertex; 4 | import org.springframework.data.gremlin.query.AbstractGremlinQuery; 5 | import org.springframework.data.gremlin.repository.GremlinGraphAdapter; 6 | import org.springframework.data.gremlin.schema.GremlinSchemaFactory; 7 | import org.springframework.data.repository.query.DefaultParameters; 8 | 9 | import java.util.Iterator; 10 | import java.util.NoSuchElementException; 11 | 12 | /** 13 | * Executes the query to return the sum of entities. 14 | * 15 | * @author Gman 16 | */ 17 | @SuppressWarnings("unchecked") 18 | public class CountExecution extends AbstractGremlinExecution { 19 | 20 | /** 21 | * Instantiates a new {@link org.springframework.data.gremlin.query.execution.CountExecution}. 22 | */ 23 | public CountExecution(GremlinSchemaFactory schemaFactory, DefaultParameters parameters, GremlinGraphAdapter graphAdapter) { 24 | super(schemaFactory, parameters, graphAdapter); 25 | } 26 | 27 | /* (non-Javadoc) 28 | * @see org.springframework.data.orient.repository.object.query.OrientQueryExecution#doExecute(org.springframework.data.orient.repository.object.query.AbstractOrientQuery, java.lang.Object[]) 29 | */ 30 | @Override 31 | protected Object doExecute(AbstractGremlinQuery query, Object[] values) { 32 | Iterator result = ((Iterable) query.runQuery(parameters, values, true)).iterator(); 33 | long counter = 0L; 34 | 35 | try { 36 | while (true) { 37 | result.next(); 38 | ++counter; 39 | } 40 | } catch (NoSuchElementException var4) { 41 | return counter; 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /spring-data-gremlin-core/src/main/java/org/springframework/data/gremlin/query/execution/MapExecution.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.query.execution; 2 | 3 | import com.tinkerpop.blueprints.Vertex; 4 | import org.springframework.data.gremlin.query.AbstractGremlinQuery; 5 | import org.springframework.data.gremlin.repository.GremlinGraphAdapter; 6 | import org.springframework.data.gremlin.schema.GremlinSchemaFactory; 7 | import org.springframework.data.repository.query.DefaultParameters; 8 | 9 | import java.util.HashMap; 10 | import java.util.Iterator; 11 | import java.util.Map; 12 | 13 | /** 14 | * Executes the query to return a Map of properties. 15 | * 16 | * @author Gman 17 | */ 18 | @SuppressWarnings("unchecked") 19 | public class MapExecution extends AbstractGremlinExecution { 20 | 21 | /** 22 | * Instantiates a new {@link CountExecution}. 23 | */ 24 | public MapExecution(GremlinSchemaFactory schemaFactory, DefaultParameters parameters, GremlinGraphAdapter graphAdapter) { 25 | super(schemaFactory, parameters, graphAdapter); 26 | } 27 | 28 | @Override 29 | protected Object doExecute(AbstractGremlinQuery query, Object[] values) { 30 | 31 | Iterator result = ((Iterable) query.runQuery(parameters, values)).iterator(); 32 | Vertex vertex = result.next(); 33 | if (vertex == null) { 34 | return null; 35 | } 36 | if (result.hasNext()) { 37 | throw new IllegalArgumentException("The query resulted in multiple Vertices. Expected only one result for this Execution."); 38 | } 39 | 40 | Map map = new HashMap(); 41 | for (String key : vertex.getPropertyKeys()) { 42 | map.put(key, vertex.getProperty(key)); 43 | } 44 | return map; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /spring-data-gremlin-core/src/main/java/org/springframework/data/gremlin/query/execution/ModifyExecution.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.query.execution; 2 | 3 | import org.springframework.data.gremlin.query.AbstractGremlinQuery; 4 | import org.springframework.data.gremlin.repository.GremlinGraphAdapter; 5 | import org.springframework.data.gremlin.schema.GremlinSchemaFactory; 6 | import org.springframework.data.repository.query.DefaultParameters; 7 | 8 | /** 9 | * Executes the query to return a sum of entities. 10 | * 11 | * @author Gman 12 | */ 13 | public class ModifyExecution extends AbstractGremlinExecution { 14 | 15 | /** 16 | * Instantiates a new {@link CountExecution}. 17 | */ 18 | public ModifyExecution(GremlinSchemaFactory schemaFactory, DefaultParameters parameters, GremlinGraphAdapter graphAdapter) { 19 | super(schemaFactory, parameters, graphAdapter); 20 | } 21 | 22 | /* (non-Javadoc) 23 | * @see org.springframework.data.orient.repository.object.query.OrientQueryExecution#doExecute(org.springframework.data.orient.repository.object.query.AbstractOrientQuery, java.lang.Object[]) 24 | */ 25 | @Override 26 | protected Object doExecute(AbstractGremlinQuery query, Object[] values) { 27 | return query.runQuery(parameters, values, true); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /spring-data-gremlin-core/src/main/java/org/springframework/data/gremlin/query/execution/SingleEntityExecution.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.query.execution; 2 | 3 | import com.tinkerpop.blueprints.Vertex; 4 | import org.springframework.data.gremlin.query.AbstractGremlinQuery; 5 | import org.springframework.data.gremlin.repository.GremlinGraphAdapter; 6 | import org.springframework.data.gremlin.schema.GremlinSchema; 7 | import org.springframework.data.gremlin.schema.GremlinSchemaFactory; 8 | import org.springframework.data.repository.query.DefaultParameters; 9 | 10 | import java.util.HashMap; 11 | import java.util.Iterator; 12 | import java.util.Map; 13 | import java.util.NoSuchElementException; 14 | 15 | /** 16 | * Executes the query to return a single entity. 17 | * 18 | * @author Gman 19 | */ 20 | @SuppressWarnings("unchecked") 21 | public class SingleEntityExecution extends AbstractGremlinExecution { 22 | 23 | /** 24 | * Instantiates a new {@link CountExecution}. 25 | */ 26 | public SingleEntityExecution(GremlinSchemaFactory schemaFactory, DefaultParameters parameters, GremlinGraphAdapter graphAdapter) { 27 | super(schemaFactory, parameters, graphAdapter); 28 | } 29 | 30 | @Override 31 | protected Object doExecute(AbstractGremlinQuery query, Object[] values) { 32 | Class mappedType = query.getQueryMethod().getReturnedObjectType(); 33 | 34 | Iterator result = ((Iterable) query.runQuery(parameters, values)).iterator(); 35 | if (!result.hasNext()) { 36 | return null; 37 | } 38 | Vertex vertex; 39 | try { 40 | vertex = result.next(); 41 | } catch (NoSuchElementException e) { 42 | return null; 43 | } 44 | 45 | if (vertex == null) { 46 | return null; 47 | } 48 | if (result.hasNext()) { 49 | throw new IllegalArgumentException("The query resulted in multiple Vertices. Expected only one result for this Execution."); 50 | } 51 | 52 | if (mappedType.isAssignableFrom(Map.class)) { 53 | 54 | Map map = new HashMap(); 55 | for (String key : vertex.getPropertyKeys()) { 56 | map.put(key, vertex.getProperty(key)); 57 | } 58 | return map; 59 | } else { 60 | GremlinSchema mapper = schemaFactory.getSchema(mappedType); 61 | return mapper.loadFromGraph(graphAdapter, vertex); 62 | 63 | } 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /spring-data-gremlin-core/src/main/java/org/springframework/data/gremlin/repository/GremlinRepository.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.repository; 2 | 3 | import org.springframework.data.repository.NoRepositoryBean; 4 | import org.springframework.data.repository.PagingAndSortingRepository; 5 | 6 | /** 7 | * The Gremlin specific extension of {@link org.springframework.data.repository.PagingAndSortingRepository}. 8 | * Note: This implementation expects an if of type String. To be fixed. 9 | * 10 | * @param the generic type to handle 11 | * @author Gman 12 | */ 13 | @NoRepositoryBean 14 | public interface GremlinRepository extends PagingAndSortingRepository { 15 | 16 | S save(S entity, Object... noCascade); 17 | } 18 | -------------------------------------------------------------------------------- /spring-data-gremlin-core/src/main/java/org/springframework/data/gremlin/repository/GremlinRepositoryWithNativeSupport.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.repository; 2 | 3 | import org.springframework.data.repository.NoRepositoryBean; 4 | import org.springframework.data.repository.PagingAndSortingRepository; 5 | 6 | /** 7 | * The Gremlin specific extension of {@link PagingAndSortingRepository}. 8 | * Note: This implementation expects an if of type String. To be fixed. 9 | * 10 | * @param the generic type to handle 11 | * @author Gman 12 | */ 13 | @NoRepositoryBean 14 | public interface GremlinRepositoryWithNativeSupport extends GremlinRepository { } 15 | -------------------------------------------------------------------------------- /spring-data-gremlin-core/src/main/java/org/springframework/data/gremlin/schema/GremlinEdgeSchema.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.schema; 2 | 3 | import com.tinkerpop.blueprints.Direction; 4 | import com.tinkerpop.blueprints.Element; 5 | import org.slf4j.Logger; 6 | import org.slf4j.LoggerFactory; 7 | import org.springframework.data.gremlin.repository.GremlinGraphAdapter; 8 | import org.springframework.data.gremlin.repository.GremlinRepository; 9 | import org.springframework.data.gremlin.schema.property.GremlinAdjacentProperty; 10 | import org.springframework.data.gremlin.schema.property.GremlinProperty; 11 | import org.springframework.data.gremlin.schema.property.accessor.GremlinFieldPropertyAccessor; 12 | import org.springframework.data.gremlin.schema.property.accessor.GremlinIdFieldPropertyAccessor; 13 | import org.springframework.data.gremlin.schema.property.accessor.GremlinPropertyAccessor; 14 | import org.springframework.data.gremlin.schema.property.encoder.GremlinPropertyEncoder; 15 | import org.springframework.data.gremlin.schema.property.mapper.GremlinPropertyMapper; 16 | import org.springframework.data.gremlin.tx.GremlinGraphFactory; 17 | 18 | import java.util.Collection; 19 | import java.util.HashMap; 20 | import java.util.Map; 21 | 22 | 23 | /** 24 | *

25 | * Defines the schema of a mapped Class. Each GremlinSchema holds the {@code className}, {@code classType}, 26 | * {@code schemaType} (VERTEX, EDGE) and the identifying {@link GremlinFieldPropertyAccessor}. 27 | *

28 | *

29 | * The GremlinSchema contains the high level logic for converting Vertices to mapped classes. 30 | *

31 | * 32 | * @author Gman 33 | */ 34 | public class GremlinEdgeSchema extends GremlinSchema { 35 | 36 | private static final Logger LOGGER = LoggerFactory.getLogger(GremlinEdgeSchema.class); 37 | 38 | public GremlinEdgeSchema(Class classType) { 39 | super(classType); 40 | } 41 | 42 | public GremlinEdgeSchema() { 43 | super(); 44 | } 45 | 46 | private GremlinAdjacentProperty outProperty; 47 | private GremlinAdjacentProperty inProperty; 48 | 49 | public void addProperty(GremlinProperty property) { 50 | super.addProperty(property); 51 | if (property instanceof GremlinAdjacentProperty) { 52 | GremlinAdjacentProperty adjacentProperty = (GremlinAdjacentProperty) property; 53 | if (adjacentProperty.getDirection() == Direction.OUT) { 54 | outProperty = adjacentProperty; 55 | } else { 56 | inProperty = adjacentProperty; 57 | } 58 | } 59 | } 60 | 61 | public GremlinAdjacentProperty getOutProperty() { 62 | return outProperty; 63 | } 64 | 65 | public GremlinAdjacentProperty getInProperty() { 66 | return inProperty; 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /spring-data-gremlin-core/src/main/java/org/springframework/data/gremlin/schema/GremlinSchemaFactory.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.schema; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.stereotype.Component; 5 | 6 | import javax.annotation.PostConstruct; 7 | import java.util.HashMap; 8 | import java.util.Map; 9 | import java.util.Set; 10 | 11 | /** 12 | * A factory for {@link GremlinSchema}s mapped by Class type. 13 | * 14 | * @author Gman 15 | */ 16 | @Component 17 | public class GremlinSchemaFactory { 18 | 19 | @Autowired 20 | private Set schemas; 21 | 22 | private Map> schemaMap = new HashMap>(); 23 | 24 | @PostConstruct 25 | public void init() { 26 | for (GremlinSchema schema : schemas) { 27 | String key = schema.getClassType().getSimpleName(); 28 | if (schemaMap.containsKey(key)) { 29 | key = schema.getClassName(); 30 | } 31 | schemaMap.put(key, schema); 32 | } 33 | } 34 | 35 | public GremlinSchema getSchema(Class type) { 36 | return (GremlinSchema) schemaMap.get(type.getSimpleName()); 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /spring-data-gremlin-core/src/main/java/org/springframework/data/gremlin/schema/GremlinVertexSchema.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.schema; 2 | 3 | import com.tinkerpop.blueprints.Direction; 4 | import org.slf4j.Logger; 5 | import org.slf4j.LoggerFactory; 6 | import org.springframework.data.gremlin.schema.property.GremlinAdjacentProperty; 7 | import org.springframework.data.gremlin.schema.property.GremlinProperty; 8 | import org.springframework.data.gremlin.schema.property.accessor.GremlinFieldPropertyAccessor; 9 | 10 | 11 | /** 12 | *

13 | * Defines the schema of a mapped Class. Each GremlinSchema holds the {@code className}, {@code classType}, 14 | * {@code schemaType} (VERTEX, EDGE) and the identifying {@link GremlinFieldPropertyAccessor}. 15 | *

16 | *

17 | * The GremlinSchema contains the high level logic for converting Vertices to mapped classes. 18 | *

19 | * 20 | * @author Gman 21 | */ 22 | public class GremlinVertexSchema extends GremlinSchema { 23 | 24 | private static final Logger LOGGER = LoggerFactory.getLogger(GremlinVertexSchema.class); 25 | 26 | public GremlinVertexSchema(Class classType) { 27 | super(classType); 28 | } 29 | 30 | public GremlinVertexSchema() { 31 | super(); 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /spring-data-gremlin-core/src/main/java/org/springframework/data/gremlin/schema/generator/AnnotatedSchemaGenerator.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.schema.generator; 2 | 3 | import java.lang.annotation.Annotation; 4 | 5 | /** 6 | * Interface defining an annotated {@link SchemaGenerator} providing the entity and embedded annotation types. 7 | * 8 | * @author Gman 9 | */ 10 | public interface AnnotatedSchemaGenerator extends SchemaGenerator { 11 | Class getVertexAnnotationType(); 12 | 13 | Class getEmbeddedAnnotationType(); 14 | 15 | Class getEdgeAnnotationType(); 16 | } 17 | -------------------------------------------------------------------------------- /spring-data-gremlin-core/src/main/java/org/springframework/data/gremlin/schema/generator/SchemaGenerator.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.schema.generator; 2 | 3 | import org.springframework.data.gremlin.schema.GremlinSchema; 4 | 5 | import java.util.Map; 6 | import java.util.Set; 7 | 8 | /** 9 | * An interface defining schema generators. 10 | * 11 | * @author Gman 12 | */ 13 | public interface SchemaGenerator { 14 | 15 | GremlinSchema generateSchema(Class clazz) throws SchemaGeneratorException; 16 | 17 | GremlinSchema generateDynamicSchema(String className, Class mapType); 18 | 19 | void setVertexClasses(Set> entities); 20 | 21 | void setVertexClasses(Class... entites); 22 | 23 | void setEmbeddedClasses(Set> embedded); 24 | 25 | void setEmbeddedClasses(Class... embedded); 26 | 27 | void setEdgeClasses(Set> relationshipClasses); 28 | 29 | void setEdgeClasses(Class... relationshipClasses); 30 | } 31 | -------------------------------------------------------------------------------- /spring-data-gremlin-core/src/main/java/org/springframework/data/gremlin/schema/generator/SchemaGeneratorException.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.schema.generator; 2 | 3 | /** 4 | * @author Gman 5 | */ 6 | public class SchemaGeneratorException extends Exception { 7 | public SchemaGeneratorException(String message) { 8 | super(message); 9 | } 10 | 11 | public SchemaGeneratorException(String message, Throwable cause) { 12 | super(message, cause); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /spring-data-gremlin-core/src/main/java/org/springframework/data/gremlin/schema/property/GremlinAdjacentProperty.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.schema.property; 2 | 3 | import com.tinkerpop.blueprints.Direction; 4 | import org.springframework.data.gremlin.schema.property.mapper.GremlinAdjacentPropertyMapper; 5 | 6 | /** 7 | * A {@link GremlinRelatedProperty} accessor for linked properties (one-to-one relationships). 8 | * 9 | * @author Gman 10 | */ 11 | public class GremlinAdjacentProperty extends GremlinRelatedProperty { 12 | 13 | public GremlinAdjacentProperty(Class cls, String name, Direction direction) { 14 | super(cls, name, direction, new GremlinAdjacentPropertyMapper(), CARDINALITY.ONE_TO_ONE); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /spring-data-gremlin-core/src/main/java/org/springframework/data/gremlin/schema/property/GremlinCollectionProperty.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.schema.property; 2 | 3 | import com.tinkerpop.blueprints.Direction; 4 | import org.springframework.data.gremlin.schema.property.mapper.GremlinCollectionPropertyMapper; 5 | 6 | /** 7 | * A concrete {@link GremlinRelatedProperty} for a Collection 8 | * 9 | * @author Gman 10 | */ 11 | public class GremlinCollectionProperty extends GremlinRelatedProperty { 12 | 13 | public GremlinCollectionProperty(Class cls, String name, Direction direction) { 14 | super(cls, name, direction, new GremlinCollectionPropertyMapper(), CARDINALITY.ONE_TO_MANY); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /spring-data-gremlin-core/src/main/java/org/springframework/data/gremlin/schema/property/GremlinCollectionViaProperty.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.schema.property; 2 | 3 | import com.tinkerpop.blueprints.Direction; 4 | import org.springframework.data.gremlin.schema.property.mapper.GremlinCollectionViaPropertyMapper; 5 | 6 | /** 7 | * A concrete {@link GremlinRelatedProperty} for a Collection via a relational entity 8 | * 9 | * @author Gman 10 | */ 11 | public class GremlinCollectionViaProperty extends GremlinRelatedProperty { 12 | 13 | public GremlinCollectionViaProperty(Class cls, String name, Direction direction) { 14 | super(cls, name, direction, new GremlinCollectionViaPropertyMapper(), CARDINALITY.ONE_TO_MANY); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /spring-data-gremlin-core/src/main/java/org/springframework/data/gremlin/schema/property/GremlinDynamicProperty.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.schema.property; 2 | 3 | import com.tinkerpop.blueprints.Direction; 4 | import org.springframework.data.gremlin.schema.property.mapper.GremlinLinkPropertyMapper; 5 | 6 | import java.util.Map; 7 | 8 | /** 9 | * A {@link GremlinRelatedProperty} accessor for linked properties (one-to-one relationships). 10 | * 11 | * @author Gman 12 | */ 13 | public class GremlinDynamicProperty extends GremlinRelatedProperty { 14 | 15 | private String relatedClassName; 16 | 17 | public GremlinDynamicProperty(Class cls, String name, String relatedClassName, Direction direction) { 18 | super(cls, name, direction, new GremlinLinkPropertyMapper(), CARDINALITY.ONE_TO_ONE); 19 | this.relatedClassName = relatedClassName; 20 | } 21 | 22 | public String getRelatedClassName() { 23 | return relatedClassName; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /spring-data-gremlin-core/src/main/java/org/springframework/data/gremlin/schema/property/GremlinLinkProperty.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.schema.property; 2 | 3 | import com.tinkerpop.blueprints.Direction; 4 | import org.springframework.data.gremlin.schema.property.mapper.GremlinLinkPropertyMapper; 5 | 6 | /** 7 | * A {@link GremlinRelatedProperty} accessor for linked properties (one-to-one relationships). 8 | * 9 | * @author Gman 10 | */ 11 | public class GremlinLinkProperty extends GremlinRelatedProperty { 12 | 13 | public GremlinLinkProperty(Class cls, String name, Direction direction) { 14 | super(cls, name, direction, new GremlinLinkPropertyMapper(), CARDINALITY.ONE_TO_ONE); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /spring-data-gremlin-core/src/main/java/org/springframework/data/gremlin/schema/property/GremlinLinkViaProperty.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.schema.property; 2 | 3 | import com.tinkerpop.blueprints.Direction; 4 | import org.springframework.data.gremlin.schema.property.mapper.GremlinLinkViaPropertyMapper; 5 | 6 | /** 7 | * A {@link GremlinRelatedProperty} accessor for linked properties (one-to-one relationships). 8 | * 9 | * @author Gman 10 | */ 11 | public class GremlinLinkViaProperty extends GremlinRelatedProperty { 12 | 13 | public GremlinLinkViaProperty(Class cls, String name, Direction direction) { 14 | super(cls, name, direction, new GremlinLinkViaPropertyMapper(), CARDINALITY.ONE_TO_ONE); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /spring-data-gremlin-core/src/main/java/org/springframework/data/gremlin/schema/property/GremlinPropertyFactory.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.schema.property; 2 | 3 | import com.tinkerpop.blueprints.Direction; 4 | import org.springframework.data.gremlin.annotation.Index; 5 | 6 | import java.util.Map; 7 | 8 | /** 9 | * Factory for {@link GremlinProperty}s. 10 | * 11 | * @author Gman 12 | */ 13 | public class GremlinPropertyFactory { 14 | 15 | public GremlinProperty getProperty(Class cls, String name) { 16 | return getIndexedProperty(cls, name, Index.IndexType.NONE, null); 17 | } 18 | 19 | public GremlinProperty getIndexedProperty(Class cls, String name, Index.IndexType index, String indexName) { 20 | return new GremlinProperty(cls, name, index, indexName); 21 | } 22 | 23 | public GremlinProperty getUniqueProperty(Class cls, String name) { 24 | return getIndexedProperty(cls, name, Index.IndexType.UNIQUE, null); 25 | } 26 | 27 | public GremlinProperty getLinkProperty(Class cls, String name, Direction direction) { 28 | return new GremlinLinkProperty(cls, name, direction); 29 | } 30 | 31 | public GremlinProperty getDynamicProperty(Class cls, String name, String relatedClassName, Direction direction) { 32 | return new GremlinDynamicProperty(cls, name, relatedClassName, direction); 33 | } 34 | 35 | public GremlinProperty getLinkViaProperty(Class cls, String name, Direction direction) { 36 | return new GremlinLinkViaProperty(cls, name, direction); 37 | } 38 | 39 | public GremlinProperty getAdjacentProperty(Class cls, String name, Direction direction) { 40 | return new GremlinAdjacentProperty(cls, name, direction); 41 | } 42 | 43 | public GremlinProperty getCollectionProperty(Class cls, String name, Direction direction) { 44 | return new GremlinCollectionProperty(cls, name, direction); 45 | } 46 | 47 | public GremlinProperty getCollectionViaProperty(Class cls, String name, Direction direction) { 48 | return new GremlinCollectionViaProperty(cls, name, direction); 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /spring-data-gremlin-core/src/main/java/org/springframework/data/gremlin/schema/property/accessor/AbstractGremlinFieldPropertyAccessor.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.schema.property.accessor; 2 | 3 | import java.lang.reflect.Field; 4 | 5 | /** 6 | * Base {@link GremlinPropertyAccessor} 7 | * 8 | * @param The result value type of the accessor 9 | * @author Gman 10 | */ 11 | public abstract class AbstractGremlinFieldPropertyAccessor implements GremlinPropertyFieldAccessor { 12 | 13 | protected Field field; 14 | 15 | protected AbstractGremlinFieldPropertyAccessor embeddedAccessor; 16 | 17 | public AbstractGremlinFieldPropertyAccessor(Field field, AbstractGremlinFieldPropertyAccessor embeddedAccessor) { 18 | this(field); 19 | this.embeddedAccessor = embeddedAccessor; 20 | } 21 | 22 | public AbstractGremlinFieldPropertyAccessor(Field field) { 23 | field.setAccessible(true); 24 | this.field = field; 25 | } 26 | 27 | protected Object getEmbeddedObject(Object object, boolean force) { 28 | 29 | if (embeddedAccessor != null) { 30 | Object parentObj = embeddedAccessor.get(object); 31 | if (parentObj == null) { 32 | if (force) { 33 | parentObj = embeddedAccessor.newInstance(); 34 | embeddedAccessor.set(object, parentObj); 35 | } 36 | } 37 | object = parentObj; 38 | } 39 | 40 | return object; 41 | } 42 | 43 | public Object newInstance() { 44 | try { 45 | return field.getType().newInstance(); 46 | } catch (Exception e) { 47 | throw new IllegalStateException("Could not create a new instance of " + field.getType() + ": " + e.getMessage(), e); 48 | } 49 | } 50 | 51 | /** 52 | * @return the root Field of this GremlinEmbeddedFieldAccessor 53 | */ 54 | public Field getRootField() { 55 | AbstractGremlinFieldPropertyAccessor rootFieldAccessor = this; 56 | AbstractGremlinFieldPropertyAccessor embeddedFieldAccessor = this.getEmbeddedAccessor(); 57 | while (embeddedFieldAccessor != null) { 58 | rootFieldAccessor = embeddedFieldAccessor; 59 | embeddedFieldAccessor = rootFieldAccessor.getEmbeddedAccessor(); 60 | } 61 | return rootFieldAccessor.getField(); 62 | } 63 | 64 | public AbstractGremlinFieldPropertyAccessor getEmbeddedAccessor() { 65 | return embeddedAccessor; 66 | } 67 | 68 | @Override 69 | public Field getField() { 70 | return field; 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /spring-data-gremlin-core/src/main/java/org/springframework/data/gremlin/schema/property/accessor/GremlinDynamicMapPropertyAccessor.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.schema.property.accessor; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | 6 | import java.lang.reflect.Field; 7 | 8 | /** 9 | * A concrete {@link AbstractGremlinFieldPropertyAccessor} for basic Fields. 10 | * 11 | * @author Gman 12 | */ 13 | public class GremlinDynamicMapPropertyAccessor extends AbstractGremlinFieldPropertyAccessor { 14 | 15 | private static final Logger LOGGER = LoggerFactory.getLogger(GremlinDynamicMapPropertyAccessor.class); 16 | 17 | public GremlinDynamicMapPropertyAccessor(Field field) { 18 | super(field); 19 | } 20 | 21 | public GremlinDynamicMapPropertyAccessor(Field field, GremlinDynamicMapPropertyAccessor parentAccessor) { 22 | super(field, parentAccessor); 23 | } 24 | 25 | @Override 26 | public V get(Object object) { 27 | try { 28 | 29 | object = getEmbeddedObject(object, false); 30 | V result = null; 31 | if (object != null) { 32 | result = (V) field.get(object); 33 | } 34 | return result; 35 | } catch (IllegalAccessException e) { 36 | throw new IllegalStateException(e.getMessage(), e); 37 | } 38 | } 39 | 40 | @Override 41 | public void set(Object object, V val) { 42 | 43 | try { 44 | object = getEmbeddedObject(object, true); 45 | if (object != null) { 46 | field.set(object, val); 47 | } 48 | } catch (IllegalAccessException e) { 49 | throw new IllegalStateException(e.getMessage(), e); 50 | } 51 | } 52 | 53 | @Override 54 | public String toString() { 55 | final StringBuilder sb = new StringBuilder("GremlinFieldPropertyAccessor{"); 56 | sb.append("field=").append(field); 57 | sb.append(", embeddedAccessor=").append(embeddedAccessor); 58 | sb.append('}'); 59 | return sb.toString(); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /spring-data-gremlin-core/src/main/java/org/springframework/data/gremlin/schema/property/accessor/GremlinEnumOrdinalFieldPropertyAccessor.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.schema.property.accessor; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | 6 | import java.lang.reflect.Field; 7 | 8 | /** 9 | * A {@link AbstractGremlinFieldPropertyAccessor} for enum properties that will be mapped with the ordinal (integer). 10 | * 11 | * @author Gman 12 | */ 13 | public class GremlinEnumOrdinalFieldPropertyAccessor extends AbstractGremlinFieldPropertyAccessor { 14 | 15 | private static final Logger LOGGER = LoggerFactory.getLogger(GremlinEnumOrdinalFieldPropertyAccessor.class); 16 | 17 | private Class numnum; 18 | 19 | public GremlinEnumOrdinalFieldPropertyAccessor(Field field, Class numnum) { 20 | super(field); 21 | this.numnum = (Class) numnum; 22 | } 23 | 24 | @Override 25 | public Integer get(Object object) { 26 | if (LOGGER.isDebugEnabled()) { 27 | LOGGER.debug("Getting enum ordinal from " + object); 28 | } 29 | try { 30 | Object result = field.get(object); 31 | if (result == null) { 32 | return null; 33 | } 34 | Enum numnum = (Enum) result; 35 | if (LOGGER.isDebugEnabled()) { 36 | LOGGER.debug("Got " + numnum + " with ordinal " + numnum.ordinal()); 37 | } 38 | return numnum.ordinal(); 39 | } catch (IllegalAccessException e) { 40 | throw new IllegalStateException(e.getMessage(), e); 41 | } 42 | } 43 | 44 | @Override 45 | public void set(Object object, Integer ordinal) { 46 | if (LOGGER.isDebugEnabled()) { 47 | LOGGER.debug("Setting enum with ordinal " + ordinal + " on " + object); 48 | } 49 | try { 50 | if (ordinal == null) { 51 | field.set(object, null); 52 | return; 53 | } 54 | 55 | Object resultEnum = numnum.getEnumConstants()[ordinal]; 56 | 57 | if (LOGGER.isDebugEnabled()) { 58 | LOGGER.debug("Found " + resultEnum + " with ordinal " + ordinal + " for " + object); 59 | } 60 | field.set(object, resultEnum); 61 | } catch (IllegalAccessException e) { 62 | throw new IllegalStateException(e.getMessage(), e); 63 | } 64 | } 65 | 66 | @Override 67 | public String toString() { 68 | final StringBuilder sb = new StringBuilder("GremlinEnumOrdinalFieldPropertyAccessor{"); 69 | sb.append("numnum=").append(numnum); 70 | sb.append('}'); 71 | return sb.toString(); 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /spring-data-gremlin-core/src/main/java/org/springframework/data/gremlin/schema/property/accessor/GremlinEnumStringFieldPropertyAccessor.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.schema.property.accessor; 2 | 3 | import java.lang.reflect.Field; 4 | 5 | /** 6 | * A {@link AbstractGremlinFieldPropertyAccessor} for enum properties that will be mapped with the name (String). 7 | * 8 | * @author Gman 9 | */ 10 | public class GremlinEnumStringFieldPropertyAccessor extends AbstractGremlinFieldPropertyAccessor { 11 | 12 | protected Class numnum; 13 | 14 | public GremlinEnumStringFieldPropertyAccessor(Field field, Class numnum) { 15 | super(field); 16 | this.numnum = (Class) numnum; 17 | } 18 | 19 | @Override 20 | public String get(Object object) { 21 | 22 | try { 23 | Object result = field.get(object); 24 | 25 | if (result == null) { 26 | return null; 27 | } 28 | return result.toString(); 29 | } catch (IllegalAccessException e) { 30 | throw new IllegalStateException(e.getMessage(), e); 31 | } 32 | } 33 | 34 | @Override 35 | public void set(Object object, String name) { 36 | try { 37 | if (name == null) { 38 | field.set(object, name); 39 | } 40 | for (Enum num : numnum.getEnumConstants()) { 41 | if (num.name().equals(name)) { 42 | field.set(object, num); 43 | break; 44 | } 45 | } 46 | } catch (IllegalAccessException e) { 47 | throw new IllegalStateException(e.getMessage(), e); 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /spring-data-gremlin-core/src/main/java/org/springframework/data/gremlin/schema/property/accessor/GremlinFieldPropertyAccessor.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.schema.property.accessor; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | 6 | import java.lang.reflect.Field; 7 | 8 | /** 9 | * A concrete {@link AbstractGremlinFieldPropertyAccessor} for basic Fields. 10 | * 11 | * @author Gman 12 | */ 13 | public class GremlinFieldPropertyAccessor extends AbstractGremlinFieldPropertyAccessor { 14 | 15 | private static final Logger LOGGER = LoggerFactory.getLogger(GremlinFieldPropertyAccessor.class); 16 | 17 | public GremlinFieldPropertyAccessor(Field field) { 18 | super(field); 19 | } 20 | 21 | public GremlinFieldPropertyAccessor(Field field, GremlinFieldPropertyAccessor parentAccessor) { 22 | super(field, parentAccessor); 23 | } 24 | 25 | @Override 26 | public V get(Object object) { 27 | try { 28 | 29 | object = getEmbeddedObject(object, false); 30 | V result = null; 31 | if (object != null) { 32 | result = (V) field.get(object); 33 | } 34 | return result; 35 | } catch (IllegalAccessException e) { 36 | throw new IllegalStateException(e.getMessage(), e); 37 | } 38 | } 39 | 40 | @Override 41 | public void set(Object object, V val) { 42 | 43 | try { 44 | object = getEmbeddedObject(object, true); 45 | if (object != null) { 46 | field.set(object, val); 47 | } 48 | } catch (IllegalAccessException e) { 49 | throw new IllegalStateException(e.getMessage(), e); 50 | } 51 | } 52 | 53 | @Override 54 | public String toString() { 55 | final StringBuilder sb = new StringBuilder("GremlinFieldPropertyAccessor{"); 56 | sb.append("field=").append(field); 57 | sb.append(", embeddedAccessor=").append(embeddedAccessor); 58 | sb.append('}'); 59 | return sb.toString(); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /spring-data-gremlin-core/src/main/java/org/springframework/data/gremlin/schema/property/accessor/GremlinIdFieldPropertyAccessor.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.schema.property.accessor; 2 | 3 | import java.lang.reflect.Field; 4 | 5 | /** 6 | * A {@link GremlinFieldPropertyAccessor} for IDs. 7 | * 8 | * @author Gman 9 | */ 10 | public class GremlinIdFieldPropertyAccessor extends GremlinFieldPropertyAccessor implements GremlinIdPropertyAccessor { 11 | 12 | 13 | public GremlinIdFieldPropertyAccessor(Field field) { 14 | super(field); 15 | } 16 | 17 | @Override 18 | public String get(Object object) { 19 | 20 | try { 21 | Object result = field.get(object); 22 | 23 | if (result == null) { 24 | return null; 25 | } 26 | return result.toString(); 27 | } catch (IllegalAccessException e) { 28 | throw new IllegalStateException(e.getMessage(), e); 29 | } 30 | } 31 | 32 | @Override 33 | public void set(Object object, String val) { 34 | try { 35 | field.set(object, val); 36 | } catch (IllegalAccessException e) { 37 | throw new IllegalStateException(e.getMessage(), e); 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /spring-data-gremlin-core/src/main/java/org/springframework/data/gremlin/schema/property/accessor/GremlinIdMapPropertyAccessor.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.schema.property.accessor; 2 | 3 | /** 4 | * 5 | * @author Gman 6 | */ 7 | public class GremlinIdMapPropertyAccessor extends GremlinMapPropertyAccessor implements GremlinIdPropertyAccessor { 8 | 9 | public GremlinIdMapPropertyAccessor() { 10 | super("_id_"); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /spring-data-gremlin-core/src/main/java/org/springframework/data/gremlin/schema/property/accessor/GremlinIdPropertyAccessor.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.schema.property.accessor; 2 | 3 | import org.springframework.data.gremlin.schema.property.GremlinProperty; 4 | 5 | /** 6 | * Interface defining an accessor of an ID {@link GremlinProperty} 7 | * 8 | * @author Gman 9 | */ 10 | public interface GremlinIdPropertyAccessor extends GremlinPropertyAccessor { 11 | } 12 | -------------------------------------------------------------------------------- /spring-data-gremlin-core/src/main/java/org/springframework/data/gremlin/schema/property/accessor/GremlinMapPropertyAccessor.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.schema.property.accessor; 2 | 3 | import org.springframework.util.Assert; 4 | 5 | import java.util.Map; 6 | 7 | /** 8 | * Base {@link GremlinPropertyAccessor} 9 | * 10 | * @param The result value type of the accessor 11 | * @author Gman 12 | */ 13 | public class GremlinMapPropertyAccessor implements GremlinPropertyAccessor { 14 | 15 | private String propertyName; 16 | 17 | public GremlinMapPropertyAccessor(String propertyName) { 18 | Assert.hasLength(propertyName); 19 | this.propertyName = propertyName; 20 | } 21 | 22 | @Override 23 | public V get(Object object) { 24 | 25 | Assert.isTrue(object instanceof Map); 26 | 27 | Map map = (Map) object; 28 | 29 | V result = null; 30 | if (map != null) { 31 | result = (V) map.get(propertyName); 32 | } 33 | return result; 34 | } 35 | 36 | @Override 37 | public void set(Object object, V val) { 38 | 39 | Assert.isTrue(object instanceof Map); 40 | Map map = (Map) object; 41 | 42 | if (map != null) { 43 | map.put(propertyName, val); 44 | } 45 | } 46 | 47 | 48 | @Override 49 | public String toString() { 50 | final StringBuilder sb = new StringBuilder("GremlinMapPropertyAccessor{"); 51 | sb.append("propertyName='").append(propertyName).append('\''); 52 | sb.append('}'); 53 | return sb.toString(); 54 | } 55 | 56 | public String getPropertyName() { 57 | return propertyName; 58 | } 59 | 60 | } 61 | -------------------------------------------------------------------------------- /spring-data-gremlin-core/src/main/java/org/springframework/data/gremlin/schema/property/accessor/GremlinPropertyAccessor.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.schema.property.accessor; 2 | 3 | import org.springframework.data.gremlin.schema.property.GremlinProperty; 4 | 5 | import java.lang.reflect.Field; 6 | 7 | /** 8 | * Interface defining an accessor of a {@link GremlinProperty} 9 | * 10 | * @param The result value type of the accessor 11 | * @author Gman 12 | */ 13 | public interface GremlinPropertyAccessor { 14 | V get(Object object); 15 | 16 | void set(Object object, V val); 17 | } 18 | -------------------------------------------------------------------------------- /spring-data-gremlin-core/src/main/java/org/springframework/data/gremlin/schema/property/accessor/GremlinPropertyFieldAccessor.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.schema.property.accessor; 2 | 3 | import org.springframework.data.gremlin.schema.property.GremlinProperty; 4 | 5 | import java.lang.reflect.Field; 6 | 7 | /** 8 | * Interface defining an accessor of a {@link GremlinProperty} 9 | * 10 | * @param The result value type of the accessor 11 | * @author Gman 12 | */ 13 | public interface GremlinPropertyFieldAccessor extends GremlinPropertyAccessor { 14 | Field getField(); 15 | } 16 | -------------------------------------------------------------------------------- /spring-data-gremlin-core/src/main/java/org/springframework/data/gremlin/schema/property/accessor/GremlinSerializableFieldPropertyAccessor.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.schema.property.accessor; 2 | 3 | import java.io.*; 4 | import java.lang.reflect.Field; 5 | 6 | /** 7 | * A {@link AbstractGremlinFieldPropertyAccessor} for Serializable properties. 8 | * 9 | * @author Gman 10 | */ 11 | public class GremlinSerializableFieldPropertyAccessor extends AbstractGremlinFieldPropertyAccessor { 12 | 13 | public GremlinSerializableFieldPropertyAccessor(Field field) { 14 | super(field); 15 | } 16 | 17 | public GremlinSerializableFieldPropertyAccessor(Field field, GremlinFieldPropertyAccessor parentAccessor) { 18 | super(field, parentAccessor); 19 | } 20 | 21 | @Override 22 | public byte[] get(Object object) { 23 | 24 | try { 25 | Object result = field.get(getEmbeddedObject(object, false)); 26 | 27 | if (result == null) { 28 | return null; 29 | } 30 | 31 | return toArray(result); 32 | } catch (IllegalAccessException | IOException e) { 33 | throw new IllegalStateException(e.getMessage(), e); 34 | } 35 | } 36 | 37 | @Override 38 | public void set(Object object, byte[] serialized) { 39 | try { 40 | object = getEmbeddedObject(object, true); 41 | if (serialized == null) { 42 | field.set(object, serialized); 43 | return; 44 | } 45 | 46 | field.set(object, fromArray(serialized)); 47 | 48 | } catch (IllegalAccessException | IOException | ClassNotFoundException e) { 49 | throw new IllegalStateException(e.getMessage(), e); 50 | } 51 | } 52 | 53 | private Object fromArray(byte[] bytes) throws IOException, ClassNotFoundException { 54 | ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(bytes)); 55 | Object obj = ois.readObject(); 56 | ois.close(); 57 | return obj; 58 | } 59 | 60 | private byte[] toArray(Object serializable) throws IOException { 61 | 62 | ByteArrayOutputStream out = new ByteArrayOutputStream(); 63 | ObjectOutputStream oos = new ObjectOutputStream(out); 64 | oos.writeObject(serializable); 65 | oos.close(); 66 | 67 | return out.toByteArray(); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /spring-data-gremlin-core/src/main/java/org/springframework/data/gremlin/schema/property/encoder/GremlinPropertyEncoder.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.schema.property.encoder; 2 | 3 | /** 4 | * Created by gman on 22/06/15. 5 | */ 6 | public interface GremlinPropertyEncoder { 7 | 8 | Object encode(Object obj); 9 | 10 | Object decode(Object obj); 11 | } 12 | -------------------------------------------------------------------------------- /spring-data-gremlin-core/src/main/java/org/springframework/data/gremlin/schema/property/mapper/GremlinAdjacentPropertyMapper.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.schema.property.mapper; 2 | 3 | import com.tinkerpop.blueprints.Direction; 4 | import com.tinkerpop.blueprints.Edge; 5 | import com.tinkerpop.blueprints.Vertex; 6 | import org.slf4j.Logger; 7 | import org.slf4j.LoggerFactory; 8 | import org.springframework.data.gremlin.repository.GremlinGraphAdapter; 9 | import org.springframework.data.gremlin.schema.property.GremlinAdjacentProperty; 10 | 11 | import java.util.Map; 12 | 13 | /** 14 | * A {@link GremlinPropertyMapper} for mapping {@link GremlinAdjacentProperty}s. 15 | * 16 | * @author Gman 17 | */ 18 | public class GremlinAdjacentPropertyMapper implements GremlinPropertyMapper { 19 | private static final Logger LOGGER = LoggerFactory.getLogger(GremlinAdjacentPropertyMapper.class); 20 | @Override 21 | public void copyToVertex(GremlinAdjacentProperty property, GremlinGraphAdapter graphAdapter, Edge edge, Object val, Map cascadingSchemas) { 22 | 23 | Vertex linkedVertex = edge.getVertex(property.getDirection()); 24 | 25 | if (linkedVertex == null) { 26 | linkedVertex = (Vertex) cascadingSchemas.get(val); 27 | } 28 | 29 | if (linkedVertex != null && (Boolean.getBoolean(CASCADE_ALL_KEY) || property.getDirection() == Direction.OUT)) { 30 | LOGGER.debug("Cascading copy of " + property.getRelatedSchema().getClassName()); 31 | // Updates or saves the val into the linkedVertex 32 | property.getRelatedSchema().cascadeCopyToGraph(graphAdapter, linkedVertex, val, cascadingSchemas); 33 | } 34 | 35 | } 36 | 37 | @Override 38 | public Object loadFromVertex(GremlinAdjacentProperty property, GremlinGraphAdapter graphAdapter, Edge edge, Map cascadingSchemas) { 39 | Object val = null; 40 | Vertex linkedVertex = edge.getVertex(property.getDirection()); 41 | if (linkedVertex != null) { 42 | graphAdapter.refresh(linkedVertex); 43 | val = property.getRelatedSchema().cascadeLoadFromGraph(graphAdapter, linkedVertex, cascadingSchemas); 44 | } 45 | return val; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /spring-data-gremlin-core/src/main/java/org/springframework/data/gremlin/schema/property/mapper/GremlinEncodedPropertyMapper.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.schema.property.mapper; 2 | 3 | import com.tinkerpop.blueprints.Element; 4 | import org.springframework.data.gremlin.repository.GremlinGraphAdapter; 5 | import org.springframework.data.gremlin.schema.property.GremlinProperty; 6 | import org.springframework.data.gremlin.schema.property.encoder.GremlinPropertyEncoder; 7 | 8 | import java.util.Map; 9 | 10 | /** 11 | * An extended {@link GremlinStandardPropertyMapper} for mapping custom encoded properties. 12 | * 13 | * @author Gman 14 | */ 15 | public class GremlinEncodedPropertyMapper extends GremlinStandardPropertyMapper { 16 | 17 | private GremlinPropertyEncoder propertyEncoder; 18 | 19 | public GremlinEncodedPropertyMapper() { 20 | } 21 | 22 | public GremlinEncodedPropertyMapper(GremlinPropertyEncoder propertyEncoder) { 23 | this.propertyEncoder = propertyEncoder; 24 | } 25 | 26 | @Override 27 | public void copyToVertex(GremlinProperty property, GremlinGraphAdapter graphAdapter, Element element, Object val, Map cascadingSchemas) { 28 | Object id = val; 29 | if (propertyEncoder != null) { 30 | id = propertyEncoder.decode(val); 31 | } 32 | super.copyToVertex(property, graphAdapter, element, id, cascadingSchemas); 33 | } 34 | 35 | @Override 36 | public Object loadFromVertex(GremlinProperty property, GremlinGraphAdapter graphAdapter, Element element, Map cascadingSchemas) { 37 | Object id = super.loadFromVertex(property, graphAdapter, element, cascadingSchemas); 38 | if (propertyEncoder != null) { 39 | id = propertyEncoder.encode(id); 40 | } 41 | return id; 42 | } 43 | 44 | 45 | } 46 | -------------------------------------------------------------------------------- /spring-data-gremlin-core/src/main/java/org/springframework/data/gremlin/schema/property/mapper/GremlinObjectMapperException.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.schema.property.mapper; 2 | 3 | /** 4 | * @author Gman 5 | */ 6 | public class GremlinObjectMapperException extends Throwable { 7 | public GremlinObjectMapperException(String msg) {super(msg);} 8 | 9 | public GremlinObjectMapperException(String msg, Exception e) { 10 | super(msg, e); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /spring-data-gremlin-core/src/main/java/org/springframework/data/gremlin/schema/property/mapper/GremlinPropertyMapper.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.schema.property.mapper; 2 | 3 | import com.tinkerpop.blueprints.Element; 4 | import com.tinkerpop.blueprints.Vertex; 5 | import org.springframework.data.gremlin.repository.GremlinGraphAdapter; 6 | import org.springframework.data.gremlin.schema.property.GremlinProperty; 7 | 8 | import java.util.Map; 9 | 10 | /** 11 | * Defines mapping a {@link GremlinProperty} to a {@link Vertex}. 12 | * 13 | * @author Gman 14 | */ 15 | public interface GremlinPropertyMapper { 16 | 17 | String CASCADE_ALL_KEY = "sdg-cascade-all"; 18 | 19 | void copyToVertex(E property, GremlinGraphAdapter graphAdapter, V element, Object val, Map cascadingSchemas); 20 | 21 | Object loadFromVertex(E property, GremlinGraphAdapter graphAdapter, V element, Map cascadingSchemas); 22 | } 23 | -------------------------------------------------------------------------------- /spring-data-gremlin-core/src/main/java/org/springframework/data/gremlin/schema/property/mapper/GremlinStandardPropertyMapper.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.schema.property.mapper; 2 | 3 | import com.tinkerpop.blueprints.Element; 4 | import com.tinkerpop.blueprints.Vertex; 5 | import org.slf4j.Logger; 6 | import org.slf4j.LoggerFactory; 7 | import org.springframework.data.gremlin.repository.GremlinGraphAdapter; 8 | import org.springframework.data.gremlin.schema.property.GremlinProperty; 9 | 10 | import java.util.Map; 11 | 12 | /** 13 | * A concrete {@link GremlinPropertyMapper} for mapping stadard Java types to Vertex properties. 14 | * 15 | * @author Gman 16 | */ 17 | public class GremlinStandardPropertyMapper implements GremlinPropertyMapper { 18 | 19 | private static final Logger LOGGER = LoggerFactory.getLogger(GremlinStandardPropertyMapper.class); 20 | 21 | @Override 22 | public void copyToVertex(GremlinProperty property, GremlinGraphAdapter graphAdapter, Element element, Object val, Map cascadingSchemas) { 23 | LOGGER.debug("Mapping property: " + property.getName() + " to element: " + element); 24 | element.setProperty(property.getName(), val); 25 | } 26 | 27 | @Override 28 | public Object loadFromVertex(GremlinProperty property, GremlinGraphAdapter graphAdapter, Element element, Map cascadingSchemas) { 29 | return element.getProperty(property.getName()); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /spring-data-gremlin-core/src/main/java/org/springframework/data/gremlin/schema/writer/SchemaWriter.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.schema.writer; 2 | 3 | import org.springframework.data.gremlin.schema.GremlinSchema; 4 | import org.springframework.data.gremlin.tx.GremlinGraphFactory; 5 | 6 | /** 7 | * Interface defining schema writer implementations. 8 | * 9 | * @author Gman 10 | */ 11 | public interface SchemaWriter { 12 | 13 | void writeSchema(GremlinGraphFactory dbf, GremlinSchema schema) throws SchemaWriterException; 14 | 15 | } 16 | -------------------------------------------------------------------------------- /spring-data-gremlin-core/src/main/java/org/springframework/data/gremlin/schema/writer/SchemaWriterException.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.schema.writer; 2 | 3 | /** 4 | * @author Gman 5 | */ 6 | public class SchemaWriterException extends Exception { 7 | public SchemaWriterException(String message) { 8 | super(message); 9 | } 10 | 11 | public SchemaWriterException(String message, Throwable cause) { 12 | super(message, cause); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /spring-data-gremlin-core/src/main/java/org/springframework/data/gremlin/support/GremlinMetamodelEntityInformation.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.support; 2 | 3 | import org.springframework.data.gremlin.schema.property.accessor.GremlinIdPropertyAccessor; 4 | import org.springframework.data.repository.core.support.AbstractEntityInformation; 5 | 6 | /** 7 | * An {@link AbstractEntityInformation} for Gremlin. 8 | * 9 | * @param The class type of the entity 10 | * @author Gman 11 | */ 12 | public class GremlinMetamodelEntityInformation extends AbstractEntityInformation { 13 | 14 | private GremlinIdPropertyAccessor idAccessor; 15 | 16 | public GremlinMetamodelEntityInformation(Class domainClass, GremlinIdPropertyAccessor idAccessor) { 17 | super(domainClass); 18 | this.idAccessor = idAccessor; 19 | } 20 | 21 | public String getId(T entity) { 22 | return idAccessor.get(entity); 23 | } 24 | 25 | public Class getIdType() { 26 | return String.class; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /spring-data-gremlin-core/src/main/java/org/springframework/data/gremlin/support/GremlinRepositoryFactoryBean.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.support; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.data.gremlin.repository.GremlinRepository; 5 | import org.springframework.data.gremlin.repository.GremlinRepositoryContext; 6 | import org.springframework.data.repository.core.support.RepositoryFactorySupport; 7 | import org.springframework.data.repository.core.support.TransactionalRepositoryFactoryBeanSupport; 8 | 9 | /** 10 | * Special adapter for Springs {@link org.springframework.beans.factory.FactoryBean} interface to allow easy setup of 11 | * repository factories via Spring configuration. 12 | * 13 | * @param the type of the repository 14 | * @param the type of the entity 15 | * @author Gman 16 | */ 17 | public class GremlinRepositoryFactoryBean, S> extends TransactionalRepositoryFactoryBeanSupport { 18 | 19 | /** The orient operations. */ 20 | @Autowired 21 | private GremlinRepositoryContext context; 22 | 23 | public GremlinRepositoryFactoryBean() { 24 | } 25 | 26 | /* (non-Javadoc) 27 | * @see org.springframework.data.repository.core.support.TransactionalRepositoryFactoryBeanSupport#doCreateRepositoryFactory() 28 | */ 29 | @Override 30 | protected RepositoryFactorySupport doCreateRepositoryFactory() { 31 | return new GremlinRepositoryFactory(context); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /spring-data-gremlin-core/src/main/java/org/springframework/data/gremlin/tx/GremlinGraphFactory.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.tx; 2 | 3 | import com.tinkerpop.blueprints.Graph; 4 | 5 | /** 6 | * An interface defining a Gremlin {@link Graph} factory. 7 | * 8 | * @param The implementing type extending {@link Graph} 9 | * @author Gman 10 | */ 11 | public interface GremlinGraphFactory { 12 | /** Default database username. */ 13 | String DEFAULT_USERNAME = "admin"; 14 | 15 | /** Default database password. */ 16 | String DEFAULT_PASSWORD = "admin"; 17 | 18 | /** Default minimum pool size. */ 19 | int DEFAULT_MIN_POOL_SIZE = 1; 20 | 21 | /** Default maximum pool size. */ 22 | int DEFAULT_MAX_POOL_SIZE = 20; 23 | 24 | boolean isActive(T graph); 25 | 26 | boolean isClosed(T graph); 27 | 28 | void beginTx(T graph); 29 | 30 | void commitTx(T graph); 31 | 32 | void rollbackTx(T graph); 33 | 34 | T graph(); 35 | 36 | T openGraph(); 37 | 38 | void shutdown(T graph); 39 | 40 | String getUrl(); 41 | 42 | void setUrl(String url); 43 | 44 | String getUsername(); 45 | 46 | void setUsername(String username); 47 | 48 | String getPassword(); 49 | 50 | void setPassword(String password); 51 | 52 | int getMinPoolSize(); 53 | 54 | void setMinPoolSize(int minPoolSize); 55 | 56 | int getMaxPoolSize(); 57 | 58 | void setMaxPoolSize(int maxPoolSize); 59 | 60 | Class getRetryException(); 61 | 62 | RuntimeException getForceRetryException(); 63 | 64 | void resumeTx(T oldGraph); 65 | } 66 | -------------------------------------------------------------------------------- /spring-data-gremlin-core/src/main/java/org/springframework/data/gremlin/tx/GremlinTransaction.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.tx; 2 | 3 | import com.tinkerpop.blueprints.Graph; 4 | 5 | /** 6 | * Created by gman on 4/05/15. 7 | */ 8 | public class GremlinTransaction { 9 | 10 | private Graph graph; 11 | 12 | public GremlinTransaction(Graph graph) { 13 | this.graph = graph; 14 | } 15 | 16 | public Graph getGraph() { 17 | return graph; 18 | } 19 | 20 | public void setGraph(Graph graph) { 21 | this.graph = graph; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /spring-data-gremlin-core/src/test/java/org/springframework/data/gremlin/schema/GremlinEnumCollectionSetFieldAccessorTest.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.schema; 2 | 3 | import org.junit.Before; 4 | import org.junit.Test; 5 | import org.springframework.data.gremlin.schema.property.accessor.GremlinEnumStringCollectionFieldPropertyAccessor; 6 | 7 | import java.util.HashSet; 8 | 9 | import static org.junit.Assert.assertEquals; 10 | import static org.junit.Assert.assertNotNull; 11 | import static org.junit.Assert.assertTrue; 12 | 13 | /** 14 | * Created by gman on 18/05/15. 15 | */ 16 | public class GremlinEnumCollectionSetFieldAccessorTest { 17 | TestObject obj1; 18 | 19 | GremlinEnumStringCollectionFieldPropertyAccessor accessor; 20 | 21 | @Before 22 | public void setUp() throws Exception { 23 | obj1 = new TestObject(); 24 | 25 | accessor = new GremlinEnumStringCollectionFieldPropertyAccessor(TestObject.class.getDeclaredField("test")); 26 | } 27 | 28 | @Test 29 | public void should_read_all_variables() throws Exception { 30 | obj1.test.add(TestObject.TEST.ONE); 31 | obj1.test.add(TestObject.TEST.TWO); 32 | 33 | String obj = accessor.get(obj1); 34 | assertTrue(obj.contains("ONE")); 35 | assertTrue(obj.contains("TWO")); 36 | } 37 | 38 | @Test 39 | public void should_read_null_variables() throws Exception { 40 | obj1.test = null; 41 | assertEquals(null, accessor.get(obj1)); 42 | } 43 | 44 | @Test 45 | public void should_write_all_variables() throws Exception { 46 | accessor.set(obj1, "TWO,THREE"); 47 | assertNotNull(obj1.test); 48 | boolean has2 = false; 49 | boolean has3 = false; 50 | for (TestObject.TEST testEnum : obj1.test) { 51 | if(testEnum == TestObject.TEST.TWO) { 52 | has2 = true; 53 | } 54 | if (testEnum == TestObject.TEST.THREE) { 55 | has3 = true; 56 | } 57 | } 58 | 59 | assertTrue(has2); 60 | assertTrue(has3); 61 | } 62 | 63 | @Test 64 | public void should_write_all_nulls() throws Exception { 65 | accessor.set(obj1, null); 66 | assertEquals(null, obj1.test); 67 | } 68 | 69 | static class TestObject { 70 | public enum TEST { 71 | ONE, 72 | TWO, 73 | THREE 74 | } 75 | 76 | HashSet test = new HashSet<>(); 77 | } 78 | 79 | } -------------------------------------------------------------------------------- /spring-data-gremlin-core/src/test/java/org/springframework/data/gremlin/schema/GremlinEnumOrdinalFieldAccessorTest.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.schema; 2 | 3 | import org.junit.Before; 4 | import org.junit.Test; 5 | import org.springframework.data.gremlin.schema.property.accessor.GremlinEnumOrdinalFieldPropertyAccessor; 6 | import org.springframework.data.gremlin.schema.property.accessor.GremlinPropertyAccessor; 7 | 8 | import static org.junit.Assert.assertEquals; 9 | 10 | /** 11 | * Created by gman on 18/05/15. 12 | */ 13 | public class GremlinEnumOrdinalFieldAccessorTest { 14 | TestObject obj1; 15 | 16 | GremlinPropertyAccessor accessor; 17 | 18 | @Before 19 | public void setUp() throws Exception { 20 | obj1 = new TestObject(); 21 | 22 | accessor = new GremlinEnumOrdinalFieldPropertyAccessor(TestObject.class.getDeclaredField("test"), TestObject.TEST.class); 23 | } 24 | 25 | 26 | @Test 27 | public void should_read_all_variables() throws Exception { 28 | assertEquals(0, accessor.get(obj1)); 29 | } 30 | 31 | @Test 32 | public void should_read_null_variables() throws Exception { 33 | obj1.test = null; 34 | assertEquals(null, accessor.get(obj1)); 35 | } 36 | 37 | @Test 38 | public void should_write_all_variables() throws Exception { 39 | accessor.set(obj1, 1); 40 | assertEquals(obj1.test, TestObject.TEST.TWO); 41 | } 42 | 43 | @Test 44 | public void should_write_all_nulls() throws Exception { 45 | accessor.set(obj1, null); 46 | assertEquals(null, obj1.test); 47 | } 48 | 49 | static class TestObject { 50 | public enum TEST { 51 | ONE, 52 | TWO 53 | } 54 | 55 | TEST test = TEST.ONE; 56 | } 57 | 58 | } -------------------------------------------------------------------------------- /spring-data-gremlin-core/src/test/java/org/springframework/data/gremlin/schema/GremlinEnumStringFieldAccessorTest.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.schema; 2 | 3 | import org.junit.Before; 4 | import org.junit.Test; 5 | import org.springframework.data.gremlin.schema.property.accessor.GremlinEnumStringFieldPropertyAccessor; 6 | import org.springframework.data.gremlin.schema.property.accessor.GremlinPropertyAccessor; 7 | 8 | import static org.junit.Assert.assertEquals; 9 | 10 | /** 11 | * Created by gman on 18/05/15. 12 | */ 13 | public class GremlinEnumStringFieldAccessorTest { 14 | TestObject obj1; 15 | 16 | GremlinPropertyAccessor accessor; 17 | 18 | @Before 19 | public void setUp() throws Exception { 20 | obj1 = new TestObject(); 21 | 22 | accessor = new GremlinEnumStringFieldPropertyAccessor(TestObject.class.getDeclaredField("test"), TestObject.TEST.class); 23 | } 24 | 25 | 26 | @Test 27 | public void should_read_all_variables() throws Exception { 28 | assertEquals("ONE", accessor.get(obj1)); 29 | } 30 | 31 | @Test 32 | public void should_read_null_variables() throws Exception { 33 | obj1.test = null; 34 | assertEquals(null, accessor.get(obj1)); 35 | } 36 | 37 | @Test 38 | public void should_write_all_variables() throws Exception { 39 | accessor.set(obj1, "TWO"); 40 | assertEquals(obj1.test, TestObject.TEST.TWO); 41 | } 42 | 43 | @Test 44 | public void should_write_all_nulls() throws Exception { 45 | accessor.set(obj1, null); 46 | assertEquals(null, obj1.test); 47 | } 48 | 49 | static class TestObject { 50 | public enum TEST { 51 | ONE, 52 | TWO 53 | } 54 | 55 | TEST test = TEST.ONE; 56 | } 57 | 58 | } -------------------------------------------------------------------------------- /spring-data-gremlin-core/src/test/java/org/springframework/data/gremlin/schema/GremlinFieldAccessorTest.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.schema; 2 | 3 | import org.junit.Before; 4 | import org.junit.Test; 5 | import org.springframework.data.gremlin.schema.property.accessor.GremlinFieldPropertyAccessor; 6 | import org.springframework.data.gremlin.schema.property.accessor.GremlinPropertyAccessor; 7 | 8 | import static org.junit.Assert.assertEquals; 9 | 10 | /** 11 | * Created by gman on 18/05/15. 12 | */ 13 | public class GremlinFieldAccessorTest { 14 | TestObject obj1; 15 | 16 | GremlinPropertyAccessor primAccessor; 17 | GremlinPropertyAccessor strAccessor; 18 | GremlinPropertyAccessor objAccessor; 19 | 20 | @Before 21 | public void setUp() throws Exception { 22 | obj1 = new TestObject(); 23 | 24 | strAccessor = new GremlinFieldPropertyAccessor(TestObject.class.getDeclaredField("str")); 25 | objAccessor = new GremlinFieldPropertyAccessor(TestObject.class.getDeclaredField("obj")); 26 | primAccessor = new GremlinFieldPropertyAccessor(TestObject.class.getDeclaredField("prim")); 27 | } 28 | 29 | 30 | @Test 31 | public void should_read_all_variables() throws Exception { 32 | assertEquals(10, primAccessor.get(obj1)); 33 | assertEquals("bla", strAccessor.get(obj1)); 34 | assertEquals(obj1.obj, objAccessor.get(obj1)); 35 | } 36 | 37 | @Test 38 | public void should_read_null_variables() throws Exception { 39 | obj1.prim = 0; 40 | obj1.str = null; 41 | obj1.obj = null; 42 | assertEquals(0, primAccessor.get(obj1)); 43 | assertEquals(null, strAccessor.get(obj1)); 44 | assertEquals(null, objAccessor.get(obj1)); 45 | } 46 | 47 | @Test 48 | public void should_write_all_variables() throws Exception { 49 | primAccessor.set(obj1, 55); 50 | strAccessor.set(obj1, "olb"); 51 | TestObject2 obj3 = new TestObject2(); 52 | objAccessor.set(obj1, obj3); 53 | 54 | 55 | assertEquals(obj1.prim, 55); 56 | assertEquals(obj1.str, "olb"); 57 | assertEquals(obj1.obj, obj3); 58 | } 59 | 60 | @Test 61 | public void should_write_all_nulls() throws Exception { 62 | primAccessor.set(obj1, 0); 63 | strAccessor.set(obj1, null); 64 | objAccessor.set(obj1, null); 65 | 66 | 67 | assertEquals(obj1.prim, 0); 68 | assertEquals(obj1.str, null); 69 | assertEquals(obj1.obj, null); 70 | } 71 | 72 | class TestObject { 73 | int prim = 10; 74 | String str = "bla"; 75 | TestObject2 obj = new TestObject2(); 76 | } 77 | 78 | class TestObject2 { } 79 | } 80 | -------------------------------------------------------------------------------- /spring-data-gremlin-core/src/test/java/org/springframework/data/gremlin/schema/property/accessor/GremlinJSONFieldPropertyAccessorTest.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.schema.property.accessor; 2 | 3 | import org.junit.Test; 4 | 5 | import java.util.ArrayList; 6 | import java.util.HashSet; 7 | import java.util.List; 8 | import java.util.Set; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Created by gman on 12/10/15. 14 | */ 15 | public class GremlinJSONFieldPropertyAccessorTest { 16 | 17 | @Test 18 | public void testGet() throws Exception { 19 | 20 | TestObject object = new TestObject(); 21 | object.rectangles.add(new Rectangle(10, 10)); 22 | 23 | GremlinJSONFieldPropertyAccessor accessor = new GremlinJSONFieldPropertyAccessor(TestObject.class.getDeclaredField("rectangles"), RectangleMixIn.class); 24 | 25 | String serialised = accessor.get(object); 26 | assertNotNull(serialised); 27 | assertEquals("[{\"width\":10,\"height\":10}]", serialised); 28 | } 29 | 30 | @Test 31 | public void testSet() throws Exception { 32 | 33 | String serialised = "[{\"width\":15,\"height\":15}]"; 34 | 35 | TestObject object = new TestObject(); 36 | 37 | GremlinJSONFieldPropertyAccessor accessor = new GremlinJSONFieldPropertyAccessor(TestObject.class.getDeclaredField("rectangles"), RectangleMixIn.class); 38 | 39 | accessor.set(object, serialised); 40 | assertNotNull(object.rectangles); 41 | assertEquals(1, object.rectangles.size()); 42 | assertEquals(15, object.rectangles.get(0).getW()); 43 | assertEquals(15, object.rectangles.get(0).getH()); 44 | } 45 | 46 | public class TestObject { 47 | private List rectangles = new ArrayList<>(); 48 | } 49 | 50 | 51 | } -------------------------------------------------------------------------------- /spring-data-gremlin-core/src/test/java/org/springframework/data/gremlin/schema/property/accessor/Rectangle.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.schema.property.accessor; 2 | 3 | /** 4 | * Created by gman on 12/10/15. 5 | */ 6 | public final class Rectangle { 7 | final private int w, h; 8 | 9 | public Rectangle(int w, int h) { 10 | this.w = w; 11 | this.h = h; 12 | } 13 | 14 | public int getW() { return w; } 15 | 16 | public int getH() { return h; } 17 | 18 | public int getSize() { return w * h; } 19 | } 20 | -------------------------------------------------------------------------------- /spring-data-gremlin-core/src/test/java/org/springframework/data/gremlin/schema/property/accessor/RectangleMixIn.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.schema.property.accessor; 2 | 3 | import com.fasterxml.jackson.annotation.JsonCreator; 4 | import com.fasterxml.jackson.annotation.JsonIgnore; 5 | import com.fasterxml.jackson.annotation.JsonProperty; 6 | 7 | /** 8 | * Created by gman on 12/10/15. 9 | */ 10 | abstract class RectangleMixIn { 11 | @JsonCreator 12 | RectangleMixIn(@JsonProperty("width") int w, @JsonProperty("height") int h) { } 13 | 14 | // note: could alternatively annotate fields "w" and "h" as well -- if so, would need to @JsonIgnore getters 15 | @JsonProperty("width") 16 | abstract int getW(); // rename property 17 | 18 | @JsonProperty("height") 19 | abstract int getH(); // rename property 20 | 21 | @JsonIgnore 22 | abstract int getSize(); // we don't need it! 23 | 24 | } 25 | -------------------------------------------------------------------------------- /spring-data-gremlin-core/src/test/java/org/springframework/data/gremlin/schema/property/mapper/GremlinLinkToPropertyMapperTest.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.schema.property.mapper; 2 | 3 | import com.tinkerpop.blueprints.Direction; 4 | import com.tinkerpop.blueprints.Edge; 5 | import com.tinkerpop.blueprints.Vertex; 6 | import org.mockito.Mockito; 7 | import org.springframework.data.gremlin.repository.GremlinGraphAdapter; 8 | import org.springframework.data.gremlin.schema.property.GremlinLinkProperty; 9 | 10 | import java.util.HashMap; 11 | import java.util.HashSet; 12 | 13 | /** 14 | * Created by gman on 24/07/15. 15 | */ 16 | public class GremlinLinkToPropertyMapperTest { 17 | 18 | // @Test 19 | public void testCopyToVertex() throws Exception { 20 | 21 | Object test = new Object(); 22 | GremlinLinkProperty prop = new GremlinLinkProperty(Object.class, "test", Direction.OUT); 23 | GremlinGraphAdapter adapter = Mockito.mock(GremlinGraphAdapter.class); 24 | Vertex vertex = Mockito.mock(Vertex.class); 25 | 26 | Mockito.when(vertex.getEdges(Direction.OUT, "test")).thenReturn(new HashSet()); 27 | 28 | 29 | GremlinLinkPropertyMapper mapper = new GremlinLinkPropertyMapper(); 30 | mapper.copyToVertex(prop, adapter, vertex, test, new HashMap<>()); 31 | 32 | } 33 | 34 | // @Test 35 | public void testLoadFromVertex() throws Exception { 36 | 37 | } 38 | } -------------------------------------------------------------------------------- /spring-data-gremlin-core/src/test/resources/application.properties: -------------------------------------------------------------------------------- 1 | 2 | logging.level.org.springframework.data.gremlin=DEBUG 3 | #logging.level.org.springframework=DEBUG -------------------------------------------------------------------------------- /spring-data-gremlin-orientdb/build.gradle: -------------------------------------------------------------------------------- 1 | dependencies { 2 | compile project(':spring-data-gremlin-core') 3 | compile('com.orientechnologies:orientdb-lucene:2.1.12') 4 | compile('com.orientechnologies:orientdb-graphdb:2.1.12') 5 | testCompile project(':spring-data-gremlin-schemagen-jpa') 6 | testCompile project(':spring-data-gremlin-schemagen-neo4j') 7 | testCompile project(':spring-data-gremlin-test') 8 | } -------------------------------------------------------------------------------- /spring-data-gremlin-orientdb/src/main/java/org/springframework/data/gremlin/repository/orientdb/OrientDBGraphAdapter.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.repository.orientdb; 2 | 3 | import com.orientechnologies.orient.core.id.ORecordId; 4 | import com.orientechnologies.orient.core.metadata.security.OIdentity; 5 | import com.tinkerpop.blueprints.Element; 6 | import com.tinkerpop.blueprints.Vertex; 7 | import com.tinkerpop.blueprints.impls.orient.OrientElement; 8 | import com.tinkerpop.blueprints.impls.orient.OrientGraph; 9 | import org.slf4j.Logger; 10 | import org.slf4j.LoggerFactory; 11 | import org.springframework.data.gremlin.repository.GremlinGraphAdapter; 12 | import org.springframework.data.gremlin.schema.property.encoder.GremlinPropertyEncoder; 13 | import org.springframework.data.gremlin.schema.property.encoder.orientdb.OrientDbIdEncoder; 14 | import org.springframework.transaction.annotation.Transactional; 15 | 16 | /** 17 | * Created by gman on 27/06/15. 18 | */ 19 | public class OrientDBGraphAdapter extends GremlinGraphAdapter { 20 | 21 | private static final Logger LOGGER = LoggerFactory.getLogger(OrientDBGraphAdapter.class); 22 | 23 | private GremlinPropertyEncoder idEncoder = new OrientDbIdEncoder(); 24 | 25 | @Override 26 | @Transactional(readOnly = false) 27 | public Vertex createVertex(OrientGraph graph, String className) { 28 | String classname = "class:" + className; 29 | Vertex vertex = graph.addVertex(classname); 30 | return vertex; 31 | } 32 | 33 | @Override 34 | public Element refresh(Element element) { 35 | ((OrientElement) element).reload(); 36 | return element; 37 | } 38 | 39 | public String encodeId(String id) { 40 | if (id == null) { 41 | return null; 42 | } 43 | if (idEncoder != null) { 44 | id = idEncoder.encode(id).toString(); 45 | } 46 | return id; 47 | } 48 | 49 | public String decodeId(String id) { 50 | if (id == null) { 51 | return null; 52 | } 53 | if (idEncoder != null) { 54 | id = idEncoder.decode(id).toString(); 55 | } 56 | return id; 57 | } 58 | 59 | @Override 60 | public boolean isValidId(String id) { 61 | return super.isValidId(id) && !id.contains("-"); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /spring-data-gremlin-orientdb/src/main/java/org/springframework/data/gremlin/schema/property/encoder/orientdb/OrientDbIdEncoder.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.schema.property.encoder.orientdb; 2 | 3 | import org.springframework.data.gremlin.schema.property.encoder.GremlinPropertyEncoder; 4 | 5 | /** 6 | * Created by gman on 23/06/15. 7 | */ 8 | public class OrientDbIdEncoder implements GremlinPropertyEncoder { 9 | 10 | @Override 11 | public Object encode(Object obj) { 12 | if (obj == null) { 13 | return null; 14 | } 15 | return obj.toString().replace('#', 'c').replace(':', 'p'); 16 | } 17 | 18 | @Override 19 | public Object decode(Object id) { 20 | if (id == null) { 21 | return null; 22 | } 23 | return id.toString().replace('c', '#').replace('p', ':'); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /spring-data-gremlin-orientdb/src/test/java/org/springframework/data/gremlin/object/tests/orientdb/core/OrientDB_Core_AddressRepositoryTest.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.object.tests.orientdb.core; 2 | 3 | import org.springframework.data.gremlin.object.core.repository.AbstractAddressRepositoryTest; 4 | import org.springframework.test.context.ContextConfiguration; 5 | 6 | /** 7 | * Created by gman on 24/06/15. 8 | */ 9 | @ContextConfiguration(classes = OrientDB_Core_TestConfiguration.class) 10 | public class OrientDB_Core_AddressRepositoryTest extends AbstractAddressRepositoryTest { } 11 | -------------------------------------------------------------------------------- /spring-data-gremlin-orientdb/src/test/java/org/springframework/data/gremlin/object/tests/orientdb/core/OrientDB_Core_EdgeRepositoryTest.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.object.tests.orientdb.core; 2 | 3 | import org.springframework.data.gremlin.object.core.repository.AbstractEdgeRepositoryTest; 4 | import org.springframework.test.context.ContextConfiguration; 5 | 6 | /** 7 | * Created by gman on 24/06/15. 8 | */ 9 | @ContextConfiguration(classes = OrientDB_Core_TestConfiguration.class) 10 | public class OrientDB_Core_EdgeRepositoryTest extends AbstractEdgeRepositoryTest { } 11 | -------------------------------------------------------------------------------- /spring-data-gremlin-orientdb/src/test/java/org/springframework/data/gremlin/object/tests/orientdb/core/OrientDB_Core_PersonRepositoryTest.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.object.tests.orientdb.core; 2 | 3 | import org.junit.Assert; 4 | import org.junit.Test; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.data.domain.Page; 7 | import org.springframework.data.domain.PageRequest; 8 | import org.springframework.data.gremlin.object.core.domain.Person; 9 | import org.springframework.data.gremlin.object.core.repository.AbstractPersonRepositoryTest; 10 | import org.springframework.data.gremlin.object.core.repository.NativePersonRepository; 11 | import org.springframework.test.context.ContextConfiguration; 12 | 13 | import java.util.Iterator; 14 | 15 | /** 16 | * Created by gman on 24/06/15. 17 | */ 18 | @ContextConfiguration(classes = OrientDB_Core_TestConfiguration.class) 19 | @SuppressWarnings("SpringJavaAutowiringInspection") 20 | public class OrientDB_Core_PersonRepositoryTest extends AbstractPersonRepositoryTest { 21 | 22 | @Autowired 23 | protected NativePersonRepository nativePersonRepository; 24 | 25 | @Test 26 | public void testDeleteAllExcept() throws Exception { 27 | int count = nativePersonRepository.deleteAllExceptUser("Lara"); 28 | Assert.assertEquals(4, count); 29 | 30 | Iterable persons = repository.findAll(); 31 | Assert.assertNotNull(persons); 32 | Iterator iterator = persons.iterator(); 33 | Assert.assertNotNull(iterator); 34 | Assert.assertNotNull(iterator.next()); 35 | Assert.assertFalse(iterator.hasNext()); 36 | } 37 | 38 | 39 | @Test 40 | public void findPeopleNear() throws Exception { 41 | Page page = nativePersonRepository.findNear(-33, 151, 50, new PageRequest(0, 10)); 42 | Assert.assertEquals(1, page.getTotalElements()); 43 | 44 | Person person = page.iterator().next(); 45 | Assert.assertNotNull(person); 46 | Assert.assertEquals("Graham", person.getFirstName()); 47 | Assert.assertNotNull(person.getLocations()); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /spring-data-gremlin-orientdb/src/test/java/org/springframework/data/gremlin/object/tests/orientdb/core/OrientDB_Core_SpatialRepositoryTest.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.object.tests.orientdb.core; 2 | 3 | import org.springframework.data.gremlin.object.core.repository.AbstractLocationRepositoryTest; 4 | import org.springframework.test.context.ContextConfiguration; 5 | 6 | /** 7 | * Created by gman on 24/06/15. 8 | */ 9 | @ContextConfiguration(classes = OrientDB_Core_TestConfiguration.class) 10 | public class OrientDB_Core_SpatialRepositoryTest extends AbstractLocationRepositoryTest { } 11 | -------------------------------------------------------------------------------- /spring-data-gremlin-orientdb/src/test/java/org/springframework/data/gremlin/object/tests/orientdb/core/OrientDB_Core_TransactionRepositoryTest.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.object.tests.orientdb.core; 2 | 3 | import org.springframework.data.gremlin.object.core.repository.AbstractTransactionRepositoryTest; 4 | import org.springframework.test.context.ContextConfiguration; 5 | 6 | /** 7 | * Created by gman on 24/06/15. 8 | */ 9 | @ContextConfiguration(classes = OrientDB_Core_TestConfiguration.class) 10 | @SuppressWarnings("SpringJavaAutowiringInspection") 11 | public class OrientDB_Core_TransactionRepositoryTest extends AbstractTransactionRepositoryTest { 12 | 13 | } 14 | -------------------------------------------------------------------------------- /spring-data-gremlin-orientdb/src/test/java/org/springframework/data/gremlin/object/tests/orientdb/jpa/OrientDB_JPA_AddressRepositoryTest.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.object.tests.orientdb.jpa; 2 | 3 | import org.springframework.data.gremlin.object.jpa.repository.AbstractAddressRepositoryTest; 4 | import org.springframework.test.context.ContextConfiguration; 5 | 6 | /** 7 | * Created by gman on 24/06/15. 8 | */ 9 | @ContextConfiguration(classes = OrientDB_JPA_TestConfiguration.class) 10 | public class OrientDB_JPA_AddressRepositoryTest extends AbstractAddressRepositoryTest { } 11 | -------------------------------------------------------------------------------- /spring-data-gremlin-orientdb/src/test/java/org/springframework/data/gremlin/object/tests/orientdb/jpa/OrientDB_JPA_PersonRepositoryTest.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.object.tests.orientdb.jpa; 2 | 3 | import org.junit.Assert; 4 | import org.junit.Test; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.data.domain.Page; 7 | import org.springframework.data.domain.PageRequest; 8 | import org.springframework.data.gremlin.object.jpa.domain.Person; 9 | import org.springframework.data.gremlin.object.jpa.repository.AbstractPersonRepositoryTest; 10 | import org.springframework.data.gremlin.object.jpa.repository.NativePersonRepository; 11 | import org.springframework.test.context.ContextConfiguration; 12 | 13 | import java.util.Iterator; 14 | 15 | /** 16 | * Created by gman on 24/06/15. 17 | */ 18 | @ContextConfiguration(classes = OrientDB_JPA_TestConfiguration.class) 19 | @SuppressWarnings("SpringJavaAutowiringInspection") 20 | public class OrientDB_JPA_PersonRepositoryTest extends AbstractPersonRepositoryTest { 21 | 22 | @Autowired 23 | protected NativePersonRepository nativePersonRepository; 24 | 25 | @Test 26 | public void testDeleteAllExcept() throws Exception { 27 | int count = nativePersonRepository.deleteAllExceptUser("Lara"); 28 | Assert.assertEquals(4, count); 29 | 30 | Iterable persons = repository.findAll(); 31 | Assert.assertNotNull(persons); 32 | Iterator iterator = persons.iterator(); 33 | Assert.assertNotNull(iterator); 34 | Assert.assertNotNull(iterator.next()); 35 | Assert.assertFalse(iterator.hasNext()); 36 | } 37 | 38 | 39 | @Test 40 | public void findPeopleNear() throws Exception { 41 | Page page = nativePersonRepository.findNear(-33, 151, 50, new PageRequest(0, 10)); 42 | Assert.assertEquals(1, page.getTotalElements()); 43 | 44 | Person person = page.iterator().next(); 45 | Assert.assertNotNull(person); 46 | Assert.assertEquals("Graham", person.getFirstName()); 47 | Assert.assertNotNull(person.getLocations()); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /spring-data-gremlin-orientdb/src/test/java/org/springframework/data/gremlin/object/tests/orientdb/jpa/OrientDB_JPA_SpatialRepositoryTest.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.object.tests.orientdb.jpa; 2 | 3 | import org.springframework.data.gremlin.object.jpa.repository.AbstractLocationRepositoryTest; 4 | import org.springframework.test.context.ContextConfiguration; 5 | 6 | /** 7 | * Created by gman on 24/06/15. 8 | */ 9 | @ContextConfiguration(classes = OrientDB_JPA_TestConfiguration.class) 10 | public class OrientDB_JPA_SpatialRepositoryTest extends AbstractLocationRepositoryTest { } 11 | -------------------------------------------------------------------------------- /spring-data-gremlin-orientdb/src/test/java/org/springframework/data/gremlin/object/tests/orientdb/jpa/OrientDB_JPA_TransactionRepositoryTest.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.object.tests.orientdb.jpa; 2 | 3 | import org.springframework.data.gremlin.object.jpa.repository.AbstractTransactionRepositoryTest; 4 | import org.springframework.test.context.ContextConfiguration; 5 | 6 | /** 7 | * Created by gman on 24/06/15. 8 | */ 9 | @ContextConfiguration(classes = OrientDB_JPA_TestConfiguration.class) 10 | @SuppressWarnings("SpringJavaAutowiringInspection") 11 | public class OrientDB_JPA_TransactionRepositoryTest extends AbstractTransactionRepositoryTest { 12 | 13 | } 14 | -------------------------------------------------------------------------------- /spring-data-gremlin-orientdb/src/test/java/org/springframework/data/gremlin/object/tests/orientdb/neo4j/OrientDB_Neo4j_AddressRepositoryTest.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.object.tests.orientdb.neo4j; 2 | 3 | import org.springframework.data.gremlin.object.neo4j.repository.AbstractAddressRepositoryTest; 4 | import org.springframework.test.context.ContextConfiguration; 5 | 6 | /** 7 | * Created by gman on 24/06/15. 8 | */ 9 | @ContextConfiguration(classes = OrientDB_Neo4j_TestConfiguration.class) 10 | public class OrientDB_Neo4j_AddressRepositoryTest extends AbstractAddressRepositoryTest { } 11 | -------------------------------------------------------------------------------- /spring-data-gremlin-orientdb/src/test/java/org/springframework/data/gremlin/object/tests/orientdb/neo4j/OrientDB_Neo4j_EdgeRepositoryTest.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.object.tests.orientdb.neo4j; 2 | 3 | import org.springframework.data.gremlin.object.neo4j.repository.AbstractEdgeRepositoryTest; 4 | import org.springframework.data.gremlin.object.tests.orientdb.neo4j.OrientDB_Neo4j_TestConfiguration; 5 | import org.springframework.test.context.ContextConfiguration; 6 | 7 | /** 8 | * Created by gman on 24/06/15. 9 | */ 10 | @ContextConfiguration(classes = OrientDB_Neo4j_TestConfiguration.class) 11 | public class OrientDB_Neo4j_EdgeRepositoryTest extends AbstractEdgeRepositoryTest { } 12 | -------------------------------------------------------------------------------- /spring-data-gremlin-orientdb/src/test/java/org/springframework/data/gremlin/object/tests/orientdb/neo4j/OrientDB_Neo4j_PersonRepositoryTest.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.object.tests.orientdb.neo4j; 2 | 3 | import org.junit.Assert; 4 | import org.junit.Test; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.data.domain.Page; 7 | import org.springframework.data.domain.PageRequest; 8 | import org.springframework.data.gremlin.object.neo4j.domain.Person; 9 | import org.springframework.data.gremlin.object.neo4j.repository.AbstractPersonRepositoryTest; 10 | import org.springframework.data.gremlin.object.neo4j.repository.NativePersonRepository; 11 | import org.springframework.test.context.ContextConfiguration; 12 | 13 | import java.util.Iterator; 14 | 15 | /** 16 | * Created by gman on 24/06/15. 17 | */ 18 | @ContextConfiguration(classes = OrientDB_Neo4j_TestConfiguration.class) 19 | @SuppressWarnings("SpringJavaAutowiringInspection") 20 | public class OrientDB_Neo4j_PersonRepositoryTest extends AbstractPersonRepositoryTest { 21 | 22 | @Autowired 23 | protected NativePersonRepository nativePersonRepository; 24 | 25 | @Test 26 | public void testDeleteAllExcept() throws Exception { 27 | int count = nativePersonRepository.deleteAllExceptUser("Lara"); 28 | Assert.assertEquals(4, count); 29 | 30 | Iterable persons = repository.findAll(); 31 | Assert.assertNotNull(persons); 32 | Iterator iterator = persons.iterator(); 33 | Assert.assertNotNull(iterator); 34 | Assert.assertNotNull(iterator.next()); 35 | Assert.assertFalse(iterator.hasNext()); 36 | } 37 | 38 | 39 | @Test 40 | public void findPeopleNear() throws Exception { 41 | Page page = nativePersonRepository.findNear(-33, 151, 50, new PageRequest(0, 10)); 42 | Assert.assertEquals(1, page.getTotalElements()); 43 | 44 | Person person = page.iterator().next(); 45 | Assert.assertNotNull(person); 46 | Assert.assertEquals("Graham", person.getFirstName()); 47 | Assert.assertNotNull(person.getLocations()); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /spring-data-gremlin-orientdb/src/test/java/org/springframework/data/gremlin/object/tests/orientdb/neo4j/OrientDB_Neo4j_SpatialRepositoryTest.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.object.tests.orientdb.neo4j; 2 | 3 | import org.springframework.data.gremlin.object.neo4j.repository.AbstractLocationRepositoryTest; 4 | import org.springframework.test.context.ContextConfiguration; 5 | 6 | /** 7 | * Created by gman on 24/06/15. 8 | */ 9 | @ContextConfiguration(classes = OrientDB_Neo4j_TestConfiguration.class) 10 | public class OrientDB_Neo4j_SpatialRepositoryTest extends AbstractLocationRepositoryTest { } 11 | -------------------------------------------------------------------------------- /spring-data-gremlin-orientdb/src/test/java/org/springframework/data/gremlin/object/tests/orientdb/neo4j/OrientDB_Neo4j_TransactionRepositoryTest.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.object.tests.orientdb.neo4j; 2 | 3 | import org.springframework.data.gremlin.object.neo4j.repository.AbstractTransactionRepositoryTest; 4 | import org.springframework.test.context.ContextConfiguration; 5 | 6 | /** 7 | * Created by gman on 24/06/15. 8 | */ 9 | @ContextConfiguration(classes = OrientDB_Neo4j_TestConfiguration.class) 10 | @SuppressWarnings("SpringJavaAutowiringInspection") 11 | public class OrientDB_Neo4j_TransactionRepositoryTest extends AbstractTransactionRepositoryTest { 12 | 13 | } 14 | -------------------------------------------------------------------------------- /spring-data-gremlin-orientdb/src/test/java/org/springframework/data/gremlin/tx/orientdb/OrientDBGremlinGraphFactoryTest.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.tx.orientdb; 2 | 3 | /** 4 | * Created by gman on 29/07/15. 5 | */ 6 | public class OrientDBGremlinGraphFactoryTest { 7 | 8 | } -------------------------------------------------------------------------------- /spring-data-gremlin-schemagen-jpa/build.gradle: -------------------------------------------------------------------------------- 1 | dependencies { 2 | compile('org.hibernate.javax.persistence:hibernate-jpa-2.1-api:1.0.0.Final') 3 | compile project(':spring-data-gremlin-core') 4 | testCompile project(':spring-data-gremlin-test') 5 | } 6 | -------------------------------------------------------------------------------- /spring-data-gremlin-schemagen-jpa/src/main/java/org/springframework/data/gremlin/schema/generator/jpa/JpaGremlinPropertyFactory.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.schema.generator.jpa; 2 | 3 | import org.springframework.data.gremlin.schema.property.GremlinPropertyFactory; 4 | 5 | /** 6 | * Created by gman on 26/07/15. 7 | */ 8 | public class JpaGremlinPropertyFactory extends GremlinPropertyFactory { 9 | // @Override 10 | // public GremlinProperty getCollectionProperty(Class cls, String name) { 11 | // return new GremlinCollectionProperty(cls, name, new GremlinCollectionOutPropertyMapper()); 12 | // } 13 | } 14 | -------------------------------------------------------------------------------- /spring-data-gremlin-schemagen-neo4j/build.gradle: -------------------------------------------------------------------------------- 1 | dependencies { 2 | compile('org.springframework.data:spring-data-neo4j:3.3.2.RELEASE') 3 | compile project(':spring-data-gremlin-core') 4 | testCompile project(':spring-data-gremlin-test') 5 | } 6 | -------------------------------------------------------------------------------- /spring-data-gremlin-test/build.gradle: -------------------------------------------------------------------------------- 1 | dependencies { 2 | compile('org.mockito:mockito-core:1.10.8') 3 | compile("org.springframework:spring-test:${springVersion}") 4 | compile('junit:junit:4.12') 5 | compile('org.hibernate.javax.persistence:hibernate-jpa-2.1-api:1.0.0.Final') 6 | compile('org.springframework.data:spring-data-neo4j:3.3.2.RELEASE') 7 | compile project(':spring-data-gremlin-core') 8 | } 9 | -------------------------------------------------------------------------------- /spring-data-gremlin-test/src/main/java/org/springframework/data/gremlin/object/core/TestService.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.object.core; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.data.domain.PageRequest; 5 | import org.springframework.data.gremlin.object.core.domain.Address; 6 | import org.springframework.data.gremlin.object.core.domain.Person; 7 | import org.springframework.data.gremlin.object.core.repository.AddressRepository; 8 | import org.springframework.data.gremlin.object.core.repository.NativePersonRepository; 9 | import org.springframework.data.gremlin.object.core.repository.PersonRepository; 10 | import org.springframework.stereotype.Service; 11 | import org.springframework.transaction.annotation.Transactional; 12 | 13 | /** 14 | * Created by gman on 30/07/15. 15 | */ 16 | @Service 17 | public class TestService { 18 | 19 | @Autowired 20 | private PersonRepository repository; 21 | 22 | @Autowired 23 | private AddressRepository addressRepository; 24 | 25 | @Autowired(required = false) 26 | private NativePersonRepository nativePersonRepository; 27 | 28 | @Transactional 29 | public void create(Person person) { 30 | repository.save(person); 31 | } 32 | 33 | @Transactional 34 | public void failCreate(Person person, Address address) { 35 | create(person); 36 | 37 | Person test = new Person("Graham", "Webber", address, true); 38 | repository.save(test); 39 | repository.findByAddress_Area_Name("asdf"); 40 | repository.queryLastName("asdf", new PageRequest(0, 2)); 41 | if (nativePersonRepository != null) { 42 | nativePersonRepository.findNear(-33d, 151d, 50, new PageRequest(0, 2)); 43 | } 44 | addressRepository.save(address); 45 | throw new IllegalStateException(); 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /spring-data-gremlin-test/src/main/java/org/springframework/data/gremlin/object/core/domain/Address.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.object.core.domain; 2 | 3 | import com.tinkerpop.blueprints.Direction; 4 | import org.springframework.data.gremlin.annotation.*; 5 | 6 | import java.util.HashSet; 7 | import java.util.Set; 8 | 9 | @Vertex 10 | public class Address { 11 | 12 | @Id 13 | private String id; 14 | 15 | @Embed(propertyOverrides = { @PropertyOverride(name = "name", property = @Property("countryName")) }) 16 | private Country country; 17 | 18 | private String city; 19 | 20 | private String street; 21 | 22 | @Link(name = "of_area") 23 | private Area area; 24 | 25 | @Link(name = "lives_at", direction = Direction.IN) 26 | private Set people; 27 | 28 | public Address() {} 29 | 30 | public Address(Country country, String city, String street, Area area) { 31 | this.country = country; 32 | this.city = city; 33 | this.street = street; 34 | this.area = area; 35 | } 36 | 37 | public String getId() { 38 | return id; 39 | } 40 | 41 | public void setId(String id) { 42 | this.id = id; 43 | } 44 | 45 | public Country getCountry() { 46 | return country; 47 | } 48 | 49 | public void setCountry(Country country) { 50 | this.country = country; 51 | } 52 | 53 | public String getCity() { 54 | return city; 55 | } 56 | 57 | public void setCity(String city) { 58 | this.city = city; 59 | } 60 | 61 | public String getStreet() { 62 | return street; 63 | } 64 | 65 | public void setStreet(String street) { 66 | this.street = street; 67 | } 68 | 69 | public Area getArea() { 70 | return area; 71 | } 72 | 73 | public void setArea(Area area) { 74 | this.area = area; 75 | } 76 | 77 | public Set getPeople() { 78 | if (people == null) { 79 | people = new HashSet(); 80 | } 81 | return people; 82 | } 83 | 84 | public void setPeople(Set people) { 85 | this.people = people; 86 | } 87 | 88 | // @Override 89 | // public boolean equals(Object o) { 90 | // if (this == o) { 91 | // return true; 92 | // } 93 | // if (o == null || getClass() != o.getClass()) { 94 | // return false; 95 | // } 96 | // 97 | // Address address = (Address) o; 98 | // 99 | // return !(id != null ? !id.equals(address.id) : address.id != null); 100 | // 101 | // } 102 | // 103 | // @Override 104 | // public int hashCode() { 105 | // return id != null ? id.hashCode() : 0; 106 | // } 107 | } 108 | -------------------------------------------------------------------------------- /spring-data-gremlin-test/src/main/java/org/springframework/data/gremlin/object/core/domain/Animal.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.object.core.domain; 2 | 3 | import org.springframework.data.gremlin.annotation.Link; 4 | 5 | import java.util.Set; 6 | 7 | /** 8 | * @author Gman 9 | * @created 21/04/2016 10 | */ 11 | public class Animal { 12 | @Link 13 | private Set stuff; 14 | 15 | @Link 16 | private T linkedStuff; 17 | 18 | public Set getStuff() { 19 | return stuff; 20 | } 21 | 22 | public void setStuff(Set stuff) { 23 | this.stuff = stuff; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /spring-data-gremlin-test/src/main/java/org/springframework/data/gremlin/object/core/domain/Area.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.object.core.domain; 2 | 3 | 4 | import org.springframework.data.gremlin.annotation.Id; 5 | import org.springframework.data.gremlin.annotation.Vertex; 6 | 7 | @Vertex 8 | public class Area extends Place { 9 | 10 | @Id 11 | private String id; 12 | 13 | private String name; 14 | 15 | public Area() { 16 | } 17 | 18 | public Area(String name) { 19 | this.name = name; 20 | } 21 | 22 | public String getId() { 23 | return id; 24 | } 25 | 26 | public void setId(String id) { 27 | this.id = id; 28 | } 29 | 30 | public String getName() { 31 | return name; 32 | } 33 | 34 | public void setName(String name) { 35 | this.name = name; 36 | } 37 | 38 | // @Override 39 | // public boolean equals(Object o) { 40 | // if (this == o) { 41 | // return true; 42 | // } 43 | // if (o == null || getClass() != o.getClass()) { 44 | // return false; 45 | // } 46 | // 47 | // Area area = (Area) o; 48 | // 49 | // return !(id != null ? !id.equals(area.id) : area.id != null); 50 | // 51 | // } 52 | // 53 | // @Override 54 | // public int hashCode() { 55 | // return id != null ? id.hashCode() : 0; 56 | // } 57 | } 58 | -------------------------------------------------------------------------------- /spring-data-gremlin-test/src/main/java/org/springframework/data/gremlin/object/core/domain/Bipod.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.object.core.domain; 2 | 3 | 4 | import org.springframework.data.gremlin.annotation.Id; 5 | import org.springframework.data.gremlin.annotation.Vertex; 6 | 7 | @Vertex 8 | public class Bipod extends Animal { 9 | 10 | @Id 11 | private String id; 12 | 13 | private String name; 14 | 15 | public Bipod() { 16 | } 17 | 18 | public Bipod(String name) { 19 | this.name = name; 20 | } 21 | 22 | public String getId() { 23 | return id; 24 | } 25 | 26 | public void setId(String id) { 27 | this.id = id; 28 | } 29 | 30 | public String getName() { 31 | return name; 32 | } 33 | 34 | public void setName(String name) { 35 | this.name = name; 36 | } 37 | 38 | // @Override 39 | // public boolean equals(Object o) { 40 | // if (this == o) { 41 | // return true; 42 | // } 43 | // if (o == null || getClass() != o.getClass()) { 44 | // return false; 45 | // } 46 | // 47 | // Area area = (Area) o; 48 | // 49 | // return !(id != null ? !id.equals(area.id) : area.id != null); 50 | // 51 | // } 52 | // 53 | // @Override 54 | // public int hashCode() { 55 | // return id != null ? id.hashCode() : 0; 56 | // } 57 | } 58 | -------------------------------------------------------------------------------- /spring-data-gremlin-test/src/main/java/org/springframework/data/gremlin/object/core/domain/Country.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.object.core.domain; 2 | 3 | import org.springframework.data.gremlin.annotation.Embeddable; 4 | 5 | /** 6 | * Created by gman on 12/08/15. 7 | */ 8 | @Embeddable 9 | public class Country { 10 | 11 | private String name; 12 | 13 | public Country() { 14 | } 15 | 16 | public Country(String name) { 17 | this.name = name; 18 | } 19 | 20 | public String getName() { 21 | return name; 22 | } 23 | 24 | public void setName(String name) { 25 | this.name = name; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /spring-data-gremlin-test/src/main/java/org/springframework/data/gremlin/object/core/domain/House.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.object.core.domain; 2 | 3 | import java.io.Serializable; 4 | 5 | /** 6 | * Created by gman on 24/09/15. 7 | */ 8 | public class House implements Serializable { 9 | 10 | private int rooms; 11 | 12 | public House() { 13 | } 14 | 15 | public House(int rooms) { 16 | this.rooms = rooms; 17 | } 18 | 19 | public int getRooms() { 20 | return rooms; 21 | } 22 | 23 | public void setRooms(int rooms) { 24 | this.rooms = rooms; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /spring-data-gremlin-test/src/main/java/org/springframework/data/gremlin/object/core/domain/Likes.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.object.core.domain; 2 | 3 | import org.springframework.data.gremlin.annotation.Edge; 4 | import org.springframework.data.gremlin.annotation.FromVertex; 5 | import org.springframework.data.gremlin.annotation.Id; 6 | import org.springframework.data.gremlin.annotation.ToVertex; 7 | 8 | import java.util.Date; 9 | 10 | /** 11 | * Created by gman on 14/09/15. 12 | */ 13 | @Edge 14 | public class Likes { 15 | 16 | @Id 17 | private String id; 18 | 19 | private Date date = new Date(); 20 | 21 | @FromVertex 22 | private Person person1; 23 | 24 | @ToVertex 25 | private Person person2; 26 | 27 | public Likes() { 28 | } 29 | 30 | public Likes(Person person1, Person person2) { 31 | this.person1 = person1; 32 | this.person2 = person2; 33 | person1.getLikes().add(this); 34 | } 35 | 36 | public Date getDate() { 37 | return date; 38 | } 39 | 40 | public Person getPerson1() { 41 | return person1; 42 | } 43 | 44 | public Person getPerson2() { 45 | return person2; 46 | } 47 | 48 | @Override 49 | public boolean equals(Object o) { 50 | if (this == o) { 51 | return true; 52 | } 53 | if (o == null || getClass() != o.getClass()) { 54 | return false; 55 | } 56 | 57 | Likes likes = (Likes) o; 58 | 59 | return !(id != null ? !id.equals(likes.id) : likes.id != null); 60 | 61 | } 62 | 63 | @Override 64 | public int hashCode() { 65 | return id != null ? id.hashCode() : 0; 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /spring-data-gremlin-test/src/main/java/org/springframework/data/gremlin/object/core/domain/Located.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.object.core.domain; 2 | 3 | import org.springframework.data.gremlin.annotation.*; 4 | 5 | import java.util.Date; 6 | 7 | /** 8 | * Created by gman on 3/08/15. 9 | */ 10 | @Edge("was_located") 11 | public class Located { 12 | 13 | @Id 14 | private String id; 15 | 16 | @Property("location_date") 17 | private Date date; 18 | 19 | @FromVertex 20 | private Person person; 21 | 22 | @ToVertex 23 | private Location location; 24 | 25 | public Located() { 26 | } 27 | 28 | public Located(Date date, Person person, Location location) { 29 | this.date = date; 30 | this.person = person; 31 | this.location = location; 32 | } 33 | 34 | public String getId() { 35 | return id; 36 | } 37 | 38 | public void setId(String id) { 39 | this.id = id; 40 | } 41 | 42 | public Date getDate() { 43 | return date; 44 | } 45 | 46 | public void setDate(Date date) { 47 | this.date = date; 48 | } 49 | 50 | public Person getPerson() { 51 | return person; 52 | } 53 | 54 | public void setPerson(Person person) { 55 | this.person = person; 56 | } 57 | 58 | public Location getLocation() { 59 | return location; 60 | } 61 | 62 | public void setLocation(Location location) { 63 | this.location = location; 64 | } 65 | 66 | // @Override 67 | // public boolean equals(Object o) { 68 | // if (this == o) { 69 | // return true; 70 | // } 71 | // if (o == null || getClass() != o.getClass()) { 72 | // return false; 73 | // } 74 | // 75 | // Located located = (Located) o; 76 | // 77 | // return !(id != null ? !id.equals(located.id) : located.id != null); 78 | // 79 | // } 80 | // 81 | // @Override 82 | // public int hashCode() { 83 | // return id != null ? id.hashCode() : 0; 84 | // } 85 | } 86 | -------------------------------------------------------------------------------- /spring-data-gremlin-test/src/main/java/org/springframework/data/gremlin/object/core/domain/Location.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.object.core.domain; 2 | 3 | import com.tinkerpop.blueprints.Direction; 4 | import org.springframework.data.gremlin.annotation.Id; 5 | import org.springframework.data.gremlin.annotation.Index; 6 | import org.springframework.data.gremlin.annotation.Link; 7 | import org.springframework.data.gremlin.annotation.Vertex; 8 | 9 | import static org.springframework.data.gremlin.annotation.Index.IndexType.SPATIAL_LATITUDE; 10 | import static org.springframework.data.gremlin.annotation.Index.IndexType.SPATIAL_LONGITUDE; 11 | 12 | /** 13 | * Created by gman on 9/06/15. 14 | */ 15 | @Vertex 16 | public class Location { 17 | 18 | @Id 19 | private String id; 20 | 21 | @Index(type = SPATIAL_LATITUDE) 22 | private double latitude; 23 | @Index(type = SPATIAL_LONGITUDE) 24 | private double longitude; 25 | 26 | @Link(value="location_in_area", direction = Direction.IN) 27 | private Area area; 28 | 29 | public Location() { 30 | } 31 | 32 | public Location(double latitude, double longitude) { 33 | this.latitude = latitude; 34 | this.longitude = longitude; 35 | } 36 | 37 | public String getId() { 38 | return id; 39 | } 40 | 41 | public void setId(String id) { 42 | this.id = id; 43 | } 44 | 45 | public double getLatitude() { 46 | return latitude; 47 | } 48 | 49 | public void setLatitude(double latitude) { 50 | this.latitude = latitude; 51 | } 52 | 53 | public double getLongitude() { 54 | return longitude; 55 | } 56 | 57 | public void setLongitude(double longitude) { 58 | this.longitude = longitude; 59 | } 60 | 61 | public Area getArea() { 62 | return area; 63 | } 64 | 65 | public void setArea(Area area) { 66 | this.area = area; 67 | } 68 | // @Override 69 | // public boolean equals(Object o) { 70 | // if (this == o) { 71 | // return true; 72 | // } 73 | // if (o == null || getClass() != o.getClass()) { 74 | // return false; 75 | // } 76 | // 77 | // Location location = (Location) o; 78 | // 79 | // return !(id != null ? !id.equals(location.id) : location.id != null); 80 | // 81 | // } 82 | // 83 | // @Override 84 | // public int hashCode() { 85 | // return id != null ? id.hashCode() : 0; 86 | // } 87 | 88 | } 89 | -------------------------------------------------------------------------------- /spring-data-gremlin-test/src/main/java/org/springframework/data/gremlin/object/core/domain/Meeting.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.object.core.domain; 2 | 3 | import org.springframework.data.gremlin.annotation.Link; 4 | import org.springframework.data.gremlin.annotation.Vertex; 5 | 6 | /** 7 | * @author Gman 8 | * @created 19/01/2016 9 | */ 10 | @Vertex 11 | public class Meeting { 12 | 13 | @Link 14 | private Person person1; 15 | 16 | @Link 17 | private Person person2; 18 | 19 | public Meeting() { 20 | } 21 | 22 | public Meeting(Person person1, Person person2) { 23 | this.person1 = person1; 24 | this.person2 = person2; 25 | } 26 | 27 | public Person getPerson2() { 28 | return person2; 29 | } 30 | 31 | public void setPerson2(Person person2) { 32 | this.person2 = person2; 33 | } 34 | 35 | public Person getPerson1() { 36 | return person1; 37 | } 38 | 39 | public void setPerson1(Person person1) { 40 | this.person1 = person1; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /spring-data-gremlin-test/src/main/java/org/springframework/data/gremlin/object/core/domain/Pet.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.object.core.domain; 2 | 3 | /** 4 | * Created by gman on 24/09/15. 5 | */ 6 | public class Pet { 7 | 8 | public enum TYPE { 9 | CAT,DOG,HORSE; 10 | } 11 | 12 | private String name; 13 | 14 | private TYPE type; 15 | 16 | public Pet(String name, TYPE type) { 17 | this.name = name; 18 | this.type = type; 19 | } 20 | 21 | public String getName() { 22 | return name; 23 | } 24 | 25 | public void setName(String name) { 26 | this.name = name; 27 | } 28 | 29 | public TYPE getType() { 30 | return type; 31 | } 32 | 33 | public void setType(TYPE type) { 34 | this.type = type; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /spring-data-gremlin-test/src/main/java/org/springframework/data/gremlin/object/core/domain/PetMxin.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.object.core.domain; 2 | 3 | import com.fasterxml.jackson.annotation.JsonProperty; 4 | 5 | /** 6 | * Created by gman on 12/10/15. 7 | */ 8 | abstract class PetMxin { 9 | 10 | PetMxin(@JsonProperty("name") String name, @JsonProperty("type") Pet.TYPE type) { } 11 | 12 | @JsonProperty("name") 13 | abstract String getName(); // rename property 14 | 15 | @JsonProperty("type") 16 | abstract Pet.TYPE getType(); // rename property 17 | 18 | } 19 | -------------------------------------------------------------------------------- /spring-data-gremlin-test/src/main/java/org/springframework/data/gremlin/object/core/domain/Place.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.object.core.domain; 2 | 3 | /** 4 | * @author Gman 5 | * @created 21/04/2016 6 | */ 7 | public abstract class Place { } 8 | -------------------------------------------------------------------------------- /spring-data-gremlin-test/src/main/java/org/springframework/data/gremlin/object/core/repository/AbstractAddressRepositoryTest.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.object.core.repository; 2 | 3 | import org.apache.commons.collections4.CollectionUtils; 4 | import org.junit.Assert; 5 | import org.junit.Test; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.data.gremlin.object.core.domain.Address; 8 | 9 | import java.util.ArrayList; 10 | import java.util.List; 11 | 12 | import static org.junit.Assert.assertEquals; 13 | import static org.junit.Assert.assertNotNull; 14 | 15 | @SuppressWarnings("SpringJavaAutowiringInspection") 16 | public abstract class AbstractAddressRepositoryTest extends BaseRepositoryTest { 17 | 18 | @Autowired 19 | protected AddressRepository addressRepository; 20 | 21 | @Test 22 | public void should_find_addresses() throws Exception { 23 | List
addresses = new ArrayList
(); 24 | 25 | CollectionUtils.addAll(addresses, addressRepository.findAll()); 26 | assertNotNull(addresses); 27 | assertEquals(2, addresses.size()); 28 | 29 | for (Address address : addresses) { 30 | Assert.assertNotNull(address.getPeople()); 31 | Assert.assertTrue(address.getPeople().size() > 0); 32 | } 33 | } 34 | 35 | 36 | @Test 37 | public void should_save_and_find_embedded_country() throws Exception { 38 | List
addresses = new ArrayList
(); 39 | 40 | CollectionUtils.addAll(addresses, addressRepository.findAll()); 41 | assertNotNull(addresses); 42 | assertEquals(2, addresses.size()); 43 | assertNotNull(addresses.get(0).getCountry()); 44 | assertEquals("Australia", addresses.get(0).getCountry().getName()); 45 | assertNotNull(addresses.get(1).getCountry()); 46 | assertEquals("Australia", addresses.get(1).getCountry().getName()); 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /spring-data-gremlin-test/src/main/java/org/springframework/data/gremlin/object/core/repository/AbstractTransactionRepositoryTest.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.object.core.repository; 2 | 3 | import com.google.common.collect.Lists; 4 | import org.junit.Test; 5 | import org.springframework.data.gremlin.object.core.domain.Address; 6 | import org.springframework.data.gremlin.object.core.domain.Area; 7 | import org.springframework.data.gremlin.object.core.domain.Country; 8 | import org.springframework.data.gremlin.object.core.domain.Person; 9 | 10 | import java.util.List; 11 | 12 | import static org.junit.Assert.assertEquals; 13 | import static org.junit.Assert.fail; 14 | 15 | /** 16 | * Created by gman on 30/07/15. 17 | */ 18 | public class AbstractTransactionRepositoryTest extends BaseRepositoryTest { 19 | 20 | @Test 21 | public void should_rollback() { 22 | 23 | List peopele = Lists.newArrayList(repository.findAll()); 24 | int beforeRollback = peopele.size(); 25 | testService.create(new Person("Graham", "Webber", null, true)); 26 | 27 | peopele = Lists.newArrayList(repository.findAll()); 28 | assertEquals(beforeRollback + 1, peopele.size()); 29 | 30 | Address address1 = new Address(new Country("Australia"), "Newcastle", "Scenic Dr", new Area("2291")); 31 | 32 | Person graham1 = new Person("Graham", "Webber", address1, true); 33 | try { 34 | testService.failCreate(graham1, address1); 35 | fail("Should've thrown exception"); 36 | } catch (RuntimeException e) { 37 | 38 | } 39 | 40 | peopele = Lists.newArrayList(repository.findAll()); 41 | assertEquals(beforeRollback + 1, peopele.size()); 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /spring-data-gremlin-test/src/main/java/org/springframework/data/gremlin/object/core/repository/AddressRepository.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.object.core.repository; 2 | 3 | import org.springframework.data.gremlin.object.core.domain.Address; 4 | import org.springframework.data.gremlin.repository.GremlinRepository; 5 | 6 | /** 7 | * Created by gman on 4/06/15. 8 | */ 9 | public interface AddressRepository extends GremlinRepository
{ } 10 | -------------------------------------------------------------------------------- /spring-data-gremlin-test/src/main/java/org/springframework/data/gremlin/object/core/repository/LikesRepository.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.object.core.repository; 2 | 3 | import org.springframework.data.gremlin.annotation.Query; 4 | import org.springframework.data.gremlin.object.core.domain.Likes; 5 | import org.springframework.data.gremlin.object.core.domain.Person; 6 | import org.springframework.data.gremlin.repository.GremlinRepository; 7 | 8 | import java.util.Date; 9 | import java.util.List; 10 | 11 | /** 12 | * Created by gman on 4/06/15. 13 | */ 14 | public interface LikesRepository extends GremlinRepository { 15 | 16 | 17 | List findByPerson1_FirstName(String firstName); 18 | 19 | @Query(value = "graph.E().has('date')") 20 | List findByHasDate(); 21 | 22 | @Query(value = "graph.V().has('firstName', ?).outE('Likes').as('x').inV.filter{it.firstName == ?}.back('x')") 23 | List findByLiking(String liker, String liked); 24 | 25 | 26 | 27 | } 28 | -------------------------------------------------------------------------------- /spring-data-gremlin-test/src/main/java/org/springframework/data/gremlin/object/core/repository/LocatedRepository.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.object.core.repository; 2 | 3 | import org.springframework.data.gremlin.object.core.domain.Located; 4 | import org.springframework.data.gremlin.repository.GremlinRepository; 5 | 6 | /** 7 | * Created by gman on 4/06/15. 8 | */ 9 | public interface LocatedRepository extends GremlinRepository { } 10 | -------------------------------------------------------------------------------- /spring-data-gremlin-test/src/main/java/org/springframework/data/gremlin/object/core/repository/LocationRepository.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.object.core.repository; 2 | 3 | import org.springframework.data.gremlin.object.core.domain.Location; 4 | import org.springframework.data.gremlin.repository.GremlinRepository; 5 | 6 | /** 7 | * Created by gman on 12/06/15. 8 | */ 9 | public interface LocationRepository extends GremlinRepository { 10 | 11 | } 12 | -------------------------------------------------------------------------------- /spring-data-gremlin-test/src/main/java/org/springframework/data/gremlin/object/core/repository/NativeLocationRepository.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.object.core.repository; 2 | 3 | import org.springframework.data.domain.Page; 4 | import org.springframework.data.domain.Pageable; 5 | import org.springframework.data.gremlin.annotation.Query; 6 | import org.springframework.data.gremlin.object.core.domain.Location; 7 | import org.springframework.data.gremlin.query.CompositeResult; 8 | import org.springframework.data.gremlin.repository.GremlinRepositoryWithNativeSupport; 9 | import org.springframework.data.repository.query.Param; 10 | 11 | import java.util.List; 12 | import java.util.Map; 13 | 14 | /** 15 | * Created by gman on 12/06/15. 16 | */ 17 | public interface NativeLocationRepository extends GremlinRepositoryWithNativeSupport { 18 | 19 | @Query(value = "SELECT * FROM Location WHERE [latitude,longitude,$spatial] NEAR [?,?,{\"maxDistance\":?}]", nativeQuery = true) 20 | List find(double latitude, double longitude, double radius); 21 | 22 | @Query(value = "SELECT * FROM Location WHERE [latitude,longitude,$spatial] NEAR [:lat,:lon,{\"maxDistance\"::radius}]", nativeQuery = true) 23 | List findWithParam(@Param("lat") double latitude, @Param("lon") double longitude, @Param("radius") double radius); 24 | 25 | @Query(value = "SELECT * FROM Location WHERE [latitude,longitude,$spatial] NEAR [?,?,{\"maxDistance\":?}]", nativeQuery = true) 26 | Page find(double latitude, double longitude, double radius, Pageable pageable); 27 | 28 | @Query(value = "SELECT *,eval('1000d * $distance') as distance FROM Location WHERE [latitude,longitude,$spatial] NEAR [?,?,{\"maxDistance\":?}]", nativeQuery = true) 29 | List> findNear(double latitude, double longitude, double radius); 30 | 31 | @Query(value = "SELECT *,eval('1000d * $distance') as distance FROM Location WHERE [latitude,longitude,$spatial] NEAR [?,?,{\"maxDistance\":?}]", nativeQuery = true) 32 | Page> findNear(double latitude, double longitude, double radius, Pageable pageable); 33 | 34 | @Query(value = "SELECT *,eval('1000d * $distance') as distance FROM Location WHERE [latitude,longitude,$spatial] NEAR [?,?,{\"maxDistance\":?}]", nativeQuery = true) 35 | List> findComposite(double latitude, double longitude, double radius); 36 | 37 | @Query(value = "SELECT *,eval('1000d * $distance') as distance FROM Location WHERE [latitude,longitude,$spatial] NEAR [?,?,{\"maxDistance\":?}]", nativeQuery = true) 38 | Page> findComposite(double latitude, double longitude, double radius, Pageable pageable); 39 | 40 | } 41 | -------------------------------------------------------------------------------- /spring-data-gremlin-test/src/main/java/org/springframework/data/gremlin/object/core/repository/NativePersonRepository.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.object.core.repository; 2 | 3 | import org.springframework.data.domain.Page; 4 | import org.springframework.data.domain.Pageable; 5 | import org.springframework.data.gremlin.annotation.Query; 6 | import org.springframework.data.gremlin.object.core.domain.Person; 7 | import org.springframework.data.gremlin.repository.GremlinRepositoryWithNativeSupport; 8 | 9 | /** 10 | * Created by gman on 25/06/15. 11 | */ 12 | public interface NativePersonRepository extends GremlinRepositoryWithNativeSupport { 13 | 14 | @Query(value = "delete vertex from (select from Person where firstName <> ?)", nativeQuery = true, modify = true) 15 | Integer deleteAllExceptUser(String firstName); 16 | 17 | 18 | @Query(value = "SELECT expand(in('was_located')) FROM (SELECT FROM Location WHERE [latitude,longitude,$spatial] NEAR [?,?,{\"maxDistance\":?}])", nativeQuery = true) 19 | Page findNear(double latitude, double longitude, double radius, Pageable pageable); 20 | 21 | } 22 | -------------------------------------------------------------------------------- /spring-data-gremlin-test/src/main/java/org/springframework/data/gremlin/object/core/repository/PersonRepository.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.object.core.repository; 2 | 3 | import org.springframework.data.domain.Page; 4 | import org.springframework.data.domain.Pageable; 5 | import org.springframework.data.gremlin.annotation.Query; 6 | import org.springframework.data.gremlin.object.core.domain.Person; 7 | import org.springframework.data.gremlin.repository.GremlinRepository; 8 | import org.springframework.data.repository.query.Param; 9 | 10 | import java.util.List; 11 | import java.util.Map; 12 | 13 | public interface PersonRepository extends GremlinRepository { 14 | 15 | @Query(value = "graph.V().has('firstName', ?)") 16 | List findByFirstName(String firstName); 17 | 18 | @Query(value = "graph.V().has('firstName', :fn)") 19 | List findByFirstNameWithParam(@Param("fn") String firstName); 20 | 21 | @Query(value = "graph.V().has('firstName', ?)") 22 | Page findByFirstName(String firstName, Pageable pageable); 23 | 24 | @Query(value = "graph.V().has('firstName', ?)") 25 | Person findSingleByFirstName(String firstName); 26 | 27 | @Query(value = "graph.V().has('firstName', ?)") 28 | List> findMapByFirstName(String firstName); 29 | 30 | @Query(value = "graph.V().has('firstName', ?)") 31 | Map findSingleMapByFirstName(String firstName); 32 | 33 | List findByLastName(String lastName); 34 | 35 | List findByLastNameLike(String lastName); 36 | 37 | List findByFirstNameAndLastName(String firstName, String lastName); 38 | 39 | List findByFirstNameOrLastName(String firstName, String lastName); 40 | 41 | List findByFirstNameLike(String string); 42 | 43 | List findByFirstNameStartsWith(String firstName); 44 | 45 | Long countByFirstName(String firstName); 46 | 47 | Long countByLastName(String lastName); 48 | 49 | // @Detach(DetachMode.ENTITY) 50 | List findByAddress_City(String city); 51 | 52 | 53 | List findByLastNameOrAddress_City(String lastName, String city); 54 | 55 | List findByAddress_Area_Name(String name); 56 | 57 | List findByLastNameOrAddress_Area_Name(String lastName, String name); 58 | 59 | // @FetchPlan("*:-1") 60 | // List findByAddress_Country(String city); 61 | 62 | List findByActiveIsTrue(); 63 | 64 | List findByActiveIsFalse(); 65 | 66 | Page findByLastName(String lastName, Pageable pageable); 67 | 68 | 69 | @Query(value = "graph.V('lastName', ?)") 70 | Page queryLastName(String lastName, Pageable pageable); 71 | 72 | } 73 | -------------------------------------------------------------------------------- /spring-data-gremlin-test/src/main/java/org/springframework/data/gremlin/object/jpa/TestService.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.object.jpa; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.data.domain.PageRequest; 5 | import org.springframework.data.gremlin.object.jpa.domain.Address; 6 | import org.springframework.data.gremlin.object.jpa.domain.Person; 7 | import org.springframework.data.gremlin.object.jpa.repository.AddressRepository; 8 | import org.springframework.data.gremlin.object.jpa.repository.NativePersonRepository; 9 | import org.springframework.data.gremlin.object.jpa.repository.PersonRepository; 10 | import org.springframework.stereotype.Service; 11 | import org.springframework.transaction.annotation.Transactional; 12 | 13 | /** 14 | * Created by gman on 30/07/15. 15 | */ 16 | @Service 17 | public class TestService { 18 | 19 | @Autowired 20 | private PersonRepository repository; 21 | 22 | @Autowired 23 | private AddressRepository addressRepository; 24 | 25 | @Autowired(required = false) 26 | private NativePersonRepository nativePersonRepository; 27 | 28 | @Transactional 29 | public void create(Person person) { 30 | repository.save(person); 31 | } 32 | 33 | @Transactional 34 | public void failCreate(Person person, Address address) { 35 | create(person); 36 | 37 | Person test = new Person("Graham", "Webber", address, true); 38 | repository.save(test); 39 | repository.findByAddress_Area_Name("asdf"); 40 | repository.queryLastName("asdf", new PageRequest(0, 2)); 41 | if (nativePersonRepository != null) { 42 | nativePersonRepository.findNear(-33d, 151d, 50, new PageRequest(0, 2)); 43 | } 44 | addressRepository.save(address); 45 | throw new IllegalStateException(); 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /spring-data-gremlin-test/src/main/java/org/springframework/data/gremlin/object/jpa/domain/Address.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.object.jpa.domain; 2 | 3 | import javax.persistence.*; 4 | import java.util.HashSet; 5 | import java.util.Set; 6 | 7 | @Entity 8 | public class Address { 9 | 10 | @Id 11 | private String id; 12 | 13 | @Embedded 14 | private Country country; 15 | 16 | private String city; 17 | 18 | private String street; 19 | 20 | @OneToOne 21 | @Column(name = "of_area") 22 | private Area area; 23 | 24 | @OneToMany(mappedBy = "address") 25 | @Column(name = "lives_at") 26 | private Set people; 27 | 28 | public Address() {} 29 | 30 | public Address(Country country, String city, String street, Area area) { 31 | this.country = country; 32 | this.city = city; 33 | this.street = street; 34 | this.area = area; 35 | } 36 | 37 | public String getId() { 38 | return id; 39 | } 40 | 41 | public void setId(String id) { 42 | this.id = id; 43 | } 44 | 45 | public Country getCountry() { 46 | return country; 47 | } 48 | 49 | public void setCountry(Country country) { 50 | this.country = country; 51 | } 52 | 53 | public String getCity() { 54 | return city; 55 | } 56 | 57 | public void setCity(String city) { 58 | this.city = city; 59 | } 60 | 61 | public String getStreet() { 62 | return street; 63 | } 64 | 65 | public void setStreet(String street) { 66 | this.street = street; 67 | } 68 | 69 | public Area getArea() { 70 | return area; 71 | } 72 | 73 | public void setArea(Area area) { 74 | this.area = area; 75 | } 76 | 77 | public Set getPeople() { 78 | if (people == null) { 79 | people = new HashSet(); 80 | } 81 | return people; 82 | } 83 | 84 | public void setPeople(Set people) { 85 | this.people = people; 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /spring-data-gremlin-test/src/main/java/org/springframework/data/gremlin/object/jpa/domain/Area.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.object.jpa.domain; 2 | 3 | import javax.persistence.Entity; 4 | import javax.persistence.Id; 5 | 6 | @Entity 7 | public class Area { 8 | 9 | @Id 10 | private String id; 11 | 12 | private String name; 13 | 14 | public Area() { 15 | } 16 | 17 | public Area(String name) { 18 | this.name = name; 19 | } 20 | 21 | public String getId() { 22 | return id; 23 | } 24 | 25 | public void setId(String id) { 26 | this.id = id; 27 | } 28 | 29 | public String getName() { 30 | return name; 31 | } 32 | 33 | public void setName(String name) { 34 | this.name = name; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /spring-data-gremlin-test/src/main/java/org/springframework/data/gremlin/object/jpa/domain/Country.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.object.jpa.domain; 2 | 3 | 4 | import javax.persistence.Embeddable; 5 | 6 | /** 7 | * Created by gman on 12/08/15. 8 | */ 9 | @Embeddable 10 | public class Country { 11 | 12 | private String name; 13 | 14 | public Country() { 15 | } 16 | 17 | public Country(String name) { 18 | this.name = name; 19 | } 20 | 21 | public String getName() { 22 | return name; 23 | } 24 | 25 | public void setName(String name) { 26 | this.name = name; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /spring-data-gremlin-test/src/main/java/org/springframework/data/gremlin/object/jpa/domain/Employee.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.object.jpa.domain; 2 | 3 | import javax.persistence.Column; 4 | import javax.persistence.Id; 5 | import javax.persistence.OneToOne; 6 | 7 | //@Entity 8 | public class Employee { 9 | 10 | @Id 11 | private String id; 12 | 13 | @Column(unique = true) 14 | private int employeeNumber; 15 | 16 | private String title; 17 | 18 | @OneToOne 19 | private Person person; 20 | 21 | public String getId() { 22 | return id; 23 | } 24 | 25 | public void setId(String id) { 26 | this.id = id; 27 | } 28 | 29 | public int getEmployeeNumber() { 30 | return employeeNumber; 31 | } 32 | 33 | public void setEmployeeNumber(int employeeNumber) { 34 | this.employeeNumber = employeeNumber; 35 | } 36 | 37 | public String getTitle() { 38 | return title; 39 | } 40 | 41 | public void setTitle(String title) { 42 | this.title = title; 43 | } 44 | 45 | public Person getPerson() { 46 | return person; 47 | } 48 | 49 | public void setPerson(Person person) { 50 | this.person = person; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /spring-data-gremlin-test/src/main/java/org/springframework/data/gremlin/object/jpa/domain/House.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.object.jpa.domain; 2 | 3 | import java.io.Serializable; 4 | 5 | /** 6 | * Created by gman on 24/09/15. 7 | */ 8 | public class House implements Serializable { 9 | 10 | private int rooms; 11 | 12 | public House() { 13 | } 14 | 15 | public House(int rooms) { 16 | this.rooms = rooms; 17 | } 18 | 19 | public int getRooms() { 20 | return rooms; 21 | } 22 | 23 | public void setRooms(int rooms) { 24 | this.rooms = rooms; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /spring-data-gremlin-test/src/main/java/org/springframework/data/gremlin/object/jpa/domain/Location.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.object.jpa.domain; 2 | 3 | import org.springframework.data.gremlin.annotation.Index; 4 | 5 | import javax.persistence.Entity; 6 | import javax.persistence.Id; 7 | 8 | import static org.springframework.data.gremlin.annotation.Index.IndexType.SPATIAL_LATITUDE; 9 | import static org.springframework.data.gremlin.annotation.Index.IndexType.SPATIAL_LONGITUDE; 10 | 11 | /** 12 | * Created by gman on 9/06/15. 13 | */ 14 | @Entity 15 | public class Location { 16 | 17 | @Id 18 | private String id; 19 | 20 | @Index(type = SPATIAL_LATITUDE) 21 | private double latitude; 22 | @Index(type = SPATIAL_LONGITUDE) 23 | private double longitude; 24 | 25 | public Location() { 26 | } 27 | 28 | public Location(double latitude, double longitude) { 29 | this.latitude = latitude; 30 | this.longitude = longitude; 31 | } 32 | 33 | public String getId() { 34 | return id; 35 | } 36 | 37 | public void setId(String id) { 38 | this.id = id; 39 | } 40 | 41 | public double getLatitude() { 42 | return latitude; 43 | } 44 | 45 | public void setLatitude(double latitude) { 46 | this.latitude = latitude; 47 | } 48 | 49 | public double getLongitude() { 50 | return longitude; 51 | } 52 | 53 | public void setLongitude(double longitude) { 54 | this.longitude = longitude; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /spring-data-gremlin-test/src/main/java/org/springframework/data/gremlin/object/jpa/domain/Pet.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.object.jpa.domain; 2 | 3 | /** 4 | * Created by gman on 24/09/15. 5 | */ 6 | public class Pet { 7 | 8 | public enum TYPE { 9 | CAT,DOG,HORSE; 10 | } 11 | 12 | private String name; 13 | 14 | private TYPE type; 15 | 16 | public Pet() { 17 | } 18 | 19 | public Pet(String name, TYPE type) { 20 | this.name = name; 21 | this.type = type; 22 | } 23 | 24 | public String getName() { 25 | return name; 26 | } 27 | 28 | public void setName(String name) { 29 | this.name = name; 30 | } 31 | 32 | public TYPE getType() { 33 | return type; 34 | } 35 | 36 | public void setType(TYPE type) { 37 | this.type = type; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /spring-data-gremlin-test/src/main/java/org/springframework/data/gremlin/object/jpa/repository/AbstractAddressRepositoryTest.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.object.jpa.repository; 2 | 3 | import org.apache.commons.collections4.CollectionUtils; 4 | import org.junit.Assert; 5 | import org.junit.Test; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.data.gremlin.object.jpa.domain.Address; 8 | 9 | import java.util.ArrayList; 10 | import java.util.List; 11 | 12 | import static org.junit.Assert.assertEquals; 13 | import static org.junit.Assert.assertNotNull; 14 | 15 | @SuppressWarnings("SpringJavaAutowiringInspection") 16 | public abstract class AbstractAddressRepositoryTest extends BaseRepositoryTest { 17 | 18 | @Autowired 19 | protected AddressRepository addressRepository; 20 | 21 | @Test 22 | public void should_find_addresses() throws Exception { 23 | List
addresses = new ArrayList
(); 24 | 25 | CollectionUtils.addAll(addresses, addressRepository.findAll()); 26 | assertNotNull(addresses); 27 | assertEquals(2, addresses.size()); 28 | 29 | for (Address address : addresses) { 30 | Assert.assertNotNull(address.getPeople()); 31 | Assert.assertTrue(address.getPeople().size() > 0); 32 | } 33 | } 34 | 35 | @Test 36 | public void should_save_and_find_embedded_country() throws Exception { 37 | List
addresses = new ArrayList<>(); 38 | 39 | CollectionUtils.addAll(addresses, addressRepository.findAll()); 40 | assertNotNull(addresses); 41 | assertEquals(2, addresses.size()); 42 | assertNotNull(addresses.get(0).getCountry()); 43 | assertEquals("Australia", addresses.get(0).getCountry().getName()); 44 | assertNotNull(addresses.get(1).getCountry()); 45 | assertEquals("Australia", addresses.get(1).getCountry().getName()); 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /spring-data-gremlin-test/src/main/java/org/springframework/data/gremlin/object/jpa/repository/AbstractTransactionRepositoryTest.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.object.jpa.repository; 2 | 3 | import com.google.common.collect.Lists; 4 | import org.junit.Test; 5 | import org.springframework.data.gremlin.object.jpa.domain.Address; 6 | import org.springframework.data.gremlin.object.jpa.domain.Area; 7 | import org.springframework.data.gremlin.object.jpa.domain.Country; 8 | import org.springframework.data.gremlin.object.jpa.domain.Person; 9 | 10 | import java.util.List; 11 | 12 | import static org.junit.Assert.assertEquals; 13 | import static org.junit.Assert.fail; 14 | 15 | /** 16 | * Created by gman on 30/07/15. 17 | */ 18 | public class AbstractTransactionRepositoryTest extends BaseRepositoryTest { 19 | 20 | @Test 21 | public void should_rollback() { 22 | 23 | List peopele = Lists.newArrayList(repository.findAll()); 24 | int beforeRollback = peopele.size(); 25 | testService.create(new Person("Graham", "Webber", null, true)); 26 | 27 | peopele = Lists.newArrayList(repository.findAll()); 28 | assertEquals(beforeRollback + 1, peopele.size()); 29 | 30 | Address address1 = new Address(new Country("Australia"), "Newcastle", "Scenic Dr", new Area("2291")); 31 | 32 | Person graham1 = new Person("Graham", "Webber", address1, true); 33 | try { 34 | testService.failCreate(graham1, address1); 35 | fail("Should've thrown exception"); 36 | } catch (RuntimeException e) { 37 | 38 | } 39 | 40 | peopele = Lists.newArrayList(repository.findAll()); 41 | assertEquals(beforeRollback + 1, peopele.size()); 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /spring-data-gremlin-test/src/main/java/org/springframework/data/gremlin/object/jpa/repository/AddressRepository.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.object.jpa.repository; 2 | 3 | import org.springframework.data.gremlin.object.jpa.domain.Address; 4 | import org.springframework.data.gremlin.repository.GremlinRepository; 5 | 6 | /** 7 | * Created by gman on 4/06/15. 8 | */ 9 | public interface AddressRepository extends GremlinRepository
{ } 10 | -------------------------------------------------------------------------------- /spring-data-gremlin-test/src/main/java/org/springframework/data/gremlin/object/jpa/repository/LocationRepository.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.object.jpa.repository; 2 | 3 | import org.springframework.data.gremlin.object.jpa.domain.Location; 4 | import org.springframework.data.gremlin.repository.GremlinRepository; 5 | 6 | /** 7 | * Created by gman on 12/06/15. 8 | */ 9 | public interface LocationRepository extends GremlinRepository { 10 | 11 | } 12 | -------------------------------------------------------------------------------- /spring-data-gremlin-test/src/main/java/org/springframework/data/gremlin/object/jpa/repository/NativeLocationRepository.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.object.jpa.repository; 2 | 3 | import org.springframework.data.domain.Page; 4 | import org.springframework.data.domain.Pageable; 5 | import org.springframework.data.gremlin.annotation.Query; 6 | import org.springframework.data.gremlin.object.jpa.domain.Location; 7 | import org.springframework.data.gremlin.query.CompositeResult; 8 | import org.springframework.data.gremlin.repository.GremlinRepositoryWithNativeSupport; 9 | import org.springframework.data.repository.query.Param; 10 | 11 | import java.util.List; 12 | import java.util.Map; 13 | 14 | /** 15 | * Created by gman on 12/06/15. 16 | */ 17 | public interface NativeLocationRepository extends GremlinRepositoryWithNativeSupport { 18 | 19 | @Query(value = "SELECT * FROM Location WHERE [latitude,longitude,$spatial] NEAR [?,?,{\"maxDistance\":?}]", nativeQuery = true) 20 | List find(double latitude, double longitude, double radius); 21 | 22 | @Query(value = "SELECT * FROM Location WHERE [latitude,longitude,$spatial] NEAR [:lat,:lon,{\"maxDistance\"::radius}]", nativeQuery = true) 23 | List findWithParam(@Param("lat") double latitude, @Param("lon") double longitude, @Param("radius") double radius); 24 | 25 | @Query(value = "SELECT * FROM Location WHERE [latitude,longitude,$spatial] NEAR [?,?,{\"maxDistance\":?}]", nativeQuery = true) 26 | Page find(double latitude, double longitude, double radius, Pageable pageable); 27 | 28 | @Query(value = "SELECT *,eval('1000d * $distance') as distance FROM Location WHERE [latitude,longitude,$spatial] NEAR [?,?,{\"maxDistance\":?}]", nativeQuery = true) 29 | List> findNear(double latitude, double longitude, double radius); 30 | 31 | @Query(value = "SELECT *,eval('1000d * $distance') as distance FROM Location WHERE [latitude,longitude,$spatial] NEAR [?,?,{\"maxDistance\":?}]", nativeQuery = true) 32 | Page> findNear(double latitude, double longitude, double radius, Pageable pageable); 33 | 34 | @Query(value = "SELECT *,eval('1000d * $distance') as distance FROM Location WHERE [latitude,longitude,$spatial] NEAR [?,?,{\"maxDistance\":?}]", nativeQuery = true) 35 | List> findComposite(double latitude, double longitude, double radius); 36 | 37 | @Query(value = "SELECT *,eval('1000d * $distance') as distance FROM Location WHERE [latitude,longitude,$spatial] NEAR [?,?,{\"maxDistance\":?}]", nativeQuery = true) 38 | Page> findComposite(double latitude, double longitude, double radius, Pageable pageable); 39 | 40 | } 41 | -------------------------------------------------------------------------------- /spring-data-gremlin-test/src/main/java/org/springframework/data/gremlin/object/jpa/repository/NativePersonRepository.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.object.jpa.repository; 2 | 3 | import org.springframework.data.domain.Page; 4 | import org.springframework.data.domain.Pageable; 5 | import org.springframework.data.gremlin.annotation.Query; 6 | import org.springframework.data.gremlin.object.jpa.domain.Person; 7 | import org.springframework.data.gremlin.repository.GremlinRepositoryWithNativeSupport; 8 | 9 | /** 10 | * Created by gman on 25/06/15. 11 | */ 12 | public interface NativePersonRepository extends GremlinRepositoryWithNativeSupport { 13 | 14 | @Query(value = "delete vertex from (select from Person where firstName <> ?)", nativeQuery = true, modify = true) 15 | Integer deleteAllExceptUser(String firstName); 16 | 17 | 18 | @Query(value = "SELECT expand(in('located_at')) FROM (SELECT FROM Location WHERE [latitude,longitude,$spatial] NEAR [?,?,{\"maxDistance\":?}])", nativeQuery = true) 19 | Page findNear(double latitude, double longitude, double radius, Pageable pageable); 20 | 21 | } 22 | -------------------------------------------------------------------------------- /spring-data-gremlin-test/src/main/java/org/springframework/data/gremlin/object/jpa/repository/PersonRepository.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.object.jpa.repository; 2 | 3 | import org.springframework.data.domain.Page; 4 | import org.springframework.data.domain.Pageable; 5 | import org.springframework.data.gremlin.annotation.Query; 6 | import org.springframework.data.gremlin.object.jpa.domain.Person; 7 | import org.springframework.data.gremlin.repository.GremlinRepository; 8 | import org.springframework.data.repository.query.Param; 9 | 10 | import java.util.List; 11 | import java.util.Map; 12 | 13 | public interface PersonRepository extends GremlinRepository { 14 | 15 | @Query(value = "graph.V().has('firstName', ?)") 16 | List findByFirstName(String firstName); 17 | 18 | @Query(value = "graph.V().has('firstName', :fn)") 19 | List findByFirstNameWithParam(@Param("fn") String firstName); 20 | 21 | @Query(value = "graph.V().has('firstName', ?)") 22 | Page findByFirstName(String firstName, Pageable pageable); 23 | 24 | @Query(value = "graph.V().has('firstName', ?)") 25 | Person findSingleByFirstName(String firstName); 26 | 27 | @Query(value = "graph.V().has('firstName', ?)") 28 | List> findMapByFirstName(String firstName); 29 | 30 | @Query(value = "graph.V().has('firstName', ?)") 31 | Map findSingleMapByFirstName(String firstName); 32 | 33 | List findByLastName(String lastName); 34 | 35 | List findByLastNameLike(String lastName); 36 | 37 | List findByFirstNameAndLastName(String firstName, String lastName); 38 | 39 | List findByFirstNameOrLastName(String firstName, String lastName); 40 | 41 | List findByFirstNameLike(String string); 42 | 43 | List findByFirstNameStartsWith(String firstName); 44 | 45 | Long countByFirstName(String firstName); 46 | 47 | Long countByLastName(String lastName); 48 | 49 | // @Detach(DetachMode.ENTITY) 50 | List findByAddress_City(String city); 51 | 52 | 53 | List findByLastNameOrAddress_City(String lastName, String city); 54 | 55 | List findByAddress_Area_Name(String name); 56 | 57 | List findByLastNameOrAddress_Area_Name(String lastName, String name); 58 | 59 | // @FetchPlan("*:-1") 60 | // List findByAddress_Country(String city); 61 | 62 | List findByActiveIsTrue(); 63 | 64 | List findByActiveIsFalse(); 65 | 66 | Page findByLastName(String lastName, Pageable pageable); 67 | 68 | 69 | @Query(value = "graph.V('lastName', ?)") 70 | Page queryLastName(String lastName, Pageable pageable); 71 | 72 | } 73 | -------------------------------------------------------------------------------- /spring-data-gremlin-test/src/main/java/org/springframework/data/gremlin/object/neo4j/TestService.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.object.neo4j; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.data.domain.PageRequest; 5 | import org.springframework.data.gremlin.object.neo4j.domain.Address; 6 | import org.springframework.data.gremlin.object.neo4j.domain.Person; 7 | import org.springframework.data.gremlin.object.neo4j.repository.AddressRepository; 8 | import org.springframework.data.gremlin.object.neo4j.repository.NativePersonRepository; 9 | import org.springframework.data.gremlin.object.neo4j.repository.PersonRepository; 10 | import org.springframework.stereotype.Service; 11 | import org.springframework.transaction.annotation.Transactional; 12 | 13 | /** 14 | * Created by gman on 30/07/15. 15 | */ 16 | @Service 17 | public class TestService { 18 | 19 | @Autowired 20 | private PersonRepository repository; 21 | 22 | @Autowired 23 | private AddressRepository addressRepository; 24 | 25 | @Autowired(required = false) 26 | private NativePersonRepository nativePersonRepository; 27 | 28 | @Transactional 29 | public void create(Person person) { 30 | repository.save(person); 31 | } 32 | 33 | @Transactional 34 | public void failCreate(Person person, Address address) { 35 | create(person); 36 | 37 | Person test = new Person("Graham", "Webber", address, true); 38 | repository.save(test); 39 | repository.findByAddress_Area_Name("asdf"); 40 | repository.queryLastName("asdf", new PageRequest(0, 2)); 41 | if (nativePersonRepository != null) { 42 | nativePersonRepository.findNear(-33d, 151d, 50, new PageRequest(0, 2)); 43 | } 44 | addressRepository.save(address); 45 | throw new IllegalStateException(); 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /spring-data-gremlin-test/src/main/java/org/springframework/data/gremlin/object/neo4j/domain/Address.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.object.neo4j.domain; 2 | 3 | import org.neo4j.graphdb.Direction; 4 | import org.springframework.data.neo4j.annotation.GraphId; 5 | import org.springframework.data.neo4j.annotation.NodeEntity; 6 | import org.springframework.data.neo4j.annotation.RelatedTo; 7 | 8 | import java.util.HashSet; 9 | import java.util.Set; 10 | 11 | @NodeEntity 12 | public class Address { 13 | 14 | @GraphId 15 | private String id; 16 | 17 | private String country; 18 | 19 | private String city; 20 | 21 | private String street; 22 | 23 | @RelatedTo(type = "of_area") 24 | private Area area; 25 | 26 | @RelatedTo(type = "lives_at", direction = Direction.INCOMING) 27 | private Set people; 28 | 29 | public Address() {} 30 | 31 | public Address(String country, String city, String street, Area area) { 32 | this.country = country; 33 | this.city = city; 34 | this.street = street; 35 | this.area = area; 36 | } 37 | 38 | public String getId() { 39 | return id; 40 | } 41 | 42 | public void setId(String id) { 43 | this.id = id; 44 | } 45 | 46 | public String getCountry() { 47 | return country; 48 | } 49 | 50 | public void setCountry(String country) { 51 | this.country = country; 52 | } 53 | 54 | public String getCity() { 55 | return city; 56 | } 57 | 58 | public void setCity(String city) { 59 | this.city = city; 60 | } 61 | 62 | public String getStreet() { 63 | return street; 64 | } 65 | 66 | public void setStreet(String street) { 67 | this.street = street; 68 | } 69 | 70 | public Area getArea() { 71 | return area; 72 | } 73 | 74 | public void setArea(Area area) { 75 | this.area = area; 76 | } 77 | 78 | public Set getPeople() { 79 | if (people == null) { 80 | people = new HashSet(); 81 | } 82 | return people; 83 | } 84 | 85 | public void setPeople(Set people) { 86 | this.people = people; 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /spring-data-gremlin-test/src/main/java/org/springframework/data/gremlin/object/neo4j/domain/Area.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.object.neo4j.domain; 2 | 3 | import org.springframework.data.neo4j.annotation.GraphId; 4 | import org.springframework.data.neo4j.annotation.NodeEntity; 5 | 6 | @NodeEntity 7 | public class Area { 8 | 9 | @GraphId 10 | private String id; 11 | 12 | private String name; 13 | 14 | public Area() { 15 | } 16 | 17 | public Area(String name) { 18 | this.name = name; 19 | } 20 | 21 | public String getId() { 22 | return id; 23 | } 24 | 25 | public void setId(String id) { 26 | this.id = id; 27 | } 28 | 29 | public String getName() { 30 | return name; 31 | } 32 | 33 | public void setName(String name) { 34 | this.name = name; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /spring-data-gremlin-test/src/main/java/org/springframework/data/gremlin/object/neo4j/domain/Employee.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.object.neo4j.domain; 2 | 3 | import javax.persistence.Column; 4 | import javax.persistence.Id; 5 | import javax.persistence.OneToOne; 6 | 7 | //@Entity 8 | public class Employee { 9 | 10 | @Id 11 | private String id; 12 | 13 | @Column(unique = true) 14 | private int employeeNumber; 15 | 16 | private String title; 17 | 18 | @OneToOne 19 | private Person person; 20 | 21 | public String getId() { 22 | return id; 23 | } 24 | 25 | public void setId(String id) { 26 | this.id = id; 27 | } 28 | 29 | public int getEmployeeNumber() { 30 | return employeeNumber; 31 | } 32 | 33 | public void setEmployeeNumber(int employeeNumber) { 34 | this.employeeNumber = employeeNumber; 35 | } 36 | 37 | public String getTitle() { 38 | return title; 39 | } 40 | 41 | public void setTitle(String title) { 42 | this.title = title; 43 | } 44 | 45 | public Person getPerson() { 46 | return person; 47 | } 48 | 49 | public void setPerson(Person person) { 50 | this.person = person; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /spring-data-gremlin-test/src/main/java/org/springframework/data/gremlin/object/neo4j/domain/House.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.object.neo4j.domain; 2 | 3 | import java.io.Serializable; 4 | 5 | /** 6 | * Created by gman on 24/09/15. 7 | */ 8 | public class House implements Serializable { 9 | 10 | private int rooms; 11 | 12 | public House() { 13 | } 14 | 15 | public House(int rooms) { 16 | this.rooms = rooms; 17 | } 18 | 19 | public int getRooms() { 20 | return rooms; 21 | } 22 | 23 | public void setRooms(int rooms) { 24 | this.rooms = rooms; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /spring-data-gremlin-test/src/main/java/org/springframework/data/gremlin/object/neo4j/domain/Likes.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.object.neo4j.domain; 2 | 3 | import org.springframework.data.gremlin.annotation.Edge; 4 | import org.springframework.data.gremlin.annotation.Id; 5 | import org.springframework.data.neo4j.annotation.EndNode; 6 | import org.springframework.data.neo4j.annotation.GraphId; 7 | import org.springframework.data.neo4j.annotation.RelationshipEntity; 8 | import org.springframework.data.neo4j.annotation.StartNode; 9 | 10 | import java.util.Date; 11 | 12 | /** 13 | * Created by gman on 16/09/15. 14 | */ 15 | @RelationshipEntity 16 | public class Likes { 17 | 18 | @GraphId 19 | private String id; 20 | 21 | private Date date = new Date(); 22 | 23 | @StartNode 24 | private Person person1; 25 | 26 | @EndNode 27 | private Person person2; 28 | 29 | public Likes() { 30 | } 31 | 32 | public Likes(Person person1, Person person2) { 33 | this.person1 = person1; 34 | this.person2 = person2; 35 | person1.getLikes().add(this); 36 | } 37 | 38 | public Date getDate() { 39 | return date; 40 | } 41 | 42 | public Person getPerson1() { 43 | return person1; 44 | } 45 | 46 | public Person getPerson2() { 47 | return person2; 48 | } 49 | 50 | @Override 51 | public boolean equals(Object o) { 52 | if (this == o) { 53 | return true; 54 | } 55 | if (o == null || getClass() != o.getClass()) { 56 | return false; 57 | } 58 | 59 | Likes likes = (Likes) o; 60 | 61 | return !(id != null ? !id.equals(likes.id) : likes.id != null); 62 | 63 | } 64 | 65 | @Override 66 | public int hashCode() { 67 | return id != null ? id.hashCode() : 0; 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /spring-data-gremlin-test/src/main/java/org/springframework/data/gremlin/object/neo4j/domain/Located.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.object.neo4j.domain; 2 | 3 | import org.springframework.data.neo4j.annotation.*; 4 | 5 | import java.util.Date; 6 | 7 | /** 8 | * Created by gman on 3/08/15. 9 | */ 10 | @RelationshipEntity(type = "was_located") 11 | public class Located { 12 | 13 | @GraphId 14 | private String id; 15 | 16 | @GraphProperty(propertyName = "location_date") 17 | private Date date; 18 | 19 | @StartNode 20 | private Person person; 21 | 22 | @EndNode 23 | private Location location; 24 | 25 | public Located() { 26 | } 27 | 28 | public Located(Date date, Person person, Location location) { 29 | this.date = date; 30 | this.person = person; 31 | this.location = location; 32 | } 33 | 34 | public String getId() { 35 | return id; 36 | } 37 | 38 | public void setId(String id) { 39 | this.id = id; 40 | } 41 | 42 | public Date getDate() { 43 | return date; 44 | } 45 | 46 | public void setDate(Date date) { 47 | this.date = date; 48 | } 49 | 50 | public Person getPerson() { 51 | return person; 52 | } 53 | 54 | public void setPerson(Person person) { 55 | this.person = person; 56 | } 57 | 58 | public Location getLocation() { 59 | return location; 60 | } 61 | 62 | public void setLocation(Location location) { 63 | this.location = location; 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /spring-data-gremlin-test/src/main/java/org/springframework/data/gremlin/object/neo4j/domain/Location.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.object.neo4j.domain; 2 | 3 | import org.springframework.data.gremlin.annotation.Index; 4 | import org.springframework.data.neo4j.annotation.GraphId; 5 | import org.springframework.data.neo4j.annotation.NodeEntity; 6 | 7 | import static org.springframework.data.gremlin.annotation.Index.IndexType.SPATIAL_LATITUDE; 8 | import static org.springframework.data.gremlin.annotation.Index.IndexType.SPATIAL_LONGITUDE; 9 | 10 | /** 11 | * Created by gman on 9/06/15. 12 | */ 13 | @NodeEntity 14 | public class Location { 15 | 16 | @GraphId 17 | private String id; 18 | 19 | @Index(type = SPATIAL_LATITUDE) 20 | private double latitude; 21 | @Index(type = SPATIAL_LONGITUDE) 22 | private double longitude; 23 | 24 | public Location() { 25 | } 26 | 27 | public Location(double latitude, double longitude) { 28 | this.latitude = latitude; 29 | this.longitude = longitude; 30 | } 31 | 32 | public String getId() { 33 | return id; 34 | } 35 | 36 | public void setId(String id) { 37 | this.id = id; 38 | } 39 | 40 | public double getLatitude() { 41 | return latitude; 42 | } 43 | 44 | public void setLatitude(double latitude) { 45 | this.latitude = latitude; 46 | } 47 | 48 | public double getLongitude() { 49 | return longitude; 50 | } 51 | 52 | public void setLongitude(double longitude) { 53 | this.longitude = longitude; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /spring-data-gremlin-test/src/main/java/org/springframework/data/gremlin/object/neo4j/domain/Pet.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.object.neo4j.domain; 2 | 3 | /** 4 | * Created by gman on 24/09/15. 5 | */ 6 | public class Pet { 7 | 8 | public enum TYPE { 9 | CAT,DOG,HORSE; 10 | } 11 | 12 | private String name; 13 | 14 | private TYPE type; 15 | 16 | public Pet() { 17 | } 18 | 19 | public Pet(String name, TYPE type) { 20 | this.name = name; 21 | this.type = type; 22 | } 23 | 24 | public String getName() { 25 | return name; 26 | } 27 | 28 | public void setName(String name) { 29 | this.name = name; 30 | } 31 | 32 | public TYPE getType() { 33 | return type; 34 | } 35 | 36 | public void setType(TYPE type) { 37 | this.type = type; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /spring-data-gremlin-test/src/main/java/org/springframework/data/gremlin/object/neo4j/repository/AbstractAddressRepositoryTest.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.object.neo4j.repository; 2 | 3 | import org.apache.commons.collections4.CollectionUtils; 4 | import org.junit.Assert; 5 | import org.junit.Test; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.data.gremlin.object.neo4j.domain.Address; 8 | 9 | import java.util.ArrayList; 10 | import java.util.List; 11 | 12 | import static org.junit.Assert.assertEquals; 13 | import static org.junit.Assert.assertNotNull; 14 | 15 | @SuppressWarnings("SpringJavaAutowiringInspection") 16 | public abstract class AbstractAddressRepositoryTest extends BaseRepositoryTest { 17 | 18 | @Autowired 19 | protected AddressRepository addressRepository; 20 | 21 | @Test 22 | public void should_find_addresses() throws Exception { 23 | List
addresses = new ArrayList
(); 24 | 25 | CollectionUtils.addAll(addresses, addressRepository.findAll()); 26 | assertNotNull(addresses); 27 | assertEquals(2, addresses.size()); 28 | 29 | for (Address address : addresses) { 30 | Assert.assertNotNull(address.getPeople()); 31 | Assert.assertTrue(address.getPeople().size() > 0); 32 | } 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /spring-data-gremlin-test/src/main/java/org/springframework/data/gremlin/object/neo4j/repository/AbstractTransactionRepositoryTest.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.object.neo4j.repository; 2 | 3 | import com.google.common.collect.Lists; 4 | import org.junit.Test; 5 | import org.springframework.data.gremlin.object.neo4j.domain.Address; 6 | import org.springframework.data.gremlin.object.neo4j.domain.Area; 7 | import org.springframework.data.gremlin.object.neo4j.domain.Person; 8 | 9 | import java.util.List; 10 | 11 | import static org.junit.Assert.assertEquals; 12 | import static org.junit.Assert.fail; 13 | 14 | /** 15 | * Created by gman on 30/07/15. 16 | */ 17 | public class AbstractTransactionRepositoryTest extends BaseRepositoryTest { 18 | 19 | @Test 20 | public void should_rollback() { 21 | 22 | List peopele = Lists.newArrayList(repository.findAll()); 23 | int beforeRollback = peopele.size(); 24 | testService.create(new Person("Graham", "Webber", null, true)); 25 | 26 | peopele = Lists.newArrayList(repository.findAll()); 27 | assertEquals(beforeRollback + 1, peopele.size()); 28 | 29 | Address address1 = new Address("Australia", "Newcastle", "Scenic Dr", new Area("2291")); 30 | 31 | Person graham1 = new Person("Graham", "Webber", address1, true); 32 | try { 33 | testService.failCreate(graham1, address1); 34 | fail("Should've thrown exception"); 35 | } catch (RuntimeException e) { 36 | 37 | } 38 | 39 | peopele = Lists.newArrayList(repository.findAll()); 40 | assertEquals(beforeRollback + 1, peopele.size()); 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /spring-data-gremlin-test/src/main/java/org/springframework/data/gremlin/object/neo4j/repository/AddressRepository.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.object.neo4j.repository; 2 | 3 | import org.springframework.data.gremlin.object.neo4j.domain.Address; 4 | import org.springframework.data.gremlin.repository.GremlinRepository; 5 | 6 | /** 7 | * Created by gman on 4/06/15. 8 | */ 9 | public interface AddressRepository extends GremlinRepository
{ } 10 | -------------------------------------------------------------------------------- /spring-data-gremlin-test/src/main/java/org/springframework/data/gremlin/object/neo4j/repository/LikesRepository.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.object.neo4j.repository; 2 | 3 | import org.springframework.data.gremlin.annotation.Query; 4 | import org.springframework.data.gremlin.object.neo4j.domain.Likes; 5 | import org.springframework.data.gremlin.repository.GremlinRepository; 6 | 7 | import java.util.Date; 8 | import java.util.List; 9 | 10 | /** 11 | * Created by gman on 4/06/15. 12 | */ 13 | public interface LikesRepository extends GremlinRepository { 14 | 15 | 16 | List findByPerson1_FirstName(String firstName); 17 | 18 | @Query(value = "graph.V().has('firstName', ?).outE('Likes').as('x').inV.filter{it.firstName == ?}.back('x')") 19 | List findByLiking(String liker, String liked); 20 | 21 | } 22 | -------------------------------------------------------------------------------- /spring-data-gremlin-test/src/main/java/org/springframework/data/gremlin/object/neo4j/repository/LocatedRepository.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.object.neo4j.repository; 2 | 3 | import org.springframework.data.gremlin.object.neo4j.domain.Located; 4 | import org.springframework.data.gremlin.repository.GremlinRepository; 5 | 6 | /** 7 | * Created by gman on 4/06/15. 8 | */ 9 | public interface LocatedRepository extends GremlinRepository { } 10 | -------------------------------------------------------------------------------- /spring-data-gremlin-test/src/main/java/org/springframework/data/gremlin/object/neo4j/repository/LocationRepository.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.object.neo4j.repository; 2 | 3 | import org.springframework.data.gremlin.object.neo4j.domain.Location; 4 | import org.springframework.data.gremlin.repository.GremlinRepository; 5 | 6 | /** 7 | * Created by gman on 12/06/15. 8 | */ 9 | public interface LocationRepository extends GremlinRepository { 10 | 11 | } 12 | -------------------------------------------------------------------------------- /spring-data-gremlin-test/src/main/java/org/springframework/data/gremlin/object/neo4j/repository/NativeLocationRepository.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.object.neo4j.repository; 2 | 3 | import org.springframework.data.domain.Page; 4 | import org.springframework.data.domain.Pageable; 5 | import org.springframework.data.gremlin.annotation.Query; 6 | import org.springframework.data.gremlin.object.neo4j.domain.Location; 7 | import org.springframework.data.gremlin.query.CompositeResult; 8 | import org.springframework.data.gremlin.repository.GremlinRepositoryWithNativeSupport; 9 | import org.springframework.data.repository.query.Param; 10 | 11 | import java.util.List; 12 | import java.util.Map; 13 | 14 | /** 15 | * Created by gman on 12/06/15. 16 | */ 17 | public interface NativeLocationRepository extends GremlinRepositoryWithNativeSupport { 18 | 19 | @Query(value = "SELECT * FROM Location WHERE [latitude,longitude,$spatial] NEAR [?,?,{\"maxDistance\":?}]", nativeQuery = true) 20 | List find(double latitude, double longitude, double radius); 21 | 22 | @Query(value = "SELECT * FROM Location WHERE [latitude,longitude,$spatial] NEAR [:lat,:lon,{\"maxDistance\"::radius}]", nativeQuery = true) 23 | List findWithParam(@Param("lat") double latitude, @Param("lon") double longitude, @Param("radius") double radius); 24 | 25 | @Query(value = "SELECT * FROM Location WHERE [latitude,longitude,$spatial] NEAR [?,?,{\"maxDistance\":?}]", nativeQuery = true) 26 | Page find(double latitude, double longitude, double radius, Pageable pageable); 27 | 28 | @Query(value = "SELECT *,eval('1000d * $distance') as distance FROM Location WHERE [latitude,longitude,$spatial] NEAR [?,?,{\"maxDistance\":?}]", nativeQuery = true) 29 | List> findNear(double latitude, double longitude, double radius); 30 | 31 | @Query(value = "SELECT *,eval('1000d * $distance') as distance FROM Location WHERE [latitude,longitude,$spatial] NEAR [?,?,{\"maxDistance\":?}]", nativeQuery = true) 32 | Page> findNear(double latitude, double longitude, double radius, Pageable pageable); 33 | 34 | @Query(value = "SELECT *,eval('1000d * $distance') as distance FROM Location WHERE [latitude,longitude,$spatial] NEAR [?,?,{\"maxDistance\":?}]", nativeQuery = true) 35 | List> findComposite(double latitude, double longitude, double radius); 36 | 37 | @Query(value = "SELECT *,eval('1000d * $distance') as distance FROM Location WHERE [latitude,longitude,$spatial] NEAR [?,?,{\"maxDistance\":?}]", nativeQuery = true) 38 | Page> findComposite(double latitude, double longitude, double radius, Pageable pageable); 39 | 40 | } 41 | -------------------------------------------------------------------------------- /spring-data-gremlin-test/src/main/java/org/springframework/data/gremlin/object/neo4j/repository/NativePersonRepository.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.object.neo4j.repository; 2 | 3 | import org.springframework.data.domain.Page; 4 | import org.springframework.data.domain.Pageable; 5 | import org.springframework.data.gremlin.annotation.Query; 6 | import org.springframework.data.gremlin.object.neo4j.domain.Person; 7 | import org.springframework.data.gremlin.repository.GremlinRepositoryWithNativeSupport; 8 | 9 | /** 10 | * Created by gman on 25/06/15. 11 | */ 12 | public interface NativePersonRepository extends GremlinRepositoryWithNativeSupport { 13 | 14 | @Query(value = "delete vertex from (select from Person where firstName <> ?)", nativeQuery = true, modify = true) 15 | Integer deleteAllExceptUser(String firstName); 16 | 17 | 18 | @Query(value = "SELECT expand(in('was_located')) FROM (SELECT FROM Location WHERE [latitude,longitude,$spatial] NEAR [?,?,{\"maxDistance\":?}])", nativeQuery = true) 19 | Page findNear(double latitude, double longitude, double radius, Pageable pageable); 20 | 21 | } 22 | -------------------------------------------------------------------------------- /spring-data-gremlin-test/src/main/java/org/springframework/data/gremlin/object/neo4j/repository/PersonRepository.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.object.neo4j.repository; 2 | 3 | import org.springframework.data.domain.Page; 4 | import org.springframework.data.domain.Pageable; 5 | import org.springframework.data.gremlin.annotation.Query; 6 | import org.springframework.data.gremlin.object.neo4j.domain.Person; 7 | import org.springframework.data.gremlin.repository.GremlinRepository; 8 | import org.springframework.data.repository.query.Param; 9 | 10 | import java.util.List; 11 | import java.util.Map; 12 | 13 | public interface PersonRepository extends GremlinRepository { 14 | 15 | @Query(value = "graph.V().has('firstName', ?)") 16 | List findByFirstName(String firstName); 17 | 18 | @Query(value = "graph.V().has('firstName', :fn)") 19 | List findByFirstNameWithParam(@Param("fn") String firstName); 20 | 21 | @Query(value = "graph.V().has('firstName', ?)") 22 | Page findByFirstName(String firstName, Pageable pageable); 23 | 24 | @Query(value = "graph.V().has('firstName', ?)") 25 | Person findSingleByFirstName(String firstName); 26 | 27 | @Query(value = "graph.V().has('firstName', ?)") 28 | List> findMapByFirstName(String firstName); 29 | 30 | @Query(value = "graph.V().has('firstName', ?)") 31 | Map findSingleMapByFirstName(String firstName); 32 | 33 | List findByLastName(String lastName); 34 | 35 | List findByLastNameLike(String lastName); 36 | 37 | List findByFirstNameAndLastName(String firstName, String lastName); 38 | 39 | List findByFirstNameOrLastName(String firstName, String lastName); 40 | 41 | List findByFirstNameLike(String string); 42 | 43 | List findByFirstNameStartsWith(String firstName); 44 | 45 | Long countByFirstName(String firstName); 46 | 47 | Long countByLastName(String lastName); 48 | 49 | // @Detach(DetachMode.ENTITY) 50 | List findByAddress_City(String city); 51 | 52 | 53 | List findByLastNameOrAddress_City(String lastName, String city); 54 | 55 | List findByAddress_Area_Name(String name); 56 | 57 | List findByLastNameOrAddress_Area_Name(String lastName, String name); 58 | 59 | // @FetchPlan("*:-1") 60 | // List findByAddress_Country(String city); 61 | 62 | List findByActiveIsTrue(); 63 | 64 | List findByActiveIsFalse(); 65 | 66 | Page findByLastName(String lastName, Pageable pageable); 67 | 68 | 69 | @Query(value = "graph.V('lastName', ?)") 70 | Page queryLastName(String lastName, Pageable pageable); 71 | 72 | } 73 | -------------------------------------------------------------------------------- /spring-data-gremlin-test/src/main/java/org/springframework/data/gremlin/schema/EmbeddedTestEntity.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.schema; 2 | 3 | import javax.persistence.Embeddable; 4 | import javax.persistence.Embedded; 5 | import java.util.Date; 6 | 7 | /** 8 | * Created by gman on 18/05/15. 9 | */ 10 | @Embeddable 11 | public class EmbeddedTestEntity { 12 | 13 | private String embeddedBla; 14 | private Date embeddedDate; 15 | private int value; 16 | 17 | @Embedded 18 | private MultiEmbeddedTestEntity multiEmbed; 19 | } 20 | -------------------------------------------------------------------------------- /spring-data-gremlin-test/src/main/java/org/springframework/data/gremlin/schema/LinkedTestEntity.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.schema; 2 | 3 | import javax.persistence.Entity; 4 | import javax.persistence.Id; 5 | 6 | /** 7 | * Created by gman on 18/05/15. 8 | */ 9 | @Entity(name = "Link") 10 | public class LinkedTestEntity { 11 | 12 | @Id 13 | private String id; 14 | 15 | } 16 | -------------------------------------------------------------------------------- /spring-data-gremlin-test/src/main/java/org/springframework/data/gremlin/schema/MultiEmbeddedTestEntity.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.schema; 2 | 3 | import javax.persistence.Embeddable; 4 | 5 | /** 6 | * Created by gman on 18/05/15. 7 | */ 8 | @Embeddable 9 | public class MultiEmbeddedTestEntity { 10 | 11 | private String multiEmbedded; 12 | } 13 | -------------------------------------------------------------------------------- /spring-data-gremlin-test/src/main/java/org/springframework/data/gremlin/schema/TestEntity.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.schema; 2 | 3 | import javax.persistence.*; 4 | 5 | /** 6 | * Created by gman on 18/05/15. 7 | */ 8 | public class TestEntity { 9 | 10 | @Id 11 | private String id; 12 | 13 | @Column(name = "unique", unique = true) 14 | private String name; 15 | 16 | private int value; 17 | 18 | @Transient 19 | private String tranny; 20 | 21 | private transient int anotherTranny; 22 | 23 | public static String staty; 24 | 25 | @OneToOne 26 | private LinkedTestEntity linkedEntity; 27 | 28 | @Embedded 29 | @AttributeOverrides({ @AttributeOverride(name = "value", column = @Column(name = "embeddedValue")) }) 30 | private EmbeddedTestEntity embeddedTestEntity; 31 | 32 | } 33 | -------------------------------------------------------------------------------- /spring-data-gremlin-tinker/build.gradle: -------------------------------------------------------------------------------- 1 | dependencies { 2 | compile project(':spring-data-gremlin-core') 3 | testCompile project(':spring-data-gremlin-test') 4 | testCompile project(':spring-data-gremlin-schemagen-jpa') 5 | testCompile project(':spring-data-gremlin-schemagen-neo4j') 6 | } -------------------------------------------------------------------------------- /spring-data-gremlin-tinker/src/main/java/org/springframework/data/gremlin/repository/tinker/TinkerGraphAdapter.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.repository.tinker; 2 | 3 | import com.tinkerpop.blueprints.Vertex; 4 | import com.tinkerpop.blueprints.impls.tg.TinkerGraph; 5 | import org.slf4j.Logger; 6 | import org.slf4j.LoggerFactory; 7 | import org.springframework.data.gremlin.repository.GremlinGraphAdapter; 8 | import org.springframework.transaction.annotation.Transactional; 9 | 10 | /** 11 | * Created by gman on 27/06/15. 12 | */ 13 | public class TinkerGraphAdapter extends GremlinGraphAdapter { 14 | 15 | private static final Logger LOGGER = LoggerFactory.getLogger(TinkerGraphAdapter.class); 16 | 17 | @Override 18 | @Transactional(readOnly = false) 19 | public Vertex createVertex(TinkerGraph graph, String className) { 20 | Vertex vertex = graph.addVertex(null); 21 | vertex.setProperty("label", className); 22 | return vertex; 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /spring-data-gremlin-tinker/src/main/java/org/springframework/data/gremlin/tx/tinker/TinkerGremlinGraphFactory.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.tx.tinker; 2 | 3 | 4 | import com.tinkerpop.blueprints.impls.tg.TinkerGraph; 5 | import org.slf4j.Logger; 6 | import org.slf4j.LoggerFactory; 7 | import org.springframework.data.gremlin.tx.AbstractGremlinGraphFactory; 8 | 9 | /** 10 | * An {@link AbstractGremlinGraphFactory} for OrentDB providing an {@link TinkerGraph} implementation of {@link com.tinkerpop.blueprints.Graph}. 11 | * 12 | * @author Gman 13 | */ 14 | public class TinkerGremlinGraphFactory extends AbstractGremlinGraphFactory { 15 | 16 | private static final Logger LOGGER = LoggerFactory.getLogger(TinkerGremlinGraphFactory.class); 17 | 18 | private TinkerGraph graph = null; 19 | 20 | @Override 21 | protected void createPool() { 22 | graph = new TinkerGraph(); 23 | } 24 | 25 | @Override 26 | public boolean isActive(TinkerGraph graph) { 27 | return false; 28 | } 29 | 30 | @Override 31 | public boolean isClosed(TinkerGraph graph) { 32 | return false; 33 | } 34 | 35 | @Override 36 | public void beginTx(TinkerGraph graph) { 37 | } 38 | 39 | @Override 40 | public void commitTx(TinkerGraph graph) { 41 | } 42 | 43 | @Override 44 | public void rollbackTx(TinkerGraph graph) { 45 | } 46 | 47 | @Override 48 | public TinkerGraph openGraph() { 49 | return graph; 50 | } 51 | 52 | @Override 53 | protected void createGraph() { 54 | LOGGER.warn("Cannot create database on remote connections."); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /spring-data-gremlin-tinker/src/test/java/org/springframework/data/gremlin/object/tests/tinker/core/Tinker_Core_AddressRepositoryTest.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.object.tests.tinker.core; 2 | 3 | import org.springframework.data.gremlin.object.core.repository.AbstractAddressRepositoryTest; 4 | import org.springframework.test.context.ContextConfiguration; 5 | 6 | /** 7 | * Created by gman on 24/06/15. 8 | */ 9 | @ContextConfiguration(classes = Tinker_Core_TestConfiguration.class) 10 | public class Tinker_Core_AddressRepositoryTest extends AbstractAddressRepositoryTest { } 11 | -------------------------------------------------------------------------------- /spring-data-gremlin-tinker/src/test/java/org/springframework/data/gremlin/object/tests/tinker/core/Tinker_Core_EdgeRepositoryTest.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.object.tests.tinker.core; 2 | 3 | import org.springframework.data.gremlin.object.core.repository.AbstractEdgeRepositoryTest; 4 | import org.springframework.test.context.ContextConfiguration; 5 | 6 | /** 7 | * Created by gman on 24/06/15. 8 | */ 9 | @ContextConfiguration(classes = Tinker_Core_TestConfiguration.class) 10 | public class Tinker_Core_EdgeRepositoryTest extends AbstractEdgeRepositoryTest { } 11 | -------------------------------------------------------------------------------- /spring-data-gremlin-tinker/src/test/java/org/springframework/data/gremlin/object/tests/tinker/core/Tinker_Core_PersonRepositoryTest.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.object.tests.tinker.core; 2 | 3 | import org.springframework.data.gremlin.object.core.repository.AbstractPersonRepositoryTest; 4 | import org.springframework.test.context.ContextConfiguration; 5 | 6 | /** 7 | * Created by gman on 24/06/15. 8 | */ 9 | @ContextConfiguration(classes = Tinker_Core_TestConfiguration.class) 10 | public class Tinker_Core_PersonRepositoryTest extends AbstractPersonRepositoryTest { } 11 | -------------------------------------------------------------------------------- /spring-data-gremlin-tinker/src/test/java/org/springframework/data/gremlin/object/tests/tinker/jpa/Tinker_JPA_AddressRepositoryTest.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.object.tests.tinker.jpa; 2 | 3 | import org.springframework.data.gremlin.object.jpa.repository.AbstractAddressRepositoryTest; 4 | import org.springframework.test.context.ContextConfiguration; 5 | 6 | /** 7 | * Created by gman on 24/06/15. 8 | */ 9 | @ContextConfiguration(classes = Tinker_JPA_TestConfiguration.class) 10 | public class Tinker_JPA_AddressRepositoryTest extends AbstractAddressRepositoryTest { } 11 | -------------------------------------------------------------------------------- /spring-data-gremlin-tinker/src/test/java/org/springframework/data/gremlin/object/tests/tinker/jpa/Tinker_JPA_PersonRepositoryTest.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.object.tests.tinker.jpa; 2 | 3 | import org.springframework.data.gremlin.object.jpa.repository.AbstractPersonRepositoryTest; 4 | import org.springframework.test.context.ContextConfiguration; 5 | 6 | /** 7 | * Created by gman on 24/06/15. 8 | */ 9 | @ContextConfiguration(classes = Tinker_JPA_TestConfiguration.class) 10 | public class Tinker_JPA_PersonRepositoryTest extends AbstractPersonRepositoryTest { } 11 | -------------------------------------------------------------------------------- /spring-data-gremlin-tinker/src/test/java/org/springframework/data/gremlin/object/tests/tinker/neo4j/Tinker_Neo4j_AddressRepositoryTest.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.object.tests.tinker.neo4j; 2 | 3 | import org.springframework.data.gremlin.object.neo4j.repository.AbstractAddressRepositoryTest; 4 | import org.springframework.test.context.ContextConfiguration; 5 | 6 | /** 7 | * Created by gman on 24/06/15. 8 | */ 9 | @ContextConfiguration(classes = Tinker_Neo4j_TestConfiguration.class) 10 | public class Tinker_Neo4j_AddressRepositoryTest extends AbstractAddressRepositoryTest { } 11 | -------------------------------------------------------------------------------- /spring-data-gremlin-tinker/src/test/java/org/springframework/data/gremlin/object/tests/tinker/neo4j/Tinker_Neo4j_EdgeRepositoryTest.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.object.tests.tinker.neo4j; 2 | 3 | import org.springframework.data.gremlin.object.neo4j.repository.AbstractEdgeRepositoryTest; 4 | import org.springframework.test.context.ContextConfiguration; 5 | 6 | /** 7 | * Created by gman on 24/06/15. 8 | */ 9 | @ContextConfiguration(classes = Tinker_Neo4j_TestConfiguration.class) 10 | public class Tinker_Neo4j_EdgeRepositoryTest extends AbstractEdgeRepositoryTest { } 11 | -------------------------------------------------------------------------------- /spring-data-gremlin-tinker/src/test/java/org/springframework/data/gremlin/object/tests/tinker/neo4j/Tinker_Neo4j_PersonRepositoryTest.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.object.tests.tinker.neo4j; 2 | 3 | import org.springframework.data.gremlin.object.neo4j.repository.AbstractPersonRepositoryTest; 4 | import org.springframework.test.context.ContextConfiguration; 5 | 6 | /** 7 | * Created by gman on 24/06/15. 8 | */ 9 | @ContextConfiguration(classes = Tinker_Neo4j_TestConfiguration.class) 10 | public class Tinker_Neo4j_PersonRepositoryTest extends AbstractPersonRepositoryTest { } 11 | -------------------------------------------------------------------------------- /spring-data-gremlin-titan/build.gradle: -------------------------------------------------------------------------------- 1 | dependencies { 2 | compile project(':spring-data-gremlin-core') 3 | compile('com.thinkaurelius.titan:titan-core:0.5.4') 4 | // testCompile('com.thinkaurelius.titan:titan-berkeleyje:0.5.4') 5 | testCompile project(':spring-data-gremlin-test') 6 | testCompile project(':spring-data-gremlin-schemagen-jpa') 7 | testCompile project(':spring-data-gremlin-schemagen-neo4j') 8 | } -------------------------------------------------------------------------------- /spring-data-gremlin-titan/src/main/java/org/springframework/data/gremlin/repository/titan/TitanGraphAdapter.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.repository.titan; 2 | 3 | import com.thinkaurelius.titan.core.TitanGraph; 4 | import com.tinkerpop.blueprints.Vertex; 5 | import org.slf4j.Logger; 6 | import org.slf4j.LoggerFactory; 7 | import org.springframework.data.gremlin.repository.GremlinGraphAdapter; 8 | import org.springframework.transaction.annotation.Transactional; 9 | 10 | /** 11 | * Created by gman on 27/06/15. 12 | */ 13 | public class TitanGraphAdapter extends GremlinGraphAdapter { 14 | 15 | private static final Logger LOGGER = LoggerFactory.getLogger(TitanGraphAdapter.class); 16 | 17 | @Override 18 | @Transactional(readOnly = false) 19 | public Vertex createVertex(TitanGraph graph, String className) { 20 | Vertex vertex = graph.addVertexWithLabel(className); 21 | return vertex; 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /spring-data-gremlin-titan/src/main/java/org/springframework/data/gremlin/tx/titan/TitanGremlinGraphFactory.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.tx.titan; 2 | 3 | import static org.springframework.util.Assert.notNull; 4 | 5 | import org.apache.commons.configuration.Configuration; 6 | import org.slf4j.Logger; 7 | import org.slf4j.LoggerFactory; 8 | import org.springframework.data.gremlin.tx.AbstractGremlinGraphFactory; 9 | 10 | import com.thinkaurelius.titan.core.TitanFactory; 11 | import com.thinkaurelius.titan.core.TitanGraph; 12 | 13 | /** 14 | * An {@link AbstractGremlinGraphFactory} for OrentDB providing an {@link TitanGraph} implementation of {@link com.tinkerpop.blueprints.Graph}. 15 | * 16 | * @author Gman 17 | */ 18 | public class TitanGremlinGraphFactory extends AbstractGremlinGraphFactory { 19 | 20 | private static final Logger LOGGER = LoggerFactory.getLogger(TitanGremlinGraphFactory.class); 21 | 22 | private TitanGraph graph = null; 23 | private Configuration configuration; 24 | 25 | @Override 26 | protected void createPool() { 27 | if(configuration != null){ 28 | graph = TitanFactory.open(configuration); 29 | } else { 30 | notNull(url); 31 | graph = TitanFactory.open(url); 32 | } 33 | } 34 | 35 | @Override 36 | public boolean isActive(TitanGraph graph) { 37 | return graph.getManagementSystem().isOpen(); 38 | } 39 | 40 | @Override 41 | public boolean isClosed(TitanGraph graph) { 42 | return graph.isClosed(); 43 | } 44 | 45 | @Override 46 | public void beginTx(TitanGraph graph) { 47 | graph.newTransaction(); 48 | } 49 | 50 | @Override 51 | public void commitTx(TitanGraph graph) { 52 | graph.commit(); 53 | } 54 | 55 | @Override 56 | public void rollbackTx(TitanGraph graph) { 57 | graph.rollback(); 58 | } 59 | 60 | @Override 61 | public TitanGraph openGraph() { 62 | if (graph == null || graph.isClosed()) { 63 | createPool(); 64 | } 65 | return graph; 66 | } 67 | 68 | @Override 69 | protected void createGraph() { 70 | } 71 | 72 | public Configuration getConfiguration() { 73 | return configuration; 74 | } 75 | 76 | public void setConfiguration(Configuration configuration) { 77 | this.configuration = configuration; 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /spring-data-gremlin-titan/src/test/java/org/springframework/data/gremlin/object/tests/titan/core/Titan_Core_AddressRepositoryTest.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.object.tests.titan.core; 2 | 3 | import org.springframework.data.gremlin.object.core.repository.AbstractAddressRepositoryTest; 4 | import org.springframework.test.context.ContextConfiguration; 5 | 6 | /** 7 | * Created by gman on 24/06/15. 8 | */ 9 | @ContextConfiguration(classes = Titan_Core_TestConfiguration.class) 10 | public class Titan_Core_AddressRepositoryTest extends AbstractAddressRepositoryTest { } 11 | -------------------------------------------------------------------------------- /spring-data-gremlin-titan/src/test/java/org/springframework/data/gremlin/object/tests/titan/core/Titan_Core_EdgeRepositoryTest.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.object.tests.titan.core; 2 | 3 | import org.springframework.data.gremlin.object.core.repository.AbstractEdgeRepositoryTest; 4 | import org.springframework.test.context.ContextConfiguration; 5 | 6 | /** 7 | * Created by gman on 24/06/15. 8 | */ 9 | @ContextConfiguration(classes = Titan_Core_TestConfiguration.class) 10 | public class Titan_Core_EdgeRepositoryTest extends AbstractEdgeRepositoryTest { } 11 | -------------------------------------------------------------------------------- /spring-data-gremlin-titan/src/test/java/org/springframework/data/gremlin/object/tests/titan/core/Titan_Core_PersonRepositoryTest.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.object.tests.titan.core; 2 | 3 | import org.springframework.data.gremlin.object.core.repository.AbstractPersonRepositoryTest; 4 | import org.springframework.test.context.ContextConfiguration; 5 | 6 | /** 7 | * Created by gman on 24/06/15. 8 | */ 9 | @ContextConfiguration(classes = Titan_Core_TestConfiguration.class) 10 | @SuppressWarnings("SpringJavaAutowiringInspection") 11 | public class Titan_Core_PersonRepositoryTest extends AbstractPersonRepositoryTest { 12 | 13 | // @Autowired 14 | // protected NativePersonRepository nativePersonRepository; 15 | 16 | // @Test 17 | // public void testDeleteAllExcept() throws Exception { 18 | // int count = ((NativePersonRepository)repository).deleteAllExceptUser("Lara"); 19 | // assertEquals(4, count); 20 | // 21 | // Iterable persons = repository.findAll(); 22 | // assertNotNull(persons); 23 | // Iterator iterator = persons.iterator(); 24 | // assertNotNull(iterator); 25 | // assertNotNull(iterator.next()); 26 | // assertFalse(iterator.hasNext()); 27 | // } 28 | } 29 | -------------------------------------------------------------------------------- /spring-data-gremlin-titan/src/test/java/org/springframework/data/gremlin/object/tests/titan/core/Titan_Core_TransactionRepositoryTest.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.object.tests.titan.core; 2 | 3 | import org.springframework.data.gremlin.object.core.repository.AbstractTransactionRepositoryTest; 4 | import org.springframework.test.context.ContextConfiguration; 5 | 6 | /** 7 | * Created by gman on 24/06/15. 8 | */ 9 | @ContextConfiguration(classes = Titan_Core_TestConfiguration.class) 10 | @SuppressWarnings("SpringJavaAutowiringInspection") 11 | public class Titan_Core_TransactionRepositoryTest extends AbstractTransactionRepositoryTest { 12 | 13 | } 14 | -------------------------------------------------------------------------------- /spring-data-gremlin-titan/src/test/java/org/springframework/data/gremlin/object/tests/titan/jpa/Titan_JPA_AddressRepositoryTest.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.object.tests.titan.jpa; 2 | 3 | import org.springframework.data.gremlin.object.jpa.repository.AbstractAddressRepositoryTest; 4 | import org.springframework.test.context.ContextConfiguration; 5 | 6 | /** 7 | * Created by gman on 24/06/15. 8 | */ 9 | @ContextConfiguration(classes = Titan_JPA_TestConfiguration.class) 10 | public class Titan_JPA_AddressRepositoryTest extends AbstractAddressRepositoryTest { } 11 | -------------------------------------------------------------------------------- /spring-data-gremlin-titan/src/test/java/org/springframework/data/gremlin/object/tests/titan/jpa/Titan_JPA_PersonRepositoryTest.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.object.tests.titan.jpa; 2 | 3 | import org.springframework.data.gremlin.object.jpa.repository.AbstractPersonRepositoryTest; 4 | import org.springframework.test.context.ContextConfiguration; 5 | 6 | /** 7 | * Created by gman on 24/06/15. 8 | */ 9 | @ContextConfiguration(classes = Titan_JPA_TestConfiguration.class) 10 | @SuppressWarnings("SpringJavaAutowiringInspection") 11 | public class Titan_JPA_PersonRepositoryTest extends AbstractPersonRepositoryTest { 12 | 13 | // @Autowired 14 | // protected NativePersonRepository nativePersonRepository; 15 | 16 | // @Test 17 | // public void testDeleteAllExcept() throws Exception { 18 | // int count = ((NativePersonRepository)repository).deleteAllExceptUser("Lara"); 19 | // assertEquals(4, count); 20 | // 21 | // Iterable persons = repository.findAll(); 22 | // assertNotNull(persons); 23 | // Iterator iterator = persons.iterator(); 24 | // assertNotNull(iterator); 25 | // assertNotNull(iterator.next()); 26 | // assertFalse(iterator.hasNext()); 27 | // } 28 | } 29 | -------------------------------------------------------------------------------- /spring-data-gremlin-titan/src/test/java/org/springframework/data/gremlin/object/tests/titan/jpa/Titan_JPA_TransactionRepositoryTest.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.object.tests.titan.jpa; 2 | 3 | import org.springframework.data.gremlin.object.jpa.repository.AbstractTransactionRepositoryTest; 4 | import org.springframework.test.context.ContextConfiguration; 5 | 6 | /** 7 | * Created by gman on 24/06/15. 8 | */ 9 | @ContextConfiguration(classes = Titan_JPA_TestConfiguration.class) 10 | @SuppressWarnings("SpringJavaAutowiringInspection") 11 | public class Titan_JPA_TransactionRepositoryTest extends AbstractTransactionRepositoryTest { 12 | 13 | } 14 | -------------------------------------------------------------------------------- /spring-data-gremlin-titan/src/test/java/org/springframework/data/gremlin/object/tests/titan/neo4j/Titan_Neo4j_AddressRepositoryTest.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.object.tests.titan.neo4j; 2 | 3 | import org.springframework.data.gremlin.object.neo4j.repository.AbstractAddressRepositoryTest; 4 | import org.springframework.test.context.ContextConfiguration; 5 | 6 | /** 7 | * Created by gman on 24/06/15. 8 | */ 9 | @ContextConfiguration(classes = Titan_Neo4j_TestConfiguration.class) 10 | public class Titan_Neo4j_AddressRepositoryTest extends AbstractAddressRepositoryTest { } 11 | -------------------------------------------------------------------------------- /spring-data-gremlin-titan/src/test/java/org/springframework/data/gremlin/object/tests/titan/neo4j/Titan_Neo4j_PersonRepositoryTest.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.object.tests.titan.neo4j; 2 | 3 | import org.springframework.data.gremlin.object.neo4j.repository.AbstractPersonRepositoryTest; 4 | import org.springframework.test.context.ContextConfiguration; 5 | 6 | /** 7 | * Created by gman on 24/06/15. 8 | */ 9 | @ContextConfiguration(classes = Titan_Neo4j_TestConfiguration.class) 10 | @SuppressWarnings("SpringJavaAutowiringInspection") 11 | public class Titan_Neo4j_PersonRepositoryTest extends AbstractPersonRepositoryTest { 12 | 13 | // @Autowired 14 | // protected NativePersonRepository nativePersonRepository; 15 | 16 | // @Test 17 | // public void testDeleteAllExcept() throws Exception { 18 | // int count = ((NativePersonRepository)repository).deleteAllExceptUser("Lara"); 19 | // assertEquals(4, count); 20 | // 21 | // Iterable persons = repository.findAll(); 22 | // assertNotNull(persons); 23 | // Iterator iterator = persons.iterator(); 24 | // assertNotNull(iterator); 25 | // assertNotNull(iterator.next()); 26 | // assertFalse(iterator.hasNext()); 27 | // } 28 | } 29 | -------------------------------------------------------------------------------- /spring-data-gremlin-titan/src/test/java/org/springframework/data/gremlin/object/tests/titan/neo4j/Titan_Neo4j_TransactionRepositoryTest.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.object.tests.titan.neo4j; 2 | 3 | import org.springframework.data.gremlin.object.neo4j.repository.AbstractTransactionRepositoryTest; 4 | import org.springframework.test.context.ContextConfiguration; 5 | 6 | /** 7 | * Created by gman on 24/06/15. 8 | */ 9 | @ContextConfiguration(classes = Titan_Neo4j_TestConfiguration.class) 10 | @SuppressWarnings("SpringJavaAutowiringInspection") 11 | public class Titan_Neo4j_TransactionRepositoryTest extends AbstractTransactionRepositoryTest { 12 | 13 | } 14 | --------------------------------------------------------------------------------