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
+