├── .editorconfig ├── .gitignore ├── .travis.yml ├── README.md ├── pom.xml ├── spring-data-gremlin-core ├── .gitignore ├── pom.xml └── 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 │ │ ├── LazyInitializationHandler.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 │ │ └── GraphUtil.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 │ └── logback.xml ├── spring-data-gremlin-janus ├── .gitignore ├── pom.xml └── src │ ├── main │ └── java │ │ └── org │ │ └── springframework │ │ └── data │ │ └── gremlin │ │ ├── repository │ │ └── janus │ │ │ ├── JanusGraphAdapter.java │ │ │ └── JanusGremlinRepository.java │ │ ├── schema │ │ └── writer │ │ │ └── janus │ │ │ └── JanusSchemaWriter.java │ │ └── tx │ │ └── janus │ │ └── JanusGremlinGraphFactory.java │ └── test │ ├── java │ └── org │ │ └── springframework │ │ └── data │ │ └── gremlin │ │ └── object │ │ └── tests │ │ └── janus │ │ ├── core │ │ ├── Janus_Core_AddressRepositoryTest.java │ │ ├── Janus_Core_EdgeRepositoryTest.java │ │ ├── Janus_Core_PersonRepositoryTest.java │ │ ├── Janus_Core_TestConfiguration.java │ │ └── Janus_Core_TransactionRepositoryTest.java │ │ ├── jpa │ │ ├── Janus_JPA_AddressRepositoryTest.java │ │ ├── Janus_JPA_PersonRepositoryTest.java │ │ ├── Janus_JPA_TestConfiguration.java │ │ └── Janus_JPA_TransactionRepositoryTest.java │ │ └── neo4j │ │ ├── Janus_Neo4j_AddressRepositoryTest.java │ │ ├── Janus_Neo4j_EdgeRepositoryTest.java │ │ ├── Janus_Neo4j_LazyLoadTest.java │ │ ├── Janus_Neo4j_PersonRepositoryTest.java │ │ ├── Janus_Neo4j_TestConfiguration.java │ │ └── Janus_Neo4j_TransactionRepositoryTest.java │ └── resources │ └── logback.xml ├── spring-data-gremlin-orientdb ├── .gitignore ├── pom.xml └── 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 │ └── resources │ └── logback.xml ├── spring-data-gremlin-schemagen-jpa ├── .gitignore ├── pom.xml └── 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 ├── .gitignore ├── pom.xml └── src │ └── main │ └── java │ └── org │ └── springframework │ └── data │ └── gremlin │ └── schema │ └── generator │ └── Neo4jSchemaGenerator.java ├── spring-data-gremlin-test ├── .gitignore ├── pom.xml └── src │ └── main │ └── java │ └── org │ └── springframework │ └── data │ └── gremlin │ ├── object │ ├── core │ │ ├── TestService.java │ │ ├── domain │ │ │ ├── Address.java │ │ │ ├── Animal.java │ │ │ ├── Area.java │ │ │ ├── Bipod.java │ │ │ ├── Country.java │ │ │ ├── ExtendedPerson.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 │ │ ├── A.java │ │ ├── Address.java │ │ ├── Area.java │ │ ├── B.java │ │ ├── C.java │ │ ├── D.java │ │ ├── Employee.java │ │ ├── ExtendedPerson.java │ │ ├── House.java │ │ ├── Likes.java │ │ ├── Located.java │ │ ├── Location.java │ │ ├── Person.java │ │ └── Pet.java │ │ └── repository │ │ ├── ARepository.java │ │ ├── AbstractAddressRepositoryTest.java │ │ ├── AbstractEdgeRepositoryTest.java │ │ ├── AbstractLocationRepositoryTest.java │ │ ├── AbstractPersonRepositoryTest.java │ │ ├── AbstractTransactionRepositoryTest.java │ │ ├── AddressRepository.java │ │ ├── BRepository.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 ├── .gitignore ├── pom.xml └── 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 └── resources └── logback.xml /.editorconfig: -------------------------------------------------------------------------------- 1 | # EditorConfig helps developers define and maintain consistent 2 | # coding styles between different editors and IDEs 3 | # editorconfig.org 4 | 5 | root = true 6 | 7 | [*] 8 | # Change these settings to your own preference 9 | indent_style = space 10 | indent_size = 4 11 | 12 | # We recommend you to keep these unchanged 13 | end_of_line = lf 14 | charset = utf-8 15 | trim_trailing_whitespace = true 16 | insert_final_newline = true 17 | 18 | [*.md] 19 | trim_trailing_whitespace = false 20 | 21 | [*.xml] 22 | indent_size = 2 23 | 24 | [*.html] 25 | indent_size = 2 26 | 27 | [*.raml] 28 | indent_size = 2 29 | indent_style = space 30 | 31 | [*.yaml] 32 | indent_size = 2 33 | indent_style = space 34 | 35 | [*.json] 36 | indent_size = 2 37 | 38 | [*.js] 39 | indent_size = 2 40 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | .idea/ 3 | .gradle/ 4 | *.iml 5 | 6 | # For Eclipse 7 | .settings/ 8 | .classpath 9 | .factorypath 10 | .project 11 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: java 2 | -------------------------------------------------------------------------------- /spring-data-gremlin-core/.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | target 3 | -------------------------------------------------------------------------------- /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 | 4 | import org.apache.tinkerpop.gremlin.structure.Direction; 5 | 6 | import java.lang.annotation.ElementType; 7 | import java.lang.annotation.Retention; 8 | import java.lang.annotation.RetentionPolicy; 9 | import java.lang.annotation.Target; 10 | 11 | /** 12 | * Created by gman on 12/08/15. 13 | */ 14 | @Retention(RetentionPolicy.RUNTIME) 15 | @Target({ ElementType.METHOD, ElementType.FIELD }) 16 | public @interface Link { 17 | 18 | String value() default ""; 19 | 20 | String name() default ""; 21 | 22 | Direction direction() default Direction.OUT; 23 | } 24 | -------------------------------------------------------------------------------- /spring-data-gremlin-core/src/main/java/org/springframework/data/gremlin/annotation/LinkVia.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.annotation; 2 | 3 | 4 | import org.apache.tinkerpop.gremlin.structure.Direction; 5 | 6 | import java.lang.annotation.ElementType; 7 | import java.lang.annotation.Retention; 8 | import java.lang.annotation.RetentionPolicy; 9 | import java.lang.annotation.Target; 10 | 11 | /** 12 | * Created by gman on 12/08/15. 13 | */ 14 | @Retention(RetentionPolicy.RUNTIME) 15 | @Target({ ElementType.METHOD, ElementType.FIELD }) 16 | public @interface LinkVia { 17 | 18 | String value() default ""; 19 | 20 | String name() default ""; 21 | 22 | Direction direction() default Direction.OUT; 23 | } 24 | -------------------------------------------------------------------------------- /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 | @Override 17 | public String getRepositoryFactoryBeanClassName() { 18 | return GremlinRepositoryFactoryBean.class.getName(); 19 | } 20 | 21 | /* (non-Javadoc) 22 | * @see org.springframework.data.repository.config.RepositoryConfigurationExtensionSupport#getModulePrefix() 23 | */ 24 | @Override 25 | protected String getModulePrefix() { 26 | return "gremlin"; 27 | } 28 | 29 | 30 | } 31 | -------------------------------------------------------------------------------- /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 | 27 | this.dbf = dbf; 28 | this.method = method; 29 | this.schemaFactory = schemaFactory; 30 | this.graphAdapter = graphAdapter; 31 | this.query = query; 32 | this.countQuery = method.hasAnnotatedQuery() && method.getQueryAnnotation().count(); 33 | this.modifyingQuery = method.hasAnnotatedQuery() && method.getQueryAnnotation().modify(); 34 | } 35 | 36 | public GremlinGraphFactory getDbf() { 37 | return dbf; 38 | } 39 | 40 | public GremlinQueryMethod getMethod() { 41 | return method; 42 | } 43 | 44 | public GremlinSchemaFactory getSchemaFactory() { 45 | return schemaFactory; 46 | } 47 | 48 | public GremlinGraphAdapter getGraphAdapter() { 49 | return graphAdapter; 50 | } 51 | 52 | public String getQuery() { 53 | return query; 54 | } 55 | 56 | @Override 57 | protected boolean isCountQuery() { 58 | return countQuery; 59 | } 60 | 61 | @Override 62 | protected boolean isModifyingQuery() { 63 | return modifyingQuery; 64 | } 65 | 66 | } 67 | -------------------------------------------------------------------------------- /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.projection.ProjectionFactory; 6 | import org.springframework.data.repository.core.RepositoryMetadata; 7 | import org.springframework.data.repository.query.QueryMethod; 8 | import org.springframework.util.StringUtils; 9 | 10 | import java.lang.reflect.Method; 11 | 12 | /** 13 | * Gremlin specific extension of {@link QueryMethod} providing the {@link Method} and {@link Query} annotaiton. 14 | * 15 | * @author Gman 16 | */ 17 | public final class GremlinQueryMethod extends QueryMethod { 18 | 19 | /** The method. */ 20 | private final Method method; 21 | 22 | /** 23 | * Instantiates a new {@link GremlinQueryMethod}. 24 | * 25 | * @param method the method 26 | * @param metadata the metadata 27 | */ 28 | public GremlinQueryMethod(Method method, RepositoryMetadata metadata, ProjectionFactory projectionFactory) { 29 | super(method, metadata, projectionFactory); 30 | this.method = method; 31 | } 32 | 33 | /** 34 | * Gets the target method. 35 | * 36 | * @return the method 37 | */ 38 | public Method getMethod() { 39 | return method; 40 | } 41 | 42 | /** 43 | * Returns whether the method has an annotated query. 44 | * 45 | * @return 46 | */ 47 | public boolean hasAnnotatedQuery() { 48 | return getAnnotatedQuery() != null; 49 | } 50 | 51 | /** 52 | * Returns the query string declared in a {@link Query} annotation or {@literal null} if neither the annotation found 53 | * nor the attribute was specified. 54 | * 55 | * @return the query 56 | */ 57 | String getAnnotatedQuery() { 58 | String query = (String) AnnotationUtils.getValue(getQueryAnnotation()); 59 | return StringUtils.hasText(query) ? query : null; 60 | } 61 | 62 | /** 63 | * Returns the {@link Query} annotation that is applied to the method or {@code null} if none available. 64 | * 65 | * @return 66 | */ 67 | Query getQueryAnnotation() { 68 | return method.getAnnotation(Query.class); 69 | } 70 | 71 | } 72 | -------------------------------------------------------------------------------- /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 org.apache.tinkerpop.gremlin.structure.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.Iterator; 12 | import java.util.Map; 13 | 14 | /** 15 | * Executes the query to return a Map of properties. 16 | * 17 | * @author Gman 18 | */ 19 | @SuppressWarnings("unchecked") 20 | public class CompositeExecution extends AbstractGremlinExecution { 21 | 22 | /** 23 | * Instantiates a new {@link CountExecution}. 24 | */ 25 | public CompositeExecution(GremlinSchemaFactory schemaFactory, DefaultParameters parameters, GremlinGraphAdapter graphAdapter) { 26 | super(schemaFactory, parameters, graphAdapter); 27 | } 28 | 29 | @Override 30 | protected Object doExecute(AbstractGremlinQuery query, Object[] values) { 31 | 32 | Iterator result = ((Iterable) query.runQuery(parameters, values)).iterator(); 33 | Vertex vertex = result.next(); 34 | if (vertex == null) { 35 | return null; 36 | } 37 | if (result.hasNext()) { 38 | throw new IllegalArgumentException("The query resulted in multiple Vertices. Expected only one result for this Execution."); 39 | } 40 | 41 | Map map = elementToMap(vertex); 42 | 43 | Class mappedType = query.getQueryMethod().getReturnedObjectType(); 44 | GremlinSchema mapper = schemaFactory.getSchema(mappedType); 45 | Object entity = mapper.loadFromGraph(graphAdapter, vertex); 46 | 47 | return new CompositeResult(entity, map); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /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 org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal; 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 | /** 10 | * Executes the query to return the sum of entities. 11 | * 12 | * @author Gman 13 | */ 14 | @SuppressWarnings("unchecked") 15 | public class CountExecution extends AbstractGremlinExecution { 16 | 17 | /** 18 | * Instantiates a new {@link org.springframework.data.gremlin.query.execution.CountExecution}. 19 | */ 20 | public CountExecution(GremlinSchemaFactory schemaFactory, DefaultParameters parameters, GremlinGraphAdapter graphAdapter) { 21 | super(schemaFactory, parameters, graphAdapter); 22 | } 23 | 24 | /* (non-Javadoc) 25 | * @see org.springframework.data.orient.repository.object.query.OrientQueryExecution#doExecute(org.springframework.data.orient.repository.object.query.AbstractOrientQuery, java.lang.Object[]) 26 | */ 27 | @Override 28 | protected Object doExecute(AbstractGremlinQuery query, Object[] values) { 29 | return ((GraphTraversal) query.runQuery(parameters, values, true)).count().next(); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /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 org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal; 4 | import org.apache.tinkerpop.gremlin.structure.Vertex; 5 | import org.springframework.data.gremlin.query.AbstractGremlinQuery; 6 | import org.springframework.data.gremlin.repository.GremlinGraphAdapter; 7 | import org.springframework.data.gremlin.schema.GremlinSchemaFactory; 8 | import org.springframework.data.repository.query.DefaultParameters; 9 | 10 | import java.util.List; 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 | List result = ((GraphTraversal) query.runQuery(parameters, values)).toList(); 32 | if (result.size() > 1) { 33 | throw new IllegalArgumentException("The query resulted in multiple Vertices. Expected only one result for this Execution."); 34 | } 35 | else if (result.size() == 1) { 36 | Vertex vertex = result.get(0); 37 | if (vertex == null) { 38 | return null; 39 | } 40 | Map map = elementToMap(vertex); 41 | return map; 42 | } 43 | else { 44 | return null; 45 | } 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /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 org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal; 4 | import org.apache.tinkerpop.gremlin.structure.Vertex; 5 | import org.springframework.data.gremlin.query.AbstractGremlinQuery; 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.List; 12 | import java.util.Map; 13 | 14 | /** 15 | * Executes the query to return a single entity. 16 | * 17 | * @author Gman 18 | */ 19 | @SuppressWarnings("unchecked") 20 | public class SingleEntityExecution extends AbstractGremlinExecution { 21 | 22 | /** 23 | * Instantiates a new {@link CountExecution}. 24 | */ 25 | public SingleEntityExecution(GremlinSchemaFactory schemaFactory, DefaultParameters parameters, GremlinGraphAdapter graphAdapter) { 26 | super(schemaFactory, parameters, graphAdapter); 27 | } 28 | 29 | @Override 30 | protected Object doExecute(AbstractGremlinQuery query, Object[] values) { 31 | Class mappedType = query.getQueryMethod().getReturnedObjectType(); 32 | 33 | List vertices = ((GraphTraversal)query.runQuery(parameters, values)).toList(); 34 | Vertex vertex; 35 | if (vertices.size() > 1) { 36 | throw new IllegalArgumentException("The query resulted in multiple Vertices. Expected only one result for this Execution."); 37 | } 38 | else if(vertices.size() == 1) { 39 | vertex = vertices.get(0); 40 | } 41 | else { 42 | return null; 43 | } 44 | 45 | if (mappedType.isAssignableFrom(Map.class)) { 46 | 47 | Map map = elementToMap(vertex); 48 | return map; 49 | } else { 50 | GremlinSchema mapper = schemaFactory.getSchema(mappedType); 51 | return mapper.loadFromGraph(graphAdapter, vertex); 52 | 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /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 org.apache.tinkerpop.gremlin.structure.Direction; 4 | import org.springframework.data.gremlin.schema.property.GremlinAdjacentProperty; 5 | import org.springframework.data.gremlin.schema.property.GremlinProperty; 6 | import org.springframework.data.gremlin.schema.property.accessor.GremlinFieldPropertyAccessor; 7 | 8 | 9 | /** 10 | *

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

