struts-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hus...@apache.org
Subject svn commit: r599476 - in /struts/sandbox/trunk/jpa-mailreader/src: main/java/ main/java/META-INF/ main/java/META-INF/xfire/ main/java/hello/ main/webapp/user/ test/java/hello/
Date Thu, 29 Nov 2007 15:15:52 GMT
Author: husted
Date: Thu Nov 29 07:15:50 2007
New Revision: 599476

URL: http://svn.apache.org/viewvc?rev=599476&view=rev
Log:
WW-1399 Add simple Hello package to demonstrate basic JPA CRUD. Remove XFire test configuration
for now. Would need to add a EntityFilter to do for Services what the EntityInterceptor does
for Actions (or use the filter for both). It would also need to observe A&A (once we add
A&A back in!). 

Added:
    struts/sandbox/trunk/jpa-mailreader/src/main/java/hello/
    struts/sandbox/trunk/jpa-mailreader/src/main/java/hello/Message.java
    struts/sandbox/trunk/jpa-mailreader/src/test/java/hello/
    struts/sandbox/trunk/jpa-mailreader/src/test/java/hello/MessageTest.java
Removed:
    struts/sandbox/trunk/jpa-mailreader/src/main/java/META-INF/xfire/
Modified:
    struts/sandbox/trunk/jpa-mailreader/src/main/java/META-INF/persistence.xml
    struts/sandbox/trunk/jpa-mailreader/src/main/java/log4j.properties
    struts/sandbox/trunk/jpa-mailreader/src/main/java/struts.xml
    struts/sandbox/trunk/jpa-mailreader/src/main/webapp/user/@form.jsp

Modified: struts/sandbox/trunk/jpa-mailreader/src/main/java/META-INF/persistence.xml
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/jpa-mailreader/src/main/java/META-INF/persistence.xml?rev=599476&r1=599475&r2=599476&view=diff
==============================================================================
--- struts/sandbox/trunk/jpa-mailreader/src/main/java/META-INF/persistence.xml (original)
+++ struts/sandbox/trunk/jpa-mailreader/src/main/java/META-INF/persistence.xml Thu Nov 29
07:15:50 2007
@@ -20,13 +20,10 @@
 -->
 
 	<persistence-unit name="entity" transaction-type="RESOURCE_LOCAL">
-		<provider>org.hibernate.ejb.HibernatePersistence</provider>
-        <class>entity.protocol.Protocol</class>
-        <class>entity.subscription.Subscription</class>
-        <class>entity.user.User</class>
+	    <provider>org.hibernate.ejb.HibernatePersistence</provider>
   		<properties>
 			<property name = "hibernate.connection.driver_class" value = "org.apache.derby.jdbc.ClientDriver"/>
-			<property name = "hibernate.connection.url" value = "jdbc:derby://localhost:1527/mailreader"/>
+			<property name = "hibernate.connection.url" value = "jdbc:derby://localhost:1527/mailreader;create=true"/>
 			<property name = "hibernate.connection.username" value = "app"/>
 			<property name = "hibernate.connection.password" value = "app"/>
   		    <property name = "hibernate.dialect" value="org.hibernate.dialect.DerbyDialect"/>

Added: struts/sandbox/trunk/jpa-mailreader/src/main/java/hello/Message.java
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/jpa-mailreader/src/main/java/hello/Message.java?rev=599476&view=auto
==============================================================================
--- struts/sandbox/trunk/jpa-mailreader/src/main/java/hello/Message.java (added)
+++ struts/sandbox/trunk/jpa-mailreader/src/main/java/hello/Message.java Thu Nov 29 07:15:50
2007
@@ -0,0 +1,53 @@
+package hello;
+
+import javax.persistence.CascadeType;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.NamedQueries;
+import javax.persistence.NamedQuery;
+import javax.persistence.OneToOne;
+
+import entity.user.User;
+
+@Entity(name = "APP_MESSAGE")
+@NamedQueries({
+        @NamedQuery(name = Message.COUNT, query = Message.COUNT_QUERY) })
+public class Message {
+
+    public static final String COUNT = "Message.COUNT";
+    private static final String COUNT_QUERY = "SELECT COUNT(*) FROM APP_MESSAGE";
+
+    @Id
+    @GeneratedValue
+    private Long id;
+    public Long getId() {
+        return id;
+    }
+    void setId(Long value) {
+        id = value;
+    }    
+    
+    private String text;
+    public String getText() {
+        return text;
+    }
+    public void setText(String value) {
+        text = value;
+    }
+
+    @OneToOne(cascade=CascadeType.ALL)
+    private Message message;    
+    public Message getNextMessage() {
+        return message;
+    }
+    public void setNextMessage(Message value) {
+        message = value;
+    }
+    
+    Message() {}
+    public Message(String value) {
+        text = value;
+    }
+    
+}
\ No newline at end of file

Modified: struts/sandbox/trunk/jpa-mailreader/src/main/java/log4j.properties
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/jpa-mailreader/src/main/java/log4j.properties?rev=599476&r1=599475&r2=599476&view=diff
==============================================================================
--- struts/sandbox/trunk/jpa-mailreader/src/main/java/log4j.properties (original)
+++ struts/sandbox/trunk/jpa-mailreader/src/main/java/log4j.properties Thu Nov 29 07:15:50
2007
@@ -1,9 +1,9 @@
 
