HHH-7003 - Fix and test

This commit is contained in:
Lukasz Antoniak 2012-01-28 23:27:06 +01:00
parent bfb7fc8596
commit 46b7a0d38e
5 changed files with 150 additions and 8 deletions

View File

@ -94,11 +94,11 @@ public class RevisionInfoConfiguration {
Element idProperty = MetadataTools.addNativelyGeneratedId(class_mapping, revisionInfoIdData.getName(),
revisionPropType);
MetadataTools.addColumn(idProperty, "REV", null, 0, 0, null, null, null, false);
MetadataTools.addColumn(idProperty, "REV", null, null, null, null, null, null, false);
Element timestampProperty = MetadataTools.addProperty(class_mapping, revisionInfoTimestampData.getName(),
revisionInfoTimestampType.getName(), true, false);
MetadataTools.addColumn(timestampProperty, "REVTSTMP", null, 0, 0, null, null, null, false);
MetadataTools.addColumn(timestampProperty, "REVTSTMP", null, null, null, null, null, null, false);
if (globalCfg.isTrackEntitiesChangedInRevisionEnabled()) {
generateEntityNamesTrackingTableMapping(class_mapping, "modifiedEntityNames",
@ -149,7 +149,7 @@ public class RevisionInfoConfiguration {
if (revisionPropSqlType != null) {
// Putting a fake name to make Hibernate happy. It will be replaced later anyway.
MetadataTools.addColumn(rev_rel_mapping, "*" , null, 0, 0, revisionPropSqlType, null, null, false);
MetadataTools.addColumn(rev_rel_mapping, "*" , null, null, null, revisionPropSqlType, null, null, false);
}
return rev_rel_mapping;

View File

@ -163,7 +163,7 @@ public final class AuditMetadataGenerator {
// add a column for the timestamp of the end revision
String revisionInfoTimestampSqlType = TimestampType.INSTANCE.getName();
Element timestampProperty = MetadataTools.addProperty(any_mapping, verEntCfg.getRevisionEndTimestampFieldName(), revisionInfoTimestampSqlType, true, true, false);
MetadataTools.addColumn(timestampProperty, verEntCfg.getRevisionEndTimestampFieldName(), 0, 0, 0, null, null, null);
MetadataTools.addColumn(timestampProperty, verEntCfg.getRevisionEndTimestampFieldName(), null, null, null, null, null, null);
}
}
}
@ -337,7 +337,7 @@ public final class AuditMetadataGenerator {
Element joinKey = joinElement.addElement("key");
MetadataTools.addColumns(joinKey, join.getKey().getColumnIterator());
MetadataTools.addColumn(joinKey, verEntCfg.getRevisionFieldName(), null, 0, 0, null, null, null);
MetadataTools.addColumn(joinKey, verEntCfg.getRevisionFieldName(), null, null, null, null, null, null);
}
}

View File

@ -99,7 +99,7 @@ public class MetadataTools {
Element column_mapping = parent.element("column");
if (column_mapping == null) {
return addColumn(parent, name, null, 0, 0, null, null, null);
return addColumn(parent, name, null, null, null, null, null, null);
}
if (!StringTools.isEmpty(name)) {
@ -127,10 +127,10 @@ public class MetadataTools {
if (length != null) {
column_mapping.addAttribute("length", length.toString());
}
if (scale != 0) {
if (scale != null) {
column_mapping.addAttribute("scale", Integer.toString(scale));
}
if (precision != 0) {
if (precision != null) {
column_mapping.addAttribute("precision", Integer.toString(precision));
}
if (!StringTools.isEmpty(sqlType)) {

View File

@ -0,0 +1,66 @@
package org.hibernate.envers.test.integration.basic;
import org.hibernate.ejb.Ejb3Configuration;
import org.hibernate.envers.test.AbstractEntityTest;
import org.hibernate.envers.test.Priority;
import org.hibernate.mapping.Column;
import org.hibernate.mapping.Table;
import org.hibernate.testing.TestForIssue;
import org.junit.Assert;
import org.junit.Test;
import javax.persistence.EntityManager;
import java.util.Arrays;
/**
* @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com)
*/
@TestForIssue(jiraKey = "HHH-7003")
public class ColumnScalePrecisionTest extends AbstractEntityTest {
private Table auditTable = null;
private Table originalTable = null;
private Long id = null;
public void configure(Ejb3Configuration cfg) {
cfg.addAnnotatedClass(ScalePrecisionEntity.class);
}
@Test
@Priority(10)
public void initData() {
EntityManager em = getEntityManager();
// Revision 1
em.getTransaction().begin();
ScalePrecisionEntity entity = new ScalePrecisionEntity(13.0);
em.persist(entity);
em.getTransaction().commit();
id = entity.getId();
auditTable = getCfg().getClassMapping("org.hibernate.envers.test.integration.basic.ScalePrecisionEntity_AUD").getTable();
originalTable = getCfg().getClassMapping("org.hibernate.envers.test.integration.basic.ScalePrecisionEntity").getTable();
}
@Test
public void testColumnScalePrecision() {
Column testColumn = new Column("number");
Column scalePrecisionAuditColumn = auditTable.getColumn(testColumn);
Column scalePrecisionColumn = originalTable.getColumn(testColumn);
Assert.assertNotNull(scalePrecisionAuditColumn);
Assert.assertEquals(scalePrecisionColumn.getPrecision(), scalePrecisionAuditColumn.getPrecision());
Assert.assertEquals(scalePrecisionColumn.getScale(), scalePrecisionAuditColumn.getScale());
}
@Test
public void testRevisionsCounts() {
assert Arrays.asList(1).equals(getAuditReader().getRevisions(ScalePrecisionEntity.class, id));
}
@Test
public void testHistoryOfScalePrecisionEntity() {
ScalePrecisionEntity ver1 = new ScalePrecisionEntity(13.0, id);
Assert.assertEquals(ver1, getAuditReader().find(ScalePrecisionEntity.class, id, 1));
}
}

View File

@ -0,0 +1,76 @@
package org.hibernate.envers.test.integration.basic;
import org.hibernate.envers.Audited;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import java.io.Serializable;
/**
* @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com)
*/
@Entity
@Audited
public class ScalePrecisionEntity implements Serializable {
@Id
@GeneratedValue
private Long id;
@Column(precision = 3, scale = 0)
private Double number;
public ScalePrecisionEntity() {
}
public ScalePrecisionEntity(Double number) {
this.number = number;
}
public ScalePrecisionEntity(Double number, Long id) {
this.id = id;
this.number = number;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof ScalePrecisionEntity)) return false;
ScalePrecisionEntity that = (ScalePrecisionEntity) o;
if (id != null ? !id.equals(that.id) : that.id != null) return false;
if (number != null ? !number.equals(that.number) : that.number != null) return false;
return true;
}
@Override
public int hashCode() {
int result = id != null ? id.hashCode() : 0;
result = 31 * result + (number != null ? number.hashCode() : 0);
return result;
}
@Override
public String toString() {
return "ScalePrecisionEntity(id = " + id + ", number = " + number + ")";
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public Double getNumber() {
return number;
}
public void setNumber(Double number) {
this.number = number;
}
}