Java Reference
Tigris provides an easy-to-use and intuitive interface for Java. Setting up the database is instantaneous, as well - no need for tedious configuration. You define the data model as part of the application code, which then drives the database infrastructure without you having to configure and provision database resources.
1. Install package
<!-- https://mvnrepository.com/artifact/com.tigrisdata/tigris-client -->
<dependency>
<groupId>com.tigrisdata</groupId>
<artifactId>tigris-client</artifactId>
<version>insert_version_number_here</version>
</dependency>
2. Define data models
package com.tigrisdata.db.client.collection;
import com.tigrisdata.db.annotation.TigrisField;
import com.tigrisdata.db.annotation.TigrisPrimaryKey;
import com.tigrisdata.db.type.TigrisDocumentCollectionType;
import java.util.Objects;
@TigrisCollection(value = "catalog")
public class Catalog implements TigrisDocumentCollectionType {
@TigrisField(description = "A unique identifier for the catalog item")
@TigrisPrimaryKey(order = 1, autoGenerate = true)
private int id;
@TigrisField(description = "Product name")
private String name;
@TigrisField(description = "Product price")
private double price;
@TigrisField(description = "Brand name")
private String brand;
@TigrisField(description = "Categorized item label")
private String labels;
@TigrisField(description = "Product's popularity rating")
private int popularity;
public Catalog() {}
public Catalog(String name, double price, String brand, String labels, int popularity) {
this.name = name;
this.price = price;
this.brand = brand;
this.labels = labels;
this.popularity = popularity;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
public String getBrand() {
return brand;
}
public void setBrand(String brand) {
this.brand = brand;
}
public String getLabels() {
return labels;
}
public void setLabels(String labels) {
this.labels = labels;
}
public int getPopularity() {
return popularity;
}
public void setPopularity(int popularity) {
this.popularity = popularity;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
Catalog catalog = (Catalog) o;
return id == catalog.id && Double.compare(catalog.price, price) == 0
&& popularity == catalog.popularity && Objects.equals(name, catalog.name)
&& Objects.equals(brand, catalog.brand) && Objects.equals(labels,
catalog.labels);
}
@Override
public int hashCode() {
return Objects.hash(id, name, price, brand, labels, popularity);
}
}
3. Persist data
Catalog product = new Catalog("fiona handbag", 99.9, "michael kors", "purses", 8);
InsertResponse<Catalog> response = catalog.insert(product);
4. Query data
Optional<Catalog> product = catalog.readOne(Filters.eq("brand", "adidas"))
5. Search data
SearchRequest request = SearchRequest.newBuilder().withQuery("running").build();
Iterator<SearchResult<Catalog>> results = catalog.search(request);