use of org.hibernate.envers.enhanced.SequenceIdRevisionEntity in project hibernate-orm by hibernate.
the class DetachedMultipleCollectionChangeTest method getAuditJoinTableRows.
private List<AuditJoinTableInfo> getAuditJoinTableRows(String middleEntityName, String joinColumnIdName, String joinColumnIdProp, String inverseJoinColumnIdName, String inverseJoinColumnIdProp, String revProp, String revIdProp, String revTypeProp) throws Exception {
StringBuilder qryBuilder = new StringBuilder("select ");
qryBuilder.append("aud ");
qryBuilder.append(", ").append(joinColumnIdProp).append(" as joinColumnId");
qryBuilder.append(", ").append(inverseJoinColumnIdProp).append(" as inverseJoinColumnId");
qryBuilder.append(", ").append(revProp).append(" as rev");
qryBuilder.append(", ").append(revIdProp).append(" as revId");
qryBuilder.append(", ").append(revTypeProp).append(" as revType");
qryBuilder.append(" from ").append(middleEntityName).append(" aud ");
qryBuilder.append(" order by joinColumnId asc, inverseJoinColumnId asc, revId asc");
String query = qryBuilder.toString();
EntityManager em = createIsolatedEntityManager();
Query qry = em.createQuery(query);
@SuppressWarnings("unchecked") List<Object[]> auditJoinTableRows = qry.getResultList();
List<AuditJoinTableInfo> result = new ArrayList<AuditJoinTableInfo>(auditJoinTableRows.size());
for (Object[] auditJoinTableRow : auditJoinTableRows) {
Long joinColumnId = (Long) auditJoinTableRow[1];
Long inverseJoinColumnId = (Long) auditJoinTableRow[2];
SequenceIdRevisionEntity rev = (SequenceIdRevisionEntity) auditJoinTableRow[3];
RevisionType revType = (RevisionType) auditJoinTableRow[5];
AuditJoinTableInfo info = new AuditJoinTableInfo(middleEntityName, rev, revType, joinColumnIdName, joinColumnId, inverseJoinColumnIdName, inverseJoinColumnId);
result.add(info);
}
return result;
}
use of org.hibernate.envers.enhanced.SequenceIdRevisionEntity in project hibernate-orm by hibernate.
the class DetachedMultipleCollectionChangeTest method testAuditJoinTable.
@Test
public void testAuditJoinTable() throws Exception {
List<AuditJoinTableInfo> mceRe1AuditJoinTableInfos = getAuditJoinTableRows("MCE_RE1_AUD", "MCE_ID", "aud.originalId.MultipleCollectionEntity_id", "RE1_ID", "aud.originalId.refEntities1_id", "aud.originalId.REV", "aud.originalId.REV.id", "aud.REVTYPE");
List<AuditJoinTableInfo> mceRe2AuditJoinTableInfos = getAuditJoinTableRows("MCE_RE2_AUD", "MCE_ID", "aud.originalId.MultipleCollectionEntity_id", "RE2_ID", "aud.originalId.refEntities2_id", "aud.originalId.REV", "aud.originalId.REV.id", "aud.REVTYPE");
assertEquals(4, mceRe1AuditJoinTableInfos.size());
assertEquals(4, mceRe2AuditJoinTableInfos.size());
SequenceIdRevisionEntity rev2 = new SequenceIdRevisionEntity();
rev2.setId(2);
SequenceIdRevisionEntity rev3 = new SequenceIdRevisionEntity();
rev3.setId(3);
assertEquals(new AuditJoinTableInfo("MCE_RE1_AUD", rev2, RevisionType.ADD, "MCE_ID", 1L, "RE1_ID", 1L), mceRe1AuditJoinTableInfos.get(0));
assertEquals(new AuditJoinTableInfo("MCE_RE1_AUD", rev2, RevisionType.ADD, "MCE_ID", 1L, "RE1_ID", 2L), mceRe1AuditJoinTableInfos.get(1));
assertEquals(new AuditJoinTableInfo("MCE_RE1_AUD", rev3, RevisionType.DEL, "MCE_ID", 1L, "RE1_ID", 2L), mceRe1AuditJoinTableInfos.get(2));
assertEquals(new AuditJoinTableInfo("MCE_RE1_AUD", rev3, RevisionType.ADD, "MCE_ID", 1L, "RE1_ID", 3L), mceRe1AuditJoinTableInfos.get(3));
assertEquals(new AuditJoinTableInfo("MCE_RE2_AUD", rev2, RevisionType.ADD, "MCE_ID", 1L, "RE2_ID", 1L), mceRe2AuditJoinTableInfos.get(0));
assertEquals(new AuditJoinTableInfo("MCE_RE2_AUD", rev2, RevisionType.ADD, "MCE_ID", 1L, "RE2_ID", 2L), mceRe2AuditJoinTableInfos.get(1));
assertEquals(new AuditJoinTableInfo("MCE_RE2_AUD", rev3, RevisionType.DEL, "MCE_ID", 1L, "RE2_ID", 2L), mceRe2AuditJoinTableInfos.get(2));
assertEquals(new AuditJoinTableInfo("MCE_RE2_AUD", rev3, RevisionType.ADD, "MCE_ID", 1L, "RE2_ID", 3L), mceRe2AuditJoinTableInfos.get(3));
}
use of org.hibernate.envers.enhanced.SequenceIdRevisionEntity in project hibernate-orm by hibernate.
the class ValidityAuditStrategyRevEndTsTest method verifyRevEndTimeStamps.
private void verifyRevEndTimeStamps(String debugInfo, List<Map<String, Object>> revisionEntities) {
for (Map<String, Object> revisionEntity : revisionEntities) {
Date revendTimestamp = (Date) revisionEntity.get(revendTimestampColumName);
SequenceIdRevisionEntity revEnd = (SequenceIdRevisionEntity) revisionEntity.get("REVEND");
if (revendTimestamp == null) {
Assert.assertNull(revEnd);
} else {
if (getDialect() instanceof MySQL5Dialect && !(getDialect() instanceof MySQL57Dialect || getDialect() instanceof MariaDB53Dialect)) {
// MySQL5 DATETIME column type does not contain milliseconds.
// MySQL 5.7 supports milliseconds and when MySQL57InnoDBDialect is used, it is assumed that
// the column is defined as DATETIME(6).
Assert.assertEquals(revendTimestamp.getTime(), (revEnd.getTimestamp() - (revEnd.getTimestamp() % 1000)));
} else if (getDialect() instanceof SybaseASE15Dialect) {
// Sybase "DATETIME values are accurate to 1/300 second on platforms that support this level of granularity".
Assert.assertEquals(revendTimestamp.getTime() / 1000.0, revEnd.getTimestamp() / 1000.0, 1.0 / 300.0);
} else {
Assert.assertEquals(revendTimestamp.getTime(), revEnd.getTimestamp());
}
}
}
}
Aggregations