Author: adamw
Date: 2008-10-13 08:27:53 -0400 (Mon, 13 Oct 2008)
New Revision: 176
Modified:
trunk/resources/demo/META-INF/persistence.xml
trunk/src/demo/org/jboss/envers/demo/TestConsole.java
Log:
Updating the demo to use new features
Modified: trunk/resources/demo/META-INF/persistence.xml
===================================================================
--- trunk/resources/demo/META-INF/persistence.xml 2008-10-13 12:15:18 UTC (rev 175)
+++ trunk/resources/demo/META-INF/persistence.xml 2008-10-13 12:27:53 UTC (rev 176)
@@ -19,8 +19,8 @@
<property name="hibernate.connection.password"
value=""/>-->
<property name="hibernate.hbm2ddl.auto"
value="update"/>
- <property name="hibernate.show_sql" value="true"/>
- <property name="hibernate.format_sql"
value="true"/>
+ <!--<property name="hibernate.show_sql"
value="true"/>
+ <property name="hibernate.format_sql"
value="true"/>-->
<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" />
Modified: trunk/src/demo/org/jboss/envers/demo/TestConsole.java
===================================================================
--- trunk/src/demo/org/jboss/envers/demo/TestConsole.java 2008-10-13 12:15:18 UTC (rev
175)
+++ trunk/src/demo/org/jboss/envers/demo/TestConsole.java 2008-10-13 12:27:53 UTC (rev
176)
@@ -23,6 +23,8 @@
import org.jboss.envers.VersionsReader;
import org.jboss.envers.VersionsReaderFactory;
+import org.jboss.envers.DefaultRevisionEntity;
+import org.jboss.envers.query.VersionsRestrictions;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
@@ -82,15 +84,21 @@
private void printPersonHistory(StringBuilder sb, int personId) {
VersionsReader reader = VersionsReaderFactory.get(entityManager);
- List<Number> revisions = reader.getRevisions(Person.class, personId);
- if (revisions.size() == 0) {
+ List personHistory = reader.createQuery()
+ .forRevisionsOfEntity(Person.class, false, true)
+ .add(VersionsRestrictions.idEq(personId))
+ .getResultList();
+
+ if (personHistory.size() == 0) {
sb.append("A person with id ").append(personId).append(" does
not exist.\n");
} else {
- for (Number revision : revisions) {
- sb.append("revision = ").append(revision).append(",
");
- printPerson(sb, reader.find(Person.class, personId, revision));
- sb.append("
(").append(reader.getRevisionDate(revision)).append(")\n");
+ for (Object historyObj : personHistory) {
+ Object[] history = (Object[]) historyObj;
+ DefaultRevisionEntity revision = (DefaultRevisionEntity) history[1];
+ sb.append("revision =
").append(revision.getId()).append(", ");
+ printPerson(sb, (Person) history[0]);
+ sb.append("
(").append(revision.getRevisionDate()).append(")\n");
}
}
}
@@ -213,21 +221,21 @@
private void printAddressHistory(StringBuilder sb, int addressId) {
VersionsReader reader = VersionsReaderFactory.get(entityManager);
- List<Number> revisions = reader.getRevisions(Address.class, addressId);
- sb.append("Please notice: changes in the collection of persons associated
with ")
- .append("a given address aren't visible! Only changes to
non-relations fields and ")
- .append("owned relations fields are shown. ")
- .append("However, querying for an address at a given revision and
then retrieving ")
- .append("the persons will always give the correct
result.\n\n");
+ List addressHistory = reader.createQuery()
+ .forRevisionsOfEntity(Address.class, false, true)
+ .add(VersionsRestrictions.idEq(addressId))
+ .getResultList();
- if (revisions.size() == 0) {
- sb.append("An address with id ").append(addressId).append("
does not exist.\n");
+ if (addressHistory.size() == 0) {
+ sb.append("A address with id ").append(addressId).append("
does not exist.\n");
} else {
- for (Number revision : revisions) {
- sb.append("revision = ").append(revision).append(",
");
- printAddress(sb, reader.find(Address.class, addressId, revision));
- sb.append("
(").append(reader.getRevisionDate(revision)).append(")\n");
+ for (Object historyObj : addressHistory) {
+ Object[] history = (Object[]) historyObj;
+ DefaultRevisionEntity revision = (DefaultRevisionEntity) history[1];
+ sb.append("revision =
").append(revision.getId()).append(", ");
+ printAddress(sb, (Address) history[0]);
+ sb.append("
(").append(revision.getRevisionDate()).append(")\n");
}
}
}
Show replies by date