You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@aries.apache.org by ti...@apache.org on 2011/09/16 18:32:50 UTC
svn commit: r1171650 - in /aries/trunk/samples/blog: ./ blog-comment-ejb/
blog-comment-ejb/src/ blog-comment-ejb/src/main/
blog-comment-ejb/src/main/java/ blog-comment-ejb/src/main/java/org/
blog-comment-ejb/src/main/java/org/apache/ blog-comment-ejb/s...
Author: timothyjward
Date: Fri Sep 16 16:32:49 2011
New Revision: 1171650
URL: http://svn.apache.org/viewvc?rev=1171650&view=rev
Log:
ARIES-747: Add EJB commenting service to the blog sample
Added:
aries/trunk/samples/blog/blog-comment-ejb/
aries/trunk/samples/blog/blog-comment-ejb/pom.xml
aries/trunk/samples/blog/blog-comment-ejb/src/
aries/trunk/samples/blog/blog-comment-ejb/src/main/
aries/trunk/samples/blog/blog-comment-ejb/src/main/java/
aries/trunk/samples/blog/blog-comment-ejb/src/main/java/org/
aries/trunk/samples/blog/blog-comment-ejb/src/main/java/org/apache/
aries/trunk/samples/blog/blog-comment-ejb/src/main/java/org/apache/aries/
aries/trunk/samples/blog/blog-comment-ejb/src/main/java/org/apache/aries/samples/
aries/trunk/samples/blog/blog-comment-ejb/src/main/java/org/apache/aries/samples/blog/
aries/trunk/samples/blog/blog-comment-ejb/src/main/java/org/apache/aries/samples/blog/comment/
aries/trunk/samples/blog/blog-comment-ejb/src/main/java/org/apache/aries/samples/blog/comment/ejb/
aries/trunk/samples/blog/blog-comment-ejb/src/main/java/org/apache/aries/samples/blog/comment/ejb/BlogCommentEJB.java
aries/trunk/samples/blog/blog-comment-ejb/src/main/java/org/apache/aries/samples/blog/comment/ejb/CommentImpl.java
aries/trunk/samples/blog/blog-comment-ejb/src/main/resources/
aries/trunk/samples/blog/blog-comment-ejb/src/main/resources/META-INF/
aries/trunk/samples/blog/blog-comment-ejb/src/main/resources/META-INF/persistence.xml
Modified:
aries/trunk/samples/blog/pom.xml
Added: aries/trunk/samples/blog/blog-comment-ejb/pom.xml
URL: http://svn.apache.org/viewvc/aries/trunk/samples/blog/blog-comment-ejb/pom.xml?rev=1171650&view=auto
==============================================================================
--- aries/trunk/samples/blog/blog-comment-ejb/pom.xml (added)
+++ aries/trunk/samples/blog/blog-comment-ejb/pom.xml Fri Sep 16 16:32:49 2011
@@ -0,0 +1,129 @@
+<?xml version="1.0" encoding="UTF-8"?>
+ <!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version
+ 2.0 (the "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0 Unless required by
+ applicable law or agreed to in writing, software distributed under the
+ License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
+ CONDITIONS OF ANY KIND, either express or implied. See the License for
+ the specific language governing permissions and limitations under the
+ License.
+ -->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.aries.samples.blog</groupId>
+ <artifactId>blog</artifactId>
+ <version>0.3.1-SNAPSHOT</version>
+ </parent>
+
+ <groupId>org.apache.aries.samples.blog</groupId>
+ <artifactId>org.apache.aries.samples.blog.comment.ejb</artifactId>
+ <name>Apache Aries blog sample commenting EJB</name>
+ <packaging>bundle</packaging>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <configuration>
+ <instructions>
+ <Export-EJB>Commenting</Export-EJB>
+ <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
+ <Private-Package>org.apache.aries.samples.blog.comment.*</Private-Package>
+ <Export-Package>!org.apache.aries.samples.blog.comment.*</Export-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-antrun-plugin</artifactId>
+ <executions>
+ <execution>
+ <phase>compile</phase>
+ <configuration>
+ <tasks>
+ <path id="enhance.path.ref">
+ <fileset dir="${project.build.outputDirectory}">
+ <include name="CommentImpl.class" />
+ </fileset>
+ </path>
+ <pathconvert property="enhance.files" refid="enhance.path.ref" pathsep=" " />
+ <java classname="org.apache.openjpa.enhance.PCEnhancer">
+ <arg line="-p persistence.xml" />
+ <arg line="${enhance.files}" />
+ <classpath>
+ <path refid="maven.dependency.classpath" />
+ <path refid="maven.compile.classpath" />
+ </classpath>
+ </java>
+ </tasks>
+ </configuration>
+ <goals>
+ <goal>run</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+
+ </plugins>
+ </build>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.aries.samples.blog</groupId>
+ <artifactId>org.apache.aries.samples.blog.api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.derby</groupId>
+ <artifactId>derby</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.geronimo.specs</groupId>
+ <artifactId>geronimo-jpa_2.0_spec</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.geronimo.specs</groupId>
+ <artifactId>geronimo-jta_1.1_spec</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.geronimo.specs</groupId>
+ <artifactId>geronimo-ejb_3.1_spec</artifactId>
+ <version>1.0.2</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.openjpa</groupId>
+ <artifactId>openjpa</artifactId>
+ </dependency>
+
+
+ <!-- OpenJPA PCEnhancer depends -->
+ <dependency>
+ <groupId>net.sourceforge.serp</groupId>
+ <artifactId>serp</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>commons-lang</groupId>
+ <artifactId>commons-lang</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>commons-collections</groupId>
+ <artifactId>commons-collections</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <!-- end OpenJPA PCEnhancer depends -->
+
+ </dependencies>
+
+</project>
Added: aries/trunk/samples/blog/blog-comment-ejb/src/main/java/org/apache/aries/samples/blog/comment/ejb/BlogCommentEJB.java
URL: http://svn.apache.org/viewvc/aries/trunk/samples/blog/blog-comment-ejb/src/main/java/org/apache/aries/samples/blog/comment/ejb/BlogCommentEJB.java?rev=1171650&view=auto
==============================================================================
--- aries/trunk/samples/blog/blog-comment-ejb/src/main/java/org/apache/aries/samples/blog/comment/ejb/BlogCommentEJB.java (added)
+++ aries/trunk/samples/blog/blog-comment-ejb/src/main/java/org/apache/aries/samples/blog/comment/ejb/BlogCommentEJB.java Fri Sep 16 16:32:49 2011
@@ -0,0 +1,69 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.aries.samples.blog.comment.ejb;
+
+import java.util.List;
+
+import javax.ejb.Stateless;
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContext;
+import javax.persistence.TypedQuery;
+
+import org.apache.aries.samples.blog.api.comment.persistence.BlogCommentService;
+import org.apache.aries.samples.blog.api.comment.persistence.Comment;
+
+@Stateless(name="Commenting")
+public class BlogCommentEJB implements BlogCommentService {
+
+ @PersistenceContext(unitName="blogComments")
+ private EntityManager commentEM;
+
+ public void createComment(String comment, String author, long entryId) {
+
+ commentEM.persist(new CommentImpl(comment, author, entryId));
+ }
+
+ public void delete(int id) {
+
+ CommentImpl c = commentEM.find(CommentImpl.class, id);
+
+ if(c != null)
+ commentEM.remove(c);
+ }
+
+
+ public List<? extends Comment> getCommentsForAuthor(String authorId) {
+
+ TypedQuery<CommentImpl> q = commentEM.createQuery(
+ "SELECT c FROM Comment c WHERE c.authorId = :authorId", CommentImpl.class);
+
+ q.setParameter("authorId", authorId);
+
+ return q.getResultList();
+ }
+
+ public List<? extends Comment> getCommentsForEntry(long entryId) {
+
+ TypedQuery<CommentImpl> q = commentEM.createQuery(
+ "SELECT c FROM Comment c WHERE c.entryId = :entryId", CommentImpl.class);
+ q.setParameter("entryId", entryId);
+
+ return q.getResultList();
+ }
+}
Added: aries/trunk/samples/blog/blog-comment-ejb/src/main/java/org/apache/aries/samples/blog/comment/ejb/CommentImpl.java
URL: http://svn.apache.org/viewvc/aries/trunk/samples/blog/blog-comment-ejb/src/main/java/org/apache/aries/samples/blog/comment/ejb/CommentImpl.java?rev=1171650&view=auto
==============================================================================
--- aries/trunk/samples/blog/blog-comment-ejb/src/main/java/org/apache/aries/samples/blog/comment/ejb/CommentImpl.java (added)
+++ aries/trunk/samples/blog/blog-comment-ejb/src/main/java/org/apache/aries/samples/blog/comment/ejb/CommentImpl.java Fri Sep 16 16:32:49 2011
@@ -0,0 +1,120 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.aries.samples.blog.comment.ejb;
+
+import java.util.Date;
+
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.Temporal;
+import javax.persistence.TemporalType;
+
+import org.apache.aries.samples.blog.api.comment.persistence.Comment;
+import org.apache.aries.samples.blog.api.persistence.Author;
+import org.apache.aries.samples.blog.api.persistence.BlogPersistenceService;
+import org.apache.aries.samples.blog.api.persistence.Entry;
+
+@Entity(name="Comment")
+public class CommentImpl implements Comment{
+
+ @Id
+ @GeneratedValue
+ private int id;
+
+ private String comment;
+
+ @Temporal(TemporalType.TIMESTAMP)
+ private Date creationDate;
+
+ //Details for author
+ private String authorId;
+
+ //Details for entry
+ private long entryId;
+
+ public CommentImpl(String comment, String authorId, long entryId) {
+ this.comment = comment;
+ this.authorId = authorId;
+ this.entryId = entryId;
+ this.creationDate = new Date();
+ }
+
+ public String getComment() {
+ return comment;
+ }
+
+ public Date getCreationDate() {
+ return creationDate;
+ }
+
+ public int getId() {
+ return id;
+ }
+
+ public Author getAuthor() {
+ try {
+ BlogPersistenceService bps = (BlogPersistenceService) new InitialContext().lookup(
+ "osgi:service/" + BlogPersistenceService.class.getName());
+ return bps.getAuthor(authorId);
+ } catch (NamingException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public Entry getEntry() {
+ try {
+ BlogPersistenceService bps = (BlogPersistenceService) new InitialContext().lookup(
+ "osgi:service/" + BlogPersistenceService.class.getName());
+ return bps.getBlogEntryById(entryId);
+ } catch (NamingException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public String getAuthorId() {
+ return authorId;
+ }
+
+ public void setAuthorId(String authorId) {
+ this.authorId = authorId;
+ }
+
+ public long getEntryId() {
+ return entryId;
+ }
+
+ public void setEntryId(long entryId) {
+ this.entryId = entryId;
+ }
+
+ public void setId(int id) {
+ this.id = id;
+ }
+
+ public void setComment(String comment) {
+ this.comment = comment;
+ }
+
+ public void setCreationDate(Date creationDate) {
+ this.creationDate = creationDate;
+ }
+}
Added: aries/trunk/samples/blog/blog-comment-ejb/src/main/resources/META-INF/persistence.xml
URL: http://svn.apache.org/viewvc/aries/trunk/samples/blog/blog-comment-ejb/src/main/resources/META-INF/persistence.xml?rev=1171650&view=auto
==============================================================================
--- aries/trunk/samples/blog/blog-comment-ejb/src/main/resources/META-INF/persistence.xml (added)
+++ aries/trunk/samples/blog/blog-comment-ejb/src/main/resources/META-INF/persistence.xml Fri Sep 16 16:32:49 2011
@@ -0,0 +1,39 @@
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<persistence xmlns="http://java.sun.com/xml/ns/persistence"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
+ version="1.0">
+
+ <persistence-unit name="blogComments" transaction-type="JTA">
+ <description>Persistence unit for the blog comment EJB</description>
+
+ <provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
+
+ <jta-data-source>osgi:service/jdbc/blogdb</jta-data-source>
+ <non-jta-data-source>osgi:service/jdbc/blogdbnojta</non-jta-data-source>
+
+ <properties>
+ <!-- These properties are creating the database on the fly. We are using them to avoid users having
+ to create a database to run the sample. This is not something that should be used in production.
+ See also the create=true line in the blog-datasource blueprint meta data -->
+ <property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema(ForeignKeys=true)"/>
+ <property name="openjpa.jdbc.DBDictionary" value="derby"/>
+ </properties>
+
+ </persistence-unit>
+</persistence>
Modified: aries/trunk/samples/blog/pom.xml
URL: http://svn.apache.org/viewvc/aries/trunk/samples/blog/pom.xml?rev=1171650&r1=1171649&r2=1171650&view=diff
==============================================================================
--- aries/trunk/samples/blog/pom.xml (original)
+++ aries/trunk/samples/blog/pom.xml Fri Sep 16 16:32:49 2011
@@ -92,6 +92,7 @@
<module>blog-persistence-jdbc</module>
<module>blog-persistence-jpa</module>
<module>blog-web</module>
+ <module>blog-comment-ejb</module>
<module>blog-itests</module>
</modules>