Skip to content
This repository has been archived by the owner on Sep 7, 2023. It is now read-only.

Commit

Permalink
fix! Updated starter application to be 1.0.0-alpha.6 compatible
Browse files Browse the repository at this point in the history
  • Loading branch information
JigarJoshi committed Apr 21, 2022
1 parent 8d0f16b commit 7fd20b9
Show file tree
Hide file tree
Showing 14 changed files with 343 additions and 225 deletions.
72 changes: 2 additions & 70 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,77 +2,9 @@
A starter Java application for TigrisDB.

[![java-ci](https://github.com/tigrisdata/tigrisdb-example-java/actions/workflows/java-ci.yml/badge.svg?branch=main)](https://github.com/tigrisdata/tigrisdb-example-java/actions/workflows/java-ci.yml)
# Key points

### Schema
TigrisDB schemas are located in `src/main/resources/tigrisdb-schema`.

Example schema

```json
{
"name": "User",
"description": "This document records the details of user for tigris store",
"properties": {
"id": {
"description": "A unique identifier for the user",
"type": "int"
},
"name": {
"description": "Name of the user",
"type": "string"
},
"balance": {
"description": "user balance in USD",
"type": "double"
}
},
"primary_key": [
"id"
]
}
```

### Schema to model generation

TigrisDB maven plugin reads these JSON schema files and generates Java models.
Refer in `pom.xml` for `com.tigrisdata.tools. code-generator:maven-plugin`
usage.

```xml

<plugin>
<groupId>com.tigrisdata.tools.code-generator</groupId>
<artifactId>maven-plugin</artifactId>
<!-- we are still pre-release -->
<version>1.0.0-alpha.2</version>

<executions>
<execution>
<goals>
<goal>generate-sources</goal>
</goals>
</execution>
</executions>
<configuration>
<schemaDir>src/main/resources/tigrisdb-schema</schemaDir>
<packageName>com.tigrisdata.store.generated</packageName>
<outputDirectory>target/generated-sources</outputDirectory>
</configuration>
</plugin>
```

### Operating on models

TigrisDB client API supports these generated models. You can use them to
represent your document.

```java
User alice = new User(1,"Alice");

TigrisCollection<User> userCollection = db.getCollection(User.class);
userCollection.insert(alice);
```
# Quick start
- [documentation](https://docs.tigrisdata.com/quickstart/with-java)

# Restful endpoints

Expand Down
67 changes: 16 additions & 51 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,9 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.tigrisdata</groupId>
<artifactId>tigrisdb-example-java</artifactId>
<version>1.0.0-alpha.2</version>
<version>1.0.0-alpha.6</version>

<dependencies>
<!-- generated models uses jackson annotations -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.13.2</version>
</dependency>
<dependency>
<groupId>com.tigrisdata</groupId>
<artifactId>tigrisdb-client</artifactId>
Expand All @@ -27,58 +21,29 @@
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-ui</artifactId>
<version>1.6.6</version>
<version>1.6.7</version>
</dependency>
</dependencies>
<properties>
<!-- we are still pre-release -->
<tigrisdb.client.java.version>1.0.0-alpha.6</tigrisdb.client.java.version>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>

<build>
<plugins>
<plugin>
<groupId>com.tigrisdata.tools.code-generator</groupId>
<artifactId>maven-plugin</artifactId>
<version>${tigrisdb.client.java.version}</version>
<executions>
<execution>
<goals>
<goal>generate-sources</goal>
</goals>
</execution>
</executions>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.10.1</version>
<configuration>
<schemaDir>src/main/resources/tigrisdb-schema</schemaDir>
<packageName>com.tigrisdata.starter.generated</packageName>
<outputDirectory>target/generated-sources</outputDirectory>
<!-- For immutable models to work with jackson -->
<compilerArgument>-parameters</compilerArgument>
</configuration>
</plugin>
</plugins>
</build>
<properties>
<!-- we are still pre-release -->
<tigrisdb.client.java.version>1.0.0-alpha.2</tigrisdb.client.java.version>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>
<repositories>
<repository>
<id>sonatype-snapshots</id>
<url>https://s01.oss.sonatype.org/content/repositories/snapshots/</url>
<snapshots>
<updatePolicy>always</updatePolicy>
<enabled>true</enabled>
</snapshots>
<layout>default</layout>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>sonatype-snapshots</id>
<url>https://s01.oss.sonatype.org/content/repositories/snapshots/</url>
<snapshots>
<updatePolicy>always</updatePolicy>
<enabled>true</enabled>
</snapshots>
<layout>default</layout>
</pluginRepository>
</pluginRepositories>
</project>
124 changes: 124 additions & 0 deletions src/main/java/com/tigrisdata/starter/collections/Order.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
/*
* Copyright 2022 Tigris Data, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the
* License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.tigrisdata.starter.collections;

import com.tigrisdata.db.annotation.TigrisDBCollectionField;
import com.tigrisdata.db.annotation.TigrisDBCollectionPrimaryKey;
import com.tigrisdata.db.type.TigrisCollectionType;

import java.util.List;
import java.util.Objects;

public class Order implements TigrisCollectionType {

@TigrisDBCollectionField(description = "A unique identifier for the order")
@TigrisDBCollectionPrimaryKey(1)
private final int id;

@TigrisDBCollectionField(description = "The identifier of the user that placed the order")
private final int userId;

@TigrisDBCollectionField(description = "The total cost of the order")
private final double orderTotal;

@TigrisDBCollectionField(description = "The list of products that are part of this order")
private final List<ProductItem> productItems;

public Order(int id, int userId, double orderTotal, List<ProductItem> productItems) {
this.id = id;
this.userId = userId;
this.orderTotal = orderTotal;
this.productItems = productItems;
}

public static class ProductItem {
@TigrisDBCollectionField(description = "The product identifier")
private final int productId;

@TigrisDBCollectionField(description = "The quantity of this product in this order")
private final int quantity;

public ProductItem(int productId, int quantity) {
this.productId = productId;
this.quantity = quantity;
}

public int getProductId() {
return productId;
}

public int getQuantity() {
return quantity;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;

ProductItem that = (ProductItem) o;

if (productId != that.productId) return false;
return quantity == that.quantity;
}

@Override
public int hashCode() {
int result = productId;
result = 31 * result + quantity;
return result;
}
}

public int getId() {
return id;
}

public int getUserId() {
return userId;
}

public double getOrderTotal() {
return orderTotal;
}

public List<ProductItem> getProductItems() {
return productItems;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;

Order order = (Order) o;

if (id != order.id) return false;
if (userId != order.userId) return false;
if (Double.compare(order.orderTotal, orderTotal) != 0) return false;
return Objects.equals(productItems, order.productItems);
}

@Override
public int hashCode() {
int result;
long temp;
result = id;
result = 31 * result + userId;
temp = Double.doubleToLongBits(orderTotal);
result = 31 * result + (int) (temp ^ (temp >>> 32));
result = 31 * result + (productItems != null ? productItems.hashCode() : 0);
return result;
}
}
84 changes: 84 additions & 0 deletions src/main/java/com/tigrisdata/starter/collections/Product.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*
* Copyright 2022 Tigris Data, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the
* License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.tigrisdata.starter.collections;

import com.tigrisdata.db.annotation.TigrisDBCollectionField;
import com.tigrisdata.db.annotation.TigrisDBCollectionPrimaryKey;
import com.tigrisdata.db.type.TigrisCollectionType;

import java.util.Objects;

public class Product implements TigrisCollectionType {

@TigrisDBCollectionField(description = "A unique identifier for the product")
@TigrisDBCollectionPrimaryKey(1)
private final int id;

@TigrisDBCollectionField(description = "Name of the product")
private final String name;

@TigrisDBCollectionField(description = "Number of products available in the store")
private final int quantity;

@TigrisDBCollectionField(description = "Price of the product")
private final double price;

public Product(int id, String name, int quantity, double price) {
this.id = id;
this.name = name;
this.quantity = quantity;
this.price = price;
}

public int getId() {
return id;
}

public String getName() {
return name;
}

public int getQuantity() {
return quantity;
}

public double getPrice() {
return price;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;

Product product = (Product) o;

if (id != product.id) return false;
if (quantity != product.quantity) return false;
if (Double.compare(product.price, price) != 0) return false;
return Objects.equals(name, product.name);
}

@Override
public int hashCode() {
int result;
long temp;
result = id;
result = 31 * result + (name != null ? name.hashCode() : 0);
result = 31 * result + quantity;
temp = Double.doubleToLongBits(price);
result = 31 * result + (int) (temp ^ (temp >>> 32));
return result;
}
}
Loading

0 comments on commit 7fd20b9

Please sign in to comment.