-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Otavio Santana <[email protected]>
- Loading branch information
1 parent
eb22245
commit a10e1e7
Showing
4 changed files
with
68 additions
and
21 deletions.
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
chapter-13/src/main/java/expert/os/books/persistence/nosql/chapter13/App.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* Copyright (c) 2022 Contributors to the Eclipse Foundation | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* and Apache License v2.0 which accompanies this distribution. | ||
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html | ||
* and the Apache License v2.0 is available at http://www.opensource.org/licenses/apache2.0.php. | ||
* | ||
* You may elect to redistribute this code under either of these licenses. | ||
*/ | ||
|
||
package expert.os.books.persistence.nosql.chapter13; | ||
|
||
|
||
import jakarta.enterprise.inject.se.SeContainer; | ||
import jakarta.enterprise.inject.se.SeContainerInitializer; | ||
import jakarta.nosql.column.ColumnTemplate; | ||
import org.eclipse.jnosql.databases.cassandra.mapping.CassandraTemplate; | ||
|
||
import java.util.Arrays; | ||
import java.util.Optional; | ||
|
||
|
||
public class App { | ||
|
||
|
||
public static void main(String[] args) { | ||
|
||
try(SeContainer container = SeContainerInitializer.newInstance().initialize()) { | ||
|
||
Person otaviojava = Person.builder().phones(Arrays.asList("123456", "432")) | ||
.name("Name").id(1).build(); | ||
|
||
ColumnTemplate template = container.select(CassandraTemplate.class).get(); | ||
Person saved = template.insert(otaviojava); | ||
System.out.println("Person saved" + saved); | ||
|
||
Optional<Person> person = template.select(Person.class) | ||
.where("id").eq(1L).singleResult(); | ||
System.out.println("Entity found: " + person); | ||
|
||
} | ||
} | ||
|
||
private App() {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
CREATE KEYSPACE IF NOT EXISTS developers WITH replication = {'class': 'SimpleStrategy', 'replication_factor' : 3}; | ||
CREATE COLUMNFAMILY IF NOT EXISTS developers.Person (id bigint PRIMARY KEY, name text, phones list<text>); | ||
CREATE COLUMNFAMILY IF NOT EXISTS developers.Person (id bigint PRIMARY KEY, name text, contacts map<text, text>); | ||
CREATE TYPE IF NOT EXISTS developers.director (name text, movies set<text> ); | ||
CREATE COLUMNFAMILY IF NOT EXISTS developers.Movie (name text PRIMARY KEY, age int,director FROZEN<director>); | ||
create index if not exists ageIndex on developers.movie(age); |