Author: adamw
Date: 2008-09-22 16:30:29 -0400 (Mon, 22 Sep 2008)
New Revision: 163
Added:
trunk/src/test/org/jboss/envers/test/entities/customtype/
trunk/src/test/org/jboss/envers/test/entities/customtype/Component.java
trunk/src/test/org/jboss/envers/test/entities/customtype/CompositeCustomTypeEntity.java
trunk/src/test/org/jboss/envers/test/entities/customtype/CompositeTestUserType.java
trunk/src/test/org/jboss/envers/test/entities/customtype/ParametrizedCustomTypeEntity.java
trunk/src/test/org/jboss/envers/test/entities/customtype/ParametrizedTestUserType.java
trunk/src/test/org/jboss/envers/test/integration/customtype/
trunk/src/test/org/jboss/envers/test/integration/customtype/CompositeCustom.java
trunk/src/test/org/jboss/envers/test/integration/customtype/ParametrizedCustom.java
Modified:
trunk/resources/test/testng.xml
trunk/src/main/org/jboss/envers/configuration/metadata/BasicMetadataGenerator.java
Log:
ENVERS-49: custom user type support
Modified: trunk/resources/test/testng.xml
===================================================================
--- trunk/resources/test/testng.xml 2008-09-22 18:07:02 UTC (rev 162)
+++ trunk/resources/test/testng.xml 2008-09-22 20:30:29 UTC (rev 163)
@@ -6,6 +6,7 @@
<package name="org.jboss.envers.test.integration.basic" />
<package name="org.jboss.envers.test.integration.collection"
/>
<package name="org.jboss.envers.test.integration.components"
/>
+ <package name="org.jboss.envers.test.integration.customtype"
/>
<package name="org.jboss.envers.test.integration.data" />
<package name="org.jboss.envers.test.integration.flush" />
<package name="org.jboss.envers.test.integration.ids" />
Modified:
trunk/src/main/org/jboss/envers/configuration/metadata/BasicMetadataGenerator.java
===================================================================
---
trunk/src/main/org/jboss/envers/configuration/metadata/BasicMetadataGenerator.java 2008-09-22
18:07:02 UTC (rev 162)
+++
trunk/src/main/org/jboss/envers/configuration/metadata/BasicMetadataGenerator.java 2008-09-22
20:30:29 UTC (rev 163)
@@ -1,10 +1,7 @@
package org.jboss.envers.configuration.metadata;
import org.dom4j.Element;
-import org.hibernate.mapping.Value;
-import org.hibernate.mapping.Column;
-import org.hibernate.mapping.Component;
-import org.hibernate.mapping.Property;
+import org.hibernate.mapping.*;
import org.hibernate.type.*;
import org.hibernate.util.StringHelper;
import org.jboss.envers.entities.mapper.SimpleMapperBuilder;
@@ -12,6 +9,7 @@
import org.jboss.envers.ModificationStore;
import java.util.Iterator;
+import java.util.Properties;
/**
* Generates metadata for basic properties: immutable types (including enums) and
components
@@ -19,40 +17,25 @@
*/
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 key) {
Type type = value.getType();
if (type instanceof ComponentType) {
addComponent(parent, name, value, mapper, entityName, key);
- } else if (type instanceof ImmutableType || type instanceof MutableType) {
- addSimpleValue(parent, name, value, mapper, store, key);
- } else if (type instanceof CustomType &&
"org.hibernate.type.EnumType".equals(type.getName())) {
- addEnumValue(parent, name, value, mapper, store, key);
- } else if (type instanceof CustomType &&
-
("org.hibernate.type.PrimitiveCharacterArrayClobType".equals(type.getName()) ||
-
"org.hibernate.type.StringClobType".equals(type.getName()))) {
- addSimpleValue(parent, name, value, mapper, store, key);
- } else if
("org.hibernate.type.PrimitiveByteArrayBlobType".equals(type.getClass().getName()))
{
- addSimpleValue(parent, name, value, mapper, store, key);
+ return true;
} else {
- return false;
+ return addBasicNoComponent(parent, name, value, mapper, store, key);
}
-
- return true;
}
boolean addBasicNoComponent(Element parent, String name, Value value,
SimpleMapperBuilder mapper,
- ModificationStore store, boolean key) {
+ ModificationStore store, boolean key) {
Type type = value.getType();
if (type instanceof ImmutableType || type instanceof MutableType) {
addSimpleValue(parent, name, value, mapper, store, key);
- } else if (type instanceof CustomType &&
"org.hibernate.type.EnumType".equals(type.getName())) {
- addEnumValue(parent, name, value, mapper, store, key);
- } else if (type instanceof CustomType &&
-
("org.hibernate.type.PrimitiveCharacterArrayClobType".equals(type.getName()) ||
-
"org.hibernate.type.StringClobType".equals(type.getName()))) {
- addSimpleValue(parent, name, value, mapper, store, key);
+ } else if (type instanceof CustomType || type instanceof CompositeCustomType) {
+ addCustomValue(parent, name, value, mapper, store, key);
} else if
("org.hibernate.type.PrimitiveByteArrayBlobType".equals(type.getClass().getName()))
{
addSimpleValue(parent, name, value, mapper, store, key);
} else {
@@ -64,7 +47,7 @@
@SuppressWarnings({"unchecked"})
private void addSimpleValue(Element parent, String name, Value value,
SimpleMapperBuilder mapper,
- ModificationStore store, boolean key) {
+ ModificationStore store, boolean key) {
if (parent != null) {
Element prop_mapping = MetadataTools.addProperty(parent, name,
value.getType().getName(), key);
@@ -78,25 +61,28 @@
}
@SuppressWarnings({"unchecked"})
- private void addEnumValue(Element parent, String name, Value value,
SimpleMapperBuilder mapper,
- ModificationStore store, boolean key) {
+ private void addCustomValue(Element parent, String name, Value value,
SimpleMapperBuilder mapper,
+ ModificationStore store, boolean key) {
if (parent != null) {
Element prop_mapping = MetadataTools.addProperty(parent, name,
null, key);
- CustomType propertyType = (CustomType) value.getType();
+ //CustomType propertyType = (CustomType) value.getType();
Element type_mapping = prop_mapping.addElement("type");
- type_mapping.addAttribute("name", propertyType.getName());
+ type_mapping.addAttribute("name", value.getType().getName());
- Element type_param1 = type_mapping.addElement("param");
- type_param1.addAttribute("name", "enumClass");
- type_param1.setText(propertyType.getReturnedClass().getName());
+ if (value instanceof SimpleValue) {
+ Properties typeParameters = ((SimpleValue) value).getTypeParameters();
+ if (typeParameters != null) {
+ for (java.util.Map.Entry paramKeyValue : typeParameters.entrySet())
{
+ Element type_param = type_mapping.addElement("param");
+ type_param.addAttribute("name", (String)
paramKeyValue.getKey());
+ type_param.setText((String) paramKeyValue.getValue());
+ }
+ }
+ }
- Element type_param2 = type_mapping.addElement("param");
- type_param2.addAttribute("name", "type");
- type_param2.setText(Integer.toString(propertyType.sqlTypes(null)[0]));
-
MetadataTools.addColumns(prop_mapping, (Iterator<Column>)
value.getColumnIterator());
}
@@ -113,7 +99,7 @@
@SuppressWarnings({"unchecked"})
private void addComponent(Element parent, String name, Value value,
CompositeMapperBuilder mapper,
- String entityName, boolean key) {
+ String entityName, boolean key) {
Element component_mapping = null;
Component prop_component = (Component) value;
Added: trunk/src/test/org/jboss/envers/test/entities/customtype/Component.java
===================================================================
--- trunk/src/test/org/jboss/envers/test/entities/customtype/Component.java
(rev 0)
+++ trunk/src/test/org/jboss/envers/test/entities/customtype/Component.java 2008-09-22
20:30:29 UTC (rev 163)
@@ -0,0 +1,54 @@
+package org.jboss.envers.test.entities.customtype;
+
+import java.io.Serializable;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+public class Component implements Serializable {
+ private String prop1;
+ private int prop2;
+
+ public Component(String prop1, int prop2) {
+ this.prop1 = prop1;
+ this.prop2 = prop2;
+ }
+
+ public Component() {
+ }
+
+ public String getProp1() {
+ return prop1;
+ }
+
+ public void setProp1(String prop1) {
+ this.prop1 = prop1;
+ }
+
+ public int getProp2() {
+ return prop2;
+ }
+
+ public void setProp2(int prop2) {
+ this.prop2 = prop2;
+ }
+
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (!(o instanceof Component)) return false;
+
+ Component that = (Component) o;
+
+ if (prop2 != that.prop2) return false;
+ if (prop1 != null ? !prop1.equals(that.prop1) : that.prop1 != null) return
false;
+
+ return true;
+ }
+
+ public int hashCode() {
+ int result;
+ result = (prop1 != null ? prop1.hashCode() : 0);
+ result = 31 * result + prop2;
+ return result;
+ }
+}
Added:
trunk/src/test/org/jboss/envers/test/entities/customtype/CompositeCustomTypeEntity.java
===================================================================
---
trunk/src/test/org/jboss/envers/test/entities/customtype/CompositeCustomTypeEntity.java
(rev 0)
+++
trunk/src/test/org/jboss/envers/test/entities/customtype/CompositeCustomTypeEntity.java 2008-09-22
20:30:29 UTC (rev 163)
@@ -0,0 +1,74 @@
+package org.jboss.envers.test.entities.customtype;
+
+import org.jboss.envers.Versioned;
+import org.hibernate.annotations.TypeDef;
+import org.hibernate.annotations.Type;
+import org.hibernate.annotations.Columns;
+
+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
+@TypeDef(name = "comp", typeClass = CompositeTestUserType.class)
+public class CompositeCustomTypeEntity {
+ @Id
+ @GeneratedValue
+ private Integer id;
+
+ @Versioned
+ @Type(type = "comp")
+ @Columns(columns = { @Column(name = "str"), @Column(name = "num")
})
+ private Component component;
+
+ public CompositeCustomTypeEntity() {
+ }
+
+ public CompositeCustomTypeEntity(Integer id, Component component) {
+ this.id = id;
+ this.component = component;
+ }
+
+ public Integer getId() {
+ return id;
+ }
+
+ public void setId(Integer id) {
+ this.id = id;
+ }
+
+ public Component getComponent() {
+ return component;
+ }
+
+ public void setComponent(Component component) {
+ this.component = component;
+ }
+
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (!(o instanceof CompositeCustomTypeEntity)) return false;
+
+ CompositeCustomTypeEntity that = (CompositeCustomTypeEntity) o;
+
+ if (component != null ? !component.equals(that.component) : that.component !=
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 + (component != null ? component.hashCode() : 0);
+ return result;
+ }
+
+ public String toString() {
+ return "CCTE(id = " + id + ", component = " + component +
")";
+ }
+}
Added:
trunk/src/test/org/jboss/envers/test/entities/customtype/CompositeTestUserType.java
===================================================================
--- trunk/src/test/org/jboss/envers/test/entities/customtype/CompositeTestUserType.java
(rev 0)
+++
trunk/src/test/org/jboss/envers/test/entities/customtype/CompositeTestUserType.java 2008-09-22
20:30:29 UTC (rev 163)
@@ -0,0 +1,117 @@
+package org.jboss.envers.test.entities.customtype;
+
+import org.hibernate.HibernateException;
+import org.hibernate.Hibernate;
+import org.hibernate.usertype.CompositeUserType;
+import org.hibernate.engine.SessionImplementor;
+import org.hibernate.type.Type;
+
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.PreparedStatement;
+import java.io.Serializable;
+
+/**
+ * @author Andrew DePue
+ * @author Adam Warski (adam at warski dot org)
+ */
+public class CompositeTestUserType implements CompositeUserType {
+ public String[] getPropertyNames() {
+ return new String[] { "prop1", "prop2" };
+ }
+
+ public Type[] getPropertyTypes() {
+ return new Type[] { Hibernate.STRING, Hibernate.INTEGER };
+ }
+
+ public Object getPropertyValue(final Object component, final int property) throws
HibernateException {
+ Component comp = (Component) component;
+ if (property == 0) {
+ return comp.getProp1();
+ } else {
+ return comp.getProp2();
+ }
+ }
+
+ public void setPropertyValue(final Object component, final int property, final Object
value) throws HibernateException {
+ Component comp = (Component) component;
+ if (property == 0) {
+ comp.setProp1((String) value);
+ } else {
+ comp.setProp2((Integer) value);
+ }
+ }
+
+ public Class returnedClass() {
+ return Component.class;
+ }
+
+ public boolean equals(final Object x, final Object y) throws HibernateException {
+ //noinspection ObjectEquality
+ if (x == y) {
+ return true;
+ }
+
+ if (x == null || y == null) {
+ return false;
+ }
+
+ return x.equals(y);
+ }
+
+ public int hashCode(final Object x) throws HibernateException {
+ return x.hashCode();
+ }
+
+ public Object nullSafeGet(final ResultSet rs, final String[] names,
+ final SessionImplementor session,
+ final Object owner) throws HibernateException, SQLException
{
+ if (rs.wasNull()) {
+ return null;
+ }
+ final String prop1 = rs.getString(names[0]);
+ if (prop1 == null) {
+ return null;
+ }
+ final int prop2 = rs.getInt(names[1]);
+
+ return new Component(prop1, prop2);
+ }
+
+ public void nullSafeSet(final PreparedStatement st, final Object value,
+ final int index, final SessionImplementor session)
+ throws HibernateException, SQLException
+ {
+ if (value == null) {
+ st.setNull(index, Hibernate.STRING.sqlType());
+ st.setNull(index + 1, Hibernate.INTEGER.sqlType());
+ } else {
+ final Component comp = (Component) value;
+ st.setString(index, comp.getProp1());
+ st.setInt(index + 1, comp.getProp2());
+ }
+ }
+
+ public Object deepCopy(final Object value) throws HibernateException {
+ Component comp = (Component) value;
+ return new Component(comp.getProp1(), comp.getProp2());
+ }
+
+ public boolean isMutable() {
+ return true;
+ }
+
+ public Serializable disassemble(final Object value, final SessionImplementor session)
throws HibernateException {
+ return (Serializable) value;
+ }
+
+ public Object assemble(final Serializable cached, final SessionImplementor session,
+ final Object owner) throws HibernateException {
+ return cached;
+ }
+
+ public Object replace(Object original, Object target,
+ SessionImplementor session, Object owner) throws
HibernateException {
+ return original;
+ }
+}
\ No newline at end of file
Added:
trunk/src/test/org/jboss/envers/test/entities/customtype/ParametrizedCustomTypeEntity.java
===================================================================
---
trunk/src/test/org/jboss/envers/test/entities/customtype/ParametrizedCustomTypeEntity.java
(rev 0)
+++
trunk/src/test/org/jboss/envers/test/entities/customtype/ParametrizedCustomTypeEntity.java 2008-09-22
20:30:29 UTC (rev 163)
@@ -0,0 +1,73 @@
+package org.jboss.envers.test.entities.customtype;
+
+import org.jboss.envers.Versioned;
+import org.hibernate.annotations.TypeDef;
+import org.hibernate.annotations.Type;
+import org.hibernate.annotations.Parameter;
+
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.GeneratedValue;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+@Entity
+@TypeDef(name = "param", typeClass = ParametrizedTestUserType.class,
+ parameters = { @Parameter(name="param1", value = "x"),
@Parameter(name="param2", value = "y") })
+public class ParametrizedCustomTypeEntity {
+ @Id
+ @GeneratedValue
+ private Integer id;
+
+ @Versioned
+ @Type(type = "param")
+ private String str;
+
+ public ParametrizedCustomTypeEntity() {
+ }
+
+ public ParametrizedCustomTypeEntity(Integer id, String str) {
+ this.id = id;
+ this.str = str;
+ }
+
+ public Integer getId() {
+ return id;
+ }
+
+ public void setId(Integer id) {
+ this.id = id;
+ }
+
+ public String getStr() {
+ return str;
+ }
+
+ public void setStr(String str) {
+ this.str = str;
+ }
+
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (!(o instanceof ParametrizedCustomTypeEntity)) return false;
+
+ ParametrizedCustomTypeEntity that = (ParametrizedCustomTypeEntity) o;
+
+ if (id != null ? !id.equals(that.id) : that.id != null) return false;
+ if (str != null ? !str.equals(that.str) : that.str != null) return false;
+
+ return true;
+ }
+
+ public int hashCode() {
+ int result;
+ result = (id != null ? id.hashCode() : 0);
+ result = 31 * result + (str != null ? str.hashCode() : 0);
+ return result;
+ }
+
+ public String toString() {
+ return "PCTE(id = " + id + ", str = " + str + ")";
+ }
+}
\ No newline at end of file
Added:
trunk/src/test/org/jboss/envers/test/entities/customtype/ParametrizedTestUserType.java
===================================================================
---
trunk/src/test/org/jboss/envers/test/entities/customtype/ParametrizedTestUserType.java
(rev 0)
+++
trunk/src/test/org/jboss/envers/test/entities/customtype/ParametrizedTestUserType.java 2008-09-22
20:30:29 UTC (rev 163)
@@ -0,0 +1,92 @@
+package org.jboss.envers.test.entities.customtype;
+
+import java.io.Serializable;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.Properties;
+
+import org.hibernate.HibernateException;
+import org.hibernate.Hibernate;
+import org.hibernate.usertype.ParameterizedType;
+import org.hibernate.usertype.UserType;
+import org.hsqldb.Types;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+public class ParametrizedTestUserType implements UserType, ParameterizedType {
+ private static final int[] TYPES = new int[] { Types.VARCHAR };
+
+ private String param1;
+ private String param2;
+
+ public void setParameterValues(Properties parameters) {
+ param1 = parameters.getProperty("param1");
+ param2 = parameters.getProperty("param2");
+ }
+
+ public Class returnedClass() {
+ return String.class;
+ }
+
+ public Object nullSafeGet(ResultSet rs, String[] names, Object owner) throws
HibernateException, SQLException {
+ return Hibernate.STRING.nullSafeGet(rs, names[0]);
+ }
+
+ public void nullSafeSet(PreparedStatement st, Object value, int index) throws
HibernateException, SQLException {
+ if (value != null) {
+ String v = (String) value;
+ if (!v.startsWith(param1)) {
+ v = param1 + v;
+ }
+ if (!v.endsWith(param2)) {
+ v = v + param2;
+ }
+ Hibernate.STRING.nullSafeSet(st, v, index);
+ } else {
+ Hibernate.STRING.nullSafeSet(st, value, index);
+ }
+ }
+
+ public int[] sqlTypes() {
+ return TYPES;
+ }
+
+ public Object assemble(Serializable cached, Object owner) throws HibernateException
{
+ return cached;
+ }
+
+ public Object deepCopy(Object value) throws HibernateException {
+ return value;
+ }
+
+ public Serializable disassemble(Object value) throws HibernateException {
+ return (Serializable) value;
+ }
+
+ public boolean equals(Object x, Object y) throws HibernateException {
+ //noinspection ObjectEquality
+ if (x == y) {
+ return true;
+ }
+
+ if (x == null || y == null) {
+ return false;
+ }
+
+ return x.equals(y);
+ }
+
+ public int hashCode(Object x) throws HibernateException {
+ return x.hashCode();
+ }
+
+ public boolean isMutable() {
+ return false;
+ }
+
+ public Object replace(Object original, Object target, Object owner) throws
HibernateException {
+ return original;
+ }
+}
Copied: trunk/src/test/org/jboss/envers/test/integration/customtype/CompositeCustom.java
(from rev 154,
trunk/src/test/org/jboss/envers/test/integration/collection/StringSet.java)
===================================================================
--- trunk/src/test/org/jboss/envers/test/integration/customtype/CompositeCustom.java
(rev 0)
+++
trunk/src/test/org/jboss/envers/test/integration/customtype/CompositeCustom.java 2008-09-22
20:30:29 UTC (rev 163)
@@ -0,0 +1,76 @@
+package org.jboss.envers.test.integration.customtype;
+
+import org.jboss.envers.test.integration.AbstractEntityTest;
+import org.jboss.envers.test.entities.customtype.CompositeCustomTypeEntity;
+import org.jboss.envers.test.entities.customtype.Component;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+import org.hibernate.ejb.Ejb3Configuration;
+
+import javax.persistence.EntityManager;
+import java.util.Arrays;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+public class CompositeCustom extends AbstractEntityTest {
+ private Integer ccte_id;
+
+ public void configure(Ejb3Configuration cfg) {
+ cfg.addAnnotatedClass(CompositeCustomTypeEntity.class);
+ }
+
+ @BeforeClass(dependsOnMethods = "init")
+ public void initData() {
+ EntityManager em = getEntityManager();
+
+ CompositeCustomTypeEntity ccte = new CompositeCustomTypeEntity();
+
+ // Revision 1 (persisting 1 entity)
+ em.getTransaction().begin();
+
+ ccte.setComponent(new Component("a", 1));
+
+ em.persist(ccte);
+
+ em.getTransaction().commit();
+
+ // Revision 2 (changing the component)
+ em.getTransaction().begin();
+
+ ccte = em.find(CompositeCustomTypeEntity.class, ccte.getId());
+
+ ccte.getComponent().setProp1("b");
+
+ em.getTransaction().commit();
+
+ // Revision 3 (replacing the component)
+ em.getTransaction().begin();
+
+ ccte = em.find(CompositeCustomTypeEntity.class, ccte.getId());
+
+ ccte.setComponent(new Component("c", 3));
+
+ em.getTransaction().commit();
+
+ //
+
+ ccte_id = ccte.getId();
+ }
+
+ @Test
+ public void testRevisionsCounts() {
+ assert Arrays.asList(1, 2,
3).equals(getVersionsReader().getRevisions(CompositeCustomTypeEntity.class, ccte_id));
+ }
+
+ @Test
+ public void testHistoryOfCcte() {
+ CompositeCustomTypeEntity rev1 =
getVersionsReader().find(CompositeCustomTypeEntity.class, ccte_id, 1);
+ CompositeCustomTypeEntity rev2 =
getVersionsReader().find(CompositeCustomTypeEntity.class, ccte_id, 2);
+ CompositeCustomTypeEntity rev3 =
getVersionsReader().find(CompositeCustomTypeEntity.class, ccte_id, 3);
+
+ assert rev1.getComponent().equals(new Component("a", 1));
+ assert rev2.getComponent().equals(new Component("b", 1));
+ assert rev3.getComponent().equals(new Component("c", 3));
+ }
+}
\ No newline at end of file
Added:
trunk/src/test/org/jboss/envers/test/integration/customtype/ParametrizedCustom.java
===================================================================
--- trunk/src/test/org/jboss/envers/test/integration/customtype/ParametrizedCustom.java
(rev 0)
+++
trunk/src/test/org/jboss/envers/test/integration/customtype/ParametrizedCustom.java 2008-09-22
20:30:29 UTC (rev 163)
@@ -0,0 +1,64 @@
+package org.jboss.envers.test.integration.customtype;
+
+import org.jboss.envers.test.integration.AbstractEntityTest;
+import org.jboss.envers.test.entities.customtype.ParametrizedCustomTypeEntity;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+import org.hibernate.ejb.Ejb3Configuration;
+
+import javax.persistence.EntityManager;
+import java.util.Arrays;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+public class ParametrizedCustom extends AbstractEntityTest {
+ private Integer pcte_id;
+
+ public void configure(Ejb3Configuration cfg) {
+ cfg.addAnnotatedClass(ParametrizedCustomTypeEntity.class);
+ }
+
+ @BeforeClass(dependsOnMethods = "init")
+ public void initData() {
+ EntityManager em = getEntityManager();
+
+ ParametrizedCustomTypeEntity pcte = new ParametrizedCustomTypeEntity();
+
+ // Revision 1 (persisting 1 entity)
+ em.getTransaction().begin();
+
+ pcte.setStr("U");
+
+ em.persist(pcte);
+
+ em.getTransaction().commit();
+
+ // Revision 2 (changing the value)
+ em.getTransaction().begin();
+
+ pcte = em.find(ParametrizedCustomTypeEntity.class, pcte.getId());
+
+ pcte.setStr("V");
+
+ em.getTransaction().commit();
+
+ //
+
+ pcte_id = pcte.getId();
+ }
+
+ @Test
+ public void testRevisionsCounts() {
+ assert Arrays.asList(1,
2).equals(getVersionsReader().getRevisions(ParametrizedCustomTypeEntity.class, pcte_id));
+ }
+
+ @Test
+ public void testHistoryOfCcte() {
+ ParametrizedCustomTypeEntity rev1 =
getVersionsReader().find(ParametrizedCustomTypeEntity.class, pcte_id, 1);
+ ParametrizedCustomTypeEntity rev2 =
getVersionsReader().find(ParametrizedCustomTypeEntity.class, pcte_id, 2);
+
+ assert "xUy".equals(rev1.getStr());
+ assert "xVy".equals(rev2.getStr());
+ }
+}
\ No newline at end of file