Author: adamw
Date: 2008-10-21 13:23:43 -0400 (Tue, 21 Oct 2008)
New Revision: 181
Added:
demos/seam/lib/envers-1.1.0.ga.jar
demos/seam/src/action/org/jboss/envers/demo/seam/wiki/WikiEdit.java
Removed:
demos/seam/lib/envers-1.1.0.beta1.jar
Modified:
demos/seam/resources/META-INF/persistence-dev.xml
demos/seam/resources/WEB-INF/pages.xml
demos/seam/resources/envers_seam_demo-dev-ds.xml
demos/seam/src/action/org/jboss/envers/demo/seam/wiki/HistoryReader.java
demos/seam/src/model/org/jboss/envers/demo/seam/wiki/WikiPage.java
demos/seam/view/wiki/edit.xhtml
demos/seam/view/wiki/view.xhtml
demos/seam/view/wiki/viewHistory.xhtml
demos/seam/view/wiki/wiki_template.xhtml
Log:
Demo update
Deleted: demos/seam/lib/envers-1.1.0.beta1.jar
===================================================================
(Binary files differ)
Added: demos/seam/lib/envers-1.1.0.ga.jar
===================================================================
(Binary files differ)
Property changes on: demos/seam/lib/envers-1.1.0.ga.jar
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Modified: demos/seam/resources/META-INF/persistence-dev.xml
===================================================================
--- demos/seam/resources/META-INF/persistence-dev.xml 2008-10-21 13:16:25 UTC (rev 180)
+++ demos/seam/resources/META-INF/persistence-dev.xml 2008-10-21 17:23:43 UTC (rev 181)
@@ -8,15 +8,20 @@
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>java:/envers_seam_demoDatasource</jta-data-source>
<properties>
- <property name="hibernate.dialect"
value="org.hibernate.dialect.HSQLDialect"/>
<property name="hibernate.hbm2ddl.auto"
value="update"/>
<property name="hibernate.show_sql"
value="false"/>
<property name="hibernate.format_sql"
value="false"/>
<property name="jboss.entity.manager.factory.jndi.name"
value="java:/envers_seam_demoEntityManagerFactory"/>
+ <!--<property name="hibernate.dialect"
value="org.hibernate.dialect.HSQLDialect"/>-->
+ <property name="hibernate.dialect"
value="org.hibernate.dialect.MySQLDialect"/>
+
<property name="hibernate.ejb.event.post-insert"
value="org.jboss.envers.event.VersionsEventListener" />
<property name="hibernate.ejb.event.post-update"
value="org.jboss.envers.event.VersionsEventListener" />
<property name="hibernate.ejb.event.post-delete"
value="org.jboss.envers.event.VersionsEventListener" />
+ <property name="hibernate.ejb.event.pre-collection-update"
value="org.jboss.envers.event.VersionsEventListener" />
+ <property name="hibernate.ejb.event.pre-collection-remove"
value="org.jboss.envers.event.VersionsEventListener" />
+ <property name="hibernate.ejb.event.post-collection-recreate"
value="org.jboss.envers.event.VersionsEventListener" />
</properties>
</persistence-unit>
</persistence>
Modified: demos/seam/resources/WEB-INF/pages.xml
===================================================================
--- demos/seam/resources/WEB-INF/pages.xml 2008-10-21 13:16:25 UTC (rev 180)
+++ demos/seam/resources/WEB-INF/pages.xml 2008-10-21 17:23:43 UTC (rev 181)
@@ -23,11 +23,14 @@
</page>
<page view-id="/wiki/edit.xhtml" login-required="true">
+ <begin-conversation flush-mode="manual" join="true" />
<param name="wikiPageId" value="#{wikiPageHome.id}"
converterId="javax.faces.Integer" />
<navigation from-action="#{wikiPageHome.persist}">
+ <end-conversation />
<redirect view-id="/wiki/list.xhtml" />
</navigation>
<navigation from-action="#{wikiPageHome.update}">
+ <end-conversation />
<redirect view-id="/wiki/list.xhtml" />
</navigation>
</page>
Modified: demos/seam/resources/envers_seam_demo-dev-ds.xml
===================================================================
--- demos/seam/resources/envers_seam_demo-dev-ds.xml 2008-10-21 13:16:25 UTC (rev 180)
+++ demos/seam/resources/envers_seam_demo-dev-ds.xml 2008-10-21 17:23:43 UTC (rev 181)
@@ -1,15 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE datasources
- PUBLIC "-//JBoss//DTD JBOSS JCA Config 1.5//EN"
- "http://www.jboss.org/j2ee/dtd/jboss-ds_1_5.dtd">
+ PUBLIC "-//JBoss//DTD JBOSS JCA Config 1.5//EN"
+ "http://www.jboss.org/j2ee/dtd/jboss-ds_1_5.dtd">
<datasources>
- <local-tx-datasource>
- <jndi-name>envers_seam_demoDatasource</jndi-name>
-
<connection-url>jdbc:hsqldb:${jboss.server.data.dir}${/}envers</connection-url>
- <driver-class>org.hsqldb.jdbcDriver</driver-class>
- <user-name>sa</user-name>
- <password></password>
- </local-tx-datasource>
+ <local-tx-datasource>
+ <jndi-name>envers_seam_demoDatasource</jndi-name>
+
+
<!--<connection-url>jdbc:hsqldb:${jboss.server.data.dir}${/}envers</connection-url>
+ <driver-class>org.hsqldb.jdbcDriver</driver-class>
+ <user-name>sa</user-name>
+ <password></password>-->
+
+
<connection-url>jdbc:mysql:///hibernate_tests?useUnicode=true&characterEncoding=UTF-8</connection-url>
+ <driver-class>com.mysql.jdbc.Driver</driver-class>
+ <user-name>root</user-name>
+ <password></password>
+ </local-tx-datasource>
</datasources>
Modified: demos/seam/src/action/org/jboss/envers/demo/seam/wiki/HistoryReader.java
===================================================================
--- demos/seam/src/action/org/jboss/envers/demo/seam/wiki/HistoryReader.java 2008-10-21
13:16:25 UTC (rev 180)
+++ demos/seam/src/action/org/jboss/envers/demo/seam/wiki/HistoryReader.java 2008-10-21
17:23:43 UTC (rev 181)
@@ -3,6 +3,8 @@
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.In;
import org.jboss.envers.VersionsReader;
+import org.jboss.envers.query.VersionsRestrictions;
+import org.jboss.envers.query.RevisionProperty;
import java.util.List;
import java.util.ArrayList;
@@ -24,9 +26,14 @@
if (history == null) {
history = new ArrayList<HistoryEntry>();
- for (Number revision : versionsReader.getRevisions(WikiPage.class,
wikiPageId)) {
- history.add(new HistoryEntry(versionsReader.find(WikiPage.class,
wikiPageId, revision),
- versionsReader.findRevision(WikiLog.class, revision)));
+ List versions =
versionsReader.createQuery().forRevisionsOfEntity(WikiPage.class, false, false)
+ .add(VersionsRestrictions.idEq(wikiPageId))
+ .addOrder(RevisionProperty.desc())
+ .getResultList();
+
+ for (Object versionDataObject : versions) {
+ Object[] versionData = (Object[]) versionDataObject;
+ history.add(new HistoryEntry((WikiPage) versionData[0], (WikiLog)
versionData[1]));
}
}
Added: demos/seam/src/action/org/jboss/envers/demo/seam/wiki/WikiEdit.java
===================================================================
--- demos/seam/src/action/org/jboss/envers/demo/seam/wiki/WikiEdit.java
(rev 0)
+++ demos/seam/src/action/org/jboss/envers/demo/seam/wiki/WikiEdit.java 2008-10-21
17:23:43 UTC (rev 181)
@@ -0,0 +1,42 @@
+package org.jboss.envers.demo.seam.wiki;
+
+import org.jboss.seam.annotations.Name;
+import org.jboss.seam.annotations.Scope;
+import org.jboss.seam.annotations.In;
+import org.jboss.seam.ScopeType;
+
+import java.util.ArrayList;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+@Name("wikiEdit")
+(a)Scope(ScopeType.CONVERSATION)
+public class WikiEdit {
+ @In("#{wikiPageHome.instance}")
+ private WikiPage wikiPage;
+
+ private String newLink;
+
+ public String getNewLink() {
+ return newLink;
+ }
+
+ public void setNewLink(String newLink) {
+ this.newLink = newLink;
+ }
+
+ public void addLink() {
+ if (wikiPage.getLinks() == null) {
+ wikiPage.setLinks(new ArrayList<String>());
+ }
+
+ wikiPage.getLinks().add(newLink);
+
+ newLink = null;
+ }
+
+ public void deleteLink(String link) {
+ wikiPage.getLinks().remove(link);
+ }
+}
Modified: demos/seam/src/model/org/jboss/envers/demo/seam/wiki/WikiPage.java
===================================================================
--- demos/seam/src/model/org/jboss/envers/demo/seam/wiki/WikiPage.java 2008-10-21 13:16:25
UTC (rev 180)
+++ demos/seam/src/model/org/jboss/envers/demo/seam/wiki/WikiPage.java 2008-10-21 17:23:43
UTC (rev 181)
@@ -1,10 +1,13 @@
package org.jboss.envers.demo.seam.wiki;
import org.jboss.envers.Versioned;
+import org.hibernate.annotations.CollectionOfElements;
+import org.hibernate.annotations.IndexColumn;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.GeneratedValue;
+import java.util.List;
/**
* @author Adam Warski (adam at warski dot org)
@@ -20,6 +23,10 @@
private String content;
+ @CollectionOfElements
+ @IndexColumn(name = "ind")
+ private List<String> links;
+
public int getId() {
return id;
}
@@ -44,6 +51,14 @@
this.content = content;
}
+ public List<String> getLinks() {
+ return links;
+ }
+
+ public void setLinks(List<String> links) {
+ this.links = links;
+ }
+
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof WikiPage)) return false;
Modified: demos/seam/view/wiki/edit.xhtml
===================================================================
--- demos/seam/view/wiki/edit.xhtml 2008-10-21 13:16:25 UTC (rev 180)
+++ demos/seam/view/wiki/edit.xhtml 2008-10-21 17:23:43 UTC (rev 181)
@@ -16,10 +16,12 @@
</h:panelGroup>
</f:facet>
+ <h:messages />
+
<h:form>
<table>
<tr>
- <td>Title:</td>
+ <td>Title (required):</td>
<td><h:inputText
value="#{wikiPageHome.instance.title}" required="true"
/></td>
</tr>
<tr>
@@ -27,11 +29,33 @@
<td><h:inputTextarea
value="#{wikiPageHome.instance.content}" rows="20" cols="50"
/></td>
</tr>
<tr>
+ <td>Links:</td>
<td>
+ <s:fragment rendered="#{not empty
wikiPageHome.instance.links}">
+ <ul>
+ <ui:repeat var="link"
value="#{wikiPageHome.instance.links}">
+ <li>
+ #{link}
+ <h:commandButton value="Remove"
action="#{wikiEdit.deleteLink(link)}" />
+ </li>
+ </ui:repeat>
+ </ul>
+ </s:fragment>
+ New link:
+ <h:inputText value="#{wikiEdit.newLink}" />
+ <h:commandButton value="Add"
action="#{wikiEdit.addLink}" />
+ </td>
+ </tr>
+ <tr>
+ <td>
<h:commandButton value="Save"
action="#{wikiPageHome.persist}"
rendered="#{!wikiPageHome.managed}"/>
<h:commandButton value="Save"
action="#{wikiPageHome.update}"
rendered="#{wikiPageHome.managed}"/>
</td>
- <td><s:button value="Cancel"
view="/wiki/list.xhtml" /></td>
+ <td>
+ <s:button value="Cancel"
view="/wiki/list.xhtml">
+ <s:conversationPropagation type="end" />
+ </s:button>
+ </td>
</tr>
</table>
</h:form>
Modified: demos/seam/view/wiki/view.xhtml
===================================================================
--- demos/seam/view/wiki/view.xhtml 2008-10-21 13:16:25 UTC (rev 180)
+++ demos/seam/view/wiki/view.xhtml 2008-10-21 17:23:43 UTC (rev 181)
@@ -25,6 +25,21 @@
<hr />
+ <p><b>Links:</b></p>
+
+ <s:fragment rendered="#{empty wikiPageHome.instance.links}">
+ <p>None</p>
+ </s:fragment>
+ <s:fragment rendered="#{not empty
wikiPageHome.instance.links}">
+ <ul>
+ <ui:repeat var="link"
value="#{wikiPageHome.instance.links}">
+ <li>#{link}</li>
+ </ui:repeat>
+ </ul>
+ </s:fragment>
+
+ <hr />
+
#{wikiPageHome.instance.content}
</rich:panel>
</ui:define>
Modified: demos/seam/view/wiki/viewHistory.xhtml
===================================================================
--- demos/seam/view/wiki/viewHistory.xhtml 2008-10-21 13:16:25 UTC (rev 180)
+++ demos/seam/view/wiki/viewHistory.xhtml 2008-10-21 17:23:43 UTC (rev 181)
@@ -54,6 +54,23 @@
<h:column>
<f:facet name="header">
+ Links
+ </f:facet>
+
+ <s:fragment rendered="#{empty
historyEntry.page.links}">
+ None
+ </s:fragment>
+ <s:fragment rendered="#{not empty
historyEntry.page.links}">
+ <ul>
+ <ui:repeat var="link"
value="#{historyEntry.page.links}">
+ <li>#{link}</li>
+ </ui:repeat>
+ </ul>
+ </s:fragment>
+ </h:column>
+
+ <h:column>
+ <f:facet name="header">
Content
</f:facet>
Modified: demos/seam/view/wiki/wiki_template.xhtml
===================================================================
--- demos/seam/view/wiki/wiki_template.xhtml 2008-10-21 13:16:25 UTC (rev 180)
+++ demos/seam/view/wiki/wiki_template.xhtml 2008-10-21 17:23:43 UTC (rev 181)
@@ -43,8 +43,16 @@
<a
href="http://www.jboss.org/files/envers/api/org/jboss/envers/Version...
interface, which in this application is managed by the
<a
href="http://fisheye.jboss.org/browse/envers/demos/seam/src/action/o...
- bean.
+ bean. Here, the history of a wiki page is retrieved using a
revisions-of-entity
+ <a
href="http://www.jboss.org/envers/queries.html">query</a>.
</p>
+
+ <p>
+ With a single revisions-of-entity query you can retrieve the whole
history of an entity, along with the
+ metadata (when the change was made and by whom). If the history is large,
you can implement paging
+ simply by setting the <code>setFirstResult</code> and
<code>setMaxResults</code> properties of the
+ query.
+ </p>
</rich:panel>
<div style="margin-right: 440px">