Hibernate SVN: r15598 - validator/tags.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2008-11-19 12:33:48 -0500 (Wed, 19 Nov 2008)
New Revision: 15598
Added:
validator/tags/BeanValidationBeforeUngenerifiedValidator/
Log:
implementation of the ungenerified validator
Copied: validator/tags/BeanValidationBeforeUngenerifiedValidator (from rev 15597, validator/trunk)
16 years
Hibernate SVN: r15597 - validator/tags.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2008-11-19 12:33:20 -0500 (Wed, 19 Nov 2008)
New Revision: 15597
Added:
validator/tags/BeanValidatonBeforeUngenerifiedValidator/
Log:
implementation of the ungenerified validator
Copied: validator/tags/BeanValidatonBeforeUngenerifiedValidator (from rev 15596, validator/trunk)
16 years
Hibernate SVN: r15596 - search/trunk/src/java/org/hibernate/search/impl.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2008-11-19 12:16:14 -0500 (Wed, 19 Nov 2008)
New Revision: 15596
Modified:
search/trunk/src/java/org/hibernate/search/impl/SearchFactoryImpl.java
Log:
HSEARCH-160
added barrier to getIndexedTypesPolymorphic
Modified: search/trunk/src/java/org/hibernate/search/impl/SearchFactoryImpl.java
===================================================================
--- search/trunk/src/java/org/hibernate/search/impl/SearchFactoryImpl.java 2008-11-19 16:50:17 UTC (rev 15595)
+++ search/trunk/src/java/org/hibernate/search/impl/SearchFactoryImpl.java 2008-11-19 17:16:14 UTC (rev 15596)
@@ -497,6 +497,8 @@
}
public Set<Class<?>> getIndexedTypesPolymorphic(Class<?>[] classes) {
+ if ( barrier != 0 ) {
+ } //read barrier
return indexHierarchy.getIndexedClasses( classes );
}
16 years
Hibernate SVN: r15595 - branches/Branch_3_2/HibernateExt/tools.
by hibernate-commits@lists.jboss.org
Author: anthonyHib
Date: 2008-11-19 11:50:17 -0500 (Wed, 19 Nov 2008)
New Revision: 15595
Modified:
branches/Branch_3_2/HibernateExt/tools/build.xml
Log:
fix classpath issue
Modified: branches/Branch_3_2/HibernateExt/tools/build.xml
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/build.xml 2008-11-19 15:12:58 UTC (rev 15594)
+++ branches/Branch_3_2/HibernateExt/tools/build.xml 2008-11-19 16:50:17 UTC (rev 15595)
@@ -24,7 +24,9 @@
<path id="junit.moduleclasspath">
<pathelement location="etc"/>
- <pathelement location="lib/testlibs/org.eclipse.jdt.core_3.1.0.jar"/>
+ <pathelement location="lib/testlibs/org.eclipse.jdt.core_3.1.0.jar"/>
+ <!-- remove hibernate-annotations.jar when migrating to maven -->
+ <pathelement location="lib/testlibs/hibernate-annotations.jar"/>
<pathelement location="${jdbc.driver.jar}"/>
<path refid="testsrc.path"/>
<pathelement location="${java.home}\..\lib\tools.jar"/>
16 years
Hibernate SVN: r15594 - in search/trunk/src/test/org/hibernate/search/test: inheritance and 1 other directories.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2008-11-19 10:12:58 -0500 (Wed, 19 Nov 2008)
New Revision: 15594
Modified:
search/trunk/src/test/org/hibernate/search/test/SearchTestCase.java
search/trunk/src/test/org/hibernate/search/test/inheritance/InheritanceTest.java
search/trunk/src/test/org/hibernate/search/test/query/ProjectionQueryTest.java
Log:
Little change in test setup which allows that all test can be run with file system based Lucene directory. setUp() will now ensure that the indexes are empty for every test.
Modified: search/trunk/src/test/org/hibernate/search/test/SearchTestCase.java
===================================================================
--- search/trunk/src/test/org/hibernate/search/test/SearchTestCase.java 2008-11-19 14:35:40 UTC (rev 15593)
+++ search/trunk/src/test/org/hibernate/search/test/SearchTestCase.java 2008-11-19 15:12:58 UTC (rev 15594)
@@ -5,6 +5,7 @@
import org.apache.lucene.analysis.StopAnalyzer;
import org.apache.lucene.store.Directory;
+
import org.hibernate.HibernateException;
import org.hibernate.Transaction;
import org.hibernate.event.PostInsertEventListener;
@@ -24,27 +25,28 @@
/**
* Base class for Hibernate Search unit tests.
- *
+ *
* @author Emmanuel Bernard
*/
public abstract class SearchTestCase extends HANTestCase {
-
- private static final Logger log = LoggerFactory
- .getLogger(SearchTestCase.class);
-
+
+ private static final Logger log = org.hibernate.search.util.LoggerFactory.make();
+
private static File indexDir;
+
static {
- String buildDir = System.getProperty("build.dir");
- if (buildDir == null) {
+ String buildDir = System.getProperty( "build.dir" );
+ if ( buildDir == null ) {
buildDir = ".";
}
File current = new File( buildDir );
indexDir = new File( current, "indextemp" );
- log.debug("Using {} as index directory.", indexDir.getAbsolutePath());
+ log.debug( "Using {} as index directory.", indexDir.getAbsolutePath() );
}
-
+
protected void setUp() throws Exception {
buildSessionFactory( getMappings(), getAnnotatedPackages(), getXmlFiles() );
+ ensureIndexesAreEmpty();
}
@SuppressWarnings("unchecked")
@@ -53,20 +55,27 @@
}
private FullTextIndexEventListener getLuceneEventListener() {
- PostInsertEventListener[] listeners = ( (SessionFactoryImpl) getSessions() ).getEventListeners().getPostInsertEventListeners();
- FullTextIndexEventListener listener = null;
- //FIXME this sucks since we mandante the event listener use
- for (PostInsertEventListener candidate : listeners) {
- if (candidate instanceof FullTextIndexEventListener ) {
- listener = (FullTextIndexEventListener) candidate;
- break;
- }
- }
- if (listener == null) throw new HibernateException("Lucene event listener not initialized");
- return listener;
- }
+ PostInsertEventListener[] listeners = ( ( SessionFactoryImpl ) getSessions() ).getEventListeners()
+ .getPostInsertEventListeners();
+ FullTextIndexEventListener listener = null;
+ //FIXME this sucks since we mandante the event listener use
+ for ( PostInsertEventListener candidate : listeners ) {
+ if ( candidate instanceof FullTextIndexEventListener ) {
+ listener = ( FullTextIndexEventListener ) candidate;
+ break;
+ }
+ }
+ if ( listener == null ) {
+ throw new HibernateException( "Lucene event listener not initialized" );
+ }
+ return listener;
+ }
protected void ensureIndexesAreEmpty() {
+ if ( "jms".equals( getCfg().getProperty( "hibernate.search.worker.backend" ) ) ) {
+ log.debug( "JMS based test. Skipping index emptying" );
+ return;
+ }
FullTextSession s = Search.getFullTextSession( openSession() );
Transaction tx;
tx = s.beginTransaction();
@@ -76,15 +85,17 @@
}
}
tx.commit();
+ s.close();
}
protected void configure(org.hibernate.cfg.Configuration cfg) {
cfg.setProperty( "hibernate.search.default.directory_provider", RAMDirectoryProvider.class.getName() );
+ cfg.setProperty( "hibernate.search.default.indexBase", indexDir.getAbsolutePath() );
cfg.setProperty( Environment.ANALYZER_CLASS, StopAnalyzer.class.getName() );
cfg.setProperty( "hibernate.search.default.transaction.merge_factor", "100" );
cfg.setProperty( "hibernate.search.default.batch.max_buffered_docs", "1000" );
}
-
+
protected File getBaseIndexDir() {
return indexDir;
}
Modified: search/trunk/src/test/org/hibernate/search/test/inheritance/InheritanceTest.java
===================================================================
--- search/trunk/src/test/org/hibernate/search/test/inheritance/InheritanceTest.java 2008-11-19 14:35:40 UTC (rev 15593)
+++ search/trunk/src/test/org/hibernate/search/test/inheritance/InheritanceTest.java 2008-11-19 15:12:58 UTC (rev 15594)
@@ -22,7 +22,6 @@
protected void setUp() throws Exception {
super.setUp();
- ensureIndexesAreEmpty();
}
public void testInheritance() throws Exception {
Modified: search/trunk/src/test/org/hibernate/search/test/query/ProjectionQueryTest.java
===================================================================
--- search/trunk/src/test/org/hibernate/search/test/query/ProjectionQueryTest.java 2008-11-19 14:35:40 UTC (rev 15593)
+++ search/trunk/src/test/org/hibernate/search/test/query/ProjectionQueryTest.java 2008-11-19 15:12:58 UTC (rev 15594)
@@ -166,7 +166,7 @@
assertEquals( "lastname incorrect", "Griffin", projection[1] );
assertEquals( "dept incorrect", "ITech", projection[2] );
assertEquals( "THIS incorrect", projection[3], s.get( Employee.class, ( Serializable ) projection[0] ) );
- assertEquals( "SCORE incorrect", 1.0F, projection[4] );
+ assertTrue( "SCORE incorrect", projection[4] instanceof Float );
assertTrue( "DOCUMENT incorrect", projection[5] instanceof Document );
assertEquals( "DOCUMENT size incorrect", 4, ( ( Document ) projection[5] ).getFields().size() );
assertEquals( "legacy ID incorrect", 1000, projection[6] );
@@ -177,7 +177,7 @@
assertEquals( "lastname incorrect", "Whetbrook", projection[1] );
assertEquals( "dept incorrect", "ITech", projection[2] );
assertEquals( "THIS incorrect", projection[3], s.get( Employee.class, ( Serializable ) projection[0] ) );
- assertEquals( "SCORE incorrect", 1.0F, projection[4] );
+ assertTrue( "SCORE incorrect", projection[4] instanceof Float );
assertTrue( "DOCUMENT incorrect", projection[5] instanceof Document );
assertEquals( "DOCUMENT size incorrect", 4, ( ( Document ) projection[5] ).getFields().size() );
assertEquals( "legacy ID incorrect", 1004, projection[6] );
@@ -188,7 +188,7 @@
assertEquals( "lastname incorrect", "Stejskal", projection[1] );
assertEquals( "dept incorrect", "ITech", projection[2] );
assertEquals( "THIS incorrect", projection[3], s.get( Employee.class, ( Serializable ) projection[0] ) );
- assertEquals( "SCORE incorrect", 1.0F, projection[4] );
+ assertTrue( "SCORE incorrect", projection[4] instanceof Float );
assertTrue( "DOCUMENT incorrect", projection[5] instanceof Document );
assertEquals( "DOCUMENT size incorrect", 4, ( ( Document ) projection[5] ).getFields().size() );
assertEquals( "legacy ID incorrect", 1003, projection[6] );
@@ -218,7 +218,7 @@
counter++;
assertEquals( "dept incorrect", "ITech", projection[2] );
assertEquals( "THIS incorrect", projection[3], s.get( Employee.class, ( Serializable ) projection[0] ) );
- assertEquals( "SCORE incorrect", 1.0F, projection[4] );
+ assertTrue( "SCORE incorrect", projection[4] instanceof Float );
assertTrue( "DOCUMENT incorrect", projection[5] instanceof Document );
assertEquals( "DOCUMENT size incorrect", 4, ( ( Document ) projection[5] ).getFields().size() );
}
@@ -258,7 +258,7 @@
assertEquals( "dept incorrect", "Accounting", projection[2] );
assertEquals( "THIS incorrect", "Jackson", ( ( Employee ) projection[3] ).getLastname() );
assertEquals( "THIS incorrect", projection[3], s.get( Employee.class, ( Serializable ) projection[0] ) );
- assertEquals( "SCORE incorrect", 1.9162908F, projection[4] );
+ assertTrue( "SCORE incorrect", projection[4] instanceof Float );
assertTrue( "DOCUMENT incorrect", projection[5] instanceof Document );
assertEquals( "DOCUMENT size incorrect", 5, ( ( Document ) projection[5] ).getFields().size() );
assertEquals( "ID incorrect", 1001, projection[6] );
@@ -279,7 +279,7 @@
assertTrue( "DOCUMENT incorrect", projection[0] instanceof Document );
assertEquals( "DOCUMENT size incorrect", 5, ( ( Document ) projection[0] ).getFields().size() );
assertEquals( "THIS incorrect", projection[1], s.get( Employee.class, ( Serializable ) projection[4] ) );
- assertEquals( "SCORE incorrect", 1.9162908F, projection[2] );
+ assertTrue( "SCORE incorrect", projection[2] instanceof Float );
assertNull( "BOOST not removed", projection[3] );
assertEquals( "ID incorrect", 1001, projection[4] );
assertEquals( "id incorrect", 1001, projection[5] );
@@ -331,7 +331,7 @@
assertNotNull( projection );
assertTrue( "THIS incorrect", projection[0] instanceof Employee );
- assertEquals( "SCORE incorrect", 1.9162908F, projection[1] );
+ assertTrue( "SCORE incorrect", projection[1] instanceof Float );
assertEquals( "last name incorrect", "Jackson", projection[3] );
//cleanup
16 years
Hibernate SVN: r15593 - in core/trunk/envers/src: demo/resources/META-INF and 2 other directories.
by hibernate-commits@lists.jboss.org
Author: adamw
Date: 2008-11-19 09:35:40 -0500 (Wed, 19 Nov 2008)
New Revision: 15593
Removed:
core/trunk/envers/src/main/java/org/hibernate/envers/query/AuditRestrictions.java
core/trunk/envers/src/main/java/org/hibernate/envers/tools/HibernateVersion.java
Modified:
core/trunk/envers/src/demo/java/org/hibernate/envers/demo/Address.java
core/trunk/envers/src/demo/java/org/hibernate/envers/demo/Person.java
core/trunk/envers/src/demo/java/org/hibernate/envers/demo/TestConsole.java
core/trunk/envers/src/demo/resources/META-INF/persistence.xml
Log:
Removing unused HibernateVersion class, updating demo
Modified: core/trunk/envers/src/demo/java/org/hibernate/envers/demo/Address.java
===================================================================
--- core/trunk/envers/src/demo/java/org/hibernate/envers/demo/Address.java 2008-11-19 14:17:48 UTC (rev 15592)
+++ core/trunk/envers/src/demo/java/org/hibernate/envers/demo/Address.java 2008-11-19 14:35:40 UTC (rev 15593)
@@ -19,9 +19,9 @@
*
* Red Hat Author(s): Adam Warski
*/
-package org.jboss.envers.demo;
+package org.hibernate.envers.demo;
-import org.jboss.envers.Versioned;
+import org.hibernate.envers.Audited;
import javax.persistence.*;
import java.util.Set;
@@ -35,16 +35,16 @@
@GeneratedValue
private int id;
- @Versioned
+ @Audited
private String streetName;
- @Versioned
+ @Audited
private Integer houseNumber;
- @Versioned
+ @Audited
private Integer flatNumber;
- @Versioned
+ @Audited
@OneToMany(mappedBy = "address")
private Set<Person> persons;
Modified: core/trunk/envers/src/demo/java/org/hibernate/envers/demo/Person.java
===================================================================
--- core/trunk/envers/src/demo/java/org/hibernate/envers/demo/Person.java 2008-11-19 14:17:48 UTC (rev 15592)
+++ core/trunk/envers/src/demo/java/org/hibernate/envers/demo/Person.java 2008-11-19 14:35:40 UTC (rev 15593)
@@ -19,9 +19,9 @@
*
* Red Hat Author(s): Adam Warski
*/
-package org.jboss.envers.demo;
+package org.hibernate.envers.demo;
-import org.jboss.envers.Versioned;
+import org.hibernate.envers.Audited;
import javax.persistence.*;
@@ -34,13 +34,13 @@
@GeneratedValue
private int id;
- @Versioned
+ @Audited
private String name;
- @Versioned
+ @Audited
private String surname;
- @Versioned
+ @Audited
@ManyToOne
private Address address;
Modified: core/trunk/envers/src/demo/java/org/hibernate/envers/demo/TestConsole.java
===================================================================
--- core/trunk/envers/src/demo/java/org/hibernate/envers/demo/TestConsole.java 2008-11-19 14:17:48 UTC (rev 15592)
+++ core/trunk/envers/src/demo/java/org/hibernate/envers/demo/TestConsole.java 2008-11-19 14:35:40 UTC (rev 15593)
@@ -19,12 +19,12 @@
*
* Red Hat Author(s): Adam Warski
*/
-package org.jboss.envers.demo;
+package org.hibernate.envers.demo;
-import org.jboss.envers.VersionsReader;
-import org.jboss.envers.VersionsReaderFactory;
-import org.jboss.envers.DefaultRevisionEntity;
-import org.jboss.envers.query.VersionsRestrictions;
+import org.hibernate.envers.query.AuditEntity;
+import org.hibernate.envers.DefaultRevisionEntity;
+import org.hibernate.envers.AuditReader;
+import org.hibernate.envers.AuditReaderFactory;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
@@ -83,11 +83,11 @@
}
private void printPersonHistory(StringBuilder sb, int personId) {
- VersionsReader reader = VersionsReaderFactory.get(entityManager);
+ AuditReader reader = AuditReaderFactory.get(entityManager);
List personHistory = reader.createQuery()
.forRevisionsOfEntity(Person.class, false, true)
- .add(VersionsRestrictions.idEq(personId))
+ .add(AuditEntity.id().eq(personId))
.getResultList();
if (personHistory.size() == 0) {
@@ -104,7 +104,7 @@
}
private void printPersonAtRevision(StringBuilder sb, int personId, int revision) {
- VersionsReader reader = VersionsReaderFactory.get(entityManager);
+ AuditReader reader = AuditReaderFactory.get(entityManager);
Person p = reader.find(Person.class, personId, revision);
if (p == null) {
@@ -220,11 +220,11 @@
}
private void printAddressHistory(StringBuilder sb, int addressId) {
- VersionsReader reader = VersionsReaderFactory.get(entityManager);
+ AuditReader reader = AuditReaderFactory.get(entityManager);
List addressHistory = reader.createQuery()
.forRevisionsOfEntity(Address.class, false, true)
- .add(VersionsRestrictions.idEq(addressId))
+ .add(AuditEntity.id().eq(addressId))
.getResultList();
if (addressHistory.size() == 0) {
@@ -241,7 +241,7 @@
}
private void printAddressAtRevision(StringBuilder sb, int addressId, int revision) {
- VersionsReader reader = VersionsReaderFactory.get(entityManager);
+ AuditReader reader = AuditReaderFactory.get(entityManager);
Address a = reader.find(Address.class, addressId, revision);
if (a == null) {
Modified: core/trunk/envers/src/demo/resources/META-INF/persistence.xml
===================================================================
--- core/trunk/envers/src/demo/resources/META-INF/persistence.xml 2008-11-19 14:17:48 UTC (rev 15592)
+++ core/trunk/envers/src/demo/resources/META-INF/persistence.xml 2008-11-19 14:35:40 UTC (rev 15593)
@@ -22,9 +22,19 @@
<!--<property name="hibernate.show_sql" value="true"/>
<property name="hibernate.format_sql" value="true"/>-->
- <property name="hibernate.ejb.event.post-insert" value="org.hibernate.envers.event.AuditEventListener" />
- <property name="hibernate.ejb.event.post-update" value="org.hibernate.envers.event.AuditEventListener" />
- <property name="hibernate.ejb.event.post-delete" value="org.hibernate.envers.event.AuditEventListener" />
+ <property name="hibernate.ejb.event.post-insert"
+ value="org.hibernate.envers.event.AuditEventListener" />
+ <property name="hibernate.ejb.event.post-update"
+ value="org.hibernate.envers.event.AuditEventListener" />
+ <property name="hibernate.ejb.event.post-delete"
+ value="org.hibernate.envers.event.AuditEventListener" />
+ <property name="hibernate.ejb.event.pre-collection-update"
+ value="org.hibernate.envers.event.AuditEventListener" />
+ <property name="hibernate.ejb.event.pre-collection-remove"
+ value="org.hibernate.envers.event.AuditEventListener" />
+ <property name="hibernate.ejb.event.post-collection-recreate"
+ value="org.hibernate.envers.event.AuditEventListener" />
+
</properties>
</persistence-unit>
</persistence>
\ No newline at end of file
Deleted: core/trunk/envers/src/main/java/org/hibernate/envers/query/AuditRestrictions.java
===================================================================
--- core/trunk/envers/src/main/java/org/hibernate/envers/query/AuditRestrictions.java 2008-11-19 14:17:48 UTC (rev 15592)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/query/AuditRestrictions.java 2008-11-19 14:35:40 UTC (rev 15593)
@@ -1,246 +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 java.util.Collection;
-
-import org.hibernate.envers.query.criteria.AuditCriterion;
-import org.hibernate.envers.query.criteria.*;
-
-import org.hibernate.criterion.MatchMode;
-
-/**
- * TODO: ilike
- * @author Adam Warski (adam at warski dot org)
- * @see org.hibernate.criterion.Restrictions
- */
-@SuppressWarnings({"JavaDoc"})
-public class AuditRestrictions {
- private AuditRestrictions() { }
-
- /**
- * Apply an "equal" constraint to the identifier property.
- */
- public static AuditCriterion idEq(Object value) {
- return new IdentifierEqAuditExpression(value);
- }
-
- /**
- * Apply an "equal" constraint to the named property
- */
- public static AuditCriterion eq(String propertyName, Object value) {
- return new SimpleAuditExpression(propertyName, value, "=");
- }
-
- /**
- * Apply a "not equal" constraint to the named property
- */
- public static AuditCriterion ne(String propertyName, Object value) {
- return new SimpleAuditExpression(propertyName, value, "<>");
- }
-
- /**
- * Apply an "equal" constraint on an id of a related entity
- */
- public static AuditCriterion relatedIdEq(String propertyName, Object id) {
- return new RelatedAuditExpression(propertyName, id, true);
- }
-
- /**
- * Apply a "not equal" constraint to the named property
- */
- public static AuditCriterion relatedIdNe(String propertyName, Object id) {
- return new RelatedAuditExpression(propertyName, id, false);
- }
-
- /**
- * Apply a "like" constraint to the named property
- */
- public static AuditCriterion like(String propertyName, Object value) {
- return new SimpleAuditExpression(propertyName, value, " like ");
- }
-
- /**
- * Apply a "like" constraint to the named property
- */
- public static AuditCriterion like(String propertyName, String value, MatchMode matchMode) {
- return new SimpleAuditExpression(propertyName, matchMode.toMatchString(value), " like " );
- }
-
- /**
- * Apply a "greater than" constraint to the named property
- */
- public static AuditCriterion gt(String propertyName, Object value) {
- return new SimpleAuditExpression(propertyName, value, ">");
- }
-
- /**
- * Apply a "less than" constraint to the named property
- */
- public static AuditCriterion lt(String propertyName, Object value) {
- return new SimpleAuditExpression(propertyName, value, "<");
- }
-
- /**
- * Apply a "less than or equal" constraint to the named property
- */
- public static AuditCriterion le(String propertyName, Object value) {
- return new SimpleAuditExpression(propertyName, value, "<=");
- }
-
- /**
- * Apply a "greater than or equal" constraint to the named property
- */
- public static AuditCriterion ge(String propertyName, Object value) {
- return new SimpleAuditExpression(propertyName, value, ">=");
- }
-
- /**
- * Apply a "between" constraint to the named property
- */
- public static AuditCriterion between(String propertyName, Object lo, Object hi) {
- return new BetweenAuditExpression(propertyName, lo, hi);
- }
-
- /**
- * Apply an "in" constraint to the named property
- */
- public static AuditCriterion in(String propertyName, Object[] values) {
- return new InAuditExpression(propertyName, values);
- }
-
- /**
- * Apply an "in" constraint to the named property
- */
- public static AuditCriterion in(String propertyName, Collection values) {
- return new InAuditExpression(propertyName, values.toArray());
- }
-
- /**
- * Apply an "is null" constraint to the named property
- */
- public static AuditCriterion isNull(String propertyName) {
- return new NullAuditExpression(propertyName);
- }
-
- /**
- * Apply an "equal" constraint to two properties
- */
- public static AuditCriterion eqProperty(String propertyName, String otherPropertyName) {
- return new PropertyAuditExpression(propertyName, otherPropertyName, "=");
- }
-
- /**
- * Apply a "not equal" constraint to two properties
- */
- public static AuditCriterion neProperty(String propertyName, String otherPropertyName) {
- return new PropertyAuditExpression(propertyName, otherPropertyName, "<>");
- }
-
- /**
- * Apply a "less than" constraint to two properties
- */
- public static AuditCriterion ltProperty(String propertyName, String otherPropertyName) {
- return new PropertyAuditExpression(propertyName, otherPropertyName, "<");
- }
-
- /**
- * Apply a "less than or equal" constraint to two properties
- */
- public static AuditCriterion leProperty(String propertyName, String otherPropertyName) {
- return new PropertyAuditExpression(propertyName, otherPropertyName, "<=");
- }
-
- /**
- * Apply a "greater than" constraint to two properties
- */
- public static AuditCriterion gtProperty(String propertyName, String otherPropertyName) {
- return new PropertyAuditExpression(propertyName, otherPropertyName, ">");
- }
-
- /**
- * Apply a "greater than or equal" constraint to two properties
- */
- public static AuditCriterion geProperty(String propertyName, String otherPropertyName) {
- return new PropertyAuditExpression(propertyName, otherPropertyName, ">=");
- }
-
- /**
- * Apply an "is not null" constraint to the named property
- */
- public static AuditCriterion isNotNull(String propertyName) {
- return new NotNullAuditExpression(propertyName);
- }
-
- /**
- * Return the conjuction of two expressions
- */
- public static AuditCriterion and(AuditCriterion lhs, AuditCriterion rhs) {
- return new LogicalAuditExpression(lhs, rhs, "and");
- }
-
- /**
- * Return the disjuction of two expressions
- */
- public static AuditCriterion or(AuditCriterion lhs, AuditCriterion rhs) {
- return new LogicalAuditExpression(lhs, rhs, "or");
- }
-
- /**
- * Return the negation of an expression
- */
- public static AuditCriterion not(AuditCriterion expression) {
- return new NotAuditExpression(expression);
- }
-
- /**
- * Group expressions together in a single conjunction (A and B and C...)
- */
- public static AuditConjunction conjunction() {
- return new AuditConjunction();
- }
-
- /**
- * Group expressions together in a single disjunction (A or B or C...)
- */
- public static AuditDisjunction disjunction() {
- return new AuditDisjunction();
- }
-
- /**
- * Apply a "maximalize property" constraint.
- */
- public static AggregatedFieldAuditExpression maximizeProperty(String propertyName) {
- return new AggregatedFieldAuditExpression(propertyName,
- AggregatedFieldAuditExpression.AggregatedMode.MAX);
- }
-
- /**
- * Apply a "minimize property" constraint.
- */
- public static AggregatedFieldAuditExpression minimizeProperty(String propertyName) {
- return new AggregatedFieldAuditExpression(propertyName,
- AggregatedFieldAuditExpression.AggregatedMode.MIN);
- }
-}
Deleted: core/trunk/envers/src/main/java/org/hibernate/envers/tools/HibernateVersion.java
===================================================================
--- core/trunk/envers/src/main/java/org/hibernate/envers/tools/HibernateVersion.java 2008-11-19 14:17:48 UTC (rev 15592)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/tools/HibernateVersion.java 2008-11-19 14:35:40 UTC (rev 15593)
@@ -1,48 +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.tools;
-
-import org.hibernate.MappingException;
-import org.hibernate.cfg.Environment;
-
-/**
- * @author Adam Warski (adam at warski dot org)
- */
-public class HibernateVersion {
- private static String version;
-
- public static String get() {
- if (version == null) {
- try {
- version = (String) Environment.class.getField("VERSION").get(null);
- } catch (IllegalAccessException e) {
- throw new MappingException(e);
- } catch (NoSuchFieldException e) {
- throw new MappingException(e);
- }
- }
-
- return version;
- }
-}
16 years
Hibernate SVN: r15592 - in search/trunk/src: java/org/hibernate/search/impl and 4 other directories.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2008-11-19 09:17:48 -0500 (Wed, 19 Nov 2008)
New Revision: 15592
Added:
search/trunk/src/test/org/hibernate/search/test/inheritance/Fish.java
Modified:
search/trunk/src/java/org/hibernate/search/engine/MultiClassesQueryLoader.java
search/trunk/src/java/org/hibernate/search/engine/ProjectionLoader.java
search/trunk/src/java/org/hibernate/search/engine/SearchFactoryImplementor.java
search/trunk/src/java/org/hibernate/search/impl/FullTextSessionImpl.java
search/trunk/src/java/org/hibernate/search/impl/SearchFactoryImpl.java
search/trunk/src/java/org/hibernate/search/query/FullTextQueryImpl.java
search/trunk/src/test/org/hibernate/search/test/SearchTestCase.java
search/trunk/src/test/org/hibernate/search/test/filter/FilterTest.java
search/trunk/src/test/org/hibernate/search/test/inheritance/Animal.java
search/trunk/src/test/org/hibernate/search/test/inheritance/Being.java
search/trunk/src/test/org/hibernate/search/test/inheritance/InheritanceTest.java
search/trunk/src/test/org/hibernate/search/test/inheritance/Mammal.java
Log:
HSEARCH-160 HSEARCH-265
- Added new data structure in order to support polymorphic queries
- Added warning for abstract classes annotated with @Indexed (no DocumentBuilder will be created)
Modified: search/trunk/src/java/org/hibernate/search/engine/MultiClassesQueryLoader.java
===================================================================
--- search/trunk/src/java/org/hibernate/search/engine/MultiClassesQueryLoader.java 2008-11-19 14:11:26 UTC (rev 15591)
+++ search/trunk/src/java/org/hibernate/search/engine/MultiClassesQueryLoader.java 2008-11-19 14:17:48 UTC (rev 15592)
@@ -1,16 +1,15 @@
// $Id$
package org.hibernate.search.engine;
-import java.util.List;
import java.util.ArrayList;
import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import java.util.Set;
-import java.util.HashMap;
-import java.util.Arrays;
-import org.hibernate.Session;
import org.hibernate.Criteria;
+import org.hibernate.Session;
import org.hibernate.annotations.common.AssertionFailure;
/**
@@ -30,13 +29,12 @@
this.objectLoader.init( session, searchFactoryImplementor );
}
- public void setEntityTypes(Class[] entityTypes) {
- List<Class> safeEntityTypes;
+ public void setEntityTypes(Set<Class<?>> entityTypes) {
+ List<Class<?>> safeEntityTypes = new ArrayList<Class<?>>();
//TODO should we go find the root entity for a given class rather than just checking for it's root status?
// root entity could lead to quite inefficient queries in Hibernate when using table per class
- if ( entityTypes.length == 0 ) {
+ if ( entityTypes.size() == 0 ) {
//support all classes
- safeEntityTypes = new ArrayList<Class>();
for( Map.Entry<Class<?>, DocumentBuilder<?>> entry : searchFactoryImplementor.getDocumentBuilders().entrySet() ) {
//get only root entities to limit queries
if ( entry.getValue().isRoot() ) {
@@ -45,7 +43,7 @@
}
}
else {
- safeEntityTypes = Arrays.asList(entityTypes);
+ safeEntityTypes.addAll(entityTypes);
}
entityMatadata = new ArrayList<RootEntityMetadata>( safeEntityTypes.size() );
for (Class clazz : safeEntityTypes) {
Modified: search/trunk/src/java/org/hibernate/search/engine/ProjectionLoader.java
===================================================================
--- search/trunk/src/java/org/hibernate/search/engine/ProjectionLoader.java 2008-11-19 14:11:26 UTC (rev 15591)
+++ search/trunk/src/java/org/hibernate/search/engine/ProjectionLoader.java 2008-11-19 14:17:48 UTC (rev 15592)
@@ -3,6 +3,7 @@
import java.util.ArrayList;
import java.util.List;
+import java.util.Set;
import org.hibernate.Session;
import org.hibernate.transform.ResultTransformer;
@@ -21,7 +22,7 @@
private Boolean projectThis;
private ResultTransformer transformer;
private String[] aliases;
- private Class[] entityTypes;
+ private Set<Class<?>> entityTypes;
public void init(Session session, SearchFactoryImplementor searchFactoryImplementor) {
this.session = session;
@@ -34,7 +35,7 @@
this.aliases = aliases;
}
- public void setEntityTypes(Class[] entityTypes) {
+ public void setEntityTypes(Set<Class<?>> entityTypes) {
this.entityTypes = entityTypes;
}
Modified: search/trunk/src/java/org/hibernate/search/engine/SearchFactoryImplementor.java
===================================================================
--- search/trunk/src/java/org/hibernate/search/engine/SearchFactoryImplementor.java 2008-11-19 14:11:26 UTC (rev 15591)
+++ search/trunk/src/java/org/hibernate/search/engine/SearchFactoryImplementor.java 2008-11-19 14:17:48 UTC (rev 15592)
@@ -58,5 +58,7 @@
void addDirectoryProvider(DirectoryProvider<?> provider);
- int getFilterCacheBitResultsSize();
+ int getFilterCacheBitResultsSize();
+
+ Set<Class<?>> getIndexedTypesPolymorphic(Class<?>[] classes);
}
Modified: search/trunk/src/java/org/hibernate/search/impl/FullTextSessionImpl.java
===================================================================
--- search/trunk/src/java/org/hibernate/search/impl/FullTextSessionImpl.java 2008-11-19 14:11:26 UTC (rev 15591)
+++ search/trunk/src/java/org/hibernate/search/impl/FullTextSessionImpl.java 2008-11-19 14:17:48 UTC (rev 15592)
@@ -109,30 +109,34 @@
// accessing the document builders is not strictly necessary but a small optimization plus let's make sure the
// client didn't mess something up.
SearchFactoryImplementor searchFactoryImplementor = getSearchFactoryImplementor();
- DocumentBuilder builder = searchFactoryImplementor.getDocumentBuilder( entityType );
- if ( builder == null ) {
- String msg = "Entity to index is not an @Indexed entity: " + entityType.getName();
- throw new IllegalArgumentException( msg );
- }
+ Set<Class<?>> targetedClasses = searchFactoryImplementor.getIndexedTypesPolymorphic( new Class[] {entityType} );
- Work<T> work;
- if ( id == null ) {
- // purge the main entity
- work = new Work<T>( entityType, id, WorkType.PURGE_ALL );
- searchFactoryImplementor.getWorker().performWork( work, transactionContext );
+ for ( Class clazz : targetedClasses ) {
+ DocumentBuilder builder = searchFactoryImplementor.getDocumentBuilder( clazz );
+ if ( builder == null ) {
+ String msg = "Entity to index is not an @Indexed entity: " + clazz.getName();
+ throw new IllegalArgumentException( msg );
+ }
- // purge the subclasses
- Set<Class<?>> subClasses = builder.getMappedSubclasses();
- for ( Class clazz : subClasses ) {
- @SuppressWarnings( "unchecked" )
- Work subClassWork = new Work( clazz, id, WorkType.PURGE_ALL );
- searchFactoryImplementor.getWorker().performWork( subClassWork, transactionContext );
+ Work<T> work;
+ if ( id == null ) {
+ // purge the main entity
+ work = new Work<T>( clazz, id, WorkType.PURGE_ALL );
+ searchFactoryImplementor.getWorker().performWork( work, transactionContext );
+
+ // purge the subclasses
+ Set<Class<?>> subClasses = builder.getMappedSubclasses();
+ for ( Class subClazz : subClasses ) {
+ @SuppressWarnings( "unchecked" )
+ Work subClassWork = new Work( subClazz, id, WorkType.PURGE_ALL );
+ searchFactoryImplementor.getWorker().performWork( subClassWork, transactionContext );
+ }
}
+ else {
+ work = new Work<T>( clazz, id, WorkType.PURGE );
+ searchFactoryImplementor.getWorker().performWork( work, transactionContext );
+ }
}
- else {
- work = new Work<T>( entityType, id, WorkType.PURGE );
- searchFactoryImplementor.getWorker().performWork( work, transactionContext );
- }
}
/**
Modified: search/trunk/src/java/org/hibernate/search/impl/SearchFactoryImpl.java
===================================================================
--- search/trunk/src/java/org/hibernate/search/impl/SearchFactoryImpl.java 2008-11-19 14:11:26 UTC (rev 15591)
+++ search/trunk/src/java/org/hibernate/search/impl/SearchFactoryImpl.java 2008-11-19 14:17:48 UTC (rev 15592)
@@ -12,6 +12,7 @@
import java.util.Map;
import java.util.Properties;
import java.util.Set;
+import java.util.Arrays;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.locks.ReentrantLock;
@@ -75,8 +76,11 @@
private Map<String, Analyzer> analyzers;
private final AtomicBoolean stopped = new AtomicBoolean( false );
private final int cacheBitResultsSize;
+
+ private final PolymorphicIndexHierarchy indexHierarchy = new PolymorphicIndexHierarchy();
+
/*
- * used as a barrier (piggyback usage) between initialization and subsequent usage of searchFactory in different threads
+ * Used as a barrier (piggyback usage) between initialization and subsequent usage of searchFactory in different threads
* this is due to our use of the initialize pattern is a few areas
* subsequent reads on volatiles should be very cheap on most platform especially since we don't write after init
*
@@ -90,12 +94,13 @@
* Each directory provider (index) can have its own performance settings.
*/
private Map<DirectoryProvider, LuceneIndexingParameters> dirProviderIndexingParams =
- new HashMap<DirectoryProvider, LuceneIndexingParameters>();
+ new HashMap<DirectoryProvider, LuceneIndexingParameters>();
private final String indexingStrategy;
public BackendQueueProcessorFactory getBackendQueueProcessorFactory() {
- if (barrier != 0) { } //read barrier
+ if ( barrier != 0 ) {
+ } //read barrier
return backendQueueProcessorFactory;
}
@@ -113,56 +118,60 @@
initDocumentBuilders( cfg, reflectionManager );
Set<Class<?>> indexedClasses = documentBuilders.keySet();
- for (DocumentBuilder builder : documentBuilders.values()) {
+ for ( DocumentBuilder builder : documentBuilders.values() ) {
builder.postInitialize( indexedClasses );
}
//not really necessary today
- for (DocumentBuilder builder : containedInOnlyBuilders.values()) {
+ for ( DocumentBuilder builder : containedInOnlyBuilders.values() ) {
builder.postInitialize( indexedClasses );
}
this.worker = WorkerFactory.createWorker( cfg, this );
this.readerProvider = ReaderProviderFactory.createReaderProvider( cfg, this );
this.filterCachingStrategy = buildFilterCachingStrategy( cfg.getProperties() );
- this.cacheBitResultsSize = ConfigurationParseHelper.getIntValue( cfg.getProperties(), Environment.CACHE_BIT_RESULT_SIZE, CachingWrapperFilter.DEFAULT_SIZE );
+ this.cacheBitResultsSize = ConfigurationParseHelper.getIntValue(
+ cfg.getProperties(), Environment.CACHE_BIT_RESULT_SIZE, CachingWrapperFilter.DEFAULT_SIZE
+ );
this.barrier = 1; //write barrier
}
private static String defineIndexingStrategy(SearchConfiguration cfg) {
String indexingStrategy = cfg.getProperties().getProperty( Environment.INDEXING_STRATEGY, "event" );
- if ( ! ("event".equals( indexingStrategy ) || "manual".equals( indexingStrategy ) ) ) {
+ if ( !( "event".equals( indexingStrategy ) || "manual".equals( indexingStrategy ) ) ) {
throw new SearchException( Environment.INDEXING_STRATEGY + " unknown: " + indexingStrategy );
}
return indexingStrategy;
}
public String getIndexingStrategy() {
- if (barrier != 0) { } //read barrier
+ if ( barrier != 0 ) {
+ } //read barrier
return indexingStrategy;
}
public void close() {
- if (barrier != 0) { } //read barrier
- if ( stopped.compareAndSet( false, true) ) {
+ if ( barrier != 0 ) {
+ } //read barrier
+ if ( stopped.compareAndSet( false, true ) ) {
try {
worker.close();
}
- catch (Exception e) {
+ catch ( Exception e ) {
log.error( "Worker raises an exception on close()", e );
}
try {
readerProvider.destroy();
}
- catch (Exception e) {
+ catch ( Exception e ) {
log.error( "ReaderProvider raises an exception on destroy()", e );
}
//TODO move to DirectoryProviderFactory for cleaner
- for (DirectoryProvider dp : getDirectoryProviders() ) {
+ for ( DirectoryProvider dp : getDirectoryProviders() ) {
try {
dp.stop();
}
- catch (Exception e) {
+ catch ( Exception e ) {
log.error( "DirectoryProvider raises an exception on stop() ", e );
}
}
@@ -171,17 +180,18 @@
public void addClassToDirectoryProvider(Class<?> clazz, DirectoryProvider<?> directoryProvider) {
//no need to set a read barrier, we only use this class in the init thread
- DirectoryProviderData data = dirProviderData.get(directoryProvider);
- if (data == null) {
+ DirectoryProviderData data = dirProviderData.get( directoryProvider );
+ if ( data == null ) {
data = new DirectoryProviderData();
dirProviderData.put( directoryProvider, data );
}
- data.classes.add(clazz);
+ data.classes.add( clazz );
}
public Set<Class<?>> getClassesInDirectoryProvider(DirectoryProvider<?> directoryProvider) {
- if (barrier != 0) { } //read barrier
- return Collections.unmodifiableSet( dirProviderData.get(directoryProvider).classes );
+ if ( barrier != 0 ) {
+ } //read barrier
+ return Collections.unmodifiableSet( dirProviderData.get( directoryProvider ).classes );
}
private void bindFilterDefs(XClass mappedXClass) {
@@ -190,7 +200,7 @@
bindFilterDef( defAnn, mappedXClass );
}
FullTextFilterDefs defsAnn = mappedXClass.getAnnotation( FullTextFilterDefs.class );
- if (defsAnn != null) {
+ if ( defsAnn != null ) {
for ( FullTextFilterDef def : defsAnn.value() ) {
bindFilterDef( def, mappedXClass );
}
@@ -199,35 +209,45 @@
private void bindFilterDef(FullTextFilterDef defAnn, XClass mappedXClass) {
if ( filterDefinitions.containsKey( defAnn.name() ) ) {
- throw new SearchException("Multiple definition of @FullTextFilterDef.name=" + defAnn.name() + ": "
- + mappedXClass.getName() );
+ throw new SearchException(
+ "Multiple definition of @FullTextFilterDef.name=" + defAnn.name() + ": "
+ + mappedXClass.getName()
+ );
}
- FilterDef filterDef = new FilterDef(defAnn);
+ FilterDef filterDef = new FilterDef( defAnn );
try {
filterDef.getImpl().newInstance();
}
- catch (IllegalAccessException e) {
- throw new SearchException("Unable to create Filter class: " + filterDef.getImpl().getName(), e);
+ catch ( IllegalAccessException e ) {
+ throw new SearchException( "Unable to create Filter class: " + filterDef.getImpl().getName(), e );
}
- catch (InstantiationException e) {
- throw new SearchException("Unable to create Filter class: " + filterDef.getImpl().getName(), e);
+ catch ( InstantiationException e ) {
+ throw new SearchException( "Unable to create Filter class: " + filterDef.getImpl().getName(), e );
}
for ( Method method : filterDef.getImpl().getMethods() ) {
if ( method.isAnnotationPresent( Factory.class ) ) {
if ( filterDef.getFactoryMethod() != null ) {
- throw new SearchException("Multiple @Factory methods found" + defAnn.name() + ": "
- + filterDef.getImpl().getName() + "." + method.getName() );
+ throw new SearchException(
+ "Multiple @Factory methods found" + defAnn.name() + ": "
+ + filterDef.getImpl().getName() + "." + method.getName()
+ );
}
- if ( !method.isAccessible() ) method.setAccessible( true );
+ if ( !method.isAccessible() ) {
+ method.setAccessible( true );
+ }
filterDef.setFactoryMethod( method );
}
if ( method.isAnnotationPresent( Key.class ) ) {
if ( filterDef.getKeyMethod() != null ) {
- throw new SearchException("Multiple @Key methods found" + defAnn.name() + ": "
- + filterDef.getImpl().getName() + "." + method.getName() );
+ throw new SearchException(
+ "Multiple @Key methods found" + defAnn.name() + ": "
+ + filterDef.getImpl().getName() + "." + method.getName()
+ );
}
- if ( !method.isAccessible() ) method.setAccessible( true );
+ if ( !method.isAccessible() ) {
+ method.setAccessible( true );
+ }
filterDef.setKeyMethod( method );
}
@@ -241,36 +261,41 @@
public Map<Class<?>, DocumentBuilder<?>> getDocumentBuilders() {
- if (barrier != 0) { } //read barrier
+ if ( barrier != 0 ) {
+ } //read barrier
return documentBuilders;
}
- @SuppressWarnings( "unchecked" )
+ @SuppressWarnings("unchecked")
public <T> DocumentBuilder<T> getDocumentBuilder(Class<T> entityType) {
- if (barrier != 0) { } //read barrier
+ if ( barrier != 0 ) {
+ } //read barrier
return ( DocumentBuilder<T> ) documentBuilders.get( entityType );
}
- @SuppressWarnings( "unchecked" )
+ @SuppressWarnings("unchecked")
public <T> DocumentBuilder<T> getContainedInOnlyBuilder(Class<T> entityType) {
- if (barrier != 0) { } //read barrier
+ if ( barrier != 0 ) {
+ } //read barrier
return ( DocumentBuilder<T> ) containedInOnlyBuilders.get( entityType );
}
public Set<DirectoryProvider<?>> getDirectoryProviders() {
- if (barrier != 0) { } //read barrier
+ if ( barrier != 0 ) {
+ } //read barrier
return this.dirProviderData.keySet();
}
public Worker getWorker() {
- if (barrier != 0) { } //read barrier
+ if ( barrier != 0 ) {
+ } //read barrier
return worker;
}
public void addOptimizerStrategy(DirectoryProvider<?> provider, OptimizerStrategy optimizerStrategy) {
//no need to set a read barrier, we run this method on the init thread
- DirectoryProviderData data = dirProviderData.get(provider);
- if (data == null) {
+ DirectoryProviderData data = dirProviderData.get( provider );
+ if ( data == null ) {
data = new DirectoryProviderData();
dirProviderData.put( provider, data );
}
@@ -283,63 +308,74 @@
}
public OptimizerStrategy getOptimizerStrategy(DirectoryProvider<?> provider) {
- if (barrier != 0) {} //read barrier
+ if ( barrier != 0 ) {
+ } //read barrier
return dirProviderData.get( provider ).optimizerStrategy;
}
- public LuceneIndexingParameters getIndexingParameters(DirectoryProvider<?> provider ) {
- if (barrier != 0) {} //read barrier
+ public LuceneIndexingParameters getIndexingParameters(DirectoryProvider<?> provider) {
+ if ( barrier != 0 ) {
+ } //read barrier
return dirProviderIndexingParams.get( provider );
}
public ReaderProvider getReaderProvider() {
- if (barrier != 0) {} //read barrier
+ if ( barrier != 0 ) {
+ } //read barrier
return readerProvider;
}
public DirectoryProvider[] getDirectoryProviders(Class<?> entity) {
- if (barrier != 0) {} //read barrier
+ if ( barrier != 0 ) {
+ } //read barrier
DocumentBuilder<?> documentBuilder = getDocumentBuilder( entity );
return documentBuilder == null ? null : documentBuilder.getDirectoryProviders();
}
public void optimize() {
- if (barrier != 0) {} //read barrier
+ if ( barrier != 0 ) {
+ } //read barrier
Set<Class<?>> clazzs = getDocumentBuilders().keySet();
- for (Class clazz : clazzs) {
+ for ( Class clazz : clazzs ) {
optimize( clazz );
}
}
public void optimize(Class entityType) {
- if (barrier != 0) {} //read barrier
- if ( ! getDocumentBuilders().containsKey( entityType ) ) {
- throw new SearchException("Entity not indexed: " + entityType);
+ if ( barrier != 0 ) {
+ } //read barrier
+ if ( !getDocumentBuilders().containsKey( entityType ) ) {
+ throw new SearchException( "Entity not indexed: " + entityType );
}
- List<LuceneWork> queue = new ArrayList<LuceneWork>(1);
+ List<LuceneWork> queue = new ArrayList<LuceneWork>( 1 );
queue.add( new OptimizeLuceneWork( entityType ) );
getBackendQueueProcessorFactory().getProcessor( queue ).run();
}
public Analyzer getAnalyzer(String name) {
- if (barrier != 0) {} //read barrier
+ if ( barrier != 0 ) {
+ } //read barrier
final Analyzer analyzer = analyzers.get( name );
- if ( analyzer == null) throw new SearchException( "Unknown Analyzer definition: " + name);
+ if ( analyzer == null ) {
+ throw new SearchException( "Unknown Analyzer definition: " + name );
+ }
return analyzer;
}
-
+
public Analyzer getAnalyzer(Class clazz) {
- if ( clazz == null) {
+ if ( clazz == null ) {
throw new IllegalArgumentException( "A class has to be specified for retrieving a scoped analyzer" );
}
-
+
DocumentBuilder<?> builder = documentBuilders.get( clazz );
if ( builder == null ) {
- throw new IllegalArgumentException( "Entity for which to retrieve the scoped analyzer is not an @Indexed entity: " + clazz.getName() );
+ throw new IllegalArgumentException(
+ "Entity for which to retrieve the scoped analyzer is not an @Indexed entity: " + clazz.getName()
+ );
}
-
+
return builder.getAnalyzer();
- }
+ }
private void initDocumentBuilders(SearchConfiguration cfg, ReflectionManager reflectionManager) {
InitContext context = new InitContext( cfg );
@@ -348,35 +384,48 @@
while ( iter.hasNext() ) {
Class mappedClass = iter.next();
- if (mappedClass != null) {
- XClass mappedXClass = reflectionManager.toXClass(mappedClass);
- if ( mappedXClass != null) {
- if ( mappedXClass.isAnnotationPresent( Indexed.class ) ) {
- DirectoryProviderFactory.DirectoryProviders providers = factory.createDirectoryProviders( mappedXClass, cfg, this, reflectionManager );
- //FIXME DocumentBuilder needs to be built by a helper method receiving Class<T> to infer T properly
- //XClass unfortunately is not (yet) genericized: TODO?
- final DocumentBuilder<?> documentBuilder = new DocumentBuilder(
- mappedXClass, context, providers.getProviders(), providers.getSelectionStrategy(),
- reflectionManager
- );
+ if ( mappedClass == null ) {
+ continue;
+ }
+ @SuppressWarnings( "unchecked" )
+ XClass mappedXClass = reflectionManager.toXClass( mappedClass );
+ if ( mappedXClass == null ) {
+ continue;
+ }
- documentBuilders.put( mappedClass, documentBuilder );
- }
- else {
- //FIXME DocumentBuilder needs to be built by a helper method receiving Class<T> to infer T properly
- //XClass unfortunately is not (yet) genericized: TODO?
- final DocumentBuilder<?> documentBuilder = new DocumentBuilder(
- mappedXClass, context, reflectionManager
- );
- //TODO enhance that, I don't like to expose EntityState
- if ( documentBuilder.getEntityState() != EntityState.NON_INDEXABLE ) {
- containedInOnlyBuilders.put( mappedClass, documentBuilder );
- }
- }
- bindFilterDefs(mappedXClass);
- //TODO should analyzer def for classes at tyher sqme level???
+ if ( mappedXClass.isAnnotationPresent( Indexed.class ) ) {
+
+ if ( mappedXClass.isAbstract() ) {
+ log.warn( "Abstract classes can never insert index documents. Remove @Indexed." );
+ continue;
}
+
+ DirectoryProviderFactory.DirectoryProviders providers = factory.createDirectoryProviders(
+ mappedXClass, cfg, this, reflectionManager
+ );
+ //FIXME DocumentBuilder needs to be built by a helper method receiving Class<T> to infer T properly
+ //XClass unfortunately is not (yet) genericized: TODO?
+ final DocumentBuilder<?> documentBuilder = new DocumentBuilder(
+ mappedXClass, context, providers.getProviders(), providers.getSelectionStrategy(),
+ reflectionManager
+ );
+
+ indexHierarchy.addIndexedClass( mappedClass );
+ documentBuilders.put( mappedClass, documentBuilder );
}
+ else {
+ //FIXME DocumentBuilder needs to be built by a helper method receiving Class<T> to infer T properly
+ //XClass unfortunately is not (yet) genericized: TODO?
+ final DocumentBuilder<?> documentBuilder = new DocumentBuilder(
+ mappedXClass, context, reflectionManager
+ );
+ //TODO enhance that, I don't like to expose EntityState
+ if ( documentBuilder.getEntityState() != EntityState.NON_INDEXABLE ) {
+ containedInOnlyBuilders.put( mappedClass, documentBuilder );
+ }
+ }
+ bindFilterDefs( mappedXClass );
+ //TODO should analyzer def for classes at tyher sqme level???
}
analyzers = context.initLazyAnalyzers();
factory.startDirectoryProviders();
@@ -390,16 +439,21 @@
}
else {
try {
- Class filterCachingStrategyClass = org.hibernate.annotations.common.util.ReflectHelper.classForName( impl, SearchFactoryImpl.class );
- filterCachingStrategy = (FilterCachingStrategy) filterCachingStrategyClass.newInstance();
+ Class filterCachingStrategyClass = org.hibernate
+ .annotations
+ .common
+ .util
+ .ReflectHelper
+ .classForName( impl, SearchFactoryImpl.class );
+ filterCachingStrategy = ( FilterCachingStrategy ) filterCachingStrategyClass.newInstance();
}
- catch (ClassNotFoundException e) {
+ catch ( ClassNotFoundException e ) {
throw new SearchException( "Unable to find filterCachingStrategy class: " + impl, e );
}
- catch (IllegalAccessException e) {
+ catch ( IllegalAccessException e ) {
throw new SearchException( "Unable to instantiate filterCachingStrategy class: " + impl, e );
}
- catch (InstantiationException e) {
+ catch ( InstantiationException e ) {
throw new SearchException( "Unable to instantiate filterCachingStrategy class: " + impl, e );
}
}
@@ -408,23 +462,26 @@
}
public FilterCachingStrategy getFilterCachingStrategy() {
- if (barrier != 0) {} //read barrier
+ if ( barrier != 0 ) {
+ } //read barrier
return filterCachingStrategy;
}
public FilterDef getFilterDefinition(String name) {
- if (barrier != 0) {} //read barrier
+ if ( barrier != 0 ) {
+ } //read barrier
return filterDefinitions.get( name );
}
private static class DirectoryProviderData {
public final ReentrantLock dirLock = new ReentrantLock();
public OptimizerStrategy optimizerStrategy;
- public Set<Class<?>> classes = new HashSet<Class<?>>(2);
+ public Set<Class<?>> classes = new HashSet<Class<?>>( 2 );
}
public ReentrantLock getDirectoryProviderLock(DirectoryProvider<?> dp) {
- if (barrier != 0) {} //read barrier
+ if ( barrier != 0 ) {
+ } //read barrier
return this.dirProviderData.get( dp ).dirLock;
}
@@ -434,7 +491,58 @@
}
public int getFilterCacheBitResultsSize() {
- if (barrier != 0) {} //read barrier
+ if ( barrier != 0 ) {
+ } //read barrier
return cacheBitResultsSize;
}
+
+ public Set<Class<?>> getIndexedTypesPolymorphic(Class<?>[] classes) {
+ return indexHierarchy.getIndexedClasses( classes );
+ }
+
+ /**
+ * Helper class which keeps track of all super classes and interfaces of the indexed entities.
+ */
+ private static class PolymorphicIndexHierarchy {
+ private Map<Class<?>, Set<Class<?>>> classToIndexedClass;
+
+ PolymorphicIndexHierarchy() {
+ classToIndexedClass = new HashMap<Class<?>, Set<Class<?>>>();
+ }
+
+ void addIndexedClass(Class indexedClass) {
+ addClass( indexedClass, indexedClass );
+ Class superClass = indexedClass.getSuperclass();
+ while ( superClass != null ) {
+ addClass( superClass, indexedClass );
+ superClass = superClass.getSuperclass();
+ }
+ for ( Class clazz : indexedClass.getInterfaces() ) {
+ addClass( clazz, indexedClass );
+ }
+ }
+
+ private void addClass(Class superclass, Class indexedClass) {
+ Set<Class<?>> classesSet = classToIndexedClass.get( superclass );
+ if ( classesSet == null ) {
+ classesSet = new HashSet<Class<?>>();
+ classToIndexedClass.put( superclass, classesSet );
+ }
+ classesSet.add( indexedClass );
+ }
+
+ Set<Class<?>> getIndexedClasses(Class<?>[] classes) {
+ Set<Class<?>> classesSet = new HashSet<Class<?>>();
+ for ( Class clazz : classes ) {
+ Set<Class<?>> set = classToIndexedClass.get( clazz );
+ if ( set != null ) {
+ classesSet.addAll( set );
+ }
+ }
+ if ( log.isTraceEnabled() ) {
+ log.trace( "Targeted indexed classes for {}: {}", Arrays.toString( classes ), classesSet );
+ }
+ return classesSet;
+ }
+ }
}
Modified: search/trunk/src/java/org/hibernate/search/query/FullTextQueryImpl.java
===================================================================
--- search/trunk/src/java/org/hibernate/search/query/FullTextQueryImpl.java 2008-11-19 14:11:26 UTC (rev 15591)
+++ search/trunk/src/java/org/hibernate/search/query/FullTextQueryImpl.java 2008-11-19 14:17:48 UTC (rev 15592)
@@ -72,7 +72,7 @@
public class FullTextQueryImpl extends AbstractQueryImpl implements FullTextQuery {
private static final Logger log = LoggerFactory.make();
private final org.apache.lucene.search.Query luceneQuery;
- private Class<?>[] classes;
+ private Set<Class<?>> targetedEntities;
private Set<Class<?>> classesAndSubclasses;
//optimization: if we can avoid the filter clause (we can most of the time) do it as it has a significant perf impact
private boolean needClassFilterClause;
@@ -93,17 +93,17 @@
/**
* Constructs a <code>FullTextQueryImpl</code> instance.
*
- * @param query The Lucene query
- * @param classes Array of classes (must be immutable) used to filter the results to the given class types.
+ * @param query The Lucene query.
+ * @param classes Array of classes (must be immutable) used to filter the results to the given class types.
* @param session Access to the Hibernate session.
- * @param parameterMetadata Additional query metadata.
+ * @param parameterMetadata Additional query metadata.
*/
public FullTextQueryImpl(org.apache.lucene.search.Query query, Class[] classes, SessionImplementor session,
ParameterMetadata parameterMetadata) {
//TODO handle flushMode
super( query.toString(), null, session, parameterMetadata );
this.luceneQuery = query;
- this.classes = classes;
+ this.targetedEntities = getSearchFactoryImplementor().getIndexedTypesPolymorphic( classes );
}
/**
@@ -132,7 +132,7 @@
//user stop using it
//scrollable is better in this area
- SearchFactoryImplementor searchFactoryImplementor = ContextHelper.getSearchFactoryBySFI( session );
+ SearchFactoryImplementor searchFactoryImplementor = getSearchFactoryImplementor();
//find the directories
IndexSearcher searcher = buildSearcher( searchFactoryImplementor );
if ( searcher == null ) {
@@ -173,22 +173,23 @@
if ( indexProjection != null ) {
ProjectionLoader loader = new ProjectionLoader();
loader.init( session, searchFactoryImplementor, resultTransformer, indexProjection );
- loader.setEntityTypes( classes );
+ loader.setEntityTypes( targetedEntities );
return loader;
}
if ( criteria != null ) {
- if ( classes.length > 1 ) {
+ if ( targetedEntities.size() > 1 ) {
throw new SearchException( "Cannot mix criteria and multiple entity types" );
}
if ( criteria instanceof CriteriaImpl ) {
String targetEntity = ( ( CriteriaImpl ) criteria ).getEntityOrClassName();
- if ( classes.length == 1 && !classes[0].getName().equals( targetEntity ) ) {
+ if ( targetedEntities.size() == 1 && !targetedEntities.iterator().next().getName().equals( targetEntity ) ) {
throw new SearchException( "Criteria query entity should match query entity" );
}
else {
try {
Class entityType = ReflectHelper.classForName( targetEntity );
- classes = new Class[] { entityType };
+ targetedEntities = new HashSet<Class<?>>( 1 );
+ targetedEntities.add( entityType );
}
catch ( ClassNotFoundException e ) {
throw new SearchException( "Unable to load entity class from criteria: " + targetEntity, e );
@@ -197,20 +198,20 @@
}
QueryLoader loader = new QueryLoader();
loader.init( session, searchFactoryImplementor );
- loader.setEntityType( classes[0] );
+ loader.setEntityType( targetedEntities.iterator().next() );
loader.setCriteria( criteria );
return loader;
}
- else if ( classes.length == 1 ) {
+ else if ( targetedEntities.size() == 1 ) {
final QueryLoader loader = new QueryLoader();
loader.init( session, searchFactoryImplementor );
- loader.setEntityType( classes[0] );
+ loader.setEntityType( targetedEntities.iterator().next() );
return loader;
}
else {
final MultiClassesQueryLoader loader = new MultiClassesQueryLoader();
loader.init( session, searchFactoryImplementor );
- loader.setEntityTypes( classes );
+ loader.setEntityTypes( targetedEntities );
return loader;
}
}
@@ -227,7 +228,7 @@
int first = first();
int max = max( first, queryHits.totalHits );
DocumentExtractor extractor = new DocumentExtractor(
- queryHits, searchFactory, indexProjection, idFieldNames,allowFieldSelectionInProjection
+ queryHits, searchFactory, indexProjection, idFieldNames, allowFieldSelectionInProjection
);
Loader loader = getLoader( ( Session ) this.session, searchFactory );
return new ScrollableResultsImpl(
@@ -574,8 +575,9 @@
* Build the index searcher for this fulltext query.
*
* @param searchFactoryImplementor the search factory.
+ *
* @return the <code>IndexSearcher</code> for this query (can be <code>null</code>.
- * TODO change classesAndSubclasses by side effect, which is a mismatch with the Searcher return, fix that.
+ * TODO change classesAndSubclasses by side effect, which is a mismatch with the Searcher return, fix that.
*/
private IndexSearcher buildSearcher(SearchFactoryImplementor searchFactoryImplementor) {
Map<Class<?>, DocumentBuilder<?>> builders = searchFactoryImplementor.getDocumentBuilders();
@@ -583,9 +585,9 @@
Set<String> idFieldNames = new HashSet<String>();
Similarity searcherSimilarity = null;
- //TODO check if caching this work for the last n list of classes makes a perf boost
- if ( classes == null || classes.length == 0 ) {
- // empty classes array means search over all indexed enities,
+ //TODO check if caching this work for the last n list of targetedEntities makes a perf boost
+ if ( targetedEntities.size() == 0 ) {
+ // empty targetedEntities array means search over all indexed enities,
// but we have to make sure there is at least one
if ( builders.isEmpty() ) {
throw new HibernateException(
@@ -606,9 +608,9 @@
classesAndSubclasses = null;
}
else {
- Set<Class<?>> involvedClasses = new HashSet<Class<?>>( classes.length );
- Collections.addAll( involvedClasses, classes );
- for ( Class<?> clazz : classes ) {
+ Set<Class<?>> involvedClasses = new HashSet<Class<?>>( targetedEntities.size() );
+ involvedClasses.addAll( targetedEntities );
+ for ( Class<?> clazz : targetedEntities ) {
DocumentBuilder<?> builder = builders.get( clazz );
if ( builder != null ) {
involvedClasses.addAll( builder.getMappedSubclasses() );
Modified: search/trunk/src/test/org/hibernate/search/test/SearchTestCase.java
===================================================================
--- search/trunk/src/test/org/hibernate/search/test/SearchTestCase.java 2008-11-19 14:11:26 UTC (rev 15591)
+++ search/trunk/src/test/org/hibernate/search/test/SearchTestCase.java 2008-11-19 14:17:48 UTC (rev 15592)
@@ -6,11 +6,19 @@
import org.apache.lucene.analysis.StopAnalyzer;
import org.apache.lucene.store.Directory;
import org.hibernate.HibernateException;
+import org.hibernate.Transaction;
import org.hibernate.event.PostInsertEventListener;
import org.hibernate.impl.SessionFactoryImpl;
import org.hibernate.search.Environment;
+import org.hibernate.search.FullTextSession;
+import org.hibernate.search.Search;
+import org.hibernate.search.annotations.Indexed;
+import org.hibernate.search.test.inheritance.Animal;
+import org.hibernate.search.test.inheritance.Mammal;
import org.hibernate.search.event.FullTextIndexEventListener;
import org.hibernate.search.store.RAMDirectoryProvider;
+import org.hibernate.search.store.FSDirectoryProvider;
+
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -58,6 +66,18 @@
return listener;
}
+ protected void ensureIndexesAreEmpty() {
+ FullTextSession s = Search.getFullTextSession( openSession() );
+ Transaction tx;
+ tx = s.beginTransaction();
+ for ( Class clazz : getMappings() ) {
+ if ( clazz.getAnnotation( Indexed.class ) != null ) {
+ s.purgeAll( clazz );
+ }
+ }
+ tx.commit();
+ }
+
protected void configure(org.hibernate.cfg.Configuration cfg) {
cfg.setProperty( "hibernate.search.default.directory_provider", RAMDirectoryProvider.class.getName() );
cfg.setProperty( Environment.ANALYZER_CLASS, StopAnalyzer.class.getName() );
Modified: search/trunk/src/test/org/hibernate/search/test/filter/FilterTest.java
===================================================================
--- search/trunk/src/test/org/hibernate/search/test/filter/FilterTest.java 2008-11-19 14:11:26 UTC (rev 15591)
+++ search/trunk/src/test/org/hibernate/search/test/filter/FilterTest.java 2008-11-19 14:17:48 UTC (rev 15592)
@@ -96,11 +96,7 @@
//success
}
-
s.getTransaction().commit();
-
-
-
s.close();
deleteData();
}
Modified: search/trunk/src/test/org/hibernate/search/test/inheritance/Animal.java
===================================================================
--- search/trunk/src/test/org/hibernate/search/test/inheritance/Animal.java 2008-11-19 14:11:26 UTC (rev 15591)
+++ search/trunk/src/test/org/hibernate/search/test/inheritance/Animal.java 2008-11-19 14:17:48 UTC (rev 15592)
@@ -1,6 +1,7 @@
//$Id$
package org.hibernate.search.test.inheritance;
+import java.io.Serializable;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
@@ -15,8 +16,7 @@
* @author Emmanuel Bernard
*/
@Entity
-@Indexed
-public class Animal extends Being {
+public abstract class Animal extends Being {
private Long id;
private String name;
Modified: search/trunk/src/test/org/hibernate/search/test/inheritance/Being.java
===================================================================
--- search/trunk/src/test/org/hibernate/search/test/inheritance/Being.java 2008-11-19 14:11:26 UTC (rev 15591)
+++ search/trunk/src/test/org/hibernate/search/test/inheritance/Being.java 2008-11-19 14:17:48 UTC (rev 15592)
@@ -6,6 +6,7 @@
import org.hibernate.search.annotations.Field;
import org.hibernate.search.annotations.Index;
import org.hibernate.search.annotations.FieldBridge;
+import org.hibernate.search.annotations.Indexed;
import org.hibernate.search.test.bridge.PaddedIntegerBridge;
/**
Copied: search/trunk/src/test/org/hibernate/search/test/inheritance/Fish.java (from rev 15588, search/trunk/src/test/org/hibernate/search/test/inheritance/Mammal.java)
===================================================================
--- search/trunk/src/test/org/hibernate/search/test/inheritance/Fish.java (rev 0)
+++ search/trunk/src/test/org/hibernate/search/test/inheritance/Fish.java 2008-11-19 14:17:48 UTC (rev 15592)
@@ -0,0 +1,28 @@
+//$Id$
+package org.hibernate.search.test.inheritance;
+
+import javax.persistence.Entity;
+
+import org.hibernate.search.annotations.Field;
+import org.hibernate.search.annotations.Index;
+import org.hibernate.search.annotations.Indexed;
+import org.hibernate.search.annotations.Store;
+
+/**
+ * @author Hardy Ferentschik
+ */
+@Entity
+@Indexed
+public class Fish extends Animal {
+
+ private int numberOfDorsalFins;
+
+ @Field(index = Index.UN_TOKENIZED, store = Store.YES)
+ public int getNumberOfDorsalFins() {
+ return numberOfDorsalFins;
+ }
+
+ public void setNumberOfDorsalFins(int numberOfDorsalFins) {
+ this.numberOfDorsalFins = numberOfDorsalFins;
+ }
+}
\ No newline at end of file
Property changes on: search/trunk/src/test/org/hibernate/search/test/inheritance/Fish.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:mergeinfo
+
Modified: search/trunk/src/test/org/hibernate/search/test/inheritance/InheritanceTest.java
===================================================================
--- search/trunk/src/test/org/hibernate/search/test/inheritance/InheritanceTest.java 2008-11-19 14:11:26 UTC (rev 15591)
+++ search/trunk/src/test/org/hibernate/search/test/inheritance/InheritanceTest.java 2008-11-19 14:17:48 UTC (rev 15592)
@@ -2,6 +2,7 @@
package org.hibernate.search.test.inheritance;
import java.util.List;
+import java.io.Serializable;
import org.apache.lucene.analysis.StopAnalyzer;
import org.apache.lucene.index.Term;
@@ -26,41 +27,76 @@
public void testInheritance() throws Exception {
createTestData();
+
FullTextSession s = Search.getFullTextSession( openSession() );
Transaction tx = s.beginTransaction();
+
QueryParser parser = new QueryParser( "name", new StopAnalyzer() );
+ Query query = parser.parse( "Elephant" );
+ org.hibernate.Query hibQuery = s.createFullTextQuery( query, Mammal.class );
+ assertItsTheElephant( hibQuery.list() );
- Query query;
- org.hibernate.Query hibQuery;
+ query = parser.parse( "hasSweatGlands:false" );
+ hibQuery = s.createFullTextQuery( query, Animal.class, Mammal.class );
+ assertItsTheElephant( hibQuery.list() );
- query = parser.parse( "Elephant" );
- hibQuery = s.createFullTextQuery( query, Mammal.class );
+ query = parser.parse( "Elephant OR White Pointer" );
+ hibQuery = s.createFullTextQuery( query, Being.class );
List result = hibQuery.list();
assertNotNull( result );
- assertEquals( "Query subclass by superclass attribute", 1, result.size() );
+ assertEquals( "Query filtering on superclass return mapped subclasses", 2, result.size() );
- query = parser.parse( "mammalNbr:[2 TO 2]" );
- hibQuery = s.createFullTextQuery( query, Animal.class, Mammal.class );
- result = hibQuery.list();
- assertNotNull( result );
- assertEquals( "Query subclass by subclass attribute", 1, result.size() );
-
- query = parser.parse( "Jr" );
+ query = new RangeQuery( new Term( "weight", "04000" ), new Term( "weight", "05000" ), true );
hibQuery = s.createFullTextQuery( query, Animal.class );
- result = hibQuery.list();
- assertNotNull( result );
- assertEquals( "Query filtering on superclass return mapped subclasses", 2, result.size() );
+ assertItsTheElephant( hibQuery.list() );
- query = new RangeQuery( new Term( "weight", "00200" ), null, true );
+ query = parser.parse( "Elephant" );
+ hibQuery = s.createFullTextQuery( query, Being.class );
+ assertItsTheElephant( hibQuery.list() );
+
+ tx.commit();
+ s.close();
+ }
+
+
+ public void testPolymorphicQueries() throws Exception {
+ createTestData();
+
+ FullTextSession s = Search.getFullTextSession( openSession() );
+ Transaction tx = s.beginTransaction();
+ QueryParser parser = new QueryParser( "name", new StopAnalyzer() );
+ Query query = parser.parse( "Elephant" );
+
+ org.hibernate.Query hibQuery = s.createFullTextQuery( query, Mammal.class );
+ assertItsTheElephant( hibQuery.list() );
+
hibQuery = s.createFullTextQuery( query, Animal.class );
- result = hibQuery.list();
- assertNotNull( result );
- assertEquals( "Query on non @Indexed superclass property", 1, result.size() );
+ assertItsTheElephant( hibQuery.list() );
+ hibQuery = s.createFullTextQuery( query, Being.class );
+ assertItsTheElephant( hibQuery.list() );
+
+ hibQuery = s.createFullTextQuery( query, Object.class );
+ assertItsTheElephant( hibQuery.list() );
+
+ hibQuery = s.createFullTextQuery( query, Serializable.class );
+ assertItsTheElephant( hibQuery.list() );
+
+ hibQuery = s.createFullTextQuery( query, Mammal.class, Animal.class, Being.class, Object.class, Serializable.class );
+ assertItsTheElephant( hibQuery.list() );
+
tx.commit();
s.close();
}
+ private void assertItsTheElephant(List result) {
+ assertNotNull( result );
+ assertEquals( "Wrong number of results", 1, result.size() );
+ assertTrue( "Wrong result type", result.get( 0 ) instanceof Mammal );
+ Mammal mammal = ( Mammal ) result.get( 0 );
+ assertEquals( "Wrong animal name", "Elephant", mammal.getName() );
+ }
+
/**
* Tests that purging the index of a class also purges the index of the subclasses. See also HSEARCH-262.
*
@@ -72,10 +108,10 @@
Transaction tx = s.beginTransaction();
QueryParser parser = new QueryParser( "name", new StopAnalyzer() );
- Query query = parser.parse( "Jr" );
+ Query query = parser.parse( "Elephant OR White Pointer OR Chimpanzee" );
List result = s.createFullTextQuery( query, Animal.class ).list();
assertNotNull( result );
- assertEquals( "Wrong number of hits. There should be one elephant and one shark.", 2, result.size() );
+ assertEquals( "Wrong number of hits. There should be one elephant and one shark.", 3, result.size() );
s.purgeAll( Animal.class );
tx.commit();
@@ -87,38 +123,40 @@
);
tx.commit();
-
s.close();
}
private void createTestData() {
FullTextSession s = Search.getFullTextSession( openSession() );
Transaction tx = s.beginTransaction();
- Animal a = new Animal();
- a.setName( "Shark Jr" );
- s.save( a );
- Mammal m = new Mammal();
- m.setMammalNbr( 2 );
- m.setName( "Elephant Jr" );
- m.setWeight( 400 );
- s.save( m );
- tx.commit();//post commit events for lucene
- s.clear();
- }
- private void ensureIndexesAreEmpty() {
- FullTextSession s = Search.getFullTextSession( openSession() );
- Transaction tx;
- tx = s.beginTransaction();
- s.purgeAll( Animal.class );
- s.purgeAll( Mammal.class );
+ Fish shark = new Fish();
+ shark.setName( "White Pointer" );
+ shark.setNumberOfDorsalFins( 2 );
+ shark.setWeight( 1500 );
+ s.save( shark );
+
+ Mammal elephant = new Mammal();
+ elephant.setName( "Elephant" );
+ elephant.setHasSweatGlands( false );
+ elephant.setWeight( 4500 );
+ s.save( elephant );
+
+ Mammal chimp = new Mammal();
+ chimp.setName( "Chimpanzee" );
+ chimp.setHasSweatGlands( true );
+ chimp.setWeight( 50 );
+ s.save( chimp );
+
tx.commit();
+ s.clear();
}
protected Class[] getMappings() {
return new Class[] {
Animal.class,
- Mammal.class
+ Mammal.class,
+ Fish.class
};
}
}
Modified: search/trunk/src/test/org/hibernate/search/test/inheritance/Mammal.java
===================================================================
--- search/trunk/src/test/org/hibernate/search/test/inheritance/Mammal.java 2008-11-19 14:11:26 UTC (rev 15591)
+++ search/trunk/src/test/org/hibernate/search/test/inheritance/Mammal.java 2008-11-19 14:17:48 UTC (rev 15592)
@@ -1,6 +1,7 @@
//$Id$
package org.hibernate.search.test.inheritance;
+import java.io.Serializable;
import javax.persistence.Entity;
import org.hibernate.search.annotations.Field;
@@ -13,15 +14,15 @@
*/
@Entity
@Indexed
-public class Mammal extends Animal {
- private int mammalNbr;
+public class Mammal extends Animal implements Serializable {
+ private boolean hasSweatGlands;
@Field(index= Index.UN_TOKENIZED, store= Store.YES)
- public int getMammalNbr() {
- return mammalNbr;
- }
+ public boolean isHasSweatGlands() {
+ return hasSweatGlands;
+ }
- public void setMammalNbr(int mammalNbr) {
- this.mammalNbr = mammalNbr;
- }
+ public void setHasSweatGlands(boolean hasSweatGlands) {
+ this.hasSweatGlands = hasSweatGlands;
+ }
}
16 years
Hibernate SVN: r15591 - search/trunk/src/test/org/hibernate/search/test/indexingStrategy.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2008-11-19 09:11:26 -0500 (Wed, 19 Nov 2008)
New Revision: 15591
Modified:
search/trunk/src/test/org/hibernate/search/test/indexingStrategy/ManualIndexingStrategyTest.java
Log:
Formatting
Modified: search/trunk/src/test/org/hibernate/search/test/indexingStrategy/ManualIndexingStrategyTest.java
===================================================================
--- search/trunk/src/test/org/hibernate/search/test/indexingStrategy/ManualIndexingStrategyTest.java 2008-11-19 13:49:52 UTC (rev 15590)
+++ search/trunk/src/test/org/hibernate/search/test/indexingStrategy/ManualIndexingStrategyTest.java 2008-11-19 14:11:26 UTC (rev 15591)
@@ -2,6 +2,7 @@
package org.hibernate.search.test.indexingStrategy;
import org.apache.lucene.index.IndexReader;
+
import org.hibernate.Session;
import org.hibernate.cfg.Configuration;
import org.hibernate.search.test.AlternateDocument;
@@ -16,7 +17,6 @@
public void testMultipleEntitiesPerIndex() throws Exception {
-
Session s = getSessions().openSession();
s.getTransaction().begin();
Document document =
@@ -24,7 +24,12 @@
s.persist( document );
s.flush();
s.persist(
- new AlternateDocument( document.getId(), "Hibernate in Action", "Object/relational mapping with Hibernate", "blah blah blah" )
+ new AlternateDocument(
+ document.getId(),
+ "Hibernate in Action",
+ "Object/relational mapping with Hibernate",
+ "blah blah blah"
+ )
);
s.getTransaction().commit();
s.close();
16 years
Hibernate SVN: r15590 - in core/trunk/documentation/envers/src/main/docbook/en-US: content and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: adamw
Date: 2008-11-19 08:49:52 -0500 (Wed, 19 Nov 2008)
New Revision: 15590
Added:
core/trunk/documentation/envers/src/main/docbook/en-US/content/queries.xml
Modified:
core/trunk/documentation/envers/src/main/docbook/en-US/Envers_Reference.xml
core/trunk/documentation/envers/src/main/docbook/en-US/content/migration.xml
core/trunk/documentation/envers/src/main/docbook/en-US/content/source.xml
Log:
Adding the missing chapter on queries
Modified: core/trunk/documentation/envers/src/main/docbook/en-US/Envers_Reference.xml
===================================================================
--- core/trunk/documentation/envers/src/main/docbook/en-US/Envers_Reference.xml 2008-11-19 13:10:40 UTC (rev 15589)
+++ core/trunk/documentation/envers/src/main/docbook/en-US/Envers_Reference.xml 2008-11-19 13:49:52 UTC (rev 15590)
@@ -51,6 +51,7 @@
<xi:include href="content/example.xml" xmlns:xi="http://www.w3.org/2001/XInclude" />
<xi:include href="content/configuration.xml" xmlns:xi="http://www.w3.org/2001/XInclude" />
<xi:include href="content/revisionlog.xml" xmlns:xi="http://www.w3.org/2001/XInclude" />
+ <xi:include href="content/queries.xml" xmlns:xi="http://www.w3.org/2001/XInclude" />
<xi:include href="content/schema.xml" xmlns:xi="http://www.w3.org/2001/XInclude" />
<xi:include href="content/tables.xml" xmlns:xi="http://www.w3.org/2001/XInclude" />
<xi:include href="content/source.xml" xmlns:xi="http://www.w3.org/2001/XInclude" />
Modified: core/trunk/documentation/envers/src/main/docbook/en-US/content/migration.xml
===================================================================
--- core/trunk/documentation/envers/src/main/docbook/en-US/content/migration.xml 2008-11-19 13:10:40 UTC (rev 15589)
+++ core/trunk/documentation/envers/src/main/docbook/en-US/content/migration.xml 2008-11-19 13:49:52 UTC (rev 15590)
@@ -49,6 +49,11 @@
and so on.
</para>
+ <para>
+ Also, the query interface has changed slightly, mainly in the part for specifying restrictions,
+ projections and order. Please refer to the API for further details.
+ </para>
+
</sect1>
<sect1 id="migrations-configuration">
Copied: core/trunk/documentation/envers/src/main/docbook/en-US/content/queries.xml (from rev 15586, core/trunk/documentation/envers/src/main/docbook/en-US/content/example.xml)
===================================================================
--- core/trunk/documentation/envers/src/main/docbook/en-US/content/queries.xml (rev 0)
+++ core/trunk/documentation/envers/src/main/docbook/en-US/content/queries.xml 2008-11-19 13:49:52 UTC (rev 15590)
@@ -0,0 +1,203 @@
+<?xml version='1.0' encoding="UTF-8"?>
+<!--
+ ~ 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
+ -->
+
+<!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd">
+
+<chapter id="queries">
+
+ <title>Queries</title>
+
+ <para>
+ You can think of historic data as having two dimension. The first - horizontal -
+ is the state of the database at a given revision. Thus, you can
+ query for entities as they were at revision N. The second - vertical - are the
+ revisions, at which entities changed. Hence, you can query for revisions,
+ in which a given entity changed.
+ </para>
+
+ <para>
+ The queries in Envers are similar to
+ <ulink url="http://www.hibernate.org/hib_docs/v3/reference/en/html/querycriteria.html">Hibernate Criteria</ulink>,
+ so if you are common with them, using Envers queries will be much easier.
+ </para>
+
+ <para>
+ The main limitation of the current queries implementation is that you cannot
+ traverse relations. You can only specify constraints on the ids of the
+ related entities, and only on the "owning" side of the relation. This however
+ will be changed in future releases.
+ </para>
+
+ <para>
+ Please note, that queries on the audited data will be in many cases much slower
+ than corresponding queries on "live" data, as they involve correlated subselects.
+ </para>
+
+ <sect1 id="entities-at-revision">
+
+ <title>Querying for entities of a class at a given revision</title>
+
+ <para>
+ The entry point for this type of queries is:
+ </para>
+
+ <programlisting><![CDATA[AuditQuery query = getAuditReader().createQuery().forEntitiesAtRevision(MyEntity.class, revisionNumber);]]></programlisting>
+
+ <para>
+ You can then specify constraints, which should be met by the entities returned, by
+ adding restrictions, which can be obtained using the <literal>AuditEntity</literal>
+ factory class. For example, to select only entities, where the "name" property
+ is equal to "John":
+ </para>
+
+ <programlisting><![CDATA[query.add(AuditEntity.property("name").eq("John"));]]></programlisting>
+
+ <para>
+ And to select only entites that are related to a given entity:
+ </para>
+
+ <programlisting><![CDATA[query.add(AuditEntity.property("address").eq(relatedEntityInstance));
+// or
+query.add(AuditEntity.relatedId("address").eq(relatedEntityId));]]></programlisting>
+
+ <para>
+ You can limit the number of results, order them, and set aggregations and projections
+ (except grouping) in the usual way.
+ When your query is complete, you can obtain the results by calling the
+ <literal>getSingleResult()</literal> or <literal>getResultList()</literal> methods.
+ </para>
+
+ <para>
+ A full query, can look for example like this:
+ </para>
+
+ <programlisting><![CDATA[List personsAtAddress = getAuditReader().createQuery()
+ .forEntitiesAtRevision(Person.class, 12)
+ .addOrder(AuditEntity.property("surname").desc())
+ .add(AuditEntity.relatedId("address").eq(addressId))
+ .setFirstResult(4)
+ .setMaxResults(2)
+ .getResultList();]]></programlisting>
+
+ </sect1>
+
+ <sect1 id="revisions-of-entity">
+
+ <title>Querying for revisions, at which entities of a given class changed</title>
+
+ <para>
+ The entry point for this type of queries is:
+ </para>
+
+ <programlisting><![CDATA[AuditQuery query = getAuditReader().createQuery()
+ .forRevisionsOfEntity(MyEntity.class, false, true);]]></programlisting>
+
+ <para>
+ You can add constraints to this query in the same way as to the previous one.
+ There are some additional possibilities:
+ </para>
+
+ <orderedlist>
+ <listitem>
+ using <literal>AuditEntity.revisionNumber()</literal> you can specify constraints, projections
+ and order on the revision number, in which the audited entity was modified
+ </listitem>
+ <listitem>
+ similarly, using <literal>AuditEntity.revisionProperty(propertyName)</literal> you can specify constraints,
+ projections and order on a property of the revision entity, corresponding to the revision
+ in which the audited entity was modified
+ </listitem>
+ <listitem>
+ <literal>AuditEntity.revisionType()</literal> gives you access as above to the type of
+ the revision (ADD, MOD, DEL).
+ </listitem>
+ </orderedlist>
+
+ <para>
+ Using these methods,
+ you can order the query results by revision number, set projection or constraint
+ the revision number to be greater or less than a specified value, etc. For example, the
+ following query will select the smallest revision number, at which entity of class
+ <literal>MyEntity</literal> with id <literal>entityId</literal> has changed, after revision
+ number 42:
+ </para>
+
+ <programlisting><![CDATA[Number revision = (Number) getAuditReader().createQuery()
+ .forRevisionsOfEntity(MyEntity.class, false, true)
+ .setProjection(AuditEntity.revisionNumber().min())
+ .add(AuditEntity.id().eq(entityId))
+ .add(AuditEntity.revisionNumber().gt(42))
+ .getSingleResult();]]></programlisting>
+
+ <para>
+ The second additional feature you can use in queries for revisions is the ability
+ to maximalize/minimize a property. For example, if you want to select the
+ revision, at which the value of the <literal>actualDate</literal> for a given entity
+ was larger then a given value, but as small as possible:
+ </para>
+
+ <programlisting><![CDATA[Number revision = (Number) getAuditReader().createQuery()
+ .forRevisionsOfEntity(MyEntity.class, false, true)
+ // We are only interested in the first revision
+ .setProjection(AuditEntity.revisionNumber().min())
+ .add(AuditEntity.property("actualDate").minimize()
+ .add(AuditEntity.property("actualDate").ge(givenDate))
+ .add(AuditEntity.id().eq(givenEntityId)))
+ .getSingleResult();
+]]></programlisting>
+
+ <para>
+ The <literal>minimize()</literal> and <literal>maximize()</literal> methods return a criteria,
+ to which you can add constraints, which must be met by the entities with the
+ maximized/minimized properties.
+ </para>
+
+ <para>
+ You probably also noticed that there are two boolean parameters, passed when
+ creating the query. The first one, <literal>selectEntitiesOnly</literal>, is only valid when
+ you don't set an explicit projection. If true, the result of the query will be
+ a list of entities (which changed at revisions satisfying the specified
+ constraints).
+ </para>
+
+ <para>
+ If false, the result will be a list of three element arrays. The
+ first element will be the changed entity instance. The second will be an entity
+ containing revision data (if no custom entity is used, this will be an instance
+ of <literal>DefaultRevisionEntity</literal>). The third will be the type of the
+ revision (one of the values of the <literal>RevisionType</literal> enumeration:
+ ADD, MOD, DEL).
+ </para>
+
+ <para>
+ The second parameter, <literal>selectDeletedEntities</literal>, specifies if revisions,
+ in which the entity was deleted should be included in the results. If yes, such entities
+ will have the revision type DEL and all fields, except the id,
+ <literal>null</literal>.
+ </para>
+
+ </sect1>
+
+</chapter>
\ No newline at end of file
Property changes on: core/trunk/documentation/envers/src/main/docbook/en-US/content/queries.xml
___________________________________________________________________
Name: svn:mergeinfo
+
Modified: core/trunk/documentation/envers/src/main/docbook/en-US/content/source.xml
===================================================================
--- core/trunk/documentation/envers/src/main/docbook/en-US/content/source.xml 2008-11-19 13:10:40 UTC (rev 15589)
+++ core/trunk/documentation/envers/src/main/docbook/en-US/content/source.xml 2008-11-19 13:49:52 UTC (rev 15590)
@@ -68,9 +68,5 @@
data is correct (the testHistoryOfXxx methods).
</para>
- <para>
- The results of the tests can be found in the "doc/report" directory.
- </para>
-
</chapter>
16 years
Hibernate SVN: r15589 - in core/trunk/envers/src: main/java/org/hibernate/envers/configuration/metadata and 12 other directories.
by hibernate-commits@lists.jboss.org
Author: adamw
Date: 2008-11-19 08:10:40 -0500 (Wed, 19 Nov 2008)
New Revision: 15589
Added:
core/trunk/envers/src/main/java/org/hibernate/envers/query/AuditEntity.java
core/trunk/envers/src/main/java/org/hibernate/envers/query/criteria/AggregatedAuditExpression.java
core/trunk/envers/src/main/java/org/hibernate/envers/query/criteria/AuditId.java
core/trunk/envers/src/main/java/org/hibernate/envers/query/criteria/AuditProperty.java
core/trunk/envers/src/main/java/org/hibernate/envers/query/criteria/AuditRelatedId.java
core/trunk/envers/src/main/java/org/hibernate/envers/query/order/PropertyAuditOrder.java
core/trunk/envers/src/main/java/org/hibernate/envers/query/projection/PropertyAuditProjection.java
core/trunk/envers/src/main/java/org/hibernate/envers/query/property/
core/trunk/envers/src/main/java/org/hibernate/envers/query/property/EntityPropertyName.java
core/trunk/envers/src/main/java/org/hibernate/envers/query/property/OriginalIdPropertyName.java
core/trunk/envers/src/main/java/org/hibernate/envers/query/property/PropertyNameGetter.java
core/trunk/envers/src/main/java/org/hibernate/envers/query/property/RevisionNumberPropertyName.java
core/trunk/envers/src/main/java/org/hibernate/envers/query/property/RevisionPropertyPropertyName.java
core/trunk/envers/src/main/java/org/hibernate/envers/query/property/RevisionTypePropertyName.java
Removed:
core/trunk/envers/src/main/java/org/hibernate/envers/query/RevisionProperty.java
core/trunk/envers/src/main/java/org/hibernate/envers/query/RevisionTypeProperty.java
core/trunk/envers/src/main/java/org/hibernate/envers/query/criteria/AggregatedFieldAuditExpression.java
core/trunk/envers/src/main/java/org/hibernate/envers/query/criteria/RevisionAuditExpression.java
core/trunk/envers/src/main/java/org/hibernate/envers/query/order/RevisionAuditOrder.java
core/trunk/envers/src/main/java/org/hibernate/envers/query/projection/RevisionAuditProjection.java
Modified:
core/trunk/envers/src/main/java/org/hibernate/envers/configuration/AuditEntitiesConfiguration.java
core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata/AuditMetadataGenerator.java
core/trunk/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/OneToOneNotOwningMapper.java
core/trunk/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/query/OneAuditEntityQueryGenerator.java
core/trunk/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/query/OneEntityQueryGenerator.java
core/trunk/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/query/ThreeEntityQueryGenerator.java
core/trunk/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/query/TwoEntityQueryGenerator.java
core/trunk/envers/src/main/java/org/hibernate/envers/query/AuditQuery.java
core/trunk/envers/src/main/java/org/hibernate/envers/query/criteria/AuditCriterion.java
core/trunk/envers/src/main/java/org/hibernate/envers/query/criteria/BetweenAuditExpression.java
core/trunk/envers/src/main/java/org/hibernate/envers/query/criteria/IdentifierEqAuditExpression.java
core/trunk/envers/src/main/java/org/hibernate/envers/query/criteria/InAuditExpression.java
core/trunk/envers/src/main/java/org/hibernate/envers/query/criteria/NotNullAuditExpression.java
core/trunk/envers/src/main/java/org/hibernate/envers/query/criteria/NullAuditExpression.java
core/trunk/envers/src/main/java/org/hibernate/envers/query/criteria/PropertyAuditExpression.java
core/trunk/envers/src/main/java/org/hibernate/envers/query/criteria/RelatedAuditExpression.java
core/trunk/envers/src/main/java/org/hibernate/envers/query/criteria/SimpleAuditExpression.java
core/trunk/envers/src/main/java/org/hibernate/envers/query/impl/AbstractAuditQuery.java
core/trunk/envers/src/main/java/org/hibernate/envers/query/impl/EntitiesAtRevisionQuery.java
core/trunk/envers/src/main/java/org/hibernate/envers/query/impl/RevisionsOfEntityQuery.java
core/trunk/envers/src/main/java/org/hibernate/envers/query/order/AuditOrder.java
core/trunk/envers/src/main/java/org/hibernate/envers/query/projection/AuditProjection.java
core/trunk/envers/src/main/java/org/hibernate/envers/reader/AuditReaderImpl.java
core/trunk/envers/src/main/java/org/hibernate/envers/synchronization/work/AbstractAuditWorkUnit.java
core/trunk/envers/src/main/java/org/hibernate/envers/synchronization/work/PersistentCollectionChangeWorkUnit.java
core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/query/AggregateQuery.java
core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/query/CustomRevEntityQuery.java
core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/query/DeletedEntities.java
core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/query/MaximalizePropertyQuery.java
core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/query/OrderByLimitQuery.java
core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/query/RevisionConstraintQuery.java
core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/query/SimpleQuery.java
core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/query/ids/EmbIdOneToManyQuery.java
core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/query/ids/MulIdOneToManyQuery.java
Log:
HHH-3611: improved query interface
Modified: core/trunk/envers/src/main/java/org/hibernate/envers/configuration/AuditEntitiesConfiguration.java
===================================================================
--- core/trunk/envers/src/main/java/org/hibernate/envers/configuration/AuditEntitiesConfiguration.java 2008-11-19 08:18:58 UTC (rev 15588)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/configuration/AuditEntitiesConfiguration.java 2008-11-19 13:10:40 UTC (rev 15589)
@@ -37,8 +37,9 @@
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,28 +56,37 @@
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() {
return revisionTypePropName;
}
Modified: core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata/AuditMetadataGenerator.java
===================================================================
--- core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata/AuditMetadataGenerator.java 2008-11-19 08:18:58 UTC (rev 15588)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata/AuditMetadataGenerator.java 2008-11-19 13:10:40 UTC (rev 15589)
@@ -88,8 +88,8 @@
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 @@
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 @@
// 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:
Modified: core/trunk/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/OneToOneNotOwningMapper.java
===================================================================
--- core/trunk/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/OneToOneNotOwningMapper.java 2008-11-19 08:18:58 UTC (rev 15588)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/OneToOneNotOwningMapper.java 2008-11-19 13:10:40 UTC (rev 15589)
@@ -33,7 +33,7 @@
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 @@
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) {
Modified: core/trunk/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/query/OneAuditEntityQueryGenerator.java
===================================================================
--- core/trunk/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/query/OneAuditEntityQueryGenerator.java 2008-11-19 08:18:58 UTC (rev 15588)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/query/OneAuditEntityQueryGenerator.java 2008-11-19 13:10:40 UTC (rev 15589)
@@ -62,7 +62,7 @@
* (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);
Modified: core/trunk/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/query/OneEntityQueryGenerator.java
===================================================================
--- core/trunk/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/query/OneEntityQueryGenerator.java 2008-11-19 08:18:58 UTC (rev 15588)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/query/OneEntityQueryGenerator.java 2008-11-19 13:10:40 UTC (rev 15589)
@@ -61,7 +61,7 @@
* (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
Modified: core/trunk/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/query/ThreeEntityQueryGenerator.java
===================================================================
--- core/trunk/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/query/ThreeEntityQueryGenerator.java 2008-11-19 08:18:58 UTC (rev 15588)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/query/ThreeEntityQueryGenerator.java 2008-11-19 13:10:40 UTC (rev 15589)
@@ -78,7 +78,7 @@
* 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;
Modified: core/trunk/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/query/TwoEntityQueryGenerator.java
===================================================================
--- core/trunk/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/query/TwoEntityQueryGenerator.java 2008-11-19 08:18:58 UTC (rev 15588)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/query/TwoEntityQueryGenerator.java 2008-11-19 13:10:40 UTC (rev 15589)
@@ -71,7 +71,7 @@
* 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;
Copied: core/trunk/envers/src/main/java/org/hibernate/envers/query/AuditEntity.java (from rev 15586, core/trunk/envers/src/main/java/org/hibernate/envers/query/AuditRestrictions.java)
===================================================================
--- core/trunk/envers/src/main/java/org/hibernate/envers/query/AuditEntity.java (rev 0)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/query/AuditEntity.java 2008-11-19 13:10:40 UTC (rev 15589)
@@ -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();
+ }
+}
Modified: core/trunk/envers/src/main/java/org/hibernate/envers/query/AuditQuery.java
===================================================================
--- core/trunk/envers/src/main/java/org/hibernate/envers/query/AuditQuery.java 2008-11-19 08:18:58 UTC (rev 15588)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/query/AuditQuery.java 2008-11-19 13:10:40 UTC (rev 15589)
@@ -47,12 +47,8 @@
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);
Deleted: core/trunk/envers/src/main/java/org/hibernate/envers/query/RevisionProperty.java
===================================================================
--- core/trunk/envers/src/main/java/org/hibernate/envers/query/RevisionProperty.java 2008-11-19 08:18:58 UTC (rev 15588)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/query/RevisionProperty.java 2008-11-19 13:10:40 UTC (rev 15589)
@@ -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);
- }
-}
Deleted: core/trunk/envers/src/main/java/org/hibernate/envers/query/RevisionTypeProperty.java
===================================================================
--- core/trunk/envers/src/main/java/org/hibernate/envers/query/RevisionTypeProperty.java 2008-11-19 08:18:58 UTC (rev 15588)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/query/RevisionTypeProperty.java 2008-11-19 13:10:40 UTC (rev 15589)
@@ -1,64 +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.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;
-
-/**
- * @author Adam Warski (adam at warski dot org)
- */
-@SuppressWarnings({"JavaDoc"})
-public class RevisionTypeProperty implements AuditProjection {
- private RevisionTypeProperty() { }
-
- /**
- * Apply a "equal" constraint on the revision type
- */
- public static AuditCriterion eq(RevisionType type) {
- return new RevisionTypeAuditExpression(type, "=");
- }
-
- /**
- * Apply a "not equal" constraint on the revision type
- */
- 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);
- }
-}
\ No newline at end of file
Copied: core/trunk/envers/src/main/java/org/hibernate/envers/query/criteria/AggregatedAuditExpression.java (from rev 15586, core/trunk/envers/src/main/java/org/hibernate/envers/query/criteria/AggregatedFieldAuditExpression.java)
===================================================================
--- core/trunk/envers/src/main/java/org/hibernate/envers/query/criteria/AggregatedAuditExpression.java (rev 0)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/query/criteria/AggregatedAuditExpression.java 2008-11-19 13:10:40 UTC (rev 15589)
@@ -0,0 +1,85 @@
+/*
+ * 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.configuration.AuditConfiguration;
+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 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
+ }
+
+ public AggregatedAuditExpression add(AuditCriterion criterion) {
+ criterions.add(criterion);
+ return this;
+ }
+
+ 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();
+
+ // Adding all specified conditions both to the main query, as well as to the
+ // aggregated one.
+ for (AuditCriterion versionsCriteria : criterions) {
+ versionsCriteria.addToQuery(auditCfg, entityName, qb, parameters);
+ versionsCriteria.addToQuery(auditCfg, entityName, subQb, subQb.getRootParameters());
+ }
+
+ // Setting the desired projection of the aggregated query
+ switch (mode) {
+ case MIN:
+ subQb.addProjection("min", propertyName, false);
+ break;
+ case MAX:
+ subQb.addProjection("max", propertyName, false);
+ }
+
+ // Adding the constrain on the result of the aggregated criteria
+ parameters.addWhere(propertyName, "=", subQb);
+ }
+}
\ No newline at end of file
Deleted: core/trunk/envers/src/main/java/org/hibernate/envers/query/criteria/AggregatedFieldAuditExpression.java
===================================================================
--- core/trunk/envers/src/main/java/org/hibernate/envers/query/criteria/AggregatedFieldAuditExpression.java 2008-11-19 08:18:58 UTC (rev 15588)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/query/criteria/AggregatedFieldAuditExpression.java 2008-11-19 13:10:40 UTC (rev 15589)
@@ -1,82 +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.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.tools.query.QueryBuilder;
-
-/**
- * @author Adam Warski (adam at warski dot org)
- */
-public class AggregatedFieldAuditExpression implements AuditCriterion, ExtendableCriterion {
- 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) {
- criterions.add(criterion);
- return this;
- }
-
- public void addToQuery(AuditConfiguration verCfg, String entityName, QueryBuilder qb, Parameters parameters) {
- CriteriaTools.checkPropertyNotARelation(verCfg, entityName, propertyName);
-
- // This will be the aggregated query, containing all the specified conditions
- QueryBuilder subQb = qb.newSubQueryBuilder();
-
- // 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());
- }
-
- // Setting the desired projection of the aggregated query
- switch (mode) {
- case MIN:
- subQb.addProjection("min", propertyName, false);
- break;
- case MAX:
- subQb.addProjection("max", propertyName, false);
- }
-
- // Adding the constrain on the result of the aggregated criteria
- parameters.addWhere(propertyName, "=", subQb);
- }
-}
\ No newline at end of file
Modified: core/trunk/envers/src/main/java/org/hibernate/envers/query/criteria/AuditCriterion.java
===================================================================
--- core/trunk/envers/src/main/java/org/hibernate/envers/query/criteria/AuditCriterion.java 2008-11-19 08:18:58 UTC (rev 15588)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/query/criteria/AuditCriterion.java 2008-11-19 13:10:40 UTC (rev 15589)
@@ -31,5 +31,5 @@
* @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);
}
Added: core/trunk/envers/src/main/java/org/hibernate/envers/query/criteria/AuditId.java
===================================================================
--- core/trunk/envers/src/main/java/org/hibernate/envers/query/criteria/AuditId.java (rev 0)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/query/criteria/AuditId.java 2008-11-19 13:10:40 UTC (rev 15589)
@@ -0,0 +1,61 @@
+/*
+ * 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.projection.AuditProjection;
+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 AuditId {
+ /**
+ * Apply an "equal" constraint
+ */
+ public AuditCriterion eq(Object id) {
+ return new IdentifierEqAuditExpression(id, true);
+ }
+
+ /**
+ * Apply a "not equal" constraint
+ */
+ public AuditCriterion ne(Object id) {
+ return new IdentifierEqAuditExpression(id, false);
+ }
+
+ // Projections
+
+ /**
+ * Projection counting the values
+ * TODO: idPropertyName isn't needed, should be read from the configuration
+ * @param idPropertyName Name of the identifier property
+ */
+ public AuditProjection count(String idPropertyName) {
+ return new PropertyAuditProjection(new OriginalIdPropertyName(idPropertyName), "count", false);
+ }
+}
\ No newline at end of file
Added: core/trunk/envers/src/main/java/org/hibernate/envers/query/criteria/AuditProperty.java
===================================================================
--- core/trunk/envers/src/main/java/org/hibernate/envers/query/criteria/AuditProperty.java (rev 0)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/query/criteria/AuditProperty.java 2008-11-19 13:10:40 UTC (rev 15589)
@@ -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);
+ }
+}
Added: core/trunk/envers/src/main/java/org/hibernate/envers/query/criteria/AuditRelatedId.java
===================================================================
--- core/trunk/envers/src/main/java/org/hibernate/envers/query/criteria/AuditRelatedId.java (rev 0)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/query/criteria/AuditRelatedId.java 2008-11-19 13:10:40 UTC (rev 15589)
@@ -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);
+ }
+}
\ No newline at end of file
Modified: core/trunk/envers/src/main/java/org/hibernate/envers/query/criteria/BetweenAuditExpression.java
===================================================================
--- core/trunk/envers/src/main/java/org/hibernate/envers/query/criteria/BetweenAuditExpression.java 2008-11-19 08:18:58 UTC (rev 15588)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/query/criteria/BetweenAuditExpression.java 2008-11-19 13:10:40 UTC (rev 15589)
@@ -26,23 +26,25 @@
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);
}
Modified: core/trunk/envers/src/main/java/org/hibernate/envers/query/criteria/IdentifierEqAuditExpression.java
===================================================================
--- core/trunk/envers/src/main/java/org/hibernate/envers/query/criteria/IdentifierEqAuditExpression.java 2008-11-19 08:18:58 UTC (rev 15588)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/query/criteria/IdentifierEqAuditExpression.java 2008-11-19 13:10:40 UTC (rev 15589)
@@ -28,17 +28,20 @@
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);
}
}
Modified: core/trunk/envers/src/main/java/org/hibernate/envers/query/criteria/InAuditExpression.java
===================================================================
--- core/trunk/envers/src/main/java/org/hibernate/envers/query/criteria/InAuditExpression.java 2008-11-19 08:18:58 UTC (rev 15588)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/query/criteria/InAuditExpression.java 2008-11-19 13:10:40 UTC (rev 15589)
@@ -26,21 +26,23 @@
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, ")");
}
}
Modified: core/trunk/envers/src/main/java/org/hibernate/envers/query/criteria/NotNullAuditExpression.java
===================================================================
--- core/trunk/envers/src/main/java/org/hibernate/envers/query/criteria/NotNullAuditExpression.java 2008-11-19 08:18:58 UTC (rev 15588)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/query/criteria/NotNullAuditExpression.java 2008-11-19 13:10:40 UTC (rev 15589)
@@ -27,19 +27,21 @@
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);
Modified: core/trunk/envers/src/main/java/org/hibernate/envers/query/criteria/NullAuditExpression.java
===================================================================
--- core/trunk/envers/src/main/java/org/hibernate/envers/query/criteria/NullAuditExpression.java 2008-11-19 08:18:58 UTC (rev 15588)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/query/criteria/NullAuditExpression.java 2008-11-19 13:10:40 UTC (rev 15589)
@@ -27,19 +27,21 @@
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);
Modified: core/trunk/envers/src/main/java/org/hibernate/envers/query/criteria/PropertyAuditExpression.java
===================================================================
--- core/trunk/envers/src/main/java/org/hibernate/envers/query/criteria/PropertyAuditExpression.java 2008-11-19 08:18:58 UTC (rev 15588)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/query/criteria/PropertyAuditExpression.java 2008-11-19 13:10:40 UTC (rev 15589)
@@ -26,24 +26,26 @@
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);
}
}
Modified: core/trunk/envers/src/main/java/org/hibernate/envers/query/criteria/RelatedAuditExpression.java
===================================================================
--- core/trunk/envers/src/main/java/org/hibernate/envers/query/criteria/RelatedAuditExpression.java 2008-11-19 08:18:58 UTC (rev 15588)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/query/criteria/RelatedAuditExpression.java 2008-11-19 13:10:40 UTC (rev 15589)
@@ -28,23 +28,26 @@
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 " +
Deleted: core/trunk/envers/src/main/java/org/hibernate/envers/query/criteria/RevisionAuditExpression.java
===================================================================
--- core/trunk/envers/src/main/java/org/hibernate/envers/query/criteria/RevisionAuditExpression.java 2008-11-19 08:18:58 UTC (rev 15588)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/query/criteria/RevisionAuditExpression.java 2008-11-19 13:10:40 UTC (rev 15589)
@@ -1,45 +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.criteria;
-
-import org.hibernate.envers.configuration.AuditConfiguration;
-import org.hibernate.envers.tools.query.Parameters;
-import org.hibernate.envers.tools.query.QueryBuilder;
-
-/**
- * @author Adam Warski (adam at warski dot org)
- */
-public class RevisionAuditExpression implements AuditCriterion {
- private Object value;
- private String op;
-
- public RevisionAuditExpression(Object value, String op) {
- this.value = value;
- this.op = op;
- }
-
- public void addToQuery(AuditConfiguration verCfg, String entityName, QueryBuilder qb, Parameters parameters) {
- parameters.addWhereWithParam(verCfg.getAuditEntCfg().getRevisionPropPath(), op, value);
- }
-}
\ No newline at end of file
Modified: core/trunk/envers/src/main/java/org/hibernate/envers/query/criteria/SimpleAuditExpression.java
===================================================================
--- core/trunk/envers/src/main/java/org/hibernate/envers/query/criteria/SimpleAuditExpression.java 2008-11-19 08:18:58 UTC (rev 15588)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/query/criteria/SimpleAuditExpression.java 2008-11-19 13:10:40 UTC (rev 15589)
@@ -28,24 +28,27 @@
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);
} else {
Modified: core/trunk/envers/src/main/java/org/hibernate/envers/query/impl/AbstractAuditQuery.java
===================================================================
--- core/trunk/envers/src/main/java/org/hibernate/envers/query/impl/AbstractAuditQuery.java 2008-11-19 08:18:58 UTC (rev 15588)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/query/impl/AbstractAuditQuery.java 2008-11-19 13:10:40 UTC (rev 15589)
@@ -121,12 +121,6 @@
// 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 @@
return this;
}
- public AuditQuery addOrder(String propertyName, boolean asc) {
+ public AuditQuery addOrder(AuditOrder order) {
hasOrder = true;
- qb.addOrder(propertyName, asc);
- return this;
- }
- public AuditQuery addOrder(AuditOrder order) {
Pair<String, Boolean> orderData = order.getData(verCfg);
- return addOrder(orderData.getFirst(), orderData.getSecond());
+ qb.addOrder(orderData.getFirst(), orderData.getSecond());
+ return this;
}
// Query properties
Modified: core/trunk/envers/src/main/java/org/hibernate/envers/query/impl/EntitiesAtRevisionQuery.java
===================================================================
--- core/trunk/envers/src/main/java/org/hibernate/envers/query/impl/EntitiesAtRevisionQuery.java 2008-11-19 08:18:58 UTC (rev 15588)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/query/impl/EntitiesAtRevisionQuery.java 2008-11-19 13:10:40 UTC (rev 15589)
@@ -61,7 +61,7 @@
AuditEntitiesConfiguration verEntCfg = verCfg.getAuditEntCfg();
- String revisionPropertyPath = verEntCfg.getRevisionPropPath();
+ String revisionPropertyPath = verEntCfg.getRevisionNumberPath();
String originalIdPropertyName = verEntCfg.getOriginalIdPropName();
// SELECT max(e2.revision)
Modified: core/trunk/envers/src/main/java/org/hibernate/envers/query/impl/RevisionsOfEntityQuery.java
===================================================================
--- core/trunk/envers/src/main/java/org/hibernate/envers/query/impl/RevisionsOfEntityQuery.java 2008-11-19 08:18:58 UTC (rev 15588)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/query/impl/RevisionsOfEntityQuery.java 2008-11-19 13:10:40 UTC (rev 15589)
@@ -57,7 +57,7 @@
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 @@
}
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();
Modified: core/trunk/envers/src/main/java/org/hibernate/envers/query/order/AuditOrder.java
===================================================================
--- core/trunk/envers/src/main/java/org/hibernate/envers/query/order/AuditOrder.java 2008-11-19 08:18:58 UTC (rev 15588)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/query/order/AuditOrder.java 2008-11-19 13:10:40 UTC (rev 15589)
@@ -31,8 +31,8 @@
*/
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);
}
Copied: core/trunk/envers/src/main/java/org/hibernate/envers/query/order/PropertyAuditOrder.java (from rev 15586, core/trunk/envers/src/main/java/org/hibernate/envers/query/order/RevisionAuditOrder.java)
===================================================================
--- core/trunk/envers/src/main/java/org/hibernate/envers/query/order/PropertyAuditOrder.java (rev 0)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/query/order/PropertyAuditOrder.java 2008-11-19 13:10:40 UTC (rev 15589)
@@ -0,0 +1,46 @@
+/*
+ * 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.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 PropertyAuditOrder implements AuditOrder {
+ private final PropertyNameGetter propertyNameGetter;
+ private final boolean asc;
+
+ public PropertyAuditOrder(PropertyNameGetter propertyNameGetter, boolean asc) {
+ this.propertyNameGetter = propertyNameGetter;
+ this.asc = asc;
+ }
+
+ public Pair<String, Boolean> getData(AuditConfiguration auditCfg) {
+ return Pair.make(propertyNameGetter.get(auditCfg), asc);
+ }
+}
\ No newline at end of file
Property changes on: core/trunk/envers/src/main/java/org/hibernate/envers/query/order/PropertyAuditOrder.java
___________________________________________________________________
Name: svn:mergeinfo
+
Deleted: core/trunk/envers/src/main/java/org/hibernate/envers/query/order/RevisionAuditOrder.java
===================================================================
--- core/trunk/envers/src/main/java/org/hibernate/envers/query/order/RevisionAuditOrder.java 2008-11-19 08:18:58 UTC (rev 15588)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/query/order/RevisionAuditOrder.java 2008-11-19 13:10:40 UTC (rev 15589)
@@ -1,43 +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.order;
-
-import org.hibernate.envers.configuration.AuditConfiguration;
-import org.hibernate.envers.tools.Pair;
-
-/**
- * @author Adam Warski (adam at warski dot org)
- */
-public class RevisionAuditOrder implements AuditOrder {
- private final boolean asc;
-
- public RevisionAuditOrder(boolean asc) {
- this.asc = asc;
- }
-
- public Pair<String, Boolean> getData(AuditConfiguration verCfg) {
- String revisionPropPath = verCfg.getAuditEntCfg().getRevisionPropPath();
- return Pair.make(revisionPropPath, asc);
- }
-}
Modified: core/trunk/envers/src/main/java/org/hibernate/envers/query/projection/AuditProjection.java
===================================================================
--- core/trunk/envers/src/main/java/org/hibernate/envers/query/projection/AuditProjection.java 2008-11-19 08:18:58 UTC (rev 15588)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/query/projection/AuditProjection.java 2008-11-19 13:10:40 UTC (rev 15589)
@@ -31,9 +31,8 @@
*/
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);
}
Copied: core/trunk/envers/src/main/java/org/hibernate/envers/query/projection/PropertyAuditProjection.java (from rev 15586, core/trunk/envers/src/main/java/org/hibernate/envers/query/projection/RevisionAuditProjection.java)
===================================================================
--- core/trunk/envers/src/main/java/org/hibernate/envers/query/projection/PropertyAuditProjection.java (rev 0)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/query/projection/PropertyAuditProjection.java 2008-11-19 13:10:40 UTC (rev 15589)
@@ -0,0 +1,50 @@
+/*
+ * 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.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 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;
+ }
+
+ public Triple<String, String, Boolean> getData(AuditConfiguration auditCfg) {
+ String propertyName = propertyNameGetter.get(auditCfg);
+
+ return Triple.make(function, propertyName, distinct);
+ }
+}
\ No newline at end of file
Property changes on: core/trunk/envers/src/main/java/org/hibernate/envers/query/projection/PropertyAuditProjection.java
___________________________________________________________________
Name: svn:mergeinfo
+
Deleted: core/trunk/envers/src/main/java/org/hibernate/envers/query/projection/RevisionAuditProjection.java
===================================================================
--- core/trunk/envers/src/main/java/org/hibernate/envers/query/projection/RevisionAuditProjection.java 2008-11-19 08:18:58 UTC (rev 15588)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/query/projection/RevisionAuditProjection.java 2008-11-19 13:10:40 UTC (rev 15589)
@@ -1,60 +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.projection;
-
-import org.hibernate.envers.configuration.AuditConfiguration;
-import org.hibernate.envers.tools.Triple;
-
-/**
- * @author Adam Warski (adam at warski dot org)
- */
-public class RevisionAuditProjection implements AuditProjection {
- public static enum ProjectionType {
- MAX,
- MIN,
- COUNT,
- COUNT_DISTINCT,
- DISTINCT
- }
-
- private final ProjectionType type;
-
- public RevisionAuditProjection(ProjectionType type) {
- this.type = type;
- }
-
- 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 + ".");
- }
-}
Added: core/trunk/envers/src/main/java/org/hibernate/envers/query/property/EntityPropertyName.java
===================================================================
--- core/trunk/envers/src/main/java/org/hibernate/envers/query/property/EntityPropertyName.java (rev 0)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/query/property/EntityPropertyName.java 2008-11-19 13:10:40 UTC (rev 15589)
@@ -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;
+ }
+}
Added: core/trunk/envers/src/main/java/org/hibernate/envers/query/property/OriginalIdPropertyName.java
===================================================================
--- core/trunk/envers/src/main/java/org/hibernate/envers/query/property/OriginalIdPropertyName.java (rev 0)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/query/property/OriginalIdPropertyName.java 2008-11-19 13:10:40 UTC (rev 15589)
@@ -0,0 +1,44 @@
+/*
+ * 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 identifier.
+ * TODO: idPropertyName should be read basing on auditCfg + entityName
+ * @author Adam Warski (adam at warski dot org)
+ */
+public class OriginalIdPropertyName implements PropertyNameGetter {
+ private final String idPropertyName;
+
+ public OriginalIdPropertyName(String idPropertyName) {
+ this.idPropertyName = idPropertyName;
+ }
+
+ public String get(AuditConfiguration auditCfg) {
+ return auditCfg.getAuditEntCfg().getOriginalIdPropName() + "." + idPropertyName;
+ }
+}
\ No newline at end of file
Added: core/trunk/envers/src/main/java/org/hibernate/envers/query/property/PropertyNameGetter.java
===================================================================
--- core/trunk/envers/src/main/java/org/hibernate/envers/query/property/PropertyNameGetter.java (rev 0)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/query/property/PropertyNameGetter.java 2008-11-19 13:10:40 UTC (rev 15589)
@@ -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);
+}
Added: core/trunk/envers/src/main/java/org/hibernate/envers/query/property/RevisionNumberPropertyName.java
===================================================================
--- core/trunk/envers/src/main/java/org/hibernate/envers/query/property/RevisionNumberPropertyName.java (rev 0)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/query/property/RevisionNumberPropertyName.java 2008-11-19 13:10:40 UTC (rev 15589)
@@ -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();
+ }
+}
\ No newline at end of file
Added: core/trunk/envers/src/main/java/org/hibernate/envers/query/property/RevisionPropertyPropertyName.java
===================================================================
--- core/trunk/envers/src/main/java/org/hibernate/envers/query/property/RevisionPropertyPropertyName.java (rev 0)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/query/property/RevisionPropertyPropertyName.java 2008-11-19 13:10:40 UTC (rev 15589)
@@ -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);
+ }
+}
\ No newline at end of file
Added: core/trunk/envers/src/main/java/org/hibernate/envers/query/property/RevisionTypePropertyName.java
===================================================================
--- core/trunk/envers/src/main/java/org/hibernate/envers/query/property/RevisionTypePropertyName.java (rev 0)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/query/property/RevisionTypePropertyName.java 2008-11-19 13:10:40 UTC (rev 15589)
@@ -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();
+ }
+}
\ No newline at end of file
Modified: core/trunk/envers/src/main/java/org/hibernate/envers/reader/AuditReaderImpl.java
===================================================================
--- core/trunk/envers/src/main/java/org/hibernate/envers/reader/AuditReaderImpl.java 2008-11-19 08:18:58 UTC (rev 15588)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/reader/AuditReaderImpl.java 2008-11-19 13:10:40 UTC (rev 15589)
@@ -31,8 +31,7 @@
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 @@
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 @@
}
return createQuery().forRevisionsOfEntity(cls, false, true)
- .addProjection(RevisionProperty.revisionNumber())
- .add(AuditRestrictions.idEq(primaryKey))
+ .addProjection(AuditEntity.revisionNumber())
+ .add(AuditEntity.id().eq(primaryKey))
.getResultList();
}
Modified: core/trunk/envers/src/main/java/org/hibernate/envers/synchronization/work/AbstractAuditWorkUnit.java
===================================================================
--- core/trunk/envers/src/main/java/org/hibernate/envers/synchronization/work/AbstractAuditWorkUnit.java 2008-11-19 08:18:58 UTC (rev 15588)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/synchronization/work/AbstractAuditWorkUnit.java 2008-11-19 13:10:40 UTC (rev 15589)
@@ -54,7 +54,7 @@
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);
Modified: core/trunk/envers/src/main/java/org/hibernate/envers/synchronization/work/PersistentCollectionChangeWorkUnit.java
===================================================================
--- core/trunk/envers/src/main/java/org/hibernate/envers/synchronization/work/PersistentCollectionChangeWorkUnit.java 2008-11-19 08:18:58 UTC (rev 15588)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/synchronization/work/PersistentCollectionChangeWorkUnit.java 2008-11-19 13:10:40 UTC (rev 15589)
@@ -63,7 +63,7 @@
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());
}
Modified: core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/query/AggregateQuery.java
===================================================================
--- core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/query/AggregateQuery.java 2008-11-19 08:18:58 UTC (rev 15588)
+++ core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/query/AggregateQuery.java 2008-11-19 13:10:40 UTC (rev 15589)
@@ -27,6 +27,7 @@
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 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;
Modified: core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/query/CustomRevEntityQuery.java
===================================================================
--- core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/query/CustomRevEntityQuery.java 2008-11-19 08:18:58 UTC (rev 15588)
+++ core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/query/CustomRevEntityQuery.java 2008-11-19 13:10:40 UTC (rev 15589)
@@ -26,7 +26,7 @@
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 @@
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 @@
}
@BeforeClass(dependsOnMethods = "init")
- public void initData() {
+ public void initData() throws InterruptedException {
// Revision 1
EntityManager em = getEntityManager();
em.getTransaction().begin();
@@ -65,6 +66,12 @@
em.getTransaction().commit();
+ Thread.sleep(100);
+
+ timestamp = System.currentTimeMillis();
+
+ Thread.sleep(100);
+
// Revision 2
em.getTransaction().begin();
@@ -79,7 +86,7 @@
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 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;
+ }
}
\ No newline at end of file
Modified: core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/query/DeletedEntities.java
===================================================================
--- core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/query/DeletedEntities.java 2008-11-19 08:18:58 UTC (rev 15588)
+++ core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/query/DeletedEntities.java 2008-11-19 13:10:40 UTC (rev 15589)
@@ -28,7 +28,7 @@
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 @@
.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;
Modified: core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/query/MaximalizePropertyQuery.java
===================================================================
--- core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/query/MaximalizePropertyQuery.java 2008-11-19 08:18:58 UTC (rev 15588)
+++ core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/query/MaximalizePropertyQuery.java 2008-11-19 13:10:40 UTC (rev 15589)
@@ -27,8 +27,7 @@
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 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 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);
+ }
}
\ No newline at end of file
Modified: core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/query/OrderByLimitQuery.java
===================================================================
--- core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/query/OrderByLimitQuery.java 2008-11-19 08:18:58 UTC (rev 15588)
+++ core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/query/OrderByLimitQuery.java 2008-11-19 13:10:40 UTC (rev 15589)
@@ -29,6 +29,7 @@
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 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 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();
Modified: core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/query/RevisionConstraintQuery.java
===================================================================
--- core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/query/RevisionConstraintQuery.java 2008-11-19 08:18:58 UTC (rev 15588)
+++ core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/query/RevisionConstraintQuery.java 2008-11-19 13:10:40 UTC (rev 15589)
@@ -27,9 +27,7 @@
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 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 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 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 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 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 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 @@
// 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 @@
// 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 @@
// 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;
Modified: core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/query/SimpleQuery.java
===================================================================
--- core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/query/SimpleQuery.java 2008-11-19 08:18:58 UTC (rev 15588)
+++ core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/query/SimpleQuery.java 2008-11-19 13:10:40 UTC (rev 15589)
@@ -30,9 +30,7 @@
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 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 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 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 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 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 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 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 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 void testEmptyDisjunctionRevisionOfEntityQuery() {
List result = getAuditReader().createQuery()
.forRevisionsOfEntity(StrIntTestEntity.class, false, true)
- .add(AuditRestrictions.disjunction())
+ .add(AuditEntity.disjunction())
.getResultList();
assert result.size() == 0;
Modified: core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/query/ids/EmbIdOneToManyQuery.java
===================================================================
--- core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/query/ids/EmbIdOneToManyQuery.java 2008-11-19 08:18:58 UTC (rev 15588)
+++ core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/query/ids/EmbIdOneToManyQuery.java 2008-11-19 13:10:40 UTC (rev 15589)
@@ -28,7 +28,7 @@
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 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 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 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 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;
Modified: core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/query/ids/MulIdOneToManyQuery.java
===================================================================
--- core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/query/ids/MulIdOneToManyQuery.java 2008-11-19 08:18:58 UTC (rev 15588)
+++ core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/query/ids/MulIdOneToManyQuery.java 2008-11-19 13:10:40 UTC (rev 15589)
@@ -28,7 +28,7 @@
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 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 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 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 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;
16 years