├── .gitignore ├── .travis.yml ├── .travis ├── codesigning.asc.enc ├── deploy.sh └── settings.xml ├── CODE_OF_CONDUCT.asciidoc ├── CONTRIBUTING.asciidoc ├── LICENSE ├── README.asciidoc ├── gremlin-objects ├── pom.xml └── src │ ├── main │ └── java │ │ └── org │ │ └── apache │ │ └── tinkerpop │ │ └── gremlin │ │ └── object │ │ ├── model │ │ ├── Alias.java │ │ ├── DefaultValue.java │ │ ├── Hidden.java │ │ ├── Object.java │ │ ├── OrderingKey.java │ │ ├── PrimaryKey.java │ │ └── PropertyValue.java │ │ ├── provider │ │ └── GraphFactory.java │ │ ├── reflect │ │ ├── Classes.java │ │ ├── Fields.java │ │ ├── Keys.java │ │ ├── Label.java │ │ ├── Parser.java │ │ ├── Primitives.java │ │ ├── Properties.java │ │ ├── Traversal.java │ │ └── UpdateBy.java │ │ ├── structure │ │ ├── Connection.java │ │ ├── Edge.java │ │ ├── EdgeGraph.java │ │ ├── Element.java │ │ ├── ElementGraph.java │ │ ├── Graph.java │ │ ├── HasFeature.java │ │ ├── ObjectGraph.java │ │ ├── Observable.java │ │ ├── SubGraph.java │ │ ├── Vertex.java │ │ └── VertexGraph.java │ │ └── traversal │ │ ├── AnyTraversal.java │ │ ├── ElementTo.java │ │ ├── ObjectQuery.java │ │ ├── Query.java │ │ ├── Selections.java │ │ ├── SubTraversal.java │ │ └── library │ │ ├── AddV.java │ │ ├── Count.java │ │ ├── Has.java │ │ ├── HasId.java │ │ ├── HasKeys.java │ │ ├── HasLabel.java │ │ ├── Id.java │ │ ├── Keys.java │ │ ├── Label.java │ │ ├── Order.java │ │ ├── Out.java │ │ ├── Page.java │ │ ├── Range.java │ │ ├── Select.java │ │ └── Values.java │ └── test │ └── java │ └── org │ └── apache │ └── tinkerpop │ └── gremlin │ └── object │ ├── ObjectGraphTest.java │ ├── edges │ ├── Created.java │ ├── Develops.java │ ├── Knows.java │ ├── Traverses.java │ └── Uses.java │ ├── graphs │ ├── Modern.java │ └── TheCrew.java │ ├── provider │ └── GraphFactoryTest.java │ ├── reflect │ ├── ClassesTest.java │ ├── FieldsTest.java │ ├── KeysTest.java │ ├── LabelTest.java │ ├── ParserTest.java │ ├── PrimitivesTest.java │ ├── PropertiesTest.java │ └── ReflectTest.java │ ├── structure │ ├── EdgeGraphTest.java │ ├── EdgeTest.java │ ├── ElementGraphTest.java │ ├── ElementTest.java │ ├── GraphTest.java │ ├── SubGraphTest.java │ ├── VertexGraphTest.java │ └── VertexTest.java │ ├── traversal │ ├── ObjectQueryTest.java │ ├── TraversalTest.java │ └── library │ │ ├── AddVTest.java │ │ ├── CountTest.java │ │ ├── HasIdTest.java │ │ ├── HasKeysTest.java │ │ ├── HasLabelTest.java │ │ ├── HasTest.java │ │ ├── IdTest.java │ │ ├── KeysTest.java │ │ ├── LabelTest.java │ │ ├── OrderTest.java │ │ ├── OutTest.java │ │ ├── RangeTest.java │ │ └── ValuesTest.java │ └── vertices │ ├── Location.java │ ├── Person.java │ └── Software.java ├── licenses └── lombok ├── pom.xml └── tinkergraph-test ├── pom.xml └── src └── test ├── java └── org │ └── apache │ └── tinkerpop │ └── gremlin │ └── tinkergraph │ └── object │ └── TinkerGraphTest.java └── resources ├── log4j-silent.properties └── log4j-test.properties /.gitignore: -------------------------------------------------------------------------------- 1 | *.log 2 | target/ 3 | *.iml 4 | .idea/ 5 | *.iws 6 | *.DS_Store 7 | *.ipr 8 | buildAll.sh 9 | build_output.txt 10 | .classpath 11 | .project 12 | .settings 13 | _bsp/ 14 | doc/out 15 | docs/*.asciidoc 16 | ext/ 17 | *$py.class 18 | __pycache__/ 19 | *.py[cdo] 20 | __version__.py 21 | .glv 22 | settings.xml 23 | tools/ 24 | [Dd]ebug/ 25 | [Rr]elease/ 26 | [Oo]bj/ 27 | *.suo 28 | *.user 29 | .vscode/ 30 | .vs/ 31 | *nupkg 32 | NuGet.Config 33 | nuget.exe 34 | pom.xml.bak 35 | pom.xml.versionsBackup 36 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: java 2 | jdk: oraclejdk8 3 | sudo: false 4 | install: 5 | - mvn --settings .travis/settings.xml install -DskipTests=true -Dgpg.skip -Dmaven.javadoc.skip=true -B -V 6 | before_install: 7 | - if [ ! -z "$GPG_SECRET_KEYS" ]; then echo $GPG_SECRET_KEYS | base64 --decode | $GPG_EXECUTABLE --import; fi 8 | - if [ ! -z "$GPG_OWNERTRUST" ]; then echo $GPG_OWNERTRUST | base64 --decode | $GPG_EXECUTABLE --import-ownertrust; fi 9 | deploy: 10 | - 11 | provider: script 12 | script: .travis/deploy.sh 13 | skip_cleanup: true 14 | on: 15 | repo: karthicks/gremlin-ogm 16 | all_branches: true 17 | jdk: oraclejdk8 18 | after_success: 19 | - bash <(curl -s https://codecov.io/bash) 20 | after_failure: 21 | - cat gremlin-objects/target/surefire-reports/*.txt 22 | cache: 23 | directories: 24 | - $HOME/.m2 25 | -------------------------------------------------------------------------------- /.travis/codesigning.asc.enc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/karthicks/gremlin-ogm/c3bb3fe4d1560094a93d28bb201895357cfd01e3/.travis/codesigning.asc.enc -------------------------------------------------------------------------------- /.travis/deploy.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # 4 | # Licensed to the Apache Software Foundation (ASF) under one 5 | # or more contributor license agreements. See the NOTICE file 6 | # distributed with this work for additional information 7 | # regarding copyright ownership. The ASF licenses this file 8 | # to you under the Apache License, Version 2.0 (the 9 | # "License"); you may not use this file except in compliance 10 | # with the License. You may obtain a copy of the License at 11 | # 12 | # http://www.apache.org/licenses/LICENSE-2.0 13 | # 14 | # Unless required by applicable law or agreed to in writing, 15 | # software distributed under the License is distributed on an 16 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | # KIND, either express or implied. See the License for the 18 | # specific language governing permissions and limitations 19 | # under the License. 20 | # 21 | 22 | if [ ! -z "$TRAVIS_TAG" ] 23 | then 24 | echo "on a tag -> set pom.xml to $TRAVIS_TAG" 25 | mvn --settings .travis/settings.xml org.codehaus.mojo:versions-maven-plugin:2.1:set -DnewVersion=$TRAVIS_TAG 1>/dev/null 2>/dev/null 26 | openssl aes-256-cbc -K $encrypted_a05ded3ed24d_key -iv $encrypted_a05ded3ed24d_iv -in .travis/codesigning.asc.enc -out .travis/codesigning.asc -d 27 | gpg --fast-import .travis/codesigning.asc 28 | rm .travis/codesigning.asc 29 | else 30 | echo "not on a tag -> keep snapshot version in pom.xml" 31 | fi 32 | 33 | mvn clean deploy --settings .travis/settings.xml -DskipTests=true -B -U 34 | -------------------------------------------------------------------------------- /.travis/settings.xml: -------------------------------------------------------------------------------- 1 | 5 | 6 | 7 | 8 | ossrh 9 | ${env.SONATYPE_USERNAME} 10 | ${env.SONATYPE_PASSWORD} 11 | 12 | 13 | 14 | 15 | ossrh 16 | 17 | true 18 | 19 | 20 | ${env.GPG_EXECUTABLE} 21 | ${env.GPG_PASSPHRASE} 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.asciidoc: -------------------------------------------------------------------------------- 1 | //// 2 | Licensed to the Apache Software Foundation (ASF) under one or more 3 | contributor license agreements. See the NOTICE file distributed with 4 | this work for additional information regarding copyright ownership. 5 | The ASF licenses this file to You under the Apache License, Version 2.0 6 | (the "License"); you may not use this file except in compliance with 7 | the License. You may obtain a copy of the License at 8 | 9 | http://www.apache.org/licenses/LICENSE-2.0 10 | 11 | Unless required by applicable law or agreed to in writing, software 12 | distributed under the License is distributed on an "AS IS" BASIS, 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | See the License for the specific language governing permissions and 15 | limitations under the License. 16 | //// 17 | === Contributor Covenant Code of Conduct 18 | 19 | ==== Our Pledge 20 | 21 | In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation. 22 | 23 | ==== Our Standards 24 | 25 | Examples of behavior that contributes to creating a positive environment include: 26 | 27 | Using welcoming and inclusive language 28 | Being respectful of differing viewpoints and experiences 29 | Gracefully accepting constructive criticism 30 | Focusing on what is best for the community 31 | Showing empathy towards other community members 32 | 33 | Examples of unacceptable behavior by participants include: 34 | 35 | The use of sexualized language or imagery and unwelcome sexual attention or advances 36 | Trolling, insulting/derogatory comments, and personal or political attacks 37 | Public or private harassment 38 | Publishing others' private information, such as a physical or electronic address, without explicit permission 39 | Other conduct which could reasonably be considered inappropriate in a professional setting 40 | 41 | ==== Our Responsibilities 42 | 43 | Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior. 44 | 45 | Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful. 46 | 47 | ==== Scope 48 | 49 | This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers. 50 | 51 | ==== Enforcement 52 | 53 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at karthick@apache.org. All complaints will be reviewed and investigated and will result in a response that is deemed necessary and appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately. 54 | 55 | Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership. 56 | 57 | ==== Attribution 58 | 59 | This Code of Conduct is adapted from the http://contributor-covenant.org/[Contributor Covenant], version 1.4, available at http://contributor-covenant.org/version/1/4. -------------------------------------------------------------------------------- /CONTRIBUTING.asciidoc: -------------------------------------------------------------------------------- 1 | //// 2 | Licensed to the Apache Software Foundation (ASF) under one or more 3 | contributor license agreements. See the NOTICE file distributed with 4 | this work for additional information regarding copyright ownership. 5 | The ASF licenses this file to You under the Apache License, Version 2.0 6 | (the "License"); you may not use this file except in compliance with 7 | the License. You may obtain a copy of the License at 8 | 9 | http://www.apache.org/licenses/LICENSE-2.0 10 | 11 | Unless required by applicable law or agreed to in writing, software 12 | distributed under the License is distributed on an "AS IS" BASIS, 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | See the License for the specific language governing permissions and 15 | limitations under the License. 16 | //// 17 | === Contributing to Gremlin OGM 18 | 19 | Contributions via GitHub pull requests are gladly accepted from their original author. By submitting any copyrighted material via pull request, email, or other means you agree to license the material under the project’s open source license and warrant that you have the legal authority to do so. -------------------------------------------------------------------------------- /gremlin-objects/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 19 | 4.0.0 20 | 21 | com.github.karthicks 22 | gremlin-ogm 23 | 3.3.1-SNAPSHOT 24 | 25 | gremlin-objects 26 | Gremlin OGM :: Gremlin Objects 27 | 28 | 29 | junit 30 | junit 31 | test 32 | 33 | 34 | org.apache.commons 35 | commons-lang3 36 | 37 | 38 | org.apache.tinkerpop 39 | gremlin-core 40 | ${tinkerpop.version} 41 | 42 | 43 | org.apache.tinkerpop 44 | gremlin-groovy 45 | ${tinkerpop.version} 46 | 47 | 48 | org.codehaus.groovy 49 | groovy 50 | 51 | 52 | 53 | 54 | org.hamcrest 55 | hamcrest-core 56 | ${hamcrest.version} 57 | test 58 | 59 | 60 | org.javatuples 61 | javatuples 62 | ${java.tuples.version} 63 | 64 | 65 | org.mockito 66 | mockito-core 67 | test 68 | 69 | 70 | org.projectlombok 71 | lombok 72 | ${lombok.version} 73 | provided 74 | 75 | 76 | javax.inject 77 | javax.inject 78 | 1 79 | 80 | 81 | org.slf4j 82 | slf4j-api 83 | ${slf4j.version} 84 | 85 | 86 | 87 | ${basedir}/target 88 | ${project.artifactId}-${project.version} 89 | 90 | 91 | org.apache.maven.plugins 92 | maven-failsafe-plugin 93 | 94 | 95 | org.apache.maven.plugins 96 | maven-jar-plugin 97 | 3.0.2 98 | 99 | 100 | 101 | test-jar 102 | 103 | 104 | 105 | 106 | 107 | org.apache.maven.plugins 108 | maven-surefire-plugin 109 | 110 | 111 | 112 | 113 | -------------------------------------------------------------------------------- /gremlin-objects/src/main/java/org/apache/tinkerpop/gremlin/object/model/Alias.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.tinkerpop.gremlin.object.model; 20 | 21 | import java.lang.annotation.ElementType; 22 | import java.lang.annotation.Retention; 23 | import java.lang.annotation.RetentionPolicy; 24 | import java.lang.annotation.Target; 25 | 26 | /** 27 | * An {@link Alias} annotation on a field is used to override the key of the corresponding property 28 | * through the {@link #key()} method. 29 | * 30 | *

31 | * When used on an {@link org.apache.tinkerpop.gremlin.object.structure.Element}, it is used to 32 | * override it's label, through the {@link #label()} method. 33 | * 34 | * @author Karthick Sankarachary (http://github.com/karthicks) 35 | */ 36 | 37 | @Target({ElementType.FIELD, ElementType.TYPE}) 38 | @Retention(RetentionPolicy.RUNTIME) 39 | public @interface Alias { 40 | 41 | String key() default ""; 42 | 43 | String label() default ""; 44 | } 45 | -------------------------------------------------------------------------------- /gremlin-objects/src/main/java/org/apache/tinkerpop/gremlin/object/model/DefaultValue.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.tinkerpop.gremlin.object.model; 20 | 21 | import java.lang.annotation.ElementType; 22 | import java.lang.annotation.Retention; 23 | import java.lang.annotation.RetentionPolicy; 24 | import java.lang.annotation.Target; 25 | 26 | /** 27 | * A field annotated with {@link DefaultValue} will inherit it's value if it has none. 28 | * 29 | *

30 | * In the following example, if the {@code name} field has no value, then when we write it, it will be set 31 | * to {@code "noname"}. 32 | * 33 | *

34 | * {@code @DefaultValue("noname") private String name; } 35 | * 36 | * @author Karthick Sankarachary (http://github.com/karthicks) 37 | */ 38 | 39 | @Target({ElementType.FIELD}) 40 | @Retention(RetentionPolicy.RUNTIME) 41 | public @interface DefaultValue { 42 | 43 | String value(); 44 | } 45 | -------------------------------------------------------------------------------- /gremlin-objects/src/main/java/org/apache/tinkerpop/gremlin/object/model/Hidden.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.tinkerpop.gremlin.object.model; 20 | 21 | import java.lang.annotation.ElementType; 22 | import java.lang.annotation.Retention; 23 | import java.lang.annotation.RetentionPolicy; 24 | import java.lang.annotation.Target; 25 | 26 | /** 27 | * The {@link Hidden} annotation on a field indicates that it does not map to any specific property 28 | * in the underlying graph element. 29 | * 30 | * @author Karthick Sankarachary (http://github.com/karthicks) 31 | */ 32 | 33 | @Target({ElementType.FIELD}) 34 | @Retention(RetentionPolicy.RUNTIME) 35 | public @interface Hidden { 36 | 37 | } 38 | -------------------------------------------------------------------------------- /gremlin-objects/src/main/java/org/apache/tinkerpop/gremlin/object/model/Object.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.tinkerpop.gremlin.object.model; 20 | 21 | import java.lang.annotation.Retention; 22 | import java.lang.annotation.RetentionPolicy; 23 | import java.lang.annotation.Target; 24 | 25 | import javax.inject.Qualifier; 26 | 27 | import static java.lang.annotation.ElementType.CONSTRUCTOR; 28 | import static java.lang.annotation.ElementType.FIELD; 29 | import static java.lang.annotation.ElementType.METHOD; 30 | import static java.lang.annotation.ElementType.PARAMETER; 31 | import static java.lang.annotation.ElementType.TYPE; 32 | 33 | /** 34 | * An {@link Object} qualifier is used to annotate an injection point, so that it can be satisfied 35 | * by an implementation of the provider's choosing. 36 | * 37 | * @author Karthick Sankarachary (http://github.com/karthicks) 38 | */ 39 | 40 | @Qualifier 41 | @Retention(RetentionPolicy.RUNTIME) 42 | @Target({FIELD, TYPE, METHOD, PARAMETER, CONSTRUCTOR}) 43 | @SuppressWarnings("PMD.TooManyStaticImports") 44 | public @interface Object { 45 | } 46 | -------------------------------------------------------------------------------- /gremlin-objects/src/main/java/org/apache/tinkerpop/gremlin/object/model/OrderingKey.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.tinkerpop.gremlin.object.model; 20 | 21 | import java.lang.annotation.ElementType; 22 | import java.lang.annotation.Retention; 23 | import java.lang.annotation.RetentionPolicy; 24 | import java.lang.annotation.Target; 25 | 26 | /** 27 | * A field annotated with {@link OrderingKey} represents a mandatory property in the underlying 28 | * graph element by which ordering occurs. 29 | * 30 | *

31 | * If the graph supports user supplied ids, then such fields will be included in the id generated 32 | * when objects are created in the graph. 33 | * 34 | *

35 | * This annotation also serves as a reminder that it's okay to order by the property that fields 36 | * annotated with {@link OrderingKey} represent. 37 | * 38 | * @author Karthick Sankarachary (http://github.com/karthicks) 39 | */ 40 | 41 | @Target({ElementType.FIELD}) 42 | @Retention(RetentionPolicy.RUNTIME) 43 | public @interface OrderingKey { 44 | 45 | } 46 | -------------------------------------------------------------------------------- /gremlin-objects/src/main/java/org/apache/tinkerpop/gremlin/object/model/PrimaryKey.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.tinkerpop.gremlin.object.model; 20 | 21 | import org.apache.tinkerpop.gremlin.object.traversal.library.HasKeys; 22 | 23 | import java.lang.annotation.ElementType; 24 | import java.lang.annotation.Retention; 25 | import java.lang.annotation.RetentionPolicy; 26 | import java.lang.annotation.Target; 27 | 28 | /** 29 | * A field annotated with {@link PrimaryKey} represents a property in the underlying graph element 30 | * by which identification should occur. Ideally, the set of fields with this annotation should be a 31 | * minimal superkey, which is both necessary and sufficient to identity the element. 32 | * 33 | *

34 | * If the graph supports user supplied ids, then such fields will be included in the id 35 | * generated when objects are created in the graph. If not, then such fields help us find objects in 36 | * the graph whose ids are unknown, through the {@link HasKeys} sub-traversal. 37 | * 38 | *

39 | * While most objects have one primary key field, they may have more than one. To facilitate 40 | * fast lookups, there must be at least one primary key field, especially if element ids are not 41 | * user supplied, in which case we may not always have those ids handy. 42 | * 43 | * @author Karthick Sankarachary (http://github.com/karthicks) 44 | */ 45 | 46 | @Target({ElementType.FIELD}) 47 | @Retention(RetentionPolicy.RUNTIME) 48 | public @interface PrimaryKey { 49 | 50 | } 51 | -------------------------------------------------------------------------------- /gremlin-objects/src/main/java/org/apache/tinkerpop/gremlin/object/model/PropertyValue.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.tinkerpop.gremlin.object.model; 20 | 21 | import java.lang.annotation.ElementType; 22 | import java.lang.annotation.Retention; 23 | import java.lang.annotation.RetentionPolicy; 24 | import java.lang.annotation.Target; 25 | 26 | /** 27 | * The {@link PropertyValue} annotation is applied on a unique field of an element class that 28 | * represents a vertex property, in case it has meta-properties of it's own. 29 | * 30 | *

31 | * Specifically, the field where that element object appears in the vertex class denotes the key 32 | * of that vertex property. And, the field annotated with {@link PropertyValue} holds the value of 33 | * that vertex property. The rest of the fields in the (vertex property) element class appear as 34 | * meta-properties tied to the vertex property. 35 | * 36 | * @author Karthick Sankarachary (http://github.com/karthicks) 37 | */ 38 | 39 | @Target({ElementType.FIELD}) 40 | @Retention(RetentionPolicy.RUNTIME) 41 | public @interface PropertyValue { 42 | 43 | } 44 | -------------------------------------------------------------------------------- /gremlin-objects/src/main/java/org/apache/tinkerpop/gremlin/object/reflect/Classes.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.tinkerpop.gremlin.object.reflect; 20 | 21 | import org.apache.tinkerpop.gremlin.object.structure.Edge; 22 | import org.apache.tinkerpop.gremlin.object.structure.Element; 23 | import org.apache.tinkerpop.gremlin.object.structure.Vertex; 24 | 25 | import java.util.ArrayList; 26 | import java.util.Collection; 27 | import java.util.Collections; 28 | import java.util.HashSet; 29 | import java.util.List; 30 | import java.util.Set; 31 | import java.util.function.Function; 32 | 33 | import lombok.SneakyThrows; 34 | 35 | /** 36 | * {@link Classes} helps you introspect classes easily. 37 | * 38 | * @author Karthick Sankarachary (http://github.com/karthicks) 39 | */ 40 | public final class Classes { 41 | 42 | private Classes() {} 43 | 44 | /** 45 | * Does the given class inherits from {@link Element}? 46 | */ 47 | public static boolean isElement(Class type) { 48 | return is(type, Element.class); 49 | } 50 | 51 | /** 52 | * Is the given object a {@link Vertex}? 53 | */ 54 | public static boolean isVertex(Object object) { 55 | return object != null && isVertex(object.getClass()); 56 | } 57 | 58 | /** 59 | * Is the given class a {@link Vertex}? 60 | */ 61 | public static boolean isVertex(Class type) { 62 | return is(type, Vertex.class); 63 | } 64 | 65 | /** 66 | * Is the given object an {@link Edge}? 67 | */ 68 | public static boolean isEdge(Object object) { 69 | return object != null && isEdge(object.getClass()); 70 | } 71 | 72 | /** 73 | * Is the given type an {@link Edge}? 74 | */ 75 | public static boolean isEdge(Class type) { 76 | return is(type, Edge.class); 77 | } 78 | 79 | /** 80 | * Is the given object a {@link List}? 81 | */ 82 | public static boolean isList(Object object) { 83 | return object != null && isList(object.getClass()); 84 | } 85 | 86 | /** 87 | * Is the given class a {@link List}? 88 | */ 89 | public static boolean isList(Class type) { 90 | return is(type, List.class); 91 | } 92 | 93 | /** 94 | * Is the given object a {@link Set}? 95 | */ 96 | public static boolean isSet(Object object) { 97 | return object != null && isSet(object.getClass()); 98 | } 99 | 100 | /** 101 | * Is the given class a {@link Set}? 102 | */ 103 | public static boolean isSet(Class type) { 104 | return is(type, Set.class); 105 | } 106 | 107 | /** 108 | * Is the given object a {@link List} or a {@link Set}? 109 | */ 110 | public static boolean isCollection(Object object) { 111 | return object != null && isCollection(object.getClass()); 112 | } 113 | 114 | /** 115 | * Is the given class a {@link List} or a {@link Set}? 116 | */ 117 | public static boolean isCollection(Class type) { 118 | return isList(type) || isSet(type); 119 | } 120 | 121 | /** 122 | * Is the given class a {@link Function}? 123 | */ 124 | public static boolean isFunctional(Class type) { 125 | return is(type, Function.class); 126 | } 127 | 128 | /** 129 | * Is the given class that of the given object? 130 | */ 131 | @SuppressWarnings({"PMD.ShortMethodName"}) 132 | public static boolean is(Class type, Object that) { 133 | return that != null && is(type, that.getClass()); 134 | } 135 | 136 | /** 137 | * Is the given object of the given class? 138 | */ 139 | @SuppressWarnings({"PMD.ShortMethodName"}) 140 | public static boolean is(Object object, Class that) { 141 | return object != null && is(object.getClass(), that); 142 | } 143 | 144 | /** 145 | * Is the type class assignable from that class? 146 | */ 147 | @SuppressWarnings({"PMD.ShortMethodName"}) 148 | public static boolean is(Class type, Class that) { 149 | return that.isAssignableFrom(type); 150 | } 151 | 152 | /** 153 | * Sort the collection, if it's a list. 154 | */ 155 | @SuppressWarnings("unchecked") 156 | public static void sortCollection(Class clazz, Collection collection) { 157 | if (isList(clazz)) { 158 | Collections.sort((List) collection); 159 | } 160 | } 161 | 162 | /** 163 | * Create a new collection of the given type. 164 | */ 165 | @SneakyThrows 166 | @SuppressWarnings("rawtypes") 167 | public static Collection newCollection(Class clazz) { 168 | if (isList(clazz)) { 169 | return new ArrayList<>(); 170 | } 171 | if (isSet(clazz)) { 172 | return new HashSet<>(); 173 | } 174 | throw Element.Exceptions.invalidCollectionType(clazz); 175 | } 176 | 177 | /** 178 | * Return the simple name of the given class. 179 | */ 180 | public static String name(Class type) { 181 | return type.getSimpleName(); 182 | } 183 | } 184 | -------------------------------------------------------------------------------- /gremlin-objects/src/main/java/org/apache/tinkerpop/gremlin/object/reflect/Label.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.tinkerpop.gremlin.object.reflect; 20 | 21 | import org.apache.commons.lang3.text.WordUtils; 22 | import org.apache.tinkerpop.gremlin.object.model.Alias; 23 | import org.apache.tinkerpop.gremlin.object.structure.Edge; 24 | import org.apache.tinkerpop.gremlin.object.structure.Element; 25 | 26 | import static org.apache.tinkerpop.gremlin.object.reflect.Classes.is; 27 | import static org.apache.tinkerpop.gremlin.object.reflect.Classes.name; 28 | import static org.apache.tinkerpop.gremlin.object.reflect.Fields.alias; 29 | 30 | /** 31 | * The label of a vertex (or edge) object can be obtained through the {@link Label#of} methods. 32 | * 33 | *

34 | * By default, the label of a vertex is the same as it's object's simple class name, and that of an 35 | * edge is the same, except it's uncapitalized. If you wish to override this default naming 36 | * convention, you may annotate the class with a {@link Alias#label()} value. 37 | * 38 | * @author Karthick Sankarachary (http://github.com/karthicks) 39 | */ 40 | public final class Label { 41 | 42 | private Label() {} 43 | 44 | @SuppressWarnings("PMD.ShortMethodName") 45 | public static String of(Element element) { 46 | return of(element.getClass()); 47 | } 48 | 49 | @SuppressWarnings("PMD.ShortMethodName") 50 | public static String of(Class elementType) { 51 | String label = alias(elementType, Alias::label); 52 | if (label == null) { 53 | label = name(elementType); 54 | if (is(elementType, Edge.class)) { 55 | label = WordUtils.uncapitalize(label); 56 | } 57 | } 58 | return label; 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /gremlin-objects/src/main/java/org/apache/tinkerpop/gremlin/object/reflect/Traversal.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.tinkerpop.gremlin.object.reflect; 20 | 21 | import org.apache.tinkerpop.gremlin.groovy.jsr223.GroovyTranslator; 22 | import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.DefaultGraphTraversal; 23 | import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal; 24 | 25 | /** 26 | * @author Karthick Sankarachary 27 | */ 28 | public class Traversal { 29 | 30 | private static final GroovyTranslator GROOVY_TRANSLATOR = GroovyTranslator.of("g"); 31 | 32 | public static String show(GraphTraversal traversal) { 33 | return (traversal instanceof DefaultGraphTraversal) ? GROOVY_TRANSLATOR 34 | .translate(((DefaultGraphTraversal) traversal).getBytecode()) : traversal.toString(); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /gremlin-objects/src/main/java/org/apache/tinkerpop/gremlin/object/reflect/UpdateBy.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.tinkerpop.gremlin.object.reflect; 20 | 21 | import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal; 22 | import org.apache.tinkerpop.gremlin.structure.Element; 23 | import org.apache.tinkerpop.gremlin.structure.Vertex; 24 | 25 | import lombok.AllArgsConstructor; 26 | import lombok.Data; 27 | import lombok.RequiredArgsConstructor; 28 | 29 | import static org.apache.tinkerpop.gremlin.structure.VertexProperty.Cardinality; 30 | 31 | /** 32 | * The {@link UpdateBy} class updates the property of an {@link Element}, using either the {@link 33 | * Element#property(String, Object)} methods or the {@link GraphTraversal#property} methods. 34 | * 35 | * @author Karthick Sankarachary (http://github.com/karthicks) 36 | */ 37 | @SuppressWarnings({"rawtypes"}) 38 | public enum UpdateBy { 39 | /** 40 | * Defines an {@link Updater} that relies on the {@link Element#property} method. 41 | */ 42 | ELEMENT(new ElementBasedUpdater()), 43 | /** 44 | * Defines an {@link Updater} that relies on the {@link GraphTraversal#property} method. 45 | */ 46 | TRAVERSAL(new TraversalBasedUpdater()); 47 | 48 | private Updater updater; 49 | 50 | UpdateBy(Updater updater) { 51 | this.updater = updater; 52 | } 53 | 54 | public Updater updater() { 55 | return updater; 56 | } 57 | 58 | /** 59 | * A function that given a property update, applies it on the given updatable object. 60 | */ 61 | @FunctionalInterface 62 | @SuppressWarnings("PMD.UnusedModifier") 63 | public interface Updater { 64 | 65 | U property(U updatable, Update update); 66 | } 67 | 68 | /** 69 | * An abstraction that captures an update on a property. 70 | */ 71 | @Data 72 | @AllArgsConstructor 73 | @RequiredArgsConstructor(staticName = "of") 74 | public static class Update { 75 | 76 | private final String key; 77 | private final Object value; 78 | private Cardinality cardinality; 79 | private Object[] keyValues; 80 | 81 | @SuppressWarnings("PMD.ShortMethodName") 82 | public static Update of(Cardinality cardinality, String key, Object value, 83 | Object... keyValues) { 84 | return new Update(key, value, cardinality, keyValues); 85 | } 86 | } 87 | 88 | /** 89 | * A property updater that goes through the {@link Element#property} methods. 90 | */ 91 | static class ElementBasedUpdater implements Updater { 92 | 93 | @Override 94 | public Element property(Element element, Update update) { 95 | if (update.getKeyValues() != null) { 96 | ((Vertex) element).property(update.getCardinality(), 97 | update.getKey(), 98 | update.getValue(), 99 | update.getKeyValues()); 100 | } else { 101 | element.property(update.getKey(), update.getValue()); 102 | } 103 | return element; 104 | } 105 | } 106 | 107 | /** 108 | * A property updater that goes through the {@link GraphTraversal#property} methods. 109 | */ 110 | static class TraversalBasedUpdater implements Updater { 111 | 112 | @Override 113 | public GraphTraversal property(GraphTraversal traversal, Update update) { 114 | if (update.getCardinality() != null) { 115 | traversal.property(update.getCardinality(), 116 | update.getKey(), 117 | update.getValue(), 118 | update.getKeyValues()); 119 | } else { 120 | traversal.property(update.getKey(), 121 | update.getValue()); 122 | } 123 | return traversal; 124 | } 125 | } 126 | } 127 | -------------------------------------------------------------------------------- /gremlin-objects/src/main/java/org/apache/tinkerpop/gremlin/object/structure/Connection.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.tinkerpop.gremlin.object.structure; 20 | 21 | import java.util.Arrays; 22 | import java.util.List; 23 | 24 | import lombok.Data; 25 | import lombok.RequiredArgsConstructor; 26 | import lombok.experimental.Accessors; 27 | 28 | /** 29 | * {@link Connection} specifies the type of vertices that an edge goes out from and in to. 30 | * 31 | *

32 | * If one tries to create an edge for an unknown connection, an object exception will be thrown. 33 | * 34 | * @author Karthick Sankarachary (http://github.com/karthicks) 35 | */ 36 | @Data 37 | @Accessors(fluent = true, chain = true) 38 | @RequiredArgsConstructor(staticName = "of") 39 | public class Connection { 40 | 41 | private final Class fromVertex; 42 | private final Class toVertex; 43 | 44 | public static List list(Class fromVertexClass, 45 | Class toVertexClass) { 46 | return list(of(fromVertexClass, toVertexClass)); 47 | } 48 | 49 | public static List list(Connection... connections) { 50 | return Arrays.asList(connections); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /gremlin-objects/src/main/java/org/apache/tinkerpop/gremlin/object/structure/HasFeature.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.tinkerpop.gremlin.object.structure; 20 | 21 | import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; 22 | import org.apache.tinkerpop.gremlin.structure.Graph; 23 | import org.apache.tinkerpop.gremlin.structure.util.empty.EmptyGraph; 24 | 25 | import java.util.function.Predicate; 26 | 27 | import lombok.Data; 28 | import lombok.RequiredArgsConstructor; 29 | 30 | import static org.apache.tinkerpop.gremlin.object.reflect.Classes.is; 31 | import static org.apache.tinkerpop.gremlin.object.reflect.Classes.isVertex; 32 | 33 | /** 34 | * {@link HasFeature} is a predicate that given the {@link org.apache.tinkerpop.gremlin.structure.Graph.Features} 35 | * of the gremlin graph, determines whether a particular feature is available. 36 | * 37 | * @author Karthick Sankarachary (http://github.com/karthicks) 38 | */ 39 | @FunctionalInterface 40 | public interface HasFeature extends Predicate { 41 | 42 | /** 43 | * The {@link Verifier} tests the given {@link HasFeature} against the features obtained from a 44 | * {@link GraphTraversalSource}. If it contains an {@link EmptyGraph}, then the feature is assumed 45 | * to be unavailable. 46 | */ 47 | @Data 48 | @RequiredArgsConstructor(staticName = "of") 49 | class Verifier { 50 | 51 | private final GraphTraversalSource g; 52 | 53 | public boolean verify(HasFeature hasFeature) { 54 | return g.getGraph() != null && !is(g.getGraph(), EmptyGraph.class) && 55 | hasFeature.test(g.getGraph().features()); 56 | } 57 | } 58 | 59 | static HasFeature supportsUserSuppliedIds(Element element) { 60 | return features -> (isVertex(element) ? features.vertex() : features.edge()) 61 | .supportsUserSuppliedIds(); 62 | } 63 | 64 | static HasFeature supportsGraphAdd(Element element) { 65 | return features -> isVertex(element) ? features.vertex().supportsAddVertices() 66 | : features.edge().supportsAddEdges(); 67 | } 68 | 69 | static HasFeature supportsGraphAddVertex() { 70 | return features -> features.vertex().supportsAddVertices(); 71 | } 72 | 73 | static HasFeature supportsGraphAddEdge() { 74 | return features -> features.edge().supportsAddEdges(); 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /gremlin-objects/src/main/java/org/apache/tinkerpop/gremlin/object/structure/Observable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.tinkerpop.gremlin.object.structure; 20 | 21 | import java.util.ArrayList; 22 | import java.util.Collections; 23 | import java.util.List; 24 | import java.util.function.Consumer; 25 | 26 | /** 27 | * {@link Observable} manages the observers that implement the interface defined by the {@link O} 28 | * type parameter. 29 | * 30 | *

31 | * The {@link Graph} is an example of an {@link Observable}, in that updates to it can be observed 32 | * through its {@code Observer} interface. 33 | * 34 | * @author Karthick Sankarachary (http://github.com/karthicks) 35 | */ 36 | public class Observable { 37 | 38 | private final List observers = Collections.synchronizedList(new ArrayList<>()); 39 | 40 | public void register(O observer) { 41 | observers.add(observer); 42 | } 43 | 44 | public void unregister(O observer) { 45 | observers.remove(observer); 46 | } 47 | 48 | public void notifyAll(Consumer change) { 49 | observers.forEach(change); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /gremlin-objects/src/main/java/org/apache/tinkerpop/gremlin/object/structure/SubGraph.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.tinkerpop.gremlin.object.structure; 20 | 21 | import java.util.function.Function; 22 | 23 | /** 24 | * The {@link SubGraph} is a function, which given a {@link Graph}, lets one chain the addition and 25 | * removal of object vertices and edges. This comes in handy, when one wants to update the {@link 26 | * Graph}, without necessarily knowing when or how it will be provided. 27 | * 28 | * @author Karthick Sankarachary (http://github.com/karthicks) 29 | */ 30 | @FunctionalInterface 31 | public interface SubGraph extends Function { 32 | 33 | /** 34 | * Returns a composed function that first applies the {@code this} function to its input, and then 35 | * applies {@code that} function to the result. If evaluation of either function throws an 36 | * exception, it is relayed to the caller of the chained function. 37 | * 38 | * It works in the reverse order of the {@link #compose(Function)} method. 39 | */ 40 | default SubGraph chain(SubGraph that) { 41 | return graph -> that.apply(apply(graph)); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /gremlin-objects/src/main/java/org/apache/tinkerpop/gremlin/object/structure/Vertex.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.tinkerpop.gremlin.object.structure; 20 | 21 | import org.apache.tinkerpop.gremlin.object.model.PropertyValue; 22 | import org.apache.tinkerpop.gremlin.object.traversal.SubTraversal; 23 | import org.apache.tinkerpop.gremlin.structure.Edge; 24 | 25 | import lombok.Data; 26 | import lombok.EqualsAndHashCode; 27 | import lombok.NoArgsConstructor; 28 | import lombok.ToString; 29 | 30 | /** 31 | * A {@link Vertex} is an {@link Element} that is the object-oriented manifestation of the 32 | * underlying graph vertex. 33 | * 34 | *

35 | * Classes that extend the {@link Vertex} will have it's fields seamlessly map to the underlying 36 | * edge's property. The label of the edge is derived as the simple name of the sub-class. 37 | * 38 | *

39 | * Typically, a vertex property is a primitive type, which manifests itself as a primitive field of 40 | * the user defined sub-class. Sometimes, a vertex property can have properties of its own, known as 41 | * meta-properties. Such vertex properties manifest themselves as fields that are {@link Element}s 42 | * in their own right. The value of the vertex property is mapped to the field of it's {@link 43 | * Element} that is annotated with {@link PropertyValue}. The rest of the fields in that element 44 | * correspond to the vertex property's meta-properties. 45 | * 46 | * @author Karthick Sankarachary (http://github.com/karthicks) 47 | */ 48 | @Data 49 | @ToString 50 | @NoArgsConstructor 51 | @EqualsAndHashCode(callSuper = true) 52 | @SuppressWarnings("PMD.CommentSize") 53 | public class Vertex extends Element { 54 | 55 | public Vertex(Element element) { 56 | super(element); 57 | } 58 | 59 | /** 60 | * Return the underlying gremlin vertex. 61 | */ 62 | public org.apache.tinkerpop.gremlin.structure.Vertex delegate() { 63 | return (org.apache.tinkerpop.gremlin.structure.Vertex) delegate; 64 | } 65 | 66 | /** 67 | * Remove this vertex, if attached. 68 | */ 69 | public void remove() { 70 | org.apache.tinkerpop.gremlin.structure.Vertex delegate = delegate(); 71 | if (delegate == null) { 72 | throw Element.Exceptions.removingDetachedElement(this); 73 | } 74 | delegate.remove(); 75 | } 76 | 77 | /** 78 | * A function denoting a {@code GraphTraversal} that starts at vertices, and ends at vertices. 79 | */ 80 | public interface ToVertex extends SubTraversal< 81 | org.apache.tinkerpop.gremlin.structure.Vertex, 82 | org.apache.tinkerpop.gremlin.structure.Vertex> { 83 | 84 | } 85 | 86 | /** 87 | * A function denoting a {@code GraphTraversal} that starts at vertices, and ends at edges. 88 | */ 89 | interface ToEdge extends SubTraversal< 90 | org.apache.tinkerpop.gremlin.structure.Vertex, Edge> { 91 | 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /gremlin-objects/src/main/java/org/apache/tinkerpop/gremlin/object/traversal/AnyTraversal.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.tinkerpop.gremlin.object.traversal; 20 | 21 | import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.DefaultGraphTraversal; 22 | import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal; 23 | import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; 24 | import org.apache.tinkerpop.gremlin.structure.util.empty.EmptyGraph; 25 | 26 | import java.util.Formattable; 27 | import java.util.Formatter; 28 | import java.util.function.Function; 29 | 30 | import lombok.SneakyThrows; 31 | 32 | 33 | /** 34 | * {@link AnyTraversal} denotes an arbitrary yet complete walk through over the graph, which returns 35 | * a {@link GraphTraversal} whose results are ready to be consumed. 36 | * 37 | * @author Karthick Sankarachary (http://github.com/karthicks) 38 | */ 39 | @FunctionalInterface 40 | public interface AnyTraversal extends Function>, 41 | Formattable { 42 | /** 43 | * Reveal the steps in the {@link SubTraversal} by passing a {@link DefaultGraphTraversal} to it, 44 | * and outputting it's string representation. 45 | */ 46 | @Override 47 | @SneakyThrows 48 | default void formatTo(Formatter formatter, int flags, int width, int precision) { 49 | GraphTraversalSource g = new GraphTraversalSource(EmptyGraph.instance()); 50 | GraphTraversal graphTraversal = apply(g); 51 | formatter.out().append(graphTraversal.toString()); 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /gremlin-objects/src/main/java/org/apache/tinkerpop/gremlin/object/traversal/ElementTo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.tinkerpop.gremlin.object.traversal; 20 | 21 | import org.apache.tinkerpop.gremlin.structure.Element; 22 | 23 | /** 24 | * Given that most {@link SubTraversal}s start at a gremlin element, it behooves us to define 25 | * specializations around that. The name of this class is indicative of the start type of the 26 | * sub-traversals defined here. The name of the inner class defined here is indicative of the end 27 | * type of the sub-traversal. 28 | * 29 | * @author Karthick Sankarachary (http://github.com/karthicks) 30 | */ 31 | @FunctionalInterface 32 | public interface ElementTo extends SubTraversal { 33 | 34 | /** 35 | * A function denoting a {@code GraphTraversal} that starts at elements, and ends at elements. 36 | */ 37 | @FunctionalInterface 38 | interface Element extends SubTraversal< 39 | org.apache.tinkerpop.gremlin.structure.Element, 40 | org.apache.tinkerpop.gremlin.structure.Element> { 41 | 42 | } 43 | 44 | /** 45 | * A function denoting a {@code GraphTraversal} that starts at elements, and ends at vertices. 46 | */ 47 | @FunctionalInterface 48 | interface Vertex extends SubTraversal< 49 | org.apache.tinkerpop.gremlin.structure.Element, 50 | org.apache.tinkerpop.gremlin.structure.Vertex> { 51 | 52 | } 53 | 54 | /** 55 | * A function denoting a {@code GraphTraversal} that starts at elements, and ends at strings. 56 | */ 57 | @FunctionalInterface 58 | interface String extends SubTraversal< 59 | org.apache.tinkerpop.gremlin.structure.Element, 60 | java.lang.String> { 61 | 62 | } 63 | 64 | /** 65 | * A function denoting a {@code GraphTraversal} that starts at elements, and ends at longs. 66 | */ 67 | @FunctionalInterface 68 | interface Long extends SubTraversal< 69 | org.apache.tinkerpop.gremlin.structure.Element, 70 | java.lang.Long> { 71 | 72 | } 73 | 74 | /** 75 | * A function denoting a {@code GraphTraversal} that starts at elements, and ends anywhere. 76 | */ 77 | @FunctionalInterface 78 | @SuppressWarnings("PMD.ShortClassName") 79 | interface Any extends SubTraversal< 80 | org.apache.tinkerpop.gremlin.structure.Element, 81 | java.lang.Object> { 82 | 83 | } 84 | 85 | /** 86 | * A function denoting a {@code GraphTraversal} that starts at elements, and ends in maps. 87 | */ 88 | @FunctionalInterface 89 | @SuppressWarnings("PMD.ShortClassName") 90 | interface Map extends SubTraversal< 91 | org.apache.tinkerpop.gremlin.structure.Element, 92 | java.util.Map> { 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /gremlin-objects/src/main/java/org/apache/tinkerpop/gremlin/object/traversal/Selections.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.tinkerpop.gremlin.object.traversal; 20 | 21 | import java.util.ArrayList; 22 | import java.util.Arrays; 23 | import java.util.HashMap; 24 | import java.util.Map; 25 | 26 | import lombok.EqualsAndHashCode; 27 | import lombok.RequiredArgsConstructor; 28 | 29 | /** 30 | * The {@link Selection} captures the result of a {@link Query} that involves a select step. For 31 | * each alias selected, the corresponding {@link Query#as(String, Class)} must be called to specify 32 | * the type of the selected alias. 33 | * 34 | *

35 | * The {@link Selection} returned by {@link Query#select()} is a list of {@link Selection}s. Each 36 | * {@link Selection} in turn is a map of the alias to it's corresponding object, whose type is as 37 | * was specified by the {@link Query#as(String, Class)} method. 38 | * 39 | * @author Karthick Sankarachary (http://github.com/karthicks) 40 | */ 41 | @RequiredArgsConstructor(staticName = "of") 42 | @EqualsAndHashCode(callSuper = true, exclude = {"classes"}) 43 | @SuppressWarnings({"PMD.ShortMethodName", "rawtypes"}) 44 | public class Selections extends ArrayList { 45 | 46 | public static final long serialVersionUID = 1L; 47 | private Map classes = new HashMap<>(); 48 | 49 | public static Selections of(Selection... selectionList) { 50 | Selections selections = Selections.of(); 51 | selections.addAll(Arrays.asList(selectionList)); 52 | return selections; 53 | } 54 | 55 | public void as(String alias, Class clazz) { 56 | classes.put(alias, clazz); 57 | } 58 | 59 | public Class as(String alias) { 60 | return classes.get(alias); 61 | } 62 | 63 | @RequiredArgsConstructor(staticName = "of") 64 | public static class Selection extends HashMap { 65 | 66 | public static final long serialVersionUID = 1L; 67 | 68 | 69 | public Selection add(String alias, Object object) { 70 | this.put(alias, object); 71 | return this; 72 | } 73 | 74 | @SuppressWarnings("unchecked") 75 | public T as(String alias, Class elementType) { 76 | return (T) this.get(alias); 77 | } 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /gremlin-objects/src/main/java/org/apache/tinkerpop/gremlin/object/traversal/SubTraversal.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.tinkerpop.gremlin.object.traversal; 20 | 21 | import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.DefaultGraphTraversal; 22 | import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal; 23 | import org.apache.tinkerpop.gremlin.structure.Element; 24 | 25 | import java.util.Formattable; 26 | import java.util.Formatter; 27 | import java.util.function.Function; 28 | 29 | import lombok.SneakyThrows; 30 | 31 | /** 32 | * {@link SubTraversal} represents a partial walk through of the graph. Given a @{link 33 | * GraphTraversal}, it applies an arbitrary number of steps on it, and returns the traversal back. 34 | * 35 | *

The {@link I} type parameter denotes the type of the selected graph elements at the start of 36 | * the sub-traversal, which we will refer to as its start type. Similarly, the {@link O} parameter 37 | * specifies the type at the end of the sub-traversal, referred to as its end type. 38 | * 39 | *

This allows you think of traversals in terms of reusing building blocks, which can then be 40 | * combined in one of two ways: 41 | * 42 | *

45 | * 46 | * @author Karthick Sankarachary (http://github.com/karthicks) 47 | */ 48 | @FunctionalInterface 49 | public interface SubTraversal 50 | extends Function, GraphTraversal>, Formattable { 51 | 52 | /** 53 | * Reveal the steps in the {@link SubTraversal} by passing a {@link DefaultGraphTraversal} to it, 54 | * and outputting it's string representation. 55 | */ 56 | @Override 57 | @SneakyThrows 58 | @SuppressWarnings("unchecked") 59 | default void formatTo(Formatter formatter, int flags, int width, int precision) { 60 | DefaultGraphTraversal defaultGraphTraversal = new DefaultGraphTraversal(); 61 | apply(defaultGraphTraversal); 62 | formatter.out().append(defaultGraphTraversal.toString()); 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /gremlin-objects/src/main/java/org/apache/tinkerpop/gremlin/object/traversal/library/AddV.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.tinkerpop.gremlin.object.traversal.library; 20 | 21 | import org.apache.tinkerpop.gremlin.object.structure.HasFeature; 22 | import org.apache.tinkerpop.gremlin.object.traversal.AnyTraversal; 23 | import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal; 24 | import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; 25 | import org.apache.tinkerpop.gremlin.structure.Element; 26 | import org.apache.tinkerpop.gremlin.structure.T; 27 | 28 | import java.lang.reflect.Field; 29 | 30 | import lombok.Data; 31 | import lombok.RequiredArgsConstructor; 32 | import lombok.SneakyThrows; 33 | import lombok.experimental.Accessors; 34 | 35 | import static org.apache.tinkerpop.gremlin.object.reflect.Fields.propertyKey; 36 | import static org.apache.tinkerpop.gremlin.object.reflect.Fields.propertyValue; 37 | import static org.apache.tinkerpop.gremlin.object.reflect.Keys.keyFields; 38 | import static org.apache.tinkerpop.gremlin.object.reflect.Primitives.isMissing; 39 | import static org.apache.tinkerpop.gremlin.object.structure.HasFeature.supportsUserSuppliedIds; 40 | 41 | /** 42 | * {@link AddV} attempts to add a vertex with the keys of the given element. 43 | * 44 | *

45 | * In the case of graphs that don't support user supplied ids, if a vertex with that key(s) already 46 | * exists, it will be returned as-is. Otherwise, a vertex will be created with the given key(s), and 47 | * returned. 48 | * 49 | *

50 | * If user supplied ids is supported, then this will add the vertex if it's missing, and raise an 51 | * exception if it already exists. 52 | * 53 | * @author Karthick Sankarachary (http://github.com/karthicks) 54 | */ 55 | @Data 56 | @Accessors(fluent = true, chain = true) 57 | @RequiredArgsConstructor(staticName = "of") 58 | @SuppressWarnings({"unchecked", "rawtypes", "PMD.TooManyStaticImports"}) 59 | public class AddV implements AnyTraversal { 60 | 61 | private final org.apache.tinkerpop.gremlin.object.structure.Element element; 62 | 63 | @Override 64 | @SneakyThrows 65 | public GraphTraversal apply(GraphTraversalSource g) { 66 | GraphTraversal traversal = g.addV(element.label()); 67 | if (element.id() != null && HasFeature.Verifier.of(g) 68 | .verify(supportsUserSuppliedIds(element))) { 69 | traversal.property(T.id, element.id()); 70 | } 71 | for (Field field : keyFields(element)) { 72 | String key = propertyKey(field); 73 | Object value = propertyValue(field, element); 74 | if (isMissing(value)) { 75 | throw org.apache.tinkerpop.gremlin.object.structure.Element.Exceptions.requiredKeysMissing( 76 | element.getClass(), key); 77 | } 78 | traversal.property(key, value); 79 | } 80 | return traversal; 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /gremlin-objects/src/main/java/org/apache/tinkerpop/gremlin/object/traversal/library/Count.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.tinkerpop.gremlin.object.traversal.library; 20 | 21 | import org.apache.tinkerpop.gremlin.object.traversal.ElementTo; 22 | import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal; 23 | import org.apache.tinkerpop.gremlin.structure.Element; 24 | 25 | import lombok.Data; 26 | import lombok.RequiredArgsConstructor; 27 | import lombok.experimental.Accessors; 28 | 29 | /** 30 | * {@link Count} applies the {@link GraphTraversal#count} step on the current traversal. 31 | * 32 | * @author Karthick Sankarachary (http://github.com/karthicks) 33 | */ 34 | @Data 35 | @Accessors(fluent = true, chain = true) 36 | @RequiredArgsConstructor(staticName = "of") 37 | public class Count implements ElementTo.Long { 38 | 39 | @Override 40 | public GraphTraversal apply(GraphTraversal traversal) { 41 | return traversal.count(); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /gremlin-objects/src/main/java/org/apache/tinkerpop/gremlin/object/traversal/library/Has.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.tinkerpop.gremlin.object.traversal.library; 20 | 21 | import org.apache.tinkerpop.gremlin.object.traversal.ElementTo; 22 | import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal; 23 | import org.apache.tinkerpop.gremlin.structure.Element; 24 | 25 | import lombok.Data; 26 | import lombok.RequiredArgsConstructor; 27 | import lombok.experimental.Accessors; 28 | 29 | /** 30 | * {@link Has} constrains the current traversal by a specific element property. 31 | * 32 | * @author Karthick Sankarachary (http://github.com/karthicks) 33 | */ 34 | @Data 35 | @Accessors(fluent = true, chain = true) 36 | @RequiredArgsConstructor(staticName = "of") 37 | @SuppressWarnings("PMD.ShortClassName") 38 | public class Has implements ElementTo.Element { 39 | 40 | private final String label; 41 | private final String key; 42 | private final Object value; 43 | 44 | @Override 45 | public GraphTraversal apply(GraphTraversal traversal) { 46 | return traversal.has(label, key, value); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /gremlin-objects/src/main/java/org/apache/tinkerpop/gremlin/object/traversal/library/HasId.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.tinkerpop.gremlin.object.traversal.library; 20 | 21 | import org.apache.tinkerpop.gremlin.object.reflect.Keys; 22 | import org.apache.tinkerpop.gremlin.object.traversal.ElementTo; 23 | import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal; 24 | import org.apache.tinkerpop.gremlin.structure.Element; 25 | 26 | import lombok.Data; 27 | import lombok.RequiredArgsConstructor; 28 | import lombok.experimental.Accessors; 29 | 30 | /** 31 | * {@link HasId} finds an adjacent graph element with the specific id of the supplied element. 32 | * 33 | * @author Karthick Sankarachary (http://github.com/karthicks) 34 | */ 35 | @Data 36 | @Accessors(fluent = true, chain = true) 37 | @RequiredArgsConstructor(staticName = "of") 38 | public class HasId implements ElementTo.Element { 39 | 40 | private final org.apache.tinkerpop.gremlin.object.structure.Element element; 41 | 42 | @Override 43 | public GraphTraversal apply(GraphTraversal traversal) { 44 | return traversal.hasId(Keys.id(element)); 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /gremlin-objects/src/main/java/org/apache/tinkerpop/gremlin/object/traversal/library/HasKeys.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.tinkerpop.gremlin.object.traversal.library; 20 | 21 | import org.apache.tinkerpop.gremlin.object.model.OrderingKey; 22 | import org.apache.tinkerpop.gremlin.object.model.PrimaryKey; 23 | import org.apache.tinkerpop.gremlin.object.traversal.ElementTo; 24 | import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal; 25 | import org.apache.tinkerpop.gremlin.structure.Element; 26 | 27 | import java.lang.annotation.Annotation; 28 | import java.lang.reflect.Field; 29 | import java.util.List; 30 | 31 | import lombok.AllArgsConstructor; 32 | import lombok.Builder; 33 | import lombok.Data; 34 | import lombok.RequiredArgsConstructor; 35 | import lombok.SneakyThrows; 36 | import lombok.experimental.Accessors; 37 | 38 | import static org.apache.tinkerpop.gremlin.object.reflect.Classes.is; 39 | import static org.apache.tinkerpop.gremlin.object.reflect.Fields.propertyKey; 40 | import static org.apache.tinkerpop.gremlin.object.reflect.Fields.propertyValue; 41 | import static org.apache.tinkerpop.gremlin.object.reflect.Keys.keyFields; 42 | import static org.apache.tinkerpop.gremlin.object.reflect.Keys.orderingKeyFields; 43 | import static org.apache.tinkerpop.gremlin.object.reflect.Keys.primaryKeyFields; 44 | import static org.apache.tinkerpop.gremlin.object.reflect.Primitives.isMissing; 45 | 46 | /** 47 | * {@link HasKeys} finds adjacent graph elements whose primary key properties correspond to that of 48 | * the given element. 49 | * 50 | * @author Karthick Sankarachary (http://github.com/karthicks) 51 | */ 52 | @Data 53 | @Builder 54 | @AllArgsConstructor 55 | @Accessors(fluent = true, chain = true) 56 | @RequiredArgsConstructor(staticName = "of") 57 | @SuppressWarnings("PMD.TooManyStaticImports") 58 | public class HasKeys implements ElementTo.Element { 59 | 60 | private final org.apache.tinkerpop.gremlin.object.structure.Element element; 61 | 62 | private Class keyType; 63 | 64 | @SuppressWarnings("PMD.ShortMethodName") 65 | public static HasKeys of(org.apache.tinkerpop.gremlin.object.structure.Element element, 66 | Class keyType) { 67 | return HasKeys.builder() 68 | .element(element) 69 | .keyType(keyType) 70 | .build(); 71 | } 72 | 73 | @Override 74 | @SneakyThrows 75 | public GraphTraversal apply(GraphTraversal traversal) { 76 | traversal.hasLabel(element.label()); 77 | List fields; 78 | if (keyType != null) { 79 | if (is(keyType, PrimaryKey.class)) { 80 | fields = primaryKeyFields(element); 81 | } else if (is(keyType, OrderingKey.class)) { 82 | fields = orderingKeyFields(element); 83 | } else { 84 | throw org.apache.tinkerpop.gremlin.object.structure.Element.Exceptions 85 | .invalidAnnotationType(keyType); 86 | } 87 | } else { 88 | fields = keyFields(element); 89 | } 90 | for (Field field : fields) { 91 | String key = propertyKey(field); 92 | Object value = propertyValue(field, element); 93 | if (isMissing(value)) { 94 | throw org.apache.tinkerpop.gremlin.object.structure.Element.Exceptions.requiredKeysMissing( 95 | element.getClass(), key); 96 | } 97 | traversal.has(key, value); 98 | } 99 | return traversal; 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /gremlin-objects/src/main/java/org/apache/tinkerpop/gremlin/object/traversal/library/HasLabel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.tinkerpop.gremlin.object.traversal.library; 20 | 21 | import org.apache.tinkerpop.gremlin.object.traversal.ElementTo; 22 | import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal; 23 | import org.apache.tinkerpop.gremlin.structure.Element; 24 | 25 | import lombok.Data; 26 | import lombok.RequiredArgsConstructor; 27 | import lombok.experimental.Accessors; 28 | 29 | /** 30 | * {@link HasLabel} finds adjacent graph elements whose label matches that of the given element. 31 | * 32 | * @author Karthick Sankarachary (http://github.com/karthicks) 33 | */ 34 | @Data 35 | @Accessors(fluent = true, chain = true) 36 | @RequiredArgsConstructor(staticName = "of") 37 | public class HasLabel implements ElementTo.Element { 38 | 39 | private final String label; 40 | 41 | @SuppressWarnings("PMD.ShortMethodName") 42 | public static HasLabel of(org.apache.tinkerpop.gremlin.object.structure.Element element) { 43 | return of(element.getClass()); 44 | } 45 | 46 | @SuppressWarnings("PMD.ShortMethodName") 47 | public static HasLabel of( 48 | Class elementType) { 49 | return of(org.apache.tinkerpop.gremlin.object.reflect.Label.of(elementType)); 50 | } 51 | 52 | @Override 53 | public GraphTraversal apply(GraphTraversal traversal) { 54 | return traversal.hasLabel(label); 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /gremlin-objects/src/main/java/org/apache/tinkerpop/gremlin/object/traversal/library/Id.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.tinkerpop.gremlin.object.traversal.library; 20 | 21 | import org.apache.tinkerpop.gremlin.object.traversal.ElementTo; 22 | import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal; 23 | import org.apache.tinkerpop.gremlin.structure.Element; 24 | 25 | import lombok.Data; 26 | import lombok.RequiredArgsConstructor; 27 | import lombok.experimental.Accessors; 28 | 29 | /** 30 | * {@link Id} extracts the id(s) of the currently selected elements in the traversal. 31 | * 32 | * @author Karthick Sankarachary (http://github.com/karthicks) 33 | */ 34 | @Data 35 | @Accessors(fluent = true, chain = true) 36 | @RequiredArgsConstructor(staticName = "of") 37 | @SuppressWarnings("PMD.ShortClassName") 38 | public class Id implements ElementTo.Any { 39 | 40 | @Override 41 | public GraphTraversal apply(GraphTraversal traversal) { 42 | return traversal.id(); 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /gremlin-objects/src/main/java/org/apache/tinkerpop/gremlin/object/traversal/library/Keys.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.tinkerpop.gremlin.object.traversal.library; 20 | 21 | import org.apache.tinkerpop.gremlin.object.traversal.ElementTo; 22 | import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal; 23 | import org.apache.tinkerpop.gremlin.structure.Element; 24 | 25 | import lombok.Data; 26 | import lombok.RequiredArgsConstructor; 27 | import lombok.experimental.Accessors; 28 | 29 | import static org.apache.tinkerpop.gremlin.object.reflect.Keys.primaryKeyNames; 30 | 31 | /** 32 | * {@link Keys} extracts the values of the primary key properties of the given element type. 33 | * 34 | * @author Karthick Sankarachary (http://github.com/karthicks) 35 | */ 36 | @Data 37 | @Accessors(fluent = true, chain = true) 38 | @RequiredArgsConstructor(staticName = "of") 39 | public class Keys implements ElementTo.Any { 40 | 41 | private final Class elementType; 42 | 43 | @SuppressWarnings("PMD.ShortMethodName") 44 | public static Keys of(org.apache.tinkerpop.gremlin.object.structure.Element element) { 45 | return of(element.getClass()); 46 | } 47 | 48 | @Override 49 | public GraphTraversal apply(GraphTraversal traversal) { 50 | return Values.of(primaryKeyNames(elementType)).apply(traversal); 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /gremlin-objects/src/main/java/org/apache/tinkerpop/gremlin/object/traversal/library/Label.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.tinkerpop.gremlin.object.traversal.library; 20 | 21 | import org.apache.tinkerpop.gremlin.object.traversal.ElementTo; 22 | import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal; 23 | import org.apache.tinkerpop.gremlin.structure.Element; 24 | 25 | import lombok.Data; 26 | import lombok.RequiredArgsConstructor; 27 | import lombok.experimental.Accessors; 28 | 29 | /** 30 | * {@link Label} extracts the label(s) of the currently selected elements in the traversal. 31 | * 32 | * @author Karthick Sankarachary (http://github.com/karthicks) 33 | */ 34 | @Data 35 | @Accessors(fluent = true, chain = true) 36 | @RequiredArgsConstructor(staticName = "of") 37 | public class Label implements ElementTo.String { 38 | 39 | @Override 40 | public GraphTraversal apply(GraphTraversal traversal) { 41 | return traversal.label(); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /gremlin-objects/src/main/java/org/apache/tinkerpop/gremlin/object/traversal/library/Order.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.tinkerpop.gremlin.object.traversal.library; 20 | 21 | import org.apache.tinkerpop.gremlin.object.traversal.ElementTo; 22 | import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal; 23 | import org.apache.tinkerpop.gremlin.structure.Element; 24 | 25 | import lombok.Data; 26 | import lombok.RequiredArgsConstructor; 27 | import lombok.experimental.Accessors; 28 | 29 | /** 30 | * {@link Order} orders the traversal by the supplied property key. 31 | * 32 | * @author Karthick Sankarachary (http://github.com/karthicks) 33 | */ 34 | @Data 35 | @Accessors(fluent = true, chain = true) 36 | @RequiredArgsConstructor(staticName = "by") 37 | public class Order implements ElementTo.Element { 38 | 39 | private final String property; 40 | 41 | @Override 42 | public GraphTraversal apply(GraphTraversal traversal) { 43 | return traversal.order().by(property); 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /gremlin-objects/src/main/java/org/apache/tinkerpop/gremlin/object/traversal/library/Out.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.tinkerpop.gremlin.object.traversal.library; 20 | 21 | import org.apache.tinkerpop.gremlin.object.traversal.SubTraversal; 22 | import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal; 23 | import org.apache.tinkerpop.gremlin.structure.Element; 24 | import org.apache.tinkerpop.gremlin.structure.Vertex; 25 | 26 | import lombok.Data; 27 | import lombok.RequiredArgsConstructor; 28 | import lombok.experimental.Accessors; 29 | 30 | /** 31 | * {@link Out} selects outgoing adjacent vertices that can be reached through the given edge label. 32 | * 33 | * @author Karthick Sankarachary (http://github.com/karthicks) 34 | */ 35 | @Data 36 | @Accessors(fluent = true, chain = true) 37 | @RequiredArgsConstructor(staticName = "of") 38 | @SuppressWarnings({"PMD.ShortClassName"}) 39 | public class Out implements SubTraversal { 40 | 41 | private final String label; 42 | 43 | @SuppressWarnings("PMD.ShortMethodName") 44 | public static Out of(org.apache.tinkerpop.gremlin.object.structure.Element element) { 45 | return of(org.apache.tinkerpop.gremlin.object.reflect.Label.of(element)); 46 | } 47 | 48 | @SuppressWarnings("PMD.ShortMethodName") 49 | public static Out of( 50 | Class elementType) { 51 | return of(org.apache.tinkerpop.gremlin.object.reflect.Label.of(elementType)); 52 | } 53 | 54 | @Override 55 | public GraphTraversal apply(GraphTraversal traversal) { 56 | return traversal.out(label); 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /gremlin-objects/src/main/java/org/apache/tinkerpop/gremlin/object/traversal/library/Page.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.tinkerpop.gremlin.object.traversal.library; 20 | 21 | import org.apache.tinkerpop.gremlin.object.traversal.ElementTo; 22 | import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal; 23 | import org.apache.tinkerpop.gremlin.structure.Element; 24 | 25 | import lombok.Data; 26 | import lombok.RequiredArgsConstructor; 27 | import lombok.SneakyThrows; 28 | import lombok.experimental.Accessors; 29 | 30 | /** 31 | * {@link Page} finds a page of elements of a given type. 32 | * 33 | * @author Karthick Sankarachary (http://github.com/karthicks) 34 | */ 35 | @Data 36 | @Accessors(fluent = true, chain = true) 37 | @RequiredArgsConstructor(staticName = "of") 38 | public class Page implements ElementTo.Element { 39 | 40 | private final Class elementType; 41 | private final long low; 42 | private final long high; 43 | 44 | @Override 45 | @SneakyThrows 46 | public GraphTraversal apply(GraphTraversal traversal) { 47 | return traversal 48 | .hasLabel(org.apache.tinkerpop.gremlin.object.reflect.Label.of(elementType)) 49 | .range(low, high); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /gremlin-objects/src/main/java/org/apache/tinkerpop/gremlin/object/traversal/library/Range.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.tinkerpop.gremlin.object.traversal.library; 20 | 21 | import org.apache.tinkerpop.gremlin.object.traversal.ElementTo; 22 | import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal; 23 | import org.apache.tinkerpop.gremlin.structure.Element; 24 | 25 | import lombok.Data; 26 | import lombok.RequiredArgsConstructor; 27 | import lombok.experimental.Accessors; 28 | 29 | /** 30 | * {@link Range} limits the count of the traversal such that it falls between the given {@link #low} 31 | * and {@link #high} numbers. 32 | * 33 | * @author Karthick Sankarachary (http://github.com/karthicks) 34 | */ 35 | @Data 36 | @Accessors(fluent = true, chain = true) 37 | @RequiredArgsConstructor(staticName = "of") 38 | public class Range implements ElementTo.Element { 39 | 40 | private final int low; 41 | private final int high; 42 | 43 | @Override 44 | public GraphTraversal apply(GraphTraversal traversal) { 45 | return traversal.range(low, high); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /gremlin-objects/src/main/java/org/apache/tinkerpop/gremlin/object/traversal/library/Select.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.tinkerpop.gremlin.object.traversal.library; 20 | 21 | import java.util.ArrayList; 22 | import java.util.Arrays; 23 | import java.util.List; 24 | import java.util.Map; 25 | import lombok.Data; 26 | import org.apache.tinkerpop.gremlin.object.traversal.ElementTo; 27 | import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal; 28 | import org.apache.tinkerpop.gremlin.structure.Element; 29 | 30 | /** 31 | * {@link Select} applies the ${link GraphTraversal#count} step on the current traversal. 32 | * 33 | * @author Karthick Sankarachary 34 | */ 35 | @Data 36 | public class Select implements ElementTo.Map { 37 | 38 | private String selectKey1; 39 | private String selectKey2; 40 | private List otherSelectKeys; 41 | 42 | @SuppressWarnings("PMD.ShortMethodName") 43 | public static Select of(String... aliases) { 44 | Select select = new Select(); 45 | if (aliases.length > 0) { 46 | select.selectKey1 = aliases[0]; 47 | } 48 | if (aliases.length > 1) { 49 | select.selectKey2 = aliases[1]; 50 | } 51 | if (aliases.length > 2) { 52 | select.otherSelectKeys = Arrays.asList(aliases); 53 | select.otherSelectKeys.remove(0); 54 | select.otherSelectKeys.remove(0); 55 | } else { 56 | select.otherSelectKeys = new ArrayList<>(); 57 | } 58 | return select; 59 | } 60 | 61 | 62 | @Override 63 | public GraphTraversal> apply( 64 | GraphTraversal traversal) { 65 | GraphTraversal> selectTraversal; 66 | if (selectKey2 == null) { 67 | selectTraversal = traversal.select(selectKey1); 68 | } else { 69 | selectTraversal = 70 | traversal.select(selectKey1, selectKey2, otherSelectKeys.toArray(new String[] {})); 71 | } 72 | if (selectKey1 != null) { 73 | selectTraversal.by(); 74 | } 75 | if (selectKey2 != null) { 76 | selectTraversal.by(); 77 | } 78 | otherSelectKeys.forEach(otherSelectKey -> { 79 | selectTraversal.by(); 80 | }); 81 | return selectTraversal; 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /gremlin-objects/src/main/java/org/apache/tinkerpop/gremlin/object/traversal/library/Values.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.tinkerpop.gremlin.object.traversal.library; 20 | 21 | import org.apache.tinkerpop.gremlin.object.reflect.Properties; 22 | import org.apache.tinkerpop.gremlin.object.traversal.ElementTo; 23 | import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal; 24 | import org.apache.tinkerpop.gremlin.structure.Element; 25 | 26 | import java.util.List; 27 | 28 | import lombok.Data; 29 | import lombok.experimental.Accessors; 30 | 31 | /** 32 | * {@link Values} extracts the values of the given property keys, and removes duplicates thereof. 33 | * 34 | * @author Karthick Sankarachary (http://github.com/karthicks) 35 | */ 36 | @Data 37 | @Accessors(fluent = true, chain = true) 38 | public class Values implements ElementTo.Any { 39 | 40 | private final String[] propertyKeys; 41 | 42 | @SuppressWarnings("PMD.ShortMethodName") 43 | public static Values of(org.apache.tinkerpop.gremlin.object.structure.Element element) { 44 | return of(Properties.names(element)); 45 | } 46 | 47 | @SuppressWarnings("PMD.ShortMethodName") 48 | public static Values of(List propertyKeys) { 49 | return of(propertyKeys.toArray(new String[] {})); 50 | } 51 | 52 | @SuppressWarnings("PMD.ShortMethodName") 53 | public static Values of(String... propertyKeys) { 54 | return new Values(propertyKeys); 55 | } 56 | 57 | @Override 58 | public GraphTraversal apply(GraphTraversal traversal) { 59 | return traversal.values(propertyKeys).dedup(); 60 | } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /gremlin-objects/src/test/java/org/apache/tinkerpop/gremlin/object/edges/Created.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.tinkerpop.gremlin.object.edges; 20 | 21 | import org.apache.tinkerpop.gremlin.object.structure.Connection; 22 | import org.apache.tinkerpop.gremlin.object.structure.Edge; 23 | import org.apache.tinkerpop.gremlin.object.vertices.Person; 24 | import org.apache.tinkerpop.gremlin.object.vertices.Software; 25 | 26 | import java.util.List; 27 | 28 | import lombok.AllArgsConstructor; 29 | import lombok.Builder; 30 | import lombok.Data; 31 | import lombok.EqualsAndHashCode; 32 | import lombok.NoArgsConstructor; 33 | import lombok.experimental.Accessors; 34 | 35 | /** 36 | * The {@link Created} class represents the "created" edge. 37 | * 38 | * @author Karthick Sankarachary (http://github.com/karthicks) 39 | */ 40 | @Data 41 | @Builder 42 | @NoArgsConstructor 43 | @AllArgsConstructor 44 | @Accessors(fluent = true, chain = true) 45 | @EqualsAndHashCode(of = {}, callSuper = true) 46 | public class Created extends Edge { 47 | 48 | private double weight; 49 | 50 | public static Created of(double weight) { 51 | return Created.builder().weight(weight).build(); 52 | } 53 | 54 | @Override 55 | protected List connections() { 56 | return Connection.list(Person.class, Software.class); 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /gremlin-objects/src/test/java/org/apache/tinkerpop/gremlin/object/edges/Develops.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.tinkerpop.gremlin.object.edges; 20 | 21 | import org.apache.tinkerpop.gremlin.object.reflect.Label; 22 | import org.apache.tinkerpop.gremlin.object.structure.Connection; 23 | import org.apache.tinkerpop.gremlin.object.structure.Edge; 24 | import org.apache.tinkerpop.gremlin.object.vertices.Location; 25 | import org.apache.tinkerpop.gremlin.object.vertices.Person; 26 | import org.apache.tinkerpop.gremlin.object.vertices.Software; 27 | 28 | import java.time.Instant; 29 | import java.util.List; 30 | 31 | import lombok.AllArgsConstructor; 32 | import lombok.Builder; 33 | import lombok.Data; 34 | import lombok.EqualsAndHashCode; 35 | import lombok.NoArgsConstructor; 36 | import lombok.experimental.Accessors; 37 | 38 | /** 39 | * The {@link Develops} class represents the "develops" edge. 40 | * 41 | * @author Karthick Sankarachary (http://github.com/karthicks) 42 | */ 43 | @Data 44 | @Builder 45 | @NoArgsConstructor 46 | @AllArgsConstructor 47 | @Accessors(fluent = true, chain = true) 48 | @EqualsAndHashCode(of = {}, callSuper = true) 49 | public class Develops extends Edge { 50 | 51 | /** 52 | * Go to the {@link Person} who develop the currently selected {@link Software}s. 53 | */ 54 | public final static ToVertex Developers = traversal -> traversal 55 | .in(Label.of(Develops.class)) 56 | .hasLabel(Label.of(Person.class)); 57 | public final static ToVertex Softwares = traversal -> traversal 58 | .out(Label.of(Develops.class)) 59 | .hasLabel(Label.of(Software.class)); 60 | private Instant since; 61 | 62 | public static Develops of(Instant since) { 63 | return Develops.builder().since(since).build(); 64 | } 65 | 66 | public static Develops of(int year) { 67 | return of(Location.year(year)); 68 | } 69 | 70 | @Override 71 | protected List connections() { 72 | return Connection.list(Person.class, Software.class); 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /gremlin-objects/src/test/java/org/apache/tinkerpop/gremlin/object/edges/Knows.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.tinkerpop.gremlin.object.edges; 20 | 21 | import org.apache.tinkerpop.gremlin.object.reflect.Label; 22 | import org.apache.tinkerpop.gremlin.object.structure.Connection; 23 | import org.apache.tinkerpop.gremlin.object.structure.Edge; 24 | import org.apache.tinkerpop.gremlin.object.vertices.Person; 25 | import org.apache.tinkerpop.gremlin.structure.Direction; 26 | 27 | import java.time.Instant; 28 | import java.util.List; 29 | 30 | import lombok.AllArgsConstructor; 31 | import lombok.Builder; 32 | import lombok.Data; 33 | import lombok.EqualsAndHashCode; 34 | import lombok.NoArgsConstructor; 35 | import lombok.experimental.Accessors; 36 | 37 | /** 38 | * The {@link Knows} class represents the "knows" edge. 39 | * 40 | * @author Karthick Sankarachary (http://github.com/karthicks) 41 | */ 42 | @Data 43 | @Builder 44 | @NoArgsConstructor 45 | @AllArgsConstructor 46 | @Accessors(fluent = true, chain = true) 47 | @EqualsAndHashCode(of = {}, callSuper = true) 48 | public class Knows extends Edge { 49 | 50 | /** 51 | * Go to the {@link Person}s you know, assuming you're currently selected. 52 | */ 53 | public final static ToVertex KnowsWho = traversal -> traversal 54 | .outE(Label.of(Knows.class)) 55 | .toV(Direction.IN); 56 | /** 57 | * Go to to the {@link Person}s who know of you, assuming you're currently selected. 58 | */ 59 | public final static ToVertex KnownBy = traversal -> traversal 60 | .inE(Label.of(Knows.class)) 61 | .toV(Direction.OUT); 62 | 63 | private Double weight; 64 | 65 | private Instant since; 66 | 67 | public static Knows of(double weight) { 68 | return of(weight, null); 69 | } 70 | 71 | public static Knows of(Instant since) { 72 | return of(null, since); 73 | } 74 | 75 | public static Knows of(Double weight, Instant since) { 76 | return Knows.builder().weight(weight).since(since).build(); 77 | } 78 | 79 | @Override 80 | protected List connections() { 81 | return Connection.list(Person.class, Person.class); 82 | } 83 | 84 | } 85 | -------------------------------------------------------------------------------- /gremlin-objects/src/test/java/org/apache/tinkerpop/gremlin/object/edges/Traverses.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.tinkerpop.gremlin.object.edges; 20 | 21 | import org.apache.tinkerpop.gremlin.object.structure.Connection; 22 | import org.apache.tinkerpop.gremlin.object.structure.Edge; 23 | import org.apache.tinkerpop.gremlin.object.vertices.Software; 24 | 25 | import java.util.List; 26 | 27 | import lombok.Builder; 28 | import lombok.Data; 29 | import lombok.EqualsAndHashCode; 30 | import lombok.NoArgsConstructor; 31 | import lombok.experimental.Accessors; 32 | 33 | /** 34 | * The {@link Traverses} class represents the "traverses" edge. 35 | * 36 | * @author Karthick Sankarachary (http://github.com/karthicks) 37 | */ 38 | @Data 39 | @Builder 40 | @NoArgsConstructor 41 | @Accessors(fluent = true, chain = true) 42 | @EqualsAndHashCode(of = {}, callSuper = true) 43 | public class Traverses extends Edge { 44 | 45 | public static Traverses of() { 46 | return Traverses.builder().build(); 47 | } 48 | 49 | @Override 50 | protected List connections() { 51 | return Connection.list(Software.class, Software.class); 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /gremlin-objects/src/test/java/org/apache/tinkerpop/gremlin/object/edges/Uses.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.tinkerpop.gremlin.object.edges; 20 | 21 | import org.apache.tinkerpop.gremlin.object.reflect.Label; 22 | import org.apache.tinkerpop.gremlin.object.structure.Connection; 23 | import org.apache.tinkerpop.gremlin.object.structure.Edge; 24 | import org.apache.tinkerpop.gremlin.object.vertices.Person; 25 | import org.apache.tinkerpop.gremlin.object.vertices.Software; 26 | import org.apache.tinkerpop.gremlin.structure.Direction; 27 | 28 | import java.util.List; 29 | 30 | import lombok.AllArgsConstructor; 31 | import lombok.Builder; 32 | import lombok.Data; 33 | import lombok.EqualsAndHashCode; 34 | import lombok.NoArgsConstructor; 35 | import lombok.experimental.Accessors; 36 | 37 | /** 38 | * The {@link Uses} class represents the "uses" edge. 39 | * 40 | * @author Karthick Sankarachary (http://github.com/karthicks) 41 | */ 42 | @Data 43 | @Builder 44 | @NoArgsConstructor 45 | @AllArgsConstructor 46 | @Accessors(fluent = true, chain = true) 47 | @EqualsAndHashCode(of = {}, callSuper = true) 48 | public class Uses extends Edge { 49 | 50 | /** 51 | * Go to the {@link Software}s used by the currently selected {@link Person}s. 52 | */ 53 | public final static ToVertex Softwares = traversal -> traversal 54 | .outE(Label.of(Uses.class)) 55 | .toV(Direction.IN); 56 | /** 57 | * Go to the {@link Person}s using the currently selected {@link Software}s. 58 | */ 59 | public final static ToVertex People = traversal -> traversal 60 | .inE(Label.of(Uses.class)) 61 | .toV(Direction.OUT); 62 | 63 | /** 64 | * An enum field whose name is used as the value of the "skill" property. 65 | */ 66 | private Skill skill; 67 | 68 | public static Uses of(Skill skill) { 69 | return Uses.builder().skill(skill).build(); 70 | } 71 | 72 | @Override 73 | protected List connections() { 74 | return Connection.list(Person.class, Software.class); 75 | } 76 | 77 | public enum Skill { 78 | Novice, Beginner, Competent, Proficient, Expert, 79 | } 80 | 81 | } 82 | -------------------------------------------------------------------------------- /gremlin-objects/src/test/java/org/apache/tinkerpop/gremlin/object/graphs/Modern.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.tinkerpop.gremlin.object.graphs; 20 | 21 | import org.apache.tinkerpop.gremlin.object.edges.Created; 22 | import org.apache.tinkerpop.gremlin.object.edges.Knows; 23 | import org.apache.tinkerpop.gremlin.object.vertices.Person; 24 | import org.apache.tinkerpop.gremlin.object.vertices.Software; 25 | import org.apache.tinkerpop.gremlin.object.structure.Graph; 26 | 27 | import lombok.Data; 28 | 29 | /** 30 | * An object oriented representation of the {@link org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerFactory#createTheCrew} 31 | * graph. 32 | * 33 | *

34 | * Note that the "person" and "software" vertices are defined using the {@link Person} and {@link 35 | * Software} classes, as opposed to outlining their properties in-line. The "knows" and "created" 36 | * edges are represented as the {@link Knows} and {@link Created} classes respectively. 37 | * 38 | * @author Karthick Sankarachary (http://github.com/karthicks) 39 | */ 40 | @Data 41 | public class Modern { 42 | 43 | private final Graph graph; 44 | 45 | public Person marko, vadas, josh, peter; 46 | public Software lop, ripple, gremlin; 47 | 48 | public static Modern of(Graph graph) { 49 | Modern modern = new Modern(graph); 50 | modern.generateModern(); 51 | return modern; 52 | } 53 | 54 | private void generateModern() { 55 | graph 56 | .addVertex(Person.of("marko", 29)).as(this::setMarko) 57 | .addVertex(Person.of("vadas", 27)).as(this::setVadas) 58 | .addVertex(Software.of("lop")).as("lop") 59 | .addVertex(Software.of("ripple")).as("ripple") 60 | .addVertex(Person.of("josh", 32)).as("josh") 61 | .addEdge(Created.of(1.0d), "ripple") 62 | .addEdge(Created.of(0.4d), "lop") 63 | .addVertex(Person.of("peter", 35)).as("peter") 64 | .addEdge(Created.of(0.2d), "lop"); 65 | graph 66 | .addEdge(Knows.of(0.5d), marko, vadas) 67 | .addEdge(Knows.of(1.0d), marko, "josh") 68 | .addEdge(Created.of(0.4d), marko, "lop"); 69 | 70 | josh = graph.get("josh", Person.class); 71 | peter = graph.get("peter", Person.class); 72 | 73 | lop = graph.get("lop", Software.class); 74 | ripple = graph.get("ripple", Software.class); 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /gremlin-objects/src/test/java/org/apache/tinkerpop/gremlin/object/graphs/TheCrew.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.tinkerpop.gremlin.object.graphs; 20 | 21 | import org.apache.tinkerpop.gremlin.object.edges.Develops; 22 | import org.apache.tinkerpop.gremlin.object.vertices.Location; 23 | import org.apache.tinkerpop.gremlin.object.vertices.Person; 24 | import org.apache.tinkerpop.gremlin.object.vertices.Software; 25 | import org.apache.tinkerpop.gremlin.object.edges.Traverses; 26 | import org.apache.tinkerpop.gremlin.object.edges.Uses; 27 | import org.apache.tinkerpop.gremlin.object.structure.Graph; 28 | 29 | import lombok.Data; 30 | 31 | import static org.apache.tinkerpop.gremlin.object.edges.Uses.Skill.Competent; 32 | import static org.apache.tinkerpop.gremlin.object.edges.Uses.Skill.Expert; 33 | import static org.apache.tinkerpop.gremlin.object.edges.Uses.Skill.Proficient; 34 | 35 | /** 36 | * An object oriented representation of the {@link org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerFactory#createModern} 37 | * graph. 38 | * 39 | *

40 | * Note that the "person" vertices are defined using the {@link Person} class, as opposed to 41 | * outlining them in-line. Edges such as "develops" and "uses" have classes of their own. 42 | * 43 | *

44 | * Last, but not the least, the "locations" property on the {@link Person} vertex gets a class of 45 | * it's own. The value of "locations" is stored in {@link Location#name}, as it's qualified with 46 | * {@link org.apache.tinkerpop.gremlin.object.model.PropertyValue}. The rest of the fields in the 47 | * {@link Location} class, such as {@link Location#startTime} become its meta-properties. 48 | * 49 | * @author Karthick Sankarachary (http://github.com/karthicks) 50 | */ 51 | @Data 52 | public class TheCrew { 53 | 54 | private final Graph graph; 55 | 56 | public Person marko, stephen, matthias, daniel; 57 | public Software tinkergraph, gremlin; 58 | 59 | public Develops markoDevelopsGremlin; 60 | 61 | public static TheCrew of(Graph graph) { 62 | TheCrew crew = new TheCrew(graph); 63 | crew.generateTheCrew(); 64 | return crew; 65 | } 66 | 67 | public void generateTheCrew() { 68 | graph 69 | .addVertex(Software.of("tinkergraph")).as("tinkergraph") 70 | .addVertex(Software.of("gremlin")).as("gremlin") 71 | .addEdge(Traverses.of(), "tinkergraph"); 72 | graph 73 | .addVertex( 74 | Person.of("marko", 75 | Location.of("san diego", 1997, 2001), 76 | Location.of("santa cruz", 2001, 2004), 77 | Location.of("brussels", 2004, 2005), 78 | Location.of("santa fe", 2005))).as("marko") 79 | .addEdge(Develops.of(2009), "gremlin").as(this::setMarkoDevelopsGremlin) 80 | .addEdge(Develops.of(2010), "tinkergraph") 81 | .addEdge(Uses.of(Proficient), "gremlin") 82 | .addEdge(Uses.of(Expert), "tinkergraph") 83 | .addVertex( 84 | Person.of("stephen", 85 | Location.of("centreville", 1990, 2000), 86 | Location.of("dulles", 2000, 2006), 87 | Location.of("purcellville", 2006))).as("stephen") 88 | .addEdge(Develops.of(2010), "gremlin") 89 | .addEdge(Develops.of(2011), "tinkergraph") 90 | .addEdge(Uses.of(Expert), "gremlin") 91 | .addEdge(Uses.of(Proficient), "tinkergraph") 92 | .addVertex( 93 | Person.of("matthias", 94 | Location.of("bremen", 2004, 2007), 95 | Location.of("baltimore", 2007, 2011), 96 | Location.of("oakland", 2011, 2014), 97 | Location.of("seattle", 2014))).as("matthias") 98 | .addEdge(Develops.of(2012), "gremlin") 99 | .addEdge(Uses.of(Competent), "gremlin") 100 | .addEdge(Uses.of(Competent), "tinkergraph") 101 | .addVertex( 102 | Person.of("daniel", 103 | Location.of("spremberg", 1982, 2005), 104 | Location.of("kaiserslautern", 2005, 2009), 105 | Location.of("aachen", 2009))).as("daniel") 106 | .addEdge(Uses.of(Expert), "gremlin") 107 | .addEdge(Uses.of(Competent), "tinkergraph"); 108 | 109 | marko = graph.get("marko", Person.class); 110 | stephen = graph.get("stephen", Person.class); 111 | matthias = graph.get("matthias", Person.class); 112 | daniel = graph.get("daniel", Person.class); 113 | 114 | gremlin = graph.get("gremlin", Software.class); 115 | tinkergraph = graph.get("tinkergraph", Software.class); 116 | } 117 | 118 | } 119 | -------------------------------------------------------------------------------- /gremlin-objects/src/test/java/org/apache/tinkerpop/gremlin/object/provider/GraphFactoryTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.tinkerpop.gremlin.object.provider; 20 | 21 | import org.apache.tinkerpop.gremlin.object.structure.Graph; 22 | import org.apache.tinkerpop.gremlin.object.traversal.Query; 23 | import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; 24 | import org.junit.After; 25 | import org.junit.Before; 26 | import org.junit.Test; 27 | import org.junit.runner.RunWith; 28 | import org.junit.runners.Parameterized; 29 | 30 | import java.util.Arrays; 31 | import java.util.Collection; 32 | import java.util.concurrent.ExecutorService; 33 | import java.util.concurrent.ForkJoinPool; 34 | 35 | import lombok.SneakyThrows; 36 | 37 | import static org.apache.tinkerpop.gremlin.object.provider.GraphFactory.ShouldCache.EVERYTHING; 38 | import static org.apache.tinkerpop.gremlin.object.provider.GraphFactory.ShouldCache.NOTHING; 39 | import static org.apache.tinkerpop.gremlin.object.provider.GraphFactory.ShouldCache.THREAD_LOCAL; 40 | import static org.junit.Assert.assertEquals; 41 | import static org.junit.Assert.assertNotEquals; 42 | import static org.mockito.Mockito.mock; 43 | 44 | /** 45 | * The {@link GraphFactoryTest} defines sanity tests to ensure that the {@link Graph} and {@link 46 | * Query} instances provided by the {@link #factory()} method work. 47 | * 48 | * @author Karthick Sankarachary (http://github.com/karthicks) 49 | */ 50 | @RunWith(Parameterized.class) 51 | @SuppressWarnings("rawtypes") 52 | public class GraphFactoryTest { 53 | 54 | @Parameterized.Parameter 55 | public GraphFactory.ShouldCache shouldCache; 56 | private Graph graph; 57 | private Query query; 58 | private GraphTraversalSource g; 59 | private GraphFactory factory; 60 | private ExecutorService executorService; 61 | 62 | @Parameterized.Parameters(name = "ShouldCache({0})") 63 | public static Collection data() { 64 | return Arrays.asList(new Object[][]{ 65 | {EVERYTHING}, {THREAD_LOCAL}, {NOTHING} 66 | }); 67 | } 68 | 69 | protected GraphFactory factory() { 70 | if (factory == null) { 71 | g = mock(GraphTraversalSource.class); 72 | factory = GraphFactory.of(g, shouldCache); 73 | factory.clear(); 74 | } 75 | return factory; 76 | } 77 | 78 | @Before 79 | public void setUp() { 80 | executorService = new ForkJoinPool(); 81 | graph = factory().graph(); 82 | query = factory().query(); 83 | } 84 | 85 | @After 86 | public void tearDown() { 87 | factory = null; 88 | graph.close(); 89 | query.close(); 90 | } 91 | 92 | @Test 93 | @SneakyThrows 94 | public void testCacheBehavior() { 95 | switch (shouldCache) { 96 | case EVERYTHING: 97 | assertEquals(factory().graph(), graph); 98 | assertEquals(factory().query(), query); 99 | break; 100 | case THREAD_LOCAL: 101 | executorService.submit(() -> { 102 | assertNotEquals(factory().graph(), graph); 103 | assertNotEquals(factory().query(), query); 104 | }).get(); 105 | assertEquals(factory().graph(), graph); 106 | assertEquals(factory().query(), query); 107 | break; 108 | case NOTHING: 109 | default: 110 | assertNotEquals(factory().graph(), graph); 111 | assertNotEquals(factory().query(), query); 112 | break; 113 | } 114 | } 115 | } 116 | -------------------------------------------------------------------------------- /gremlin-objects/src/test/java/org/apache/tinkerpop/gremlin/object/reflect/ClassesTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.tinkerpop.gremlin.object.reflect; 20 | 21 | import org.apache.tinkerpop.gremlin.object.edges.Develops; 22 | import org.apache.tinkerpop.gremlin.object.vertices.Person; 23 | import org.apache.tinkerpop.gremlin.object.structure.Edge; 24 | import org.apache.tinkerpop.gremlin.object.structure.Vertex; 25 | import org.apache.tinkerpop.gremlin.object.traversal.library.HasKeys; 26 | import org.junit.Test; 27 | 28 | import java.util.ArrayList; 29 | import java.util.Arrays; 30 | import java.util.HashSet; 31 | import java.util.PriorityQueue; 32 | 33 | import static org.apache.tinkerpop.gremlin.object.reflect.Classes.is; 34 | import static org.apache.tinkerpop.gremlin.object.reflect.Classes.isCollection; 35 | import static org.apache.tinkerpop.gremlin.object.reflect.Classes.isEdge; 36 | import static org.apache.tinkerpop.gremlin.object.reflect.Classes.isElement; 37 | import static org.apache.tinkerpop.gremlin.object.reflect.Classes.isFunctional; 38 | import static org.apache.tinkerpop.gremlin.object.reflect.Classes.isList; 39 | import static org.apache.tinkerpop.gremlin.object.reflect.Classes.isSet; 40 | import static org.apache.tinkerpop.gremlin.object.reflect.Classes.isVertex; 41 | import static org.junit.Assert.assertFalse; 42 | import static org.junit.Assert.assertTrue; 43 | 44 | /** 45 | * Assert that the {@link Classes#is*} methods behave as expected. 46 | * 47 | * @author Karthick Sankarachary (http://github.com/karthicks) 48 | */ 49 | public class ClassesTest extends ReflectTest { 50 | 51 | @Test 52 | public void testIsElement() { 53 | assertTrue(isElement(Person.class)); 54 | assertTrue(isElement(Develops.class)); 55 | } 56 | 57 | @Test 58 | public void testIsVertex() { 59 | assertTrue(isVertex(Person.class)); 60 | assertFalse(isVertex(Develops.class)); 61 | } 62 | 63 | @Test 64 | public void testIsEdge() { 65 | assertFalse(isEdge(Person.class)); 66 | assertTrue(isEdge(Develops.class)); 67 | } 68 | 69 | @Test 70 | public void testIsList() { 71 | assertFalse(isList(Person.class)); 72 | assertTrue(isList(Arrays.asList(develops))); 73 | } 74 | 75 | @Test 76 | public void testIsSet() { 77 | assertTrue(isSet(new HashSet<>())); 78 | assertFalse(isSet(Person.class)); 79 | } 80 | 81 | @Test 82 | public void testIsCollection() { 83 | assertTrue(isCollection(new ArrayList<>())); 84 | assertFalse(isCollection(new PriorityQueue<>())); 85 | assertFalse(isCollection(Person.class)); 86 | } 87 | 88 | @Test 89 | public void testIsFunctional() { 90 | assertTrue(isFunctional(HasKeys.class)); 91 | assertFalse(isFunctional(Person.class)); 92 | } 93 | 94 | @Test 95 | public void testIsSomething() { 96 | assertTrue(is(Develops.class, Edge.class)); 97 | assertTrue(is(develops, Edge.class)); 98 | assertTrue(is(Develops.class, develops)); 99 | assertFalse(is(Develops.class, Vertex.class)); 100 | assertFalse(is(develops, Vertex.class)); 101 | assertFalse(is(Develops.class, marko)); 102 | } 103 | 104 | } 105 | -------------------------------------------------------------------------------- /gremlin-objects/src/test/java/org/apache/tinkerpop/gremlin/object/reflect/KeysTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.tinkerpop.gremlin.object.reflect; 20 | 21 | import org.apache.tinkerpop.gremlin.object.edges.Develops; 22 | import org.apache.tinkerpop.gremlin.object.vertices.Person; 23 | import org.apache.tinkerpop.gremlin.structure.T; 24 | import org.junit.Before; 25 | import org.junit.Test; 26 | 27 | import java.lang.reflect.Field; 28 | import java.util.Arrays; 29 | import java.util.HashMap; 30 | 31 | import static org.apache.tinkerpop.gremlin.object.reflect.Fields.field; 32 | import static org.apache.tinkerpop.gremlin.object.reflect.Keys.hasPrimaryKeys; 33 | import static org.apache.tinkerpop.gremlin.object.reflect.Keys.id; 34 | import static org.apache.tinkerpop.gremlin.object.reflect.Keys.isOrderingKey; 35 | import static org.apache.tinkerpop.gremlin.object.reflect.Keys.isPrimaryKey; 36 | import static org.apache.tinkerpop.gremlin.object.reflect.Keys.orderingKeyFields; 37 | import static org.apache.tinkerpop.gremlin.object.reflect.Keys.primaryKeyFields; 38 | import static org.apache.tinkerpop.gremlin.object.reflect.Keys.primaryKeyNames; 39 | import static org.junit.Assert.assertEquals; 40 | import static org.junit.Assert.assertFalse; 41 | import static org.junit.Assert.assertTrue; 42 | 43 | /** 44 | * Assert that {@link Keys} finds the fields annotated 45 | * 46 | * @author Karthick Sankarachary (http://github.com/karthicks) 47 | */ 48 | public class KeysTest extends ReflectTest { 49 | 50 | private Field personName; 51 | private Field personAge; 52 | private Field personTitles; 53 | 54 | @Before 55 | public void setUp() { 56 | super.setUp(); 57 | personName = field(Person.class, "name"); 58 | personAge = field(Person.class, "age"); 59 | personTitles = field(Person.class, "titles"); 60 | } 61 | 62 | @Test 63 | public void testIsPrimaryKey() { 64 | assertTrue(isPrimaryKey(personName)); 65 | assertFalse(isPrimaryKey(personAge)); 66 | assertFalse(isPrimaryKey(personTitles)); 67 | } 68 | 69 | @Test 70 | public void testIsOrderingKey() { 71 | assertFalse(isOrderingKey(personName)); 72 | assertTrue(isOrderingKey(personAge)); 73 | assertFalse(isOrderingKey(personTitles)); 74 | } 75 | 76 | @Test 77 | public void testPrimaryKeyFields() { 78 | assertEquals(Arrays.asList(personName), primaryKeyFields(Person.class)); 79 | assertTrue(primaryKeyFields(Develops.class).isEmpty()); 80 | } 81 | 82 | @Test 83 | public void testHasPrimaryKey() { 84 | assertTrue(hasPrimaryKeys(Person.class)); 85 | assertFalse(hasPrimaryKeys(Develops.class)); 86 | } 87 | 88 | @Test 89 | public void testOrderingKeyFields() { 90 | assertEquals(Arrays.asList(personAge), orderingKeyFields(Person.class)); 91 | assertTrue(orderingKeyFields(Develops.class).isEmpty()); 92 | } 93 | 94 | @Test 95 | public void testPrimaryKeyNames() { 96 | assertEquals(Arrays.asList("name"), primaryKeyNames(Person.class)); 97 | assertTrue(primaryKeyNames(Develops.class).isEmpty()); 98 | } 99 | 100 | @Test(expected = IllegalArgumentException.class) 101 | public void testNullPrimaryKey() { 102 | marko.name(null); 103 | id(marko); 104 | } 105 | 106 | @Test(expected = IllegalArgumentException.class) 107 | public void testNullOrderingKey() { 108 | Primitives.allowDefaultKeys = false; 109 | marko.age(0); 110 | id(marko); 111 | } 112 | 113 | @Test 114 | @SuppressWarnings("serial") 115 | public void testIdIsInternalOrGenerated() { 116 | assertEquals(new HashMap() { 117 | { 118 | put(T.label.getAccessor(), marko.label()); 119 | put("name", "marko"); 120 | put("age", 29); 121 | } 122 | }, id(marko)); 123 | } 124 | 125 | } 126 | -------------------------------------------------------------------------------- /gremlin-objects/src/test/java/org/apache/tinkerpop/gremlin/object/reflect/LabelTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.tinkerpop.gremlin.object.reflect; 20 | 21 | import org.apache.tinkerpop.gremlin.object.edges.Develops; 22 | import org.apache.tinkerpop.gremlin.object.vertices.Person; 23 | import org.apache.tinkerpop.gremlin.object.structure.Vertex; 24 | import org.junit.Test; 25 | 26 | import static org.apache.tinkerpop.gremlin.object.reflect.Label.of; 27 | import static org.junit.Assert.assertEquals; 28 | 29 | /** 30 | * Assert that {@link Label} determines the label of the element as expected. 31 | * 32 | * @author Karthick Sankarachary (http://github.com/karthicks) 33 | */ 34 | public class LabelTest extends ReflectTest { 35 | 36 | @Test 37 | public void testVertexLabelWithAlias() { 38 | assertEquals("person", of(Person.class)); 39 | assertEquals("person", of(marko)); 40 | } 41 | 42 | @Test 43 | public void testEdgeLabelWithoutAlias() { 44 | assertEquals("develops", of(Develops.class)); 45 | assertEquals("develops", of(develops)); 46 | } 47 | 48 | @Test 49 | public void testVertexLabelWithoutAlias() { 50 | assertEquals("City", of(City.class)); 51 | } 52 | 53 | private static class City extends Vertex { 54 | 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /gremlin-objects/src/test/java/org/apache/tinkerpop/gremlin/object/reflect/ParserTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.tinkerpop.gremlin.object.reflect; 20 | 21 | import org.apache.tinkerpop.gremlin.object.edges.Develops; 22 | import org.apache.tinkerpop.gremlin.object.vertices.Person; 23 | import org.apache.tinkerpop.gremlin.structure.util.detached.DetachedEdge; 24 | import org.apache.tinkerpop.gremlin.structure.util.detached.DetachedVertex; 25 | import org.junit.Test; 26 | 27 | import java.util.ArrayList; 28 | import java.util.Arrays; 29 | import java.util.Collections; 30 | import java.util.HashMap; 31 | 32 | import static org.apache.tinkerpop.gremlin.object.reflect.Parser.as; 33 | import static org.apache.tinkerpop.gremlin.object.reflect.Parser.isPropertyValue; 34 | import static org.apache.tinkerpop.gremlin.object.reflect.Fields.field; 35 | import static org.apache.tinkerpop.gremlin.object.structure.Graph.Should; 36 | import static org.apache.tinkerpop.gremlin.object.structure.Graph.Should.MERGE; 37 | import static org.junit.Assert.assertEquals; 38 | import static org.junit.Assert.assertFalse; 39 | import static org.junit.Assert.assertTrue; 40 | 41 | /** 42 | * Assert that {@link Parser} materializes {@link org.apache.tinkerpop.gremlin.object.structure.Element} 43 | * objects from underlying {@link org.apache.tinkerpop.gremlin.structure.Element} structures as 44 | * expected. 45 | * 46 | * @author Karthick Sankarachary (http://github.com/karthicks) 47 | */ 48 | @SuppressWarnings({"unchecked", "serial"}) 49 | public class ParserTest extends ReflectTest { 50 | 51 | @Test 52 | public void testIsPropertyValue() { 53 | assertTrue(isPropertyValue(field(location, "name"))); 54 | assertFalse(isPropertyValue(field(marko, "age"))); 55 | } 56 | 57 | @Test 58 | public void testAsEnum() { 59 | assertEquals(MERGE, as("MERGE", Should.class)); 60 | } 61 | 62 | @Test 63 | public void testAsItself() { 64 | assertEquals(MERGE, as(MERGE, Should.class)); 65 | } 66 | 67 | @Test(expected = ClassCastException.class) 68 | public void testAsUnhandled() { 69 | assertEquals(Collections.emptyList(), as(new ArrayList<>(), Person.class)); 70 | } 71 | 72 | @Test 73 | public void testAsVertex() { 74 | assertEquals(marko, as(new DetachedVertex( 75 | 1, "person", new HashMap() { 76 | { 77 | put("name", Arrays.asList(new HashMap() { 78 | { 79 | put("value", "marko"); 80 | } 81 | })); 82 | put("age", Arrays.asList(new HashMap() { 83 | { 84 | put("value", 29); 85 | } 86 | })); 87 | } 88 | }), Person.class)); 89 | } 90 | 91 | @Test 92 | public void testAsEdge() { 93 | assertEquals(develops, as(new DetachedEdge( 94 | null, Label.of(Develops.class), new HashMap() { 95 | { 96 | put("since", develops.since()); 97 | } 98 | }, null, null, null, null), Develops.class)); 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /gremlin-objects/src/test/java/org/apache/tinkerpop/gremlin/object/reflect/PrimitivesTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.tinkerpop.gremlin.object.reflect; 20 | 21 | import org.apache.tinkerpop.gremlin.object.structure.Graph; 22 | import org.junit.Before; 23 | import org.junit.Test; 24 | 25 | import java.time.Instant; 26 | import java.util.Date; 27 | import java.util.Set; 28 | 29 | import static org.apache.tinkerpop.gremlin.object.vertices.Location.year; 30 | import static org.apache.tinkerpop.gremlin.object.reflect.Primitives.isPrimitive; 31 | import static org.apache.tinkerpop.gremlin.object.reflect.Primitives.isTimeType; 32 | import static org.apache.tinkerpop.gremlin.object.reflect.Primitives.toTimeType; 33 | import static org.junit.Assert.assertEquals; 34 | import static org.junit.Assert.assertFalse; 35 | import static org.junit.Assert.assertTrue; 36 | 37 | /** 38 | * Assert that {@link Primitives} identifies the registered primitive types properly. It also tests 39 | * that time properties can be converted between compatible types. 40 | * 41 | * @author Karthick Sankarachary (http://github.com/karthicks) 42 | */ 43 | public class PrimitivesTest extends ReflectTest { 44 | 45 | private Instant now; 46 | 47 | @Before 48 | public void setUp() { 49 | now = year(2017); 50 | } 51 | 52 | @Test 53 | public void testIsPrimitiveType() { 54 | assertTrue(isPrimitive(String.class)); 55 | assertTrue(isPrimitive(Graph.Should.class)); 56 | assertFalse(isPrimitive(Set.class)); 57 | } 58 | 59 | @Test 60 | public void testIsTimeType() { 61 | assertTrue(isTimeType(Instant.class)); 62 | assertFalse(isTimeType(Integer.class)); 63 | } 64 | 65 | @Test 66 | public void testToDateTime() { 67 | assertEquals(Date.from(now), toTimeType(now, Date.class)); 68 | assertEquals(Date.from(now), toTimeType(now.toEpochMilli(), Date.class)); 69 | } 70 | 71 | @Test 72 | public void testToInstantTime() { 73 | assertEquals(now, toTimeType(Date.from(now), Instant.class)); 74 | assertEquals(now, toTimeType(now.toEpochMilli(), Instant.class)); 75 | } 76 | 77 | @Test 78 | public void testToEpochTime() { 79 | assertEquals(Long.valueOf(now.toEpochMilli()), toTimeType(now, Long.class)); 80 | assertEquals(Long.valueOf(now.toEpochMilli()), toTimeType(Date.from(now), Long.class)); 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /gremlin-objects/src/test/java/org/apache/tinkerpop/gremlin/object/reflect/PropertiesTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.tinkerpop.gremlin.object.reflect; 20 | 21 | import org.apache.tinkerpop.gremlin.structure.Property; 22 | import org.junit.Test; 23 | 24 | import java.time.Instant; 25 | import java.util.Arrays; 26 | 27 | import static org.apache.tinkerpop.gremlin.object.vertices.Location.year; 28 | import static org.apache.tinkerpop.gremlin.object.reflect.Properties.all; 29 | import static org.apache.tinkerpop.gremlin.object.reflect.Properties.id; 30 | import static org.apache.tinkerpop.gremlin.object.reflect.Properties.list; 31 | import static org.apache.tinkerpop.gremlin.object.reflect.Properties.names; 32 | import static org.apache.tinkerpop.gremlin.object.reflect.Properties.of; 33 | import static org.apache.tinkerpop.gremlin.object.reflect.Properties.values; 34 | import static org.junit.Assert.assertArrayEquals; 35 | import static org.junit.Assert.assertEquals; 36 | 37 | /** 38 | * Assert that {@link Properties} lists the key and value of properties of any given kind. 39 | * 40 | * @author Karthick Sankarachary (http://github.com/karthicks) 41 | */ 42 | public class PropertiesTest extends ReflectTest { 43 | 44 | @Test 45 | public void testPropertyId() { 46 | assertArrayEquals(new Object[] {"name", "marko", "age", 29}, id(marko)); 47 | assertArrayEquals(new Object[] {}, id(develops)); 48 | } 49 | 50 | @Test 51 | public void testPropertyAll() { 52 | assertArrayEquals(new Object[] {"name", "marko", "age", 29}, all(marko)); 53 | assertArrayEquals(new Object[] {"since", year(2000)}, all(develops)); 54 | } 55 | 56 | @Test 57 | public void testPropertyOf() { 58 | assertArrayEquals(new Object[] {}, of(marko)); 59 | assertArrayEquals(new Object[] {"since", year(2000)}, of(develops)); 60 | } 61 | 62 | @Test 63 | public void testPropertyNames() { 64 | assertEquals(Arrays.asList("name", "age", "locations", "titles"), names(marko)); 65 | assertEquals(Arrays.asList("since"), names(develops)); 66 | } 67 | 68 | @Test 69 | public void testPropertyValues() { 70 | assertEquals(Arrays.asList("san diego", "startTime", year(2000)), values(location)); 71 | assertEquals(Arrays.asList("since", year(2000)), values(develops)); 72 | 73 | } 74 | 75 | @Test 76 | @SuppressWarnings("unchecked") 77 | public void testPropertyLists() { 78 | Property since = list(of(develops)).get(0); 79 | assertEquals("since", since.key()); 80 | assertEquals(year(2000), since.value()); 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /gremlin-objects/src/test/java/org/apache/tinkerpop/gremlin/object/reflect/ReflectTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.tinkerpop.gremlin.object.reflect; 20 | 21 | import org.apache.tinkerpop.gremlin.object.edges.Develops; 22 | import org.apache.tinkerpop.gremlin.object.vertices.Location; 23 | import org.apache.tinkerpop.gremlin.object.vertices.Person; 24 | import org.junit.Before; 25 | 26 | import java.lang.reflect.Field; 27 | 28 | import static org.apache.tinkerpop.gremlin.object.reflect.Fields.field; 29 | 30 | /** 31 | * This acts as a base of all tests in the reflect package. 32 | * 33 | * @author Karthick Sankarachary (http://github.com/karthicks) 34 | */ 35 | public abstract class ReflectTest { 36 | 37 | protected Person marko; 38 | protected Develops develops; 39 | protected Location location; 40 | 41 | protected Field name; 42 | protected Field locations; 43 | 44 | @Before 45 | public void setUp() { 46 | marko = Person.of("marko", 29); 47 | develops = Develops.of(2000); 48 | location = Location.of("san diego", 2000); 49 | name = field(marko, "name"); 50 | locations = field(marko, "locations"); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /gremlin-objects/src/test/java/org/apache/tinkerpop/gremlin/object/structure/EdgeTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.tinkerpop.gremlin.object.structure; 20 | 21 | import org.apache.tinkerpop.gremlin.object.edges.Develops; 22 | import org.apache.tinkerpop.gremlin.object.vertices.Person; 23 | import org.apache.tinkerpop.gremlin.object.vertices.Software; 24 | import org.junit.Test; 25 | 26 | import static org.junit.Assert.assertFalse; 27 | import static org.junit.Assert.assertTrue; 28 | 29 | /** 30 | * Assert that the {@link Edge#connects} methods work. 31 | * 32 | * @author Karthick Sankarachary (http://github.com/karthicks) 33 | */ 34 | public class EdgeTest extends ElementTest { 35 | 36 | @Override 37 | protected Develops createElement() { 38 | return Develops.of(2010); 39 | } 40 | 41 | @Override 42 | protected Develops anotherElement() { 43 | return Develops.of(2017); 44 | } 45 | 46 | @Test 47 | public void testConnectsProperly() { 48 | Develops develops = createElement(); 49 | 50 | assertTrue(develops.connects(Person.class, Software.class)); 51 | assertFalse(develops.connects(Person.class, Person.class)); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /gremlin-objects/src/test/java/org/apache/tinkerpop/gremlin/object/structure/ElementTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.tinkerpop.gremlin.object.structure; 20 | 21 | import org.apache.tinkerpop.gremlin.object.vertices.Location; 22 | import org.apache.tinkerpop.gremlin.object.reflect.Label; 23 | import org.apache.tinkerpop.gremlin.object.traversal.ElementTo; 24 | import org.apache.tinkerpop.gremlin.object.traversal.TraversalTest; 25 | import org.apache.tinkerpop.gremlin.object.traversal.library.Count; 26 | import org.apache.tinkerpop.gremlin.object.traversal.library.HasLabel; 27 | import org.junit.Test; 28 | 29 | import java.util.Arrays; 30 | import java.util.List; 31 | 32 | import static org.apache.tinkerpop.gremlin.object.structure.Element.compose; 33 | import static org.junit.Assert.assertEquals; 34 | import static org.junit.Assert.assertFalse; 35 | import static org.junit.Assert.assertNotEquals; 36 | import static org.junit.Assert.assertTrue; 37 | import static org.mockito.Mockito.times; 38 | import static org.mockito.Mockito.verify; 39 | 40 | /** 41 | * Verify that the sub-traversals defined in the {@link Element} class works as expected. In 42 | * addition, it also checks the {@link #equals} method. 43 | * 44 | * @author Karthick Sankarachary (http://github.com/karthicks) 45 | */ 46 | public class ElementTest extends TraversalTest { 47 | 48 | @SuppressWarnings("unchecked") 49 | protected O createElement() { 50 | return (O) Location.of("San Francisco", 2000); 51 | } 52 | 53 | @SuppressWarnings("unchecked") 54 | protected O anotherElement() { 55 | return (O) Location.of("New York", 2000); 56 | } 57 | 58 | @Test 59 | public void testWithIdTraversal() { 60 | Element element = createElement(); 61 | 62 | traverse(element.withId); 63 | 64 | verify(traversal, times(1)).hasId(element.id()); 65 | } 66 | 67 | @Test 68 | public void testWithLabelTraversal() { 69 | Element element = createElement(); 70 | 71 | traverse(element.withLabel); 72 | 73 | verify(traversal, times(1)).hasLabel(element.label()); 74 | } 75 | 76 | @Test 77 | public void testComposeTraversals() { 78 | Element element = createElement(); 79 | ElementTo counter = compose( 80 | HasLabel.of(element), 81 | Count.of()); 82 | 83 | traverse(counter); 84 | 85 | verify(traversal, times(1)).hasLabel(element.label()); 86 | verify(traversal, times(1)).count(); 87 | } 88 | 89 | @Test 90 | public void testLabelExists() { 91 | Element element = createElement(); 92 | 93 | assertEquals(Label.of(element), element.label()); 94 | } 95 | 96 | @Test 97 | public void testExistsIn() { 98 | Element element = createElement(); 99 | Element other = anotherElement(); 100 | 101 | assertTrue(element.existsIn(Arrays.asList(element))); 102 | assertFalse(element.existsIn(Arrays.asList(other))); 103 | } 104 | 105 | @Test 106 | public void testPossessionApostrophe() { 107 | Element element = createElement(); 108 | List userSuppliedId = Arrays.asList(1L, 2L, 3L); 109 | element.setUserSuppliedId(userSuppliedId); 110 | assertEquals(userSuppliedId, element.id()); 111 | 112 | traverse(element.s("userSuppliedId")); 113 | 114 | verify(traversal, times(1)).has(element.label(), "id", element.id()); 115 | } 116 | 117 | @Test 118 | public void testEqualsByEverything() { 119 | Element original = createElement(); 120 | Element duplicate = createElement(); 121 | 122 | assertEquals(duplicate, original); 123 | 124 | original.setUserSuppliedId("the original identity"); 125 | duplicate.setUserSuppliedId("a duplicate identity"); 126 | assertNotEquals(duplicate, original); 127 | } 128 | 129 | } 130 | -------------------------------------------------------------------------------- /gremlin-objects/src/test/java/org/apache/tinkerpop/gremlin/object/structure/GraphTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.tinkerpop.gremlin.object.structure; 20 | 21 | import org.junit.After; 22 | import org.junit.Before; 23 | import org.junit.runner.RunWith; 24 | import org.junit.runners.Parameterized; 25 | 26 | import java.util.Arrays; 27 | import java.util.Collection; 28 | 29 | import lombok.Data; 30 | import lombok.extern.slf4j.Slf4j; 31 | 32 | import static org.apache.tinkerpop.gremlin.object.structure.Graph.Should.CREATE; 33 | import static org.apache.tinkerpop.gremlin.object.structure.Graph.Should.IGNORE; 34 | import static org.apache.tinkerpop.gremlin.object.structure.Graph.Should.INSERT; 35 | import static org.apache.tinkerpop.gremlin.object.structure.Graph.Should.MERGE; 36 | import static org.apache.tinkerpop.gremlin.object.structure.Graph.Should.REPLACE; 37 | 38 | /** 39 | * This acts as a base class for all {@link Graph} related tests. It parameterizes the {@link 40 | * #should} variable, and runs all tests for each of the possible values of {@link Graph.Should}. 41 | * 42 | * @author Karthick Sankarachary (http://github.com/karthicks) 43 | */ 44 | @Data 45 | @Slf4j 46 | @RunWith(Parameterized.class) 47 | public abstract class GraphTest { 48 | 49 | protected final Graph graph; 50 | @Parameterized.Parameter 51 | public Graph.Should should; 52 | 53 | protected GraphTest(Graph graph) { 54 | this.graph = graph; 55 | } 56 | 57 | @Parameterized.Parameters(name = "should({0})") 58 | public static Collection data() { 59 | return Arrays.asList(new Object[][] { 60 | {CREATE}, {MERGE}, {REPLACE}, {IGNORE}, {INSERT} 61 | }); 62 | } 63 | 64 | @Before 65 | public void setUp() { 66 | this.graph.should(should); 67 | graph.drop(); 68 | } 69 | 70 | @After 71 | public void tearDown() { 72 | graph.reset(); 73 | graph.drop(); 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /gremlin-objects/src/test/java/org/apache/tinkerpop/gremlin/object/structure/SubGraphTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.tinkerpop.gremlin.object.structure; 20 | 21 | import org.apache.tinkerpop.gremlin.object.graphs.Modern; 22 | import org.apache.tinkerpop.gremlin.object.graphs.TheCrew; 23 | import org.apache.tinkerpop.gremlin.object.vertices.Person; 24 | import org.apache.tinkerpop.gremlin.object.vertices.Software; 25 | import org.junit.Before; 26 | import org.junit.Test; 27 | 28 | import java.util.function.Consumer; 29 | 30 | import static org.mockito.Matchers.any; 31 | import static org.mockito.Matchers.anyString; 32 | import static org.mockito.Matchers.eq; 33 | import static org.mockito.Mockito.mock; 34 | import static org.mockito.Mockito.times; 35 | import static org.mockito.Mockito.verify; 36 | import static org.mockito.Mockito.when; 37 | 38 | /** 39 | * Verify that the sub-graphs can be defined and composed as expected. 40 | * 41 | * @author Karthick Sankarachary (http://github.com/karthicks) 42 | */ 43 | @SuppressWarnings({"rawtypes", "unchecked"}) 44 | public class SubGraphTest { 45 | 46 | private Graph graph; 47 | private Person person; 48 | private Software software; 49 | 50 | @Before 51 | public void setUp() { 52 | graph = mock(Graph.class); 53 | person = mock(Person.class); 54 | software = mock(Software.class); 55 | 56 | when(graph.addVertex(any())).thenReturn(graph); 57 | when(graph.addEdge(any(Edge.class), anyString())).thenReturn(graph); 58 | when(graph.addEdge(any(Edge.class), any(Vertex.class), any(Vertex.class))).thenReturn(graph); 59 | when(graph.addEdge(any(Edge.class), any(Vertex.class), anyString())).thenReturn(graph); 60 | when(graph.as(anyString())).thenReturn(graph); 61 | when(graph.as(any(Consumer.class))).thenReturn(graph); 62 | 63 | when(graph.get(eq("marko"), any(Class.class))).thenReturn(person); 64 | when(graph.get(eq("stephen"), any(Class.class))).thenReturn(person); 65 | when(graph.get(eq("matthias"), any(Class.class))).thenReturn(person); 66 | when(graph.get(eq("daniel"), any(Class.class))).thenReturn(person); 67 | 68 | when(graph.get(eq("gremlin"), any(Class.class))).thenReturn(software); 69 | when(graph.get(eq("tinkergraph"), any(Class.class))).thenReturn(software); 70 | } 71 | 72 | @Test 73 | public void testSubGraphChange() { 74 | SubGraph createCrew = graph -> 75 | TheCrew.of(graph).getGraph(); 76 | 77 | createCrew.apply(graph); 78 | 79 | verify(graph, times(6)).addVertex(any(Vertex.class)); 80 | verify(graph, times(14)).addEdge(any(Edge.class), anyString()); 81 | verify(graph, times(6)).as(anyString()); 82 | verify(graph, times(6)).get(anyString(), any(Class.class)); 83 | } 84 | 85 | @Test 86 | public void testSubGraphCompose() { 87 | SubGraph createCrew = graph -> 88 | TheCrew.of(graph).getGraph(); 89 | SubGraph createModern = graph -> 90 | Modern.of(graph).getGraph(); 91 | 92 | createCrew.chain(createModern).apply(graph); 93 | 94 | verify(graph, times(12)).addVertex(any(Vertex.class)); 95 | verify(graph, times(17)).addEdge(any(Edge.class), anyString()); 96 | verify(graph, times(2)).addEdge(any(Edge.class), any(Vertex.class), anyString()); 97 | verify(graph, times(1)).addEdge(any(Edge.class), any(Vertex.class), any(Vertex.class)); 98 | verify(graph, times(10)).as(anyString()); 99 | verify(graph, times(10)).get(anyString(), any(Class.class)); 100 | } 101 | 102 | } 103 | -------------------------------------------------------------------------------- /gremlin-objects/src/test/java/org/apache/tinkerpop/gremlin/object/structure/VertexTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.tinkerpop.gremlin.object.structure; 20 | 21 | import org.apache.tinkerpop.gremlin.object.vertices.Location; 22 | import org.apache.tinkerpop.gremlin.object.vertices.Person; 23 | import org.junit.Test; 24 | 25 | /** 26 | * Verify that the helper methods in the {@link Vertex} class work as expected. 27 | * 28 | * @author Karthick Sankarachary (http://github.com/karthicks) 29 | */ 30 | public class VertexTest extends ElementTest { 31 | 32 | @Override 33 | protected Person createElement() { 34 | return Person.of("marko", 29, Location.of("san diego", 1997, 2001), 35 | Location.of("santa cruz", 2001, 2004), 36 | Location.of("brussels", 2004, 2005), 37 | Location.of("santa fe", 2005)); 38 | } 39 | 40 | @Override 41 | protected Person anotherElement() { 42 | return Person.of("daniel", 43 | Location.of("spremberg", 1982, 2005), 44 | Location.of("kaiserslautern", 2005, 2009), 45 | Location.of("aachen", 2009)); 46 | } 47 | 48 | @Test(expected = IllegalStateException.class) 49 | public void testCannotDeleteDetachedVertex() { 50 | Person person = createElement(); 51 | person.remove(); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /gremlin-objects/src/test/java/org/apache/tinkerpop/gremlin/object/traversal/ObjectQueryTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.tinkerpop.gremlin.object.traversal; 20 | 21 | import org.apache.tinkerpop.gremlin.object.vertices.Person; 22 | import org.apache.tinkerpop.gremlin.object.model.PrimaryKey; 23 | import org.apache.tinkerpop.gremlin.object.traversal.library.HasKeys; 24 | import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal; 25 | import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; 26 | import org.apache.tinkerpop.gremlin.process.traversal.step.util.BulkSet; 27 | import org.apache.tinkerpop.gremlin.structure.Vertex; 28 | import org.apache.tinkerpop.gremlin.structure.util.detached.DetachedVertex; 29 | import org.apache.tinkerpop.gremlin.util.function.BulkSetSupplier; 30 | import org.junit.Before; 31 | import org.junit.Test; 32 | 33 | import java.util.Arrays; 34 | import java.util.HashMap; 35 | import java.util.List; 36 | 37 | import lombok.Data; 38 | import lombok.NoArgsConstructor; 39 | import lombok.extern.slf4j.Slf4j; 40 | 41 | import static org.junit.Assert.assertEquals; 42 | import static org.mockito.Matchers.any; 43 | import static org.mockito.Matchers.anyString; 44 | import static org.mockito.Mockito.mock; 45 | import static org.mockito.Mockito.when; 46 | 47 | /** 48 | * Verify that the {@link ObjectQuery} executes queries and returns objects as expected. The 49 | * provider of the {@link GraphTraversalSource} is mocked, as are the gremlin {@link Vertex}s. 50 | * 51 | * @author Karthick Sankarachary (http://github.com/karthicks) 52 | */ 53 | @Data 54 | @Slf4j 55 | @NoArgsConstructor 56 | @SuppressWarnings({"unchecked", "rawtypes", "serial"}) 57 | public class ObjectQueryTest { 58 | 59 | protected ObjectQuery query; 60 | 61 | protected GraphTraversalSource g; 62 | 63 | protected GraphTraversal traversal; 64 | 65 | protected Person marko; 66 | 67 | protected Vertex vertex; 68 | 69 | @Before 70 | public void setUp() { 71 | marko = Person.of("marko"); 72 | vertex = new DetachedVertex( 73 | 1, "person", new HashMap() { 74 | { 75 | put("name", Arrays.asList(new HashMap() { 76 | { 77 | put("value", "marko"); 78 | } 79 | })); 80 | } 81 | }); 82 | 83 | g = mock(GraphTraversalSource.class); 84 | traversal = mock(GraphTraversal.class); 85 | 86 | when(g.V()).thenReturn(traversal); 87 | 88 | query = new ObjectQuery(g); 89 | } 90 | 91 | @Test 92 | @SuppressWarnings("cast") 93 | public void testQueryByAnyTraversal() { 94 | when(traversal.hasLabel(anyString())).thenReturn(traversal); 95 | when(traversal.has(anyString(), (Object) any())).thenReturn(traversal); 96 | BulkSet bulkSet = BulkSetSupplier.instance().get(); 97 | bulkSet.add(vertex); 98 | when(traversal.toBulkSet()).thenReturn(bulkSet); 99 | 100 | Person actual = query 101 | .by(g -> g.V().hasLabel(marko.label()).has("name", marko.name())) 102 | .one(Person.class); 103 | 104 | assertEquals(marko, actual); 105 | } 106 | 107 | @Test 108 | @SuppressWarnings("cast") 109 | public void testQueryBySubTraversals() { 110 | when(traversal.hasLabel(anyString())).thenReturn(traversal); 111 | when(traversal.has(anyString(), (Object) any())).thenReturn(traversal); 112 | BulkSet bulkSet = BulkSetSupplier.instance().get(); 113 | bulkSet.add(vertex); 114 | when(traversal.toBulkSet()).thenReturn(bulkSet); 115 | 116 | List actuals = query 117 | .by(HasKeys.of(marko, PrimaryKey.class)) 118 | .list(Person.class); 119 | 120 | assertEquals(Arrays.asList(marko), actuals); 121 | } 122 | } 123 | -------------------------------------------------------------------------------- /gremlin-objects/src/test/java/org/apache/tinkerpop/gremlin/object/traversal/TraversalTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.tinkerpop.gremlin.object.traversal; 20 | 21 | import org.apache.tinkerpop.gremlin.object.model.PrimaryKey; 22 | import org.apache.tinkerpop.gremlin.object.structure.Connection; 23 | import org.apache.tinkerpop.gremlin.object.structure.Edge; 24 | import org.apache.tinkerpop.gremlin.object.structure.Vertex; 25 | import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal; 26 | import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; 27 | import org.apache.tinkerpop.gremlin.structure.Element; 28 | import org.junit.Before; 29 | 30 | import java.util.List; 31 | 32 | import lombok.AllArgsConstructor; 33 | import lombok.Builder; 34 | import lombok.Data; 35 | import lombok.EqualsAndHashCode; 36 | import lombok.RequiredArgsConstructor; 37 | 38 | import static org.mockito.Matchers.any; 39 | import static org.mockito.Matchers.anyString; 40 | import static org.mockito.Mockito.mock; 41 | import static org.mockito.Mockito.when; 42 | 43 | /** 44 | * An abstraction that serves as the base for all test cases under the library package. It provides 45 | * a mocked {@link GraphTraversal}, with certain {@link org.mockito.Mockito#when}s applied. 46 | * 47 | * @author Karthick Sankarachary (http://github.com/karthicks) 48 | */ 49 | @SuppressWarnings("unchecked") 50 | public abstract class TraversalTest { 51 | 52 | protected GraphTraversalSource g; 53 | protected GraphTraversal traversal; 54 | 55 | protected City sanFrancisco; 56 | 57 | @Before 58 | public void setUp() { 59 | sanFrancisco = City.of("San Francisco"); 60 | traversal = (GraphTraversal) mock(GraphTraversal.class); 61 | when(traversal.property(anyString(), any())).thenReturn(traversal); 62 | when(traversal.hasLabel(anyString())).thenReturn(traversal); 63 | when(traversal.count()).thenReturn((GraphTraversal) traversal); 64 | g = mock(GraphTraversalSource.class); 65 | when(g.V()).thenReturn((GraphTraversal) traversal); 66 | when(g.addV(anyString())).thenReturn((GraphTraversal) traversal); 67 | } 68 | 69 | protected GraphTraversal traverse(AnyTraversal anyTraversal) { 70 | return (GraphTraversal) anyTraversal.apply(g); 71 | } 72 | 73 | @SuppressWarnings("rawtypes") 74 | protected GraphTraversal traverse(SubTraversal subTraversal) { 75 | return (GraphTraversal) subTraversal.apply(traversal); 76 | } 77 | 78 | @Data 79 | @Builder 80 | @AllArgsConstructor 81 | @EqualsAndHashCode(callSuper = true) 82 | public static class City extends Vertex { 83 | 84 | @PrimaryKey 85 | private String name; 86 | private int population; 87 | 88 | public static City of(String name) { 89 | return City.builder().name(name).build(); 90 | } 91 | } 92 | 93 | @Data 94 | @Builder 95 | @EqualsAndHashCode(callSuper = true) 96 | @RequiredArgsConstructor(staticName = "of") 97 | public static class Highway extends Edge { 98 | 99 | @PrimaryKey 100 | private final String name; 101 | 102 | @Override 103 | protected List connections() { 104 | return Connection.list(City.class, City.class); 105 | } 106 | } 107 | 108 | } 109 | -------------------------------------------------------------------------------- /gremlin-objects/src/test/java/org/apache/tinkerpop/gremlin/object/traversal/library/AddVTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.tinkerpop.gremlin.object.traversal.library; 20 | 21 | import org.apache.tinkerpop.gremlin.object.traversal.TraversalTest; 22 | import org.apache.tinkerpop.gremlin.structure.Element; 23 | import org.junit.Test; 24 | 25 | import static org.junit.Assert.assertEquals; 26 | import static org.mockito.Mockito.times; 27 | import static org.mockito.Mockito.verify; 28 | 29 | /** 30 | * Verify that {@link HasKeys} steps through the given element's label, followed by it's 31 | * primary key property(s). 32 | * 33 | * @author Karthick Sankarachary (http://github.com/karthicks) 34 | */ 35 | public class AddVTest extends TraversalTest { 36 | 37 | @Test 38 | public void testAddKeyTraversal() { 39 | AddV addV = AddV.of(sanFrancisco); 40 | 41 | traverse(addV); 42 | 43 | verify(g, times(1)).addV(sanFrancisco.label()); 44 | verify(traversal, times(1)).property("name", "San Francisco"); 45 | assertEquals(sanFrancisco, addV.element()); 46 | } 47 | 48 | @Test(expected = IllegalArgumentException.class) 49 | public void testAddNullKeyTraversal() { 50 | City nowhere = City.of(null); 51 | AddV addV = AddV.of(nowhere); 52 | 53 | traverse(addV); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /gremlin-objects/src/test/java/org/apache/tinkerpop/gremlin/object/traversal/library/CountTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.tinkerpop.gremlin.object.traversal.library; 20 | 21 | import org.apache.tinkerpop.gremlin.object.traversal.TraversalTest; 22 | import org.junit.Test; 23 | 24 | import static org.mockito.Mockito.times; 25 | import static org.mockito.Mockito.verify; 26 | 27 | /** 28 | * Verify that {@link Count} invokes the {@link org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal#count} 29 | * step. 30 | * 31 | * @author Karthick Sankarachary (http://github.com/karthicks) 32 | */ 33 | public class CountTest extends TraversalTest { 34 | 35 | @Test 36 | public void testCountTraversal() { 37 | Count count = Count.of(); 38 | traverse(count); 39 | verify(traversal, times(1)).count(); 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /gremlin-objects/src/test/java/org/apache/tinkerpop/gremlin/object/traversal/library/HasIdTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.tinkerpop.gremlin.object.traversal.library; 20 | 21 | import org.apache.tinkerpop.gremlin.object.traversal.TraversalTest; 22 | import org.apache.tinkerpop.gremlin.structure.Element; 23 | import org.apache.tinkerpop.gremlin.structure.T; 24 | import org.junit.Test; 25 | 26 | import java.util.HashMap; 27 | 28 | import static org.junit.Assert.assertEquals; 29 | import static org.mockito.Mockito.times; 30 | import static org.mockito.Mockito.verify; 31 | 32 | /** 33 | * Verify that {@link HasId} checks if the traversal has the generated id, since its {@link City#id} 34 | * is missing. 35 | * 36 | * @author Karthick Sankarachary (http://github.com/karthicks) 37 | */ 38 | @SuppressWarnings("serial") 39 | public class HasIdTest extends TraversalTest { 40 | 41 | @Test 42 | public void testHasIdTraversal() { 43 | HasId hasId = HasId.of(sanFrancisco); 44 | 45 | traverse(hasId); 46 | 47 | verify(traversal, times(1)).hasId(new HashMap() { 48 | { 49 | put(T.label.getAccessor(), sanFrancisco.label()); 50 | put("name", "San Francisco"); 51 | } 52 | }); 53 | assertEquals(sanFrancisco, hasId.element()); 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /gremlin-objects/src/test/java/org/apache/tinkerpop/gremlin/object/traversal/library/HasKeysTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.tinkerpop.gremlin.object.traversal.library; 20 | 21 | import org.apache.tinkerpop.gremlin.object.traversal.TraversalTest; 22 | import org.apache.tinkerpop.gremlin.structure.Element; 23 | import org.junit.Test; 24 | 25 | import static org.junit.Assert.assertEquals; 26 | import static org.mockito.Mockito.times; 27 | import static org.mockito.Mockito.verify; 28 | 29 | /** 30 | * Verify that {@link HasKeys} steps through the given element's label, followed by it's 31 | * primary key property(s). 32 | * 33 | * @author Karthick Sankarachary (http://github.com/karthicks) 34 | */ 35 | public class HasKeysTest extends TraversalTest { 36 | 37 | @Test 38 | public void testHasPrimaryKeyTraversal() { 39 | HasKeys hasKeys = HasKeys.of(sanFrancisco); 40 | 41 | traverse(hasKeys); 42 | 43 | verify(traversal, times(1)).hasLabel("City"); 44 | verify(traversal, times(1)).has("name", "San Francisco"); 45 | assertEquals(sanFrancisco, hasKeys.element()); 46 | } 47 | 48 | @Test(expected = IllegalArgumentException.class) 49 | public void testNullPrimaryKeyTraversal() { 50 | sanFrancisco.setName(null); 51 | HasKeys hasKeys = HasKeys.of(sanFrancisco); 52 | 53 | traverse(hasKeys); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /gremlin-objects/src/test/java/org/apache/tinkerpop/gremlin/object/traversal/library/HasLabelTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.tinkerpop.gremlin.object.traversal.library; 20 | 21 | import org.apache.tinkerpop.gremlin.object.reflect.Label; 22 | import org.apache.tinkerpop.gremlin.object.traversal.TraversalTest; 23 | import org.apache.tinkerpop.gremlin.structure.Element; 24 | import org.junit.Test; 25 | 26 | import static org.junit.Assert.assertEquals; 27 | import static org.mockito.Mockito.times; 28 | import static org.mockito.Mockito.verify; 29 | 30 | /** 31 | * Verify that {@link HasLabel} checks for the label of the provided element. 32 | * 33 | * @author Karthick Sankarachary (http://github.com/karthicks) 34 | */ 35 | public class HasLabelTest extends TraversalTest { 36 | 37 | @Test 38 | public void testHasLabelTraversal() { 39 | HasLabel hasLabel = HasLabel.of(sanFrancisco); 40 | 41 | traverse(hasLabel); 42 | 43 | verify(traversal, times(1)).hasLabel("City"); 44 | assertEquals(Label.of(sanFrancisco), hasLabel.label()); 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /gremlin-objects/src/test/java/org/apache/tinkerpop/gremlin/object/traversal/library/HasTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.tinkerpop.gremlin.object.traversal.library; 20 | 21 | import org.apache.tinkerpop.gremlin.object.traversal.TraversalTest; 22 | import org.apache.tinkerpop.gremlin.structure.Element; 23 | import org.junit.Test; 24 | 25 | import static org.junit.Assert.assertEquals; 26 | import static org.mockito.Mockito.times; 27 | import static org.mockito.Mockito.verify; 28 | 29 | /** 30 | * Verify that {@link HasTest} traverses the has step with the provided arguments. 31 | * 32 | * @author Karthick Sankarachary (http://github.com/karthicks) 33 | */ 34 | public class HasTest extends TraversalTest { 35 | 36 | @Test 37 | public void testHasTraversal() { 38 | Has has = Has.of("label", "key", "value"); 39 | 40 | traverse(has); 41 | 42 | verify(traversal, times(1)).has("label", "key", "value"); 43 | assertEquals("label", has.label()); 44 | assertEquals("key", has.key()); 45 | assertEquals("value", has.value()); 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /gremlin-objects/src/test/java/org/apache/tinkerpop/gremlin/object/traversal/library/IdTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.tinkerpop.gremlin.object.traversal.library; 20 | 21 | import org.apache.tinkerpop.gremlin.object.traversal.TraversalTest; 22 | import org.junit.Test; 23 | 24 | import static org.mockito.Mockito.times; 25 | import static org.mockito.Mockito.verify; 26 | 27 | /** 28 | * Verify that {@link Id} traverses the id step. 29 | * 30 | * @author Karthick Sankarachary (http://github.com/karthicks) 31 | */ 32 | public class IdTest extends TraversalTest { 33 | 34 | @Test 35 | public void testIdTraversal() { 36 | Id id = Id.of(); 37 | 38 | traverse(id); 39 | 40 | verify(traversal, times(1)).id(); 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /gremlin-objects/src/test/java/org/apache/tinkerpop/gremlin/object/traversal/library/KeysTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.tinkerpop.gremlin.object.traversal.library; 20 | 21 | import org.apache.tinkerpop.gremlin.object.traversal.TraversalTest; 22 | import org.junit.Test; 23 | 24 | import static org.junit.Assert.assertEquals; 25 | import static org.mockito.Matchers.anyVararg; 26 | import static org.mockito.Mockito.times; 27 | import static org.mockito.Mockito.verify; 28 | import static org.mockito.Mockito.when; 29 | 30 | /** 31 | * Verify that {@link Keys} retrieves the values of the primary key(s) of the given element. 32 | * 33 | * @author Karthick Sankarachary (http://github.com/karthicks) 34 | */ 35 | public class KeysTest extends TraversalTest { 36 | 37 | @Test 38 | public void testKeysTraversal() { 39 | Keys keys = Keys.of(sanFrancisco); 40 | when(traversal.values(anyVararg())).thenReturn(traversal); 41 | 42 | traverse(keys); 43 | 44 | verify(traversal, times(1)).values("name"); 45 | verify(traversal, times(1)).dedup(); 46 | assertEquals(City.class, keys.elementType()); 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /gremlin-objects/src/test/java/org/apache/tinkerpop/gremlin/object/traversal/library/LabelTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.tinkerpop.gremlin.object.traversal.library; 20 | 21 | import org.apache.tinkerpop.gremlin.object.traversal.TraversalTest; 22 | import org.apache.tinkerpop.gremlin.structure.Element; 23 | import org.junit.Test; 24 | 25 | import static org.mockito.Mockito.times; 26 | import static org.mockito.Mockito.verify; 27 | 28 | /** 29 | * Verify that {@link Label} retrieves the labels from the traversal. 30 | * 31 | * @author Karthick Sankarachary (http://github.com/karthicks) 32 | */ 33 | public class LabelTest extends TraversalTest { 34 | 35 | @Test 36 | public void testLabelTraversal() { 37 | Label label = Label.of(); 38 | 39 | traverse(label); 40 | 41 | verify(traversal, times(1)).label(); 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /gremlin-objects/src/test/java/org/apache/tinkerpop/gremlin/object/traversal/library/OrderTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.tinkerpop.gremlin.object.traversal.library; 20 | 21 | import org.apache.tinkerpop.gremlin.object.traversal.TraversalTest; 22 | import org.apache.tinkerpop.gremlin.structure.Element; 23 | import org.junit.Test; 24 | 25 | import static org.junit.Assert.assertEquals; 26 | import static org.mockito.Mockito.times; 27 | import static org.mockito.Mockito.verify; 28 | import static org.mockito.Mockito.when; 29 | 30 | /** 31 | * Verify that {@link Order} orders by the given property. 32 | * 33 | * @author Karthick Sankarachary (http://github.com/karthicks) 34 | */ 35 | public class OrderTest extends TraversalTest { 36 | 37 | @Test 38 | public void testOrderTraversal() { 39 | Order order = Order.by("population"); 40 | 41 | when(traversal.order()).thenReturn(traversal); 42 | traverse(order); 43 | 44 | verify(traversal, times(1)).order(); 45 | verify(traversal, times(1)).by("population"); 46 | assertEquals("population", order.property()); 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /gremlin-objects/src/test/java/org/apache/tinkerpop/gremlin/object/traversal/library/OutTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.tinkerpop.gremlin.object.traversal.library; 20 | 21 | import org.apache.tinkerpop.gremlin.object.traversal.TraversalTest; 22 | import org.apache.tinkerpop.gremlin.structure.Element; 23 | import org.junit.Test; 24 | 25 | import static org.junit.Assert.assertEquals; 26 | import static org.mockito.Mockito.times; 27 | import static org.mockito.Mockito.verify; 28 | 29 | /** 30 | * Verify that {@link Out} goes along the outgoing edges of the given element. 31 | * 32 | * @author Karthick Sankarachary (http://github.com/karthicks) 33 | */ 34 | public class OutTest extends TraversalTest { 35 | 36 | @Test 37 | public void testOutTraversal() { 38 | Out out = Out.of(sanFrancisco); 39 | 40 | traverse(out); 41 | 42 | verify(traversal, times(1)).out("City"); 43 | assertEquals(sanFrancisco.label(), out.label()); 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /gremlin-objects/src/test/java/org/apache/tinkerpop/gremlin/object/traversal/library/RangeTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.tinkerpop.gremlin.object.traversal.library; 20 | 21 | import org.apache.tinkerpop.gremlin.object.traversal.TraversalTest; 22 | import org.apache.tinkerpop.gremlin.structure.Element; 23 | import org.junit.Test; 24 | 25 | import static org.junit.Assert.assertEquals; 26 | import static org.mockito.Mockito.times; 27 | import static org.mockito.Mockito.verify; 28 | 29 | /** 30 | * Verify that {@link Range} limits the traversal using the given bounds. 31 | * 32 | * @author Karthick Sankarachary (http://github.com/karthicks) 33 | */ 34 | public class RangeTest extends TraversalTest { 35 | 36 | @Test 37 | public void testRangeTraversal() { 38 | Range range = Range.of(10, 20); 39 | 40 | traverse(range); 41 | 42 | verify(traversal, times(1)).range(10, 20); 43 | assertEquals(10, range.low()); 44 | assertEquals(20, range.high()); 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /gremlin-objects/src/test/java/org/apache/tinkerpop/gremlin/object/traversal/library/ValuesTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.tinkerpop.gremlin.object.traversal.library; 20 | 21 | import org.apache.tinkerpop.gremlin.object.traversal.TraversalTest; 22 | import org.junit.Test; 23 | 24 | import static org.junit.Assert.assertArrayEquals; 25 | import static org.mockito.Matchers.anyVararg; 26 | import static org.mockito.Mockito.times; 27 | import static org.mockito.Mockito.verify; 28 | import static org.mockito.Mockito.when; 29 | 30 | /** 31 | * Verify that {@link Values} gets the values of all the properties of the given element, de-duped. 32 | * 33 | * @author Karthick Sankarachary (http://github.com/karthicks) 34 | */ 35 | public class ValuesTest extends TraversalTest { 36 | 37 | @Test 38 | public void testValuesTraversal() { 39 | City sanFrancisco = City.of("San Francisco"); 40 | Values values = Values.of(sanFrancisco); 41 | 42 | when(traversal.values(anyVararg())).thenReturn(traversal); 43 | traverse(values); 44 | 45 | verify(traversal, times(1)).values("name", "population"); 46 | verify(traversal, times(1)).dedup(); 47 | assertArrayEquals(new String[] {"name", "population"}, values.propertyKeys()); 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /gremlin-objects/src/test/java/org/apache/tinkerpop/gremlin/object/vertices/Location.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.tinkerpop.gremlin.object.vertices; 20 | 21 | import org.apache.tinkerpop.gremlin.object.model.Alias; 22 | import org.apache.tinkerpop.gremlin.object.model.OrderingKey; 23 | import org.apache.tinkerpop.gremlin.object.model.PropertyValue; 24 | import org.apache.tinkerpop.gremlin.object.structure.Element; 25 | 26 | import java.time.Instant; 27 | import java.time.LocalDate; 28 | import java.time.ZoneOffset; 29 | import java.util.HashMap; 30 | import java.util.Map; 31 | 32 | import lombok.AllArgsConstructor; 33 | import lombok.Builder; 34 | import lombok.Data; 35 | import lombok.EqualsAndHashCode; 36 | import lombok.NoArgsConstructor; 37 | import lombok.experimental.Accessors; 38 | 39 | /** 40 | * The {@link Location} class represents the "locations" vertex property, whose value is kept in the 41 | * {@link #name} field that is annotated with {@link PropertyValue}. The rest of the fields become 42 | * its meta-properties. 43 | * 44 | * @author Karthick Sankarachary (http://github.com/karthicks) 45 | */ 46 | @Data 47 | @Builder 48 | @NoArgsConstructor 49 | @AllArgsConstructor 50 | @Alias(label = "location") 51 | @Accessors(fluent = true, chain = true) 52 | @EqualsAndHashCode(of = {}, callSuper = true) 53 | public class Location extends Element { 54 | 55 | @OrderingKey 56 | @PropertyValue 57 | private String name; 58 | @OrderingKey 59 | private Instant startTime; 60 | private Instant endTime; 61 | 62 | public static Location of(String name, int startYear) { 63 | return of(name, year(startYear)); 64 | } 65 | 66 | public static Location of(String name, Instant startTime) { 67 | return of(name, startTime, null); 68 | } 69 | 70 | public static Location of(String name, int startYear, int endYear) { 71 | return of(name, year(startYear), year(endYear)); 72 | } 73 | 74 | public static Location of(String name, Instant startTime, Instant endTime) { 75 | return Location.builder().name(name).startTime(startTime).endTime(endTime).build(); 76 | } 77 | 78 | private static Map years = new HashMap<>(); 79 | 80 | public static Instant year(int value) { 81 | Instant instant = years.get(value); 82 | if (instant != null) { 83 | return instant; 84 | } 85 | instant = LocalDate.parse(String.format("%s-01-01", value)).atStartOfDay() 86 | .toInstant(ZoneOffset.UTC); 87 | years.put(value, instant); 88 | return instant; 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /gremlin-objects/src/test/java/org/apache/tinkerpop/gremlin/object/vertices/Software.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.tinkerpop.gremlin.object.vertices; 20 | 21 | import org.apache.tinkerpop.gremlin.object.model.Alias; 22 | import org.apache.tinkerpop.gremlin.object.model.PrimaryKey; 23 | import org.apache.tinkerpop.gremlin.object.structure.Vertex; 24 | 25 | import lombok.AllArgsConstructor; 26 | import lombok.Builder; 27 | import lombok.Data; 28 | import lombok.EqualsAndHashCode; 29 | import lombok.NoArgsConstructor; 30 | import lombok.experimental.Accessors; 31 | 32 | /** 33 | * The {@link Software} class represents the "software" vertex. 34 | * 35 | * @author Karthick Sankarachary (http://github.com/karthicks) 36 | */ 37 | @Data 38 | @Builder 39 | @NoArgsConstructor 40 | @AllArgsConstructor 41 | @Alias(label = "software") 42 | @Accessors(fluent = true, chain = true) 43 | @EqualsAndHashCode(of = {}, callSuper = true) 44 | public class Software extends Vertex { 45 | 46 | @PrimaryKey 47 | private String name; 48 | 49 | public static Software of(String name) { 50 | return Software.builder().name(name).build(); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /licenses/lombok: -------------------------------------------------------------------------------- 1 | Copyright (C) 2009-2015 The Project Lombok Authors. 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 21 | 4.0.0 22 | 23 | org.apache.tinkerpop 24 | tinkerpop 25 | 3.3.1 26 | 27 | com.github.karthicks 28 | gremlin-ogm 29 | 3.3.1-SNAPSHOT 30 | pom 31 | Gremlin OGM 32 | An Object Graph Mapping Library 33 | http://github.com/karthicks/gremlin-ogm 34 | 2017 35 | 36 | 37 | Apache 2 38 | http://www.opensource.org/licenses/Apache-2.0 39 | 40 | 41 | 42 | 43 | Karthick Sankarachary 44 | karthick@apache.org 45 | http://github.com/karthicks 46 | 47 | 48 | 49 | 3.0.5 50 | 51 | 52 | gremlin-objects 53 | tinkergraph-test 54 | 55 | 56 | 3.3.1 57 | 1.3 58 | 1.2 59 | 1.2.17 60 | 1.16.18 61 | 1.7.21 62 | 63 | 64 | scm:git:git://github.com/karthicks/gremlin-ogm.git 65 | scm:git:git://github.com/karthicks/gremlin-ogm.git 66 | https://github.com/karthicks/gremlin-ogm 67 | 68 | 69 | 70 | ossrh 71 | https://oss.sonatype.org/content/repositories/snapshots 72 | 73 | 74 | ossrh 75 | https://oss.sonatype.org/service/local/staging/deploy/maven2/ 76 | 77 | 78 | 79 | 80 | 81 | org.apache.maven.plugins 82 | maven-compiler-plugin 83 | 84 | 85 | org.sonatype.plugins 86 | nexus-staging-maven-plugin 87 | 1.6.3 88 | true 89 | 90 | ossrh 91 | https://oss.sonatype.org/ 92 | true 93 | 94 | 95 | 96 | org.apache.maven.plugins 97 | maven-source-plugin 98 | 99 | 100 | org.apache.maven.plugins 101 | maven-javadoc-plugin 102 | 103 | 104 | org.apache.maven.plugins 105 | maven-gpg-plugin 106 | 1.5 107 | 108 | 109 | sign-artifacts 110 | verify 111 | 112 | sign 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | -------------------------------------------------------------------------------- /tinkergraph-test/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 19 | 4.0.0 20 | 21 | com.github.karthicks 22 | gremlin-ogm 23 | 3.3.1-SNAPSHOT 24 | 25 | tinkergraph-test 26 | Gremlin OGM :: TinkerGraph Test 27 | 28 | 29 | commons-configuration 30 | commons-configuration 31 | test 32 | 33 | 34 | commons-logging 35 | commons-logging 36 | 37 | 38 | 39 | 40 | junit 41 | junit 42 | test 43 | 44 | 45 | org.apache.tinkerpop 46 | gremlin-core 47 | ${tinkerpop.version} 48 | test 49 | 50 | 51 | com.github.karthicks 52 | gremlin-objects 53 | ${project.version} 54 | test 55 | 56 | 57 | com.github.karthicks 58 | gremlin-objects 59 | ${project.version} 60 | test-jar 61 | test 62 | 63 | 64 | org.apache.tinkerpop 65 | tinkergraph-gremlin 66 | ${tinkerpop.version} 67 | test 68 | 69 | 70 | org.apache.tinkerpop 71 | gremlin-test 72 | 73 | 74 | 75 | 76 | org.hamcrest 77 | hamcrest-core 78 | ${hamcrest.version} 79 | test 80 | 81 | 82 | org.projectlombok 83 | lombok 84 | ${lombok.version} 85 | provided 86 | 87 | 88 | org.slf4j 89 | slf4j-api 90 | ${slf4j.version} 91 | test 92 | 93 | 94 | 95 | ${basedir}/target 96 | ${project.artifactId}-${project.version} 97 | 98 | 99 | org.apache.maven.plugins 100 | maven-failsafe-plugin 101 | 102 | 103 | org.apache.maven.plugins 104 | maven-surefire-plugin 105 | 106 | 107 | 108 | 109 | -------------------------------------------------------------------------------- /tinkergraph-test/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/object/TinkerGraphTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.tinkerpop.gremlin.tinkergraph.object; 20 | 21 | import org.apache.tinkerpop.gremlin.object.ObjectGraphTest; 22 | import org.apache.tinkerpop.gremlin.object.provider.GraphFactory; 23 | import org.apache.tinkerpop.gremlin.object.structure.Graph; 24 | import org.apache.tinkerpop.gremlin.object.traversal.Query; 25 | import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraph; 26 | 27 | import lombok.extern.slf4j.Slf4j; 28 | 29 | import static org.apache.tinkerpop.gremlin.object.provider.GraphFactory.ShouldCache.THREAD_LOCAL; 30 | 31 | /** 32 | * This is a test suite for the {@link Graph} and {@link Query} implementations, when it points to a 33 | * {@link TinkerGraph} traversal. While all of the testing is defined in {@link ObjectGraphTest}, 34 | * this class is responsible for providing a tinkergraph-specific version of the {@link Graph} and 35 | * {@link Query} to it. 36 | * 37 | * @author Karthick Sankarachary (http://github.com/karthicks) 38 | */ 39 | @Slf4j 40 | public class TinkerGraphTest extends ObjectGraphTest { 41 | 42 | private static final GraphFactory FACTORY = GraphFactory.of(TinkerGraph.open().traversal()); 43 | 44 | public TinkerGraphTest() { 45 | super(FACTORY.graph(), FACTORY.query()); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /tinkergraph-test/src/test/resources/log4j-silent.properties: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | # this file should always have logging set to OFF. it seems, however, that an appender of some sort is 19 | # required or else some logs throw error and use other log4j.properties files on the path. 20 | log4j.rootLogger=OFF, stdout 21 | log4j.appender.stdout=org.apache.log4j.ConsoleAppender 22 | log4j.appender.stdout.layout=org.apache.log4j.PatternLayout 23 | log4j.appender.stdout.layout.ConversionPattern=[%p] %C - %m%n -------------------------------------------------------------------------------- /tinkergraph-test/src/test/resources/log4j-test.properties: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | log4j.rootLogger=WARN, stdout 19 | log4j.appender.stdout=org.apache.log4j.ConsoleAppender 20 | log4j.appender.stdout.layout=org.apache.log4j.PatternLayout 21 | log4j.appender.stdout.layout.ConversionPattern=[%p] %C - %m%n --------------------------------------------------------------------------------