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

Commit

Permalink
fix: Fixed the transactional collection
Browse files Browse the repository at this point in the history
  • Loading branch information
JigarJoshi committed Apr 13, 2022
1 parent 0172d84 commit 8d0f16b
Showing 1 changed file with 9 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,21 @@

import com.tigrisdata.db.client.error.TigrisDBException;
import com.tigrisdata.db.client.model.Filters;
import com.tigrisdata.db.client.service.TigrisCollection;
import com.tigrisdata.db.client.model.TransactionOptions;
import com.tigrisdata.db.client.model.UpdateFields;
import com.tigrisdata.db.client.service.TigrisDatabase;
import com.tigrisdata.db.client.service.TransactionSession;
import com.tigrisdata.db.client.service.TransactionTigrisCollection;
import com.tigrisdata.starter.generated.Order;
import com.tigrisdata.starter.generated.Product;
import com.tigrisdata.starter.generated.User;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.atomic.AtomicInteger;
Expand All @@ -32,22 +39,14 @@
public class OrderController {
private final TigrisDatabase tigrisStarterDatabase;
private final AtomicInteger orderIdSequence;
private final TigrisCollection<User> userCollection;
private final TigrisCollection<Product> productCollection;
private final TigrisCollection<Order> orderCollection;


public OrderController(TigrisDatabase tigrisStarterDatabase) {
this.tigrisStarterDatabase = tigrisStarterDatabase;
this.orderIdSequence = new AtomicInteger();

this.userCollection = tigrisStarterDatabase.getCollection(User.class);
this.productCollection = tigrisStarterDatabase.getCollection(Product.class);
this.orderCollection = tigrisStarterDatabase.getCollection(Order.class);
}

@GetMapping("/{id}")
public Order read(@PathVariable("id") int id) throws TigrisDBException {
return orderCollection.readOne(Filters.eq("id", id)).get();
return tigrisStarterDatabase.getCollection(Order.class).readOne(Filters.eq("id", id)).get();
}
}

0 comments on commit 8d0f16b

Please sign in to comment.