|
4 | 4 | import com.dtsx.astra.sdk.AstraDBRepository; |
5 | 5 | import com.fasterxml.jackson.annotation.JsonProperty; |
6 | 6 | import io.stargate.sdk.json.domain.odm.Document; |
7 | | - |
8 | 7 | import java.util.List; |
9 | 8 |
|
10 | 9 | public class ObjectMappingUpdateMany { |
11 | | - static class Product { |
12 | | - @JsonProperty("product_name") private String name; |
13 | | - @JsonProperty("product_price") private Double price; |
14 | | - Product(String name, Double price) { |
15 | | - this.name = name; |
16 | | - this.price = price; |
17 | | - } |
18 | | - } |
19 | | - public static void main(String[] args) { |
20 | | - AstraDB db = new AstraDB("<token>", "<api_endpoint>"); |
21 | | - AstraDBRepository<Product> productRepository = db |
22 | | - .createCollection("collection_vector1", 14, Product.class); |
| 10 | + static class Product { |
| 11 | + @JsonProperty("product_name") private String name; |
| 12 | + @JsonProperty("product_price") private Double price; |
| 13 | + Product(String name, Double price) { |
| 14 | + this.name = name; |
| 15 | + this.price = price; |
| 16 | + } |
| 17 | + } |
| 18 | + |
| 19 | + public static void main(String[] args) { |
| 20 | + AstraDB db = new AstraDB("<token>", "<api_endpoint>"); |
| 21 | + AstraDBRepository<Product> productRepository = |
| 22 | + db.createCollection("collection_vector1", 14, Product.class); |
23 | 23 |
|
24 | | - // Insert documents into the collection (IDs are generated automatically) |
25 | | - List<String> identifiers = productRepository.saveAll( |
26 | | - List.of( |
27 | | - new Document<Product>() |
28 | | - .vector(new float[]{1f, 0f, 1f, 1f, .5f, 1f, 0f, 0.3f, 0f, 0f, 0f, 0f, 0f, 0f}) |
29 | | - .data(new Product("product1", 9.99)), |
30 | | - new Document<Product>() |
31 | | - .vector(new float[]{1f, 0f, 1f, 1f, .5f, 1f, 0f, 0.3f, 0f, 0f, 0f, 0f, 0f, 0f}) |
32 | | - .data(new Product("product2", 12.99)) |
33 | | - ) |
34 | | - ); |
| 24 | + // Insert documents into the collection (IDs are generated automatically) |
| 25 | + List<String> identifiers = productRepository.saveAll( |
| 26 | + List.of( |
| 27 | + new Document<Product>() |
| 28 | + .vector(new float[]{1f, 0f, 1f, 1f, .5f, 1f, 0f, 0.3f, 0f, 0f, 0f, 0f, 0f, 0f}) |
| 29 | + .data(new Product("product1", 9.99)), |
| 30 | + new Document<Product>() |
| 31 | + .vector(new float[]{1f, 0f, 1f, 1f, .5f, 1f, 0f, 0.3f, 0f, 0f, 0f, 0f, 0f, 0f}) |
| 32 | + .data(new Product("product2", 12.99)))); |
35 | 33 | } |
36 | 34 | } |
0 commit comments