HHH-3611: improved query interface
git-svn-id: https://svn.jboss.org/repos/hibernate/core/trunk@15589 1b8cb986-b30d-0410-93ca-fae66ebed9b2
This commit is contained in:
parent
a91681858e
commit
ef45d04181
|
@ -37,8 +37,9 @@ public class AuditEntitiesConfiguration {
|
|||
|
||||
private final String originalIdPropName;
|
||||
|
||||
private final String revisionPropName;
|
||||
private final String revisionPropPath;
|
||||
private final String revisionFieldName;
|
||||
private final String revisionNumberPath;
|
||||
private final String revisionPropBasePath;
|
||||
|
||||
private final String revisionTypePropName;
|
||||
private final String revisionTypePropType;
|
||||
|
@ -55,26 +56,35 @@ public class AuditEntitiesConfiguration {
|
|||
|
||||
originalIdPropName = "originalId";
|
||||
|
||||
revisionPropName = properties.getProperty("org.hibernate.envers.revisionFieldName", "REV");
|
||||
revisionFieldName = properties.getProperty("org.hibernate.envers.revisionFieldName", "REV");
|
||||
|
||||
revisionTypePropName = properties.getProperty("org.hibernate.envers.revisionTypeFieldName", "REVTYPE");
|
||||
revisionTypePropType = "byte";
|
||||
|
||||
customAuditTablesNames = new HashMap<String, String>();
|
||||
|
||||
revisionPropPath = originalIdPropName + "." + revisionPropName + ".id";
|
||||
revisionNumberPath = originalIdPropName + "." + revisionFieldName + ".id";
|
||||
revisionPropBasePath = originalIdPropName + "." + revisionFieldName + ".";
|
||||
}
|
||||
|
||||
public String getOriginalIdPropName() {
|
||||
return originalIdPropName;
|
||||
}
|
||||
|
||||
public String getRevisionPropName() {
|
||||
return revisionPropName;
|
||||
public String getRevisionFieldName() {
|
||||
return revisionFieldName;
|
||||
}
|
||||
|
||||
public String getRevisionPropPath() {
|
||||
return revisionPropPath;
|
||||
public String getRevisionNumberPath() {
|
||||
return revisionNumberPath;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param propertyName Property of the revision entity.
|
||||
* @return A path to the given property of the revision entity associated with an audit entity.
|
||||
*/
|
||||
public String getRevisionPropPath(String propertyName) {
|
||||
return revisionPropBasePath + propertyName;
|
||||
}
|
||||
|
||||
public String getRevisionTypePropName() {
|
||||
|
|
|
@ -88,8 +88,8 @@ public final class AuditMetadataGenerator {
|
|||
|
||||
void addRevisionInfoRelation(Element any_mapping) {
|
||||
Element rev_mapping = (Element) revisionInfoRelationMapping.clone();
|
||||
rev_mapping.addAttribute("name", verEntCfg.getRevisionPropName());
|
||||
MetadataTools.addColumn(rev_mapping, verEntCfg.getRevisionPropName(), null);
|
||||
rev_mapping.addAttribute("name", verEntCfg.getRevisionFieldName());
|
||||
MetadataTools.addColumn(rev_mapping, verEntCfg.getRevisionFieldName(), null);
|
||||
|
||||
any_mapping.add(rev_mapping);
|
||||
}
|
||||
|
@ -192,7 +192,7 @@ public final class AuditMetadataGenerator {
|
|||
|
||||
Element joinKey = joinElement.addElement("key");
|
||||
MetadataTools.addColumns(joinKey, join.getKey().getColumnIterator());
|
||||
MetadataTools.addColumn(joinKey, verEntCfg.getRevisionPropName(), null);
|
||||
MetadataTools.addColumn(joinKey, verEntCfg.getRevisionFieldName(), null);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -298,7 +298,7 @@ public final class AuditMetadataGenerator {
|
|||
// Adding the "key" element with all columns + the revision number column
|
||||
Element keyMapping = mappingData.getFirst().addElement("key");
|
||||
MetadataTools.addColumns(keyMapping, pc.getIdentifierProperty().getColumnIterator());
|
||||
MetadataTools.addColumn(keyMapping, verEntCfg.getRevisionPropName(), null);
|
||||
MetadataTools.addColumn(keyMapping, verEntCfg.getRevisionFieldName(), null);
|
||||
break;
|
||||
|
||||
case TABLE_PER_CLASS:
|
||||
|
|
|
@ -33,7 +33,7 @@ import org.hibernate.envers.entities.mapper.PersistentCollectionChangeData;
|
|||
import org.hibernate.envers.entities.mapper.PropertyMapper;
|
||||
import org.hibernate.envers.entities.PropertyData;
|
||||
import org.hibernate.envers.exception.AuditException;
|
||||
import org.hibernate.envers.query.AuditRestrictions;
|
||||
import org.hibernate.envers.query.AuditEntity;
|
||||
import org.hibernate.envers.reader.AuditReaderImplementor;
|
||||
import org.hibernate.envers.tools.reflection.ReflectionTools;
|
||||
|
||||
|
@ -71,7 +71,7 @@ public class OneToOneNotOwningMapper implements PropertyMapper {
|
|||
|
||||
try {
|
||||
value = versionsReader.createQuery().forEntitiesAtRevision(entityClass, revision)
|
||||
.add(AuditRestrictions.relatedIdEq(owningReferencePropertyName, primaryKey)).getSingleResult();
|
||||
.add(AuditEntity.relatedId(owningReferencePropertyName).eq(primaryKey)).getSingleResult();
|
||||
} catch (NoResultException e) {
|
||||
value = null;
|
||||
} catch (NonUniqueResultException e) {
|
||||
|
|
|
@ -62,7 +62,7 @@ public final class OneAuditEntityQueryGenerator implements RelationQueryGenerato
|
|||
* (only non-deleted entities)
|
||||
* e.revision_type != DEL
|
||||
*/
|
||||
String revisionPropertyPath = verEntCfg.getRevisionPropPath();
|
||||
String revisionPropertyPath = verEntCfg.getRevisionNumberPath();
|
||||
String originalIdPropertyName = verEntCfg.getOriginalIdPropName();
|
||||
|
||||
String versionsReferencedEntityName = verEntCfg.getAuditEntityName(referencedEntityName);
|
||||
|
|
|
@ -61,7 +61,7 @@ public final class OneEntityQueryGenerator implements RelationQueryGenerator {
|
|||
* (only non-deleted entities and associations)
|
||||
* ee.revision_type != DEL
|
||||
*/
|
||||
String revisionPropertyPath = verEntCfg.getRevisionPropPath();
|
||||
String revisionPropertyPath = verEntCfg.getRevisionNumberPath();
|
||||
String originalIdPropertyName = verEntCfg.getOriginalIdPropName();
|
||||
|
||||
// SELECT new list(ee) FROM middleEntity ee
|
||||
|
|
|
@ -78,7 +78,7 @@ public final class ThreeEntityQueryGenerator implements RelationQueryGenerator {
|
|||
* e.revision_type != DEL AND
|
||||
* f.revision_type != DEL
|
||||
*/
|
||||
String revisionPropertyPath = verEntCfg.getRevisionPropPath();
|
||||
String revisionPropertyPath = verEntCfg.getRevisionNumberPath();
|
||||
String originalIdPropertyName = verEntCfg.getOriginalIdPropName();
|
||||
|
||||
String eeOriginalIdPropertyPath = "ee." + originalIdPropertyName;
|
||||
|
|
|
@ -71,7 +71,7 @@ public final class TwoEntityQueryGenerator implements RelationQueryGenerator {
|
|||
* ee.revision_type != DEL AND
|
||||
* e.revision_type != DEL
|
||||
*/
|
||||
String revisionPropertyPath = verEntCfg.getRevisionPropPath();
|
||||
String revisionPropertyPath = verEntCfg.getRevisionNumberPath();
|
||||
String originalIdPropertyName = verEntCfg.getOriginalIdPropName();
|
||||
|
||||
String eeOriginalIdPropertyPath = "ee." + originalIdPropertyName;
|
||||
|
|
|
@ -0,0 +1,122 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
|
||||
* indicated by the @author tags or express copyright attribution
|
||||
* statements applied by the authors. All third-party contributions are
|
||||
* distributed under license by Red Hat Middleware LLC.
|
||||
*
|
||||
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||
* Lesser General Public License, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this distribution; if not, write to:
|
||||
* Free Software Foundation, Inc.
|
||||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package org.hibernate.envers.query;
|
||||
|
||||
import org.hibernate.envers.query.criteria.AuditCriterion;
|
||||
import org.hibernate.envers.query.criteria.*;
|
||||
import org.hibernate.envers.query.property.EntityPropertyName;
|
||||
import org.hibernate.envers.query.property.RevisionNumberPropertyName;
|
||||
import org.hibernate.envers.query.property.RevisionPropertyPropertyName;
|
||||
import org.hibernate.envers.query.property.RevisionTypePropertyName;
|
||||
import org.hibernate.envers.RevisionType;
|
||||
|
||||
/**
|
||||
* TODO: ilike
|
||||
* @author Adam Warski (adam at warski dot org)
|
||||
* @see org.hibernate.criterion.Restrictions
|
||||
*/
|
||||
@SuppressWarnings({"JavaDoc"})
|
||||
public class AuditEntity {
|
||||
private AuditEntity() { }
|
||||
|
||||
public static AuditId id() {
|
||||
return new AuditId();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create restrictions, projections and specify order for a property of an audited entity.
|
||||
* @param propertyName Name of the property.
|
||||
*/
|
||||
public static AuditProperty<Object> property(String propertyName) {
|
||||
return new AuditProperty<Object>(new EntityPropertyName(propertyName));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create restrictions, projections and specify order for the revision number, corresponding to an
|
||||
* audited entity.
|
||||
*/
|
||||
public static AuditProperty<Number> revisionNumber() {
|
||||
return new AuditProperty<Number>(new RevisionNumberPropertyName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Create restrictions, projections and specify order for a property of the revision entity,
|
||||
* corresponding to an audited entity.
|
||||
* @param propertyName Name of the property.
|
||||
*/
|
||||
public static AuditProperty<Object> revisionProperty(String propertyName) {
|
||||
return new AuditProperty<Object>(new RevisionPropertyPropertyName(propertyName));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create restrictions, projections and specify order for the revision type, corresponding to an
|
||||
* audited entity.
|
||||
*/
|
||||
public static AuditProperty<RevisionType> revisionType() {
|
||||
return new AuditProperty<RevisionType>(new RevisionTypePropertyName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Create restrictions on an id of a related entity.
|
||||
* @param propertyName Name of the property, which is the relation.
|
||||
*/
|
||||
public static AuditRelatedId relatedId(String propertyName) {
|
||||
return new AuditRelatedId(new EntityPropertyName(propertyName));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the conjuction of two criterions.
|
||||
*/
|
||||
public static AuditCriterion and(AuditCriterion lhs, AuditCriterion rhs) {
|
||||
return new LogicalAuditExpression(lhs, rhs, "and");
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the disjuction of two criterions.
|
||||
*/
|
||||
public static AuditCriterion or(AuditCriterion lhs, AuditCriterion rhs) {
|
||||
return new LogicalAuditExpression(lhs, rhs, "or");
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the negation of a criterion.
|
||||
*/
|
||||
public static AuditCriterion not(AuditCriterion expression) {
|
||||
return new NotAuditExpression(expression);
|
||||
}
|
||||
|
||||
/**
|
||||
* Group criterions together in a single conjunction (A and B and C...).
|
||||
*/
|
||||
public static AuditConjunction conjunction() {
|
||||
return new AuditConjunction();
|
||||
}
|
||||
|
||||
/**
|
||||
* Group criterions together in a single disjunction (A or B or C...).
|
||||
*/
|
||||
public static AuditDisjunction disjunction() {
|
||||
return new AuditDisjunction();
|
||||
}
|
||||
}
|
|
@ -47,12 +47,8 @@ public interface AuditQuery {
|
|||
|
||||
AuditQuery add(AuditCriterion criterion);
|
||||
|
||||
AuditQuery addProjection(String function, String propertyName);
|
||||
|
||||
AuditQuery addProjection(AuditProjection projection);
|
||||
|
||||
AuditQuery addOrder(String propertyName, boolean asc);
|
||||
|
||||
AuditQuery addOrder(AuditOrder order);
|
||||
|
||||
AuditQuery setMaxResults(int maxResults);
|
||||
|
|
|
@ -1,143 +0,0 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
|
||||
* indicated by the @author tags or express copyright attribution
|
||||
* statements applied by the authors. All third-party contributions are
|
||||
* distributed under license by Red Hat Middleware LLC.
|
||||
*
|
||||
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||
* Lesser General Public License, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this distribution; if not, write to:
|
||||
* Free Software Foundation, Inc.
|
||||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package org.hibernate.envers.query;
|
||||
|
||||
import org.hibernate.envers.configuration.AuditConfiguration;
|
||||
import org.hibernate.envers.query.criteria.RevisionAuditExpression;
|
||||
import org.hibernate.envers.query.criteria.AuditCriterion;
|
||||
import org.hibernate.envers.query.order.RevisionAuditOrder;
|
||||
import org.hibernate.envers.query.order.AuditOrder;
|
||||
import org.hibernate.envers.query.projection.RevisionAuditProjection;
|
||||
import org.hibernate.envers.query.projection.AuditProjection;
|
||||
import org.hibernate.envers.tools.Triple;
|
||||
|
||||
/**
|
||||
* @author Adam Warski (adam at warski dot org)
|
||||
*/
|
||||
@SuppressWarnings({"JavaDoc"})
|
||||
public class RevisionProperty implements AuditProjection {
|
||||
private RevisionProperty() { }
|
||||
|
||||
/**
|
||||
* Apply a "equal" constraint on the revision number
|
||||
*/
|
||||
public static AuditCriterion eq(Integer revision) {
|
||||
return new RevisionAuditExpression(revision, "=");
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply a "not equal" constraint on the revision number
|
||||
*/
|
||||
public static AuditCriterion ne(Integer revision) {
|
||||
return new RevisionAuditExpression(revision, "<>");
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply a "greater than" constraint on the revision number
|
||||
*/
|
||||
public static AuditCriterion gt(Integer revision) {
|
||||
return new RevisionAuditExpression(revision, ">");
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply a "greater than or equal" constraint on the revision number
|
||||
*/
|
||||
public static AuditCriterion ge(Integer revision) {
|
||||
return new RevisionAuditExpression(revision, ">=");
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply a "less than" constraint on the revision number
|
||||
*/
|
||||
public static AuditCriterion lt(Integer revision) {
|
||||
return new RevisionAuditExpression(revision, "<");
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply a "less than or equal" constraint on the revision number
|
||||
*/
|
||||
public static AuditCriterion le(Integer revision) {
|
||||
return new RevisionAuditExpression(revision, "<=");
|
||||
}
|
||||
|
||||
/**
|
||||
* Sort the results by revision in ascending order
|
||||
*/
|
||||
public static AuditOrder asc() {
|
||||
return new RevisionAuditOrder(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sort the results by revision in descending order
|
||||
*/
|
||||
public static AuditOrder desc() {
|
||||
return new RevisionAuditOrder(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Select the maximum revision
|
||||
*/
|
||||
public static AuditProjection max() {
|
||||
return new RevisionAuditProjection(RevisionAuditProjection.ProjectionType.MAX);
|
||||
}
|
||||
|
||||
/**
|
||||
* Select the minimum revision
|
||||
*/
|
||||
public static AuditProjection min() {
|
||||
return new RevisionAuditProjection(RevisionAuditProjection.ProjectionType.MIN);
|
||||
}
|
||||
|
||||
/**
|
||||
* Count revisions
|
||||
*/
|
||||
public static AuditProjection count() {
|
||||
return new RevisionAuditProjection(RevisionAuditProjection.ProjectionType.COUNT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Count distinct revisions
|
||||
*/
|
||||
public static AuditProjection countDistinct() {
|
||||
return new RevisionAuditProjection(RevisionAuditProjection.ProjectionType.COUNT_DISTINCT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Distinct revisions
|
||||
*/
|
||||
public static AuditProjection distinct() {
|
||||
return new RevisionAuditProjection(RevisionAuditProjection.ProjectionType.DISTINCT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Projection the revision number
|
||||
*/
|
||||
public static AuditProjection revisionNumber() {
|
||||
return new RevisionProperty();
|
||||
}
|
||||
|
||||
public Triple<String, String, Boolean> getData(AuditConfiguration verCfg) {
|
||||
return Triple.make(null, verCfg.getAuditEntCfg().getRevisionPropPath(), false);
|
||||
}
|
||||
}
|
|
@ -23,39 +23,42 @@
|
|||
*/
|
||||
package org.hibernate.envers.query.criteria;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.hibernate.envers.configuration.AuditConfiguration;
|
||||
import org.hibernate.envers.tools.query.Parameters;
|
||||
import org.hibernate.envers.query.property.PropertyNameGetter;
|
||||
import org.hibernate.envers.tools.query.QueryBuilder;
|
||||
import org.hibernate.envers.tools.query.Parameters;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* @author Adam Warski (adam at warski dot org)
|
||||
*/
|
||||
public class AggregatedFieldAuditExpression implements AuditCriterion, ExtendableCriterion {
|
||||
public class AggregatedAuditExpression implements AuditCriterion, ExtendableCriterion {
|
||||
private PropertyNameGetter propertyNameGetter;
|
||||
private AggregatedMode mode;
|
||||
private List<AuditCriterion> criterions;
|
||||
|
||||
public AggregatedAuditExpression(PropertyNameGetter propertyNameGetter, AggregatedMode mode) {
|
||||
this.propertyNameGetter = propertyNameGetter;
|
||||
this.mode = mode;
|
||||
criterions = new ArrayList<AuditCriterion>();
|
||||
}
|
||||
|
||||
public static enum AggregatedMode {
|
||||
MAX,
|
||||
MIN
|
||||
}
|
||||
|
||||
private String propertyName;
|
||||
private AggregatedMode mode;
|
||||
private List<AuditCriterion> criterions;
|
||||
|
||||
public AggregatedFieldAuditExpression(String propertyName, AggregatedMode mode) {
|
||||
this.propertyName = propertyName;
|
||||
this.mode = mode;
|
||||
criterions = new ArrayList<AuditCriterion>();
|
||||
}
|
||||
|
||||
public AggregatedFieldAuditExpression add(AuditCriterion criterion) {
|
||||
public AggregatedAuditExpression add(AuditCriterion criterion) {
|
||||
criterions.add(criterion);
|
||||
return this;
|
||||
}
|
||||
|
||||
public void addToQuery(AuditConfiguration verCfg, String entityName, QueryBuilder qb, Parameters parameters) {
|
||||
CriteriaTools.checkPropertyNotARelation(verCfg, entityName, propertyName);
|
||||
public void addToQuery(AuditConfiguration auditCfg, String entityName, QueryBuilder qb, Parameters parameters) {
|
||||
String propertyName = propertyNameGetter.get(auditCfg);
|
||||
|
||||
CriteriaTools.checkPropertyNotARelation(auditCfg, entityName, propertyName);
|
||||
|
||||
// This will be the aggregated query, containing all the specified conditions
|
||||
QueryBuilder subQb = qb.newSubQueryBuilder();
|
||||
|
@ -63,8 +66,8 @@ public class AggregatedFieldAuditExpression implements AuditCriterion, Extendabl
|
|||
// Adding all specified conditions both to the main query, as well as to the
|
||||
// aggregated one.
|
||||
for (AuditCriterion versionsCriteria : criterions) {
|
||||
versionsCriteria.addToQuery(verCfg, entityName, qb, parameters);
|
||||
versionsCriteria.addToQuery(verCfg, entityName, subQb, subQb.getRootParameters());
|
||||
versionsCriteria.addToQuery(auditCfg, entityName, qb, parameters);
|
||||
versionsCriteria.addToQuery(auditCfg, entityName, subQb, subQb.getRootParameters());
|
||||
}
|
||||
|
||||
// Setting the desired projection of the aggregated query
|
|
@ -31,5 +31,5 @@ import org.hibernate.envers.tools.query.QueryBuilder;
|
|||
* @author Adam Warski (adam at warski dot org)
|
||||
*/
|
||||
public interface AuditCriterion {
|
||||
void addToQuery(AuditConfiguration verCfg, String entityName, QueryBuilder qb, Parameters parameters);
|
||||
void addToQuery(AuditConfiguration auditCfg, String entityName, QueryBuilder qb, Parameters parameters);
|
||||
}
|
||||
|
|
|
@ -21,44 +21,41 @@
|
|||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package org.hibernate.envers.query;
|
||||
|
||||
import org.hibernate.envers.configuration.AuditConfiguration;
|
||||
package org.hibernate.envers.query.criteria;
|
||||
|
||||
import org.hibernate.envers.query.projection.AuditProjection;
|
||||
import org.hibernate.envers.query.criteria.AuditCriterion;
|
||||
import org.hibernate.envers.query.criteria.RevisionTypeAuditExpression;
|
||||
import org.hibernate.envers.tools.Triple;
|
||||
import org.hibernate.envers.RevisionType;
|
||||
import org.hibernate.envers.query.projection.PropertyAuditProjection;
|
||||
import org.hibernate.envers.query.property.OriginalIdPropertyName;
|
||||
|
||||
/**
|
||||
* Create restrictions and projections for the id of an audited entity.
|
||||
* @author Adam Warski (adam at warski dot org)
|
||||
*/
|
||||
@SuppressWarnings({"JavaDoc"})
|
||||
public class RevisionTypeProperty implements AuditProjection {
|
||||
private RevisionTypeProperty() { }
|
||||
public class AuditId {
|
||||
/**
|
||||
* Apply an "equal" constraint
|
||||
*/
|
||||
public AuditCriterion eq(Object id) {
|
||||
return new IdentifierEqAuditExpression(id, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply a "equal" constraint on the revision type
|
||||
*/
|
||||
public static AuditCriterion eq(RevisionType type) {
|
||||
return new RevisionTypeAuditExpression(type, "=");
|
||||
}
|
||||
* Apply a "not equal" constraint
|
||||
*/
|
||||
public AuditCriterion ne(Object id) {
|
||||
return new IdentifierEqAuditExpression(id, false);
|
||||
}
|
||||
|
||||
// Projections
|
||||
|
||||
/**
|
||||
* Apply a "not equal" constraint on the revision type
|
||||
* Projection counting the values
|
||||
* TODO: idPropertyName isn't needed, should be read from the configuration
|
||||
* @param idPropertyName Name of the identifier property
|
||||
*/
|
||||
public static AuditCriterion ne(RevisionType type) {
|
||||
return new RevisionTypeAuditExpression(type, "<>");
|
||||
}
|
||||
|
||||
/**
|
||||
* Projection on the revision type
|
||||
*/
|
||||
public static AuditProjection revisionType() {
|
||||
return new RevisionTypeProperty();
|
||||
}
|
||||
|
||||
public Triple<String, String, Boolean> getData(AuditConfiguration verCfg) {
|
||||
return Triple.make(null, verCfg.getAuditEntCfg().getRevisionTypePropName(), false);
|
||||
public AuditProjection count(String idPropertyName) {
|
||||
return new PropertyAuditProjection(new OriginalIdPropertyName(idPropertyName), "count", false);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,266 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
|
||||
* indicated by the @author tags or express copyright attribution
|
||||
* statements applied by the authors. All third-party contributions are
|
||||
* distributed under license by Red Hat Middleware LLC.
|
||||
*
|
||||
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||
* Lesser General Public License, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this distribution; if not, write to:
|
||||
* Free Software Foundation, Inc.
|
||||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
package org.hibernate.envers.query.criteria;
|
||||
|
||||
import org.hibernate.envers.query.property.PropertyNameGetter;
|
||||
import org.hibernate.envers.query.order.AuditOrder;
|
||||
import org.hibernate.envers.query.order.PropertyAuditOrder;
|
||||
import org.hibernate.envers.query.projection.AuditProjection;
|
||||
import org.hibernate.envers.query.projection.PropertyAuditProjection;
|
||||
import org.hibernate.envers.tools.Triple;
|
||||
import org.hibernate.envers.configuration.AuditConfiguration;
|
||||
import org.hibernate.criterion.MatchMode;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* Create restrictions, projections and specify order for a property of an audited entity.
|
||||
* @author Adam Warski (adam at warski dot org)
|
||||
*/
|
||||
@SuppressWarnings({"JavaDoc"})
|
||||
public class AuditProperty<T> implements AuditProjection {
|
||||
private final PropertyNameGetter propertyNameGetter;
|
||||
|
||||
public AuditProperty(PropertyNameGetter propertyNameGetter) {
|
||||
this.propertyNameGetter = propertyNameGetter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply an "equal" constraint
|
||||
*/
|
||||
public AuditCriterion eq(T value) {
|
||||
return new SimpleAuditExpression(propertyNameGetter, value, "=");
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply a "not equal" constraint
|
||||
*/
|
||||
public AuditCriterion ne(T value) {
|
||||
return new SimpleAuditExpression(propertyNameGetter, value, "<>");
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply a "like" constraint
|
||||
*/
|
||||
public AuditCriterion like(T value) {
|
||||
return new SimpleAuditExpression(propertyNameGetter, value, " like ");
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply a "like" constraint
|
||||
*/
|
||||
public AuditCriterion like(String value, MatchMode matchMode) {
|
||||
return new SimpleAuditExpression(propertyNameGetter, matchMode.toMatchString(value), " like " );
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply a "greater than" constraint
|
||||
*/
|
||||
public AuditCriterion gt(T value) {
|
||||
return new SimpleAuditExpression(propertyNameGetter, value, ">");
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply a "less than" constraint
|
||||
*/
|
||||
public AuditCriterion lt(T value) {
|
||||
return new SimpleAuditExpression(propertyNameGetter, value, "<");
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply a "less than or equal" constraint
|
||||
*/
|
||||
public AuditCriterion le(T value) {
|
||||
return new SimpleAuditExpression(propertyNameGetter, value, "<=");
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply a "greater than or equal" constraint
|
||||
*/
|
||||
public AuditCriterion ge(T value) {
|
||||
return new SimpleAuditExpression(propertyNameGetter, value, ">=");
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply a "between" constraint
|
||||
*/
|
||||
public AuditCriterion between(T lo, T hi) {
|
||||
return new BetweenAuditExpression(propertyNameGetter, lo, hi);
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply an "in" constraint
|
||||
*/
|
||||
public AuditCriterion in(T[] values) {
|
||||
return new InAuditExpression(propertyNameGetter, values);
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply an "in" constraint
|
||||
*/
|
||||
public AuditCriterion in(Collection values) {
|
||||
return new InAuditExpression(propertyNameGetter, values.toArray());
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply an "is null" constraint
|
||||
*/
|
||||
public AuditCriterion isNull() {
|
||||
return new NullAuditExpression(propertyNameGetter);
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply an "equal" constraint to another property
|
||||
*/
|
||||
public AuditCriterion eqProperty(String otherPropertyName) {
|
||||
return new PropertyAuditExpression(propertyNameGetter, otherPropertyName, "=");
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply a "not equal" constraint to another property
|
||||
*/
|
||||
public AuditCriterion neProperty(String otherPropertyName) {
|
||||
return new PropertyAuditExpression(propertyNameGetter, otherPropertyName, "<>");
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply a "less than" constraint to another property
|
||||
*/
|
||||
public AuditCriterion ltProperty(String otherPropertyName) {
|
||||
return new PropertyAuditExpression(propertyNameGetter, otherPropertyName, "<");
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply a "less than or equal" constraint to another property
|
||||
*/
|
||||
public AuditCriterion leProperty(String otherPropertyName) {
|
||||
return new PropertyAuditExpression(propertyNameGetter, otherPropertyName, "<=");
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply a "greater than" constraint to another property
|
||||
*/
|
||||
public AuditCriterion gtProperty(String otherPropertyName) {
|
||||
return new PropertyAuditExpression(propertyNameGetter, otherPropertyName, ">");
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply a "greater than or equal" constraint to another property
|
||||
*/
|
||||
public AuditCriterion geProperty(String otherPropertyName) {
|
||||
return new PropertyAuditExpression(propertyNameGetter, otherPropertyName, ">=");
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply an "is not null" constraint to the another property
|
||||
*/
|
||||
public AuditCriterion isNotNull() {
|
||||
return new NotNullAuditExpression(propertyNameGetter);
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply a "maximalize" constraint, with the ability to specify further constraints on the maximized
|
||||
* property
|
||||
*/
|
||||
public AggregatedAuditExpression maximize() {
|
||||
return new AggregatedAuditExpression(propertyNameGetter,
|
||||
AggregatedAuditExpression.AggregatedMode.MAX);
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply a "minimize" constraint, with the ability to specify further constraints on the minimized
|
||||
* property
|
||||
*/
|
||||
public AggregatedAuditExpression minimize() {
|
||||
return new AggregatedAuditExpression(propertyNameGetter,
|
||||
AggregatedAuditExpression.AggregatedMode.MIN);
|
||||
}
|
||||
|
||||
// Projections
|
||||
|
||||
/**
|
||||
* Projection on the maximum value
|
||||
*/
|
||||
public AuditProjection max() {
|
||||
return new PropertyAuditProjection(propertyNameGetter, "max", false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Projection on the minimum value
|
||||
*/
|
||||
public AuditProjection min() {
|
||||
return new PropertyAuditProjection(propertyNameGetter, "min", false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Projection counting the values
|
||||
*/
|
||||
public AuditProjection count() {
|
||||
return new PropertyAuditProjection(propertyNameGetter, "count", false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Projection counting distinct values
|
||||
*/
|
||||
public AuditProjection countDistinct() {
|
||||
return new PropertyAuditProjection(propertyNameGetter, "count", true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Projection on distinct values
|
||||
*/
|
||||
public AuditProjection distinct() {
|
||||
return new PropertyAuditProjection(propertyNameGetter, null, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Projection using a custom function
|
||||
*/
|
||||
public AuditProjection function(String functionName) {
|
||||
return new PropertyAuditProjection(propertyNameGetter, functionName, false);
|
||||
}
|
||||
|
||||
// Projection on this property
|
||||
|
||||
public Triple<String, String, Boolean> getData(AuditConfiguration auditCfg) {
|
||||
return Triple.make(null, propertyNameGetter.get(auditCfg), false);
|
||||
}
|
||||
|
||||
// Order
|
||||
|
||||
/**
|
||||
* Sort the results by the property in ascending order
|
||||
*/
|
||||
public AuditOrder asc() {
|
||||
return new PropertyAuditOrder(propertyNameGetter, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sort the results by the property in descending order
|
||||
*/
|
||||
public AuditOrder desc() {
|
||||
return new PropertyAuditOrder(propertyNameGetter, false);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,54 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
|
||||
* indicated by the @author tags or express copyright attribution
|
||||
* statements applied by the authors. All third-party contributions are
|
||||
* distributed under license by Red Hat Middleware LLC.
|
||||
*
|
||||
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||
* Lesser General Public License, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this distribution; if not, write to:
|
||||
* Free Software Foundation, Inc.
|
||||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
package org.hibernate.envers.query.criteria;
|
||||
|
||||
import org.hibernate.envers.query.property.PropertyNameGetter;
|
||||
|
||||
/**
|
||||
* Create restrictions on an id of an entity related to an audited entity.
|
||||
* @author Adam Warski (adam at warski dot org)
|
||||
*/
|
||||
@SuppressWarnings({"JavaDoc"})
|
||||
public class AuditRelatedId {
|
||||
private final PropertyNameGetter propertyNameGetter;
|
||||
|
||||
public AuditRelatedId(PropertyNameGetter propertyNameGetter) {
|
||||
this.propertyNameGetter = propertyNameGetter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply an "equal" constraint
|
||||
*/
|
||||
public AuditCriterion eq(Object id) {
|
||||
return new RelatedAuditExpression(propertyNameGetter, id, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply a "not equal" constraint
|
||||
*/
|
||||
public AuditCriterion ne(Object id) {
|
||||
return new RelatedAuditExpression(propertyNameGetter, id, false);
|
||||
}
|
||||
}
|
|
@ -26,23 +26,25 @@ package org.hibernate.envers.query.criteria;
|
|||
import org.hibernate.envers.configuration.AuditConfiguration;
|
||||
import org.hibernate.envers.tools.query.Parameters;
|
||||
import org.hibernate.envers.tools.query.QueryBuilder;
|
||||
import org.hibernate.envers.query.property.PropertyNameGetter;
|
||||
|
||||
/**
|
||||
* @author Adam Warski (adam at warski dot org)
|
||||
*/
|
||||
public class BetweenAuditExpression implements AuditCriterion {
|
||||
private String propertyName;
|
||||
private PropertyNameGetter propertyNameGetter;
|
||||
private Object lo;
|
||||
private Object hi;
|
||||
|
||||
public BetweenAuditExpression(String propertyName, Object lo, Object hi) {
|
||||
this.propertyName = propertyName;
|
||||
public BetweenAuditExpression(PropertyNameGetter propertyNameGetter, Object lo, Object hi) {
|
||||
this.propertyNameGetter = propertyNameGetter;
|
||||
this.lo = lo;
|
||||
this.hi = hi;
|
||||
}
|
||||
|
||||
public void addToQuery(AuditConfiguration verCfg, String entityName, QueryBuilder qb, Parameters parameters) {
|
||||
CriteriaTools.checkPropertyNotARelation(verCfg, entityName, propertyName);
|
||||
public void addToQuery(AuditConfiguration auditCfg, String entityName, QueryBuilder qb, Parameters parameters) {
|
||||
String propertyName = propertyNameGetter.get(auditCfg);
|
||||
CriteriaTools.checkPropertyNotARelation(auditCfg, entityName, propertyName);
|
||||
parameters.addWhereWithParam(propertyName, ">=", lo);
|
||||
parameters.addWhereWithParam(propertyName, "<=", hi);
|
||||
}
|
||||
|
|
|
@ -28,17 +28,20 @@ import org.hibernate.envers.tools.query.Parameters;
|
|||
import org.hibernate.envers.tools.query.QueryBuilder;
|
||||
|
||||
/**
|
||||
* A criterion that expresses that the id of an entity is equal or not equal to some specified value.
|
||||
* @author Adam Warski (adam at warski dot org)
|
||||
*/
|
||||
public class IdentifierEqAuditExpression implements AuditCriterion {
|
||||
private Object id;
|
||||
private final Object id;
|
||||
private final boolean equals;
|
||||
|
||||
public IdentifierEqAuditExpression(Object id) {
|
||||
public IdentifierEqAuditExpression(Object id, boolean equals) {
|
||||
this.id = id;
|
||||
this.equals = equals;
|
||||
}
|
||||
|
||||
public void addToQuery(AuditConfiguration verCfg, String entityName, QueryBuilder qb, Parameters parameters) {
|
||||
verCfg.getEntCfg().get(entityName).getIdMapper()
|
||||
.addIdEqualsToQuery(parameters, id, verCfg.getAuditEntCfg().getOriginalIdPropName(), true);
|
||||
.addIdEqualsToQuery(parameters, id, verCfg.getAuditEntCfg().getOriginalIdPropName(), equals);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,21 +26,23 @@ package org.hibernate.envers.query.criteria;
|
|||
import org.hibernate.envers.configuration.AuditConfiguration;
|
||||
import org.hibernate.envers.tools.query.Parameters;
|
||||
import org.hibernate.envers.tools.query.QueryBuilder;
|
||||
import org.hibernate.envers.query.property.PropertyNameGetter;
|
||||
|
||||
/**
|
||||
* @author Adam Warski (adam at warski dot org)
|
||||
*/
|
||||
public class InAuditExpression implements AuditCriterion {
|
||||
private String propertyName;
|
||||
private PropertyNameGetter propertyNameGetter;
|
||||
private Object[] values;
|
||||
|
||||
public InAuditExpression(String propertyName, Object[] values) {
|
||||
this.propertyName = propertyName;
|
||||
public InAuditExpression(PropertyNameGetter propertyNameGetter, Object[] values) {
|
||||
this.propertyNameGetter = propertyNameGetter;
|
||||
this.values = values;
|
||||
}
|
||||
|
||||
public void addToQuery(AuditConfiguration verCfg, String entityName, QueryBuilder qb, Parameters parameters) {
|
||||
CriteriaTools.checkPropertyNotARelation(verCfg, entityName, propertyName);
|
||||
public void addToQuery(AuditConfiguration auditCfg, String entityName, QueryBuilder qb, Parameters parameters) {
|
||||
String propertyName = propertyNameGetter.get(auditCfg);
|
||||
CriteriaTools.checkPropertyNotARelation(auditCfg, entityName, propertyName);
|
||||
parameters.addWhereWithParams(propertyName, "in (", values, ")");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,19 +27,21 @@ import org.hibernate.envers.configuration.AuditConfiguration;
|
|||
import org.hibernate.envers.entities.RelationDescription;
|
||||
import org.hibernate.envers.tools.query.Parameters;
|
||||
import org.hibernate.envers.tools.query.QueryBuilder;
|
||||
import org.hibernate.envers.query.property.PropertyNameGetter;
|
||||
|
||||
/**
|
||||
* @author Adam Warski (adam at warski dot org)
|
||||
*/
|
||||
public class NotNullAuditExpression implements AuditCriterion {
|
||||
private String propertyName;
|
||||
private PropertyNameGetter propertyNameGetter;
|
||||
|
||||
public NotNullAuditExpression(String propertyName) {
|
||||
this.propertyName = propertyName;
|
||||
public NotNullAuditExpression(PropertyNameGetter propertyNameGetter) {
|
||||
this.propertyNameGetter = propertyNameGetter;
|
||||
}
|
||||
|
||||
public void addToQuery(AuditConfiguration verCfg, String entityName, QueryBuilder qb, Parameters parameters) {
|
||||
RelationDescription relatedEntity = CriteriaTools.getRelatedEntity(verCfg, entityName, propertyName);
|
||||
public void addToQuery(AuditConfiguration auditCfg, String entityName, QueryBuilder qb, Parameters parameters) {
|
||||
String propertyName = propertyNameGetter.get(auditCfg);
|
||||
RelationDescription relatedEntity = CriteriaTools.getRelatedEntity(auditCfg, entityName, propertyName);
|
||||
|
||||
if (relatedEntity == null) {
|
||||
parameters.addWhereWithParam(propertyName, "<>", null);
|
||||
|
|
|
@ -27,19 +27,21 @@ import org.hibernate.envers.configuration.AuditConfiguration;
|
|||
import org.hibernate.envers.entities.RelationDescription;
|
||||
import org.hibernate.envers.tools.query.Parameters;
|
||||
import org.hibernate.envers.tools.query.QueryBuilder;
|
||||
import org.hibernate.envers.query.property.PropertyNameGetter;
|
||||
|
||||
/**
|
||||
* @author Adam Warski (adam at warski dot org)
|
||||
*/
|
||||
public class NullAuditExpression implements AuditCriterion {
|
||||
private String propertyName;
|
||||
private PropertyNameGetter propertyNameGetter;
|
||||
|
||||
public NullAuditExpression(String propertyName) {
|
||||
this.propertyName = propertyName;
|
||||
public NullAuditExpression(PropertyNameGetter propertyNameGetter) {
|
||||
this.propertyNameGetter = propertyNameGetter;
|
||||
}
|
||||
|
||||
public void addToQuery(AuditConfiguration verCfg, String entityName, QueryBuilder qb, Parameters parameters) {
|
||||
RelationDescription relatedEntity = CriteriaTools.getRelatedEntity(verCfg, entityName, propertyName);
|
||||
public void addToQuery(AuditConfiguration auditCfg, String entityName, QueryBuilder qb, Parameters parameters) {
|
||||
String propertyName = propertyNameGetter.get(auditCfg);
|
||||
RelationDescription relatedEntity = CriteriaTools.getRelatedEntity(auditCfg, entityName, propertyName);
|
||||
|
||||
if (relatedEntity == null) {
|
||||
parameters.addWhereWithParam(propertyName, "=", null);
|
||||
|
|
|
@ -26,24 +26,26 @@ package org.hibernate.envers.query.criteria;
|
|||
import org.hibernate.envers.configuration.AuditConfiguration;
|
||||
import org.hibernate.envers.tools.query.Parameters;
|
||||
import org.hibernate.envers.tools.query.QueryBuilder;
|
||||
import org.hibernate.envers.query.property.PropertyNameGetter;
|
||||
|
||||
/**
|
||||
* @author Adam Warski (adam at warski dot org)
|
||||
*/
|
||||
public class PropertyAuditExpression implements AuditCriterion {
|
||||
private String propertyName;
|
||||
private PropertyNameGetter propertyNameGetter;
|
||||
private String otherPropertyName;
|
||||
private String op;
|
||||
|
||||
public PropertyAuditExpression(String propertyName, String otherPropertyName, String op) {
|
||||
this.propertyName = propertyName;
|
||||
public PropertyAuditExpression(PropertyNameGetter propertyNameGetter, String otherPropertyName, String op) {
|
||||
this.propertyNameGetter = propertyNameGetter;
|
||||
this.otherPropertyName = otherPropertyName;
|
||||
this.op = op;
|
||||
}
|
||||
|
||||
public void addToQuery(AuditConfiguration verCfg, String entityName, QueryBuilder qb, Parameters parameters) {
|
||||
CriteriaTools.checkPropertyNotARelation(verCfg, entityName, propertyName);
|
||||
CriteriaTools.checkPropertyNotARelation(verCfg, entityName, otherPropertyName);
|
||||
public void addToQuery(AuditConfiguration auditCfg, String entityName, QueryBuilder qb, Parameters parameters) {
|
||||
String propertyName = propertyNameGetter.get(auditCfg);
|
||||
CriteriaTools.checkPropertyNotARelation(auditCfg, entityName, propertyName);
|
||||
CriteriaTools.checkPropertyNotARelation(auditCfg, entityName, otherPropertyName);
|
||||
parameters.addWhere(propertyName, op, otherPropertyName);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,23 +28,26 @@ import org.hibernate.envers.entities.RelationDescription;
|
|||
import org.hibernate.envers.exception.AuditException;
|
||||
import org.hibernate.envers.tools.query.Parameters;
|
||||
import org.hibernate.envers.tools.query.QueryBuilder;
|
||||
import org.hibernate.envers.query.property.PropertyNameGetter;
|
||||
|
||||
/**
|
||||
* @author Adam Warski (adam at warski dot org)
|
||||
*/
|
||||
public class RelatedAuditExpression implements AuditCriterion {
|
||||
private String propertyName;
|
||||
private Object id;
|
||||
private boolean equals;
|
||||
private final PropertyNameGetter propertyNameGetter;
|
||||
private final Object id;
|
||||
private final boolean equals;
|
||||
|
||||
public RelatedAuditExpression(String propertyName, Object id, boolean equals) {
|
||||
this.propertyName = propertyName;
|
||||
public RelatedAuditExpression(PropertyNameGetter propertyNameGetter, Object id, boolean equals) {
|
||||
this.propertyNameGetter = propertyNameGetter;
|
||||
this.id = id;
|
||||
this.equals = equals;
|
||||
}
|
||||
|
||||
public void addToQuery(AuditConfiguration verCfg, String entityName, QueryBuilder qb, Parameters parameters) {
|
||||
RelationDescription relatedEntity = CriteriaTools.getRelatedEntity(verCfg, entityName, propertyName);
|
||||
public void addToQuery(AuditConfiguration auditCfg, String entityName, QueryBuilder qb, Parameters parameters) {
|
||||
String propertyName = propertyNameGetter.get(auditCfg);
|
||||
|
||||
RelationDescription relatedEntity = CriteriaTools.getRelatedEntity(auditCfg, entityName, propertyName);
|
||||
|
||||
if (relatedEntity == null) {
|
||||
throw new AuditException("This criterion can only be used on a property that is " +
|
||||
|
|
|
@ -28,23 +28,26 @@ import org.hibernate.envers.entities.RelationDescription;
|
|||
import org.hibernate.envers.exception.AuditException;
|
||||
import org.hibernate.envers.tools.query.Parameters;
|
||||
import org.hibernate.envers.tools.query.QueryBuilder;
|
||||
import org.hibernate.envers.query.property.PropertyNameGetter;
|
||||
|
||||
/**
|
||||
* @author Adam Warski (adam at warski dot org)
|
||||
*/
|
||||
public class SimpleAuditExpression implements AuditCriterion {
|
||||
private String propertyName;
|
||||
private PropertyNameGetter propertyNameGetter;
|
||||
private Object value;
|
||||
private String op;
|
||||
|
||||
public SimpleAuditExpression(String propertyName, Object value, String op) {
|
||||
this.propertyName = propertyName;
|
||||
public SimpleAuditExpression(PropertyNameGetter propertyNameGetter, Object value, String op) {
|
||||
this.propertyNameGetter = propertyNameGetter;
|
||||
this.value = value;
|
||||
this.op = op;
|
||||
}
|
||||
|
||||
public void addToQuery(AuditConfiguration verCfg, String entityName, QueryBuilder qb, Parameters parameters) {
|
||||
RelationDescription relatedEntity = CriteriaTools.getRelatedEntity(verCfg, entityName, propertyName);
|
||||
public void addToQuery(AuditConfiguration auditCfg, String entityName, QueryBuilder qb, Parameters parameters) {
|
||||
String propertyName = propertyNameGetter.get(auditCfg);
|
||||
|
||||
RelationDescription relatedEntity = CriteriaTools.getRelatedEntity(auditCfg, entityName, propertyName);
|
||||
|
||||
if (relatedEntity == null) {
|
||||
parameters.addWhereWithParam(propertyName, op, value);
|
||||
|
|
|
@ -121,12 +121,6 @@ public abstract class AbstractAuditQuery implements AuditQuery {
|
|||
|
||||
// Projection and order
|
||||
|
||||
public AuditQuery addProjection(String function, String propertyName) {
|
||||
hasProjection = true;
|
||||
qb.addProjection(function, propertyName, false);
|
||||
return this;
|
||||
}
|
||||
|
||||
public AuditQuery addProjection(AuditProjection projection) {
|
||||
Triple<String, String, Boolean> projectionData = projection.getData(verCfg);
|
||||
hasProjection = true;
|
||||
|
@ -134,15 +128,12 @@ public abstract class AbstractAuditQuery implements AuditQuery {
|
|||
return this;
|
||||
}
|
||||
|
||||
public AuditQuery addOrder(String propertyName, boolean asc) {
|
||||
hasOrder = true;
|
||||
qb.addOrder(propertyName, asc);
|
||||
return this;
|
||||
}
|
||||
|
||||
public AuditQuery addOrder(AuditOrder order) {
|
||||
hasOrder = true;
|
||||
|
||||
Pair<String, Boolean> orderData = order.getData(verCfg);
|
||||
return addOrder(orderData.getFirst(), orderData.getSecond());
|
||||
qb.addOrder(orderData.getFirst(), orderData.getSecond());
|
||||
return this;
|
||||
}
|
||||
|
||||
// Query properties
|
||||
|
|
|
@ -61,7 +61,7 @@ public class EntitiesAtRevisionQuery extends AbstractAuditQuery {
|
|||
|
||||
AuditEntitiesConfiguration verEntCfg = verCfg.getAuditEntCfg();
|
||||
|
||||
String revisionPropertyPath = verEntCfg.getRevisionPropPath();
|
||||
String revisionPropertyPath = verEntCfg.getRevisionNumberPath();
|
||||
String originalIdPropertyName = verEntCfg.getOriginalIdPropName();
|
||||
|
||||
// SELECT max(e2.revision)
|
||||
|
|
|
@ -57,7 +57,7 @@ public class RevisionsOfEntityQuery extends AbstractAuditQuery {
|
|||
AuditEntitiesConfiguration verEntCfg = verCfg.getAuditEntCfg();
|
||||
|
||||
String originalId = verEntCfg.getOriginalIdPropName();
|
||||
String revisionPropertyName = verEntCfg.getRevisionPropName();
|
||||
String revisionPropertyName = verEntCfg.getRevisionFieldName();
|
||||
|
||||
Object revisionInfoObject = ((Map) versionsEntity.get(originalId)).get(revisionPropertyName);
|
||||
|
||||
|
@ -92,13 +92,13 @@ public class RevisionsOfEntityQuery extends AbstractAuditQuery {
|
|||
}
|
||||
|
||||
if (!hasProjection && !hasOrder) {
|
||||
String revisionPropertyPath = verEntCfg.getRevisionPropPath();
|
||||
String revisionPropertyPath = verEntCfg.getRevisionNumberPath();
|
||||
qb.addOrder(revisionPropertyPath, true);
|
||||
}
|
||||
|
||||
if (!selectEntitiesOnly) {
|
||||
qb.addFrom(verCfg.getAuditEntCfg().getRevisionInfoEntityName(), "r");
|
||||
qb.getRootParameters().addWhere(verCfg.getAuditEntCfg().getRevisionPropPath(), true, "=", "r.id", false);
|
||||
qb.getRootParameters().addWhere(verCfg.getAuditEntCfg().getRevisionNumberPath(), true, "=", "r.id", false);
|
||||
}
|
||||
|
||||
List<Object> queryResult = buildAndExecuteQuery();
|
||||
|
|
|
@ -31,8 +31,8 @@ import org.hibernate.envers.tools.Pair;
|
|||
*/
|
||||
public interface AuditOrder {
|
||||
/**
|
||||
* @param verCfg Configuration.
|
||||
* @param auditCfg Configuration.
|
||||
* @return A pair: (property name, ascending?).
|
||||
*/
|
||||
Pair<String, Boolean> getData(AuditConfiguration verCfg);
|
||||
Pair<String, Boolean> getData(AuditConfiguration auditCfg);
|
||||
}
|
||||
|
|
|
@ -21,23 +21,26 @@
|
|||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
package org.hibernate.envers.query.order;
|
||||
|
||||
import org.hibernate.envers.configuration.AuditConfiguration;
|
||||
import org.hibernate.envers.tools.Pair;
|
||||
import org.hibernate.envers.query.property.PropertyNameGetter;
|
||||
|
||||
/**
|
||||
* @author Adam Warski (adam at warski dot org)
|
||||
*/
|
||||
public class RevisionAuditOrder implements AuditOrder {
|
||||
public class PropertyAuditOrder implements AuditOrder {
|
||||
private final PropertyNameGetter propertyNameGetter;
|
||||
private final boolean asc;
|
||||
|
||||
public RevisionAuditOrder(boolean asc) {
|
||||
public PropertyAuditOrder(PropertyNameGetter propertyNameGetter, boolean asc) {
|
||||
this.propertyNameGetter = propertyNameGetter;
|
||||
this.asc = asc;
|
||||
}
|
||||
|
||||
public Pair<String, Boolean> getData(AuditConfiguration verCfg) {
|
||||
String revisionPropPath = verCfg.getAuditEntCfg().getRevisionPropPath();
|
||||
return Pair.make(revisionPropPath, asc);
|
||||
public Pair<String, Boolean> getData(AuditConfiguration auditCfg) {
|
||||
return Pair.make(propertyNameGetter.get(auditCfg), asc);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -31,9 +31,8 @@ import org.hibernate.envers.tools.Triple;
|
|||
*/
|
||||
public interface AuditProjection {
|
||||
/**
|
||||
*
|
||||
* @param verCfg Configuration.
|
||||
* @param auditCfg Configuration.
|
||||
* @return A triple: (function name - possibly null, property name, add distinct?).
|
||||
*/
|
||||
Triple<String, String, Boolean> getData(AuditConfiguration verCfg);
|
||||
Triple<String, String, Boolean> getData(AuditConfiguration auditCfg);
|
||||
}
|
||||
|
|
|
@ -21,40 +21,30 @@
|
|||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
package org.hibernate.envers.query.projection;
|
||||
|
||||
import org.hibernate.envers.configuration.AuditConfiguration;
|
||||
import org.hibernate.envers.tools.Triple;
|
||||
import org.hibernate.envers.query.property.PropertyNameGetter;
|
||||
|
||||
/**
|
||||
* @author Adam Warski (adam at warski dot org)
|
||||
*/
|
||||
public class RevisionAuditProjection implements AuditProjection {
|
||||
public static enum ProjectionType {
|
||||
MAX,
|
||||
MIN,
|
||||
COUNT,
|
||||
COUNT_DISTINCT,
|
||||
DISTINCT
|
||||
public class PropertyAuditProjection implements AuditProjection {
|
||||
private final PropertyNameGetter propertyNameGetter;
|
||||
private final String function;
|
||||
private final boolean distinct;
|
||||
|
||||
public PropertyAuditProjection(PropertyNameGetter propertyNameGetter, String function, boolean distinct) {
|
||||
this.propertyNameGetter = propertyNameGetter;
|
||||
this.function = function;
|
||||
this.distinct = distinct;
|
||||
}
|
||||
|
||||
private final ProjectionType type;
|
||||
public Triple<String, String, Boolean> getData(AuditConfiguration auditCfg) {
|
||||
String propertyName = propertyNameGetter.get(auditCfg);
|
||||
|
||||
public RevisionAuditProjection(ProjectionType type) {
|
||||
this.type = type;
|
||||
return Triple.make(function, propertyName, distinct);
|
||||
}
|
||||
|
||||
public Triple<String, String, Boolean> getData(AuditConfiguration verCfg) {
|
||||
String revisionPropPath = verCfg.getAuditEntCfg().getRevisionPropPath();
|
||||
|
||||
switch (type) {
|
||||
case MAX: return Triple.make("max", revisionPropPath, false);
|
||||
case MIN: return Triple.make("min", revisionPropPath, false);
|
||||
case COUNT: return Triple.make("count", revisionPropPath, false);
|
||||
case COUNT_DISTINCT: return Triple.make("count", revisionPropPath, true);
|
||||
case DISTINCT: return Triple.make(null, revisionPropPath, true);
|
||||
}
|
||||
|
||||
throw new IllegalArgumentException("Unknown type " + type + ".");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
|
||||
* indicated by the @author tags or express copyright attribution
|
||||
* statements applied by the authors. All third-party contributions are
|
||||
* distributed under license by Red Hat Middleware LLC.
|
||||
*
|
||||
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||
* Lesser General Public License, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this distribution; if not, write to:
|
||||
* Free Software Foundation, Inc.
|
||||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
package org.hibernate.envers.query.property;
|
||||
|
||||
import org.hibernate.envers.configuration.AuditConfiguration;
|
||||
|
||||
/**
|
||||
* Used for specifying restrictions on a property of an audited entity.
|
||||
* @author Adam Warski (adam at warski dot org)
|
||||
*/
|
||||
public class EntityPropertyName implements PropertyNameGetter {
|
||||
private final String propertyName;
|
||||
|
||||
public EntityPropertyName(String propertyName) {
|
||||
this.propertyName = propertyName;
|
||||
}
|
||||
|
||||
public String get(AuditConfiguration auditCfg) {
|
||||
return propertyName;
|
||||
}
|
||||
}
|
|
@ -21,25 +21,24 @@
|
|||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package org.hibernate.envers.query.criteria;
|
||||
|
||||
package org.hibernate.envers.query.property;
|
||||
|
||||
import org.hibernate.envers.configuration.AuditConfiguration;
|
||||
import org.hibernate.envers.tools.query.Parameters;
|
||||
import org.hibernate.envers.tools.query.QueryBuilder;
|
||||
|
||||
/**
|
||||
* Used for specifying restrictions on the identifier.
|
||||
* TODO: idPropertyName should be read basing on auditCfg + entityName
|
||||
* @author Adam Warski (adam at warski dot org)
|
||||
*/
|
||||
public class RevisionAuditExpression implements AuditCriterion {
|
||||
private Object value;
|
||||
private String op;
|
||||
public class OriginalIdPropertyName implements PropertyNameGetter {
|
||||
private final String idPropertyName;
|
||||
|
||||
public RevisionAuditExpression(Object value, String op) {
|
||||
this.value = value;
|
||||
this.op = op;
|
||||
public OriginalIdPropertyName(String idPropertyName) {
|
||||
this.idPropertyName = idPropertyName;
|
||||
}
|
||||
|
||||
public void addToQuery(AuditConfiguration verCfg, String entityName, QueryBuilder qb, Parameters parameters) {
|
||||
parameters.addWhereWithParam(verCfg.getAuditEntCfg().getRevisionPropPath(), op, value);
|
||||
public String get(AuditConfiguration auditCfg) {
|
||||
return auditCfg.getAuditEntCfg().getOriginalIdPropName() + "." + idPropertyName;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
|
||||
* indicated by the @author tags or express copyright attribution
|
||||
* statements applied by the authors. All third-party contributions are
|
||||
* distributed under license by Red Hat Middleware LLC.
|
||||
*
|
||||
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||
* Lesser General Public License, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this distribution; if not, write to:
|
||||
* Free Software Foundation, Inc.
|
||||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
package org.hibernate.envers.query.property;
|
||||
|
||||
import org.hibernate.envers.configuration.AuditConfiguration;
|
||||
|
||||
/**
|
||||
* Provides a function to get the name of a property, which is used in a query, to apply some restrictions on it.
|
||||
* @author Adam Warski (adam at warski dot org)
|
||||
*/
|
||||
public interface PropertyNameGetter {
|
||||
/**
|
||||
* @param auditCfg Audit configuration.
|
||||
* @return Name of the property, to be used in a query.
|
||||
*/
|
||||
public String get(AuditConfiguration auditCfg);
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
|
||||
* indicated by the @author tags or express copyright attribution
|
||||
* statements applied by the authors. All third-party contributions are
|
||||
* distributed under license by Red Hat Middleware LLC.
|
||||
*
|
||||
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||
* Lesser General Public License, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this distribution; if not, write to:
|
||||
* Free Software Foundation, Inc.
|
||||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
package org.hibernate.envers.query.property;
|
||||
|
||||
import org.hibernate.envers.configuration.AuditConfiguration;
|
||||
|
||||
/**
|
||||
* Used for specifying restrictions on the revision number, corresponding to an audit entity.
|
||||
* @author Adam Warski (adam at warski dot org)
|
||||
*/
|
||||
public class RevisionNumberPropertyName implements PropertyNameGetter {
|
||||
public String get(AuditConfiguration auditCfg) {
|
||||
return auditCfg.getAuditEntCfg().getRevisionNumberPath();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
|
||||
* indicated by the @author tags or express copyright attribution
|
||||
* statements applied by the authors. All third-party contributions are
|
||||
* distributed under license by Red Hat Middleware LLC.
|
||||
*
|
||||
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||
* Lesser General Public License, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this distribution; if not, write to:
|
||||
* Free Software Foundation, Inc.
|
||||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
package org.hibernate.envers.query.property;
|
||||
|
||||
import org.hibernate.envers.configuration.AuditConfiguration;
|
||||
|
||||
/**
|
||||
* Used for specifying restrictions on a property of the revision entity, which is associated with an audit entity.
|
||||
* @author Adam Warski (adam at warski dot org)
|
||||
*/
|
||||
public class RevisionPropertyPropertyName implements PropertyNameGetter {
|
||||
private final String propertyName;
|
||||
|
||||
public RevisionPropertyPropertyName(String propertyName) {
|
||||
this.propertyName = propertyName;
|
||||
}
|
||||
|
||||
public String get(AuditConfiguration auditCfg) {
|
||||
return auditCfg.getAuditEntCfg().getRevisionPropPath(propertyName);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
|
||||
* indicated by the @author tags or express copyright attribution
|
||||
* statements applied by the authors. All third-party contributions are
|
||||
* distributed under license by Red Hat Middleware LLC.
|
||||
*
|
||||
* This copyrighted material is made available to anyone wishing to use, modify,
|
||||
* copy, or redistribute it subject to the terms and conditions of the GNU
|
||||
* Lesser General Public License, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this distribution; if not, write to:
|
||||
* Free Software Foundation, Inc.
|
||||
* 51 Franklin Street, Fifth Floor
|
||||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
package org.hibernate.envers.query.property;
|
||||
|
||||
import org.hibernate.envers.configuration.AuditConfiguration;
|
||||
|
||||
/**
|
||||
* Used for specifying restrictions on the revision number, corresponding to an audit entity.
|
||||
* @author Adam Warski (adam at warski dot org)
|
||||
*/
|
||||
public class RevisionTypePropertyName implements PropertyNameGetter {
|
||||
public String get(AuditConfiguration auditCfg) {
|
||||
return auditCfg.getAuditEntCfg().getRevisionTypePropName();
|
||||
}
|
||||
}
|
|
@ -31,8 +31,7 @@ import org.hibernate.envers.configuration.AuditConfiguration;
|
|||
import org.hibernate.envers.exception.NotAuditedException;
|
||||
import org.hibernate.envers.exception.RevisionDoesNotExistException;
|
||||
import org.hibernate.envers.exception.AuditException;
|
||||
import org.hibernate.envers.query.RevisionProperty;
|
||||
import org.hibernate.envers.query.AuditRestrictions;
|
||||
import org.hibernate.envers.query.AuditEntity;
|
||||
import static org.hibernate.envers.tools.ArgumentsTools.checkNotNull;
|
||||
import static org.hibernate.envers.tools.ArgumentsTools.checkPositive;
|
||||
|
||||
|
@ -101,7 +100,7 @@ public class AuditReaderImpl implements AuditReaderImplementor {
|
|||
try {
|
||||
// The result is put into the cache by the entity instantiator called from the query
|
||||
result = createQuery().forEntitiesAtRevision(cls, revision)
|
||||
.add(AuditRestrictions.idEq(primaryKey)).getSingleResult();
|
||||
.add(AuditEntity.id().eq(primaryKey)).getSingleResult();
|
||||
} catch (NoResultException e) {
|
||||
result = null;
|
||||
} catch (NonUniqueResultException e) {
|
||||
|
@ -126,8 +125,8 @@ public class AuditReaderImpl implements AuditReaderImplementor {
|
|||
}
|
||||
|
||||
return createQuery().forRevisionsOfEntity(cls, false, true)
|
||||
.addProjection(RevisionProperty.revisionNumber())
|
||||
.add(AuditRestrictions.idEq(primaryKey))
|
||||
.addProjection(AuditEntity.revisionNumber())
|
||||
.add(AuditEntity.id().eq(primaryKey))
|
||||
.getResultList();
|
||||
}
|
||||
|
||||
|
|
|
@ -54,7 +54,7 @@ public abstract class AbstractAuditWorkUnit implements AuditWorkUnit {
|
|||
AuditEntitiesConfiguration entitiesCfg = verCfg.getAuditEntCfg();
|
||||
|
||||
Map<String, Object> originalId = new HashMap<String, Object>();
|
||||
originalId.put(entitiesCfg.getRevisionPropName(), revision);
|
||||
originalId.put(entitiesCfg.getRevisionFieldName(), revision);
|
||||
|
||||
verCfg.getEntCfg().get(getEntityName()).getIdMapper().mapToMapFromId(originalId, id);
|
||||
data.put(entitiesCfg.getRevisionTypePropName(), revisionType);
|
||||
|
|
|
@ -63,7 +63,7 @@ public class PersistentCollectionChangeWorkUnit extends AbstractAuditWorkUnit im
|
|||
for (PersistentCollectionChangeData persistentCollectionChangeData : collectionChanges) {
|
||||
// Setting the revision number
|
||||
((Map<String, Object>) persistentCollectionChangeData.getData().get(entitiesCfg.getOriginalIdPropName()))
|
||||
.put(entitiesCfg.getRevisionPropName(), revisionData);
|
||||
.put(entitiesCfg.getRevisionFieldName(), revisionData);
|
||||
|
||||
session.save(persistentCollectionChangeData.getEntityName(), persistentCollectionChangeData.getData());
|
||||
}
|
||||
|
|
|
@ -27,6 +27,7 @@ import javax.persistence.EntityManager;
|
|||
|
||||
import org.hibernate.envers.test.AbstractEntityTest;
|
||||
import org.hibernate.envers.test.entities.IntTestEntity;
|
||||
import org.hibernate.envers.query.AuditEntity;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
|
@ -83,20 +84,20 @@ public class AggregateQuery extends AbstractEntityTest {
|
|||
public void testEntitiesAvgMaxQuery() {
|
||||
Object[] ver1 = (Object[]) getAuditReader().createQuery()
|
||||
.forEntitiesAtRevision(IntTestEntity.class, 1)
|
||||
.addProjection("max", "number")
|
||||
.addProjection("avg", "number")
|
||||
.addProjection(AuditEntity.property("number").max())
|
||||
.addProjection(AuditEntity.property("number").function("avg"))
|
||||
.getSingleResult();
|
||||
|
||||
Object[] ver2 = (Object[]) getAuditReader().createQuery()
|
||||
.forEntitiesAtRevision(IntTestEntity.class, 2)
|
||||
.addProjection("max", "number")
|
||||
.addProjection("avg", "number")
|
||||
.addProjection(AuditEntity.property("number").max())
|
||||
.addProjection(AuditEntity.property("number").function("avg"))
|
||||
.getSingleResult();
|
||||
|
||||
Object[] ver3 = (Object[]) getAuditReader().createQuery()
|
||||
.forEntitiesAtRevision(IntTestEntity.class, 3)
|
||||
.addProjection("max", "number")
|
||||
.addProjection("avg", "number")
|
||||
.addProjection(AuditEntity.property("number").max())
|
||||
.addProjection(AuditEntity.property("number").function("avg"))
|
||||
.getSingleResult();
|
||||
|
||||
assert (Integer) ver1[0] == 10;
|
||||
|
|
|
@ -26,7 +26,7 @@ package org.hibernate.envers.test.integration.query;
|
|||
import java.util.List;
|
||||
import javax.persistence.EntityManager;
|
||||
|
||||
import org.hibernate.envers.query.AuditRestrictions;
|
||||
import org.hibernate.envers.query.AuditEntity;
|
||||
import org.hibernate.envers.test.AbstractEntityTest;
|
||||
import org.hibernate.envers.test.entities.StrIntTestEntity;
|
||||
import org.hibernate.envers.test.entities.reventity.CustomRevEntity;
|
||||
|
@ -42,6 +42,7 @@ import org.hibernate.ejb.Ejb3Configuration;
|
|||
public class CustomRevEntityQuery extends AbstractEntityTest {
|
||||
private Integer id1;
|
||||
private Integer id2;
|
||||
private Long timestamp;
|
||||
|
||||
public void configure(Ejb3Configuration cfg) {
|
||||
cfg.addAnnotatedClass(CustomRevEntity.class);
|
||||
|
@ -49,7 +50,7 @@ public class CustomRevEntityQuery extends AbstractEntityTest {
|
|||
}
|
||||
|
||||
@BeforeClass(dependsOnMethods = "init")
|
||||
public void initData() {
|
||||
public void initData() throws InterruptedException {
|
||||
// Revision 1
|
||||
EntityManager em = getEntityManager();
|
||||
em.getTransaction().begin();
|
||||
|
@ -65,6 +66,12 @@ public class CustomRevEntityQuery extends AbstractEntityTest {
|
|||
|
||||
em.getTransaction().commit();
|
||||
|
||||
Thread.sleep(100);
|
||||
|
||||
timestamp = System.currentTimeMillis();
|
||||
|
||||
Thread.sleep(100);
|
||||
|
||||
// Revision 2
|
||||
em.getTransaction().begin();
|
||||
|
||||
|
@ -79,7 +86,7 @@ public class CustomRevEntityQuery extends AbstractEntityTest {
|
|||
public void testRevisionsOfId1Query() {
|
||||
List<Object[]> result = getAuditReader().createQuery()
|
||||
.forRevisionsOfEntity(StrIntTestEntity.class, false, true)
|
||||
.add(AuditRestrictions.idEq(id1))
|
||||
.add(AuditEntity.id().eq(id1))
|
||||
.getResultList();
|
||||
|
||||
assert result.get(0)[0].equals(new StrIntTestEntity("a", 10, id1));
|
||||
|
@ -95,11 +102,25 @@ public class CustomRevEntityQuery extends AbstractEntityTest {
|
|||
public void testRevisionsOfId2Query() {
|
||||
List<Object[]> result = getAuditReader().createQuery()
|
||||
.forRevisionsOfEntity(StrIntTestEntity.class, false, true)
|
||||
.add(AuditRestrictions.idEq(id2))
|
||||
.add(AuditEntity.id().eq(id2))
|
||||
.getResultList();
|
||||
|
||||
assert result.get(0)[0].equals(new StrIntTestEntity("b", 15, id2));
|
||||
assert result.get(0)[1] instanceof CustomRevEntity;
|
||||
assert ((CustomRevEntity) result.get(0)[1]).getCustomId() == 1;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRevisionPropertyRestriction() {
|
||||
List<Object[]> result = getAuditReader().createQuery()
|
||||
.forRevisionsOfEntity(StrIntTestEntity.class, false, true)
|
||||
.add(AuditEntity.id().eq(id1))
|
||||
.add(AuditEntity.revisionProperty("customTimestamp").ge(timestamp))
|
||||
.getResultList();
|
||||
|
||||
assert result.get(0)[0].equals(new StrIntTestEntity("c", 10, id1));
|
||||
assert result.get(0)[1] instanceof CustomRevEntity;
|
||||
assert ((CustomRevEntity) result.get(0)[1]).getCustomId() == 2;
|
||||
assert ((CustomRevEntity) result.get(0)[1]).getCustomTimestamp() >= timestamp;
|
||||
}
|
||||
}
|
|
@ -28,7 +28,7 @@ import javax.persistence.EntityManager;
|
|||
|
||||
import org.hibernate.envers.DefaultRevisionEntity;
|
||||
import org.hibernate.envers.RevisionType;
|
||||
import org.hibernate.envers.query.AuditRestrictions;
|
||||
import org.hibernate.envers.query.AuditEntity;
|
||||
import org.hibernate.envers.test.AbstractEntityTest;
|
||||
import org.hibernate.envers.test.entities.StrIntTestEntity;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
|
@ -79,16 +79,16 @@ public class DeletedEntities extends AbstractEntityTest {
|
|||
.getResultList().size() == 1;
|
||||
|
||||
assert (Long) getAuditReader().createQuery().forEntitiesAtRevision(StrIntTestEntity.class, 1)
|
||||
.addProjection("count", "originalId.id").getResultList().get(0) == 2;
|
||||
.addProjection(AuditEntity.id().count("id")).getResultList().get(0) == 2;
|
||||
assert (Long) getAuditReader().createQuery().forEntitiesAtRevision(StrIntTestEntity.class, 2)
|
||||
.addProjection("count", "originalId.id").getResultList().get(0) == 1;
|
||||
.addProjection(AuditEntity.id().count("id")).getResultList().get(0) == 1;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRevisionsOfEntityWithoutDelete() {
|
||||
List result = getAuditReader().createQuery()
|
||||
.forRevisionsOfEntity(StrIntTestEntity.class, false, false)
|
||||
.add(AuditRestrictions.idEq(id2))
|
||||
.add(AuditEntity.id().eq(id2))
|
||||
.getResultList();
|
||||
|
||||
assert result.size() == 1;
|
||||
|
|
|
@ -27,8 +27,7 @@ import java.util.Arrays;
|
|||
import java.util.List;
|
||||
import javax.persistence.EntityManager;
|
||||
|
||||
import org.hibernate.envers.query.RevisionProperty;
|
||||
import org.hibernate.envers.query.AuditRestrictions;
|
||||
import org.hibernate.envers.query.AuditEntity;
|
||||
import org.hibernate.envers.test.AbstractEntityTest;
|
||||
import org.hibernate.envers.test.entities.StrIntTestEntity;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
|
@ -103,9 +102,9 @@ public class MaximalizePropertyQuery extends AbstractEntityTest {
|
|||
public void testMaximizeWithIdEq() {
|
||||
List revs_id1 = getAuditReader().createQuery()
|
||||
.forRevisionsOfEntity(StrIntTestEntity.class, false, true)
|
||||
.addProjection(RevisionProperty.revisionNumber())
|
||||
.add(AuditRestrictions.maximizeProperty("number")
|
||||
.add(AuditRestrictions.idEq(id2)))
|
||||
.addProjection(AuditEntity.revisionNumber())
|
||||
.add(AuditEntity.property("number").maximize()
|
||||
.add(AuditEntity.id().eq(id2)))
|
||||
.getResultList();
|
||||
|
||||
assert Arrays.asList(2, 3, 4).equals(revs_id1);
|
||||
|
@ -115,11 +114,24 @@ public class MaximalizePropertyQuery extends AbstractEntityTest {
|
|||
public void testMinimizeWithPropertyEq() {
|
||||
List result = getAuditReader().createQuery()
|
||||
.forRevisionsOfEntity(StrIntTestEntity.class, false, true)
|
||||
.addProjection(RevisionProperty.revisionNumber())
|
||||
.add(AuditRestrictions.minimizeProperty("number")
|
||||
.add(AuditRestrictions.eq("str1", "a")))
|
||||
.addProjection(AuditEntity.revisionNumber())
|
||||
.add(AuditEntity.property("number").minimize()
|
||||
.add(AuditEntity.property("str1").eq("a")))
|
||||
.getResultList();
|
||||
|
||||
assert Arrays.asList(1).equals(result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMaximizeRevision() {
|
||||
List result = getAuditReader().createQuery()
|
||||
.forRevisionsOfEntity(StrIntTestEntity.class, false, true)
|
||||
.addProjection(AuditEntity.revisionNumber())
|
||||
.add(AuditEntity.revisionNumber().maximize()
|
||||
.add(AuditEntity.property("number").eq(10)))
|
||||
.getResultList();
|
||||
|
||||
System.out.println(result);
|
||||
assert Arrays.asList(2).equals(result);
|
||||
}
|
||||
}
|
|
@ -29,6 +29,7 @@ import javax.persistence.EntityManager;
|
|||
|
||||
import org.hibernate.envers.test.AbstractEntityTest;
|
||||
import org.hibernate.envers.test.entities.IntTestEntity;
|
||||
import org.hibernate.envers.query.AuditEntity;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
|
@ -92,21 +93,21 @@ public class OrderByLimitQuery extends AbstractEntityTest {
|
|||
public void testEntitiesOrderLimitByQueryRev1() {
|
||||
List res_0_to_1 = getAuditReader().createQuery()
|
||||
.forEntitiesAtRevision(IntTestEntity.class, 1)
|
||||
.addOrder("number", false)
|
||||
.addOrder(AuditEntity.property("number").desc())
|
||||
.setFirstResult(0)
|
||||
.setMaxResults(2)
|
||||
.getResultList();
|
||||
|
||||
List res_2_to_3 = getAuditReader().createQuery()
|
||||
.forEntitiesAtRevision(IntTestEntity.class, 1)
|
||||
.addOrder("number", false)
|
||||
.addOrder(AuditEntity.property("number").desc())
|
||||
.setFirstResult(2)
|
||||
.setMaxResults(2)
|
||||
.getResultList();
|
||||
|
||||
List res_empty = getAuditReader().createQuery()
|
||||
.forEntitiesAtRevision(IntTestEntity.class, 1)
|
||||
.addOrder("number", false)
|
||||
.addOrder(AuditEntity.property("number").desc())
|
||||
.setFirstResult(4)
|
||||
.setMaxResults(2)
|
||||
.getResultList();
|
||||
|
@ -120,21 +121,21 @@ public class OrderByLimitQuery extends AbstractEntityTest {
|
|||
public void testEntitiesOrderLimitByQueryRev2() {
|
||||
List res_0_to_1 = getAuditReader().createQuery()
|
||||
.forEntitiesAtRevision(IntTestEntity.class, 2)
|
||||
.addOrder("number", false)
|
||||
.addOrder(AuditEntity.property("number").desc())
|
||||
.setFirstResult(0)
|
||||
.setMaxResults(2)
|
||||
.getResultList();
|
||||
|
||||
List res_2_to_3 = getAuditReader().createQuery()
|
||||
.forEntitiesAtRevision(IntTestEntity.class, 2)
|
||||
.addOrder("number", false)
|
||||
.addOrder(AuditEntity.property("number").desc())
|
||||
.setFirstResult(2)
|
||||
.setMaxResults(2)
|
||||
.getResultList();
|
||||
|
||||
List res_4 = getAuditReader().createQuery()
|
||||
.forEntitiesAtRevision(IntTestEntity.class, 2)
|
||||
.addOrder("number", false)
|
||||
.addOrder(AuditEntity.property("number").desc())
|
||||
.setFirstResult(4)
|
||||
.setMaxResults(2)
|
||||
.getResultList();
|
||||
|
|
|
@ -27,9 +27,7 @@ import java.util.Arrays;
|
|||
import java.util.List;
|
||||
import javax.persistence.EntityManager;
|
||||
|
||||
import org.hibernate.envers.query.RevisionProperty;
|
||||
import org.hibernate.envers.query.AuditRestrictions;
|
||||
import org.hibernate.envers.query.RevisionTypeProperty;
|
||||
import org.hibernate.envers.query.AuditEntity;
|
||||
import org.hibernate.envers.test.AbstractEntityTest;
|
||||
import org.hibernate.envers.test.entities.StrIntTestEntity;
|
||||
import org.hibernate.envers.RevisionType;
|
||||
|
@ -104,8 +102,8 @@ public class RevisionConstraintQuery extends AbstractEntityTest {
|
|||
public void testRevisionsLtQuery() {
|
||||
List result = getAuditReader().createQuery()
|
||||
.forRevisionsOfEntity(StrIntTestEntity.class, false, true)
|
||||
.addProjection(RevisionProperty.distinct())
|
||||
.add(RevisionProperty.lt(3))
|
||||
.addProjection(AuditEntity.revisionNumber().distinct())
|
||||
.add(AuditEntity.revisionNumber().lt(3))
|
||||
.getResultList();
|
||||
|
||||
assert Arrays.asList(1, 2).equals(result);
|
||||
|
@ -115,8 +113,8 @@ public class RevisionConstraintQuery extends AbstractEntityTest {
|
|||
public void testRevisionsGeQuery() {
|
||||
List result = getAuditReader().createQuery()
|
||||
.forRevisionsOfEntity(StrIntTestEntity.class, false, true)
|
||||
.addProjection(RevisionProperty.distinct())
|
||||
.add(RevisionProperty.ge(2))
|
||||
.addProjection(AuditEntity.revisionNumber().distinct())
|
||||
.add(AuditEntity.revisionNumber().ge(2))
|
||||
.getResultList();
|
||||
|
||||
assert Arrays.asList(2, 3, 4).equals(result);
|
||||
|
@ -126,9 +124,9 @@ public class RevisionConstraintQuery extends AbstractEntityTest {
|
|||
public void testRevisionsLeWithPropertyQuery() {
|
||||
List result = getAuditReader().createQuery()
|
||||
.forRevisionsOfEntity(StrIntTestEntity.class, false, true)
|
||||
.addProjection(RevisionProperty.revisionNumber())
|
||||
.add(RevisionProperty.le(3))
|
||||
.add(AuditRestrictions.eq("str1", "a"))
|
||||
.addProjection(AuditEntity.revisionNumber())
|
||||
.add(AuditEntity.revisionNumber().le(3))
|
||||
.add(AuditEntity.property("str1").eq("a"))
|
||||
.getResultList();
|
||||
|
||||
assert Arrays.asList(1).equals(result);
|
||||
|
@ -138,9 +136,9 @@ public class RevisionConstraintQuery extends AbstractEntityTest {
|
|||
public void testRevisionsGtWithPropertyQuery() {
|
||||
List result = getAuditReader().createQuery()
|
||||
.forRevisionsOfEntity(StrIntTestEntity.class, false, true)
|
||||
.addProjection(RevisionProperty.revisionNumber())
|
||||
.add(RevisionProperty.gt(1))
|
||||
.add(AuditRestrictions.lt("number", 10))
|
||||
.addProjection(AuditEntity.revisionNumber())
|
||||
.add(AuditEntity.revisionNumber().gt(1))
|
||||
.add(AuditEntity.property("number").lt(10))
|
||||
.getResultList();
|
||||
|
||||
assert Arrays.asList(3, 4).equals(result);
|
||||
|
@ -150,11 +148,11 @@ public class RevisionConstraintQuery extends AbstractEntityTest {
|
|||
public void testRevisionProjectionQuery() {
|
||||
Object[] result = (Object[]) getAuditReader().createQuery()
|
||||
.forRevisionsOfEntity(StrIntTestEntity.class, false, true)
|
||||
.addProjection(RevisionProperty.max())
|
||||
.addProjection(RevisionProperty.count())
|
||||
.addProjection(RevisionProperty.countDistinct())
|
||||
.addProjection(RevisionProperty.min())
|
||||
.add(AuditRestrictions.idEq(id1))
|
||||
.addProjection(AuditEntity.revisionNumber().max())
|
||||
.addProjection(AuditEntity.revisionNumber().count())
|
||||
.addProjection(AuditEntity.revisionNumber().countDistinct())
|
||||
.addProjection(AuditEntity.revisionNumber().min())
|
||||
.add(AuditEntity.id().eq(id1))
|
||||
.getSingleResult();
|
||||
|
||||
assert (Integer) result[0] == 4;
|
||||
|
@ -167,9 +165,9 @@ public class RevisionConstraintQuery extends AbstractEntityTest {
|
|||
public void testRevisionOrderQuery() {
|
||||
List result = getAuditReader().createQuery()
|
||||
.forRevisionsOfEntity(StrIntTestEntity.class, false, true)
|
||||
.addProjection(RevisionProperty.revisionNumber())
|
||||
.add(AuditRestrictions.idEq(id1))
|
||||
.addOrder(RevisionProperty.desc())
|
||||
.addProjection(AuditEntity.revisionNumber())
|
||||
.add(AuditEntity.id().eq(id1))
|
||||
.addOrder(AuditEntity.revisionNumber().desc())
|
||||
.getResultList();
|
||||
|
||||
assert Arrays.asList(4, 3, 2, 1).equals(result);
|
||||
|
@ -180,8 +178,8 @@ public class RevisionConstraintQuery extends AbstractEntityTest {
|
|||
// The query shouldn't be ordered as always, otherwise - we get an exception.
|
||||
Object result = getAuditReader().createQuery()
|
||||
.forRevisionsOfEntity(StrIntTestEntity.class, false, true)
|
||||
.addProjection(RevisionProperty.count())
|
||||
.add(AuditRestrictions.idEq(id1))
|
||||
.addProjection(AuditEntity.revisionNumber().count())
|
||||
.add(AuditEntity.id().eq(id1))
|
||||
.getSingleResult();
|
||||
|
||||
assert (Long) result == 4;
|
||||
|
@ -192,8 +190,8 @@ public class RevisionConstraintQuery extends AbstractEntityTest {
|
|||
// The query shouldn't be ordered as always, otherwise - we get an exception.
|
||||
List results = getAuditReader().createQuery()
|
||||
.forRevisionsOfEntity(StrIntTestEntity.class, true, true)
|
||||
.add(AuditRestrictions.idEq(id1))
|
||||
.add(RevisionTypeProperty.eq(RevisionType.MOD))
|
||||
.add(AuditEntity.id().eq(id1))
|
||||
.add(AuditEntity.revisionType().eq(RevisionType.MOD))
|
||||
.getResultList();
|
||||
|
||||
assert results.size() == 3;
|
||||
|
@ -207,8 +205,8 @@ public class RevisionConstraintQuery extends AbstractEntityTest {
|
|||
// The query shouldn't be ordered as always, otherwise - we get an exception.
|
||||
List results = getAuditReader().createQuery()
|
||||
.forRevisionsOfEntity(StrIntTestEntity.class, true, true)
|
||||
.add(AuditRestrictions.idEq(id1))
|
||||
.add(RevisionTypeProperty.ne(RevisionType.MOD))
|
||||
.add(AuditEntity.id().eq(id1))
|
||||
.add(AuditEntity.revisionType().ne(RevisionType.MOD))
|
||||
.getResultList();
|
||||
|
||||
assert results.size() == 1;
|
||||
|
|
|
@ -30,9 +30,7 @@ import javax.persistence.EntityManager;
|
|||
|
||||
import org.hibernate.envers.DefaultRevisionEntity;
|
||||
import org.hibernate.envers.RevisionType;
|
||||
import org.hibernate.envers.query.RevisionProperty;
|
||||
import org.hibernate.envers.query.RevisionTypeProperty;
|
||||
import org.hibernate.envers.query.AuditRestrictions;
|
||||
import org.hibernate.envers.query.AuditEntity;
|
||||
import org.hibernate.envers.test.AbstractEntityTest;
|
||||
import org.hibernate.envers.test.entities.StrIntTestEntity;
|
||||
import org.hibernate.envers.test.tools.TestTools;
|
||||
|
@ -108,7 +106,7 @@ public class SimpleQuery extends AbstractEntityTest {
|
|||
public void testEntitiesIdQuery() {
|
||||
StrIntTestEntity ver2 = (StrIntTestEntity) getAuditReader().createQuery()
|
||||
.forEntitiesAtRevision(StrIntTestEntity.class, 2)
|
||||
.add(AuditRestrictions.idEq(id2))
|
||||
.add(AuditEntity.id().eq(id2))
|
||||
.getSingleResult();
|
||||
|
||||
assert ver2.equals(new StrIntTestEntity("a", 20, id2));
|
||||
|
@ -118,17 +116,17 @@ public class SimpleQuery extends AbstractEntityTest {
|
|||
public void testEntitiesPropertyEqualsQuery() {
|
||||
List ver1 = getAuditReader().createQuery()
|
||||
.forEntitiesAtRevision(StrIntTestEntity.class, 1)
|
||||
.add(AuditRestrictions.eq("str1", "a"))
|
||||
.add(AuditEntity.property("str1").eq("a"))
|
||||
.getResultList();
|
||||
|
||||
List ver2 = getAuditReader().createQuery()
|
||||
.forEntitiesAtRevision(StrIntTestEntity.class, 2)
|
||||
.add(AuditRestrictions.eq("str1", "a"))
|
||||
.add(AuditEntity.property("str1").eq("a"))
|
||||
.getResultList();
|
||||
|
||||
List ver3 = getAuditReader().createQuery()
|
||||
.forEntitiesAtRevision(StrIntTestEntity.class, 3)
|
||||
.add(AuditRestrictions.eq("str1", "a"))
|
||||
.add(AuditEntity.property("str1").eq("a"))
|
||||
.getResultList();
|
||||
|
||||
assert new HashSet(ver1).equals(TestTools.makeSet(new StrIntTestEntity("a", 10, id1),
|
||||
|
@ -142,17 +140,17 @@ public class SimpleQuery extends AbstractEntityTest {
|
|||
public void testEntitiesPropertyLeQuery() {
|
||||
List ver1 = getAuditReader().createQuery()
|
||||
.forEntitiesAtRevision(StrIntTestEntity.class, 1)
|
||||
.add(AuditRestrictions.le("number", 10))
|
||||
.add(AuditEntity.property("number").le(10))
|
||||
.getResultList();
|
||||
|
||||
List ver2 = getAuditReader().createQuery()
|
||||
.forEntitiesAtRevision(StrIntTestEntity.class, 2)
|
||||
.add(AuditRestrictions.le("number", 10))
|
||||
.add(AuditEntity.property("number").le(10))
|
||||
.getResultList();
|
||||
|
||||
List ver3 = getAuditReader().createQuery()
|
||||
.forEntitiesAtRevision(StrIntTestEntity.class, 3)
|
||||
.add(AuditRestrictions.le("number", 10))
|
||||
.add(AuditEntity.property("number").le(10))
|
||||
.getResultList();
|
||||
|
||||
assert new HashSet(ver1).equals(TestTools.makeSet(new StrIntTestEntity("a", 10, id1),
|
||||
|
@ -167,23 +165,23 @@ public class SimpleQuery extends AbstractEntityTest {
|
|||
public void testRevisionsPropertyEqQuery() {
|
||||
List revs_id1 = getAuditReader().createQuery()
|
||||
.forRevisionsOfEntity(StrIntTestEntity.class, false, true)
|
||||
.addProjection(RevisionProperty.revisionNumber())
|
||||
.add(AuditRestrictions.le("str1", "a"))
|
||||
.add(AuditRestrictions.idEq(id1))
|
||||
.addProjection(AuditEntity.revisionNumber())
|
||||
.add(AuditEntity.property("str1").le("a"))
|
||||
.add(AuditEntity.id().eq(id1))
|
||||
.getResultList();
|
||||
|
||||
List revs_id2 = getAuditReader().createQuery()
|
||||
.forRevisionsOfEntity(StrIntTestEntity.class, false, true)
|
||||
.addProjection(RevisionProperty.revisionNumber())
|
||||
.add(AuditRestrictions.le("str1", "a"))
|
||||
.add(AuditRestrictions.idEq(id2))
|
||||
.addProjection(AuditEntity.revisionNumber())
|
||||
.add(AuditEntity.property("str1").le("a"))
|
||||
.add(AuditEntity.id().eq(id2))
|
||||
.getResultList();
|
||||
|
||||
List revs_id3 = getAuditReader().createQuery()
|
||||
.forRevisionsOfEntity(StrIntTestEntity.class, false, true)
|
||||
.addProjection(RevisionProperty.revisionNumber())
|
||||
.add(AuditRestrictions.le("str1", "a"))
|
||||
.add(AuditRestrictions.idEq(id3))
|
||||
.addProjection(AuditEntity.revisionNumber())
|
||||
.add(AuditEntity.property("str1").le("a"))
|
||||
.add(AuditEntity.id().eq(id3))
|
||||
.getResultList();
|
||||
|
||||
assert Arrays.asList(1).equals(revs_id1);
|
||||
|
@ -195,7 +193,7 @@ public class SimpleQuery extends AbstractEntityTest {
|
|||
public void testSelectEntitiesQuery() {
|
||||
List result = getAuditReader().createQuery()
|
||||
.forRevisionsOfEntity(StrIntTestEntity.class, true, false)
|
||||
.add(AuditRestrictions.idEq(id1))
|
||||
.add(AuditEntity.id().eq(id1))
|
||||
.getResultList();
|
||||
|
||||
assert result.size() == 2;
|
||||
|
@ -208,7 +206,7 @@ public class SimpleQuery extends AbstractEntityTest {
|
|||
public void testSelectEntitiesAndRevisionsQuery() {
|
||||
List result = getAuditReader().createQuery()
|
||||
.forRevisionsOfEntity(StrIntTestEntity.class, false, true)
|
||||
.add(AuditRestrictions.idEq(id1))
|
||||
.add(AuditEntity.id().eq(id1))
|
||||
.getResultList();
|
||||
|
||||
assert result.size() == 3;
|
||||
|
@ -230,8 +228,8 @@ public class SimpleQuery extends AbstractEntityTest {
|
|||
public void testSelectRevisionTypeQuery() {
|
||||
List result = getAuditReader().createQuery()
|
||||
.forRevisionsOfEntity(StrIntTestEntity.class, false, true)
|
||||
.addProjection(RevisionTypeProperty.revisionType())
|
||||
.add(AuditRestrictions.idEq(id1))
|
||||
.addProjection(AuditEntity.revisionType())
|
||||
.add(AuditEntity.id().eq(id1))
|
||||
.getResultList();
|
||||
|
||||
assert result.size() == 3;
|
||||
|
@ -254,7 +252,7 @@ public class SimpleQuery extends AbstractEntityTest {
|
|||
public void testEmptyConjunctionRevisionOfEntityQuery() {
|
||||
List result = getAuditReader().createQuery()
|
||||
.forRevisionsOfEntity(StrIntTestEntity.class, false, true)
|
||||
.add(AuditRestrictions.conjunction())
|
||||
.add(AuditEntity.conjunction())
|
||||
.getResultList();
|
||||
|
||||
assert result.size() == 7;
|
||||
|
@ -264,7 +262,7 @@ public class SimpleQuery extends AbstractEntityTest {
|
|||
public void testEmptyDisjunctionRevisionOfEntityQuery() {
|
||||
List result = getAuditReader().createQuery()
|
||||
.forRevisionsOfEntity(StrIntTestEntity.class, false, true)
|
||||
.add(AuditRestrictions.disjunction())
|
||||
.add(AuditEntity.disjunction())
|
||||
.getResultList();
|
||||
|
||||
assert result.size() == 0;
|
||||
|
|
|
@ -28,7 +28,7 @@ import java.util.List;
|
|||
import java.util.Set;
|
||||
import javax.persistence.EntityManager;
|
||||
|
||||
import org.hibernate.envers.query.AuditRestrictions;
|
||||
import org.hibernate.envers.query.AuditEntity;
|
||||
import org.hibernate.envers.test.AbstractEntityTest;
|
||||
import org.hibernate.envers.test.entities.ids.EmbId;
|
||||
import org.hibernate.envers.test.entities.onetomany.ids.SetRefEdEmbIdEntity;
|
||||
|
@ -105,32 +105,32 @@ public class EmbIdOneToManyQuery extends AbstractEntityTest {
|
|||
public void testEntitiesReferencedToId3() {
|
||||
Set rev1_related = new HashSet(getAuditReader().createQuery()
|
||||
.forEntitiesAtRevision(SetRefIngEmbIdEntity.class, 1)
|
||||
.add(AuditRestrictions.relatedIdEq("reference", id3))
|
||||
.add(AuditEntity.relatedId("reference").eq(id3))
|
||||
.getResultList());
|
||||
|
||||
Set rev1 = new HashSet(getAuditReader().createQuery()
|
||||
.forEntitiesAtRevision(SetRefIngEmbIdEntity.class, 1)
|
||||
.add(AuditRestrictions.eq("reference", new SetRefEdEmbIdEntity(id3, null)))
|
||||
.add(AuditEntity.property("reference").eq(new SetRefEdEmbIdEntity(id3, null)))
|
||||
.getResultList());
|
||||
|
||||
Set rev2_related = new HashSet(getAuditReader().createQuery()
|
||||
.forEntitiesAtRevision(SetRefIngEmbIdEntity.class, 2)
|
||||
.add(AuditRestrictions.relatedIdEq("reference", id3))
|
||||
.add(AuditEntity.relatedId("reference").eq(id3))
|
||||
.getResultList());
|
||||
|
||||
Set rev2 = new HashSet(getAuditReader().createQuery()
|
||||
.forEntitiesAtRevision(SetRefIngEmbIdEntity.class, 2)
|
||||
.add(AuditRestrictions.eq("reference", new SetRefEdEmbIdEntity(id3, null)))
|
||||
.add(AuditEntity.property("reference").eq(new SetRefEdEmbIdEntity(id3, null)))
|
||||
.getResultList());
|
||||
|
||||
Set rev3_related = new HashSet(getAuditReader().createQuery()
|
||||
.forEntitiesAtRevision(SetRefIngEmbIdEntity.class, 3)
|
||||
.add(AuditRestrictions.relatedIdEq("reference", id3))
|
||||
.add(AuditEntity.relatedId("reference").eq(id3))
|
||||
.getResultList());
|
||||
|
||||
Set rev3 = new HashSet(getAuditReader().createQuery()
|
||||
.forEntitiesAtRevision(SetRefIngEmbIdEntity.class, 3)
|
||||
.add(AuditRestrictions.eq("reference", new SetRefEdEmbIdEntity(id3, null)))
|
||||
.add(AuditEntity.property("reference").eq(new SetRefEdEmbIdEntity(id3, null)))
|
||||
.getResultList());
|
||||
|
||||
assert rev1.equals(rev1_related);
|
||||
|
@ -147,17 +147,17 @@ public class EmbIdOneToManyQuery extends AbstractEntityTest {
|
|||
public void testEntitiesReferencedToId4() {
|
||||
Set rev1_related = new HashSet(getAuditReader().createQuery()
|
||||
.forEntitiesAtRevision(SetRefIngEmbIdEntity.class, 1)
|
||||
.add(AuditRestrictions.relatedIdEq("reference", id4))
|
||||
.add(AuditEntity.relatedId("reference").eq(id4))
|
||||
.getResultList());
|
||||
|
||||
Set rev2_related = new HashSet(getAuditReader().createQuery()
|
||||
.forEntitiesAtRevision(SetRefIngEmbIdEntity.class, 2)
|
||||
.add(AuditRestrictions.relatedIdEq("reference", id4))
|
||||
.add(AuditEntity.relatedId("reference").eq(id4))
|
||||
.getResultList());
|
||||
|
||||
Set rev3_related = new HashSet(getAuditReader().createQuery()
|
||||
.forEntitiesAtRevision(SetRefIngEmbIdEntity.class, 3)
|
||||
.add(AuditRestrictions.relatedIdEq("reference", id4))
|
||||
.add(AuditEntity.relatedId("reference").eq(id4))
|
||||
.getResultList());
|
||||
|
||||
assert rev1_related.equals(TestTools.makeSet());
|
||||
|
@ -169,20 +169,20 @@ public class EmbIdOneToManyQuery extends AbstractEntityTest {
|
|||
public void testEntitiesReferencedByIng1ToId3() {
|
||||
List rev1_related = getAuditReader().createQuery()
|
||||
.forEntitiesAtRevision(SetRefIngEmbIdEntity.class, 1)
|
||||
.add(AuditRestrictions.relatedIdEq("reference", id3))
|
||||
.add(AuditRestrictions.idEq(id1))
|
||||
.add(AuditEntity.relatedId("reference").eq(id3))
|
||||
.add(AuditEntity.id().eq(id1))
|
||||
.getResultList();
|
||||
|
||||
Object rev2_related = getAuditReader().createQuery()
|
||||
.forEntitiesAtRevision(SetRefIngEmbIdEntity.class, 2)
|
||||
.add(AuditRestrictions.relatedIdEq("reference", id3))
|
||||
.add(AuditRestrictions.idEq(id1))
|
||||
.add(AuditEntity.relatedId("reference").eq(id3))
|
||||
.add(AuditEntity.id().eq(id1))
|
||||
.getSingleResult();
|
||||
|
||||
Object rev3_related = getAuditReader().createQuery()
|
||||
.forEntitiesAtRevision(SetRefIngEmbIdEntity.class, 3)
|
||||
.add(AuditRestrictions.relatedIdEq("reference", id3))
|
||||
.add(AuditRestrictions.idEq(id1))
|
||||
.add(AuditEntity.relatedId("reference").eq(id3))
|
||||
.add(AuditEntity.id().eq(id1))
|
||||
.getSingleResult();
|
||||
|
||||
assert rev1_related.size() == 0;
|
||||
|
@ -194,20 +194,20 @@ public class EmbIdOneToManyQuery extends AbstractEntityTest {
|
|||
public void testEntitiesReferencedByIng2ToId3() {
|
||||
List rev1_related = getAuditReader().createQuery()
|
||||
.forEntitiesAtRevision(SetRefIngEmbIdEntity.class, 1)
|
||||
.add(AuditRestrictions.relatedIdEq("reference", id3))
|
||||
.add(AuditRestrictions.idEq(id2))
|
||||
.add(AuditEntity.relatedId("reference").eq(id3))
|
||||
.add(AuditEntity.id().eq(id2))
|
||||
.getResultList();
|
||||
|
||||
List rev2_related = getAuditReader().createQuery()
|
||||
.forEntitiesAtRevision(SetRefIngEmbIdEntity.class, 2)
|
||||
.add(AuditRestrictions.relatedIdEq("reference", id3))
|
||||
.add(AuditRestrictions.idEq(id2))
|
||||
.add(AuditEntity.relatedId("reference").eq(id3))
|
||||
.add(AuditEntity.id().eq(id2))
|
||||
.getResultList();
|
||||
|
||||
Object rev3_related = getAuditReader().createQuery()
|
||||
.forEntitiesAtRevision(SetRefIngEmbIdEntity.class, 3)
|
||||
.add(AuditRestrictions.relatedIdEq("reference", id3))
|
||||
.add(AuditRestrictions.idEq(id2))
|
||||
.add(AuditEntity.relatedId("reference").eq(id3))
|
||||
.add(AuditEntity.id().eq(id2))
|
||||
.getSingleResult();
|
||||
|
||||
assert rev1_related.size() == 0;
|
||||
|
|
|
@ -28,7 +28,7 @@ import java.util.List;
|
|||
import java.util.Set;
|
||||
import javax.persistence.EntityManager;
|
||||
|
||||
import org.hibernate.envers.query.AuditRestrictions;
|
||||
import org.hibernate.envers.query.AuditEntity;
|
||||
import org.hibernate.envers.test.AbstractEntityTest;
|
||||
import org.hibernate.envers.test.entities.ids.MulId;
|
||||
import org.hibernate.envers.test.entities.onetomany.ids.SetRefEdMulIdEntity;
|
||||
|
@ -105,32 +105,32 @@ public class MulIdOneToManyQuery extends AbstractEntityTest {
|
|||
public void testEntitiesReferencedToId3() {
|
||||
Set rev1_related = new HashSet(getAuditReader().createQuery()
|
||||
.forEntitiesAtRevision(SetRefIngMulIdEntity.class, 1)
|
||||
.add(AuditRestrictions.relatedIdEq("reference", id3))
|
||||
.add(AuditEntity.relatedId("reference").eq(id3))
|
||||
.getResultList());
|
||||
|
||||
Set rev1 = new HashSet(getAuditReader().createQuery()
|
||||
.forEntitiesAtRevision(SetRefIngMulIdEntity.class, 1)
|
||||
.add(AuditRestrictions.eq("reference", new SetRefEdMulIdEntity(id3, null)))
|
||||
.add(AuditEntity.property("reference").eq(new SetRefEdMulIdEntity(id3, null)))
|
||||
.getResultList());
|
||||
|
||||
Set rev2_related = new HashSet(getAuditReader().createQuery()
|
||||
.forEntitiesAtRevision(SetRefIngMulIdEntity.class, 2)
|
||||
.add(AuditRestrictions.relatedIdEq("reference", id3))
|
||||
.add(AuditEntity.relatedId("reference").eq(id3))
|
||||
.getResultList());
|
||||
|
||||
Set rev2 = new HashSet(getAuditReader().createQuery()
|
||||
.forEntitiesAtRevision(SetRefIngMulIdEntity.class, 2)
|
||||
.add(AuditRestrictions.eq("reference", new SetRefEdMulIdEntity(id3, null)))
|
||||
.add(AuditEntity.property("reference").eq(new SetRefEdMulIdEntity(id3, null)))
|
||||
.getResultList());
|
||||
|
||||
Set rev3_related = new HashSet(getAuditReader().createQuery()
|
||||
.forEntitiesAtRevision(SetRefIngMulIdEntity.class, 3)
|
||||
.add(AuditRestrictions.relatedIdEq("reference", id3))
|
||||
.add(AuditEntity.relatedId("reference").eq(id3))
|
||||
.getResultList());
|
||||
|
||||
Set rev3 = new HashSet(getAuditReader().createQuery()
|
||||
.forEntitiesAtRevision(SetRefIngMulIdEntity.class, 3)
|
||||
.add(AuditRestrictions.eq("reference", new SetRefEdMulIdEntity(id3, null)))
|
||||
.add(AuditEntity.property("reference").eq(new SetRefEdMulIdEntity(id3, null)))
|
||||
.getResultList());
|
||||
|
||||
assert rev1.equals(rev1_related);
|
||||
|
@ -147,17 +147,17 @@ public class MulIdOneToManyQuery extends AbstractEntityTest {
|
|||
public void testEntitiesReferencedToId4() {
|
||||
Set rev1_related = new HashSet(getAuditReader().createQuery()
|
||||
.forEntitiesAtRevision(SetRefIngMulIdEntity.class, 1)
|
||||
.add(AuditRestrictions.relatedIdEq("reference", id4))
|
||||
.add(AuditEntity.relatedId("reference").eq(id4))
|
||||
.getResultList());
|
||||
|
||||
Set rev2_related = new HashSet(getAuditReader().createQuery()
|
||||
.forEntitiesAtRevision(SetRefIngMulIdEntity.class, 2)
|
||||
.add(AuditRestrictions.relatedIdEq("reference", id4))
|
||||
.add(AuditEntity.relatedId("reference").eq(id4))
|
||||
.getResultList());
|
||||
|
||||
Set rev3_related = new HashSet(getAuditReader().createQuery()
|
||||
.forEntitiesAtRevision(SetRefIngMulIdEntity.class, 3)
|
||||
.add(AuditRestrictions.relatedIdEq("reference", id4))
|
||||
.add(AuditEntity.relatedId("reference").eq(id4))
|
||||
.getResultList());
|
||||
|
||||
assert rev1_related.equals(TestTools.makeSet());
|
||||
|
@ -169,20 +169,20 @@ public class MulIdOneToManyQuery extends AbstractEntityTest {
|
|||
public void testEntitiesReferencedByIng1ToId3() {
|
||||
List rev1_related = getAuditReader().createQuery()
|
||||
.forEntitiesAtRevision(SetRefIngMulIdEntity.class, 1)
|
||||
.add(AuditRestrictions.relatedIdEq("reference", id3))
|
||||
.add(AuditRestrictions.idEq(id1))
|
||||
.add(AuditEntity.relatedId("reference").eq(id3))
|
||||
.add(AuditEntity.id().eq(id1))
|
||||
.getResultList();
|
||||
|
||||
Object rev2_related = getAuditReader().createQuery()
|
||||
.forEntitiesAtRevision(SetRefIngMulIdEntity.class, 2)
|
||||
.add(AuditRestrictions.relatedIdEq("reference", id3))
|
||||
.add(AuditRestrictions.idEq(id1))
|
||||
.add(AuditEntity.relatedId("reference").eq(id3))
|
||||
.add(AuditEntity.id().eq(id1))
|
||||
.getSingleResult();
|
||||
|
||||
Object rev3_related = getAuditReader().createQuery()
|
||||
.forEntitiesAtRevision(SetRefIngMulIdEntity.class, 3)
|
||||
.add(AuditRestrictions.relatedIdEq("reference", id3))
|
||||
.add(AuditRestrictions.idEq(id1))
|
||||
.add(AuditEntity.relatedId("reference").eq(id3))
|
||||
.add(AuditEntity.id().eq(id1))
|
||||
.getSingleResult();
|
||||
|
||||
assert rev1_related.size() == 0;
|
||||
|
@ -194,20 +194,20 @@ public class MulIdOneToManyQuery extends AbstractEntityTest {
|
|||
public void testEntitiesReferencedByIng2ToId3() {
|
||||
List rev1_related = getAuditReader().createQuery()
|
||||
.forEntitiesAtRevision(SetRefIngMulIdEntity.class, 1)
|
||||
.add(AuditRestrictions.relatedIdEq("reference", id3))
|
||||
.add(AuditRestrictions.idEq(id2))
|
||||
.add(AuditEntity.relatedId("reference").eq(id3))
|
||||
.add(AuditEntity.id().eq(id2))
|
||||
.getResultList();
|
||||
|
||||
List rev2_related = getAuditReader().createQuery()
|
||||
.forEntitiesAtRevision(SetRefIngMulIdEntity.class, 2)
|
||||
.add(AuditRestrictions.relatedIdEq("reference", id3))
|
||||
.add(AuditRestrictions.idEq(id2))
|
||||
.add(AuditEntity.relatedId("reference").eq(id3))
|
||||
.add(AuditEntity.id().eq(id2))
|
||||
.getResultList();
|
||||
|
||||
Object rev3_related = getAuditReader().createQuery()
|
||||
.forEntitiesAtRevision(SetRefIngMulIdEntity.class, 3)
|
||||
.add(AuditRestrictions.relatedIdEq("reference", id3))
|
||||
.add(AuditRestrictions.idEq(id2))
|
||||
.add(AuditEntity.relatedId("reference").eq(id3))
|
||||
.add(AuditEntity.id().eq(id2))
|
||||
.getSingleResult();
|
||||
|
||||
assert rev1_related.size() == 0;
|
||||
|
|
Loading…
Reference in New Issue