diff --git a/jnosql/jnosql-artemis/pom.xml b/jnosql/jnosql-artemis/pom.xml new file mode 100644 index 0000000000..6186b3510c --- /dev/null +++ b/jnosql/jnosql-artemis/pom.xml @@ -0,0 +1,88 @@ + + + 4.0.0 + + + com.baeldung.jnosql + jnosql + 1.0-SNAPSHOT + + + jnosql-artemis + war + + + 2.4.2 + false + + + + ${artifactId} + + + net.wasdev.wlp.maven.plugins + liberty-maven-plugin + ${liberty-maven-plugin.version} + + + io.openliberty + openliberty-webProfile8 + RELEASE + zip + + project + true + src/main/liberty/config/server.xml + + + + install-server + prepare-package + + install-server + create-server + install-feature + + + + install-apps + package + + install-apps + + + + + + + + + + + javax + javaee-web-api + 8.0 + provided + + + + org.jnosql.artemis + artemis-configuration + ${jnosql.version} + + + org.jnosql.artemis + artemis-document + ${jnosql.version} + + + org.jnosql.diana + mongodb-driver + ${jnosql.version} + + + + + diff --git a/jnosql/jnosql-artemis/src/main/java/com/baeldung/jnosql/artemis/AppConfig.java b/jnosql/jnosql-artemis/src/main/java/com/baeldung/jnosql/artemis/AppConfig.java new file mode 100644 index 0000000000..bf445d9d01 --- /dev/null +++ b/jnosql/jnosql-artemis/src/main/java/com/baeldung/jnosql/artemis/AppConfig.java @@ -0,0 +1,10 @@ +package com.baeldung.jnosql.artemis; + +import javax.enterprise.context.Initialized; +import javax.enterprise.event.Observes; +import javax.ws.rs.ApplicationPath; +import javax.ws.rs.core.Application; + +@ApplicationPath("") +public class AppConfig extends Application { +} diff --git a/jnosql/jnosql-artemis/src/main/java/com/baeldung/jnosql/artemis/EmbeddedMongoDBSetup.java b/jnosql/jnosql-artemis/src/main/java/com/baeldung/jnosql/artemis/EmbeddedMongoDBSetup.java new file mode 100644 index 0000000000..8b3e161f85 --- /dev/null +++ b/jnosql/jnosql-artemis/src/main/java/com/baeldung/jnosql/artemis/EmbeddedMongoDBSetup.java @@ -0,0 +1,52 @@ +package com.baeldung.jnosql.artemis; + +import de.flapdoodle.embed.mongo.MongodExecutable; +import de.flapdoodle.embed.mongo.MongodProcess; +import de.flapdoodle.embed.mongo.MongodStarter; +import de.flapdoodle.embed.mongo.config.MongodConfigBuilder; +import de.flapdoodle.embed.mongo.config.Net; +import de.flapdoodle.embed.mongo.distribution.Version; +import de.flapdoodle.embed.process.runtime.Network; + +import javax.enterprise.context.ApplicationScoped; +import javax.enterprise.context.Destroyed; +import javax.enterprise.context.Initialized; +import javax.enterprise.event.Observes; +import java.io.IOException; + +@ApplicationScoped +public class EmbeddedMongoDBSetup { + + private static final String MONGODB_HOST = "localhost"; + private static final int MONGODB_PORT = 27019; + + private static final MongodStarter starter = MongodStarter.getDefaultInstance(); + private static MongodExecutable _mongodExe; + private static MongodProcess _mongod; + + public void init(@Observes @Initialized(ApplicationScoped.class) Object init) { + try { + System.out.println("Starting Embedded MongoDB"); + initdb(); + System.out.println("Embedded MongoDB started"); + } catch (IOException e) { + System.out.println("Embedded MongoDB starting error !!"); + e.printStackTrace(); + } + } + + private void initdb() throws IOException { + _mongodExe = starter.prepare(new MongodConfigBuilder() + .version(Version.Main.DEVELOPMENT) + .net(new Net(MONGODB_HOST, MONGODB_PORT, Network.localhostIsIPv6())) + .build()); + _mongod = _mongodExe.start(); + } + + public void destroy(@Observes @Destroyed(ApplicationScoped.class) Object init) { + System.out.println("Stopping Embedded MongoDB"); + _mongod.stop(); + _mongodExe.stop(); + System.out.println("Embedded MongoDB stopped !"); + } +} diff --git a/jnosql/jnosql-artemis/src/main/java/com/baeldung/jnosql/artemis/EntityManagerProducer.java b/jnosql/jnosql-artemis/src/main/java/com/baeldung/jnosql/artemis/EntityManagerProducer.java new file mode 100644 index 0000000000..c51868886b --- /dev/null +++ b/jnosql/jnosql-artemis/src/main/java/com/baeldung/jnosql/artemis/EntityManagerProducer.java @@ -0,0 +1,33 @@ +package com.baeldung.jnosql.artemis; + +import org.jnosql.artemis.ConfigurationUnit; +import org.jnosql.diana.api.document.DocumentCollectionManager; +import org.jnosql.diana.api.document.DocumentCollectionManagerFactory; +import org.jnosql.diana.mongodb.document.MongoDBDocumentCollectionManager; +import org.jnosql.diana.mongodb.document.MongoDBDocumentConfiguration; + +import javax.annotation.PostConstruct; +import javax.enterprise.context.ApplicationScoped; +import javax.enterprise.inject.Disposes; +import javax.enterprise.inject.Produces; +import javax.inject.Inject; + +@ApplicationScoped +public class EntityManagerProducer { + + private static final String DATABASE = "todos"; + + @Inject + @ConfigurationUnit(name = "document") + private DocumentCollectionManagerFactory managerFactory; + + @Produces + public DocumentCollectionManager getEntityManager() { + return managerFactory.get(DATABASE); + } + + public void close(@Disposes DocumentCollectionManager entityManager) { + entityManager.close(); + } + +} diff --git a/jnosql/jnosql-artemis/src/main/java/com/baeldung/jnosql/artemis/RepositoryTodoManager.java b/jnosql/jnosql-artemis/src/main/java/com/baeldung/jnosql/artemis/RepositoryTodoManager.java new file mode 100644 index 0000000000..2b19858f6d --- /dev/null +++ b/jnosql/jnosql-artemis/src/main/java/com/baeldung/jnosql/artemis/RepositoryTodoManager.java @@ -0,0 +1,41 @@ +package com.baeldung.jnosql.artemis; + +import com.baeldung.jnosql.artemis.qualifier.Repo; +import org.jnosql.artemis.Database; +import org.jnosql.artemis.DatabaseType; + +import javax.enterprise.context.ApplicationScoped; +import javax.inject.Inject; +import java.util.List; +import java.util.Optional; + +@ApplicationScoped +@Repo +public class RepositoryTodoManager implements TodoManager { + + @Inject + @Database(DatabaseType.DOCUMENT) + private TodoRepository repository; + + @Override + public Todo add(Todo todo) { + return repository.save(todo); + } + + @Override + public Todo get(String id) { + Optional todo = repository.findById(id); + return todo.get(); + } + + @Override + public List getAll() { + return repository.findAll(); + } + + @Override + public void delete(String id) { + repository.deleteById(id); + } + +} diff --git a/jnosql/jnosql-artemis/src/main/java/com/baeldung/jnosql/artemis/TemplateTodoManager.java b/jnosql/jnosql-artemis/src/main/java/com/baeldung/jnosql/artemis/TemplateTodoManager.java new file mode 100644 index 0000000000..8c9ce745f7 --- /dev/null +++ b/jnosql/jnosql-artemis/src/main/java/com/baeldung/jnosql/artemis/TemplateTodoManager.java @@ -0,0 +1,43 @@ +package com.baeldung.jnosql.artemis; + +import com.baeldung.jnosql.artemis.qualifier.Template; +import org.jnosql.artemis.document.DocumentTemplate; +import org.jnosql.diana.api.document.DocumentQuery; + +import javax.enterprise.context.ApplicationScoped; +import javax.inject.Inject; +import java.util.List; +import java.util.Optional; + +import static org.jnosql.diana.api.document.query.DocumentQueryBuilder.select; + +@ApplicationScoped +@Template +public class TemplateTodoManager implements TodoManager { + + @Inject + private DocumentTemplate documentTemplate; + + @Override + public Todo add(Todo todo) { + return documentTemplate.insert(todo); + } + + @Override + public Todo get(String id) { + Optional todo = documentTemplate.find(Todo.class, id); + return todo.get(); + } + + @Override + public List getAll() { + DocumentQuery query = select().from("Todo").build(); + return documentTemplate.select(query); + } + + @Override + public void delete(String id) { + documentTemplate.delete(Todo.class, id); + } + +} diff --git a/jnosql/jnosql-artemis/src/main/java/com/baeldung/jnosql/artemis/Todo.java b/jnosql/jnosql-artemis/src/main/java/com/baeldung/jnosql/artemis/Todo.java new file mode 100644 index 0000000000..f250ddfa66 --- /dev/null +++ b/jnosql/jnosql-artemis/src/main/java/com/baeldung/jnosql/artemis/Todo.java @@ -0,0 +1,51 @@ +package com.baeldung.jnosql.artemis; + +import org.jnosql.artemis.Column; +import org.jnosql.artemis.Entity; +import org.jnosql.artemis.Id; + +import java.io.Serializable; + +@Entity +public class Todo implements Serializable { + + @Id("id") + public String id; + @Column + public String name; + @Column + public String description; + + public Todo() { + } + + public Todo(String id, String name, String description) { + this.id = id; + this.name = name; + this.description = description; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } +} diff --git a/jnosql/jnosql-artemis/src/main/java/com/baeldung/jnosql/artemis/TodoManager.java b/jnosql/jnosql-artemis/src/main/java/com/baeldung/jnosql/artemis/TodoManager.java new file mode 100644 index 0000000000..cdcfea5b40 --- /dev/null +++ b/jnosql/jnosql-artemis/src/main/java/com/baeldung/jnosql/artemis/TodoManager.java @@ -0,0 +1,14 @@ +package com.baeldung.jnosql.artemis; + +import java.util.List; + +public interface TodoManager { + + Todo add(Todo todo); + + Todo get(String id); + + List getAll(); + + void delete(String id); +} diff --git a/jnosql/jnosql-artemis/src/main/java/com/baeldung/jnosql/artemis/TodoRepository.java b/jnosql/jnosql-artemis/src/main/java/com/baeldung/jnosql/artemis/TodoRepository.java new file mode 100644 index 0000000000..52381d1757 --- /dev/null +++ b/jnosql/jnosql-artemis/src/main/java/com/baeldung/jnosql/artemis/TodoRepository.java @@ -0,0 +1,10 @@ +package com.baeldung.jnosql.artemis; + +import org.jnosql.artemis.Repository; + +import java.util.List; + +public interface TodoRepository extends Repository { + List findByName(String name); + List findAll(); +} diff --git a/jnosql/jnosql-artemis/src/main/java/com/baeldung/jnosql/artemis/TodoResource.java b/jnosql/jnosql-artemis/src/main/java/com/baeldung/jnosql/artemis/TodoResource.java new file mode 100644 index 0000000000..42149af3cc --- /dev/null +++ b/jnosql/jnosql-artemis/src/main/java/com/baeldung/jnosql/artemis/TodoResource.java @@ -0,0 +1,48 @@ +package com.baeldung.jnosql.artemis; + +import com.baeldung.jnosql.artemis.qualifier.Repo; +import com.baeldung.jnosql.artemis.qualifier.Template; + +import javax.inject.Inject; +import javax.ws.rs.*; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import javax.ws.rs.core.UriBuilder; + +@Path("todos") +public class TodoResource { + + /* + Use eiher @Template or @Repo + */ + @Inject + @Template + //@Repo + private TodoManager todoManager; + + @GET + @Path("") + @Produces(MediaType.APPLICATION_JSON) + public Response all() { + return Response.ok(todoManager.getAll()).build(); + } + + @GET + @Path("{id}") + @Produces(MediaType.APPLICATION_JSON) + public Response get(@PathParam("id") String id) { + Todo todo = todoManager.get(id); + return Response.ok(todo).build(); + } + + @POST + @Consumes(MediaType.APPLICATION_JSON) + public Response add(Todo todo) { + Todo savedTodo = todoManager.add(todo); + System.out.println(savedTodo.id); + return Response.created( + UriBuilder.fromResource(this.getClass()).path(String.valueOf(savedTodo.id)).build()) + .build(); + } + +} diff --git a/jnosql/jnosql-artemis/src/main/java/com/baeldung/jnosql/artemis/qualifier/Repo.java b/jnosql/jnosql-artemis/src/main/java/com/baeldung/jnosql/artemis/qualifier/Repo.java new file mode 100644 index 0000000000..a5883946db --- /dev/null +++ b/jnosql/jnosql-artemis/src/main/java/com/baeldung/jnosql/artemis/qualifier/Repo.java @@ -0,0 +1,13 @@ +package com.baeldung.jnosql.artemis.qualifier; + +import javax.inject.Qualifier; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Retention(RetentionPolicy.RUNTIME) +@Target({ElementType.FIELD, ElementType.TYPE}) +@Qualifier +public @interface Repo { +} \ No newline at end of file diff --git a/jnosql/jnosql-artemis/src/main/java/com/baeldung/jnosql/artemis/qualifier/Template.java b/jnosql/jnosql-artemis/src/main/java/com/baeldung/jnosql/artemis/qualifier/Template.java new file mode 100644 index 0000000000..81fbbe5271 --- /dev/null +++ b/jnosql/jnosql-artemis/src/main/java/com/baeldung/jnosql/artemis/qualifier/Template.java @@ -0,0 +1,13 @@ +package com.baeldung.jnosql.artemis.qualifier; + +import javax.inject.Qualifier; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Retention(RetentionPolicy.RUNTIME) +@Target({ElementType.FIELD, ElementType.TYPE}) +@Qualifier +public @interface Template { +} \ No newline at end of file diff --git a/jnosql/jnosql-artemis/src/main/liberty/config/server.xml b/jnosql/jnosql-artemis/src/main/liberty/config/server.xml new file mode 100644 index 0000000000..897aca853a --- /dev/null +++ b/jnosql/jnosql-artemis/src/main/liberty/config/server.xml @@ -0,0 +1,6 @@ + + + webProfile-8.0 + + + diff --git a/jnosql/jnosql-artemis/src/main/resources/META-INF/beans.xml b/jnosql/jnosql-artemis/src/main/resources/META-INF/beans.xml new file mode 100644 index 0000000000..4f0b3cdeeb --- /dev/null +++ b/jnosql/jnosql-artemis/src/main/resources/META-INF/beans.xml @@ -0,0 +1,6 @@ + + \ No newline at end of file diff --git a/jnosql/jnosql-artemis/src/main/resources/META-INF/jnosql.json b/jnosql/jnosql-artemis/src/main/resources/META-INF/jnosql.json new file mode 100644 index 0000000000..b8e26cf54a --- /dev/null +++ b/jnosql/jnosql-artemis/src/main/resources/META-INF/jnosql.json @@ -0,0 +1,10 @@ +[ + { + "description": "The mongodb document configuration", + "name": "document", + "provider": "org.jnosql.diana.mongodb.document.MongoDBDocumentConfiguration", + "settings": { + "mongodb-server-host-1":"localhost:27019" + } + } +] \ No newline at end of file diff --git a/jnosql/jnosql-artemis/src/main/webapp/WEB-INF/jnosql.json b/jnosql/jnosql-artemis/src/main/webapp/WEB-INF/jnosql.json new file mode 100644 index 0000000000..b8e26cf54a --- /dev/null +++ b/jnosql/jnosql-artemis/src/main/webapp/WEB-INF/jnosql.json @@ -0,0 +1,10 @@ +[ + { + "description": "The mongodb document configuration", + "name": "document", + "provider": "org.jnosql.diana.mongodb.document.MongoDBDocumentConfiguration", + "settings": { + "mongodb-server-host-1":"localhost:27019" + } + } +] \ No newline at end of file diff --git a/jnosql/jnosql-diana/pom.xml b/jnosql/jnosql-diana/pom.xml new file mode 100644 index 0000000000..767defb2a8 --- /dev/null +++ b/jnosql/jnosql-diana/pom.xml @@ -0,0 +1,93 @@ + + + 4.0.0 + + + com.baeldung.jnosql + jnosql + 1.0-SNAPSHOT + + + jnosql-diana + + + + + org.codehaus.mojo + exec-maven-plugin + 1.6.0 + + + document + + java + + + com.baeldung.jnosql.diana.document.DocumentApp + + + + column + + java + + + com.baeldung.jnosql.diana.column.ColumnFamilyApp + + + + key + + java + + + com.baeldung.jnosql.diana.key.KeyValueApp + + + + + + + + + + + + org.jnosql.diana + diana-document + 0.0.5 + + + org.jnosql.diana + mongodb-driver + 0.0.5 + + + + + org.jnosql.diana + diana-column + 0.0.5 + + + org.jnosql.diana + cassandra-driver + 0.0.5 + + + + + org.jnosql.diana + diana-key-value + 0.0.5 + + + org.jnosql.diana + hazelcast-driver + 0.0.5 + + + + \ No newline at end of file diff --git a/jnosql/jnosql-diana/src/main/java/com/baeldung/jnosql/diana/column/ColumnFamilyApp.java b/jnosql/jnosql-diana/src/main/java/com/baeldung/jnosql/diana/column/ColumnFamilyApp.java new file mode 100644 index 0000000000..5b65f9ad73 --- /dev/null +++ b/jnosql/jnosql-diana/src/main/java/com/baeldung/jnosql/diana/column/ColumnFamilyApp.java @@ -0,0 +1,32 @@ +package com.baeldung.jnosql.diana.column; + +import org.cassandraunit.utils.EmbeddedCassandraServerHelper; +import org.jnosql.diana.api.column.*; +import org.jnosql.diana.cassandra.column.CassandraConfiguration; + +public class ColumnFamilyApp { + + private static final String KEY_SPACE = "myKeySpace"; + private static final String COLUMN_FAMILY = "books"; + + public static void main(String... args) throws Exception { + + EmbeddedCassandraServerHelper.startEmbeddedCassandra(); + + ColumnConfiguration configuration = new CassandraConfiguration(); + try(ColumnFamilyManagerFactory entityManagerFactory = configuration.get()) { + ColumnFamilyManager entityManager = entityManagerFactory.get(KEY_SPACE); + ColumnEntity columnEntity = ColumnEntity.of(COLUMN_FAMILY); + Column key = Columns.of("id", 10L); + Column name = Columns.of("name", "JNoSQL in Acion"); + columnEntity.add(key); + columnEntity.add(name); + ColumnEntity saved = entityManager.insert(columnEntity); + System.out.println(saved); + } + + EmbeddedCassandraServerHelper.cleanEmbeddedCassandra(); + EmbeddedCassandraServerHelper.stopEmbeddedCassandra(); + } + +} diff --git a/jnosql/jnosql-diana/src/main/java/com/baeldung/jnosql/diana/document/DocumentApp.java b/jnosql/jnosql-diana/src/main/java/com/baeldung/jnosql/diana/document/DocumentApp.java new file mode 100644 index 0000000000..258c812a31 --- /dev/null +++ b/jnosql/jnosql-diana/src/main/java/com/baeldung/jnosql/diana/document/DocumentApp.java @@ -0,0 +1,67 @@ +package com.baeldung.jnosql.diana.document; + +import org.jnosql.diana.api.Settings; +import org.jnosql.diana.api.document.*; +import org.jnosql.diana.mongodb.document.MongoDBDocumentConfiguration; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import static org.jnosql.diana.api.document.query.DocumentQueryBuilder.delete; +import static org.jnosql.diana.api.document.query.DocumentQueryBuilder.select; + +public class DocumentApp { + + private static final String DB_NAME = "my-db"; + private static final String DOCUMENT_COLLECTION = "books"; + + public static final String KEY_NAME = "_id"; + + DocumentConfiguration configuration = new MongoDBDocumentConfiguration(); + + public static void main(String... args) throws Exception { + MongoDbInit.startMongoDb(); + + DocumentApp app = new DocumentApp(); + app.process(); + + MongoDbInit.stopMongoDb(); + } + + public void process() { + + Map map = new HashMap<>(); + map.put("mongodb-server-host-1", "localhost:27017"); + + try (DocumentCollectionManagerFactory managerFactory = configuration.get(Settings.of(map)); + DocumentCollectionManager manager = managerFactory.get(DB_NAME);) { + + DocumentEntity documentEntity = DocumentEntity.of(DOCUMENT_COLLECTION); + documentEntity.add(Document.of(KEY_NAME, "100")); + documentEntity.add(Document.of("name", "JNoSQL in Action")); + documentEntity.add(Document.of("pages", 620)); + + //CREATE + DocumentEntity saved = manager.insert(documentEntity); + + //READ + DocumentQuery query = select().from(DOCUMENT_COLLECTION).where(KEY_NAME).eq("100").build(); + List entities = manager.select(query); + System.out.println(entities.get(0)); + + //UPDATE + saved.add(Document.of("author", "baeldung")); + DocumentEntity updated = manager.update(saved); + System.out.println(updated); + + //DELETE + DocumentDeleteQuery deleteQuery = delete().from(DOCUMENT_COLLECTION).where(KEY_NAME).eq("100").build(); + manager.delete(deleteQuery); + + List documentEntityList = manager.select(select().from(DOCUMENT_COLLECTION).build()); + System.out.println(documentEntityList); + } + } + +} diff --git a/jnosql/jnosql-diana/src/main/java/com/baeldung/jnosql/diana/document/MongoDbInit.java b/jnosql/jnosql-diana/src/main/java/com/baeldung/jnosql/diana/document/MongoDbInit.java new file mode 100644 index 0000000000..19bb347581 --- /dev/null +++ b/jnosql/jnosql-diana/src/main/java/com/baeldung/jnosql/diana/document/MongoDbInit.java @@ -0,0 +1,32 @@ +package com.baeldung.jnosql.diana.document; + +import de.flapdoodle.embed.mongo.MongodExecutable; +import de.flapdoodle.embed.mongo.MongodProcess; +import de.flapdoodle.embed.mongo.MongodStarter; +import de.flapdoodle.embed.mongo.config.MongodConfigBuilder; +import de.flapdoodle.embed.mongo.config.Net; +import de.flapdoodle.embed.mongo.distribution.Version; +import de.flapdoodle.embed.process.runtime.Network; + +import java.io.IOException; + +public abstract class MongoDbInit { + + private static final MongodStarter starter = MongodStarter.getDefaultInstance(); + private static MongodExecutable _mongodExe; + private static MongodProcess _mongod; + + public static void startMongoDb() throws IOException { + _mongodExe = starter.prepare(new MongodConfigBuilder() + .version(Version.Main.DEVELOPMENT) + .net(new Net("localhost", 27017, Network.localhostIsIPv6())) + .build()); + _mongod = _mongodExe.start(); + } + + public static void stopMongoDb(){ + _mongod.stop(); + _mongodExe.stop(); + } + +} \ No newline at end of file diff --git a/jnosql/jnosql-diana/src/main/java/com/baeldung/jnosql/diana/key/Book.java b/jnosql/jnosql-diana/src/main/java/com/baeldung/jnosql/diana/key/Book.java new file mode 100644 index 0000000000..afa20e66b1 --- /dev/null +++ b/jnosql/jnosql-diana/src/main/java/com/baeldung/jnosql/diana/key/Book.java @@ -0,0 +1,63 @@ +package com.baeldung.jnosql.diana.key; + +import java.io.Serializable; + +public class Book implements Serializable { + + private String isbn; + private String name; + private String author; + private int pages; + + public Book() { + } + + public Book(String isbn, String name, String author, int pages) { + this.isbn = isbn; + this.name = name; + this.author = author; + this.pages = pages; + } + + public String getIsbn() { + return isbn; + } + + public void setIsbn(String isbn) { + this.isbn = isbn; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getAuthor() { + return author; + } + + public void setAuthor(String author) { + this.author = author; + } + + public int getPages() { + return pages; + } + + public void setPages(int pages) { + this.pages = pages; + } + + @Override + public String toString() { + return "Book{" + + "isbn='" + isbn + '\'' + + ", name='" + name + '\'' + + ", author='" + author + '\'' + + ", pages=" + pages + + '}'; + } +} diff --git a/jnosql/jnosql-diana/src/main/java/com/baeldung/jnosql/diana/key/KeyValueApp.java b/jnosql/jnosql-diana/src/main/java/com/baeldung/jnosql/diana/key/KeyValueApp.java new file mode 100644 index 0000000000..ab51bfa4fc --- /dev/null +++ b/jnosql/jnosql-diana/src/main/java/com/baeldung/jnosql/diana/key/KeyValueApp.java @@ -0,0 +1,33 @@ +package com.baeldung.jnosql.diana.key; + +import com.hazelcast.core.Hazelcast; +import org.jnosql.diana.api.Value; +import org.jnosql.diana.api.key.BucketManager; +import org.jnosql.diana.api.key.BucketManagerFactory; +import org.jnosql.diana.api.key.KeyValueConfiguration; +import org.jnosql.diana.api.key.KeyValueEntity; +import org.jnosql.diana.hazelcast.key.HazelcastKeyValueConfiguration; + +import java.util.Optional; + +public class KeyValueApp { + + private static final String BUCKET_NAME = "books"; + + public static void main(String... args) throws Exception { + KeyValueConfiguration configuration = new HazelcastKeyValueConfiguration(); + try (BucketManagerFactory managerFactory = configuration.get()) { + BucketManager manager = managerFactory.getBucketManager(BUCKET_NAME); + + Book book = new Book("12345", "JNoSQL in Action", "baeldung", 420); + KeyValueEntity keyValueEntity = KeyValueEntity.of(book.getIsbn(), book); + manager.put(keyValueEntity); + + Optional optionalValue = manager.get("12345"); + Value value = optionalValue.get(); + Book savedBook = value.get(Book.class); + System.out.println(savedBook); + } + Hazelcast.shutdownAll(); + } +} diff --git a/jnosql/jnosql-diana/src/main/resources/diana-cassandra.properties b/jnosql/jnosql-diana/src/main/resources/diana-cassandra.properties new file mode 100644 index 0000000000..5d7d840d65 --- /dev/null +++ b/jnosql/jnosql-diana/src/main/resources/diana-cassandra.properties @@ -0,0 +1,5 @@ +cassandra-host-1=localhost +cassandra-port=9142 +#cassandra-threads-number=2 +cassandra-query-1=CREATE KEYSPACE IF NOT EXISTS myKeySpace WITH replication = {'class': 'SimpleStrategy', 'replication_factor' : 3}; +cassandra-query-2=CREATE COLUMNFAMILY IF NOT EXISTS myKeySpace.books (id bigint PRIMARY KEY, name text); diff --git a/jnosql/jnosql-diana/src/main/resources/diana-hazelcast.properties b/jnosql/jnosql-diana/src/main/resources/diana-hazelcast.properties new file mode 100644 index 0000000000..010b4a6e47 --- /dev/null +++ b/jnosql/jnosql-diana/src/main/resources/diana-hazelcast.properties @@ -0,0 +1 @@ +hazelcast-instanceName=hazelcast \ No newline at end of file diff --git a/jnosql/jnosql-diana/src/main/resources/diana-mongodb.properties b/jnosql/jnosql-diana/src/main/resources/diana-mongodb.properties new file mode 100644 index 0000000000..5b425bd7bf --- /dev/null +++ b/jnosql/jnosql-diana/src/main/resources/diana-mongodb.properties @@ -0,0 +1,2 @@ +#Define Host and Port +mongodb-server-host-1=localhost:27017 diff --git a/jnosql/pom.xml b/jnosql/pom.xml new file mode 100644 index 0000000000..c87ad3cf4b --- /dev/null +++ b/jnosql/pom.xml @@ -0,0 +1,23 @@ + + + 4.0.0 + + com.baeldung.jnosql + jnosql + 1.0-SNAPSHOT + pom + + + 1.8 + 1.8 + 0.0.5 + + + + jnosql-diana + jnosql-artemis + + + diff --git a/pom.xml b/pom.xml index 77d184b78b..74520c04c5 100644 --- a/pom.xml +++ b/pom.xml @@ -545,6 +545,7 @@ antlr maven-archetype apache-meecrowave + jnosql