Hibernate SVN: r18205 - core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/configuration/metadata.
by hibernate-commits@lists.jboss.org
Author: adamw
Date: 2009-12-11 02:47:28 -0500 (Fri, 11 Dec 2009)
New Revision: 18205
Modified:
core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/configuration/metadata/CollectionMetadataGenerator.java
Log:
svn merge -r 18202:18204 https://svn.jboss.org/repos/hibernate/core/trunk/envers .
Modified: core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/configuration/metadata/CollectionMetadataGenerator.java
===================================================================
--- core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/configuration/metadata/CollectionMetadataGenerator.java 2009-12-11 07:43:34 UTC (rev 18204)
+++ core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/configuration/metadata/CollectionMetadataGenerator.java 2009-12-11 07:47:28 UTC (rev 18205)
@@ -145,7 +145,7 @@
void addCollection() {
Type type = propertyValue.getType();
- if ((type instanceof BagType || type instanceof SetType || type instanceof MapType) &&
+ if ((type instanceof BagType || type instanceof SetType || type instanceof MapType || type instanceof ListType) &&
(propertyValue.getElement() instanceof OneToMany) && (propertyValue.isInverse())) {
// A one-to-many relation mapped using @ManyToOne and @OneToMany(mappedBy="...")
addOneToManyAttached();
15 years
Hibernate SVN: r18204 - core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata.
by hibernate-commits@lists.jboss.org
Author: adamw
Date: 2009-12-11 02:43:34 -0500 (Fri, 11 Dec 2009)
New Revision: 18204
Modified:
core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata/CollectionMetadataGenerator.java
Log:
- Lists also can be the inverse side of bidirectional one-to-many relationships
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 2009-12-11 07:17:36 UTC (rev 18203)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata/CollectionMetadataGenerator.java 2009-12-11 07:43:34 UTC (rev 18204)
@@ -145,7 +145,7 @@
void addCollection() {
Type type = propertyValue.getType();
- if ((type instanceof BagType || type instanceof SetType || type instanceof MapType) &&
+ if ((type instanceof BagType || type instanceof SetType || type instanceof MapType || type instanceof ListType) &&
(propertyValue.getElement() instanceof OneToMany) && (propertyValue.isInverse())) {
// A one-to-many relation mapped using @ManyToOne and @OneToMany(mappedBy="...")
addOneToManyAttached();
15 years
Hibernate SVN: r18203 - in core/branches/envers-hibernate-3.3/src: main/java/org/hibernate/envers/configuration/metadata and 5 other directories.
by hibernate-commits@lists.jboss.org
Author: adamw
Date: 2009-12-11 02:17:36 -0500 (Fri, 11 Dec 2009)
New Revision: 18203
Added:
core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/entities/mapper/relation/query/TwoEntityOneAuditedQueryGenerator.java
core/branches/envers-hibernate-3.3/src/test/java/org/hibernate/envers/test/entities/manytomany/unidirectional/M2MTargetNotAuditedEntity.java
core/branches/envers-hibernate-3.3/src/test/java/org/hibernate/envers/test/integration/manytomany/unidirectional/M2MRelationNotAuditedTarget.java
Removed:
core/branches/envers-hibernate-3.3/src/main/java/org/jboss/
Modified:
core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/configuration/metadata/AuditMetadataGenerator.java
core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/configuration/metadata/CollectionMetadataGenerator.java
core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/configuration/metadata/QueryGeneratorBuilder.java
core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/configuration/metadata/ToOneRelationMetadataGenerator.java
core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/entities/mapper/relation/MiddleIdData.java
core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/entities/mapper/relation/lazy/initializor/BasicCollectionInitializor.java
core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/entities/mapper/relation/query/QueryGeneratorTools.java
core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/entities/mapper/relation/query/RelationQueryGenerator.java
core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/entities/mapper/relation/query/ThreeEntityQueryGenerator.java
core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/entities/mapper/relation/query/TwoEntityQueryGenerator.java
Log:
svn merge -r 18152:18202 https://svn.jboss.org/repos/hibernate/core/trunk/envers .
Modified: core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/configuration/metadata/AuditMetadataGenerator.java
===================================================================
--- core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/configuration/metadata/AuditMetadataGenerator.java 2009-12-10 21:47:01 UTC (rev 18202)
+++ core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/configuration/metadata/AuditMetadataGenerator.java 2009-12-11 07:17:36 UTC (rev 18203)
@@ -40,6 +40,7 @@
import org.hibernate.envers.entities.mapper.SubclassPropertyMapper;
import org.hibernate.envers.tools.StringTools;
import org.hibernate.envers.tools.Triple;
+import org.hibernate.envers.RelationTargetAuditMode;
import org.hibernate.MappingException;
import org.hibernate.cfg.Configuration;
@@ -380,7 +381,7 @@
String parentEntityName = null;
EntityConfiguration entityCfg = new EntityConfiguration(entityName, idMapper, propertyMapper,
parentEntityName);
- notAuditedEntitiesConfigurations.put(pc.getEntityName(), entityCfg);
+ notAuditedEntitiesConfigurations.put(entityName, entityCfg);
return;
}
@@ -513,6 +514,36 @@
throw new MappingException(message);
}
+ /**
+ * Reads the id mapping data of a referenced entity.
+ * @param entityName Name of the entity which is the source of the relation.
+ * @param referencedEntityName Name of the entity which is the target of the relation.
+ * @param propertyAuditingData Auditing data of the property that is the source of the relation.
+ * @param allowNotAuditedTarget Are not-audited target entities allowed.
+ * @throws MappingException If a relation from an audited to a non-audited entity is detected, which is not
+ * mapped using {@link RelationTargetAuditMode#NOT_AUDITED}.
+ * @return The id mapping data of the related entity.
+ */
+ IdMappingData getReferencedIdMappingData(String entityName, String referencedEntityName,
+ PropertyAuditingData propertyAuditingData,
+ boolean allowNotAuditedTarget) {
+ EntityConfiguration configuration = getEntitiesConfigurations().get(referencedEntityName);
+ if (configuration == null) {
+ RelationTargetAuditMode relationTargetAuditMode = propertyAuditingData.getRelationTargetAuditMode();
+ configuration = getNotAuditedEntitiesConfigurations().get(referencedEntityName);
+
+ if (configuration == null || !allowNotAuditedTarget || !RelationTargetAuditMode.NOT_AUDITED.equals(relationTargetAuditMode)) {
+ throw new MappingException("An audited relation from " + entityName + "."
+ + propertyAuditingData.getName() + " to a not audited entity " + referencedEntityName + "!"
+ + (allowNotAuditedTarget ?
+ " Such mapping is possible, but has to be explicitly defined using @Audited(targetAuditMode = NOT_AUDITED)." :
+ ""));
+ }
+ }
+
+ return configuration.getIdMappingData();
+ }
+
/**
* Get the notAuditedEntitiesConfigurations property.
*
Modified: core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/configuration/metadata/CollectionMetadataGenerator.java
===================================================================
--- core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/configuration/metadata/CollectionMetadataGenerator.java 2009-12-10 21:47:01 UTC (rev 18202)
+++ core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/configuration/metadata/CollectionMetadataGenerator.java 2009-12-11 07:17:36 UTC (rev 18203)
@@ -155,28 +155,26 @@
}
}
+ private MiddleIdData createMiddleIdData(IdMappingData idMappingData, String prefix, String entityName) {
+ return new MiddleIdData(mainGenerator.getVerEntCfg(), idMappingData, prefix, entityName,
+ mainGenerator.getEntitiesConfigurations().containsKey(entityName));
+ }
+
@SuppressWarnings({"unchecked"})
private void addOneToManyAttached() {
String mappedBy = getMappedBy(propertyValue);
- EntityConfiguration referencedEntityConfiguration = mainGenerator.getEntitiesConfigurations()
- .get(referencedEntityName);
-
- if (referencedEntityConfiguration == null) {
- throwRelationNotAudited(referencedEntityName);
- // Impossible to get here.
- throw new AssertionError();
- }
- IdMappingData referencedIdMapping = referencedEntityConfiguration.getIdMappingData();
+ IdMappingData referencedIdMapping = mainGenerator.getReferencedIdMappingData(referencingEntityName,
+ referencedEntityName, propertyAuditingData, false);
IdMappingData referencingIdMapping = referencingEntityConfiguration.getIdMappingData();
// Generating the id mappers data for the referencing side of the relation.
- MiddleIdData referencingIdData = new MiddleIdData(mainGenerator.getVerEntCfg(), referencingIdMapping,
+ MiddleIdData referencingIdData = createMiddleIdData(referencingIdMapping,
mappedBy + "_", referencingEntityName);
// And for the referenced side. The prefixed mapper won't be used (as this collection isn't persisted
// in a join table, so the prefix value is arbitrary).
- MiddleIdData referencedIdData = new MiddleIdData(mainGenerator.getVerEntCfg(), referencedIdMapping,
+ MiddleIdData referencedIdData = createMiddleIdData(referencedIdMapping,
null, referencedEntityName);
// Generating the element mapping.
@@ -293,7 +291,7 @@
}
// Storing the id data of the referencing entity: original mapper, prefixed mapper and entity name.
- MiddleIdData referencingIdData = new MiddleIdData(mainGenerator.getVerEntCfg(), referencingIdMapping,
+ MiddleIdData referencingIdData = createMiddleIdData(referencingIdMapping,
referencingPrefixRelated, referencingEntityName);
// Creating a query generator builder, to which additional id data will be added, in case this collection
@@ -390,15 +388,10 @@
String prefixRelated = prefix + "_";
String referencedEntityName = getReferencedEntityName(value);
- EntityConfiguration referencedEntityConfiguration = mainGenerator.getEntitiesConfigurations()
- .get(referencedEntityName);
- if (referencedEntityConfiguration == null) {
- throwRelationNotAudited(referencedEntityName);
- // Impossible to get here.
- throw new AssertionError();
- }
- IdMappingData referencedIdMapping = referencedEntityConfiguration.getIdMappingData();
+ IdMappingData referencedIdMapping = mainGenerator.getReferencedIdMappingData(referencingEntityName,
+ referencedEntityName, propertyAuditingData, true);
+
// Adding related-entity (in this case: the referenced entities id) id mapping to the xml only if the
// relation isn't inverse (so when <code>xmlMapping</code> is not null).
if (xmlMapping != null) {
@@ -410,7 +403,7 @@
}
// Storing the id data of the referenced entity: original mapper, prefixed mapper and entity name.
- MiddleIdData referencedIdData = new MiddleIdData(mainGenerator.getVerEntCfg(), referencedIdMapping,
+ MiddleIdData referencedIdData = createMiddleIdData(referencedIdMapping,
prefixRelated, referencedEntityName);
// And adding it to the generator builder.
queryGeneratorBuilder.addRelation(referencedIdData);
@@ -541,9 +534,4 @@
throw new MappingException("Unable to read the mapped by attribute for " + propertyName + " in "
+ referencingEntityName + "!");
}
-
- private void throwRelationNotAudited(String referencedEntityName) {
- throw new MappingException("An audited relation from " + referencingEntityName +
- " to a non-audited entity: " + referencedEntityName);
- }
}
Modified: core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/configuration/metadata/QueryGeneratorBuilder.java
===================================================================
--- core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/configuration/metadata/QueryGeneratorBuilder.java 2009-12-10 21:47:01 UTC (rev 18202)
+++ core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/configuration/metadata/QueryGeneratorBuilder.java 2009-12-11 07:17:36 UTC (rev 18203)
@@ -30,10 +30,8 @@
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.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.TwoEntityQueryGenerator;
+import org.hibernate.envers.entities.mapper.relation.query.*;
+import org.hibernate.MappingException;
/**
* Builds query generators, for reading collection middle tables, along with any related entities.
@@ -66,9 +64,19 @@
return new OneEntityQueryGenerator(verEntCfg, auditMiddleEntityName, referencingIdData,
componentDatas);
} else if (idDatas.size() == 1) {
- return new TwoEntityQueryGenerator(globalCfg, verEntCfg, auditMiddleEntityName, referencingIdData,
- idDatas.get(0), componentDatas);
+ if (idDatas.get(0).isAudited()) {
+ return new TwoEntityQueryGenerator(globalCfg, verEntCfg, auditMiddleEntityName, referencingIdData,
+ idDatas.get(0), componentDatas);
+ } else {
+ return new TwoEntityOneAuditedQueryGenerator(verEntCfg, auditMiddleEntityName, referencingIdData,
+ idDatas.get(0), componentDatas);
+ }
} else if (idDatas.size() == 2) {
+ // All entities must be audited.
+ if (!idDatas.get(0).isAudited() || !idDatas.get(1).isAudited()) {
+ throw new MappingException("Ternary relations using @Audited(targetAuditMode = NOT_AUDITED) are not supported.");
+ }
+
return new ThreeEntityQueryGenerator(globalCfg, verEntCfg, auditMiddleEntityName, referencingIdData,
idDatas.get(0), idDatas.get(1), componentDatas);
} else {
Modified: core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/configuration/metadata/ToOneRelationMetadataGenerator.java
===================================================================
--- core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/configuration/metadata/ToOneRelationMetadataGenerator.java 2009-12-10 21:47:01 UTC (rev 18202)
+++ core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/configuration/metadata/ToOneRelationMetadataGenerator.java 2009-12-11 07:17:36 UTC (rev 18203)
@@ -24,7 +24,6 @@
package org.hibernate.envers.configuration.metadata;
import org.dom4j.Element;
-import org.hibernate.envers.RelationTargetAuditMode;
import org.hibernate.envers.entities.EntityConfiguration;
import org.hibernate.envers.entities.IdMappingData;
import org.hibernate.envers.entities.PropertyData;
@@ -55,25 +54,9 @@
CompositeMapperBuilder mapper, String entityName, boolean insertable) {
String referencedEntityName = ((ToOne) value).getReferencedEntityName();
- EntityConfiguration configuration = mainGenerator.getEntitiesConfigurations().get(referencedEntityName);
- if (configuration == null) {
- configuration = mainGenerator.getNotAuditedEntitiesConfigurations().get(referencedEntityName);
- if (configuration != null) {
- RelationTargetAuditMode relationTargetAuditMode = propertyAuditingData.getRelationTargetAuditMode();
- if (!RelationTargetAuditMode.NOT_AUDITED.equals(relationTargetAuditMode)) {
- throw new MappingException("An audited relation from " + entityName + "."
- + propertyAuditingData.getName() + " to a not audited entity " + referencedEntityName + "!"
- + ". Such mapping is possible, but has to be strictly defined using RelationTargetAuditMode.NOT_AUDITED in @Audited.");
- }
- }
- }
- if (configuration == null) {
- throw new MappingException("An audited relation from " + entityName + "."
- + propertyAuditingData.getName() + " to a not audited entity " + referencedEntityName + "!");
- }
+ IdMappingData idMapping = mainGenerator.getReferencedIdMappingData(entityName, referencedEntityName,
+ propertyAuditingData, true);
- IdMappingData idMapping = configuration.getIdMappingData();
-
String lastPropertyPrefix = propertyAuditingData.getName() + "_";
// Generating the id mapper for the relation
Modified: core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/entities/mapper/relation/MiddleIdData.java
===================================================================
--- core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/entities/mapper/relation/MiddleIdData.java 2009-12-10 21:47:01 UTC (rev 18202)
+++ core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/entities/mapper/relation/MiddleIdData.java 2009-12-11 07:17:36 UTC (rev 18203)
@@ -33,44 +33,51 @@
* @author Adam Warski (adam at warski dot org)
*/
public final class MiddleIdData {
- /**
- * Original id mapper of the related entity.
- */
private final IdMapper originalMapper;
- /**
- * Prefixed id mapper (with the names for the id fields that are used in the middle table) of the related entity.
- */
private final IdMapper prefixedMapper;
- /**
- * Name of the related entity.
- */
private final String entityName;
- /**
- * Versions name of the related entity.
- */
- private final String versionsEntityName;
+ private final String auditEntityName;
public MiddleIdData(AuditEntitiesConfiguration verEntCfg, IdMappingData mappingData, String prefix,
- String entityName) {
+ String entityName, boolean audited) {
this.originalMapper = mappingData.getIdMapper();
this.prefixedMapper = mappingData.getIdMapper().prefixMappedProperties(prefix);
this.entityName = entityName;
- this.versionsEntityName = verEntCfg.getAuditEntityName(entityName);
+ this.auditEntityName = audited ? verEntCfg.getAuditEntityName(entityName) : null;
}
+ /**
+ * @return Original id mapper of the related entity.
+ */
public IdMapper getOriginalMapper() {
return originalMapper;
}
+ /**
+ * @return prefixed id mapper (with the names for the id fields that are used in the middle table) of the related entity.
+ */
public IdMapper getPrefixedMapper() {
return prefixedMapper;
}
+ /**
+ * @return Name of the related entity (regular, not audited).
+ */
public String getEntityName() {
return entityName;
}
- public String getVersionsEntityName() {
- return versionsEntityName;
+ /**
+ * @return Audit name of the related entity.
+ */
+ public String getAuditEntityName() {
+ return auditEntityName;
}
+
+ /**
+ * @return Is the entity, to which this middle id data correspond, audited.
+ */
+ public boolean isAudited() {
+ return auditEntityName != null;
+ }
}
Modified: core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/entities/mapper/relation/lazy/initializor/BasicCollectionInitializor.java
===================================================================
--- core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/entities/mapper/relation/lazy/initializor/BasicCollectionInitializor.java 2009-12-10 21:47:01 UTC (rev 18202)
+++ core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/entities/mapper/relation/lazy/initializor/BasicCollectionInitializor.java 2009-12-11 07:17:36 UTC (rev 18203)
@@ -66,8 +66,16 @@
@SuppressWarnings({"unchecked"})
protected void addToCollection(T collection, Object collectionRow) {
Object elementData = ((List) collectionRow).get(elementComponentData.getComponentIndex());
- Object element = elementComponentData.getComponentMapper().mapToObjectFromFullMap(entityInstantiator,
- (Map<String, Object>) elementData, null, revision);
+
+ // If the target entity is not audited, the elements may be the entities already, so we have to check
+ // if they are maps or not.
+ Object element;
+ if (elementData instanceof Map) {
+ element = elementComponentData.getComponentMapper().mapToObjectFromFullMap(entityInstantiator,
+ (Map<String, Object>) elementData, null, revision);
+ } else {
+ element = elementData;
+ }
collection.add(element);
}
}
Modified: core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/entities/mapper/relation/query/QueryGeneratorTools.java
===================================================================
--- core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/entities/mapper/relation/query/QueryGeneratorTools.java 2009-12-10 21:47:01 UTC (rev 18202)
+++ core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/entities/mapper/relation/query/QueryGeneratorTools.java 2009-12-11 07:17:36 UTC (rev 18203)
@@ -37,7 +37,7 @@
MiddleIdData idData, String revisionPropertyPath, String originalIdPropertyName,
String alias1, String alias2) {
// SELECT max(e.revision) FROM versionsReferencedEntity e2
- QueryBuilder maxERevQb = qb.newSubQueryBuilder(idData.getVersionsEntityName(), alias2);
+ QueryBuilder maxERevQb = qb.newSubQueryBuilder(idData.getAuditEntityName(), alias2);
maxERevQb.addProjection("max", revisionPropertyPath, false);
// WHERE
Parameters maxERevQbParameters = maxERevQb.getRootParameters();
Modified: core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/entities/mapper/relation/query/RelationQueryGenerator.java
===================================================================
--- core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/entities/mapper/relation/query/RelationQueryGenerator.java 2009-12-10 21:47:01 UTC (rev 18202)
+++ core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/entities/mapper/relation/query/RelationQueryGenerator.java 2009-12-11 07:17:36 UTC (rev 18203)
@@ -28,6 +28,8 @@
import org.hibernate.Query;
/**
+ * TODO: cleanup implementations and extract common code
+ *
* Implementations of this interface provide a method to generate queries on a relation table (a table used
* for mapping relations). The query can select, apart from selecting the content of the relation table, also data of
* other "related" entities.
Modified: core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/entities/mapper/relation/query/ThreeEntityQueryGenerator.java
===================================================================
--- core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/entities/mapper/relation/query/ThreeEntityQueryGenerator.java 2009-12-10 21:47:01 UTC (rev 18202)
+++ core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/entities/mapper/relation/query/ThreeEntityQueryGenerator.java 2009-12-11 07:17:36 UTC (rev 18203)
@@ -85,8 +85,8 @@
// SELECT new list(ee) FROM middleEntity ee
QueryBuilder qb = new QueryBuilder(versionsMiddleEntityName, "ee");
- qb.addFrom(referencedIdData.getVersionsEntityName(), "e");
- qb.addFrom(indexIdData.getVersionsEntityName(), "f");
+ qb.addFrom(referencedIdData.getAuditEntityName(), "e");
+ qb.addFrom(indexIdData.getAuditEntityName(), "f");
qb.addProjection("new list", "ee, e, f", false, false);
// WHERE
Parameters rootParameters = qb.getRootParameters();
Copied: core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/entities/mapper/relation/query/TwoEntityOneAuditedQueryGenerator.java (from rev 18202, core/trunk/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/query/TwoEntityOneAuditedQueryGenerator.java)
===================================================================
--- core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/entities/mapper/relation/query/TwoEntityOneAuditedQueryGenerator.java (rev 0)
+++ core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/entities/mapper/relation/query/TwoEntityOneAuditedQueryGenerator.java 2009-12-11 07:17:36 UTC (rev 18203)
@@ -0,0 +1,108 @@
+/*
+ * 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 java.util.Collections;
+
+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.tools.query.Parameters;
+import org.hibernate.envers.tools.query.QueryBuilder;
+
+import org.hibernate.Query;
+
+/**
+ * Selects data from a relation middle-table and a related non-audited entity.
+ * @author Adam Warski (adam at warski dot org)
+ */
+public final class TwoEntityOneAuditedQueryGenerator implements RelationQueryGenerator {
+ private final String queryString;
+ private final MiddleIdData referencingIdData;
+
+ public TwoEntityOneAuditedQueryGenerator(
+ AuditEntitiesConfiguration verEntCfg,
+ String versionsMiddleEntityName,
+ MiddleIdData referencingIdData,
+ MiddleIdData referencedIdData,
+ MiddleComponentData... componentDatas) {
+ this.referencingIdData = referencingIdData;
+
+ /*
+ * The query that we need to create:
+ * SELECT new list(ee, e) FROM referencedEntity e, middleEntity ee
+ * WHERE
+ * (entities referenced by the middle table; id_ref_ed = id of the referenced entity)
+ * 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)
+ * ee.revision = (SELECT max(ee2.revision) FROM middleEntity ee2
+ * WHERE ee2.revision <= :revision AND ee2.originalId.* = ee.originalId.*) AND
+ * (only non-deleted entities and associations)
+ * ee.revision_type != DEL
+ */
+ String revisionPropertyPath = verEntCfg.getRevisionNumberPath();
+ String originalIdPropertyName = verEntCfg.getOriginalIdPropName();
+
+ String eeOriginalIdPropertyPath = "ee." + originalIdPropertyName;
+
+ // SELECT new list(ee) FROM middleEntity ee
+ QueryBuilder qb = new QueryBuilder(versionsMiddleEntityName, "ee");
+ qb.addFrom(referencedIdData.getEntityName(), "e");
+ qb.addProjection("new list", "ee, e", false, false);
+ // WHERE
+ Parameters rootParameters = qb.getRootParameters();
+ // ee.id_ref_ed = e.id_ref_ed
+ referencedIdData.getPrefixedMapper().addIdsEqualToQuery(rootParameters, eeOriginalIdPropertyPath,
+ referencedIdData.getOriginalMapper(), "e");
+ // 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);
+
+ // ee.revision_type != DEL
+ rootParameters.addWhereWithNamedParam(verEntCfg.getRevisionTypePropName(), "!=", "delrevisiontype");
+
+ StringBuilder sb = new StringBuilder();
+ qb.build(sb, Collections.<String, Object>emptyMap());
+ queryString = sb.toString();
+ }
+
+ public Query getQuery(AuditReaderImplementor versionsReader, Object primaryKey, Number revision) {
+ Query query = versionsReader.getSession().createQuery(queryString);
+ query.setParameter("revision", revision);
+ query.setParameter("delrevisiontype", RevisionType.DEL);
+ for (QueryParameterData paramData: referencingIdData.getPrefixedMapper().mapToQueryParametersFromId(primaryKey)) {
+ paramData.setParameterValue(query);
+ }
+
+ return query;
+ }
+}
\ No newline at end of file
Modified: core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/entities/mapper/relation/query/TwoEntityQueryGenerator.java
===================================================================
--- core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/entities/mapper/relation/query/TwoEntityQueryGenerator.java 2009-12-10 21:47:01 UTC (rev 18202)
+++ core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/entities/mapper/relation/query/TwoEntityQueryGenerator.java 2009-12-11 07:17:36 UTC (rev 18203)
@@ -78,7 +78,7 @@
// SELECT new list(ee) FROM middleEntity ee
QueryBuilder qb = new QueryBuilder(versionsMiddleEntityName, "ee");
- qb.addFrom(referencedIdData.getVersionsEntityName(), "e");
+ qb.addFrom(referencedIdData.getAuditEntityName(), "e");
qb.addProjection("new list", "ee, e", false, false);
// WHERE
Parameters rootParameters = qb.getRootParameters();
Copied: core/branches/envers-hibernate-3.3/src/test/java/org/hibernate/envers/test/entities/manytomany/unidirectional/M2MTargetNotAuditedEntity.java (from rev 18202, core/trunk/envers/src/test/java/org/hibernate/envers/test/entities/manytomany/unidirectional/M2MTargetNotAuditedEntity.java)
===================================================================
--- core/branches/envers-hibernate-3.3/src/test/java/org/hibernate/envers/test/entities/manytomany/unidirectional/M2MTargetNotAuditedEntity.java (rev 0)
+++ core/branches/envers-hibernate-3.3/src/test/java/org/hibernate/envers/test/entities/manytomany/unidirectional/M2MTargetNotAuditedEntity.java 2009-12-11 07:17:36 UTC (rev 18203)
@@ -0,0 +1,116 @@
+/*
+ * 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.test.entities.manytomany.unidirectional;
+
+import javax.persistence.*;
+
+import org.hibernate.envers.Audited;
+import org.hibernate.envers.RelationTargetAuditMode;
+import org.hibernate.envers.test.entities.UnversionedStrTestEntity;
+
+import java.util.List;
+
+/**
+ * Audited entity with a many-to-many-reference to not audited entity.
+ * @author Toamsz Bech
+ * @author Adam Warski
+ */
+@Entity
+public class M2MTargetNotAuditedEntity {
+ @Id
+ private Integer id;
+
+ @Audited
+ private String data;
+
+ @Audited(targetAuditMode = RelationTargetAuditMode.NOT_AUDITED)
+ @ManyToMany(fetch = FetchType.LAZY)
+ private List<UnversionedStrTestEntity> references;
+
+ public M2MTargetNotAuditedEntity() { }
+
+ public M2MTargetNotAuditedEntity(Integer id, String data, List<UnversionedStrTestEntity> references) {
+ this.id = id;
+ this.data = data;
+ this.references = references;
+ }
+
+ public M2MTargetNotAuditedEntity(String data, List<UnversionedStrTestEntity> references) {
+ this.data = data;
+ this.references = references;
+ }
+
+ public M2MTargetNotAuditedEntity(Integer id, String data) {
+ this.id = id;
+ this.data = data;
+ }
+
+ public Integer getId() {
+ return id;
+ }
+
+ public void setId(Integer id) {
+ this.id = id;
+ }
+
+ public String getData() {
+ return data;
+ }
+
+ public void setData(String data) {
+ this.data = data;
+ }
+
+ public List<UnversionedStrTestEntity> getReferences() {
+ return references;
+ }
+
+ public void setReferences(List<UnversionedStrTestEntity> references) {
+ this.references = references;
+ }
+
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (!(o instanceof M2MTargetNotAuditedEntity)) return false;
+
+ M2MTargetNotAuditedEntity that = (M2MTargetNotAuditedEntity) o;
+
+ if (data != null ? !data.equals(that.getData()) : that.getData() != null) return false;
+ //noinspection RedundantIfStatement
+ if (id != null ? !id.equals(that.getId()) : that.getId() != null) return false;
+
+ return true;
+ }
+
+ public int hashCode() {
+ int result;
+ result = (id != null ? id.hashCode() : 0);
+ result = 31 * result + (data != null ? data.hashCode() : 0);
+ return result;
+ }
+
+ public String toString() {
+ return "M2MTargetNotAuditedEntity(id = " + id + ", data = " + data + ")";
+ }
+}
Copied: core/branches/envers-hibernate-3.3/src/test/java/org/hibernate/envers/test/integration/manytomany/unidirectional/M2MRelationNotAuditedTarget.java (from rev 18202, core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/manytomany/unidirectional/M2MRelationNotAuditedTarget.java)
===================================================================
--- core/branches/envers-hibernate-3.3/src/test/java/org/hibernate/envers/test/integration/manytomany/unidirectional/M2MRelationNotAuditedTarget.java (rev 0)
+++ core/branches/envers-hibernate-3.3/src/test/java/org/hibernate/envers/test/integration/manytomany/unidirectional/M2MRelationNotAuditedTarget.java 2009-12-11 07:17:36 UTC (rev 18203)
@@ -0,0 +1,167 @@
+/*
+ * 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.test.integration.manytomany.unidirectional;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.ArrayList;
+
+import javax.persistence.EntityManager;
+
+import org.hibernate.ejb.Ejb3Configuration;
+import org.hibernate.envers.test.AbstractEntityTest;
+import static org.hibernate.envers.test.tools.TestTools.*;
+import org.hibernate.envers.test.entities.UnversionedStrTestEntity;
+import org.hibernate.envers.test.entities.manytomany.unidirectional.M2MTargetNotAuditedEntity;
+
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+/**
+ * A test for auditing a many-to-many relation where the target entity is not audited.
+ * @author Adam Warski
+ */
+public class M2MRelationNotAuditedTarget extends AbstractEntityTest {
+ private Integer tnae1_id;
+ private Integer tnae2_id;
+
+ private Integer uste1_id;
+ private Integer uste2_id;
+
+ public void configure(Ejb3Configuration cfg) {
+ cfg.addAnnotatedClass(M2MTargetNotAuditedEntity.class);
+ cfg.addAnnotatedClass(UnversionedStrTestEntity.class);
+ }
+
+ @BeforeClass(dependsOnMethods = "init")
+ public void initData() {
+ EntityManager em = getEntityManager();
+
+ UnversionedStrTestEntity uste1 = new UnversionedStrTestEntity("str1");
+ UnversionedStrTestEntity uste2 = new UnversionedStrTestEntity("str2");
+
+ // No revision
+ em.getTransaction().begin();
+
+ em.persist(uste1);
+ em.persist(uste2);
+
+ em.getTransaction().commit();
+
+ // Revision 1
+ em.getTransaction().begin();
+
+ uste1 = em.find(UnversionedStrTestEntity.class, uste1.getId());
+ uste2 = em.find(UnversionedStrTestEntity.class, uste2.getId());
+
+ M2MTargetNotAuditedEntity tnae1 = new M2MTargetNotAuditedEntity(1, "tnae1", new ArrayList<UnversionedStrTestEntity>());
+ M2MTargetNotAuditedEntity tnae2 = new M2MTargetNotAuditedEntity(2, "tnae2", new ArrayList<UnversionedStrTestEntity>());
+ tnae2.getReferences().add(uste1);
+ tnae2.getReferences().add(uste2);
+ em.persist(tnae1);
+ em.persist(tnae2);
+
+ em.getTransaction().commit();
+
+ // Revision 2
+ em.getTransaction().begin();
+
+ tnae1 = em.find(M2MTargetNotAuditedEntity.class, tnae1.getId());
+ tnae2 = em.find(M2MTargetNotAuditedEntity.class, tnae2.getId());
+
+ tnae1.getReferences().add(uste1);
+ tnae2.getReferences().remove(uste1);
+
+ em.getTransaction().commit();
+
+ // Revision 3
+ em.getTransaction().begin();
+
+ tnae1 = em.find(M2MTargetNotAuditedEntity.class, tnae1.getId());
+ tnae2 = em.find(M2MTargetNotAuditedEntity.class, tnae2.getId());
+
+ //field not changed!!!
+ tnae1.getReferences().add(uste1);
+ tnae2.getReferences().remove(uste2);
+
+ em.getTransaction().commit();
+
+ // Revision 4
+ em.getTransaction().begin();
+
+ tnae1 = em.find(M2MTargetNotAuditedEntity.class, tnae1.getId());
+ tnae2 = em.find(M2MTargetNotAuditedEntity.class, tnae2.getId());
+
+ tnae1.getReferences().add(uste2);
+ tnae2.getReferences().add(uste1);
+
+ em.getTransaction().commit();
+
+ //
+ tnae1_id = tnae1.getId();
+ tnae2_id = tnae2.getId();
+ uste1_id = uste1.getId();
+ uste2_id = uste2.getId();
+ }
+
+ @Test
+ public void testRevisionsCounts() {
+ List<Number> revisions = getAuditReader().getRevisions(M2MTargetNotAuditedEntity.class, tnae1_id);
+ assert Arrays.asList(1, 2, 4).equals(revisions);
+ revisions = getAuditReader().getRevisions(M2MTargetNotAuditedEntity.class, tnae2_id);
+ assert Arrays.asList(1, 2, 3, 4).equals(revisions);
+ }
+
+ @Test
+ public void testHistoryOfTnae1_id() {
+ UnversionedStrTestEntity uste1 = getEntityManager().find(UnversionedStrTestEntity.class, uste1_id);
+ UnversionedStrTestEntity uste2 = getEntityManager().find(UnversionedStrTestEntity.class, uste2_id);
+
+ M2MTargetNotAuditedEntity rev1 = getAuditReader().find(M2MTargetNotAuditedEntity.class, tnae1_id, 1);
+ M2MTargetNotAuditedEntity rev2 = getAuditReader().find(M2MTargetNotAuditedEntity.class, tnae1_id, 2);
+ M2MTargetNotAuditedEntity rev3 = getAuditReader().find(M2MTargetNotAuditedEntity.class, tnae1_id, 3);
+ M2MTargetNotAuditedEntity rev4 = getAuditReader().find(M2MTargetNotAuditedEntity.class, tnae1_id, 4);
+
+ checkList(rev1.getReferences());
+ checkList(rev2.getReferences(), uste1);
+ checkList(rev3.getReferences(), uste1);
+ checkList(rev4.getReferences(), uste1, uste2);
+ }
+
+ @Test
+ public void testHistoryOfTnae2_id() {
+ UnversionedStrTestEntity uste1 = getEntityManager().find(UnversionedStrTestEntity.class, uste1_id);
+ UnversionedStrTestEntity uste2 = getEntityManager().find(UnversionedStrTestEntity.class, uste2_id);
+
+ M2MTargetNotAuditedEntity rev1 = getAuditReader().find(M2MTargetNotAuditedEntity.class, tnae2_id, 1);
+ M2MTargetNotAuditedEntity rev2 = getAuditReader().find(M2MTargetNotAuditedEntity.class, tnae2_id, 2);
+ M2MTargetNotAuditedEntity rev3 = getAuditReader().find(M2MTargetNotAuditedEntity.class, tnae2_id, 3);
+ M2MTargetNotAuditedEntity rev4 = getAuditReader().find(M2MTargetNotAuditedEntity.class, tnae2_id, 4);
+
+ checkList(rev1.getReferences(), uste1, uste2);
+ checkList(rev2.getReferences(), uste2);
+ checkList(rev3.getReferences());
+ checkList(rev4.getReferences(), uste1);
+ }
+}
15 years
Hibernate SVN: r18202 - in validator/trunk: hibernate-validator-legacy/src/main/resources/org/hibernate/validator/resources and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2009-12-10 16:47:01 -0500 (Thu, 10 Dec 2009)
New Revision: 18202
Added:
validator/trunk/hibernate-validator-legacy/src/main/resources/org/hibernate/validator/resources/DefaultValidatorMessages_mn_MN.properties
validator/trunk/hibernate-validator/src/main/resources/org/hibernate/validator/ValidationMessages_mn_MN.properties
Log:
HV-151 applied mongolian resource bundles
Added: validator/trunk/hibernate-validator/src/main/resources/org/hibernate/validator/ValidationMessages_mn_MN.properties
===================================================================
--- validator/trunk/hibernate-validator/src/main/resources/org/hibernate/validator/ValidationMessages_mn_MN.properties (rev 0)
+++ validator/trunk/hibernate-validator/src/main/resources/org/hibernate/validator/ValidationMessages_mn_MN.properties 2009-12-10 21:47:01 UTC (rev 18202)
@@ -0,0 +1,17 @@
+javax.validation.constraints.AssertFalse.message=\u0425\u0443\u0434\u0430\u043B \u0431\u0430\u0439\u0445 \u0451\u0441\u0442\u043E\u0439
+javax.validation.constraints.AssertTrue.message=\u04AE\u043D\u044D\u043D \u0431\u0430\u0439\u0445 \u0451\u0441\u0442\u043E\u0439
+javax.validation.constraints.DecimalMax.message={value}-\u0430\u0430\u0441 \u0431\u0430\u0433\u0430 \u0431\u0443\u044E\u0443 \u0442\u044D\u043D\u0446\u04AF\u04AF \u0431\u0430\u0439\u0445 \u0451\u0441\u0442\u043E\u0439
+javax.validation.constraints.DecimalMin.message={value}-\u0430\u0430\u0441 \u0438\u0445 \u0431\u0443\u044E\u0443 \u0442\u044D\u043D\u0446\u04AF\u04AF \u0431\u0430\u0439\u0445 \u0451\u0441\u0442\u043E\u0439
+javax.validation.constraints.Digits.message=\u0422\u043E\u043E\u043D \u0445\u044F\u0437\u0433\u0430\u0430\u0440\u0430\u0430\u0441 \u0445\u044D\u0442\u044D\u0440\u0441\u044D\u043D \u0431\u0430\u0439\u043D\u0430 (<{integerDigits} digits>.<{fractionalDigits} digits> \u0445\u043E\u043E\u0440\u043E\u043D\u0434 \u0431\u0430\u0439\u043D\u0430)
+javax.validation.constraints.Future.message=\u0418\u0440\u044D\u044D\u0434\u04AF\u0439\u0434 \u0431\u0430\u0439\u0445 \u0451\u0441\u0442\u043E\u0439
+javax.validation.constraints.Max.message={value}-\u0430\u0430\u0441 \u0431\u0430\u0433\u0430 \u0431\u0443\u044E\u0443 \u0442\u044D\u043D\u0446\u04AF\u04AF \u0431\u0430\u0439\u0445 \u0451\u0441\u0442\u043E\u0439
+javax.validation.constraints.Min.message={value}-\u0430\u0430\u0441 \u0438\u0445 \u0431\u0443\u044E\u0443 \u0442\u044D\u043D\u0446\u04AF\u04AF \u0431\u0430\u0439\u0445 \u0451\u0441\u0442\u043E\u0439
+javax.validation.constraints.NotNull.message=null \u0431\u0430\u0439\u0436 \u0431\u043E\u043B\u043E\u0445\u0433\u04AF\u0439
+javax.validation.constraints.Null.message=null \u0431\u0430\u0439\u0445 \u0451\u0441\u0442\u043E\u0439
+javax.validation.constraints.Past.message=\u04E8\u043D\u0433\u04E9\u0440\u0441\u04E9\u043D\u0434 \u0431\u0430\u0439\u0445 \u0451\u0441\u0442\u043E\u0439
+javax.validation.constraints.Pattern.message=\"{regexp}\"-\u0434 \u0442\u0430\u0430\u0440\u0430\u0445 \u0451\u0441\u0442\u043E\u0439
+javax.validation.constraints.Size.message=\u0425\u044D\u043C\u0436\u044D\u044D {min}-\u0441 {max} \u0445\u043E\u043E\u0440\u043E\u043D\u0434 \u0431\u0430\u0439\u043D\u0430
+org.hibernate.validator.constraints.Email.message=\u0411\u0443\u0440\u0443\u0443 \u0438-\u043C\u044D\u0439\u043B \u0445\u0430\u044F\u0433 \u0431\u0430\u0439\u043D\u0430
+org.hibernate.validator.constraints.Length.message=\u0422\u044D\u043C\u0434\u044D\u0433\u0442\u0438\u0439\u043D \u0443\u0440\u0442 {min}-\u0441 {max} \u0445\u043E\u043E\u0440\u043E\u043D\u0434 \u0431\u0430\u0439\u043D\u0430
+org.hibernate.validator.constraints.NotEmpty.message=\u0425\u043E\u043E\u0441\u043E\u043D \u0431\u0430\u0439\u0436 \u0431\u043E\u043B\u043E\u0445\u0433\u04AF\u0439
+org.hibernate.validator.constraints.Range.message=\u0423\u0442\u0433\u0430 {min}-\u0441 {max} \u0445\u043E\u043E\u0440\u043E\u043D\u0434 \u0431\u0430\u0439\u043D\u0430
\ No newline at end of file
Added: validator/trunk/hibernate-validator-legacy/src/main/resources/org/hibernate/validator/resources/DefaultValidatorMessages_mn_MN.properties
===================================================================
--- validator/trunk/hibernate-validator-legacy/src/main/resources/org/hibernate/validator/resources/DefaultValidatorMessages_mn_MN.properties (rev 0)
+++ validator/trunk/hibernate-validator-legacy/src/main/resources/org/hibernate/validator/resources/DefaultValidatorMessages_mn_MN.properties 2009-12-10 21:47:01 UTC (rev 18202)
@@ -0,0 +1,16 @@
+validator.assertFalse=\u0411\u0430\u0442\u0430\u043B\u0433\u0430\u0430\u0436\u0443\u0443\u043B\u0430\u043B\u0442 \u0430\u043C\u0436\u0438\u043B\u0442\u0433\u04AF\u0439 \u0431\u043E\u043B\u043B\u043E\u043E
+validator.assertTrue=\u0411\u0430\u0442\u0430\u043B\u0433\u0430\u0430\u0436\u0443\u0443\u043B\u0430\u043B\u0442 \u0430\u043C\u0436\u0438\u043B\u0442\u0433\u04AF\u0439 \u0431\u043E\u043B\u043B\u043E\u043E
+validator.future={value}-\u0441 \u0445\u043E\u0439\u0448\u0438\u0445 \u043E\u0433\u043D\u043E\u043E \u043E\u0440\u0443\u0443\u043B\u043D\u0430 \u0443\u0443
+validator.length=\u0422\u044D\u043C\u0434\u044D\u0433\u0442\u0438\u0439\u043D \u0443\u0440\u0442 {min}-\u0441 {max} \u0445\u043E\u043E\u0440\u043E\u043D\u0434 \u0431\u0430\u0439\u043D\u0430
+validator.max=\u0422\u044D\u043C\u0434\u044D\u0433\u0442\u0438\u0439\u043D \u0443\u0440\u0442 {value}-\u0441 \u0438\u0445\u0433\u04AF\u0439 \u0431\u0430\u0439\u043D\u0430
+validator.min=\u0422\u044D\u043C\u0434\u044D\u0433\u0442\u0438\u0439\u043D \u0443\u0440\u0442 {value}-\u0441 \u0431\u0430\u0433\u0430\u0433\u04AF\u0439 \u0431\u0430\u0439\u043D\u0430
+validator.notNull=\u0425\u043E\u043E\u0441\u043E\u043D \u0431\u0430\u0439\u0436 \u0431\u043E\u043B\u043E\u0445\u0433\u04AF\u0439
+validator.past={value}-\u0441 \u04E9\u043C\u043D\u04E9\u0445 \u043E\u0433\u043D\u043E\u043E \u043E\u0440\u0443\u0443\u043B\u043D\u0430 \u0443\u0443
+validator.pattern="{regex}"-\u0434 \u0442\u0430\u0430\u0440\u0430\u0445 \u0451\u0441\u0442\u043E\u0439
+validator.range=\u0423\u0442\u0433\u0430 {min}-\u0441 {max} \u0445\u043E\u043E\u0440\u043E\u043D\u0434 \u0431\u0430\u0439\u043D\u0430
+validator.size=\u0425\u044D\u043C\u0436\u044D\u044D {min}-\u0441 {max} \u0445\u043E\u043E\u0440\u043E\u043D\u0434 \u0431\u0430\u0439\u043D\u0430
+validator.email=\u0411\u0443\u0440\u0443\u0443 \u0438-\u043C\u044D\u0439\u043B \u0445\u0430\u044F\u0433 \u0431\u0430\u0439\u043D\u0430
+validator.notEmpty=\u0425\u043E\u043E\u0441\u043E\u043D \u0431\u0430\u0439\u0436 \u0431\u043E\u043B\u043E\u0445\u0433\u04AF\u0439
+validator.digits=\u0422\u043E\u043E\u043D\u044B \u0445\u044F\u0437\u0433\u0430\u0430\u0440\u0430\u0430\u0441 \u0445\u044D\u0442\u044D\u0440\u0441\u044D\u043D \u0431\u0430\u0439\u043D\u0430 (<{integerDigits} digits>.<{fractionalDigits} digits>)
+validator.creditCard=\u041A\u0440\u0435\u0434\u0438\u0442 \u043A\u0430\u0440\u0442\u044B\u043D \u0434\u0443\u0433\u0430\u0430\u0440 \u0431\u0443\u0440\u0443\u0443 \u0431\u0430\u0439\u043D\u0430
+validator.ean=\u0411\u0443\u0440\u0443\u0443 EAN \u043A\u043E\u0434 \u0431\u0430\u0439\u043D\u0430
\ No newline at end of file
15 years
Hibernate SVN: r18201 - in core/trunk/envers/src: main/java/org/hibernate/envers/configuration/metadata and 5 other directories.
by hibernate-commits@lists.jboss.org
Author: adamw
Date: 2009-12-10 15:28:27 -0500 (Thu, 10 Dec 2009)
New Revision: 18201
Added:
core/trunk/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/query/TwoEntityOneAuditedQueryGenerator.java
core/trunk/envers/src/test/java/org/hibernate/envers/test/entities/manytomany/unidirectional/M2MTargetNotAuditedEntity.java
core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/manytomany/unidirectional/M2MRelationNotAuditedTarget.java
Removed:
core/trunk/envers/src/main/java/org/jboss/
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/CollectionMetadataGenerator.java
core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata/QueryGeneratorBuilder.java
core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata/ToOneRelationMetadataGenerator.java
core/trunk/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/MiddleIdData.java
core/trunk/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/lazy/initializor/BasicCollectionInitializor.java
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/RelationQueryGenerator.java
core/trunk/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/query/ThreeEntityQueryGenerator.java
core/trunk/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/query/TwoEntityQueryGenerator.java
Log:
HHH-4090:
- adding support for many-to-many relations from an audited, to a non-audited entity
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 2009-12-10 16:49:46 UTC (rev 18200)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata/AuditMetadataGenerator.java 2009-12-10 20:28:27 UTC (rev 18201)
@@ -40,6 +40,7 @@
import org.hibernate.envers.entities.mapper.SubclassPropertyMapper;
import org.hibernate.envers.tools.StringTools;
import org.hibernate.envers.tools.Triple;
+import org.hibernate.envers.RelationTargetAuditMode;
import org.hibernate.MappingException;
import org.hibernate.cfg.Configuration;
@@ -348,7 +349,7 @@
String parentEntityName = null;
EntityConfiguration entityCfg = new EntityConfiguration(entityName, idMapper, propertyMapper,
parentEntityName);
- notAuditedEntitiesConfigurations.put(pc.getEntityName(), entityCfg);
+ notAuditedEntitiesConfigurations.put(entityName, entityCfg);
return;
}
@@ -476,6 +477,36 @@
throw new MappingException(message);
}
+ /**
+ * Reads the id mapping data of a referenced entity.
+ * @param entityName Name of the entity which is the source of the relation.
+ * @param referencedEntityName Name of the entity which is the target of the relation.
+ * @param propertyAuditingData Auditing data of the property that is the source of the relation.
+ * @param allowNotAuditedTarget Are not-audited target entities allowed.
+ * @throws MappingException If a relation from an audited to a non-audited entity is detected, which is not
+ * mapped using {@link RelationTargetAuditMode#NOT_AUDITED}.
+ * @return The id mapping data of the related entity.
+ */
+ IdMappingData getReferencedIdMappingData(String entityName, String referencedEntityName,
+ PropertyAuditingData propertyAuditingData,
+ boolean allowNotAuditedTarget) {
+ EntityConfiguration configuration = getEntitiesConfigurations().get(referencedEntityName);
+ if (configuration == null) {
+ RelationTargetAuditMode relationTargetAuditMode = propertyAuditingData.getRelationTargetAuditMode();
+ configuration = getNotAuditedEntitiesConfigurations().get(referencedEntityName);
+
+ if (configuration == null || !allowNotAuditedTarget || !RelationTargetAuditMode.NOT_AUDITED.equals(relationTargetAuditMode)) {
+ throw new MappingException("An audited relation from " + entityName + "."
+ + propertyAuditingData.getName() + " to a not audited entity " + referencedEntityName + "!"
+ + (allowNotAuditedTarget ?
+ " Such mapping is possible, but has to be explicitly defined using @Audited(targetAuditMode = NOT_AUDITED)." :
+ ""));
+ }
+ }
+
+ return configuration.getIdMappingData();
+ }
+
/**
* Get the notAuditedEntitiesConfigurations property.
*
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 2009-12-10 16:49:46 UTC (rev 18200)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata/CollectionMetadataGenerator.java 2009-12-10 20:28:27 UTC (rev 18201)
@@ -155,28 +155,26 @@
}
}
+ private MiddleIdData createMiddleIdData(IdMappingData idMappingData, String prefix, String entityName) {
+ return new MiddleIdData(mainGenerator.getVerEntCfg(), idMappingData, prefix, entityName,
+ mainGenerator.getEntitiesConfigurations().containsKey(entityName));
+ }
+
@SuppressWarnings({"unchecked"})
private void addOneToManyAttached() {
String mappedBy = getMappedBy(propertyValue);
- EntityConfiguration referencedEntityConfiguration = mainGenerator.getEntitiesConfigurations()
- .get(referencedEntityName);
-
- if (referencedEntityConfiguration == null) {
- throwRelationNotAudited(referencedEntityName);
- // Impossible to get here.
- throw new AssertionError();
- }
- IdMappingData referencedIdMapping = referencedEntityConfiguration.getIdMappingData();
+ IdMappingData referencedIdMapping = mainGenerator.getReferencedIdMappingData(referencingEntityName,
+ referencedEntityName, propertyAuditingData, false);
IdMappingData referencingIdMapping = referencingEntityConfiguration.getIdMappingData();
// Generating the id mappers data for the referencing side of the relation.
- MiddleIdData referencingIdData = new MiddleIdData(mainGenerator.getVerEntCfg(), referencingIdMapping,
+ MiddleIdData referencingIdData = createMiddleIdData(referencingIdMapping,
mappedBy + "_", referencingEntityName);
// And for the referenced side. The prefixed mapper won't be used (as this collection isn't persisted
// in a join table, so the prefix value is arbitrary).
- MiddleIdData referencedIdData = new MiddleIdData(mainGenerator.getVerEntCfg(), referencedIdMapping,
+ MiddleIdData referencedIdData = createMiddleIdData(referencedIdMapping,
null, referencedEntityName);
// Generating the element mapping.
@@ -293,7 +291,7 @@
}
// Storing the id data of the referencing entity: original mapper, prefixed mapper and entity name.
- MiddleIdData referencingIdData = new MiddleIdData(mainGenerator.getVerEntCfg(), referencingIdMapping,
+ MiddleIdData referencingIdData = createMiddleIdData(referencingIdMapping,
referencingPrefixRelated, referencingEntityName);
// Creating a query generator builder, to which additional id data will be added, in case this collection
@@ -390,15 +388,10 @@
String prefixRelated = prefix + "_";
String referencedEntityName = getReferencedEntityName(value);
- EntityConfiguration referencedEntityConfiguration = mainGenerator.getEntitiesConfigurations()
- .get(referencedEntityName);
- if (referencedEntityConfiguration == null) {
- throwRelationNotAudited(referencedEntityName);
- // Impossible to get here.
- throw new AssertionError();
- }
- IdMappingData referencedIdMapping = referencedEntityConfiguration.getIdMappingData();
+ IdMappingData referencedIdMapping = mainGenerator.getReferencedIdMappingData(referencingEntityName,
+ referencedEntityName, propertyAuditingData, true);
+
// Adding related-entity (in this case: the referenced entities id) id mapping to the xml only if the
// relation isn't inverse (so when <code>xmlMapping</code> is not null).
if (xmlMapping != null) {
@@ -410,7 +403,7 @@
}
// Storing the id data of the referenced entity: original mapper, prefixed mapper and entity name.
- MiddleIdData referencedIdData = new MiddleIdData(mainGenerator.getVerEntCfg(), referencedIdMapping,
+ MiddleIdData referencedIdData = createMiddleIdData(referencedIdMapping,
prefixRelated, referencedEntityName);
// And adding it to the generator builder.
queryGeneratorBuilder.addRelation(referencedIdData);
@@ -541,9 +534,4 @@
throw new MappingException("Unable to read the mapped by attribute for " + propertyName + " in "
+ referencingEntityName + "!");
}
-
- private void throwRelationNotAudited(String referencedEntityName) {
- throw new MappingException("An audited relation from " + referencingEntityName +
- " to a non-audited entity: " + referencedEntityName);
- }
}
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 2009-12-10 16:49:46 UTC (rev 18200)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata/QueryGeneratorBuilder.java 2009-12-10 20:28:27 UTC (rev 18201)
@@ -30,10 +30,8 @@
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.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.TwoEntityQueryGenerator;
+import org.hibernate.envers.entities.mapper.relation.query.*;
+import org.hibernate.MappingException;
/**
* Builds query generators, for reading collection middle tables, along with any related entities.
@@ -66,9 +64,19 @@
return new OneEntityQueryGenerator(verEntCfg, auditMiddleEntityName, referencingIdData,
componentDatas);
} else if (idDatas.size() == 1) {
- return new TwoEntityQueryGenerator(globalCfg, verEntCfg, auditMiddleEntityName, referencingIdData,
- idDatas.get(0), componentDatas);
+ if (idDatas.get(0).isAudited()) {
+ return new TwoEntityQueryGenerator(globalCfg, verEntCfg, auditMiddleEntityName, referencingIdData,
+ idDatas.get(0), componentDatas);
+ } else {
+ return new TwoEntityOneAuditedQueryGenerator(verEntCfg, auditMiddleEntityName, referencingIdData,
+ idDatas.get(0), componentDatas);
+ }
} else if (idDatas.size() == 2) {
+ // All entities must be audited.
+ if (!idDatas.get(0).isAudited() || !idDatas.get(1).isAudited()) {
+ throw new MappingException("Ternary relations using @Audited(targetAuditMode = NOT_AUDITED) are not supported.");
+ }
+
return new ThreeEntityQueryGenerator(globalCfg, verEntCfg, auditMiddleEntityName, referencingIdData,
idDatas.get(0), idDatas.get(1), componentDatas);
} else {
Modified: core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata/ToOneRelationMetadataGenerator.java
===================================================================
--- core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata/ToOneRelationMetadataGenerator.java 2009-12-10 16:49:46 UTC (rev 18200)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata/ToOneRelationMetadataGenerator.java 2009-12-10 20:28:27 UTC (rev 18201)
@@ -24,7 +24,6 @@
package org.hibernate.envers.configuration.metadata;
import org.dom4j.Element;
-import org.hibernate.envers.RelationTargetAuditMode;
import org.hibernate.envers.entities.EntityConfiguration;
import org.hibernate.envers.entities.IdMappingData;
import org.hibernate.envers.entities.PropertyData;
@@ -55,25 +54,9 @@
CompositeMapperBuilder mapper, String entityName, boolean insertable) {
String referencedEntityName = ((ToOne) value).getReferencedEntityName();
- EntityConfiguration configuration = mainGenerator.getEntitiesConfigurations().get(referencedEntityName);
- if (configuration == null) {
- configuration = mainGenerator.getNotAuditedEntitiesConfigurations().get(referencedEntityName);
- if (configuration != null) {
- RelationTargetAuditMode relationTargetAuditMode = propertyAuditingData.getRelationTargetAuditMode();
- if (!RelationTargetAuditMode.NOT_AUDITED.equals(relationTargetAuditMode)) {
- throw new MappingException("An audited relation from " + entityName + "."
- + propertyAuditingData.getName() + " to a not audited entity " + referencedEntityName + "!"
- + ". Such mapping is possible, but has to be strictly defined using RelationTargetAuditMode.NOT_AUDITED in @Audited.");
- }
- }
- }
- if (configuration == null) {
- throw new MappingException("An audited relation from " + entityName + "."
- + propertyAuditingData.getName() + " to a not audited entity " + referencedEntityName + "!");
- }
+ IdMappingData idMapping = mainGenerator.getReferencedIdMappingData(entityName, referencedEntityName,
+ propertyAuditingData, true);
- IdMappingData idMapping = configuration.getIdMappingData();
-
String lastPropertyPrefix = propertyAuditingData.getName() + "_";
// Generating the id mapper for the relation
Modified: core/trunk/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/MiddleIdData.java
===================================================================
--- core/trunk/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/MiddleIdData.java 2009-12-10 16:49:46 UTC (rev 18200)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/MiddleIdData.java 2009-12-10 20:28:27 UTC (rev 18201)
@@ -33,44 +33,51 @@
* @author Adam Warski (adam at warski dot org)
*/
public final class MiddleIdData {
- /**
- * Original id mapper of the related entity.
- */
private final IdMapper originalMapper;
- /**
- * Prefixed id mapper (with the names for the id fields that are used in the middle table) of the related entity.
- */
private final IdMapper prefixedMapper;
- /**
- * Name of the related entity.
- */
private final String entityName;
- /**
- * Versions name of the related entity.
- */
- private final String versionsEntityName;
+ private final String auditEntityName;
public MiddleIdData(AuditEntitiesConfiguration verEntCfg, IdMappingData mappingData, String prefix,
- String entityName) {
+ String entityName, boolean audited) {
this.originalMapper = mappingData.getIdMapper();
this.prefixedMapper = mappingData.getIdMapper().prefixMappedProperties(prefix);
this.entityName = entityName;
- this.versionsEntityName = verEntCfg.getAuditEntityName(entityName);
+ this.auditEntityName = audited ? verEntCfg.getAuditEntityName(entityName) : null;
}
+ /**
+ * @return Original id mapper of the related entity.
+ */
public IdMapper getOriginalMapper() {
return originalMapper;
}
+ /**
+ * @return prefixed id mapper (with the names for the id fields that are used in the middle table) of the related entity.
+ */
public IdMapper getPrefixedMapper() {
return prefixedMapper;
}
+ /**
+ * @return Name of the related entity (regular, not audited).
+ */
public String getEntityName() {
return entityName;
}
- public String getVersionsEntityName() {
- return versionsEntityName;
+ /**
+ * @return Audit name of the related entity.
+ */
+ public String getAuditEntityName() {
+ return auditEntityName;
}
+
+ /**
+ * @return Is the entity, to which this middle id data correspond, audited.
+ */
+ public boolean isAudited() {
+ return auditEntityName != null;
+ }
}
Modified: core/trunk/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/lazy/initializor/BasicCollectionInitializor.java
===================================================================
--- core/trunk/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/lazy/initializor/BasicCollectionInitializor.java 2009-12-10 16:49:46 UTC (rev 18200)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/lazy/initializor/BasicCollectionInitializor.java 2009-12-10 20:28:27 UTC (rev 18201)
@@ -66,8 +66,16 @@
@SuppressWarnings({"unchecked"})
protected void addToCollection(T collection, Object collectionRow) {
Object elementData = ((List) collectionRow).get(elementComponentData.getComponentIndex());
- Object element = elementComponentData.getComponentMapper().mapToObjectFromFullMap(entityInstantiator,
- (Map<String, Object>) elementData, null, revision);
+
+ // If the target entity is not audited, the elements may be the entities already, so we have to check
+ // if they are maps or not.
+ Object element;
+ if (elementData instanceof Map) {
+ element = elementComponentData.getComponentMapper().mapToObjectFromFullMap(entityInstantiator,
+ (Map<String, Object>) elementData, null, revision);
+ } else {
+ element = elementData;
+ }
collection.add(element);
}
}
Modified: 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 2009-12-10 16:49:46 UTC (rev 18200)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/query/QueryGeneratorTools.java 2009-12-10 20:28:27 UTC (rev 18201)
@@ -37,7 +37,7 @@
MiddleIdData idData, String revisionPropertyPath, String originalIdPropertyName,
String alias1, String alias2) {
// SELECT max(e.revision) FROM versionsReferencedEntity e2
- QueryBuilder maxERevQb = qb.newSubQueryBuilder(idData.getVersionsEntityName(), alias2);
+ QueryBuilder maxERevQb = qb.newSubQueryBuilder(idData.getAuditEntityName(), alias2);
maxERevQb.addProjection("max", revisionPropertyPath, false);
// WHERE
Parameters maxERevQbParameters = maxERevQb.getRootParameters();
Modified: core/trunk/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/query/RelationQueryGenerator.java
===================================================================
--- core/trunk/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/query/RelationQueryGenerator.java 2009-12-10 16:49:46 UTC (rev 18200)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/query/RelationQueryGenerator.java 2009-12-10 20:28:27 UTC (rev 18201)
@@ -28,6 +28,8 @@
import org.hibernate.Query;
/**
+ * TODO: cleanup implementations and extract common code
+ *
* Implementations of this interface provide a method to generate queries on a relation table (a table used
* for mapping relations). The query can select, apart from selecting the content of the relation table, also data of
* other "related" entities.
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 2009-12-10 16:49:46 UTC (rev 18200)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/query/ThreeEntityQueryGenerator.java 2009-12-10 20:28:27 UTC (rev 18201)
@@ -85,8 +85,8 @@
// SELECT new list(ee) FROM middleEntity ee
QueryBuilder qb = new QueryBuilder(versionsMiddleEntityName, "ee");
- qb.addFrom(referencedIdData.getVersionsEntityName(), "e");
- qb.addFrom(indexIdData.getVersionsEntityName(), "f");
+ qb.addFrom(referencedIdData.getAuditEntityName(), "e");
+ qb.addFrom(indexIdData.getAuditEntityName(), "f");
qb.addProjection("new list", "ee, e, f", false, false);
// WHERE
Parameters rootParameters = qb.getRootParameters();
Copied: core/trunk/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/query/TwoEntityOneAuditedQueryGenerator.java (from rev 18113, 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/TwoEntityOneAuditedQueryGenerator.java (rev 0)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/query/TwoEntityOneAuditedQueryGenerator.java 2009-12-10 20:28:27 UTC (rev 18201)
@@ -0,0 +1,108 @@
+/*
+ * 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 java.util.Collections;
+
+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.tools.query.Parameters;
+import org.hibernate.envers.tools.query.QueryBuilder;
+
+import org.hibernate.Query;
+
+/**
+ * Selects data from a relation middle-table and a related non-audited entity.
+ * @author Adam Warski (adam at warski dot org)
+ */
+public final class TwoEntityOneAuditedQueryGenerator implements RelationQueryGenerator {
+ private final String queryString;
+ private final MiddleIdData referencingIdData;
+
+ public TwoEntityOneAuditedQueryGenerator(
+ AuditEntitiesConfiguration verEntCfg,
+ String versionsMiddleEntityName,
+ MiddleIdData referencingIdData,
+ MiddleIdData referencedIdData,
+ MiddleComponentData... componentDatas) {
+ this.referencingIdData = referencingIdData;
+
+ /*
+ * The query that we need to create:
+ * SELECT new list(ee, e) FROM referencedEntity e, middleEntity ee
+ * WHERE
+ * (entities referenced by the middle table; id_ref_ed = id of the referenced entity)
+ * 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)
+ * ee.revision = (SELECT max(ee2.revision) FROM middleEntity ee2
+ * WHERE ee2.revision <= :revision AND ee2.originalId.* = ee.originalId.*) AND
+ * (only non-deleted entities and associations)
+ * ee.revision_type != DEL
+ */
+ String revisionPropertyPath = verEntCfg.getRevisionNumberPath();
+ String originalIdPropertyName = verEntCfg.getOriginalIdPropName();
+
+ String eeOriginalIdPropertyPath = "ee." + originalIdPropertyName;
+
+ // SELECT new list(ee) FROM middleEntity ee
+ QueryBuilder qb = new QueryBuilder(versionsMiddleEntityName, "ee");
+ qb.addFrom(referencedIdData.getEntityName(), "e");
+ qb.addProjection("new list", "ee, e", false, false);
+ // WHERE
+ Parameters rootParameters = qb.getRootParameters();
+ // ee.id_ref_ed = e.id_ref_ed
+ referencedIdData.getPrefixedMapper().addIdsEqualToQuery(rootParameters, eeOriginalIdPropertyPath,
+ referencedIdData.getOriginalMapper(), "e");
+ // 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);
+
+ // ee.revision_type != DEL
+ rootParameters.addWhereWithNamedParam(verEntCfg.getRevisionTypePropName(), "!=", "delrevisiontype");
+
+ StringBuilder sb = new StringBuilder();
+ qb.build(sb, Collections.<String, Object>emptyMap());
+ queryString = sb.toString();
+ }
+
+ public Query getQuery(AuditReaderImplementor versionsReader, Object primaryKey, Number revision) {
+ Query query = versionsReader.getSession().createQuery(queryString);
+ query.setParameter("revision", revision);
+ query.setParameter("delrevisiontype", RevisionType.DEL);
+ for (QueryParameterData paramData: referencingIdData.getPrefixedMapper().mapToQueryParametersFromId(primaryKey)) {
+ paramData.setParameterValue(query);
+ }
+
+ 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 2009-12-10 16:49:46 UTC (rev 18200)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/query/TwoEntityQueryGenerator.java 2009-12-10 20:28:27 UTC (rev 18201)
@@ -78,7 +78,7 @@
// SELECT new list(ee) FROM middleEntity ee
QueryBuilder qb = new QueryBuilder(versionsMiddleEntityName, "ee");
- qb.addFrom(referencedIdData.getVersionsEntityName(), "e");
+ qb.addFrom(referencedIdData.getAuditEntityName(), "e");
qb.addProjection("new list", "ee, e", false, false);
// WHERE
Parameters rootParameters = qb.getRootParameters();
Added: core/trunk/envers/src/test/java/org/hibernate/envers/test/entities/manytomany/unidirectional/M2MTargetNotAuditedEntity.java
===================================================================
--- core/trunk/envers/src/test/java/org/hibernate/envers/test/entities/manytomany/unidirectional/M2MTargetNotAuditedEntity.java (rev 0)
+++ core/trunk/envers/src/test/java/org/hibernate/envers/test/entities/manytomany/unidirectional/M2MTargetNotAuditedEntity.java 2009-12-10 20:28:27 UTC (rev 18201)
@@ -0,0 +1,116 @@
+/*
+ * 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.test.entities.manytomany.unidirectional;
+
+import javax.persistence.*;
+
+import org.hibernate.envers.Audited;
+import org.hibernate.envers.RelationTargetAuditMode;
+import org.hibernate.envers.test.entities.UnversionedStrTestEntity;
+
+import java.util.List;
+
+/**
+ * Audited entity with a many-to-many-reference to not audited entity.
+ * @author Toamsz Bech
+ * @author Adam Warski
+ */
+@Entity
+public class M2MTargetNotAuditedEntity {
+ @Id
+ private Integer id;
+
+ @Audited
+ private String data;
+
+ @Audited(targetAuditMode = RelationTargetAuditMode.NOT_AUDITED)
+ @ManyToMany(fetch = FetchType.LAZY)
+ private List<UnversionedStrTestEntity> references;
+
+ public M2MTargetNotAuditedEntity() { }
+
+ public M2MTargetNotAuditedEntity(Integer id, String data, List<UnversionedStrTestEntity> references) {
+ this.id = id;
+ this.data = data;
+ this.references = references;
+ }
+
+ public M2MTargetNotAuditedEntity(String data, List<UnversionedStrTestEntity> references) {
+ this.data = data;
+ this.references = references;
+ }
+
+ public M2MTargetNotAuditedEntity(Integer id, String data) {
+ this.id = id;
+ this.data = data;
+ }
+
+ public Integer getId() {
+ return id;
+ }
+
+ public void setId(Integer id) {
+ this.id = id;
+ }
+
+ public String getData() {
+ return data;
+ }
+
+ public void setData(String data) {
+ this.data = data;
+ }
+
+ public List<UnversionedStrTestEntity> getReferences() {
+ return references;
+ }
+
+ public void setReferences(List<UnversionedStrTestEntity> references) {
+ this.references = references;
+ }
+
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (!(o instanceof M2MTargetNotAuditedEntity)) return false;
+
+ M2MTargetNotAuditedEntity that = (M2MTargetNotAuditedEntity) o;
+
+ if (data != null ? !data.equals(that.getData()) : that.getData() != null) return false;
+ //noinspection RedundantIfStatement
+ if (id != null ? !id.equals(that.getId()) : that.getId() != null) return false;
+
+ return true;
+ }
+
+ public int hashCode() {
+ int result;
+ result = (id != null ? id.hashCode() : 0);
+ result = 31 * result + (data != null ? data.hashCode() : 0);
+ return result;
+ }
+
+ public String toString() {
+ return "M2MTargetNotAuditedEntity(id = " + id + ", data = " + data + ")";
+ }
+}
Added: core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/manytomany/unidirectional/M2MRelationNotAuditedTarget.java
===================================================================
--- core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/manytomany/unidirectional/M2MRelationNotAuditedTarget.java (rev 0)
+++ core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/manytomany/unidirectional/M2MRelationNotAuditedTarget.java 2009-12-10 20:28:27 UTC (rev 18201)
@@ -0,0 +1,167 @@
+/*
+ * 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.test.integration.manytomany.unidirectional;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.ArrayList;
+
+import javax.persistence.EntityManager;
+
+import org.hibernate.ejb.Ejb3Configuration;
+import org.hibernate.envers.test.AbstractEntityTest;
+import static org.hibernate.envers.test.tools.TestTools.*;
+import org.hibernate.envers.test.entities.UnversionedStrTestEntity;
+import org.hibernate.envers.test.entities.manytomany.unidirectional.M2MTargetNotAuditedEntity;
+
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+/**
+ * A test for auditing a many-to-many relation where the target entity is not audited.
+ * @author Adam Warski
+ */
+public class M2MRelationNotAuditedTarget extends AbstractEntityTest {
+ private Integer tnae1_id;
+ private Integer tnae2_id;
+
+ private Integer uste1_id;
+ private Integer uste2_id;
+
+ public void configure(Ejb3Configuration cfg) {
+ cfg.addAnnotatedClass(M2MTargetNotAuditedEntity.class);
+ cfg.addAnnotatedClass(UnversionedStrTestEntity.class);
+ }
+
+ @BeforeClass(dependsOnMethods = "init")
+ public void initData() {
+ EntityManager em = getEntityManager();
+
+ UnversionedStrTestEntity uste1 = new UnversionedStrTestEntity("str1");
+ UnversionedStrTestEntity uste2 = new UnversionedStrTestEntity("str2");
+
+ // No revision
+ em.getTransaction().begin();
+
+ em.persist(uste1);
+ em.persist(uste2);
+
+ em.getTransaction().commit();
+
+ // Revision 1
+ em.getTransaction().begin();
+
+ uste1 = em.find(UnversionedStrTestEntity.class, uste1.getId());
+ uste2 = em.find(UnversionedStrTestEntity.class, uste2.getId());
+
+ M2MTargetNotAuditedEntity tnae1 = new M2MTargetNotAuditedEntity(1, "tnae1", new ArrayList<UnversionedStrTestEntity>());
+ M2MTargetNotAuditedEntity tnae2 = new M2MTargetNotAuditedEntity(2, "tnae2", new ArrayList<UnversionedStrTestEntity>());
+ tnae2.getReferences().add(uste1);
+ tnae2.getReferences().add(uste2);
+ em.persist(tnae1);
+ em.persist(tnae2);
+
+ em.getTransaction().commit();
+
+ // Revision 2
+ em.getTransaction().begin();
+
+ tnae1 = em.find(M2MTargetNotAuditedEntity.class, tnae1.getId());
+ tnae2 = em.find(M2MTargetNotAuditedEntity.class, tnae2.getId());
+
+ tnae1.getReferences().add(uste1);
+ tnae2.getReferences().remove(uste1);
+
+ em.getTransaction().commit();
+
+ // Revision 3
+ em.getTransaction().begin();
+
+ tnae1 = em.find(M2MTargetNotAuditedEntity.class, tnae1.getId());
+ tnae2 = em.find(M2MTargetNotAuditedEntity.class, tnae2.getId());
+
+ //field not changed!!!
+ tnae1.getReferences().add(uste1);
+ tnae2.getReferences().remove(uste2);
+
+ em.getTransaction().commit();
+
+ // Revision 4
+ em.getTransaction().begin();
+
+ tnae1 = em.find(M2MTargetNotAuditedEntity.class, tnae1.getId());
+ tnae2 = em.find(M2MTargetNotAuditedEntity.class, tnae2.getId());
+
+ tnae1.getReferences().add(uste2);
+ tnae2.getReferences().add(uste1);
+
+ em.getTransaction().commit();
+
+ //
+ tnae1_id = tnae1.getId();
+ tnae2_id = tnae2.getId();
+ uste1_id = uste1.getId();
+ uste2_id = uste2.getId();
+ }
+
+ @Test
+ public void testRevisionsCounts() {
+ List<Number> revisions = getAuditReader().getRevisions(M2MTargetNotAuditedEntity.class, tnae1_id);
+ assert Arrays.asList(1, 2, 4).equals(revisions);
+ revisions = getAuditReader().getRevisions(M2MTargetNotAuditedEntity.class, tnae2_id);
+ assert Arrays.asList(1, 2, 3, 4).equals(revisions);
+ }
+
+ @Test
+ public void testHistoryOfTnae1_id() {
+ UnversionedStrTestEntity uste1 = getEntityManager().find(UnversionedStrTestEntity.class, uste1_id);
+ UnversionedStrTestEntity uste2 = getEntityManager().find(UnversionedStrTestEntity.class, uste2_id);
+
+ M2MTargetNotAuditedEntity rev1 = getAuditReader().find(M2MTargetNotAuditedEntity.class, tnae1_id, 1);
+ M2MTargetNotAuditedEntity rev2 = getAuditReader().find(M2MTargetNotAuditedEntity.class, tnae1_id, 2);
+ M2MTargetNotAuditedEntity rev3 = getAuditReader().find(M2MTargetNotAuditedEntity.class, tnae1_id, 3);
+ M2MTargetNotAuditedEntity rev4 = getAuditReader().find(M2MTargetNotAuditedEntity.class, tnae1_id, 4);
+
+ checkList(rev1.getReferences());
+ checkList(rev2.getReferences(), uste1);
+ checkList(rev3.getReferences(), uste1);
+ checkList(rev4.getReferences(), uste1, uste2);
+ }
+
+ @Test
+ public void testHistoryOfTnae2_id() {
+ UnversionedStrTestEntity uste1 = getEntityManager().find(UnversionedStrTestEntity.class, uste1_id);
+ UnversionedStrTestEntity uste2 = getEntityManager().find(UnversionedStrTestEntity.class, uste2_id);
+
+ M2MTargetNotAuditedEntity rev1 = getAuditReader().find(M2MTargetNotAuditedEntity.class, tnae2_id, 1);
+ M2MTargetNotAuditedEntity rev2 = getAuditReader().find(M2MTargetNotAuditedEntity.class, tnae2_id, 2);
+ M2MTargetNotAuditedEntity rev3 = getAuditReader().find(M2MTargetNotAuditedEntity.class, tnae2_id, 3);
+ M2MTargetNotAuditedEntity rev4 = getAuditReader().find(M2MTargetNotAuditedEntity.class, tnae2_id, 4);
+
+ checkList(rev1.getReferences(), uste1, uste2);
+ checkList(rev2.getReferences(), uste2);
+ checkList(rev3.getReferences());
+ checkList(rev4.getReferences(), uste1);
+ }
+}
15 years
hibernate-commits@lists.jboss.org Hello!
by Me
Hi!
I saw your profile and would like to get to know you better.
Im looking for open, adventurous people, in my area, but we can start here.
Email me back at marishka(a)email-chatting.com .
Muah!
Marishka ;-)
15 years
Hibernate SVN: r18200 - in core/trunk/entitymanager/src/main/java/org/hibernate/ejb: packaging and 1 other directories.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2009-12-10 11:49:46 -0500 (Thu, 10 Dec 2009)
New Revision: 18200
Modified:
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/Ejb3Configuration.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/HibernatePersistence.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/packaging/PersistenceMetadata.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/packaging/PersistenceXmlLoader.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/util/LogHelper.java
Log:
HHH-4659 HHH-4668 add mapping support for validation-mode and shared-cache-mode
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/Ejb3Configuration.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/Ejb3Configuration.java 2009-12-10 15:44:02 UTC (rev 18199)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/Ejb3Configuration.java 2009-12-10 16:49:46 UTC (rev 18200)
@@ -55,6 +55,7 @@
import javax.persistence.EntityNotFoundException;
import javax.persistence.MappedSuperclass;
import javax.persistence.PersistenceException;
+import javax.persistence.ValidationMode;
import javax.persistence.spi.PersistenceUnitInfo;
import javax.persistence.spi.PersistenceUnitTransactionType;
import javax.sql.DataSource;
@@ -200,6 +201,12 @@
if ( metadata.getHbmfiles().size() > 0 ) {
workingVars.put( HibernatePersistence.HBXML_FILES, metadata.getHbmfiles() );
}
+ if ( metadata.getValidationMode() != null) {
+ workingVars.put( HibernatePersistence.VALIDATION_MODE, metadata.getValidationMode() );
+ }
+ if ( metadata.getSharedCacheMode() != null) {
+ workingVars.put( HibernatePersistence.SHARED_CACHE_MODE, metadata.getSharedCacheMode() );
+ }
Properties props = new Properties();
props.putAll( metadata.getProps() );
if ( overrides != null ) {
@@ -476,6 +483,18 @@
workingVars.put( HibernatePersistence.XML_FILE_NAMES, xmlFiles );
if ( hbmFiles.size() > 0 ) workingVars.put( HibernatePersistence.HBXML_FILES, hbmFiles );
+ //validation-mode
+ final Object validationMode = info.getValidationMode();
+ if ( validationMode != null) {
+ workingVars.put( HibernatePersistence.VALIDATION_MODE, validationMode );
+ }
+
+ //shared-cache-mode
+ final Object sharedCacheMode = info.getSharedCacheMode();
+ if ( sharedCacheMode != null) {
+ workingVars.put( HibernatePersistence.SHARED_CACHE_MODE, sharedCacheMode );
+ }
+
//datasources
Boolean isJTA = null;
boolean overridenDatasource = false;
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/HibernatePersistence.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/HibernatePersistence.java 2009-12-10 15:44:02 UTC (rev 18199)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/HibernatePersistence.java 2009-12-10 16:49:46 UTC (rev 18200)
@@ -56,6 +56,14 @@
*/
public static final String NON_JTA_DATASOURCE = "javax.persistence.nonJtaDataSource";
/**
+ * Validation mode
+ */
+ public static final String VALIDATION_MODE = "javax.persistence.validation.mode";
+ /**
+ * Shared cache mode
+ */
+ public static final String SHARED_CACHE_MODE = "javax.persistence.sharedCache.mode";
+ /**
* JAR autodetection artifacts class, hbm
*/
public static final String AUTODETECTION = "hibernate.archive.autodetection";
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/packaging/PersistenceMetadata.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/packaging/PersistenceMetadata.java 2009-12-10 15:44:02 UTC (rev 18199)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/packaging/PersistenceMetadata.java 2009-12-10 16:49:46 UTC (rev 18200)
@@ -51,7 +51,18 @@
private List<NamedInputStream> hbmfiles = new ArrayList<NamedInputStream>();
private Properties props = new Properties();
private boolean excludeUnlistedClasses = false;
+ private String validationMode;
+ public String getSharedCacheMode() {
+ return sharedCacheMode;
+ }
+
+ public boolean isExcludeUnlistedClasses() {
+ return excludeUnlistedClasses;
+ }
+
+ private String sharedCacheMode;
+
public String getName() {
return name;
}
@@ -204,6 +215,13 @@
.append( hbmfiles != null ? hbmfiles.size() : 0 ).append("\n")
.append("\tproperties[\n");
+ if (validationMode != null) {
+ sb.append("\tvalidation-mode: ").append(validationMode).append("\n");
+ }
+ if (sharedCacheMode != null) {
+ sb.append("\tshared-cache-mode: ").append(sharedCacheMode).append("\n");
+ }
+
if (props != null) {
for ( Map.Entry elt : props.entrySet()) {
sb.append("\t\t").append( elt.getKey() ).append(": ").append( elt.getValue() ).append("\n");
@@ -213,4 +231,16 @@
return sb.toString();
}
+
+ public void setValidationMode(String validationMode) {
+ this.validationMode = validationMode;
+ }
+
+ public String getValidationMode() {
+ return validationMode;
+ }
+
+ public void setSharedCacheMode(String sharedCacheMode) {
+ this.sharedCacheMode = sharedCacheMode;
+ }
}
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/packaging/PersistenceXmlLoader.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/packaging/PersistenceXmlLoader.java 2009-12-10 15:44:02 UTC (rev 18199)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/packaging/PersistenceXmlLoader.java 2009-12-10 16:49:46 UTC (rev 18200)
@@ -212,6 +212,12 @@
else if ( tag.equals( "delimited-identifiers" ) ) {
metadata.setUseQuotedIdentifiers( true );
}
+ else if ( tag.equals( "validation-mode" ) ) {
+ metadata.setValidationMode( XmlHelper.getElementContent( element ) );
+ }
+ else if ( tag.equals( "shared-cache-mode" ) ) {
+ metadata.setSharedCacheMode( XmlHelper.getElementContent( element ) );
+ }
else if ( tag.equals( "properties" ) ) {
NodeList props = element.getChildNodes();
for ( int j = 0; j < props.getLength() ; j++ ) {
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/util/LogHelper.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/util/LogHelper.java 2009-12-10 15:44:02 UTC (rev 18199)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/util/LogHelper.java 2009-12-10 16:49:46 UTC (rev 18200)
@@ -63,6 +63,12 @@
.append( "\n\t" )
.append( "PU root URL: " )
.append( unitInfo.getPersistenceUnitRootUrl() )
+ .append( "\n\t" )
+ .append( "Shared Cache Mode: " )
+ .append( unitInfo.getSharedCacheMode() )
+ .append( "\n\t" )
+ .append( "Validation Mode: " )
+ .append( unitInfo.getValidationMode() )
.append( "\n\t" );
sb.append( "Jar files URLs [" );
List<URL> jarFileUrls = unitInfo.getJarFileUrls();
15 years
Hibernate SVN: r18199 - in validator/trunk/hibernate-validator-annotation-processor/src: main/java/org/hibernate/validator/ap/util and 11 other directories.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2009-12-10 10:44:02 -0500 (Thu, 10 Dec 2009)
New Revision: 18199
Added:
validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/boxing/
validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/boxing/ValidLong.java
validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/boxing/ValidLongValidator.java
validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/boxing/ValidationUsingBoxing.java
validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/classlevelconstraints/
validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/classlevelconstraints/ClassLevelValidation.java
validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/classlevelconstraints/ValidCustomer.java
validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/classlevelconstraints/ValidCustomerValidator.java
validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/composedconstraint/
validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/composedconstraint/FieldLevelValidationUsingComposedConstraint.java
validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/composedconstraint/ValidOrderNumber.java
validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/composedconstraint2/
validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/composedconstraint2/ComposedConstraint.java
validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/composedconstraint2/ComposingConstraint1.java
validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/composedconstraint2/ComposingConstraint1ValidatorForGregorianCalendar.java
validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/composedconstraint2/ComposingConstraint1ValidatorForList.java
validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/composedconstraint2/ComposingConstraint1ValidatorForString.java
validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/composedconstraint2/ComposingConstraint2.java
validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/composedconstraint2/ComposingConstraint2ValidatorForArrayList.java
validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/composedconstraint2/ComposingConstraint2ValidatorForCalendar.java
validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/composedconstraint2/ComposingConstraint2ValidatorForCollection.java
validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/composedconstraint2/FieldLevelValidationUsingComplexComposedConstraint.java
validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/invalidcomposedconstraint/
validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/invalidcomposedconstraint/ValidCustomerNumber.java
Modified:
validator/trunk/hibernate-validator-annotation-processor/src/main/java/org/hibernate/validator/ap/ConstraintAnnotationVisitor.java
validator/trunk/hibernate-validator-annotation-processor/src/main/java/org/hibernate/validator/ap/ConstraintValidationProcessor.java
validator/trunk/hibernate-validator-annotation-processor/src/main/java/org/hibernate/validator/ap/util/ConstraintHelper.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/ConstraintValidationProcessorTest.java
validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/FieldLevelValidationUsingBuiltInConstraints.java
validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/MethodLevelValidationUsingBuiltInConstraints.java
validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/customconstraints/CaseMode.java
validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/customconstraints/CheckCase.java
validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/customconstraints/CheckCaseValidator.java
validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testutil/CompilerTestHelper.java
validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/util/DiagnosticExpection.java
Log:
HV-269 - Applied Gunnar's latest patch (with some additional formatting)
Modified: validator/trunk/hibernate-validator-annotation-processor/src/main/java/org/hibernate/validator/ap/ConstraintAnnotationVisitor.java
===================================================================
--- validator/trunk/hibernate-validator-annotation-processor/src/main/java/org/hibernate/validator/ap/ConstraintAnnotationVisitor.java 2009-12-10 15:27:00 UTC (rev 18198)
+++ validator/trunk/hibernate-validator-annotation-processor/src/main/java/org/hibernate/validator/ap/ConstraintAnnotationVisitor.java 2009-12-10 15:44:02 UTC (rev 18199)
@@ -20,14 +20,17 @@
import java.text.MessageFormat;
import java.util.List;
import java.util.ResourceBundle;
-
import javax.annotation.processing.ProcessingEnvironment;
import javax.lang.model.element.AnnotationMirror;
+import javax.lang.model.element.Element;
import javax.lang.model.element.ElementVisitor;
import javax.lang.model.element.ExecutableElement;
+import javax.lang.model.element.Modifier;
+import javax.lang.model.element.TypeElement;
import javax.lang.model.element.VariableElement;
import javax.lang.model.util.ElementKindVisitor6;
import javax.tools.Diagnostic.Kind;
+import javax.validation.Constraint;
import org.hibernate.validator.ap.util.ConstraintHelper;
@@ -35,53 +38,73 @@
* An {@link ElementVisitor} that visits elements (type declarations, methods
* and fields) annotated with constraint annotations from the Bean Validation
* API.
- *
- * TODO GM: visit type declarations.
- *
+ *
* @author Gunnar Morling.
- *
*/
-final class ConstraintAnnotationVisitor extends
- ElementKindVisitor6<Void, List<AnnotationMirror>> {
-
- private ProcessingEnvironment processingEnvironment;
-
- private ResourceBundle errorMessages;
+final class ConstraintAnnotationVisitor extends ElementKindVisitor6<Void, List<AnnotationMirror>> {
+ private final ProcessingEnvironment processingEnvironment;
+ private final ResourceBundle errorMessages;
+
//TODO GM: make configurable using Options API
- private Kind messagingKind = Kind.ERROR;
+ private final Kind messagingKind = Kind.ERROR;
+ private final ConstraintHelper constraintHelper;
+
public ConstraintAnnotationVisitor(ProcessingEnvironment processingEnvironment) {
-
+
this.processingEnvironment = processingEnvironment;
- errorMessages = ResourceBundle.getBundle("org.hibernate.validator.ap.ValidationProcessorMessages");
+
+ errorMessages = ResourceBundle.getBundle( "org.hibernate.validator.ap.ValidationProcessorMessages" );
+ constraintHelper = new ConstraintHelper(
+ processingEnvironment.getElementUtils(), processingEnvironment.getTypeUtils()
+ );
}
-
+
/**
* <p>
* Checks whether the given mirrors representing one or more constraint annotations are correctly
* specified at the given method. The following checks are performed:</p>
* <ul>
* <li>
- * The method must be a JavaBeans getter method.
- * </li>
+ * The method must be a JavaBeans getter method (name starts with "is", "get" or "has", no parameters)
+ * </li>
* <li>
- * TODO GM:
* The return type of the method must be supported by the constraints.
* </li>
+ * <li>
+ * The method must not be static.
+ * </li>
* </ul>
*/
@Override
public Void visitExecutableAsMethod(ExecutableElement element,
- List<AnnotationMirror> mirrors) {
-
- for (AnnotationMirror oneAnnotationMirror : mirrors) {
- if(!isJavaBeanGetterName(element.getSimpleName().toString())) {
-
- processingEnvironment.getMessager().printMessage(
- messagingKind,
- errorMessages.getString("ONLY_GETTERS_MAY_BE_ANNOTATED"), element, oneAnnotationMirror);
+ List<AnnotationMirror> mirrors) {
+
+ for ( AnnotationMirror oneAnnotationMirror : mirrors ) {
+
+ if ( !isJavaBeanGetterName( element.getSimpleName().toString() ) ||
+ hasParameters( element ) ) {
+
+ reportError( element, oneAnnotationMirror, "ONLY_GETTERS_MAY_BE_ANNOTATED" );
+
+ continue;
}
+
+ if ( isStaticMethod( element ) ) {
+
+ reportError( element, oneAnnotationMirror, "STATIC_METHODS_MAY_NOT_BE_ANNOTATED" );
+
+ continue;
+ }
+
+ if ( !constraintHelper.isAnnotationAllowedAtMethod( oneAnnotationMirror.getAnnotationType(), element ) ) {
+
+ reportError(
+ element, oneAnnotationMirror, "NOT_SUPPORTED_RETURN_TYPE",
+ oneAnnotationMirror.getAnnotationType().asElement().getSimpleName()
+ );
+ }
}
return null;
}
@@ -98,27 +121,124 @@
*/
@Override
public Void visitVariableAsField(VariableElement annotatedField, List<AnnotationMirror> mirrors) {
-
- for (AnnotationMirror oneAnnotationMirror : mirrors) {
-
- ConstraintHelper builtInConstraintHelper =
- new ConstraintHelper(processingEnvironment.getElementUtils(), processingEnvironment.getTypeUtils());
-
- boolean annotationAllowedAtElementType =
- builtInConstraintHelper.isAnnotationAllowedAtElement(oneAnnotationMirror.getAnnotationType(), annotatedField);
-
- if(!annotationAllowedAtElementType) {
- processingEnvironment.getMessager().printMessage(
- messagingKind,
- MessageFormat.format(errorMessages.getString("NOT_SUPPORTED_TYPE"), oneAnnotationMirror.getAnnotationType().asElement().getSimpleName()), annotatedField, oneAnnotationMirror);
+
+ for ( AnnotationMirror oneAnnotationMirror : mirrors ) {
+
+ if ( !constraintHelper.isAnnotationAllowedAtField(
+ oneAnnotationMirror.getAnnotationType(), annotatedField
+ ) ) {
+
+ reportError(
+ annotatedField, oneAnnotationMirror, "NOT_SUPPORTED_TYPE",
+ oneAnnotationMirror.getAnnotationType().asElement().getSimpleName()
+ );
}
}
-
+
return null;
}
-
- private boolean isJavaBeanGetterName(String name) {
- return name.startsWith("is") || name.startsWith("has") || name.startsWith("get");
+
+ /**
+ * <p>
+ * Checks whether the given mirrors representing one or more constraint
+ * annotations are correctly specified at the given annotation type
+ * declaration. The only annotation types allowed to be annotated with a
+ * constraint annotation are other (composed) constraint annotation type
+ * declarations.
+ * </p>
+ */
+ @Override
+ public Void visitTypeAsAnnotationType(TypeElement e,
+ List<AnnotationMirror> mirrors) {
+
+ if ( !isConstraintAnnotation( e ) ) {
+
+ for ( AnnotationMirror oneAnnotationMirror : mirrors ) {
+ reportError( e, oneAnnotationMirror, "ONLY_CONSTRAINT_ANNOTATIONS_MAY_BE_ANNOTATED" );
+ }
+ }
+
+ return null;
}
-
+
+ @Override
+ public Void visitTypeAsClass(TypeElement e, List<AnnotationMirror> p) {
+ return visitClassOrInterfaceOrEnumType( e, p );
+ }
+
+ @Override
+ public Void visitTypeAsEnum(TypeElement e, List<AnnotationMirror> p) {
+ return visitClassOrInterfaceOrEnumType( e, p );
+ }
+
+ @Override
+ public Void visitTypeAsInterface(TypeElement e, List<AnnotationMirror> p) {
+ return visitClassOrInterfaceOrEnumType( e, p );
+ }
+
+ // ==================================
+ // private API below
+ // ==================================
+
+ private Void visitClassOrInterfaceOrEnumType(TypeElement annotatedType,
+ List<AnnotationMirror> mirrors) {
+
+ for ( AnnotationMirror oneAnnotationMirror : mirrors ) {
+
+ if ( !constraintHelper.isAnnotationAllowedAtType(
+ oneAnnotationMirror.getAnnotationType(), annotatedType
+ ) ) {
+
+ reportError(
+ annotatedType, oneAnnotationMirror, "NOT_SUPPORTED_TYPE",
+ oneAnnotationMirror.getAnnotationType().asElement().getSimpleName()
+ );
+ }
+ }
+
+ return null;
+ }
+
+ private boolean hasParameters(ExecutableElement method) {
+ return !method.getParameters().isEmpty();
+ }
+
+ private boolean isJavaBeanGetterName(String methodName) {
+ return methodName.startsWith( "is" ) || methodName.startsWith( "has" ) || methodName.startsWith( "get" );
+ }
+
+ private boolean isStaticMethod(ExecutableElement method) {
+ return method.getModifiers().contains( Modifier.STATIC );
+ }
+
+ private boolean isConstraintAnnotation(TypeElement e) {
+ return e.getAnnotation( Constraint.class ) != null;
+ }
+
+ /**
+ * Reports an error at the given location using the given message key and
+ * optionally the given message parameters.
+ *
+ * @param element The element at which the error shall be reported.
+ * @param annotationMirror The annotation mirror at which the error shall be reported.
+ * @param messageKey The message key to be used to retrieve the text.
+ * @param messageParameters An optional array of message parameters to be put into the
+ * message using a {@link MessageFormat}.
+ */
+ private void reportError(Element element, AnnotationMirror annotationMirror, String messageKey, Object... messageParameters) {
+
+ String message;
+
+ if ( messageParameters == null ) {
+ message = errorMessages.getString( messageKey );
+ }
+ else {
+ message = MessageFormat.format( errorMessages.getString( messageKey ), messageParameters );
+ }
+
+ processingEnvironment.getMessager().printMessage(
+ messagingKind, message, element, annotationMirror
+ );
+ }
+
}
\ No newline at end of file
Modified: validator/trunk/hibernate-validator-annotation-processor/src/main/java/org/hibernate/validator/ap/ConstraintValidationProcessor.java
===================================================================
--- validator/trunk/hibernate-validator-annotation-processor/src/main/java/org/hibernate/validator/ap/ConstraintValidationProcessor.java 2009-12-10 15:27:00 UTC (rev 18198)
+++ validator/trunk/hibernate-validator-annotation-processor/src/main/java/org/hibernate/validator/ap/ConstraintValidationProcessor.java 2009-12-10 15:44:02 UTC (rev 18199)
@@ -19,7 +19,6 @@
import java.util.List;
import java.util.Set;
-
import javax.annotation.processing.AbstractProcessor;
import javax.annotation.processing.RoundEnvironment;
import javax.annotation.processing.SupportedAnnotationTypes;
@@ -27,12 +26,12 @@
import javax.lang.model.SourceVersion;
import javax.lang.model.element.AnnotationMirror;
import javax.lang.model.element.Element;
+import javax.lang.model.element.ElementVisitor;
import javax.lang.model.element.TypeElement;
import org.hibernate.validator.ap.util.AnnotationApiHelper;
import org.hibernate.validator.ap.util.ConstraintHelper;
-
/**
* Annotation processor for validating Bean Validation constraints.
*
@@ -42,43 +41,44 @@
@SupportedAnnotationTypes("*")
@SupportedSourceVersion(SourceVersion.RELEASE_6)
public class ConstraintValidationProcessor extends AbstractProcessor {
-
/**
* Whether this processor claims all processed annotations exclusively or not.
*/
private static final boolean ANNOTATIONS_CLAIMED_EXCLUSIVELY = false;
-
-
+
+
@Override
public boolean process(
- final Set<? extends TypeElement> annotations,
- final RoundEnvironment roundEnvironment) {
-
- AnnotationApiHelper typeHelper = new AnnotationApiHelper(processingEnv.getElementUtils(), processingEnv.getTypeUtils());
- ConstraintAnnotationVisitor v = new ConstraintAnnotationVisitor(processingEnv);
- ConstraintHelper constraintHelper = new ConstraintHelper(processingEnv.getElementUtils(), processingEnv.getTypeUtils());
-
- for (TypeElement oneAnnotation : annotations) {
-
+ final Set<? extends TypeElement> annotations,
+ final RoundEnvironment roundEnvironment) {
+
+ AnnotationApiHelper typeHelper = new AnnotationApiHelper(
+ processingEnv.getElementUtils(), processingEnv.getTypeUtils()
+ );
+ ElementVisitor<Void, List<AnnotationMirror>> visitor = new ConstraintAnnotationVisitor( processingEnv );
+ ConstraintHelper constraintHelper = new ConstraintHelper(
+ processingEnv.getElementUtils(), processingEnv.getTypeUtils()
+ );
+
+ for ( TypeElement oneAnnotation : annotations ) {
+
//only constraint annotations are relevant
- if(!constraintHelper.isConstraintAnnotation(oneAnnotation)) {
+ if ( !constraintHelper.isConstraintAnnotation( oneAnnotation ) ) {
continue;
}
-
- Set<? extends Element> elementsWithConstraintAnnotation =
- roundEnvironment.getElementsAnnotatedWith(oneAnnotation);
-
- for (Element oneAnnotatedElement : elementsWithConstraintAnnotation) {
-
- List<AnnotationMirror> mirrorsOfCurrentAnnotation =
- typeHelper.filterByType(oneAnnotatedElement.getAnnotationMirrors(), oneAnnotation.asType());
-
-
- oneAnnotatedElement.accept(v, mirrorsOfCurrentAnnotation);
+
+ Set<? extends Element> elementsWithConstraintAnnotation =
+ roundEnvironment.getElementsAnnotatedWith( oneAnnotation );
+
+ for ( Element oneAnnotatedElement : elementsWithConstraintAnnotation ) {
+
+ List<AnnotationMirror> mirrorsOfCurrentAnnotation =
+ typeHelper.filterByType( oneAnnotatedElement.getAnnotationMirrors(), oneAnnotation.asType() );
+
+ oneAnnotatedElement.accept( visitor, mirrorsOfCurrentAnnotation );
}
- }
-
+ }
+
return ANNOTATIONS_CLAIMED_EXCLUSIVELY;
}
-
}
Modified: validator/trunk/hibernate-validator-annotation-processor/src/main/java/org/hibernate/validator/ap/util/ConstraintHelper.java
===================================================================
--- validator/trunk/hibernate-validator-annotation-processor/src/main/java/org/hibernate/validator/ap/util/ConstraintHelper.java 2009-12-10 15:27:00 UTC (rev 18198)
+++ validator/trunk/hibernate-validator-annotation-processor/src/main/java/org/hibernate/validator/ap/util/ConstraintHelper.java 2009-12-10 15:44:02 UTC (rev 18199)
@@ -18,8 +18,10 @@
package org.hibernate.validator.ap.util;
import java.lang.annotation.Annotation;
+import java.util.Calendar;
import java.util.Collection;
import java.util.Collections;
+import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -31,15 +33,29 @@
import javax.lang.model.element.ExecutableElement;
import javax.lang.model.element.Name;
import javax.lang.model.element.TypeElement;
+import javax.lang.model.element.VariableElement;
import javax.lang.model.type.DeclaredType;
+import javax.lang.model.type.PrimitiveType;
+import javax.lang.model.type.TypeKind;
import javax.lang.model.type.TypeMirror;
import javax.lang.model.util.Elements;
+import javax.lang.model.util.SimpleAnnotationValueVisitor6;
+import javax.lang.model.util.TypeKindVisitor6;
import javax.lang.model.util.Types;
import javax.validation.Constraint;
import javax.validation.ConstraintValidator;
+import javax.validation.constraints.AssertFalse;
import javax.validation.constraints.AssertTrue;
+import javax.validation.constraints.DecimalMax;
+import javax.validation.constraints.DecimalMin;
+import javax.validation.constraints.Digits;
+import javax.validation.constraints.Future;
+import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
+import javax.validation.constraints.Null;
+import javax.validation.constraints.Past;
+import javax.validation.constraints.Pattern;
import javax.validation.constraints.Size;
/**
@@ -58,7 +74,7 @@
*/
private final Name CONSTRAINT_ANNOTATION_PACKAGE_NAME;
- private static Map<Name, Set<TypeElement>> builtInConstraints;
+ private static Map<Name, Set<TypeMirror>> builtInConstraints;
private Elements elementUtils;
@@ -73,11 +89,21 @@
builtInConstraints = CollectionHelper.newHashMap();
- //TODO GM: register all types
- registerAllowedTypesForBuiltInConstraint(Size.class, CollectionHelper.<Class<?>>asSet(Collection.class, String.class));
- registerAllowedTypesForBuiltInConstraint(AssertTrue.class, CollectionHelper.<Class<?>>asSet(Boolean.class, boolean.class));
+ registerAllowedTypesForBuiltInConstraint(AssertFalse.class, CollectionHelper.<Class<?>>asSet(Boolean.class));
+ registerAllowedTypesForBuiltInConstraint(AssertTrue.class, CollectionHelper.<Class<?>>asSet(Boolean.class));
+ registerAllowedTypesForBuiltInConstraint(DecimalMax.class, CollectionHelper.<Class<?>>asSet(Number.class, String.class));
+ registerAllowedTypesForBuiltInConstraint(DecimalMin.class, CollectionHelper.<Class<?>>asSet(Number.class, String.class));
+ registerAllowedTypesForBuiltInConstraint(Digits.class, CollectionHelper.<Class<?>>asSet(Number.class, String.class));
+ registerAllowedTypesForBuiltInConstraint(Future.class, CollectionHelper.<Class<?>>asSet(Calendar.class, Date.class));
+ registerAllowedTypesForBuiltInConstraint(Max.class, CollectionHelper.<Class<?>>asSet(Number.class, String.class));
+ registerAllowedTypesForBuiltInConstraint(Min.class, CollectionHelper.<Class<?>>asSet(Number.class, String.class));
registerAllowedTypesForBuiltInConstraint(NotNull.class, CollectionHelper.<Class<?>>asSet(Object.class));
- registerAllowedTypesForBuiltInConstraint(Min.class, CollectionHelper.<Class<?>>asSet(Integer.class, Long.class));
+ registerAllowedTypesForBuiltInConstraint(Null.class, CollectionHelper.<Class<?>>asSet(Object.class));
+ registerAllowedTypesForBuiltInConstraint(Past.class, CollectionHelper.<Class<?>>asSet(Calendar.class, Date.class));
+ registerAllowedTypesForBuiltInConstraint(Pattern.class, CollectionHelper.<Class<?>>asSet(String.class));
+
+ //TODO GM: register all array types
+ registerAllowedTypesForBuiltInConstraint(Size.class, CollectionHelper.<Class<?>>asSet(Collection.class, Map.class, String.class, boolean[].class));
}
/**
@@ -86,7 +112,8 @@
* {@link Constraint} meta-annotation (which is only allowed at annotation
* declarations).
*
- * @param typeElement The element of interest.
+ * @param The
+ * element of interest.
* @return True, if the given element is a constraint annotation type, false
* otherwise.
*/
@@ -94,47 +121,77 @@
return typeElement.getAnnotation(Constraint.class) != null;
}
- public boolean isAnnotationAllowedAtElement(DeclaredType annotationType, Element annotatedElement) {
+ public boolean isAnnotationAllowedAtType(DeclaredType annotationType, TypeElement annotatedType) {
- Set<TypeElement> allowedTypesForConstraint = getAllowedTypesForConstraint(annotationType);
+ return isAnnotationAllowed(annotationType, annotatedType.asType());
+ }
- if(allowedTypesForConstraint.isEmpty()) {
- return false;
- }
+ public boolean isAnnotationAllowedAtMethod(DeclaredType annotationType, ExecutableElement annotatedMethod) {
- Element typeElementOfAnnotatedElement = typeUtils.asElement(annotatedElement.asType());
+ return isAnnotationAllowed(annotationType, annotatedMethod.getReturnType());
+ }
+ public boolean isAnnotationAllowedAtField(DeclaredType annotationType, VariableElement annotatedField) {
- if(allowedTypesForConstraint.contains(typeElementOfAnnotatedElement)) {
- return true;
- }
+ return isAnnotationAllowed(annotationType, annotatedField.asType());
+ }
- List<? extends TypeMirror> directSupertypes = typeUtils.directSupertypes(annotatedElement.asType());
+ // ==================================
+ // private API below
+ // ==================================
+ private Set<TypeMirror> getAllSuperTypes(TypeMirror type) {
+
+ Set<TypeMirror> allSuperTypes = CollectionHelper.newHashSet();
+
+ List<? extends TypeMirror> directSupertypes = typeUtils.directSupertypes(type);
+
while(!directSupertypes.isEmpty()) {
- List<TypeMirror> nextSupertypes = CollectionHelper.newArrayList();
- for (TypeMirror oneSuperType : directSupertypes) {
- Element oneSuperTypeAsElement = typeUtils.asElement(oneSuperType);
+ for (TypeMirror typeMirror : directSupertypes) {
+ allSuperTypes.add(typeMirror);
+ }
- if(allowedTypesForConstraint.contains(oneSuperTypeAsElement)) {
- return true;
- }
+ List<TypeMirror> nextSuperTypes = CollectionHelper.newArrayList();
- nextSupertypes.addAll(typeUtils.directSupertypes(oneSuperType));
+ for (TypeMirror typeMirror : directSupertypes) {
+ nextSuperTypes.addAll(typeUtils.directSupertypes(typeMirror));
}
+ directSupertypes = nextSuperTypes;
+ }
- directSupertypes = nextSupertypes;
+
+ return allSuperTypes;
+ }
+
+ /**
+ * Checks whether the given annotation type may be specified at elements of
+ * the specified type.
+ */
+ private boolean isAnnotationAllowed(DeclaredType annotationType, TypeMirror typeOfAnnotatedElement) {
+
+ //TODO GM: implement array type checking
+ if(typeOfAnnotatedElement.getKind() == TypeKind.ARRAY) {
+ return true;
}
+ //convert primitive types into their corresponding boxed type
+ if(typeOfAnnotatedElement.getKind().isPrimitive()) {
+ typeOfAnnotatedElement = (DeclaredType)typeUtils.boxedClass((PrimitiveType)typeOfAnnotatedElement).asType();
+ }
+ Set<TypeMirror> allowedTypesForConstraint = getAllowedTypesForConstraint(annotationType);
+
+ //is the annotation allowed at the given type?
+ for (TypeMirror oneAllowedType : allowedTypesForConstraint) {
+ if(typeUtils.isAssignable(typeOfAnnotatedElement, oneAllowedType)) {
+ return true;
+ }
+ }
+
return false;
}
- // ==================================
- // private API below
- // ==================================
-
/**
* Returns a set with all those type elements, at which the given constraint annotation
* type may be specified.
@@ -142,19 +199,23 @@
* @param annotationType
* @return
*/
- private Set<TypeElement> getAllowedTypesForConstraint(DeclaredType annotationType) {
+ private Set<TypeMirror> getAllowedTypesForConstraint(DeclaredType annotationType) {
+ Set<TypeMirror> theValue;
+
if(isBuiltInConstraint(annotationType)) {
- return getAllowedTypesFromBuiltInConstraint(annotationType);
+ theValue = getAllowedTypesFromBuiltInConstraint(annotationType);
}
else {
- return getAllowedTypesFromCustomConstraint(annotationType);
+ theValue = getAllowedTypesFromCustomConstraint(annotationType);
}
+
+ return theValue;
}
- private Set<TypeElement> getAllowedTypesFromBuiltInConstraint(DeclaredType builtInAnnotationType) {
+ private Set<TypeMirror> getAllowedTypesFromBuiltInConstraint(DeclaredType builtInAnnotationType) {
- Set<TypeElement> theValue = builtInConstraints.get(builtInAnnotationType.asElement().getSimpleName());
+ Set<TypeMirror> theValue = builtInConstraints.get(builtInAnnotationType.asElement().getSimpleName());
if(theValue == null) {
theValue = Collections.emptySet();
@@ -167,24 +228,22 @@
* Returns a set containing all those types, at which the specified custom
* constraint-annotation is allowed.
*
- * @param customInAnnotationType
+ * @param customAnnotationType
* A custom constraint type.
*
* @return A set with all types supported by the given constraint. May be
* empty in case of constraint composition, if there is no common
* type supported by all composing constraints.
- *
- * TODO GM: consider constraint composition
*/
- private Set<TypeElement> getAllowedTypesFromCustomConstraint(DeclaredType customInAnnotationType) {
+ private Set<TypeMirror> getAllowedTypesFromCustomConstraint(DeclaredType customAnnotationType) {
- Set<TypeElement> theValue = CollectionHelper.newHashSet();
+ Set<TypeMirror> theValue = null;
//the Constraint meta-annotation at the type declaration, e.g. "@Constraint(validatedBy = CheckCaseValidator.class)"
- AnnotationMirror constraintMetaAnnotation = getConstraintMetaAnnotation(customInAnnotationType);
+ AnnotationMirror constraintMetaAnnotation = getConstraintMetaAnnotation(customAnnotationType);
if(constraintMetaAnnotation == null) {
- return theValue;
+ throw new IllegalArgumentException("Given type " + customAnnotationType + " isn't a constraint annotation type.");
}
//the validator classes, e.g. [CheckCaseValidator.class]
@@ -192,34 +251,125 @@
for (AnnotationValue oneValidatorClassReference : validatorClassReferences) {
- DeclaredType validatorType = (DeclaredType)oneValidatorClassReference.getValue();
+ if(theValue == null) {
+ theValue = CollectionHelper.newHashSet();
+ }
- //contains the bindings of the type parameters from the implemented ConstraintValidator
- //interface, e.g. "ConstraintValidator<CheckCase, String>"
- DeclaredType constraintValidatorImplementation = getConstraintValidatorSuperType(validatorType);
+ theValue.add(getSupportedType(oneValidatorClassReference));
+ }
- if(constraintValidatorImplementation != null) {
+ Set<AnnotationMirror> composingConstraints = getComposingConstraints(customAnnotationType);
+ for (AnnotationMirror oneComposingConstraint : composingConstraints) {
+
+ Set<TypeMirror> allowedTypesForComposingConstraint = getAllowedTypesForConstraint(oneComposingConstraint.getAnnotationType());
+
+ if(theValue == null) {
+ theValue = allowedTypesForComposingConstraint;
+ }
+ else {
+ theValue = intersect(theValue, allowedTypesForComposingConstraint);
+ }
+ }
+
+ if(theValue == null) {
+ theValue = Collections.emptySet();
+ }
+
+ return theValue;
+ }
+
+ private TypeMirror getSupportedType(AnnotationValue oneValidatorClassReference) {
+
+ TypeMirror validatorType = oneValidatorClassReference.accept(new SimpleAnnotationValueVisitor6<TypeMirror, Void>() {
+
+ @Override
+ public TypeMirror visitType(TypeMirror t, Void p) {
+ return t;
+ }
+ }, null);
+
+ //contains the bindings of the type parameters from the implemented ConstraintValidator
+ //interface, e.g. "ConstraintValidator<CheckCase, String>"
+ TypeMirror constraintValidatorImplementation = getConstraintValidatorSuperType(validatorType);
+
+
+ TypeMirror supportedType = constraintValidatorImplementation.accept(new TypeKindVisitor6<TypeMirror, Void>() {
+
+ @Override
+ public TypeMirror visitDeclared(DeclaredType constraintValidatorImplementation, Void p) {
//2nd type parameter contains the data type supported by current validator class, e.g. "String"
- TypeMirror supportedTypeParameter = constraintValidatorImplementation.getTypeArguments().get(1);
- theValue.add((TypeElement)typeUtils.asElement(supportedTypeParameter));
+ return constraintValidatorImplementation.getTypeArguments().get(1);
}
+
+ }, null);
+
+ return supportedType;
+ }
+
+ private Set<TypeMirror> intersect(Set<TypeMirror> set1, Set<TypeMirror> set2) {
+
+ Set<TypeMirror> theValue = keepThoseWithSuperTypeAndNoSubType(set1, set2);
+
+ theValue.addAll(keepThoseWithSuperTypeAndNoSubType(set2, set1));
+
+ return theValue;
+ }
+
+ //TODO GM: refactor
+ private Set<TypeMirror> keepThoseWithSuperTypeAndNoSubType(Set<TypeMirror> set1, Set<TypeMirror> set2) {
+
+ Set<TypeMirror> theValue = CollectionHelper.newHashSet();
+
+ for (TypeMirror oneType : set1) {
+
+ for (TypeMirror typeMirror : set2) {
+ if(typeUtils.isSameType(oneType, typeMirror)) {
+ theValue.add(oneType);
+ continue;
+ }
+ }
+
+ Set<TypeMirror> superTypes = getAllSuperTypes(oneType);
+ for (TypeMirror oneSuperType : superTypes) {
+
+ for (TypeMirror typeMirror : set2) {
+ if(typeUtils.isSameType(oneSuperType, typeMirror)) {
+
+ if(!containsSubType(oneType, set2)) {
+ theValue.add(oneType);
+ }
+ }
+ }
+ }
}
return theValue;
}
- private DeclaredType getConstraintValidatorSuperType(DeclaredType type) {
+ private boolean containsSubType(TypeMirror type, Set<TypeMirror> potentialSubTypes) {
+ for (TypeMirror onePotentialSubType : potentialSubTypes) {
+
+ if(typeUtils.isAssignable(onePotentialSubType, type)) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ private TypeMirror getConstraintValidatorSuperType(TypeMirror type) {
+
List<? extends TypeMirror> directSupertypes = typeUtils.directSupertypes(type);
for (TypeMirror typeMirror : directSupertypes) {
if(typeUtils.asElement(typeMirror).getSimpleName().contentEquals(ConstraintValidator.class.getSimpleName())) {
- return (DeclaredType)typeMirror;
+ return typeMirror;
}
}
- return null;
+ throw new AssertionError("Class " + type + " specified in @Constraint.validatedBy doesn't implement ConstraintValidator.");
}
/**
@@ -257,13 +407,19 @@
private void registerAllowedTypesForBuiltInConstraint(Class<? extends Annotation> annotation, Set<Class<?>> allowedTypes) {
- Set<TypeElement> allowedTypesAsElements = CollectionHelper.newHashSet();
+ Set<TypeMirror> allowedTypesAsElements = CollectionHelper.newHashSet();
for (Class<?> oneType : allowedTypes) {
- TypeElement typeElement = elementUtils.getTypeElement(oneType.getCanonicalName());
+ if(oneType.isArray()) {
+
+ //TODO GM: handle array types
+ }
+ else {
+ TypeElement typeElement = elementUtils.getTypeElement(oneType.getCanonicalName());
- if(typeElement != null) {
- allowedTypesAsElements.add(typeElement);
+ if(typeElement != null) {
+ allowedTypesAsElements.add(typeUtils.getDeclaredType(typeElement));
+ }
}
}
@@ -290,4 +446,20 @@
return CONSTRAINT_ANNOTATION_PACKAGE_NAME.equals(elementUtils.getPackageOf(element).getQualifiedName());
}
+
+ private Set<AnnotationMirror> getComposingConstraints(DeclaredType constraintAnnotationType) {
+
+ Set<AnnotationMirror> theValue = CollectionHelper.newHashSet();
+
+ List<? extends AnnotationMirror> annotationMirrors = constraintAnnotationType.asElement().getAnnotationMirrors();
+
+ for (AnnotationMirror oneAnnotationMirror : annotationMirrors) {
+ if(getConstraintMetaAnnotation(oneAnnotationMirror.getAnnotationType()) != null) {
+ theValue.add(oneAnnotationMirror);
+ }
+ }
+
+ return theValue;
+ }
+
}
\ No newline at end of file
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 2009-12-10 15:27:00 UTC (rev 18198)
+++ validator/trunk/hibernate-validator-annotation-processor/src/main/resources/org/hibernate/validator/ap/ValidationProcessorMessages.properties 2009-12-10 15:44:02 UTC (rev 18199)
@@ -3,4 +3,7 @@
# Contains error messages to be used by the ConstraintValidationProcessor.
ONLY_GETTERS_MAY_BE_ANNOTATED=Constraint annotations must not be specified at methods, which are no valid JavaBeans getter methods.
-NOT_SUPPORTED_TYPE=The annotation @{0} is disallowed for this data type.
\ No newline at end of file
+NOT_SUPPORTED_TYPE=The annotation @{0} is disallowed for this data type.
+NOT_SUPPORTED_RETURN_TYPE=The annotation @{0} is disallowed for the return type of this method.
+ONLY_CONSTRAINT_ANNOTATIONS_MAY_BE_ANNOTATED=Constraint annotations must not be specified at annotation types, which are no constraint annotation types themselves.
+STATIC_METHODS_MAY_NOT_BE_ANNOTATED=Only non-static methods may be annotated with constraint annotations.
\ No newline at end of file
Modified: validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/ConstraintValidationProcessorTest.java
===================================================================
--- validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/ConstraintValidationProcessorTest.java 2009-12-10 15:27:00 UTC (rev 18198)
+++ validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/ConstraintValidationProcessorTest.java 2009-12-10 15:44:02 UTC (rev 18199)
@@ -17,95 +17,249 @@
*/
package org.hibernate.validator.ap;
-import static org.hibernate.validator.ap.testutil.CompilerTestHelper.assertDiagnostics;
-import static org.testng.Assert.assertFalse;
-import static org.testng.Assert.assertNotNull;
-
import java.io.File;
-
+import javax.tools.Diagnostic.Kind;
import javax.tools.DiagnosticCollector;
import javax.tools.JavaFileObject;
import javax.tools.ToolProvider;
-import javax.tools.Diagnostic.Kind;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
import org.hibernate.validator.ap.testmodel.FieldLevelValidationUsingBuiltInConstraints;
import org.hibernate.validator.ap.testmodel.MethodLevelValidationUsingBuiltInConstraints;
+import org.hibernate.validator.ap.testmodel.boxing.ValidLong;
+import org.hibernate.validator.ap.testmodel.boxing.ValidLongValidator;
+import org.hibernate.validator.ap.testmodel.boxing.ValidationUsingBoxing;
+import org.hibernate.validator.ap.testmodel.classlevelconstraints.ClassLevelValidation;
+import org.hibernate.validator.ap.testmodel.classlevelconstraints.ValidCustomer;
+import org.hibernate.validator.ap.testmodel.classlevelconstraints.ValidCustomerValidator;
+import org.hibernate.validator.ap.testmodel.composedconstraint.FieldLevelValidationUsingComposedConstraint;
+import org.hibernate.validator.ap.testmodel.composedconstraint.ValidOrderNumber;
+import org.hibernate.validator.ap.testmodel.composedconstraint2.ComposedConstraint;
+import org.hibernate.validator.ap.testmodel.composedconstraint2.ComposingConstraint1;
+import org.hibernate.validator.ap.testmodel.composedconstraint2.ComposingConstraint1ValidatorForGregorianCalendar;
+import org.hibernate.validator.ap.testmodel.composedconstraint2.ComposingConstraint1ValidatorForList;
+import org.hibernate.validator.ap.testmodel.composedconstraint2.ComposingConstraint1ValidatorForString;
+import org.hibernate.validator.ap.testmodel.composedconstraint2.ComposingConstraint2;
+import org.hibernate.validator.ap.testmodel.composedconstraint2.ComposingConstraint2ValidatorForArrayList;
+import org.hibernate.validator.ap.testmodel.composedconstraint2.ComposingConstraint2ValidatorForCalendar;
+import org.hibernate.validator.ap.testmodel.composedconstraint2.ComposingConstraint2ValidatorForCollection;
+import org.hibernate.validator.ap.testmodel.composedconstraint2.FieldLevelValidationUsingComplexComposedConstraint;
import org.hibernate.validator.ap.testmodel.customconstraints.CaseMode;
import org.hibernate.validator.ap.testmodel.customconstraints.CheckCase;
import org.hibernate.validator.ap.testmodel.customconstraints.CheckCaseValidator;
import org.hibernate.validator.ap.testmodel.customconstraints.FieldLevelValidationUsingCustomConstraints;
+import org.hibernate.validator.ap.testmodel.invalidcomposedconstraint.ValidCustomerNumber;
import org.hibernate.validator.ap.testutil.CompilerTestHelper;
import org.hibernate.validator.ap.util.DiagnosticExpection;
-import org.testng.annotations.BeforeClass;
-import org.testng.annotations.Test;
+import static org.hibernate.validator.ap.testutil.CompilerTestHelper.assertDiagnostics;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertNotNull;
+
/**
* Test for {@link ConstraintValidationProcessor} using the Java compiler
* API as defined by JSR 199.
- *
+ *
* @author Gunnar Morling.
- *
*/
public class ConstraintValidationProcessorTest {
+ private static CompilerTestHelper compilerHelper;
- private static CompilerTestHelper compilerHelper;
-
@BeforeClass
public static void setUpCompilerHelper() {
- String testSourceBaseDir = System.getProperty("testSourceBaseDir");
- String pathToBeanValidationApiJar = System.getProperty("pathToBeanValidationApiJar");
-
- assertNotNull(testSourceBaseDir, "The system property testSourceBaseDir has to be set and point to the base directory of the test java sources.");
- assertNotNull(pathToBeanValidationApiJar, "The system property pathToBeanValidationApiJar has to be set and point to the BV API Jars.");
-
- compilerHelper =
- new CompilerTestHelper(ToolProvider.getSystemJavaCompiler(), testSourceBaseDir, pathToBeanValidationApiJar);
+ String testSourceBaseDir = System.getProperty( "testSourceBaseDir" );
+ String pathToBeanValidationApiJar = System.getProperty( "pathToBeanValidationApiJar" );
+
+ assertNotNull(
+ testSourceBaseDir,
+ "The system property testSourceBaseDir has to be set and point to the base directory of the test java sources."
+ );
+ assertNotNull(
+ pathToBeanValidationApiJar,
+ "The system property pathToBeanValidationApiJar has to be set and point to the BV API Jars."
+ );
+
+ compilerHelper =
+ new CompilerTestHelper(
+ ToolProvider.getSystemJavaCompiler(), testSourceBaseDir, pathToBeanValidationApiJar
+ );
}
@Test
public void fieldLevelValidationUsingBuiltInConstraints() {
DiagnosticCollector<JavaFileObject> diagnostics = new DiagnosticCollector<JavaFileObject>();
-
- File sourceFile = compilerHelper.getSourceFile(FieldLevelValidationUsingBuiltInConstraints.class);
-
- boolean compilationResult =
- compilerHelper.compile(new ConstraintValidationProcessor(), diagnostics, sourceFile);
- assertFalse(compilationResult);
- assertDiagnostics(diagnostics, new DiagnosticExpection(Kind.ERROR, 48));
+ File sourceFile = compilerHelper.getSourceFile( FieldLevelValidationUsingBuiltInConstraints.class );
+
+ boolean compilationResult =
+ compilerHelper.compile( new ConstraintValidationProcessor(), diagnostics, sourceFile );
+
+ assertFalse( compilationResult );
+ assertDiagnostics( diagnostics, new DiagnosticExpection( Kind.ERROR, 43 ) );
}
-
+
@Test
public void fieldLevelValidationUsingCustomConstraints() {
DiagnosticCollector<JavaFileObject> diagnostics = new DiagnosticCollector<JavaFileObject>();
-
- File sourceFile1 = compilerHelper.getSourceFile(FieldLevelValidationUsingCustomConstraints.class);
- File sourceFile2 = compilerHelper.getSourceFile(CheckCase.class);
- File sourceFile3 = compilerHelper.getSourceFile(CaseMode.class);
- File sourceFile4 = compilerHelper.getSourceFile(CheckCaseValidator.class);
-
- boolean compilationResult =
- compilerHelper.compile(new ConstraintValidationProcessor(), diagnostics, sourceFile1, sourceFile2, sourceFile3, sourceFile4);
- assertFalse(compilationResult);
- assertDiagnostics(diagnostics, new DiagnosticExpection(Kind.ERROR, 30));
+ File sourceFile1 = compilerHelper.getSourceFile( FieldLevelValidationUsingCustomConstraints.class );
+ File sourceFile2 = compilerHelper.getSourceFile( CheckCase.class );
+ File sourceFile3 = compilerHelper.getSourceFile( CaseMode.class );
+ File sourceFile4 = compilerHelper.getSourceFile( CheckCaseValidator.class );
+
+ boolean compilationResult =
+ compilerHelper.compile(
+ new ConstraintValidationProcessor(),
+ diagnostics,
+ sourceFile1,
+ sourceFile2,
+ sourceFile3,
+ sourceFile4
+ );
+
+ assertFalse( compilationResult );
+ assertDiagnostics( diagnostics, new DiagnosticExpection( Kind.ERROR, 30 ) );
}
-
+
@Test
public void methodLevelValidationUsingBuiltInConstraints() {
DiagnosticCollector<JavaFileObject> diagnostics = new DiagnosticCollector<JavaFileObject>();
-
- File sourceFile = compilerHelper.getSourceFile(MethodLevelValidationUsingBuiltInConstraints.class);
-
- boolean compilationResult =
- compilerHelper.compile(new ConstraintValidationProcessor(), diagnostics, sourceFile);
- assertFalse(compilationResult);
- assertDiagnostics(diagnostics, new DiagnosticExpection(Kind.ERROR, 32));
+ File sourceFile = compilerHelper.getSourceFile( MethodLevelValidationUsingBuiltInConstraints.class );
+
+ boolean compilationResult =
+ compilerHelper.compile( new ConstraintValidationProcessor(), diagnostics, sourceFile );
+
+ assertFalse( compilationResult );
+ assertDiagnostics(
+ diagnostics,
+ new DiagnosticExpection( Kind.ERROR, 32 ),
+ new DiagnosticExpection( Kind.ERROR, 39 ),
+ new DiagnosticExpection( Kind.ERROR, 47 ),
+ new DiagnosticExpection( Kind.ERROR, 54 )
+ );
}
-
+
+ @Test
+ public void classLevelValidation() {
+
+ DiagnosticCollector<JavaFileObject> diagnostics = new DiagnosticCollector<JavaFileObject>();
+
+ File sourceFile1 = compilerHelper.getSourceFile( ClassLevelValidation.class );
+ File sourceFile2 = compilerHelper.getSourceFile( ValidCustomer.class );
+ File sourceFile3 = compilerHelper.getSourceFile( ValidCustomerValidator.class );
+
+ boolean compilationResult =
+ compilerHelper.compile(
+ new ConstraintValidationProcessor(), diagnostics, sourceFile1, sourceFile2, sourceFile3
+ );
+
+ assertFalse( compilationResult );
+ assertDiagnostics( diagnostics, new DiagnosticExpection( Kind.ERROR, 28 ) );
+ }
+
+ @Test
+ public void validationUsingComposedConstraint() {
+
+ DiagnosticCollector<JavaFileObject> diagnostics = new DiagnosticCollector<JavaFileObject>();
+
+ File sourceFile1 = compilerHelper.getSourceFile( FieldLevelValidationUsingComposedConstraint.class );
+ File sourceFile2 = compilerHelper.getSourceFile( ValidOrderNumber.class );
+
+ boolean compilationResult =
+ compilerHelper.compile( new ConstraintValidationProcessor(), diagnostics, sourceFile1, sourceFile2 );
+
+ assertFalse( compilationResult );
+ assertDiagnostics( diagnostics, new DiagnosticExpection( Kind.ERROR, 29 ) );
+ }
+
+ @Test
+ public void validationUsingComplexComposedConstraint() {
+
+ DiagnosticCollector<JavaFileObject> diagnostics = new DiagnosticCollector<JavaFileObject>();
+
+ File sourceFile1 = compilerHelper.getSourceFile( FieldLevelValidationUsingComplexComposedConstraint.class );
+ File sourceFile2 = compilerHelper.getSourceFile( ComposedConstraint.class );
+ File sourceFile3 = compilerHelper.getSourceFile( ComposingConstraint1.class );
+ File sourceFile4 = compilerHelper.getSourceFile( ComposingConstraint1ValidatorForString.class );
+ File sourceFile5 = compilerHelper.getSourceFile( ComposingConstraint1ValidatorForGregorianCalendar.class );
+ File sourceFile6 = compilerHelper.getSourceFile( ComposingConstraint1ValidatorForList.class );
+ File sourceFile7 = compilerHelper.getSourceFile( ComposingConstraint2.class );
+ File sourceFile8 = compilerHelper.getSourceFile( ComposingConstraint2ValidatorForArrayList.class );
+ File sourceFile9 = compilerHelper.getSourceFile( ComposingConstraint2ValidatorForCalendar.class );
+ File sourceFile10 = compilerHelper.getSourceFile( ComposingConstraint2ValidatorForCollection.class );
+
+ boolean compilationResult =
+ compilerHelper.compile(
+ new ConstraintValidationProcessor(),
+ diagnostics,
+ sourceFile1,
+ sourceFile2,
+ sourceFile3,
+ sourceFile4,
+ sourceFile5,
+ sourceFile6,
+ sourceFile7,
+ sourceFile8,
+ sourceFile9,
+ sourceFile10
+ );
+
+ assertFalse( compilationResult );
+ assertDiagnostics(
+ diagnostics,
+ new DiagnosticExpection( Kind.ERROR, 29 ),
+ new DiagnosticExpection( Kind.ERROR, 32 ),
+ new DiagnosticExpection( Kind.ERROR, 41 ),
+ new DiagnosticExpection( Kind.ERROR, 50 ),
+ new DiagnosticExpection( Kind.ERROR, 56 )
+ );
+ }
+
+ @Test
+ public void validationUsingBoxing() {
+
+ DiagnosticCollector<JavaFileObject> diagnostics = new DiagnosticCollector<JavaFileObject>();
+
+ File sourceFile1 = compilerHelper.getSourceFile( ValidationUsingBoxing.class );
+ File sourceFile2 = compilerHelper.getSourceFile( ValidLong.class );
+ File sourceFile3 = compilerHelper.getSourceFile( ValidLongValidator.class );
+
+ boolean compilationResult =
+ compilerHelper.compile(
+ new ConstraintValidationProcessor(), diagnostics, sourceFile1, sourceFile2, sourceFile3
+ );
+
+ assertFalse( compilationResult );
+ assertDiagnostics(
+ diagnostics,
+ new DiagnosticExpection( Kind.ERROR, 31 ),
+ new DiagnosticExpection( Kind.ERROR, 37 ),
+ new DiagnosticExpection( Kind.ERROR, 43 ),
+ new DiagnosticExpection( Kind.ERROR, 59 ),
+ new DiagnosticExpection( Kind.ERROR, 67 )
+ );
+ }
+
+ @Test
+ public void constraintAnnotationGivenAtNonConstraintAnnotationType() {
+
+ DiagnosticCollector<JavaFileObject> diagnostics = new DiagnosticCollector<JavaFileObject>();
+
+ File sourceFile = compilerHelper.getSourceFile( ValidCustomerNumber.class );
+
+ boolean compilationResult =
+ compilerHelper.compile( new ConstraintValidationProcessor(), diagnostics, sourceFile );
+
+ assertFalse( compilationResult );
+ assertDiagnostics(
+ diagnostics, new DiagnosticExpection( Kind.ERROR, 28 ), new DiagnosticExpection( Kind.ERROR, 29 )
+ );
+ }
}
\ No newline at end of file
Modified: validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/FieldLevelValidationUsingBuiltInConstraints.java
===================================================================
--- validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/FieldLevelValidationUsingBuiltInConstraints.java 2009-12-10 15:27:00 UTC (rev 18198)
+++ validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/FieldLevelValidationUsingBuiltInConstraints.java 2009-12-10 15:44:02 UTC (rev 18199)
@@ -20,32 +20,29 @@
import java.util.Collection;
import java.util.Date;
import java.util.List;
-
import javax.validation.constraints.Size;
public class FieldLevelValidationUsingBuiltInConstraints {
-
- @Size(min=10)
+ @Size(min = 10)
public String string;
-
- @Size(min=10)
+
+ @Size(min = 10)
public Collection<String> collection;
-
+
//TODO GM: support array-typed elements
-
-// @Size(min=10)
-// public boolean[] array;
-
+
/**
* Allowed, as List extends Collection.
*/
- @Size(min=10)
+ @Size(min = 10)
public List<String> list;
-
+
/**
* Not allowed.
*/
- @Size(min=10)
+ @Size(min = 10)
public Date date;
+ @Size(min = 10)
+ public static String staticString;
}
Modified: validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/MethodLevelValidationUsingBuiltInConstraints.java
===================================================================
--- validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/MethodLevelValidationUsingBuiltInConstraints.java 2009-12-10 15:27:00 UTC (rev 18198)
+++ validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/MethodLevelValidationUsingBuiltInConstraints.java 2009-12-10 15:44:02 UTC (rev 18199)
@@ -17,21 +17,42 @@
*/
package org.hibernate.validator.ap.testmodel;
+import java.util.Date;
import javax.validation.constraints.Size;
public class MethodLevelValidationUsingBuiltInConstraints {
-
- @Size(min=10)
+ @Size(min = 10)
public String getString() {
return null;
}
-
+
/**
* Not allowed. Method is no getter.
*/
- @Size(min=10)
+ @Size(min = 10)
public void setString() {
-
}
-}
+ /**
+ * Not allowed. Return type doesn't match.
+ */
+ @Size(min = 10)
+ public Date getDate() {
+ return null;
+ }
+
+ /**
+ * Not allowed. No return type.
+ */
+ @Size(min = 10)
+ public void getAnotherString() {
+ }
+
+ /**
+ * Not allowed. Static method.
+ */
+ @Size(min = 10)
+ public static String getStringStatically() {
+ return null;
+ }
+}
\ No newline at end of file
Added: validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/boxing/ValidLong.java
===================================================================
--- validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/boxing/ValidLong.java (rev 0)
+++ validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/boxing/ValidLong.java 2009-12-10 15:44:02 UTC (rev 18199)
@@ -0,0 +1,41 @@
+// $Id: ValidLong.java 17946 2009-11-06 18:23:48Z hardy.ferentschik $
+/*
+* 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.boxing;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+import javax.validation.Constraint;
+import javax.validation.Payload;
+
+import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+@Target({ METHOD, FIELD, ANNOTATION_TYPE })
+@Retention(RUNTIME)
+@Constraint(validatedBy = ValidLongValidator.class)
+@Documented
+public @interface ValidLong {
+ String message() default "";
+
+ Class<?>[] groups() default { };
+
+ Class<? extends Payload>[] payload() default { };
+}
Added: validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/boxing/ValidLongValidator.java
===================================================================
--- validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/boxing/ValidLongValidator.java (rev 0)
+++ validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/boxing/ValidLongValidator.java 2009-12-10 15:44:02 UTC (rev 18199)
@@ -0,0 +1,30 @@
+// $Id: ValidLongValidator.java 17946 2009-11-06 18:23:48Z hardy.ferentschik $
+/*
+* 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.boxing;
+
+import javax.validation.ConstraintValidator;
+import javax.validation.ConstraintValidatorContext;
+
+public class ValidLongValidator implements ConstraintValidator<ValidLong, Long> {
+ public void initialize(ValidLong constraintAnnotation) {
+ }
+
+ public boolean isValid(Long object, ConstraintValidatorContext constraintContext) {
+ return true;
+ }
+}
Added: validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/boxing/ValidationUsingBoxing.java
===================================================================
--- validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/boxing/ValidationUsingBoxing.java (rev 0)
+++ validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/boxing/ValidationUsingBoxing.java 2009-12-10 15:44:02 UTC (rev 18199)
@@ -0,0 +1,72 @@
+// $Id: ValidationUsingBoxing.java 17946 2009-11-06 18:23:48Z hardy.ferentschik $
+/*
+* 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.boxing;
+
+public class ValidationUsingBoxing {
+
+ @ValidLong
+ public long primitiveLongField;
+
+ @ValidLong
+ public Long longField;
+
+ /**
+ * Not allowed.
+ */
+ @ValidLong
+ public int intField;
+
+ /**
+ * Not allowed.
+ */
+ @ValidLong
+ public Integer integerField;
+
+ /**
+ * Not allowed.
+ */
+ @ValidLong
+ public double doubleField;
+
+ @ValidLong
+ public long getPrimitiveLong() {
+ return 0;
+ }
+
+ @ValidLong
+ public Long getLong() {
+ return Long.MIN_VALUE;
+ }
+
+ /**
+ * Not allowed.
+ */
+ @ValidLong
+ public int getInt() {
+ return 0;
+ }
+
+ /**
+ * Not allowed.
+ */
+ @ValidLong
+ public Integer getInteger() {
+ return Integer.MIN_VALUE;
+ }
+
+}
Added: validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/classlevelconstraints/ClassLevelValidation.java
===================================================================
--- validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/classlevelconstraints/ClassLevelValidation.java (rev 0)
+++ validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/classlevelconstraints/ClassLevelValidation.java 2009-12-10 15:44:02 UTC (rev 18199)
@@ -0,0 +1,31 @@
+// $Id: ClassLevelValidation.java 17946 2009-11-06 18:23:48Z hardy.ferentschik $
+/*
+* 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.classlevelconstraints;
+
+public class ClassLevelValidation {
+ @ValidCustomer
+ public static class Customer {
+ }
+
+ /**
+ * Not allowed.
+ */
+ @ValidCustomer
+ public static class Order {
+ }
+}
Added: validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/classlevelconstraints/ValidCustomer.java
===================================================================
--- validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/classlevelconstraints/ValidCustomer.java (rev 0)
+++ validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/classlevelconstraints/ValidCustomer.java 2009-12-10 15:44:02 UTC (rev 18199)
@@ -0,0 +1,39 @@
+// $Id: ValidCustomer.java 17946 2009-11-06 18:23:48Z hardy.ferentschik $
+/*
+* 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.classlevelconstraints;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+import javax.validation.Constraint;
+import javax.validation.Payload;
+
+import static java.lang.annotation.ElementType.TYPE;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+@Target({ TYPE })
+@Retention(RUNTIME)
+@Constraint(validatedBy = ValidCustomerValidator.class)
+@Documented
+public @interface ValidCustomer {
+ String message() default "";
+
+ Class<?>[] groups() default { };
+
+ Class<? extends Payload>[] payload() default { };
+}
Added: validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/classlevelconstraints/ValidCustomerValidator.java
===================================================================
--- validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/classlevelconstraints/ValidCustomerValidator.java (rev 0)
+++ validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/classlevelconstraints/ValidCustomerValidator.java 2009-12-10 15:44:02 UTC (rev 18199)
@@ -0,0 +1,32 @@
+// $Id: ValidCustomerValidator.java 17946 2009-11-06 18:23:48Z hardy.ferentschik $
+/*
+* 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.classlevelconstraints;
+
+import javax.validation.ConstraintValidator;
+import javax.validation.ConstraintValidatorContext;
+
+import org.hibernate.validator.ap.testmodel.classlevelconstraints.ClassLevelValidation.Customer;
+
+public class ValidCustomerValidator implements ConstraintValidator<ValidCustomer, Customer> {
+ public void initialize(ValidCustomer constraintAnnotation) {
+ }
+
+ public boolean isValid(Customer customer, ConstraintValidatorContext constraintContext) {
+ return true;
+ }
+}
Added: validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/composedconstraint/FieldLevelValidationUsingComposedConstraint.java
===================================================================
--- validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/composedconstraint/FieldLevelValidationUsingComposedConstraint.java (rev 0)
+++ validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/composedconstraint/FieldLevelValidationUsingComposedConstraint.java 2009-12-10 15:44:02 UTC (rev 18199)
@@ -0,0 +1,31 @@
+// $Id: FieldLevelValidationUsingComposedConstraint.java 17946 2009-11-06 18:23:48Z hardy.ferentschik $
+/*
+* 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.composedconstraint;
+
+import java.util.Date;
+
+public class FieldLevelValidationUsingComposedConstraint {
+ @ValidOrderNumber
+ public String string;
+
+ /**
+ * Not allowed.
+ */
+ @ValidOrderNumber
+ public Date date;
+}
Added: validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/composedconstraint/ValidOrderNumber.java
===================================================================
--- validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/composedconstraint/ValidOrderNumber.java (rev 0)
+++ validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/composedconstraint/ValidOrderNumber.java 2009-12-10 15:44:02 UTC (rev 18199)
@@ -0,0 +1,45 @@
+// $Id: ValidOrderNumber.java 17946 2009-11-06 18:23:48Z hardy.ferentschik $
+/*
+* 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.composedconstraint;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+import javax.validation.Constraint;
+import javax.validation.Payload;
+import javax.validation.constraints.NotNull;
+import javax.validation.constraints.Size;
+
+import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+@NotNull
+@Size(min = 10, max = 10)
+@Target({ METHOD, FIELD, ANNOTATION_TYPE })
+@Retention(RUNTIME)
+@Constraint(validatedBy = { })
+@Documented
+public @interface ValidOrderNumber {
+ String message() default "";
+
+ Class<?>[] groups() default { };
+
+ Class<? extends Payload>[] payload() default { };
+}
Added: validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/composedconstraint2/ComposedConstraint.java
===================================================================
--- validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/composedconstraint2/ComposedConstraint.java (rev 0)
+++ validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/composedconstraint2/ComposedConstraint.java 2009-12-10 15:44:02 UTC (rev 18199)
@@ -0,0 +1,43 @@
+// $Id: ComposedConstraint.java 17946 2009-11-06 18:23:48Z hardy.ferentschik $
+/*
+* 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.composedconstraint2;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+import javax.validation.Constraint;
+import javax.validation.Payload;
+
+import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+@ComposingConstraint1
+@ComposingConstraint2
+@Target({ METHOD, FIELD, ANNOTATION_TYPE })
+@Retention(RUNTIME)
+@Constraint(validatedBy = { })
+@Documented
+public @interface ComposedConstraint {
+ String message() default "";
+
+ Class<?>[] groups() default { };
+
+ Class<? extends Payload>[] payload() default { };
+}
Added: validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/composedconstraint2/ComposingConstraint1.java
===================================================================
--- validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/composedconstraint2/ComposingConstraint1.java (rev 0)
+++ validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/composedconstraint2/ComposingConstraint1.java 2009-12-10 15:44:02 UTC (rev 18199)
@@ -0,0 +1,45 @@
+// $Id: ComposingConstraint1.java 17946 2009-11-06 18:23:48Z hardy.ferentschik $
+/*
+* 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.composedconstraint2;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+import javax.validation.Constraint;
+import javax.validation.Payload;
+
+import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+@Target({ METHOD, FIELD, ANNOTATION_TYPE })
+@Retention(RUNTIME)
+@Constraint(validatedBy = {
+ ComposingConstraint1ValidatorForList.class,
+ ComposingConstraint1ValidatorForString.class,
+ ComposingConstraint1ValidatorForGregorianCalendar.class
+})
+@Documented
+public @interface ComposingConstraint1 {
+ String message() default "";
+
+ Class<?>[] groups() default { };
+
+ Class<? extends Payload>[] payload() default { };
+}
Added: validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/composedconstraint2/ComposingConstraint1ValidatorForGregorianCalendar.java
===================================================================
--- validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/composedconstraint2/ComposingConstraint1ValidatorForGregorianCalendar.java (rev 0)
+++ validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/composedconstraint2/ComposingConstraint1ValidatorForGregorianCalendar.java 2009-12-10 15:44:02 UTC (rev 18199)
@@ -0,0 +1,32 @@
+// $Id: ComposingConstraint1ValidatorForGregorianCalendar.java 17946 2009-11-06 18:23:48Z hardy.ferentschik $
+/*
+* 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.composedconstraint2;
+
+import java.util.GregorianCalendar;
+import javax.validation.ConstraintValidator;
+import javax.validation.ConstraintValidatorContext;
+
+public class ComposingConstraint1ValidatorForGregorianCalendar
+ implements ConstraintValidator<ComposingConstraint1, GregorianCalendar> {
+ public void initialize(ComposingConstraint1 constraintAnnotation) {
+ }
+
+ public boolean isValid(GregorianCalendar object, ConstraintValidatorContext constraintContext) {
+ return true;
+ }
+}
Added: validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/composedconstraint2/ComposingConstraint1ValidatorForList.java
===================================================================
--- validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/composedconstraint2/ComposingConstraint1ValidatorForList.java (rev 0)
+++ validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/composedconstraint2/ComposingConstraint1ValidatorForList.java 2009-12-10 15:44:02 UTC (rev 18199)
@@ -0,0 +1,32 @@
+// $Id: ComposingConstraint1ValidatorForList.java 17946 2009-11-06 18:23:48Z hardy.ferentschik $
+/*
+* 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.composedconstraint2;
+
+import java.util.List;
+import javax.validation.ConstraintValidator;
+import javax.validation.ConstraintValidatorContext;
+
+public class ComposingConstraint1ValidatorForList implements ConstraintValidator<ComposingConstraint1, List<?>> {
+ public void initialize(ComposingConstraint1 constraintAnnotation) {
+
+ }
+
+ public boolean isValid(List<?> object, ConstraintValidatorContext constraintContext) {
+ return true;
+ }
+}
Added: validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/composedconstraint2/ComposingConstraint1ValidatorForString.java
===================================================================
--- validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/composedconstraint2/ComposingConstraint1ValidatorForString.java (rev 0)
+++ validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/composedconstraint2/ComposingConstraint1ValidatorForString.java 2009-12-10 15:44:02 UTC (rev 18199)
@@ -0,0 +1,38 @@
+// $Id: ComposingConstraint1ValidatorForString.java 17946 2009-11-06 18:23:48Z hardy.ferentschik $
+/*
+* 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.composedconstraint2;
+
+import javax.validation.ConstraintValidator;
+import javax.validation.ConstraintValidatorContext;
+
+public class ComposingConstraint1ValidatorForString implements
+ConstraintValidator<ComposingConstraint1, String> {
+
+
+
+ public void initialize(ComposingConstraint1 constraintAnnotation) {
+
+ }
+
+ public boolean isValid(String object,
+ ConstraintValidatorContext constraintContext) {
+
+ return true;
+ }
+
+}
Added: validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/composedconstraint2/ComposingConstraint2.java
===================================================================
--- validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/composedconstraint2/ComposingConstraint2.java (rev 0)
+++ validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/composedconstraint2/ComposingConstraint2.java 2009-12-10 15:44:02 UTC (rev 18199)
@@ -0,0 +1,45 @@
+// $Id: ComposingConstraint2.java 17946 2009-11-06 18:23:48Z hardy.ferentschik $
+/*
+* 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.composedconstraint2;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+import javax.validation.Constraint;
+import javax.validation.Payload;
+
+import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+@Target({ METHOD, FIELD, ANNOTATION_TYPE })
+@Retention(RUNTIME)
+@Constraint(validatedBy = {
+ ComposingConstraint2ValidatorForArrayList.class,
+ ComposingConstraint2ValidatorForCalendar.class,
+ ComposingConstraint2ValidatorForCollection.class
+})
+@Documented
+public @interface ComposingConstraint2 {
+ String message() default "";
+
+ Class<?>[] groups() default { };
+
+ Class<? extends Payload>[] payload() default { };
+}
Added: validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/composedconstraint2/ComposingConstraint2ValidatorForArrayList.java
===================================================================
--- validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/composedconstraint2/ComposingConstraint2ValidatorForArrayList.java (rev 0)
+++ validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/composedconstraint2/ComposingConstraint2ValidatorForArrayList.java 2009-12-10 15:44:02 UTC (rev 18199)
@@ -0,0 +1,33 @@
+// $Id: ComposingConstraint2ValidatorForArrayList.java 17946 2009-11-06 18:23:48Z hardy.ferentschik $
+/*
+* 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.composedconstraint2;
+
+import java.util.ArrayList;
+import javax.validation.ConstraintValidator;
+import javax.validation.ConstraintValidatorContext;
+
+public class ComposingConstraint2ValidatorForArrayList
+ implements ConstraintValidator<ComposingConstraint2, ArrayList<?>> {
+
+ public void initialize(ComposingConstraint2 constraintAnnotation) {
+ }
+
+ public boolean isValid(ArrayList<?> object, ConstraintValidatorContext constraintContext) {
+ return true;
+ }
+}
Added: validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/composedconstraint2/ComposingConstraint2ValidatorForCalendar.java
===================================================================
--- validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/composedconstraint2/ComposingConstraint2ValidatorForCalendar.java (rev 0)
+++ validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/composedconstraint2/ComposingConstraint2ValidatorForCalendar.java 2009-12-10 15:44:02 UTC (rev 18199)
@@ -0,0 +1,38 @@
+// $Id: ComposingConstraint2ValidatorForCalendar.java 17946 2009-11-06 18:23:48Z hardy.ferentschik $
+/*
+* 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.composedconstraint2;
+
+import java.util.Calendar;
+
+import javax.validation.ConstraintValidator;
+import javax.validation.ConstraintValidatorContext;
+
+public class ComposingConstraint2ValidatorForCalendar implements
+ConstraintValidator<ComposingConstraint2, Calendar> {
+
+ public void initialize(ComposingConstraint2 constraintAnnotation) {
+
+ }
+
+ public boolean isValid(Calendar object,
+ ConstraintValidatorContext constraintContext) {
+
+ return true;
+ }
+
+}
Added: validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/composedconstraint2/ComposingConstraint2ValidatorForCollection.java
===================================================================
--- validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/composedconstraint2/ComposingConstraint2ValidatorForCollection.java (rev 0)
+++ validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/composedconstraint2/ComposingConstraint2ValidatorForCollection.java 2009-12-10 15:44:02 UTC (rev 18199)
@@ -0,0 +1,32 @@
+// $Id: ComposingConstraint2ValidatorForCollection.java 17946 2009-11-06 18:23:48Z hardy.ferentschik $
+/*
+* 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.composedconstraint2;
+
+import java.util.Collection;
+import javax.validation.ConstraintValidator;
+import javax.validation.ConstraintValidatorContext;
+
+public class ComposingConstraint2ValidatorForCollection
+ implements ConstraintValidator<ComposingConstraint2, Collection<?>> {
+ public void initialize(ComposingConstraint2 constraintAnnotation) {
+ }
+
+ public boolean isValid(Collection<?> object, ConstraintValidatorContext constraintContext) {
+ return true;
+ }
+}
Added: validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/composedconstraint2/FieldLevelValidationUsingComplexComposedConstraint.java
===================================================================
--- validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/composedconstraint2/FieldLevelValidationUsingComplexComposedConstraint.java (rev 0)
+++ validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/composedconstraint2/FieldLevelValidationUsingComplexComposedConstraint.java 2009-12-10 15:44:02 UTC (rev 18199)
@@ -0,0 +1,59 @@
+// $Id: FieldLevelValidationUsingComplexComposedConstraint.java 17946 2009-11-06 18:23:48Z hardy.ferentschik $
+/*
+* 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.composedconstraint2;
+
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Collection;
+import java.util.Date;
+import java.util.GregorianCalendar;
+import java.util.List;
+
+public class FieldLevelValidationUsingComplexComposedConstraint {
+
+ @ComposedConstraint
+ public String string;
+
+ @ComposedConstraint
+ public List<?> list;
+
+ /**
+ * Allowed
+ */
+ @ComposedConstraint
+ public GregorianCalendar gregorianCalendar;
+
+ @ComposedConstraint
+ public Collection<?> collection;
+
+ /**
+ * Allowed
+ */
+ @ComposedConstraint
+ public ArrayList<?> arrayList;
+
+ @ComposedConstraint
+ public Calendar calendar;
+
+ /**
+ * Not allowed.
+ */
+ @ComposedConstraint
+ public Date date;
+
+}
Modified: validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/customconstraints/CaseMode.java
===================================================================
--- validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/customconstraints/CaseMode.java 2009-12-10 15:27:00 UTC (rev 18198)
+++ validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/customconstraints/CaseMode.java 2009-12-10 15:44:02 UTC (rev 18199)
@@ -18,9 +18,6 @@
package org.hibernate.validator.ap.testmodel.customconstraints;
public enum CaseMode {
-
- UPPER,
-
+ UPPER,
LOWER;
-
}
Modified: validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/customconstraints/CheckCase.java
===================================================================
--- validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/customconstraints/CheckCase.java 2009-12-10 15:27:00 UTC (rev 18198)
+++ validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/customconstraints/CheckCase.java 2009-12-10 15:44:02 UTC (rev 18199)
@@ -17,27 +17,27 @@
*/
package org.hibernate.validator.ap.testmodel.customconstraints;
+import java.lang.annotation.Documented;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+import javax.validation.Constraint;
+import javax.validation.Payload;
+
import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
-import java.lang.annotation.Documented;
-import java.lang.annotation.Retention;
-import java.lang.annotation.Target;
-
-import javax.validation.Constraint;
-
-@Target( { METHOD, FIELD, ANNOTATION_TYPE })
+@Target({ METHOD, FIELD, ANNOTATION_TYPE })
@Retention(RUNTIME)
@Constraint(validatedBy = CheckCaseValidator.class)
@Documented
public @interface CheckCase {
+ String message() default "";
- String message() default "{validator.checkcase}";
+ Class<?>[] groups() default { };
- Class<?>[] groups() default {};
-
- CaseMode value();
+ Class<? extends Payload>[] payload() default { };
-}
+ CaseMode value();
+}
\ No newline at end of file
Modified: validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/customconstraints/CheckCaseValidator.java
===================================================================
--- validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/customconstraints/CheckCaseValidator.java 2009-12-10 15:27:00 UTC (rev 18198)
+++ validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/customconstraints/CheckCaseValidator.java 2009-12-10 15:44:02 UTC (rev 18199)
@@ -20,25 +20,23 @@
import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
-public class CheckCaseValidator implements
-ConstraintValidator<CheckCase, String> {
-
+public class CheckCaseValidator implements ConstraintValidator<CheckCase, String> {
private CaseMode caseMode;
public void initialize(CheckCase constraintAnnotation) {
this.caseMode = constraintAnnotation.value();
}
- public boolean isValid(String object,
- ConstraintValidatorContext constraintContext) {
-
- if (object == null)
+ public boolean isValid(String object, ConstraintValidatorContext constraintContext) {
+ if ( object == null ) {
return true;
+ }
- if (caseMode == CaseMode.UPPER)
- return object.equals(object.toUpperCase());
- else
- return object.equals(object.toLowerCase());
+ if ( caseMode == CaseMode.UPPER ) {
+ return object.equals( object.toUpperCase() );
+ }
+ else {
+ return object.equals( object.toLowerCase() );
+ }
}
-
}
Added: validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/invalidcomposedconstraint/ValidCustomerNumber.java
===================================================================
--- validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/invalidcomposedconstraint/ValidCustomerNumber.java (rev 0)
+++ validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testmodel/invalidcomposedconstraint/ValidCustomerNumber.java 2009-12-10 15:44:02 UTC (rev 18199)
@@ -0,0 +1,36 @@
+// $Id: ValidCustomerNumber.java 17946 2009-11-06 18:23:48Z hardy.ferentschik $
+/*
+* 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.invalidcomposedconstraint;
+
+import javax.validation.Payload;
+import javax.validation.constraints.NotNull;
+import javax.validation.constraints.Size;
+
+/**
+ * Constraint annotations are not allowed here, as ValidOrderNumber
+ * isn't a proper constraint type definition.
+ */
+@NotNull
+@Size(min = 10, max = 10)
+public @interface ValidCustomerNumber {
+ String message() default "";
+
+ Class<?>[] groups() default { };
+
+ Class<? extends Payload>[] payload() default { };
+}
Modified: validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testutil/CompilerTestHelper.java
===================================================================
--- validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testutil/CompilerTestHelper.java 2009-12-10 15:27:00 UTC (rev 18198)
+++ validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/testutil/CompilerTestHelper.java 2009-12-10 15:44:02 UTC (rev 18199)
@@ -17,33 +17,31 @@
*/
package org.hibernate.validator.ap.testutil;
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertTrue;
-
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
-
import javax.annotation.processing.Processor;
+import javax.tools.Diagnostic;
import javax.tools.DiagnosticCollector;
import javax.tools.JavaCompiler;
+import javax.tools.JavaCompiler.CompilationTask;
import javax.tools.JavaFileObject;
import javax.tools.StandardJavaFileManager;
-import javax.tools.JavaCompiler.CompilationTask;
import org.hibernate.validator.ap.util.DiagnosticExpection;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertTrue;
+
/**
* Infrastructure for unit tests based on the Java Compiler API.
- *
+ *
* @author Gunnar Morling
- *
*/
public class CompilerTestHelper {
+ private final JavaCompiler compiler;
- private final JavaCompiler compiler;
-
private final String sourceBaseDir;
/**
@@ -51,7 +49,7 @@
* Eclipse, but not on the command line.
*/
private final String pathToBeanValidationApiJar;
-
+
public CompilerTestHelper(JavaCompiler compiler, String sourceBaseDir, String pathToBeanValidationApiJar) {
this.compiler = compiler;
@@ -60,46 +58,53 @@
}
public File getSourceFile(Class<?> clazz) {
-
+
String sourceFileName =
- File.separator + clazz.getName().replace(".", File.separator) + ".java";
-
- return new File(sourceBaseDir + sourceFileName);
+ File.separator + clazz.getName().replace( ".", File.separator ) + ".java";
+
+ return new File( sourceBaseDir + sourceFileName );
}
-
+
public boolean compile(
- Processor annotationProcessor, DiagnosticCollector<JavaFileObject> diagnostics, File... sourceFiles) {
-
- StandardJavaFileManager fileManager =
- compiler.getStandardFileManager(null, null, null);
-
- Iterable<? extends JavaFileObject> compilationUnits = fileManager.getJavaFileObjects(sourceFiles);
+ Processor annotationProcessor, DiagnosticCollector<JavaFileObject> diagnostics, File... sourceFiles) {
+
+ StandardJavaFileManager fileManager =
+ compiler.getStandardFileManager( null, null, null );
+
+ Iterable<? extends JavaFileObject> compilationUnits = fileManager.getJavaFileObjects( sourceFiles );
+
List<String> optionList = new ArrayList<String>();
- optionList.addAll(Arrays.asList("-classpath", pathToBeanValidationApiJar));
+ optionList.addAll( Arrays.asList( "-classpath", pathToBeanValidationApiJar ) );
- CompilationTask task = compiler.getTask(null, fileManager, diagnostics, optionList, null, compilationUnits);
+ CompilationTask task = compiler.getTask( null, fileManager, diagnostics, optionList, null, compilationUnits );
+ task.setProcessors( Arrays.asList( annotationProcessor ) );
- task.setProcessors(Arrays.asList(annotationProcessor));
-
return task.call();
}
-
+
public static void assertDiagnostics(DiagnosticCollector<JavaFileObject> diagnostics, DiagnosticExpection... expections) {
-
- if(expections == null) {
- assertTrue(diagnostics.getDiagnostics().isEmpty());
+
+ List<Diagnostic<? extends JavaFileObject>> diagnosticsList = diagnostics.getDiagnostics();
+
+ if ( expections == null ) {
+ assertTrue( diagnosticsList.isEmpty() );
}
else {
-
- assertEquals(diagnostics.getDiagnostics().size(), expections.length);
-
+
+ if ( diagnosticsList.size() != expections.length ) {
+ System.out.println( diagnosticsList );
+ }
+
+ assertEquals( diagnosticsList.size(), expections.length, "Wrong number of diagnostic expections." );
+
int i = 0;
- for (DiagnosticExpection oneExpection : expections) {
-
- assertEquals(diagnostics.getDiagnostics().get(i).getKind(), oneExpection.getKind());
- assertEquals(diagnostics.getDiagnostics().get(i).getLineNumber(), oneExpection.getLineNumber());
+ for ( DiagnosticExpection oneExpection : expections ) {
+
+ assertEquals( diagnosticsList.get( i ).getKind(), oneExpection.getKind() );
+ assertEquals( diagnosticsList.get( i ).getLineNumber(), oneExpection.getLineNumber() );
+
+ i++;
}
}
}
-
-}
+}
\ No newline at end of file
Modified: validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/util/DiagnosticExpection.java
===================================================================
--- validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/util/DiagnosticExpection.java 2009-12-10 15:27:00 UTC (rev 18198)
+++ validator/trunk/hibernate-validator-annotation-processor/src/test/java/org/hibernate/validator/ap/util/DiagnosticExpection.java 2009-12-10 15:44:02 UTC (rev 18199)
@@ -22,17 +22,15 @@
/**
* Expectation value to be matched against a given {@link Diagnostic}.
- *
+ *
* @author Gunnar Morling
*/
public class DiagnosticExpection {
-
private final Kind kind;
-
+
private final long lineNumber;
-
+
public DiagnosticExpection(Kind kind, long lineNumber) {
-
this.kind = kind;
this.lineNumber = lineNumber;
}
@@ -44,4 +42,9 @@
public long getLineNumber() {
return lineNumber;
}
+
+ @Override
+ public String toString() {
+ return "DiagnosticExpection [kind=" + kind + ", lineNumber=" + lineNumber + "]";
+ }
}
\ No newline at end of file
15 years
Hibernate SVN: r18198 - core/trunk/entitymanager/src/main/java/org/hibernate/ejb.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2009-12-10 10:27:00 -0500 (Thu, 10 Dec 2009)
New Revision: 18198
Modified:
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/EntityManagerFactoryImpl.java
Log:
HHH-4665 PersistenceUnitUtil.getIdentifier()
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/EntityManagerFactoryImpl.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/EntityManagerFactoryImpl.java 2009-12-10 14:40:53 UTC (rev 18197)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/EntityManagerFactoryImpl.java 2009-12-10 15:27:00 UTC (rev 18198)
@@ -35,6 +35,10 @@
import javax.persistence.spi.LoadState;
import org.hibernate.SessionFactory;
+import org.hibernate.Hibernate;
+import org.hibernate.HibernateException;
+import org.hibernate.EntityMode;
+import org.hibernate.metadata.ClassMetadata;
import org.hibernate.engine.SessionFactoryImplementor;
import org.hibernate.mapping.PersistentClass;
import org.hibernate.cfg.Configuration;
@@ -110,18 +114,19 @@
return null; //To change body of implemented methods use File | Settings | File Templates.
}
- public Set<String> getSupportedProperties() {
- //FIXME
- return null; //To change body of implemented methods use File | Settings | File Templates.
- }
-
public Cache getCache() {
// TODO : cache the cache reference?
+ if ( ! isOpen() ) {
+ throw new IllegalStateException("EntityManagerFactory is closed");
+ }
return new JPACache( sessionFactory );
}
public PersistenceUnitUtil getPersistenceUnitUtil() {
- return null; //To change body of implemented methods use File | Settings | File Templates.
+ if ( ! isOpen() ) {
+ throw new IllegalStateException("EntityManagerFactory is closed");
+ }
+ return util;
}
public boolean isOpen() {
@@ -160,7 +165,7 @@
}
private static class HibernatePersistenceUnitUtil implements PersistenceUnitUtil, Serializable {
- private final EntityManagerFactoryImpl emf;
+ private final HibernateEntityManagerFactory emf;
private HibernatePersistenceUnitUtil(EntityManagerFactoryImpl emf) {
this.emf = emf;
@@ -177,8 +182,6 @@
else {
return PersistenceUtilHelper.isLoadedWithReference( entity, attributeName ) != LoadState.NOT_LOADED;
}
-
-
}
public boolean isLoaded(Object entity) {
@@ -186,7 +189,13 @@
}
public Object getIdentifier(Object entity) {
- throw new UnsupportedOperationException( "Not yet implemented" );
+ final Class entityClass = Hibernate.getClass( entity );
+ final ClassMetadata classMetadata = emf.getSessionFactory().getClassMetadata( entityClass );
+ if (classMetadata == null) {
+ throw new IllegalArgumentException( entityClass + " is not an entity" );
+ }
+ //TODO does that work for @IdClass?
+ return classMetadata.getIdentifier( entity, EntityMode.POJO );
}
}
}
15 years
Hibernate SVN: r18197 - validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/engine/messageinterpolation.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2009-12-10 09:40:53 -0500 (Thu, 10 Dec 2009)
New Revision: 18197
Modified:
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/engine/messageinterpolation/MessageInterpolationWithDefaultBundleTest.java
Log:
HV-241 Updated test
Modified: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/engine/messageinterpolation/MessageInterpolationWithDefaultBundleTest.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/engine/messageinterpolation/MessageInterpolationWithDefaultBundleTest.java 2009-12-10 14:27:30 UTC (rev 18196)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/engine/messageinterpolation/MessageInterpolationWithDefaultBundleTest.java 2009-12-10 14:40:53 UTC (rev 18197)
@@ -101,7 +101,7 @@
Set<ConstraintViolation<User>> constraintViolations = validator.validate( user );
assertNumberOfViolations( constraintViolations, 2 );
assertCorrectConstraintViolationMessages(
- constraintViolations, "Address email mal form\u00E9e", "doit \u00EAtre entre 18 et 21"
+ constraintViolations, "Addresse email mal form\u00E9e", "doit \u00EAtre entre 18 et 21"
);
}
}
15 years