Skip to content

Commit f4c2125

Browse files
authored
Merge pull request #120 from djsauble/patch-35
Update ObjectMappingInsertMany.java
2 parents a0cb4e3 + b4082c2 commit f4c2125

File tree

1 file changed

+22
-24
lines changed

1 file changed

+22
-24
lines changed

astra-db-client/src/test/java/com/dtsx/astra/sdk/documentation/ObjectMappingInsertMany.java

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,31 @@
44
import com.dtsx.astra.sdk.AstraDBRepository;
55
import com.fasterxml.jackson.annotation.JsonProperty;
66
import io.stargate.sdk.json.domain.odm.Document;
7-
87
import java.util.List;
98

109
public class ObjectMappingInsertMany {
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);
2323

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))));
3533
}
3634
}

0 commit comments

Comments
 (0)