Hibernate SVN: r20315 - in core/trunk/envers/src/main/java/org/hibernate/envers: configuration/metadata and 3 other directories.
by hibernate-commits@lists.jboss.org
Author: adamw
Date: 2010-09-07 09:52:38 -0400 (Tue, 07 Sep 2010)
New Revision: 20315
Removed:
core/trunk/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/query/QueryGeneratorTools.java
Modified:
core/trunk/envers/src/main/java/org/hibernate/envers/configuration/AuditConfiguration.java
core/trunk/envers/src/main/java/org/hibernate/envers/configuration/EntitiesConfigurator.java
core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata/AuditMetadataGenerator.java
core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata/CollectionMetadataGenerator.java
core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata/QueryGeneratorBuilder.java
core/trunk/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/query/OneAuditEntityQueryGenerator.java
core/trunk/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/query/OneEntityQueryGenerator.java
core/trunk/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/query/ThreeEntityQueryGenerator.java
core/trunk/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/query/TwoEntityOneAuditedQueryGenerator.java
core/trunk/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/query/TwoEntityQueryGenerator.java
core/trunk/envers/src/main/java/org/hibernate/envers/query/impl/AbstractAuditQuery.java
core/trunk/envers/src/main/java/org/hibernate/envers/query/impl/EntitiesAtRevisionQuery.java
core/trunk/envers/src/main/java/org/hibernate/envers/strategy/AuditStrategy.java
core/trunk/envers/src/main/java/org/hibernate/envers/strategy/DefaultAuditStrategy.java
core/trunk/envers/src/main/java/org/hibernate/envers/strategy/ValidTimeAuditStrategy.java
Log:
HHH-5372:
applying patch by Matthew B. Jones and Erik-Berndt Scheper
Using the revend column in queries that retrieve historical data, which is much faster then doing the subselect.
Modified: core/trunk/envers/src/main/java/org/hibernate/envers/configuration/AuditConfiguration.java
===================================================================
--- core/trunk/envers/src/main/java/org/hibernate/envers/configuration/AuditConfiguration.java 2010-09-07 07:33:33 UTC (rev 20314)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/configuration/AuditConfiguration.java 2010-09-07 13:52:38 UTC (rev 20315)
@@ -83,7 +83,7 @@
public AuditConfiguration(Configuration cfg) {
Properties properties = cfg.getProperties();
- ReflectionManager reflectionManager = ((AnnotationConfiguration) cfg).getReflectionManager();
+ ReflectionManager reflectionManager = cfg.getReflectionManager();
RevisionInfoConfiguration revInfoCfg = new RevisionInfoConfiguration();
RevisionInfoConfigurationResult revInfoCfgResult = revInfoCfg.configure(cfg, reflectionManager);
auditEntCfg = new AuditEntitiesConfiguration(properties, revInfoCfgResult.getRevisionInfoEntityName());
@@ -99,7 +99,7 @@
revisionInfoQueryCreator = revInfoCfgResult.getRevisionInfoQueryCreator();
revisionInfoNumberReader = revInfoCfgResult.getRevisionInfoNumberReader();
- entCfg = new EntitiesConfigurator().configure(cfg, reflectionManager, globalCfg, auditEntCfg,
+ entCfg = new EntitiesConfigurator().configure(cfg, reflectionManager, globalCfg, auditEntCfg, auditStrategy,
revInfoCfgResult.getRevisionInfoXmlMapping(), revInfoCfgResult.getRevisionInfoRelationMapping());
}
Modified: core/trunk/envers/src/main/java/org/hibernate/envers/configuration/EntitiesConfigurator.java
===================================================================
--- core/trunk/envers/src/main/java/org/hibernate/envers/configuration/EntitiesConfigurator.java 2010-09-07 07:33:33 UTC (rev 20314)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/configuration/EntitiesConfigurator.java 2010-09-07 13:52:38 UTC (rev 20315)
@@ -43,6 +43,7 @@
import org.hibernate.envers.configuration.metadata.AuditMetadataGenerator;
import org.hibernate.envers.configuration.metadata.AuditEntityNameRegister;
import org.hibernate.envers.entities.EntitiesConfigurations;
+import org.hibernate.envers.strategy.AuditStrategy;
import org.hibernate.envers.tools.StringTools;
import org.hibernate.envers.tools.graph.GraphTopologicalSort;
@@ -57,6 +58,7 @@
public class EntitiesConfigurator {
public EntitiesConfigurations configure(Configuration cfg, ReflectionManager reflectionManager,
GlobalConfiguration globalCfg, AuditEntitiesConfiguration verEntCfg,
+ AuditStrategy auditStrategy,
Document revisionInfoXmlMapping, Element revisionInfoRelationMapping) {
// Creating a name register to capture all audit entity names created.
AuditEntityNameRegister auditEntityNameRegister = new AuditEntityNameRegister();
@@ -83,7 +85,7 @@
// Now that all information is read we can update the calculated fields.
classesAuditingData.updateCalculatedFields();
- AuditMetadataGenerator auditMetaGen = new AuditMetadataGenerator(cfg, globalCfg, verEntCfg,
+ AuditMetadataGenerator auditMetaGen = new AuditMetadataGenerator(cfg, globalCfg, verEntCfg, auditStrategy,
revisionInfoRelationMapping, auditEntityNameRegister);
// First pass
Modified: core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata/AuditMetadataGenerator.java
===================================================================
--- core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata/AuditMetadataGenerator.java 2010-09-07 07:33:33 UTC (rev 20314)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata/AuditMetadataGenerator.java 2010-09-07 13:52:38 UTC (rev 20315)
@@ -28,6 +28,7 @@
import java.util.Map;
import org.dom4j.Element;
+import org.hibernate.envers.configuration.AuditConfiguration;
import org.hibernate.envers.configuration.GlobalConfiguration;
import org.hibernate.envers.configuration.AuditEntitiesConfiguration;
import org.hibernate.envers.configuration.metadata.reader.ClassAuditingData;
@@ -38,6 +39,7 @@
import org.hibernate.envers.entities.mapper.ExtendedPropertyMapper;
import org.hibernate.envers.entities.mapper.MultiPropertyMapper;
import org.hibernate.envers.entities.mapper.SubclassPropertyMapper;
+import org.hibernate.envers.strategy.AuditStrategy;
import org.hibernate.envers.strategy.ValidTimeAuditStrategy;
import org.hibernate.envers.tools.StringTools;
import org.hibernate.envers.tools.Triple;
@@ -63,6 +65,7 @@
private final Configuration cfg;
private final GlobalConfiguration globalCfg;
private final AuditEntitiesConfiguration verEntCfg;
+ private final AuditStrategy auditStrategy;
private final Element revisionInfoRelationMapping;
/*
@@ -86,11 +89,13 @@
public AuditMetadataGenerator(Configuration cfg, GlobalConfiguration globalCfg,
AuditEntitiesConfiguration verEntCfg,
+ AuditStrategy auditStrategy,
Element revisionInfoRelationMapping,
AuditEntityNameRegister auditEntityNameRegister) {
this.cfg = cfg;
this.globalCfg = globalCfg;
this.verEntCfg = verEntCfg;
+ this.auditStrategy = auditStrategy;
this.revisionInfoRelationMapping = revisionInfoRelationMapping;
this.basicMetadataGenerator = new BasicMetadataGenerator();
@@ -490,6 +495,10 @@
return verEntCfg;
}
+ AuditStrategy getAuditStrategy() {
+ return auditStrategy;
+ }
+
AuditEntityNameRegister getAuditEntityNameRegister() {
return auditEntityNameRegister;
}
Modified: core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata/CollectionMetadataGenerator.java
===================================================================
--- core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata/CollectionMetadataGenerator.java 2010-09-07 07:33:33 UTC (rev 20314)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata/CollectionMetadataGenerator.java 2010-09-07 13:52:38 UTC (rev 20315)
@@ -32,9 +32,11 @@
import java.util.Set;
import java.util.TreeMap;
import java.util.TreeSet;
+
import javax.persistence.JoinColumn;
import org.dom4j.Element;
+import org.hibernate.MappingException;
import org.hibernate.envers.ModificationStore;
import org.hibernate.envers.RelationTargetAuditMode;
import org.hibernate.envers.configuration.metadata.reader.PropertyAuditingData;
@@ -45,8 +47,19 @@
import org.hibernate.envers.entities.mapper.PropertyMapper;
import org.hibernate.envers.entities.mapper.SinglePropertyMapper;
import org.hibernate.envers.entities.mapper.id.IdMapper;
-import org.hibernate.envers.entities.mapper.relation.*;
-import org.hibernate.envers.entities.mapper.relation.component.*;
+import org.hibernate.envers.entities.mapper.relation.BasicCollectionMapper;
+import org.hibernate.envers.entities.mapper.relation.CommonCollectionMapperData;
+import org.hibernate.envers.entities.mapper.relation.ListCollectionMapper;
+import org.hibernate.envers.entities.mapper.relation.MapCollectionMapper;
+import org.hibernate.envers.entities.mapper.relation.MiddleComponentData;
+import org.hibernate.envers.entities.mapper.relation.MiddleIdData;
+import org.hibernate.envers.entities.mapper.relation.ToOneIdMapper;
+import org.hibernate.envers.entities.mapper.relation.component.MiddleDummyComponentMapper;
+import org.hibernate.envers.entities.mapper.relation.component.MiddleMapKeyIdComponentMapper;
+import org.hibernate.envers.entities.mapper.relation.component.MiddleMapKeyPropertyComponentMapper;
+import org.hibernate.envers.entities.mapper.relation.component.MiddleRelatedComponentMapper;
+import org.hibernate.envers.entities.mapper.relation.component.MiddleSimpleComponentMapper;
+import org.hibernate.envers.entities.mapper.relation.component.MiddleStraightComponentMapper;
import org.hibernate.envers.entities.mapper.relation.lazy.proxy.ListProxy;
import org.hibernate.envers.entities.mapper.relation.lazy.proxy.MapProxy;
import org.hibernate.envers.entities.mapper.relation.lazy.proxy.SetProxy;
@@ -54,11 +67,9 @@
import org.hibernate.envers.entities.mapper.relation.lazy.proxy.SortedSetProxy;
import org.hibernate.envers.entities.mapper.relation.query.OneAuditEntityQueryGenerator;
import org.hibernate.envers.entities.mapper.relation.query.RelationQueryGenerator;
+import org.hibernate.envers.tools.MappingTools;
import org.hibernate.envers.tools.StringTools;
import org.hibernate.envers.tools.Tools;
-import org.hibernate.envers.tools.MappingTools;
-
-import org.hibernate.MappingException;
import org.hibernate.mapping.Collection;
import org.hibernate.mapping.IndexedCollection;
import org.hibernate.mapping.OneToMany;
@@ -184,8 +195,8 @@
// Generating the query generator - it should read directly from the related entity.
RelationQueryGenerator queryGenerator = new OneAuditEntityQueryGenerator(mainGenerator.getGlobalCfg(),
- mainGenerator.getVerEntCfg(), referencingIdData, referencedEntityName,
- referencedIdMapping.getIdMapper());
+ mainGenerator.getVerEntCfg(), mainGenerator.getAuditStrategy(),
+ referencingIdData, referencedEntityName, referencedIdData);
// Creating common mapper data.
CommonCollectionMapperData commonCollectionMapperData = new CommonCollectionMapperData(
@@ -332,8 +343,9 @@
// 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.getGlobalCfg(),
- mainGenerator.getVerEntCfg(), referencingIdData, auditMiddleEntityName);
+ QueryGeneratorBuilder queryGeneratorBuilder = new QueryGeneratorBuilder(mainGenerator.getGlobalCfg(),
+ mainGenerator.getVerEntCfg(), mainGenerator.getAuditStrategy(), referencingIdData,
+ auditMiddleEntityName);
// Adding the XML mapping for the referencing entity, if the relation isn't inverse.
if (middleEntityXml != null) {
Modified: core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata/QueryGeneratorBuilder.java
===================================================================
--- core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata/QueryGeneratorBuilder.java 2010-09-07 07:33:33 UTC (rev 20314)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata/QueryGeneratorBuilder.java 2010-09-07 13:52:38 UTC (rev 20315)
@@ -26,12 +26,17 @@
import java.util.ArrayList;
import java.util.List;
+import org.hibernate.MappingException;
+import org.hibernate.envers.configuration.AuditEntitiesConfiguration;
import org.hibernate.envers.configuration.GlobalConfiguration;
-import org.hibernate.envers.configuration.AuditEntitiesConfiguration;
import org.hibernate.envers.entities.mapper.relation.MiddleComponentData;
import org.hibernate.envers.entities.mapper.relation.MiddleIdData;
-import org.hibernate.envers.entities.mapper.relation.query.*;
-import org.hibernate.MappingException;
+import org.hibernate.envers.entities.mapper.relation.query.OneEntityQueryGenerator;
+import org.hibernate.envers.entities.mapper.relation.query.RelationQueryGenerator;
+import org.hibernate.envers.entities.mapper.relation.query.ThreeEntityQueryGenerator;
+import org.hibernate.envers.entities.mapper.relation.query.TwoEntityOneAuditedQueryGenerator;
+import org.hibernate.envers.entities.mapper.relation.query.TwoEntityQueryGenerator;
+import org.hibernate.envers.strategy.AuditStrategy;
/**
* Builds query generators, for reading collection middle tables, along with any related entities.
@@ -41,14 +46,17 @@
public final class QueryGeneratorBuilder {
private final GlobalConfiguration globalCfg;
private final AuditEntitiesConfiguration verEntCfg;
+ private final AuditStrategy auditStrategy;
private final MiddleIdData referencingIdData;
private final String auditMiddleEntityName;
private final List<MiddleIdData> idDatas;
QueryGeneratorBuilder(GlobalConfiguration globalCfg, AuditEntitiesConfiguration verEntCfg,
+ AuditStrategy auditStrategy,
MiddleIdData referencingIdData, String auditMiddleEntityName) {
this.globalCfg = globalCfg;
this.verEntCfg = verEntCfg;
+ this.auditStrategy = auditStrategy;
this.referencingIdData = referencingIdData;
this.auditMiddleEntityName = auditMiddleEntityName;
@@ -61,14 +69,14 @@
RelationQueryGenerator build(MiddleComponentData... componentDatas) {
if (idDatas.size() == 0) {
- return new OneEntityQueryGenerator(verEntCfg, auditMiddleEntityName, referencingIdData,
+ return new OneEntityQueryGenerator(verEntCfg, auditStrategy, auditMiddleEntityName, referencingIdData,
componentDatas);
} else if (idDatas.size() == 1) {
if (idDatas.get(0).isAudited()) {
- return new TwoEntityQueryGenerator(globalCfg, verEntCfg, auditMiddleEntityName, referencingIdData,
+ return new TwoEntityQueryGenerator(globalCfg, verEntCfg, auditStrategy, auditMiddleEntityName, referencingIdData,
idDatas.get(0), componentDatas);
} else {
- return new TwoEntityOneAuditedQueryGenerator(verEntCfg, auditMiddleEntityName, referencingIdData,
+ return new TwoEntityOneAuditedQueryGenerator(verEntCfg, auditStrategy, auditMiddleEntityName, referencingIdData,
idDatas.get(0), componentDatas);
}
} else if (idDatas.size() == 2) {
@@ -77,7 +85,7 @@
throw new MappingException("Ternary relations using @Audited(targetAuditMode = NOT_AUDITED) are not supported.");
}
- return new ThreeEntityQueryGenerator(globalCfg, verEntCfg, auditMiddleEntityName, referencingIdData,
+ return new ThreeEntityQueryGenerator(globalCfg, verEntCfg, auditStrategy, auditMiddleEntityName, referencingIdData,
idDatas.get(0), idDatas.get(1), componentDatas);
} else {
throw new IllegalStateException("Illegal number of related entities.");
Modified: core/trunk/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/query/OneAuditEntityQueryGenerator.java
===================================================================
--- core/trunk/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/query/OneAuditEntityQueryGenerator.java 2010-09-07 07:33:33 UTC (rev 20314)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/query/OneAuditEntityQueryGenerator.java 2010-09-07 13:52:38 UTC (rev 20315)
@@ -25,18 +25,17 @@
import java.util.Collections;
+import org.hibernate.Query;
import org.hibernate.envers.RevisionType;
-import org.hibernate.envers.configuration.GlobalConfiguration;
import org.hibernate.envers.configuration.AuditEntitiesConfiguration;
-import org.hibernate.envers.entities.mapper.id.IdMapper;
+import org.hibernate.envers.configuration.GlobalConfiguration;
import org.hibernate.envers.entities.mapper.id.QueryParameterData;
import org.hibernate.envers.entities.mapper.relation.MiddleIdData;
import org.hibernate.envers.reader.AuditReaderImplementor;
+import org.hibernate.envers.strategy.AuditStrategy;
import org.hibernate.envers.tools.query.Parameters;
import org.hibernate.envers.tools.query.QueryBuilder;
-import org.hibernate.Query;
-
/**
* Selects data from an audit entity.
* @author Adam Warski (adam at warski dot org)
@@ -45,9 +44,10 @@
private final String queryString;
private final MiddleIdData referencingIdData;
- public OneAuditEntityQueryGenerator(GlobalConfiguration globalCfg, AuditEntitiesConfiguration verEntCfg,
- MiddleIdData referencingIdData, String referencedEntityName,
- IdMapper referencedIdMapper) {
+ public OneAuditEntityQueryGenerator(GlobalConfiguration globalCfg, AuditEntitiesConfiguration verEntCfg,
+ AuditStrategy auditStrategy,
+ MiddleIdData referencingIdData,
+ String referencedEntityName, MiddleIdData referencedIdData) {
this.referencingIdData = referencingIdData;
/*
@@ -57,8 +57,14 @@
* (only entities referenced by the association; id_ref_ing = id of the referencing entity)
* e.id_ref_ing = :id_ref_ing AND
* (selecting e entities at revision :revision)
+ * --> for DefaultAuditStrategy:
* e.revision = (SELECT max(e2.revision) FROM versionsReferencedEntity e2
- * WHERE e2.revision <= :revision AND e2.id = e.id) AND
+ * WHERE e2.revision <= :revision AND e2.id = e.id)
+ *
+ * --> for ValidTimeAuditStrategy:
+ * e.revision <= :revision and (e.endRevision > :revision or e.endRevision is null)
+ *
+ * AND
* (only non-deleted entities)
* e.revision_type != DEL
*/
@@ -75,20 +81,12 @@
// e.id_ref_ed = :id_ref_ed
referencingIdData.getPrefixedMapper().addNamedIdEqualsToQuery(rootParameters, null, true);
- // SELECT max(e.revision) FROM versionsReferencedEntity e2
- QueryBuilder maxERevQb = qb.newSubQueryBuilder(versionsReferencedEntityName, "e2");
- maxERevQb.addProjection("max", revisionPropertyPath, false);
- // WHERE
- Parameters maxERevQbParameters = maxERevQb.getRootParameters();
- // e2.revision <= :revision
- maxERevQbParameters.addWhereWithNamedParam(revisionPropertyPath, "<=", "revision");
- // e2.id = e.id
- referencedIdMapper.addIdsEqualToQuery(maxERevQbParameters,
- "e." + originalIdPropertyName, "e2." + originalIdPropertyName);
+ // (selecting e entities at revision :revision)
+ // --> based on auditStrategy (see above)
+ auditStrategy.addEntityAtRevisionRestriction(globalCfg, qb, revisionPropertyPath,
+ verEntCfg.getRevisionEndFieldName(), true, referencedIdData,
+ revisionPropertyPath, originalIdPropertyName, "e", "e2");
- // e.revision = (SELECT max(...) ...)
- rootParameters.addWhere(revisionPropertyPath, false, globalCfg.getCorrelatedSubqueryOperator(), maxERevQb);
-
// e.revision_type != DEL
rootParameters.addWhereWithNamedParam(verEntCfg.getRevisionTypePropName(), false, "!=", "delrevisiontype");
@@ -107,4 +105,4 @@
return query;
}
-}
\ No newline at end of file
+}
Modified: core/trunk/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/query/OneEntityQueryGenerator.java
===================================================================
--- core/trunk/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/query/OneEntityQueryGenerator.java 2010-09-07 07:33:33 UTC (rev 20314)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/query/OneEntityQueryGenerator.java 2010-09-07 13:52:38 UTC (rev 20315)
@@ -25,17 +25,17 @@
import java.util.Collections;
+import org.hibernate.Query;
import org.hibernate.envers.RevisionType;
import org.hibernate.envers.configuration.AuditEntitiesConfiguration;
import org.hibernate.envers.entities.mapper.id.QueryParameterData;
import org.hibernate.envers.entities.mapper.relation.MiddleComponentData;
import org.hibernate.envers.entities.mapper.relation.MiddleIdData;
import org.hibernate.envers.reader.AuditReaderImplementor;
+import org.hibernate.envers.strategy.AuditStrategy;
import org.hibernate.envers.tools.query.Parameters;
import org.hibernate.envers.tools.query.QueryBuilder;
-import org.hibernate.Query;
-
/**
* Selects data from a relation middle-table only.
* @author Adam Warski (adam at warski dot org)
@@ -45,6 +45,7 @@
private final MiddleIdData referencingIdData;
public OneEntityQueryGenerator(AuditEntitiesConfiguration verEntCfg,
+ AuditStrategy auditStrategy,
String versionsMiddleEntityName,
MiddleIdData referencingIdData,
MiddleComponentData... componentDatas) {
@@ -55,9 +56,17 @@
* SELECT new list(ee) FROM middleEntity ee WHERE
* (only entities referenced by the association; id_ref_ing = id of the referencing entity)
* ee.originalId.id_ref_ing = :id_ref_ing AND
+ *
* (the association at revision :revision)
+ * --> for DefaultAuditStrategy:
* ee.revision = (SELECT max(ee2.revision) FROM middleEntity ee2
- * WHERE ee2.revision <= :revision AND ee2.originalId.* = ee.originalId.*) AND
+ * WHERE ee2.revision <= :revision AND ee2.originalId.* = ee.originalId.*)
+ *
+ * --> for ValidTimeAuditStrategy:
+ * ee.revision <= :revision and (ee.endRevision > :revision or ee.endRevision is null)
+ *
+ * AND
+ *
* (only non-deleted entities and associations)
* ee.revision_type != DEL
*/
@@ -71,22 +80,15 @@
Parameters rootParameters = qb.getRootParameters();
// ee.originalId.id_ref_ing = :id_ref_ing
referencingIdData.getPrefixedMapper().addNamedIdEqualsToQuery(rootParameters, originalIdPropertyName, true);
- // SELECT max(ee2.revision) FROM middleEntity ee2
- QueryBuilder maxRevQb = qb.newSubQueryBuilder(versionsMiddleEntityName, "ee2");
- maxRevQb.addProjection("max", revisionPropertyPath, false);
- // WHERE
- Parameters maxRevQbParameters = maxRevQb.getRootParameters();
- // ee2.revision <= :revision
- maxRevQbParameters.addWhereWithNamedParam(revisionPropertyPath, "<=", "revision");
- // ee2.originalId.* = ee.originalId.*
+
String eeOriginalIdPropertyPath = "ee." + originalIdPropertyName;
- String ee2OriginalIdPropertyPath = "ee2." + originalIdPropertyName;
- referencingIdData.getPrefixedMapper().addIdsEqualToQuery(maxRevQbParameters, eeOriginalIdPropertyPath, ee2OriginalIdPropertyPath);
- for (MiddleComponentData componentData : componentDatas) {
- componentData.getComponentMapper().addMiddleEqualToQuery(maxRevQbParameters, eeOriginalIdPropertyPath, ee2OriginalIdPropertyPath);
- }
- // ee.revision = (SELECT max(...) ...)
- rootParameters.addWhere(revisionPropertyPath, "=", maxRevQb);
+
+ // (with ee association at revision :revision)
+ // --> based on auditStrategy (see above)
+ auditStrategy.addAssociationAtRevisionRestriction(qb, revisionPropertyPath,
+ verEntCfg.getRevisionEndFieldName(), true,referencingIdData, versionsMiddleEntityName,
+ eeOriginalIdPropertyPath, revisionPropertyPath, originalIdPropertyName, componentDatas);
+
// ee.revision_type != DEL
rootParameters.addWhereWithNamedParam(verEntCfg.getRevisionTypePropName(), "!=", "delrevisiontype");
Deleted: core/trunk/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/query/QueryGeneratorTools.java
===================================================================
--- core/trunk/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/query/QueryGeneratorTools.java 2010-09-07 07:33:33 UTC (rev 20314)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/query/QueryGeneratorTools.java 2010-09-07 13:52:38 UTC (rev 20315)
@@ -1,75 +0,0 @@
-/*
- * Hibernate, Relational Persistence for Idiomatic Java
- *
- * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
- * indicated by the @author tags or express copyright attribution
- * statements applied by the authors. All third-party contributions are
- * distributed under license by Red Hat Middleware LLC.
- *
- * This copyrighted material is made available to anyone wishing to use, modify,
- * copy, or redistribute it subject to the terms and conditions of the GNU
- * Lesser General Public License, as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
- * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
- * for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this distribution; if not, write to:
- * Free Software Foundation, Inc.
- * 51 Franklin Street, Fifth Floor
- * Boston, MA 02110-1301 USA
- */
-package org.hibernate.envers.entities.mapper.relation.query;
-
-import org.hibernate.envers.configuration.GlobalConfiguration;
-import org.hibernate.envers.entities.mapper.relation.MiddleComponentData;
-import org.hibernate.envers.entities.mapper.relation.MiddleIdData;
-import org.hibernate.envers.tools.query.Parameters;
-import org.hibernate.envers.tools.query.QueryBuilder;
-
-/**
- * @author Adam Warski (adam at warski dot org)
- */
-public class QueryGeneratorTools {
- 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.getAuditEntityName(), alias2);
- maxERevQb.addProjection("max", revisionPropertyPath, false);
- // WHERE
- Parameters maxERevQbParameters = maxERevQb.getRootParameters();
- // e2.revision <= :revision
- maxERevQbParameters.addWhereWithNamedParam(revisionPropertyPath, "<=", "revision");
- // e2.id_ref_ed = e.id_ref_ed
- idData.getOriginalMapper().addIdsEqualToQuery(maxERevQbParameters,
- alias1 + "." + originalIdPropertyName, alias2 +"." + originalIdPropertyName);
-
- // e.revision = (SELECT max(...) ...)
- rootParameters.addWhere("e." + revisionPropertyPath, false, globalCfg.getCorrelatedSubqueryOperator(), maxERevQb);
- }
-
- public static void addAssociationAtRevision(QueryBuilder qb, Parameters rootParameters,
- MiddleIdData referencingIdData, String versionsMiddleEntityName,
- String eeOriginalIdPropertyPath, String revisionPropertyPath,
- String originalIdPropertyName, MiddleComponentData... componentDatas) {
- // SELECT max(ee2.revision) FROM middleEntity ee2
- QueryBuilder maxEeRevQb = qb.newSubQueryBuilder(versionsMiddleEntityName, "ee2");
- maxEeRevQb.addProjection("max", revisionPropertyPath, false);
- // WHERE
- Parameters maxEeRevQbParameters = maxEeRevQb.getRootParameters();
- // ee2.revision <= :revision
- maxEeRevQbParameters.addWhereWithNamedParam(revisionPropertyPath, "<=", "revision");
- // ee2.originalId.* = ee.originalId.*
- String ee2OriginalIdPropertyPath = "ee2." + originalIdPropertyName;
- referencingIdData.getPrefixedMapper().addIdsEqualToQuery(maxEeRevQbParameters, eeOriginalIdPropertyPath, ee2OriginalIdPropertyPath);
- for (MiddleComponentData componentData : componentDatas) {
- componentData.getComponentMapper().addMiddleEqualToQuery(maxEeRevQbParameters, eeOriginalIdPropertyPath, ee2OriginalIdPropertyPath);
- }
-
- // ee.revision = (SELECT max(...) ...)
- rootParameters.addWhere(revisionPropertyPath, "=", maxEeRevQb);
- }
-}
Modified: core/trunk/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/query/ThreeEntityQueryGenerator.java
===================================================================
--- core/trunk/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/query/ThreeEntityQueryGenerator.java 2010-09-07 07:33:33 UTC (rev 20314)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/query/ThreeEntityQueryGenerator.java 2010-09-07 13:52:38 UTC (rev 20315)
@@ -25,18 +25,18 @@
import java.util.Collections;
+import org.hibernate.Query;
import org.hibernate.envers.RevisionType;
+import org.hibernate.envers.configuration.AuditEntitiesConfiguration;
import org.hibernate.envers.configuration.GlobalConfiguration;
-import org.hibernate.envers.configuration.AuditEntitiesConfiguration;
import org.hibernate.envers.entities.mapper.id.QueryParameterData;
import org.hibernate.envers.entities.mapper.relation.MiddleComponentData;
import org.hibernate.envers.entities.mapper.relation.MiddleIdData;
import org.hibernate.envers.reader.AuditReaderImplementor;
+import org.hibernate.envers.strategy.AuditStrategy;
import org.hibernate.envers.tools.query.Parameters;
import org.hibernate.envers.tools.query.QueryBuilder;
-import org.hibernate.Query;
-
/**
* Selects data from a relation middle-table and a two related versions entity.
* @author Adam Warski (adam at warski dot org)
@@ -47,6 +47,7 @@
public ThreeEntityQueryGenerator(GlobalConfiguration globalCfg,
AuditEntitiesConfiguration verEntCfg,
+ AuditStrategy auditStrategy,
String versionsMiddleEntityName,
MiddleIdData referencingIdData,
MiddleIdData referencedIdData,
@@ -65,14 +66,48 @@
* (only entities referenced by the association; id_ref_ing = id of the referencing entity)
* ee.id_ref_ing = :id_ref_ing AND
* (selecting e entities at revision :revision)
+ * --> for DefaultAuditStrategy:
* e.revision = (SELECT max(e2.revision) FROM versionsReferencedEntity e2
- * WHERE e2.revision <= :revision AND e2.id_ref_ed = e.id_ref_ed) AND
+ * WHERE e2.revision <= :revision AND e2.id = e.id)
+ *
+ * --> for ValidTimeAuditStrategy:
+ * e.revision <= :revision and (e.endRevision > :revision or e.endRevision is null)
+ *
+ * AND
+ *
* (selecting f entities at revision :revision)
+ * --> for DefaultAuditStrategy:
* f.revision = (SELECT max(f2.revision) FROM versionsIndexEntity f2
- * WHERE f2.revision <= :revision AND f2.id_ref_ed = f.id_ref_ed) AND
+ * WHERE f2.revision <= :revision AND f2.id_ref_ed = f.id_ref_ed)
+ *
+ * --> for ValidTimeAuditStrategy:
+ * f.revision <= :revision and (f.endRevision > :revision or f.endRevision is null)
+ *
+ * AND
+ *
* (the association at revision :revision)
+ * --> for DefaultAuditStrategy:
* ee.revision = (SELECT max(ee2.revision) FROM middleEntity ee2
- * WHERE ee2.revision <= :revision AND ee2.originalId.* = ee.originalId.*) AND
+ * WHERE ee2.revision <= :revision AND ee2.originalId.* = ee.originalId.*)
+ *
+ * --> for ValidTimeAuditStrategy:
+ * ee.revision <= :revision and (ee.endRevision > :revision or ee.endRevision is null)
+ *
+ and (
+ strtestent1_.REVEND>?
+ or strtestent1_.REVEND is null
+ )
+ and (
+ strtestent1_.REVEND>?
+ or strtestent1_.REVEND is null
+ )
+ and (
+ ternarymap0_.REVEND>?
+ or ternarymap0_.REVEND is null
+ )
+ *
+ *
+ *
* (only non-deleted entities and associations)
* ee.revision_type != DEL AND
* e.revision_type != DEL AND
@@ -80,7 +115,6 @@
*/
String revisionPropertyPath = verEntCfg.getRevisionNumberPath();
String originalIdPropertyName = verEntCfg.getOriginalIdPropName();
-
String eeOriginalIdPropertyPath = "ee." + originalIdPropertyName;
// SELECT new list(ee) FROM middleEntity ee
@@ -99,18 +133,24 @@
// ee.originalId.id_ref_ing = :id_ref_ing
referencingIdData.getPrefixedMapper().addNamedIdEqualsToQuery(rootParameters, originalIdPropertyName, true);
- // e.revision = (SELECT max(...) ...)
- QueryGeneratorTools.addEntityAtRevision(globalCfg, qb, rootParameters, referencedIdData, revisionPropertyPath,
- originalIdPropertyName, "e", "e2");
+ // (selecting e entities at revision :revision)
+ // --> based on auditStrategy (see above)
+ auditStrategy.addEntityAtRevisionRestriction(globalCfg, qb, "e." + revisionPropertyPath,
+ "e." + verEntCfg.getRevisionEndFieldName(), false,
+ referencedIdData, revisionPropertyPath, originalIdPropertyName, "e", "e2");
+
+ // (selecting f entities at revision :revision)
+ // --> based on auditStrategy (see above)
+ auditStrategy.addEntityAtRevisionRestriction(globalCfg, qb, "e." + revisionPropertyPath,
+ "e." + verEntCfg.getRevisionEndFieldName(), false,
+ referencedIdData, revisionPropertyPath, originalIdPropertyName, "f", "f2");
- // f.revision = (SELECT max(...) ...)
- QueryGeneratorTools.addEntityAtRevision(globalCfg, qb, rootParameters, indexIdData, revisionPropertyPath,
- originalIdPropertyName, "f", "f2");
+ // (with ee association at revision :revision)
+ // --> based on auditStrategy (see above)
+ auditStrategy.addAssociationAtRevisionRestriction(qb, revisionPropertyPath,
+ verEntCfg.getRevisionEndFieldName(), true, referencingIdData, versionsMiddleEntityName,
+ eeOriginalIdPropertyPath, revisionPropertyPath, originalIdPropertyName, componentDatas);
- // ee.revision = (SELECT max(...) ...)
- QueryGeneratorTools.addAssociationAtRevision(qb, rootParameters, referencingIdData, versionsMiddleEntityName,
- eeOriginalIdPropertyPath, revisionPropertyPath, originalIdPropertyName, componentDatas);
-
// ee.revision_type != DEL
rootParameters.addWhereWithNamedParam(verEntCfg.getRevisionTypePropName(), "!=", "delrevisiontype");
// e.revision_type != DEL
Modified: core/trunk/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/query/TwoEntityOneAuditedQueryGenerator.java
===================================================================
--- core/trunk/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/query/TwoEntityOneAuditedQueryGenerator.java 2010-09-07 07:33:33 UTC (rev 20314)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/query/TwoEntityOneAuditedQueryGenerator.java 2010-09-07 13:52:38 UTC (rev 20315)
@@ -26,11 +26,14 @@
import java.util.Collections;
import org.hibernate.envers.RevisionType;
+import org.hibernate.envers.configuration.AuditConfiguration;
import org.hibernate.envers.configuration.AuditEntitiesConfiguration;
+import org.hibernate.envers.configuration.GlobalConfiguration;
import org.hibernate.envers.entities.mapper.id.QueryParameterData;
import org.hibernate.envers.entities.mapper.relation.MiddleComponentData;
import org.hibernate.envers.entities.mapper.relation.MiddleIdData;
import org.hibernate.envers.reader.AuditReaderImplementor;
+import org.hibernate.envers.strategy.AuditStrategy;
import org.hibernate.envers.tools.query.Parameters;
import org.hibernate.envers.tools.query.QueryBuilder;
@@ -44,8 +47,7 @@
private final String queryString;
private final MiddleIdData referencingIdData;
- public TwoEntityOneAuditedQueryGenerator(
- AuditEntitiesConfiguration verEntCfg,
+ public TwoEntityOneAuditedQueryGenerator(AuditEntitiesConfiguration verEntCfg, AuditStrategy auditStrategy,
String versionsMiddleEntityName,
MiddleIdData referencingIdData,
MiddleIdData referencedIdData,
@@ -60,9 +62,17 @@
* ee.id_ref_ed = e.id_ref_ed AND
* (only entities referenced by the association; id_ref_ing = id of the referencing entity)
* ee.id_ref_ing = :id_ref_ing AND
+ *
* (the association at revision :revision)
+ * --> for DefaultAuditStrategy:
* ee.revision = (SELECT max(ee2.revision) FROM middleEntity ee2
- * WHERE ee2.revision <= :revision AND ee2.originalId.* = ee.originalId.*) AND
+ * WHERE ee2.revision <= :revision AND ee2.originalId.* = ee.originalId.*)
+ *
+ * --> for ValidTimeAuditStrategy:
+ * ee.revision <= :revision and (ee.endRevision > :revision or ee.endRevision is null)
+ *
+ * AND
+ *
* (only non-deleted entities and associations)
* ee.revision_type != DEL
*/
@@ -83,9 +93,11 @@
// ee.originalId.id_ref_ing = :id_ref_ing
referencingIdData.getPrefixedMapper().addNamedIdEqualsToQuery(rootParameters, originalIdPropertyName, true);
- // ee.revision = (SELECT max(...) ...)
- QueryGeneratorTools.addAssociationAtRevision(qb, rootParameters, referencingIdData, versionsMiddleEntityName,
- eeOriginalIdPropertyPath, revisionPropertyPath, originalIdPropertyName, componentDatas);
+ // (with ee association at revision :revision)
+ // --> based on auditStrategy (see above)
+ auditStrategy.addAssociationAtRevisionRestriction(qb, revisionPropertyPath,
+ verEntCfg.getRevisionEndFieldName(), true,referencingIdData, versionsMiddleEntityName,
+ eeOriginalIdPropertyPath, revisionPropertyPath, originalIdPropertyName, componentDatas);
// ee.revision_type != DEL
rootParameters.addWhereWithNamedParam(verEntCfg.getRevisionTypePropName(), "!=", "delrevisiontype");
@@ -105,4 +117,4 @@
return query;
}
-}
\ No newline at end of file
+}
Modified: core/trunk/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/query/TwoEntityQueryGenerator.java
===================================================================
--- core/trunk/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/query/TwoEntityQueryGenerator.java 2010-09-07 07:33:33 UTC (rev 20314)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/query/TwoEntityQueryGenerator.java 2010-09-07 13:52:38 UTC (rev 20315)
@@ -25,18 +25,18 @@
import java.util.Collections;
+import org.hibernate.Query;
import org.hibernate.envers.RevisionType;
+import org.hibernate.envers.configuration.AuditEntitiesConfiguration;
import org.hibernate.envers.configuration.GlobalConfiguration;
-import org.hibernate.envers.configuration.AuditEntitiesConfiguration;
import org.hibernate.envers.entities.mapper.id.QueryParameterData;
import org.hibernate.envers.entities.mapper.relation.MiddleComponentData;
import org.hibernate.envers.entities.mapper.relation.MiddleIdData;
import org.hibernate.envers.reader.AuditReaderImplementor;
+import org.hibernate.envers.strategy.AuditStrategy;
import org.hibernate.envers.tools.query.Parameters;
import org.hibernate.envers.tools.query.QueryBuilder;
-import org.hibernate.Query;
-
/**
* Selects data from a relation middle-table and a related versions entity.
* @author Adam Warski (adam at warski dot org)
@@ -47,6 +47,7 @@
public TwoEntityQueryGenerator(GlobalConfiguration globalCfg,
AuditEntitiesConfiguration verEntCfg,
+ AuditStrategy auditStrategy,
String versionsMiddleEntityName,
MiddleIdData referencingIdData,
MiddleIdData referencedIdData,
@@ -61,12 +62,25 @@
* ee.id_ref_ed = e.id_ref_ed AND
* (only entities referenced by the association; id_ref_ing = id of the referencing entity)
* ee.id_ref_ing = :id_ref_ing AND
+ *
* (selecting e entities at revision :revision)
+ * --> for DefaultAuditStrategy:
* e.revision = (SELECT max(e2.revision) FROM versionsReferencedEntity e2
- * WHERE e2.revision <= :revision AND e2.id_ref_ed = e.id_ref_ed) AND
- * (the association at revision :revision)
+ * WHERE e2.revision <= :revision AND e2.id = e.id)
+ *
+ * --> for ValidTimeAuditStrategy:
+ * e.revision <= :revision and (e.endRevision > :revision or e.endRevision is null)
+ *
+ * AND
+ *
+ * (the association at revision :revision)
+ * --> for DefaultAuditStrategy:
* ee.revision = (SELECT max(ee2.revision) FROM middleEntity ee2
- * WHERE ee2.revision <= :revision AND ee2.originalId.* = ee.originalId.*) AND
+ * WHERE ee2.revision <= :revision AND ee2.originalId.* = ee.originalId.*)
+ *
+ * --> for ValidTimeAuditStrategy:
+ * ee.revision <= :revision and (ee.endRevision > :revision or ee.endRevision is null)
+ *
* (only non-deleted entities and associations)
* ee.revision_type != DEL AND
* e.revision_type != DEL
@@ -88,13 +102,17 @@
// ee.originalId.id_ref_ing = :id_ref_ing
referencingIdData.getPrefixedMapper().addNamedIdEqualsToQuery(rootParameters, originalIdPropertyName, true);
- // e.revision = (SELECT max(...) ...)
- QueryGeneratorTools.addEntityAtRevision(globalCfg, qb, rootParameters, referencedIdData, revisionPropertyPath,
- originalIdPropertyName, "e", "e2");
+ // (selecting e entities at revision :revision)
+ // --> based on auditStrategy (see above)
+ auditStrategy.addEntityAtRevisionRestriction(globalCfg, qb, "e." + revisionPropertyPath,
+ "e." + verEntCfg.getRevisionEndFieldName(), false,
+ referencedIdData, revisionPropertyPath, originalIdPropertyName, "e", "e2");
- // ee.revision = (SELECT max(...) ...)
- QueryGeneratorTools.addAssociationAtRevision(qb, rootParameters, referencingIdData, versionsMiddleEntityName,
- eeOriginalIdPropertyPath, revisionPropertyPath, originalIdPropertyName, componentDatas);
+ // (with ee association at revision :revision)
+ // --> based on auditStrategy (see above)
+ auditStrategy.addAssociationAtRevisionRestriction(qb, revisionPropertyPath,
+ verEntCfg.getRevisionEndFieldName(), true, referencingIdData, versionsMiddleEntityName,
+ eeOriginalIdPropertyPath, revisionPropertyPath, originalIdPropertyName, componentDatas);
// ee.revision_type != DEL
rootParameters.addWhereWithNamedParam(verEntCfg.getRevisionTypePropName(), "!=", "delrevisiontype");
Modified: core/trunk/envers/src/main/java/org/hibernate/envers/query/impl/AbstractAuditQuery.java
===================================================================
--- core/trunk/envers/src/main/java/org/hibernate/envers/query/impl/AbstractAuditQuery.java 2010-09-07 07:33:33 UTC (rev 20314)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/query/impl/AbstractAuditQuery.java 2010-09-07 13:52:38 UTC (rev 20315)
@@ -86,10 +86,14 @@
qb = new QueryBuilder(versionsEntityName, "e");
}
- protected List buildAndExecuteQuery() {
+ protected Query buildQuery() {
Query query = qb.toQuery(versionsReader.getSession());
-
setQueryProperties(query);
+ return query;
+ }
+
+ protected List buildAndExecuteQuery() {
+ Query query = buildQuery();
return query.list();
}
Modified: core/trunk/envers/src/main/java/org/hibernate/envers/query/impl/EntitiesAtRevisionQuery.java
===================================================================
--- core/trunk/envers/src/main/java/org/hibernate/envers/query/impl/EntitiesAtRevisionQuery.java 2010-09-07 07:33:33 UTC (rev 20314)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/query/impl/EntitiesAtRevisionQuery.java 2010-09-07 13:52:38 UTC (rev 20315)
@@ -24,14 +24,16 @@
package org.hibernate.envers.query.impl;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.List;
+import org.hibernate.Query;
import org.hibernate.envers.RevisionType;
import org.hibernate.envers.configuration.AuditConfiguration;
import org.hibernate.envers.configuration.AuditEntitiesConfiguration;
+import org.hibernate.envers.entities.mapper.relation.MiddleIdData;
import org.hibernate.envers.query.criteria.AuditCriterion;
import org.hibernate.envers.reader.AuditReaderImplementor;
-import org.hibernate.envers.tools.query.QueryBuilder;
/**
* @author Adam Warski (adam at warski dot org)
@@ -56,40 +58,51 @@
@SuppressWarnings({"unchecked"})
public List list() {
/*
- The query that should be executed in the versions table:
- SELECT e FROM ent_ver e WHERE
- (all specified conditions, transformed, on the "e" entity) AND
- e.revision_type != DEL AND
- e.revision = (SELECT max(e2.revision) FROM ent_ver e2 WHERE
- e2.revision <= :revision AND e2.originalId.id = e.originalId.id)
+ * The query that we need to create:
+ * SELECT new list(e) FROM versionsReferencedEntity e
+ * WHERE
+ * (all specified conditions, transformed, on the "e" entity) AND
+ * (selecting e entities at revision :revision)
+ * --> for DefaultAuditStrategy:
+ * e.revision = (SELECT max(e2.revision) FROM versionsReferencedEntity e2
+ * WHERE e2.revision <= :revision AND e2.id = e.id)
+ *
+ * --> for ValidTimeAuditStrategy:
+ * e.revision <= :revision and (e.endRevision > :revision or e.endRevision is null)
+ *
+ * AND
+ * (only non-deleted entities)
+ * e.revision_type != DEL
*/
-
- QueryBuilder maxRevQb = qb.newSubQueryBuilder(versionsEntityName, "e2");
-
AuditEntitiesConfiguration verEntCfg = verCfg.getAuditEntCfg();
-
String revisionPropertyPath = verEntCfg.getRevisionNumberPath();
String originalIdPropertyName = verEntCfg.getOriginalIdPropName();
- // SELECT max(e2.revision)
- maxRevQb.addProjection("max", revisionPropertyPath, false);
- // e2.revision <= :revision
- maxRevQb.getRootParameters().addWhereWithParam(revisionPropertyPath, "<=", revision);
- // e2.id = e.id
- verCfg.getEntCfg().get(entityName).getIdMapper().addIdsEqualToQuery(maxRevQb.getRootParameters(),
- "e." + originalIdPropertyName, "e2." + originalIdPropertyName);
+ MiddleIdData referencedIdData = new MiddleIdData(verEntCfg, verCfg.getEntCfg().get(entityName).getIdMappingData(),
+ null, entityName, verCfg.getEntCfg().isVersioned(entityName));
- // e.revision_type != DEL AND
- qb.getRootParameters().addWhereWithParam(verEntCfg.getRevisionTypePropName(), "<>", RevisionType.DEL);
- // e.revision = (SELECT max(...) ...)
- qb.getRootParameters().addWhere(revisionPropertyPath, verCfg.getGlobalCfg().getCorrelatedSubqueryOperator(), maxRevQb);
+ // (selecting e entities at revision :revision)
+ // --> based on auditStrategy (see above)
+ verCfg.getAuditStrategy().addEntityAtRevisionRestriction(verCfg.getGlobalCfg(), qb, revisionPropertyPath,
+ verEntCfg.getRevisionEndFieldName(), true, referencedIdData,
+ revisionPropertyPath, originalIdPropertyName, "e", "e2");
+
+ // e.revision_type != DEL
+ qb.getRootParameters().addWhereWithParam(verEntCfg.getRevisionTypePropName(), "<>", RevisionType.DEL);
+
// all specified conditions
for (AuditCriterion criterion : criterions) {
criterion.addToQuery(verCfg, entityName, qb, qb.getRootParameters());
}
+
+ Query query = buildQuery();
+ // add named parameter (only used for ValidAuditTimeStrategy)
+ List<String> params = Arrays.asList(query.getNamedParameters());
+ if (params.contains("revision")) {
+ query.setParameter("revision", revision);
+ }
+ List queryResult = query.list();
- List queryResult = buildAndExecuteQuery();
-
if (hasProjection) {
return queryResult;
} else {
Modified: core/trunk/envers/src/main/java/org/hibernate/envers/strategy/AuditStrategy.java
===================================================================
--- core/trunk/envers/src/main/java/org/hibernate/envers/strategy/AuditStrategy.java 2010-09-07 07:33:33 UTC (rev 20314)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/strategy/AuditStrategy.java 2010-09-07 13:52:38 UTC (rev 20315)
@@ -1,11 +1,15 @@
package org.hibernate.envers.strategy;
+import java.io.Serializable;
+
import org.hibernate.Session;
import org.hibernate.envers.configuration.AuditConfiguration;
+import org.hibernate.envers.configuration.GlobalConfiguration;
import org.hibernate.envers.entities.mapper.PersistentCollectionChangeData;
+import org.hibernate.envers.entities.mapper.relation.MiddleComponentData;
+import org.hibernate.envers.entities.mapper.relation.MiddleIdData;
+import org.hibernate.envers.tools.query.QueryBuilder;
-import java.io.Serializable;
-
/**
* Behaviours of different audit strategy for populating audit data.
*
@@ -36,4 +40,61 @@
*/
void performCollectionChange(Session session, AuditConfiguration auditCfg,
PersistentCollectionChangeData persistentCollectionChangeData, Object revision);
+
+
+ /**
+ * Update the rootQueryBuilder with an extra WHERE clause to restrict the revision for a two-entity relation.
+ * This WHERE clause depends on the AuditStrategy, as follows:
+ * <ul>
+ * <li>For {@link DefaultAuditStrategy} a subquery is created:
+ * <p><code>e.revision = (SELECT max(...) ...)</code></p>
+ * </li>
+ * <li>for {@link ValidTimeAuditStrategy} the revision-end column is used:
+ * <p><code>e.revision <= :revision and (e.endRevision > :revision or e.endRevision is null)</code></p>
+ * </li>
+ * </ul>
+ *
+ * @param globalCfg the {@link GlobalConfiguration}
+ * @param rootQueryBuilder the {@link QueryBuilder} that will be updated
+ * @param revisionProperty property of the revision column
+ * @param revisionEndProperty property of the revisionEnd column (only used for {@link ValidTimeAuditStrategy})
+ * @param addAlias {@code boolean} indicator if a left alias is needed
+ * @param idData id-information for the two-entity relation (only used for {@link DefaultAuditStrategy})
+ * @param revisionPropertyPath path of the revision property (only used for {@link ValidTimeAuditStrategy})
+ * @param originalIdPropertyName name of the id property (only used for {@link ValidTimeAuditStrategy})
+ * @param alias1 an alias used for subquery (only used for {@link ValidTimeAuditStrategy})
+ * @param alias2 an alias used for subquery (only used for {@link ValidTimeAuditStrategy})
+ */
+ void addEntityAtRevisionRestriction(GlobalConfiguration globalCfg, QueryBuilder rootQueryBuilder,
+ String revisionProperty, String revisionEndProperty, boolean addAlias, MiddleIdData idData,
+ String revisionPropertyPath, String originalIdPropertyName, String alias1, String alias2);
+
+ /**
+ * Update the rootQueryBuilder with an extra WHERE clause to restrict the revision for a middle-entity
+ * association. This WHERE clause depends on the AuditStrategy, as follows:
+ * <ul>
+ * <li>For {@link DefaultAuditStrategy} a subquery is created:
+ * <p><code>e.revision = (SELECT max(...) ...)</code></p>
+ * </li>
+ * <li>for {@link ValidTimeAuditStrategy} the revision-end column is used:
+ * <p><code>e.revision <= :revision and (e.endRevision > :revision or e.endRevision is null)</code></p>
+ * </li>
+ * </ul>
+ *
+ * @param rootQueryBuilder the {@link QueryBuilder} that will be updated
+ * @param revisionProperty property of the revision column
+ * @param revisionEndProperty property of the revisionEnd column (only used for {@link ValidTimeAuditStrategy})
+ * @param addAlias {@code boolean} indicator if a left alias is needed
+ * @param referencingIdData id-information for the middle-entity association (only used for {@link DefaultAuditStrategy})
+ * @param versionsMiddleEntityName name of the middle-entity
+ * @param eeOriginalIdPropertyPath name of the id property (only used for {@link ValidTimeAuditStrategy})
+ * @param revisionPropertyPath path of the revision property (only used for {@link ValidTimeAuditStrategy})
+ * @param originalIdPropertyName name of the id property (only used for {@link ValidTimeAuditStrategy})
+ * @param componentDatas information about the middle-entity relation
+ */
+ void addAssociationAtRevisionRestriction(QueryBuilder rootQueryBuilder, String revisionProperty,
+ String revisionEndProperty, boolean addAlias, MiddleIdData referencingIdData,
+ String versionsMiddleEntityName, String eeOriginalIdPropertyPath, String revisionPropertyPath,
+ String originalIdPropertyName, MiddleComponentData... componentDatas);
+
}
Modified: core/trunk/envers/src/main/java/org/hibernate/envers/strategy/DefaultAuditStrategy.java
===================================================================
--- core/trunk/envers/src/main/java/org/hibernate/envers/strategy/DefaultAuditStrategy.java 2010-09-07 07:33:33 UTC (rev 20314)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/strategy/DefaultAuditStrategy.java 2010-09-07 13:52:38 UTC (rev 20315)
@@ -1,11 +1,16 @@
package org.hibernate.envers.strategy;
+import java.io.Serializable;
+
import org.hibernate.Session;
import org.hibernate.envers.configuration.AuditConfiguration;
+import org.hibernate.envers.configuration.GlobalConfiguration;
import org.hibernate.envers.entities.mapper.PersistentCollectionChangeData;
+import org.hibernate.envers.entities.mapper.relation.MiddleComponentData;
+import org.hibernate.envers.entities.mapper.relation.MiddleIdData;
+import org.hibernate.envers.tools.query.Parameters;
+import org.hibernate.envers.tools.query.QueryBuilder;
-import java.io.Serializable;
-
/**
* Default strategy is to simply persist the audit data.
*
@@ -22,4 +27,52 @@
PersistentCollectionChangeData persistentCollectionChangeData, Object revision) {
session.save(persistentCollectionChangeData.getEntityName(), persistentCollectionChangeData.getData());
}
+
+
+ public void addEntityAtRevisionRestriction(GlobalConfiguration globalCfg, QueryBuilder rootQueryBuilder, String revisionProperty,
+ String revisionEndProperty, boolean addAlias, MiddleIdData idData, String revisionPropertyPath,
+ String originalIdPropertyName, String alias1, String alias2) {
+ Parameters rootParameters = rootQueryBuilder.getRootParameters();
+
+ // create a subquery builder
+ // SELECT max(e.revision) FROM versionsReferencedEntity e2
+ QueryBuilder maxERevQb = rootQueryBuilder.newSubQueryBuilder(idData.getAuditEntityName(), alias2);
+ maxERevQb.addProjection("max", revisionPropertyPath, false);
+ // WHERE
+ Parameters maxERevQbParameters = maxERevQb.getRootParameters();
+ // e2.revision <= :revision
+ maxERevQbParameters.addWhereWithNamedParam(revisionPropertyPath, "<=", "revision");
+ // e2.id_ref_ed = e.id_ref_ed
+ idData.getOriginalMapper().addIdsEqualToQuery(maxERevQbParameters,
+ alias1 + "." + originalIdPropertyName, alias2 +"." + originalIdPropertyName);
+
+ // add subquery to rootParameters
+ String subqueryOperator = globalCfg.getCorrelatedSubqueryOperator();
+ rootParameters.addWhere(revisionProperty, addAlias, subqueryOperator, maxERevQb);
+ }
+
+ public void addAssociationAtRevisionRestriction(QueryBuilder rootQueryBuilder, String revisionProperty,
+ String revisionEndProperty, boolean addAlias, MiddleIdData referencingIdData, String versionsMiddleEntityName,
+ String eeOriginalIdPropertyPath, String revisionPropertyPath,
+ String originalIdPropertyName, MiddleComponentData... componentDatas) {
+ Parameters rootParameters = rootQueryBuilder.getRootParameters();
+
+ // SELECT max(ee2.revision) FROM middleEntity ee2
+ QueryBuilder maxEeRevQb = rootQueryBuilder.newSubQueryBuilder(versionsMiddleEntityName, "ee2");
+ maxEeRevQb.addProjection("max", revisionPropertyPath, false);
+ // WHERE
+ Parameters maxEeRevQbParameters = maxEeRevQb.getRootParameters();
+ // ee2.revision <= :revision
+ maxEeRevQbParameters.addWhereWithNamedParam(revisionPropertyPath, "<=", "revision");
+ // ee2.originalId.* = ee.originalId.*
+ String ee2OriginalIdPropertyPath = "ee2." + originalIdPropertyName;
+ referencingIdData.getPrefixedMapper().addIdsEqualToQuery(maxEeRevQbParameters, eeOriginalIdPropertyPath, ee2OriginalIdPropertyPath);
+ for (MiddleComponentData componentData : componentDatas) {
+ componentData.getComponentMapper().addMiddleEqualToQuery(maxEeRevQbParameters, eeOriginalIdPropertyPath, ee2OriginalIdPropertyPath);
+ }
+
+ // add subquery to rootParameters
+ rootParameters.addWhere(revisionProperty, addAlias, "=", maxEeRevQb);
+ }
+
}
Modified: core/trunk/envers/src/main/java/org/hibernate/envers/strategy/ValidTimeAuditStrategy.java
===================================================================
--- core/trunk/envers/src/main/java/org/hibernate/envers/strategy/ValidTimeAuditStrategy.java 2010-09-07 07:33:33 UTC (rev 20314)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/strategy/ValidTimeAuditStrategy.java 2010-09-07 13:52:38 UTC (rev 20315)
@@ -8,8 +8,12 @@
import org.hibernate.envers.RevisionType;
import org.hibernate.envers.configuration.AuditConfiguration;
import org.hibernate.envers.configuration.AuditEntitiesConfiguration;
+import org.hibernate.envers.configuration.GlobalConfiguration;
import org.hibernate.envers.entities.mapper.PersistentCollectionChangeData;
import org.hibernate.envers.entities.mapper.id.IdMapper;
+import org.hibernate.envers.entities.mapper.relation.MiddleComponentData;
+import org.hibernate.envers.entities.mapper.relation.MiddleIdData;
+import org.hibernate.envers.tools.query.Parameters;
import org.hibernate.envers.tools.query.QueryBuilder;
/**
@@ -75,6 +79,32 @@
session.save(persistentCollectionChangeData.getEntityName(), persistentCollectionChangeData.getData());
}
+ public void addEntityAtRevisionRestriction(GlobalConfiguration globalCfg, QueryBuilder rootQueryBuilder,
+ String revisionProperty,String revisionEndProperty, boolean addAlias,
+ MiddleIdData idData, String revisionPropertyPath, String originalIdPropertyName,
+ String alias1, String alias2) {
+ Parameters rootParameters = rootQueryBuilder.getRootParameters();
+ addRevisionRestriction(rootParameters, revisionProperty, revisionEndProperty, addAlias);
+ }
+
+ public void addAssociationAtRevisionRestriction(QueryBuilder rootQueryBuilder, String revisionProperty,
+ String revisionEndProperty, boolean addAlias, MiddleIdData referencingIdData,
+ String versionsMiddleEntityName, String eeOriginalIdPropertyPath, String revisionPropertyPath,
+ String originalIdPropertyName, MiddleComponentData... componentDatas) {
+ Parameters rootParameters = rootQueryBuilder.getRootParameters();
+ addRevisionRestriction(rootParameters, revisionProperty, revisionEndProperty, addAlias);
+ }
+
+ private void addRevisionRestriction(Parameters rootParameters,
+ String revisionProperty, String revisionEndProperty, boolean addAlias) {
+
+ // e.revision <= _revision and (e.endRevision > _revision or e.endRevision is null)
+ Parameters subParm = rootParameters.addSubParameters("or");
+ rootParameters.addWhereWithNamedParam(revisionProperty, addAlias, "<=", "revision");
+ subParm.addWhereWithNamedParam(revisionEndProperty + ".id", addAlias, ">", "revision");
+ subParm.addWhere(revisionEndProperty, addAlias, "is", "null", false);
+ }
+
@SuppressWarnings({"unchecked"})
private RevisionType getRevisionType(AuditConfiguration auditCfg, Object data) {
return (RevisionType) ((Map<String, Object>) data).get(auditCfg.getAuditEntCfg().getRevisionTypePropName());
14 years, 6 months
Hibernate SVN: r20314 - in entitymanager/branches/v3_3_2_GA_CP: ivy and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: stliu
Date: 2010-09-07 03:33:33 -0400 (Tue, 07 Sep 2010)
New Revision: 20314
Added:
entitymanager/branches/v3_3_2_GA_CP/ivy.xml
entitymanager/branches/v3_3_2_GA_CP/ivy/
entitymanager/branches/v3_3_2_GA_CP/ivy/ivy-1.4.1.jar
entitymanager/branches/v3_3_2_GA_CP/ivy/ivyconf.xml
Removed:
entitymanager/branches/v3_3_2_GA_CP/ivy/ivy-1.4.1.jar
entitymanager/branches/v3_3_2_GA_CP/ivy/ivyconf.xml
Log:
JBPAPP-4959 rollback
Copied: entitymanager/branches/v3_3_2_GA_CP/ivy (from rev 20311, entitymanager/branches/v3_3_2_GA_CP/ivy)
Deleted: entitymanager/branches/v3_3_2_GA_CP/ivy/ivy-1.4.1.jar
===================================================================
(Binary files differ)
Copied: entitymanager/branches/v3_3_2_GA_CP/ivy/ivy-1.4.1.jar (from rev 20311, entitymanager/branches/v3_3_2_GA_CP/ivy/ivy-1.4.1.jar)
===================================================================
(Binary files differ)
Deleted: entitymanager/branches/v3_3_2_GA_CP/ivy/ivyconf.xml
===================================================================
--- entitymanager/branches/v3_3_2_GA_CP/ivy/ivyconf.xml 2010-09-06 08:30:26 UTC (rev 20311)
+++ entitymanager/branches/v3_3_2_GA_CP/ivy/ivyconf.xml 2010-09-07 07:33:33 UTC (rev 20314)
@@ -1,31 +0,0 @@
-<ivyconf>
- <conf defaultResolver="jboss-rep"/>
- <resolvers>
- <chain name="jboss-rep">
- <url name="jboss-rep-regular">
- <artifact pattern="http://repository.jboss.org/[module]/[revision]/lib/[artifact].[ext]"/>
- </url>
- </chain>
- <chain name="rep-hibernate" returnFirst="true" latest="latest-revision">
- <filesystem name="local">
- <ivy pattern="../[module]/target/[revision]/ivy.xml"/>
- <artifact pattern="../[module]/target/[revision]/[artifact].[ext]"/>
- </filesystem>
- <url name="jboss-rep-hibernate">
- <ivy pattern="http://repository.jboss.org/hibernate-[module]/[revision]/ivy.xml"/>
- <artifact pattern="http://repository.jboss.org/hibernate-[module]/[revision]/lib/[artifact]...."/>
- </url>
- <url name="jboss-rep-regular-with-ivy">
- <ivy pattern="http://repository.jboss.org/[module]/[revision]/ivy.xml"/>
- <artifact pattern="http://repository.jboss.org/[module]/[revision]/lib/[artifact].[ext]"/>
- </url>
- <url name="jboss-rep-maven" m2compatible="true">
- <ivy pattern="http://repository.jboss.org/maven2/[organization]/[module]/[revision]/ivy..."/>
- <artifact pattern="http://repository.jboss.org/maven2/[organization]/[module]/[revision]/[ar..."/>
- </url>
- </chain>
- </resolvers>
- <modules>
- <module organisation="org.hibernate" name="*" resolver="rep-hibernate"/>
- </modules>
-</ivyconf>
Copied: entitymanager/branches/v3_3_2_GA_CP/ivy/ivyconf.xml (from rev 20311, entitymanager/branches/v3_3_2_GA_CP/ivy/ivyconf.xml)
===================================================================
--- entitymanager/branches/v3_3_2_GA_CP/ivy/ivyconf.xml (rev 0)
+++ entitymanager/branches/v3_3_2_GA_CP/ivy/ivyconf.xml 2010-09-07 07:33:33 UTC (rev 20314)
@@ -0,0 +1,31 @@
+<ivyconf>
+ <conf defaultResolver="jboss-rep"/>
+ <resolvers>
+ <chain name="jboss-rep">
+ <url name="jboss-rep-regular">
+ <artifact pattern="http://repository.jboss.org/[module]/[revision]/lib/[artifact].[ext]"/>
+ </url>
+ </chain>
+ <chain name="rep-hibernate" returnFirst="true" latest="latest-revision">
+ <filesystem name="local">
+ <ivy pattern="../[module]/target/[revision]/ivy.xml"/>
+ <artifact pattern="../[module]/target/[revision]/[artifact].[ext]"/>
+ </filesystem>
+ <url name="jboss-rep-hibernate">
+ <ivy pattern="http://repository.jboss.org/hibernate-[module]/[revision]/ivy.xml"/>
+ <artifact pattern="http://repository.jboss.org/hibernate-[module]/[revision]/lib/[artifact]...."/>
+ </url>
+ <url name="jboss-rep-regular-with-ivy">
+ <ivy pattern="http://repository.jboss.org/[module]/[revision]/ivy.xml"/>
+ <artifact pattern="http://repository.jboss.org/[module]/[revision]/lib/[artifact].[ext]"/>
+ </url>
+ <url name="jboss-rep-maven" m2compatible="true">
+ <ivy pattern="http://repository.jboss.org/maven2/[organization]/[module]/[revision]/ivy..."/>
+ <artifact pattern="http://repository.jboss.org/maven2/[organization]/[module]/[revision]/[ar..."/>
+ </url>
+ </chain>
+ </resolvers>
+ <modules>
+ <module organisation="org.hibernate" name="*" resolver="rep-hibernate"/>
+ </modules>
+</ivyconf>
Copied: entitymanager/branches/v3_3_2_GA_CP/ivy.xml (from rev 20312, entitymanager/branches/v3_3_2_GA_CP/ivy.xml)
===================================================================
--- entitymanager/branches/v3_3_2_GA_CP/ivy.xml (rev 0)
+++ entitymanager/branches/v3_3_2_GA_CP/ivy.xml 2010-09-07 07:33:33 UTC (rev 20314)
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ivy-module version="1.3"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:noNamespaceSchemaLocation=
+ "http://www.jayasoft.org/misc/ivy/ivy.xsd">
+ <info organisation="org.hibernate" module="hibernate-entitymanager"/>
+ <configurations>
+ <conf name="core" description="Core module dependencies"/>
+ <conf name="test" visibility="private" description="Dependencies needed for testing purposes"/>
+ </configurations>
+ <publications>
+ <artifact name="hibernate-entitymanager" conf="core"/>
+ </publications>
+ <dependencies>
+ <dependency name="hibernate-annotations" rev="3.3.1.GA" conf="core->core"/>
+ <dependency name="ejb3-persistence" rev="1.0.1.GA" conf="core->default"/>
+ <dependency name="commons-annotations" rev="3.0.0.GA" conf="core->core"/>
+ </dependencies>
+</ivy-module>
\ No newline at end of file
14 years, 6 months
Hibernate SVN: r20313 - entitymanager/branches/v3_3_2_GA_CP.
by hibernate-commits@lists.jboss.org
Author: stliu
Date: 2010-09-06 04:33:07 -0400 (Mon, 06 Sep 2010)
New Revision: 20313
Removed:
entitymanager/branches/v3_3_2_GA_CP/ivy.xml
Log:
JBPAPP-4959 remove ivy dependencies
Deleted: entitymanager/branches/v3_3_2_GA_CP/ivy.xml
===================================================================
--- entitymanager/branches/v3_3_2_GA_CP/ivy.xml 2010-09-06 08:31:56 UTC (rev 20312)
+++ entitymanager/branches/v3_3_2_GA_CP/ivy.xml 2010-09-06 08:33:07 UTC (rev 20313)
@@ -1,19 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<ivy-module version="1.3"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:noNamespaceSchemaLocation=
- "http://www.jayasoft.org/misc/ivy/ivy.xsd">
- <info organisation="org.hibernate" module="hibernate-entitymanager"/>
- <configurations>
- <conf name="core" description="Core module dependencies"/>
- <conf name="test" visibility="private" description="Dependencies needed for testing purposes"/>
- </configurations>
- <publications>
- <artifact name="hibernate-entitymanager" conf="core"/>
- </publications>
- <dependencies>
- <dependency name="hibernate-annotations" rev="3.3.1.GA" conf="core->core"/>
- <dependency name="ejb3-persistence" rev="1.0.1.GA" conf="core->default"/>
- <dependency name="commons-annotations" rev="3.0.0.GA" conf="core->core"/>
- </dependencies>
-</ivy-module>
\ No newline at end of file
14 years, 6 months
Hibernate SVN: r20311 - entitymanager/branches/v3_3_2_GA_CP.
by hibernate-commits@lists.jboss.org
Author: stliu
Date: 2010-09-06 04:30:26 -0400 (Mon, 06 Sep 2010)
New Revision: 20311
Removed:
entitymanager/branches/v3_3_2_GA_CP/doc/
Log:
JBPAPP-4959 remove unused doc source, the publish product doc comes from docs team's repo
14 years, 6 months
Hibernate SVN: r20310 - in validator/trunk/hibernate-validator-annotation-processor/src: main/resources/org/hibernate/validator/ap and 2 other directories.
by hibernate-commits@lists.jboss.org
Author: gunnar.morling
Date: 2010-09-05 06:48:06 -0400 (Sun, 05 Sep 2010)
New Revision: 20310
Added:
validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/constrainttypes/ConstraintsWithWrongGroupsAttribute.java
validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/constrainttypes/ConstraintsWithWrongPayloadAttribute.java
Modified:
validator/trunk/hibernate-validator-annotation-processor/src/main/java/org/hibernate/validator/ap/checks/AnnotationTypeMemberCheck.java
validator/trunk/hibernate-validator-annotation-processor/src/main/resources/org/hibernate/validator/ap/ValidationProcessorMessages.properties
validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/AnnotationTypeValidationTest.java
Log:
HV-299: Implemented check, that each constraint annotation type defines the members groups() and payload()
Modified: validator/trunk/hibernate-validator-annotation-processor/src/main/java/org/hibernate/validator/ap/checks/AnnotationTypeMemberCheck.java
===================================================================
--- validator/trunk/hibernate-validator-annotation-processor/src/main/java/org/hibernate/validator/ap/checks/AnnotationTypeMemberCheck.java 2010-09-04 07:40:43 UTC (rev 20309)
+++ validator/trunk/hibernate-validator-annotation-processor/src/main/java/org/hibernate/validator/ap/checks/AnnotationTypeMemberCheck.java 2010-09-05 10:48:06 UTC (rev 20310)
@@ -18,11 +18,20 @@
package org.hibernate.validator.ap.checks;
import java.util.Collections;
+import java.util.List;
import java.util.Set;
import javax.lang.model.element.AnnotationMirror;
+import javax.lang.model.element.AnnotationValue;
import javax.lang.model.element.ExecutableElement;
import javax.lang.model.element.TypeElement;
+import javax.lang.model.type.ArrayType;
+import javax.lang.model.type.DeclaredType;
+import javax.lang.model.type.TypeMirror;
+import javax.lang.model.type.WildcardType;
+import javax.lang.model.util.SimpleAnnotationValueVisitor6;
+import javax.lang.model.util.TypeKindVisitor6;
import javax.lang.model.util.Types;
+import javax.validation.Payload;
import org.hibernate.validator.ap.util.AnnotationApiHelper;
import org.hibernate.validator.ap.util.CollectionHelper;
@@ -30,7 +39,8 @@
import static javax.lang.model.util.ElementFilter.methodsIn;
/**
- * Checks, that each constraint annotation type declares the members message(), groups() and payload().
+ * Checks, that each constraint annotation type declares the members message(), groups() and payload() as
+ * defined by the BV spec.
*
* @author Gunnar Morling
*/
@@ -58,6 +68,18 @@
return theValue;
}
+ /**
+ * Checks that the given type element
+ * <p/>
+ * <ul>
+ * <li>has a method with name "message",</li>
+ * <li>the return type of this method is {@link String}.</li>
+ * </ul>
+ *
+ * @param element The element of interest.
+ *
+ * @return A possibly non-empty set of constraint check errors, never null.
+ */
private Set<ConstraintCheckError> checkMessageAttribute(TypeElement element) {
ExecutableElement messageMethod = getMethod( element, "message" );
@@ -79,14 +101,116 @@
return Collections.emptySet();
}
+ /**
+ * Checks that the given type element
+ * <p/>
+ * <ul>
+ * <li>has a method with name "groups",</li>
+ * <li>the return type of this method is <code>Class<?>[]</code>,</li>
+ * <li>the default value of this method is <code>{}</code>.</li>
+ * </ul>
+ *
+ * @param element The element of interest.
+ *
+ * @return A possibly non-empty set of constraint check errors, never null.
+ */
private Set<ConstraintCheckError> checkGroupsAttribute(TypeElement element) {
+
+ ExecutableElement groupsMethod = getMethod( element, "groups" );
+
+ if ( groupsMethod == null ) {
+ return CollectionHelper.asSet(
+ new ConstraintCheckError( element, null, "CONSTRAINT_TYPE_MUST_DECLARE_GROUPS_MEMBER" )
+ );
+ }
+
+ DeclaredType type = getComponentTypeOfArrayReturnType( groupsMethod );
+
+ if ( type == null ) {
+ return CollectionHelper.asSet(
+ new ConstraintCheckError( groupsMethod, null, "RETURN_TYPE_MUST_BE_CLASS_ARRAY" )
+ );
+ }
+
+ boolean typeHasNameClass = type.asElement().getSimpleName().contentEquals( "Class" );
+ boolean typeHasExactlyOneTypeArgument = type.getTypeArguments().size() == 1;
+ boolean typeArgumentIsUnboundWildcard = validateWildcardBounds( type.getTypeArguments().get( 0 ), null, null );
+
+ if ( !( typeHasNameClass && typeHasExactlyOneTypeArgument && typeArgumentIsUnboundWildcard ) ) {
+ return CollectionHelper.asSet(
+ new ConstraintCheckError( groupsMethod, null, "RETURN_TYPE_MUST_BE_CLASS_ARRAY" )
+ );
+ }
+
+ if ( !isEmptyArray( groupsMethod.getDefaultValue() ) ) {
+ return CollectionHelper.asSet(
+ new ConstraintCheckError( groupsMethod, null, "DEFAULT_VALUE_MUST_BE_EMPTY_ARRAY" )
+ );
+ }
+
return Collections.emptySet();
}
+ /**
+ * Checks that the given type element
+ * <p/>
+ * <ul>
+ * <li>has a method with name "payload",</li>
+ * <li>the return type of this method is <code>Class<? extends Payload>[]</code>,</li>
+ * <li>the default value of this method is <code>{}</code>.</li>
+ * </ul>
+ *
+ * @param element The element of interest.
+ *
+ * @return A possibly non-empty set of constraint check errors, never null.
+ */
private Set<ConstraintCheckError> checkPayloadAttribute(TypeElement element) {
+
+ ExecutableElement payloadMethod = getMethod( element, "payload" );
+
+ if ( payloadMethod == null ) {
+ return CollectionHelper.asSet(
+ new ConstraintCheckError( element, null, "CONSTRAINT_TYPE_MUST_DECLARE_PAYLOAD_MEMBER" )
+ );
+ }
+
+ DeclaredType type = getComponentTypeOfArrayReturnType( payloadMethod );
+
+ if ( type == null ) {
+ return CollectionHelper.asSet(
+ new ConstraintCheckError( payloadMethod, null, "PAYLOAD_RETURN_TYPE_MUST_BE_CLASS_ARRAY" )
+ );
+ }
+
+ boolean typeHasNameClass = type.asElement().getSimpleName().contentEquals( "Class" );
+ boolean typeHasExactlyOneTypeArgument = type.getTypeArguments().size() == 1;
+ boolean typeArgumentIsWildcardWithPayloadExtendsBound = validateWildcardBounds(
+ type.getTypeArguments().get( 0 ), annotationApiHelper.getMirrorForType( Payload.class ), null
+ );
+
+ if ( !( typeHasNameClass && typeHasExactlyOneTypeArgument && typeArgumentIsWildcardWithPayloadExtendsBound ) ) {
+ return CollectionHelper.asSet(
+ new ConstraintCheckError( payloadMethod, null, "PAYLOAD_RETURN_TYPE_MUST_BE_CLASS_ARRAY" )
+ );
+ }
+
+ if ( !isEmptyArray( payloadMethod.getDefaultValue() ) ) {
+ return CollectionHelper.asSet(
+ new ConstraintCheckError( payloadMethod, null, "PAYLOAD_DEFAULT_VALUE_MUST_BE_EMPTY_ARRAY" )
+ );
+ }
+
return Collections.emptySet();
}
+ /**
+ * Returns the method of the given type with the given name.
+ *
+ * @param element The type of interest.
+ * @param name The name of the method which should be returned.
+ *
+ * @return The method of the given type with the given name or null if no such method exists.
+ */
private ExecutableElement getMethod(TypeElement element, String name) {
for ( ExecutableElement oneMethod : methodsIn( element.getEnclosedElements() ) ) {
@@ -99,4 +223,91 @@
return null;
}
+ /**
+ * Returns the component type of the array-typed return value of the given method.
+ *
+ * @param method The method of interest.
+ *
+ * @return The component type of the array-typed return value of the given method or null,
+ * if the given method has no array-typed return value.
+ */
+ private DeclaredType getComponentTypeOfArrayReturnType(ExecutableElement method) {
+
+ return method.getReturnType().accept(
+ new TypeKindVisitor6<DeclaredType, Void>() {
+
+ @Override
+ public DeclaredType visitArray(ArrayType t, Void p) {
+
+ return t.getComponentType().accept(
+ new TypeKindVisitor6<DeclaredType, Void>() {
+
+ @Override
+ public DeclaredType visitDeclared(DeclaredType t, Void p) {
+ return t;
+ }
+
+ }, null
+ );
+ }
+
+ }, null
+ );
+
+ }
+
+ /**
+ * Returns true, if the given type mirror is a wildcard type with the given extends and super bounds, false otherwise.
+ *
+ * @param type The type to check.
+ * @param expectedExtendsBound A mirror representing the expected extends bound.
+ * @param expectedSuperBound A mirror representing the expected super bound.
+ *
+ * @return True, if the given type mirror is a wildcard type with the given extends and super bounds, false otherwise.
+ */
+ private boolean validateWildcardBounds(TypeMirror type, final TypeMirror expectedExtendsBound, final TypeMirror expectedSuperBound) {
+
+ Boolean theValue = type.accept(
+ new TypeKindVisitor6<Boolean, Void>() {
+
+ @Override
+ public Boolean visitWildcard(WildcardType t, Void p) {
+
+ boolean extendsBoundMatches = ( t.getExtendsBound() == null ? expectedExtendsBound == null : expectedExtendsBound != null && typeUtils
+ .isSameType( t.getExtendsBound(), expectedExtendsBound ) );
+ boolean superBoundMatches = ( t.getSuperBound() == null ? expectedSuperBound == null : expectedSuperBound != null && typeUtils
+ .isSameType( t.getSuperBound(), expectedSuperBound ) );
+
+ return extendsBoundMatches && superBoundMatches;
+ }
+
+ }, null
+ );
+
+ return Boolean.TRUE.equals( theValue );
+ }
+
+ /**
+ * Checks whether the given annotation value is an empty array or not.
+ *
+ * @param annotationValue The annotation value of interest.
+ *
+ * @return True, if the given annotation value is an empty array, false otherwise.
+ */
+ private boolean isEmptyArray(AnnotationValue annotationValue) {
+
+ return annotationValue != null && Boolean.TRUE.equals(
+ annotationValue.accept(
+ new SimpleAnnotationValueVisitor6<Boolean, Void>() {
+
+ @Override
+ public Boolean visitArray(List<? extends AnnotationValue> values, Void p) {
+ return values.size() == 0;
+ }
+
+ }, null
+ )
+ );
+ }
+
}
Modified: validator/trunk/hibernate-validator-annotation-processor/src/main/resources/org/hibernate/validator/ap/ValidationProcessorMessages.properties
===================================================================
--- validator/trunk/hibernate-validator-annotation-processor/src/main/resources/org/hibernate/validator/ap/ValidationProcessorMessages.properties 2010-09-04 07:40:43 UTC (rev 20309)
+++ validator/trunk/hibernate-validator-annotation-processor/src/main/resources/org/hibernate/validator/ap/ValidationProcessorMessages.properties 2010-09-05 10:48:06 UTC (rev 20310)
@@ -16,3 +16,9 @@
CONSTRAINT_TYPE_WITHOUT_VALIDATOR=For non-composed constraints a validator implementation must be specified using @Constraint#validatedBy().
CONSTRAINT_TYPE_MUST_DECLARE_MESSAGE_MEMBER=Constraint annotation types must declare a member 'String message()'.
RETURN_TYPE_MUST_BE_STRING=Return type of constraint annotation type member 'message()' must be 'String'.
+CONSTRAINT_TYPE_MUST_DECLARE_GROUPS_MEMBER=Constraint annotation types must declare a member 'Class<?>[] groups() default {}'.
+RETURN_TYPE_MUST_BE_CLASS_ARRAY=Return type of constraint annotation type member 'groups()' must be 'Class<?>[]'.
+DEFAULT_VALUE_MUST_BE_EMPTY_ARRAY=Default value of the 'groups()' member must be an empty array.
+CONSTRAINT_TYPE_MUST_DECLARE_PAYLOAD_MEMBER=Constraint annotation types must declare a member 'Class<? extends Payload>[] payload() default {}'.
+PAYLOAD_RETURN_TYPE_MUST_BE_CLASS_ARRAY=Return type of constraint annotation type member 'payload()' must be 'Class<? extends Payload>[]'.
+PAYLOAD_DEFAULT_VALUE_MUST_BE_EMPTY_ARRAY=Default value of the 'payload()' member must be an empty array.
Modified: validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/AnnotationTypeValidationTest.java
===================================================================
--- validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/AnnotationTypeValidationTest.java 2010-09-04 07:40:43 UTC (rev 20309)
+++ validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/AnnotationTypeValidationTest.java 2010-09-05 10:48:06 UTC (rev 20310)
@@ -24,7 +24,9 @@
import org.hibernate.validator.ap.testmodel.constrainttypes.ConstraintsWithIllegalRetentionPolicies;
import org.hibernate.validator.ap.testmodel.constrainttypes.ConstraintsWithIllegalTargets;
+import org.hibernate.validator.ap.testmodel.constrainttypes.ConstraintsWithWrongGroupsAttribute;
import org.hibernate.validator.ap.testmodel.constrainttypes.ConstraintsWithWrongMessageAttribute;
+import org.hibernate.validator.ap.testmodel.constrainttypes.ConstraintsWithWrongPayloadAttribute;
import org.hibernate.validator.ap.testmodel.constrainttypes.ConstraintsWithoutValidator;
import org.hibernate.validator.ap.testmodel.constrainttypes.DummyValidator;
import org.hibernate.validator.ap.testmodel.constrainttypes.ValidCustomerNumber;
@@ -118,4 +120,50 @@
new DiagnosticExpectation( Kind.ERROR, 35 ), new DiagnosticExpectation( Kind.ERROR, 50 )
);
}
+
+ @Test
+ public void testThatConstraintAnnotationTypeWithMissingOrWrongGroupsAttributeCausesCompilationError() {
+
+ File sourceFile1 = compilerHelper.getSourceFile( ConstraintsWithWrongGroupsAttribute.class );
+ File sourceFile2 = compilerHelper.getSourceFile( DummyValidator.class );
+
+ boolean compilationResult =
+ compilerHelper.compile( new ConstraintValidationProcessor(), diagnostics, sourceFile1, sourceFile2 );
+
+ assertFalse( compilationResult );
+ assertThatDiagnosticsMatch(
+ diagnostics,
+ new DiagnosticExpectation( Kind.ERROR, 35 ),
+ new DiagnosticExpectation( Kind.ERROR, 52 ),
+ new DiagnosticExpectation( Kind.ERROR, 67 ),
+ new DiagnosticExpectation( Kind.ERROR, 82 ),
+ new DiagnosticExpectation( Kind.ERROR, 97 ),
+ new DiagnosticExpectation( Kind.ERROR, 112 ),
+ new DiagnosticExpectation( Kind.ERROR, 127 )
+ );
+ }
+
+ @Test
+ public void testThatConstraintAnnotationTypeWithMissingOrPayloadGroupsAttributeCausesCompilationError() {
+
+ File sourceFile1 = compilerHelper.getSourceFile( ConstraintsWithWrongPayloadAttribute.class );
+ File sourceFile2 = compilerHelper.getSourceFile( DummyValidator.class );
+
+ boolean compilationResult =
+ compilerHelper.compile( new ConstraintValidationProcessor(), diagnostics, sourceFile1, sourceFile2 );
+
+ assertFalse( compilationResult );
+ assertThatDiagnosticsMatch(
+ diagnostics,
+ new DiagnosticExpectation( Kind.ERROR, 35 ),
+ new DiagnosticExpectation( Kind.ERROR, 53 ),
+ new DiagnosticExpectation( Kind.ERROR, 68 ),
+ new DiagnosticExpectation( Kind.ERROR, 83 ),
+ new DiagnosticExpectation( Kind.ERROR, 98 ),
+ new DiagnosticExpectation( Kind.ERROR, 113 ),
+ new DiagnosticExpectation( Kind.ERROR, 128 ),
+ new DiagnosticExpectation( Kind.ERROR, 143 )
+ );
+ }
+
}
Added: validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/constrainttypes/ConstraintsWithWrongGroupsAttribute.java
===================================================================
--- validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/constrainttypes/ConstraintsWithWrongGroupsAttribute.java (rev 0)
+++ validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/constrainttypes/ConstraintsWithWrongGroupsAttribute.java 2010-09-05 10:48:06 UTC (rev 20310)
@@ -0,0 +1,148 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat Middleware LLC, and individual contributors
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+* http://www.apache.org/licenses/LICENSE-2.0
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.hibernate.validator.ap.testmodel.constrainttypes;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import javax.validation.Constraint;
+import javax.validation.Payload;
+
+/**
+ * @author Gunnar Morling
+ */
+public interface ConstraintsWithWrongGroupsAttribute {
+
+ /**
+ * Compilation error expected due to missing groups attribute.
+ */
+ @Retention(RetentionPolicy.RUNTIME)
+ @Constraint(validatedBy = { DummyValidator.class })
+ public @interface ConstraintWithoutGroupsParameter {
+
+ String message() default "";
+
+ Class<? extends Payload>[] payload() default { };
+
+ }
+
+ /**
+ * Compilation error expected due to groups attribute of wrong type.
+ */
+ @Retention(RetentionPolicy.RUNTIME)
+ @Constraint(validatedBy = { DummyValidator.class })
+ public @interface ConstraintWithGroupsParameterWithWrongType1 {
+
+ String message() default "";
+
+ int[] groups() default { };
+
+ Class<? extends Payload>[] payload() default { };
+
+ }
+
+ /**
+ * Compilation error expected due to groups attribute of non-array class type.
+ */
+ @Retention(RetentionPolicy.RUNTIME)
+ @Constraint(validatedBy = { DummyValidator.class })
+ public @interface ConstraintWithGroupsParameterWithWrongType2 {
+
+ String message() default "";
+
+ Class<?> groups();
+
+ Class<? extends Payload>[] payload() default { };
+
+ }
+
+ /**
+ * Compilation error expected due to groups attribute with super bound.
+ */
+ @Retention(RetentionPolicy.RUNTIME)
+ @Constraint(validatedBy = { DummyValidator.class })
+ public @interface ConstraintWithGroupsParameterWithSuperBound {
+
+ String message() default "";
+
+ Class<? super Long>[] groups() default { };
+
+ Class<? extends Payload>[] payload() default { };
+
+ }
+
+ /**
+ * Compilation error expected due to groups attribute with extends bound.
+ */
+ @Retention(RetentionPolicy.RUNTIME)
+ @Constraint(validatedBy = { DummyValidator.class })
+ public @interface ConstraintWithGroupsParameterWithExtendsBound {
+
+ String message() default "";
+
+ Class<? extends Long>[] groups() default { };
+
+ Class<? extends Payload>[] payload() default { };
+
+ }
+
+ /**
+ * Compilation error expected due missing default value for groups attribute.
+ */
+ @Retention(RetentionPolicy.RUNTIME)
+ @Constraint(validatedBy = { DummyValidator.class })
+ public @interface ConstraintWithGroupsParameterWithoutDefaultValue {
+
+ String message() default "";
+
+ Class<?>[] groups();
+
+ Class<? extends Payload>[] payload() default { };
+
+ }
+
+ /**
+ * Compilation error expected due to non-empty default value for groups attribute.
+ */
+ @Retention(RetentionPolicy.RUNTIME)
+ @Constraint(validatedBy = { DummyValidator.class })
+ public @interface ConstraintWithGroupsParameterWithNonEmptyDefaultValue {
+
+ String message() default "";
+
+ Class<?>[] groups() default { Object.class };
+
+ Class<? extends Payload>[] payload() default { };
+
+ }
+
+ /**
+ * No compilation error expected.
+ */
+ @Retention(RetentionPolicy.RUNTIME)
+ @Constraint(validatedBy = { DummyValidator.class })
+ public @interface ConstraintWithCorrectGroupsParameter {
+
+ String message() default "";
+
+ Class<?>[] groups() default { };
+
+ Class<? extends Payload>[] payload() default { };
+
+ }
+
+}
Property changes on: validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/constrainttypes/ConstraintsWithWrongGroupsAttribute.java
___________________________________________________________________
Name: svn:keywords
+ Id
Added: validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/constrainttypes/ConstraintsWithWrongPayloadAttribute.java
===================================================================
--- validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/constrainttypes/ConstraintsWithWrongPayloadAttribute.java (rev 0)
+++ validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/constrainttypes/ConstraintsWithWrongPayloadAttribute.java 2010-09-05 10:48:06 UTC (rev 20310)
@@ -0,0 +1,165 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat Middleware LLC, and individual contributors
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+* http://www.apache.org/licenses/LICENSE-2.0
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.hibernate.validator.ap.testmodel.constrainttypes;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import javax.validation.Constraint;
+import javax.validation.Payload;
+
+/**
+ * @author Gunnar Morling
+ */
+public interface ConstraintsWithWrongPayloadAttribute {
+
+ /**
+ * Compilation error expected due to missing payload attribute.
+ */
+ @Retention(RetentionPolicy.RUNTIME)
+ @Constraint(validatedBy = { DummyValidator.class })
+ public @interface ConstraintWithoutPayloadParameter {
+
+ String message() default "";
+
+ Class<?>[] groups() default { };
+ }
+
+ /**
+ * Compilation error expected due to payload attribute of wrong type.
+ */
+ @Retention(RetentionPolicy.RUNTIME)
+ @Constraint(validatedBy = { DummyValidator.class })
+ public @interface ConstraintWithPayloadParameterWithWrongType1 {
+
+ String message() default "";
+
+ Class<?>[] groups() default { };
+
+ int[] payload() default { };
+
+ }
+
+ /**
+ * Compilation error expected due to payload attribute of non-array class type.
+ */
+ @Retention(RetentionPolicy.RUNTIME)
+ @Constraint(validatedBy = { DummyValidator.class })
+ public @interface ConstraintWithPayloadParameterWithWrongType2 {
+
+ String message() default "";
+
+ Class<?>[] groups() default { };
+
+ Class<? extends Payload> payload();
+
+ }
+
+ /**
+ * Compilation error expected due to payload attribute with wrong extends bound.
+ */
+ @Retention(RetentionPolicy.RUNTIME)
+ @Constraint(validatedBy = { DummyValidator.class })
+ public @interface ConstraintWithPayloadParameterWithWrongExtendsBound {
+
+ String message() default "";
+
+ Class<?>[] groups() default { };
+
+ Class<? extends Long>[] payload() default { };
+
+ }
+
+ /**
+ * Compilation error expected due to payload attribute without extend bound.
+ */
+ @Retention(RetentionPolicy.RUNTIME)
+ @Constraint(validatedBy = { DummyValidator.class })
+ public @interface ConstraintWithPayloadParameterWithoutExtendsBound {
+
+ String message() default "";
+
+ Class<?>[] groups() default { };
+
+ Class<?>[] payload() default { };
+
+ }
+
+ /**
+ * Compilation error expected due to payload attribute with super bound.
+ */
+ @Retention(RetentionPolicy.RUNTIME)
+ @Constraint(validatedBy = { DummyValidator.class })
+ public @interface ConstraintWithPayloadParameterWithSuperBound {
+
+ String message() default "";
+
+ Class<?>[] groups() default { };
+
+ Class<? super Payload>[] payload() default { };
+
+ }
+
+ /**
+ * Compilation error expected due missing default value for payload attribute.
+ */
+ @Retention(RetentionPolicy.RUNTIME)
+ @Constraint(validatedBy = { DummyValidator.class })
+ public @interface ConstraintWithPayloadParameterWithoutDefaultValue {
+
+ String message() default "";
+
+ Class<?>[] groups() default { };
+
+ Class<? extends Payload>[] payload();
+
+ }
+
+ /**
+ * Compilation error expected due to non-empty default value for payload attribute.
+ */
+ @Retention(RetentionPolicy.RUNTIME)
+ @Constraint(validatedBy = { DummyValidator.class })
+ public @interface ConstraintWithPayloadParameterWithNonEmptyDefaultValue {
+
+ String message() default "";
+
+ Class<?>[] groups() default { };
+
+ Class<? extends Payload>[] payload() default { SamplePayload.class };
+
+ }
+
+ /**
+ * No compilation error expected.
+ */
+ @Retention(RetentionPolicy.RUNTIME)
+ @Constraint(validatedBy = { DummyValidator.class })
+ public @interface ConstraintWithCorrectPayloadParameter {
+
+ String message() default "";
+
+ Class<?>[] groups() default { };
+
+ Class<? extends Payload>[] payload() default { };
+
+ }
+
+ public static class SamplePayload implements Payload {
+ }
+
+}
Property changes on: validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/constrainttypes/ConstraintsWithWrongPayloadAttribute.java
___________________________________________________________________
Name: svn:keywords
+ Id
14 years, 6 months
Hibernate SVN: r20309 - in core/trunk/envers/src: main/java/org/hibernate/envers/reader and 2 other directories.
by hibernate-commits@lists.jboss.org
Author: adamw
Date: 2010-09-04 03:40:43 -0400 (Sat, 04 Sep 2010)
New Revision: 20309
Modified:
core/trunk/envers/src/main/java/org/hibernate/envers/AuditReader.java
core/trunk/envers/src/main/java/org/hibernate/envers/reader/AuditReaderImpl.java
core/trunk/envers/src/main/java/org/hibernate/envers/revisioninfo/RevisionInfoQueryCreator.java
core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/reventity/Custom.java
core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/reventity/CustomBoxed.java
core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/reventity/Inherited.java
core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/reventity/Listener.java
core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/reventity/LongRevNumber.java
Log:
HHH-5499:
Extend AuditReader interface with findRevisions() method
Applying patch by Erik-Berndt Scheper - thanks!
Modified: core/trunk/envers/src/main/java/org/hibernate/envers/AuditReader.java
===================================================================
--- core/trunk/envers/src/main/java/org/hibernate/envers/AuditReader.java 2010-09-03 12:39:22 UTC (rev 20308)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/AuditReader.java 2010-09-04 07:40:43 UTC (rev 20309)
@@ -25,6 +25,8 @@
import java.util.Date;
import java.util.List;
+import java.util.Map;
+import java.util.Set;
import org.hibernate.envers.exception.NotAuditedException;
import org.hibernate.envers.exception.RevisionDoesNotExistException;
@@ -133,6 +135,25 @@
<T> T findRevision(Class<T> revisionEntityClass, Number revision) throws IllegalArgumentException,
RevisionDoesNotExistException, IllegalStateException;
+ /**
+ * Find a map of revisions using the revision numbers specified.
+ *
+ * @param revisionEntityClass
+ * Class of the revision entity. Should be annotated with
+ * {@link RevisionEntity}.
+ * @param revisions
+ * Revision numbers of the revision for which to get the data.
+ * @return A map of revision number and the given revision entity.
+ * @throws IllegalArgumentException
+ * If a revision number is less or equal to 0 or if the class of
+ * the revision entity is invalid.
+ * @throws IllegalStateException
+ * If the associated entity manager is closed.
+ */
+ <T> Map<Number, T> findRevisions(Class<T> revisionEntityClass,
+ Set<Number> revisions) throws IllegalArgumentException,
+ IllegalStateException;
+
/**
* Gets an instance of the current revision entity, to which any entries in the audit tables will be bound.
* Please note the if {@code persist} is {@code false}, and no audited entities are modified in this session,
Modified: core/trunk/envers/src/main/java/org/hibernate/envers/reader/AuditReaderImpl.java
===================================================================
--- core/trunk/envers/src/main/java/org/hibernate/envers/reader/AuditReaderImpl.java 2010-09-03 12:39:22 UTC (rev 20308)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/reader/AuditReaderImpl.java 2010-09-04 07:40:43 UTC (rev 20309)
@@ -23,26 +23,31 @@
*/
package org.hibernate.envers.reader;
+import static org.hibernate.envers.tools.ArgumentsTools.checkNotNull;
+import static org.hibernate.envers.tools.ArgumentsTools.checkPositive;
+
import java.util.Date;
+import java.util.HashMap;
+import java.util.HashSet;
import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
import javax.persistence.NoResultException;
+import org.hibernate.HibernateException;
+import org.hibernate.NonUniqueResultException;
+import org.hibernate.Query;
+import org.hibernate.Session;
+import org.hibernate.engine.SessionImplementor;
import org.hibernate.envers.configuration.AuditConfiguration;
+import org.hibernate.envers.exception.AuditException;
import org.hibernate.envers.exception.NotAuditedException;
import org.hibernate.envers.exception.RevisionDoesNotExistException;
-import org.hibernate.envers.exception.AuditException;
import org.hibernate.envers.query.AuditEntity;
import org.hibernate.envers.query.AuditQueryCreator;
-import static org.hibernate.envers.tools.ArgumentsTools.checkNotNull;
-import static org.hibernate.envers.tools.ArgumentsTools.checkPositive;
-
import org.hibernate.envers.synchronization.AuditProcess;
-
-import org.hibernate.NonUniqueResultException;
-import org.hibernate.Query;
-import org.hibernate.Session;
import org.hibernate.event.EventSource;
-import org.hibernate.engine.SessionImplementor;
/**
* @author Adam Warski (adam at warski dot org)
@@ -190,7 +195,9 @@
checkPositive(revision, "Entity revision");
checkSession();
- Query query = verCfg.getRevisionInfoQueryCreator().getRevisionQuery(session, revision);
+ Set<Number> revisions = new HashSet<Number>(1);
+ revisions.add(revision);
+ Query query = verCfg.getRevisionInfoQueryCreator().getRevisionsQuery(session, revisions);
try {
T revisionData = (T) query.uniqueResult();
@@ -205,6 +212,32 @@
}
}
+ @SuppressWarnings({"unchecked"})
+ public <T> Map<Number, T> findRevisions(Class<T> revisionEntityClass, Set<Number> revisions) throws IllegalArgumentException,
+ IllegalStateException {
+ Map<Number, T> result = new HashMap<Number, T>(revisions.size());
+
+ for (Number revision : revisions) {
+ checkNotNull(revision, "Entity revision");
+ checkPositive(revision, "Entity revision");
+ }
+ checkSession();
+
+ Query query = verCfg.getRevisionInfoQueryCreator().getRevisionsQuery(session, revisions);
+
+ try {
+ List<T> revisionList = query.list();
+ for (T revision : revisionList) {
+ Number revNo = verCfg.getRevisionInfoNumberReader().getRevisionNumber(revision);
+ result.put(revNo, revision);
+ }
+
+ return result;
+ } catch (HibernateException e) {
+ throw new AuditException(e);
+ }
+ }
+
@SuppressWarnings({"unchecked"})
public <T> T getCurrentRevision(Class<T> revisionEntityClass, boolean persist) {
if (!(session instanceof EventSource)) {
Modified: core/trunk/envers/src/main/java/org/hibernate/envers/revisioninfo/RevisionInfoQueryCreator.java
===================================================================
--- core/trunk/envers/src/main/java/org/hibernate/envers/revisioninfo/RevisionInfoQueryCreator.java 2010-09-03 12:39:22 UTC (rev 20308)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/revisioninfo/RevisionInfoQueryCreator.java 2010-09-04 07:40:43 UTC (rev 20309)
@@ -24,6 +24,7 @@
package org.hibernate.envers.revisioninfo;
import java.util.Date;
+import java.util.Set;
import org.hibernate.Query;
import org.hibernate.Session;
@@ -34,7 +35,7 @@
public class RevisionInfoQueryCreator {
private final String revisionDateQuery;
private final String revisionNumberForDateQuery;
- private final String revisionQuery;
+ private final String revisionsQuery;
private final boolean timestampAsDate;
public RevisionInfoQueryCreator(String revisionInfoEntityName, String revisionInfoIdName,
@@ -53,10 +54,10 @@
.append(" rev where ").append(revisionInfoTimestampName).append(" <= :_revision_date")
.toString();
- revisionQuery = new StringBuilder()
+ revisionsQuery = new StringBuilder()
.append("select rev from ").append(revisionInfoEntityName)
.append(" rev where ").append(revisionInfoIdName)
- .append(" = :_revision_number")
+ .append(" in (:_revision_numbers)")
.toString();
}
@@ -68,7 +69,7 @@
return session.createQuery(revisionNumberForDateQuery).setParameter("_revision_date", timestampAsDate ? date : date.getTime());
}
- public Query getRevisionQuery(Session session, Number revision) {
- return session.createQuery(revisionQuery).setParameter("_revision_number", revision);
+ public Query getRevisionsQuery(Session session, Set<Number> revisions) {
+ return session.createQuery(revisionsQuery).setParameterList("_revision_numbers", revisions);
}
}
Modified: core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/reventity/Custom.java
===================================================================
--- core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/reventity/Custom.java 2010-09-03 12:39:22 UTC (rev 20308)
+++ core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/reventity/Custom.java 2010-09-04 07:40:43 UTC (rev 20309)
@@ -25,8 +25,13 @@
import java.util.Arrays;
import java.util.Date;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
import javax.persistence.EntityManager;
+import org.hibernate.ejb.Ejb3Configuration;
import org.hibernate.envers.AuditReader;
import org.hibernate.envers.exception.RevisionDoesNotExistException;
import org.hibernate.envers.test.AbstractEntityTest;
@@ -35,8 +40,6 @@
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
-import org.hibernate.ejb.Ejb3Configuration;
-
/**
* @author Adam Warski (adam at warski dot org)
*/
@@ -120,6 +123,20 @@
}
@Test
+ public void testFindRevisions() {
+ AuditReader vr = getAuditReader();
+
+ Set<Number> revNumbers = new HashSet<Number>();
+ revNumbers.add(1);
+ revNumbers.add(2);
+
+ Map<Number, CustomRevEntity> revisionMap = vr.findRevisions(CustomRevEntity.class, revNumbers);
+ assert(revisionMap.size() == 2);
+ assert(revisionMap.get(1).equals(vr.findRevision(CustomRevEntity.class, 1)));
+ assert(revisionMap.get(2).equals(vr.findRevision(CustomRevEntity.class, 2)));
+ }
+
+ @Test
public void testRevisionsCounts() {
assert Arrays.asList(1, 2).equals(getAuditReader().getRevisions(StrTestEntity.class, id));
}
Modified: core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/reventity/CustomBoxed.java
===================================================================
--- core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/reventity/CustomBoxed.java 2010-09-03 12:39:22 UTC (rev 20308)
+++ core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/reventity/CustomBoxed.java 2010-09-04 07:40:43 UTC (rev 20309)
@@ -25,8 +25,13 @@
import java.util.Arrays;
import java.util.Date;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
import javax.persistence.EntityManager;
+import org.hibernate.ejb.Ejb3Configuration;
import org.hibernate.envers.AuditReader;
import org.hibernate.envers.exception.RevisionDoesNotExistException;
import org.hibernate.envers.test.AbstractEntityTest;
@@ -34,8 +39,6 @@
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
-import org.hibernate.ejb.Ejb3Configuration;
-
/**
* @author Adam Warski (adam at warski dot org)
*/
@@ -119,6 +122,20 @@
}
@Test
+ public void testFindRevisions() {
+ AuditReader vr = getAuditReader();
+
+ Set<Number> revNumbers = new HashSet<Number>();
+ revNumbers.add(1);
+ revNumbers.add(2);
+
+ Map<Number, CustomBoxedRevEntity> revisionMap = vr.findRevisions(CustomBoxedRevEntity.class, revNumbers);
+ assert(revisionMap.size() == 2);
+ assert(revisionMap.get(1).equals(vr.findRevision(CustomBoxedRevEntity.class, 1)));
+ assert(revisionMap.get(2).equals(vr.findRevision(CustomBoxedRevEntity.class, 2)));
+ }
+
+ @Test
public void testRevisionsCounts() {
assert Arrays.asList(1, 2).equals(getAuditReader().getRevisions(StrTestEntity.class, id));
}
@@ -131,4 +148,4 @@
assert getAuditReader().find(StrTestEntity.class, id, 1).equals(ver1);
assert getAuditReader().find(StrTestEntity.class, id, 2).equals(ver2);
}
-}
\ No newline at end of file
+}
Modified: core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/reventity/Inherited.java
===================================================================
--- core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/reventity/Inherited.java 2010-09-03 12:39:22 UTC (rev 20308)
+++ core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/reventity/Inherited.java 2010-09-04 07:40:43 UTC (rev 20309)
@@ -25,8 +25,13 @@
import java.util.Arrays;
import java.util.Date;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
import javax.persistence.EntityManager;
+import org.hibernate.ejb.Ejb3Configuration;
import org.hibernate.envers.AuditReader;
import org.hibernate.envers.exception.RevisionDoesNotExistException;
import org.hibernate.envers.test.AbstractEntityTest;
@@ -34,8 +39,6 @@
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
-import org.hibernate.ejb.Ejb3Configuration;
-
/**
* @author Adam Warski (adam at warski dot org)
*/
@@ -119,6 +122,20 @@
}
@Test
+ public void testFindRevisions() {
+ AuditReader vr = getAuditReader();
+
+ Set<Number> revNumbers = new HashSet<Number>();
+ revNumbers.add(1);
+ revNumbers.add(2);
+
+ Map<Number, InheritedRevEntity> revisionMap = vr.findRevisions(InheritedRevEntity.class, revNumbers);
+ assert(revisionMap.size() == 2);
+ assert(revisionMap.get(1).equals(vr.findRevision(InheritedRevEntity.class, 1)));
+ assert(revisionMap.get(2).equals(vr.findRevision(InheritedRevEntity.class, 2)));
+ }
+
+ @Test
public void testRevisionsCounts() {
assert Arrays.asList(1, 2).equals(getAuditReader().getRevisions(StrTestEntity.class, id));
}
Modified: core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/reventity/Listener.java
===================================================================
--- core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/reventity/Listener.java 2010-09-03 12:39:22 UTC (rev 20308)
+++ core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/reventity/Listener.java 2010-09-04 07:40:43 UTC (rev 20309)
@@ -25,8 +25,13 @@
import java.util.Arrays;
import java.util.Date;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
import javax.persistence.EntityManager;
+import org.hibernate.ejb.Ejb3Configuration;
import org.hibernate.envers.AuditReader;
import org.hibernate.envers.exception.RevisionDoesNotExistException;
import org.hibernate.envers.test.AbstractEntityTest;
@@ -34,8 +39,6 @@
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
-import org.hibernate.ejb.Ejb3Configuration;
-
/**
* @author Adam Warski (adam at warski dot org)
*/
@@ -132,6 +135,20 @@
}
@Test
+ public void testFindRevisions() {
+ AuditReader vr = getAuditReader();
+
+ Set<Number> revNumbers = new HashSet<Number>();
+ revNumbers.add(1);
+ revNumbers.add(2);
+
+ Map<Number, ListenerRevEntity> revisionMap = vr.findRevisions(ListenerRevEntity.class, revNumbers);
+ assert(revisionMap.size() == 2);
+ assert(revisionMap.get(1).equals(vr.findRevision(ListenerRevEntity.class, 1)));
+ assert(revisionMap.get(2).equals(vr.findRevision(ListenerRevEntity.class, 2)));
+ }
+
+ @Test
public void testRevisionsCounts() {
assert Arrays.asList(1, 2).equals(getAuditReader().getRevisions(StrTestEntity.class, id));
}
Modified: core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/reventity/LongRevNumber.java
===================================================================
--- core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/reventity/LongRevNumber.java 2010-09-03 12:39:22 UTC (rev 20308)
+++ core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/reventity/LongRevNumber.java 2010-09-04 07:40:43 UTC (rev 20309)
@@ -24,16 +24,19 @@
package org.hibernate.envers.test.integration.reventity;
import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
import javax.persistence.EntityManager;
+import org.hibernate.ejb.Ejb3Configuration;
import org.hibernate.envers.AuditReader;
import org.hibernate.envers.test.AbstractEntityTest;
import org.hibernate.envers.test.entities.StrTestEntity;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
-import org.hibernate.ejb.Ejb3Configuration;
-
/**
* @author Adam Warski (adam at warski dot org)
*/
@@ -71,6 +74,20 @@
}
@Test
+ public void testFindRevisions() {
+ AuditReader vr = getAuditReader();
+
+ Set<Number> revNumbers = new HashSet<Number>();
+ revNumbers.add(1l);
+ revNumbers.add(2l);
+
+ Map<Number, LongRevNumberRevEntity> revisionMap = vr.findRevisions(LongRevNumberRevEntity.class, revNumbers);
+ assert(revisionMap.size() == 2);
+ assert(revisionMap.get(1l).equals(vr.findRevision(LongRevNumberRevEntity.class, 1l)));
+ assert(revisionMap.get(2l).equals(vr.findRevision(LongRevNumberRevEntity.class, 2l)));
+ }
+
+ @Test
public void testRevisionsCounts() {
assert Arrays.asList(1l, 2l).equals(getAuditReader().getRevisions(StrTestEntity.class, id));
}
@@ -83,4 +100,4 @@
assert getAuditReader().find(StrTestEntity.class, id, 1l).equals(ver1);
assert getAuditReader().find(StrTestEntity.class, id, 2l).equals(ver2);
}
-}
\ No newline at end of file
+}
14 years, 6 months
Hibernate SVN: r20308 - tools/trunk/src/java/org/hibernate/cfg/reveng.
by hibernate-commits@lists.jboss.org
Author: dgeraskov
Date: 2010-09-03 08:39:22 -0400 (Fri, 03 Sep 2010)
New Revision: 20308
Modified:
tools/trunk/src/java/org/hibernate/cfg/reveng/JDBCReader.java
Log:
https://jira.jboss.org/browse/JBIDE-6351
Table type considered as case insensitive
Modified: tools/trunk/src/java/org/hibernate/cfg/reveng/JDBCReader.java
===================================================================
--- tools/trunk/src/java/org/hibernate/cfg/reveng/JDBCReader.java 2010-09-03 06:55:53 UTC (rev 20307)
+++ tools/trunk/src/java/org/hibernate/cfg/reveng/JDBCReader.java 2010-09-03 12:39:22 UTC (rev 20308)
@@ -536,7 +536,7 @@
log.debug("Ignoring " + tableName + " since it has already been processed");
continue;
} else {
- if ( ("TABLE".equals(tableType) || "VIEW".equals(tableType) /*|| "SYNONYM".equals(tableType) */) ) { //||
+ if ( ("TABLE".equalsIgnoreCase(tableType) || "VIEW".equalsIgnoreCase(tableType) /*|| "SYNONYM".equals(tableType) */) ) { //||
// ("SYNONYM".equals(tableType) && isOracle() ) ) { // only on oracle ? TODO: HBX-218
// it's a regular table or a synonym
@@ -551,7 +551,7 @@
progress.startSubTask("Found " + tableName);
Table table = dbs.addTable(quote(getSchemaForModel(schemaName)), getCatalogForModel(catalogName), quote(tableName));
table.setComment(comment);
- if(tableType.equals("TABLE")) {
+ if(tableType.equalsIgnoreCase("TABLE")) {
hasIndices.add(table);
}
processedTables.add( table );
14 years, 6 months
Hibernate SVN: r20307 - in core/trunk/documentation/quickstart/src/main/docbook/en-US: content and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: misty(a)redhat.com
Date: 2010-09-03 02:55:53 -0400 (Fri, 03 Sep 2010)
New Revision: 20307
Modified:
core/trunk/documentation/quickstart/src/main/docbook/en-US/Hibernate_Getting_Started_Guide.xml
core/trunk/documentation/quickstart/src/main/docbook/en-US/content/community.xml
core/trunk/documentation/quickstart/src/main/docbook/en-US/content/obtaining.xml
Log:
Edits to the Getting Started Guide
Modified: core/trunk/documentation/quickstart/src/main/docbook/en-US/Hibernate_Getting_Started_Guide.xml
===================================================================
--- core/trunk/documentation/quickstart/src/main/docbook/en-US/Hibernate_Getting_Started_Guide.xml 2010-09-02 06:31:15 UTC (rev 20306)
+++ core/trunk/documentation/quickstart/src/main/docbook/en-US/Hibernate_Getting_Started_Guide.xml 2010-09-03 06:55:53 UTC (rev 20307)
@@ -11,10 +11,13 @@
<part label="I">
<title>Basic Information</title>
<partintro>
+ <!-- Don't refer to things by Part #, because things could be re-ordered later
<para>
The sections in Part I present basic information you will
likely need to get started utilizing Hibernate
</para>
+ -->
+ <para>Set up and begin using Hibernate.</para>
</partintro>
<xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="content/community.xml" />
<xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="content/obtaining.xml" />
@@ -23,11 +26,16 @@
<part label="II">
<title>Tutorials</title>
<partintro>
+ <!--
<para>
The sections in Part II dive into illustrative examples of using Hibernate in various
ways. The referenced projects and code are available for download at
<ulink url="http://sourceforge.net/projects/hibernate/files/hibernate/&version;"/>
</para>
+ -->
+ <para>
+ Learn by doing, with guided tutorials. The referenced projects and code are available for download at <ulink url="http://sourceforge.net/projects/hibernate/files/hibernate/&version;"/>.
+ </para>
</partintro>
<xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="content/tutorial_native.xml" />
<xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="content/tutorial_annotations.xml" />
Modified: core/trunk/documentation/quickstart/src/main/docbook/en-US/content/community.xml
===================================================================
--- core/trunk/documentation/quickstart/src/main/docbook/en-US/content/community.xml 2010-09-02 06:31:15 UTC (rev 20306)
+++ core/trunk/documentation/quickstart/src/main/docbook/en-US/content/community.xml 2010-09-03 06:55:53 UTC (rev 20307)
@@ -4,39 +4,38 @@
<chapter id="hibernate-gsg-community">
<title>Hibernate Community</title>
- <para>
- There are a number of ways to become involved in the Hibernate community, including
- <itemizedlist>
- <listitem>
- <para>
- Trying stuff out and reporting bugs. See <ulink url="http://hibernate.org/issuetracker.html"/> for
- details.
- </para>
- </listitem>
- <listitem>
- <para>
- Trying your hand at fixing some bugs or implementing enhancements. Again, see
- <ulink url="http://hibernate.org/issuetracker.html"/>.
- </para>
- </listitem>
- <listitem>
- <para>
- <ulink url="http://hibernate.org/community.html"/> lists a number of ways to engage in the community
- including mailing lists, forums, IRC and others.
- </para>
- </listitem>
- <listitem>
- <para>
- Helping improve or translate this documentation. Contact us on the developer mailing list
- if you have interest.
- </para>
- </listitem>
- <listitem>
- <para>
- Evangelizing Hibernate within your organization.
- </para>
- </listitem>
- </itemizedlist>
- </para>
-
+ <!-- I removed the para and titled the list instead. I changed gerunds to imperative verbs (Use instead of Using). -->
+ <itemizedlist>
+ <title>Get Involved</title>
+ <listitem>
+ <para>
+ Use Hibernate and report any bugs or issues you find. See
+ <ulink url="http://hibernate.org/issuetracker.html"/> for
+ details.
+ </para>
+ </listitem>
+ <listitem>
+ <para>
+ Try your hand at fixing some bugs or implementing
+ enhancements. Again, see <ulink
+ url="http://hibernate.org/issuetracker.html"/>.
+ </para>
+ </listitem>
+ <listitem>
+ <para>
+ Engage with the community using mailing lists, forums, IRC, or other ways listed at <ulink url="http://hibernate.org/community.html"/>.
+ </para>
+ </listitem>
+ <listitem>
+ <para>
+ Help improve or translate this documentation. Contact us on
+ the developer mailing list if you have interest.
+ </para>
+ </listitem>
+ <listitem>
+ <para>
+ Spread the word. Let the rest of your organization know about the benefits of Hibernate.<!-- I didn't like 'evangelize'. Too many religious overtones. I'd like something stronger than this though. I'll have a think. -->
+ </para>
+ </listitem>
+ </itemizedlist>
</chapter>
Modified: core/trunk/documentation/quickstart/src/main/docbook/en-US/content/obtaining.xml
===================================================================
--- core/trunk/documentation/quickstart/src/main/docbook/en-US/content/obtaining.xml 2010-09-02 06:31:15 UTC (rev 20306)
+++ core/trunk/documentation/quickstart/src/main/docbook/en-US/content/obtaining.xml 2010-09-03 06:55:53 UTC (rev 20307)
@@ -8,40 +8,39 @@
<section id="hibernate-gsg-setup-releaseBundle">
<title>Release Bundle Downloads</title>
<para>
- The Hibernate team provides release bundles hosted on the SourceForge File Release System, both in
- <literal>ZIP</literal> and <literal>TGZ</literal> formats. A release bundle contains <literal>JARs</literal>,
+ The Hibernate team provides release bundles hosted on the SourceForge File Release System, in
+ <literal>ZIP</literal> and <literal>TGZ</literal> formats. Each release bundle contains <literal>JARs</literal>,
documentation, source code, and other information.
</para>
<para>
- Navigate to <ulink url="http://sourceforge.net/projects/hibernate/files/hibernate3/"/> and download the
- desired release from the list, in your format of choice.
+ You can download releases of Hibernate, in your chosen format, from the list at <ulink url="http://sourceforge.net/projects/hibernate/files/hibernate3/"/>.
</para>
<itemizedlist>
<listitem>
<para>
<filename>hibernate3.jar</filename> is an aggregation of all the Hibernate Core classes.
- This would need to be part of your project classpath.
+ This must be included in your project's classpath.
</para>
</listitem>
<listitem>
<para>
- The <filename>lib/required</filename> directory contains jars that are
- <emphasis>required</emphasis> for Hibernate to run. All the jars in this directory would need
- to be part of your project classpath as well.
+ The <filename>lib/required/</filename> directory contains JARs Hibernate requires. All the jars in this directory must also be included in your project's classpath as well.
</para>
<important>
<para>
- The slf4j jar is special in that you still need further jar file(s) for it to work correctly.
- Which jar(s) depends on which logging back-end you want to use. See the
- <ulink url="http://slf4j.org/">slf4j site</ulink> for details.
+ The <filename>slf4j</filename> JAR has additional
+ requirements for it to function properly. The exact
+ requirements depend on your logging back-end. See <ulink
+ url="http://slf4j.org/">slf4j site</ulink> for details.
</para>
</important>
</listitem>
<listitem>
<para>
- The <filename>/lib/jpa</filename> directory contains the
- <ulink url="http://jcp.org/en/jsr/detail?id=317">JPA</ulink> API jar. If you want to use the
- JPA APIs or JPA annotations, this jar will need to be part of your project classpath too.
+ The <filename>/lib/jpa/</filename> directory contains the
+ <ulink url="http://jcp.org/en/jsr/detail?id=317">JPA</ulink>
+ API JAR. This JAR needs to be in your project's classpath if
+ you want to use the JPA APIs or JPA annotations.
</para>
</listitem>
</itemizedlist>
@@ -49,152 +48,188 @@
<section id="hibernate-gsg-setup-mavenRepoArtifacts">
<title>Maven Repository Artifacts</title>
- <important>
- <para>
- The authoritative repository for Hibernate artifacts is the JBoss
- Maven repository. The team responsible for the JBoss Maven repository maintains a number of wiki
- pages that contain important information:
- <itemizedlist>
- <listitem>
- <para>
- <ulink url="http://community.jboss.org/docs/DOC-14900">http://community.jboss.org/docs/DOC-14900</ulink> -
- contains general information about the repository
- </para>
- </listitem>
- <listitem>
- <para>
- <ulink url="http://community.jboss.org/docs/DOC-15170">http://community.jboss.org/docs/DOC-15170</ulink> -
- contains information about setting up access to the repository for <emphasis>developers</emphasis>
- (aka, developers working on Hibernate or JBoss projects).
- </para>
- </listitem>
- <listitem>
- <para>
- <ulink url="http://community.jboss.org/docs/DOC-15169">http://community.jboss.org/docs/DOC-15169</ulink> -
- contains information about setting up access to the repository for <emphasis>users</emphasis>
- (aka, consumers of Hibernate or JBoss projects).
- </para>
- </listitem>
- </itemizedlist>
- </para>
- </important>
+ <para>
+ The authoritative repository for Hibernate artifacts is the
+ JBoss Maven repository. The team responsible for the JBoss
+ Maven repository maintains a number of Wiki pages that contain
+ important information.
+ </para>
+ <!-- lists inside <para> don't work in Publican, and you don't lose
+ anything by putting them outside the para. -->
+ <variablelist>
+ <title>Maven Repository Wiki Pages</title>
+ <varlistentry>
+ <term><ulink url="http://community.jboss.org/docs/DOC-14900">http://community.jboss.org/docs/DOC-14900</ulink></term>
+ <listitem>
+ <para>
+ General information about the repository.
+ </para>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term><ulink url="http://community.jboss.org/docs/DOC-15170">http://community.jboss.org/docs/DOC-15170</ulink></term>
+ <listitem>
+ <para>
+ Information about setting up the JBoss repositories in order to do development work on JBoss projects themselves.
+ </para>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term><ulink url="http://community.jboss.org/docs/DOC-15169">http://community.jboss.org/docs/DOC-15169</ulink></term>
+ <listitem>
+ <para>
+ Information about setting up access to the repository to use JBoss projects as part of your own software.
+ </para>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+
<para>
- Hibernate produces a number of artifacts (all under the org.hibernate groupId):
- <itemizedlist>
- <listitem>
- <para>
- <emphasis>hibernate-core</emphasis> - This is the main artifact. It contains all the
- Hibernate classes (<package>org.hibernate</package>) needed to build applications using
- the native Hibernate APIs. It includes capabilities for using native Hibernate mapping
- (<filename>hbm.xml</filename>) files as well as annotations.
- </para>
- </listitem>
- <listitem>
- <para>
- <emphasis>hibernate-entitymanager</emphasis> - Hibernate provides an implementation of
- <ulink url="http://jcp.org/en/jsr/detail?id=317">JPA</ulink>. This is the artifact that
- represents this JPA implementation.
- </para>
- <para>
- This artifact depends on <emphasis>hibernate-core</emphasis>.
- </para>
- </listitem>
- <listitem>
- <para>
- <emphasis>hibernate-envers</emphasis> - Envers is an optional module that
- provides historical auditing of changes to your entities.
- </para>
- <para>
- This artifact depends on both <emphasis>hibernate-core</emphasis> and
- <emphasis>hibernate-entitymanager</emphasis>.
- </para>
- </listitem>
- <listitem>
- <para>
- <emphasis>hibernate-c3p0</emphasis> - Represents the integration between Hibernate
- and the <ulink url="http://sourceforge.net/projects/c3p0/">C3P0</ulink> connection pool
- library.
- </para>
- <para>
- This artifact depends on <emphasis>hibernate-core</emphasis>; however it would generally
- be included in a project as a runtime dependency (rarely would you need to bind against
- these classes at compile time). It also pulls in the C3P0 dependencies.
- be
- </para>
- </listitem>
- <listitem>
- <para>
- <emphasis>hibernate-proxool</emphasis> - Represents the integration between Hibernate
- and the <ulink url="http://proxool.sourceforge.net/">Proxool</ulink> connection pool
- library.
- </para>
- <para>
- This artifact depends on <emphasis>hibernate-core</emphasis>; however it would generally
- be included in a project as a runtime dependency (rarely would you need to bind against
- these classes at compile time). It also pulls in the Proxool dependencies.
- </para>
- </listitem>
- <listitem>
- <para>
- <emphasis>hibernate-ehcache</emphasis> - Represents the integration between Hibernate
- and <ulink url="http://ehcache.sourceforge.net/">EhCache</ulink> as a second level cache
- implementation.
- </para>
- <para>
- This artifact depends on <emphasis>hibernate-core</emphasis>; however it would generally
- be included in a project as a runtime dependency (rarely would you need to bind against
- these classes at compile time). It also pulls in the Ehcache dependencies.
- </para>
- </listitem>
- <listitem>
- <para>
- <emphasis>hibernate-infinispan</emphasis> - Represents the integration between Hibernate
- and <ulink url="http://jboss.org/infinispan">Infinispan</ulink> as a second level cache
- implementation.
- </para>
- <para>
- This artifact depends on <emphasis>hibernate-core</emphasis>; however it would generally
- be included in a project as a runtime dependency (rarely would you need to bind against
- these classes at compile time). It also pulls in the Infinispan dependencies.
- </para>
- </listitem>
- <listitem>
- <para>
- <emphasis>hibernate-jbosscache</emphasis> - Represents the integration between Hibernate
- and <ulink url="http://jboss.org/jbosscache">JBossCache</ulink> as a second level cache
- implementation.
- </para>
- <para>
- This artifact depends on <emphasis>hibernate-core</emphasis>; however it would generally
- be included in a project as a runtime dependency (rarely would you need to bind against
- these classes at compile time). It also pulls in the JBossCache dependencies
- </para>
- </listitem>
- <listitem>
- <para>
- <emphasis>hibernate-oscache</emphasis> - Represents the integration between Hibernate
- and <ulink url="http://www.opensymphony.com/oscache/">OSCache</ulink> as a second level cache
- implementation.
- </para>
- <para>
- This artifact depends on <emphasis>hibernate-core</emphasis>; however it would generally
- be included in a project as a runtime dependency (rarely would you need to bind against
- these classes at compile time). It also pulls in the OSCache dependencies.
- </para>
- </listitem>
- <listitem>
- <para>
- <emphasis>hibernate-swarmcache</emphasis> - Represents the integration between Hibernate
- and <ulink url="http://swarmcache.sourceforge.net/">SwarmCache</ulink> as a second level cache
- implementation.
- </para>
- <para>
- This artifact depends on <emphasis>hibernate-core</emphasis>; however it would generally
- be included in a project as a runtime dependency (rarely would you need to bind against
- these classes at compile time). It also pulls in the SwarmCache dependencies.
- </para>
- </listitem>
- </itemizedlist>
- </para>
+ Hibernate produces a number of artifacts (all under the org.hibernate groupId):
+ </para>
+ <variablelist>
+ <title>Hibernate Artifacts under groupId<systemitem>org.hibernate</systemitem></title>
+ <varlistentry>
+ <term>hibernate-core</term>
+ <listitem>
+ <para>
+ The main artifact, which contains all the Hibernate classes, in
+ package <package>org.hibernate</package>. You need these to
+ build applications using the native Hibernate APIs. It includes
+ capabilities for using native Hibernate mapping in
+ <filename>hbm.xml</filename> files, as well as annotations.
+ </para>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term>hibernate-entitymanager</term>
+ <listitem>
+ <para>
+ Represents Hibernate's implementation of
+ <application>JPA</application>, as specified at<ulink
+ url="http://jcp.org/en/jsr/detail?id=317" />.
+ </para>
+ <para>
+ This artifact depends on <systemitem>hibernate-core</systemitem>
+ </para>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term>hibernate-envers</term>
+ <listitem>
+ <para>
+ An optional module that provides historical auditing of changes
+ to your entities.
+ </para>
+ <para>
+ This artifact depends on both
+ <systemitem>hibernate-core</systemitem> and
+ <systemitem>hibernate-entitymanager</systemitem>.
+ </para>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term>hibernate-c3p0</term>
+ <listitem>
+ <para>
+ Provides integration between Hibernate and the
+ <application>C3P0</application> connection pool library. See
+ <ulink url="http://sourceforge.net/projects/c3p0/" /> for
+ information about <application>C3P0</application>.
+ </para>
+ <para>
+ This artifact depends on <systemitem>hibernate-core</systemitem>, but is generally included in a project as a runtime dependency. It pulls in the <application>C3P0</application> dependencies automatically.
+ </para>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term>hibernate-proxool</term>
+ <listitem>
+ <para>
+ Provides integration between Hibernate and the
+ <application>Proxool</application> connection pool library. See
+ <ulink url="http://proxool.sourceforge.net/" /> for more
+ information about this library. library.
+ </para>
+ <para>
+ This artifact depends on
+ <systemitem>hibernate-core</systemitem>, but is generally
+ included in a project as a runtime dependency. It pulls in the
+ <application>Proxool</application> dependencies automatically..
+ </para>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term>hibernate-ehcache</term>
+ <listitem>
+ <para>
+ Privides integration between Hibernate and
+ <application>EhCache</application>, as a second-level cache. See
+ <ulink url="http://ehcache.sourceforge.net/" /> for more
+ information about <application>EhCache</application>.
+ </para>
+ <para>
+ This artifact depends on
+ <systemitem>hibernate-core</systemitem>, but is generally
+ included in a project as a runtime dependency. It pulls in the
+ <application>Ehcache</application> dependencies automatically.
+ </para>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term>hibernate-infinispan</term>
+ <listitem>
+ <para>
+ Provides integration between Hibernate
+ and <application>Infinispan</application>, as a second-level cache. See <ulink url="http://jboss.org/infinispan" /> for more information about <application>Infinispan</application>.
+ </para>
+ <para>
+ This artifact depends on <systemitem>hibernate-core</systemitem>, but is generally included in a project as a runtime
+ dependency. It pulls in the <application>Infinispan</application> dependencies automatically.
+ </para>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term>hibernate-jbosscache</term>
+ <listitem>
+ <para>
+ Provides integration between Hibernate
+ and <application>JBossCache</application>, as a second-level cache. See <ulink url="http://jboss.org/jbosscache" /> for information about <application>JBossCache</application>.
+ </para>
+ <para>
+ This artifact depends on <systemitem>hibernate-core</systemitem>,
+ but is generally included in a project as a runtime dependency.
+ It pulls in the <application>JBossCache</application>
+ dependencies automatically.
+ </para>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term>hibernate-oscache</term>
+ <listitem>
+ <para>
+ Provides integration between Hibernate
+ and <application>OSCache</application> as a second-level cache. See <ulink url="http://www.opensymphony.com/oscache/" /> for information about <application>OSCache</application>.
+ </para>
+ <para>
+ This artifact depends on <systemitem>hibernate-core</systemitem>,
+ but is generally included in a project as a runtime dependency.
+ It pulls in the OSCache dependencies automatically.
+ </para>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term>hibernate-swarmcache</term>
+ <listitem>
+ <para>
+ Provides integration between Hibernate
+ and <application>SwarmCache</application>, as a second-level cache. See <ulink url="http://swarmcache.sourceforge.net/" /> for more information about <application>SwarmCache</application>.
+ </para>
+ <para>
+ This artifact depends on <systemitem>hibernate-core</systemitem>, but is generally included in a project as a runtime dependency. It pulls in the <application>SwarmCache</application> dependencies automatically.
+ </para>
+ </listitem>
+ </varlistentry>
+ </variablelist>
</section>
</chapter>
\ No newline at end of file
14 years, 6 months
Hibernate SVN: r20306 - search/branches/v3_1_1_GA_CP/src/test/java/org/hibernate/search/test/optimizer.
by hibernate-commits@lists.jboss.org
Author: stliu
Date: 2010-09-02 02:31:15 -0400 (Thu, 02 Sep 2010)
New Revision: 20306
Modified:
search/branches/v3_1_1_GA_CP/src/test/java/org/hibernate/search/test/optimizer/OptimizerTestCase.java
Log:
JBPAPP-5005 org.hibernate.search.test.optimizer.OptimizerTestCase hangs on sybase
Modified: search/branches/v3_1_1_GA_CP/src/test/java/org/hibernate/search/test/optimizer/OptimizerTestCase.java
===================================================================
--- search/branches/v3_1_1_GA_CP/src/test/java/org/hibernate/search/test/optimizer/OptimizerTestCase.java 2010-09-02 03:08:59 UTC (rev 20305)
+++ search/branches/v3_1_1_GA_CP/src/test/java/org/hibernate/search/test/optimizer/OptimizerTestCase.java 2010-09-02 06:31:15 UTC (rev 20306)
@@ -4,6 +4,7 @@
import java.io.File;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
+import java.util.concurrent.atomic.AtomicInteger;
import org.apache.lucene.analysis.StopAnalyzer;
import org.apache.lucene.queryParser.ParseException;
@@ -54,7 +55,7 @@
es.execute( work );
es.execute( reverseWork );
}
- while ( work.count < iteration - 1 ) {
+ while ( work.count.get() < iteration - 1 ) {
Thread.sleep( 20 );
}
System.out.println( iteration + " iterations (8 tx per iteration) in " + nThreads + " threads: " + ( System
@@ -63,7 +64,7 @@
protected static class Work implements Runnable {
private final SessionFactory sf;
- public volatile int count = 0;
+ public AtomicInteger count = new AtomicInteger(0);
public Work(SessionFactory sf) {
this.sf = sf;
@@ -121,7 +122,7 @@
s.delete( c );
tx.commit();
s.close();
- count++;
+ count.getAndIncrement();
} catch (Throwable t) {
t.printStackTrace( );
}
14 years, 6 months