|
| 1 | +/* |
| 2 | + * Copyright (c) 2022 Contributors to the Eclipse Foundation |
| 3 | + * All rights reserved. This program and the accompanying materials |
| 4 | + * are made available under the terms of the Eclipse Public License v1.0 |
| 5 | + * and Apache License v2.0 which accompanies this distribution. |
| 6 | + * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html |
| 7 | + * and the Apache License v2.0 is available at http://www.opensource.org/licenses/apache2.0.php. |
| 8 | + * |
| 9 | + * You may elect to redistribute this code under either of these licenses. |
| 10 | + */ |
| 11 | + |
| 12 | +package org.soujava.demos.mongodb.document; |
| 13 | + |
| 14 | + |
| 15 | +import jakarta.enterprise.inject.se.SeContainer; |
| 16 | +import jakarta.enterprise.inject.se.SeContainerInitializer; |
| 17 | +import net.datafaker.Faker; |
| 18 | +import org.eclipse.jnosql.mapping.document.DocumentTemplate; |
| 19 | + |
| 20 | +import java.util.List; |
| 21 | +import java.util.Set; |
| 22 | +import java.util.logging.Logger; |
| 23 | + |
| 24 | + |
| 25 | +public class App { |
| 26 | + |
| 27 | + private static final Logger LOGGER = Logger.getLogger(App.class.getName()); |
| 28 | + |
| 29 | + public static void main(String[] args) { |
| 30 | + var faker = new Faker(); |
| 31 | + LOGGER.info("Starting the application"); |
| 32 | + try (SeContainer container = SeContainerInitializer.newInstance().initialize()) { |
| 33 | + var template = container.select(DocumentTemplate.class).get(); |
| 34 | + var electronicsCategory = new Category("Electronics", "All electronics"); |
| 35 | + var computerCategory = new Category("Computers", "All computers"); |
| 36 | + var tags = List.of("smartphone", "tablet", "laptop"); |
| 37 | + var manufacturer = new Manufacturer("Apple", "One Infinite Loop Cupertino, CA 95014", "+1-408-996-1010"); |
| 38 | + Product macBookPro = Product.builder().categories(Set.of(electronicsCategory, computerCategory)) |
| 39 | + .manufacturer(manufacturer) |
| 40 | + .name("MacBook Pro") |
| 41 | + .tags(tags) |
| 42 | + .build(); |
| 43 | + |
| 44 | + Product product = template.insert(macBookPro); |
| 45 | + |
| 46 | + LOGGER.info("Product saved: " + product); |
| 47 | + template.select(Product.class).where("id") |
| 48 | + .eq(product.getId()) |
| 49 | + .result().forEach(p -> LOGGER.info("Product found: " + p)); |
| 50 | + |
| 51 | + |
| 52 | + } |
| 53 | + } |
| 54 | + |
| 55 | + private App() { |
| 56 | + } |
| 57 | +} |
0 commit comments