Add Maven dependencies to your pom.xml:
<dependency>
<groupId>com.protonail.bolt-jna</groupId>
<artifactId>bolt-jna-core</artifactId>
<version>x.x.x</version>
</dependency>
<dependency>
<groupId>com.protonail.bolt-jna</groupId>
<artifactId>bolt-jna-native</artifactId>
<version>x.x.x</version>
<classifier>osx</classifier>
</dependency>
<dependency>
<groupId>com.protonail.bolt-jna</groupId>
<artifactId>bolt-jna-native</artifactId>
<version>x.x.x</version>
<classifier>windows-x86_64</classifier>
</dependency>
<dependency>
<groupId>com.protonail.bolt-jna</groupId>
<artifactId>bolt-jna-native</artifactId>
<version>x.x.x</version>
<classifier>windows-x86</classifier>
</dependency>
<dependency>
<groupId>com.protonail.bolt-jna</groupId>
<artifactId>bolt-jna-native</artifactId>
<version>x.x.x</version>
<classifier>linux-x86_64</classifier>
</dependency>
<dependency>
<groupId>com.protonail.bolt-jna</groupId>
<artifactId>bolt-jna-native</artifactId>
<version>x.x.x</version>
<classifier>linux-x86</classifier>
</dependency>
If you don't want to use native libraries for some platforms (see classifier
tag) then just remove theirs dependencies.
If you want to use snapshot version (with -SNAPSHOR
suffix) then just add snapshot repository to your pom.xml:
<repositories>
...
<repository>
<id>sonatype</id>
<url>https://oss.sonatype.org/content/groups/public</url>
</repository>
...
</repositories>
Go runtime should be initialized straight after Java application start. It it can help to avoid "could not obtain pthread_keys" error (details here).
public static void main() {
Bolt.init() // Hack for fix error: could not obtain pthread_keys
...
}
try(Bolt bolt = new Bolt(databaseFile, options)) {
// Work with database here
}
or with options
try(BoltOptions options = new BoltOptions(5000 /* timeout in ms */)) {
try(Bolt bolt = new Bolt(databaseFile, BoltFileMode.DEFAULT, options)) {
// Work with database here
}
}
bolt.update(boltTransaction -> {
try(BoltBucket bucket = boltTransaction.createBucket("my-bucket".getBytes())) { // 'my-bucket' must not be exists
// Work with bucket here
}
});
or user createBucketIfNotExists
bolt.update(boltTransaction -> {
try(BoltBucket bucket = boltTransaction.createBucketIfNotExists("my-bucket".getBytes())) { // 'my-bucket' must not be exists
// Work with bucket here
}
});
bolt.update(boltTransaction -> {
boltTransaction.deleteBucket("my-bucket".getBytes()); // 'my-bucket' must be exists
});
bolt.view(boltTransaction -> {
try(BoltBucket bucket = boltTransaction.getBucket("my-bucket".getBytes())) { // 'my-bucket' must be exists
byte[] value = bucket.get("key".getBytes());
}
});
bolt.update(boltTransaction -> {
try(BoltBucket bucket = boltTransaction.getBucket("my-bucket".getBytes())) { // 'my-bucket' must be exists
bucket.put("key".getBytes(), "value".getBytes());
}
});
bolt.update(boltTransaction -> {
try(BoltBucket bucket = boltTransaction.getBucket("my-bucket".getBytes())) { // 'my-bucket' must be exists
bucket.delete("key".getBytes());
}
});
bolt.view(boltTransaction -> {
try(BoltBucket bucket = boltTransaction.getBucket("my-bucket".getBytes())) { // 'my-bucket' must be exists
try(BoltCursor cursor = bucket.createCursor()) {
BoltKeyValue currentKeyValue = cursor.first();
while (currentKeyValue != null) {
byte[] key = currentKeyValue.getKey();
byte[] value = currentKeyValue.getValue();
currentKeyValue = cursor.next();
}
}
}
});