Spring is coming! – ArangoDB meets Spring Data
This year we got a lot of requests from our customers to provide Spring Data support for ArangoDB. So we listened and teamed up with one of our bigger customers from the financial sector to develop a Spring Data implementation for ArangoDB. We have also made an extensive demo on how to use Spring Data ArangoDB with an example data set of Game of Thrones characters and locations. So, Spring is not only coming... it is already there!
What is the Spring Framework?
The Spring Framework is an open source Java application framework which provides an Inversion of Control (IoC) Container to manage Plain-Old-Java-Objects (POJO) through Dependency Injection (DI). The Spring Framework includes a wide range of modules providing several services. One interesting module for us is Spring Data which provides a Spring like programming model for data access. There are already a lot of subprojects of Spring Data which specify data access to different specific database technologies and now ArangoDB joins in.
Why did it take some time?
To successfully implement our Spring Data module for ArangoDB we needed a solid base with our team and with our Java driver which runs under the hood. In the last two years, we expanded our team of developers who are well versed in the Java world. With their help we implemented a completely new Java driver with a more intuitive and object oriented API, but also several new features like VelocyStream support, multi-document operations, automatic fallback and, with the current release, built-in load balancing. Especially the load balancing and fallback features were a high priority for our customers running ArangoDB in a cluster setup. With this preliminary work, we started implementing our Spring Data module this year in close teamwork with two great developers from our customer. (Thanks for your great work, guys!)
Features
Spring Data ArangoDB provides a solution for all core concepts of Spring Data. With ArangoTemplate you are able to perform common database operations from managing databases, collections and graphs to single or batch CRUD operations. This includes annotation based object mapping of POJOs to VelocyPack documents (ArangoDBs internal storage format) and exception translation into data access exceptions used in Spring. You are also able to write repository interfaces which will be automatically implemented. Within these repository interfaces, you can implement custom methods from which AQL queries will be derived. With this feature, you can perform a wide range of queries with filter conditions, joins, graph traversals and even geospatial queries. It also supports passing AQL bind parameters as parameters in your method. But you can still write your AQL queries on your own and attach it with the @Query annotation to your custom method.
Example
Configuration
Configure the connection to ArangoDB server and enable Spring Data ArangoDB repositories.
@Configuration
@EnableArangoRepositories(basePackages = { "com.arangodb.spring.demo" })
public class DemoConfiguration extends AbstractArangoConfiguration {
@Override
public Builder arango() {
return new ArangoDB.Builder().host("localhost", 8529).user("root").password(null);
}
@Override
public String database() {
return "spring-demo";
}
}
Entities
Create and annotate your objects.
@Document
public class Character {
@Id
private String id;
private Integer age;
@Relations(edges = ChildOf.class, lazy = true)
private Collection<Character> childs;
}
@Edge
public class ChildOf {
@Id
private String id;
@From
private Character child;
@To
private Character parent;
}
Repositories
Create repository interfaces and implement custom methods.
public interface CharacterRepository extends ArangoRepository<Character> {
Iterable<Character> findByChildsAgeBetween(int lowerBound, int upperBound);
}
public interface ChildOfRepository extends ArangoRepository<ChildOf> {
}
Usage
@Autowired CharacterRepository characterRepo;
@Autowired ChildOfRepository childOfRepo;
List<Character> characters = ...
characterRepo.save(characters)
List<ChildOf> edges = ...
childOfRepo.save(edges);
Iterable<Character> childsBetween16a20 = repo.findByChildsAgeBetween(16, 20);
ArangoDB Java Driver: Load Balancing for Performance
The newest release 4.3.2 of the official ArangoDB Java driver comes with load balancing for cluster setups and advanced fallback mechanics.
Load balancing strategies
Round robin
There are two different strategies for load balancing that the Java driver provides. The first and most common strategy is the round robin way. Round robin does, what the name already assumes, a round robin load balancing where a list of known coordinators in the cluster is iterated through. Each database operation uses a different coordinator than the one before. Read more
ArangoDB | VelocyStream Async Binary Protocol – Data Streaming
With the 3.2 release, ArangoDB comes with version 1.1 of the binary protocol VelocyStream. VelocyStream is a bi-directional async binary protocol which supports sending messages pipelined, multiplexed, uni-directional or bi-directional. The messages themselves are VelocyPack objects. Read more
ArangoDB Spark Connector: Seamless Integration
Currently we are diving deeper into the Apache Spark world. We started with an implementation of a Spark-Connector written in Scala. The connector supports loading of data from ArangoDB into Spark and vice-versa. Today we release a first prototype with an aim of including our community into the development process early to build a product that fits your needs. Your feedback is more than welcome! Read more
ArangoDB Java Driver for Graphs: Enhanced Functionality
After defining a graph and filling it with some vertices and edges (see part 1), the time has come to retrieve information out of the graph.
Please take a look at the defined graph operations of ArangoDB. These will be the base for our next examples. (Yes, there may be other ways to get the results, this post does not claim completeness!)
We will start with some easy stuff and then smoothly advance in complexity.
Question: “How many edges are defined within the graph?”
ArangoDB Java Driver: Graph Data Manipulation & Queries
With ArangoDB 2.2 the new graph API was released featuring multi collection graphs (see blog). With the new version (2.2.1) of arangodb-java-driver the new graph API is supported. In the following you can find a small example of creating a graph with Java.
For the import via maven and configuring the driver, please read the Basics and Driver Setup. For the following we assume, that arangodbDriver
is a configured instance of the driver.
So let’s start the whole thing…
ArangoDB Java Driver: Batch & Asynchronous Mode | ArangoDB Blog
The current arangodb-java-driver supports the usage of ArangoDB’s batch and asynchronous interface. This post will guide you through the usage of these features.
The batch interface
The batch interface enables the user to stack a series of calls and execute them in a batch request. Each stacked request returns a request id that can be used to retrieve the single results from the batch response. So how do you use this feature in the java driver ?
First we create an instance of the java driver:
ArangoConfigure configure = new ArangoConfigure();
configure.init();
ArangoDriver driver = new ArangoDriver(configure);
ArangoDB Java Driver: Simplifying Database Interactions
A new arangodb-java-driver is out now, it’s on github. The driver is available for ArangoDB from version 2.2 onwards.
How to include the driver in your application ?
The driver is available as maven artifact. To add the driver to your project with maven, add the following code to your pom.xml:
<dependencies>
<dependency>
<groupId>com.arangodb</groupId>
<artifactId>arangodb-java-driver</artifactId>
<version>2.2</version>
</dependency>
....
</dependencies>
Get the latest tutorials,
blog posts and news:
Thanks for subscribing! Please check your email for further instructions.