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

Commit

Permalink
fix: Updated to use client library at 1.0.0-alpha.14 with autoGenerat…
Browse files Browse the repository at this point in the history
…e keys support
  • Loading branch information
JigarJoshi committed May 27, 2022
1 parent 0f4524f commit ffaf279
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 36 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.tigrisdata</groupId>
<artifactId>tigris-example-java</artifactId>
<version>1.0.0-alpha.13</version>
<version>1.0.0-alpha.15</version>

<dependencies>
<dependency>
Expand All @@ -26,7 +26,7 @@
</dependencies>
<properties>
<!-- we are still pre-release -->
<tigris.client.java.version>1.0.0-alpha.13</tigris.client.java.version>
<tigris.client.java.version>1.0.0-alpha.15</tigris.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>
Expand Down
17 changes: 7 additions & 10 deletions src/main/java/com/tigrisdata/starter/collections/Order.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
public class Order implements TigrisCollectionType {

@TigrisField(description = "A unique identifier for the order")
@TigrisPrimaryKey(1)
private int id;
@TigrisPrimaryKey(order = 1, autoGenerate = true)
private Integer id;

@TigrisField(description = "The identifier of the user that placed the order")
private int userId;
Expand All @@ -37,8 +37,7 @@ public class Order implements TigrisCollectionType {

public Order() {}

public Order(int id, int userId, double orderTotal, List<ProductItem> productItems) {
this.id = id;
public Order(int userId, double orderTotal, List<ProductItem> productItems) {
this.userId = userId;
this.orderTotal = orderTotal;
this.productItems = productItems;
Expand Down Expand Up @@ -93,7 +92,7 @@ public int hashCode() {
}
}

public int getId() {
public Integer getId() {
return id;
}

Expand All @@ -109,7 +108,7 @@ public List<ProductItem> getProductItems() {
return productItems;
}

public void setId(int id) {
public void setId(Integer id) {
this.id = id;
}

Expand All @@ -130,10 +129,8 @@ public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Order order = (Order) o;
return id == order.id
&& userId == order.userId
&& Double.compare(order.orderTotal, orderTotal) == 0
&& Objects.equals(productItems, order.productItems);
return userId == order.userId && Double.compare(order.orderTotal, orderTotal) == 0 && Objects.equals(id,
order.id) && Objects.equals(productItems, order.productItems);
}

@Override
Expand Down
16 changes: 7 additions & 9 deletions src/main/java/com/tigrisdata/starter/collections/Product.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
public class Product implements TigrisCollectionType {

@TigrisField(description = "A unique identifier for the product")
@TigrisPrimaryKey(1)
private int id;
@TigrisPrimaryKey(order = 1, autoGenerate = true)
private Integer id;

@TigrisField(description = "Name of the product")
private String name;
Expand All @@ -38,14 +38,14 @@ public class Product implements TigrisCollectionType {

public Product() {}

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

public int getId() {
public Integer getId() {
return id;
}

Expand All @@ -61,7 +61,7 @@ public double getPrice() {
return price;
}

public void setId(int id) {
public void setId(Integer id) {
this.id = id;
}

Expand All @@ -82,10 +82,8 @@ public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Product product = (Product) o;
return id == product.id
&& quantity == product.quantity
&& Double.compare(product.price, price) == 0
&& Objects.equals(name, product.name);
return quantity == product.quantity && Double.compare(product.price, price) == 0 && Objects.equals(id,
product.id) && Objects.equals(name, product.name);
}

@Override
Expand Down
12 changes: 5 additions & 7 deletions src/main/java/com/tigrisdata/starter/collections/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@

public class User implements TigrisCollectionType {
@TigrisField(description = "A unique identifier for the user")
@TigrisPrimaryKey(1)
private int id;
@TigrisPrimaryKey(order = 1, autoGenerate = true)
private Integer id;

@TigrisField(description = "Name of the user")
private String name;
Expand All @@ -32,7 +32,7 @@ public class User implements TigrisCollectionType {

public User() {}

public int getId() {
public Integer getId() {
return id;
}

Expand All @@ -44,7 +44,7 @@ public double getBalance() {
return balance;
}

public void setId(int id) {
public void setId(Integer id) {
this.id = id;
}

Expand All @@ -61,9 +61,7 @@ public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
User user = (User) o;
return id == user.id
&& Double.compare(user.balance, balance) == 0
&& Objects.equals(name, user.name);
return Double.compare(user.balance, balance) == 0 && Objects.equals(id, user.id) && Objects.equals(name, user.name);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import org.springframework.web.bind.annotation.RestController;

import java.util.Optional;
import java.util.concurrent.atomic.AtomicInteger;

@RestController
@RequestMapping("order")
Expand All @@ -37,14 +36,11 @@ public class OrderController {
private final TigrisCollection<Product> productCollection;
private final TigrisCollection<Order> orderCollection;

private final AtomicInteger orderIdSequence;

public OrderController(TigrisDatabase tigrisStarterDatabase) {
this.tigrisStarterDatabase = tigrisStarterDatabase;
this.userCollection = tigrisStarterDatabase.getCollection(User.class);
this.productCollection = tigrisStarterDatabase.getCollection(Product.class);
this.orderCollection = tigrisStarterDatabase.getCollection(Order.class);
this.orderIdSequence = new AtomicInteger();
}

@GetMapping("/{id}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
package com.tigrisdata.starter.controller;

import com.tigrisdata.db.client.Filters;
import com.tigrisdata.db.client.InsertResponse;
import com.tigrisdata.db.client.TigrisCollection;
import com.tigrisdata.db.client.TigrisDatabase;
import com.tigrisdata.db.client.error.TigrisException;
Expand Down Expand Up @@ -42,8 +43,8 @@ public ProductController(TigrisDatabase tigrisDatabase) {

@PostMapping("/create")
public ResponseEntity<String> create(@RequestBody Product product) throws TigrisException {
productTigrisCollection.insert(product);
return ResponseEntity.status(HttpStatus.CREATED).body("product created");
InsertResponse insertResponse = productTigrisCollection.insert(product);
return ResponseEntity.status(HttpStatus.CREATED).body("product created with id = "+insertResponse.getGeneratedKeys()[0].get("id"));
}

@GetMapping("/{id}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
package com.tigrisdata.starter.controller;

import com.tigrisdata.db.client.Filters;
import com.tigrisdata.db.client.InsertResponse;
import com.tigrisdata.db.client.TigrisCollection;
import com.tigrisdata.db.client.TigrisDatabase;
import com.tigrisdata.db.client.error.TigrisException;
Expand Down Expand Up @@ -42,8 +43,8 @@ public UserController(TigrisDatabase tigrisDatabase) {

@PostMapping("/create")
public ResponseEntity<String> create(@RequestBody User user) throws TigrisException {
userTigrisCollection.insert(user);
return ResponseEntity.status(HttpStatus.CREATED).body("User created");
InsertResponse insertResponse = userTigrisCollection.insert(user);
return ResponseEntity.status(HttpStatus.CREATED).body("User created with id = "+insertResponse.getGeneratedKeys()[0].get("id"));
}

@GetMapping("/{id}")
Expand Down

0 comments on commit ffaf279

Please sign in to comment.