From e75eef0a7563f690bad2d09a2b8d0418ab5b5094 Mon Sep 17 00:00:00 2001 From: Arun Gupta Date: Wed, 2 Oct 2013 14:59:40 -0700 Subject: [PATCH 001/934] Explicitly specifying application/* media type --- .../java/org/javaee7/jaxrs/server/negotiation/TestServlet.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jaxrs/server-negotiation/src/main/java/org/javaee7/jaxrs/server/negotiation/TestServlet.java b/jaxrs/server-negotiation/src/main/java/org/javaee7/jaxrs/server/negotiation/TestServlet.java index a0b9b236d..6a804779a 100644 --- a/jaxrs/server-negotiation/src/main/java/org/javaee7/jaxrs/server/negotiation/TestServlet.java +++ b/jaxrs/server-negotiation/src/main/java/org/javaee7/jaxrs/server/negotiation/TestServlet.java @@ -90,7 +90,7 @@ protected void processRequest(HttpServletRequest request, HttpServletResponse re // GET out.print("GETTing...
"); - String string = target.request().get(String.class); + String string = target.request().accept("application/*").get(String.class); out.format("GOT the representation: " + string); out.format("

Did you get the JSON representation ?"); out.println("

... done.
"); From 44ecab6db022e33d2e74183c434809c3d7b3bc19 Mon Sep 17 00:00:00 2001 From: Arun Gupta Date: Wed, 2 Oct 2013 15:00:43 -0700 Subject: [PATCH 002/934] "mvn embedded-glassfish run" to run the samples in embedded GlassFish. TBD: how to connect with database. --- pom.xml | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/pom.xml b/pom.xml index d688cba82..7f3ca6bb4 100644 --- a/pom.xml +++ b/pom.xml @@ -111,6 +111,48 @@ + + org.glassfish.embedded + maven-embedded-glassfish-plugin + 4.0 + + target/${project.artifactId}.war + 8080 + + 8181 + + + + + org.glassfish.main.common + simple-glassfish-api + 4.0 + + + org.glassfish.main.extras + glassfish-embedded-all + 4.0 + + + + + start + integration-test + + start + deploy + + + + stop + post-integration-test + + undeploy + stop + + + + From 0d8444d4716e798cdf2f7d0c4c879fbed928c75d Mon Sep 17 00:00:00 2001 From: Arun Gupta Date: Wed, 2 Oct 2013 16:31:14 -0700 Subject: [PATCH 003/934] Fixing a variable name --- .../src/main/java/org/javaee7/extra/mongo/Person.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/extra/mongo/src/main/java/org/javaee7/extra/mongo/Person.java b/extra/mongo/src/main/java/org/javaee7/extra/mongo/Person.java index 7b4620f3e..eb9c48f21 100644 --- a/extra/mongo/src/main/java/org/javaee7/extra/mongo/Person.java +++ b/extra/mongo/src/main/java/org/javaee7/extra/mongo/Person.java @@ -89,12 +89,12 @@ public BasicDBObject toDBObject() { } public static Person fromDBObject(DBObject doc) { - Person m = new Person(); + Person p = new Person(); - m.name = (String) doc.get("name"); - m.age = (int) doc.get("age"); + p.name = (String) doc.get("name"); + p.age = (int) doc.get("age"); - return m; + return p; } @Override From 05e77c3e02d37f226414e74a72e30dd111635f00 Mon Sep 17 00:00:00 2001 From: Arun Gupta Date: Wed, 2 Oct 2013 17:22:05 -0700 Subject: [PATCH 004/934] New Couchbase sample - getBulk does not seem to be returning correct values, needs further investigation --- extra/couchbase/pom.xml | 23 ++++ .../org/javaee7/extra/couchbase/Person.java | 86 +++++++++++++ .../extra/couchbase/PersonSessionBean.java | 114 ++++++++++++++++++ .../src/main/webapp/WEB-INF/beans.xml | 49 ++++++++ .../src/main/webapp/WEB-INF/template.xhtml | 26 ++++ .../couchbase/src/main/webapp/WEB-INF/web.xml | 24 ++++ extra/couchbase/src/main/webapp/index.xhtml | 37 ++++++ .../main/webapp/resources/css/cssLayout.css | 61 ++++++++++ .../src/main/webapp/resources/css/default.css | 29 +++++ extra/couchbase/src/main/webapp/show.xhtml | 22 ++++ 10 files changed, 471 insertions(+) create mode 100644 extra/couchbase/pom.xml create mode 100644 extra/couchbase/src/main/java/org/javaee7/extra/couchbase/Person.java create mode 100644 extra/couchbase/src/main/java/org/javaee7/extra/couchbase/PersonSessionBean.java create mode 100644 extra/couchbase/src/main/webapp/WEB-INF/beans.xml create mode 100644 extra/couchbase/src/main/webapp/WEB-INF/template.xhtml create mode 100644 extra/couchbase/src/main/webapp/WEB-INF/web.xml create mode 100644 extra/couchbase/src/main/webapp/index.xhtml create mode 100644 extra/couchbase/src/main/webapp/resources/css/cssLayout.css create mode 100644 extra/couchbase/src/main/webapp/resources/css/default.css create mode 100644 extra/couchbase/src/main/webapp/show.xhtml diff --git a/extra/couchbase/pom.xml b/extra/couchbase/pom.xml new file mode 100644 index 000000000..9f4768057 --- /dev/null +++ b/extra/couchbase/pom.xml @@ -0,0 +1,23 @@ + + + 4.0.0 + + org.javaee7.extra + extra-samples + 1.0-SNAPSHOT + ../pom.xml + + + org.javaee7.extra + couchbase + 1.0-SNAPSHOT + war + + + + com.couchbase.client + couchbase-client + 1.2.0 + + + diff --git a/extra/couchbase/src/main/java/org/javaee7/extra/couchbase/Person.java b/extra/couchbase/src/main/java/org/javaee7/extra/couchbase/Person.java new file mode 100644 index 000000000..690c2ebb7 --- /dev/null +++ b/extra/couchbase/src/main/java/org/javaee7/extra/couchbase/Person.java @@ -0,0 +1,86 @@ +/* + * 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.couchbase; + +import javax.enterprise.context.ApplicationScoped; +import javax.inject.Named; +import javax.validation.constraints.Size; + +/** + * @author Arun Gupta + */ +@Named +@ApplicationScoped +public class Person { + + @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; + } +} diff --git a/extra/couchbase/src/main/java/org/javaee7/extra/couchbase/PersonSessionBean.java b/extra/couchbase/src/main/java/org/javaee7/extra/couchbase/PersonSessionBean.java new file mode 100644 index 000000000..bef1549ee --- /dev/null +++ b/extra/couchbase/src/main/java/org/javaee7/extra/couchbase/PersonSessionBean.java @@ -0,0 +1,114 @@ +/* + * 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.couchbase; + +import com.couchbase.client.CouchbaseClient; +import java.io.IOException; +import java.net.URI; +import java.net.URISyntaxException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.logging.Level; +import java.util.logging.Logger; +import javax.annotation.PostConstruct; +import javax.annotation.PreDestroy; +import javax.inject.Inject; +import javax.inject.Named; +import javax.inject.Singleton; + +/** + * @author Arun Gupta + */ +@Named +@Singleton +public class PersonSessionBean { + + @Inject + Person person; + + CouchbaseClient client; + + Set set = new HashSet<>(); + + @PostConstruct + private void initDB() { + try { + // Get an instance of Couchbase + List hosts = Arrays.asList( + new URI("http://localhost:8091/pools") + ); + + // Get an instance of Couchbase + // Name of the Bucket to connect to + String bucket = "default"; + + // Password of the bucket (empty) string if none + String password = ""; + + // Connect to the Cluster + client = new CouchbaseClient(hosts, bucket, password); + } catch (URISyntaxException | IOException ex) { + Logger.getLogger(PersonSessionBean.class.getName()).log(Level.SEVERE, null, ex); + } + } + + @PreDestroy + private void stopDB() { + client.shutdown(); + } + + public void createPerson() { + client.set(person.getName(), person); + set.add(person.getName()); + } + + public List getPersons() { + List persons = new ArrayList(); + Map map = client.getBulk(set.iterator()); + for (String key : map.keySet()) { + persons.add((Person)map.get(key)); + } + return persons; + } +} diff --git a/extra/couchbase/src/main/webapp/WEB-INF/beans.xml b/extra/couchbase/src/main/webapp/WEB-INF/beans.xml new file mode 100644 index 000000000..aa81c7c3c --- /dev/null +++ b/extra/couchbase/src/main/webapp/WEB-INF/beans.xml @@ -0,0 +1,49 @@ + + + + \ No newline at end of file diff --git a/extra/couchbase/src/main/webapp/WEB-INF/template.xhtml b/extra/couchbase/src/main/webapp/WEB-INF/template.xhtml new file mode 100644 index 000000000..9eb7c0652 --- /dev/null +++ b/extra/couchbase/src/main/webapp/WEB-INF/template.xhtml @@ -0,0 +1,26 @@ + + + + + + + + + Couchbase using Java EE 7 + + + + +
+

Couchbase using Java EE 7

+
+ +
+ Content +
+ +
+ + diff --git a/extra/couchbase/src/main/webapp/WEB-INF/web.xml b/extra/couchbase/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 000000000..c5e7c7381 --- /dev/null +++ b/extra/couchbase/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/couchbase/src/main/webapp/index.xhtml b/extra/couchbase/src/main/webapp/index.xhtml new file mode 100644 index 000000000..16b846aef --- /dev/null +++ b/extra/couchbase/src/main/webapp/index.xhtml @@ -0,0 +1,37 @@ + + + + + + + + + + + Name:
+ Age:
+ +
+
+ Make sure to start Couchbase server. Confirm by visiting pools and look for output as: + +
+"pools": [
+    {
+        "name": "default",
+        "uri": "/pools/default?uuid=21041e11772b15d7c64f3451e1293215",
+        "streamingUri": "/poolsStreaming/default?uuid=21041e11772b15d7c64f3451e1293215"
+    }
+],
+                
+
+ +
+ + + diff --git a/extra/couchbase/src/main/webapp/resources/css/cssLayout.css b/extra/couchbase/src/main/webapp/resources/css/cssLayout.css new file mode 100644 index 000000000..8ee7cebe3 --- /dev/null +++ b/extra/couchbase/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/couchbase/src/main/webapp/resources/css/default.css b/extra/couchbase/src/main/webapp/resources/css/default.css new file mode 100644 index 000000000..6cbc3d18e --- /dev/null +++ b/extra/couchbase/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/couchbase/src/main/webapp/show.xhtml b/extra/couchbase/src/main/webapp/show.xhtml new file mode 100644 index 000000000..19203f612 --- /dev/null +++ b/extra/couchbase/src/main/webapp/show.xhtml @@ -0,0 +1,22 @@ + + + + + + + + + + + Name#{p.name} + Age#{p.age} + + + + + + + From 52b4b7c4356c06f92178e6ccb4ed22ce58730f80 Mon Sep 17 00:00:00 2001 From: Arun Gupta Date: Wed, 2 Oct 2013 17:22:15 -0700 Subject: [PATCH 005/934] Adding couchbase module --- extra/pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/extra/pom.xml b/extra/pom.xml index 5d49f9138..6e78376ca 100644 --- a/extra/pom.xml +++ b/extra/pom.xml @@ -18,5 +18,6 @@ quartz twitter-search mongo + couchbase From 0ba5d04c7cdea62e726743122f572cbdfdc430ed Mon Sep 17 00:00:00 2001 From: Arun Gupta Date: Thu, 3 Oct 2013 09:50:32 -0700 Subject: [PATCH 006/934] Making the object serializable so that it can be persisted in Couchbase --- .../src/main/java/org/javaee7/extra/couchbase/Person.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/extra/couchbase/src/main/java/org/javaee7/extra/couchbase/Person.java b/extra/couchbase/src/main/java/org/javaee7/extra/couchbase/Person.java index 690c2ebb7..1a72e8409 100644 --- a/extra/couchbase/src/main/java/org/javaee7/extra/couchbase/Person.java +++ b/extra/couchbase/src/main/java/org/javaee7/extra/couchbase/Person.java @@ -39,6 +39,7 @@ */ package org.javaee7.extra.couchbase; +import java.io.Serializable; import javax.enterprise.context.ApplicationScoped; import javax.inject.Named; import javax.validation.constraints.Size; @@ -48,7 +49,7 @@ */ @Named @ApplicationScoped -public class Person { +public class Person implements Serializable { @Size(min = 1, max = 20) private String name; From 6a0def18faa6a0581d645b040baeb977db7af82c Mon Sep 17 00:00:00 2001 From: Arun Gupta Date: Thu, 3 Oct 2013 09:50:51 -0700 Subject: [PATCH 007/934] Persisting object instance instead of proxy --- .../java/org/javaee7/extra/couchbase/PersonSessionBean.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extra/couchbase/src/main/java/org/javaee7/extra/couchbase/PersonSessionBean.java b/extra/couchbase/src/main/java/org/javaee7/extra/couchbase/PersonSessionBean.java index bef1549ee..e4fb4ccf6 100644 --- a/extra/couchbase/src/main/java/org/javaee7/extra/couchbase/PersonSessionBean.java +++ b/extra/couchbase/src/main/java/org/javaee7/extra/couchbase/PersonSessionBean.java @@ -99,7 +99,7 @@ private void stopDB() { } public void createPerson() { - client.set(person.getName(), person); + client.set(person.getName(), new Person(person.getName(), person.getAge())); set.add(person.getName()); } From 31392a6b136a2f2d23b47f835834b128d90081d2 Mon Sep 17 00:00:00 2001 From: Arun Gupta Date: Thu, 3 Oct 2013 09:51:16 -0700 Subject: [PATCH 008/934] Adding Back button and some formatting --- extra/couchbase/src/main/webapp/index.xhtml | 5 ++--- extra/couchbase/src/main/webapp/show.xhtml | 5 +++++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/extra/couchbase/src/main/webapp/index.xhtml b/extra/couchbase/src/main/webapp/index.xhtml index 16b846aef..daf471c32 100644 --- a/extra/couchbase/src/main/webapp/index.xhtml +++ b/extra/couchbase/src/main/webapp/index.xhtml @@ -11,11 +11,10 @@ Name:
- Age:
+ Age:

+ value="Add"/>

Make sure to start Couchbase server. Confirm by visiting pools and look for output as: diff --git a/extra/couchbase/src/main/webapp/show.xhtml b/extra/couchbase/src/main/webapp/show.xhtml index 19203f612..8f1d60f31 100644 --- a/extra/couchbase/src/main/webapp/show.xhtml +++ b/extra/couchbase/src/main/webapp/show.xhtml @@ -14,6 +14,11 @@ Name#{p.name} Age#{p.age} +

+ + + +
From 12a236eb4147bc2d8dc5fe58a395e325707e811d Mon Sep 17 00:00:00 2001 From: Arun Gupta Date: Thu, 3 Oct 2013 14:05:31 -0700 Subject: [PATCH 009/934] New sample that shows Redis and Java EE integration --- extra/redis/pom.xml | 23 +++++ .../java/org/javaee7/extra/redis/Person.java | 92 +++++++++++++++++++ .../extra/redis/PersonSessionBean.java | 90 ++++++++++++++++++ extra/redis/src/main/webapp/WEB-INF/beans.xml | 49 ++++++++++ .../src/main/webapp/WEB-INF/template.xhtml | 26 ++++++ extra/redis/src/main/webapp/WEB-INF/web.xml | 24 +++++ extra/redis/src/main/webapp/index.xhtml | 28 ++++++ .../main/webapp/resources/css/cssLayout.css | 61 ++++++++++++ .../src/main/webapp/resources/css/default.css | 29 ++++++ extra/redis/src/main/webapp/show.xhtml | 29 ++++++ 10 files changed, 451 insertions(+) create mode 100644 extra/redis/pom.xml create mode 100644 extra/redis/src/main/java/org/javaee7/extra/redis/Person.java create mode 100644 extra/redis/src/main/java/org/javaee7/extra/redis/PersonSessionBean.java create mode 100644 extra/redis/src/main/webapp/WEB-INF/beans.xml create mode 100644 extra/redis/src/main/webapp/WEB-INF/template.xhtml create mode 100644 extra/redis/src/main/webapp/WEB-INF/web.xml create mode 100644 extra/redis/src/main/webapp/index.xhtml create mode 100644 extra/redis/src/main/webapp/resources/css/cssLayout.css create mode 100644 extra/redis/src/main/webapp/resources/css/default.css create mode 100644 extra/redis/src/main/webapp/show.xhtml diff --git a/extra/redis/pom.xml b/extra/redis/pom.xml new file mode 100644 index 000000000..ce6b57832 --- /dev/null +++ b/extra/redis/pom.xml @@ -0,0 +1,23 @@ + + + 4.0.0 + + org.javaee7.extra + extra-samples + 1.0-SNAPSHOT + ../pom.xml + + + org.javaee7.extra + redis + 1.0-SNAPSHOT + war + + + + redis.clients + jedis + 2.2.0 + + + diff --git a/extra/redis/src/main/java/org/javaee7/extra/redis/Person.java b/extra/redis/src/main/java/org/javaee7/extra/redis/Person.java new file mode 100644 index 000000000..83a5781fd --- /dev/null +++ b/extra/redis/src/main/java/org/javaee7/extra/redis/Person.java @@ -0,0 +1,92 @@ +/* + * 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.redis; + +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 { + + @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/redis/src/main/java/org/javaee7/extra/redis/PersonSessionBean.java b/extra/redis/src/main/java/org/javaee7/extra/redis/PersonSessionBean.java new file mode 100644 index 000000000..efdd3b669 --- /dev/null +++ b/extra/redis/src/main/java/org/javaee7/extra/redis/PersonSessionBean.java @@ -0,0 +1,90 @@ +/* + * 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.redis; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import javax.annotation.PostConstruct; +import javax.annotation.PreDestroy; +import javax.ejb.Stateless; +import javax.inject.Inject; +import javax.inject.Named; +import redis.clients.jedis.Jedis; + +/** + * @author Arun Gupta + */ +@Named +@Stateless +public class PersonSessionBean { + + @Inject + Person person; + + Jedis jedis; + + Set set = new HashSet<>(); + + @PostConstruct + private void initDB() { +// Start embedded Redis + jedis = new Jedis("localhost", 6379); + } + + @PreDestroy + private void stopDB() { + jedis.shutdown(); + } + + public void createPerson() { + jedis.set(person.getName(), new Person(person.getName(), person.getAge()).toString()); + set.add(person.getName()); + } + + public List getPersons() { + List persons = new ArrayList<>(); + for (String key : set) { + persons.add(Person.fromString(jedis.get(key))); + } + return persons; + } +} diff --git a/extra/redis/src/main/webapp/WEB-INF/beans.xml b/extra/redis/src/main/webapp/WEB-INF/beans.xml new file mode 100644 index 000000000..aa81c7c3c --- /dev/null +++ b/extra/redis/src/main/webapp/WEB-INF/beans.xml @@ -0,0 +1,49 @@ + + + + \ No newline at end of file diff --git a/extra/redis/src/main/webapp/WEB-INF/template.xhtml b/extra/redis/src/main/webapp/WEB-INF/template.xhtml new file mode 100644 index 000000000..c0d6c22b3 --- /dev/null +++ b/extra/redis/src/main/webapp/WEB-INF/template.xhtml @@ -0,0 +1,26 @@ + + + + + + + + + Redis using Java EE 7 + + + + +
+

Redis using Java EE 7

+
+ +
+ Content +
+ +
+ + diff --git a/extra/redis/src/main/webapp/WEB-INF/web.xml b/extra/redis/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 000000000..c5e7c7381 --- /dev/null +++ b/extra/redis/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/redis/src/main/webapp/index.xhtml b/extra/redis/src/main/webapp/index.xhtml new file mode 100644 index 000000000..0adf58b04 --- /dev/null +++ b/extra/redis/src/main/webapp/index.xhtml @@ -0,0 +1,28 @@ + + + + + + + + + + + Name:
+ Age:

+ +
+
+ Make sure to download latest stable release, compile, and run it. Look for a message like: + +
* The server is now ready to accept connections on port 6379
+
+ +
+ + + diff --git a/extra/redis/src/main/webapp/resources/css/cssLayout.css b/extra/redis/src/main/webapp/resources/css/cssLayout.css new file mode 100644 index 000000000..8ee7cebe3 --- /dev/null +++ b/extra/redis/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/redis/src/main/webapp/resources/css/default.css b/extra/redis/src/main/webapp/resources/css/default.css new file mode 100644 index 000000000..6cbc3d18e --- /dev/null +++ b/extra/redis/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/redis/src/main/webapp/show.xhtml b/extra/redis/src/main/webapp/show.xhtml new file mode 100644 index 000000000..342b4446b --- /dev/null +++ b/extra/redis/src/main/webapp/show.xhtml @@ -0,0 +1,29 @@ + + + + + + + + + + + Name#{p.name} + Age#{p.age} + +

+ + + + +
+ +
+ + + From c73b40556a946fa05de3e887e9ae4262afde842d Mon Sep 17 00:00:00 2001 From: Arun Gupta Date: Thu, 3 Oct 2013 14:05:45 -0700 Subject: [PATCH 010/934] Adding redis module --- extra/pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/extra/pom.xml b/extra/pom.xml index 6e78376ca..775db0336 100644 --- a/extra/pom.xml +++ b/extra/pom.xml @@ -19,5 +19,6 @@ twitter-search mongo couchbase + redis From d87cc280026b5317a98610b86ae23baab567a5fe Mon Sep 17 00:00:00 2001 From: Arun Gupta Date: Thu, 3 Oct 2013 14:11:11 -0700 Subject: [PATCH 011/934] Moving NoSQL samples to a separate module --- .../org/javaee7/extra/mongo/TestServlet.java | 146 ------------------ extra/{ => nosql}/couchbase/pom.xml | 6 +- .../org/javaee7/extra/couchbase/Person.java | 0 .../extra/couchbase/PersonSessionBean.java | 0 .../src/main/webapp/WEB-INF/beans.xml | 0 .../src/main/webapp/WEB-INF/template.xhtml | 0 .../couchbase/src/main/webapp/WEB-INF/web.xml | 0 .../couchbase/src/main/webapp/index.xhtml | 0 .../main/webapp/resources/css/cssLayout.css | 0 .../src/main/webapp/resources/css/default.css | 0 .../couchbase/src/main/webapp/show.xhtml | 0 extra/{ => nosql}/mongo/pom.xml | 6 +- .../java/org/javaee7/extra/mongo/Person.java | 0 .../extra/mongo/PersonSessionBean.java | 0 .../mongo/src/main/webapp/WEB-INF/beans.xml | 0 .../src/main/webapp/WEB-INF/template.xhtml | 0 .../mongo/src/main/webapp/WEB-INF/web.xml | 0 .../mongo/src/main/webapp/index.xhtml | 0 .../main/webapp/resources/css/cssLayout.css | 0 .../src/main/webapp/resources/css/default.css | 0 .../mongo/src/main/webapp/show.xhtml | 0 extra/nosql/pom.xml | 22 +++ extra/{ => nosql}/redis/pom.xml | 6 +- .../java/org/javaee7/extra/redis/Person.java | 0 .../extra/redis/PersonSessionBean.java | 0 .../redis/src/main/webapp/WEB-INF/beans.xml | 0 .../src/main/webapp/WEB-INF/template.xhtml | 0 .../redis/src/main/webapp/WEB-INF/web.xml | 0 .../redis/src/main/webapp/index.xhtml | 0 .../main/webapp/resources/css/cssLayout.css | 0 .../src/main/webapp/resources/css/default.css | 0 .../redis/src/main/webapp/show.xhtml | 0 extra/pom.xml | 4 +- 33 files changed, 32 insertions(+), 158 deletions(-) delete mode 100644 extra/mongo/src/main/java/org/javaee7/extra/mongo/TestServlet.java rename extra/{ => nosql}/couchbase/pom.xml (81%) rename extra/{ => nosql}/couchbase/src/main/java/org/javaee7/extra/couchbase/Person.java (100%) rename extra/{ => nosql}/couchbase/src/main/java/org/javaee7/extra/couchbase/PersonSessionBean.java (100%) rename extra/{ => nosql}/couchbase/src/main/webapp/WEB-INF/beans.xml (100%) rename extra/{ => nosql}/couchbase/src/main/webapp/WEB-INF/template.xhtml (100%) rename extra/{ => nosql}/couchbase/src/main/webapp/WEB-INF/web.xml (100%) rename extra/{ => nosql}/couchbase/src/main/webapp/index.xhtml (100%) rename extra/{ => nosql}/couchbase/src/main/webapp/resources/css/cssLayout.css (100%) rename extra/{ => nosql}/couchbase/src/main/webapp/resources/css/default.css (100%) rename extra/{ => nosql}/couchbase/src/main/webapp/show.xhtml (100%) rename extra/{ => nosql}/mongo/pom.xml (83%) rename extra/{ => nosql}/mongo/src/main/java/org/javaee7/extra/mongo/Person.java (100%) rename extra/{ => nosql}/mongo/src/main/java/org/javaee7/extra/mongo/PersonSessionBean.java (100%) rename extra/{ => nosql}/mongo/src/main/webapp/WEB-INF/beans.xml (100%) rename extra/{ => nosql}/mongo/src/main/webapp/WEB-INF/template.xhtml (100%) rename extra/{ => nosql}/mongo/src/main/webapp/WEB-INF/web.xml (100%) rename extra/{ => nosql}/mongo/src/main/webapp/index.xhtml (100%) rename extra/{ => nosql}/mongo/src/main/webapp/resources/css/cssLayout.css (100%) rename extra/{ => nosql}/mongo/src/main/webapp/resources/css/default.css (100%) rename extra/{ => nosql}/mongo/src/main/webapp/show.xhtml (100%) create mode 100644 extra/nosql/pom.xml rename extra/{ => nosql}/redis/pom.xml (80%) rename extra/{ => nosql}/redis/src/main/java/org/javaee7/extra/redis/Person.java (100%) rename extra/{ => nosql}/redis/src/main/java/org/javaee7/extra/redis/PersonSessionBean.java (100%) rename extra/{ => nosql}/redis/src/main/webapp/WEB-INF/beans.xml (100%) rename extra/{ => nosql}/redis/src/main/webapp/WEB-INF/template.xhtml (100%) rename extra/{ => nosql}/redis/src/main/webapp/WEB-INF/web.xml (100%) rename extra/{ => nosql}/redis/src/main/webapp/index.xhtml (100%) rename extra/{ => nosql}/redis/src/main/webapp/resources/css/cssLayout.css (100%) rename extra/{ => nosql}/redis/src/main/webapp/resources/css/default.css (100%) rename extra/{ => nosql}/redis/src/main/webapp/show.xhtml (100%) diff --git a/extra/mongo/src/main/java/org/javaee7/extra/mongo/TestServlet.java b/extra/mongo/src/main/java/org/javaee7/extra/mongo/TestServlet.java deleted file mode 100644 index 7236eadfb..000000000 --- a/extra/mongo/src/main/java/org/javaee7/extra/mongo/TestServlet.java +++ /dev/null @@ -1,146 +0,0 @@ -/* - * 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.mongo; - -import java.io.IOException; -import java.io.PrintWriter; -import java.util.logging.Level; -import java.util.logging.Logger; -import javax.servlet.ServletException; -import javax.servlet.annotation.WebServlet; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -/** - * @author Arun Gupta - */ -@WebServlet(urlPatterns = {"/TestServlet"}) -public class TestServlet extends HttpServlet { - - /** - * Processes requests for both HTTP GET and POST - * methods. - * - * @param request servlet request - * @param response servlet response - * @throws ServletException if a servlet-specific error occurs - * @throws IOException if an I/O error occurs - */ - protected void processRequest(HttpServletRequest request, HttpServletResponse response) - throws ServletException, IOException { - response.setContentType("text/html;charset=UTF-8"); - try (PrintWriter out = response.getWriter()) { - out.println(""); - out.println(""); - out.println(""); - out.println("Mongo with Java EE 7"); - out.println(""); - out.println(""); - out.println("

Mongo with Java EE 7

"); - -// Mongo m = new Mongo(); -// DB db = m.getDB("movieDB"); -// DBCollection coll = db.getCollection("test"); -// if (coll == null) { -// System.out.println("Creating a new test collection"); -// coll = db.createCollection("test", null); -// } -// BasicDBObject bdbo = new BasicDBObject(); -// bdbo.put("name", "mario"); -// coll.insert(bdbo); -// bdbo.clear(); -// bdbo.put("name", "luigi"); -// coll.insert(bdbo); -// -// out.println("Found " + coll.getCount() + " elements
"); -// DBCursor cur = coll.find(); -// for (DBObject o : cur.toArray()) { -// out.println(o.get("name") + "
"); -// } - - out.println(""); - out.println(""); - } - } - - // - /** - * Handles the HTTP GET method. - * - * @param request servlet request - * @param response servlet response - * @throws ServletException if a servlet-specific error occurs - * @throws IOException if an I/O error occurs - */ - @Override - protected void doGet - (HttpServletRequest request, HttpServletResponse response) - throws ServletException, IOException { - processRequest(request, response); - } - - /** - * Handles the HTTP POST method. - * - * @param request servlet request - * @param response servlet response - * @throws ServletException if a servlet-specific error occurs - * @throws IOException if an I/O error occurs - */ - @Override - protected void doPost - (HttpServletRequest request, HttpServletResponse response) - throws ServletException, IOException { - processRequest(request, response); - } - - /** - * Returns a short description of the servlet. - * - * @return a String containing servlet description - */ - @Override - public String getServletInfo - - () { - return "Short description"; - }// - } diff --git a/extra/couchbase/pom.xml b/extra/nosql/couchbase/pom.xml similarity index 81% rename from extra/couchbase/pom.xml rename to extra/nosql/couchbase/pom.xml index 9f4768057..3e19cae10 100644 --- a/extra/couchbase/pom.xml +++ b/extra/nosql/couchbase/pom.xml @@ -2,13 +2,13 @@ 4.0.0 - org.javaee7.extra - extra-samples + org.javaee7.extra.nosql + extra-nosql-samples 1.0-SNAPSHOT ../pom.xml - org.javaee7.extra + org.javaee7.extra.nosql couchbase 1.0-SNAPSHOT war diff --git a/extra/couchbase/src/main/java/org/javaee7/extra/couchbase/Person.java b/extra/nosql/couchbase/src/main/java/org/javaee7/extra/couchbase/Person.java similarity index 100% rename from extra/couchbase/src/main/java/org/javaee7/extra/couchbase/Person.java rename to extra/nosql/couchbase/src/main/java/org/javaee7/extra/couchbase/Person.java diff --git a/extra/couchbase/src/main/java/org/javaee7/extra/couchbase/PersonSessionBean.java b/extra/nosql/couchbase/src/main/java/org/javaee7/extra/couchbase/PersonSessionBean.java similarity index 100% rename from extra/couchbase/src/main/java/org/javaee7/extra/couchbase/PersonSessionBean.java rename to extra/nosql/couchbase/src/main/java/org/javaee7/extra/couchbase/PersonSessionBean.java diff --git a/extra/couchbase/src/main/webapp/WEB-INF/beans.xml b/extra/nosql/couchbase/src/main/webapp/WEB-INF/beans.xml similarity index 100% rename from extra/couchbase/src/main/webapp/WEB-INF/beans.xml rename to extra/nosql/couchbase/src/main/webapp/WEB-INF/beans.xml diff --git a/extra/couchbase/src/main/webapp/WEB-INF/template.xhtml b/extra/nosql/couchbase/src/main/webapp/WEB-INF/template.xhtml similarity index 100% rename from extra/couchbase/src/main/webapp/WEB-INF/template.xhtml rename to extra/nosql/couchbase/src/main/webapp/WEB-INF/template.xhtml diff --git a/extra/couchbase/src/main/webapp/WEB-INF/web.xml b/extra/nosql/couchbase/src/main/webapp/WEB-INF/web.xml similarity index 100% rename from extra/couchbase/src/main/webapp/WEB-INF/web.xml rename to extra/nosql/couchbase/src/main/webapp/WEB-INF/web.xml diff --git a/extra/couchbase/src/main/webapp/index.xhtml b/extra/nosql/couchbase/src/main/webapp/index.xhtml similarity index 100% rename from extra/couchbase/src/main/webapp/index.xhtml rename to extra/nosql/couchbase/src/main/webapp/index.xhtml diff --git a/extra/couchbase/src/main/webapp/resources/css/cssLayout.css b/extra/nosql/couchbase/src/main/webapp/resources/css/cssLayout.css similarity index 100% rename from extra/couchbase/src/main/webapp/resources/css/cssLayout.css rename to extra/nosql/couchbase/src/main/webapp/resources/css/cssLayout.css diff --git a/extra/couchbase/src/main/webapp/resources/css/default.css b/extra/nosql/couchbase/src/main/webapp/resources/css/default.css similarity index 100% rename from extra/couchbase/src/main/webapp/resources/css/default.css rename to extra/nosql/couchbase/src/main/webapp/resources/css/default.css diff --git a/extra/couchbase/src/main/webapp/show.xhtml b/extra/nosql/couchbase/src/main/webapp/show.xhtml similarity index 100% rename from extra/couchbase/src/main/webapp/show.xhtml rename to extra/nosql/couchbase/src/main/webapp/show.xhtml diff --git a/extra/mongo/pom.xml b/extra/nosql/mongo/pom.xml similarity index 83% rename from extra/mongo/pom.xml rename to extra/nosql/mongo/pom.xml index 00fd31e5b..793d799c6 100644 --- a/extra/mongo/pom.xml +++ b/extra/nosql/mongo/pom.xml @@ -2,13 +2,13 @@ 4.0.0 - org.javaee7.extra - extra-samples + org.javaee7.extra.nosql + extra-nosql-samples 1.0-SNAPSHOT ../pom.xml - org.javaee7.extra + org.javaee7.extra.nosql mongo 1.0-SNAPSHOT war diff --git a/extra/mongo/src/main/java/org/javaee7/extra/mongo/Person.java b/extra/nosql/mongo/src/main/java/org/javaee7/extra/mongo/Person.java similarity index 100% rename from extra/mongo/src/main/java/org/javaee7/extra/mongo/Person.java rename to extra/nosql/mongo/src/main/java/org/javaee7/extra/mongo/Person.java diff --git a/extra/mongo/src/main/java/org/javaee7/extra/mongo/PersonSessionBean.java b/extra/nosql/mongo/src/main/java/org/javaee7/extra/mongo/PersonSessionBean.java similarity index 100% rename from extra/mongo/src/main/java/org/javaee7/extra/mongo/PersonSessionBean.java rename to extra/nosql/mongo/src/main/java/org/javaee7/extra/mongo/PersonSessionBean.java diff --git a/extra/mongo/src/main/webapp/WEB-INF/beans.xml b/extra/nosql/mongo/src/main/webapp/WEB-INF/beans.xml similarity index 100% rename from extra/mongo/src/main/webapp/WEB-INF/beans.xml rename to extra/nosql/mongo/src/main/webapp/WEB-INF/beans.xml diff --git a/extra/mongo/src/main/webapp/WEB-INF/template.xhtml b/extra/nosql/mongo/src/main/webapp/WEB-INF/template.xhtml similarity index 100% rename from extra/mongo/src/main/webapp/WEB-INF/template.xhtml rename to extra/nosql/mongo/src/main/webapp/WEB-INF/template.xhtml diff --git a/extra/mongo/src/main/webapp/WEB-INF/web.xml b/extra/nosql/mongo/src/main/webapp/WEB-INF/web.xml similarity index 100% rename from extra/mongo/src/main/webapp/WEB-INF/web.xml rename to extra/nosql/mongo/src/main/webapp/WEB-INF/web.xml diff --git a/extra/mongo/src/main/webapp/index.xhtml b/extra/nosql/mongo/src/main/webapp/index.xhtml similarity index 100% rename from extra/mongo/src/main/webapp/index.xhtml rename to extra/nosql/mongo/src/main/webapp/index.xhtml diff --git a/extra/mongo/src/main/webapp/resources/css/cssLayout.css b/extra/nosql/mongo/src/main/webapp/resources/css/cssLayout.css similarity index 100% rename from extra/mongo/src/main/webapp/resources/css/cssLayout.css rename to extra/nosql/mongo/src/main/webapp/resources/css/cssLayout.css diff --git a/extra/mongo/src/main/webapp/resources/css/default.css b/extra/nosql/mongo/src/main/webapp/resources/css/default.css similarity index 100% rename from extra/mongo/src/main/webapp/resources/css/default.css rename to extra/nosql/mongo/src/main/webapp/resources/css/default.css diff --git a/extra/mongo/src/main/webapp/show.xhtml b/extra/nosql/mongo/src/main/webapp/show.xhtml similarity index 100% rename from extra/mongo/src/main/webapp/show.xhtml rename to extra/nosql/mongo/src/main/webapp/show.xhtml diff --git a/extra/nosql/pom.xml b/extra/nosql/pom.xml new file mode 100644 index 000000000..b11f5f7f6 --- /dev/null +++ b/extra/nosql/pom.xml @@ -0,0 +1,22 @@ + + + 4.0.0 + + org.javaee7.extra + extra-samples + 1.0-SNAPSHOT + ../pom.xml + + + org.javaee7.extra.nosql + extra-nosql-samples + 1.0-SNAPSHOT + pom + Java EE 7 Extra NoSQL Samples + + + mongo + couchbase + redis + + diff --git a/extra/redis/pom.xml b/extra/nosql/redis/pom.xml similarity index 80% rename from extra/redis/pom.xml rename to extra/nosql/redis/pom.xml index ce6b57832..bb38e5f06 100644 --- a/extra/redis/pom.xml +++ b/extra/nosql/redis/pom.xml @@ -2,13 +2,13 @@ 4.0.0 - org.javaee7.extra - extra-samples + org.javaee7.extra.nosql + extra-nosql-samples 1.0-SNAPSHOT ../pom.xml - org.javaee7.extra + org.javaee7.extra.nosql redis 1.0-SNAPSHOT war diff --git a/extra/redis/src/main/java/org/javaee7/extra/redis/Person.java b/extra/nosql/redis/src/main/java/org/javaee7/extra/redis/Person.java similarity index 100% rename from extra/redis/src/main/java/org/javaee7/extra/redis/Person.java rename to extra/nosql/redis/src/main/java/org/javaee7/extra/redis/Person.java diff --git a/extra/redis/src/main/java/org/javaee7/extra/redis/PersonSessionBean.java b/extra/nosql/redis/src/main/java/org/javaee7/extra/redis/PersonSessionBean.java similarity index 100% rename from extra/redis/src/main/java/org/javaee7/extra/redis/PersonSessionBean.java rename to extra/nosql/redis/src/main/java/org/javaee7/extra/redis/PersonSessionBean.java diff --git a/extra/redis/src/main/webapp/WEB-INF/beans.xml b/extra/nosql/redis/src/main/webapp/WEB-INF/beans.xml similarity index 100% rename from extra/redis/src/main/webapp/WEB-INF/beans.xml rename to extra/nosql/redis/src/main/webapp/WEB-INF/beans.xml diff --git a/extra/redis/src/main/webapp/WEB-INF/template.xhtml b/extra/nosql/redis/src/main/webapp/WEB-INF/template.xhtml similarity index 100% rename from extra/redis/src/main/webapp/WEB-INF/template.xhtml rename to extra/nosql/redis/src/main/webapp/WEB-INF/template.xhtml diff --git a/extra/redis/src/main/webapp/WEB-INF/web.xml b/extra/nosql/redis/src/main/webapp/WEB-INF/web.xml similarity index 100% rename from extra/redis/src/main/webapp/WEB-INF/web.xml rename to extra/nosql/redis/src/main/webapp/WEB-INF/web.xml diff --git a/extra/redis/src/main/webapp/index.xhtml b/extra/nosql/redis/src/main/webapp/index.xhtml similarity index 100% rename from extra/redis/src/main/webapp/index.xhtml rename to extra/nosql/redis/src/main/webapp/index.xhtml diff --git a/extra/redis/src/main/webapp/resources/css/cssLayout.css b/extra/nosql/redis/src/main/webapp/resources/css/cssLayout.css similarity index 100% rename from extra/redis/src/main/webapp/resources/css/cssLayout.css rename to extra/nosql/redis/src/main/webapp/resources/css/cssLayout.css diff --git a/extra/redis/src/main/webapp/resources/css/default.css b/extra/nosql/redis/src/main/webapp/resources/css/default.css similarity index 100% rename from extra/redis/src/main/webapp/resources/css/default.css rename to extra/nosql/redis/src/main/webapp/resources/css/default.css diff --git a/extra/redis/src/main/webapp/show.xhtml b/extra/nosql/redis/src/main/webapp/show.xhtml similarity index 100% rename from extra/redis/src/main/webapp/show.xhtml rename to extra/nosql/redis/src/main/webapp/show.xhtml diff --git a/extra/pom.xml b/extra/pom.xml index 775db0336..3538abb30 100644 --- a/extra/pom.xml +++ b/extra/pom.xml @@ -17,8 +17,6 @@ quartz twitter-search - mongo - couchbase - redis + nosql From e7ad02df7d049c4ed90b854a67a412a7dff0e972 Mon Sep 17 00:00:00 2001 From: Arun Gupta Date: Thu, 3 Oct 2013 14:13:54 -0700 Subject: [PATCH 012/934] Fixing the package name --- .../java/org/javaee7/extra/{ => nosql}/couchbase/Person.java | 2 +- .../javaee7/extra/{ => nosql}/couchbase/PersonSessionBean.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) rename extra/nosql/couchbase/src/main/java/org/javaee7/extra/{ => nosql}/couchbase/Person.java (98%) rename extra/nosql/couchbase/src/main/java/org/javaee7/extra/{ => nosql}/couchbase/PersonSessionBean.java (98%) diff --git a/extra/nosql/couchbase/src/main/java/org/javaee7/extra/couchbase/Person.java b/extra/nosql/couchbase/src/main/java/org/javaee7/extra/nosql/couchbase/Person.java similarity index 98% rename from extra/nosql/couchbase/src/main/java/org/javaee7/extra/couchbase/Person.java rename to extra/nosql/couchbase/src/main/java/org/javaee7/extra/nosql/couchbase/Person.java index 1a72e8409..fa3c3e477 100644 --- a/extra/nosql/couchbase/src/main/java/org/javaee7/extra/couchbase/Person.java +++ b/extra/nosql/couchbase/src/main/java/org/javaee7/extra/nosql/couchbase/Person.java @@ -37,7 +37,7 @@ * only if the new code is made subject to such option by the copyright * holder. */ -package org.javaee7.extra.couchbase; +package org.javaee7.extra.nosql.couchbase; import java.io.Serializable; import javax.enterprise.context.ApplicationScoped; diff --git a/extra/nosql/couchbase/src/main/java/org/javaee7/extra/couchbase/PersonSessionBean.java b/extra/nosql/couchbase/src/main/java/org/javaee7/extra/nosql/couchbase/PersonSessionBean.java similarity index 98% rename from extra/nosql/couchbase/src/main/java/org/javaee7/extra/couchbase/PersonSessionBean.java rename to extra/nosql/couchbase/src/main/java/org/javaee7/extra/nosql/couchbase/PersonSessionBean.java index e4fb4ccf6..1c591a168 100644 --- a/extra/nosql/couchbase/src/main/java/org/javaee7/extra/couchbase/PersonSessionBean.java +++ b/extra/nosql/couchbase/src/main/java/org/javaee7/extra/nosql/couchbase/PersonSessionBean.java @@ -37,7 +37,7 @@ * only if the new code is made subject to such option by the copyright * holder. */ -package org.javaee7.extra.couchbase; +package org.javaee7.extra.nosql.couchbase; import com.couchbase.client.CouchbaseClient; import java.io.IOException; From b6c5a686d6fef71458976769ef42abbafe49db5a Mon Sep 17 00:00:00 2001 From: Arun Gupta Date: Thu, 3 Oct 2013 14:14:11 -0700 Subject: [PATCH 013/934] Fixing the package name --- .../main/java/org/javaee7/extra/{ => nosql}/mongo/Person.java | 2 +- .../org/javaee7/extra/{ => nosql}/mongo/PersonSessionBean.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) rename extra/nosql/mongo/src/main/java/org/javaee7/extra/{ => nosql}/mongo/Person.java (98%) rename extra/nosql/mongo/src/main/java/org/javaee7/extra/{ => nosql}/mongo/PersonSessionBean.java (99%) diff --git a/extra/nosql/mongo/src/main/java/org/javaee7/extra/mongo/Person.java b/extra/nosql/mongo/src/main/java/org/javaee7/extra/nosql/mongo/Person.java similarity index 98% rename from extra/nosql/mongo/src/main/java/org/javaee7/extra/mongo/Person.java rename to extra/nosql/mongo/src/main/java/org/javaee7/extra/nosql/mongo/Person.java index eb9c48f21..52c203032 100644 --- a/extra/nosql/mongo/src/main/java/org/javaee7/extra/mongo/Person.java +++ b/extra/nosql/mongo/src/main/java/org/javaee7/extra/nosql/mongo/Person.java @@ -37,7 +37,7 @@ * only if the new code is made subject to such option by the copyright * holder. */ -package org.javaee7.extra.mongo; +package org.javaee7.extra.nosql.mongo; import com.mongodb.BasicDBObject; import com.mongodb.DBObject; diff --git a/extra/nosql/mongo/src/main/java/org/javaee7/extra/mongo/PersonSessionBean.java b/extra/nosql/mongo/src/main/java/org/javaee7/extra/nosql/mongo/PersonSessionBean.java similarity index 99% rename from extra/nosql/mongo/src/main/java/org/javaee7/extra/mongo/PersonSessionBean.java rename to extra/nosql/mongo/src/main/java/org/javaee7/extra/nosql/mongo/PersonSessionBean.java index 504fbf884..64ab51cda 100644 --- a/extra/nosql/mongo/src/main/java/org/javaee7/extra/mongo/PersonSessionBean.java +++ b/extra/nosql/mongo/src/main/java/org/javaee7/extra/nosql/mongo/PersonSessionBean.java @@ -37,7 +37,7 @@ * only if the new code is made subject to such option by the copyright * holder. */ -package org.javaee7.extra.mongo; +package org.javaee7.extra.nosql.mongo; import com.mongodb.BasicDBObject; import com.mongodb.DB; From 40e21237069b2dc9e8a69ccad2a190ee227ce6ec Mon Sep 17 00:00:00 2001 From: Arun Gupta Date: Thu, 3 Oct 2013 14:14:22 -0700 Subject: [PATCH 014/934] Fixing the package name --- .../main/java/org/javaee7/extra/{ => nosql}/redis/Person.java | 2 +- .../org/javaee7/extra/{ => nosql}/redis/PersonSessionBean.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) rename extra/nosql/redis/src/main/java/org/javaee7/extra/{ => nosql}/redis/Person.java (98%) rename extra/nosql/redis/src/main/java/org/javaee7/extra/{ => nosql}/redis/PersonSessionBean.java (98%) diff --git a/extra/nosql/redis/src/main/java/org/javaee7/extra/redis/Person.java b/extra/nosql/redis/src/main/java/org/javaee7/extra/nosql/redis/Person.java similarity index 98% rename from extra/nosql/redis/src/main/java/org/javaee7/extra/redis/Person.java rename to extra/nosql/redis/src/main/java/org/javaee7/extra/nosql/redis/Person.java index 83a5781fd..dfbee998a 100644 --- a/extra/nosql/redis/src/main/java/org/javaee7/extra/redis/Person.java +++ b/extra/nosql/redis/src/main/java/org/javaee7/extra/nosql/redis/Person.java @@ -37,7 +37,7 @@ * only if the new code is made subject to such option by the copyright * holder. */ -package org.javaee7.extra.redis; +package org.javaee7.extra.nosql.redis; import java.util.StringTokenizer; import javax.enterprise.context.ApplicationScoped; diff --git a/extra/nosql/redis/src/main/java/org/javaee7/extra/redis/PersonSessionBean.java b/extra/nosql/redis/src/main/java/org/javaee7/extra/nosql/redis/PersonSessionBean.java similarity index 98% rename from extra/nosql/redis/src/main/java/org/javaee7/extra/redis/PersonSessionBean.java rename to extra/nosql/redis/src/main/java/org/javaee7/extra/nosql/redis/PersonSessionBean.java index efdd3b669..5f6884bdf 100644 --- a/extra/nosql/redis/src/main/java/org/javaee7/extra/redis/PersonSessionBean.java +++ b/extra/nosql/redis/src/main/java/org/javaee7/extra/nosql/redis/PersonSessionBean.java @@ -37,7 +37,7 @@ * only if the new code is made subject to such option by the copyright * holder. */ -package org.javaee7.extra.redis; +package org.javaee7.extra.nosql.redis; import java.util.ArrayList; import java.util.HashSet; From 772dfcec54e52af97ed01ad9c00f372d3c3759f3 Mon Sep 17 00:00:00 2001 From: Arun Gupta Date: Thu, 3 Oct 2013 16:26:45 -0700 Subject: [PATCH 015/934] Added a new profile to download s source and javadoc bundles from Maven repository --- pom.xml | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/pom.xml b/pom.xml index 7f3ca6bb4..a47a3bf76 100644 --- a/pom.xml +++ b/pom.xml @@ -257,6 +257,32 @@ + + javadocs + + + + org.apache.maven.plugins + maven-dependency-plugin + 2.8 + + + sources + process-resources + + sources + resolve + + + javadoc + false + + + + + + + From 0689f22dd0a89c07d16796a8b1ebf95f6a64a2b5 Mon Sep 17 00:00:00 2001 From: Arun Gupta Date: Thu, 3 Oct 2013 17:32:29 -0700 Subject: [PATCH 016/934] New sample to show Cassandra usage --- extra/nosql/cassandra/pom.xml | 23 ++++ .../javaee7/extra/nosql/cassandra/Person.java | 92 +++++++++++++ .../nosql/cassandra/PersonSessionBean.java | 127 ++++++++++++++++++ .../src/main/webapp/WEB-INF/beans.xml | 49 +++++++ .../src/main/webapp/WEB-INF/template.xhtml | 26 ++++ .../cassandra/src/main/webapp/WEB-INF/web.xml | 24 ++++ .../cassandra/src/main/webapp/index.xhtml | 43 ++++++ .../main/webapp/resources/css/cssLayout.css | 61 +++++++++ .../src/main/webapp/resources/css/default.css | 29 ++++ .../cassandra/src/main/webapp/show.xhtml | 27 ++++ extra/nosql/pom.xml | 1 + 11 files changed, 502 insertions(+) create mode 100644 extra/nosql/cassandra/pom.xml create mode 100644 extra/nosql/cassandra/src/main/java/org/javaee7/extra/nosql/cassandra/Person.java create mode 100644 extra/nosql/cassandra/src/main/java/org/javaee7/extra/nosql/cassandra/PersonSessionBean.java create mode 100644 extra/nosql/cassandra/src/main/webapp/WEB-INF/beans.xml create mode 100644 extra/nosql/cassandra/src/main/webapp/WEB-INF/template.xhtml create mode 100644 extra/nosql/cassandra/src/main/webapp/WEB-INF/web.xml create mode 100644 extra/nosql/cassandra/src/main/webapp/index.xhtml create mode 100644 extra/nosql/cassandra/src/main/webapp/resources/css/cssLayout.css create mode 100644 extra/nosql/cassandra/src/main/webapp/resources/css/default.css create mode 100644 extra/nosql/cassandra/src/main/webapp/show.xhtml diff --git a/extra/nosql/cassandra/pom.xml b/extra/nosql/cassandra/pom.xml new file mode 100644 index 000000000..cf5864490 --- /dev/null +++ b/extra/nosql/cassandra/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 + cassandra + 1.0-SNAPSHOT + war + + + + com.datastax.cassandra + cassandra-driver-core + 2.0.0-beta2 + + + diff --git a/extra/nosql/cassandra/src/main/java/org/javaee7/extra/nosql/cassandra/Person.java b/extra/nosql/cassandra/src/main/java/org/javaee7/extra/nosql/cassandra/Person.java new file mode 100644 index 000000000..eb527a41e --- /dev/null +++ b/extra/nosql/cassandra/src/main/java/org/javaee7/extra/nosql/cassandra/Person.java @@ -0,0 +1,92 @@ +/* + * 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.cassandra; + +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 { + + @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/cassandra/src/main/java/org/javaee7/extra/nosql/cassandra/PersonSessionBean.java b/extra/nosql/cassandra/src/main/java/org/javaee7/extra/nosql/cassandra/PersonSessionBean.java new file mode 100644 index 000000000..23d0677e6 --- /dev/null +++ b/extra/nosql/cassandra/src/main/java/org/javaee7/extra/nosql/cassandra/PersonSessionBean.java @@ -0,0 +1,127 @@ +/* + * 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.cassandra; + +import com.datastax.driver.core.Cluster; +import com.datastax.driver.core.Host; +import com.datastax.driver.core.Metadata; +import com.datastax.driver.core.ResultSet; +import com.datastax.driver.core.Row; +import com.datastax.driver.core.Session; +import com.datastax.driver.core.exceptions.AlreadyExistsException; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import javax.annotation.PostConstruct; +import javax.annotation.PreDestroy; +import javax.ejb.Singleton; +import javax.inject.Inject; +import javax.inject.Named; + +/** + * @author Arun Gupta + */ +@Named +@Singleton +public class PersonSessionBean { + + @Inject + Person person; + + Set set = new HashSet<>(); + + private Cluster cluster; + private Session session; + + @PostConstruct + private void initDB() { + cluster = Cluster.builder() + .addContactPoint("localhost") + // .withSSL() // Uncomment if using client to node encryption + .build(); + Metadata metadata = cluster.getMetadata(); + System.out.printf("Connected to cluster: %s\n", metadata.getClusterName()); + for (Host host : metadata.getAllHosts()) { + System.out.printf("Datacenter: %s; Host: %s; Rack: %s\n", + host.getDatacenter(), host.getAddress(), host.getRack()); + } + session = cluster.connect(); + try { + session.execute("CREATE KEYSPACE test WITH replication " + + "= {'class':'SimpleStrategy', 'replication_factor':3};"); + } catch (AlreadyExistsException e) { + System.out.println(e.getLocalizedMessage() + " ... keep moving!"); + } + try { + session.execute( + "CREATE TABLE test.person (" + + "name text PRIMARY KEY," + + "age int" + + ");"); + } catch (AlreadyExistsException e) { + System.out.println(e.getLocalizedMessage() + " ... keep moving!"); + } + } + + @PreDestroy + private void stopDB() { + cluster.shutdown(); + } + + public void createPerson() { + session.execute( + "INSERT INTO test.person (name, age) " + + "VALUES (" + + "'" + person.getName() + "'," + + person.getAge() + ")" + + ";"); +// set.add(person.getName()); + } + + public List getPersons() { + List persons = new ArrayList<>(); + ResultSet results = session.execute("SELECT * FROM test.person;"); + for (Row row : results) { + persons.add(new Person(row.getString("name"), row.getInt("age"))); + } + return persons; + } +} diff --git a/extra/nosql/cassandra/src/main/webapp/WEB-INF/beans.xml b/extra/nosql/cassandra/src/main/webapp/WEB-INF/beans.xml new file mode 100644 index 000000000..aa81c7c3c --- /dev/null +++ b/extra/nosql/cassandra/src/main/webapp/WEB-INF/beans.xml @@ -0,0 +1,49 @@ + + + + \ No newline at end of file diff --git a/extra/nosql/cassandra/src/main/webapp/WEB-INF/template.xhtml b/extra/nosql/cassandra/src/main/webapp/WEB-INF/template.xhtml new file mode 100644 index 000000000..82f183175 --- /dev/null +++ b/extra/nosql/cassandra/src/main/webapp/WEB-INF/template.xhtml @@ -0,0 +1,26 @@ + + + + + + + + + Cassandra using Java EE 7 + + + + +
+

Cassandra using Java EE 7

+
+ +
+ Content +
+ +
+ + diff --git a/extra/nosql/cassandra/src/main/webapp/WEB-INF/web.xml b/extra/nosql/cassandra/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 000000000..c5e7c7381 --- /dev/null +++ b/extra/nosql/cassandra/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/cassandra/src/main/webapp/index.xhtml b/extra/nosql/cassandra/src/main/webapp/index.xhtml new file mode 100644 index 000000000..f9d6dd768 --- /dev/null +++ b/extra/nosql/cassandra/src/main/webapp/index.xhtml @@ -0,0 +1,43 @@ + + + + + + + + + + + Name:
+ Age:

+ +
+
+
    +
  • Make sure to download latest Cassandra server and untar.
  • +
  • Follow the instructions in the bundled README.txt to start the server: +
      +
    • sudo mkdir -p /var/log/cassandra
    • +
    • sudo chown -R `whoami` /var/log/cassandra
    • +
    • sudo mkdir -p /var/lib/cassandra
    • +
    • sudo chown -R `whoami` /var/lib/cassandra
    • +
    • bin/cassandra -f
    +
  • +
  • Look for message as: +
    +INFO 16:39:08,258 Binding thrift service to localhost/127.0.0.1:9160
    +INFO 16:39:08,266 Using synchronous/threadpool thrift server on localhost : 9160
    +INFO 16:39:08,293 Listening for thrift clients...
    +                        
    +
  • +
+
+ +
+ + + diff --git a/extra/nosql/cassandra/src/main/webapp/resources/css/cssLayout.css b/extra/nosql/cassandra/src/main/webapp/resources/css/cssLayout.css new file mode 100644 index 000000000..8ee7cebe3 --- /dev/null +++ b/extra/nosql/cassandra/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/cassandra/src/main/webapp/resources/css/default.css b/extra/nosql/cassandra/src/main/webapp/resources/css/default.css new file mode 100644 index 000000000..6cbc3d18e --- /dev/null +++ b/extra/nosql/cassandra/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/cassandra/src/main/webapp/show.xhtml b/extra/nosql/cassandra/src/main/webapp/show.xhtml new file mode 100644 index 000000000..8f1d60f31 --- /dev/null +++ b/extra/nosql/cassandra/src/main/webapp/show.xhtml @@ -0,0 +1,27 @@ + + + + + + + + + + + Name#{p.name} + Age#{p.age} + +

+ + + + +
+ +
+ + + diff --git a/extra/nosql/pom.xml b/extra/nosql/pom.xml index b11f5f7f6..f00b553af 100644 --- a/extra/nosql/pom.xml +++ b/extra/nosql/pom.xml @@ -18,5 +18,6 @@ mongo couchbase redis + cassandra
From 3ca5d0639a6f7d8c9e64da676e3622b3366c5b52 Mon Sep 17 00:00:00 2001 From: Michael Figuiere Date: Thu, 3 Oct 2013 19:01:53 -0700 Subject: [PATCH 017/934] Uses PreparedStatements instead of contatenated strings. Replaces AlreadyExistsException with "IF NOT EXISTS" DDL statements added in Cassandra 2.0. --- .../nosql/cassandra/PersonSessionBean.java | 38 +++++++++---------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/extra/nosql/cassandra/src/main/java/org/javaee7/extra/nosql/cassandra/PersonSessionBean.java b/extra/nosql/cassandra/src/main/java/org/javaee7/extra/nosql/cassandra/PersonSessionBean.java index 23d0677e6..649d01e1d 100644 --- a/extra/nosql/cassandra/src/main/java/org/javaee7/extra/nosql/cassandra/PersonSessionBean.java +++ b/extra/nosql/cassandra/src/main/java/org/javaee7/extra/nosql/cassandra/PersonSessionBean.java @@ -42,14 +42,16 @@ import com.datastax.driver.core.Cluster; import com.datastax.driver.core.Host; import com.datastax.driver.core.Metadata; +import com.datastax.driver.core.PreparedStatement; import com.datastax.driver.core.ResultSet; import com.datastax.driver.core.Row; import com.datastax.driver.core.Session; -import com.datastax.driver.core.exceptions.AlreadyExistsException; + import java.util.ArrayList; import java.util.HashSet; import java.util.List; import java.util.Set; + import javax.annotation.PostConstruct; import javax.annotation.PreDestroy; import javax.ejb.Singleton; @@ -71,6 +73,9 @@ public class PersonSessionBean { private Cluster cluster; private Session session; + private PreparedStatement selectAllPersons; + private PreparedStatement insertPerson; + @PostConstruct private void initDB() { cluster = Cluster.builder() @@ -84,21 +89,19 @@ private void initDB() { host.getDatacenter(), host.getAddress(), host.getRack()); } session = cluster.connect(); - try { - session.execute("CREATE KEYSPACE test WITH replication " - + "= {'class':'SimpleStrategy', 'replication_factor':3};"); - } catch (AlreadyExistsException e) { - System.out.println(e.getLocalizedMessage() + " ... keep moving!"); - } - try { + session.execute("CREATE KEYSPACE IF NOT EXISTS test WITH replication " + + "= {'class':'SimpleStrategy', 'replication_factor':1};"); + session.execute( - "CREATE TABLE test.person (" + "CREATE TABLE IF NOT EXISTS test.person (" + "name text PRIMARY KEY," + "age int" + ");"); - } catch (AlreadyExistsException e) { - System.out.println(e.getLocalizedMessage() + " ... keep moving!"); - } + + selectAllPersons = session.prepare("SELECT * FROM test.person"); + insertPerson = session.prepare( + "INSERT INTO test.person (name, age) VALUES (?, ?);" + ); } @PreDestroy @@ -107,18 +110,13 @@ private void stopDB() { } public void createPerson() { - session.execute( - "INSERT INTO test.person (name, age) " - + "VALUES (" - + "'" + person.getName() + "'," - + person.getAge() + ")" - + ";"); -// set.add(person.getName()); + session.execute(insertPerson.bind(person.getName(), person.getAge())); +// set.add(person.getName()); } public List getPersons() { List persons = new ArrayList<>(); - ResultSet results = session.execute("SELECT * FROM test.person;"); + ResultSet results = session.execute(selectAllPersons.bind()); for (Row row : results) { persons.add(new Person(row.getString("name"), row.getInt("age"))); } From 12cffb361b1bc3b62f964129632e8bb9b6af7fd0 Mon Sep 17 00:00:00 2001 From: Arun Gupta Date: Thu, 3 Oct 2013 22:06:07 -0700 Subject: [PATCH 018/934] Removing some redundant code --- .../org/javaee7/extra/nosql/cassandra/PersonSessionBean.java | 5 ----- 1 file changed, 5 deletions(-) diff --git a/extra/nosql/cassandra/src/main/java/org/javaee7/extra/nosql/cassandra/PersonSessionBean.java b/extra/nosql/cassandra/src/main/java/org/javaee7/extra/nosql/cassandra/PersonSessionBean.java index 649d01e1d..5cf4c67d2 100644 --- a/extra/nosql/cassandra/src/main/java/org/javaee7/extra/nosql/cassandra/PersonSessionBean.java +++ b/extra/nosql/cassandra/src/main/java/org/javaee7/extra/nosql/cassandra/PersonSessionBean.java @@ -48,9 +48,7 @@ import com.datastax.driver.core.Session; import java.util.ArrayList; -import java.util.HashSet; import java.util.List; -import java.util.Set; import javax.annotation.PostConstruct; import javax.annotation.PreDestroy; @@ -68,8 +66,6 @@ public class PersonSessionBean { @Inject Person person; - Set set = new HashSet<>(); - private Cluster cluster; private Session session; @@ -111,7 +107,6 @@ private void stopDB() { public void createPerson() { session.execute(insertPerson.bind(person.getName(), person.getAge())); -// set.add(person.getName()); } public List getPersons() { From bfc51422b58d5e3e87a14dd80236a676de39294b Mon Sep 17 00:00:00 2001 From: Arun Gupta Date: Thu, 3 Oct 2013 22:19:04 -0700 Subject: [PATCH 019/934] Adding navigation to the previous page --- extra/nosql/mongo/src/main/webapp/show.xhtml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/extra/nosql/mongo/src/main/webapp/show.xhtml b/extra/nosql/mongo/src/main/webapp/show.xhtml index 19203f612..5ffc5aae0 100644 --- a/extra/nosql/mongo/src/main/webapp/show.xhtml +++ b/extra/nosql/mongo/src/main/webapp/show.xhtml @@ -14,6 +14,10 @@ Name#{p.name} Age#{p.age} +

+ + + From ee5b4c4dd3e37716732dd180cdc5ab0bd42bf70e Mon Sep 17 00:00:00 2001 From: Arun Gupta Date: Thu, 3 Oct 2013 22:19:21 -0700 Subject: [PATCH 020/934] Adding instructions to download, configure and start Mongo --- extra/nosql/mongo/src/main/webapp/index.xhtml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/extra/nosql/mongo/src/main/webapp/index.xhtml b/extra/nosql/mongo/src/main/webapp/index.xhtml index db1c9bca4..aaf6bc1f3 100644 --- a/extra/nosql/mongo/src/main/webapp/index.xhtml +++ b/extra/nosql/mongo/src/main/webapp/index.xhtml @@ -17,6 +17,13 @@ title="Add" value="Submit"/> +
+ Make sure to download Mongo. Follow the quick start to start the server: +
    +
  • sudo mkdir -p /data/db
  • +
  • sudo chown `id -u` /data/db
  • +
  • ./bin/mongod
  • +
From e9714584600488f98bfa879b6f6b193b6da9e6dc Mon Sep 17 00:00:00 2001 From: Arun Gupta Date: Thu, 3 Oct 2013 22:20:35 -0700 Subject: [PATCH 021/934] Removing the usage of embedded Mongo, asking the users to explicitly start Mongo --- .../extra/nosql/mongo/PersonSessionBean.java | 35 +++---------------- 1 file changed, 4 insertions(+), 31 deletions(-) diff --git a/extra/nosql/mongo/src/main/java/org/javaee7/extra/nosql/mongo/PersonSessionBean.java b/extra/nosql/mongo/src/main/java/org/javaee7/extra/nosql/mongo/PersonSessionBean.java index 64ab51cda..0532ed813 100644 --- a/extra/nosql/mongo/src/main/java/org/javaee7/extra/nosql/mongo/PersonSessionBean.java +++ b/extra/nosql/mongo/src/main/java/org/javaee7/extra/nosql/mongo/PersonSessionBean.java @@ -45,21 +45,12 @@ import com.mongodb.DBCursor; import com.mongodb.DBObject; import com.mongodb.Mongo; -import com.mongodb.MongoException; -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; +import java.net.UnknownHostException; import java.util.ArrayList; import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; import javax.annotation.PostConstruct; -import javax.annotation.PreDestroy; import javax.ejb.Stateless; import javax.inject.Inject; import javax.inject.Named; @@ -76,39 +67,21 @@ public class PersonSessionBean { DBCollection personCollection; - private MongodExecutable mongodExe; - private MongodProcess mongod; - private final int MONGO_PORT = 12345; - @PostConstruct private void initDB() { - try { - // Start embedded Mongo - MongodStarter runtime = MongodStarter.getDefaultInstance(); - mongodExe = runtime.prepare(new MongodConfigBuilder() - .version(Version.Main.PRODUCTION) - .net(new Net(MONGO_PORT, Network.localhostIsIPv6())) - .build()); - mongod = mongodExe.start(); - + try { // Get an instance of Mongo - Mongo m = new Mongo("localhost", MONGO_PORT); + Mongo m = new Mongo("localhost", 27017); DB db = m.getDB("personDB"); personCollection = db.getCollection("persons"); if (personCollection == null) { personCollection = db.createCollection("persons", null); } - } catch (MongoException | IOException ex) { + } catch (UnknownHostException ex) { Logger.getLogger(PersonSessionBean.class.getName()).log(Level.SEVERE, null, ex); } } - @PreDestroy - private void stopDB() { - mongod.stop(); - mongodExe.stop(); - } - public void createPerson() { BasicDBObject doc = person.toDBObject(); personCollection.insert(doc); From a488d82c80b82f6ede0dab47b5636a1d328d6574 Mon Sep 17 00:00:00 2001 From: Arun Gupta Date: Thu, 3 Oct 2013 22:20:51 -0700 Subject: [PATCH 022/934] Removing the redundant dependency --- extra/nosql/mongo/pom.xml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/extra/nosql/mongo/pom.xml b/extra/nosql/mongo/pom.xml index 793d799c6..152582c7c 100644 --- a/extra/nosql/mongo/pom.xml +++ b/extra/nosql/mongo/pom.xml @@ -19,10 +19,5 @@ mongo-java-driver 1.3 - - de.flapdoodle.embed - de.flapdoodle.embed.mongo - 1.36 -
From cbd39b89f4e1d9393ccf2fa8eec8f7116ddb42c7 Mon Sep 17 00:00:00 2001 From: Arun Gupta Date: Thu, 3 Oct 2013 22:30:19 -0700 Subject: [PATCH 023/934] Samples can run using Embedded GlassFish using "embedded-glassfish" profile --- pom.xml | 91 +++++++++++++++++++++++++++++++-------------------------- 1 file changed, 49 insertions(+), 42 deletions(-) diff --git a/pom.xml b/pom.xml index a47a3bf76..72dd86b90 100644 --- a/pom.xml +++ b/pom.xml @@ -111,48 +111,6 @@ - - org.glassfish.embedded - maven-embedded-glassfish-plugin - 4.0 - - target/${project.artifactId}.war - 8080 - - 8181 - - - - - org.glassfish.main.common - simple-glassfish-api - 4.0 - - - org.glassfish.main.extras - glassfish-embedded-all - 4.0 - - - - - start - integration-test - - start - deploy - - - - stop - post-integration-test - - undeploy - stop - - - - @@ -194,6 +152,55 @@ + + embedded-glassfish + + + + org.glassfish.embedded + maven-embedded-glassfish-plugin + 4.0 + + target/${project.artifactId}.war + 8080 + + 8181 + + + + + org.glassfish.main.common + simple-glassfish-api + 4.0 + + + org.glassfish.main.extras + glassfish-embedded-all + 4.0 + + + + + start + integration-test + + start + deploy + + + + stop + post-integration-test + + undeploy + stop + + + + + + + wildfly From fa5c17910442ae3f76f06e6bf39264ba15730a56 Mon Sep 17 00:00:00 2001 From: Arun Gupta Date: Fri, 4 Oct 2013 17:40:58 -0700 Subject: [PATCH 024/934] Starting work on Neo4j sample --- extra/nosql/neo4j/pom.xml | 23 +++ .../extra/nosql/neo4j/BackingBean.java | 119 ++++++++++++++ .../org/javaee7/extra/nosql/neo4j/Person.java | 90 +++++++++++ .../extra/nosql/neo4j/PersonSessionBean.java | 148 ++++++++++++++++++ .../neo4j/src/main/webapp/WEB-INF/beans.xml | 49 ++++++ .../src/main/webapp/WEB-INF/template.xhtml | 26 +++ .../neo4j/src/main/webapp/WEB-INF/web.xml | 24 +++ extra/nosql/neo4j/src/main/webapp/index.xhtml | 36 +++++ .../main/webapp/resources/css/cssLayout.css | 61 ++++++++ .../src/main/webapp/resources/css/default.css | 29 ++++ extra/nosql/neo4j/src/main/webapp/show.xhtml | 28 ++++ 11 files changed, 633 insertions(+) create mode 100644 extra/nosql/neo4j/pom.xml create mode 100644 extra/nosql/neo4j/src/main/java/org/javaee7/extra/nosql/neo4j/BackingBean.java create mode 100644 extra/nosql/neo4j/src/main/java/org/javaee7/extra/nosql/neo4j/Person.java create mode 100644 extra/nosql/neo4j/src/main/java/org/javaee7/extra/nosql/neo4j/PersonSessionBean.java create mode 100644 extra/nosql/neo4j/src/main/webapp/WEB-INF/beans.xml create mode 100644 extra/nosql/neo4j/src/main/webapp/WEB-INF/template.xhtml create mode 100644 extra/nosql/neo4j/src/main/webapp/WEB-INF/web.xml create mode 100644 extra/nosql/neo4j/src/main/webapp/index.xhtml create mode 100644 extra/nosql/neo4j/src/main/webapp/resources/css/cssLayout.css create mode 100644 extra/nosql/neo4j/src/main/webapp/resources/css/default.css create mode 100644 extra/nosql/neo4j/src/main/webapp/show.xhtml diff --git a/extra/nosql/neo4j/pom.xml b/extra/nosql/neo4j/pom.xml new file mode 100644 index 000000000..3abd78f3d --- /dev/null +++ b/extra/nosql/neo4j/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 + neo4j + 1.0-SNAPSHOT + war + + + + org.neo4j + neo4j + 2.0.0-M05 + + + diff --git a/extra/nosql/neo4j/src/main/java/org/javaee7/extra/nosql/neo4j/BackingBean.java b/extra/nosql/neo4j/src/main/java/org/javaee7/extra/nosql/neo4j/BackingBean.java new file mode 100644 index 000000000..2b13229f8 --- /dev/null +++ b/extra/nosql/neo4j/src/main/java/org/javaee7/extra/nosql/neo4j/BackingBean.java @@ -0,0 +1,119 @@ +/* + * 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.neo4j; + +import javax.enterprise.context.ApplicationScoped; +import javax.inject.Named; +import javax.validation.constraints.Size; + +/** + * @author Arun Gupta + */ +@Named +@ApplicationScoped +public class BackingBean { + + @Size(min = 1, max = 20) + private String name; + + private int age; + + private String name2; + + private int age2; + + private String relationship; + + public BackingBean() { + } + + public BackingBean(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; + } + + public String getName2() { + return name2; + } + + public void setName2(String name2) { + this.name2 = name2; + } + + public int getAge2() { + return age2; + } + + public void setAge2(int age2) { + this.age2 = age2; + } + + public String getRelationship() { + return relationship; + } + + public void setRelationship(String relationship) { + this.relationship = relationship; + } + + public String person1String() { + return name + ", " + age; + } + + public String person2String() { + return name2 + ", " + age2; + } +} diff --git a/extra/nosql/neo4j/src/main/java/org/javaee7/extra/nosql/neo4j/Person.java b/extra/nosql/neo4j/src/main/java/org/javaee7/extra/nosql/neo4j/Person.java new file mode 100644 index 000000000..cf4323903 --- /dev/null +++ b/extra/nosql/neo4j/src/main/java/org/javaee7/extra/nosql/neo4j/Person.java @@ -0,0 +1,90 @@ +/* + * 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.neo4j; + +import java.util.StringTokenizer; +import javax.validation.constraints.Size; + +/** + * @author Arun Gupta + */ +public class Person { + + @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 final Person fromString(String string) { + StringTokenizer tokens = new StringTokenizer(string, ","); + Person p = new Person(tokens.nextToken(), Integer.parseInt(tokens.nextToken().trim())); + + return p; + } +} diff --git a/extra/nosql/neo4j/src/main/java/org/javaee7/extra/nosql/neo4j/PersonSessionBean.java b/extra/nosql/neo4j/src/main/java/org/javaee7/extra/nosql/neo4j/PersonSessionBean.java new file mode 100644 index 000000000..f86b4bc00 --- /dev/null +++ b/extra/nosql/neo4j/src/main/java/org/javaee7/extra/nosql/neo4j/PersonSessionBean.java @@ -0,0 +1,148 @@ +/* + * 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.neo4j; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.attribute.FileAttribute; +import java.nio.file.attribute.PosixFilePermission; +import java.nio.file.attribute.PosixFilePermissions; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.logging.Level; +import java.util.logging.Logger; +import javax.annotation.PostConstruct; +import javax.annotation.PreDestroy; +import javax.inject.Inject; +import javax.inject.Named; +import javax.inject.Singleton; +import org.neo4j.graphdb.GraphDatabaseService; +import org.neo4j.graphdb.Node; +import org.neo4j.graphdb.Relationship; +import org.neo4j.graphdb.RelationshipType; +import org.neo4j.graphdb.Transaction; +import org.neo4j.graphdb.factory.GraphDatabaseFactory; + +/** + * @author Arun Gupta + */ +@Named +@Singleton +public class PersonSessionBean { + + @Inject + BackingBean backingBean; + + GraphDatabaseService graphDb; + Node firstNode; + Node secondNode; + + private static enum RelTypes implements RelationshipType { + + SPOUSE, BROTHER, SISTER + } + + Set set = new HashSet<>(); + + @PostConstruct + private void initDB() { + try { + Path tempDir = Files.createTempDirectory("test-neo4j"); +// Set perms = PosixFilePermissions.fromString("rwxr-x---"); +// FileAttribute> attr = PosixFilePermissions.asFileAttribute(perms); +// Files.createDirectories(DB_PATH, attr); + graphDb = new GraphDatabaseFactory().newEmbeddedDatabase(tempDir.toString()); + try (Transaction tx = graphDb.beginTx()) { + firstNode = graphDb.createNode(); + secondNode = graphDb.createNode(); + } + } catch (IOException ex) { + Logger.getLogger(PersonSessionBean.class.getName()).log(Level.SEVERE, null, ex); + } + } + + @PreDestroy + private void stopDB() { + graphDb.shutdown(); + } + + public void createPerson() { + try (Transaction tx = graphDb.beginTx()) { + firstNode.setProperty(backingBean.getName(), backingBean.person1String()); + secondNode.setProperty(backingBean.getName2(), backingBean.person2String()); + switch (backingBean.getRelationship()) { + case "spouse": + firstNode.createRelationshipTo(secondNode, RelTypes.SPOUSE); + break; + case "brother": + firstNode.createRelationshipTo(secondNode, RelTypes.BROTHER); + break; + case "sister": + firstNode.createRelationshipTo(secondNode, RelTypes.SISTER); + break; + } + tx.success(); + } + } + + public List getPersons() { + List beans = new ArrayList(); + for (String key : firstNode.getPropertyKeys()) { + BackingBean bean = new BackingBean(); + Person p = Person.fromString((String)firstNode.getProperty(key)); + bean.setName(p.getName()); + bean.setAge(p.getAge()); + for (Relationship r : firstNode.getRelationships(RelTypes.SPOUSE, RelTypes.SISTER, RelTypes.BROTHER)) { + if (r.isType(RelTypes.SPOUSE)) { + bean.setRelationship("spouse"); + } else if (r.isType(RelTypes.SISTER)) { + bean.setRelationship("sister"); + } else if (r.isType(RelTypes.BROTHER)) { + bean.setRelationship("brother"); + } + } + beans.add(bean); + } + return beans; + } +} diff --git a/extra/nosql/neo4j/src/main/webapp/WEB-INF/beans.xml b/extra/nosql/neo4j/src/main/webapp/WEB-INF/beans.xml new file mode 100644 index 000000000..aa81c7c3c --- /dev/null +++ b/extra/nosql/neo4j/src/main/webapp/WEB-INF/beans.xml @@ -0,0 +1,49 @@ + + + + \ No newline at end of file diff --git a/extra/nosql/neo4j/src/main/webapp/WEB-INF/template.xhtml b/extra/nosql/neo4j/src/main/webapp/WEB-INF/template.xhtml new file mode 100644 index 000000000..9eb7c0652 --- /dev/null +++ b/extra/nosql/neo4j/src/main/webapp/WEB-INF/template.xhtml @@ -0,0 +1,26 @@ + + + + + + + + + Couchbase using Java EE 7 + + + + +
+

Couchbase using Java EE 7

+
+ +
+ Content +
+ +
+ + diff --git a/extra/nosql/neo4j/src/main/webapp/WEB-INF/web.xml b/extra/nosql/neo4j/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 000000000..c5e7c7381 --- /dev/null +++ b/extra/nosql/neo4j/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/neo4j/src/main/webapp/index.xhtml b/extra/nosql/neo4j/src/main/webapp/index.xhtml new file mode 100644 index 000000000..6995adb2a --- /dev/null +++ b/extra/nosql/neo4j/src/main/webapp/index.xhtml @@ -0,0 +1,36 @@ + + + + + + + + + + + Name:
+ Age:

+ Related as: + + + + +

+ + Name2:
+ Age2:

+ +
+
+ Download Neo4j Community version. Untar and start the server as "bin/neo4j start". +
+ +
+ + + diff --git a/extra/nosql/neo4j/src/main/webapp/resources/css/cssLayout.css b/extra/nosql/neo4j/src/main/webapp/resources/css/cssLayout.css new file mode 100644 index 000000000..8ee7cebe3 --- /dev/null +++ b/extra/nosql/neo4j/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/neo4j/src/main/webapp/resources/css/default.css b/extra/nosql/neo4j/src/main/webapp/resources/css/default.css new file mode 100644 index 000000000..6cbc3d18e --- /dev/null +++ b/extra/nosql/neo4j/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/neo4j/src/main/webapp/show.xhtml b/extra/nosql/neo4j/src/main/webapp/show.xhtml new file mode 100644 index 000000000..48b1ea71c --- /dev/null +++ b/extra/nosql/neo4j/src/main/webapp/show.xhtml @@ -0,0 +1,28 @@ + + + + + + + + + + + Name#{p.name} + Age#{p.age} + Relationship#{p.relationship} + +

+ + + + +
+ +
+ + + From cacbe635fdd3be2122e8123d5d9f402f3c86ed00 Mon Sep 17 00:00:00 2001 From: Arun Gupta Date: Fri, 4 Oct 2013 23:12:18 -0700 Subject: [PATCH 025/934] Marking transactions for committing during close --- .../extra/nosql/neo4j/PersonSessionBean.java | 39 +++++++++---------- 1 file changed, 18 insertions(+), 21 deletions(-) diff --git a/extra/nosql/neo4j/src/main/java/org/javaee7/extra/nosql/neo4j/PersonSessionBean.java b/extra/nosql/neo4j/src/main/java/org/javaee7/extra/nosql/neo4j/PersonSessionBean.java index f86b4bc00..f4e2ffba7 100644 --- a/extra/nosql/neo4j/src/main/java/org/javaee7/extra/nosql/neo4j/PersonSessionBean.java +++ b/extra/nosql/neo4j/src/main/java/org/javaee7/extra/nosql/neo4j/PersonSessionBean.java @@ -42,9 +42,6 @@ import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; -import java.nio.file.attribute.FileAttribute; -import java.nio.file.attribute.PosixFilePermission; -import java.nio.file.attribute.PosixFilePermissions; import java.util.ArrayList; import java.util.HashSet; import java.util.List; @@ -78,7 +75,6 @@ public class PersonSessionBean { Node secondNode; private static enum RelTypes implements RelationshipType { - SPOUSE, BROTHER, SISTER } @@ -88,15 +84,13 @@ private static enum RelTypes implements RelationshipType { private void initDB() { try { Path tempDir = Files.createTempDirectory("test-neo4j"); -// Set perms = PosixFilePermissions.fromString("rwxr-x---"); -// FileAttribute> attr = PosixFilePermissions.asFileAttribute(perms); -// Files.createDirectories(DB_PATH, attr); graphDb = new GraphDatabaseFactory().newEmbeddedDatabase(tempDir.toString()); try (Transaction tx = graphDb.beginTx()) { firstNode = graphDb.createNode(); secondNode = graphDb.createNode(); + tx.success(); } - } catch (IOException ex) { + } catch (IOException ex) { Logger.getLogger(PersonSessionBean.class.getName()).log(Level.SEVERE, null, ex); } } @@ -127,21 +121,24 @@ public void createPerson() { public List getPersons() { List beans = new ArrayList(); - for (String key : firstNode.getPropertyKeys()) { - BackingBean bean = new BackingBean(); - Person p = Person.fromString((String)firstNode.getProperty(key)); - bean.setName(p.getName()); - bean.setAge(p.getAge()); - for (Relationship r : firstNode.getRelationships(RelTypes.SPOUSE, RelTypes.SISTER, RelTypes.BROTHER)) { - if (r.isType(RelTypes.SPOUSE)) { - bean.setRelationship("spouse"); - } else if (r.isType(RelTypes.SISTER)) { - bean.setRelationship("sister"); - } else if (r.isType(RelTypes.BROTHER)) { - bean.setRelationship("brother"); + try (Transaction tx = graphDb.beginTx()) { + for (String key : firstNode.getPropertyKeys()) { + BackingBean bean = new BackingBean(); + Person p = Person.fromString((String) firstNode.getProperty(key)); + bean.setName(p.getName()); + bean.setAge(p.getAge()); + for (Relationship r : firstNode.getRelationships(RelTypes.SPOUSE, RelTypes.SISTER, RelTypes.BROTHER)) { + if (r.isType(RelTypes.SPOUSE)) { + bean.setRelationship("spouse"); + } else if (r.isType(RelTypes.SISTER)) { + bean.setRelationship("sister"); + } else if (r.isType(RelTypes.BROTHER)) { + bean.setRelationship("brother"); + } } + beans.add(bean); } - beans.add(bean); + tx.success(); } return beans; } From 24b94b6bb1ff816ce6838928a3e8df896fe9875f Mon Sep 17 00:00:00 2001 From: Arun Gupta Date: Fri, 4 Oct 2013 23:12:40 -0700 Subject: [PATCH 026/934] Adding neo4j sample --- extra/nosql/pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/extra/nosql/pom.xml b/extra/nosql/pom.xml index f00b553af..b18f17bf3 100644 --- a/extra/nosql/pom.xml +++ b/extra/nosql/pom.xml @@ -19,5 +19,6 @@ couchbase redis cassandra + neo4j From 5131a1d9c14398ed44e0d7615fe94a00832a7402 Mon Sep 17 00:00:00 2001 From: Arun Gupta Date: Fri, 4 Oct 2013 23:20:55 -0700 Subject: [PATCH 027/934] Adding a break to avoid redundant evaluation --- .../java/org/javaee7/extra/nosql/neo4j/PersonSessionBean.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/extra/nosql/neo4j/src/main/java/org/javaee7/extra/nosql/neo4j/PersonSessionBean.java b/extra/nosql/neo4j/src/main/java/org/javaee7/extra/nosql/neo4j/PersonSessionBean.java index f4e2ffba7..407917d58 100644 --- a/extra/nosql/neo4j/src/main/java/org/javaee7/extra/nosql/neo4j/PersonSessionBean.java +++ b/extra/nosql/neo4j/src/main/java/org/javaee7/extra/nosql/neo4j/PersonSessionBean.java @@ -130,10 +130,13 @@ public List getPersons() { for (Relationship r : firstNode.getRelationships(RelTypes.SPOUSE, RelTypes.SISTER, RelTypes.BROTHER)) { if (r.isType(RelTypes.SPOUSE)) { bean.setRelationship("spouse"); + break; } else if (r.isType(RelTypes.SISTER)) { bean.setRelationship("sister"); + break; } else if (r.isType(RelTypes.BROTHER)) { bean.setRelationship("brother"); + break; } } beans.add(bean); From 21179a3dabb85695f95a7b17c3e923bf077f17b3 Mon Sep 17 00:00:00 2001 From: Arun Gupta Date: Sun, 6 Oct 2013 21:50:44 -0700 Subject: [PATCH 028/934] Starting work on HBase sample --- extra/nosql/hbase/pom.xml | 28 +++ .../org/javaee7/extra/nosql/hbase/Person.java | 92 ++++++++++ .../extra/nosql/hbase/PersonSessionBean.java | 162 ++++++++++++++++++ .../hbase/src/main/webapp/WEB-INF/beans.xml | 49 ++++++ .../src/main/webapp/WEB-INF/template.xhtml | 26 +++ .../hbase/src/main/webapp/WEB-INF/web.xml | 24 +++ extra/nosql/hbase/src/main/webapp/index.xhtml | 33 ++++ .../main/webapp/resources/css/cssLayout.css | 61 +++++++ .../src/main/webapp/resources/css/default.css | 29 ++++ extra/nosql/hbase/src/main/webapp/show.xhtml | 29 ++++ 10 files changed, 533 insertions(+) create mode 100644 extra/nosql/hbase/pom.xml create mode 100644 extra/nosql/hbase/src/main/java/org/javaee7/extra/nosql/hbase/Person.java create mode 100644 extra/nosql/hbase/src/main/java/org/javaee7/extra/nosql/hbase/PersonSessionBean.java create mode 100644 extra/nosql/hbase/src/main/webapp/WEB-INF/beans.xml create mode 100644 extra/nosql/hbase/src/main/webapp/WEB-INF/template.xhtml create mode 100644 extra/nosql/hbase/src/main/webapp/WEB-INF/web.xml create mode 100644 extra/nosql/hbase/src/main/webapp/index.xhtml create mode 100644 extra/nosql/hbase/src/main/webapp/resources/css/cssLayout.css create mode 100644 extra/nosql/hbase/src/main/webapp/resources/css/default.css create mode 100644 extra/nosql/hbase/src/main/webapp/show.xhtml diff --git a/extra/nosql/hbase/pom.xml b/extra/nosql/hbase/pom.xml new file mode 100644 index 000000000..574b06db3 --- /dev/null +++ b/extra/nosql/hbase/pom.xml @@ -0,0 +1,28 @@ + + + 4.0.0 + + org.javaee7.extra.nosql + extra-nosql-samples + 1.0-SNAPSHOT + ../pom.xml + + + org.javaee7.extra.nosql + hbase + 1.0-SNAPSHOT + war + + + + org.apache.hadoop + hadoop-core + 0.20.2 + + + org.apache.hbase + hbase + 0.90.2 + + + diff --git a/extra/nosql/hbase/src/main/java/org/javaee7/extra/nosql/hbase/Person.java b/extra/nosql/hbase/src/main/java/org/javaee7/extra/nosql/hbase/Person.java new file mode 100644 index 000000000..0842f0198 --- /dev/null +++ b/extra/nosql/hbase/src/main/java/org/javaee7/extra/nosql/hbase/Person.java @@ -0,0 +1,92 @@ +/* + * 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.hbase; + +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 { + + @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/hbase/src/main/java/org/javaee7/extra/nosql/hbase/PersonSessionBean.java b/extra/nosql/hbase/src/main/java/org/javaee7/extra/nosql/hbase/PersonSessionBean.java new file mode 100644 index 000000000..10643fd11 --- /dev/null +++ b/extra/nosql/hbase/src/main/java/org/javaee7/extra/nosql/hbase/PersonSessionBean.java @@ -0,0 +1,162 @@ +/* + * 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.hbase; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.logging.Level; +import java.util.logging.Logger; +import javax.annotation.PostConstruct; +import javax.annotation.PreDestroy; +import javax.ejb.Stateless; +import javax.inject.Inject; +import javax.inject.Named; +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.hbase.HBaseConfiguration; +import org.apache.hadoop.hbase.HColumnDescriptor; +import org.apache.hadoop.hbase.HTableDescriptor; +import org.apache.hadoop.hbase.KeyValue; +import org.apache.hadoop.hbase.client.HBaseAdmin; +import org.apache.hadoop.hbase.client.HTableInterface; +import org.apache.hadoop.hbase.client.HTablePool; +import org.apache.hadoop.hbase.client.Put; +import org.apache.hadoop.hbase.client.Result; +import org.apache.hadoop.hbase.client.ResultScanner; +import org.apache.hadoop.hbase.client.Scan; +import org.apache.hadoop.hbase.util.Bytes; + +/** + * @author Arun Gupta + */ +@Named +@Stateless +public class PersonSessionBean { + + @Inject + Person person; + + Set set = new HashSet<>(); + + private static final String personsColumnFamily = "person"; + private static final String personsTable = "persons"; + HTablePool pool; + + @PostConstruct + private void initDB() { + try { + // By default, it's localhost, don't worry. + Configuration config = HBaseConfiguration.create(); + + // Without pooling, the connection to a table will be reinitialized. + // Creating a new connection to a table might take up to 5-10 seconds! + pool = new HTablePool(config, 10); + + HBaseAdmin admin = new HBaseAdmin(config); + HTableDescriptor blogstable = new HTableDescriptor(personsTable); + admin.createTable(blogstable); + + // Cannot edit a stucture on an active table. + admin.disableTable(personsTable); + + HColumnDescriptor userCol = new HColumnDescriptor("name"); + admin.addColumn(personsTable, userCol); + + HColumnDescriptor ageCol = new HColumnDescriptor("age"); + admin.addColumn(personsTable, ageCol); + + // For readin, it needs to be re-enabled. + admin.enableTable(personsTable); + } catch (IOException ex) { + Logger.getLogger(PersonSessionBean.class.getName()).log(Level.SEVERE, null, ex); + } + } + + @PreDestroy + private void stopDB() { + } + + public void createPerson() { + try { + HTableInterface table = pool.getTable(personsTable); + Put put = new Put(Bytes.toBytes(person.getName())); + put.add( + Bytes.toBytes(personsColumnFamily), + Bytes.toBytes(person.getName()), + Bytes.toBytes(person.getAge())); + table.put(put); + table.close(); + } catch (IOException ex) { + Logger.getLogger(PersonSessionBean.class.getName()).log(Level.SEVERE, null, ex); + } + } + + public List getPersons() { + List persons = new ArrayList<>(); + + try { + HTableInterface table = pool.getTable(personsTable); + Scan scan = new Scan(); + scan.addFamily(Bytes.toBytes(personsColumnFamily)); + + ResultScanner resultScanner = table.getScanner(scan); + +// For each row + for (Result result : resultScanner) { + for (KeyValue kv : result.raw()) { + Person p = new Person(); +// p.setTitle(Bytes.toString(kv.getQualifier())); +// p.setBody(Bytes.toString(kv.getValue())); +// p.setId(Bytes.toString(result.getRow())); + persons.add(person); + } + } + + resultScanner.close(); + table.close(); + } catch (IOException ex) { + Logger.getLogger(PersonSessionBean.class.getName()).log(Level.SEVERE, null, ex); + } + + return persons; + } +} diff --git a/extra/nosql/hbase/src/main/webapp/WEB-INF/beans.xml b/extra/nosql/hbase/src/main/webapp/WEB-INF/beans.xml new file mode 100644 index 000000000..aa81c7c3c --- /dev/null +++ b/extra/nosql/hbase/src/main/webapp/WEB-INF/beans.xml @@ -0,0 +1,49 @@ + + + + \ No newline at end of file diff --git a/extra/nosql/hbase/src/main/webapp/WEB-INF/template.xhtml b/extra/nosql/hbase/src/main/webapp/WEB-INF/template.xhtml new file mode 100644 index 000000000..c0d6c22b3 --- /dev/null +++ b/extra/nosql/hbase/src/main/webapp/WEB-INF/template.xhtml @@ -0,0 +1,26 @@ + + + + + + + + + Redis using Java EE 7 + + + + +
+

Redis using Java EE 7

+
+ +
+ Content +
+ +
+ + diff --git a/extra/nosql/hbase/src/main/webapp/WEB-INF/web.xml b/extra/nosql/hbase/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 000000000..c5e7c7381 --- /dev/null +++ b/extra/nosql/hbase/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/hbase/src/main/webapp/index.xhtml b/extra/nosql/hbase/src/main/webapp/index.xhtml new file mode 100644 index 000000000..e2f909985 --- /dev/null +++ b/extra/nosql/hbase/src/main/webapp/index.xhtml @@ -0,0 +1,33 @@ + + + + + + + + + + + Name:
+ Age:

+ +
+
+

+
    +
  • Download HBase stable and tar xzvf.
  • +
  • Start HBase: ./bin/start-hbase.sh
  • +
  • Look for messages like:
    + starting master, logging to /Users/arungup/tools/hbase/hbase-0.94.12/bin/../logs/hbase-arungup-master-arungup-mac.local.out +
  • +
+
+ +
+ + + diff --git a/extra/nosql/hbase/src/main/webapp/resources/css/cssLayout.css b/extra/nosql/hbase/src/main/webapp/resources/css/cssLayout.css new file mode 100644 index 000000000..8ee7cebe3 --- /dev/null +++ b/extra/nosql/hbase/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/hbase/src/main/webapp/resources/css/default.css b/extra/nosql/hbase/src/main/webapp/resources/css/default.css new file mode 100644 index 000000000..6cbc3d18e --- /dev/null +++ b/extra/nosql/hbase/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/hbase/src/main/webapp/show.xhtml b/extra/nosql/hbase/src/main/webapp/show.xhtml new file mode 100644 index 000000000..342b4446b --- /dev/null +++ b/extra/nosql/hbase/src/main/webapp/show.xhtml @@ -0,0 +1,29 @@ + + + + + + + + + + + Name#{p.name} + Age#{p.age} + +

+ + + + +
+ +
+ + + From 743c01967074ad713a9b42d78bc4f304f5af471e Mon Sep 17 00:00:00 2001 From: Heiko Scherrer Date: Mon, 7 Oct 2013 09:15:39 +0200 Subject: [PATCH 029/934] Fixed javadocs and sources download --- .gitignore | 198 +++++++++++++++++++++-------------------------------- pom.xml | 11 ++- 2 files changed, 87 insertions(+), 122 deletions(-) diff --git a/.gitignore b/.gitignore index 4da7b0943..4f469494d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,121 +1,77 @@ -/jaxrs/resource-validation/target/ -/jaxrs/mapping-exceptions/target/ -/jaxrs/server-negotiation/target/ -/jaxrs/async-client/target/ -/batch/flow/target/ -/batch/batchlet-simple/target/ -/batch/chunk-checkpoint/target/ -/batch/chunk-exception/target/ -/batch/chunk-mapper/target/ -/batch/decision/target/ -/batch/listeners/target/ -/batch/multiple-steps/target/ -/batch/split/target/ -/batch/chunk-simple-nobeans/target/ -/json/object-builder/target/ -/json/object-reader/target/ -/json/streaming-generate/target/ -/json/streaming-parser/target/ -/websocket/binary/target/ -/websocket/whiteboard/target/ -/cdi/vetoed/target/ -/cdi/pkg-level/target/ -/cdi/decorators/target/ -/cdi/bean-discovery-all/target/ -/cdi/bean-discovery-none/target/ -/cdi/bean-discovery-annotated/target/ -/cdi/exclude-filter/target/ -/cdi/built-in/target/ -/cdi/interceptors/target/ -/cdi/nobeans-xml/target/ -/cdi/beansxml-noversion/target/ -/cdi/beanmanager/target/ -/concurrency/dynamicproxy/target/ -/concurrency/executor/target/ -/concurrency/schedule/target/ -/concurrency/threads/target/ -/websocket/chat/target/ -/websocket/encoder/target/ -/websocket/encoder-client/target/ -/websocket/encoder-programmatic/target/ -/websocket/endpoint/target/ -/websocket/endpoint-async/target/ -/jaxrs/endpoint/target/ -/jaxrs/client/target/ -/jsf/server-extension/target/ -/jaxrs/jaxrs-endpoint/target/ -/jaxrs/jaxrs-client/target/ -/jsf/http-get/target/ -/websocket/endpoint-javatypes/target/ -/websocket/endpoint-config/target/ -/websocket/endpoint-programmatic/target/ -/websocket/endpoint-programmatic-async/target/ -/websocket/endpoint-programmatic-config/target/ -/websocket/endpoint-programmatic-injection/target/ -/websocket/endpoint-security/target/ -/websocket/httpsession/target/ -/websocket/injection/target/ -/websocket/messagesize/target/ -/websocket/parameters/target/ -/websocket/websocket-vs-rest/target/ -/websocket/subprotocol/target/ -/websocket/websocket-client/target/ -/websocket/websocket-client-config/target/ -/websocket/websocket-client-programmatic/target/ -/websocket/websocket-client-programmatic-config/target/ -/websocket/websocket-client-programmatic-encoders/target/ -/websocket/javase-client/target/ -/ejb/stateful/target/ -/jpa/pu-typesafe/target/ -/jpa/criteria/target/ -/jta/transactional/target/ -/jta/transaction-scope/target/ -/jta/tx-exception/target/ -/ejb/stateless/target/ -/servlet/cookies/target/ -/jpa/schema-gen-scripts/target/ -/jta/user-transaction/target/ -/ejb/singleton/target/ -/ejb/lifecycle/singleton/target/ -/servlet/async-servlet/target/ -/jms/send-receive-simple/target/ -/jms/send-receive/target/ -/servlet/error-mapping/target/ -/servlet/event-listeners/target/ -/servlet/metadata-complete/target/ -/servlet/nonblocking/target/ -/servlet/resource-packaging/target/ -/servlet/servlet-filters/target/ -/servlet/web-fragment/target/ -/servlet/servlet-security/target/ -/jsf/flows-simple/target/ -/jsf/flows-mixed/target/ -/jaxrs/client-negotiation/target/ -/jpa/schema-gen-scripts-generate/target/ -/jaxrs/readerwriter-injection/target/ -/jsf/flows-programmatic/target/ -/jsf/flows-declarative/target/ -/javamail/definition/target/ -/jta/transactional-scope/target/ -/cdi/extension-impl/target/ -/cdi/extension/target/ -/batch/chunk-csv-database/target/ -/batch/chunk-optional-processor/target/ -/batch/chunk-partition/target/ -/jpa/listeners/target/ -/jpa/multiple-pu/target/ -/json/twitter-search/target/ -/jsf/radio-buttons/target/ -/jsf/viewscoped/target/ -/ejb/lifecycle/target/ -/jpa/schema-gen/target/ -/jpa/storedprocedure/target/ -/jsf/contracts/target/ -/jsf/contracts-library/target/ -/jsf/file-upload/target/ -/extra/quartz/target/ -/extra/twitter-search/target/ -/concurrency/managedexecutor/target/ -/concurrency/managedscheduledexecutor/target/ -/concurrency/manageablethread/target/ -/batch/chunk-simple/target/ \ No newline at end of file +# Directories # +/build/ +/bin/ +target/ +libs/ + +# OS Files # +.DS_Store + +*.class + +# Package Files # +*.jar +*.war +*.ear +*.db +rebel.xml + +###################### +# Windows +###################### + +# Windows image file caches +Thumbs.db + +# Folder config file +Desktop.ini + +###################### +# OSX +###################### + +.DS_Store +.svn + +# Thumbnails +._* + +# Files that might appear on external disk +.Spotlight-V100 +.Trashes + +###################### +# IDEA +###################### +*.iml + +###################### +# Eclipse +###################### + +*.pydevproject +.project +.metadata +bin/** +tmp/** +tmp/**/* +*.tmp +*.bak +*.swp +*~.nib +local.properties +.classpath +.settings/ +.loadpath +/src/main/resources/rebel.xml +# External tool builders +.externalToolBuilders/ + +# Locally stored "Eclipse launch configurations" +*.launch + +# CDT-specific +.cproject + +# PDT-specific +.buildpath \ No newline at end of file diff --git a/pom.xml b/pom.xml index 72dd86b90..0bda70765 100644 --- a/pom.xml +++ b/pom.xml @@ -266,12 +266,21 @@
javadocs + javadocs + org.apache.maven.plugins maven-dependency-plugin - 2.8 + 2.4 sources From d85165f994535b37466b5521fc8c691ecc5523ab Mon Sep 17 00:00:00 2001 From: Heiko Scherrer Date: Mon, 7 Oct 2013 19:49:17 +0200 Subject: [PATCH 030/934] Added maven-enforcer-plugin to take care of Maven in version 3.x and Java 1.7, to avoid clashes on developer environment --- pom.xml | 58 ++++++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 49 insertions(+), 9 deletions(-) diff --git a/pom.xml b/pom.xml index 0bda70765..44267415d 100644 --- a/pom.xml +++ b/pom.xml @@ -1,5 +1,5 @@ + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 org.javaee7 @@ -9,6 +9,8 @@ Java EE 7 Samples + 1.7 + 3.0.0 glassfish4x /Users/arungup/tools/glassfish/4.0/final/glassfish4 wildfly8x @@ -17,8 +19,11 @@ weblogic12x /Users/arungup/tools/weblogic/12c/wlserver gfv3ee6 + + + 1.3.1 - + javax @@ -33,7 +38,7 @@ provided - + codehaus-snapshots @@ -70,8 +75,8 @@ maven-compiler-plugin 2.3.2 - 1.7 - 1.7 + ${java.min.version} + ${java.min.version} @@ -111,9 +116,36 @@ + + maven-enforcer-plugin + + + + At least Maven in version ${maven.min.version} is required. + ${maven.min.version} + + + At least a JDK in version ${java.min.version} is required. + ${java.min.version} + + + + + enforce + + + + + + org.apache.maven.plugins + maven-enforcer-plugin + ${plugin.enforcer.version} + + + - + glassfish @@ -165,14 +197,14 @@ 8080 8181 - + org.glassfish.main.common simple-glassfish-api 4.0 - + org.glassfish.main.extras glassfish-embedded-all @@ -266,7 +298,11 @@ javadocs - javadocs + + + javadocs + + + + \ No newline at end of file diff --git a/extra/nosql/voldemort/src/main/webapp/WEB-INF/template.xhtml b/extra/nosql/voldemort/src/main/webapp/WEB-INF/template.xhtml new file mode 100644 index 000000000..31d2e3aeb --- /dev/null +++ b/extra/nosql/voldemort/src/main/webapp/WEB-INF/template.xhtml @@ -0,0 +1,26 @@ + + + + + + + + + Voldemort using Java EE 7 + + + + +
+

Voldemort using Java EE 7

+
+ +
+ Content +
+ +
+ + diff --git a/extra/nosql/voldemort/src/main/webapp/WEB-INF/web.xml b/extra/nosql/voldemort/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 000000000..c5e7c7381 --- /dev/null +++ b/extra/nosql/voldemort/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/voldemort/src/main/webapp/index.xhtml b/extra/nosql/voldemort/src/main/webapp/index.xhtml new file mode 100644 index 000000000..457c3dba9 --- /dev/null +++ b/extra/nosql/voldemort/src/main/webapp/index.xhtml @@ -0,0 +1,29 @@ + + + + + + + + + + + Name:
+ Age:

+ +
+
+ +
+ +
+ + + diff --git a/extra/nosql/voldemort/src/main/webapp/resources/css/cssLayout.css b/extra/nosql/voldemort/src/main/webapp/resources/css/cssLayout.css new file mode 100644 index 000000000..8ee7cebe3 --- /dev/null +++ b/extra/nosql/voldemort/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/voldemort/src/main/webapp/resources/css/default.css b/extra/nosql/voldemort/src/main/webapp/resources/css/default.css new file mode 100644 index 000000000..6cbc3d18e --- /dev/null +++ b/extra/nosql/voldemort/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/voldemort/src/main/webapp/show.xhtml b/extra/nosql/voldemort/src/main/webapp/show.xhtml new file mode 100644 index 000000000..8f1d60f31 --- /dev/null +++ b/extra/nosql/voldemort/src/main/webapp/show.xhtml @@ -0,0 +1,27 @@ + + + + + + + + + + + Name#{p.name} + Age#{p.age} + +

+ + + + +
+ +
+ + + From 3a36540c684f577daa89c3e32d798dcf0cb0f267 Mon Sep 17 00:00:00 2001 From: Arun Gupta Date: Mon, 7 Oct 2013 17:32:55 -0700 Subject: [PATCH 034/934] Starting work on Alternatives sample --- cdi/alternatives/pom.xml | 15 +++ .../org/javaee7/cdi/alternatives/Fancy.java | 58 ++++++++ .../cdi/alternatives/FancyGreeting.java | 56 ++++++++ .../javaee7/cdi/alternatives/Greeting.java | 47 +++++++ .../cdi/alternatives/SimpleGreeting.java | 55 ++++++++ .../javaee7/cdi/alternatives/TestServlet.java | 127 ++++++++++++++++++ .../src/main/webapp/WEB-INF/beans.xml | 52 +++++++ cdi/alternatives/src/main/webapp/index.jsp | 55 ++++++++ 8 files changed, 465 insertions(+) create mode 100644 cdi/alternatives/pom.xml create mode 100644 cdi/alternatives/src/main/java/org/javaee7/cdi/alternatives/Fancy.java create mode 100644 cdi/alternatives/src/main/java/org/javaee7/cdi/alternatives/FancyGreeting.java create mode 100644 cdi/alternatives/src/main/java/org/javaee7/cdi/alternatives/Greeting.java create mode 100644 cdi/alternatives/src/main/java/org/javaee7/cdi/alternatives/SimpleGreeting.java create mode 100644 cdi/alternatives/src/main/java/org/javaee7/cdi/alternatives/TestServlet.java create mode 100644 cdi/alternatives/src/main/webapp/WEB-INF/beans.xml create mode 100644 cdi/alternatives/src/main/webapp/index.jsp diff --git a/cdi/alternatives/pom.xml b/cdi/alternatives/pom.xml new file mode 100644 index 000000000..6f1fcf381 --- /dev/null +++ b/cdi/alternatives/pom.xml @@ -0,0 +1,15 @@ + + + 4.0.0 + + org.javaee7.cdi + cdi-samples + 1.0-SNAPSHOT + ../pom.xml + + + org.javaee7.cdi + alternatives + 1.0-SNAPSHOT + war + diff --git a/cdi/alternatives/src/main/java/org/javaee7/cdi/alternatives/Fancy.java b/cdi/alternatives/src/main/java/org/javaee7/cdi/alternatives/Fancy.java new file mode 100644 index 000000000..a30c0f6d3 --- /dev/null +++ b/cdi/alternatives/src/main/java/org/javaee7/cdi/alternatives/Fancy.java @@ -0,0 +1,58 @@ +/* + * 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.cdi.alternatives; + +import static java.lang.annotation.ElementType.TYPE; +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.PARAMETER; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.RetentionPolicy.RUNTIME; +import java.lang.annotation.Retention; +import java.lang.annotation.Target; +import javax.inject.Qualifier; + +/** + * @author Arun Gupta + */ +@Qualifier +@Retention(RUNTIME) +@Target({METHOD, FIELD, PARAMETER, TYPE}) +public @interface Fancy { +} diff --git a/cdi/alternatives/src/main/java/org/javaee7/cdi/alternatives/FancyGreeting.java b/cdi/alternatives/src/main/java/org/javaee7/cdi/alternatives/FancyGreeting.java new file mode 100644 index 000000000..c08874349 --- /dev/null +++ b/cdi/alternatives/src/main/java/org/javaee7/cdi/alternatives/FancyGreeting.java @@ -0,0 +1,56 @@ +/* + * 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.cdi.alternatives; + +import javax.enterprise.inject.Alternative; + +/** + * @author Arun Gupta + */ +@Fancy +@Alternative +public class FancyGreeting implements Greeting { + + @Override + public String greet(String name) { + return "Nice to meet you, hello" + name; + } + +} diff --git a/cdi/alternatives/src/main/java/org/javaee7/cdi/alternatives/Greeting.java b/cdi/alternatives/src/main/java/org/javaee7/cdi/alternatives/Greeting.java new file mode 100644 index 000000000..7c65d641f --- /dev/null +++ b/cdi/alternatives/src/main/java/org/javaee7/cdi/alternatives/Greeting.java @@ -0,0 +1,47 @@ +/* + * 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.cdi.alternatives; + +/** + * @author Arun Gupta + */ +public interface Greeting { + public String greet(String name); +} diff --git a/cdi/alternatives/src/main/java/org/javaee7/cdi/alternatives/SimpleGreeting.java b/cdi/alternatives/src/main/java/org/javaee7/cdi/alternatives/SimpleGreeting.java new file mode 100644 index 000000000..9ea9b18ea --- /dev/null +++ b/cdi/alternatives/src/main/java/org/javaee7/cdi/alternatives/SimpleGreeting.java @@ -0,0 +1,55 @@ +/* + * 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.cdi.alternatives; + +import javax.enterprise.inject.Alternative; + +/** + * @author Arun Gupta + */ +@Alternative +public class SimpleGreeting implements Greeting { + + @Override + public String greet(String name) { + return "Hello " + name; + } + +} diff --git a/cdi/alternatives/src/main/java/org/javaee7/cdi/alternatives/TestServlet.java b/cdi/alternatives/src/main/java/org/javaee7/cdi/alternatives/TestServlet.java new file mode 100644 index 000000000..821fb7fec --- /dev/null +++ b/cdi/alternatives/src/main/java/org/javaee7/cdi/alternatives/TestServlet.java @@ -0,0 +1,127 @@ +/* + * 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.cdi.alternatives; + +import java.io.IOException; +import java.io.PrintWriter; +import javax.inject.Inject; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +/** + * @author Arun Gupta + */ +@WebServlet(urlPatterns = {"/TestServlet"}) +public class TestServlet extends HttpServlet { + + @Inject Greeting greeting; + + /** + * Processes requests for both HTTP + * GET and + * POST methods. + * + * @param request servlet request + * @param response servlet response + * @throws ServletException if a servlet-specific error occurs + * @throws IOException if an I/O error occurs + */ + protected void processRequest(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + response.setContentType("text/html;charset=UTF-8"); + try (PrintWriter out = response.getWriter()) { + out.println(""); + out.println(""); + out.println(""); + out.println("CDI Interceptors"); + out.println(""); + out.println(""); + out.println("

CDI Interceptors

"); + out.println(greeting.greet("Duke")); + out.println("

Look for output in \"server.log\"."); + out.println(""); + out.println(""); + } + } + + // + /** + * Handles the HTTP + * GET method. + * + * @param request servlet request + * @param response servlet response + * @throws ServletException if a servlet-specific error occurs + * @throws IOException if an I/O error occurs + */ + @Override + protected void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + processRequest(request, response); + } + + /** + * Handles the HTTP + * POST method. + * + * @param request servlet request + * @param response servlet response + * @throws ServletException if a servlet-specific error occurs + * @throws IOException if an I/O error occurs + */ + @Override + protected void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + processRequest(request, response); + } + + /** + * Returns a short description of the servlet. + * + * @return a String containing servlet description + */ + @Override + public String getServletInfo() { + return "Short description"; + }// +} diff --git a/cdi/alternatives/src/main/webapp/WEB-INF/beans.xml b/cdi/alternatives/src/main/webapp/WEB-INF/beans.xml new file mode 100644 index 000000000..ea66c22d0 --- /dev/null +++ b/cdi/alternatives/src/main/webapp/WEB-INF/beans.xml @@ -0,0 +1,52 @@ + + + + + org.javaee7.cdi.alternatives.FancyGreeting + + diff --git a/cdi/alternatives/src/main/webapp/index.jsp b/cdi/alternatives/src/main/webapp/index.jsp new file mode 100644 index 000000000..fc02ee19d --- /dev/null +++ b/cdi/alternatives/src/main/webapp/index.jsp @@ -0,0 +1,55 @@ + +<%@page contentType="text/html" pageEncoding="UTF-8"%> + + + + + + CDI : Alternatives + + +

CDI : Alternatives

+ Invoke the client. + + From 8be988cfce0bc882b0caaea6bc4b22b9c9025937 Mon Sep 17 00:00:00 2001 From: Arun Gupta Date: Tue, 8 Oct 2013 14:41:19 -0700 Subject: [PATCH 035/934] Adding alternatives module --- cdi/pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/cdi/pom.xml b/cdi/pom.xml index bf10b1f41..6d9a4bd77 100644 --- a/cdi/pom.xml +++ b/cdi/pom.xml @@ -29,5 +29,6 @@ beanmanager extension scopes + alternatives From b327f697479562fa3572071b0ead1df7e5fefe8a Mon Sep 17 00:00:00 2001 From: Arun Gupta Date: Tue, 8 Oct 2013 16:57:25 -0700 Subject: [PATCH 036/934] Adding riak module --- extra/nosql/pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/extra/nosql/pom.xml b/extra/nosql/pom.xml index cc3b0bd64..4c3088fa7 100644 --- a/extra/nosql/pom.xml +++ b/extra/nosql/pom.xml @@ -22,5 +22,6 @@ neo4j hbase voldemort + riak From aa2b1a46d499fee4635f89c845329a367aed7b53 Mon Sep 17 00:00:00 2001 From: Arun Gupta Date: Tue, 8 Oct 2013 16:57:34 -0700 Subject: [PATCH 037/934] Adding Riak module --- extra/nosql/riak/pom.xml | 30 +++++ .../org/javaee7/extra/nosql/riak/Person.java | 95 +++++++++++++++ .../extra/nosql/riak/PersonSessionBean.java | 109 ++++++++++++++++++ .../riak/src/main/webapp/WEB-INF/beans.xml | 49 ++++++++ .../src/main/webapp/WEB-INF/template.xhtml | 26 +++++ .../riak/src/main/webapp/WEB-INF/web.xml | 24 ++++ extra/nosql/riak/src/main/webapp/index.xhtml | 49 ++++++++ .../main/webapp/resources/css/cssLayout.css | 61 ++++++++++ .../src/main/webapp/resources/css/default.css | 29 +++++ extra/nosql/riak/src/main/webapp/show.xhtml | 27 +++++ 10 files changed, 499 insertions(+) create mode 100644 extra/nosql/riak/pom.xml create mode 100644 extra/nosql/riak/src/main/java/org/javaee7/extra/nosql/riak/Person.java create mode 100644 extra/nosql/riak/src/main/java/org/javaee7/extra/nosql/riak/PersonSessionBean.java create mode 100644 extra/nosql/riak/src/main/webapp/WEB-INF/beans.xml create mode 100644 extra/nosql/riak/src/main/webapp/WEB-INF/template.xhtml create mode 100644 extra/nosql/riak/src/main/webapp/WEB-INF/web.xml create mode 100644 extra/nosql/riak/src/main/webapp/index.xhtml create mode 100644 extra/nosql/riak/src/main/webapp/resources/css/cssLayout.css create mode 100644 extra/nosql/riak/src/main/webapp/resources/css/default.css create mode 100644 extra/nosql/riak/src/main/webapp/show.xhtml diff --git a/extra/nosql/riak/pom.xml b/extra/nosql/riak/pom.xml new file mode 100644 index 000000000..73eb681e1 --- /dev/null +++ b/extra/nosql/riak/pom.xml @@ -0,0 +1,30 @@ + + + 4.0.0 + + org.javaee7.extra.nosql + extra-nosql-samples + 1.0-SNAPSHOT + ../pom.xml + + + org.javaee7.extra.nosql + riak + 1.0-SNAPSHOT + war + + + + voldemort-repo + http://repo.springsource.org/plugins-release/ + + + + + + com.basho.riak + riak-client + 1.4.1 + + + diff --git a/extra/nosql/riak/src/main/java/org/javaee7/extra/nosql/riak/Person.java b/extra/nosql/riak/src/main/java/org/javaee7/extra/nosql/riak/Person.java new file mode 100644 index 000000000..154f2a246 --- /dev/null +++ b/extra/nosql/riak/src/main/java/org/javaee7/extra/nosql/riak/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.riak; + +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/riak/src/main/java/org/javaee7/extra/nosql/riak/PersonSessionBean.java b/extra/nosql/riak/src/main/java/org/javaee7/extra/nosql/riak/PersonSessionBean.java new file mode 100644 index 000000000..85d04d6ad --- /dev/null +++ b/extra/nosql/riak/src/main/java/org/javaee7/extra/nosql/riak/PersonSessionBean.java @@ -0,0 +1,109 @@ +/* + * 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.riak; + +import com.basho.riak.client.IRiakClient; +import com.basho.riak.client.RiakException; +import com.basho.riak.client.RiakFactory; +import com.basho.riak.client.RiakRetryFailedException; +import com.basho.riak.client.bucket.Bucket; +import com.basho.riak.client.cap.UnresolvedConflictException; +import com.basho.riak.client.convert.ConversionException; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.logging.Level; +import java.util.logging.Logger; +import javax.annotation.PostConstruct; +import javax.annotation.PreDestroy; +import javax.inject.Inject; +import javax.inject.Named; +import javax.inject.Singleton; + +/** + * @author Arun Gupta + */ +@Named +@Singleton +public class PersonSessionBean { + + @Inject + Person person; + + Set set = new HashSet<>(); + Bucket myBucket; + + @PostConstruct + private void initDB() { + try { + IRiakClient client = RiakFactory.pbcClient("localhost", 8087); + myBucket = client.fetchBucket("test").execute(); + } catch (RiakException ex) { + Logger.getLogger(PersonSessionBean.class.getName()).log(Level.SEVERE, null, ex); + } + } + + @PreDestroy + private void stopDB() { + } + + public void createPerson() { + try { + myBucket.store(person.getName(), new Person(person.getName(), person.getAge())).execute(); + set.add(person.getName()); + } catch (RiakRetryFailedException | UnresolvedConflictException | ConversionException ex) { + Logger.getLogger(PersonSessionBean.class.getName()).log(Level.SEVERE, null, ex); + } + } + + public List getPersons() { + List persons = new ArrayList(); + for (String key : set) { + try { + Person p = myBucket.fetch(key, Person.class).execute(); + persons.add(p); + } catch (UnresolvedConflictException | RiakRetryFailedException | ConversionException ex) { + Logger.getLogger(PersonSessionBean.class.getName()).log(Level.SEVERE, null, ex); + } + } + return persons; + } +} diff --git a/extra/nosql/riak/src/main/webapp/WEB-INF/beans.xml b/extra/nosql/riak/src/main/webapp/WEB-INF/beans.xml new file mode 100644 index 000000000..aa81c7c3c --- /dev/null +++ b/extra/nosql/riak/src/main/webapp/WEB-INF/beans.xml @@ -0,0 +1,49 @@ + + + + \ No newline at end of file diff --git a/extra/nosql/riak/src/main/webapp/WEB-INF/template.xhtml b/extra/nosql/riak/src/main/webapp/WEB-INF/template.xhtml new file mode 100644 index 000000000..730271b63 --- /dev/null +++ b/extra/nosql/riak/src/main/webapp/WEB-INF/template.xhtml @@ -0,0 +1,26 @@ + + + + + + + + + Riak using Java EE 7 + + + + +
+

Riak using Java EE 7

+
+ +
+ Content +
+ +
+ + diff --git a/extra/nosql/riak/src/main/webapp/WEB-INF/web.xml b/extra/nosql/riak/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 000000000..c5e7c7381 --- /dev/null +++ b/extra/nosql/riak/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/riak/src/main/webapp/index.xhtml b/extra/nosql/riak/src/main/webapp/index.xhtml new file mode 100644 index 000000000..b05d3200a --- /dev/null +++ b/extra/nosql/riak/src/main/webapp/index.xhtml @@ -0,0 +1,49 @@ + + + + + + + + + + + Name:
+ Age:

+ +
+
+ + +
    Build from source (more details) +
  • Install Erlang (more details)
  • +
      +
    • curl -O http://erlang.org/download/otp_src_R15B01.tar.gz
    • +
    • tar zxvf otp_src_R15B01.tar.gz
    • +
    • cd otp_src_R15B01
    • +
    • export CFLAGS=-O0
    • +
    • ./configure --disable-hipe --enable-smp-support --enable-threads --enable-kernel-poll --enable-darwin-64bit
    • +
    • unset CFLAGS
    • +
    • make
    • +
    • make install
    • +
    +
  • wget http://s3.amazonaws.com/downloads.basho.com/riak/1.4/1.4.2/riak-1.4.2.tar.gz
  • +
  • tar zxvf riak-1.4.2.tar.gz
  • +
  • cd riak-1.4.2
  • +
  • make rel
  • +
  • cd rel/riak
  • +
  • ./bin/riak start
  • +
  • ./bin/riak ping (to verify)
  • +
+
+ +
+ + + diff --git a/extra/nosql/riak/src/main/webapp/resources/css/cssLayout.css b/extra/nosql/riak/src/main/webapp/resources/css/cssLayout.css new file mode 100644 index 000000000..8ee7cebe3 --- /dev/null +++ b/extra/nosql/riak/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/riak/src/main/webapp/resources/css/default.css b/extra/nosql/riak/src/main/webapp/resources/css/default.css new file mode 100644 index 000000000..6cbc3d18e --- /dev/null +++ b/extra/nosql/riak/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/riak/src/main/webapp/show.xhtml b/extra/nosql/riak/src/main/webapp/show.xhtml new file mode 100644 index 000000000..8f1d60f31 --- /dev/null +++ b/extra/nosql/riak/src/main/webapp/show.xhtml @@ -0,0 +1,27 @@ + + + + + + + + + + + Name#{p.name} + Age#{p.age} + +

+ + + + +
+ +
+ + + From 2d3edb86f95c0154885ac673e01e25f9c15c93ef Mon Sep 17 00:00:00 2001 From: Arun Gupta Date: Thu, 10 Oct 2013 14:04:06 -0700 Subject: [PATCH 038/934] 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 039/934] 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 @@