Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Java Quickstart Example #4

Merged
merged 33 commits into from
Jan 29, 2025
Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
f68d5bc
initial quickstart for java
AerospikeNate-L Nov 5, 2024
54b0688
adjust pom.xml per Lyndon's recs, add print statements
AerospikeNate-L Nov 5, 2024
4742863
teardown (needs fixing)
AerospikeNate-L Nov 5, 2024
f09ccc3
we close the *cluster* not the TraversalSource..
AerospikeNate-L Nov 6, 2024
0ea477e
add artifacts dir to gitignore
AerospikeNate-L Nov 6, 2024
5221c5c
rename project, tidy up
AerospikeNate-L Nov 6, 2024
2f8c74e
need to get properties from vertex rather than RefernceVertex
AerospikeNate-L Nov 6, 2024
0da878f
add README
AerospikeNate-L Nov 6, 2024
3d6eafd
add newlines to ends of files
AerospikeNate-L Nov 6, 2024
59e3787
remove unused imports, add comment to modify HOST string
AerospikeNate-L Nov 6, 2024
6c9263b
use `localhost` for HOST string
AerospikeNate-L Nov 7, 2024
701a055
Remove excess whitespace
AerospikeNate-L Nov 7, 2024
65dbdbc
Closing Connect -> Closing connection
AerospikeNate-L Nov 20, 2024
1aebd0b
`,` -> `;`
AerospikeNate-L Nov 20, 2024
8105d73
casing
AerospikeNate-L Nov 20, 2024
37589b5
ellipses
AerospikeNate-L Nov 20, 2024
75c0ea7
punctuation
AerospikeNate-L Nov 20, 2024
9eebbdb
trim ws
AerospikeNate-L Nov 20, 2024
6e9fefa
Update examples output
AerospikeNate-L Nov 20, 2024
09cc1ee
camel_case -> snake-case
AerospikeNate-L Nov 20, 2024
b893c01
cleanup
AerospikeNate-L Nov 20, 2024
6423154
only require java 11
AerospikeNate-L Nov 20, 2024
2893f43
fix renaming reversion from cleanup commit
AerospikeNate-L Nov 20, 2024
75c4162
EOF gets its own line
AerospikeNate-L Nov 20, 2024
b9f0dfe
snake case the jar too
AerospikeNate-L Nov 20, 2024
019cfe8
no snapshot, fix java version
AerospikeNate-L Nov 20, 2024
3b701d2
New java example
ishaanb Jan 28, 2025
61aae13
updated readme
ishaanb Jan 28, 2025
5434256
renamed java dir
ishaanb Jan 28, 2025
536cd68
Apply suggestions from code review
ishaanb Jan 29, 2025
1725f3b
remove target folder
ishaanb Jan 29, 2025
b9896f3
remove upi py file from this commit
ishaanb Jan 29, 2025
ebf3e5f
Apply suggestions from code review
ishaanb Jan 29, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
.venv

.vscode/
.DS_Store
.DS_Store

examples/*/target
21 changes: 21 additions & 0 deletions examples/ags-java-example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
## To run Java example

#### Reqs: Java 11+

```
cd ags_java_example
mvn clean install -q
java -jar target/ags-java-example-1.0-jar-with-dependencies.jar
```
Example output:
```
CONNECTED TO GRAPH; ADDING ELEMENTS
READING BACK DATA...
Edge: e[/////////+b/////////5g==][-51-connects->-52]
Out from: v[-51]
In to: v[-52]
v[-51] has Properties:
--> vp1 : vpv1
--> vp2 : vpv2
DONE; CLOSING CONNECTION!
```
67 changes: 67 additions & 0 deletions examples/ags-java-example/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>aerospike.com</groupId>
<artifactId>ags-java-example</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<tinkerpop.version>3.7.2</tinkerpop.version>
<junit.version>4.13.1</junit.version>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.tinkerpop</groupId>
<artifactId>gremlin-core</artifactId>
<version>${tinkerpop.version}</version>
</dependency>
<dependency>
<groupId>org.apache.tinkerpop</groupId>
<artifactId>gremlin-driver</artifactId>
<version>${tinkerpop.version}</version>
</dependency>

</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>11</source>
<target>11</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>aerospike.com.Main</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
</plugins>
</build>

</project>
69 changes: 69 additions & 0 deletions examples/ags-java-example/src/main/java/aerospike/com/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package aerospike.com;

import org.apache.tinkerpop.gremlin.structure.Vertex;
import org.apache.tinkerpop.gremlin.structure.Edge;
import org.apache.tinkerpop.gremlin.driver.Cluster;
import org.apache.tinkerpop.gremlin.driver.remote.DriverRemoteConnection;
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
import static org.apache.tinkerpop.gremlin.process.traversal.AnonymousTraversalSource.traversal;


public class Main {
private static final String HOST = "localhost";
private static final int PORT = 8182;
private static final Cluster.Builder BUILDER = Cluster.build().addContactPoint(HOST).port(PORT).enableSsl(false);

public static void main(String[] args) {
final Cluster cluster = BUILDER.create();
final GraphTraversalSource g = traversal().withRemote(DriverRemoteConnection.using(cluster));

System.out.println("CONNECTED TO GRAPH; ADDING ELEMENTS");
// Add 2 vertices and an edge between them with 2 properties each
Vertex v1 = g.addV("V1")
.property("vp1", "vpv1")
.property("vp2", "vpv2")
.next();

Vertex v2 = g.addV("V2")
.property("vp1", "vpv3")
.property("vp2", "vpv4")
.next();

g.addE("connects").from(v1).to(v2)
.property("ep1", "ev1")
.property("ep2", "ev2")
.iterate();

System.out.println("READING BACK DATA...");

Edge edge = g.E().hasLabel("connects").next();
System.out.print("Edge: ");
System.out.println(edge);
System.out.print("Out from: ");
Vertex outV = edge.outVertex();
System.out.println(outV);
System.out.print("In to: ");
Vertex inV = edge.inVertex();
System.out.println(inV);

// List properties
v1 = g.V().hasLabel("V1").next();
System.out.println(v1 + " has Properties:");
v1.properties()
.forEachRemaining(property -> {
System.out.println(
"--> " + property.key() + " : " + property.value()
);
});

// Clean up
g.V().drop().iterate();
System.out.print("DONE; ");
try {
System.out.println("CLOSING CONNECTION!");
cluster.close();
} catch (Exception e) {
System.err.println("FAILED TO CLOSE!");
}
}
}