8000 GitHub - tarantool/cartridge-java at v0.11.1
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

tarantool/cartridge-java

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Java driver for Tarantool Cartridge

java-driver:ubuntu/master Actions Status

Java driver for Tarantool Cartridge for Tarantool versions 1.10+ based on the asynchronous Netty framework and official MessagePack serializer. Provides CRUD APIs for seamlessly working with standalone Tarantool servers and clusters managed by Tarantool Cartridge with sharding via vshard.

Quickstart

Example of single instance Tarantool application and java app connected using cartridge-java.

The easiest way to start experimenting with cartridge-java and single instance tarantool app is to use single instance test. You can set breakpoints and run it in debug mode. Testcontainers will start single instance tarantool application for you. So you will be able to manipulate data in Tarantool in real life through java expressions or Tarantool console.

If you want to start tarantool application manually all you need is to run this file in tarantool

tarantool src/test/resources/single-instance.lua

Example of TarantoolClient set up

return TarantoolClientFactory.createClient()
// If any addresses or an address provider are not specified,
// the default host 127.0.0.1 and port 3301 are used
.withAddress(container.getHost(), container.getPort())
// For connecting to a Cartridge application, use the value of cluster_cookie parameter in the init.lua file
.withCredentials(container.getUsername(), container.getPassword())
// you may also specify more client settings, such as:
// timeouts, number of connections, custom MessagePack entities to Java objects mapping, etc.
.build();

Example of client API usage

try (TarantoolClient<TarantoolTuple, TarantoolResult<TarantoolTuple>> client = setupClient()) {
TarantoolTupleFactory tupleFactory =
new DefaultTarantoolTupleFactory(mapperFactory.defaultComplexTypesMapper());
TarantoolSpaceOperations<TarantoolTuple, TarantoolResult<TarantoolTuple>> regionSpace =
client.space("region");
TarantoolTuple tarantoolTuple = tupleFactory.create(Arrays.asList(77, "Moscow"));
TarantoolResult<TarantoolTuple> insertTuples = regionSpace.insert(tarantoolTuple).get();
TarantoolResult<TarantoolTuple> selectTuples =
regionSpace.select(Conditions.equals("id", 77)).get();
TarantoolTuple insertTuple = insertTuples.get(0);
TarantoolTuple selectTuple = selectTuples.get(0);
assertEquals(insertTuple.getInteger("id"), selectTuple.getInteger("id"));
assertEquals(insertTuple.getString("name"), selectTuple.getString("name"));
}

If you use this code in another project don't forget to add cartridge-driver dependency:

<dependency>
  <groupId>io.tarantool</groupId>
  <artifactId>cartridge-driver</artifactId>
  <version>0.11.1</version>
</dependency>

Advanced usage

Documentation

The Java Docs are available at Github pages.

If you have any questions about working with Tarantool, check out the site tarantool.io.

Feel free to ask questions about Tarantool and usage of this driver on Stack Overflow with tag tarantool or join our community support chats in Telegram: English and Russian.

Requirements

Java 1.8 or higher is required for building and using this driver.

Building

  1. Docker accessible to the current user is required for running integration tests.
  2. Set up the right user for running Tarantool with in the container:
export TARANTOOL_SERVER_USER=<current user>
export TARANTOOL_SERVER_GROUP=<current group>

Substitute the user and group in these commands with the user and group under which the tests will run. 3. Use ./mvnw verify to run unit tests and ./mvnw test -Pintegration to run integration tests. 4. Use ./mvnw install for installing the artifact locally.

Contributing

Contributions to this project are always welcome and highly encouraged. See conventions for tests

About

Tarantool Cartridge Java driver for Tarantool versions 1.10+ based on Netty framework

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 16

Languages

0