From 2d3edb86f95c0154885ac673e01e25f9c15c93ef Mon Sep 17 00:00:00 2001 From: Arun Gupta Date: Thu, 10 Oct 2013 14:04:06 -0700 Subject: [PATCH 001/897] Adding new sample for Oracle NoSQL --- extra/nosql/oracle/pom.xml | 23 +++++ .../javaee7/extra/nosql/oracle/Person.java | 95 +++++++++++++++++++ .../extra/nosql/oracle/PersonSessionBean.java | 94 ++++++++++++++++++ .../oracle/src/main/webapp/WEB-INF/beans.xml | 49 ++++++++++ .../src/main/webapp/WEB-INF/template.xhtml | 26 +++++ .../oracle/src/main/webapp/WEB-INF/web.xml | 24 +++++ .../nosql/oracle/src/main/webapp/index.xhtml | 33 +++++++ .../main/webapp/resources/css/cssLayout.css | 61 ++++++++++++ .../src/main/webapp/resources/css/default.css | 29 ++++++ extra/nosql/oracle/src/main/webapp/show.xhtml | 27 ++++++ 10 files changed, 461 insertions(+) create mode 100644 extra/nosql/oracle/pom.xml create mode 100644 extra/nosql/oracle/src/main/java/org/javaee7/extra/nosql/oracle/Person.java create mode 100644 extra/nosql/oracle/src/main/java/org/javaee7/extra/nosql/oracle/PersonSessionBean.java create mode 100644 extra/nosql/oracle/src/main/webapp/WEB-INF/beans.xml create mode 100644 extra/nosql/oracle/src/main/webapp/WEB-INF/template.xhtml create mode 100644 extra/nosql/oracle/src/main/webapp/WEB-INF/web.xml create mode 100644 extra/nosql/oracle/src/main/webapp/index.xhtml create mode 100644 extra/nosql/oracle/src/main/webapp/resources/css/cssLayout.css create mode 100644 extra/nosql/oracle/src/main/webapp/resources/css/default.css create mode 100644 extra/nosql/oracle/src/main/webapp/show.xhtml diff --git a/extra/nosql/oracle/pom.xml b/extra/nosql/oracle/pom.xml new file mode 100644 index 000000000..125b0685b --- /dev/null +++ b/extra/nosql/oracle/pom.xml @@ -0,0 +1,23 @@ + + + 4.0.0 + + org.javaee7.extra.nosql + extra-nosql-samples + 1.0-SNAPSHOT + ../pom.xml + + + org.javaee7.extra.nosql + oracle + 1.0-SNAPSHOT + war + + + + com.oracle.nosql + oracle-nosql + 2.1.19 + + + diff --git a/extra/nosql/oracle/src/main/java/org/javaee7/extra/nosql/oracle/Person.java b/extra/nosql/oracle/src/main/java/org/javaee7/extra/nosql/oracle/Person.java new file mode 100644 index 000000000..bec1295d5 --- /dev/null +++ b/extra/nosql/oracle/src/main/java/org/javaee7/extra/nosql/oracle/Person.java @@ -0,0 +1,95 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2013 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html + * or packager/legal/LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at packager/legal/LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ +package org.javaee7.extra.nosql.oracle; + +import java.io.Serializable; +import java.util.StringTokenizer; +import javax.enterprise.context.ApplicationScoped; +import javax.inject.Named; +import javax.validation.constraints.Size; + +/** + * @author Arun Gupta + */ +@Named +@ApplicationScoped +public class Person implements Serializable { + + @Size(min = 1, max = 20) + private String name; + + private int age; + + public Person() { + } + + public Person(String name, int age) { + this.name = name; + this.age = age; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public int getAge() { + return age; + } + + public void setAge(int age) { + this.age = age; + } + + @Override + public String toString() { + return name + ", " + age; + } + + public static Person fromString(String string) { + StringTokenizer tokens = new StringTokenizer(string, ","); + + return new Person(tokens.nextToken(), Integer.parseInt(tokens.nextToken().trim())); + } + +} diff --git a/extra/nosql/oracle/src/main/java/org/javaee7/extra/nosql/oracle/PersonSessionBean.java b/extra/nosql/oracle/src/main/java/org/javaee7/extra/nosql/oracle/PersonSessionBean.java new file mode 100644 index 000000000..bc1a17a53 --- /dev/null +++ b/extra/nosql/oracle/src/main/java/org/javaee7/extra/nosql/oracle/PersonSessionBean.java @@ -0,0 +1,94 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2013 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html + * or packager/legal/LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at packager/legal/LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ +package org.javaee7.extra.nosql.oracle; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import javax.annotation.PostConstruct; +import javax.annotation.PreDestroy; +import javax.inject.Inject; +import javax.inject.Named; +import javax.inject.Singleton; +import oracle.kv.KVStore; +import oracle.kv.KVStoreConfig; +import oracle.kv.KVStoreFactory; +import oracle.kv.Key; +import oracle.kv.Value; + +/** + * @author Arun Gupta + */ +@Named +@Singleton +public class PersonSessionBean { + + @Inject + Person person; + + Set set = new HashSet<>(); + + private KVStore store; + + @PostConstruct + private void initDB() { + // bootstrap + store = KVStoreFactory.getStore(new KVStoreConfig("kvstore", "localhost:5000")); + } + + @PreDestroy + private void stopDB() { + } + + public void createPerson() { + store.put(Key.createKey(person.getName()), Value.createValue(new Person(person.getName(), person.getAge()).toString().getBytes())); + set.add(person.getName()); + } + + public List getPersons() { + List persons = new ArrayList(); + for (String key : set) { + persons.add(Person.fromString(new String(store.get(Key.createKey(key)).getValue().getValue()))); + } + return persons; + } +} diff --git a/extra/nosql/oracle/src/main/webapp/WEB-INF/beans.xml b/extra/nosql/oracle/src/main/webapp/WEB-INF/beans.xml new file mode 100644 index 000000000..aa81c7c3c --- /dev/null +++ b/extra/nosql/oracle/src/main/webapp/WEB-INF/beans.xml @@ -0,0 +1,49 @@ + + + + \ No newline at end of file diff --git a/extra/nosql/oracle/src/main/webapp/WEB-INF/template.xhtml b/extra/nosql/oracle/src/main/webapp/WEB-INF/template.xhtml new file mode 100644 index 000000000..3418cda01 --- /dev/null +++ b/extra/nosql/oracle/src/main/webapp/WEB-INF/template.xhtml @@ -0,0 +1,26 @@ + + + + + + + + + Oracle NoSQL using Java EE 7 + + + + +
+

Oracle NoSQL using Java EE 7

+
+ +
+ Content +
+ +
+ + diff --git a/extra/nosql/oracle/src/main/webapp/WEB-INF/web.xml b/extra/nosql/oracle/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 000000000..c5e7c7381 --- /dev/null +++ b/extra/nosql/oracle/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,24 @@ + + + + javax.faces.PROJECT_STAGE + Development + + + Faces Servlet + javax.faces.webapp.FacesServlet + 1 + + + Faces Servlet + /faces/* + + + + 30 + + + + faces/index.xhtml + + diff --git a/extra/nosql/oracle/src/main/webapp/index.xhtml b/extra/nosql/oracle/src/main/webapp/index.xhtml new file mode 100644 index 000000000..eae2f204d --- /dev/null +++ b/extra/nosql/oracle/src/main/webapp/index.xhtml @@ -0,0 +1,33 @@ + + + + + + + + + + + Name:
+ Age:

+ +
+
+
    +
  • Download Oracle NoSQL Community Edition and unzip.
  • +
  • Install the NoSQL Client jar: mvn install:install-file -Dfile=/Users/arungup/tools/oracle/nosql/kv-2.1.19/lib/kvclient.jar -DgroupId=com.oracle.nosql -DartifactId=oracle-nosql -Dversion=2.1.19 -Dpackaging=jar
  • +
  • Start the server as: java -jar lib/kvstore.jar kvlite to see the output as:
    +Created new kvlite store with args:
    +-root ./kvroot -store kvstore -host arungup-mac.local -port 5000 -admin 5001 +
  • +
+
+ +
+ + + diff --git a/extra/nosql/oracle/src/main/webapp/resources/css/cssLayout.css b/extra/nosql/oracle/src/main/webapp/resources/css/cssLayout.css new file mode 100644 index 000000000..8ee7cebe3 --- /dev/null +++ b/extra/nosql/oracle/src/main/webapp/resources/css/cssLayout.css @@ -0,0 +1,61 @@ + +#top { + position: relative; + background-color: #036fab; + color: white; + padding: 5px; + margin: 0px 0px 10px 0px; +} + +#bottom { + position: relative; + background-color: #c2dfef; + padding: 5px; + margin: 10px 0px 0px 0px; +} + +#left { + float: left; + background-color: #ece3a5; + padding: 5px; + width: 150px; +} + +#right { + float: right; + background-color: #ece3a5; + padding: 5px; + width: 150px; +} + +.center_content { + position: relative; + background-color: #dddddd; + padding: 5px; +} + +.left_content { + background-color: #dddddd; + padding: 5px; + margin-left: 170px; +} + +.right_content { + background-color: #dddddd; + padding: 5px; + margin: 0px 170px 0px 170px; +} + +#top a:link, #top a:visited { + color: white; + font-weight : bold; + text-decoration: none; +} + +#top a:link:hover, #top a:visited:hover { + color: black; + font-weight : bold; + text-decoration : underline; +} + + diff --git a/extra/nosql/oracle/src/main/webapp/resources/css/default.css b/extra/nosql/oracle/src/main/webapp/resources/css/default.css new file mode 100644 index 000000000..6cbc3d18e --- /dev/null +++ b/extra/nosql/oracle/src/main/webapp/resources/css/default.css @@ -0,0 +1,29 @@ +body { + background-color: #ffffff; + font-size: 12px; + font-family: Verdana, "Verdana CE", Arial, "Arial CE", "Lucida Grande CE", lucida, "Helvetica CE", sans-serif; + color: #000000; + margin: 10px; +} + +h1 { + font-family: Arial, "Arial CE", "Lucida Grande CE", lucida, "Helvetica CE", sans-serif; + border-bottom: 1px solid #AFAFAF; + font-size: 16px; + font-weight: bold; + margin: 0px; + padding: 0px; + color: #D20005; +} + +a:link, a:visited { + color: #045491; + font-weight : bold; + text-decoration: none; +} + +a:link:hover, a:visited:hover { + color: #045491; + font-weight : bold; + text-decoration : underline; +} diff --git a/extra/nosql/oracle/src/main/webapp/show.xhtml b/extra/nosql/oracle/src/main/webapp/show.xhtml new file mode 100644 index 000000000..8f1d60f31 --- /dev/null +++ b/extra/nosql/oracle/src/main/webapp/show.xhtml @@ -0,0 +1,27 @@ + + + + + + + + + + + Name#{p.name} + Age#{p.age} + +

+ + + + +
+ +
+ + + From 3214cca7f2c614e74dbe39c214fa63a730d8305b Mon Sep 17 00:00:00 2001 From: Arun Gupta Date: Thu, 10 Oct 2013 15:41:05 -0700 Subject: [PATCH 002/897] Adding a line break --- extra/nosql/oracle/src/main/webapp/index.xhtml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extra/nosql/oracle/src/main/webapp/index.xhtml b/extra/nosql/oracle/src/main/webapp/index.xhtml index eae2f204d..5e1c6d271 100644 --- a/extra/nosql/oracle/src/main/webapp/index.xhtml +++ b/extra/nosql/oracle/src/main/webapp/index.xhtml @@ -20,7 +20,7 @@