Search in sources :

Example 1 with SequenceIdRevisionEntity

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;
}
Also used : Query(javax.persistence.Query) SequenceIdRevisionEntity(org.hibernate.envers.enhanced.SequenceIdRevisionEntity) ArrayList(java.util.ArrayList) EntityManager(javax.persistence.EntityManager) RevisionType(org.hibernate.envers.RevisionType)

Example 2 with SequenceIdRevisionEntity

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));
}
Also used : SequenceIdRevisionEntity(org.hibernate.envers.enhanced.SequenceIdRevisionEntity) Test(org.junit.Test)

Example 3 with SequenceIdRevisionEntity

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());
            }
        }
    }
}
Also used : MySQL57Dialect(org.hibernate.dialect.MySQL57Dialect) MySQL5Dialect(org.hibernate.dialect.MySQL5Dialect) MariaDB53Dialect(org.hibernate.dialect.MariaDB53Dialect) SybaseASE15Dialect(org.hibernate.dialect.SybaseASE15Dialect) SequenceIdRevisionEntity(org.hibernate.envers.enhanced.SequenceIdRevisionEntity) Date(java.util.Date)

Aggregations

SequenceIdRevisionEntity (org.hibernate.envers.enhanced.SequenceIdRevisionEntity)3 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 EntityManager (javax.persistence.EntityManager)1 Query (javax.persistence.Query)1 MariaDB53Dialect (org.hibernate.dialect.MariaDB53Dialect)1 MySQL57Dialect (org.hibernate.dialect.MySQL57Dialect)1 MySQL5Dialect (org.hibernate.dialect.MySQL5Dialect)1 SybaseASE15Dialect (org.hibernate.dialect.SybaseASE15Dialect)1 RevisionType (org.hibernate.envers.RevisionType)1 Test (org.junit.Test)1