-# -- production mode --
+# -- development mode --
 
-log4j.rootLogger = error, stdout
+log4j.rootLogger = info, stdout
 log4j.appender.stdout = org.apache.log4j.ConsoleAppender
-log4j.appender.stdout.Threshold = error
+log4j.appender.stdout.Threshold = info
 log4j.appender.stdout.Target = System.out
 log4j.appender.stdout.layout = org.apache.log4j.PatternLayout
 log4j.appender.stdout.layout.ConversionPattern = %d{ISO8601} %-5p [%F:%L] : %m%n

Modified: struts/sandbox/trunk/jpa-mailreader/src/main/java/struts.xml
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/jpa-mailreader/src/main/java/struts.xml?rev=599476&r1=599475&r2=599476&view=diff
==============================================================================
--- struts/sandbox/trunk/jpa-mailreader/src/main/java/struts.xml (original)
+++ struts/sandbox/trunk/jpa-mailreader/src/main/java/struts.xml Thu Nov 29 07:15:50 2007
@@ -7,6 +7,7 @@
 
     <constant name="struts.devMode" value="false" />
     <constant name="struts.action.extension" value="do" />
+    <constant name="struts.serve.static" value="true" />
     
     <package name="entity-default" extends="struts-default">
 		<interceptors>

Modified: struts/sandbox/trunk/jpa-mailreader/src/main/webapp/user/@form.jsp
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/jpa-mailreader/src/main/webapp/user/%40form.jsp?rev=599476&r1=599475&r2=599476&view=diff
==============================================================================
--- struts/sandbox/trunk/jpa-mailreader/src/main/webapp/user/@form.jsp (original)
+++ struts/sandbox/trunk/jpa-mailreader/src/main/webapp/user/@form.jsp Thu Nov 29 07:15:50
2007
@@ -23,6 +23,7 @@
     <s:if test="input == 'create'">
         <s:submit key="button.update" action="create" />     
         <s:submit key="button.cancel" action="create" method="cancel" onclick="form.onsubmit=null"/>
+        <s:submit action="create" >Label</s:submit>     
     </s:if>
     <s:else>
         <s:submit key="button.update" action="update"/>

Added: struts/sandbox/trunk/jpa-mailreader/src/test/java/hello/MessageTest.java
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/jpa-mailreader/src/test/java/hello/MessageTest.java?rev=599476&view=auto
==============================================================================
--- struts/sandbox/trunk/jpa-mailreader/src/test/java/hello/MessageTest.java (added)
+++ struts/sandbox/trunk/jpa-mailreader/src/test/java/hello/MessageTest.java Thu Nov 29 07:15:50
2007
@@ -0,0 +1,78 @@
+package hello;
+
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceException;
+import javax.persistence.Query;
+
+import entity.EntityManagerHelper;
+import entity.user.User;
+import junit.framework.TestCase;
+
+public class MessageTest extends TestCase {
+
+    protected EntityManager manager;
+
+    protected void setUp() throws Exception {
+        super.setUp();
+        manager = EntityManagerHelper.getEntityManager();
+        EntityManagerHelper.beginTransaction();        
+    }
+
+    protected void tearDown() throws Exception {
+        super.tearDown();
+        EntityManagerHelper.commit();
+        EntityManagerHelper.closeEntityManager();        
+    }    
+    
+    public int count() throws Exception {
+        final String COUNT_QUERY = "SELECT COUNT(*) FROM APP_MESSAGE";        
+        Query query = manager.createQuery(COUNT_QUERY);        
+        Long count = (Long) query.getSingleResult();
+        int result = count.intValue();
+        return result;
+    }    
+    
+    public void testMessage() throws Exception {
+        final String MESSAGE = "Hello World!";
+        
+        Message message = new Message(MESSAGE);
+        
+        String text = message.getText();
+        assertEquals(MESSAGE,text);
+        
+        manager.persist(message);
+    }
+    
+    public void testNextMessage() throws Exception {
+        final String MESSAGE = "Greeting Earthling!";
+        final String NEXT_MESSAGE = "Take me to your leader.";        
+
+        Message message = new Message(MESSAGE);
+        Message next_message = new Message(NEXT_MESSAGE);       
+        message.setNextMessage(next_message);
+        
+        String text = message.getText();
+        assertEquals(MESSAGE, text);
+        String next_text = message.getNextMessage().getText();
+        assertEquals(NEXT_MESSAGE, next_text);
+
+        int beginCount = count();
+            manager.persist(message);
+        int endCount = count();
+        assertTrue("Expected count to increase!",endCount>beginCount);
+    }
+    
+    public void testInsertDelete() throws Exception {       
+        Message message = new Message("Delete me");
+        int beginCount = count();
+        manager.persist(message);
+        manager.flush();
+        int endCount = count();
+        assertTrue(endCount>beginCount);
+        manager.remove(message);
+        manager.flush();
+        int finalCount = count();
+        assertTrue(finalCount == beginCount);
+    }
+
+}



Mime
View raw message