Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5d541ae
commit 0b11cb9
Showing
5 changed files
with
188 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
.../test/java/org/hibernate/envers/test/integration/naming/quotation/QuotedFieldsEntity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package org.hibernate.envers.test.integration.naming.quotation; | ||
|
||
import org.hibernate.envers.Audited; | ||
|
||
import javax.persistence.*; | ||
|
||
/** | ||
* @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com) | ||
*/ | ||
@Entity | ||
public class QuotedFieldsEntity { | ||
@Id | ||
@GeneratedValue | ||
@Column(name = "`id#`") | ||
private Long id; | ||
|
||
@Column(name = "`#data1`") | ||
@Audited | ||
private String data1; | ||
|
||
@Column(name = "`#data2`") | ||
@Audited | ||
private Integer data2; | ||
|
||
public QuotedFieldsEntity() { | ||
} | ||
|
||
public QuotedFieldsEntity(String data1, Integer data2) { | ||
this.data1 = data1; | ||
this.data2 = data2; | ||
} | ||
|
||
public QuotedFieldsEntity(Long id, String data1, Integer data2) { | ||
this.id = id; | ||
this.data1 = data1; | ||
this.data2 = data2; | ||
} | ||
|
||
public Long getId() { | ||
return id; | ||
} | ||
|
||
public void setId(Long id) { | ||
this.id = id; | ||
} | ||
|
||
public String getData1() { | ||
return data1; | ||
} | ||
|
||
public void setData1(String data1) { | ||
this.data1 = data1; | ||
} | ||
|
||
public Integer getData2() { | ||
return data2; | ||
} | ||
|
||
public void setData2(Integer data2) { | ||
this.data2 = data2; | ||
} | ||
|
||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (!(o instanceof QuotedFieldsEntity)) return false; | ||
|
||
QuotedFieldsEntity that = (QuotedFieldsEntity) o; | ||
|
||
if (id != null ? !id.equals(that.id) : that.id != null) return false; | ||
if (data1 != null ? !data1.equals(that.data1) : that.data1 != null) return false; | ||
if (data2 != null ? !data2.equals(that.data2) : that.data2 != null) return false; | ||
|
||
return true; | ||
} | ||
|
||
public int hashCode() { | ||
int result; | ||
result = (id != null ? id.hashCode() : 0); | ||
result = 31 * result + (data1 != null ? data1.hashCode() : 0); | ||
result = 31 * result + (data2 != null ? data2.hashCode() : 0); | ||
return result; | ||
} | ||
} |
104 changes: 104 additions & 0 deletions
104
...rc/test/java/org/hibernate/envers/test/integration/naming/quotation/QuotedFieldsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
package org.hibernate.envers.test.integration.naming.quotation; | ||
|
||
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.junit.Test; | ||
|
||
import javax.persistence.EntityManager; | ||
import java.util.Arrays; | ||
import java.util.Iterator; | ||
|
||
/** | ||
* @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com) | ||
*/ | ||
public class QuotedFieldsTest extends AbstractEntityTest { | ||
private Long qfeId1 = null; | ||
private Long qfeId2 = null; | ||
|
||
public void configure(Ejb3Configuration cfg) { | ||
cfg.addAnnotatedClass(QuotedFieldsEntity.class); | ||
} | ||
|
||
@Test | ||
@Priority(10) | ||
public void initData() { | ||
QuotedFieldsEntity qfe1 = new QuotedFieldsEntity("data1", 1); | ||
QuotedFieldsEntity qfe2 = new QuotedFieldsEntity("data2", 2); | ||
|
||
// Revision 1 | ||
EntityManager em = getEntityManager(); | ||
em.getTransaction().begin(); | ||
em.persist(qfe1); | ||
em.persist(qfe2); | ||
em.getTransaction().commit(); | ||
|
||
// Revision 2 | ||
em.getTransaction().begin(); | ||
qfe1 = em.find(QuotedFieldsEntity.class, qfe1.getId()); | ||
qfe1.setData1("data1 changed"); | ||
em.getTransaction().commit(); | ||
|
||
// Revision 3 | ||
em.getTransaction().begin(); | ||
qfe2 = em.find(QuotedFieldsEntity.class, qfe2.getId()); | ||
qfe2.setData2(3); | ||
em.getTransaction().commit(); | ||
|
||
qfeId1 = qfe1.getId(); | ||
qfeId2 = qfe2.getId(); | ||
} | ||
|
||
@Test | ||
public void testRevisionsCounts() { | ||
assert Arrays.asList(1, 2).equals(getAuditReader().getRevisions(QuotedFieldsEntity.class, qfeId1)); | ||
assert Arrays.asList(1, 3).equals(getAuditReader().getRevisions(QuotedFieldsEntity.class, qfeId2)); | ||
} | ||
|
||
@Test | ||
public void testHistoryOfId1() { | ||
QuotedFieldsEntity ver1 = new QuotedFieldsEntity(qfeId1, "data2", 1); | ||
QuotedFieldsEntity ver2 = new QuotedFieldsEntity(qfeId1, "data1 changed", 1); | ||
|
||
assert getAuditReader().find(QuotedFieldsEntity.class, qfeId1, 1).equals(ver1); | ||
assert getAuditReader().find(QuotedFieldsEntity.class, qfeId1, 2).equals(ver2); | ||
assert getAuditReader().find(QuotedFieldsEntity.class, qfeId1, 3).equals(ver2); | ||
} | ||
|
||
@Test | ||
public void testHistoryOfId2() { | ||
QuotedFieldsEntity ver1 = new QuotedFieldsEntity(qfeId2, "data2", 2); | ||
QuotedFieldsEntity ver2 = new QuotedFieldsEntity(qfeId2, "data2", 3); | ||
|
||
assert getAuditReader().find(QuotedFieldsEntity.class, qfeId2, 1).equals(ver1); | ||
assert getAuditReader().find(QuotedFieldsEntity.class, qfeId2, 2).equals(ver1); | ||
assert getAuditReader().find(QuotedFieldsEntity.class, qfeId2, 3).equals(ver2); | ||
} | ||
|
||
@Test | ||
public void testEscapeEntityField() { | ||
Table table = getCfg().getClassMapping("org.hibernate.envers.test.integration.naming.quotation.QuotedFieldsEntity_AUD").getTable(); | ||
Column column1 = getColumnByName(table, "id#"); | ||
Column column2 = getColumnByName(table, "#data1"); | ||
Column column3 = getColumnByName(table, "#data2"); | ||
assert column1 != null; | ||
assert column2 != null; | ||
assert column3 != null; | ||
assert column1.isQuoted(); | ||
assert column2.isQuoted(); | ||
assert column3.isQuoted(); | ||
} | ||
|
||
private Column getColumnByName(Table table, String columnName) { | ||
Iterator<Column> columnIterator = table.getColumnIterator(); | ||
while (columnIterator.hasNext()) { | ||
Column column = columnIterator.next(); | ||
if (columnName.equals(column.getName())) { | ||
return column; | ||
} | ||
} | ||
return null; | ||
} | ||
} |