Author: adamw
Date: 2008-10-13 14:02:35 -0400 (Mon, 13 Oct 2008)
New Revision: 178
Modified:
trunk/src/main/org/jboss/envers/configuration/GlobalConfiguration.java
trunk/src/main/org/jboss/envers/configuration/metadata/CollectionMetadataGenerator.java
trunk/src/main/org/jboss/envers/configuration/metadata/QueryGeneratorBuilder.java
trunk/src/main/org/jboss/envers/configuration/metadata/VersionsMetadataGenerator.java
trunk/src/main/org/jboss/envers/entities/mapper/relation/query/OneVersionsEntityQueryGenerator.java
trunk/src/main/org/jboss/envers/entities/mapper/relation/query/QueryGeneratorTools.java
trunk/src/main/org/jboss/envers/entities/mapper/relation/query/ThreeEntityQueryGenerator.java
trunk/src/main/org/jboss/envers/entities/mapper/relation/query/TwoEntityQueryGenerator.java
trunk/src/main/org/jboss/envers/query/impl/EntitiesAtRevisionQuery.java
Log:
ENVERS-57: workaround for HSQLDB
Modified: trunk/src/main/org/jboss/envers/configuration/GlobalConfiguration.java
===================================================================
--- trunk/src/main/org/jboss/envers/configuration/GlobalConfiguration.java 2008-10-13
14:43:11 UTC (rev 177)
+++ trunk/src/main/org/jboss/envers/configuration/GlobalConfiguration.java 2008-10-13
18:02:35 UTC (rev 178)
@@ -39,6 +39,14 @@
// Should the optimistic locking property of an entity be considered unversioned
private final boolean unversionedOptimisticLockingField;
+ /*
+ Which operator to use in correlated subqueries (when we want a property to be equal
to the result of
+ a correlated subquery, for example: e.p <operator> (select max(e2.p) where
e2.p2 = e.p2 ...).
+ Normally, this should be "=". However, HSQLDB has an issue related to
that, so as a workaround,
+ "in" is used. See {@link org.jboss.envers.test.various.HsqlTest}.
+ */
+ private final String correlatedSubqueryOperator;
+
public GlobalConfiguration(Properties properties) {
String generateRevisionsForCollectionsStr =
properties.getProperty("org.jboss.envers.revisionOnCollectionChange",
"true");
@@ -51,6 +59,9 @@
String ignoreOptimisticLockingPropertyStr =
properties.getProperty("org.jboss.envers.unversionedOptimisticLockingField",
"false");
unversionedOptimisticLockingField =
Boolean.parseBoolean(ignoreOptimisticLockingPropertyStr);
+
+ correlatedSubqueryOperator =
"org.hibernate.dialect.HSQLDialect".equals(
+ properties.getProperty("hibernate.dialect")) ? "in" :
"=";
}
public boolean isGenerateRevisionsForCollections() {
@@ -64,4 +75,8 @@
public boolean isUnversionedOptimisticLockingField() {
return unversionedOptimisticLockingField;
}
+
+ public String getCorrelatedSubqueryOperator() {
+ return correlatedSubqueryOperator;
+ }
}
Modified:
trunk/src/main/org/jboss/envers/configuration/metadata/CollectionMetadataGenerator.java
===================================================================
---
trunk/src/main/org/jboss/envers/configuration/metadata/CollectionMetadataGenerator.java 2008-10-13
14:43:11 UTC (rev 177)
+++
trunk/src/main/org/jboss/envers/configuration/metadata/CollectionMetadataGenerator.java 2008-10-13
18:02:35 UTC (rev 178)
@@ -154,8 +154,9 @@
MiddleComponentData indexComponentData = addIndex(null, null);
// Generating the query generator - it should read directly from the related
entity.
- RelationQueryGenerator queryGenerator = new
OneVersionsEntityQueryGenerator(mainGenerator.getVerEntCfg(),
- referencingIdData, referencedEntityName,
referencedIdMapping.getIdMapper());
+ RelationQueryGenerator queryGenerator = new
OneVersionsEntityQueryGenerator(mainGenerator.getGlobalCfg(),
+ mainGenerator.getVerEntCfg(), referencingIdData, referencedEntityName,
+ referencedIdMapping.getIdMapper());
// Creating common mapper data.
CommonCollectionMapperData commonCollectionMapperData = new
CommonCollectionMapperData(
@@ -256,8 +257,8 @@
// Creating a query generator builder, to which additional id data will be added,
in case this collection
// references some entities (either from the element or index). At the end, this
will be used to build
// a query generator to read the raw data collection from the middle table.
- QueryGeneratorBuilder queryGeneratorBuilder = new
QueryGeneratorBuilder(mainGenerator.getVerEntCfg(),
- referencingIdData, versionsMiddleEntityName);
+ QueryGeneratorBuilder queryGeneratorBuilder = new
QueryGeneratorBuilder(mainGenerator.getGlobalCfg(),
+ mainGenerator.getVerEntCfg(), referencingIdData,
versionsMiddleEntityName);
// Adding the XML mapping for the referencing entity, if the relation isn't
inverse.
if (middleEntityXml != null) {
@@ -317,7 +318,6 @@
return new MiddleComponentData(new
MiddleMapKeyPropertyComponentMapper(mapKey), currentIndex);
}
}
- // TODO: @MapKeyManyToMany
} else {
// No index - creating a dummy mapper.
return new MiddleComponentData(new MiddleDummyComponentMapper(), 0);
Modified:
trunk/src/main/org/jboss/envers/configuration/metadata/QueryGeneratorBuilder.java
===================================================================
---
trunk/src/main/org/jboss/envers/configuration/metadata/QueryGeneratorBuilder.java 2008-10-13
14:43:11 UTC (rev 177)
+++
trunk/src/main/org/jboss/envers/configuration/metadata/QueryGeneratorBuilder.java 2008-10-13
18:02:35 UTC (rev 178)
@@ -30,6 +30,7 @@
import org.jboss.envers.entities.mapper.relation.query.ThreeEntityQueryGenerator;
import org.jboss.envers.entities.mapper.relation.query.TwoEntityQueryGenerator;
import org.jboss.envers.configuration.VersionsEntitiesConfiguration;
+import org.jboss.envers.configuration.GlobalConfiguration;
import java.util.List;
import java.util.ArrayList;
@@ -40,13 +41,15 @@
* @author Adam Warski (adam at warski dot org)
*/
public final class QueryGeneratorBuilder {
+ private final GlobalConfiguration globalCfg;
private final VersionsEntitiesConfiguration verEntCfg;
private final MiddleIdData referencingIdData;
private final String versionsMiddleEntityName;
private final List<MiddleIdData> idDatas;
- QueryGeneratorBuilder(VersionsEntitiesConfiguration verEntCfg, MiddleIdData
referencingIdData,
- String versionsMiddleEntityName) {
+ QueryGeneratorBuilder(GlobalConfiguration globalCfg, VersionsEntitiesConfiguration
verEntCfg,
+ MiddleIdData referencingIdData, String
versionsMiddleEntityName) {
+ this.globalCfg = globalCfg;
this.verEntCfg = verEntCfg;
this.referencingIdData = referencingIdData;
this.versionsMiddleEntityName = versionsMiddleEntityName;
@@ -63,10 +66,10 @@
return new OneEntityQueryGenerator(verEntCfg, versionsMiddleEntityName,
referencingIdData,
componentDatas);
} else if (idDatas.size() == 1) {
- return new TwoEntityQueryGenerator(verEntCfg, versionsMiddleEntityName,
referencingIdData,
+ return new TwoEntityQueryGenerator(globalCfg, verEntCfg,
versionsMiddleEntityName, referencingIdData,
idDatas.get(0), componentDatas);
} else if (idDatas.size() == 2) {
- return new ThreeEntityQueryGenerator(verEntCfg, versionsMiddleEntityName,
referencingIdData,
+ return new ThreeEntityQueryGenerator(globalCfg, verEntCfg,
versionsMiddleEntityName, referencingIdData,
idDatas.get(0), idDatas.get(1), componentDatas);
} else {
throw new IllegalStateException("Illegal number of related
entities.");
Modified:
trunk/src/main/org/jboss/envers/configuration/metadata/VersionsMetadataGenerator.java
===================================================================
---
trunk/src/main/org/jboss/envers/configuration/metadata/VersionsMetadataGenerator.java 2008-10-13
14:43:11 UTC (rev 177)
+++
trunk/src/main/org/jboss/envers/configuration/metadata/VersionsMetadataGenerator.java 2008-10-13
18:02:35 UTC (rev 178)
@@ -360,6 +360,10 @@
return cfg;
}
+ GlobalConfiguration getGlobalCfg() {
+ return globalCfg;
+ }
+
VersionsEntitiesConfiguration getVerEntCfg() {
return verEntCfg;
}
Modified:
trunk/src/main/org/jboss/envers/entities/mapper/relation/query/OneVersionsEntityQueryGenerator.java
===================================================================
---
trunk/src/main/org/jboss/envers/entities/mapper/relation/query/OneVersionsEntityQueryGenerator.java 2008-10-13
14:43:11 UTC (rev 177)
+++
trunk/src/main/org/jboss/envers/entities/mapper/relation/query/OneVersionsEntityQueryGenerator.java 2008-10-13
18:02:35 UTC (rev 178)
@@ -27,6 +27,7 @@
import org.jboss.envers.entities.mapper.id.IdMapper;
import org.jboss.envers.entities.mapper.relation.MiddleIdData;
import org.jboss.envers.configuration.VersionsEntitiesConfiguration;
+import org.jboss.envers.configuration.GlobalConfiguration;
import org.jboss.envers.reader.VersionsReaderImplementor;
import org.jboss.envers.RevisionType;
import org.jboss.envers.tools.query.QueryBuilder;
@@ -43,8 +44,9 @@
private final String queryString;
private final MiddleIdData referencingIdData;
- public OneVersionsEntityQueryGenerator(VersionsEntitiesConfiguration verEntCfg,
MiddleIdData referencingIdData,
- String referencedEntityName, IdMapper
referencedIdMapper) {
+ public OneVersionsEntityQueryGenerator(GlobalConfiguration globalCfg,
VersionsEntitiesConfiguration verEntCfg,
+ MiddleIdData referencingIdData, String
referencedEntityName,
+ IdMapper referencedIdMapper) {
this.referencingIdData = referencingIdData;
/*
@@ -84,7 +86,7 @@
"e." + originalIdPropertyName, "e2." +
originalIdPropertyName);
// e.revision = (SELECT max(...) ...)
- rootParameters.addWhere(revisionPropertyPath, false, "=", maxERevQb);
+ rootParameters.addWhere(revisionPropertyPath, false,
globalCfg.getCorrelatedSubqueryOperator(), maxERevQb);
// e.revision_type != DEL
rootParameters.addWhereWithNamedParam(verEntCfg.getRevisionTypePropName(), false,
"!=", "delrevisiontype");
Modified:
trunk/src/main/org/jboss/envers/entities/mapper/relation/query/QueryGeneratorTools.java
===================================================================
---
trunk/src/main/org/jboss/envers/entities/mapper/relation/query/QueryGeneratorTools.java 2008-10-13
14:43:11 UTC (rev 177)
+++
trunk/src/main/org/jboss/envers/entities/mapper/relation/query/QueryGeneratorTools.java 2008-10-13
18:02:35 UTC (rev 178)
@@ -27,13 +27,14 @@
import org.jboss.envers.tools.query.Parameters;
import org.jboss.envers.entities.mapper.relation.MiddleIdData;
import org.jboss.envers.entities.mapper.relation.MiddleComponentData;
+import org.jboss.envers.configuration.GlobalConfiguration;
/**
* @author Adam Warski (adam at warski dot org)
*/
public class QueryGeneratorTools {
- public static void addEntityAtRevision(QueryBuilder qb, Parameters rootParameters,
MiddleIdData idData,
- String revisionPropertyPath, String
originalIdPropertyName,
+ public static void addEntityAtRevision(GlobalConfiguration globalCfg, QueryBuilder
qb, Parameters rootParameters,
+ MiddleIdData idData, String
revisionPropertyPath, String originalIdPropertyName,
String alias1, String alias2) {
// SELECT max(e.revision) FROM versionsReferencedEntity e2
QueryBuilder maxERevQb = qb.newSubQueryBuilder(idData.getVersionsEntityName(),
alias2);
@@ -47,7 +48,7 @@
alias1 + "." + originalIdPropertyName, alias2 +"." +
originalIdPropertyName);
// e.revision = (SELECT max(...) ...)
- rootParameters.addWhere("e." + revisionPropertyPath, false,
"=", maxERevQb);
+ rootParameters.addWhere("e." + revisionPropertyPath, false,
globalCfg.getCorrelatedSubqueryOperator(), maxERevQb);
}
public static void addAssociationAtRevision(QueryBuilder qb, Parameters
rootParameters,
Modified:
trunk/src/main/org/jboss/envers/entities/mapper/relation/query/ThreeEntityQueryGenerator.java
===================================================================
---
trunk/src/main/org/jboss/envers/entities/mapper/relation/query/ThreeEntityQueryGenerator.java 2008-10-13
14:43:11 UTC (rev 177)
+++
trunk/src/main/org/jboss/envers/entities/mapper/relation/query/ThreeEntityQueryGenerator.java 2008-10-13
18:02:35 UTC (rev 178)
@@ -27,6 +27,7 @@
import org.jboss.envers.entities.mapper.relation.MiddleIdData;
import org.jboss.envers.entities.mapper.relation.MiddleComponentData;
import org.jboss.envers.configuration.VersionsEntitiesConfiguration;
+import org.jboss.envers.configuration.GlobalConfiguration;
import org.jboss.envers.reader.VersionsReaderImplementor;
import org.jboss.envers.RevisionType;
import org.jboss.envers.tools.query.QueryBuilder;
@@ -43,7 +44,8 @@
private final String queryString;
private final MiddleIdData referencingIdData;
- public ThreeEntityQueryGenerator(VersionsEntitiesConfiguration verEntCfg,
+ public ThreeEntityQueryGenerator(GlobalConfiguration globalCfg,
+ VersionsEntitiesConfiguration verEntCfg,
String versionsMiddleEntityName,
MiddleIdData referencingIdData,
MiddleIdData referencedIdData,
@@ -97,11 +99,11 @@
referencingIdData.getPrefixedMapper().addNamedIdEqualsToQuery(rootParameters,
originalIdPropertyName, true);
// e.revision = (SELECT max(...) ...)
- QueryGeneratorTools.addEntityAtRevision(qb, rootParameters, referencedIdData,
revisionPropertyPath,
+ QueryGeneratorTools.addEntityAtRevision(globalCfg, qb, rootParameters,
referencedIdData, revisionPropertyPath,
originalIdPropertyName, "e", "e2");
// f.revision = (SELECT max(...) ...)
- QueryGeneratorTools.addEntityAtRevision(qb, rootParameters, indexIdData,
revisionPropertyPath,
+ QueryGeneratorTools.addEntityAtRevision(globalCfg, qb, rootParameters,
indexIdData, revisionPropertyPath,
originalIdPropertyName, "f", "f2");
// ee.revision = (SELECT max(...) ...)
Modified:
trunk/src/main/org/jboss/envers/entities/mapper/relation/query/TwoEntityQueryGenerator.java
===================================================================
---
trunk/src/main/org/jboss/envers/entities/mapper/relation/query/TwoEntityQueryGenerator.java 2008-10-13
14:43:11 UTC (rev 177)
+++
trunk/src/main/org/jboss/envers/entities/mapper/relation/query/TwoEntityQueryGenerator.java 2008-10-13
18:02:35 UTC (rev 178)
@@ -27,6 +27,7 @@
import org.jboss.envers.entities.mapper.relation.MiddleIdData;
import org.jboss.envers.entities.mapper.relation.MiddleComponentData;
import org.jboss.envers.configuration.VersionsEntitiesConfiguration;
+import org.jboss.envers.configuration.GlobalConfiguration;
import org.jboss.envers.reader.VersionsReaderImplementor;
import org.jboss.envers.RevisionType;
import org.jboss.envers.tools.query.QueryBuilder;
@@ -43,7 +44,8 @@
private final String queryString;
private final MiddleIdData referencingIdData;
- public TwoEntityQueryGenerator(VersionsEntitiesConfiguration verEntCfg,
+ public TwoEntityQueryGenerator(GlobalConfiguration globalCfg,
+ VersionsEntitiesConfiguration verEntCfg,
String versionsMiddleEntityName,
MiddleIdData referencingIdData,
MiddleIdData referencedIdData,
@@ -86,7 +88,7 @@
referencingIdData.getPrefixedMapper().addNamedIdEqualsToQuery(rootParameters,
originalIdPropertyName, true);
// e.revision = (SELECT max(...) ...)
- QueryGeneratorTools.addEntityAtRevision(qb, rootParameters, referencedIdData,
revisionPropertyPath,
+ QueryGeneratorTools.addEntityAtRevision(globalCfg, qb, rootParameters,
referencedIdData, revisionPropertyPath,
originalIdPropertyName, "e", "e2");
// ee.revision = (SELECT max(...) ...)
Modified: trunk/src/main/org/jboss/envers/query/impl/EntitiesAtRevisionQuery.java
===================================================================
--- trunk/src/main/org/jboss/envers/query/impl/EntitiesAtRevisionQuery.java 2008-10-13
14:43:11 UTC (rev 177)
+++ trunk/src/main/org/jboss/envers/query/impl/EntitiesAtRevisionQuery.java 2008-10-13
18:02:35 UTC (rev 178)
@@ -72,8 +72,8 @@
// e.revision_type != DEL AND
qb.getRootParameters().addWhereWithParam(verEntCfg.getRevisionTypePropName(),
"<>", RevisionType.DEL);
- // e.revision = (SELECT max(...) ...)
- qb.getRootParameters().addWhere(revisionPropertyPath, "=", maxRevQb);
+ // e.revision = (SELECT max(...) ...)
+ qb.getRootParameters().addWhere(revisionPropertyPath,
verCfg.getGlobalCfg().getCorrelatedSubqueryOperator(), maxRevQb);
// all specified conditions
for (VersionsCriterion criterion : criterions) {
criterion.addToQuery(verCfg, entityName, qb, qb.getRootParameters());