/** * 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 property( null, propertyName ); }
/** * Create restrictions, projections and specify order for the revision type, corresponding to an * audited entity. */ public static AuditProperty<RevisionType> revisionType() { return revisionType( null ); }
/** * 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 revisionProperty( null, propertyName ); }
@Test public void testEntityRevisionsWithChangesQueryNoDeletions() { List results = getAuditReader().createQuery() .forRevisionsOfEntityWithChanges( Simple.class, false ) .add( AuditEntity.id().eq( simpleId ) ) .getResultList(); compareResults( getExpectedResults( false ), results ); }
private List getEntitiesModifiedAtRevisionUsingAssociationQueryResults(Number revision) { // Without fix HHH-11981, throw org.hibernate.QueryException - Parameter not bound : revision return getAuditReader().createQuery() .forEntitiesModifiedAtRevision( Template.class, revision ) .traverseRelation( "templateType", JoinType.INNER ) .addProjection( AuditEntity.selectEntity( false ) ) .up() .add( AuditEntity.property( "templateType" ).hasChanged() ) .getResultList(); } }
@Test public void testComparisonOfTwoPropertiesFromDifferentEntities() { AuditReader auditReader = getAuditReader(); // the car where the owner age is equal to the owner address number. Car result = (Car) auditReader.createQuery() .forEntitiesAtRevision( Car.class, 1 ) .traverseRelation( "owner", JoinType.INNER, "p" ) .traverseRelation( "address", JoinType.INNER, "a" ) .up().up().add(AuditEntity.property( "p", "age" ) .eqProperty( "a", "number" ) ).getSingleResult(); assertEquals( "Unexpected car returned", toyota.getId(), result.getId() ); }
@Override protected Object queryForReferencedEntity( AuditReaderImplementor versionsReader, EntityInfo referencedEntity, Serializable primaryKey, Number revision) { return versionsReader.createQuery().forEntitiesAtRevision( referencedEntity.getEntityClass(), referencedEntity.getEntityName(), revision ) .add( AuditEntity.relatedId( owningReferencePropertyName ).eq( primaryKey ) ) .getSingleResult(); } }
private AuditQuery createForRevisionsQuery(Class<?> clazz, Object id, boolean withDeleted) { return getAuditReader().createQuery() .forRevisionsOfEntity( clazz, false, withDeleted ) .add( AuditEntity.id().eq( id ) ); }
@Test public void testEmptyDisjunctionRevisionOfEntityQuery() { List result = getAuditReader().createQuery() .forRevisionsOfEntity( StrIntTestEntity.class, false, true ) .add( AuditEntity.disjunction() ) .getResultList(); assert result.size() == 0; }
@Test public void testEmptyConjunctionRevisionOfEntityQuery() { List result = getAuditReader().createQuery() .forRevisionsOfEntity( StrIntTestEntity.class, false, true ) .add( AuditEntity.conjunction() ) .getResultList(); assert result.size() == 7; }
private void addHasChangedProperties( AuditQuery query, String[] propertyNames) { for ( String propertyName : propertyNames ) { query.add( AuditEntity.property( propertyName ).hasChanged() ); } }
private void addHasNotChangedProperties( AuditQuery query, String[] propertyNames) { for ( String propertyName : propertyNames ) { query.add( AuditEntity.property( propertyName ).hasNotChanged() ); } }
protected List queryForPropertyHasChangedWithDeleted( Class<?> clazz, Object id, String... propertyNames) { AuditQuery query = createForRevisionsQuery( clazz, id, true ); addHasChangedProperties( query, propertyNames ); return query.getResultList(); }
/** * Create restrictions, projections and specify order for the revision number, corresponding to an * audited entity. */ public static AuditProperty<Number> revisionNumber() { return revisionNumber( null ); }
public static AuditId id() { return id( null ); }
/** * Creates a query, which will return entities satisfying some conditions (specified later), * at a given revision and a given entityName. Deleted entities are not included. * * @param c Class of the entities for which to query. * @param entityName Name of the entity (if can't be guessed basing on the {@code c}). * @param revision Revision number at which to execute the query. * * @return A query for entities at a given revision, to which conditions can be added and which * can then be executed. The result of the query will be a list of entities (beans), unless a * projection is added. */ public AuditQuery forEntitiesAtRevision(Class<?> c, String entityName, Number revision) { return forEntitiesAtRevision( c, entityName, revision, false ); }
/** * 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 relatedId( null, propertyName ); }
@Override public AuditQueryCreator createQuery() { return new AuditQueryCreator( enversService, this ); }
@Test public void testEntityRevisionsWithChangesQuery() { List results = getAuditReader().createQuery() .forRevisionsOfEntityWithChanges( Simple.class, true ) .add( AuditEntity.id().eq( simpleId ) ) .getResultList(); compareResults( getExpectedResults( true ), results ); }
protected List queryForPropertyHasNotChanged( Class<?> clazz, Object id, String... propertyNames) { AuditQuery query = createForRevisionsQuery( clazz, id, false ); addHasNotChangedProperties( query, propertyNames ); return query.getResultList(); }