Skip to content
This repository was archived by the owner on Aug 28, 2024. It is now read-only.

Commit 556165d

Browse files
Add starter and example code for gremlin (#373)
* Add stater and sample code for gremlin autoconfiguration. * Update sample code description. Signed-off-by: Pan Li <panli@microsoft.com> Signed-off-by: Weiping Pan <Weiping.Pan@microsoft.com>
1 parent d849695 commit 556165d

File tree

9 files changed

+177
-0
lines changed

9 files changed

+177
-0
lines changed

azure-spring-boot-bom/pom.xml

+5
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,11 @@
9696
<artifactId>azure-mediaservices-spring-boot-starter</artifactId>
9797
<version>${azure.spring.boot.version}</version>
9898
</dependency>
99+
<dependency>
100+
<groupId>com.microsoft.azure</groupId>
101+
<artifactId>spring-data-gremlin-boot-starter</artifactId>
102+
<version>${azure.spring.boot.version}</version>
103+
</dependency>
99104
<dependency>
100105
<groupId>com.microsoft.azure</groupId>
101106
<artifactId>azure-spring-boot</artifactId>

azure-spring-boot-samples/pom.xml

+1
Original file line numberDiff line numberDiff line change
@@ -150,5 +150,6 @@
150150
<module>azure-servicebus-spring-boot-sample</module>
151151
<module>azure-storage-spring-boot-sample</module>
152152
<module>azure-cloud-foundry-service-sample</module>
153+
<module>spring-data-gremlin-boot-sample</module>
153154
</modules>
154155
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<parent>
8+
<artifactId>azure-spring-boot-samples</artifactId>
9+
<groupId>com.microsoft.azure</groupId>
10+
<version>0.0.1-SNAPSHOT</version>
11+
<relativePath>../pom.xml</relativePath>
12+
</parent>
13+
14+
<artifactId>spring-data-gremlin-boot-sample</artifactId>
15+
<packaging>jar</packaging>
16+
17+
<name>Spring Data Gremlin Boot Starter Sample</name>
18+
<description>Sample project for Spring Data Gremlin</description>
19+
<url>https://github.com/Microsoft/azure-spring-boot</url>
20+
21+
<dependencies>
22+
<dependency>
23+
<groupId>com.microsoft.azure</groupId>
24+
<artifactId>spring-data-gremlin-boot-starter</artifactId>
25+
</dependency>
26+
<dependency>
27+
<groupId>org.projectlombok</groupId>
28+
<artifactId>lombok</artifactId>
29+
<scope>provided</scope>
30+
</dependency>
31+
</dependencies>
32+
33+
<properties>
34+
<project.rootdir>${project.basedir}/../..</project.rootdir>
35+
</properties>
36+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/**
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See LICENSE in the project root for
4+
* license information.
5+
*/
6+
package sample.gremlin;
7+
8+
import com.microsoft.spring.data.gremlin.common.GremlinFactory;
9+
import org.springframework.beans.factory.annotation.Autowired;
10+
import org.springframework.boot.CommandLineRunner;
11+
import org.springframework.boot.SpringApplication;
12+
import org.springframework.boot.autoconfigure.SpringBootApplication;
13+
import org.springframework.util.Assert;
14+
15+
import java.util.List;
16+
import java.util.Optional;
17+
18+
@SpringBootApplication
19+
public class GremlinApplication implements CommandLineRunner {
20+
21+
@Autowired
22+
private GremlinFactory factory;
23+
24+
@Autowired
25+
private PersonRepository repository;
26+
27+
public static void main(String[] args) {
28+
SpringApplication.run(GremlinApplication.class, args);
29+
}
30+
31+
private void closeClusterConnection() {
32+
if (this.factory.getGremlinCluster().isClosed() || this.factory.getGremlinCluster().isClosing()) {
33+
return;
34+
}
35+
36+
this.factory.getGremlinCluster().closeAsync();
37+
}
38+
39+
public void run(String... vars) {
40+
final Person person = new Person("fake-id", "fake-name", 123);
41+
42+
this.repository.deleteAll();
43+
this.repository.save(person);
44+
45+
final Optional<Person> foundPerson = this.repository.findById(person.getId());
46+
Assert.isTrue(foundPerson.isPresent(), "optional of Person should be present");
47+
Assert.state(foundPerson.get().equals(person), "should be the equals");
48+
49+
final List<Person> foundPersons = this.repository.findByNameAndLevel(person.getName(), person.getLevel());
50+
Assert.isTrue(foundPersons.size() == 1, "should be only one element");
51+
Assert.state(foundPersons.get(0).getId().equals(person.getId()), "should be the same id");
52+
53+
this.closeClusterConnection();
54+
}
55+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/**
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See LICENSE in the project root for
4+
* license information.
5+
*/
6+
package sample.gremlin;
7+
8+
import com.microsoft.spring.data.gremlin.annotation.Vertex;
9+
import lombok.AllArgsConstructor;
10+
import lombok.Data;
11+
import lombok.NoArgsConstructor;
12+
import org.springframework.data.annotation.Id;
13+
14+
@Vertex
15+
@Data
16+
@AllArgsConstructor
17+
@NoArgsConstructor
18+
public class Person {
19+
20+
@Id
21+
private String id;
22+
23+
private String name;
24+
25+
private int level;
26+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See LICENSE in the project root for
4+
* license information.
5+
*/
6+
package sample.gremlin;
7+
8+
import com.microsoft.spring.data.gremlin.repository.GremlinRepository;
9+
10+
import java.util.List;
11+
12+
public interface PersonRepository extends GremlinRepository<Person, String> {
13+
14+
List<Person> findByNameAndLevel(String name, int level);
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
gremlin.endpoint=${your-remote-server-endpoint}
2+
gremlin.port=443
3+
gremlin.username=${your-database-username}
4+
gremlin.password=${your-database-password}
5+

azure-spring-boot-starters/pom.xml

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
<module>azure-mediaservices-spring-boot-starter</module>
2727
<module>azure-servicebus-spring-boot-starter</module>
2828
<module>azure-storage-spring-boot-starter</module>
29+
<module>spring-data-gremlin-boot-starter</module>
2930
</modules>
3031

3132
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
<parent>
7+
<groupId>com.microsoft.azure</groupId>
8+
<artifactId>azure-spring-boot-parent</artifactId>
9+
<version>2.0.4-SNAPSHOT</version>
10+
<relativePath>../../azure-spring-boot-parent/pom.xml</relativePath>
11+
</parent>
12+
13+
<artifactId>spring-data-gremlin-boot-starter</artifactId>
14+
15+
<name>Spring Data Gremlin Boot Starter</name>
16+
<description>Spring Boot Starter for Spring Data Gremlin</description>
17+
<url>https://github.com/Microsoft/azure-spring-boot</url>
18+
19+
<properties>
20+
<project.rootdir>${project.basedir}/../..</project.rootdir>
21+
</properties>
22+
23+
<dependencies>
24+
<dependency>
25+
<groupId>com.microsoft.azure</groupId>
26+
<artifactId>azure-spring-boot-starter</artifactId>
27+
</dependency>
28+
<dependency>
29+
<groupId>com.microsoft.spring.data.gremlin</groupId>
30+
<artifactId>spring-data-gremlin</artifactId>
31+
</dependency>
32+
</dependencies>
33+
</project>

0 commit comments

Comments
 (0)