Author: dan.j.allen
Date: 2009-12-08 22:55:30 -0500 (Tue, 08 Dec 2009)
New Revision: 5242
Added:
archetypes/trunk/jsf/jee/src/main/resources/archetype-resources/src/main/java/Widget.java
archetypes/trunk/jsf/jee/src/main/resources/archetype-resources/src/main/java/WidgetDatabaseProducer.java
archetypes/trunk/jsf/jee/src/main/resources/archetype-resources/src/main/java/WidgetListProducer.java
archetypes/trunk/jsf/jee/src/main/resources/archetype-resources/src/main/java/WidgetRepository.java
archetypes/trunk/jsf/jee/src/main/resources/archetype-resources/src/main/resources/META-INF/persistence.xml
archetypes/trunk/jsf/jee/src/main/resources/archetype-resources/src/main/resources/import.sql
Modified:
archetypes/trunk/jsf/jee/src/main/resources/META-INF/archetype.xml
archetypes/trunk/jsf/jee/src/main/resources/archetype-resources/pom.xml
archetypes/trunk/jsf/jee/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/web.xml
archetypes/trunk/jsf/jee/src/main/resources/archetype-resources/src/main/webapp/index.xhtml
Log:
add persistence and some example beans
Modified: archetypes/trunk/jsf/jee/src/main/resources/META-INF/archetype.xml
===================================================================
--- archetypes/trunk/jsf/jee/src/main/resources/META-INF/archetype.xml 2009-12-09 03:55:05
UTC (rev 5241)
+++ archetypes/trunk/jsf/jee/src/main/resources/META-INF/archetype.xml 2009-12-09 03:55:30
UTC (rev 5242)
@@ -1,16 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<archetype>
- <id>weld-archetype-servlet-quickstart</id>
+ <id>weld-archetype-jee-quickstart</id>
<resources>
+ <resource>src/main/resources/import.sql</resource>
+ <resource>src/main/resources/META-INF/beans.xml</resource>
+ <resource>src/main/resources/META-INF/persistence.xml</resource>
<resource>src/main/webapp/index.xhtml</resource>
<resource>src/main/webapp/index.jsp</resource>
<resource>src/main/webapp/WEB-INF/web.xml</resource>
<resource>src/main/webapp/WEB-INF/faces-config.xml</resource>
- <resource>src/main/resources/META-INF/beans.xml</resource>
<resource>src/main/webapp/META-INF/context.xml</resource>
</resources>
<sources>
<source>src/main/java/HelloWorld.java</source>
+ <source>src/main/java/Widget.java</source>
+ <source>src/main/java/WidgetListProducer.java</source>
+ <source>src/main/java/WidgetRepository.java</source>
+ <source>src/main/java/WidgetRepositoryProducer.java</source>
</sources>
<testSources />
<testResources />
Modified: archetypes/trunk/jsf/jee/src/main/resources/archetype-resources/pom.xml
===================================================================
--- archetypes/trunk/jsf/jee/src/main/resources/archetype-resources/pom.xml 2009-12-09
03:55:05 UTC (rev 5241)
+++ archetypes/trunk/jsf/jee/src/main/resources/archetype-resources/pom.xml 2009-12-09
03:55:30 UTC (rev 5242)
@@ -42,6 +42,13 @@
<artifactId>cdi-api</artifactId>
<scope>provided</scope>
</dependency>
+ <!-- EJB -->
+ <dependency>
+ <groupId>org.jboss.ejb3</groupId>
+ <artifactId>jboss-ejb3-api</artifactId>
+ <scope>provided</scope>
+ <version>3.1.0</version>
+ </dependency>
<!-- Common annotations (e.g., @PostConstruct) -->
<dependency>
<groupId>javax.annotation</groupId>
@@ -69,6 +76,12 @@
<artifactId>jsf-api</artifactId>
<scope>provided</scope>
</dependency>
+ <!-- JPA -->
+ <dependency>
+ <groupId>javax.persistence</groupId>
+ <artifactId>persistence-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
<!-- Optional, but highly recommended. -->
<dependency>
@@ -93,53 +106,6 @@
</exclusion>
</exclusions>
</dependency>
-
- <!--
- Experimental Dependencies. Still working through these. If these are incorrect,
please change and notify
- someone at weld-dev(a)lists.jboss.org They will be finalized soon.
- -->
- <!-- JPA Dependencies. -->
- <!-- Should this be provided? -->
- <dependency>
- <groupId>javax.persistence</groupId>
- <artifactId>persistence-api</artifactId>
- </dependency>
- <!-- Should this be provided? -->
- <dependency>
- <groupId>org.hibernate</groupId>
- <artifactId>hibernate</artifactId>
- <version>3.2.6.ga</version>
- <!-- why? -->
- <exclusions>
- <exclusion>
- <groupId>javax.transaction</groupId>
- <artifactId>jta</artifactId>
- </exclusion>
- </exclusions>
- </dependency>
- <!-- Should this be provided? -->
- <dependency>
- <groupId>org.hibernate</groupId>
- <artifactId>hibernate-entitymanager</artifactId>
- <version>3.4.0.GA</version>
- </dependency>
- <!-- Should this be provided? -->
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-simple</artifactId>
- <version>1.4.2</version>
- </dependency>
- <!--<dependency>-->
- <!-- <groupId>c3p0</groupId>-->
- <!-- <artifactId>c3p0</artifactId>-->
- <!-- <version>0.9.1.2</version>-->
- <!--</dependency>-->
- <!-- Hypersonic in-memory database. Replace with a driver that reflects your
database. -->
- <dependency>
- <groupId>org.hsqldb</groupId>
- <artifactId>hsqldb</artifactId>
- <version>1.8.0.10</version>
- </dependency>
</dependencies>
<build>
<finalName>${artifactId}</finalName>
Added:
archetypes/trunk/jsf/jee/src/main/resources/archetype-resources/src/main/java/Widget.java
===================================================================
---
archetypes/trunk/jsf/jee/src/main/resources/archetype-resources/src/main/java/Widget.java
(rev 0)
+++
archetypes/trunk/jsf/jee/src/main/resources/archetype-resources/src/main/java/Widget.java 2009-12-09
03:55:30 UTC (rev 5242)
@@ -0,0 +1,61 @@
+package ${package};
+
+import java.io.Serializable;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+
+@Entity
+public class Widget implements Serializable
+{
+ private Long id;
+ private String partNumber;
+ private String name;
+ private String description;
+
+ @Id
+ @GeneratedValue
+ public Long getId()
+ {
+ return id;
+ }
+
+ public void setId(Long id)
+ {
+ this.id = id;
+ }
+
+ // demonstrates a column name override
+ @Column(name = "partno")
+ public String getPartNumber()
+ {
+ return partNumber;
+ }
+
+ public void setPartNumber(String partNumber)
+ {
+ this.partNumber = partNumber;
+ }
+
+ public String getName()
+ {
+ return name;
+ }
+
+ public void setName(String name)
+ {
+ this.name = name;
+ }
+
+ public String getDescription()
+ {
+ return description;
+ }
+
+ public void setDescription(String description)
+ {
+ this.description = description;
+ }
+}
Added:
archetypes/trunk/jsf/jee/src/main/resources/archetype-resources/src/main/java/WidgetDatabaseProducer.java
===================================================================
---
archetypes/trunk/jsf/jee/src/main/resources/archetype-resources/src/main/java/WidgetDatabaseProducer.java
(rev 0)
+++
archetypes/trunk/jsf/jee/src/main/resources/archetype-resources/src/main/java/WidgetDatabaseProducer.java 2009-12-09
03:55:30 UTC (rev 5242)
@@ -0,0 +1,13 @@
+package ${package};
+
+import javax.ejb.Stateless;
+import javax.enterprise.inject.Produces;
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContext;
+
+public
+@Stateless
+class WidgetDatabaseProducer
+{
+ @PersistenceContext @Produces @WidgetRepository EntityManager em;
+}
Added:
archetypes/trunk/jsf/jee/src/main/resources/archetype-resources/src/main/java/WidgetListProducer.java
===================================================================
---
archetypes/trunk/jsf/jee/src/main/resources/archetype-resources/src/main/java/WidgetListProducer.java
(rev 0)
+++
archetypes/trunk/jsf/jee/src/main/resources/archetype-resources/src/main/java/WidgetListProducer.java 2009-12-09
03:55:30 UTC (rev 5242)
@@ -0,0 +1,22 @@
+package ${package};
+
+import java.util.List;
+
+import javax.enterprise.context.RequestScoped;
+import javax.enterprise.inject.Produces;
+import javax.inject.Inject;
+import javax.inject.Named;
+import javax.persistence.EntityManager;
+
+public class WidgetListProducer
+{
+ @Inject @WidgetRepository EntityManager widgetRepository;
+
+ @Produces
+ @Named
+ @RequestScoped
+ @SuppressWarnings("unchecked")
+ List<Widget> getWidgets() {
+ return widgetRepository.createQuery("select w from Widget w order by
w.name").getResultList();
+ }
+}
Added:
archetypes/trunk/jsf/jee/src/main/resources/archetype-resources/src/main/java/WidgetRepository.java
===================================================================
---
archetypes/trunk/jsf/jee/src/main/resources/archetype-resources/src/main/java/WidgetRepository.java
(rev 0)
+++
archetypes/trunk/jsf/jee/src/main/resources/archetype-resources/src/main/java/WidgetRepository.java 2009-12-09
03:55:30 UTC (rev 5242)
@@ -0,0 +1,13 @@
+package ${package};
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+import javax.inject.Qualifier;
+
+@Qualifier
+(a)Target({ElementType.FIELD, ElementType.PARAMETER})
+(a)Retention(RetentionPolicy.RUNTIME)
+public @interface WidgetRepository {}
Added:
archetypes/trunk/jsf/jee/src/main/resources/archetype-resources/src/main/resources/META-INF/persistence.xml
===================================================================
---
archetypes/trunk/jsf/jee/src/main/resources/archetype-resources/src/main/resources/META-INF/persistence.xml
(rev 0)
+++
archetypes/trunk/jsf/jee/src/main/resources/archetype-resources/src/main/resources/META-INF/persistence.xml 2009-12-09
03:55:30 UTC (rev 5242)
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<persistence version="1.0"
+
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">
+ <persistence-unit name="widgets">
+ <!-- Use this data source name for JBoss AS -->
+ <jta-data-source>java:/DefaultDS</jta-data-source>
+ <!-- Use this data source name for Glassfish -->
+ <!--
+ <jta-data-source>jdbc/__default</jta-data-source>
+ -->
+ <properties>
+ <property name="hibernate.hbm2ddl.auto"
value="create-drop"/>
+ <property name="hibernate.show_sql" value="true"/>
+ <property name="hibernate.transaction.flush_before_completion"
value="true"/>
+ <property name="hibernate.cache.provider_class"
value="org.hibernate.cache.HashtableCacheProvider"/>
+ </properties>
+ </persistence-unit>
+</persistence>
Added:
archetypes/trunk/jsf/jee/src/main/resources/archetype-resources/src/main/resources/import.sql
===================================================================
---
archetypes/trunk/jsf/jee/src/main/resources/archetype-resources/src/main/resources/import.sql
(rev 0)
+++
archetypes/trunk/jsf/jee/src/main/resources/archetype-resources/src/main/resources/import.sql 2009-12-09
03:55:30 UTC (rev 5242)
@@ -0,0 +1 @@
+insert into Widget (id, partno, name, description) values (1, 'AAA001',
'Portable Hole', 'A hole for when you need to disappear fast.')
Modified:
archetypes/trunk/jsf/jee/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/web.xml
===================================================================
---
archetypes/trunk/jsf/jee/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/web.xml 2009-12-09
03:55:05 UTC (rev 5241)
+++
archetypes/trunk/jsf/jee/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/web.xml 2009-12-09
03:55:30 UTC (rev 5242)
@@ -26,4 +26,9 @@
<param-value>true</param-value>
</context-param>
+ <persistence-unit-ref>
+ <persistence-unit-ref-name>widgets/pu</persistence-unit-ref-name>
+ <persistence-unit-name>widgets</persistence-unit-name>
+ </persistence-unit-ref>
+
</web-app>
Modified:
archetypes/trunk/jsf/jee/src/main/resources/archetype-resources/src/main/webapp/index.xhtml
===================================================================
---
archetypes/trunk/jsf/jee/src/main/resources/archetype-resources/src/main/webapp/index.xhtml 2009-12-09
03:55:05 UTC (rev 5241)
+++
archetypes/trunk/jsf/jee/src/main/resources/archetype-resources/src/main/webapp/index.xhtml 2009-12-09
03:55:30 UTC (rev 5242)
@@ -47,5 +47,26 @@
<h:outputText value=" All clear!"
rendered="#{facesContext.postback and empty facesContext.messageList}"
style="color: green;"/>
</p>
</h:form>
+
+ <h2>Widgets</h2>
+ <h:dataTable var="_widget" value="#{widgets}">
+ <h:column>
+ <f:facet name="header">Id</f:facet>
+ #{_widget.id}
+ </h:column>
+ <h:column>
+ <f:facet name="header">Part Number</f:facet>
+ #{_widget.partNumber}
+ </h:column>
+ <h:column>
+ <f:facet name="header">Name</f:facet>
+ #{_widget.name}
+ </h:column>
+ <h:column>
+ <f:facet name="header">Description</f:facet>
+ #{_widget.description}
+ </h:column>
+ </h:dataTable>
+
</h:body>
</html>