Giriş
İki tane standart var
1. Jakarta NoSQL Standardı
2. Jakarta Data Standardı
Jakarta NoSQL Standardı
Açıklaması şöyle. Yani NoSQL veri tabanları ile çalışmak için
We have JPA for a while in the specification world to make your life easier in the relational database world. We're glad to work on a specification to make it easier to work with NoSQL: Jakarta NoSQL.
The core principle of the Jakarta NoSQL is to standardize behavior, to make a low cognitive load while changing among databases, and at the same time be extensible enough to allow specific behavior from a particular vendor. At this time we have the pleasure of announcing a new version, Jakarta NoSQL Version 1.0.0-b4.
Jakarta Data Standardı
Açıklaması şöyle.
After several discussions to have more integration between JPA and NoSQL, the community has decided to create a new specification to apply those patterns around data: Jakarta Data. We've published it to the Jakarta EE Committee.Jakarta NoSQL Kullanımı
Builder veya Fluent şekilde kullanılabilir. Açıklaması şöyle
... Jakarta NoSQL has two approaches to creating a database request: using a fluent API and using a builder pattern.
Maven
Şu satırı dahil ederiz
<dependency>
<groupId>org.eclipse.jnosql.mapping</groupId>
<artifactId>mongodb-extension</artifactId>
<version>${project.version}</version>
</dependency>
DocumentCollectionManager Sınıfı
Örnek
Şöyle yaparız
@ApplicationScoped public class MongoDBProducer { @Inject @ConfigProperty(name = "document") private DocumentCollectionManager manager; @Produces public MongoDBDocumentCollectionManager getManager() { return (MongoDBDocumentCollectionManager) manager; } public void destroy(@Disposes DocumentCollectionManager manager) { manager.close(); } }
properties dosyası şöyledir
document=document document.database=olympus document.settings.jakarta.nosql.host=localhost:27017 document.provider=org.eclipse.jnosql.communication.mongodb.document.MongoDBDocumentConfiguration
DocumentTemplate Sınfı
try (SeContainer container = SeContainerInitializer.newInstance().initialize()) { Worker poliana = Worker.builder() .age(30).name("Poliana") .city("Salvador") .gender(Gender.FEMALE) .dailyHours(30).build(); Worker otavio = Worker.builder() .age(35).name("Otavio") .city("Salvador") .gender(Gender.MALE) .dailyHours(30).build(); DocumentTemplate template = container.select(DocumentTemplate.class).get(); template.insert(Arrays.asList(otavio, poliana)); ... template.delete(Worker.class, otavio.getId()); template.delete(Worker.class, poliana.getId()); }
insert metodu
Örnek
Şöyle yaparız
try (SeContainer container = SeContainerInitializer.newInstance().initialize()) { Worker poliana = Worker.builder() .age(30).name("Poliana") .city("Salvador") .gender(Gender.FEMALE) .dailyHours(30).build(); Worker otavio = Worker.builder() .age(35).name("Otavio") .city("Salvador") .gender(Gender.MALE) .dailyHours(30).build(); DocumentTemplate template = container.select(DocumentTemplate.class).get(); template.insert(Arrays.asList(otavio, poliana)); }
try (SeContainer container = SeContainerInitializer.newInstance().initialize()) { DocumentTemplate template = container.select(DocumentTemplate.class).get(); DocumentCondition maleAfterThirty = and(eq("gender", Gender.MALE), gte("age", 30)); DocumentCondition femaleAfterThirty = and(eq("gender", Gender.FEMALE),gte("age", 30)); DocumentQuery query = DocumentQuery.builder() .from("Worker") .sort(asc("name")) .where(or(maleAfterThirty, femaleAfterThirty)) .build(); Stream<Worker> stream = template.select(query); List<Worker> workers = stream.collect(Collectors.toList()); workers.forEach(System.out::println); }
Hiç yorum yok:
Yorum Gönder