use of org.hibernate.envers.internal.tools.query.QueryBuilder in project hibernate-orm by hibernate.
the class OneEntityQueryGenerator method commonQueryPart.
/**
* Compute common part for both queries.
*/
private QueryBuilder commonQueryPart(String versionsMiddleEntityName) {
// SELECT ee FROM middleEntity ee
final QueryBuilder qb = new QueryBuilder(versionsMiddleEntityName, MIDDLE_ENTITY_ALIAS);
qb.addProjection(null, MIDDLE_ENTITY_ALIAS, null, false);
// WHERE
// ee.originalId.id_ref_ing = :id_ref_ing
referencingIdData.getPrefixedMapper().addNamedIdEqualsToQuery(qb.getRootParameters(), verEntCfg.getOriginalIdPropName(), true);
return qb;
}
use of org.hibernate.envers.internal.tools.query.QueryBuilder in project hibernate-orm by hibernate.
the class ThreeEntityQueryGenerator method commonQueryPart.
/**
* Compute common part for both queries.
*/
private QueryBuilder commonQueryPart(MiddleIdData referencedIdData, MiddleIdData indexIdData, String versionsMiddleEntityName, String originalIdPropertyName) {
final String eeOriginalIdPropertyPath = MIDDLE_ENTITY_ALIAS + "." + originalIdPropertyName;
// SELECT new list(ee) FROM middleEntity ee
final QueryBuilder qb = new QueryBuilder(versionsMiddleEntityName, MIDDLE_ENTITY_ALIAS);
qb.addFrom(referencedIdData.getAuditEntityName(), REFERENCED_ENTITY_ALIAS, false);
qb.addFrom(indexIdData.getAuditEntityName(), INDEX_ENTITY_ALIAS, false);
qb.addProjection("new list", MIDDLE_ENTITY_ALIAS + ", " + REFERENCED_ENTITY_ALIAS + ", " + INDEX_ENTITY_ALIAS, null, false);
// WHERE
final Parameters rootParameters = qb.getRootParameters();
// ee.id_ref_ed = e.id_ref_ed
referencedIdData.getPrefixedMapper().addIdsEqualToQuery(rootParameters, eeOriginalIdPropertyPath, referencedIdData.getOriginalMapper(), REFERENCED_ENTITY_ALIAS + "." + originalIdPropertyName);
// ee.id_ref_ind = f.id_ref_ind
indexIdData.getPrefixedMapper().addIdsEqualToQuery(rootParameters, eeOriginalIdPropertyPath, indexIdData.getOriginalMapper(), INDEX_ENTITY_ALIAS + "." + originalIdPropertyName);
// ee.originalId.id_ref_ing = :id_ref_ing
referencingIdData.getPrefixedMapper().addNamedIdEqualsToQuery(rootParameters, originalIdPropertyName, true);
return qb;
}
use of org.hibernate.envers.internal.tools.query.QueryBuilder in project hibernate-orm by hibernate.
the class TwoEntityOneAuditedQueryGenerator method commonQueryPart.
/**
* Compute common part for both queries.
*/
private QueryBuilder commonQueryPart(MiddleIdData referencedIdData, String versionsMiddleEntityName, String originalIdPropertyName) {
final String eeOriginalIdPropertyPath = MIDDLE_ENTITY_ALIAS + "." + originalIdPropertyName;
// SELECT new list(ee) FROM middleEntity ee
final QueryBuilder qb = new QueryBuilder(versionsMiddleEntityName, MIDDLE_ENTITY_ALIAS);
qb.addFrom(referencedIdData.getEntityName(), REFERENCED_ENTITY_ALIAS, false);
qb.addProjection("new list", MIDDLE_ENTITY_ALIAS + ", " + REFERENCED_ENTITY_ALIAS, null, false);
// WHERE
final Parameters rootParameters = qb.getRootParameters();
// ee.id_ref_ed = e.id_ref_ed
referencedIdData.getPrefixedMapper().addIdsEqualToQuery(rootParameters, eeOriginalIdPropertyPath, referencedIdData.getOriginalMapper(), REFERENCED_ENTITY_ALIAS);
// ee.originalId.id_ref_ing = :id_ref_ing
referencingIdData.getPrefixedMapper().addNamedIdEqualsToQuery(rootParameters, originalIdPropertyName, true);
return qb;
}
use of org.hibernate.envers.internal.tools.query.QueryBuilder in project hibernate-orm by hibernate.
the class ValidityAuditStrategy method performCollectionChange.
@Override
@SuppressWarnings({ "unchecked" })
public void performCollectionChange(Session session, String entityName, String propertyName, AuditEntitiesConfiguration auditEntitiesConfiguration, PersistentCollectionChangeData persistentCollectionChangeData, Object revision) {
final QueryBuilder qb = new QueryBuilder(persistentCollectionChangeData.getEntityName(), MIDDLE_ENTITY_ALIAS);
final String originalIdPropName = auditEntitiesConfiguration.getOriginalIdPropName();
final Map<String, Object> originalId = (Map<String, Object>) persistentCollectionChangeData.getData().get(originalIdPropName);
final String revisionFieldName = auditEntitiesConfiguration.getRevisionFieldName();
final String revisionTypePropName = auditEntitiesConfiguration.getRevisionTypePropName();
final String ordinalPropName = auditEntitiesConfiguration.getEmbeddableSetOrdinalPropertyName();
// Adding a parameter for each id component, except the rev number and type.
for (Map.Entry<String, Object> originalIdEntry : originalId.entrySet()) {
if (!revisionFieldName.equals(originalIdEntry.getKey()) && !revisionTypePropName.equals(originalIdEntry.getKey()) && !ordinalPropName.equals(originalIdEntry.getKey())) {
qb.getRootParameters().addWhereWithParam(originalIdPropName + "." + originalIdEntry.getKey(), true, "=", originalIdEntry.getValue());
}
}
if (isNonIdentifierWhereConditionsRequired(entityName, propertyName, (SessionImplementor) session)) {
addNonIdentifierWhereConditions(qb, persistentCollectionChangeData.getData(), originalIdPropName);
}
addEndRevisionNullRestriction(auditEntitiesConfiguration, qb.getRootParameters());
final List<Object> l = qb.toQuery(session).setLockOptions(LockOptions.UPGRADE).list();
// ADD, we may need to update the last revision.
if (l.size() > 0) {
updateLastRevision(session, auditEntitiesConfiguration, l, originalId, persistentCollectionChangeData.getEntityName(), revision);
}
// Save the audit data
session.save(persistentCollectionChangeData.getEntityName(), persistentCollectionChangeData.getData());
sessionCacheCleaner.scheduleAuditDataRemoval(session, persistentCollectionChangeData.getData());
}
Aggregations