JBoss Envers SVN: r141 - in trunk/src: main/org/jboss/envers/configuration and 3 other directories.
by jboss-envers-commits@lists.jboss.org
Author: adamw
Date: 2008-09-03 03:29:48 -0400 (Wed, 03 Sep 2008)
New Revision: 141
Modified:
trunk/src/main/org/jboss/envers/DefaultRevisionEntity.java
trunk/src/main/org/jboss/envers/configuration/RevisionInfoConfiguration.java
trunk/src/main/org/jboss/envers/configuration/VersionsConfiguration.java
trunk/src/main/org/jboss/envers/configuration/VersionsEntitiesConfiguration.java
trunk/src/main/org/jboss/envers/query/VersionsQueryCreator.java
trunk/src/main/org/jboss/envers/query/impl/AbstractVersionsQuery.java
trunk/src/main/org/jboss/envers/query/impl/QueryBuilder.java
trunk/src/main/org/jboss/envers/query/impl/RevisionsOfEntityQuery.java
trunk/src/test/org/jboss/envers/test/integration/query/DeletedEntities.java
trunk/src/test/org/jboss/envers/test/integration/query/SimpleQuery.java
Log:
ENVERS-47: selecting all revision information in revisions-of-entity query
Modified: trunk/src/main/org/jboss/envers/DefaultRevisionEntity.java
===================================================================
--- trunk/src/main/org/jboss/envers/DefaultRevisionEntity.java 2008-09-03 06:27:36 UTC (rev 140)
+++ trunk/src/main/org/jboss/envers/DefaultRevisionEntity.java 2008-09-03 07:29:48 UTC (rev 141)
@@ -24,6 +24,9 @@
import javax.persistence.MappedSuperclass;
import javax.persistence.Id;
import javax.persistence.GeneratedValue;
+import javax.persistence.Transient;
+import java.util.Date;
+import java.text.DateFormat;
/**
* @author Adam Warski (adam at warski dot org)
@@ -46,6 +49,11 @@
this.id = id;
}
+ @Transient
+ public Date getRevisionDate() {
+ return new Date(timestamp);
+ }
+
public long getTimestamp() {
return timestamp;
}
@@ -72,4 +80,8 @@
result = 31 * result + (int) (timestamp ^ (timestamp >>> 32));
return result;
}
+
+ public String toString() {
+ return "DefaultRevisionEntity(id = " + id + ", revisionDate = " + DateFormat.getDateTimeInstance().format(getRevisionDate()) + ")";
+ }
}
Modified: trunk/src/main/org/jboss/envers/configuration/RevisionInfoConfiguration.java
===================================================================
--- trunk/src/main/org/jboss/envers/configuration/RevisionInfoConfiguration.java 2008-09-03 06:27:36 UTC (rev 140)
+++ trunk/src/main/org/jboss/envers/configuration/RevisionInfoConfiguration.java 2008-09-03 07:29:48 UTC (rev 141)
@@ -164,7 +164,7 @@
revisionInfoEntityName = pc.getEntityName();
revisionInfoClass = pc.getMappedClass();
- revisionInfoGenerator = new DefaultRevisionInfoGenerator(revisionInfoEntityName, pc.getMappedClass(),
+ revisionInfoGenerator = new DefaultRevisionInfoGenerator(revisionInfoEntityName, revisionInfoClass,
revisionEntity.value(), revisionInfoTimestampName);
}
}
@@ -173,10 +173,8 @@
Document revisionInfoXmlMapping = null;
if (revisionInfoGenerator == null) {
- // TODO - remove default
- //revisionInfoGenerator = new DefaultRevisionInfoGenerator(revisionInfoEntityName, revisionInfoTimestampName);
revisionInfoClass = DefaultRevisionEntity.class;
- revisionInfoGenerator = new DefaultRevisionInfoGenerator(revisionInfoEntityName, DefaultRevisionEntity.class,
+ revisionInfoGenerator = new DefaultRevisionInfoGenerator(revisionInfoEntityName, revisionInfoClass,
RevisionListener.class, revisionInfoTimestampName);
revisionInfoXmlMapping = generateDefaultRevisionInfoXmlMapping();
}
@@ -184,8 +182,8 @@
return new RevisionInfoConfigurationResult(
revisionInfoGenerator, revisionPropType, revisionInfoXmlMapping,
new RevisionInfoQueryCreator(revisionInfoEntityName, revisionInfoIdName, revisionInfoTimestampName),
- generateRevisionInfoRelationMapping(), revisionInfoIdName,
- new RevisionInfoNumberReader(revisionInfoClass, revisionInfoIdName));
+ generateRevisionInfoRelationMapping(),
+ new RevisionInfoNumberReader(revisionInfoClass, revisionInfoIdName), revisionInfoEntityName);
}
}
@@ -195,21 +193,20 @@
private final Document revisionInfoXmlMapping;
private final RevisionInfoQueryCreator revisionInfoQueryCreator;
private final Element revisionInfoRelationMapping;
- // TODO - remove ?
- private final String revisionInfoIdName;
private final RevisionInfoNumberReader revisionInfoNumberReader;
+ private final String revisionInfoEntityName;
RevisionInfoConfigurationResult(RevisionInfoGenerator revisionInfoGenerator, String revisionPropType,
Document revisionInfoXmlMapping, RevisionInfoQueryCreator revisionInfoQueryCreator,
- Element revisionInfoRelationMapping, String revisionInfoIdName,
- RevisionInfoNumberReader revisionInfoNumberReader) {
+ Element revisionInfoRelationMapping,
+ RevisionInfoNumberReader revisionInfoNumberReader, String revisionInfoEntityName) {
this.revisionInfoGenerator = revisionInfoGenerator;
this.revisionPropType = revisionPropType;
this.revisionInfoXmlMapping = revisionInfoXmlMapping;
this.revisionInfoQueryCreator = revisionInfoQueryCreator;
this.revisionInfoRelationMapping = revisionInfoRelationMapping;
- this.revisionInfoIdName = revisionInfoIdName;
this.revisionInfoNumberReader = revisionInfoNumberReader;
+ this.revisionInfoEntityName = revisionInfoEntityName;
}
public RevisionInfoGenerator getRevisionInfoGenerator() {
@@ -232,11 +229,11 @@
return revisionInfoRelationMapping;
}
- public String getRevisionInfoIdName() {
- return revisionInfoIdName;
- }
-
public RevisionInfoNumberReader getRevisionInfoNumberReader() {
return revisionInfoNumberReader;
}
+
+ public String getRevisionInfoEntityName() {
+ return revisionInfoEntityName;
+ }
}
\ No newline at end of file
Modified: trunk/src/main/org/jboss/envers/configuration/VersionsConfiguration.java
===================================================================
--- trunk/src/main/org/jboss/envers/configuration/VersionsConfiguration.java 2008-09-03 06:27:36 UTC (rev 140)
+++ trunk/src/main/org/jboss/envers/configuration/VersionsConfiguration.java 2008-09-03 07:29:48 UTC (rev 141)
@@ -73,7 +73,7 @@
RevisionInfoConfiguration revInfoCfg = new RevisionInfoConfiguration();
RevisionInfoConfigurationResult revInfoCfgResult = revInfoCfg.configure(cfg, reflectionManager);
verEntCfg = new VersionsEntitiesConfiguration(properties, revInfoCfgResult.getRevisionPropType(),
- revInfoCfgResult.getRevisionInfoIdName());
+ revInfoCfgResult.getRevisionInfoEntityName());
globalCfg = new GlobalConfiguration(properties);
versionsSyncManager = new VersionsSyncManager(revInfoCfgResult.getRevisionInfoGenerator());
revisionInfoQueryCreator = revInfoCfgResult.getRevisionInfoQueryCreator();
Modified: trunk/src/main/org/jboss/envers/configuration/VersionsEntitiesConfiguration.java
===================================================================
--- trunk/src/main/org/jboss/envers/configuration/VersionsEntitiesConfiguration.java 2008-09-03 06:27:36 UTC (rev 140)
+++ trunk/src/main/org/jboss/envers/configuration/VersionsEntitiesConfiguration.java 2008-09-03 07:29:48 UTC (rev 141)
@@ -42,12 +42,12 @@
private final String revisionTypePropName;
private final String revisionTypePropType;
- private final String revisionInfoIdName;
+ private final String revisionInfoEntityName;
private final Map<String, String> customVersionsTablesNames;
- public VersionsEntitiesConfiguration(Properties properties, String revisionPropType, String revisionInfoIdName) {
- this.revisionInfoIdName = revisionInfoIdName;
+ public VersionsEntitiesConfiguration(Properties properties, String revisionPropType, String revisionInfoEntityName) {
+ this.revisionInfoEntityName = revisionInfoEntityName;
versionsTablePrefix = properties.getProperty("org.jboss.envers.versionsTablePrefix", "");
versionsTableSuffix = properties.getProperty("org.jboss.envers.versionsTableSuffix", "_versions");
@@ -90,14 +90,14 @@
return revisionTypePropType;
}
- public String getRevisionInfoIdName() {
- return revisionInfoIdName;
- }
-
public String getRevisionEntityPath() {
return revisionEntityPath;
}
+ public String getRevisionInfoEntityName() {
+ return revisionInfoEntityName;
+ }
+
//
public void addCustomVersionsTableName(String entityName, String tableName) {
Modified: trunk/src/main/org/jboss/envers/query/VersionsQueryCreator.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/VersionsQueryCreator.java 2008-09-03 06:27:36 UTC (rev 140)
+++ trunk/src/main/org/jboss/envers/query/VersionsQueryCreator.java 2008-09-03 07:29:48 UTC (rev 141)
@@ -55,10 +55,14 @@
}
/**
- * Creates a query, which will return a list of three-element arrays, containing the entity instance, the number
- * of the revision (unless a projection is set), at which instances of the given entity were modified, and the type
- * of the revision ({@link org.jboss.envers.RevisionType}). Additional conditions that the results must satisfy
- * may be specified.
+ * Creates a query, which selects the revisions, at which the given entity was modified.
+ * Unless an explicit projection is set, the result will be a list of three-element arrays, containing:
+ * <ol>
+ * <li>the entity instance</li>
+ * <li>revision entity, corresponding to the revision at which the entity was modified. If no custom
+ * revision entity is used, this will be an instance of {@link org.jboss.envers.DefaultRevisionEntity}</li>
+ * <li>type of the revision (an enum instance of class {@link org.jboss.envers.RevisionType})</li>.
+ * Additional conditions that the results must satisfy may be specified.
* @param c Class of the entities for which to query.
* @param selectEntitiesOnly If true, instead of a list of three-element arrays, a list of entites will be
* returned as a result of executing this query.
Modified: trunk/src/main/org/jboss/envers/query/impl/AbstractVersionsQuery.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/impl/AbstractVersionsQuery.java 2008-09-03 06:27:36 UTC (rev 140)
+++ trunk/src/main/org/jboss/envers/query/impl/AbstractVersionsQuery.java 2008-09-03 07:29:48 UTC (rev 141)
@@ -84,9 +84,6 @@
setQueryProperties(query);
- System.out.println("QUERY: " + querySb);
- System.out.println("PARAMS: " + queryParamValues);
-
return query.list();
}
Modified: trunk/src/main/org/jboss/envers/query/impl/QueryBuilder.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/impl/QueryBuilder.java 2008-09-03 06:27:36 UTC (rev 140)
+++ trunk/src/main/org/jboss/envers/query/impl/QueryBuilder.java 2008-09-03 07:29:48 UTC (rev 141)
@@ -45,8 +45,7 @@
/**
*
- * @param entityName Main entity which should be selected. Its properties don't have to be referred to
- * using the alias.
+ * @param entityName Main entity which should be selected.
* @param alias Alias of the entity
*/
public QueryBuilder(String entityName, String alias) {
@@ -70,8 +69,7 @@
/**
* Add an entity from which to select.
- * @param entityName Name of the entity from which to select. Its properties always have to be referred to
- * using the alias.
+ * @param entityName Name of the entity from which to select.
* @param alias Alias of the entity. Should be different than all other aliases.
*/
public void addFrom(String entityName, String alias) {
@@ -167,7 +165,7 @@
private List<String> getOrderList() {
List<String> orderList = new ArrayList<String>();
for (Pair<String, Boolean> order : orders) {
- orderList.add(order.getFirst() + " " + (order.getSecond() ? "asc" : "desc"));
+ orderList.add(alias + "." + order.getFirst() + " " + (order.getSecond() ? "asc" : "desc"));
}
return orderList;
Modified: trunk/src/main/org/jboss/envers/query/impl/RevisionsOfEntityQuery.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/impl/RevisionsOfEntityQuery.java 2008-09-03 06:27:36 UTC (rev 140)
+++ trunk/src/main/org/jboss/envers/query/impl/RevisionsOfEntityQuery.java 2008-09-03 07:29:48 UTC (rev 141)
@@ -72,8 +72,9 @@
/*
The query that should be executed in the versions table:
- SELECT e (unless another projection is specified) FROM ent_ver e WHERE
- e.revision_type != DEL AND (if selectDeletedEntities == false)
+ SELECT e (unless another projection is specified) FROM ent_ver e, rev_entity r WHERE
+ e.revision_type != DEL (if selectDeletedEntities == false) AND
+ e.revision = r.revision AND
(all specified conditions, transformed, on the "e" entity)
ORDER BY e.revision ASC (unless another order or projection is specified)
*/
@@ -92,26 +93,37 @@
qb.addOrder(revisionPropertyPath, true);
}
- // TODO
if (!selectEntitiesOnly) {
- //versionsCriteria.setFetchMode("e._revision", FetchMode.JOIN);
- //versionsCriteria.createCriteria("e.originalId._revision").add(Property.forName("id").eq(1));
+ qb.addFrom(verCfg.getVerEntCfg().getRevisionInfoEntityName(), "r");
+ qb.getRootParameters().addWhere(verCfg.getVerEntCfg().getRevisionPropPath(), true, "=", "r.id", false);
}
- List<Map> queryResult = buildAndExecuteQuery();
+ List<Object> queryResult = buildAndExecuteQuery();
if (hasProjection) {
return queryResult;
} else {
List entities = new ArrayList();
String revisionTypePropertyName = verEntCfg.getRevisionTypePropName();
- for (Map versionsEntity : queryResult) {
+ for (Object resultRow : queryResult) {
+ Map versionsEntity;
+ Object revisionData;
+
+ if (selectEntitiesOnly) {
+ versionsEntity = (Map) resultRow;
+ revisionData = null;
+ } else {
+ Object[] arrayResultRow = (Object[]) resultRow;
+ versionsEntity = (Map) arrayResultRow[0];
+ revisionData = arrayResultRow[1];
+ }
+
Number revision = getRevisionNumber(versionsEntity);
Object entity = entityInstantiator.createInstanceFromVersionsEntity(entityName, versionsEntity, revision);
if (!selectEntitiesOnly) {
- entities.add(new Object[] { entity, revision, versionsEntity.get(revisionTypePropertyName) });
+ entities.add(new Object[] { entity, revisionData, versionsEntity.get(revisionTypePropertyName) });
} else {
entities.add(entity);
}
Modified: trunk/src/test/org/jboss/envers/test/integration/query/DeletedEntities.java
===================================================================
--- trunk/src/test/org/jboss/envers/test/integration/query/DeletedEntities.java 2008-09-03 06:27:36 UTC (rev 140)
+++ trunk/src/test/org/jboss/envers/test/integration/query/DeletedEntities.java 2008-09-03 07:29:48 UTC (rev 141)
@@ -4,6 +4,7 @@
import org.jboss.envers.test.entities.StrIntTestEntity;
import org.jboss.envers.query.VersionsRestrictions;
import org.jboss.envers.RevisionType;
+import org.jboss.envers.DefaultRevisionEntity;
import org.hibernate.ejb.Ejb3Configuration;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
@@ -69,7 +70,7 @@
assert result.size() == 1;
assert ((Object []) result.get(0))[0].equals(new StrIntTestEntity("b", 11, id2));
- assert ((Object []) result.get(0))[1].equals(1);
+ assert ((DefaultRevisionEntity) ((Object []) result.get(0))[1]).getId() == 1;
assert ((Object []) result.get(0))[2].equals(RevisionType.ADD);
}
}
Modified: trunk/src/test/org/jboss/envers/test/integration/query/SimpleQuery.java
===================================================================
--- trunk/src/test/org/jboss/envers/test/integration/query/SimpleQuery.java 2008-09-03 06:27:36 UTC (rev 140)
+++ trunk/src/test/org/jboss/envers/test/integration/query/SimpleQuery.java 2008-09-03 07:29:48 UTC (rev 141)
@@ -7,6 +7,7 @@
import org.jboss.envers.query.RevisionProperty;
import org.jboss.envers.query.RevisionTypeProperty;
import org.jboss.envers.RevisionType;
+import org.jboss.envers.DefaultRevisionEntity;
import org.hibernate.ejb.Ejb3Configuration;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
@@ -192,9 +193,9 @@
assert ((Object []) result.get(1))[0].equals(new StrIntTestEntity("c", 10, id1));
assert ((Object []) result.get(2))[0].equals(new StrIntTestEntity(null, null, id1));
- assert ((Object []) result.get(0))[1].equals(1);
- assert ((Object []) result.get(1))[1].equals(2);
- assert ((Object []) result.get(2))[1].equals(4);
+ assert ((DefaultRevisionEntity) ((Object []) result.get(0))[1]).getId() == 1;
+ assert ((DefaultRevisionEntity) ((Object []) result.get(1))[1]).getId() == 2;
+ assert ((DefaultRevisionEntity) ((Object []) result.get(2))[1]).getId() == 4;
assert ((Object []) result.get(0))[2].equals(RevisionType.ADD);
assert ((Object []) result.get(1))[2].equals(RevisionType.MOD);
16 years, 4 months
JBoss Envers SVN: r139 - trunk/src/test/org/jboss/envers/test.
by jboss-envers-commits@lists.jboss.org
Author: adamw
Date: 2008-09-03 02:27:28 -0400 (Wed, 03 Sep 2008)
New Revision: 139
Modified:
trunk/src/test/org/jboss/envers/test/
Log:
Removing the working-test directory from svn
Property changes on: trunk/src/test/org/jboss/envers/test
___________________________________________________________________
Name: svn:ignore
+ working
16 years, 4 months
JBoss Envers SVN: r138 - in trunk/src/main/org/jboss/envers/query: criteria and 3 other directories.
by jboss-envers-commits@lists.jboss.org
Author: adamw
Date: 2008-09-03 02:04:11 -0400 (Wed, 03 Sep 2008)
New Revision: 138
Modified:
trunk/src/main/org/jboss/envers/query/RevisionProperty.java
trunk/src/main/org/jboss/envers/query/RevisionTypeProperty.java
trunk/src/main/org/jboss/envers/query/criteria/AggregatedFieldVersionsExpression.java
trunk/src/main/org/jboss/envers/query/criteria/VersionsConjunction.java
trunk/src/main/org/jboss/envers/query/criteria/VersionsDisjunction.java
trunk/src/main/org/jboss/envers/query/impl/AbstractVersionsQuery.java
trunk/src/main/org/jboss/envers/query/impl/EntitiesAtRevisionQuery.java
trunk/src/main/org/jboss/envers/query/impl/Parameters.java
trunk/src/main/org/jboss/envers/query/impl/QueryBuilder.java
trunk/src/main/org/jboss/envers/query/impl/RevisionsOfEntityQuery.java
trunk/src/main/org/jboss/envers/query/order/RevisionVersionsOrder.java
trunk/src/main/org/jboss/envers/query/order/VersionsOrder.java
trunk/src/main/org/jboss/envers/query/projection/RevisionVersionsProjection.java
trunk/src/main/org/jboss/envers/query/projection/VersionsProjection.java
Log:
ENVERS-47: some comments
Modified: trunk/src/main/org/jboss/envers/query/RevisionProperty.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/RevisionProperty.java 2008-09-02 11:42:56 UTC (rev 137)
+++ trunk/src/main/org/jboss/envers/query/RevisionProperty.java 2008-09-03 06:04:11 UTC (rev 138)
@@ -115,13 +115,13 @@
}
/**
- * Select the revision number
+ * Projection the revision number
*/
public static VersionsProjection revisionNumber() {
return new RevisionProperty();
}
- public Triple<String, String, Boolean> getProjectionData(VersionsConfiguration verCfg) {
+ public Triple<String, String, Boolean> getData(VersionsConfiguration verCfg) {
return Triple.make(null, verCfg.getVerEntCfg().getRevisionPropPath(), false);
}
}
Modified: trunk/src/main/org/jboss/envers/query/RevisionTypeProperty.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/RevisionTypeProperty.java 2008-09-02 11:42:56 UTC (rev 137)
+++ trunk/src/main/org/jboss/envers/query/RevisionTypeProperty.java 2008-09-03 06:04:11 UTC (rev 138)
@@ -33,13 +33,13 @@
private RevisionTypeProperty() { }
/**
- * Select the revision type
+ * Projection on the revision type
*/
public static VersionsProjection revisionType() {
return new RevisionTypeProperty();
}
- public Triple<String, String, Boolean> getProjectionData(VersionsConfiguration verCfg) {
+ public Triple<String, String, Boolean> getData(VersionsConfiguration verCfg) {
return Triple.make(null, verCfg.getVerEntCfg().getRevisionTypePropName(), false);
}
}
\ No newline at end of file
Modified: trunk/src/main/org/jboss/envers/query/criteria/AggregatedFieldVersionsExpression.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/criteria/AggregatedFieldVersionsExpression.java 2008-09-02 11:42:56 UTC (rev 137)
+++ trunk/src/main/org/jboss/envers/query/criteria/AggregatedFieldVersionsExpression.java 2008-09-03 06:04:11 UTC (rev 138)
@@ -68,10 +68,10 @@
// Setting the desired projection of the aggregated query
switch (mode) {
case MIN:
- subQb.addProjection("min", propertyName);
+ subQb.addProjection("min", propertyName, false);
break;
case MAX:
- subQb.addProjection("max", propertyName);
+ subQb.addProjection("max", propertyName, false);
}
// Adding the constrain on the result of the aggregated criteria
Modified: trunk/src/main/org/jboss/envers/query/criteria/VersionsConjunction.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/criteria/VersionsConjunction.java 2008-09-02 11:42:56 UTC (rev 137)
+++ trunk/src/main/org/jboss/envers/query/criteria/VersionsConjunction.java 2008-09-03 06:04:11 UTC (rev 138)
@@ -44,7 +44,7 @@
}
public void addToQuery(VersionsConfiguration verCfg, String entityName, QueryBuilder qb, Parameters parameters) {
- Parameters andParameters = parameters.addSubParameters("and");
+ Parameters andParameters = parameters.addSubParameters(Parameters.AND);
for (VersionsCriterion criterion : criterions) {
criterion.addToQuery(verCfg, entityName, qb, andParameters);
Modified: trunk/src/main/org/jboss/envers/query/criteria/VersionsDisjunction.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/criteria/VersionsDisjunction.java 2008-09-02 11:42:56 UTC (rev 137)
+++ trunk/src/main/org/jboss/envers/query/criteria/VersionsDisjunction.java 2008-09-03 06:04:11 UTC (rev 138)
@@ -44,7 +44,7 @@
}
public void addToQuery(VersionsConfiguration verCfg, String entityName, QueryBuilder qb, Parameters parameters) {
- Parameters orParameters = parameters.addSubParameters("or");
+ Parameters orParameters = parameters.addSubParameters(Parameters.OR);
for (VersionsCriterion criterion : criterions) {
criterion.addToQuery(verCfg, entityName, qb, orParameters);
Modified: trunk/src/main/org/jboss/envers/query/impl/AbstractVersionsQuery.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/impl/AbstractVersionsQuery.java 2008-09-02 11:42:56 UTC (rev 137)
+++ trunk/src/main/org/jboss/envers/query/impl/AbstractVersionsQuery.java 2008-09-03 06:04:11 UTC (rev 138)
@@ -29,7 +29,6 @@
import org.jboss.envers.query.projection.VersionsProjection;
import org.jboss.envers.exception.VersionsException;
import org.jboss.envers.configuration.VersionsConfiguration;
-import org.jboss.envers.tools.MutableInteger;
import org.jboss.envers.tools.Pair;
import org.jboss.envers.tools.Triple;
import org.hibernate.*;
@@ -69,24 +68,24 @@
entityName = cls.getName();
versionsEntityName = verCfg.getVerEntCfg().getVersionsEntityName(entityName);
- qb = new QueryBuilder(versionsEntityName, "e", new MutableInteger(), new MutableInteger());
+ qb = new QueryBuilder(versionsEntityName, "e");
}
- protected List listQuery() {
+ protected List buildAndExecuteQuery() {
StringBuilder querySb = new StringBuilder();
- Map<String, Object> paramValues = new HashMap<String, Object>();
+ Map<String, Object> queryParamValues = new HashMap<String, Object>();
- qb.build(querySb, paramValues);
+ qb.build(querySb, queryParamValues);
Query query = versionsReader.getSession().createQuery(querySb.toString());
- for (Map.Entry<String, Object> paramValue : paramValues.entrySet()) {
+ for (Map.Entry<String, Object> paramValue : queryParamValues.entrySet()) {
query.setParameter(paramValue.getKey(), paramValue.getValue());
}
setQueryProperties(query);
System.out.println("QUERY: " + querySb);
- System.out.println("PARAMS: " + paramValues);
+ System.out.println("PARAMS: " + queryParamValues);
return query.list();
}
@@ -125,7 +124,7 @@
}
public VersionsQuery addProjection(VersionsProjection projection) {
- Triple<String, String, Boolean> projectionData = projection.getProjectionData(verCfg);
+ Triple<String, String, Boolean> projectionData = projection.getData(verCfg);
hasProjection = true;
qb.addProjection(projectionData.getFirst(), projectionData.getSecond(), projectionData.getThird());
return this;
@@ -138,7 +137,7 @@
}
public VersionsQuery addOrder(VersionsOrder order) {
- Pair<String, Boolean> orderData = order.getOrderData(verCfg);
+ Pair<String, Boolean> orderData = order.getData(verCfg);
return addOrder(orderData.getFirst(), orderData.getSecond());
}
Modified: trunk/src/main/org/jboss/envers/query/impl/EntitiesAtRevisionQuery.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/impl/EntitiesAtRevisionQuery.java 2008-09-02 11:42:56 UTC (rev 137)
+++ trunk/src/main/org/jboss/envers/query/impl/EntitiesAtRevisionQuery.java 2008-09-03 06:04:11 UTC (rev 138)
@@ -62,7 +62,7 @@
String originalIdPropertyName = verEntCfg.getOriginalIdPropName();
// SELECT max(e2.revision)
- maxRevQb.addProjection("max", revisionPropertyPath);
+ maxRevQb.addProjection("max", revisionPropertyPath, false);
// e2.revision <= :revision
maxRevQb.getRootParameters().addWhereWithParam(revisionPropertyPath, "<=", revision);
// e2.id = e.id
@@ -78,7 +78,7 @@
criterion.addToQuery(verCfg, entityName, qb, qb.getRootParameters());
}
- List queryResult = listQuery();
+ List queryResult = buildAndExecuteQuery();
if (hasProjection) {
return queryResult;
Modified: trunk/src/main/org/jboss/envers/query/impl/Parameters.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/impl/Parameters.java 2008-09-02 11:42:56 UTC (rev 137)
+++ trunk/src/main/org/jboss/envers/query/impl/Parameters.java 2008-09-03 06:04:11 UTC (rev 138)
@@ -9,10 +9,13 @@
import java.util.HashMap;
/**
- * Parameters of a query.
+ * Parameters of a query, built using {@link org.jboss.envers.query.impl.QueryBuilder}.
* @author Adam Warski (adam at warski dot org)
*/
public class Parameters {
+ public final static String AND = "and";
+ public final static String OR = "or";
+
/**
* Main alias of the entity.
*/
@@ -22,17 +25,26 @@
*/
private final String connective;
/**
- * For use by the parameter generator.
+ * For use by the parameter generator. Must be the same in all "child" (and parent) parameters.
*/
private final MutableInteger queryParamCounter;
+ /**
+ * A list of sub-parameters (parameters with a different connective).
+ */
private final List<Parameters> subParameters;
+ /**
+ * A list of negated parameters.
+ */
private final List<Parameters> negatedParameters;
+ /**
+ * A list of complete where-expressions.
+ */
private final List<String> expressions;
/**
* Values of parameters used in expressions.
*/
- private final Map<String, Object> queryParamValues;
+ private final Map<String, Object> localQueryParamValues;
Parameters(String alias, String connective, MutableInteger queryParamCounter) {
this.alias = alias;
@@ -42,13 +54,20 @@
subParameters = new ArrayList<Parameters>();
negatedParameters = new ArrayList<Parameters>();
expressions = new ArrayList<String>();
- queryParamValues = new HashMap<String, Object>();
+ localQueryParamValues = new HashMap<String, Object>();
}
private String generateQueryParam() {
return "_p" + queryParamCounter.getAndIncrease();
}
+ /**
+ * Adds sub-parameters with a new connective. That is, the parameters will be grouped in parentheses in the
+ * generated query, e.g.: ... and (exp1 or exp2) and ..., assuming the old connective is "and", and the
+ * new connective is "or".
+ * @param newConnective New connective of the parameters.
+ * @return Sub-parameters with the given connective.
+ */
public Parameters addSubParameters(String newConnective) {
if (connective.equals(newConnective)) {
return this;
@@ -59,8 +78,13 @@
}
}
+ /**
+ * Adds negated parameters, by default with the "and" connective. These paremeters will be grouped in parentheses
+ * in the generated query and negated, e.g. ... not (exp1 and exp2) ...
+ * @return Negated sub paremters.
+ */
public Parameters addNegatedParameters() {
- Parameters newParams = new Parameters(alias, "and", queryParamCounter);
+ Parameters newParams = new Parameters(alias, AND, queryParamCounter);
negatedParameters.add(newParams);
return newParams;
}
@@ -96,7 +120,7 @@
expression.append(" ").append(op).append(" ");
String paramName = generateQueryParam();
- queryParamValues.put(paramName, paramValue);
+ localQueryParamValues.put(paramName, paramValue);
expression.append(":").append(paramName);
expressions.add(expression.toString());
@@ -110,7 +134,7 @@
for (int i=0; i<paramValues.length; i++) {
Object paramValue = paramValues[i];
String paramName = generateQueryParam();
- queryParamValues.put(paramName, paramValue);
+ localQueryParamValues.put(paramName, paramValue);
expression.append(":").append(paramName);
if (i != paramValues.length-1) {
@@ -131,7 +155,7 @@
expression.append(" ").append(op).append(" ");
expression.append("(");
- right.build(expression, queryParamValues);
+ right.build(expression, localQueryParamValues);
expression.append(")");
expressions.add(expression.toString());
@@ -147,11 +171,11 @@
isFirst.unset();
}
- public boolean isEmpty() {
+ boolean isEmpty() {
return expressions.size() == 0 && subParameters.size() == 0 && negatedParameters.size() == 0;
}
- public void build(StringBuilder sb, Map<String, Object> paramValues) {
+ void build(StringBuilder sb, Map<String, Object> queryParamValues) {
MutableBoolean isFirst = new MutableBoolean(true);
for (String expression : expressions) {
@@ -159,17 +183,22 @@
}
for (Parameters sub : subParameters) {
- append(sb, "(", isFirst);
- sub.build(sb, paramValues);
- sb.append(")");
+ if (!subParameters.isEmpty()) {
+ append(sb, "(", isFirst);
+ sub.build(sb, queryParamValues);
+ sb.append(")");
+ }
}
for (Parameters negated : negatedParameters) {
- append(sb, "not (", isFirst);
- negated.build(sb, paramValues);
- sb.append(")");
+ if (!negatedParameters.isEmpty()) {
+ append(sb, "not (", isFirst);
+ negated.build(sb, queryParamValues);
+ sb.append(")");
+ }
}
- paramValues.putAll(queryParamValues);
+ queryParamValues.putAll(localQueryParamValues);
}
}
+
Modified: trunk/src/main/org/jboss/envers/query/impl/QueryBuilder.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/impl/QueryBuilder.java 2008-09-02 11:42:56 UTC (rev 137)
+++ trunk/src/main/org/jboss/envers/query/impl/QueryBuilder.java 2008-09-03 06:04:11 UTC (rev 138)
@@ -9,6 +9,7 @@
import java.util.ArrayList;
/**
+ * A class for incrementaly building a HQL query.
* @author Adam Warski (adam at warski dot org)
*/
public class QueryBuilder {
@@ -19,20 +20,46 @@
* For use by alias generator (in case an alias is not provided by the user).
*/
private final MutableInteger aliasCounter;
+ /**
+ * For use by parameter generator, in {@link org.jboss.envers.query.impl.Parameters}. This counter must be
+ * the same in all parameters and sub-queries of this query.
+ */
private final MutableInteger paramCounter;
- private final Parameters parameters;
+ /**
+ * Main "where" parameters for this query.
+ */
+ private final Parameters rootParameters;
+ /**
+ * A list of pairs (from entity name, alias name).
+ */
private final List<Pair<String, String>> froms;
+ /**
+ * A list of pairs (property name, order ascending?).
+ */
private final List<Pair<String, Boolean>> orders;
+ /**
+ * A list of complete projection definitions: either a sole property name, or a function(property name).
+ */
private final List<String> projections;
- public QueryBuilder(String entityName, String alias, MutableInteger aliasCounter, MutableInteger paramCounter) {
+ /**
+ *
+ * @param entityName Main entity which should be selected. Its properties don't have to be referred to
+ * using the alias.
+ * @param alias Alias of the entity
+ */
+ public QueryBuilder(String entityName, String alias) {
+ this(entityName, alias, new MutableInteger(), new MutableInteger());
+ }
+
+ private QueryBuilder(String entityName, String alias, MutableInteger aliasCounter, MutableInteger paramCounter) {
this.entityName = entityName;
this.alias = alias;
this.aliasCounter = aliasCounter;
this.paramCounter = paramCounter;
- parameters = new Parameters(alias, "and", paramCounter);
+ rootParameters = new Parameters(alias, "and", paramCounter);
froms = new ArrayList<Pair<String, String>>();
orders = new ArrayList<Pair<String, Boolean>>();
@@ -41,6 +68,12 @@
addFrom(entityName, alias);
}
+ /**
+ * Add an entity from which to select.
+ * @param entityName Name of the entity from which to select. Its properties always have to be referred to
+ * using the alias.
+ * @param alias Alias of the entity. Should be different than all other aliases.
+ */
public void addFrom(String entityName, String alias) {
froms.add(Pair.make(entityName, alias));
}
@@ -50,7 +83,8 @@
}
/**
- * @return A sub-query builder for the same entity (with an auto-generated alias).
+ * @return A sub-query builder for the same entity (with an auto-generated alias). The sub-query can
+ * be later used as a value of a parameter.
*/
public QueryBuilder newSubQueryBuilder() {
return newSubQueryBuilder(entityName, generateAlias());
@@ -59,24 +93,21 @@
/**
* @param entityName Entity name, which will be the main entity for the sub-query.
* @param alias Alias of the entity, which can later be used in parameters.
- * @return A sub-query builder for the given entity, with the given alias.
+ * @return A sub-query builder for the given entity, with the given alias. The sub-query can
+ * be later used as a value of a parameter.
*/
public QueryBuilder newSubQueryBuilder(String entityName, String alias) {
return new QueryBuilder(entityName, alias, aliasCounter, paramCounter);
}
public Parameters getRootParameters() {
- return parameters;
+ return rootParameters;
}
public void addOrder(String propertyName, boolean ascending) {
orders.add(Pair.make(propertyName, ascending));
}
- public void addProjection(String function, String propertyName) {
- addProjection(function, propertyName, false);
- }
-
public void addProjection(String function, String propertyName, boolean distinct) {
if (function == null) {
projections.add((distinct ? "distinct " : "") + alias + "." + propertyName);
@@ -85,7 +116,13 @@
}
}
- public void build(StringBuilder sb, Map<String, Object> paramValues) {
+ /**
+ * Builds the given query, appending results to the given string buffer, and adding all query parameter values
+ * that are used to the map provided.
+ * @param sb String builder to which the query will be appended.
+ * @param queryParamValues Values of parameters used in the query.
+ */
+ public void build(StringBuilder sb, Map<String, Object> queryParamValues) {
sb.append("select ");
if (projections.size() > 0) {
// all projections separated with commas
@@ -97,10 +134,10 @@
sb.append(" from ");
// all from entities with aliases, separated with commas
StringTools.append(sb, getFromList().iterator(), ", ");
- // where part - parameters
- if (!parameters.isEmpty()) {
+ // where part - rootParameters
+ if (!rootParameters.isEmpty()) {
sb.append(" where ");
- parameters.build(sb, paramValues);
+ rootParameters.build(sb, queryParamValues);
}
// orders
if (orders.size() > 0) {
Modified: trunk/src/main/org/jboss/envers/query/impl/RevisionsOfEntityQuery.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/impl/RevisionsOfEntityQuery.java 2008-09-02 11:42:56 UTC (rev 137)
+++ trunk/src/main/org/jboss/envers/query/impl/RevisionsOfEntityQuery.java 2008-09-03 06:04:11 UTC (rev 138)
@@ -98,7 +98,7 @@
//versionsCriteria.createCriteria("e.originalId._revision").add(Property.forName("id").eq(1));
}
- List<Map> queryResult = listQuery();
+ List<Map> queryResult = buildAndExecuteQuery();
if (hasProjection) {
return queryResult;
} else {
Modified: trunk/src/main/org/jboss/envers/query/order/RevisionVersionsOrder.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/order/RevisionVersionsOrder.java 2008-09-02 11:42:56 UTC (rev 137)
+++ trunk/src/main/org/jboss/envers/query/order/RevisionVersionsOrder.java 2008-09-03 06:04:11 UTC (rev 138)
@@ -34,7 +34,7 @@
this.asc = asc;
}
- public Pair<String, Boolean> getOrderData(VersionsConfiguration verCfg) {
+ public Pair<String, Boolean> getData(VersionsConfiguration verCfg) {
String revisionPropPath = verCfg.getVerEntCfg().getRevisionPropPath();
return Pair.make(revisionPropPath, asc);
}
Modified: trunk/src/main/org/jboss/envers/query/order/VersionsOrder.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/order/VersionsOrder.java 2008-09-02 11:42:56 UTC (rev 137)
+++ trunk/src/main/org/jboss/envers/query/order/VersionsOrder.java 2008-09-03 06:04:11 UTC (rev 138)
@@ -28,5 +28,9 @@
* @author Adam Warski (adam at warski dot org)
*/
public interface VersionsOrder {
- Pair<String, Boolean> getOrderData(VersionsConfiguration verCfg);
+ /**
+ * @param verCfg Configuration.
+ * @return A pair: (property name, ascending?).
+ */
+ Pair<String, Boolean> getData(VersionsConfiguration verCfg);
}
Modified: trunk/src/main/org/jboss/envers/query/projection/RevisionVersionsProjection.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/projection/RevisionVersionsProjection.java 2008-09-02 11:42:56 UTC (rev 137)
+++ trunk/src/main/org/jboss/envers/query/projection/RevisionVersionsProjection.java 2008-09-03 06:04:11 UTC (rev 138)
@@ -42,7 +42,7 @@
this.type = type;
}
- public Triple<String, String, Boolean> getProjectionData(VersionsConfiguration verCfg) {
+ public Triple<String, String, Boolean> getData(VersionsConfiguration verCfg) {
String revisionPropPath = verCfg.getVerEntCfg().getRevisionPropPath();
switch (type) {
Modified: trunk/src/main/org/jboss/envers/query/projection/VersionsProjection.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/projection/VersionsProjection.java 2008-09-02 11:42:56 UTC (rev 137)
+++ trunk/src/main/org/jboss/envers/query/projection/VersionsProjection.java 2008-09-03 06:04:11 UTC (rev 138)
@@ -29,5 +29,10 @@
* @author Adam Warski (adam at warski dot org)
*/
public interface VersionsProjection {
- Triple<String, String, Boolean> getProjectionData(VersionsConfiguration verCfg);
+ /**
+ *
+ * @param verCfg Configuration.
+ * @return A triple: (function name - possibly null, property name, add distinct?).
+ */
+ Triple<String, String, Boolean> getData(VersionsConfiguration verCfg);
}
16 years, 4 months
JBoss Envers SVN: r137 - in trunk/src: main/org/jboss/envers/query and 7 other directories.
by jboss-envers-commits@lists.jboss.org
Author: adamw
Date: 2008-09-02 07:42:56 -0400 (Tue, 02 Sep 2008)
New Revision: 137
Added:
trunk/src/main/org/jboss/envers/query/impl/Parameters.java
trunk/src/main/org/jboss/envers/query/impl/QueryBuilder.java
trunk/src/main/org/jboss/envers/tools/MutableInteger.java
trunk/src/main/org/jboss/envers/tools/Triple.java
Removed:
trunk/src/main/org/jboss/envers/query/VersionsProjections.java
trunk/src/main/org/jboss/envers/query/criteria/IlikeVersionsExpression.java
trunk/src/main/org/jboss/envers/query/criteria/PublicLogicalExpression.java
trunk/src/main/org/jboss/envers/query/criteria/PublicPropertyExpression.java
trunk/src/main/org/jboss/envers/query/criteria/PublicSimpleExpression.java
trunk/src/main/org/jboss/envers/query/projection/DistinctVersionsProjection.java
trunk/src/main/org/jboss/envers/query/projection/ProjectionWrapper.java
trunk/src/main/org/jboss/envers/query/projection/VersionsProjectionList.java
Modified:
trunk/src/main/org/jboss/envers/entities/mapper/id/AbstractIdMapper.java
trunk/src/main/org/jboss/envers/entities/mapper/id/IdMapper.java
trunk/src/main/org/jboss/envers/query/RevisionProperty.java
trunk/src/main/org/jboss/envers/query/RevisionTypeProperty.java
trunk/src/main/org/jboss/envers/query/VersionsQuery.java
trunk/src/main/org/jboss/envers/query/VersionsRestrictions.java
trunk/src/main/org/jboss/envers/query/criteria/AggregatedFieldVersionsExpression.java
trunk/src/main/org/jboss/envers/query/criteria/BetweenVersionsExpression.java
trunk/src/main/org/jboss/envers/query/criteria/IdentifierEqVersionsExpression.java
trunk/src/main/org/jboss/envers/query/criteria/InVersionsExpression.java
trunk/src/main/org/jboss/envers/query/criteria/LogicalVersionsExpression.java
trunk/src/main/org/jboss/envers/query/criteria/NotNullVersionsExpression.java
trunk/src/main/org/jboss/envers/query/criteria/NotVersionsExpression.java
trunk/src/main/org/jboss/envers/query/criteria/NullVersionsExpression.java
trunk/src/main/org/jboss/envers/query/criteria/PropertyVersionsExpression.java
trunk/src/main/org/jboss/envers/query/criteria/RelatedVersionsExpression.java
trunk/src/main/org/jboss/envers/query/criteria/RevisionVersionsExpression.java
trunk/src/main/org/jboss/envers/query/criteria/SimpleVersionsExpression.java
trunk/src/main/org/jboss/envers/query/criteria/VersionsConjunction.java
trunk/src/main/org/jboss/envers/query/criteria/VersionsCriterion.java
trunk/src/main/org/jboss/envers/query/criteria/VersionsDisjunction.java
trunk/src/main/org/jboss/envers/query/impl/AbstractVersionsQuery.java
trunk/src/main/org/jboss/envers/query/impl/EntitiesAtRevisionQuery.java
trunk/src/main/org/jboss/envers/query/impl/RevisionsOfEntityQuery.java
trunk/src/main/org/jboss/envers/query/order/RevisionVersionsOrder.java
trunk/src/main/org/jboss/envers/query/order/VersionsOrder.java
trunk/src/main/org/jboss/envers/query/projection/RevisionVersionsProjection.java
trunk/src/main/org/jboss/envers/query/projection/VersionsProjection.java
trunk/src/main/org/jboss/envers/reader/VersionsReaderImpl.java
trunk/src/main/org/jboss/envers/tools/StringTools.java
trunk/src/test/org/jboss/envers/test/integration/query/AggregateQuery.java
trunk/src/test/org/jboss/envers/test/integration/query/DeletedEntities.java
trunk/src/test/org/jboss/envers/test/integration/query/MaximalizePropertyQuery.java
trunk/src/test/org/jboss/envers/test/integration/query/OrderByLimitQuery.java
trunk/src/test/org/jboss/envers/test/integration/query/RevisionConstraintQuery.java
trunk/src/test/org/jboss/envers/test/integration/query/SimpleQuery.java
Log:
ENVERS-47: rewriting query implementation
Modified: trunk/src/main/org/jboss/envers/entities/mapper/id/AbstractIdMapper.java
===================================================================
--- trunk/src/main/org/jboss/envers/entities/mapper/id/AbstractIdMapper.java 2008-08-31 08:46:36 UTC (rev 136)
+++ trunk/src/main/org/jboss/envers/entities/mapper/id/AbstractIdMapper.java 2008-09-02 11:42:56 UTC (rev 137)
@@ -21,9 +21,7 @@
*/
package org.jboss.envers.entities.mapper.id;
-import org.hibernate.criterion.Restrictions;
-import org.hibernate.criterion.Criterion;
-import org.hibernate.criterion.Conjunction;
+import org.jboss.envers.query.impl.Parameters;
import java.util.Iterator;
import java.util.List;
@@ -32,23 +30,34 @@
* @author Adam Warski (adam at warski dot org)
*/
public abstract class AbstractIdMapper implements IdMapper {
- public Criterion getIdsEqualCriterion(String prefix1, String prefix2) {
+ public void addIdsEqualToQuery(Parameters parameters, String prefix1, String prefix2) {
List<QueryParameterData> paramDatas = mapToQueryParametersFromId(null);
- if (paramDatas.size() == 1) {
- QueryParameterData paramData = paramDatas.iterator().next();
- return Restrictions.eqProperty(paramData.getProperty(prefix1),
- paramData.getProperty(prefix2));
+ Parameters parametersToUse;
+ if (paramDatas.size() > 1) {
+ parametersToUse = parameters.addSubParameters("and");
} else {
- Conjunction conjunction = Restrictions.conjunction();
+ parametersToUse = parameters;
+ }
- for (QueryParameterData paramData : paramDatas) {
- conjunction.add(Restrictions.eqProperty(paramData.getProperty(prefix1),
- paramData.getProperty(prefix2)));
- }
+ for (QueryParameterData paramData : paramDatas) {
+ parametersToUse.addWhere(paramData.getProperty(prefix1), false, "=", paramData.getProperty(prefix2), false);
+ }
+ }
- return conjunction;
+ public void addIdEqualsToQuery(Parameters parameters, Object id, String prefix, boolean equals) {
+ List<QueryParameterData> paramDatas = mapToQueryParametersFromId(id);
+
+ Parameters parametersToUse;
+ if (paramDatas.size() > 1) {
+ parametersToUse = parameters.addSubParameters("and");
+ } else {
+ parametersToUse = parameters;
}
+
+ for (QueryParameterData paramData : paramDatas) {
+ parametersToUse.addWhereWithParam(paramData.getProperty(prefix), equals ? "=" : "<>", paramData.getValue());
+ }
}
public String getIdsEqualQuery(String prefix1, String prefix2) {
@@ -99,7 +108,7 @@
while (paramDataIter.hasNext()) {
QueryParameterData paramData = paramDataIter.next();
-
+
query.append(paramData.getProperty(prefix));
if (equals) {
query.append(" = ");
@@ -107,7 +116,7 @@
query.append(" != ");
}
query.append(":").append(paramData.getQueryParameterName());
-
+
if (paramDataIter.hasNext()) {
query.append(" AND ");
}
@@ -115,29 +124,4 @@
return query.toString();
}
-
- public Criterion getIdEqualsCriterion(Object id, String prefix, boolean equals) {
- List<QueryParameterData> paramDatas = mapToQueryParametersFromId(id);
-
- if (paramDatas.size() == 1) {
- QueryParameterData paramData = paramDatas.iterator().next();
- if (equals) {
- return Restrictions.eq(paramData.getProperty(prefix), paramData.getValue());
- } else {
- return Restrictions.ne(paramData.getProperty(prefix), paramData.getValue());
- }
- } else {
- Conjunction conjunction = Restrictions.conjunction();
-
- for (QueryParameterData paramData : paramDatas) {
- if (equals) {
- conjunction.add(Restrictions.eq(paramData.getProperty(prefix), paramData.getValue()));
- } else {
- conjunction.add(Restrictions.ne(paramData.getProperty(prefix), paramData.getValue()));
- }
- }
-
- return conjunction;
- }
- }
}
Modified: trunk/src/main/org/jboss/envers/entities/mapper/id/IdMapper.java
===================================================================
--- trunk/src/main/org/jboss/envers/entities/mapper/id/IdMapper.java 2008-08-31 08:46:36 UTC (rev 136)
+++ trunk/src/main/org/jboss/envers/entities/mapper/id/IdMapper.java 2008-09-02 11:42:56 UTC (rev 137)
@@ -21,7 +21,7 @@
*/
package org.jboss.envers.entities.mapper.id;
-import org.hibernate.criterion.Criterion;
+import org.jboss.envers.query.impl.Parameters;
import java.util.Map;
import java.util.List;
@@ -30,15 +30,15 @@
* @author Adam Warski (adam at warski dot org)
*/
public interface IdMapper {
- public void mapToMapFromId(Map<String, Object> data, Object obj);
+ void mapToMapFromId(Map<String, Object> data, Object obj);
- public void mapToMapFromEntity(Map<String, Object> data, Object obj);
+ void mapToMapFromEntity(Map<String, Object> data, Object obj);
- public void mapToEntityFromMap(Object obj, Map data);
+ void mapToEntityFromMap(Object obj, Map data);
- public Object mapToIdFromEntity(Object data);
+ Object mapToIdFromEntity(Object data);
- public Object mapToIdFromMap(Map data);
+ Object mapToIdFromMap(Map data);
/**
* Creates a mapper with all mapped properties prefixed. A mapped property is a property which
@@ -46,41 +46,41 @@
* @param prefix Prefix to add to mapped properties
* @return A copy of the current property mapper, with mapped properties prefixed.
*/
- public IdMapper prefixMappedProperties(String prefix);
+ IdMapper prefixMappedProperties(String prefix);
/**
* @param obj Id from which to map.
* @return A set parameter data, needed to build a query basing on the given id.
*/
- public List<QueryParameterData> mapToQueryParametersFromId(Object obj);
+ List<QueryParameterData> mapToQueryParametersFromId(Object obj);
/**
- * Gets a criteria object, which contains restrictions, which express the property that the id of the entity
+ * Gets a query string, which contains equalities, which express the property that the id of the entity
* with alias prefix1, is equal to the id of the entity with alias prefix2 (the entity is the same).
* @param prefix1 First alias of the entity.
* @param prefix2 Second alias of the entity.
- * @return A criterion object expressing the property described above.
+ * @return A query string expressing the property described above.
*/
- public Criterion getIdsEqualCriterion(String prefix1, String prefix2);
+ String getIdsEqualQuery(String prefix1, String prefix2);
/**
- * Gets a query string, which contains equalities, which express the property that the id of the entity
+ * Adds query statements, which contains restrictions, which express the property that the id of the entity
* with alias prefix1, is equal to the id of the entity with alias prefix2 (the entity is the same).
- * @param prefix1 First alias of the entity.
- * @param prefix2 Second alias of the entity.
- * @return A query string expressing the property described above.
+ * @param parameters Parameters, to which to add the statements.
+ * @param prefix1 First alias of the entity + prefix to add to the properties.
+ * @param prefix2 Second alias of the entity + prefix to add to the properties.
*/
- public String getIdsEqualQuery(String prefix1, String prefix2);
+ void addIdsEqualToQuery(Parameters parameters, String prefix1, String prefix2);
/**
- * Gets a criteria object, which contains restrictions, which express the property that the id of the entity
+ * Adds query statements, which contains restrictions, which express the property that the id of the entity
* with alias prefix, is equal to the given object.
+ * @param parameters Parameters, to which to add the statements.
* @param id Value of id.
- * @param prefix Alias of the entity (may be null).
- * @param equals Should this criteria express the "=" relation or the "<>" relation.
- * @return A criterion object expressing the property described above.
+ * @param prefix Prefix to add to the properties (may be null).
+ * @param equals Should this query express the "=" relation or the "<>" relation.
*/
- public Criterion getIdEqualsCriterion(Object id, String prefix, boolean equals);
+ void addIdEqualsToQuery(Parameters parameters, Object id, String prefix, boolean equals);
/**
* Gets a query string, which contains equalities, which express the property that the id of the entity
@@ -90,7 +90,7 @@
* @param equals Should this query express the "=" relation or the "<>" relation.
* @return A query string expressing the property described above.
*/
- public String getIdEqualsQuery(String prefix, boolean equals);
+ String getIdEqualsQuery(String prefix, boolean equals);
/**
* Gets a query string, which contains equalities, which express the property that the id of the entity
@@ -102,5 +102,5 @@
* @param prefix2 Second alias of the entity.
* @return A query string expressing the property described above.
*/
- public String getIdsEqualQuery(String prefix1, IdMapper mapper2, String prefix2);
+ String getIdsEqualQuery(String prefix1, IdMapper mapper2, String prefix2);
}
Modified: trunk/src/main/org/jboss/envers/query/RevisionProperty.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/RevisionProperty.java 2008-08-31 08:46:36 UTC (rev 136)
+++ trunk/src/main/org/jboss/envers/query/RevisionProperty.java 2008-09-02 11:42:56 UTC (rev 137)
@@ -28,8 +28,7 @@
import org.jboss.envers.query.projection.VersionsProjection;
import org.jboss.envers.query.projection.RevisionVersionsProjection;
import org.jboss.envers.configuration.VersionsConfiguration;
-import org.hibernate.criterion.Projection;
-import org.hibernate.criterion.Projections;
+import org.jboss.envers.tools.Triple;
/**
* @author Adam Warski (adam at warski dot org)
@@ -109,13 +108,20 @@
}
/**
+ * Distinct revisions
+ */
+ public static VersionsProjection distinct() {
+ return new RevisionVersionsProjection(RevisionVersionsProjection.ProjectionType.DISTINCT);
+ }
+
+ /**
* Select the revision number
*/
public static VersionsProjection revisionNumber() {
return new RevisionProperty();
}
- public Projection getProjection(VersionsConfiguration verCfg, String entityName) {
- return Projections.property(verCfg.getVerEntCfg().getRevisionPropPath());
+ public Triple<String, String, Boolean> getProjectionData(VersionsConfiguration verCfg) {
+ return Triple.make(null, verCfg.getVerEntCfg().getRevisionPropPath(), false);
}
}
Modified: trunk/src/main/org/jboss/envers/query/RevisionTypeProperty.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/RevisionTypeProperty.java 2008-08-31 08:46:36 UTC (rev 136)
+++ trunk/src/main/org/jboss/envers/query/RevisionTypeProperty.java 2008-09-02 11:42:56 UTC (rev 137)
@@ -23,8 +23,7 @@
import org.jboss.envers.query.projection.VersionsProjection;
import org.jboss.envers.configuration.VersionsConfiguration;
-import org.hibernate.criterion.Projection;
-import org.hibernate.criterion.Projections;
+import org.jboss.envers.tools.Triple;
/**
* @author Adam Warski (adam at warski dot org)
@@ -40,7 +39,7 @@
return new RevisionTypeProperty();
}
- public Projection getProjection(VersionsConfiguration verCfg, String entityName) {
- return Projections.property(verCfg.getVerEntCfg().getRevisionTypePropName());
+ public Triple<String, String, Boolean> getProjectionData(VersionsConfiguration verCfg) {
+ return Triple.make(null, verCfg.getVerEntCfg().getRevisionTypePropName(), false);
}
}
\ No newline at end of file
Deleted: trunk/src/main/org/jboss/envers/query/VersionsProjections.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/VersionsProjections.java 2008-08-31 08:46:36 UTC (rev 136)
+++ trunk/src/main/org/jboss/envers/query/VersionsProjections.java 2008-09-02 11:42:56 UTC (rev 137)
@@ -1,58 +0,0 @@
-/*
- * Envers. http://www.jboss.org/envers
- *
- * Copyright 2008 Red Hat Middleware, LLC. All rights reserved.
- *
- * 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, v. 2.1.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT A 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, v.2.1 along with this distribution; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301, USA.
- *
- * Red Hat Author(s): Adam Warski
- */
-package org.jboss.envers.query;
-
-import org.jboss.envers.query.projection.VersionsProjection;
-import org.jboss.envers.query.projection.DistinctVersionsProjection;
-import org.jboss.envers.query.projection.ProjectionWrapper;
-import org.jboss.envers.query.projection.VersionsProjectionList;
-import org.hibernate.criterion.Projection;
-
-/**
- * @author Adam Warski (adam at warski dot org)
- */
-@SuppressWarnings({"JavaDoc"})
-public class VersionsProjections {
- /**
- * A distinct projection on a given versions projection.
- * @param projection
- * @return
- */
- public static VersionsProjection distinct(VersionsProjection projection) {
- return new DistinctVersionsProjection(projection);
- }
-
- /**
- * A distinct projection on a given hibernate projection, which can be later used together with
- * other versions projections (for example in a list).
- */
- public static VersionsProjection distinct(Projection projection) {
- return new DistinctVersionsProjection(new ProjectionWrapper(projection));
- }
-
- /**
- * A list of versions and hibernate projections.
- */
- public static VersionsProjectionList projectionList() {
- return new VersionsProjectionList();
- }
-}
Modified: trunk/src/main/org/jboss/envers/query/VersionsQuery.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/VersionsQuery.java 2008-08-31 08:46:36 UTC (rev 136)
+++ trunk/src/main/org/jboss/envers/query/VersionsQuery.java 2008-09-02 11:42:56 UTC (rev 137)
@@ -25,8 +25,6 @@
import org.jboss.envers.query.projection.VersionsProjection;
import org.jboss.envers.query.order.VersionsOrder;
import org.jboss.envers.exception.VersionsException;
-import org.hibernate.criterion.Projection;
-import org.hibernate.criterion.Order;
import org.hibernate.FlushMode;
import org.hibernate.CacheMode;
import org.hibernate.LockMode;
@@ -46,11 +44,11 @@
VersionsQuery add(VersionsCriterion criterion);
- VersionsQuery setProjection(Projection projection);
+ VersionsQuery addProjection(String function, String propertyName);
- VersionsQuery setProjection(VersionsProjection projection);
+ VersionsQuery addProjection(VersionsProjection projection);
- VersionsQuery addOrder(Order order);
+ VersionsQuery addOrder(String propertyName, boolean asc);
VersionsQuery addOrder(VersionsOrder order);
Modified: trunk/src/main/org/jboss/envers/query/VersionsRestrictions.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/VersionsRestrictions.java 2008-08-31 08:46:36 UTC (rev 136)
+++ trunk/src/main/org/jboss/envers/query/VersionsRestrictions.java 2008-09-02 11:42:56 UTC (rev 137)
@@ -27,6 +27,7 @@
import java.util.Collection;
/**
+ * TODO: ilike
* @author Adam Warski (adam at warski dot org)
* @see org.hibernate.criterion.Restrictions
*/
@@ -84,22 +85,6 @@
}
/**
- * A case-insensitive "like", similar to Postgres <tt>ilike</tt>
- * operator
- */
- public static VersionsCriterion ilike(String propertyName, String value, MatchMode matchMode) {
- return new IlikeVersionsExpression(propertyName, value, matchMode);
- }
-
- /**
- * A case-insensitive "like", similar to Postgres <tt>ilike</tt>
- * operator
- */
- public static VersionsCriterion ilike(String propertyName, Object value) {
- return new IlikeVersionsExpression(propertyName, value);
- }
-
- /**
* Apply a "greater than" constraint to the named property
*/
public static VersionsCriterion gt(String propertyName, Object value) {
Modified: trunk/src/main/org/jboss/envers/query/criteria/AggregatedFieldVersionsExpression.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/criteria/AggregatedFieldVersionsExpression.java 2008-08-31 08:46:36 UTC (rev 136)
+++ trunk/src/main/org/jboss/envers/query/criteria/AggregatedFieldVersionsExpression.java 2008-09-02 11:42:56 UTC (rev 137)
@@ -21,9 +21,9 @@
*/
package org.jboss.envers.query.criteria;
-import org.hibernate.criterion.*;
-import org.jboss.envers.exception.VersionsException;
import org.jboss.envers.configuration.VersionsConfiguration;
+import org.jboss.envers.query.impl.QueryBuilder;
+import org.jboss.envers.query.impl.Parameters;
import java.util.List;
import java.util.ArrayList;
@@ -52,40 +52,29 @@
return this;
}
- public Criterion toVersionsCriterion(VersionsConfiguration verCfg, String entityName)
- throws VersionsException {
+ public void addToQuery(VersionsConfiguration verCfg, String entityName, QueryBuilder qb, Parameters parameters) {
CriteriaTools.checkPropertyNotARelation(verCfg, entityName, propertyName);
- String versionsEntityName = verCfg.getVerEntCfg().getVersionsEntityName(entityName);
+ // This will be the aggregated query, containing all the specified conditions
+ QueryBuilder subQb = qb.newSubQueryBuilder();
- // This will be the aggregated criteria, containing all the specified conditions
- DetachedCriteria aggregatedCriteria = DetachedCriteria.forEntityName(versionsEntityName);
-
- // This will contain all the specified conditions and an equal constraing on the result of the
- // aggregated criteria.
- Conjunction conjunction = Restrictions.conjunction();
-
- // First adding all specified conditions both to the main criteria, as well as to the
+ // Adding all specified conditions both to the main query, as well as to the
// aggregated one.
for (VersionsCriterion versionsCriteria : criterions) {
- Criterion transformedCriterion = versionsCriteria.toVersionsCriterion(verCfg, entityName);
-
- conjunction.add(transformedCriterion);
- aggregatedCriteria.add(transformedCriterion);
+ versionsCriteria.addToQuery(verCfg, entityName, qb, parameters);
+ versionsCriteria.addToQuery(verCfg, entityName, subQb, subQb.getRootParameters());
}
- // Setting the desired projection of the aggregated criteria
+ // Setting the desired projection of the aggregated query
switch (mode) {
case MIN:
- aggregatedCriteria.setProjection(Property.forName(propertyName).min());
+ subQb.addProjection("min", propertyName);
break;
case MAX:
- aggregatedCriteria.setProjection(Property.forName(propertyName).max());
- }
+ subQb.addProjection("max", propertyName);
+ }
// Adding the constrain on the result of the aggregated criteria
- conjunction.add(Property.forName(propertyName).eq(aggregatedCriteria));
-
- return conjunction;
+ parameters.addWhere(propertyName, "=", subQb);
}
}
\ No newline at end of file
Modified: trunk/src/main/org/jboss/envers/query/criteria/BetweenVersionsExpression.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/criteria/BetweenVersionsExpression.java 2008-08-31 08:46:36 UTC (rev 136)
+++ trunk/src/main/org/jboss/envers/query/criteria/BetweenVersionsExpression.java 2008-09-02 11:42:56 UTC (rev 137)
@@ -21,10 +21,9 @@
*/
package org.jboss.envers.query.criteria;
-import org.hibernate.criterion.Criterion;
-import org.hibernate.criterion.Restrictions;
-import org.jboss.envers.exception.VersionsException;
import org.jboss.envers.configuration.VersionsConfiguration;
+import org.jboss.envers.query.impl.QueryBuilder;
+import org.jboss.envers.query.impl.Parameters;
/**
* @author Adam Warski (adam at warski dot org)
@@ -40,9 +39,9 @@
this.hi = hi;
}
- public Criterion toVersionsCriterion(VersionsConfiguration verCfg, String entityName)
- throws VersionsException {
+ public void addToQuery(VersionsConfiguration verCfg, String entityName, QueryBuilder qb, Parameters parameters) {
CriteriaTools.checkPropertyNotARelation(verCfg, entityName, propertyName);
- return Restrictions.between(propertyName, lo, hi);
+ parameters.addWhereWithParam(propertyName, ">=", lo);
+ parameters.addWhereWithParam(propertyName, "<=", hi);
}
}
Modified: trunk/src/main/org/jboss/envers/query/criteria/IdentifierEqVersionsExpression.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/criteria/IdentifierEqVersionsExpression.java 2008-08-31 08:46:36 UTC (rev 136)
+++ trunk/src/main/org/jboss/envers/query/criteria/IdentifierEqVersionsExpression.java 2008-09-02 11:42:56 UTC (rev 137)
@@ -21,9 +21,9 @@
*/
package org.jboss.envers.query.criteria;
-import org.hibernate.criterion.Criterion;
-import org.jboss.envers.exception.VersionsException;
import org.jboss.envers.configuration.VersionsConfiguration;
+import org.jboss.envers.query.impl.QueryBuilder;
+import org.jboss.envers.query.impl.Parameters;
/**
* @author Adam Warski (adam at warski dot org)
@@ -35,9 +35,8 @@
this.id = id;
}
- public Criterion toVersionsCriterion(VersionsConfiguration verCfg, String entityName)
- throws VersionsException {
- return verCfg.getEntCfg().get(entityName).getIdMapper()
- .getIdEqualsCriterion(id, verCfg.getVerEntCfg().getOriginalIdPropName(), true);
+ public void addToQuery(VersionsConfiguration verCfg, String entityName, QueryBuilder qb, Parameters parameters) {
+ verCfg.getEntCfg().get(entityName).getIdMapper()
+ .addIdEqualsToQuery(parameters, id, verCfg.getVerEntCfg().getOriginalIdPropName(), true);
}
}
Deleted: trunk/src/main/org/jboss/envers/query/criteria/IlikeVersionsExpression.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/criteria/IlikeVersionsExpression.java 2008-08-31 08:46:36 UTC (rev 136)
+++ trunk/src/main/org/jboss/envers/query/criteria/IlikeVersionsExpression.java 2008-09-02 11:42:56 UTC (rev 137)
@@ -1,51 +0,0 @@
-/*
- * Envers. http://www.jboss.org/envers
- *
- * Copyright 2008 Red Hat Middleware, LLC. All rights reserved.
- *
- * 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, v. 2.1.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT A 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, v.2.1 along with this distribution; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301, USA.
- *
- * Red Hat Author(s): Adam Warski
- */
-package org.jboss.envers.query.criteria;
-
-import org.hibernate.criterion.Criterion;
-import org.hibernate.criterion.MatchMode;
-import org.hibernate.criterion.Restrictions;
-import org.jboss.envers.exception.VersionsException;
-import org.jboss.envers.configuration.VersionsConfiguration;
-
-/**
- * @author Adam Warski (adam at warski dot org)
- */
-public class IlikeVersionsExpression implements VersionsCriterion {
- private final String propertyName;
- private final Object value;
-
- public IlikeVersionsExpression(String propertyName, Object value) {
- this.propertyName = propertyName;
- this.value = value;
- }
-
- public IlikeVersionsExpression(String propertyName, String value, MatchMode matchMode) {
- this(propertyName, matchMode.toMatchString(value));
- }
-
- public Criterion toVersionsCriterion(VersionsConfiguration verCfg, String entityName)
- throws VersionsException {
- CriteriaTools.checkPropertyNotARelation(verCfg, entityName, propertyName);
- return Restrictions.ilike(propertyName, value);
- }
-}
Modified: trunk/src/main/org/jboss/envers/query/criteria/InVersionsExpression.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/criteria/InVersionsExpression.java 2008-08-31 08:46:36 UTC (rev 136)
+++ trunk/src/main/org/jboss/envers/query/criteria/InVersionsExpression.java 2008-09-02 11:42:56 UTC (rev 137)
@@ -21,10 +21,9 @@
*/
package org.jboss.envers.query.criteria;
-import org.hibernate.criterion.Criterion;
-import org.hibernate.criterion.Restrictions;
-import org.jboss.envers.exception.VersionsException;
import org.jboss.envers.configuration.VersionsConfiguration;
+import org.jboss.envers.query.impl.QueryBuilder;
+import org.jboss.envers.query.impl.Parameters;
/**
* @author Adam Warski (adam at warski dot org)
@@ -38,9 +37,8 @@
this.values = values;
}
- public Criterion toVersionsCriterion(VersionsConfiguration verCfg, String entityName)
- throws VersionsException {
+ public void addToQuery(VersionsConfiguration verCfg, String entityName, QueryBuilder qb, Parameters parameters) {
CriteriaTools.checkPropertyNotARelation(verCfg, entityName, propertyName);
- return Restrictions.in(propertyName, values);
+ parameters.addWhereWithParams(propertyName, "in (", values, ")");
}
}
Modified: trunk/src/main/org/jboss/envers/query/criteria/LogicalVersionsExpression.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/criteria/LogicalVersionsExpression.java 2008-08-31 08:46:36 UTC (rev 136)
+++ trunk/src/main/org/jboss/envers/query/criteria/LogicalVersionsExpression.java 2008-09-02 11:42:56 UTC (rev 137)
@@ -21,9 +21,9 @@
*/
package org.jboss.envers.query.criteria;
-import org.hibernate.criterion.Criterion;
-import org.jboss.envers.exception.VersionsException;
import org.jboss.envers.configuration.VersionsConfiguration;
+import org.jboss.envers.query.impl.QueryBuilder;
+import org.jboss.envers.query.impl.Parameters;
/**
* @author Adam Warski (adam at warski dot org)
@@ -39,9 +39,10 @@
this.op = op;
}
- public Criterion toVersionsCriterion(VersionsConfiguration verCfg, String entityName)
- throws VersionsException {
- return new PublicLogicalExpression(lhs.toVersionsCriterion(verCfg, null),
- rhs.toVersionsCriterion(verCfg, null), op);
+ public void addToQuery(VersionsConfiguration verCfg, String entityName, QueryBuilder qb, Parameters parameters) {
+ Parameters opParameters = parameters.addSubParameters(op);
+
+ lhs.addToQuery(verCfg, entityName, qb, opParameters.addSubParameters("and"));
+ rhs.addToQuery(verCfg, entityName, qb, opParameters.addSubParameters("and"));
}
}
Modified: trunk/src/main/org/jboss/envers/query/criteria/NotNullVersionsExpression.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/criteria/NotNullVersionsExpression.java 2008-08-31 08:46:36 UTC (rev 136)
+++ trunk/src/main/org/jboss/envers/query/criteria/NotNullVersionsExpression.java 2008-09-02 11:42:56 UTC (rev 137)
@@ -21,11 +21,10 @@
*/
package org.jboss.envers.query.criteria;
-import org.hibernate.criterion.Criterion;
-import org.hibernate.criterion.Restrictions;
-import org.jboss.envers.exception.VersionsException;
import org.jboss.envers.entities.RelationDescription;
import org.jboss.envers.configuration.VersionsConfiguration;
+import org.jboss.envers.query.impl.QueryBuilder;
+import org.jboss.envers.query.impl.Parameters;
/**
* @author Adam Warski (adam at warski dot org)
@@ -37,14 +36,13 @@
this.propertyName = propertyName;
}
- public Criterion toVersionsCriterion(VersionsConfiguration verCfg, String entityName)
- throws VersionsException {
+ public void addToQuery(VersionsConfiguration verCfg, String entityName, QueryBuilder qb, Parameters parameters) {
RelationDescription relatedEntity = CriteriaTools.getRelatedEntity(verCfg, entityName, propertyName);
if (relatedEntity == null) {
- return Restrictions.isNotNull(propertyName);
+ parameters.addWhereWithParam(propertyName, "<>", null);
} else {
- return relatedEntity.getIdMapper().getIdEqualsCriterion(null, propertyName, false);
+ relatedEntity.getIdMapper().addIdEqualsToQuery(parameters, null, propertyName, false);
}
}
}
Modified: trunk/src/main/org/jboss/envers/query/criteria/NotVersionsExpression.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/criteria/NotVersionsExpression.java 2008-08-31 08:46:36 UTC (rev 136)
+++ trunk/src/main/org/jboss/envers/query/criteria/NotVersionsExpression.java 2008-09-02 11:42:56 UTC (rev 137)
@@ -21,10 +21,9 @@
*/
package org.jboss.envers.query.criteria;
-import org.hibernate.criterion.Criterion;
-import org.hibernate.criterion.Restrictions;
-import org.jboss.envers.exception.VersionsException;
import org.jboss.envers.configuration.VersionsConfiguration;
+import org.jboss.envers.query.impl.QueryBuilder;
+import org.jboss.envers.query.impl.Parameters;
/**
* @author Adam Warski (adam at warski dot org)
@@ -36,8 +35,7 @@
this.criterion = criterion;
}
- public Criterion toVersionsCriterion(VersionsConfiguration verCfg, String entityName)
- throws VersionsException {
- return Restrictions.not(criterion.toVersionsCriterion(verCfg, null));
+ public void addToQuery(VersionsConfiguration verCfg, String entityName, QueryBuilder qb, Parameters parameters) {
+ criterion.addToQuery(verCfg, entityName, qb, parameters.addNegatedParameters());
}
}
Modified: trunk/src/main/org/jboss/envers/query/criteria/NullVersionsExpression.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/criteria/NullVersionsExpression.java 2008-08-31 08:46:36 UTC (rev 136)
+++ trunk/src/main/org/jboss/envers/query/criteria/NullVersionsExpression.java 2008-09-02 11:42:56 UTC (rev 137)
@@ -21,11 +21,10 @@
*/
package org.jboss.envers.query.criteria;
-import org.hibernate.criterion.Criterion;
-import org.hibernate.criterion.Restrictions;
-import org.jboss.envers.exception.VersionsException;
import org.jboss.envers.entities.RelationDescription;
import org.jboss.envers.configuration.VersionsConfiguration;
+import org.jboss.envers.query.impl.QueryBuilder;
+import org.jboss.envers.query.impl.Parameters;
/**
* @author Adam Warski (adam at warski dot org)
@@ -37,14 +36,13 @@
this.propertyName = propertyName;
}
- public Criterion toVersionsCriterion(VersionsConfiguration verCfg, String entityName)
- throws VersionsException {
+ public void addToQuery(VersionsConfiguration verCfg, String entityName, QueryBuilder qb, Parameters parameters) {
RelationDescription relatedEntity = CriteriaTools.getRelatedEntity(verCfg, entityName, propertyName);
if (relatedEntity == null) {
- return Restrictions.isNull(propertyName);
+ parameters.addWhereWithParam(propertyName, "=", null);
} else {
- return relatedEntity.getIdMapper().getIdEqualsCriterion(null, propertyName, true);
+ relatedEntity.getIdMapper().addIdEqualsToQuery(parameters, null, propertyName, true);
}
}
}
Modified: trunk/src/main/org/jboss/envers/query/criteria/PropertyVersionsExpression.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/criteria/PropertyVersionsExpression.java 2008-08-31 08:46:36 UTC (rev 136)
+++ trunk/src/main/org/jboss/envers/query/criteria/PropertyVersionsExpression.java 2008-09-02 11:42:56 UTC (rev 137)
@@ -21,9 +21,9 @@
*/
package org.jboss.envers.query.criteria;
-import org.hibernate.criterion.Criterion;
-import org.jboss.envers.exception.VersionsException;
import org.jboss.envers.configuration.VersionsConfiguration;
+import org.jboss.envers.query.impl.QueryBuilder;
+import org.jboss.envers.query.impl.Parameters;
/**
* @author Adam Warski (adam at warski dot org)
@@ -39,10 +39,9 @@
this.op = op;
}
- public Criterion toVersionsCriterion(VersionsConfiguration verCfg, String entityName)
- throws VersionsException {
+ public void addToQuery(VersionsConfiguration verCfg, String entityName, QueryBuilder qb, Parameters parameters) {
CriteriaTools.checkPropertyNotARelation(verCfg, entityName, propertyName);
CriteriaTools.checkPropertyNotARelation(verCfg, entityName, otherPropertyName);
- return new PublicPropertyExpression(propertyName, otherPropertyName, op);
+ parameters.addWhere(propertyName, op, otherPropertyName);
}
}
Deleted: trunk/src/main/org/jboss/envers/query/criteria/PublicLogicalExpression.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/criteria/PublicLogicalExpression.java 2008-08-31 08:46:36 UTC (rev 136)
+++ trunk/src/main/org/jboss/envers/query/criteria/PublicLogicalExpression.java 2008-09-02 11:42:56 UTC (rev 137)
@@ -1,35 +0,0 @@
-/*
- * Envers. http://www.jboss.org/envers
- *
- * Copyright 2008 Red Hat Middleware, LLC. All rights reserved.
- *
- * 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, v. 2.1.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT A 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, v.2.1 along with this distribution; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301, USA.
- *
- * Red Hat Author(s): Adam Warski
- */
-package org.jboss.envers.query.criteria;
-
-import org.hibernate.criterion.LogicalExpression;
-import org.hibernate.criterion.Criterion;
-
-/**
- * A class which exposes LogicalExpression's protected constructor as public.
- * @author Adam Warski (adam at warski dot org)
- */
-public class PublicLogicalExpression extends LogicalExpression {
- protected PublicLogicalExpression(Criterion lhs, Criterion rhs, String op) {
- super(lhs, rhs, op);
- }
-}
Deleted: trunk/src/main/org/jboss/envers/query/criteria/PublicPropertyExpression.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/criteria/PublicPropertyExpression.java 2008-08-31 08:46:36 UTC (rev 136)
+++ trunk/src/main/org/jboss/envers/query/criteria/PublicPropertyExpression.java 2008-09-02 11:42:56 UTC (rev 137)
@@ -1,34 +0,0 @@
-/*
- * Envers. http://www.jboss.org/envers
- *
- * Copyright 2008 Red Hat Middleware, LLC. All rights reserved.
- *
- * 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, v. 2.1.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT A 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, v.2.1 along with this distribution; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301, USA.
- *
- * Red Hat Author(s): Adam Warski
- */
-package org.jboss.envers.query.criteria;
-
-import org.hibernate.criterion.PropertyExpression;
-
-/**
- * A class which exposes PropertyExpression's protected constructor as public.
- * @author Adam Warski (adam at warski dot org)
- */
-public class PublicPropertyExpression extends PropertyExpression {
- public PublicPropertyExpression(String propertyName, String otherPropertyName, String op) {
- super(propertyName, otherPropertyName, op);
- }
-}
\ No newline at end of file
Deleted: trunk/src/main/org/jboss/envers/query/criteria/PublicSimpleExpression.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/criteria/PublicSimpleExpression.java 2008-08-31 08:46:36 UTC (rev 136)
+++ trunk/src/main/org/jboss/envers/query/criteria/PublicSimpleExpression.java 2008-09-02 11:42:56 UTC (rev 137)
@@ -1,34 +0,0 @@
-/*
- * Envers. http://www.jboss.org/envers
- *
- * Copyright 2008 Red Hat Middleware, LLC. All rights reserved.
- *
- * 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, v. 2.1.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT A 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, v.2.1 along with this distribution; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301, USA.
- *
- * Red Hat Author(s): Adam Warski
- */
-package org.jboss.envers.query.criteria;
-
-import org.hibernate.criterion.SimpleExpression;
-
-/**
- * A class which exposes SimpleExpression's protected constructor as public.
- * @author Adam Warski (adam at warski dot org)
- */
-public class PublicSimpleExpression extends SimpleExpression {
- public PublicSimpleExpression(String propertyName, Object value, String op, boolean ignoreCase) {
- super(propertyName, value, op, ignoreCase);
- }
-}
Modified: trunk/src/main/org/jboss/envers/query/criteria/RelatedVersionsExpression.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/criteria/RelatedVersionsExpression.java 2008-08-31 08:46:36 UTC (rev 136)
+++ trunk/src/main/org/jboss/envers/query/criteria/RelatedVersionsExpression.java 2008-09-02 11:42:56 UTC (rev 137)
@@ -21,10 +21,11 @@
*/
package org.jboss.envers.query.criteria;
-import org.hibernate.criterion.Criterion;
import org.jboss.envers.exception.VersionsException;
import org.jboss.envers.entities.RelationDescription;
import org.jboss.envers.configuration.VersionsConfiguration;
+import org.jboss.envers.query.impl.QueryBuilder;
+import org.jboss.envers.query.impl.Parameters;
/**
* @author Adam Warski (adam at warski dot org)
@@ -40,15 +41,14 @@
this.equals = equals;
}
- public Criterion toVersionsCriterion(VersionsConfiguration verCfg, String entityName)
- throws VersionsException {
+ public void addToQuery(VersionsConfiguration verCfg, String entityName, QueryBuilder qb, Parameters parameters) {
RelationDescription relatedEntity = CriteriaTools.getRelatedEntity(verCfg, entityName, propertyName);
if (relatedEntity == null) {
throw new VersionsException("This criterion can only be used on a property that is " +
"a relation to another property.");
} else {
- return relatedEntity.getIdMapper().getIdEqualsCriterion(id, propertyName, equals);
+ relatedEntity.getIdMapper().addIdEqualsToQuery(parameters, id, propertyName, equals);
}
}
}
\ No newline at end of file
Modified: trunk/src/main/org/jboss/envers/query/criteria/RevisionVersionsExpression.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/criteria/RevisionVersionsExpression.java 2008-08-31 08:46:36 UTC (rev 136)
+++ trunk/src/main/org/jboss/envers/query/criteria/RevisionVersionsExpression.java 2008-09-02 11:42:56 UTC (rev 137)
@@ -21,9 +21,9 @@
*/
package org.jboss.envers.query.criteria;
-import org.hibernate.criterion.Criterion;
-import org.jboss.envers.exception.VersionsException;
import org.jboss.envers.configuration.VersionsConfiguration;
+import org.jboss.envers.query.impl.QueryBuilder;
+import org.jboss.envers.query.impl.Parameters;
/**
* @author Adam Warski (adam at warski dot org)
@@ -37,9 +37,7 @@
this.op = op;
}
- public Criterion toVersionsCriterion(VersionsConfiguration verCfg, String entityName)
- throws VersionsException {
- return new PublicSimpleExpression(verCfg.getVerEntCfg().getRevisionPropPath(),
- value, op, false);
+ public void addToQuery(VersionsConfiguration verCfg, String entityName, QueryBuilder qb, Parameters parameters) {
+ parameters.addWhereWithParam(verCfg.getVerEntCfg().getRevisionPropPath(), op, value);
}
}
\ No newline at end of file
Modified: trunk/src/main/org/jboss/envers/query/criteria/SimpleVersionsExpression.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/criteria/SimpleVersionsExpression.java 2008-08-31 08:46:36 UTC (rev 136)
+++ trunk/src/main/org/jboss/envers/query/criteria/SimpleVersionsExpression.java 2008-09-02 11:42:56 UTC (rev 137)
@@ -21,10 +21,11 @@
*/
package org.jboss.envers.query.criteria;
-import org.hibernate.criterion.Criterion;
import org.jboss.envers.exception.VersionsException;
import org.jboss.envers.entities.RelationDescription;
import org.jboss.envers.configuration.VersionsConfiguration;
+import org.jboss.envers.query.impl.QueryBuilder;
+import org.jboss.envers.query.impl.Parameters;
/**
* @author Adam Warski (adam at warski dot org)
@@ -33,7 +34,6 @@
private String propertyName;
private Object value;
private String op;
- private boolean ignoreCase;
public SimpleVersionsExpression(String propertyName, Object value, String op) {
this.propertyName = propertyName;
@@ -41,19 +41,11 @@
this.op = op;
}
- public SimpleVersionsExpression(String propertyName, Object value, String op, boolean ignoreCase) {
- this.propertyName = propertyName;
- this.value = value;
- this.op = op;
- this.ignoreCase = ignoreCase;
- }
-
- public Criterion toVersionsCriterion(VersionsConfiguration verCfg, String entityName)
- throws VersionsException {
+ public void addToQuery(VersionsConfiguration verCfg, String entityName, QueryBuilder qb, Parameters parameters) {
RelationDescription relatedEntity = CriteriaTools.getRelatedEntity(verCfg, entityName, propertyName);
if (relatedEntity == null) {
- return new PublicSimpleExpression(propertyName, value, op, ignoreCase);
+ parameters.addWhereWithParam(propertyName, op, value);
} else {
if (!"=".equals(op) && !"<>".equals(op)) {
throw new VersionsException("This type of operation: " + op + " (" + entityName + "." + propertyName +
@@ -62,7 +54,7 @@
Object id = relatedEntity.getIdMapper().mapToIdFromEntity(value);
- return relatedEntity.getIdMapper().getIdEqualsCriterion(id, propertyName, "=".equals(op));
+ relatedEntity.getIdMapper().addIdEqualsToQuery(parameters, id, propertyName, "=".equals(op));
}
}
}
Modified: trunk/src/main/org/jboss/envers/query/criteria/VersionsConjunction.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/criteria/VersionsConjunction.java 2008-08-31 08:46:36 UTC (rev 136)
+++ trunk/src/main/org/jboss/envers/query/criteria/VersionsConjunction.java 2008-09-02 11:42:56 UTC (rev 137)
@@ -21,11 +21,9 @@
*/
package org.jboss.envers.query.criteria;
-import org.hibernate.criterion.Criterion;
-import org.hibernate.criterion.Conjunction;
-import org.hibernate.criterion.Restrictions;
-import org.jboss.envers.exception.VersionsException;
import org.jboss.envers.configuration.VersionsConfiguration;
+import org.jboss.envers.query.impl.QueryBuilder;
+import org.jboss.envers.query.impl.Parameters;
import java.util.ArrayList;
import java.util.List;
@@ -45,14 +43,11 @@
return this;
}
- public Criterion toVersionsCriterion(VersionsConfiguration verCfg, String entityName)
- throws VersionsException {
- Conjunction conjunction = Restrictions.conjunction();
+ public void addToQuery(VersionsConfiguration verCfg, String entityName, QueryBuilder qb, Parameters parameters) {
+ Parameters andParameters = parameters.addSubParameters("and");
for (VersionsCriterion criterion : criterions) {
- conjunction.add(criterion.toVersionsCriterion(verCfg, null));
+ criterion.addToQuery(verCfg, entityName, qb, andParameters);
}
-
- return conjunction;
}
}
Modified: trunk/src/main/org/jboss/envers/query/criteria/VersionsCriterion.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/criteria/VersionsCriterion.java 2008-08-31 08:46:36 UTC (rev 136)
+++ trunk/src/main/org/jboss/envers/query/criteria/VersionsCriterion.java 2008-09-02 11:42:56 UTC (rev 137)
@@ -21,13 +21,13 @@
*/
package org.jboss.envers.query.criteria;
-import org.hibernate.criterion.Criterion;
-import org.jboss.envers.exception.VersionsException;
import org.jboss.envers.configuration.VersionsConfiguration;
+import org.jboss.envers.query.impl.QueryBuilder;
+import org.jboss.envers.query.impl.Parameters;
/**
* @author Adam Warski (adam at warski dot org)
*/
public interface VersionsCriterion {
- Criterion toVersionsCriterion(VersionsConfiguration verCfg, String entityName) throws VersionsException;
+ void addToQuery(VersionsConfiguration verCfg, String entityName, QueryBuilder qb, Parameters parameters);
}
Modified: trunk/src/main/org/jboss/envers/query/criteria/VersionsDisjunction.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/criteria/VersionsDisjunction.java 2008-08-31 08:46:36 UTC (rev 136)
+++ trunk/src/main/org/jboss/envers/query/criteria/VersionsDisjunction.java 2008-09-02 11:42:56 UTC (rev 137)
@@ -21,11 +21,9 @@
*/
package org.jboss.envers.query.criteria;
-import org.hibernate.criterion.Disjunction;
-import org.hibernate.criterion.Criterion;
-import org.hibernate.criterion.Restrictions;
-import org.jboss.envers.exception.VersionsException;
import org.jboss.envers.configuration.VersionsConfiguration;
+import org.jboss.envers.query.impl.QueryBuilder;
+import org.jboss.envers.query.impl.Parameters;
import java.util.List;
import java.util.ArrayList;
@@ -45,14 +43,11 @@
return this;
}
- public Criterion toVersionsCriterion(VersionsConfiguration verCfg, String entityName)
- throws VersionsException {
- Disjunction conjunction = Restrictions.disjunction();
+ public void addToQuery(VersionsConfiguration verCfg, String entityName, QueryBuilder qb, Parameters parameters) {
+ Parameters orParameters = parameters.addSubParameters("or");
for (VersionsCriterion criterion : criterions) {
- conjunction.add(criterion.toVersionsCriterion(verCfg, null));
+ criterion.addToQuery(verCfg, entityName, qb, orParameters);
}
-
- return conjunction;
}
}
\ No newline at end of file
Modified: trunk/src/main/org/jboss/envers/query/impl/AbstractVersionsQuery.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/impl/AbstractVersionsQuery.java 2008-08-31 08:46:36 UTC (rev 136)
+++ trunk/src/main/org/jboss/envers/query/impl/AbstractVersionsQuery.java 2008-09-02 11:42:56 UTC (rev 137)
@@ -25,48 +25,72 @@
import org.jboss.envers.entities.EntityInstantiator;
import org.jboss.envers.query.criteria.VersionsCriterion;
import org.jboss.envers.query.VersionsQuery;
+import org.jboss.envers.query.order.VersionsOrder;
import org.jboss.envers.query.projection.VersionsProjection;
-import org.jboss.envers.query.order.VersionsOrder;
import org.jboss.envers.exception.VersionsException;
import org.jboss.envers.configuration.VersionsConfiguration;
-import org.hibernate.criterion.Projection;
-import org.hibernate.criterion.Order;
+import org.jboss.envers.tools.MutableInteger;
+import org.jboss.envers.tools.Pair;
+import org.jboss.envers.tools.Triple;
import org.hibernate.*;
import javax.persistence.NonUniqueResultException;
import javax.persistence.NoResultException;
import java.util.List;
import java.util.ArrayList;
+import java.util.Map;
+import java.util.HashMap;
/**
* @author Adam Warski (adam at warski dot org)
*/
public abstract class AbstractVersionsQuery implements VersionsQuery {
- //protected VersionsReaderImplementor versionsReader;
protected EntityInstantiator entityInstantiator;
protected List<VersionsCriterion> criterions;
protected String entityName;
protected String versionsEntityName;
- protected Criteria versionsCriteria;
+ protected QueryBuilder qb;
protected boolean hasProjection;
protected boolean hasOrder;
protected final VersionsConfiguration verCfg;
+ private final VersionsReaderImplementor versionsReader;
protected AbstractVersionsQuery(VersionsConfiguration verCfg, VersionsReaderImplementor versionsReader,
Class<?> cls) {
this.verCfg = verCfg;
+ this.versionsReader = versionsReader;
criterions = new ArrayList<VersionsCriterion>();
entityInstantiator = new EntityInstantiator(verCfg, versionsReader);
entityName = cls.getName();
versionsEntityName = verCfg.getVerEntCfg().getVersionsEntityName(entityName);
- versionsCriteria = versionsReader.getSession().createCriteria(versionsEntityName, "e");
+
+ qb = new QueryBuilder(versionsEntityName, "e", new MutableInteger(), new MutableInteger());
}
+ protected List listQuery() {
+ StringBuilder querySb = new StringBuilder();
+ Map<String, Object> paramValues = new HashMap<String, Object>();
+
+ qb.build(querySb, paramValues);
+
+ Query query = versionsReader.getSession().createQuery(querySb.toString());
+ for (Map.Entry<String, Object> paramValue : paramValues.entrySet()) {
+ query.setParameter(paramValue.getKey(), paramValue.getValue());
+ }
+
+ setQueryProperties(query);
+
+ System.out.println("QUERY: " + querySb);
+ System.out.println("PARAMS: " + paramValues);
+
+ return query.list();
+ }
+
public abstract List list() throws VersionsException;
public List getResultList() throws VersionsException {
@@ -92,74 +116,98 @@
return this;
}
- // Various options
+ // Projection and order
- public VersionsQuery setProjection(Projection projection) {
+ public VersionsQuery addProjection(String function, String propertyName) {
hasProjection = true;
- versionsCriteria.setProjection(projection);
+ qb.addProjection(function, propertyName, false);
return this;
}
- public VersionsQuery setProjection(VersionsProjection projection) {
+ public VersionsQuery addProjection(VersionsProjection projection) {
+ Triple<String, String, Boolean> projectionData = projection.getProjectionData(verCfg);
hasProjection = true;
- versionsCriteria.setProjection(projection.getProjection(verCfg, entityName));
+ qb.addProjection(projectionData.getFirst(), projectionData.getSecond(), projectionData.getThird());
return this;
}
- public VersionsQuery addOrder(Order order) {
+ public VersionsQuery addOrder(String propertyName, boolean asc) {
hasOrder = true;
- versionsCriteria.addOrder(order);
+ qb.addOrder(propertyName, asc);
return this;
}
public VersionsQuery addOrder(VersionsOrder order) {
- hasOrder = true;
- versionsCriteria.addOrder(order.getOrder(verCfg, entityName));
- return this;
+ Pair<String, Boolean> orderData = order.getOrderData(verCfg);
+ return addOrder(orderData.getFirst(), orderData.getSecond());
}
+ // Query properties
+
+ private Integer maxResults;
+ private Integer firstResult;
+ private Boolean cacheable;
+ private String cacheRegion;
+ private String comment;
+ private FlushMode flushMode;
+ private CacheMode cacheMode;
+ private Integer timeout;
+ private LockMode lockMode;
+
public VersionsQuery setMaxResults(int maxResults) {
- versionsCriteria.setMaxResults(maxResults);
+ this.maxResults = maxResults;
return this;
}
public VersionsQuery setFirstResult(int firstResult) {
- versionsCriteria.setFirstResult(firstResult);
+ this.firstResult = firstResult;
return this;
}
public VersionsQuery setCacheable(boolean cacheable) {
- versionsCriteria.setCacheable(cacheable);
+ this.cacheable = cacheable;
return this;
}
public VersionsQuery setCacheRegion(String cacheRegion) {
- versionsCriteria.setCacheRegion(cacheRegion);
+ this.cacheRegion = cacheRegion;
return this;
}
public VersionsQuery setComment(String comment) {
- versionsCriteria.setComment(comment);
+ this.comment = comment;
return this;
}
public VersionsQuery setFlushMode(FlushMode flushMode) {
- versionsCriteria.setFlushMode(flushMode);
+ this.flushMode = flushMode;
return this;
}
public VersionsQuery setCacheMode(CacheMode cacheMode) {
- versionsCriteria.setCacheMode(cacheMode);
+ this.cacheMode = cacheMode;
return this;
}
public VersionsQuery setTimeout(int timeout) {
- versionsCriteria.setTimeout(timeout);
+ this.timeout = timeout;
return this;
}
public VersionsQuery setLockMode(LockMode lockMode) {
- versionsCriteria.setLockMode(lockMode);
+ this.lockMode = lockMode;
return this;
}
+
+ protected void setQueryProperties(Query query) {
+ if (maxResults != null) query.setMaxResults(maxResults);
+ if (firstResult != null) query.setFirstResult(firstResult);
+ if (cacheable != null) query.setCacheable(cacheable);
+ if (cacheRegion != null) query.setCacheRegion(cacheRegion);
+ if (comment != null) query.setComment(comment);
+ if (flushMode != null) query.setFlushMode(flushMode);
+ if (cacheMode != null) query.setCacheMode(cacheMode);
+ if (timeout != null) query.setTimeout(timeout);
+ if (lockMode != null) query.setLockMode("e", lockMode);
+ }
}
Modified: trunk/src/main/org/jboss/envers/query/impl/EntitiesAtRevisionQuery.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/impl/EntitiesAtRevisionQuery.java 2008-08-31 08:46:36 UTC (rev 136)
+++ trunk/src/main/org/jboss/envers/query/impl/EntitiesAtRevisionQuery.java 2008-09-02 11:42:56 UTC (rev 137)
@@ -26,7 +26,6 @@
import org.jboss.envers.RevisionType;
import org.jboss.envers.configuration.VersionsEntitiesConfiguration;
import org.jboss.envers.configuration.VersionsConfiguration;
-import org.hibernate.criterion.*;
import java.util.List;
import java.util.ArrayList;
@@ -55,7 +54,7 @@
e2.revision <= :revision AND e2.originalId.id = e.originalId.id)
*/
- DetachedCriteria maxRevCriteria = DetachedCriteria.forEntityName(versionsEntityName, "e2");
+ QueryBuilder maxRevQb = qb.newSubQueryBuilder(versionsEntityName, "e2");
VersionsEntitiesConfiguration verEntCfg = verCfg.getVerEntCfg();
@@ -63,23 +62,23 @@
String originalIdPropertyName = verEntCfg.getOriginalIdPropName();
// SELECT max(e2.revision)
- maxRevCriteria.setProjection(Property.forName(revisionPropertyPath).max());
+ maxRevQb.addProjection("max", revisionPropertyPath);
// e2.revision <= :revision
- maxRevCriteria.add(Restrictions.le(revisionPropertyPath, revision));
+ maxRevQb.getRootParameters().addWhereWithParam(revisionPropertyPath, "<=", revision);
// e2.id = e.id
- maxRevCriteria.add(verCfg.getEntCfg().get(entityName).getIdMapper().getIdsEqualCriterion(
- "e." + originalIdPropertyName, "e2." + originalIdPropertyName));
+ verCfg.getEntCfg().get(entityName).getIdMapper().addIdsEqualToQuery(maxRevQb.getRootParameters(),
+ "e." + originalIdPropertyName, "e2." + originalIdPropertyName);
// e.revision_type != DEL AND
- versionsCriteria.add(Property.forName(verEntCfg.getRevisionTypePropName()).ne(RevisionType.DEL));
+ qb.getRootParameters().addWhereWithParam(verEntCfg.getRevisionTypePropName(), "<>", RevisionType.DEL);
// e.revision = (SELECT max(...) ...)
- versionsCriteria.add(Property.forName(revisionPropertyPath).eq(maxRevCriteria));
- // all specified conditions, transformed
+ qb.getRootParameters().addWhere(revisionPropertyPath, "=", maxRevQb);
+ // all specified conditions
for (VersionsCriterion criterion : criterions) {
- versionsCriteria.add(criterion.toVersionsCriterion(verCfg, entityName));
+ criterion.addToQuery(verCfg, entityName, qb, qb.getRootParameters());
}
- List queryResult = versionsCriteria.list();
+ List queryResult = listQuery();
if (hasProjection) {
return queryResult;
Added: trunk/src/main/org/jboss/envers/query/impl/Parameters.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/impl/Parameters.java (rev 0)
+++ trunk/src/main/org/jboss/envers/query/impl/Parameters.java 2008-09-02 11:42:56 UTC (rev 137)
@@ -0,0 +1,175 @@
+package org.jboss.envers.query.impl;
+
+import org.jboss.envers.tools.MutableInteger;
+import org.jboss.envers.tools.MutableBoolean;
+
+import java.util.List;
+import java.util.ArrayList;
+import java.util.Map;
+import java.util.HashMap;
+
+/**
+ * Parameters of a query.
+ * @author Adam Warski (adam at warski dot org)
+ */
+public class Parameters {
+ /**
+ * Main alias of the entity.
+ */
+ private final String alias;
+ /**
+ * Connective between these parameters - "and" or "or".
+ */
+ private final String connective;
+ /**
+ * For use by the parameter generator.
+ */
+ private final MutableInteger queryParamCounter;
+
+ private final List<Parameters> subParameters;
+ private final List<Parameters> negatedParameters;
+ private final List<String> expressions;
+ /**
+ * Values of parameters used in expressions.
+ */
+ private final Map<String, Object> queryParamValues;
+
+ Parameters(String alias, String connective, MutableInteger queryParamCounter) {
+ this.alias = alias;
+ this.connective = connective;
+ this.queryParamCounter = queryParamCounter;
+
+ subParameters = new ArrayList<Parameters>();
+ negatedParameters = new ArrayList<Parameters>();
+ expressions = new ArrayList<String>();
+ queryParamValues = new HashMap<String, Object>();
+ }
+
+ private String generateQueryParam() {
+ return "_p" + queryParamCounter.getAndIncrease();
+ }
+
+ public Parameters addSubParameters(String newConnective) {
+ if (connective.equals(newConnective)) {
+ return this;
+ } else {
+ Parameters newParams = new Parameters(alias, newConnective, queryParamCounter);
+ subParameters.add(newParams);
+ return newParams;
+ }
+ }
+
+ public Parameters addNegatedParameters() {
+ Parameters newParams = new Parameters(alias, "and", queryParamCounter);
+ negatedParameters.add(newParams);
+ return newParams;
+ }
+
+ public void addWhere(String left, String op, String right) {
+ addWhere(left, true, op, right, true);
+ }
+
+ public void addWhere(String left, boolean addAliasLeft, String op, String right, boolean addAliasRight) {
+ StringBuilder expression = new StringBuilder();
+
+ if (addAliasLeft) { expression.append(alias).append("."); }
+ expression.append(left);
+
+ expression.append(" ").append(op).append(" ");
+
+ if (addAliasRight) { expression.append(alias).append("."); }
+ expression.append(right);
+
+ expressions.add(expression.toString());
+ }
+
+ public void addWhereWithParam(String left, String op, Object paramValue) {
+ addWhereWithParam(left, true, op, paramValue);
+ }
+
+ public void addWhereWithParam(String left, boolean addAlias, String op, Object paramValue) {
+ StringBuilder expression = new StringBuilder();
+
+ if (addAlias) { expression.append(alias).append("."); }
+ expression.append(left);
+
+ expression.append(" ").append(op).append(" ");
+
+ String paramName = generateQueryParam();
+ queryParamValues.put(paramName, paramValue);
+ expression.append(":").append(paramName);
+
+ expressions.add(expression.toString());
+ }
+
+ public void addWhereWithParams(String left, String opStart, Object[] paramValues, String opEnd) {
+ StringBuilder expression = new StringBuilder();
+
+ expression.append(alias).append(".").append(left).append(" ").append(opStart);
+
+ for (int i=0; i<paramValues.length; i++) {
+ Object paramValue = paramValues[i];
+ String paramName = generateQueryParam();
+ queryParamValues.put(paramName, paramValue);
+ expression.append(":").append(paramName);
+
+ if (i != paramValues.length-1) {
+ expression.append(", ");
+ }
+ }
+
+ expression.append(opEnd);
+
+ expressions.add(expression.toString());
+ }
+
+ public void addWhere(String left, String op, QueryBuilder right) {
+ StringBuilder expression = new StringBuilder();
+
+ expression.append(alias).append(".").append(left);
+
+ expression.append(" ").append(op).append(" ");
+
+ expression.append("(");
+ right.build(expression, queryParamValues);
+ expression.append(")");
+
+ expressions.add(expression.toString());
+ }
+
+ private void append(StringBuilder sb, String toAppend, MutableBoolean isFirst) {
+ if (!isFirst.isSet()) {
+ sb.append(" ").append(connective).append(" ");
+ }
+
+ sb.append(toAppend);
+
+ isFirst.unset();
+ }
+
+ public boolean isEmpty() {
+ return expressions.size() == 0 && subParameters.size() == 0 && negatedParameters.size() == 0;
+ }
+
+ public void build(StringBuilder sb, Map<String, Object> paramValues) {
+ MutableBoolean isFirst = new MutableBoolean(true);
+
+ for (String expression : expressions) {
+ append(sb, expression, isFirst);
+ }
+
+ for (Parameters sub : subParameters) {
+ append(sb, "(", isFirst);
+ sub.build(sb, paramValues);
+ sb.append(")");
+ }
+
+ for (Parameters negated : negatedParameters) {
+ append(sb, "not (", isFirst);
+ negated.build(sb, paramValues);
+ sb.append(")");
+ }
+
+ paramValues.putAll(queryParamValues);
+ }
+}
Added: trunk/src/main/org/jboss/envers/query/impl/QueryBuilder.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/impl/QueryBuilder.java (rev 0)
+++ trunk/src/main/org/jboss/envers/query/impl/QueryBuilder.java 2008-09-02 11:42:56 UTC (rev 137)
@@ -0,0 +1,138 @@
+package org.jboss.envers.query.impl;
+
+import org.jboss.envers.tools.MutableInteger;
+import org.jboss.envers.tools.Pair;
+import org.jboss.envers.tools.StringTools;
+
+import java.util.Map;
+import java.util.List;
+import java.util.ArrayList;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+public class QueryBuilder {
+ private final String entityName;
+ private final String alias;
+
+ /**
+ * For use by alias generator (in case an alias is not provided by the user).
+ */
+ private final MutableInteger aliasCounter;
+ private final MutableInteger paramCounter;
+ private final Parameters parameters;
+
+ private final List<Pair<String, String>> froms;
+ private final List<Pair<String, Boolean>> orders;
+ private final List<String> projections;
+
+ public QueryBuilder(String entityName, String alias, MutableInteger aliasCounter, MutableInteger paramCounter) {
+ this.entityName = entityName;
+ this.alias = alias;
+ this.aliasCounter = aliasCounter;
+ this.paramCounter = paramCounter;
+
+ parameters = new Parameters(alias, "and", paramCounter);
+
+ froms = new ArrayList<Pair<String, String>>();
+ orders = new ArrayList<Pair<String, Boolean>>();
+ projections = new ArrayList<String>();
+
+ addFrom(entityName, alias);
+ }
+
+ public void addFrom(String entityName, String alias) {
+ froms.add(Pair.make(entityName, alias));
+ }
+
+ private String generateAlias() {
+ return "_e" + aliasCounter.getAndIncrease();
+ }
+
+ /**
+ * @return A sub-query builder for the same entity (with an auto-generated alias).
+ */
+ public QueryBuilder newSubQueryBuilder() {
+ return newSubQueryBuilder(entityName, generateAlias());
+ }
+
+ /**
+ * @param entityName Entity name, which will be the main entity for the sub-query.
+ * @param alias Alias of the entity, which can later be used in parameters.
+ * @return A sub-query builder for the given entity, with the given alias.
+ */
+ public QueryBuilder newSubQueryBuilder(String entityName, String alias) {
+ return new QueryBuilder(entityName, alias, aliasCounter, paramCounter);
+ }
+
+ public Parameters getRootParameters() {
+ return parameters;
+ }
+
+ public void addOrder(String propertyName, boolean ascending) {
+ orders.add(Pair.make(propertyName, ascending));
+ }
+
+ public void addProjection(String function, String propertyName) {
+ addProjection(function, propertyName, false);
+ }
+
+ public void addProjection(String function, String propertyName, boolean distinct) {
+ if (function == null) {
+ projections.add((distinct ? "distinct " : "") + alias + "." + propertyName);
+ } else {
+ projections.add(function + "(" + (distinct ? "distinct " : "") + alias + "." + propertyName + ")");
+ }
+ }
+
+ public void build(StringBuilder sb, Map<String, Object> paramValues) {
+ sb.append("select ");
+ if (projections.size() > 0) {
+ // all projections separated with commas
+ StringTools.append(sb, projections.iterator(), ", ");
+ } else {
+ // all aliases separated with commas
+ StringTools.append(sb, getAliasList().iterator(), ", ");
+ }
+ sb.append(" from ");
+ // all from entities with aliases, separated with commas
+ StringTools.append(sb, getFromList().iterator(), ", ");
+ // where part - parameters
+ if (!parameters.isEmpty()) {
+ sb.append(" where ");
+ parameters.build(sb, paramValues);
+ }
+ // orders
+ if (orders.size() > 0) {
+ sb.append(" order by ");
+ StringTools.append(sb, getOrderList().iterator(), ", ");
+ }
+ }
+
+ private List<String> getAliasList() {
+ List<String> aliasList = new ArrayList<String>();
+ for (Pair<String, String> from : froms) {
+ aliasList.add(from.getSecond());
+ }
+
+ return aliasList;
+ }
+
+ private List<String> getFromList() {
+ List<String> fromList = new ArrayList<String>();
+ for (Pair<String, String> from : froms) {
+ fromList.add(from.getFirst() + " " + from.getSecond());
+ }
+
+ return fromList;
+ }
+
+ private List<String> getOrderList() {
+ List<String> orderList = new ArrayList<String>();
+ for (Pair<String, Boolean> order : orders) {
+ orderList.add(order.getFirst() + " " + (order.getSecond() ? "asc" : "desc"));
+ }
+
+ return orderList;
+ }
+}
Modified: trunk/src/main/org/jboss/envers/query/impl/RevisionsOfEntityQuery.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/impl/RevisionsOfEntityQuery.java 2008-08-31 08:46:36 UTC (rev 136)
+++ trunk/src/main/org/jboss/envers/query/impl/RevisionsOfEntityQuery.java 2008-09-02 11:42:56 UTC (rev 137)
@@ -27,8 +27,6 @@
import org.jboss.envers.RevisionType;
import org.jboss.envers.configuration.VersionsEntitiesConfiguration;
import org.jboss.envers.configuration.VersionsConfiguration;
-import org.hibernate.criterion.Order;
-import org.hibernate.criterion.Property;
import org.hibernate.proxy.HibernateProxy;
import java.util.List;
@@ -81,26 +79,26 @@
*/
if (!selectDeletedEntities) {
// e.revision_type != DEL AND
- versionsCriteria.add(Property.forName(verEntCfg.getRevisionTypePropName()).ne(RevisionType.DEL));
+ qb.getRootParameters().addWhereWithParam(verEntCfg.getRevisionTypePropName(), "<>", RevisionType.DEL);
}
// all specified conditions, transformed
for (VersionsCriterion criterion : criterions) {
- versionsCriteria.add(criterion.toVersionsCriterion(verCfg, entityName));
+ criterion.addToQuery(verCfg, entityName, qb, qb.getRootParameters());
}
if (!hasProjection && !hasOrder) {
String revisionPropertyPath = verEntCfg.getRevisionPropPath();
- versionsCriteria.addOrder(Order.asc(revisionPropertyPath));
+ qb.addOrder(revisionPropertyPath, true);
}
// TODO
if (!selectEntitiesOnly) {
//versionsCriteria.setFetchMode("e._revision", FetchMode.JOIN);
- //versionsCriteria.createCriteria("e.originalId._revision").add(Property.forName("revision_id").eq(1));
+ //versionsCriteria.createCriteria("e.originalId._revision").add(Property.forName("id").eq(1));
}
- List<Map> queryResult = versionsCriteria.list();
+ List<Map> queryResult = listQuery();
if (hasProjection) {
return queryResult;
} else {
Modified: trunk/src/main/org/jboss/envers/query/order/RevisionVersionsOrder.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/order/RevisionVersionsOrder.java 2008-08-31 08:46:36 UTC (rev 136)
+++ trunk/src/main/org/jboss/envers/query/order/RevisionVersionsOrder.java 2008-09-02 11:42:56 UTC (rev 137)
@@ -21,8 +21,8 @@
*/
package org.jboss.envers.query.order;
-import org.hibernate.criterion.Order;
import org.jboss.envers.configuration.VersionsConfiguration;
+import org.jboss.envers.tools.Pair;
/**
* @author Adam Warski (adam at warski dot org)
@@ -34,13 +34,8 @@
this.asc = asc;
}
- public Order getOrder(VersionsConfiguration verCfg, String entityName) {
+ public Pair<String, Boolean> getOrderData(VersionsConfiguration verCfg) {
String revisionPropPath = verCfg.getVerEntCfg().getRevisionPropPath();
-
- if (asc) {
- return Order.asc(revisionPropPath);
- } else {
- return Order.desc(revisionPropPath);
- }
+ return Pair.make(revisionPropPath, asc);
}
}
Modified: trunk/src/main/org/jboss/envers/query/order/VersionsOrder.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/order/VersionsOrder.java 2008-08-31 08:46:36 UTC (rev 136)
+++ trunk/src/main/org/jboss/envers/query/order/VersionsOrder.java 2008-09-02 11:42:56 UTC (rev 137)
@@ -21,13 +21,12 @@
*/
package org.jboss.envers.query.order;
-import org.hibernate.criterion.Order;
-import org.jboss.envers.reader.VersionsReaderImplementor;
import org.jboss.envers.configuration.VersionsConfiguration;
+import org.jboss.envers.tools.Pair;
/**
* @author Adam Warski (adam at warski dot org)
*/
public interface VersionsOrder {
- public Order getOrder(VersionsConfiguration verCfg, String entityName);
+ Pair<String, Boolean> getOrderData(VersionsConfiguration verCfg);
}
Deleted: trunk/src/main/org/jboss/envers/query/projection/DistinctVersionsProjection.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/projection/DistinctVersionsProjection.java 2008-08-31 08:46:36 UTC (rev 136)
+++ trunk/src/main/org/jboss/envers/query/projection/DistinctVersionsProjection.java 2008-09-02 11:42:56 UTC (rev 137)
@@ -1,41 +0,0 @@
-/*
- * Envers. http://www.jboss.org/envers
- *
- * Copyright 2008 Red Hat Middleware, LLC. All rights reserved.
- *
- * 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, v. 2.1.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT A 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, v.2.1 along with this distribution; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301, USA.
- *
- * Red Hat Author(s): Adam Warski
- */
-package org.jboss.envers.query.projection;
-
-import org.hibernate.criterion.Projection;
-import org.hibernate.criterion.Projections;
-import org.jboss.envers.configuration.VersionsConfiguration;
-
-/**
- * @author Adam Warski (adam at warski dot org)
- */
-public class DistinctVersionsProjection implements VersionsProjection {
- private final VersionsProjection projection;
-
- public DistinctVersionsProjection(VersionsProjection projection) {
- this.projection = projection;
- }
-
- public Projection getProjection(VersionsConfiguration verCfg, String entityName) {
- return Projections.distinct(projection.getProjection(verCfg, entityName));
- }
-}
Deleted: trunk/src/main/org/jboss/envers/query/projection/ProjectionWrapper.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/projection/ProjectionWrapper.java 2008-08-31 08:46:36 UTC (rev 136)
+++ trunk/src/main/org/jboss/envers/query/projection/ProjectionWrapper.java 2008-09-02 11:42:56 UTC (rev 137)
@@ -1,41 +0,0 @@
-/*
- * Envers. http://www.jboss.org/envers
- *
- * Copyright 2008 Red Hat Middleware, LLC. All rights reserved.
- *
- * 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, v. 2.1.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT A 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, v.2.1 along with this distribution; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301, USA.
- *
- * Red Hat Author(s): Adam Warski
- */
-package org.jboss.envers.query.projection;
-
-import org.hibernate.criterion.Projection;
-import org.jboss.envers.configuration.VersionsConfiguration;
-
-/**
- * Wraps a hibernate projection so that it can be used as a versions projection.
- * @author Adam Warski (adam at warski dot org)
- */
-public class ProjectionWrapper implements VersionsProjection {
- private final Projection wrapped;
-
- public ProjectionWrapper(Projection wrapped) {
- this.wrapped = wrapped;
- }
-
- public Projection getProjection(VersionsConfiguration verCfg, String entityName) {
- return wrapped;
- }
-}
Modified: trunk/src/main/org/jboss/envers/query/projection/RevisionVersionsProjection.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/projection/RevisionVersionsProjection.java 2008-08-31 08:46:36 UTC (rev 136)
+++ trunk/src/main/org/jboss/envers/query/projection/RevisionVersionsProjection.java 2008-09-02 11:42:56 UTC (rev 137)
@@ -21,9 +21,8 @@
*/
package org.jboss.envers.query.projection;
-import org.hibernate.criterion.Projection;
-import org.hibernate.criterion.Projections;
import org.jboss.envers.configuration.VersionsConfiguration;
+import org.jboss.envers.tools.Triple;
/**
* @author Adam Warski (adam at warski dot org)
@@ -33,7 +32,8 @@
MAX,
MIN,
COUNT,
- COUNT_DISTINCT
+ COUNT_DISTINCT,
+ DISTINCT
}
private final ProjectionType type;
@@ -42,14 +42,15 @@
this.type = type;
}
- public Projection getProjection(VersionsConfiguration verCfg, String entityName) {
+ public Triple<String, String, Boolean> getProjectionData(VersionsConfiguration verCfg) {
String revisionPropPath = verCfg.getVerEntCfg().getRevisionPropPath();
switch (type) {
- case MAX: return Projections.max(revisionPropPath);
- case MIN: return Projections.min(revisionPropPath);
- case COUNT: return Projections.count(revisionPropPath);
- case COUNT_DISTINCT: return Projections.countDistinct(revisionPropPath);
+ 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 + ".");
Modified: trunk/src/main/org/jboss/envers/query/projection/VersionsProjection.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/projection/VersionsProjection.java 2008-08-31 08:46:36 UTC (rev 136)
+++ trunk/src/main/org/jboss/envers/query/projection/VersionsProjection.java 2008-09-02 11:42:56 UTC (rev 137)
@@ -22,11 +22,12 @@
package org.jboss.envers.query.projection;
import org.jboss.envers.configuration.VersionsConfiguration;
-import org.hibernate.criterion.Projection;
+import org.jboss.envers.tools.Pair;
+import org.jboss.envers.tools.Triple;
/**
* @author Adam Warski (adam at warski dot org)
*/
public interface VersionsProjection {
- public Projection getProjection(VersionsConfiguration verCfg, String entityName);
+ Triple<String, String, Boolean> getProjectionData(VersionsConfiguration verCfg);
}
Deleted: trunk/src/main/org/jboss/envers/query/projection/VersionsProjectionList.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/projection/VersionsProjectionList.java 2008-08-31 08:46:36 UTC (rev 136)
+++ trunk/src/main/org/jboss/envers/query/projection/VersionsProjectionList.java 2008-09-02 11:42:56 UTC (rev 137)
@@ -1,61 +0,0 @@
-/*
- * Envers. http://www.jboss.org/envers
- *
- * Copyright 2008 Red Hat Middleware, LLC. All rights reserved.
- *
- * 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, v. 2.1.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT A 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, v.2.1 along with this distribution; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301, USA.
- *
- * Red Hat Author(s): Adam Warski
- */
-package org.jboss.envers.query.projection;
-
-import org.hibernate.criterion.Projection;
-import org.hibernate.criterion.Projections;
-import org.hibernate.criterion.ProjectionList;
-import org.jboss.envers.configuration.VersionsConfiguration;
-
-import java.util.List;
-import java.util.ArrayList;
-
-/**
- * @author Adam Warski (adam at warski dot org)
- */
-public class VersionsProjectionList implements VersionsProjection {
- private final List<VersionsProjection> projections;
-
- public VersionsProjectionList() {
- projections = new ArrayList<VersionsProjection>();
- }
-
- public VersionsProjectionList add(VersionsProjection projection) {
- projections.add(projection);
- return this;
- }
-
- public VersionsProjectionList add(Projection projection) {
- projections.add(new ProjectionWrapper(projection));
- return this;
- }
-
- public Projection getProjection(VersionsConfiguration verCfg, String entityName) {
- ProjectionList list = Projections.projectionList();
-
- for (VersionsProjection projection : projections) {
- list.add(projection.getProjection(verCfg, entityName));
- }
-
- return list;
- }
-}
Modified: trunk/src/main/org/jboss/envers/reader/VersionsReaderImpl.java
===================================================================
--- trunk/src/main/org/jboss/envers/reader/VersionsReaderImpl.java 2008-08-31 08:46:36 UTC (rev 136)
+++ trunk/src/main/org/jboss/envers/reader/VersionsReaderImpl.java 2008-09-02 11:42:56 UTC (rev 137)
@@ -108,7 +108,7 @@
}
return createQuery().forRevisionsOfEntity(cls, false, true)
- .setProjection(RevisionProperty.revisionNumber())
+ .addProjection(RevisionProperty.revisionNumber())
.add(VersionsRestrictions.idEq(primaryKey))
.getResultList();
}
Copied: trunk/src/main/org/jboss/envers/tools/MutableInteger.java (from rev 132, trunk/src/main/org/jboss/envers/tools/MutableBoolean.java)
===================================================================
--- trunk/src/main/org/jboss/envers/tools/MutableInteger.java (rev 0)
+++ trunk/src/main/org/jboss/envers/tools/MutableInteger.java 2008-09-02 11:42:56 UTC (rev 137)
@@ -0,0 +1,48 @@
+/*
+ * Envers. http://www.jboss.org/envers
+ *
+ * Copyright 2008 Red Hat Middleware, LLC. All rights reserved.
+ *
+ * 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, v. 2.1.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT A 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, v.2.1 along with this distribution; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ *
+ * Red Hat Author(s): Adam Warski
+ */
+package org.jboss.envers.tools;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+public class MutableInteger {
+ private int value;
+
+ public MutableInteger() {
+ }
+
+ public MutableInteger(int value) {
+ this.value = value;
+ }
+
+ public int get() {
+ return value;
+ }
+
+ public void set(int value) {
+ this.value = value;
+ }
+
+ public int getAndIncrease() {
+ return value++;
+ }
+}
\ No newline at end of file
Property changes on: trunk/src/main/org/jboss/envers/tools/MutableInteger.java
___________________________________________________________________
Name: svn:mergeinfo
+
Modified: trunk/src/main/org/jboss/envers/tools/StringTools.java
===================================================================
--- trunk/src/main/org/jboss/envers/tools/StringTools.java 2008-08-31 08:46:36 UTC (rev 136)
+++ trunk/src/main/org/jboss/envers/tools/StringTools.java 2008-09-02 11:42:56 UTC (rev 137)
@@ -21,6 +21,8 @@
*/
package org.jboss.envers.tools;
+import java.util.Iterator;
+
/**
* @author Adam Warski (adam at warski dot org)
*/
@@ -29,6 +31,11 @@
return s == null || "".equals(s);
}
+ /**
+ * @param s String, from which to get the last component.
+ * @return The last component of the dot-separated string <code>s</code>. For example, for a string
+ * "a.b.c", the result is "c".
+ */
public static String getLastComponent(String s) {
if (s == null) {
return null;
@@ -41,4 +48,25 @@
return s.substring(lastDot + 1);
}
}
+
+ /**
+ * To the given string builder, appends all strings in the given iterator, separating them with the given
+ * separator. For example, for an interator "a" "b" "c" and separator ":" the output is "a:b:c".
+ * @param sb String builder, to which to append.
+ * @param contents Strings to be appended.
+ * @param separator Separator between subsequent content.
+ */
+ public static void append(StringBuilder sb, Iterator<String> contents, String separator) {
+ boolean isFirst = true;
+
+ while (contents.hasNext()) {
+ if (!isFirst) {
+ sb.append(separator);
+ }
+
+ sb.append(contents.next());
+
+ isFirst = false;
+ }
+ }
}
Copied: trunk/src/main/org/jboss/envers/tools/Triple.java (from rev 132, trunk/src/main/org/jboss/envers/tools/Pair.java)
===================================================================
--- trunk/src/main/org/jboss/envers/tools/Triple.java (rev 0)
+++ trunk/src/main/org/jboss/envers/tools/Triple.java 2008-09-02 11:42:56 UTC (rev 137)
@@ -0,0 +1,93 @@
+/*
+ * Envers. http://www.jboss.org/envers
+ *
+ * Copyright 2008 Red Hat Middleware, LLC. All rights reserved.
+ *
+ * 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, v. 2.1.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT A 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, v.2.1 along with this distribution; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ *
+ * Red Hat Author(s): Adam Warski
+ */
+package org.jboss.envers.tools;
+
+/**
+ * A triple of objects.
+ * @param <T1>
+ * @param <T2>
+ * @param <T3>
+ * @author Adam Warski (adamw(a)aster.pl)
+ */
+public class Triple<T1, T2, T3> {
+ private T1 obj1;
+ private T2 obj2;
+ private T3 obj3;
+
+ public Triple() {
+ }
+
+ public Triple(T1 obj1, T2 obj2, T3 obj3) {
+ this.obj1 = obj1;
+ this.obj2 = obj2;
+ this.obj3 = obj3;
+ }
+
+ public T1 getFirst() {
+ return obj1;
+ }
+
+ public T2 getSecond() {
+ return obj2;
+ }
+
+ public T3 getThird() {
+ return obj3;
+ }
+
+ public void setFirst(T1 obj1) {
+ this.obj1 = obj1;
+ }
+
+ public void setSecond(T2 obj2) {
+ this.obj2 = obj2;
+ }
+
+ public void setThird(T3 obj3) {
+ this.obj3 = obj3;
+ }
+
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (!(o instanceof Triple)) return false;
+
+ Triple triple = (Triple) o;
+
+ if (obj1 != null ? !obj1.equals(triple.obj1) : triple.obj1 != null) return false;
+ if (obj2 != null ? !obj2.equals(triple.obj2) : triple.obj2 != null) return false;
+ if (obj3 != null ? !obj3.equals(triple.obj3) : triple.obj3 != null) return false;
+
+ return true;
+ }
+
+ public int hashCode() {
+ int result;
+ result = (obj1 != null ? obj1.hashCode() : 0);
+ result = 31 * result + (obj2 != null ? obj2.hashCode() : 0);
+ result = 31 * result + (obj3 != null ? obj3.hashCode() : 0);
+ return result;
+ }
+
+ public static <T1, T2, T3> Triple<T1, T2, T3> make(T1 obj1, T2 obj2, T3 obj3) {
+ return new Triple<T1, T2, T3>(obj1, obj2, obj3);
+ }
+}
\ No newline at end of file
Property changes on: trunk/src/main/org/jboss/envers/tools/Triple.java
___________________________________________________________________
Name: svn:mergeinfo
+
Modified: trunk/src/test/org/jboss/envers/test/integration/query/AggregateQuery.java
===================================================================
--- trunk/src/test/org/jboss/envers/test/integration/query/AggregateQuery.java 2008-08-31 08:46:36 UTC (rev 136)
+++ trunk/src/test/org/jboss/envers/test/integration/query/AggregateQuery.java 2008-09-02 11:42:56 UTC (rev 137)
@@ -3,7 +3,6 @@
import org.jboss.envers.test.integration.AbstractEntityTest;
import org.jboss.envers.test.entities.IntTestEntity;
import org.hibernate.ejb.Ejb3Configuration;
-import org.hibernate.criterion.Projections;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
@@ -60,23 +59,20 @@
public void testEntitiesAvgMaxQuery() {
Object[] ver1 = (Object[]) getVersionsReader().createQuery()
.forEntitiesAtRevision(IntTestEntity.class, 1)
- .setProjection(Projections.projectionList()
- .add(Projections.max("number"))
- .add(Projections.avg("number")))
+ .addProjection("max", "number")
+ .addProjection("avg", "number")
.getSingleResult();
Object[] ver2 = (Object[]) getVersionsReader().createQuery()
.forEntitiesAtRevision(IntTestEntity.class, 2)
- .setProjection(Projections.projectionList()
- .add(Projections.max("number"))
- .add(Projections.avg("number")))
+ .addProjection("max", "number")
+ .addProjection("avg", "number")
.getSingleResult();
Object[] ver3 = (Object[]) getVersionsReader().createQuery()
.forEntitiesAtRevision(IntTestEntity.class, 3)
- .setProjection(Projections.projectionList()
- .add(Projections.max("number"))
- .add(Projections.avg("number")))
+ .addProjection("max", "number")
+ .addProjection("avg", "number")
.getSingleResult();
assert (Integer) ver1[0] == 10;
Modified: trunk/src/test/org/jboss/envers/test/integration/query/DeletedEntities.java
===================================================================
--- trunk/src/test/org/jboss/envers/test/integration/query/DeletedEntities.java 2008-08-31 08:46:36 UTC (rev 136)
+++ trunk/src/test/org/jboss/envers/test/integration/query/DeletedEntities.java 2008-09-02 11:42:56 UTC (rev 137)
@@ -5,7 +5,6 @@
import org.jboss.envers.query.VersionsRestrictions;
import org.jboss.envers.RevisionType;
import org.hibernate.ejb.Ejb3Configuration;
-import org.hibernate.criterion.Projections;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
@@ -54,10 +53,10 @@
assert getVersionsReader().createQuery().forEntitiesAtRevision(StrIntTestEntity.class, 2)
.getResultList().size() == 1;
- assert (Integer) getVersionsReader().createQuery().forEntitiesAtRevision(StrIntTestEntity.class, 1)
- .setProjection(Projections.count("originalId.id")).getResultList().get(0) == 2;
- assert (Integer) getVersionsReader().createQuery().forEntitiesAtRevision(StrIntTestEntity.class, 2)
- .setProjection(Projections.count("originalId.id")).getResultList().get(0) == 1;
+ assert (Long) getVersionsReader().createQuery().forEntitiesAtRevision(StrIntTestEntity.class, 1)
+ .addProjection("count", "originalId.id").getResultList().get(0) == 2;
+ assert (Long) getVersionsReader().createQuery().forEntitiesAtRevision(StrIntTestEntity.class, 2)
+ .addProjection("count", "originalId.id").getResultList().get(0) == 1;
}
@Test
Modified: trunk/src/test/org/jboss/envers/test/integration/query/MaximalizePropertyQuery.java
===================================================================
--- trunk/src/test/org/jboss/envers/test/integration/query/MaximalizePropertyQuery.java 2008-08-31 08:46:36 UTC (rev 136)
+++ trunk/src/test/org/jboss/envers/test/integration/query/MaximalizePropertyQuery.java 2008-09-02 11:42:56 UTC (rev 137)
@@ -79,7 +79,7 @@
public void testMaximizeWithIdEq() {
List revs_id1 = getVersionsReader().createQuery()
.forRevisionsOfEntity(StrIntTestEntity.class, false, true)
- .setProjection(RevisionProperty.revisionNumber())
+ .addProjection(RevisionProperty.revisionNumber())
.add(VersionsRestrictions.maximizeProperty("number")
.add(VersionsRestrictions.idEq(id2)))
.getResultList();
@@ -91,7 +91,7 @@
public void testMinimizeWithPropertyEq() {
List result = getVersionsReader().createQuery()
.forRevisionsOfEntity(StrIntTestEntity.class, false, true)
- .setProjection(RevisionProperty.revisionNumber())
+ .addProjection(RevisionProperty.revisionNumber())
.add(VersionsRestrictions.minimizeProperty("number")
.add(VersionsRestrictions.eq("str1", "a")))
.getResultList();
Modified: trunk/src/test/org/jboss/envers/test/integration/query/OrderByLimitQuery.java
===================================================================
--- trunk/src/test/org/jboss/envers/test/integration/query/OrderByLimitQuery.java 2008-08-31 08:46:36 UTC (rev 136)
+++ trunk/src/test/org/jboss/envers/test/integration/query/OrderByLimitQuery.java 2008-09-02 11:42:56 UTC (rev 137)
@@ -3,8 +3,6 @@
import org.jboss.envers.test.integration.AbstractEntityTest;
import org.jboss.envers.test.entities.IntTestEntity;
import org.hibernate.ejb.Ejb3Configuration;
-import org.hibernate.criterion.Projections;
-import org.hibernate.criterion.Order;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
@@ -70,21 +68,21 @@
public void testEntitiesOrderLimitByQueryRev1() {
List res_0_to_1 = getVersionsReader().createQuery()
.forEntitiesAtRevision(IntTestEntity.class, 1)
- .addOrder(Order.desc("number"))
+ .addOrder("number", false)
.setFirstResult(0)
.setMaxResults(2)
.getResultList();
List res_2_to_3 = getVersionsReader().createQuery()
.forEntitiesAtRevision(IntTestEntity.class, 1)
- .addOrder(Order.desc("number"))
+ .addOrder("number", false)
.setFirstResult(2)
.setMaxResults(2)
.getResultList();
List res_empty = getVersionsReader().createQuery()
.forEntitiesAtRevision(IntTestEntity.class, 1)
- .addOrder(Order.desc("number"))
+ .addOrder("number", false)
.setFirstResult(4)
.setMaxResults(2)
.getResultList();
@@ -98,21 +96,21 @@
public void testEntitiesOrderLimitByQueryRev2() {
List res_0_to_1 = getVersionsReader().createQuery()
.forEntitiesAtRevision(IntTestEntity.class, 2)
- .addOrder(Order.desc("number"))
+ .addOrder("number", false)
.setFirstResult(0)
.setMaxResults(2)
.getResultList();
List res_2_to_3 = getVersionsReader().createQuery()
.forEntitiesAtRevision(IntTestEntity.class, 2)
- .addOrder(Order.desc("number"))
+ .addOrder("number", false)
.setFirstResult(2)
.setMaxResults(2)
.getResultList();
List res_4 = getVersionsReader().createQuery()
.forEntitiesAtRevision(IntTestEntity.class, 2)
- .addOrder(Order.desc("number"))
+ .addOrder("number", false)
.setFirstResult(4)
.setMaxResults(2)
.getResultList();
Modified: trunk/src/test/org/jboss/envers/test/integration/query/RevisionConstraintQuery.java
===================================================================
--- trunk/src/test/org/jboss/envers/test/integration/query/RevisionConstraintQuery.java 2008-08-31 08:46:36 UTC (rev 136)
+++ trunk/src/test/org/jboss/envers/test/integration/query/RevisionConstraintQuery.java 2008-09-02 11:42:56 UTC (rev 137)
@@ -4,7 +4,6 @@
import org.jboss.envers.test.entities.StrIntTestEntity;
import org.jboss.envers.query.VersionsRestrictions;
import org.jboss.envers.query.RevisionProperty;
-import org.jboss.envers.query.VersionsProjections;
import org.hibernate.ejb.Ejb3Configuration;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
@@ -79,7 +78,7 @@
public void testRevisionsLtQuery() {
List result = getVersionsReader().createQuery()
.forRevisionsOfEntity(StrIntTestEntity.class, false, true)
- .setProjection(VersionsProjections.distinct(RevisionProperty.revisionNumber()))
+ .addProjection(RevisionProperty.distinct())
.add(RevisionProperty.lt(3))
.getResultList();
@@ -90,7 +89,7 @@
public void testRevisionsGeQuery() {
List result = getVersionsReader().createQuery()
.forRevisionsOfEntity(StrIntTestEntity.class, false, true)
- .setProjection(VersionsProjections.distinct(RevisionProperty.revisionNumber()))
+ .addProjection(RevisionProperty.distinct())
.add(RevisionProperty.ge(2))
.getResultList();
@@ -101,7 +100,7 @@
public void testRevisionsLeWithPropertyQuery() {
List result = getVersionsReader().createQuery()
.forRevisionsOfEntity(StrIntTestEntity.class, false, true)
- .setProjection(RevisionProperty.revisionNumber())
+ .addProjection(RevisionProperty.revisionNumber())
.add(RevisionProperty.le(3))
.add(VersionsRestrictions.eq("str1", "a"))
.getResultList();
@@ -113,7 +112,7 @@
public void testRevisionsGtWithPropertyQuery() {
List result = getVersionsReader().createQuery()
.forRevisionsOfEntity(StrIntTestEntity.class, false, true)
- .setProjection(RevisionProperty.revisionNumber())
+ .addProjection(RevisionProperty.revisionNumber())
.add(RevisionProperty.gt(1))
.add(VersionsRestrictions.lt("number", 10))
.getResultList();
@@ -125,24 +124,24 @@
public void testRevisionProjectionQuery() {
Object[] result = (Object[]) getVersionsReader().createQuery()
.forRevisionsOfEntity(StrIntTestEntity.class, false, true)
- .setProjection(
- VersionsProjections.projectionList()
- .add(RevisionProperty.max())
- .add(RevisionProperty.count())
- .add(RevisionProperty.min()))
+ .addProjection(RevisionProperty.max())
+ .addProjection(RevisionProperty.count())
+ .addProjection(RevisionProperty.countDistinct())
+ .addProjection(RevisionProperty.min())
.add(VersionsRestrictions.idEq(id1))
.getSingleResult();
assert (Integer) result[0] == 4;
- assert (Integer) result[1] == 4;
- assert (Integer) result[2] == 1;
+ assert (Long) result[1] == 4;
+ assert (Long) result[2] == 4;
+ assert (Integer) result[3] == 1;
}
@Test
public void testRevisionOrderQuery() {
List result = getVersionsReader().createQuery()
.forRevisionsOfEntity(StrIntTestEntity.class, false, true)
- .setProjection(RevisionProperty.revisionNumber())
+ .addProjection(RevisionProperty.revisionNumber())
.add(VersionsRestrictions.idEq(id1))
.addOrder(RevisionProperty.desc())
.getResultList();
@@ -155,10 +154,10 @@
// The query shouldn't be ordered as always, otherwise - we get an exception.
Object result = getVersionsReader().createQuery()
.forRevisionsOfEntity(StrIntTestEntity.class, false, true)
- .setProjection(RevisionProperty.count())
+ .addProjection(RevisionProperty.count())
.add(VersionsRestrictions.idEq(id1))
.getSingleResult();
- assert (Integer) result == 4;
+ assert (Long) result == 4;
}
}
\ No newline at end of file
Modified: trunk/src/test/org/jboss/envers/test/integration/query/SimpleQuery.java
===================================================================
--- trunk/src/test/org/jboss/envers/test/integration/query/SimpleQuery.java 2008-08-31 08:46:36 UTC (rev 136)
+++ trunk/src/test/org/jboss/envers/test/integration/query/SimpleQuery.java 2008-09-02 11:42:56 UTC (rev 137)
@@ -142,21 +142,21 @@
public void testRevisionsPropertyEqQuery() {
List revs_id1 = getVersionsReader().createQuery()
.forRevisionsOfEntity(StrIntTestEntity.class, false, true)
- .setProjection(RevisionProperty.revisionNumber())
+ .addProjection(RevisionProperty.revisionNumber())
.add(VersionsRestrictions.le("str1", "a"))
.add(VersionsRestrictions.idEq(id1))
.getResultList();
List revs_id2 = getVersionsReader().createQuery()
.forRevisionsOfEntity(StrIntTestEntity.class, false, true)
- .setProjection(RevisionProperty.revisionNumber())
+ .addProjection(RevisionProperty.revisionNumber())
.add(VersionsRestrictions.le("str1", "a"))
.add(VersionsRestrictions.idEq(id2))
.getResultList();
List revs_id3 = getVersionsReader().createQuery()
.forRevisionsOfEntity(StrIntTestEntity.class, false, true)
- .setProjection(RevisionProperty.revisionNumber())
+ .addProjection(RevisionProperty.revisionNumber())
.add(VersionsRestrictions.le("str1", "a"))
.add(VersionsRestrictions.idEq(id3))
.getResultList();
@@ -205,7 +205,7 @@
public void testSelectRevisionTypeQuery() {
List result = getVersionsReader().createQuery()
.forRevisionsOfEntity(StrIntTestEntity.class, false, true)
- .setProjection(RevisionTypeProperty.revisionType())
+ .addProjection(RevisionTypeProperty.revisionType())
.add(VersionsRestrictions.idEq(id1))
.getResultList();
16 years, 4 months