14 | *

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

17 | * 18 | * @author Gman 19 | */ 20 | public class GremlinEdgeSchema extends GremlinSchema { 21 | 22 | public GremlinEdgeSchema(Class classType, GremlinSchema superSchema) { 23 | super(classType, superSchema); 24 | } 25 | 26 | private GremlinAdjacentProperty outProperty; 27 | private GremlinAdjacentProperty inProperty; 28 | 29 | public void addProperty(GremlinProperty property) { 30 | super.addProperty(property); 31 | if (property instanceof GremlinAdjacentProperty) { 32 | GremlinAdjacentProperty adjacentProperty = (GremlinAdjacentProperty) property; 33 | if (adjacentProperty.getDirection() == Direction.OUT) { 34 | outProperty = adjacentProperty; 35 | } else { 36 | inProperty = adjacentProperty; 37 | } 38 | } 39 | } 40 | 41 | public GremlinAdjacentProperty getOutProperty() { 42 | return outProperty; 43 | } 44 | 45 | public GremlinAdjacentProperty getInProperty() { 46 | return inProperty; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /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 org.springframework.data.gremlin.schema.property.accessor.GremlinFieldPropertyAccessor; 4 | 5 | 6 | /** 7 | *

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

11 | *

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

14 | * 15 | * @author Gman 16 | */ 17 | public class GremlinVertexSchema extends GremlinSchema { 18 | 19 | public GremlinVertexSchema(Class classType, GremlinSchema superSchema) { 20 | super(classType, superSchema); 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /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 org.apache.tinkerpop.gremlin.structure.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 org.apache.tinkerpop.gremlin.structure.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 org.apache.tinkerpop.gremlin.structure.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 org.apache.tinkerpop.gremlin.structure.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 org.apache.tinkerpop.gremlin.structure.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 org.apache.tinkerpop.gremlin.structure.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 org.apache.tinkerpop.gremlin.structure.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 | } -------------------------------------------------------------------------------- /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/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.springframework.data.gremlin.schema.LazyInitializationHandler; 4 | 5 | import java.lang.reflect.Field; 6 | 7 | /** 8 | * A concrete {@link AbstractGremlinFieldPropertyAccessor} for basic Fields. 9 | * 10 | * @author Gman 11 | */ 12 | public class GremlinFieldPropertyAccessor extends AbstractGremlinFieldPropertyAccessor { 13 | 14 | public GremlinFieldPropertyAccessor(Field field) { 15 | super(field); 16 | } 17 | 18 | public GremlinFieldPropertyAccessor(Field field, GremlinFieldPropertyAccessor parentAccessor) { 19 | super(field, parentAccessor); 20 | } 21 | 22 | @Override 23 | public V get(Object object) { 24 | try { 25 | LazyInitializationHandler.initProxy(object); 26 | object = getEmbeddedObject(object, false); 27 | V result = null; 28 | if (object != null) { 29 | result = (V) field.get(object); 30 | } 31 | return result; 32 | } catch (IllegalAccessException e) { 33 | throw new IllegalStateException(e.getMessage(), e); 34 | } 35 | } 36 | 37 | @Override 38 | public void set(Object object, V val) { 39 | 40 | try { 41 | object = getEmbeddedObject(object, true); 42 | if (object != null) { 43 | field.set(object, val); 44 | } 45 | } catch (IllegalAccessException e) { 46 | throw new IllegalStateException(e.getMessage(), e); 47 | } 48 | } 49 | 50 | @Override 51 | public String toString() { 52 | return "GremlinFieldPropertyAccessor{" 53 | + "field=" + field 54 | + ", embeddedAccessor=" + embeddedAccessor + 55 | '}'; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /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, GremlinFieldPropertyAccessor parentAccessor) { 14 | super(field, parentAccessor); 15 | } 16 | 17 | @Override 18 | public byte[] get(Object object) { 19 | 20 | try { 21 | Object result = field.get(getEmbeddedObject(object, false)); 22 | 23 | if (result == null) { 24 | return null; 25 | } 26 | 27 | return toArray(result); 28 | } catch (IllegalAccessException | IOException e) { 29 | throw new IllegalStateException(e.getMessage(), e); 30 | } 31 | } 32 | 33 | @Override 34 | public void set(Object object, byte[] serialized) { 35 | try { 36 | object = getEmbeddedObject(object, true); 37 | if (serialized == null) { 38 | field.set(object, serialized); 39 | return; 40 | } 41 | 42 | field.set(object, fromArray(serialized)); 43 | 44 | } catch (IllegalAccessException | IOException | ClassNotFoundException e) { 45 | throw new IllegalStateException(e.getMessage(), e); 46 | } 47 | } 48 | 49 | private Object fromArray(byte[] bytes) throws IOException, ClassNotFoundException { 50 | ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(bytes)); 51 | Object obj = ois.readObject(); 52 | ois.close(); 53 | return obj; 54 | } 55 | 56 | private byte[] toArray(Object serializable) throws IOException { 57 | 58 | ByteArrayOutputStream out = new ByteArrayOutputStream(); 59 | ObjectOutputStream oos = new ObjectOutputStream(out); 60 | oos.writeObject(serializable); 61 | oos.close(); 62 | 63 | return out.toByteArray(); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /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 org.apache.tinkerpop.gremlin.structure.Direction; 4 | import org.apache.tinkerpop.gremlin.structure.Edge; 5 | import org.apache.tinkerpop.gremlin.structure.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.Iterator; 12 | import java.util.Map; 13 | 14 | /** 15 | * A {@link GremlinPropertyMapper} for mapping {@link GremlinAdjacentProperty}s. 16 | * 17 | * @author Gman 18 | */ 19 | public class GremlinAdjacentPropertyMapper implements GremlinPropertyMapper { 20 | private static final Logger LOGGER = LoggerFactory.getLogger(GremlinAdjacentPropertyMapper.class); 21 | @Override 22 | public void copyToVertex(final GremlinAdjacentProperty property, final GremlinGraphAdapter graphAdapter, final Edge edge, final Object val, final Map cascadingSchemas) { 23 | 24 | Iterator vertices = edge.vertices(property.getDirection()); 25 | Vertex linkedVertex = vertices.hasNext() ? vertices.next() : null; 26 | 27 | if (linkedVertex == null) { 28 | linkedVertex = (Vertex) cascadingSchemas.get(val); 29 | } 30 | 31 | if (linkedVertex != null && (Boolean.getBoolean(CASCADE_ALL_KEY) || property.getDirection() == Direction.OUT)) { 32 | // Updates or saves the val into the linkedVertex 33 | property.getRelatedSchema().cascadeCopyToGraph(graphAdapter, linkedVertex, val, cascadingSchemas); 34 | } 35 | } 36 | 37 | @Override 38 | public Object loadFromVertex(final GremlinAdjacentProperty property, final GremlinGraphAdapter graphAdapter, final Edge edge, final Map cascadingSchemas) { 39 | Object val = null; 40 | Vertex linkedVertex = edge.vertices(property.getDirection()).next(); 41 | if (linkedVertex != null) { 42 | //TODO fix empty map at the end 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 | 4 | import org.apache.tinkerpop.gremlin.structure.Element; 5 | import org.springframework.data.gremlin.repository.GremlinGraphAdapter; 6 | import org.springframework.data.gremlin.schema.property.GremlinProperty; 7 | import org.springframework.data.gremlin.schema.property.encoder.GremlinPropertyEncoder; 8 | 9 | import java.util.Map; 10 | 11 | /** 12 | * An extended {@link GremlinStandardPropertyMapper} for mapping custom encoded properties. 13 | * 14 | * @author Gman 15 | */ 16 | public class GremlinEncodedPropertyMapper extends GremlinStandardPropertyMapper { 17 | 18 | private GremlinPropertyEncoder propertyEncoder; 19 | 20 | public GremlinEncodedPropertyMapper() { 21 | } 22 | 23 | public GremlinEncodedPropertyMapper(GremlinPropertyEncoder propertyEncoder) { 24 | this.propertyEncoder = propertyEncoder; 25 | } 26 | 27 | @Override 28 | public void copyToVertex(GremlinProperty property, GremlinGraphAdapter graphAdapter, Element element, Object val, Map cascadingSchemas) { 29 | Object id = val; 30 | if (propertyEncoder != null) { 31 | id = propertyEncoder.decode(val); 32 | } 33 | super.copyToVertex(property, graphAdapter, element, id, cascadingSchemas); 34 | } 35 | 36 | @Override 37 | public Object loadFromVertex(GremlinProperty property, GremlinGraphAdapter graphAdapter, Element element, Map cascadingSchemas) { 38 | Object id = super.loadFromVertex(property, graphAdapter, element, cascadingSchemas); 39 | if (propertyEncoder != null) { 40 | id = propertyEncoder.encode(id); 41 | } 42 | return id; 43 | } 44 | 45 | 46 | } 47 | -------------------------------------------------------------------------------- /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 org.apache.tinkerpop.gremlin.structure.Element; 4 | import org.apache.tinkerpop.gremlin.structure.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 org.apache.tinkerpop.gremlin.structure.Element; 4 | import org.apache.tinkerpop.gremlin.structure.Property; 5 | import org.apache.tinkerpop.gremlin.structure.VertexProperty; 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.GremlinProperty; 10 | import org.springframework.data.gremlin.schema.property.accessor.GremlinFieldPropertyAccessor; 11 | 12 | import java.util.Iterator; 13 | import java.util.Map; 14 | 15 | /** 16 | * A concrete {@link GremlinPropertyMapper} for mapping stadard Java types to Vertex properties. 17 | * 18 | * @author Gman 19 | */ 20 | public class GremlinStandardPropertyMapper implements GremlinPropertyMapper { 21 | 22 | private static final Logger LOGGER = LoggerFactory.getLogger(GremlinStandardPropertyMapper.class); 23 | 24 | @Override 25 | public void copyToVertex(GremlinProperty property, GremlinGraphAdapter graphAdapter, Element element, Object val, Map cascadingSchemas) { 26 | LOGGER.debug("Mapping property: " + property.getName() + " to element: " + element); 27 | element.property(property.getName(), val); 28 | } 29 | 30 | @Override 31 | public Object loadFromVertex(GremlinProperty property, GremlinGraphAdapter graphAdapter, Element element, Map cascadingSchemas) { 32 | if (element.property(property.getName()).isPresent()) { 33 | return element.value(property.getName()); 34 | } 35 | else { 36 | return null; 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /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 | protected GremlinRepositoryFactoryBean(Class repositoryInterface) { 24 | super(repositoryInterface) ; 25 | } 26 | 27 | /* (non-Javadoc) 28 | * @see org.springframework.data.repository.core.support.TransactionalRepositoryFactoryBeanSupport#doCreateRepositoryFactory() 29 | */ 30 | @Override 31 | protected RepositoryFactorySupport doCreateRepositoryFactory() { 32 | return new GremlinRepositoryFactory(context); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /spring-data-gremlin-core/src/main/java/org/springframework/data/gremlin/tx/GremlinGraphFactory.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.tx; 2 | 3 | import org.apache.tinkerpop.gremlin.structure.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 org.apache.tinkerpop.gremlin.structure.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/main/java/org/springframework/data/gremlin/utils/GraphUtil.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.utils; 2 | 3 | import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal; 4 | import org.apache.tinkerpop.gremlin.structure.Graph; 5 | 6 | /** 7 | * Created by mmichail (zifnab87) on 4/14/2017. 8 | */ 9 | public class GraphUtil { 10 | 11 | public static String queryToString(Graph graph, GraphTraversal traversal) { 12 | if (traversal == null) { 13 | return ""; 14 | } 15 | return org.apache.tinkerpop.gremlin.groovy.jsr223.GroovyTranslator.of(graph.toString()).translate((traversal.asAdmin().clone()).getBytecode()); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /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 org.apache.tinkerpop.gremlin.structure.Direction; 4 | import org.apache.tinkerpop.gremlin.structure.Edge; 5 | import org.apache.tinkerpop.gremlin.structure.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.edges(Direction.OUT, "test")).thenReturn(new HashSet().iterator()); 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-core/src/test/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 7 | %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /spring-data-gremlin-janus/.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | target 3 | -------------------------------------------------------------------------------- /spring-data-gremlin-janus/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | 8 | com.github.jespersm.spring-data-gremlin 9 | spring-data-gremlin 10 | 1.0.0-SNAPSHOT 11 | 12 | 13 | spring-data-gremlin-janus 14 | 15 | 16 | 17 | com.github.jespersm.spring-data-gremlin 18 | spring-data-gremlin-core 19 | 20 | 21 | org.janusgraph 22 | janusgraph-core 23 | 0.3.1 24 | 25 | 26 | com.github.jespersm.spring-data-gremlin 27 | spring-data-gremlin-test 28 | test 29 | 30 | 31 | com.github.jespersm.spring-data-gremlin 32 | spring-data-gremlin-schemagen-neo4j 33 | test 34 | 35 | 36 | com.github.jespersm.spring-data-gremlin 37 | spring-data-gremlin-schemagen-jpa 38 | test 39 | 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /spring-data-gremlin-janus/src/main/java/org/springframework/data/gremlin/repository/janus/JanusGraphAdapter.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.repository.janus; 2 | 3 | import org.apache.tinkerpop.gremlin.structure.Vertex; 4 | import org.janusgraph.core.JanusGraph; 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 mmichail (zifnab87) on 13/04/17 based on gman's titan files. 12 | */ 13 | public class JanusGraphAdapter extends GremlinGraphAdapter { 14 | 15 | private static final Logger LOGGER = LoggerFactory.getLogger(JanusGraphAdapter.class); 16 | 17 | @Override 18 | @Transactional(readOnly = false) 19 | public Vertex createVertex(JanusGraph graph, String className) { 20 | Vertex vertex = graph.addVertex(className); 21 | return vertex; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /spring-data-gremlin-janus/src/main/java/org/springframework/data/gremlin/tx/janus/JanusGremlinGraphFactory.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.tx.janus; 2 | 3 | import org.apache.commons.configuration.Configuration; 4 | import org.janusgraph.core.JanusGraph; 5 | import org.janusgraph.core.JanusGraphFactory; 6 | import org.slf4j.Logger; 7 | import org.slf4j.LoggerFactory; 8 | import org.springframework.data.gremlin.tx.AbstractGremlinGraphFactory; 9 | 10 | import static org.springframework.util.Assert.notNull; 11 | 12 | /** 13 | * An {@link AbstractGremlinGraphFactory} for OrentDB providing an {@link JanusGraph} implementation of {@link org.apache.tinkerpop.gremlin.structure.Graph}. 14 | * 15 | * @author Gman 16 | */ 17 | public class JanusGremlinGraphFactory extends AbstractGremlinGraphFactory { 18 | 19 | private static final Logger LOGGER = LoggerFactory.getLogger(JanusGremlinGraphFactory.class); 20 | 21 | private JanusGraph graph = null; 22 | private Configuration configuration; 23 | 24 | @Override 25 | protected void createPool() { 26 | if (configuration != null) { 27 | graph = JanusGraphFactory.open(configuration); 28 | } else { 29 | notNull(url); 30 | graph = JanusGraphFactory.open(url); 31 | 32 | } 33 | } 34 | 35 | @Override 36 | public boolean isActive(JanusGraph graph) { 37 | return graph.isOpen(); 38 | } 39 | 40 | @Override 41 | public boolean isClosed(JanusGraph graph) { 42 | return graph.isClosed(); 43 | } 44 | 45 | @Override 46 | public void beginTx(JanusGraph graph) { 47 | graph.newTransaction(); 48 | } 49 | 50 | @Override 51 | public void commitTx(JanusGraph graph) { 52 | graph.tx().commit(); 53 | } 54 | 55 | @Override 56 | public void rollbackTx(JanusGraph graph) { 57 | graph.tx().rollback(); 58 | } 59 | 60 | @Override 61 | public JanusGraph 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-janus/src/test/java/org/springframework/data/gremlin/object/tests/janus/core/Janus_Core_AddressRepositoryTest.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.object.tests.janus.core; 2 | 3 | import org.springframework.data.gremlin.object.core.repository.AbstractAddressRepositoryTest; 4 | import org.springframework.test.context.ContextConfiguration; 5 | 6 | /** 7 | * Created by mmichail (zifnab87) on 13/04/17 based on gman's titan files. 8 | */ 9 | @ContextConfiguration(classes = Janus_Core_TestConfiguration.class) 10 | public class Janus_Core_AddressRepositoryTest extends AbstractAddressRepositoryTest { } 11 | -------------------------------------------------------------------------------- /spring-data-gremlin-janus/src/test/java/org/springframework/data/gremlin/object/tests/janus/core/Janus_Core_EdgeRepositoryTest.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.object.tests.janus.core; 2 | 3 | import org.springframework.data.gremlin.object.core.repository.AbstractEdgeRepositoryTest; 4 | import org.springframework.test.context.ContextConfiguration; 5 | 6 | /** 7 | * Created by mmichail (zifnab87) on 13/04/17 based on gman's titan files. 8 | */ 9 | @ContextConfiguration(classes = Janus_Core_TestConfiguration.class) 10 | public class Janus_Core_EdgeRepositoryTest extends AbstractEdgeRepositoryTest { } 11 | -------------------------------------------------------------------------------- /spring-data-gremlin-janus/src/test/java/org/springframework/data/gremlin/object/tests/janus/core/Janus_Core_PersonRepositoryTest.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.object.tests.janus.core; 2 | 3 | import org.springframework.data.gremlin.object.core.repository.AbstractPersonRepositoryTest; 4 | import org.springframework.test.context.ContextConfiguration; 5 | 6 | /** 7 | * Created by mmichail (zifnab87) on 13/04/17 based on gman's titan files. 8 | */ 9 | @ContextConfiguration(classes = Janus_Core_TestConfiguration.class) 10 | @SuppressWarnings("SpringJavaAutowiringInspection") 11 | public class Janus_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-janus/src/test/java/org/springframework/data/gremlin/object/tests/janus/core/Janus_Core_TransactionRepositoryTest.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.object.tests.janus.core; 2 | 3 | import org.springframework.data.gremlin.object.core.repository.AbstractTransactionRepositoryTest; 4 | import org.springframework.test.context.ContextConfiguration; 5 | 6 | /** 7 | * Created by mmichail (zifnab87) on 13/04/17 based on gman's titan files. 8 | */ 9 | @ContextConfiguration(classes = Janus_Core_TestConfiguration.class) 10 | @SuppressWarnings("SpringJavaAutowiringInspection") 11 | public class Janus_Core_TransactionRepositoryTest extends AbstractTransactionRepositoryTest { 12 | 13 | } 14 | -------------------------------------------------------------------------------- /spring-data-gremlin-janus/src/test/java/org/springframework/data/gremlin/object/tests/janus/jpa/Janus_JPA_AddressRepositoryTest.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.object.tests.janus.jpa; 2 | 3 | import org.springframework.data.gremlin.object.jpa.repository.AbstractAddressRepositoryTest; 4 | import org.springframework.test.context.ContextConfiguration; 5 | 6 | /** 7 | * Created by mmichail (zifnab87) on 13/04/17 based on gman's titan files. 8 | */ 9 | @ContextConfiguration(classes = Janus_JPA_TestConfiguration.class) 10 | public class Janus_JPA_AddressRepositoryTest extends AbstractAddressRepositoryTest { } 11 | -------------------------------------------------------------------------------- /spring-data-gremlin-janus/src/test/java/org/springframework/data/gremlin/object/tests/janus/jpa/Janus_JPA_PersonRepositoryTest.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.object.tests.janus.jpa; 2 | 3 | import org.springframework.data.gremlin.object.jpa.repository.AbstractPersonRepositoryTest; 4 | import org.springframework.test.context.ContextConfiguration; 5 | 6 | /** 7 | * Created by mmichail (zifnab87) on 13/04/17 based on gman's titan files. 8 | */ 9 | @ContextConfiguration(classes = Janus_JPA_TestConfiguration.class) 10 | @SuppressWarnings("SpringJavaAutowiringInspection") 11 | public class Janus_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-janus/src/test/java/org/springframework/data/gremlin/object/tests/janus/jpa/Janus_JPA_TransactionRepositoryTest.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.object.tests.janus.jpa; 2 | 3 | import org.springframework.data.gremlin.object.jpa.repository.AbstractTransactionRepositoryTest; 4 | import org.springframework.test.context.ContextConfiguration; 5 | 6 | /** 7 | * Created by mmichail (zifnab87) on 13/04/17 based on gman's titan files. 8 | */ 9 | 10 | @ContextConfiguration(classes = Janus_JPA_TestConfiguration.class) 11 | @SuppressWarnings("SpringJavaAutowiringInspection") 12 | public class Janus_JPA_TransactionRepositoryTest extends AbstractTransactionRepositoryTest { 13 | 14 | } 15 | -------------------------------------------------------------------------------- /spring-data-gremlin-janus/src/test/java/org/springframework/data/gremlin/object/tests/janus/neo4j/Janus_Neo4j_AddressRepositoryTest.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.object.tests.janus.neo4j; 2 | 3 | import org.springframework.data.gremlin.object.neo4j.repository.AbstractAddressRepositoryTest; 4 | import org.springframework.test.context.ContextConfiguration; 5 | 6 | /** 7 | * Created by mmichail (zifnab87) on 13/04/17 based on gman's titan files. 8 | */ 9 | 10 | @ContextConfiguration(classes = Janus_Neo4j_TestConfiguration.class) 11 | public class Janus_Neo4j_AddressRepositoryTest extends AbstractAddressRepositoryTest { } 12 | -------------------------------------------------------------------------------- /spring-data-gremlin-janus/src/test/java/org/springframework/data/gremlin/object/tests/janus/neo4j/Janus_Neo4j_EdgeRepositoryTest.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.object.tests.janus.neo4j; 2 | 3 | import org.springframework.data.gremlin.object.neo4j.repository.AbstractEdgeRepositoryTest; 4 | import org.springframework.test.context.ContextConfiguration; 5 | 6 | /** 7 | * Created by mmichail (zifnab87) on 4/14/2017. 8 | */ 9 | @ContextConfiguration(classes = Janus_Neo4j_TestConfiguration.class) 10 | public class Janus_Neo4j_EdgeRepositoryTest extends AbstractEdgeRepositoryTest { } 11 | -------------------------------------------------------------------------------- /spring-data-gremlin-janus/src/test/java/org/springframework/data/gremlin/object/tests/janus/neo4j/Janus_Neo4j_PersonRepositoryTest.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.object.tests.janus.neo4j; 2 | 3 | import org.springframework.data.gremlin.object.neo4j.repository.AbstractPersonRepositoryTest; 4 | import org.springframework.test.context.ContextConfiguration; 5 | 6 | /** 7 | * Created by mmichail (zifnab87) on 13/04/17 based on gman's titan files. 8 | */ 9 | 10 | @ContextConfiguration(classes = Janus_Neo4j_TestConfiguration.class) 11 | @SuppressWarnings("SpringJavaAutowiringInspection") 12 | public class Janus_Neo4j_PersonRepositoryTest extends AbstractPersonRepositoryTest { 13 | 14 | // @Autowired 15 | // protected NativePersonRepository nativePersonRepository; 16 | 17 | // @Test 18 | // public void testDeleteAllExcept() throws Exception { 19 | // int count = ((NativePersonRepository)repository).deleteAllExceptUser("Lara"); 20 | // assertEquals(4, count); 21 | // 22 | // Iterable persons = repository.findAll(); 23 | // assertNotNull(persons); 24 | // Iterator iterator = persons.iterator(); 25 | // assertNotNull(iterator); 26 | // assertNotNull(iterator.next()); 27 | // assertFalse(iterator.hasNext()); 28 | // } 29 | } 30 | -------------------------------------------------------------------------------- /spring-data-gremlin-janus/src/test/java/org/springframework/data/gremlin/object/tests/janus/neo4j/Janus_Neo4j_TransactionRepositoryTest.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.object.tests.janus.neo4j; 2 | 3 | import org.springframework.data.gremlin.object.neo4j.repository.AbstractTransactionRepositoryTest; 4 | import org.springframework.test.context.ContextConfiguration; 5 | 6 | /** 7 | * Created by mmichail (zifnab87) on 13/04/17 based on gman's titan files. 8 | */ 9 | @ContextConfiguration(classes = Janus_Neo4j_TestConfiguration.class) 10 | @SuppressWarnings("SpringJavaAutowiringInspection") 11 | public class Janus_Neo4j_TransactionRepositoryTest extends AbstractTransactionRepositoryTest { 12 | 13 | } 14 | -------------------------------------------------------------------------------- /spring-data-gremlin-janus/src/test/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 7 | %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /spring-data-gremlin-orientdb/.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | target 3 | -------------------------------------------------------------------------------- /spring-data-gremlin-orientdb/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | 8 | com.github.jespersm.spring-data-gremlin 9 | spring-data-gremlin 10 | 1.0.0-SNAPSHOT 11 | 12 | 13 | spring-data-gremlin-orientdb 14 | 15 | 16 | 3.0.0RC1 17 | 18 | 19 | 20 | 21 | com.github.jespersm.spring-data-gremlin 22 | spring-data-gremlin-core 23 | 24 | 25 | com.orientechnologies 26 | orientdb-gremlin 27 | ${orientdb.version} 28 | 29 | 30 | com.orientechnologies 31 | orientdb-lucene 32 | ${orientdb.version} 33 | test 34 | 35 | 36 | com.orientechnologies 37 | orientdb-spatial 38 | ${orientdb.version} 39 | test 40 | 41 | 42 | com.github.jespersm.spring-data-gremlin 43 | spring-data-gremlin-test 44 | test 45 | 46 | 47 | com.github.jespersm.spring-data-gremlin 48 | spring-data-gremlin-schemagen-neo4j 49 | test 50 | 51 | 52 | com.github.jespersm.spring-data-gremlin 53 | spring-data-gremlin-schemagen-jpa 54 | test 55 | 56 | 57 | 58 | 59 | 60 | -------------------------------------------------------------------------------- /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 org.apache.tinkerpop.gremlin.orientdb.OrientGraph; 4 | import org.apache.tinkerpop.gremlin.structure.Element; 5 | import org.apache.tinkerpop.gremlin.structure.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.encoder.GremlinPropertyEncoder; 10 | import org.springframework.data.gremlin.schema.property.encoder.orientdb.OrientDbIdEncoder; 11 | import org.springframework.transaction.annotation.Transactional; 12 | 13 | /** 14 | * Created by gman on 27/06/15. 15 | */ 16 | public class OrientDBGraphAdapter extends GremlinGraphAdapter { 17 | 18 | private static final Logger LOGGER = LoggerFactory.getLogger(OrientDBGraphAdapter.class); 19 | 20 | private GremlinPropertyEncoder idEncoder = new OrientDbIdEncoder(); 21 | 22 | @Override 23 | @Transactional(readOnly = false) 24 | public Vertex createVertex(OrientGraph graph, String className) { 25 | return graph.addVertex(className); 26 | } 27 | 28 | @Override 29 | public Element refresh(Element element) { 30 | //((OrientElement) element).reload(); 31 | return element; 32 | } 33 | 34 | public String encodeId(String id) { 35 | if (id == null) { 36 | return null; 37 | } 38 | if (idEncoder != null) { 39 | id = idEncoder.encode(id).toString(); 40 | } 41 | return id; 42 | } 43 | 44 | public String decodeId(String id) { 45 | if (id == null) { 46 | return null; 47 | } 48 | if (idEncoder != null) { 49 | id = idEncoder.decode(id).toString(); 50 | } 51 | return id; 52 | } 53 | 54 | @Override 55 | public boolean isValidId(String id) { 56 | return super.isValidId(id) && !id.contains("-"); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /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.data.gremlin.object.core.repository.PersonRepository; 12 | import org.springframework.test.context.ContextConfiguration; 13 | 14 | import java.util.Iterator; 15 | 16 | /** 17 | * Created by gman on 24/06/15. 18 | */ 19 | @ContextConfiguration(classes = OrientDB_Core_TestConfiguration.class) 20 | @SuppressWarnings("SpringJavaAutowiringInspection") 21 | public class OrientDB_Core_PersonRepositoryTest extends AbstractPersonRepositoryTest { 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 | Iterable persons = repository.findAll(); 30 | Assert.assertNotNull(persons); 31 | Iterator iterator = persons.iterator(); 32 | Assert.assertNotNull(iterator); 33 | Assert.assertNotNull(iterator.next()); 34 | Assert.assertFalse(iterator.hasNext()); 35 | } 36 | 37 | @Test 38 | public void findPeopleNear() throws Exception { 39 | Page page = nativePersonRepository.findNear(-33, 151, 50, new PageRequest(0, 10)); 40 | Assert.assertEquals(1, page.getTotalElements()); 41 | Person person = page.iterator().next(); 42 | Assert.assertNotNull(person); 43 | Assert.assertEquals("Graham", person.getFirstName()); 44 | Assert.assertNotNull(person.getLocations()); 45 | } 46 | 47 | @Test 48 | public void findEscapeString() throws Exception { 49 | Person person = nativePersonRepository.findOneByName("John St'"); 50 | Assert.assertNull(person); 51 | } 52 | @Test 53 | public void deleteAllEscapeString() throws Exception { 54 | int deleted = nativePersonRepository.deleteAllExceptUser("John St'"); 55 | Assert.assertNotEquals(0, deleted); 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /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-orientdb/src/test/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 7 | %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /spring-data-gremlin-schemagen-jpa/.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | target 3 | -------------------------------------------------------------------------------- /spring-data-gremlin-schemagen-jpa/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | 8 | com.github.jespersm.spring-data-gremlin 9 | spring-data-gremlin 10 | 1.0.0-SNAPSHOT 11 | 12 | 13 | spring-data-gremlin-schemagen-jpa 14 | 15 | 16 | 17 | com.github.jespersm.spring-data-gremlin 18 | spring-data-gremlin-core 19 | 20 | 21 | org.hibernate.javax.persistence 22 | hibernate-jpa-2.1-api 23 | 24 | 25 | com.github.jespersm.spring-data-gremlin 26 | spring-data-gremlin-test 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /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 | } 10 | -------------------------------------------------------------------------------- /spring-data-gremlin-schemagen-neo4j/.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | target 3 | -------------------------------------------------------------------------------- /spring-data-gremlin-schemagen-neo4j/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | 8 | com.github.jespersm.spring-data-gremlin 9 | spring-data-gremlin 10 | 1.0.0-SNAPSHOT 11 | 12 | 13 | spring-data-gremlin-schemagen-neo4j 14 | 15 | 16 | 17 | com.github.jespersm.spring-data-gremlin 18 | spring-data-gremlin-core 19 | 20 | 21 | com.github.jespersm.spring-data-gremlin 22 | spring-data-gremlin-test 23 | test 24 | 25 | 26 | org.neo4j 27 | neo4j-ogm-core 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /spring-data-gremlin-test/.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | target 3 | -------------------------------------------------------------------------------- /spring-data-gremlin-test/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | 8 | com.github.jespersm.spring-data-gremlin 9 | spring-data-gremlin 10 | 1.0.0-SNAPSHOT 11 | 12 | 13 | spring-data-gremlin-test 14 | 15 | 16 | 17 | com.github.jespersm.spring-data-gremlin 18 | spring-data-gremlin-core 19 | 20 | 21 | org.springframework 22 | spring-test 23 | 24 | 25 | junit 26 | junit 27 | 28 | 29 | org.hibernate.javax.persistence 30 | hibernate-jpa-2.1-api 31 | 32 | 33 | org.neo4j 34 | neo4j-ogm-core 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /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/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/ExtendedPerson.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.object.core.domain; 2 | 3 | import org.springframework.data.gremlin.annotation.Vertex; 4 | 5 | import java.util.Map; 6 | 7 | /** 8 | * @author Andreas Berger 9 | */ 10 | @Vertex 11 | public class ExtendedPerson extends Person { 12 | private Integer size; 13 | 14 | public ExtendedPerson() { 15 | } 16 | 17 | public ExtendedPerson(String firstName, String lastName) { 18 | super(firstName, lastName); 19 | } 20 | 21 | public ExtendedPerson(String firstName, String lastName, Address address, Boolean active) { 22 | super(firstName, lastName, address, active); 23 | } 24 | 25 | public ExtendedPerson(String firstName, String lastName, Address address, Boolean active, Map randoms) { 26 | super(firstName, lastName, address, active, randoms); 27 | } 28 | 29 | public Integer getSize() { 30 | return size; 31 | } 32 | 33 | public ExtendedPerson setSize(Integer size) { 34 | this.size = size; 35 | return this; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /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 || !(o instanceof Likes)) { 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 org.apache.tinkerpop.gremlin.structure.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.Id; 4 | import org.springframework.data.gremlin.annotation.Link; 5 | import org.springframework.data.gremlin.annotation.Vertex; 6 | 7 | /** 8 | * @author Gman 9 | * @created 19/01/2016 10 | */ 11 | @Vertex 12 | public class Meeting { 13 | 14 | @Id 15 | private String id; 16 | 17 | @Link 18 | private Person person1; 19 | 20 | @Link 21 | private Person person2; 22 | 23 | public Meeting() { 24 | } 25 | 26 | public Meeting(Person person1, Person person2) { 27 | this.person1 = person1; 28 | this.person2 = person2; 29 | } 30 | 31 | public String getId() { 32 | return id; 33 | } 34 | 35 | public void setId(String id) { 36 | this.id = id; 37 | } 38 | 39 | public Person getPerson2() { 40 | return person2; 41 | } 42 | 43 | public void setPerson2(Person person2) { 44 | this.person2 = person2; 45 | } 46 | 47 | public Person getPerson1() { 48 | return person1; 49 | } 50 | 51 | public void setPerson1(Person person1) { 52 | this.person1 = person1; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /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 abstract 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.repository.GremlinRepository; 6 | 7 | import java.util.List; 8 | 9 | /** 10 | * Created by gman on 4/06/15. 11 | */ 12 | public interface LikesRepository extends GremlinRepository { 13 | 14 | 15 | List findByPerson1_FirstName(String firstName); 16 | 17 | @Query(value = "graph.E().has('date')") 18 | List findByHasDate(); 19 | 20 | @Query(value = "graph.V().has('firstName', ?).outE('Likes').as('x').inV().has('firstName', ?).select('x')") 21 | List findByLiking(String liker, String liked); 22 | 23 | 24 | 25 | } 26 | -------------------------------------------------------------------------------- /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 | import org.springframework.data.repository.query.Param; 9 | 10 | /** 11 | * Created by gman on 25/06/15. 12 | */ 13 | public interface NativePersonRepository extends GremlinRepositoryWithNativeSupport { 14 | 15 | @Query(value = "delete vertex from (select from Person where firstName <> ?)", nativeQuery = true, modify = true) 16 | Integer deleteAllExceptUser(String firstName); 17 | 18 | 19 | @Query(value = "SELECT expand(in('was_located')) FROM (SELECT FROM Location WHERE [latitude,longitude,$spatial] NEAR [?,?,{\"maxDistance\":?}])", nativeQuery = true) 20 | Page findNear(double latitude, double longitude, double radius, Pageable pageable); 21 | @Query(value = "SELECT FROM Person WHERE name = :nameParam", nativeQuery = true) 22 | Person findOneByName(@Param("nameParam") String name); 23 | 24 | } 25 | -------------------------------------------------------------------------------- /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 abstract 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/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/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/A.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.object.neo4j.domain; 2 | 3 | import java.util.HashSet; 4 | import java.util.Set; 5 | 6 | import org.neo4j.ogm.annotation.GeneratedValue; 7 | import org.neo4j.ogm.annotation.Id; 8 | import org.neo4j.ogm.annotation.NodeEntity; 9 | import org.neo4j.ogm.annotation.Property; 10 | import org.neo4j.ogm.annotation.Relationship; 11 | 12 | @NodeEntity 13 | public class A { 14 | @Id @GeneratedValue 15 | public String id; 16 | 17 | @Property 18 | private String name; 19 | 20 | @Relationship(type = "A_B") 21 | private Set bs = new HashSet<>(); 22 | 23 | public Set getBs() { 24 | return bs; 25 | } 26 | 27 | public void setBs(Set bs) { 28 | this.bs = bs; 29 | } 30 | 31 | public String getName() { 32 | return name; 33 | } 34 | 35 | public void setName(String name) { 36 | this.name = name; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /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.ogm.annotation.GraphId; 4 | import org.neo4j.ogm.annotation.NodeEntity; 5 | import org.neo4j.ogm.annotation.Relationship; 6 | 7 | import java.util.HashSet; 8 | import java.util.Set; 9 | 10 | @NodeEntity 11 | public class Address { 12 | 13 | @GraphId 14 | private String id; 15 | 16 | private String country; 17 | 18 | private String city; 19 | 20 | private String street; 21 | 22 | @Relationship(type = "of_area") 23 | private Area area; 24 | 25 | @Relationship(type = "lives_at", direction = Relationship.INCOMING) 26 | private Set people; 27 | 28 | public Address() {} 29 | 30 | public Address(String 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 String getCountry() { 46 | return country; 47 | } 48 | 49 | public void setCountry(String 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/neo4j/domain/Area.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.object.neo4j.domain; 2 | 3 | import org.neo4j.ogm.annotation.GraphId; 4 | import org.neo4j.ogm.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/B.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.object.neo4j.domain; 2 | 3 | import java.util.HashSet; 4 | import java.util.Set; 5 | 6 | import org.neo4j.ogm.annotation.Id; 7 | import org.neo4j.ogm.annotation.NodeEntity; 8 | import org.neo4j.ogm.annotation.Property; 9 | import org.neo4j.ogm.annotation.Relationship; 10 | 11 | @NodeEntity 12 | public class B { 13 | @Id 14 | public String id; 15 | 16 | @Property 17 | private String name; 18 | 19 | @Relationship(type = "B_C") 20 | private Set cs = new HashSet<>(); 21 | 22 | public String getName() { 23 | return name; 24 | } 25 | 26 | public void setName(String name) { 27 | this.name = name; 28 | } 29 | 30 | public Set getCs() { 31 | return cs; 32 | } 33 | 34 | public void setCs(Set cs) { 35 | this.cs = cs; 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /spring-data-gremlin-test/src/main/java/org/springframework/data/gremlin/object/neo4j/domain/C.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.object.neo4j.domain; 2 | 3 | 4 | import org.neo4j.ogm.annotation.GeneratedValue; 5 | import org.neo4j.ogm.annotation.Id; 6 | import org.neo4j.ogm.annotation.NodeEntity; 7 | import org.neo4j.ogm.annotation.Property; 8 | import org.neo4j.ogm.annotation.Relationship; 9 | 10 | @NodeEntity 11 | public class C { 12 | @Id @GeneratedValue 13 | public String id; 14 | 15 | @Property 16 | private String name; 17 | 18 | @Relationship(type = "D_C", direction=Relationship.INCOMING) 19 | private D d = null; 20 | 21 | public D getD() { 22 | return d; 23 | } 24 | 25 | public void setD(D d) { 26 | this.d = d; 27 | } 28 | 29 | public String getName() { 30 | return name; 31 | } 32 | 33 | public void setName(String name) { 34 | this.name = name; 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /spring-data-gremlin-test/src/main/java/org/springframework/data/gremlin/object/neo4j/domain/D.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.object.neo4j.domain; 2 | 3 | import java.util.HashSet; 4 | import java.util.Set; 5 | 6 | import org.neo4j.ogm.annotation.GeneratedValue; 7 | import org.neo4j.ogm.annotation.Id; 8 | import org.neo4j.ogm.annotation.NodeEntity; 9 | import org.neo4j.ogm.annotation.Property; 10 | import org.neo4j.ogm.annotation.Relationship; 11 | 12 | @NodeEntity 13 | public class D { 14 | 15 | @Id @GeneratedValue 16 | public String id; 17 | 18 | @Property 19 | private String name; 20 | 21 | @Relationship(type = "D_C") 22 | private Set cs = new HashSet<>(); 23 | 24 | public String getName() { 25 | return name; 26 | } 27 | 28 | public void setName(String dName) { 29 | this.name = dName; 30 | } 31 | 32 | public Set getCs() { 33 | return cs; 34 | } 35 | 36 | public void setCs(Set cs) { 37 | this.cs = cs; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /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/ExtendedPerson.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.object.neo4j.domain; 2 | 3 | import org.neo4j.ogm.annotation.NodeEntity; 4 | 5 | /** 6 | * @author Andreas Berger 7 | */ 8 | @NodeEntity 9 | public class ExtendedPerson extends Person { 10 | 11 | 12 | private Integer size; 13 | 14 | public ExtendedPerson() { 15 | } 16 | 17 | public ExtendedPerson(String firstName, String lastName) { 18 | super(firstName, lastName); 19 | } 20 | 21 | public ExtendedPerson(String firstName, String lastName, Address address, Boolean active) { 22 | super(firstName, lastName, address, active); 23 | } 24 | 25 | public Integer getSize() { 26 | return size; 27 | } 28 | 29 | public ExtendedPerson setSize(Integer size) { 30 | this.size = size; 31 | return this; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /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.neo4j.ogm.annotation.EndNode; 4 | import org.neo4j.ogm.annotation.GraphId; 5 | import org.neo4j.ogm.annotation.RelationshipEntity; 6 | import org.neo4j.ogm.annotation.StartNode; 7 | 8 | import java.util.Date; 9 | 10 | /** 11 | * Created by gman on 16/09/15. 12 | */ 13 | @RelationshipEntity 14 | public class Likes { 15 | 16 | @GraphId 17 | private String id; 18 | 19 | private Date date = new Date(); 20 | 21 | @StartNode 22 | private Person person1; 23 | 24 | @EndNode 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 || !(o instanceof Likes)) { 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/neo4j/domain/Located.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.object.neo4j.domain; 2 | 3 | import org.neo4j.ogm.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 | @Property(name = "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.neo4j.ogm.annotation.GraphId; 5 | import org.neo4j.ogm.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/ARepository.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.object.neo4j.repository; 2 | 3 | import org.springframework.data.gremlin.object.neo4j.domain.A; 4 | import org.springframework.data.gremlin.repository.GremlinRepository; 5 | import org.springframework.stereotype.Repository; 6 | 7 | @Repository 8 | public interface ARepository extends GremlinRepository { 9 | 10 | } 11 | -------------------------------------------------------------------------------- /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 abstract 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/BRepository.java: -------------------------------------------------------------------------------- 1 | package org.springframework.data.gremlin.object.neo4j.repository; 2 | 3 | import org.springframework.data.gremlin.object.neo4j.domain.B; 4 | import org.springframework.data.gremlin.repository.GremlinRepository; 5 | import org.springframework.stereotype.Repository; 6 | 7 | @Repository 8 | public interface BRepository extends GremlinRepository { 9 | 10 | } 11 | -------------------------------------------------------------------------------- /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.List; 8 | 9 | /** 10 | * Created by gman on 4/06/15. 11 | */ 12 | public interface LikesRepository extends GremlinRepository { 13 | 14 | 15 | List findByPerson1_FirstName(String firstName); 16 | 17 | @Query(value = "graph.V().has('firstName', ?).outE('Likes').as('x').inV().has('firstName',?).select('x')") 18 | List findByLiking(String liker, String liked); 19 | 20 | } 21 | -------------------------------------------------------------------------------- /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/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/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/.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | target 3 | -------------------------------------------------------------------------------- /spring-data-gremlin-tinker/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | 8 | com.github.jespersm.spring-data-gremlin 9 | spring-data-gremlin 10 | 1.0.0-SNAPSHOT 11 | 12 | 13 | spring-data-gremlin-tinker 14 | 15 | 16 | 17 | com.github.jespersm.spring-data-gremlin 18 | spring-data-gremlin-core 19 | 20 | 21 | com.github.jespersm.spring-data-gremlin 22 | spring-data-gremlin-test 23 | test 24 | 25 | 26 | com.github.jespersm.spring-data-gremlin 27 | spring-data-gremlin-schemagen-neo4j 28 | test 29 | 30 | 31 | com.github.jespersm.spring-data-gremlin 32 | spring-data-gremlin-schemagen-jpa 33 | test 34 | 35 | 36 | org.apache.tinkerpop 37 | tinkergraph-gremlin 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /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 org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraph; 4 | import org.springframework.data.gremlin.repository.GremlinGraphAdapter; 5 | 6 | /** 7 | * Created by gman on 27/06/15.. 8 | */ 9 | public class TinkerGraphAdapter extends GremlinGraphAdapter { 10 | } 11 | -------------------------------------------------------------------------------- /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 | import org.apache.commons.configuration.BaseConfiguration; 4 | import org.apache.tinkerpop.gremlin.tinkergraph.structure.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 org.apache.tinkerpop.gremlin.structure.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 | BaseConfiguration config = new BaseConfiguration(); 23 | config.setProperty("gremlin.tinkergraph.vertexIdManager", "LONG"); 24 | graph = TinkerGraph.open(config); 25 | } 26 | 27 | @Override 28 | public boolean isActive(TinkerGraph graph) { 29 | return false; 30 | } 31 | 32 | @Override 33 | public boolean isClosed(TinkerGraph graph) { 34 | return false; 35 | } 36 | 37 | @Override 38 | public void beginTx(TinkerGraph graph) { 39 | } 40 | 41 | @Override 42 | public void commitTx(TinkerGraph graph) { 43 | } 44 | 45 | @Override 46 | public void rollbackTx(TinkerGraph graph) { 47 | } 48 | 49 | @Override 50 | public TinkerGraph openGraph() { 51 | return graph; 52 | } 53 | 54 | @Override 55 | protected void createGraph() { 56 | LOGGER.warn("Cannot create database on remote connections."); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /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-tinker/src/test/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 7 | %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | --------------------------------------------------------------------------------