JBoss Envers SVN: r185 - in trunk: resources/test and 5 other directories.
by jboss-envers-commits@lists.jboss.org
Author: adamw
Date: 2008-10-24 06:41:00 -0400 (Fri, 24 Oct 2008)
New Revision: 185
Added:
trunk/lib/hibernate-common/hibernate-validator.jar
trunk/src/test/org/jboss/envers/test/integration/notinsertable/
trunk/src/test/org/jboss/envers/test/integration/notinsertable/NotInsertable.java
trunk/src/test/org/jboss/envers/test/integration/notinsertable/NotInsertableTestEntity.java
Modified:
trunk/resources/test/testng.xml
trunk/src/main/org/jboss/envers/configuration/RevisionInfoConfiguration.java
trunk/src/main/org/jboss/envers/configuration/metadata/BasicMetadataGenerator.java
trunk/src/main/org/jboss/envers/configuration/metadata/CollectionMetadataGenerator.java
trunk/src/main/org/jboss/envers/configuration/metadata/IdMetadataGenerator.java
trunk/src/main/org/jboss/envers/configuration/metadata/MetadataTools.java
trunk/src/main/org/jboss/envers/configuration/metadata/VersionsMetadataGenerator.java
trunk/src/main/org/jboss/envers/tools/reflection/YReflectionManager.java
Log:
ENVERS-64: fix for non-insertable columns
Added: trunk/lib/hibernate-common/hibernate-validator.jar
===================================================================
(Binary files differ)
Property changes on: trunk/lib/hibernate-common/hibernate-validator.jar
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Modified: trunk/resources/test/testng.xml
===================================================================
--- trunk/resources/test/testng.xml 2008-10-23 07:48:17 UTC (rev 184)
+++ trunk/resources/test/testng.xml 2008-10-24 10:41:00 UTC (rev 185)
@@ -20,6 +20,7 @@
<package name="org.jboss.envers.test.integration.manytomany.unidirectional" />
<package name="org.jboss.envers.test.integration.naming" />
<package name="org.jboss.envers.test.integration.naming.ids" />
+ <package name="org.jboss.envers.test.integration.notinsertable" />
<package name="org.jboss.envers.test.integration.onetomany" />
<package name="org.jboss.envers.test.integration.onetomany.detached" />
<package name="org.jboss.envers.test.integration.onetoone.bidirectional" />
Modified: trunk/src/main/org/jboss/envers/configuration/RevisionInfoConfiguration.java
===================================================================
--- trunk/src/main/org/jboss/envers/configuration/RevisionInfoConfiguration.java 2008-10-23 07:48:17 UTC (rev 184)
+++ trunk/src/main/org/jboss/envers/configuration/RevisionInfoConfiguration.java 2008-10-24 10:41:00 UTC (rev 185)
@@ -72,7 +72,7 @@
MetadataTools.addColumn(idProperty, "revision_id", null);
Element timestampProperty = MetadataTools.addProperty(class_mapping, revisionInfoTimestampName,
- revisionInfoTimestampType, false);
+ revisionInfoTimestampType, true, false);
MetadataTools.addColumn(timestampProperty, "revision_timestamp", null);
return document;
Modified: trunk/src/main/org/jboss/envers/configuration/metadata/BasicMetadataGenerator.java
===================================================================
--- trunk/src/main/org/jboss/envers/configuration/metadata/BasicMetadataGenerator.java 2008-10-23 07:48:17 UTC (rev 184)
+++ trunk/src/main/org/jboss/envers/configuration/metadata/BasicMetadataGenerator.java 2008-10-24 10:41:00 UTC (rev 185)
@@ -40,27 +40,27 @@
*/
public final class BasicMetadataGenerator {
boolean addBasic(Element parent, String name, Value value, CompositeMapperBuilder mapper,
- ModificationStore store, String entityName, boolean key) {
+ ModificationStore store, String entityName, boolean insertable, boolean key) {
Type type = value.getType();
if (type instanceof ComponentType) {
addComponent(parent, name, value, mapper, entityName, key);
return true;
} else {
- return addBasicNoComponent(parent, name, value, mapper, store, key);
+ return addBasicNoComponent(parent, name, value, mapper, store, insertable, key);
}
}
boolean addBasicNoComponent(Element parent, String name, Value value, SimpleMapperBuilder mapper,
- ModificationStore store, boolean key) {
+ ModificationStore store, boolean insertable, boolean key) {
Type type = value.getType();
if (type instanceof ImmutableType || type instanceof MutableType) {
- addSimpleValue(parent, name, value, mapper, store, key);
+ addSimpleValue(parent, name, value, mapper, store, insertable, key);
} else if (type instanceof CustomType || type instanceof CompositeCustomType) {
- addCustomValue(parent, name, value, mapper, store, key);
+ addCustomValue(parent, name, value, mapper, store, insertable, key);
} else if ("org.hibernate.type.PrimitiveByteArrayBlobType".equals(type.getClass().getName())) {
- addSimpleValue(parent, name, value, mapper, store, key);
+ addSimpleValue(parent, name, value, mapper, store, insertable, key);
} else {
return false;
}
@@ -70,10 +70,10 @@
@SuppressWarnings({"unchecked"})
private void addSimpleValue(Element parent, String name, Value value, SimpleMapperBuilder mapper,
- ModificationStore store, boolean key) {
+ ModificationStore store, boolean insertable, boolean key) {
if (parent != null) {
Element prop_mapping = MetadataTools.addProperty(parent, name,
- value.getType().getName(), key);
+ value.getType().getName(), insertable, key);
MetadataTools.addColumns(prop_mapping, (Iterator<Column>) value.getColumnIterator());
}
@@ -85,10 +85,10 @@
@SuppressWarnings({"unchecked"})
private void addCustomValue(Element parent, String name, Value value, SimpleMapperBuilder mapper,
- ModificationStore store, boolean key) {
+ ModificationStore store, boolean insertable, boolean key) {
if (parent != null) {
Element prop_mapping = MetadataTools.addProperty(parent, name,
- null, key);
+ null, insertable, key);
//CustomType propertyType = (CustomType) value.getType();
@@ -158,7 +158,7 @@
while (properties.hasNext()) {
Property property = properties.next();
addBasic(component_mapping, property.getName(), property.getValue(), componentMapper,
- ModificationStore.FULL, entityName, key);
+ ModificationStore.FULL, entityName, property.isInsertable(), key);
}
}
}
Modified: trunk/src/main/org/jboss/envers/configuration/metadata/CollectionMetadataGenerator.java
===================================================================
--- trunk/src/main/org/jboss/envers/configuration/metadata/CollectionMetadataGenerator.java 2008-10-23 07:48:17 UTC (rev 184)
+++ trunk/src/main/org/jboss/envers/configuration/metadata/CollectionMetadataGenerator.java 2008-10-24 10:41:00 UTC (rev 185)
@@ -366,8 +366,9 @@
return new MiddleComponentData(new MiddleRelatedComponentMapper(referencedIdData),
queryGeneratorBuilder.getCurrentIndex());
} else {
+ // Last but one parameter: collection components are always insertable
boolean mapped = mainGenerator.getBasicMetadataGenerator().addBasicNoComponent(xmlMapping, prefix, value, null,
- ModificationStore.FULL, true);
+ ModificationStore.FULL, true, true);
if (mapped) {
// Simple values are always stored in the first item of the array returned by the query generator.
Modified: trunk/src/main/org/jboss/envers/configuration/metadata/IdMetadataGenerator.java
===================================================================
--- trunk/src/main/org/jboss/envers/configuration/metadata/IdMetadataGenerator.java 2008-10-23 07:48:17 UTC (rev 184)
+++ trunk/src/main/org/jboss/envers/configuration/metadata/IdMetadataGenerator.java 2008-10-24 10:41:00 UTC (rev 185)
@@ -59,8 +59,9 @@
Type propertyType = property.getType();
if (!"_identifierMapper".equals(property.getName())) {
if (propertyType instanceof ImmutableType) {
+ // Last but one parameter: ids are always insertable
mainGenerator.getBasicMetadataGenerator().addBasicNoComponent(parent, property.getName(),
- property.getValue(), mapper, ModificationStore.FULL, key);
+ property.getValue(), mapper, ModificationStore.FULL, true, key);
} else {
throw new MappingException("Type not supported: " + propertyType.getClass().getName());
}
@@ -102,12 +103,13 @@
mapper = new SingleIdMapper();
+ // Last but one parameter: ids are always insertable
mainGenerator.getBasicMetadataGenerator().addBasicNoComponent(rel_id_mapping, id_prop.getName(),
- id_prop.getValue(), mapper, ModificationStore.FULL, false);
+ id_prop.getValue(), mapper, ModificationStore.FULL, true, false);
// null mapper - the mapping where already added the first time, now we only want to generate the xml
mainGenerator.getBasicMetadataGenerator().addBasicNoComponent(orig_id_mapping, id_prop.getName(),
- id_prop.getValue(), null, ModificationStore.FULL, true);
+ id_prop.getValue(), null, ModificationStore.FULL, true, true);
}
orig_id_mapping.addAttribute("name", mainGenerator.getVerEntCfg().getOriginalIdPropName());
Modified: trunk/src/main/org/jboss/envers/configuration/metadata/MetadataTools.java
===================================================================
--- trunk/src/main/org/jboss/envers/configuration/metadata/MetadataTools.java 2008-10-23 07:48:17 UTC (rev 184)
+++ trunk/src/main/org/jboss/envers/configuration/metadata/MetadataTools.java 2008-10-24 10:41:00 UTC (rev 185)
@@ -46,7 +46,7 @@
return id_mapping;
}
- public static Element addProperty(Element parent, String name, String type, boolean key) {
+ public static Element addProperty(Element parent, String name, String type, boolean insertable, boolean key) {
Element prop_mapping;
if (key) {
prop_mapping = parent.addElement("key-property");
@@ -55,6 +55,7 @@
}
prop_mapping.addAttribute("name", name);
+ prop_mapping.addAttribute("insert", Boolean.toString(insertable));
if (type != null) {
prop_mapping.addAttribute("type", type);
Modified: trunk/src/main/org/jboss/envers/configuration/metadata/VersionsMetadataGenerator.java
===================================================================
--- trunk/src/main/org/jboss/envers/configuration/metadata/VersionsMetadataGenerator.java 2008-10-23 07:48:17 UTC (rev 184)
+++ trunk/src/main/org/jboss/envers/configuration/metadata/VersionsMetadataGenerator.java 2008-10-24 10:41:00 UTC (rev 185)
@@ -90,7 +90,7 @@
void addRevisionType(Element any_mapping) {
Element revTypeProperty = MetadataTools.addProperty(any_mapping, verEntCfg.getRevisionTypePropName(),
- verEntCfg.getRevisionTypePropType(), false);
+ verEntCfg.getRevisionTypePropType(), true, false);
revTypeProperty.addAttribute("type", "org.jboss.envers.entities.RevisionTypeType");
}
@@ -119,12 +119,13 @@
@SuppressWarnings({"unchecked"})
void addValue(Element parent, String name, Value value, CompositeMapperBuilder currentMapper,
ModificationStore store, String entityName, EntityXmlMappingData xmlMappingData,
- VersionsJoinTable joinTable, String mapKey, boolean firstPass) {
+ VersionsJoinTable joinTable, String mapKey, boolean insertable, boolean firstPass) {
Type type = value.getType();
// only first pass
if (firstPass) {
- if (basicMetadataGenerator.addBasic(parent, name, value, currentMapper, store, entityName, false)) {
+ if (basicMetadataGenerator.addBasic(parent, name, value, currentMapper, store, entityName, insertable,
+ false)) {
// The property was mapped by the basic generator.
return;
}
@@ -169,7 +170,7 @@
if (store != null) {
addValue(parent, property.getName(), property.getValue(), currentMapper, store, entityName,
xmlMappingData, versioningData.versionsJoinTables.get(property.getName()),
- versioningData.mapKeys.get(property.getName()), firstPass);
+ versioningData.mapKeys.get(property.getName()), property.isInsertable(), firstPass);
}
}
}
@@ -226,8 +227,6 @@
}
}
-
-
private void addPersisterHack(Element class_mapping) {
String persisterClassName;
if (HibernateVersion.get().startsWith("3.3")) {
Modified: trunk/src/main/org/jboss/envers/tools/reflection/YReflectionManager.java
===================================================================
--- trunk/src/main/org/jboss/envers/tools/reflection/YReflectionManager.java 2008-10-23 07:48:17 UTC (rev 184)
+++ trunk/src/main/org/jboss/envers/tools/reflection/YReflectionManager.java 2008-10-24 10:41:00 UTC (rev 185)
@@ -37,7 +37,16 @@
private final YMethodsAndClasses ymc;
public YReflectionManager(Configuration cfg) throws Exception {
- delegate = cfg.getClass().getMethod("getReflectionManager").invoke(cfg);
+ Object delegateTemp;
+ try {
+ delegateTemp = cfg.getClass().getMethod("getReflectionManager").invoke(cfg);
+ } catch (NoSuchMethodException e) {
+ // TODO - what if there it's a pure Hibernate envirionment?
+ delegateTemp = ReflectionTools
+ .loadClass("org.hibernate.cfg.annotations.reflection.EJB3ReflectionManager")
+ .newInstance();
+ }
+ delegate = delegateTemp;
ymc = new YMethodsAndClasses(delegate.getClass());
}
Copied: trunk/src/test/org/jboss/envers/test/integration/notinsertable/NotInsertable.java (from rev 174, trunk/src/test/org/jboss/envers/test/integration/data/Dates.java)
===================================================================
--- trunk/src/test/org/jboss/envers/test/integration/notinsertable/NotInsertable.java (rev 0)
+++ trunk/src/test/org/jboss/envers/test/integration/notinsertable/NotInsertable.java 2008-10-24 10:41:00 UTC (rev 185)
@@ -0,0 +1,49 @@
+package org.jboss.envers.test.integration.notinsertable;
+
+import org.jboss.envers.test.AbstractEntityTest;
+import org.hibernate.ejb.Ejb3Configuration;
+import org.testng.annotations.Test;
+import org.testng.annotations.BeforeClass;
+
+import javax.persistence.EntityManager;
+import java.util.Arrays;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+public class NotInsertable extends AbstractEntityTest {
+ private Integer id1;
+
+ public void configure(Ejb3Configuration cfg) {
+ cfg.addAnnotatedClass(NotInsertableTestEntity.class);
+ }
+
+ @BeforeClass(dependsOnMethods = "init")
+ public void initData() {
+ EntityManager em = getEntityManager();
+ em.getTransaction().begin();
+ NotInsertableTestEntity dte = new NotInsertableTestEntity("data1");
+ em.persist(dte);
+ id1 = dte.getId();
+ em.getTransaction().commit();
+
+ em.getTransaction().begin();
+ dte = em.find(NotInsertableTestEntity.class, id1);
+ dte.setData("data2");
+ em.getTransaction().commit();
+ }
+
+ @Test
+ public void testRevisionsCounts() {
+ assert Arrays.asList(1, 2).equals(getVersionsReader().getRevisions(NotInsertableTestEntity.class, id1));
+ }
+
+ @Test
+ public void testHistoryOfId1() {
+ NotInsertableTestEntity ver1 = new NotInsertableTestEntity(id1, "data1", "data1");
+ NotInsertableTestEntity ver2 = new NotInsertableTestEntity(id1, "data2", "data2");
+
+ assert getVersionsReader().find(NotInsertableTestEntity.class, id1, 1).equals(ver1);
+ assert getVersionsReader().find(NotInsertableTestEntity.class, id1, 2).equals(ver2);
+ }
+}
\ No newline at end of file
Property changes on: trunk/src/test/org/jboss/envers/test/integration/notinsertable/NotInsertable.java
___________________________________________________________________
Name: svn:mergeinfo
+
Copied: trunk/src/test/org/jboss/envers/test/integration/notinsertable/NotInsertableTestEntity.java (from rev 173, trunk/src/test/org/jboss/envers/test/integration/data/DateTestEntity.java)
===================================================================
--- trunk/src/test/org/jboss/envers/test/integration/notinsertable/NotInsertableTestEntity.java (rev 0)
+++ trunk/src/test/org/jboss/envers/test/integration/notinsertable/NotInsertableTestEntity.java 2008-10-24 10:41:00 UTC (rev 185)
@@ -0,0 +1,83 @@
+package org.jboss.envers.test.integration.notinsertable;
+
+import org.jboss.envers.Versioned;
+
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Column;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+@Entity
+@Versioned
+public class NotInsertableTestEntity {
+ @Id
+ @GeneratedValue
+ private Integer id;
+
+ @Column(name = "data")
+ private String data;
+
+ @Column(name = "data", insertable = false, updatable = false)
+ private String dataCopy;
+
+ public NotInsertableTestEntity() {
+ }
+
+ public NotInsertableTestEntity(Integer id, String data, String dataCopy) {
+ this.id = id;
+ this.data = data;
+ this.dataCopy = dataCopy;
+ }
+
+ public NotInsertableTestEntity(String data) {
+ this.data = data;
+ }
+
+ public Integer getId() {
+ return id;
+ }
+
+ public void setId(Integer id) {
+ this.id = id;
+ }
+
+ public String getData() {
+ return data;
+ }
+
+ public void setData(String data) {
+ this.data = data;
+ }
+
+ public String getDataCopy() {
+ return dataCopy;
+ }
+
+ public void setDataCopy(String dataCopy) {
+ this.dataCopy = dataCopy;
+ }
+
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (!(o instanceof NotInsertableTestEntity)) return false;
+
+ NotInsertableTestEntity that = (NotInsertableTestEntity) o;
+
+ if (data != null ? !data.equals(that.data) : that.data != null) return false;
+ if (dataCopy != null ? !dataCopy.equals(that.dataCopy) : that.dataCopy != null) return false;
+ if (id != null ? !id.equals(that.id) : that.id != null) return false;
+
+ return true;
+ }
+
+ public int hashCode() {
+ int result;
+ result = (id != null ? id.hashCode() : 0);
+ result = 31 * result + (data != null ? data.hashCode() : 0);
+ result = 31 * result + (dataCopy != null ? dataCopy.hashCode() : 0);
+ return result;
+ }
+}
\ No newline at end of file
Property changes on: trunk/src/test/org/jboss/envers/test/integration/notinsertable/NotInsertableTestEntity.java
___________________________________________________________________
Name: svn:mergeinfo
+
16 years
JBoss Envers SVN: r184 - trunk/src/main/org/jboss/envers/tools/reflection.
by jboss-envers-commits@lists.jboss.org
Author: adamw
Date: 2008-10-23 03:48:17 -0400 (Thu, 23 Oct 2008)
New Revision: 184
Modified:
trunk/src/main/org/jboss/envers/tools/reflection/ReflectionTools.java
Log:
Reflection cache fix
Modified: trunk/src/main/org/jboss/envers/tools/reflection/ReflectionTools.java
===================================================================
--- trunk/src/main/org/jboss/envers/tools/reflection/ReflectionTools.java 2008-10-21 17:45:56 UTC (rev 183)
+++ trunk/src/main/org/jboss/envers/tools/reflection/ReflectionTools.java 2008-10-23 07:48:17 UTC (rev 184)
@@ -41,11 +41,11 @@
private static final Map<Pair<Class, String>, Getter> getterCache =
new ConcurrentReferenceHashMap<Pair<Class, String>, Getter>(10,
ConcurrentReferenceHashMap.ReferenceType.SOFT,
- ConcurrentReferenceHashMap.ReferenceType.STRONG);
+ ConcurrentReferenceHashMap.ReferenceType.SOFT);
private static final Map<Pair<Class, String>, Setter> setterCache =
new ConcurrentReferenceHashMap<Pair<Class, String>, Setter>(10,
ConcurrentReferenceHashMap.ReferenceType.SOFT,
- ConcurrentReferenceHashMap.ReferenceType.STRONG);
+ ConcurrentReferenceHashMap.ReferenceType.SOFT);
private static final PropertyAccessor BASIC_PROPERTY_ACCESSOR = new BasicPropertyAccessor();
16 years
JBoss Envers SVN: r183 - tags.
by jboss-envers-commits@lists.jboss.org
Author: adamw
Date: 2008-10-21 13:45:56 -0400 (Tue, 21 Oct 2008)
New Revision: 183
Added:
tags/1.1.0-ga/
Log:
Tagging the 1.1.0.GA release
Copied: tags/1.1.0-ga (from rev 182, trunk)
16 years
JBoss Envers SVN: r182 - in demos/seam/resources: META-INF and 1 other directory.
by jboss-envers-commits@lists.jboss.org
Author: adamw
Date: 2008-10-21 13:27:02 -0400 (Tue, 21 Oct 2008)
New Revision: 182
Modified:
demos/seam/resources/META-INF/persistence-dev.xml
demos/seam/resources/envers_seam_demo-dev-ds.xml
Log:
Demo update
Modified: demos/seam/resources/META-INF/persistence-dev.xml
===================================================================
--- demos/seam/resources/META-INF/persistence-dev.xml 2008-10-21 17:23:43 UTC (rev 181)
+++ demos/seam/resources/META-INF/persistence-dev.xml 2008-10-21 17:27:02 UTC (rev 182)
@@ -13,8 +13,8 @@
<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.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" />
Modified: demos/seam/resources/envers_seam_demo-dev-ds.xml
===================================================================
--- demos/seam/resources/envers_seam_demo-dev-ds.xml 2008-10-21 17:23:43 UTC (rev 181)
+++ demos/seam/resources/envers_seam_demo-dev-ds.xml 2008-10-21 17:27:02 UTC (rev 182)
@@ -7,15 +7,15 @@
<local-tx-datasource>
<jndi-name>envers_seam_demoDatasource</jndi-name>
- <!--<connection-url>jdbc:hsqldb:${jboss.server.data.dir}${/}envers</connection-url>
+ <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>-->
+ <password></password>
- <connection-url>jdbc:mysql:///hibernate_tests?useUnicode=true&characterEncoding=UTF-8</connection-url>
+ <!--<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>
+ <password></password>-->
</local-tx-datasource>
</datasources>
16 years
JBoss Envers SVN: r181 - in demos/seam: resources and 5 other directories.
by jboss-envers-commits@lists.jboss.org
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/VersionsReader.html">VersionsReader</a>
interface, which in this application is managed by the
<a href="http://fisheye.jboss.org/browse/envers/demos/seam/src/action/org/jboss/en...">VersionsReaderManager</a>
- 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">
16 years
JBoss Envers SVN: r180 - trunk/src/test/org/jboss/envers/test/various.
by jboss-envers-commits@lists.jboss.org
Author: adamw
Date: 2008-10-21 09:16:25 -0400 (Tue, 21 Oct 2008)
New Revision: 180
Added:
trunk/src/test/org/jboss/envers/test/various/Address.java
trunk/src/test/org/jboss/envers/test/various/Person.java
Modified:
trunk/src/test/org/jboss/envers/test/various/HsqlTest.java
Log:
Test update
Copied: trunk/src/test/org/jboss/envers/test/various/Address.java (from rev 173, trunk/src/demo/org/jboss/envers/demo/Address.java)
===================================================================
--- trunk/src/test/org/jboss/envers/test/various/Address.java (rev 0)
+++ trunk/src/test/org/jboss/envers/test/various/Address.java 2008-10-21 13:16:25 UTC (rev 180)
@@ -0,0 +1,113 @@
+/*
+ * Envers. http://www.jboss.org/envers
+ *
+ * Copyright 2008 Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT A WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License, v.2.1 along with this distribution; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ *
+ * Red Hat Author(s): Adam Warski
+ */
+package org.jboss.envers.test.various;
+
+import org.jboss.envers.Versioned;
+
+import javax.persistence.*;
+import java.util.Set;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+@Entity
+public class Address {
+ @Id
+ @GeneratedValue
+ private int id;
+
+ @Versioned
+ private String streetName;
+
+ @Versioned
+ private Integer houseNumber;
+
+ @Versioned
+ private Integer flatNumber;
+
+ @Versioned
+ @OneToMany(mappedBy = "address")
+ private Set<Person> persons;
+
+ public int getId() {
+ return id;
+ }
+
+ public void setId(int id) {
+ this.id = id;
+ }
+
+ public String getStreetName() {
+ return streetName;
+ }
+
+ public void setStreetName(String streetName) {
+ this.streetName = streetName;
+ }
+
+ public Integer getHouseNumber() {
+ return houseNumber;
+ }
+
+ public void setHouseNumber(Integer houseNumber) {
+ this.houseNumber = houseNumber;
+ }
+
+ public Integer getFlatNumber() {
+ return flatNumber;
+ }
+
+ public void setFlatNumber(Integer flatNumber) {
+ this.flatNumber = flatNumber;
+ }
+
+ public Set<Person> getPersons() {
+ return persons;
+ }
+
+ public void setPersons(Set<Person> persons) {
+ this.persons = persons;
+ }
+
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (!(o instanceof Address)) return false;
+
+ Address address = (Address) o;
+
+ if (id != address.id) return false;
+ if (flatNumber != null ? !flatNumber.equals(address.flatNumber) : address.flatNumber != null) return false;
+ if (houseNumber != null ? !houseNumber.equals(address.houseNumber) : address.houseNumber != null) return false;
+ if (streetName != null ? !streetName.equals(address.streetName) : address.streetName != null) return false;
+
+ return true;
+ }
+
+ public int hashCode() {
+ int result;
+ result = id;
+ result = 31 * result + (streetName != null ? streetName.hashCode() : 0);
+ result = 31 * result + (houseNumber != null ? houseNumber.hashCode() : 0);
+ result = 31 * result + (flatNumber != null ? flatNumber.hashCode() : 0);
+ return result;
+ }
+}
\ No newline at end of file
Property changes on: trunk/src/test/org/jboss/envers/test/various/Address.java
___________________________________________________________________
Name: svn:mergeinfo
+
Modified: trunk/src/test/org/jboss/envers/test/various/HsqlTest.java
===================================================================
--- trunk/src/test/org/jboss/envers/test/various/HsqlTest.java 2008-10-21 13:00:23 UTC (rev 179)
+++ trunk/src/test/org/jboss/envers/test/various/HsqlTest.java 2008-10-21 13:16:25 UTC (rev 180)
@@ -1,7 +1,5 @@
package org.jboss.envers.test.various;
-import org.jboss.envers.demo.Person;
-import org.jboss.envers.demo.Address;
import org.hibernate.Session;
import javax.persistence.EntityManagerFactory;
Copied: trunk/src/test/org/jboss/envers/test/various/Person.java (from rev 173, trunk/src/demo/org/jboss/envers/demo/Person.java)
===================================================================
--- trunk/src/test/org/jboss/envers/test/various/Person.java (rev 0)
+++ trunk/src/test/org/jboss/envers/test/various/Person.java 2008-10-21 13:16:25 UTC (rev 180)
@@ -0,0 +1,99 @@
+/*
+ * Envers. http://www.jboss.org/envers
+ *
+ * Copyright 2008 Red Hat Middleware, LLC. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT A WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License, v.2.1 along with this distribution; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ *
+ * Red Hat Author(s): Adam Warski
+ */
+package org.jboss.envers.test.various;
+
+import org.jboss.envers.Versioned;
+
+import javax.persistence.*;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+@Entity
+public class Person {
+ @Id
+ @GeneratedValue
+ private int id;
+
+ @Versioned
+ private String name;
+
+ @Versioned
+ private String surname;
+
+ @Versioned
+ @ManyToOne
+ private Address address;
+
+ public int getId() {
+ return id;
+ }
+
+ public void setId(int id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getSurname() {
+ return surname;
+ }
+
+ public void setSurname(String surname) {
+ this.surname = surname;
+ }
+
+ public Address getAddress() {
+ return address;
+ }
+
+ public void setAddress(Address address) {
+ this.address = address;
+ }
+
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (!(o instanceof Person)) return false;
+
+ Person person = (Person) o;
+
+ if (id != person.id) return false;
+ if (name != null ? !name.equals(person.name) : person.name != null) return false;
+ if (surname != null ? !surname.equals(person.surname) : person.surname != null) return false;
+
+ return true;
+ }
+
+ public int hashCode() {
+ int result;
+ result = id;
+ result = 31 * result + (name != null ? name.hashCode() : 0);
+ result = 31 * result + (surname != null ? surname.hashCode() : 0);
+ return result;
+ }
+}
\ No newline at end of file
Property changes on: trunk/src/test/org/jboss/envers/test/various/Person.java
___________________________________________________________________
Name: svn:mergeinfo
+
16 years
JBoss Envers SVN: r179 - trunk/src/test/org/jboss/envers/test/various.
by jboss-envers-commits@lists.jboss.org
Author: adamw
Date: 2008-10-21 09:00:23 -0400 (Tue, 21 Oct 2008)
New Revision: 179
Modified:
trunk/src/test/org/jboss/envers/test/various/HsqlTest.java
Log:
Test update
Modified: trunk/src/test/org/jboss/envers/test/various/HsqlTest.java
===================================================================
--- trunk/src/test/org/jboss/envers/test/various/HsqlTest.java 2008-10-13 18:02:35 UTC (rev 178)
+++ trunk/src/test/org/jboss/envers/test/various/HsqlTest.java 2008-10-21 13:00:23 UTC (rev 179)
@@ -66,6 +66,8 @@
Both queries work from HSQL console
(to run: java -cp hsqldb.jar org.hsqldb.util.DatabaseManager -user sa -url jdbc:hsqldb:file:/tmp/_versions_demo.db)
+
+ TODO: post hibernate bug
*/
public static void main(String[] argv) {
16 years
JBoss Envers SVN: r178 - in trunk/src/main/org/jboss/envers: configuration/metadata and 2 other directories.
by jboss-envers-commits@lists.jboss.org
Author: adamw
Date: 2008-10-13 14:02:35 -0400 (Mon, 13 Oct 2008)
New Revision: 178
Modified:
trunk/src/main/org/jboss/envers/configuration/GlobalConfiguration.java
trunk/src/main/org/jboss/envers/configuration/metadata/CollectionMetadataGenerator.java
trunk/src/main/org/jboss/envers/configuration/metadata/QueryGeneratorBuilder.java
trunk/src/main/org/jboss/envers/configuration/metadata/VersionsMetadataGenerator.java
trunk/src/main/org/jboss/envers/entities/mapper/relation/query/OneVersionsEntityQueryGenerator.java
trunk/src/main/org/jboss/envers/entities/mapper/relation/query/QueryGeneratorTools.java
trunk/src/main/org/jboss/envers/entities/mapper/relation/query/ThreeEntityQueryGenerator.java
trunk/src/main/org/jboss/envers/entities/mapper/relation/query/TwoEntityQueryGenerator.java
trunk/src/main/org/jboss/envers/query/impl/EntitiesAtRevisionQuery.java
Log:
ENVERS-57: workaround for HSQLDB
Modified: trunk/src/main/org/jboss/envers/configuration/GlobalConfiguration.java
===================================================================
--- trunk/src/main/org/jboss/envers/configuration/GlobalConfiguration.java 2008-10-13 14:43:11 UTC (rev 177)
+++ trunk/src/main/org/jboss/envers/configuration/GlobalConfiguration.java 2008-10-13 18:02:35 UTC (rev 178)
@@ -39,6 +39,14 @@
// Should the optimistic locking property of an entity be considered unversioned
private final boolean unversionedOptimisticLockingField;
+ /*
+ Which operator to use in correlated subqueries (when we want a property to be equal to the result of
+ a correlated subquery, for example: e.p <operator> (select max(e2.p) where e2.p2 = e.p2 ...).
+ Normally, this should be "=". However, HSQLDB has an issue related to that, so as a workaround,
+ "in" is used. See {@link org.jboss.envers.test.various.HsqlTest}.
+ */
+ private final String correlatedSubqueryOperator;
+
public GlobalConfiguration(Properties properties) {
String generateRevisionsForCollectionsStr = properties.getProperty("org.jboss.envers.revisionOnCollectionChange",
"true");
@@ -51,6 +59,9 @@
String ignoreOptimisticLockingPropertyStr = properties.getProperty("org.jboss.envers.unversionedOptimisticLockingField",
"false");
unversionedOptimisticLockingField = Boolean.parseBoolean(ignoreOptimisticLockingPropertyStr);
+
+ correlatedSubqueryOperator = "org.hibernate.dialect.HSQLDialect".equals(
+ properties.getProperty("hibernate.dialect")) ? "in" : "=";
}
public boolean isGenerateRevisionsForCollections() {
@@ -64,4 +75,8 @@
public boolean isUnversionedOptimisticLockingField() {
return unversionedOptimisticLockingField;
}
+
+ public String getCorrelatedSubqueryOperator() {
+ return correlatedSubqueryOperator;
+ }
}
Modified: trunk/src/main/org/jboss/envers/configuration/metadata/CollectionMetadataGenerator.java
===================================================================
--- trunk/src/main/org/jboss/envers/configuration/metadata/CollectionMetadataGenerator.java 2008-10-13 14:43:11 UTC (rev 177)
+++ trunk/src/main/org/jboss/envers/configuration/metadata/CollectionMetadataGenerator.java 2008-10-13 18:02:35 UTC (rev 178)
@@ -154,8 +154,9 @@
MiddleComponentData indexComponentData = addIndex(null, null);
// Generating the query generator - it should read directly from the related entity.
- RelationQueryGenerator queryGenerator = new OneVersionsEntityQueryGenerator(mainGenerator.getVerEntCfg(),
- referencingIdData, referencedEntityName, referencedIdMapping.getIdMapper());
+ RelationQueryGenerator queryGenerator = new OneVersionsEntityQueryGenerator(mainGenerator.getGlobalCfg(),
+ mainGenerator.getVerEntCfg(), referencingIdData, referencedEntityName,
+ referencedIdMapping.getIdMapper());
// Creating common mapper data.
CommonCollectionMapperData commonCollectionMapperData = new CommonCollectionMapperData(
@@ -256,8 +257,8 @@
// Creating a query generator builder, to which additional id data will be added, in case this collection
// references some entities (either from the element or index). At the end, this will be used to build
// a query generator to read the raw data collection from the middle table.
- QueryGeneratorBuilder queryGeneratorBuilder = new QueryGeneratorBuilder(mainGenerator.getVerEntCfg(),
- referencingIdData, versionsMiddleEntityName);
+ QueryGeneratorBuilder queryGeneratorBuilder = new QueryGeneratorBuilder(mainGenerator.getGlobalCfg(),
+ mainGenerator.getVerEntCfg(), referencingIdData, versionsMiddleEntityName);
// Adding the XML mapping for the referencing entity, if the relation isn't inverse.
if (middleEntityXml != null) {
@@ -317,7 +318,6 @@
return new MiddleComponentData(new MiddleMapKeyPropertyComponentMapper(mapKey), currentIndex);
}
}
- // TODO: @MapKeyManyToMany
} else {
// No index - creating a dummy mapper.
return new MiddleComponentData(new MiddleDummyComponentMapper(), 0);
Modified: trunk/src/main/org/jboss/envers/configuration/metadata/QueryGeneratorBuilder.java
===================================================================
--- trunk/src/main/org/jboss/envers/configuration/metadata/QueryGeneratorBuilder.java 2008-10-13 14:43:11 UTC (rev 177)
+++ trunk/src/main/org/jboss/envers/configuration/metadata/QueryGeneratorBuilder.java 2008-10-13 18:02:35 UTC (rev 178)
@@ -30,6 +30,7 @@
import org.jboss.envers.entities.mapper.relation.query.ThreeEntityQueryGenerator;
import org.jboss.envers.entities.mapper.relation.query.TwoEntityQueryGenerator;
import org.jboss.envers.configuration.VersionsEntitiesConfiguration;
+import org.jboss.envers.configuration.GlobalConfiguration;
import java.util.List;
import java.util.ArrayList;
@@ -40,13 +41,15 @@
* @author Adam Warski (adam at warski dot org)
*/
public final class QueryGeneratorBuilder {
+ private final GlobalConfiguration globalCfg;
private final VersionsEntitiesConfiguration verEntCfg;
private final MiddleIdData referencingIdData;
private final String versionsMiddleEntityName;
private final List<MiddleIdData> idDatas;
- QueryGeneratorBuilder(VersionsEntitiesConfiguration verEntCfg, MiddleIdData referencingIdData,
- String versionsMiddleEntityName) {
+ QueryGeneratorBuilder(GlobalConfiguration globalCfg, VersionsEntitiesConfiguration verEntCfg,
+ MiddleIdData referencingIdData, String versionsMiddleEntityName) {
+ this.globalCfg = globalCfg;
this.verEntCfg = verEntCfg;
this.referencingIdData = referencingIdData;
this.versionsMiddleEntityName = versionsMiddleEntityName;
@@ -63,10 +66,10 @@
return new OneEntityQueryGenerator(verEntCfg, versionsMiddleEntityName, referencingIdData,
componentDatas);
} else if (idDatas.size() == 1) {
- return new TwoEntityQueryGenerator(verEntCfg, versionsMiddleEntityName, referencingIdData,
+ return new TwoEntityQueryGenerator(globalCfg, verEntCfg, versionsMiddleEntityName, referencingIdData,
idDatas.get(0), componentDatas);
} else if (idDatas.size() == 2) {
- return new ThreeEntityQueryGenerator(verEntCfg, versionsMiddleEntityName, referencingIdData,
+ return new ThreeEntityQueryGenerator(globalCfg, verEntCfg, versionsMiddleEntityName, referencingIdData,
idDatas.get(0), idDatas.get(1), componentDatas);
} else {
throw new IllegalStateException("Illegal number of related entities.");
Modified: trunk/src/main/org/jboss/envers/configuration/metadata/VersionsMetadataGenerator.java
===================================================================
--- trunk/src/main/org/jboss/envers/configuration/metadata/VersionsMetadataGenerator.java 2008-10-13 14:43:11 UTC (rev 177)
+++ trunk/src/main/org/jboss/envers/configuration/metadata/VersionsMetadataGenerator.java 2008-10-13 18:02:35 UTC (rev 178)
@@ -360,6 +360,10 @@
return cfg;
}
+ GlobalConfiguration getGlobalCfg() {
+ return globalCfg;
+ }
+
VersionsEntitiesConfiguration getVerEntCfg() {
return verEntCfg;
}
Modified: trunk/src/main/org/jboss/envers/entities/mapper/relation/query/OneVersionsEntityQueryGenerator.java
===================================================================
--- trunk/src/main/org/jboss/envers/entities/mapper/relation/query/OneVersionsEntityQueryGenerator.java 2008-10-13 14:43:11 UTC (rev 177)
+++ trunk/src/main/org/jboss/envers/entities/mapper/relation/query/OneVersionsEntityQueryGenerator.java 2008-10-13 18:02:35 UTC (rev 178)
@@ -27,6 +27,7 @@
import org.jboss.envers.entities.mapper.id.IdMapper;
import org.jboss.envers.entities.mapper.relation.MiddleIdData;
import org.jboss.envers.configuration.VersionsEntitiesConfiguration;
+import org.jboss.envers.configuration.GlobalConfiguration;
import org.jboss.envers.reader.VersionsReaderImplementor;
import org.jboss.envers.RevisionType;
import org.jboss.envers.tools.query.QueryBuilder;
@@ -43,8 +44,9 @@
private final String queryString;
private final MiddleIdData referencingIdData;
- public OneVersionsEntityQueryGenerator(VersionsEntitiesConfiguration verEntCfg, MiddleIdData referencingIdData,
- String referencedEntityName, IdMapper referencedIdMapper) {
+ public OneVersionsEntityQueryGenerator(GlobalConfiguration globalCfg, VersionsEntitiesConfiguration verEntCfg,
+ MiddleIdData referencingIdData, String referencedEntityName,
+ IdMapper referencedIdMapper) {
this.referencingIdData = referencingIdData;
/*
@@ -84,7 +86,7 @@
"e." + originalIdPropertyName, "e2." + originalIdPropertyName);
// e.revision = (SELECT max(...) ...)
- rootParameters.addWhere(revisionPropertyPath, false, "=", maxERevQb);
+ rootParameters.addWhere(revisionPropertyPath, false, globalCfg.getCorrelatedSubqueryOperator(), maxERevQb);
// e.revision_type != DEL
rootParameters.addWhereWithNamedParam(verEntCfg.getRevisionTypePropName(), false, "!=", "delrevisiontype");
Modified: trunk/src/main/org/jboss/envers/entities/mapper/relation/query/QueryGeneratorTools.java
===================================================================
--- trunk/src/main/org/jboss/envers/entities/mapper/relation/query/QueryGeneratorTools.java 2008-10-13 14:43:11 UTC (rev 177)
+++ trunk/src/main/org/jboss/envers/entities/mapper/relation/query/QueryGeneratorTools.java 2008-10-13 18:02:35 UTC (rev 178)
@@ -27,13 +27,14 @@
import org.jboss.envers.tools.query.Parameters;
import org.jboss.envers.entities.mapper.relation.MiddleIdData;
import org.jboss.envers.entities.mapper.relation.MiddleComponentData;
+import org.jboss.envers.configuration.GlobalConfiguration;
/**
* @author Adam Warski (adam at warski dot org)
*/
public class QueryGeneratorTools {
- public static void addEntityAtRevision(QueryBuilder qb, Parameters rootParameters, MiddleIdData idData,
- String revisionPropertyPath, String originalIdPropertyName,
+ public static void addEntityAtRevision(GlobalConfiguration globalCfg, QueryBuilder qb, Parameters rootParameters,
+ MiddleIdData idData, String revisionPropertyPath, String originalIdPropertyName,
String alias1, String alias2) {
// SELECT max(e.revision) FROM versionsReferencedEntity e2
QueryBuilder maxERevQb = qb.newSubQueryBuilder(idData.getVersionsEntityName(), alias2);
@@ -47,7 +48,7 @@
alias1 + "." + originalIdPropertyName, alias2 +"." + originalIdPropertyName);
// e.revision = (SELECT max(...) ...)
- rootParameters.addWhere("e." + revisionPropertyPath, false, "=", maxERevQb);
+ rootParameters.addWhere("e." + revisionPropertyPath, false, globalCfg.getCorrelatedSubqueryOperator(), maxERevQb);
}
public static void addAssociationAtRevision(QueryBuilder qb, Parameters rootParameters,
Modified: trunk/src/main/org/jboss/envers/entities/mapper/relation/query/ThreeEntityQueryGenerator.java
===================================================================
--- trunk/src/main/org/jboss/envers/entities/mapper/relation/query/ThreeEntityQueryGenerator.java 2008-10-13 14:43:11 UTC (rev 177)
+++ trunk/src/main/org/jboss/envers/entities/mapper/relation/query/ThreeEntityQueryGenerator.java 2008-10-13 18:02:35 UTC (rev 178)
@@ -27,6 +27,7 @@
import org.jboss.envers.entities.mapper.relation.MiddleIdData;
import org.jboss.envers.entities.mapper.relation.MiddleComponentData;
import org.jboss.envers.configuration.VersionsEntitiesConfiguration;
+import org.jboss.envers.configuration.GlobalConfiguration;
import org.jboss.envers.reader.VersionsReaderImplementor;
import org.jboss.envers.RevisionType;
import org.jboss.envers.tools.query.QueryBuilder;
@@ -43,7 +44,8 @@
private final String queryString;
private final MiddleIdData referencingIdData;
- public ThreeEntityQueryGenerator(VersionsEntitiesConfiguration verEntCfg,
+ public ThreeEntityQueryGenerator(GlobalConfiguration globalCfg,
+ VersionsEntitiesConfiguration verEntCfg,
String versionsMiddleEntityName,
MiddleIdData referencingIdData,
MiddleIdData referencedIdData,
@@ -97,11 +99,11 @@
referencingIdData.getPrefixedMapper().addNamedIdEqualsToQuery(rootParameters, originalIdPropertyName, true);
// e.revision = (SELECT max(...) ...)
- QueryGeneratorTools.addEntityAtRevision(qb, rootParameters, referencedIdData, revisionPropertyPath,
+ QueryGeneratorTools.addEntityAtRevision(globalCfg, qb, rootParameters, referencedIdData, revisionPropertyPath,
originalIdPropertyName, "e", "e2");
// f.revision = (SELECT max(...) ...)
- QueryGeneratorTools.addEntityAtRevision(qb, rootParameters, indexIdData, revisionPropertyPath,
+ QueryGeneratorTools.addEntityAtRevision(globalCfg, qb, rootParameters, indexIdData, revisionPropertyPath,
originalIdPropertyName, "f", "f2");
// ee.revision = (SELECT max(...) ...)
Modified: trunk/src/main/org/jboss/envers/entities/mapper/relation/query/TwoEntityQueryGenerator.java
===================================================================
--- trunk/src/main/org/jboss/envers/entities/mapper/relation/query/TwoEntityQueryGenerator.java 2008-10-13 14:43:11 UTC (rev 177)
+++ trunk/src/main/org/jboss/envers/entities/mapper/relation/query/TwoEntityQueryGenerator.java 2008-10-13 18:02:35 UTC (rev 178)
@@ -27,6 +27,7 @@
import org.jboss.envers.entities.mapper.relation.MiddleIdData;
import org.jboss.envers.entities.mapper.relation.MiddleComponentData;
import org.jboss.envers.configuration.VersionsEntitiesConfiguration;
+import org.jboss.envers.configuration.GlobalConfiguration;
import org.jboss.envers.reader.VersionsReaderImplementor;
import org.jboss.envers.RevisionType;
import org.jboss.envers.tools.query.QueryBuilder;
@@ -43,7 +44,8 @@
private final String queryString;
private final MiddleIdData referencingIdData;
- public TwoEntityQueryGenerator(VersionsEntitiesConfiguration verEntCfg,
+ public TwoEntityQueryGenerator(GlobalConfiguration globalCfg,
+ VersionsEntitiesConfiguration verEntCfg,
String versionsMiddleEntityName,
MiddleIdData referencingIdData,
MiddleIdData referencedIdData,
@@ -86,7 +88,7 @@
referencingIdData.getPrefixedMapper().addNamedIdEqualsToQuery(rootParameters, originalIdPropertyName, true);
// e.revision = (SELECT max(...) ...)
- QueryGeneratorTools.addEntityAtRevision(qb, rootParameters, referencedIdData, revisionPropertyPath,
+ QueryGeneratorTools.addEntityAtRevision(globalCfg, qb, rootParameters, referencedIdData, revisionPropertyPath,
originalIdPropertyName, "e", "e2");
// ee.revision = (SELECT max(...) ...)
Modified: trunk/src/main/org/jboss/envers/query/impl/EntitiesAtRevisionQuery.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/impl/EntitiesAtRevisionQuery.java 2008-10-13 14:43:11 UTC (rev 177)
+++ trunk/src/main/org/jboss/envers/query/impl/EntitiesAtRevisionQuery.java 2008-10-13 18:02:35 UTC (rev 178)
@@ -72,8 +72,8 @@
// e.revision_type != DEL AND
qb.getRootParameters().addWhereWithParam(verEntCfg.getRevisionTypePropName(), "<>", RevisionType.DEL);
- // e.revision = (SELECT max(...) ...)
- qb.getRootParameters().addWhere(revisionPropertyPath, "=", maxRevQb);
+ // e.revision = (SELECT max(...) ...)
+ qb.getRootParameters().addWhere(revisionPropertyPath, verCfg.getGlobalCfg().getCorrelatedSubqueryOperator(), maxRevQb);
// all specified conditions
for (VersionsCriterion criterion : criterions) {
criterion.addToQuery(verCfg, entityName, qb, qb.getRootParameters());
16 years
JBoss Envers SVN: r177 - in trunk/src: main/org/jboss/envers/configuration and 2 other directories.
by jboss-envers-commits@lists.jboss.org
Author: adamw
Date: 2008-10-13 10:43:11 -0400 (Mon, 13 Oct 2008)
New Revision: 177
Added:
trunk/src/test/org/jboss/envers/test/entities/reventity/CustomPropertyAccessRevEntity.java
trunk/src/test/org/jboss/envers/test/integration/reventity/CustomPropertyAccess.java
Modified:
trunk/src/main/org/jboss/envers/RevisionNumber.java
trunk/src/main/org/jboss/envers/RevisionTimestamp.java
trunk/src/main/org/jboss/envers/configuration/RevisionInfoConfiguration.java
Log:
ENVERS-58: revision name and timestamp annotations on a custom revision entity also allowed on getter methods + test
Modified: trunk/src/main/org/jboss/envers/RevisionNumber.java
===================================================================
--- trunk/src/main/org/jboss/envers/RevisionNumber.java 2008-10-13 12:27:53 UTC (rev 176)
+++ trunk/src/main/org/jboss/envers/RevisionNumber.java 2008-10-13 14:43:11 UTC (rev 177)
@@ -32,8 +32,9 @@
* of numbers. The value of this property won't be set by Envers. In most cases, this should be
* an auto-generated database-assigned primary id.
* @author Adam Warski (adam at warski dot org)
+ * @author Sanne Grinovero
*/
@Retention(RetentionPolicy.RUNTIME)
-(a)Target(ElementType.FIELD)
+(a)Target({ElementType.METHOD, ElementType.FIELD})
public @interface RevisionNumber {
}
Modified: trunk/src/main/org/jboss/envers/RevisionTimestamp.java
===================================================================
--- trunk/src/main/org/jboss/envers/RevisionTimestamp.java 2008-10-13 12:27:53 UTC (rev 176)
+++ trunk/src/main/org/jboss/envers/RevisionTimestamp.java 2008-10-13 14:43:11 UTC (rev 177)
@@ -30,8 +30,9 @@
* Marks a property which will hold the timestamp of the revision in a revision entity, see
* {@link RevisionListener}. The value of this property will be automatically set by Envers.
* @author Adam Warski (adam at warski dot org)
+ * @author Sanne Grinovero
*/
@Retention(RetentionPolicy.RUNTIME)
-(a)Target(ElementType.FIELD)
+(a)Target({ElementType.METHOD, ElementType.FIELD})
public @interface RevisionTimestamp {
}
Modified: trunk/src/main/org/jboss/envers/configuration/RevisionInfoConfiguration.java
===================================================================
--- trunk/src/main/org/jboss/envers/configuration/RevisionInfoConfiguration.java 2008-10-13 12:27:53 UTC (rev 176)
+++ trunk/src/main/org/jboss/envers/configuration/RevisionInfoConfiguration.java 2008-10-13 14:43:11 UTC (rev 177)
@@ -87,14 +87,10 @@
return rev_rel_mapping;
}
- private void searchForRevisionInfoCfg(YClass clazz, YReflectionManager reflectionManager,
- MutableBoolean revisionNumberFound, MutableBoolean revisionTimestampFound) {
- YClass superclazz = clazz.getSuperclass();
- if (!"java.lang.Object".equals(superclazz.getName())) {
- searchForRevisionInfoCfg(superclazz, reflectionManager, revisionNumberFound, revisionTimestampFound);
- }
-
- for (YProperty property : clazz.getDeclaredProperties("field")) {
+ private void searchForRevisionInfoCfgInProperties(YClass clazz, YReflectionManager reflectionManager,
+ MutableBoolean revisionNumberFound, MutableBoolean revisionTimestampFound,
+ String accessType) {
+ for (YProperty property : clazz.getDeclaredProperties(accessType)) {
RevisionNumber revisionNumber = property.getAnnotation(RevisionNumber.class);
RevisionTimestamp revisionTimestamp = property.getAnnotation(RevisionTimestamp.class);
@@ -139,6 +135,19 @@
}
}
+ private void searchForRevisionInfoCfg(YClass clazz, YReflectionManager reflectionManager,
+ MutableBoolean revisionNumberFound, MutableBoolean revisionTimestampFound) {
+ YClass superclazz = clazz.getSuperclass();
+ if (!"java.lang.Object".equals(superclazz.getName())) {
+ searchForRevisionInfoCfg(superclazz, reflectionManager, revisionNumberFound, revisionTimestampFound);
+ }
+
+ searchForRevisionInfoCfgInProperties(clazz, reflectionManager, revisionNumberFound, revisionTimestampFound,
+ "field");
+ searchForRevisionInfoCfgInProperties(clazz, reflectionManager, revisionNumberFound, revisionTimestampFound,
+ "property");
+ }
+
@SuppressWarnings({"unchecked"})
public RevisionInfoConfigurationResult configure(Configuration cfg, YReflectionManager reflectionManager) {
Iterator<PersistentClass> classes = (Iterator<PersistentClass>) cfg.getClassMappings();
Copied: trunk/src/test/org/jboss/envers/test/entities/reventity/CustomPropertyAccessRevEntity.java (from rev 173, trunk/src/test/org/jboss/envers/test/entities/reventity/CustomRevEntity.java)
===================================================================
--- trunk/src/test/org/jboss/envers/test/entities/reventity/CustomPropertyAccessRevEntity.java (rev 0)
+++ trunk/src/test/org/jboss/envers/test/entities/reventity/CustomPropertyAccessRevEntity.java 2008-10-13 14:43:11 UTC (rev 177)
@@ -0,0 +1,59 @@
+package org.jboss.envers.test.entities.reventity;
+
+import org.jboss.envers.RevisionNumber;
+import org.jboss.envers.RevisionTimestamp;
+import org.jboss.envers.RevisionEntity;
+
+import javax.persistence.Id;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Entity;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+@Entity
+@RevisionEntity
+public class CustomPropertyAccessRevEntity {
+ private int customId;
+
+ private long customTimestamp;
+
+ @Id
+ @GeneratedValue
+ @RevisionNumber
+ public int getCustomId() {
+ return customId;
+ }
+
+ public void setCustomId(int customId) {
+ this.customId = customId;
+ }
+
+ @RevisionTimestamp
+ public long getCustomTimestamp() {
+ return customTimestamp;
+ }
+
+ public void setCustomTimestamp(long customTimestamp) {
+ this.customTimestamp = customTimestamp;
+ }
+
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (!(o instanceof CustomPropertyAccessRevEntity)) return false;
+
+ CustomPropertyAccessRevEntity that = (CustomPropertyAccessRevEntity) o;
+
+ if (customId != that.customId) return false;
+ if (customTimestamp != that.customTimestamp) return false;
+
+ return true;
+ }
+
+ public int hashCode() {
+ int result;
+ result = customId;
+ result = 31 * result + (int) (customTimestamp ^ (customTimestamp >>> 32));
+ return result;
+ }
+}
\ No newline at end of file
Property changes on: trunk/src/test/org/jboss/envers/test/entities/reventity/CustomPropertyAccessRevEntity.java
___________________________________________________________________
Name: svn:mergeinfo
+
Copied: trunk/src/test/org/jboss/envers/test/integration/reventity/CustomPropertyAccess.java (from rev 174, trunk/src/test/org/jboss/envers/test/integration/reventity/Custom.java)
===================================================================
--- trunk/src/test/org/jboss/envers/test/integration/reventity/CustomPropertyAccess.java (rev 0)
+++ trunk/src/test/org/jboss/envers/test/integration/reventity/CustomPropertyAccess.java 2008-10-13 14:43:11 UTC (rev 177)
@@ -0,0 +1,111 @@
+package org.jboss.envers.test.integration.reventity;
+
+import org.jboss.envers.test.AbstractEntityTest;
+import org.jboss.envers.test.entities.StrTestEntity;
+import org.jboss.envers.test.entities.reventity.CustomPropertyAccessRevEntity;
+import org.jboss.envers.exception.RevisionDoesNotExistException;
+import org.jboss.envers.VersionsReader;
+import org.hibernate.ejb.Ejb3Configuration;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+import javax.persistence.EntityManager;
+import java.util.Date;
+import java.util.Arrays;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+public class CustomPropertyAccess extends AbstractEntityTest {
+ private Integer id;
+ private long timestamp1;
+ private long timestamp2;
+ private long timestamp3;
+
+ public void configure(Ejb3Configuration cfg) {
+ cfg.addAnnotatedClass(StrTestEntity.class);
+ cfg.addAnnotatedClass(CustomPropertyAccessRevEntity.class);
+ }
+
+ @BeforeClass(dependsOnMethods = "init")
+ public void initData() throws InterruptedException {
+ timestamp1 = System.currentTimeMillis();
+
+ Thread.sleep(100);
+
+ // Revision 1
+ EntityManager em = getEntityManager();
+ em.getTransaction().begin();
+ StrTestEntity te = new StrTestEntity("x");
+ em.persist(te);
+ id = te.getId();
+ em.getTransaction().commit();
+
+ timestamp2 = System.currentTimeMillis();
+
+ Thread.sleep(100);
+
+ // Revision 2
+ em.getTransaction().begin();
+ te = em.find(StrTestEntity.class, id);
+ te.setStr("y");
+ em.getTransaction().commit();
+
+ timestamp3 = System.currentTimeMillis();
+ }
+
+ @Test(expectedExceptions = RevisionDoesNotExistException.class)
+ public void testTimestamps1() {
+ getVersionsReader().getRevisionNumberForDate(new Date(timestamp1));
+ }
+
+ @Test
+ public void testTimestamps() {
+ assert getVersionsReader().getRevisionNumberForDate(new Date(timestamp2)).intValue() == 1;
+ assert getVersionsReader().getRevisionNumberForDate(new Date(timestamp3)).intValue() == 2;
+ }
+
+ @Test
+ public void testDatesForRevisions() {
+ VersionsReader vr = getVersionsReader();
+ assert vr.getRevisionNumberForDate(vr.getRevisionDate(1)).intValue() == 1;
+ assert vr.getRevisionNumberForDate(vr.getRevisionDate(2)).intValue() == 2;
+ }
+
+ @Test
+ public void testRevisionsForDates() {
+ VersionsReader vr = getVersionsReader();
+
+ assert vr.getRevisionDate(vr.getRevisionNumberForDate(new Date(timestamp2))).getTime() <= timestamp2;
+ assert vr.getRevisionDate(vr.getRevisionNumberForDate(new Date(timestamp2)).intValue()+1).getTime() > timestamp2;
+
+ assert vr.getRevisionDate(vr.getRevisionNumberForDate(new Date(timestamp3))).getTime() <= timestamp3;
+ }
+
+ @Test
+ public void testFindRevision() {
+ VersionsReader vr = getVersionsReader();
+
+ long rev1Timestamp = vr.findRevision(CustomPropertyAccessRevEntity.class, 1).getCustomTimestamp();
+ assert rev1Timestamp > timestamp1;
+ assert rev1Timestamp <= timestamp2;
+
+ long rev2Timestamp = vr.findRevision(CustomPropertyAccessRevEntity.class, 2).getCustomTimestamp();
+ assert rev2Timestamp > timestamp2;
+ assert rev2Timestamp <= timestamp3;
+ }
+
+ @Test
+ public void testRevisionsCounts() {
+ assert Arrays.asList(1, 2).equals(getVersionsReader().getRevisions(StrTestEntity.class, id));
+ }
+
+ @Test
+ public void testHistoryOfId1() {
+ StrTestEntity ver1 = new StrTestEntity("x", id);
+ StrTestEntity ver2 = new StrTestEntity("y", id);
+
+ assert getVersionsReader().find(StrTestEntity.class, id, 1).equals(ver1);
+ assert getVersionsReader().find(StrTestEntity.class, id, 2).equals(ver2);
+ }
+}
\ No newline at end of file
Property changes on: trunk/src/test/org/jboss/envers/test/integration/reventity/CustomPropertyAccess.java
___________________________________________________________________
Name: svn:mergeinfo
+
16 years
JBoss Envers SVN: r176 - in trunk: src/demo/org/jboss/envers/demo and 1 other directory.
by jboss-envers-commits@lists.jboss.org
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");
}
}
}
16 years