Hibernate SVN: r19907 - core/branches/Branch_3_5/annotations/src/test/java/org/hibernate/test/annotations/inheritance/joined.
by hibernate-commits@lists.jboss.org
Author: sharathjreddy
Date: 2010-07-07 09:39:12 -0400 (Wed, 07 Jul 2010)
New Revision: 19907
Added:
core/branches/Branch_3_5/annotations/src/test/java/org/hibernate/test/annotations/inheritance/joined/Company.java
core/branches/Branch_3_5/annotations/src/test/java/org/hibernate/test/annotations/inheritance/joined/Customer.java
core/branches/Branch_3_5/annotations/src/test/java/org/hibernate/test/annotations/inheritance/joined/LegalEntity.java
Modified:
core/branches/Branch_3_5/annotations/src/test/java/org/hibernate/test/annotations/inheritance/joined/JoinedSubclassTest.java
Log:
HHH-4240 - SecondaryTables not recognized when using JOINED inheritance
Added: core/branches/Branch_3_5/annotations/src/test/java/org/hibernate/test/annotations/inheritance/joined/Company.java
===================================================================
--- core/branches/Branch_3_5/annotations/src/test/java/org/hibernate/test/annotations/inheritance/joined/Company.java (rev 0)
+++ core/branches/Branch_3_5/annotations/src/test/java/org/hibernate/test/annotations/inheritance/joined/Company.java 2010-07-07 13:39:12 UTC (rev 19907)
@@ -0,0 +1,71 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2009, Red Hat, Inc. and/or its affiliates 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, Inc.
+ *
+ * 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.test.annotations.inheritance.joined;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.SecondaryTable;
+import javax.persistence.Table;
+
+/**
+ * @author Sharath Reddy
+ *
+ */
+@Entity
+@Table(name = "Company")
+@SecondaryTable(name = "CompanyAddress")
+public class Company extends Customer {
+
+ private String companyName;
+ private String companyAddress;
+
+ @Column
+ public String getCompanyName() {
+ return companyName;
+ }
+
+ public void setCompanyName(String companyName) {
+ this.companyName = companyName;
+ }
+
+ @Column(table = "CompanyAddress")
+ public String getCompanyAddress() {
+ return companyAddress;
+ }
+
+ public void setCompanyAddress(String companyAddress) {
+ this.companyAddress = companyAddress;
+ }
+
+
+
+
+
+
+
+}
Added: core/branches/Branch_3_5/annotations/src/test/java/org/hibernate/test/annotations/inheritance/joined/Customer.java
===================================================================
--- core/branches/Branch_3_5/annotations/src/test/java/org/hibernate/test/annotations/inheritance/joined/Customer.java (rev 0)
+++ core/branches/Branch_3_5/annotations/src/test/java/org/hibernate/test/annotations/inheritance/joined/Customer.java 2010-07-07 13:39:12 UTC (rev 19907)
@@ -0,0 +1,67 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2009, Red Hat, Inc. and/or its affiliates 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, Inc.
+ *
+ * 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.test.annotations.inheritance.joined;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.Inheritance;
+import javax.persistence.SecondaryTable;
+import javax.persistence.Table;
+import javax.persistence.InheritanceType;
+
+/**
+ * @author Sharath Reddy
+ *
+ */
+@Entity
+@Inheritance(strategy = InheritanceType.JOINED)
+@Table(name = "Customer")
+@SecondaryTable(name = "CustomerDetails")
+public class Customer extends LegalEntity {
+
+ public String customerName;
+ public String customerCode;
+
+ @Column
+ public String getCustomerName() {
+ return customerName;
+ }
+
+ public void setCustomerName(String val) {
+ this.customerName = val;
+ }
+
+ @Column(table="CustomerDetails")
+ public String getCustomerCode() {
+ return customerCode;
+ }
+
+ public void setCustomerCode(String val) {
+ this.customerCode = val;
+ }
+}
\ No newline at end of file
Modified: core/branches/Branch_3_5/annotations/src/test/java/org/hibernate/test/annotations/inheritance/joined/JoinedSubclassTest.java
===================================================================
--- core/branches/Branch_3_5/annotations/src/test/java/org/hibernate/test/annotations/inheritance/joined/JoinedSubclassTest.java 2010-07-07 13:08:31 UTC (rev 19906)
+++ core/branches/Branch_3_5/annotations/src/test/java/org/hibernate/test/annotations/inheritance/joined/JoinedSubclassTest.java 2010-07-07 13:39:12 UTC (rev 19907)
@@ -166,6 +166,38 @@
tx.rollback();
s.close();
}
+
+ /**
+ * HHH-4240 - SecondaryTables not recognized when using JOINED inheritance
+ */
+ public void testSecondaryTables() {
+
+ Session s = openSession();
+ s.getTransaction().begin();
+
+ Company company = new Company();
+ company.setCustomerName("Mama");
+ company.setCustomerCode("123");
+ company.setCompanyName("Mama Mia Pizza");
+ company.setCompanyAddress("Rome");
+
+ s.persist( company );
+ s.getTransaction().commit();
+ s.clear();
+
+ s = openSession();
+ s.getTransaction().begin();
+ company = (Company) s.get( Company.class, company.getId());
+ assertEquals("Mama", company.getCustomerName());
+ assertEquals("123", company.getCustomerCode());
+ assertEquals("Mama Mia Pizza", company.getCompanyName());
+ assertEquals("Rome", company.getCompanyAddress());
+
+ s.delete( company );
+ s.getTransaction().commit();
+ s.close();
+ }
+
// public void testManyToOneAndJoin() throws Exception {
// Session session = openSession();
@@ -213,7 +245,9 @@
EventInformation.class,
Alarm.class,
Client.class,
- Account.class
+ Account.class,
+ Customer.class,
+ Company.class
//Asset.class,
//Parent.class,
//PropertyAsset.class,
Added: core/branches/Branch_3_5/annotations/src/test/java/org/hibernate/test/annotations/inheritance/joined/LegalEntity.java
===================================================================
--- core/branches/Branch_3_5/annotations/src/test/java/org/hibernate/test/annotations/inheritance/joined/LegalEntity.java (rev 0)
+++ core/branches/Branch_3_5/annotations/src/test/java/org/hibernate/test/annotations/inheritance/joined/LegalEntity.java 2010-07-07 13:39:12 UTC (rev 19907)
@@ -0,0 +1,56 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2009, Red Hat, Inc. and/or its affiliates 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, Inc.
+ *
+ * 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.test.annotations.inheritance.joined;
+
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.MappedSuperclass;
+
+/**
+ * @author Sharath Reddy
+ *
+ */
+@MappedSuperclass
+public class LegalEntity {
+
+ private Long id;
+
+ @Id
+ @GeneratedValue(strategy=GenerationType.AUTO)
+ public Long getId() {
+ return this.id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+
+
+}
14 years, 7 months
Hibernate SVN: r19906 - in core/branches/Branch_3_3_2_GA_CP: testsuite/src/test/perf/org/hibernate/test/perf and 1 other directories.
by hibernate-commits@lists.jboss.org
Author: stliu
Date: 2010-07-07 09:08:31 -0400 (Wed, 07 Jul 2010)
New Revision: 19906
Added:
core/branches/Branch_3_3_2_GA_CP/testsuite/src/test/perf/org/hibernate/test/perf/CascadingTest.hbm.xml
core/branches/Branch_3_3_2_GA_CP/testsuite/src/test/perf/org/hibernate/test/perf/CascadingTest.java
core/branches/Branch_3_3_2_GA_CP/testsuite/src/test/perf/org/hibernate/test/perf/object/
core/branches/Branch_3_3_2_GA_CP/testsuite/src/test/perf/org/hibernate/test/perf/object/A.java
core/branches/Branch_3_3_2_GA_CP/testsuite/src/test/perf/org/hibernate/test/perf/object/B.java
core/branches/Branch_3_3_2_GA_CP/testsuite/src/test/perf/org/hibernate/test/perf/object/C.java
Modified:
core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/engine/Cascade.java
core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/engine/PersistenceContext.java
core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/engine/StatefulPersistenceContext.java
Log:
JBPAPP-4562 HHH-3860 Cascading performance problems when session contains many entities
Modified: core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/engine/Cascade.java
===================================================================
--- core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/engine/Cascade.java 2010-07-06 19:35:13 UTC (rev 19905)
+++ core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/engine/Cascade.java 2010-07-07 13:08:31 UTC (rev 19906)
@@ -152,6 +152,7 @@
if ( style.doCascade( action ) ) {
cascadeProperty(
+ parent,
persister.getPropertyValue( parent, i, entityMode ),
types[i],
style,
@@ -180,6 +181,7 @@
* Cascade an action to the child or children
*/
private void cascadeProperty(
+ final Object parent,
final Object child,
final Type type,
final CascadeStyle style,
@@ -191,6 +193,7 @@
AssociationType associationType = (AssociationType) type;
if ( cascadeAssociationNow( associationType ) ) {
cascadeAssociation(
+ parent,
child,
type,
style,
@@ -200,7 +203,7 @@
}
}
else if ( type.isComponentType() ) {
- cascadeComponent( child, (AbstractComponentType) type, anything );
+ cascadeComponent( parent, child, (AbstractComponentType) type, anything );
}
}
}
@@ -211,6 +214,7 @@
}
private void cascadeComponent(
+ final Object parent,
final Object child,
final AbstractComponentType componentType,
final Object anything) {
@@ -220,6 +224,7 @@
CascadeStyle componentPropertyStyle = componentType.getCascadeStyle(i);
if ( componentPropertyStyle.doCascade(action) ) {
cascadeProperty(
+ parent,
children[i],
types[i],
componentPropertyStyle,
@@ -231,16 +236,17 @@
}
private void cascadeAssociation(
+ final Object parent,
final Object child,
final Type type,
final CascadeStyle style,
final Object anything,
final boolean isCascadeDeleteEnabled) {
if ( type.isEntityType() || type.isAnyType() ) {
- cascadeToOne( child, type, style, anything, isCascadeDeleteEnabled );
+ cascadeToOne( parent, child, type, style, anything, isCascadeDeleteEnabled );
}
else if ( type.isCollectionType() ) {
- cascadeCollection( child, style, anything, (CollectionType) type );
+ cascadeCollection( parent, child, style, anything, (CollectionType) type );
}
}
@@ -248,6 +254,7 @@
* Cascade an action to a collection
*/
private void cascadeCollection(
+ final Object parent,
final Object child,
final CascadeStyle style,
final Object anything,
@@ -264,6 +271,7 @@
//cascade to current collection elements
if ( elemType.isEntityType() || elemType.isAnyType() || elemType.isComponentType() ) {
cascadeCollectionElements(
+ parent,
child,
type,
style,
@@ -280,6 +288,7 @@
* Cascade an action to a to-one association or any type
*/
private void cascadeToOne(
+ final Object parent,
final Object child,
final Type type,
final CascadeStyle style,
@@ -289,7 +298,9 @@
? ( (EntityType) type ).getAssociatedEntityName()
: null;
if ( style.reallyDoCascade(action) ) { //not really necessary, but good for consistency...
+ eventSource.getPersistenceContext().addChildParent(child, parent);
action.cascade(eventSource, child, entityName, anything, isCascadeDeleteEnabled);
+ eventSource.getPersistenceContext().removeChildParent(child);
}
}
@@ -297,6 +308,7 @@
* Cascade to the collection elements
*/
private void cascadeCollectionElements(
+ final Object parent,
final Object child,
final CollectionType collectionType,
final CascadeStyle style,
@@ -318,6 +330,7 @@
Iterator iter = action.getCascadableChildrenIterator(eventSource, collectionType, child);
while ( iter.hasNext() ) {
cascadeProperty(
+ parent,
iter.next(),
elemType,
style,
Modified: core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/engine/PersistenceContext.java
===================================================================
--- core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/engine/PersistenceContext.java 2010-07-06 19:35:13 UTC (rev 19905)
+++ core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/engine/PersistenceContext.java 2010-07-07 13:08:31 UTC (rev 19906)
@@ -486,4 +486,17 @@
public void setReadOnly(Object entity, boolean readOnly);
void replaceDelayedEntityIdentityInsertKeys(EntityKey oldKey, Serializable generatedId);
+
+ /**
+ * Put child/parent relation to cache for cascading op
+ * @param parent
+ * @param child
+ */
+ public void addChildParent(Object parent, Object child);
+
+ /**
+ * Remove child/parent relation from cache
+ * @param child
+ */
+ public void removeChildParent(Object child);
}
Modified: core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/engine/StatefulPersistenceContext.java
===================================================================
--- core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/engine/StatefulPersistenceContext.java 2010-07-06 19:35:13 UTC (rev 19905)
+++ core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/engine/StatefulPersistenceContext.java 2010-07-07 13:08:31 UTC (rev 19906)
@@ -118,7 +118,9 @@
// A container for collections we load up when the owning entity is not
// yet loaded ... for now, this is purely transient!
private Map unownedCollections;
-
+ // Parent entities cache by their child for cascading
+ // May be empty or not contains all relation
+ private Map parentsByChild;
private int cascading = 0;
private int loadCounter = 0;
private boolean flushing = false;
@@ -147,7 +149,7 @@
collectionEntries = IdentityMap.instantiateSequenced( INIT_COLL_SIZE );
collectionsByKey = new HashMap( INIT_COLL_SIZE );
arrayHolders = IdentityMap.instantiate( INIT_COLL_SIZE );
-
+ parentsByChild = IdentityMap.instantiateSequenced( INIT_COLL_SIZE );
nullifiableEntityKeys = new HashSet();
initTransientState();
@@ -210,6 +212,7 @@
entitiesByKey.clear();
entitiesByUniqueKey.clear();
entityEntries.clear();
+ parentsByChild.clear();
entitySnapshotsByKey.clear();
collectionsByKey.clear();
collectionEntries.clear();
@@ -356,6 +359,8 @@
while ( iter.hasNext() ) {
if ( iter.next()==entity ) iter.remove();
}
+ // Clear all parent cache
+ parentsByChild.clear();
entitySnapshotsByKey.remove(key);
nullifiableEntityKeys.remove(key);
getBatchFetchQueue().removeBatchLoadableEntityKey(key);
@@ -1093,9 +1098,18 @@
final String collectionRole = entityName + '.' + propertyName;
final EntityPersister persister = session.getFactory().getEntityPersister( entityName );
final CollectionPersister collectionPersister = session.getFactory().getCollectionPersister( collectionRole );
-
+ // try cache lookup first
+ Object parent = parentsByChild.get(childEntity);
+ if (parent != null) {
+ if (isFoundInParent(propertyName, childEntity, persister,
+ collectionPersister, parent)) {
+ return getEntry(parent).getId();
+ } else {
+ parentsByChild.remove(childEntity); // remove wrong entry
+ }
+ }
// iterate all the entities currently associated with the persistence context.
- Iterator entities = entityEntries.entrySet().iterator();
+ Iterator entities = IdentityMap.entries(entityEntries).iterator();
while ( entities.hasNext() ) {
final Map.Entry me = ( Map.Entry ) entities.next();
final EntityEntry entityEntry = ( EntityEntry ) me.getValue();
@@ -1197,7 +1211,27 @@
.getEntityPersister(entity);
CollectionPersister cp = session.getFactory()
.getCollectionPersister(entity + '.' + property);
- Iterator entities = entityEntries.entrySet().iterator();
+ // try cache lookup first
+ Object parent = parentsByChild.get(childEntity);
+ if (parent != null) {
+ Object index = getIndexInParent(property, childEntity, persister,
+ cp, parent);
+
+ if (index == null && mergeMap != null) {
+ Object unmergedInstance = mergeMap.get(parent);
+ Object unmergedChild = mergeMap.get(childEntity);
+ if (unmergedInstance != null && unmergedChild != null) {
+ index = getIndexInParent(property, unmergedChild,
+ persister, cp, unmergedInstance);
+ }
+ }
+ if (index != null) {
+ return index;
+ }
+ parentsByChild.remove(childEntity); // remove wrong entry
+ }
+
+ Iterator entities = IdentityMap.entries(entityEntries).iterator();
while ( entities.hasNext() ) {
Map.Entry me = (Map.Entry) entities.next();
EntityEntry ee = (EntityEntry) me.getValue();
@@ -1267,6 +1301,8 @@
public void replaceDelayedEntityIdentityInsertKeys(EntityKey oldKey, Serializable generatedId) {
Object entity = entitiesByKey.remove( oldKey );
EntityEntry oldEntry = ( EntityEntry ) entityEntries.remove( entity );
+ parentsByChild.clear();
+
EntityKey newKey = new EntityKey( generatedId, oldEntry.getPersister(), getSession().getEntityMode() );
addEntity( newKey, entity );
@@ -1477,4 +1513,19 @@
return rtn;
}
+
+ /**
+ * @see org.hibernate.engine.PersistenceContext#addChildParent(java.lang.Object,
+ * java.lang.Object)
+ */
+ public void addChildParent(Object child, Object parent) {
+ parentsByChild.put(child, parent);
+ }
+
+ /**
+ * @see org.hibernate.engine.PersistenceContext#removeChildParent(java.lang.Object)
+ */
+ public void removeChildParent(Object child) {
+ parentsByChild.remove(child);
+ }
}
Added: core/branches/Branch_3_3_2_GA_CP/testsuite/src/test/perf/org/hibernate/test/perf/CascadingTest.hbm.xml
===================================================================
--- core/branches/Branch_3_3_2_GA_CP/testsuite/src/test/perf/org/hibernate/test/perf/CascadingTest.hbm.xml (rev 0)
+++ core/branches/Branch_3_3_2_GA_CP/testsuite/src/test/perf/org/hibernate/test/perf/CascadingTest.hbm.xml 2010-07-07 13:08:31 UTC (rev 19906)
@@ -0,0 +1,40 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE hibernate-mapping PUBLIC
+ "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
+ "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
+<hibernate-mapping package="org.hibernate.test.perf.object">
+ <class name="A" table="A">
+ <id name="id" type="long" access="field">
+ <generator class="hilo">
+ <param name="max_lo">10000</param>
+ </generator>
+ </id>
+ <property name="a" type="integer" access="field"/>
+ <map name="map" access="field" cascade="all">
+ <key column="a" not-null="true"/>
+ <map-key column="keycol" type="integer"/>
+ <one-to-many class="B"/>
+ </map>
+ </class>
+ <class name="B" table="B">
+ <id name="id" type="long" access="field">
+ <generator class="hilo">
+ <param name="max_lo">10000</param>
+ </generator>
+ </id>
+ <property name="b" type="integer" access="field"/>
+ <list name="list" access="field" cascade="all">
+ <key column="keycol" not-null="true"/>
+ <list-index column="pos"/>
+ <one-to-many class="C"/>
+ </list>
+ </class>
+ <class name="C" table="C">
+ <id name="id" type="long" access="field">
+ <generator class="hilo">
+ <param name="max_lo">10000</param>
+ </generator>
+ </id>
+ <property name="c" type="integer" access="field"/>
+ </class>
+</hibernate-mapping>
\ No newline at end of file
Added: core/branches/Branch_3_3_2_GA_CP/testsuite/src/test/perf/org/hibernate/test/perf/CascadingTest.java
===================================================================
--- core/branches/Branch_3_3_2_GA_CP/testsuite/src/test/perf/org/hibernate/test/perf/CascadingTest.java (rev 0)
+++ core/branches/Branch_3_3_2_GA_CP/testsuite/src/test/perf/org/hibernate/test/perf/CascadingTest.java 2010-07-07 13:08:31 UTC (rev 19906)
@@ -0,0 +1,65 @@
+package org.hibernate.test.perf;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+
+import org.hibernate.Session;
+import org.hibernate.Transaction;
+import org.hibernate.junit.functional.FunctionalTestCase;
+import org.hibernate.test.perf.object.A;
+import org.hibernate.test.perf.object.B;
+import org.hibernate.test.perf.object.C;
+
+public class CascadingTest extends FunctionalTestCase {
+
+ public CascadingTest(String string) {
+ super(string);
+ }
+
+ public String[] getMappings() {
+ return new String[] { "perf/CascadingTest.hbm.xml" };
+ }
+
+ /**
+ * Make 5510 objects on database
+ */
+ public void testSaveSession() {
+ Session session = openSession();
+ Transaction tx = session.beginTransaction();
+ long timeTotal = System.currentTimeMillis();
+ for (int x = 0; x < 10; x++) {
+ makeObjects(session);
+ }
+ session.flush();
+ tx.commit();
+ session.close();
+ System.out.println("Total took " + ((System.currentTimeMillis() - timeTotal)) + " ms");
+ }
+
+
+ /**
+ * Make 551 new objects
+ *
+ * @param session
+ */
+ private void makeObjects(Session session) {
+ A a = new A();
+ a.setA(-1);
+ a.setMap(new HashMap());
+ for (int i = 0; i < 50; i++) {
+ B b = new B();
+ b.setB(i);
+ b.setList(new ArrayList());
+ a.getMap().put(new Integer(i), b);
+ for (int j = 0; j < 10; j++) {
+ C c = new C();
+ c.setC(j * 1000000);
+ b.getList().add(c);
+ }
+ }
+ long time = System.currentTimeMillis();
+ session.save(a);
+ System.out.println("Save took " + ((System.currentTimeMillis() - time)) + " ms");
+ time = System.currentTimeMillis();
+ }
+}
Added: core/branches/Branch_3_3_2_GA_CP/testsuite/src/test/perf/org/hibernate/test/perf/object/A.java
===================================================================
--- core/branches/Branch_3_3_2_GA_CP/testsuite/src/test/perf/org/hibernate/test/perf/object/A.java (rev 0)
+++ core/branches/Branch_3_3_2_GA_CP/testsuite/src/test/perf/org/hibernate/test/perf/object/A.java 2010-07-07 13:08:31 UTC (rev 19906)
@@ -0,0 +1,32 @@
+package org.hibernate.test.perf.object;
+
+import java.util.Map;
+
+public class A {
+ protected long id;
+
+ protected int a;
+
+ protected Map map;
+
+ public int getA() {
+ return a;
+ }
+
+ public void setA(int a) {
+ this.a = a;
+ }
+
+ public Map getMap() {
+ return map;
+ }
+
+ public void setMap(Map map) {
+ this.map = map;
+ }
+
+ public long getId() {
+ return id;
+ }
+
+}
Added: core/branches/Branch_3_3_2_GA_CP/testsuite/src/test/perf/org/hibernate/test/perf/object/B.java
===================================================================
--- core/branches/Branch_3_3_2_GA_CP/testsuite/src/test/perf/org/hibernate/test/perf/object/B.java (rev 0)
+++ core/branches/Branch_3_3_2_GA_CP/testsuite/src/test/perf/org/hibernate/test/perf/object/B.java 2010-07-07 13:08:31 UTC (rev 19906)
@@ -0,0 +1,32 @@
+package org.hibernate.test.perf.object;
+
+import java.util.List;
+
+public class B {
+ protected long id;
+
+ protected int b;
+
+ protected List list;
+
+ public int getB() {
+ return b;
+ }
+
+ public void setB(int b) {
+ this.b = b;
+ }
+
+ public List getList() {
+ return list;
+ }
+
+ public void setList(List list) {
+ this.list = list;
+ }
+
+ public long getId() {
+ return id;
+ }
+
+}
Added: core/branches/Branch_3_3_2_GA_CP/testsuite/src/test/perf/org/hibernate/test/perf/object/C.java
===================================================================
--- core/branches/Branch_3_3_2_GA_CP/testsuite/src/test/perf/org/hibernate/test/perf/object/C.java (rev 0)
+++ core/branches/Branch_3_3_2_GA_CP/testsuite/src/test/perf/org/hibernate/test/perf/object/C.java 2010-07-07 13:08:31 UTC (rev 19906)
@@ -0,0 +1,19 @@
+package org.hibernate.test.perf.object;
+
+public class C {
+ protected long id;
+
+ protected int c;
+
+ public int getC() {
+ return c;
+ }
+
+ public void setC(int c) {
+ this.c = c;
+ }
+
+ public long getId() {
+ return id;
+ }
+}
14 years, 7 months
Hibernate SVN: r19905 - validator/trunk/hibernate-validator/src/main/docbook/zh-CN/modules.
by hibernate-commits@lists.jboss.org
Author: stliu
Date: 2010-07-06 15:35:13 -0400 (Tue, 06 Jul 2010)
New Revision: 19905
Modified:
validator/trunk/hibernate-validator/src/main/docbook/zh-CN/modules/gettingstarted.po
validator/trunk/hibernate-validator/src/main/docbook/zh-CN/modules/preface.po
Log:
HV-351 first chapter
Modified: validator/trunk/hibernate-validator/src/main/docbook/zh-CN/modules/gettingstarted.po
===================================================================
--- validator/trunk/hibernate-validator/src/main/docbook/zh-CN/modules/gettingstarted.po 2010-07-06 15:18:26 UTC (rev 19904)
+++ validator/trunk/hibernate-validator/src/main/docbook/zh-CN/modules/gettingstarted.po 2010-07-06 19:35:13 UTC (rev 19905)
@@ -6,8 +6,8 @@
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: http://bugs.kde.org\n"
"POT-Creation-Date: 2010-07-06 14:46+0000\n"
-"PO-Revision-Date: 2010-07-06 14:46+0000\n"
-"Last-Translator: Automatically generated\n"
+"PO-Revision-Date: 2010-07-07 03:33+0830\n"
+"Last-Translator: Strong Liu <stliu(a)hibernate.org>\n"
"Language-Team: none\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
@@ -17,43 +17,37 @@
#: gettingstarted.xml:25
#, no-c-format
msgid "Getting started"
-msgstr ""
+msgstr "开始入门"
#. Tag: para
#: gettingstarted.xml:27
#, no-c-format
-msgid ""
-"This chapter will show you how to get started with Hibernate Validator, the "
-"reference implementation (RI) of Bean Validation. For the following "
-"quickstart you need:"
-msgstr ""
+msgid "This chapter will show you how to get started with Hibernate Validator, the reference implementation (RI) of Bean Validation. For the following quickstart you need:"
+msgstr "本章将会告诉你如何使用Hibernate Validator, 在开始之前,你需要准备好下面的环境:"
#. Tag: para
#: gettingstarted.xml:33
#, no-c-format
msgid "A JDK >= 5"
-msgstr ""
+msgstr "A JDK >= 5"
#. Tag: ulink
#: gettingstarted.xml:37
#, no-c-format
msgid "Apache Maven"
-msgstr ""
+msgstr "Apache Maven"
#. Tag: para
#: gettingstarted.xml:41
#, no-c-format
msgid "An Internet connection (Maven has to download all required libraries)"
-msgstr ""
+msgstr "网络连接 ( Maven需要通过互联网下载所需的类库)"
#. Tag: para
#: gettingstarted.xml:46
#, no-c-format
msgid ""
-"A properly configured remote repository. Add the following to your "
-"<filename>settings.xml</filename>: <example> <title>Configuring the JBoss "
-"Maven repository in <filename>settings.xml</filename></title> "
-"<programlisting><repositories>\n"
+"A properly configured remote repository. Add the following to your <filename>settings.xml</filename>: <example> <title>Configuring the JBoss Maven repository in <filename>settings.xml</filename></title> <programlisting><repositories>\n"
" <repository>\n"
" <id>jboss</id>\n"
" <url>http://repository.jboss.com/maven2</url>\n"
@@ -64,21 +58,26 @@
" <enabled>false</enabled>\n"
" </snapshots>\n"
" </repository>\n"
-"</repositories></programlisting> </example>More information about "
-"<filename>settings.xml</filename> can be found in the <ulink url=\"http://"
-"maven.apache.org/ref/2.0.8/maven-settings/settings.html\">Maven Local "
-"Settings Model</ulink>."
+"</repositories></programlisting> </example>More information about <filename>settings.xml</filename> can be found in the <ulink url=\"http://maven.apache.org/ref/2.0.8/maven-settings/settings.html\">Maven Local Settings Model</ulink>."
msgstr ""
+"配置远端maven仓库. 添加下面的内容到你的<filename>settings.xml</filename>中:<example> <title>Configuring the JBoss Maven repository in <filename>settings.xml</filename></title> <programlisting><repositories>\n"
+" <repository>\n"
+" <id>jboss</id>\n"
+" <url>http://repository.jboss.com/maven2</url>\n"
+" <releases>\n"
+" <enabled>true</enabled>\n"
+" </releases>\n"
+" <snapshots>\n"
+" <enabled>false</enabled>\n"
+" </snapshots>\n"
+" </repository>\n"
+"</repositories></programlisting> </example>更多关于<filename>settings.xml</filename> 的信息请参考<ulink url=\"http://maven.apache.org/ref/2.0.8/maven-settings/settings.html\">Maven Local Settings Model</ulink>."
#. Tag: para
#: gettingstarted.xml:60
#, no-c-format
msgid ""
-"Hibernate Validator uses JAXB for XML parsing. JAXB is part of the Java "
-"Class Library since Java 6 which means that if you run Hibernate Validator "
-"with Java 5 you will have to add additional JAXB dependencies. Using maven "
-"you have to add the following dependencies:<programlisting><"
-"dependency>\n"
+"Hibernate Validator uses JAXB for XML parsing. JAXB is part of the Java Class Library since Java 6 which means that if you run Hibernate Validator with Java 5 you will have to add additional JAXB dependencies. Using maven you have to add the following dependencies:<programlisting><dependency>\n"
" <groupId>javax.xml.bind</groupId>\n"
" <artifactId>jaxb-api</artifactId>\n"
" <version>2.2</version>\n"
@@ -88,89 +87,89 @@
" <artifactId>jaxb-impl</artifactId>\n"
" <version>2.1.12</version>\n"
"</dependency>\n"
-"</programlisting> if you are using the SourceForge package you find the "
-"necessary libraries in the <filename>lib/jdk5</filename> directory. In case "
-"you are not using the XML configuration you can also disable it explicitly "
-"by calling <methodname>Configuration.ignoreXmlConfiguration()</methodname> "
-"during <classname>ValidationFactory</classname> creation. In this case the "
-"JAXB dependencies are not needed."
+"</programlisting> if you are using the SourceForge package you find the necessary libraries in the <filename>lib/jdk5</filename> directory. In case you are not using the XML configuration you can also disable it explicitly by calling <methodname>Configuration.ignoreXmlConfiguration()</methodname> during <classname>ValidationFactory</classname> creation. In this case the JAXB dependencies are not needed."
msgstr ""
+"Hibernate Validator 使用JAXB 来解析XML. JAXB 已经被集成进Java 6了, 所以,如果你要在Java 5上使用Hibernate Validator的话, 那么,还需要添加额外的JAXB的依赖. 如果你使用Maven的话,你可以把下面的内容添加到pom当中:<programlisting><dependency>\n"
+" <groupId>javax.xml.bind</groupId>\n"
+" <artifactId>jaxb-api</artifactId>\n"
+" <version>2.2</version>\n"
+"</dependency>\n"
+"<dependency>\n"
+" <groupId>com.sun.xml.bind</groupId>\n"
+" <artifactId>jaxb-impl</artifactId>\n"
+" <version>2.1.12</version>\n"
+"</dependency>\n"
+"</programlisting>"
#. Tag: title
#: gettingstarted.xml:73
#, no-c-format
msgid "Setting up a new Maven project"
-msgstr ""
+msgstr "第一个Maven项目"
#. Tag: para
#: gettingstarted.xml:75
#, no-c-format
-msgid ""
-"Start by creating new Maven project using the Maven archetype plugin as "
-"follows:"
-msgstr ""
+msgid "Start by creating new Maven project using the Maven archetype plugin as follows:"
+msgstr "使用Maven archetype插件来创建一个新的Maven 项目"
#. Tag: title
#: gettingstarted.xml:79
#, no-c-format
-msgid ""
-"Using Maven's archetype plugin to create a sample project using Hibernate "
-"Validator"
-msgstr ""
+msgid "Using Maven's archetype plugin to create a sample project using Hibernate Validator"
+msgstr "使用Maven archetype 插件来创建一个简单的基于Hibernate Validator的项目"
#. Tag: programlisting
#: gettingstarted.xml:82
#, no-c-format
msgid ""
"mvn archetype:create -DarchetypeGroupId=org.hibernate \\\n"
-" -DarchetypeArtifactId=hibernate-validator-quickstart-"
-"archetype \\\n"
+" -DarchetypeArtifactId=hibernate-validator-quickstart-archetype \\\n"
" -DarchetypeVersion=&version; \\\n"
" -DgroupId=com.mycompany \n"
" -DartifactId=hv-quickstart"
msgstr ""
+"mvn archetype:create -DarchetypeGroupId=org.hibernate \\\n"
+" -DarchetypeArtifactId=hibernate-validator-quickstart-archetype \\\n"
+" -DarchetypeVersion=&version; \\\n"
+" -DgroupId=com.mycompany \n"
+" -DartifactId=hv-quickstart"
#. Tag: para
#: gettingstarted.xml:85
#, no-c-format
-msgid ""
-"Maven will create your project in the directory hv-quickstart. Change into "
-"this directory and run:"
-msgstr ""
+msgid "Maven will create your project in the directory hv-quickstart. Change into this directory and run:"
+msgstr "Maven 将会把你的项目创建在hv-quickstart目录中. 进入这个目录并且执行:"
#. Tag: programlisting
#: gettingstarted.xml:88
#, no-c-format
msgid "mvn test"
-msgstr ""
+msgstr "mvn test"
#. Tag: para
#: gettingstarted.xml:88
#, no-c-format
-msgid ""
-"Maven will compile the example code and run the implemented unit tests. "
-"Let's have a look at the actual code."
-msgstr ""
+msgid "Maven will compile the example code and run the implemented unit tests. Let's have a look at the actual code."
+msgstr "这样, Maven会编译示例代码并且运行单元测试, 接下来,让我们看看生成的代码."
#. Tag: title
#: gettingstarted.xml:94
#, no-c-format
msgid "Applying constraints"
-msgstr ""
+msgstr "添加约束"
#. Tag: para
#: gettingstarted.xml:96
#, no-c-format
-msgid ""
-"Open the project in the IDE of your choice and have a look at the class "
-"<classname>Car</classname>:"
-msgstr ""
+msgid "Open the project in the IDE of your choice and have a look at the class <classname>Car</classname>:"
+msgstr "在你喜欢的IDE中打开这个项目中的<classname>Car</classname>类:"
#. Tag: title
#: gettingstarted.xml:100
#, no-c-format
msgid "Class Car annotated with constraints"
-msgstr ""
+msgstr "带约束性标注(annotated with constraints)的Car 类"
#. Tag: programlisting
#: gettingstarted.xml:102
@@ -203,57 +202,74 @@
" //getters and setters ...\n"
"}"
msgstr ""
+"package com.mycompany;\n"
+"\n"
+"import javax.validation.constraints.Min;\n"
+"import javax.validation.constraints.NotNull;\n"
+"import javax.validation.constraints.Size;\n"
+"\n"
+"public class Car {\n"
+"\n"
+" @NotNull\n"
+" private String manufacturer;\n"
+"\n"
+" @NotNull\n"
+" @Size(min = 2, max = 14)\n"
+" private String licensePlate;\n"
+"\n"
+" @Min(2)\n"
+" private int seatCount;\n"
+" \n"
+" public Car(String manufacturer, String licencePlate, int seatCount) {\n"
+" this.manufacturer = manufacturer;\n"
+" this.licensePlate = licencePlate;\n"
+" this.seatCount = seatCount;\n"
+" }\n"
+"\n"
+" //getters and setters ...\n"
+"}"
#. Tag: para
#: gettingstarted.xml:105
#, no-c-format
-msgid ""
-"<classname>@NotNull</classname>, <classname>@Size</classname> and "
-"<classname>@Min</classname> are so-called constraint annotations, that we "
-"use to declare constraints, which shall be applied to the fields of a "
-"<classname>Car</classname> instance:"
-msgstr ""
+msgid "<classname>@NotNull</classname>, <classname>@Size</classname> and <classname>@Min</classname> are so-called constraint annotations, that we use to declare constraints, which shall be applied to the fields of a <classname>Car</classname> instance:"
+msgstr "<classname>@NotNull</classname>, <classname>@Size</classname> and <classname>@Min</classname>就是上面所属的约束性标注( constraint annotations), 我们就是使用它们来声明约束, 例如在<classname>Car</classname>的字段中我们可以看到:"
#. Tag: para
#: gettingstarted.xml:112
#, no-c-format
msgid "<property>manufacturer</property> shall never be null"
-msgstr ""
+msgstr "<property>manufacturer</property>永远不能为null"
#. Tag: para
#: gettingstarted.xml:116
#, no-c-format
-msgid ""
-"<property>licensePlate</property> shall never be null and must be between 2 "
-"and 14 characters long"
-msgstr ""
+msgid "<property>licensePlate</property> shall never be null and must be between 2 and 14 characters long"
+msgstr "<property>licensePlate</property>永远不能为null,并且它的值字符串的长度要在2到14之间"
#. Tag: para
#: gettingstarted.xml:121
#, no-c-format
msgid "<property>seatCount</property> shall be at least 2."
-msgstr ""
+msgstr "<property>seatCount</property>的值要不能小于2"
#. Tag: title
#: gettingstarted.xml:127
#, no-c-format
msgid "Validating constraints"
-msgstr ""
+msgstr "校验约束"
#. Tag: para
#: gettingstarted.xml:129
#, no-c-format
-msgid ""
-"To perform a validation of these constraints, we use a <classname>Validator</"
-"classname> instance. Let's have a look at the <classname>CarTest</classname> "
-"class:"
-msgstr ""
+msgid "To perform a validation of these constraints, we use a <classname>Validator</classname> instance. Let's have a look at the <classname>CarTest</classname> class:"
+msgstr "我们需要使用<classname>Validator</classname>来对上面的那些约束进行校验. 让我们来看看<classname>CarTest</classname>这个类:"
#. Tag: title
#: gettingstarted.xml:134
#, no-c-format
msgid "Class CarTest showing validation examples"
-msgstr ""
+msgstr "在CarTest中使用校验"
#. Tag: programlisting
#: gettingstarted.xml:136
@@ -279,8 +295,7 @@
"\n"
" @BeforeClass\n"
" public static void setUp() {\n"
-" ValidatorFactory factory = Validation.buildDefaultValidatorFactory"
-"();\n"
+" ValidatorFactory factory = Validation.buildDefaultValidatorFactory();\n"
" validator = factory.getValidator();\n"
" }\n"
"\n"
@@ -292,8 +307,7 @@
" validator.validate(car);\n"
"\n"
" assertEquals(1, constraintViolations.size());\n"
-" assertEquals(\"may not be null\", constraintViolations.iterator()."
-"next().getMessage());\n"
+" assertEquals(\"may not be null\", constraintViolations.iterator().next().getMessage());\n"
" }\n"
"\n"
" @Test\n"
@@ -304,8 +318,7 @@
" validator.validate(car);\n"
"\n"
" assertEquals(1, constraintViolations.size());\n"
-" assertEquals(\"size must be between 2 and 14\", constraintViolations."
-"iterator().next().getMessage());\n"
+" assertEquals(\"size must be between 2 and 14\", constraintViolations.iterator().next().getMessage());\n"
" }\n"
" \n"
" @Test\n"
@@ -316,8 +329,7 @@
" validator.validate(car);\n"
"\n"
" assertEquals(1, constraintViolations.size());\n"
-" assertEquals(\"must be greater than or equal to 2\", "
-"constraintViolations.iterator().next().getMessage());\n"
+" assertEquals(\"must be greater than or equal to 2\", constraintViolations.iterator().next().getMessage());\n"
" }\n"
"\n"
" @Test\n"
@@ -331,85 +343,125 @@
" }\n"
"}"
msgstr ""
+"package com.mycompany;\n"
+"\n"
+"import static org.junit.Assert.*;\n"
+"\n"
+"import java.util.Set;\n"
+"\n"
+"import javax.validation.ConstraintViolation;\n"
+"import javax.validation.Validation;\n"
+"import javax.validation.Validator;\n"
+"import javax.validation.ValidatorFactory;\n"
+"\n"
+"import org.junit.BeforeClass;\n"
+"import org.junit.Test;\n"
+"\n"
+"public class CarTest {\n"
+"\n"
+" private static Validator validator;\n"
+"\n"
+" @BeforeClass\n"
+" public static void setUp() {\n"
+" ValidatorFactory factory = Validation.buildDefaultValidatorFactory();\n"
+" validator = factory.getValidator();\n"
+" }\n"
+"\n"
+" @Test\n"
+" public void manufacturerIsNull() {\n"
+" Car car = new Car(null, \"DD-AB-123\", 4);\n"
+"\n"
+" Set<ConstraintViolation<Car>> constraintViolations =\n"
+" validator.validate(car);\n"
+"\n"
+" assertEquals(1, constraintViolations.size());\n"
+" assertEquals(\"may not be null\", constraintViolations.iterator().next().getMessage());\n"
+" }\n"
+"\n"
+" @Test\n"
+" public void licensePlateTooShort() {\n"
+" Car car = new Car(\"Morris\", \"D\", 4);\n"
+"\n"
+" Set<ConstraintViolation<Car>> constraintViolations = \n"
+" validator.validate(car);\n"
+"\n"
+" assertEquals(1, constraintViolations.size());\n"
+" assertEquals(\"size must be between 2 and 14\", constraintViolations.iterator().next().getMessage());\n"
+" }\n"
+" \n"
+" @Test\n"
+" public void seatCountTooLow() {\n"
+" Car car = new Car(\"Morris\", \"DD-AB-123\", 1);\n"
+"\n"
+" Set<ConstraintViolation<Car>> constraintViolations =\n"
+" validator.validate(car);\n"
+"\n"
+" assertEquals(1, constraintViolations.size());\n"
+" assertEquals(\"must be greater than or equal to 2\", constraintViolations.iterator().next().getMessage());\n"
+" }\n"
+"\n"
+" @Test\n"
+" public void carIsValid() {\n"
+" Car car = new Car(\"Morris\", \"DD-AB-123\", 2);\n"
+"\n"
+" Set<ConstraintViolation<Car>> constraintViolations =\n"
+" validator.validate(car);\n"
+"\n"
+" assertEquals(0, constraintViolations.size());\n"
+" }\n"
+"}"
#. Tag: para
#: gettingstarted.xml:139
#, no-c-format
-msgid ""
-"In the <methodname>setUp()</methodname> method we get a "
-"<classname>Validator</classname> instance from the "
-"<classname>ValidatorFactory</classname>. A <classname>Validator</classname> "
-"instance is thread-safe and may be reused multiple times. For this reason we "
-"store it as field of our test class. We can use the <classname>Validator</"
-"classname> now to validate the different car instances in the test methods."
-msgstr ""
+msgid "In the <methodname>setUp()</methodname> method we get a <classname>Validator</classname> instance from the <classname>ValidatorFactory</classname>. A <classname>Validator</classname> instance is thread-safe and may be reused multiple times. For this reason we store it as field of our test class. We can use the <classname>Validator</classname> now to validate the different car instances in the test methods."
+msgstr "在<methodname>setUp()</methodname>方法中,我们通过<classname>ValidatorFactory</classname>得到了一个<classname>Validator</classname>的实例. <classname>Validator</classname>是线程安全的,并且可以重复使用, 所以我们把它保存成一个类变量. 现在我们可以在test方法中使用这个validator的实例来校验不同的car实例了."
#. Tag: para
#: gettingstarted.xml:147
#, no-c-format
-msgid ""
-"The <methodname>validate()</methodname> method returns a set of "
-"<classname>ConstraintViolation</classname> instances, which we can iterate "
-"in order to see which validation errors occurred. The first three test "
-"methods show some expected constraint violations:"
-msgstr ""
+msgid "The <methodname>validate()</methodname> method returns a set of <classname>ConstraintViolation</classname> instances, which we can iterate in order to see which validation errors occurred. The first three test methods show some expected constraint violations:"
+msgstr "<methodname>validate()</methodname>方法会返回一个set的<classname>ConstraintViolation</classname>的实例的集合, 我们可以通过遍历它来查看有哪些验证错误. 前面三个测试用例显示了一些预期的校验约束:"
#. Tag: para
#: gettingstarted.xml:154
#, no-c-format
-msgid ""
-"The <classname>@NotNull</classname> constraint on manufacturer is violated "
-"in <methodname>manufacturerIsNull()</methodname>"
-msgstr ""
+msgid "The <classname>@NotNull</classname> constraint on manufacturer is violated in <methodname>manufacturerIsNull()</methodname>"
+msgstr "在<methodname>manufacturerIsNull()</methodname>中可以看到manufacturer违反了<classname>@NotNull</classname>约束"
#. Tag: para
#: gettingstarted.xml:159
#, no-c-format
-msgid ""
-"The <classname>@Size</classname> constraint on licensePlate is violated in "
-"<methodname>licensePlateTooShort()</methodname>"
-msgstr ""
+msgid "The <classname>@Size</classname> constraint on licensePlate is violated in <methodname>licensePlateTooShort()</methodname>"
+msgstr "<methodname>licensePlateTooShort()</methodname>中的licensePlate违反了<classname>@Size</classname>约束"
#. Tag: para
#: gettingstarted.xml:164
#, no-c-format
-msgid ""
-"The <classname>@Min</classname> constraint on seatCount is violated in "
-"<methodname>seatCountTooLow()</methodname>"
-msgstr ""
+msgid "The <classname>@Min</classname> constraint on seatCount is violated in <methodname>seatCountTooLow()</methodname>"
+msgstr "而<methodname>seatCountTooLow()</methodname>中则导致seatCount违反了<classname>@Min</classname>约束"
#. Tag: para
#: gettingstarted.xml:169
#, no-c-format
-msgid ""
-"If the object validates successfully, <methodname>validate()</methodname> "
-"returns an empty set."
-msgstr ""
+msgid "If the object validates successfully, <methodname>validate()</methodname> returns an empty set."
+msgstr " 如果一个对象没有校验出问题的话,那么<methodname>validate()</methodname> 会返回一个空的set对象."
#. Tag: para
#: gettingstarted.xml:172
#, no-c-format
-msgid ""
-"Note that we only use classes from the package <package>javax.validation</"
-"package> from the Bean Validation API. As we don't reference any classes of "
-"the RI directly, it would be no problem to switch to another implementation "
-"of the API, should that need arise."
-msgstr ""
+msgid "Note that we only use classes from the package <package>javax.validation</package> from the Bean Validation API. As we don't reference any classes of the RI directly, it would be no problem to switch to another implementation of the API, should that need arise."
+msgstr "注意,我们只使用了Bean Validation API中的package <package>javax.validation</package>中的类, 并没有直接调用参考实现中的任何类,所以, 没有任何问题如果切换到其他的实现."
#. Tag: title
#: gettingstarted.xml:180
#, no-c-format
msgid "Where to go next?"
-msgstr ""
+msgstr "更进一步"
#. Tag: para
#: gettingstarted.xml:182
#, no-c-format
-msgid ""
-"That concludes our 5 minute tour through the world of Hibernate Validator. "
-"Continue exploring the code examples or look at further examples referenced "
-"in <xref linkend=\"chapter-further-reading\"/>. To deepen your understanding "
-"of Hibernate Validator just continue reading <xref linkend=\"validator-"
-"usingvalidator\"/>. In case your application has specific validation "
-"requirements have a look at <xref linkend=\"validator-customconstraints\"/>."
-msgstr ""
+msgid "That concludes our 5 minute tour through the world of Hibernate Validator. Continue exploring the code examples or look at further examples referenced in <xref linkend=\"chapter-further-reading\"/>. To deepen your understanding of Hibernate Validator just continue reading <xref linkend=\"validator-usingvalidator\"/>. In case your application has specific validation requirements have a look at <xref linkend=\"validator-customconstraints\"/>."
+msgstr "在本章中, 您了解了一个基于Hibernate Validator的简单例子. 更多的示例请参考 <xref linkend=\"chapter-further-reading\"/>. 如果想进一步了解Hibenate Validator, 请继续阅读<xref linkend=\"validator-usingvalidator\"/>. 如果您的应用程序有特殊的校验需求,请参考 <xref linkend=\"validator-customconstraints\"/>."
+
Modified: validator/trunk/hibernate-validator/src/main/docbook/zh-CN/modules/preface.po
===================================================================
--- validator/trunk/hibernate-validator/src/main/docbook/zh-CN/modules/preface.po 2010-07-06 15:18:26 UTC (rev 19904)
+++ validator/trunk/hibernate-validator/src/main/docbook/zh-CN/modules/preface.po 2010-07-06 19:35:13 UTC (rev 19905)
@@ -6,8 +6,8 @@
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: http://bugs.kde.org\n"
"POT-Creation-Date: 2010-07-06 14:46+0000\n"
-"PO-Revision-Date: 2010-07-06 14:46+0000\n"
-"Last-Translator: Automatically generated\n"
+"PO-Revision-Date: 2010-07-06 23:46+0830\n"
+"Last-Translator: Strong Liu <stliu(a)hibernate.org>\n"
"Language-Team: none\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
@@ -17,36 +17,23 @@
#: preface.xml:25
#, no-c-format
msgid "Preface"
-msgstr ""
+msgstr "序言"
#. Tag: para
#: preface.xml:27
#, no-c-format
-msgid ""
-"Validating data is a common task that occurs throughout any application, "
-"from the presentation layer to the persistence layer. Often the same "
-"validation logic is implemented in each layer, proving time consuming and "
-"error-prone. To avoid duplication of these validations in each layer, "
-"developers often bundle validation logic directly into the domain model, "
-"cluttering domain classes with validation code which is really metadata "
-"about the class itself."
-msgstr ""
+msgid "Validating data is a common task that occurs throughout any application, from the presentation layer to the persistence layer. Often the same validation logic is implemented in each layer, proving time consuming and error-prone. To avoid duplication of these validations in each layer, developers often bundle validation logic directly into the domain model, cluttering domain classes with validation code which is really metadata about the class itself."
+msgstr "数据校验是任何一个应用程序都会用到的功能,无论是显示层还是持久层. 通常,相同的校验逻辑会分散在各个层中, 这样,不仅浪费了时间还会导致错误的发生(译注: 重复代码). 为了避免重复, 开发人员经常会把这些校验逻辑直接写在领域模型里面, 但是这样又把领域模型代码和校验代码混杂在了一起, 而这些校验逻辑更应该是描述领域模型的元数据."
#. Tag: para
#: preface.xml:46
#, no-c-format
-msgid ""
-"JSR 303 - Bean Validation - defines a metadata model and API for entity "
-"validation. The default metadata source is annotations, with the ability to "
-"override and extend the meta-data through the use of XML. The API is not "
-"tied to a specific application tier or programming model. It is specifically "
-"not tied to either the web tier or the persistence tier, and is available "
-"for both server-side application programming, as well as rich client Swing "
-"application developers."
-msgstr ""
+msgid "JSR 303 - Bean Validation - defines a metadata model and API for entity validation. The default metadata source is annotations, with the ability to override and extend the meta-data through the use of XML. The API is not tied to a specific application tier or programming model. It is specifically not tied to either the web tier or the persistence tier, and is available for both server-side application programming, as well as rich client Swing application developers."
+msgstr "JSR 303 - Bean Validation - 为实体验证定义了元数据模型和API. 默认的元数据模型是通过Annotations来描述的,但是也可以使用XML来重载或者扩展. Bean Validation API 并不局限于应用程序的某一层或者哪种编程模型, 例如,如图所示, Bean Validation 可以被用在任何一层, 或者是像类似Swing的富客户端程序中."
#. Tag: para
#: preface.xml:65
#, no-c-format
msgid "Hibernate Validator is the reference implementation of this JSR."
-msgstr ""
+msgstr "Hibernate Validator 是这个JSR的参考实现."
+
14 years, 7 months
Hibernate SVN: r19904 - in validator/trunk/hibernate-validator: src/main/docbook and 5 other directories.
by hibernate-commits@lists.jboss.org
Author: stliu
Date: 2010-07-06 11:18:26 -0400 (Tue, 06 Jul 2010)
New Revision: 19904
Added:
validator/trunk/hibernate-validator/src/main/docbook/pot/
validator/trunk/hibernate-validator/src/main/docbook/pot/master.pot
validator/trunk/hibernate-validator/src/main/docbook/pot/modules/
validator/trunk/hibernate-validator/src/main/docbook/pot/modules/annotationprocessor.pot
validator/trunk/hibernate-validator/src/main/docbook/pot/modules/bootstrapping.pot
validator/trunk/hibernate-validator/src/main/docbook/pot/modules/customconstraints.pot
validator/trunk/hibernate-validator/src/main/docbook/pot/modules/furtherreading.pot
validator/trunk/hibernate-validator/src/main/docbook/pot/modules/gettingstarted.pot
validator/trunk/hibernate-validator/src/main/docbook/pot/modules/integration.pot
validator/trunk/hibernate-validator/src/main/docbook/pot/modules/preface.pot
validator/trunk/hibernate-validator/src/main/docbook/pot/modules/programmaticapi.pot
validator/trunk/hibernate-validator/src/main/docbook/pot/modules/usingvalidator.pot
validator/trunk/hibernate-validator/src/main/docbook/pot/modules/xmlconfiguration.pot
validator/trunk/hibernate-validator/src/main/docbook/zh-CN/
validator/trunk/hibernate-validator/src/main/docbook/zh-CN/master.po
validator/trunk/hibernate-validator/src/main/docbook/zh-CN/modules/
validator/trunk/hibernate-validator/src/main/docbook/zh-CN/modules/annotationprocessor.po
validator/trunk/hibernate-validator/src/main/docbook/zh-CN/modules/bootstrapping.po
validator/trunk/hibernate-validator/src/main/docbook/zh-CN/modules/customconstraints.po
validator/trunk/hibernate-validator/src/main/docbook/zh-CN/modules/furtherreading.po
validator/trunk/hibernate-validator/src/main/docbook/zh-CN/modules/gettingstarted.po
validator/trunk/hibernate-validator/src/main/docbook/zh-CN/modules/integration.po
validator/trunk/hibernate-validator/src/main/docbook/zh-CN/modules/preface.po
validator/trunk/hibernate-validator/src/main/docbook/zh-CN/modules/programmaticapi.po
validator/trunk/hibernate-validator/src/main/docbook/zh-CN/modules/usingvalidator.po
validator/trunk/hibernate-validator/src/main/docbook/zh-CN/modules/xmlconfiguration.po
Modified:
validator/trunk/hibernate-validator/pom.xml
validator/trunk/hibernate-validator/src/main/docbook/en-US/modules/gettingstarted.xml
Log:
HV-351 add pot and po files for translating doc into chinese
Modified: validator/trunk/hibernate-validator/pom.xml
===================================================================
--- validator/trunk/hibernate-validator/pom.xml 2010-07-06 10:31:48 UTC (rev 19903)
+++ validator/trunk/hibernate-validator/pom.xml 2010-07-06 15:18:26 UTC (rev 19904)
@@ -263,6 +263,9 @@
<sourceDocumentName>master.xml</sourceDocumentName>
<sourceDirectory>${basedir}/src/main/docbook</sourceDirectory>
<masterTranslation>en-US</masterTranslation>
+ <translations>
+ <translation>zh-CN</translation>
+ </translations>
<imageResource>
<directory>${basedir}/src/main/docbook/en-US/images</directory>
</imageResource>
Modified: validator/trunk/hibernate-validator/src/main/docbook/en-US/modules/gettingstarted.xml
===================================================================
--- validator/trunk/hibernate-validator/src/main/docbook/en-US/modules/gettingstarted.xml 2010-07-06 10:31:48 UTC (rev 19903)
+++ validator/trunk/hibernate-validator/src/main/docbook/en-US/modules/gettingstarted.xml 2010-07-06 15:18:26 UTC (rev 19904)
@@ -110,9 +110,9 @@
<para>Maven will create your project in the directory hv-quickstart.
Change into this directory and run:</para>
- <para><programlisting>mvn test</programlisting>Maven will compile the
- example code and run the implemented unit tests. Let's have a look at the
- actual code.</para>
+ <para><programlisting>mvn test</programlisting>
+ Maven will compile the example code and run the implemented unit tests. Let's have a look at the actual code.
+ </para>
</section>
<section id="validator-gettingstarted-createmodel">
Added: validator/trunk/hibernate-validator/src/main/docbook/pot/master.pot
===================================================================
--- validator/trunk/hibernate-validator/src/main/docbook/pot/master.pot (rev 0)
+++ validator/trunk/hibernate-validator/src/main/docbook/pot/master.pot 2010-07-06 15:18:26 UTC (rev 19904)
@@ -0,0 +1,52 @@
+# SOME DESCRIPTIVE TITLE.
+# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
+#
+#, fuzzy
+msgid ""
+msgstr ""
+"Project-Id-Version: PACKAGE VERSION\n"
+"Report-Msgid-Bugs-To: http://bugs.kde.org\n"
+"POT-Creation-Date: 2010-07-06 14:46+0000\n"
+"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
+"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
+"Language-Team: LANGUAGE <kde-i18n-doc(a)kde.org>\n"
+"MIME-Version: 1.0\n"
+"Content-Type: application/x-xml2pot; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+
+#. Tag: title
+#: master.xml:26
+#, no-c-format
+msgid "Hibernate Validator"
+msgstr ""
+
+#. Tag: subtitle
+#: master.xml:27
+#, no-c-format
+msgid "JSR 303 Reference Implementation"
+msgstr ""
+
+#. Tag: subtitle
+#: master.xml:28
+#, no-c-format
+msgid "Reference Guide"
+msgstr ""
+
+#. Tag: holder
+#: master.xml:34
+#, no-c-format
+msgid "©rightHolder;"
+msgstr ""
+
+#. Tag: author
+#: master.xml:37
+#, no-c-format
+msgid "<firstname>Hardy</firstname> <surname>Ferentschik</surname>"
+msgstr ""
+
+#. Tag: author
+#: master.xml:41
+#, no-c-format
+msgid "<firstname>Gunnar</firstname> <surname>Morling</surname>"
+msgstr ""
+
Added: validator/trunk/hibernate-validator/src/main/docbook/pot/modules/annotationprocessor.pot
===================================================================
--- validator/trunk/hibernate-validator/src/main/docbook/pot/modules/annotationprocessor.pot (rev 0)
+++ validator/trunk/hibernate-validator/src/main/docbook/pot/modules/annotationprocessor.pot 2010-07-06 15:18:26 UTC (rev 19904)
@@ -0,0 +1,529 @@
+# SOME DESCRIPTIVE TITLE.
+# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
+#
+#, fuzzy
+msgid ""
+msgstr ""
+"Project-Id-Version: PACKAGE VERSION\n"
+"Report-Msgid-Bugs-To: http://bugs.kde.org\n"
+"POT-Creation-Date: 2010-07-06 14:46+0000\n"
+"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
+"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
+"Language-Team: LANGUAGE <kde-i18n-doc(a)kde.org>\n"
+"MIME-Version: 1.0\n"
+"Content-Type: application/x-xml2pot; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+
+#. Tag: title
+#: annotationprocessor.xml:25
+#, no-c-format
+msgid "Annotation Processor (EXPERIMENTAL)"
+msgstr ""
+
+#. Tag: para
+#: annotationprocessor.xml:27
+#, no-c-format
+msgid "Have you ever caught yourself by unintentionally doing things like"
+msgstr ""
+
+#. Tag: para
+#: annotationprocessor.xml:32
+#, no-c-format
+msgid "annotating Strings with @Min to specify a minimum length (instead of using @Size)"
+msgstr ""
+
+#. Tag: para
+#: annotationprocessor.xml:37
+#, no-c-format
+msgid "annotating the setter of a JavaBean property (instead of the getter method)"
+msgstr ""
+
+#. Tag: para
+#: annotationprocessor.xml:42
+#, no-c-format
+msgid "annotating static fields/methods with constraint annotations (which is not supported)?"
+msgstr ""
+
+#. Tag: para
+#: annotationprocessor.xml:47
+#, no-c-format
+msgid "Then the Hibernate Validator Annotation Processor is the right thing for you. It helps preventing such mistakes by plugging into the build process and raising compilation errors whenever constraint annotations are incorrectly used."
+msgstr ""
+
+#. Tag: para
+#: annotationprocessor.xml:53
+#, no-c-format
+msgid "A first version of the Hibernate Validator Annotation Processor is part of Hibernate Validator since release 4.1. It is currently still under development and should therefore be considered as an experimental feature. Some <link linkend=\"section-known-issues\">known issues</link> can be found at the end of this chapter. In case any problems arise when using the processor feel free to ask for help at the <ulink url=\"https://forum.hibernate.org/viewforum.php?f=9\">forum</ulink> or create an issue within<ulink url=\"http://opensource.atlassian.com/projects/hibernate/browse/HV/component/10..."> JIRA</ulink>."
+msgstr ""
+
+#. Tag: title
+#: annotationprocessor.xml:66
+#, no-c-format
+msgid "Prerequisites"
+msgstr ""
+
+#. Tag: para
+#: annotationprocessor.xml:68
+#, no-c-format
+msgid "The Hibernate Validator Annotation Processor is based on the \"Pluggable Annotation Processing API\" as defined by <ulink url=\"http://jcp.org/en/jsr/detail?id=269\">JSR 269</ulink>. This API is part of the Java Platform since Java 6. So be sure to use this or a later version."
+msgstr ""
+
+#. Tag: title
+#: annotationprocessor.xml:76
+#, no-c-format
+msgid "Features"
+msgstr ""
+
+#. Tag: para
+#: annotationprocessor.xml:78
+#, no-c-format
+msgid "As of Hibernate Validator 4.1 the Hibernate Validator Annotation Processor checks that:"
+msgstr ""
+
+#. Tag: para
+#: annotationprocessor.xml:83
+#, no-c-format
+msgid "constraint annotations are allowed for the type of the annotated element"
+msgstr ""
+
+#. Tag: para
+#: annotationprocessor.xml:88
+#, no-c-format
+msgid "JavaBean getter methods are annotated in case of property validation"
+msgstr ""
+
+#. Tag: para
+#: annotationprocessor.xml:93
+#, no-c-format
+msgid "only non-static fields or properties are annotated with constraint annotations"
+msgstr ""
+
+#. Tag: para
+#: annotationprocessor.xml:98
+#, no-c-format
+msgid "only non-primitive fields or properties are annotated with @Valid"
+msgstr ""
+
+#. Tag: para
+#: annotationprocessor.xml:103
+#, no-c-format
+msgid "only such annotation types are annotated with constraint annotations which are constraint annotations themselves"
+msgstr ""
+
+#. Tag: title
+#: annotationprocessor.xml:110
+#, no-c-format
+msgid "Options"
+msgstr ""
+
+#. Tag: para
+#: annotationprocessor.xml:112
+#, no-c-format
+msgid "The behavior of the Hibernate Validator Annotation Processor can be controlled using the <ulink url=\"http://java.sun.com/javase/6/docs/technotes/tools/windows/javac.html#opti...">processor options</ulink> listed in table<xref linkend=\"table_processor_options\"/>:"
+msgstr ""
+
+#. Tag: title
+#: annotationprocessor.xml:119
+#, no-c-format
+msgid "Hibernate Validator Annotation Processor options"
+msgstr ""
+
+#. Tag: entry
+#: annotationprocessor.xml:124
+#, no-c-format
+msgid "Option"
+msgstr ""
+
+#. Tag: entry
+#: annotationprocessor.xml:126
+#, no-c-format
+msgid "Explanation"
+msgstr ""
+
+#. Tag: varname
+#: annotationprocessor.xml:132
+#, no-c-format
+msgid "diagnosticKind"
+msgstr ""
+
+#. Tag: entry
+#: annotationprocessor.xml:134
+#, no-c-format
+msgid "Controls how constraint problems are reported. Must be the string representation of one of the values from the enum <classname>javax.tools.Diagnostic.Kind</classname>, e.g. <classname>WARNING</classname>. A value of <classname>ERROR</classname> will cause compilation to halt whenever the AP detects a constraint problem. Defaults to <classname>ERROR</classname>."
+msgstr ""
+
+#. Tag: varname
+#: annotationprocessor.xml:144
+#, no-c-format
+msgid "verbose"
+msgstr ""
+
+#. Tag: entry
+#: annotationprocessor.xml:146
+#, no-c-format
+msgid "Controls whether detailed processing information shall be displayed or not, useful for debugging purposes. Must be either <varname>true</varname> or<varname>false</varname>. Defaults to <varname>false</varname>."
+msgstr ""
+
+#. Tag: title
+#: annotationprocessor.xml:157
+#, no-c-format
+msgid "Using the Annotation Processor"
+msgstr ""
+
+#. Tag: para
+#: annotationprocessor.xml:159
+#, no-c-format
+msgid "This section shows in detail how to integrate the Hibernate Validator Annotation Processor into command line builds (javac, Ant, Maven) as well as IDE-based builds (Eclipse, IntelliJ IDEA, NetBeans)."
+msgstr ""
+
+#. Tag: title
+#: annotationprocessor.xml:165
+#, no-c-format
+msgid "Command line builds"
+msgstr ""
+
+#. Tag: title
+#: annotationprocessor.xml:168
+#, no-c-format
+msgid "javac"
+msgstr ""
+
+#. Tag: para
+#: annotationprocessor.xml:170
+#, no-c-format
+msgid "When compiling on the command line using <ulink url=\"http://java.sun.com/javase/6/docs/technotes/guides/javac/index.html\">javac</ulink>, specify the following JARs using the \"processorpath\" option:"
+msgstr ""
+
+#. Tag: para
+#: annotationprocessor.xml:176 annotationprocessor.xml:287 annotationprocessor.xml:377
+#, no-c-format
+msgid "validation-api-&bvVersion;.jar"
+msgstr ""
+
+#. Tag: para
+#: annotationprocessor.xml:180 annotationprocessor.xml:291 annotationprocessor.xml:381
+#, no-c-format
+msgid "hibernate-validator-annotation-processor-&version;.jar"
+msgstr ""
+
+#. Tag: para
+#: annotationprocessor.xml:184
+#, no-c-format
+msgid "The following listing shows an example. The processor will be detected automatically by the compiler and invoked during compilation."
+msgstr ""
+
+#. Tag: title
+#: annotationprocessor.xml:189
+#, no-c-format
+msgid "Using the annotation processor with javac"
+msgstr ""
+
+#. Tag: programlisting
+#: annotationprocessor.xml:191
+#, no-c-format
+msgid ""
+ "javac src/main/java/org/hibernate/validator/ap/demo/Car.java \\\n"
+ " -cp /path/to/validation-api-&bvVersion;.jar \\ \n"
+ " -processorpath /path/to/validation-api-&bvVersion;.jar:/path/to/hibernate-validator-annotation-processor-&version;.jar"
+msgstr ""
+
+#. Tag: title
+#: annotationprocessor.xml:196
+#, no-c-format
+msgid "Apache Ant"
+msgstr ""
+
+#. Tag: para
+#: annotationprocessor.xml:198
+#, no-c-format
+msgid "Similar to directly working with javac, the annotation processor can be added as as compiler argument when invoking the <ulink url=\"http://ant.apache.org/manual/CoreTasks/javac.html\">javac task</ulink> for <ulink url=\"http://ant.apache.org/\">Apache Ant</ulink>:"
+msgstr ""
+
+#. Tag: title
+#: annotationprocessor.xml:205
+#, no-c-format
+msgid "Using the annotation processor with Ant"
+msgstr ""
+
+#. Tag: programlisting
+#: annotationprocessor.xml:207
+#, no-c-format
+msgid ""
+ "<javac srcdir=\"src/main\"\n"
+ " destdir=\"build/classes\"\n"
+ " classpath=\"/path/to/validation-api-&bvVersion;.jar\">\n"
+ " <compilerarg value=\"-processorpath\" />\n"
+ " <compilerarg value=\"/path/to/validation-api-&bvVersion;.jar:/path/to/hibernate-validator-annotation-processor-&version;.jar\"/>\n"
+ "</javac>"
+msgstr ""
+
+#. Tag: title
+#: annotationprocessor.xml:212
+#, no-c-format
+msgid "Maven"
+msgstr ""
+
+#. Tag: para
+#: annotationprocessor.xml:214
+#, no-c-format
+msgid "There are several options for integrating the annotation processor with <ulink url=\"http://maven.apache.org/\">Apache Maven</ulink>. Generally it is sufficient to add the Hibernate Validator Annotation Processor as dependency to your project:"
+msgstr ""
+
+#. Tag: title
+#: annotationprocessor.xml:220
+#, no-c-format
+msgid "Adding the HV Annotation Processor as dependency"
+msgstr ""
+
+#. Tag: programlisting
+#: annotationprocessor.xml:222
+#, no-c-format
+msgid ""
+ "...\n"
+ "<dependency>\n"
+ " <groupId>org.hibernate</groupId>\n"
+ " <artifactId>hibernate-validator-annotation-processor</artifactId>\n"
+ " <version>&version;</version>\n"
+ " <scope>compile</scope>\n"
+ "</dependency>\n"
+ "..."
+msgstr ""
+
+#. Tag: para
+#: annotationprocessor.xml:225
+#, no-c-format
+msgid "The processor will then be executed automatically by the compiler. This basically works, but comes with the disadavantage that in some cases messages from the annotation processor are not displayed (see <ulink url=\"http://jira.codehaus.org/browse/MCOMPILER-66\">MCOMPILER-66</ulink>)."
+msgstr ""
+
+#. Tag: para
+#: annotationprocessor.xml:231
+#, no-c-format
+msgid "Another option is using the <ulink url=\"http://code.google.com/p/maven-annotation-plugin/\">Maven Annotation Plugin</ulink>. At the time of this writing the plugin is not yet available in any of the well-known repositories. Therefore you have to add the project's own repository to your settings.xml or pom.xml:"
+msgstr ""
+
+#. Tag: title
+#: annotationprocessor.xml:239
+#, no-c-format
+msgid "Adding the Maven Annotation Plugin repository"
+msgstr ""
+
+#. Tag: programlisting
+#: annotationprocessor.xml:241
+#, no-c-format
+msgid ""
+ "...\n"
+ "<pluginRepositories>\n"
+ " <pluginRepository>\n"
+ " <id>maven-annotation-plugin-repo</id>\n"
+ " <url>http://maven-annotation-plugin.googlecode.com/svn/trunk/mavenrepo&..."
+ " </pluginRepository>\n"
+ "</pluginRepositories>\n"
+ "..."
+msgstr ""
+
+#. Tag: para
+#: annotationprocessor.xml:242
+#, no-c-format
+msgid "Now disable the standard annotation processing performed by the compiler plugin and configure the annotation plugin by specifying an execution and adding the Hibernate Validator Annotation Processor as plugin dependency (that way the AP is not visible on the project's actual classpath):"
+msgstr ""
+
+#. Tag: title
+#: annotationprocessor.xml:249
+#, no-c-format
+msgid "Configuring the Maven Annotation Plugin"
+msgstr ""
+
+#. Tag: programlisting
+#: annotationprocessor.xml:251
+#, no-c-format
+msgid ""
+ "...\n"
+ "<plugin>\n"
+ " <artifactId>maven-compiler-plugin</artifactId>\n"
+ " <configuration>\n"
+ " <source>1.6</source>\n"
+ " <target>1.6</target>\n"
+ " <compilerArgument>-proc:none</compilerArgument>\n"
+ " </configuration>\n"
+ "</plugin>\n"
+ "<plugin>\n"
+ " <groupId>org.bsc.maven</groupId>\n"
+ " <artifactId>maven-processor-plugin</artifactId>\n"
+ " <version>1.3.4</version>\n"
+ " <executions>\n"
+ " <execution>\n"
+ " <id>process</id>\n"
+ " <goals>\n"
+ " <goal>process</goal>\n"
+ " </goals>\n"
+ " <phase>process-sources</phase>\n"
+ " </execution>\n"
+ " </executions>\n"
+ " <dependencies>\n"
+ " <dependency>\n"
+ " <groupId>org.hibernate</groupId>\n"
+ " <artifactId>hibernate-validator-annotation-processor</artifactId>\n"
+ " <version>&version;</version>\n"
+ " <scope>compile</scope>\n"
+ " </dependency>\n"
+ " </dependencies>\n"
+ "</plugin>\n"
+ "..."
+msgstr ""
+
+#. Tag: title
+#: annotationprocessor.xml:257
+#, no-c-format
+msgid "IDE builds"
+msgstr ""
+
+#. Tag: title
+#: annotationprocessor.xml:260
+#, no-c-format
+msgid "Eclipse"
+msgstr ""
+
+#. Tag: para
+#: annotationprocessor.xml:262
+#, no-c-format
+msgid "Do the following to use the annotation processor within the <ulink url=\"http://www.eclipse.org/\">Eclipse</ulink> IDE:"
+msgstr ""
+
+#. Tag: para
+#: annotationprocessor.xml:267 annotationprocessor.xml:368
+#, no-c-format
+msgid "Right-click your project, choose \"Properties\""
+msgstr ""
+
+#. Tag: para
+#: annotationprocessor.xml:271
+#, no-c-format
+msgid "Go to \"Java Compiler\" and make sure, that \"Compiler compliance level\" is set to \"1.6\". Otherwise the processor won't be activated"
+msgstr ""
+
+#. Tag: para
+#: annotationprocessor.xml:277
+#, no-c-format
+msgid "Go to \"Java Compiler - Annotation Processing\" and choose \"Enable annotation processing\""
+msgstr ""
+
+#. Tag: para
+#: annotationprocessor.xml:282
+#, no-c-format
+msgid "Go to \"Java Compiler - Annotation Processing - Factory Path\" and add the following JARs:"
+msgstr ""
+
+#. Tag: para
+#: annotationprocessor.xml:297
+#, no-c-format
+msgid "Confirm the workspace rebuild"
+msgstr ""
+
+#. Tag: para
+#: annotationprocessor.xml:301
+#, no-c-format
+msgid "You now should see any annotation problems as regular error markers within the editor and in the \"Problem\" view:"
+msgstr ""
+
+#. Tag: title
+#: annotationprocessor.xml:313
+#, no-c-format
+msgid "IntelliJ IDEA"
+msgstr ""
+
+#. Tag: para
+#: annotationprocessor.xml:315
+#, no-c-format
+msgid "The following steps must be followed to use the annotation processor within <ulink url=\"http://www.jetbrains.com/idea/\">IntelliJ IDEA</ulink> (version 9 and above):"
+msgstr ""
+
+#. Tag: para
+#: annotationprocessor.xml:321
+#, no-c-format
+msgid "Go to \"File\", then \"Settings\","
+msgstr ""
+
+#. Tag: para
+#: annotationprocessor.xml:325
+#, no-c-format
+msgid "Expand the node \"Compiler\", then \"Annotation Processors\""
+msgstr ""
+
+#. Tag: para
+#: annotationprocessor.xml:330
+#, no-c-format
+msgid "Choose \"Enable annotation processing\" and enter the following as \"Processor path\": /path/to/validation-api-&bvVersion;.jar:/path/to/hibernate-validator-annotation-processor-&version;.jar"
+msgstr ""
+
+#. Tag: para
+#: annotationprocessor.xml:336
+#, no-c-format
+msgid "Add the processor's fully qualified name <classname>org.hibernate.validator.ap.ConstraintValidationProcessor</classname> to the \"Annotation Processors\" list"
+msgstr ""
+
+#. Tag: para
+#: annotationprocessor.xml:342
+#, no-c-format
+msgid "If applicable add you module to the \"Processed Modules\" list"
+msgstr ""
+
+#. Tag: para
+#: annotationprocessor.xml:347
+#, no-c-format
+msgid "Rebuilding your project then should show any erronous constraint annotations:"
+msgstr ""
+
+#. Tag: title
+#: annotationprocessor.xml:359
+#, no-c-format
+msgid "NetBeans"
+msgstr ""
+
+#. Tag: para
+#: annotationprocessor.xml:361
+#, no-c-format
+msgid "Starting with version 6.9, also the <ulink url=\"http://www.netbeans.org/\">NetBeans</ulink> IDE supports using annotation processors within the IDE build. To do so, do the following:"
+msgstr ""
+
+#. Tag: para
+#: annotationprocessor.xml:372
+#, no-c-format
+msgid "Go to \"Libraries\", tab \"Processor\", and add the following two JARs:"
+msgstr ""
+
+#. Tag: para
+#: annotationprocessor.xml:387
+#, no-c-format
+msgid "Go to \"Build - Compiling\", select \"Enable Annotation Processing\" and \"Enable Annotation Processing in Editor\". Add the annotation processor by specifying its fully qualified name <classname>org.hibernate.validator.ap.ConstraintValidationProcessor</classname>"
+msgstr ""
+
+#. Tag: para
+#: annotationprocessor.xml:394
+#, no-c-format
+msgid "Any constraint annotation problems will then be marked directly within the editor:"
+msgstr ""
+
+#. Tag: title
+#: annotationprocessor.xml:408
+#, no-c-format
+msgid "Known issues"
+msgstr ""
+
+#. Tag: para
+#: annotationprocessor.xml:410
+#, no-c-format
+msgid "The following known issues exist as of May 2010:"
+msgstr ""
+
+#. Tag: para
+#: annotationprocessor.xml:414
+#, no-c-format
+msgid "<ulink url=\"http://opensource.atlassian.com/projects/hibernate/browse/HV-308\">HV-308</ulink>: Additional validators registered for a constraint <ulink url=\"http://docs.jboss.org/hibernate/stable/validator/reference/en/html_single...">using XML</ulink> are not evaluated by the annotation processor."
+msgstr ""
+
+#. Tag: para
+#: annotationprocessor.xml:422
+#, no-c-format
+msgid "Sometimes custom constraints can't be <ulink url=\"http://opensource.atlassian.com/projects/hibernate/browse/HV-293\">properly evaluated</ulink> when using the processor within Eclipse. Cleaning the project can help in these situations. This seems to be an issue with the Eclipse JSR 269 API implementation, but further investigation is required here."
+msgstr ""
+
Added: validator/trunk/hibernate-validator/src/main/docbook/pot/modules/bootstrapping.pot
===================================================================
--- validator/trunk/hibernate-validator/src/main/docbook/pot/modules/bootstrapping.pot (rev 0)
+++ validator/trunk/hibernate-validator/src/main/docbook/pot/modules/bootstrapping.pot 2010-07-06 15:18:26 UTC (rev 19904)
@@ -0,0 +1,426 @@
+# SOME DESCRIPTIVE TITLE.
+# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
+#
+#, fuzzy
+msgid ""
+msgstr ""
+"Project-Id-Version: PACKAGE VERSION\n"
+"Report-Msgid-Bugs-To: http://bugs.kde.org\n"
+"POT-Creation-Date: 2010-07-06 14:46+0000\n"
+"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
+"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
+"Language-Team: LANGUAGE <kde-i18n-doc(a)kde.org>\n"
+"MIME-Version: 1.0\n"
+"Content-Type: application/x-xml2pot; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+
+#. Tag: title
+#: bootstrapping.xml:25
+#, no-c-format
+msgid "Bootstrapping"
+msgstr ""
+
+#. Tag: para
+#: bootstrapping.xml:27
+#, no-c-format
+msgid "We already seen in <xref linkend=\"section-validator-instance\"/> the easiest way to create a <classname>Validator</classname> instance - <methodname>Validation.buildDefaultValidatorFactory</methodname>. In this chapter we have a look at the other methods in <classname>javax.validation.Validation</classname> and how they allow to configure several aspects of Bean Validation at bootstrapping time."
+msgstr ""
+
+#. Tag: para
+#: bootstrapping.xml:34
+#, no-c-format
+msgid "The different bootstrapping options allow, amongst other things, to bootstrap any Bean Validation implementation on the classpath. Generally, an available provider is discovered by the <ulink url=\"http://java.sun.com/j2se/1.3/docs/guide/jar/jar.html#Service%20Provider\">Java Service Provider</ulink> mechanism. A Bean Validation implementation includes the file <filename>javax.validation.spi.ValidationProvider</filename> in <filename>META-INF/services</filename>. This file contains the fully qualified classname of the <classname>ValidationProvider</classname> of the implementation. In the case of Hibernate Validator this is <classname>org.hibernate.validator.HibernateValidator</classname>."
+msgstr ""
+
+#. Tag: para
+#: bootstrapping.xml:47
+#, no-c-format
+msgid "If there are more than one Bean Validation implementation providers in the classpath and <methodname>Validation.buildDefaultValidatorFactory()</methodname> is used, there is no guarantee which provider will be chosen. To enforce the provider <methodname>Validation.byProvider()</methodname> should be used."
+msgstr ""
+
+#. Tag: title
+#: bootstrapping.xml:56
+#, no-c-format
+msgid "<classname>Configuration</classname> and <classname>ValidatorFactory</classname>"
+msgstr ""
+
+#. Tag: para
+#: bootstrapping.xml:59
+#, no-c-format
+msgid "There are three different methods in the Validation class to create a Validator instance. The easiest in shown in <xref linkend=\"example-build-default-validator-factory\"/>."
+msgstr ""
+
+#. Tag: title
+#: bootstrapping.xml:64
+#, no-c-format
+msgid "Validation.buildDefaultValidatorFactory()"
+msgstr ""
+
+#. Tag: programlisting
+#: bootstrapping.xml:66
+#, no-c-format
+msgid ""
+ "ValidatorFactory factory = Validation.buildDefaultValidatorFactory();\n"
+ "Validator validator = factory.getValidator();"
+msgstr ""
+
+#. Tag: para
+#: bootstrapping.xml:69
+#, no-c-format
+msgid "You can also use the method <methodname>Validation.byDefaultProvider()</methodname> which will allow you to configure several aspects of the created Validator instance:"
+msgstr ""
+
+#. Tag: title
+#: bootstrapping.xml:74
+#, no-c-format
+msgid "Validation.byDefaultProvider()"
+msgstr ""
+
+#. Tag: programlisting
+#: bootstrapping.xml:76
+#, no-c-format
+msgid ""
+ "Configuration<?> config = Validation.byDefaultProvider().configure();\n"
+ "config.messageInterpolator(new MyMessageInterpolator())\n"
+ " .traversableResolver( new MyTraversableResolver())\n"
+ " .constraintValidatorFactory(new MyConstraintValidatorFactory());\n"
+ "\n"
+ "ValidatorFactory factory = config.buildValidatorFactory();\n"
+ "Validator validator = factory.getValidator();"
+msgstr ""
+
+#. Tag: para
+#: bootstrapping.xml:79
+#, no-c-format
+msgid "We will learn more about <classname>MessageInterpolator</classname>, <classname>TraversableResolver</classname> and <classname>ConstraintValidatorFactory</classname> in the following sections."
+msgstr ""
+
+#. Tag: para
+#: bootstrapping.xml:84
+#, no-c-format
+msgid "Last but not least you can ask for a Configuration object of a specific Bean Validation provider. This is useful if you have more than one Bean Validation provider in your classpath. In this situation you can make an explicit choice about which implementation to use. In the case of Hibernate Validator the <classname>Validator</classname> creation looks like:"
+msgstr ""
+
+#. Tag: title
+#: bootstrapping.xml:92
+#, no-c-format
+msgid "Validation.byProvider( HibernateValidator.class )"
+msgstr ""
+
+#. Tag: programlisting
+#: bootstrapping.xml:94
+#, no-c-format
+msgid ""
+ "HibernateValidatorConfiguration config = Validation.byProvider( HibernateValidator.class ).configure();\n"
+ "config.messageInterpolator(new MyMessageInterpolator())\n"
+ " .traversableResolver( new MyTraversableResolver())\n"
+ " .constraintValidatorFactory(new MyConstraintValidatorFactory());\n"
+ "\n"
+ "ValidatorFactory factory = config.buildValidatorFactory();\n"
+ "Validator validator = factory.getValidator();"
+msgstr ""
+
+#. Tag: para
+#: bootstrapping.xml:98
+#, no-c-format
+msgid "The generated <classname>Validator</classname> instance is thread safe and can be cached."
+msgstr ""
+
+#. Tag: classname
+#: bootstrapping.xml:104
+#, no-c-format
+msgid "ValidationProviderResolver"
+msgstr ""
+
+#. Tag: para
+#: bootstrapping.xml:106
+#, no-c-format
+msgid "In the case that the Java Service Provider mechanism does not work in your environment or you have a special classloader setup, you are able to provide a custom <classname>ValidationProviderResolver</classname>. An example in an OSGi environment you could plug your custom provider resolver like seen in <xref linkend=\"example-provider-resolver\"/>."
+msgstr ""
+
+#. Tag: title
+#: bootstrapping.xml:113
+#, no-c-format
+msgid "Providing a custom ValidationProviderResolver"
+msgstr ""
+
+#. Tag: programlisting
+#: bootstrapping.xml:115
+#, no-c-format
+msgid ""
+ "Configuration<?> config = Validation.byDefaultProvider()\n"
+ " .providerResolver( new OSGiServiceDiscoverer() )\n"
+ " .configure();\n"
+ "\n"
+ "ValidatorFactory factory = config.buildValidatorFactory();\n"
+ "Validator validator = factory.getValidator();"
+msgstr ""
+
+#. Tag: para
+#: bootstrapping.xml:118
+#, no-c-format
+msgid "Your <classname>OSGiServiceDiscoverer</classname> must in this case implement the interface <classname>ValidationProviderResolver</classname>:"
+msgstr ""
+
+#. Tag: title
+#: bootstrapping.xml:123
+#, no-c-format
+msgid "ValidationProviderResolver interface"
+msgstr ""
+
+#. Tag: programlisting
+#: bootstrapping.xml:125
+#, no-c-format
+msgid ""
+ "public interface ValidationProviderResolver {\n"
+ " /**\n"
+ " * Returns a list of ValidationProviders available in the runtime environment.\n"
+ " *\n"
+ " * @return list of validation providers. \n"
+ " */\n"
+ " List<ValidationProvider<?>> getValidationProviders();\n"
+ "}"
+msgstr ""
+
+#. Tag: classname
+#: bootstrapping.xml:130
+#, no-c-format
+msgid "MessageInterpolator"
+msgstr ""
+
+#. Tag: para
+#: bootstrapping.xml:132
+#, no-c-format
+msgid "already discussed the default message interpolation algorithm. If you have special requirements for your message interpolation you can provide a custom interpolator using <methodname>Configuration.messageInterpolator()</methodname>. This message interpolator will be shared by all validators generated by the <classname>ValidatorFactory</classname> created from this <classname>Configuration</classname>(see <xref linkend=\"example-message-interpolator\"/>)."
+msgstr ""
+
+#. Tag: title
+#: bootstrapping.xml:143
+#, no-c-format
+msgid "Providing a custom MessageInterpolator"
+msgstr ""
+
+#. Tag: programlisting
+#: bootstrapping.xml:145
+#, no-c-format
+msgid ""
+ "Configuration<?> configuration = Validation.byDefaultProvider().configure();\n"
+ "ValidatorFactory factory = configuration\n"
+ " .messageInterpolator(new ContextualMessageInterpolator(configuration.getDefaultMessageInterpolator()))\n"
+ " .buildValidatorFactory();\n"
+ "\n"
+ "Validator validator = factory.getValidator();"
+msgstr ""
+
+#. Tag: para
+#: bootstrapping.xml:149
+#, no-c-format
+msgid "It is recommended that <classname>MessageInterpolator</classname> implementations delegate final interpolation to the Bean Validation default <classname>MessageInterpolator</classname> to ensure standard Bean Validation interpolation rules are followed. The default implementation is accessible through <methodname>Configuration.getDefaultMessageInterpolator()</methodname>."
+msgstr ""
+
+#. Tag: title
+#: bootstrapping.xml:158
+#, no-c-format
+msgid "ResourceBundleLocator"
+msgstr ""
+
+#. Tag: para
+#: bootstrapping.xml:160
+#, no-c-format
+msgid "A common use case is the ability to specify your own resource bundles for message interpolation. The default <classname>MessageInterpolator</classname> implementation in Hibernate Validator is called <classname>ResourceBundleMessageInterpolator</classname> and per default loads resource bundles via <methodname>ResourceBundle.getBundle</methodname>. However, <classname>ResourceBundleMessageInterpolator</classname> also allows you to specify a custom implementation of <classname>ResourceBundleLocator</classname> allowing you to provide your own resource bundles. <xref linkend=\"example-resource-bundle-locator\"/> shows an example. In the example<methodname> HibernateValidatorConfiguration.getDefaultResourceBundleLocator</methodname> is used to retrieve the default <classname>ResourceBundleLocator</classname> which then can be passed to the custom implementation in order implement delegation."
+msgstr ""
+
+#. Tag: title
+#: bootstrapping.xml:179
+#, no-c-format
+msgid "Providing a custom ResourceBundleLocator"
+msgstr ""
+
+#. Tag: programlisting
+#: bootstrapping.xml:181
+#, no-c-format
+msgid ""
+ "HibernateValidatorConfiguration configure = Validation.byProvider(HibernateValidator.class).configure();\n"
+ "\n"
+ "ResourceBundleLocator defaultResourceBundleLocator = configure.getDefaultResourceBundleLocator(); \n"
+ "ResourceBundleLocator myResourceBundleLocator = new MyCustomResourceBundleLocator(defaultResourceBundleLocator);\n"
+ "\n"
+ "configure.messageInterpolator(new ResourceBundleMessageInterpolator(myResourceBundleLocator));"
+msgstr ""
+
+#. Tag: para
+#: bootstrapping.xml:184
+#, no-c-format
+msgid "Hibernate Validator provides the following implementation of <classname>ResourceBundleLocator</classname> - <classname>PlatformResourceBundleLocator</classname> (the default) and <classname>AggregateResourceBundleLocator</classname>. The latter can be used to specify a list of resource bundle names which will get loaded and merged into a single resource bundle. Refer to the JavaDoc documentation for more information."
+msgstr ""
+
+#. Tag: classname
+#: bootstrapping.xml:195
+#, no-c-format
+msgid "TraversableResolver"
+msgstr ""
+
+#. Tag: para
+#: bootstrapping.xml:197
+#, no-c-format
+msgid "The usage of the <classname>TraversableResolver</classname> has so far not been discussed. The idea is that in some cases, the state of a property should not be accessed. The most obvious example for that is a lazy loaded property or association of a Java Persistence provider. Validating this lazy property or association would mean that its state would have to be accessed triggering a load from the database. Bean Validation controls which property can and cannot be accessed via the <classname>TraversableResolver</classname> interface (see <xref linkend=\"example-traversable-resolver\"/>). In the example HibernateValidatorConfiguration."
+msgstr ""
+
+#. Tag: title
+#: bootstrapping.xml:209
+#, no-c-format
+msgid "TraversableResolver interface"
+msgstr ""
+
+#. Tag: programlisting
+#: bootstrapping.xml:211
+#, no-c-format
+msgid ""
+ "/**\n"
+ " * Contract determining if a property can be accessed by the Bean Validation provider\n"
+ " * This contract is called for each property that is being either validated or cascaded.\n"
+ " *\n"
+ " * A traversable resolver implementation must be thread-safe.\n"
+ " *\n"
+ " */\n"
+ "public interface TraversableResolver {\n"
+ " /**\n"
+ " * Determine if the Bean Validation provider is allowed to reach the property state\n"
+ " *\n"
+ " * @param traversableObject object hosting <code>traversableProperty</code> or null \n"
+ " * if validateValue is called\n"
+ " * @param traversableProperty the traversable property.\n"
+ " * @param rootBeanType type of the root object passed to the Validator.\n"
+ " * @param pathToTraversableObject path from the root object to\n"
+ " * <code>traversableObject</code>\n"
+ " * (using the path specification defined by Bean Validator).\n"
+ " * @param elementType either <code>FIELD</code> or <code>METHOD</code>.\n"
+ " *\n"
+ " * @return <code>true</code> if the Bean Validation provider is allowed to\n"
+ " * reach the property state, <code>false</code> otherwise.\n"
+ " */\n"
+ " boolean isReachable(Object traversableObject,\n"
+ " Path.Node traversableProperty,\n"
+ " Class<?> rootBeanType,\n"
+ " Path pathToTraversableObject,\n"
+ " ElementType elementType);\n"
+ "\n"
+ " /**\n"
+ " * Determine if the Bean Validation provider is allowed to cascade validation on\n"
+ " * the bean instance returned by the property value\n"
+ " * marked as <code>(a)Valid</code>.\n"
+ " * Note that this method is called only if isReachable returns true for the same set of\n"
+ " * arguments and if the property is marked as <code>@Valid</code>\n"
+ " *\n"
+ " * @param traversableObject object hosting <code>traversableProperty</code> or null\n"
+ " * if validateValue is called\n"
+ " * @param traversableProperty the traversable property.\n"
+ " * @param rootBeanType type of the root object passed to the Validator.\n"
+ " * @param pathToTraversableObject path from the root object to\n"
+ " * <code>traversableObject</code>\n"
+ " * (using the path specification defined by Bean Validator).\n"
+ " * @param elementType either <code>FIELD</code> or <code>METHOD</code>.\n"
+ " *\n"
+ " * @return <code>true</code> if the Bean Validation provider is allowed to\n"
+ " * cascade validation, <code>false</code> otherwise.\n"
+ " */\n"
+ " boolean isCascadable(Object traversableObject,\n"
+ " Path.Node traversableProperty,\n"
+ " Class<?> rootBeanType,\n"
+ " Path pathToTraversableObject,\n"
+ " ElementType elementType);\n"
+ "}"
+msgstr ""
+
+#. Tag: para
+#: bootstrapping.xml:214
+#, no-c-format
+msgid "Hibernate Validator provides two <classname>TraversableResolver</classname>s out of the box which will be enabled automatically depending on your environment. The first is the <classname>DefaultTraversableResolver</classname> which will always return true for <methodname>isReachable()</methodname> and i<methodname>sTraversable()</methodname>. The second is the <classname>JPATraversableResolver</classname> which gets enabled when Hibernate Validator gets used in combination with JPA 2. In case you have to provide your own resolver you can do so again using the <classname>Configuration</classname> object as seen in <xref linkend=\"example-traversable-resolver-config\"/>."
+msgstr ""
+
+#. Tag: title
+#: bootstrapping.xml:227
+#, no-c-format
+msgid "Providing a custom TraversableResolver"
+msgstr ""
+
+#. Tag: programlisting
+#: bootstrapping.xml:229
+#, no-c-format
+msgid ""
+ "Configuration<?> configuration = Validation.byDefaultProvider().configure();\n"
+ "ValidatorFactory factory = configuration\n"
+ " .traversableResolver(new MyTraversableResolver())\n"
+ " .buildValidatorFactory();\n"
+ "\n"
+ "Validator validator = factory.getValidator();"
+msgstr ""
+
+#. Tag: classname
+#: bootstrapping.xml:234
+#, no-c-format
+msgid "ConstraintValidatorFactory"
+msgstr ""
+
+#. Tag: para
+#: bootstrapping.xml:236
+#, no-c-format
+msgid "Last but not least, there is one more configuration option to discuss, the <classname>ConstraintValidatorFactory</classname>. The default <classname>ConstraintValidatorFactory</classname> provided by Hibernate Validator requires a public no-arg constructor to instantiate <classname>ConstraintValidator</classname> instances (see <xref linkend=\"section-constraint-validator\"/>). Using a custom <classname>ConstraintValidatorFactory</classname> offers for example the possibility to use dependency injection in constraint implementations. The configuration of the custom factory is once more via the <classname>Configuration</classname> (<xref linkend=\"example-constraint-validator-factory\"/>)."
+msgstr ""
+
+#. Tag: title
+#: bootstrapping.xml:249
+#, no-c-format
+msgid "Providing a custom ConstraintValidatorFactory"
+msgstr ""
+
+#. Tag: programlisting
+#: bootstrapping.xml:251
+#, no-c-format
+msgid ""
+ "Configuration<?> configuration = Validation.byDefaultProvider().configure();\n"
+ "ValidatorFactory factory = configuration\n"
+ " .constraintValidatorFactory(new IOCConstraintValidatorFactory())\n"
+ " .buildValidatorFactory();\n"
+ "\n"
+ "Validator validator = factory.getValidator();"
+msgstr ""
+
+#. Tag: para
+#: bootstrapping.xml:254
+#, no-c-format
+msgid "The interface you have to implement is:"
+msgstr ""
+
+#. Tag: title
+#: bootstrapping.xml:257
+#, no-c-format
+msgid "ConstraintValidatorFactory interface"
+msgstr ""
+
+#. Tag: programlisting
+#: bootstrapping.xml:259
+#, no-c-format
+msgid ""
+ "public interface ConstraintValidatorFactory {\n"
+ " /**\n"
+ " * @param key The class of the constraint validator to instantiate.\n"
+ " *\n"
+ " * @return A constraint validator instance of the specified class.\n"
+ " */\n"
+ " <T extends ConstraintValidator<?,?>> T getInstance(Class<T> key);\n"
+ "}"
+msgstr ""
+
+#. Tag: para
+#: bootstrapping.xml:263
+#, no-c-format
+msgid "Any constraint implementation relying on <classname>ConstraintValidatorFactory</classname> behaviors specific to an implementation (dependency injection, no no-arg constructor and so on) are not considered portable."
+msgstr ""
+
+#. Tag: para
+#: bootstrapping.xml:270
+#, no-c-format
+msgid "ConstraintValidatorFactory should not cache instances as the state of each instance can be altered in the initialize method."
+msgstr ""
+
Added: validator/trunk/hibernate-validator/src/main/docbook/pot/modules/customconstraints.pot
===================================================================
--- validator/trunk/hibernate-validator/src/main/docbook/pot/modules/customconstraints.pot (rev 0)
+++ validator/trunk/hibernate-validator/src/main/docbook/pot/modules/customconstraints.pot 2010-07-06 15:18:26 UTC (rev 19904)
@@ -0,0 +1,675 @@
+# SOME DESCRIPTIVE TITLE.
+# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
+#
+#, fuzzy
+msgid ""
+msgstr ""
+"Project-Id-Version: PACKAGE VERSION\n"
+"Report-Msgid-Bugs-To: http://bugs.kde.org\n"
+"POT-Creation-Date: 2010-07-06 14:46+0000\n"
+"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
+"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
+"Language-Team: LANGUAGE <kde-i18n-doc(a)kde.org>\n"
+"MIME-Version: 1.0\n"
+"Content-Type: application/x-xml2pot; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+
+#. Tag: title
+#: customconstraints.xml:25
+#, no-c-format
+msgid "Creating custom constraints"
+msgstr ""
+
+#. Tag: para
+#: customconstraints.xml:27
+#, no-c-format
+msgid "Though the Bean Validation API defines a whole set of standard constraint annotations one can easily think of situations in which these standard annotations won't suffice. For these cases you are able to create custom constraints tailored to your specific validation requirements in a simple manner."
+msgstr ""
+
+#. Tag: title
+#: customconstraints.xml:34
+#, no-c-format
+msgid "Creating a simple constraint"
+msgstr ""
+
+#. Tag: para
+#: customconstraints.xml:36
+#, no-c-format
+msgid "To create a custom constraint, the following three steps are required:"
+msgstr ""
+
+#. Tag: para
+#: customconstraints.xml:41
+#, no-c-format
+msgid "Create a constraint annotation"
+msgstr ""
+
+#. Tag: para
+#: customconstraints.xml:45
+#, no-c-format
+msgid "Implement a validator"
+msgstr ""
+
+#. Tag: para
+#: customconstraints.xml:49
+#, no-c-format
+msgid "Define a default error message"
+msgstr ""
+
+#. Tag: title
+#: customconstraints.xml:54
+#, no-c-format
+msgid "The constraint annotation"
+msgstr ""
+
+#. Tag: para
+#: customconstraints.xml:56
+#, no-c-format
+msgid "Let's write a constraint annotation, that can be used to express that a given string shall either be upper case or lower case. We'll apply it later on to the <property>licensePlate</property> field of the <classname>Car</classname> class from <xref linkend=\"validator-gettingstarted\"/> to ensure, that the field is always an upper-case string."
+msgstr ""
+
+#. Tag: para
+#: customconstraints.xml:63
+#, no-c-format
+msgid "First we need a way to express the two case modes. We might use <classname>String</classname> constants, but a better way to go is to use a Java 5 enum for that purpose:"
+msgstr ""
+
+#. Tag: title
+#: customconstraints.xml:68
+#, no-c-format
+msgid "Enum <classname>CaseMode</classname> to express upper vs. lower case"
+msgstr ""
+
+#. Tag: programlisting
+#: customconstraints.xml:71
+#, no-c-format
+msgid ""
+ "package com.mycompany;\n"
+ "\n"
+ "public enum CaseMode {\n"
+ " UPPER, \n"
+ " LOWER;\n"
+ "}"
+msgstr ""
+
+#. Tag: para
+#: customconstraints.xml:74
+#, no-c-format
+msgid "Now we can define the actual constraint annotation. If you've never designed an annotation before, this may look a bit scary, but actually it's not that hard:"
+msgstr ""
+
+#. Tag: title
+#: customconstraints.xml:79
+#, no-c-format
+msgid "Defining CheckCase constraint annotation"
+msgstr ""
+
+#. Tag: programlisting
+#: customconstraints.xml:81
+#, no-c-format
+msgid ""
+ "package com.mycompany;\n"
+ "\n"
+ "import static java.lang.annotation.ElementType.*;\n"
+ "import static java.lang.annotation.RetentionPolicy.*;\n"
+ "\n"
+ "import java.lang.annotation.Documented;\n"
+ "import java.lang.annotation.Retention;\n"
+ "import java.lang.annotation.Target;\n"
+ "\n"
+ "import javax.validation.Constraint;\n"
+ "import javax.validation.Payload;\n"
+ "\n"
+ "@Target( { METHOD, FIELD, ANNOTATION_TYPE })\n"
+ "@Retention(RUNTIME)\n"
+ "@Constraint(validatedBy = CheckCaseValidator.class)\n"
+ "@Documented\n"
+ "public @interface CheckCase {\n"
+ "\n"
+ " String message() default \"{com.mycompany.constraints.checkcase}\";\n"
+ "\n"
+ " Class<?>[] groups() default {};\n"
+ "\n"
+ " Class<? extends Payload>[] payload() default {};\n"
+ " \n"
+ " CaseMode value();\n"
+ "\n"
+ "}"
+msgstr ""
+
+#. Tag: para
+#: customconstraints.xml:84
+#, no-c-format
+msgid "An annotation type is defined using the <code>@interface</code> keyword. All attributes of an annotation type are declared in a method-like manner. The specification of the Bean Validation API demands, that any constraint annotation defines"
+msgstr ""
+
+#. Tag: para
+#: customconstraints.xml:91
+#, no-c-format
+msgid "an attribute <property>message</property> that returns the default key for creating error messages in case the constraint is violated"
+msgstr ""
+
+#. Tag: para
+#: customconstraints.xml:97
+#, no-c-format
+msgid "an attribute <property>groups</property> that allows the specification of validation groups, to which this constraint belongs (see <xref linkend=\"validator-usingvalidator-validationgroups\"/>). This must default to an empty array of type <classname>Class<?></classname>."
+msgstr ""
+
+#. Tag: para
+#: customconstraints.xml:105
+#, no-c-format
+msgid "an attribute <classname>payload</classname> that can be used by clients of the Bean Validation API to assign custom payload objects to a constraint. This attribute is not used by the API itself."
+msgstr ""
+
+#. Tag: para
+#: customconstraints.xml:109
+#, no-c-format
+msgid "An example for a custom payload could be the definition of a severity."
+msgstr ""
+
+#. Tag: programlisting
+#: customconstraints.xml:112
+#, no-c-format
+msgid ""
+ "public class Severity {\n"
+ " public static class Info extends Payload {};\n"
+ " public static class Error extends Payload {};\n"
+ "}\n"
+ "\n"
+ "public class ContactDetails {\n"
+ " @NotNull(message=\"Name is mandatory\", payload=Severity.Error.class)\n"
+ " private String name;\n"
+ "\n"
+ " @NotNull(message=\"Phone number not specified, but not mandatory\", payload=Severity.Info.class)\n"
+ " private String phoneNumber;\n"
+ "\n"
+ " // ...\n"
+ "}"
+msgstr ""
+
+#. Tag: para
+#: customconstraints.xml:114
+#, no-c-format
+msgid "Now a client can after the validation of a <classname>ContactDetails</classname> instance access the severity of a constraint using <methodname>ConstraintViolation.getConstraintDescriptor().getPayload()</methodname> and adjust its behaviour depending on the severity."
+msgstr ""
+
+#. Tag: para
+#: customconstraints.xml:123
+#, no-c-format
+msgid "Besides those three mandatory attributes (<property>message</property>, <property>groups</property> and <property>payload</property>) we add another one allowing for the required case mode to be specified. The name <property>value</property> is a special one, which can be omitted upon using the annotation, if it is the only attribute specified, as e.g. in <code>@CheckCase(CaseMode.UPPER)</code>."
+msgstr ""
+
+#. Tag: para
+#: customconstraints.xml:131
+#, no-c-format
+msgid "In addition we annotate the annotation type with a couple of so-called meta annotations:"
+msgstr ""
+
+#. Tag: para
+#: customconstraints.xml:136
+#, no-c-format
+msgid "<code>@Target({ METHOD, FIELD, ANNOTATION_TYPE })</code>: Says, that methods, fields and annotation declarations may be annotated with @CheckCase (but not type declarations e.g.)"
+msgstr ""
+
+#. Tag: para
+#: customconstraints.xml:142
+#, no-c-format
+msgid "<code>@Retention(RUNTIME)</code>: Specifies, that annotations of this type will be available at runtime by the means of reflection"
+msgstr ""
+
+#. Tag: para
+#: customconstraints.xml:148
+#, no-c-format
+msgid "<code>@Constraint(validatedBy = CheckCaseValidator.class)</code>: Specifies the validator to be used to validate elements annotated with @CheckCase"
+msgstr ""
+
+#. Tag: para
+#: customconstraints.xml:154
+#, no-c-format
+msgid "<code>@Documented</code>: Says, that the use of <code>@CheckCase</code> will be contained in the JavaDoc of elements annotated with it"
+msgstr ""
+
+#. Tag: title
+#: customconstraints.xml:162
+#, no-c-format
+msgid "The constraint validator"
+msgstr ""
+
+#. Tag: para
+#: customconstraints.xml:165
+#, no-c-format
+msgid "Next, we need to implement a constraint validator, that's able to validate elements with a <classname>@CheckCase</classname> annotation. To do so, we implement the interface ConstraintValidator as shown below:"
+msgstr ""
+
+#. Tag: title
+#: customconstraints.xml:171
+#, no-c-format
+msgid "Implementing a constraint validator for the constraint <classname>CheckCase</classname>"
+msgstr ""
+
+#. Tag: programlisting
+#: customconstraints.xml:174
+#, no-c-format
+msgid ""
+ "package com.mycompany;\n"
+ "\n"
+ "import javax.validation.ConstraintValidator;\n"
+ "import javax.validation.ConstraintValidatorContext;\n"
+ "\n"
+ "public class CheckCaseValidator implements ConstraintValidator<CheckCase, String> {\n"
+ "\n"
+ " private CaseMode caseMode;\n"
+ "\n"
+ " public void initialize(CheckCase constraintAnnotation) {\n"
+ " this.caseMode = constraintAnnotation.value();\n"
+ " }\n"
+ "\n"
+ " public boolean isValid(String object, ConstraintValidatorContext constraintContext) {\n"
+ "\n"
+ " if (object == null)\n"
+ " return true;\n"
+ "\n"
+ " if (caseMode == CaseMode.UPPER)\n"
+ " return object.equals(object.toUpperCase());\n"
+ " else\n"
+ " return object.equals(object.toLowerCase());\n"
+ " }\n"
+ "\n"
+ "}"
+msgstr ""
+
+#. Tag: para
+#: customconstraints.xml:177
+#, no-c-format
+msgid "The <classname>ConstraintValidator</classname> interface defines two type parameters, which we set in our implementation. The first one specifies the annotation type to be validated (in our example <classname>CheckCase</classname>), the second one the type of elements, which the validator can handle (here <classname>String</classname>)."
+msgstr ""
+
+#. Tag: para
+#: customconstraints.xml:184
+#, no-c-format
+msgid "In case a constraint annotation is allowed at elements of different types, a <classname>ConstraintValidator</classname> for each allowed type has to be implemented and registered at the constraint annotation as shown above."
+msgstr ""
+
+#. Tag: para
+#: customconstraints.xml:189
+#, no-c-format
+msgid "The implementation of the validator is straightforward. The <methodname>initialize()</methodname> method gives us access to the attribute values of the annotation to be validated. In the example we store the <classname>CaseMode</classname> in a field of the validator for further usage."
+msgstr ""
+
+#. Tag: para
+#: customconstraints.xml:195
+#, no-c-format
+msgid "In the <methodname>isValid()</methodname> method we implement the logic, that determines, whether a <classname>String</classname> is valid according to a given <classname>@CheckCase</classname> annotation or not. This decision depends on the case mode retrieved in <classname>initialize()</classname>. As the Bean Validation specification recommends, we consider <code>null</code> values as being valid. If <code>null</code> is not a valid value for an element, it should be annotated with <code>@NotNull</code> explicitly."
+msgstr ""
+
+#. Tag: title
+#: customconstraints.xml:205
+#, no-c-format
+msgid "The ConstraintValidatorContext"
+msgstr ""
+
+#. Tag: para
+#: customconstraints.xml:207
+#, no-c-format
+msgid "relies on the default error message generation by just returning <constant>true</constant> or <constant>false</constant> from the <methodname>isValid</methodname> call. Using the passed <classname>ConstraintValidatorContext</classname> object it is possible to either add additional error messages or completely disable the default error message generation and solely define custom error messages. The <classname>ConstraintValidatorContext</classname> API is modeled as fluent interface and is best demonstrated with an example:"
+msgstr ""
+
+#. Tag: title
+#: customconstraints.xml:219
+#, no-c-format
+msgid "Use of ConstraintValidatorContext to define custom error messages"
+msgstr ""
+
+#. Tag: programlisting
+#: customconstraints.xml:222
+#, no-c-format
+msgid ""
+ "package com.mycompany;\n"
+ "\n"
+ "import javax.validation.ConstraintValidator;\n"
+ "import javax.validation.ConstraintValidatorContext;\n"
+ "\n"
+ "public class CheckCaseValidator implements ConstraintValidator<CheckCase, String> {\n"
+ "\n"
+ " private CaseMode caseMode;\n"
+ "\n"
+ " public void initialize(CheckCase constraintAnnotation) {\n"
+ " this.caseMode = constraintAnnotation.value();\n"
+ " }\n"
+ "\n"
+ " public boolean isValid(String object, ConstraintValidatorContext constraintContext) {\n"
+ "\n"
+ " if (object == null)\n"
+ " return true;\n"
+ " \n"
+ " boolean isValid;\n"
+ " if (caseMode == CaseMode.UPPER) {\n"
+ " isValid = object.equals(object.toUpperCase());\n"
+ " }\n"
+ " else {\n"
+ " isValid = object.equals(object.toLowerCase());\n"
+ " }\n"
+ " \n"
+ " if(!isValid) {\n"
+ " constraintContext.disableDefaultConstraintViolation();\n"
+ " constraintContext.buildConstraintViolationWithTemplate( \"{com.mycompany.constraints.CheckCase.message}\" ).addConstraintViolation();\n"
+ " }\n"
+ " return result;\n"
+ " }\n"
+ "\n"
+ "}"
+msgstr ""
+
+#. Tag: para
+#: customconstraints.xml:225
+#, no-c-format
+msgid "shows how you can disable the default error message generation and add a custom error message using a specified message template. In this example the use of the <classname>ConstraintValidatorContext</classname> results in the same error message as the default error message generation."
+msgstr ""
+
+#. Tag: para
+#: customconstraints.xml:231
+#, no-c-format
+msgid "It is important to end each new constraint violation with <methodname>addConstraintViolation</methodname>. Only after that the new constraint violation will be created."
+msgstr ""
+
+#. Tag: para
+#: customconstraints.xml:236
+#, no-c-format
+msgid "In case you are implementing a <classname>ConstraintValidator</classname> a class level constraint it is also possible to adjust set the property path for the created constraint violations. This is important for the case where you validate multiple properties of the class or even traverse the object graph. A custom property path creation could look like <xref linkend=\"example-custom-error\"/>."
+msgstr ""
+
+#. Tag: title
+#: customconstraints.xml:245
+#, no-c-format
+msgid "Adding new <classname>ConstraintViolation</classname> with custom property path"
+msgstr ""
+
+#. Tag: programlisting
+#: customconstraints.xml:248
+#, no-c-format
+msgid ""
+ "public boolean isValid(Group group, ConstraintValidatorContext constraintValidatorContext) {\n"
+ " boolean isValid = false;\n"
+ " ...\n"
+ "\n"
+ " if(!isValid) {\n"
+ " constraintValidatorContext\n"
+ " .buildConstraintViolationWithTemplate( \"{my.custom.template}\" )\n"
+ " .addNode( \"myProperty\" ).addConstraintViolation();\n"
+ " }\n"
+ " return isValid;\n"
+ "}"
+msgstr ""
+
+#. Tag: title
+#: customconstraints.xml:254
+#, no-c-format
+msgid "The error message"
+msgstr ""
+
+#. Tag: para
+#: customconstraints.xml:256
+#, no-c-format
+msgid "Finally we need to specify the error message, that shall be used, in case a <classname>@CheckCase</classname> constraint is violated. To do so, we add the following to our custom <filename>ValidationMessages.properties</filename> (see also <xref linkend=\"section-message-interpolation\"/>)"
+msgstr ""
+
+#. Tag: title
+#: customconstraints.xml:263
+#, no-c-format
+msgid "Defining a custom error message for the <classname>CheckCase</classname> constraint"
+msgstr ""
+
+#. Tag: programlisting
+#: customconstraints.xml:266
+#, no-c-format
+msgid "com.mycompany.constraints.CheckCase.message=Case mode must be {value}."
+msgstr ""
+
+#. Tag: para
+#: customconstraints.xml:269
+#, no-c-format
+msgid "If a validation error occurs, the validation runtime will use the default value, that we specified for the message attribute of the <classname>@CheckCase</classname> annotation to look up the error message in this file."
+msgstr ""
+
+#. Tag: title
+#: customconstraints.xml:276
+#, no-c-format
+msgid "Using the constraint"
+msgstr ""
+
+#. Tag: para
+#: customconstraints.xml:278
+#, no-c-format
+msgid "Now that our first custom constraint is completed, we can use it in the <classname>Car</classname> class from the <xref linkend=\"validator-gettingstarted\"/> chapter to specify that the <property>licensePlate</property> field shall only contain upper-case strings:"
+msgstr ""
+
+#. Tag: title
+#: customconstraints.xml:285
+#, no-c-format
+msgid "Applying the <classname>CheckCase</classname> constraint"
+msgstr ""
+
+#. Tag: programlisting
+#: customconstraints.xml:288
+#, no-c-format
+msgid ""
+ "package com.mycompany;\n"
+ "\n"
+ "import javax.validation.constraints.Min;\n"
+ "import javax.validation.constraints.NotNull;\n"
+ "import javax.validation.constraints.Size;\n"
+ "\n"
+ "public class Car {\n"
+ "\n"
+ " @NotNull\n"
+ " private String manufacturer;\n"
+ "\n"
+ " @NotNull\n"
+ " @Size(min = 2, max = 14)\n"
+ " @CheckCase(CaseMode.UPPER)\n"
+ " private String licensePlate;\n"
+ "\n"
+ " @Min(2)\n"
+ " private int seatCount;\n"
+ " \n"
+ " public Car(String manufacturer, String licencePlate, int seatCount) {\n"
+ "\n"
+ " this.manufacturer = manufacturer;\n"
+ " this.licensePlate = licencePlate;\n"
+ " this.seatCount = seatCount;\n"
+ " }\n"
+ "\n"
+ " //getters and setters ...\n"
+ "\n"
+ "}"
+msgstr ""
+
+#. Tag: para
+#: customconstraints.xml:291
+#, no-c-format
+msgid "Finally let's demonstrate in a little test that the <classname>@CheckCase</classname> constraint is properly validated:"
+msgstr ""
+
+#. Tag: title
+#: customconstraints.xml:296
+#, no-c-format
+msgid "Testcase demonstrating the <classname>CheckCase</classname> validation"
+msgstr ""
+
+#. Tag: programlisting
+#: customconstraints.xml:299
+#, no-c-format
+msgid ""
+ "package com.mycompany;\n"
+ "\n"
+ "import static org.junit.Assert.*;\n"
+ "\n"
+ "import java.util.Set;\n"
+ "\n"
+ "import javax.validation.ConstraintViolation;\n"
+ "import javax.validation.Validation;\n"
+ "import javax.validation.Validator;\n"
+ "import javax.validation.ValidatorFactory;\n"
+ "\n"
+ "import org.junit.BeforeClass;\n"
+ "import org.junit.Test;\n"
+ "\n"
+ "public class CarTest {\n"
+ "\n"
+ " private static Validator validator;\n"
+ "\n"
+ " @BeforeClass\n"
+ " public static void setUp() {\n"
+ " ValidatorFactory factory = Validation.buildDefaultValidatorFactory();\n"
+ " validator = factory.getValidator();\n"
+ " }\n"
+ "\n"
+ " @Test\n"
+ " public void testLicensePlateNotUpperCase() {\n"
+ "\n"
+ " Car car = new Car(\"Morris\", \"dd-ab-123\", 4);\n"
+ "\n"
+ " Set<ConstraintViolation<Car>> constraintViolations =\n"
+ " validator.validate(car);\n"
+ " assertEquals(1, constraintViolations.size());\n"
+ " assertEquals(\n"
+ " \"Case mode must be UPPER.\", \n"
+ " constraintViolations.iterator().next().getMessage());\n"
+ " }\n"
+ "\n"
+ " @Test\n"
+ " public void carIsValid() {\n"
+ "\n"
+ " Car car = new Car(\"Morris\", \"DD-AB-123\", 4);\n"
+ "\n"
+ " Set<ConstraintViolation<Car>> constraintViolations =\n"
+ " validator.validate(car);\n"
+ "\n"
+ " assertEquals(0, constraintViolations.size());\n"
+ " }\n"
+ "}"
+msgstr ""
+
+#. Tag: title
+#: customconstraints.xml:305
+#, no-c-format
+msgid "Constraint composition"
+msgstr ""
+
+#. Tag: para
+#: customconstraints.xml:307
+#, no-c-format
+msgid "Looking at the <property>licensePlate</property> field of the <classname>Car</classname> class in <xref linkend=\"example-car-with-checkcase\"/>, we see three constraint annotations already. In complexer scenarios, where even more constraints could be applied to one element, this might become a bit confusing easily. Furthermore, if we had a <property>licensePlate</property> field in another class, we would have to copy all constraint declarations to the other class as well, violating the DRY principle."
+msgstr ""
+
+#. Tag: para
+#: customconstraints.xml:316
+#, no-c-format
+msgid "This problem can be tackled using compound constraints. In the following we create a new constraint annotation <classname>@ValidLicensePlate</classname>, that comprises the constraints <classname>@NotNull</classname>, <classname>@Size</classname> and <classname>@CheckCase</classname>:"
+msgstr ""
+
+#. Tag: title
+#: customconstraints.xml:323
+#, no-c-format
+msgid "Creating a composing constraint <classname>ValidLicensePlate</classname>"
+msgstr ""
+
+#. Tag: programlisting
+#: customconstraints.xml:326
+#, no-c-format
+msgid ""
+ "package com.mycompany;\n"
+ "\n"
+ "import static java.lang.annotation.ElementType.*;\n"
+ "import static java.lang.annotation.RetentionPolicy.*;\n"
+ "\n"
+ "import java.lang.annotation.Documented;\n"
+ "import java.lang.annotation.Retention;\n"
+ "import java.lang.annotation.Target;\n"
+ "\n"
+ "import javax.validation.Constraint;\n"
+ "import javax.validation.Payload;\n"
+ "import javax.validation.constraints.NotNull;\n"
+ "import javax.validation.constraints.Size;\n"
+ "\n"
+ "@NotNull\n"
+ "@Size(min = 2, max = 14)\n"
+ "@CheckCase(CaseMode.UPPER)\n"
+ "@Target( { METHOD, FIELD, ANNOTATION_TYPE })\n"
+ "@Retention(RUNTIME)\n"
+ "@Constraint(validatedBy = {})\n"
+ "@Documented\n"
+ "public @interface ValidLicensePlate {\n"
+ "\n"
+ " String message() default \"{com.mycompany.constraints.validlicenseplate}\";\n"
+ "\n"
+ " Class<?>[] groups() default {};\n"
+ "\n"
+ " Class<? extends Payload>[] payload() default {};\n"
+ "\n"
+ "}"
+msgstr ""
+
+#. Tag: para
+#: customconstraints.xml:329
+#, no-c-format
+msgid "To do so, we just have to annotate the constraint declaration with its comprising constraints (btw. that's exactly why we allowed annotation types as target for the <classname>@CheckCase</classname> annotation). As no additional validation is required for the <classname>@ValidLicensePlate</classname> annotation itself, we don't declare a validator within the <classname>@Constraint </classname>meta annotation."
+msgstr ""
+
+#. Tag: para
+#: customconstraints.xml:337
+#, no-c-format
+msgid "Using the new compound constraint at the <property>licensePlate</property> field now is fully equivalent to the previous version, where we declared the three constraints directly at the field itself:"
+msgstr ""
+
+#. Tag: title
+#: customconstraints.xml:343
+#, no-c-format
+msgid "Application of composing constraint <classname>ValidLicensePlate</classname>"
+msgstr ""
+
+#. Tag: programlisting
+#: customconstraints.xml:346
+#, no-c-format
+msgid ""
+ "package com.mycompany;\n"
+ "\n"
+ "public class Car {\n"
+ "\n"
+ " @ValidLicensePlate\n"
+ " private String licensePlate;\n"
+ "\n"
+ " //...\n"
+ "\n"
+ "}"
+msgstr ""
+
+#. Tag: para
+#: customconstraints.xml:349
+#, no-c-format
+msgid "The set of <classname>ConstraintViolations</classname> retrieved when validating a <classname>Car</classname> instance will contain an entry for each violated composing constraint of the <classname>@ValidLicensePlate</classname> constraint. If you rather prefer a single <classname>ConstraintViolation</classname> in case any of the composing constraints is violated, the <classname>@ReportAsSingleViolation</classname> meta constraint can be used as follows:"
+msgstr ""
+
+#. Tag: title
+#: customconstraints.xml:359
+#, no-c-format
+msgid "Usage of <classname>@ReportAsSingleViolation</classname>"
+msgstr ""
+
+#. Tag: programlisting
+#: customconstraints.xml:361
+#, no-c-format
+msgid ""
+ "//...\n"
+ "@ReportAsSingleViolation\n"
+ "public @interface ValidLicensePlate {\n"
+ "\n"
+ " String message() default \"{com.mycompany.constraints.validlicenseplate}\";\n"
+ "\n"
+ " Class<?>[] groups() default {};\n"
+ "\n"
+ " Class<? extends Payload>[] payload() default {};\n"
+ "\n"
+ "}"
+msgstr ""
+
Added: validator/trunk/hibernate-validator/src/main/docbook/pot/modules/furtherreading.pot
===================================================================
--- validator/trunk/hibernate-validator/src/main/docbook/pot/modules/furtherreading.pot (rev 0)
+++ validator/trunk/hibernate-validator/src/main/docbook/pot/modules/furtherreading.pot 2010-07-06 15:18:26 UTC (rev 19904)
@@ -0,0 +1,40 @@
+# SOME DESCRIPTIVE TITLE.
+# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
+#
+#, fuzzy
+msgid ""
+msgstr ""
+"Project-Id-Version: PACKAGE VERSION\n"
+"Report-Msgid-Bugs-To: http://bugs.kde.org\n"
+"POT-Creation-Date: 2010-07-06 14:46+0000\n"
+"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
+"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
+"Language-Team: LANGUAGE <kde-i18n-doc(a)kde.org>\n"
+"MIME-Version: 1.0\n"
+"Content-Type: application/x-xml2pot; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+
+#. Tag: title
+#: furtherreading.xml:25
+#, no-c-format
+msgid "Further reading"
+msgstr ""
+
+#. Tag: para
+#: furtherreading.xml:27
+#, no-c-format
+msgid "Last but not least, a few pointers to further information. A great source for examples is the Bean Validation TCK which can is available for anonymous access in the Hibernate <ulink url=\"http://anonsvn.jboss.org/repos/hibernate/validator/trunk\">SVN repository</ulink>. Alternatively you can view the tests using <ulink url=\"http://fisheye.jboss.org/browse/Hibernate/beanvalidation/trunk/validation...">Hibernate's fisheye</ulink> installation. <ulink url=\"http://jcp.org/en/jsr/detail?id=303\">The JSR 303</ulink> specification itself is also a great way to deepen your understanding of Bean Validation resp. Hibernate Validator."
+msgstr ""
+
+#. Tag: para
+#: furtherreading.xml:38
+#, no-c-format
+msgid "If you have any further questions to Hibernate Validator or want to share some of your use cases have a look at the <ulink url=\"http://community.jboss.org/en/hibernate/validator\">Hibernate Validator Wiki</ulink> and the <ulink url=\"https://forum.hibernate.org/viewforum.php?f=9\">Hibernate Validator Forum</ulink>."
+msgstr ""
+
+#. Tag: para
+#: furtherreading.xml:45
+#, no-c-format
+msgid "In case you would like to report a bug use <ulink url=\"http://opensource.atlassian.com/projects/hibernate/browse/HV\">Hibernate's Jira</ulink> instance. Feedback is always welcome!"
+msgstr ""
+
Added: validator/trunk/hibernate-validator/src/main/docbook/pot/modules/gettingstarted.pot
===================================================================
--- validator/trunk/hibernate-validator/src/main/docbook/pot/modules/gettingstarted.pot (rev 0)
+++ validator/trunk/hibernate-validator/src/main/docbook/pot/modules/gettingstarted.pot 2010-07-06 15:18:26 UTC (rev 19904)
@@ -0,0 +1,347 @@
+# SOME DESCRIPTIVE TITLE.
+# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
+#
+#, fuzzy
+msgid ""
+msgstr ""
+"Project-Id-Version: PACKAGE VERSION\n"
+"Report-Msgid-Bugs-To: http://bugs.kde.org\n"
+"POT-Creation-Date: 2010-07-06 14:51+0000\n"
+"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
+"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
+"Language-Team: LANGUAGE <kde-i18n-doc(a)kde.org>\n"
+"MIME-Version: 1.0\n"
+"Content-Type: application/x-xml2pot; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+
+#. Tag: title
+#: gettingstarted.xml:25
+#, no-c-format
+msgid "Getting started"
+msgstr ""
+
+#. Tag: para
+#: gettingstarted.xml:27
+#, no-c-format
+msgid "This chapter will show you how to get started with Hibernate Validator, the reference implementation (RI) of Bean Validation. For the following quickstart you need:"
+msgstr ""
+
+#. Tag: para
+#: gettingstarted.xml:33
+#, no-c-format
+msgid "A JDK >= 5"
+msgstr ""
+
+#. Tag: ulink
+#: gettingstarted.xml:37
+#, no-c-format
+msgid "Apache Maven"
+msgstr ""
+
+#. Tag: para
+#: gettingstarted.xml:41
+#, no-c-format
+msgid "An Internet connection (Maven has to download all required libraries)"
+msgstr ""
+
+#. Tag: para
+#: gettingstarted.xml:46
+#, no-c-format
+msgid ""
+ "A properly configured remote repository. Add the following to your <filename>settings.xml</filename>: <example> <title>Configuring the JBoss Maven repository in <filename>settings.xml</filename></title> <programlisting><repositories>\n"
+ " <repository>\n"
+ " <id>jboss</id>\n"
+ " <url>http://repository.jboss.com/maven2</url>\n"
+ " <releases>\n"
+ " <enabled>true</enabled>\n"
+ " </releases>\n"
+ " <snapshots>\n"
+ " <enabled>false</enabled>\n"
+ " </snapshots>\n"
+ " </repository>\n"
+ "</repositories></programlisting> </example>More information about <filename>settings.xml</filename> can be found in the <ulink url=\"http://maven.apache.org/ref/2.0.8/maven-settings/settings.html\">Maven Local Settings Model</ulink>."
+msgstr ""
+
+#. Tag: para
+#: gettingstarted.xml:60
+#, no-c-format
+msgid ""
+ "Hibernate Validator uses JAXB for XML parsing. JAXB is part of the Java Class Library since Java 6 which means that if you run Hibernate Validator with Java 5 you will have to add additional JAXB dependencies. Using maven you have to add the following dependencies:<programlisting><dependency>\n"
+ " <groupId>javax.xml.bind</groupId>\n"
+ " <artifactId>jaxb-api</artifactId>\n"
+ " <version>2.2</version>\n"
+ "</dependency>\n"
+ "<dependency>\n"
+ " <groupId>com.sun.xml.bind</groupId>\n"
+ " <artifactId>jaxb-impl</artifactId>\n"
+ " <version>2.1.12</version>\n"
+ "</dependency>\n"
+ "</programlisting> if you are using the SourceForge package you find the necessary libraries in the <filename>lib/jdk5</filename> directory. In case you are not using the XML configuration you can also disable it explicitly by calling <methodname>Configuration.ignoreXmlConfiguration()</methodname> during <classname>ValidationFactory</classname> creation. In this case the JAXB dependencies are not needed."
+msgstr ""
+
+#. Tag: title
+#: gettingstarted.xml:73
+#, no-c-format
+msgid "Setting up a new Maven project"
+msgstr ""
+
+#. Tag: para
+#: gettingstarted.xml:75
+#, no-c-format
+msgid "Start by creating new Maven project using the Maven archetype plugin as follows:"
+msgstr ""
+
+#. Tag: title
+#: gettingstarted.xml:79
+#, no-c-format
+msgid "Using Maven's archetype plugin to create a sample project using Hibernate Validator"
+msgstr ""
+
+#. Tag: programlisting
+#: gettingstarted.xml:82
+#, no-c-format
+msgid ""
+ "mvn archetype:create -DarchetypeGroupId=org.hibernate \\\n"
+ " -DarchetypeArtifactId=hibernate-validator-quickstart-archetype \\\n"
+ " -DarchetypeVersion=&version; \\\n"
+ " -DgroupId=com.mycompany \n"
+ " -DartifactId=hv-quickstart"
+msgstr ""
+
+#. Tag: para
+#: gettingstarted.xml:85
+#, no-c-format
+msgid "Maven will create your project in the directory hv-quickstart. Change into this directory and run:"
+msgstr ""
+
+#. Tag: programlisting
+#: gettingstarted.xml:88
+#, no-c-format
+msgid "mvn test"
+msgstr ""
+
+#. Tag: para
+#: gettingstarted.xml:88
+#, no-c-format
+msgid "Maven will compile the example code and run the implemented unit tests. Let's have a look at the actual code."
+msgstr ""
+
+#. Tag: title
+#: gettingstarted.xml:94
+#, no-c-format
+msgid "Applying constraints"
+msgstr ""
+
+#. Tag: para
+#: gettingstarted.xml:96
+#, no-c-format
+msgid "Open the project in the IDE of your choice and have a look at the class <classname>Car</classname>:"
+msgstr ""
+
+#. Tag: title
+#: gettingstarted.xml:100
+#, no-c-format
+msgid "Class Car annotated with constraints"
+msgstr ""
+
+#. Tag: programlisting
+#: gettingstarted.xml:102
+#, no-c-format
+msgid ""
+ "package com.mycompany;\n"
+ "\n"
+ "import javax.validation.constraints.Min;\n"
+ "import javax.validation.constraints.NotNull;\n"
+ "import javax.validation.constraints.Size;\n"
+ "\n"
+ "public class Car {\n"
+ "\n"
+ " @NotNull\n"
+ " private String manufacturer;\n"
+ "\n"
+ " @NotNull\n"
+ " @Size(min = 2, max = 14)\n"
+ " private String licensePlate;\n"
+ "\n"
+ " @Min(2)\n"
+ " private int seatCount;\n"
+ " \n"
+ " public Car(String manufacturer, String licencePlate, int seatCount) {\n"
+ " this.manufacturer = manufacturer;\n"
+ " this.licensePlate = licencePlate;\n"
+ " this.seatCount = seatCount;\n"
+ " }\n"
+ "\n"
+ " //getters and setters ...\n"
+ "}"
+msgstr ""
+
+#. Tag: para
+#: gettingstarted.xml:105
+#, no-c-format
+msgid "<classname>@NotNull</classname>, <classname>@Size</classname> and <classname>@Min</classname> are so-called constraint annotations, that we use to declare constraints, which shall be applied to the fields of a <classname>Car</classname> instance:"
+msgstr ""
+
+#. Tag: para
+#: gettingstarted.xml:112
+#, no-c-format
+msgid "<property>manufacturer</property> shall never be null"
+msgstr ""
+
+#. Tag: para
+#: gettingstarted.xml:116
+#, no-c-format
+msgid "<property>licensePlate</property> shall never be null and must be between 2 and 14 characters long"
+msgstr ""
+
+#. Tag: para
+#: gettingstarted.xml:121
+#, no-c-format
+msgid "<property>seatCount</property> shall be at least 2."
+msgstr ""
+
+#. Tag: title
+#: gettingstarted.xml:127
+#, no-c-format
+msgid "Validating constraints"
+msgstr ""
+
+#. Tag: para
+#: gettingstarted.xml:129
+#, no-c-format
+msgid "To perform a validation of these constraints, we use a <classname>Validator</classname> instance. Let's have a look at the <classname>CarTest</classname> class:"
+msgstr ""
+
+#. Tag: title
+#: gettingstarted.xml:134
+#, no-c-format
+msgid "Class CarTest showing validation examples"
+msgstr ""
+
+#. Tag: programlisting
+#: gettingstarted.xml:136
+#, no-c-format
+msgid ""
+ "package com.mycompany;\n"
+ "\n"
+ "import static org.junit.Assert.*;\n"
+ "\n"
+ "import java.util.Set;\n"
+ "\n"
+ "import javax.validation.ConstraintViolation;\n"
+ "import javax.validation.Validation;\n"
+ "import javax.validation.Validator;\n"
+ "import javax.validation.ValidatorFactory;\n"
+ "\n"
+ "import org.junit.BeforeClass;\n"
+ "import org.junit.Test;\n"
+ "\n"
+ "public class CarTest {\n"
+ "\n"
+ " private static Validator validator;\n"
+ "\n"
+ " @BeforeClass\n"
+ " public static void setUp() {\n"
+ " ValidatorFactory factory = Validation.buildDefaultValidatorFactory();\n"
+ " validator = factory.getValidator();\n"
+ " }\n"
+ "\n"
+ " @Test\n"
+ " public void manufacturerIsNull() {\n"
+ " Car car = new Car(null, \"DD-AB-123\", 4);\n"
+ "\n"
+ " Set<ConstraintViolation<Car>> constraintViolations =\n"
+ " validator.validate(car);\n"
+ "\n"
+ " assertEquals(1, constraintViolations.size());\n"
+ " assertEquals(\"may not be null\", constraintViolations.iterator().next().getMessage());\n"
+ " }\n"
+ "\n"
+ " @Test\n"
+ " public void licensePlateTooShort() {\n"
+ " Car car = new Car(\"Morris\", \"D\", 4);\n"
+ "\n"
+ " Set<ConstraintViolation<Car>> constraintViolations = \n"
+ " validator.validate(car);\n"
+ "\n"
+ " assertEquals(1, constraintViolations.size());\n"
+ " assertEquals(\"size must be between 2 and 14\", constraintViolations.iterator().next().getMessage());\n"
+ " }\n"
+ " \n"
+ " @Test\n"
+ " public void seatCountTooLow() {\n"
+ " Car car = new Car(\"Morris\", \"DD-AB-123\", 1);\n"
+ "\n"
+ " Set<ConstraintViolation<Car>> constraintViolations =\n"
+ " validator.validate(car);\n"
+ "\n"
+ " assertEquals(1, constraintViolations.size());\n"
+ " assertEquals(\"must be greater than or equal to 2\", constraintViolations.iterator().next().getMessage());\n"
+ " }\n"
+ "\n"
+ " @Test\n"
+ " public void carIsValid() {\n"
+ " Car car = new Car(\"Morris\", \"DD-AB-123\", 2);\n"
+ "\n"
+ " Set<ConstraintViolation<Car>> constraintViolations =\n"
+ " validator.validate(car);\n"
+ "\n"
+ " assertEquals(0, constraintViolations.size());\n"
+ " }\n"
+ "}"
+msgstr ""
+
+#. Tag: para
+#: gettingstarted.xml:139
+#, no-c-format
+msgid "In the <methodname>setUp()</methodname> method we get a <classname>Validator</classname> instance from the <classname>ValidatorFactory</classname>. A <classname>Validator</classname> instance is thread-safe and may be reused multiple times. For this reason we store it as field of our test class. We can use the <classname>Validator</classname> now to validate the different car instances in the test methods."
+msgstr ""
+
+#. Tag: para
+#: gettingstarted.xml:147
+#, no-c-format
+msgid "The <methodname>validate()</methodname> method returns a set of <classname>ConstraintViolation</classname> instances, which we can iterate in order to see which validation errors occurred. The first three test methods show some expected constraint violations:"
+msgstr ""
+
+#. Tag: para
+#: gettingstarted.xml:154
+#, no-c-format
+msgid "The <classname>@NotNull</classname> constraint on manufacturer is violated in <methodname>manufacturerIsNull()</methodname>"
+msgstr ""
+
+#. Tag: para
+#: gettingstarted.xml:159
+#, no-c-format
+msgid "The <classname>@Size</classname> constraint on licensePlate is violated in <methodname>licensePlateTooShort()</methodname>"
+msgstr ""
+
+#. Tag: para
+#: gettingstarted.xml:164
+#, no-c-format
+msgid "The <classname>@Min</classname> constraint on seatCount is violated in <methodname>seatCountTooLow()</methodname>"
+msgstr ""
+
+#. Tag: para
+#: gettingstarted.xml:169
+#, no-c-format
+msgid "If the object validates successfully, <methodname>validate()</methodname> returns an empty set."
+msgstr ""
+
+#. Tag: para
+#: gettingstarted.xml:172
+#, no-c-format
+msgid "Note that we only use classes from the package <package>javax.validation</package> from the Bean Validation API. As we don't reference any classes of the RI directly, it would be no problem to switch to another implementation of the API, should that need arise."
+msgstr ""
+
+#. Tag: title
+#: gettingstarted.xml:180
+#, no-c-format
+msgid "Where to go next?"
+msgstr ""
+
+#. Tag: para
+#: gettingstarted.xml:182
+#, no-c-format
+msgid "That concludes our 5 minute tour through the world of Hibernate Validator. Continue exploring the code examples or look at further examples referenced in <xref linkend=\"chapter-further-reading\"/>. To deepen your understanding of Hibernate Validator just continue reading <xref linkend=\"validator-usingvalidator\"/>. In case your application has specific validation requirements have a look at <xref linkend=\"validator-customconstraints\"/>."
+msgstr ""
+
Added: validator/trunk/hibernate-validator/src/main/docbook/pot/modules/integration.pot
===================================================================
--- validator/trunk/hibernate-validator/src/main/docbook/pot/modules/integration.pot (rev 0)
+++ validator/trunk/hibernate-validator/src/main/docbook/pot/modules/integration.pot 2010-07-06 15:18:26 UTC (rev 19904)
@@ -0,0 +1,191 @@
+# SOME DESCRIPTIVE TITLE.
+# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
+#
+#, fuzzy
+msgid ""
+msgstr ""
+"Project-Id-Version: PACKAGE VERSION\n"
+"Report-Msgid-Bugs-To: http://bugs.kde.org\n"
+"POT-Creation-Date: 2010-07-06 14:46+0000\n"
+"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
+"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
+"Language-Team: LANGUAGE <kde-i18n-doc(a)kde.org>\n"
+"MIME-Version: 1.0\n"
+"Content-Type: application/x-xml2pot; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+
+#. Tag: title
+#: integration.xml:25
+#, no-c-format
+msgid "Integration with other frameworks"
+msgstr ""
+
+#. Tag: para
+#: integration.xml:27
+#, no-c-format
+msgid "Hibernate Validator is intended to be used to implement multi-layered data validation, where constraints are expressed in a single place (the annotated domain model) and checked in various different layers of the application."
+msgstr ""
+
+#. Tag: title
+#: integration.xml:33
+#, no-c-format
+msgid "OSGi"
+msgstr ""
+
+#. Tag: para
+#: integration.xml:35
+#, no-c-format
+msgid "The Hibernate Validator jar file is conform to the OSGi specification and can be used within any OSGi container. The classes in the following packages are exported by Hibernate Validator and are considered part of the public API - <package>org.hibernate.validator</package>, <package>org.hibernate.validator.constraints</package>, <package>org.hibernate.validator.messageinterpolation</package> and <package>org.hibernate.validator.resourceloading</package>."
+msgstr ""
+
+#. Tag: title
+#: integration.xml:46
+#, no-c-format
+msgid "Database schema-level validation"
+msgstr ""
+
+#. Tag: para
+#: integration.xml:48
+#, no-c-format
+msgid "Out of the box, Hibernate Annotations (as of Hibernate 3.5.x) will translate the constraints you have defined for your entities into mapping metadata. For example, if a property of your entity is annotated <literal>@NotNull</literal>, its columns will be declared as <literal>not null</literal> in the DDL schema generated by Hibernate."
+msgstr ""
+
+#. Tag: para
+#: integration.xml:54
+#, no-c-format
+msgid "If, for some reason, the feature needs to be disabled, set <literal>hibernate.validator.apply_to_ddl</literal> to <literal>false</literal>. See also <xref linkend=\"table-builtin-constraints\"/>."
+msgstr ""
+
+#. Tag: para
+#: integration.xml:59
+#, no-c-format
+msgid "You can also limit the DDL constraint generation to a subset of the defined constraints by setting the property <property>org.hibernate.validator.group.ddl</property>. The property specifies the comma-separated, fully specified class names of the groups a constraint has to be part of in order to be considered for DDL schema generation."
+msgstr ""
+
+#. Tag: title
+#: integration.xml:68
+#, no-c-format
+msgid "ORM integration"
+msgstr ""
+
+#. Tag: para
+#: integration.xml:70
+#, no-c-format
+msgid "Hibernate Validator integrates with both Hibernate and all pure Java Persistence providers."
+msgstr ""
+
+#. Tag: title
+#: integration.xml:74
+#, no-c-format
+msgid "Hibernate event-based validation"
+msgstr ""
+
+#. Tag: para
+#: integration.xml:76
+#, no-c-format
+msgid "Hibernate Validator has a built-in Hibernate event listener - <ulink url=\"http://fisheye.jboss.org/browse/Hibernate/core/trunk/annotations/src/main..."><classname>org.hibernate.cfg.beanvalidation.BeanValidationEventListener</classname></ulink> - which is part of Hibernate Annotations (as of Hibernate 3.5.x). Whenever a <literal>PreInsertEvent</literal>, <literal>PreUpdateEvent</literal> or <classname>PreDeleteEvent</classname> occurs, the listener will verify all constraints of the entity instance and throw an exception if any constraint is violated. Per default objects will be checked before any inserts or updates are made by Hibernate. Pre deletion events will per default not trigger a validation. You can configure the groups to be validated per event type using the properties <property>javax.persistence.validation.group.pre-persist</property>, <property>javax.persistence.validation.group.pre-upd!
ate</property> and <property>javax.persistence.validation.group.pre-remove</property>. The values of these properties are the comma-separated, fully specified class names of the groups to validate. <xref linkend=\"example-beanvalidationeventlistener-config\"/> shows the default values for these properties. In this case they could also be omitted."
+msgstr ""
+
+#. Tag: para
+#: integration.xml:97
+#, no-c-format
+msgid "On constraint violation, the event will raise a runtime <classname>ConstraintViolationException</classname> which contains a set of <literal>ConstraintViolation</literal>s describing each failure."
+msgstr ""
+
+#. Tag: para
+#: integration.xml:102
+#, no-c-format
+msgid "If Hibernate Validator is present in the classpath, Hibernate Annotations (or Hibernate EntityManager) will use it transparently. To avoid validation even though Hibernate Validator is in the classpath set <property>javax.persistence.validation.mode</property> to <constant>none</constant>."
+msgstr ""
+
+#. Tag: para
+#: integration.xml:109
+#, no-c-format
+msgid "If the beans are not annotated with validation annotations, there is no runtime performance cost."
+msgstr ""
+
+#. Tag: para
+#: integration.xml:113
+#, no-c-format
+msgid "In case you need to manually set the event listeners for Hibernate Core, use the following configuration in <literal>hibernate.cfg.xml</literal>:"
+msgstr ""
+
+#. Tag: title
+#: integration.xml:118
+#, no-c-format
+msgid "Manual configuration of <classname>BeanValidationEvenListener</classname>"
+msgstr ""
+
+#. Tag: programlisting
+#: integration.xml:121
+#, no-c-format
+msgid ""
+ "<hibernate-configuration>\n"
+ " <session-factory>\n"
+ " ...\n"
+ " <property name=\"javax.persistence.validation.group.pre-persist\">javax.validation.groups.Default</property>\n"
+ " <property name=\"javax.persistence.validation.group.pre-update\">javax.validation.groups.Default</property>\n"
+ " <property name=\"javax.persistence.validation.group.pre-remove\"></property>\n"
+ " ...\n"
+ " <event type=\"pre-update\">\n"
+ " <listener class=\"org.hibernate.cfg.beanvalidation.BeanValidationEventListener\"/>\n"
+ " </event>\n"
+ " <event type=\"pre-insert\">\n"
+ " <listener class=\"org.hibernate.cfg.beanvalidation.BeanValidationEventListener\"/>\n"
+ " </event>\n"
+ " <event type=\"pre-delete\">\n"
+ " <listener class=\"org.hibernate.cfg.beanvalidation.BeanValidationEventListener\"/>\n"
+ " </event>\n"
+ " </session-factory>\n"
+ "</hibernate-configuration>"
+msgstr ""
+
+#. Tag: title
+#: integration.xml:126
+#, no-c-format
+msgid "<title>JPA</title>"
+msgstr ""
+
+#. Tag: para
+#: integration.xml:128
+#, no-c-format
+msgid "If you are using JPA 2 and Hibernate Validator is in the classpath the JPA2 specification requires that Bean Validation gets enabled. The properties <property>javax.persistence.validation.group.pre-persist</property>, <property>javax.persistence.validation.group.pre-update</property> and <property>javax.persistence.validation.group.pre-remove</property> as described in <xref linkend=\"validator-checkconstraints-orm-hibernateevent\"/> can in this case be configured in <filename>persistence.xml</filename>. <filename>persistence.xml</filename> also defines a node validation-mode while can be set to <constant>AUTO</constant>, <constant>CALLBACK</constant>, <constant>NONE</constant>. The default is <constant>AUTO</constant>."
+msgstr ""
+
+#. Tag: para
+#: integration.xml:142
+#, no-c-format
+msgid "In a JPA 1 you will have to create and register Hibernate Validator yourself. In case you are using Hibernate EntityManager you can add a customized version of the <classname>BeanValidationEventListener</classname> described in <xref linkend=\"validator-checkconstraints-orm-hibernateevent\"/> to your project and register it manually."
+msgstr ""
+
+#. Tag: title
+#: integration.xml:152
+#, no-c-format
+msgid "Presentation layer validation"
+msgstr ""
+
+#. Tag: para
+#: integration.xml:154
+#, no-c-format
+msgid "When working with JSF2 or <productname>JBoss Seam</productname> and Hibernate Validator (Bean Validation) is present in the runtime environment validation is triggered for every field in the application. <xref linkend=\"example-jsf2\"/> shows an example of the f:validateBean tag in a JSF page. For more information refer to the Seam documentation or the JSF 2 specification."
+msgstr ""
+
+#. Tag: title
+#: integration.xml:162
+#, no-c-format
+msgid "Usage of Bean Validation within JSF2"
+msgstr ""
+
+#. Tag: programlisting
+#: integration.xml:164
+#, no-c-format
+msgid ""
+ "<h:form>\n"
+ " <emphasis role=\"bold\"><f:validateBean></emphasis>\n"
+ " <h:inputText value=”#{model.property}” />\n"
+ " <h:selectOneRadio value=”#{model.radioProperty}” > ... </h:selectOneRadio>\n"
+ " <!-- other input components here -->\n"
+ " <emphasis role=\"bold\"></f:validateBean></emphasis>\n"
+ "</h:form>"
+msgstr ""
+
Added: validator/trunk/hibernate-validator/src/main/docbook/pot/modules/preface.pot
===================================================================
--- validator/trunk/hibernate-validator/src/main/docbook/pot/modules/preface.pot (rev 0)
+++ validator/trunk/hibernate-validator/src/main/docbook/pot/modules/preface.pot 2010-07-06 15:18:26 UTC (rev 19904)
@@ -0,0 +1,40 @@
+# SOME DESCRIPTIVE TITLE.
+# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
+#
+#, fuzzy
+msgid ""
+msgstr ""
+"Project-Id-Version: PACKAGE VERSION\n"
+"Report-Msgid-Bugs-To: http://bugs.kde.org\n"
+"POT-Creation-Date: 2010-07-06 14:46+0000\n"
+"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
+"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
+"Language-Team: LANGUAGE <kde-i18n-doc(a)kde.org>\n"
+"MIME-Version: 1.0\n"
+"Content-Type: application/x-xml2pot; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+
+#. Tag: title
+#: preface.xml:25
+#, no-c-format
+msgid "Preface"
+msgstr ""
+
+#. Tag: para
+#: preface.xml:27
+#, no-c-format
+msgid "Validating data is a common task that occurs throughout any application, from the presentation layer to the persistence layer. Often the same validation logic is implemented in each layer, proving time consuming and error-prone. To avoid duplication of these validations in each layer, developers often bundle validation logic directly into the domain model, cluttering domain classes with validation code which is really metadata about the class itself."
+msgstr ""
+
+#. Tag: para
+#: preface.xml:46
+#, no-c-format
+msgid "JSR 303 - Bean Validation - defines a metadata model and API for entity validation. The default metadata source is annotations, with the ability to override and extend the meta-data through the use of XML. The API is not tied to a specific application tier or programming model. It is specifically not tied to either the web tier or the persistence tier, and is available for both server-side application programming, as well as rich client Swing application developers."
+msgstr ""
+
+#. Tag: para
+#: preface.xml:65
+#, no-c-format
+msgid "Hibernate Validator is the reference implementation of this JSR."
+msgstr ""
+
Added: validator/trunk/hibernate-validator/src/main/docbook/pot/modules/programmaticapi.pot
===================================================================
--- validator/trunk/hibernate-validator/src/main/docbook/pot/modules/programmaticapi.pot (rev 0)
+++ validator/trunk/hibernate-validator/src/main/docbook/pot/modules/programmaticapi.pot 2010-07-06 15:18:26 UTC (rev 19904)
@@ -0,0 +1,133 @@
+# SOME DESCRIPTIVE TITLE.
+# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
+#
+#, fuzzy
+msgid ""
+msgstr ""
+"Project-Id-Version: PACKAGE VERSION\n"
+"Report-Msgid-Bugs-To: http://bugs.kde.org\n"
+"POT-Creation-Date: 2010-07-06 14:46+0000\n"
+"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
+"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
+"Language-Team: LANGUAGE <kde-i18n-doc(a)kde.org>\n"
+"MIME-Version: 1.0\n"
+"Content-Type: application/x-xml2pot; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+
+#. Tag: title
+#: programmaticapi.xml:25 programmaticapi.xml:48
+#, no-c-format
+msgid "Programmatic constraint definition"
+msgstr ""
+
+#. Tag: para
+#: programmaticapi.xml:28
+#, no-c-format
+msgid "Use of the features described in the following sections is not portable between Bean Validation providers/implementations."
+msgstr ""
+
+#. Tag: para
+#: programmaticapi.xml:32
+#, no-c-format
+msgid "Hibernate Validator allows to configure constraints not only via annotations and xml, but also via a programmatic API. This API can be used exclusively or in combination with annotations and xml. If used in combination programmatic constraints are additive to otherwise configured constraints."
+msgstr ""
+
+#. Tag: para
+#: programmaticapi.xml:38
+#, no-c-format
+msgid "The programmatic API is centered around the <classname>ConstraintMapping</classname> class which can be found together with its supporting classes in the <package>org.hibernate.validator.cfg</package> package. <classname>ConstraintMapping</classname> is the entry point to a fluent API allowing the definition of constraints. <xref lang=\"\" linkend=\"example-constraint-mapping\"/> shows how the API can be used."
+msgstr ""
+
+#. Tag: programlisting
+#: programmaticapi.xml:50
+#, no-c-format
+msgid ""
+ "ConstraintMapping mapping = new ConstraintMapping();\n"
+ "mapping.type( Car.class )\n"
+ " .property( \"manufacturer\", FIELD )\n"
+ " .constraint( NotNullDef.class )\n"
+ " .property( \"licensePlate\", FIELD )\n"
+ " .constraint( NotNullDef.class )\n"
+ " .constraint( SizeDef.class )\n"
+ " .min( 2 )\n"
+ " .max( 14 )\n"
+ " .property( \"seatCount\", FIELD )\n"
+ " .constraint( MinDef.class )\n"
+ " .value ( 2 )\n"
+ ".type( RentalCar.class )\n"
+ " .property( \"rentalStation\", METHOD)\n"
+ " .constraint( NotNullDef.class );"
+msgstr ""
+
+#. Tag: para
+#: programmaticapi.xml:53
+#, no-c-format
+msgid "As you can see you can configure constraints on multiple classes and properties using method chaining. The constraint definition classes <classname>NotNullDef</classname>, <classname>SizeDef</classname> and <classname>MinDef</classname> are helper classes which allow to configure constraint parameters in a type-safe fashion. Definition classes exists for all built-in constraints in the <classname>org.hibernate.validator.cfg.defs</classname> package. For a custom constraint you can either create your own definition class extending <classname>ConstraintDef</classname> or you can use <classname>GenericConstraintDef</classname> as seen in <xref linkend=\"example-generic-constraint-mapping\"/>."
+msgstr ""
+
+#. Tag: title
+#: programmaticapi.xml:66
+#, no-c-format
+msgid "Programmatic constraint definition using <classname>GenericConstraintDef</classname>"
+msgstr ""
+
+#. Tag: programlisting
+#: programmaticapi.xml:69
+#, no-c-format
+msgid ""
+ "ConstraintMapping mapping = new ConstraintMapping();\n"
+ "mapping.type( Car.class )\n"
+ " .property( \"licensePlate\", FIELD )\n"
+ " .constraint( GenericConstraintDef.class )\n"
+ " .constraintType( CheckCase.class )\n"
+ " .param( \"value\", CaseMode.UPPER );"
+msgstr ""
+
+#. Tag: para
+#: programmaticapi.xml:72
+#, no-c-format
+msgid "Last but not least, you can also define cascading constraints as well as the default group sequence of an entity."
+msgstr ""
+
+#. Tag: title
+#: programmaticapi.xml:76
+#, no-c-format
+msgid "Cascading constraints and group redefinition"
+msgstr ""
+
+#. Tag: programlisting
+#: programmaticapi.xml:78
+#, no-c-format
+msgid ""
+ "ConstraintMapping mapping = new ConstraintMapping();\n"
+ "mapping.type( Car.class )\n"
+ " .valid( \"driver\", FIELD )\n"
+ ".type( RentalCar.class)\n"
+ " .defaultGroupSequence( RentalCar.class, CarChecks.class );"
+msgstr ""
+
+#. Tag: para
+#: programmaticapi.xml:81
+#, no-c-format
+msgid "Once you have your <classname>ConstraintMapping</classname> you will have to pass it to the configuration. Since the programmatic configuration is not part of the official Bean Validation specification you will have to get hold of the Hibernate Validator specific configuration instance. See <xref linkend=\"example-hibernate-specific-config\"/>."
+msgstr ""
+
+#. Tag: title
+#: programmaticapi.xml:88
+#, no-c-format
+msgid "Creating a Hibernate Validator specific configuration"
+msgstr ""
+
+#. Tag: programlisting
+#: programmaticapi.xml:90
+#, no-c-format
+msgid ""
+ "ConstraintMapping mapping = new ConstraintMapping();\n"
+ "// configure mapping instance\n"
+ "\n"
+ "HibernateValidatorConfiguration config = Validation.byProvider( HibernateValidator.class ).configure();\n"
+ "config.addMapping( mapping );\n"
+ "ValidatorFactory factory = config.buildValidatorFactory();\n"
+ "Validator validator = factory.getValidator();"
+msgstr ""
+
Added: validator/trunk/hibernate-validator/src/main/docbook/pot/modules/usingvalidator.pot
===================================================================
--- validator/trunk/hibernate-validator/src/main/docbook/pot/modules/usingvalidator.pot (rev 0)
+++ validator/trunk/hibernate-validator/src/main/docbook/pot/modules/usingvalidator.pot 2010-07-06 15:18:26 UTC (rev 19904)
@@ -0,0 +1,1593 @@
+# SOME DESCRIPTIVE TITLE.
+# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
+#
+#, fuzzy
+msgid ""
+msgstr ""
+"Project-Id-Version: PACKAGE VERSION\n"
+"Report-Msgid-Bugs-To: http://bugs.kde.org\n"
+"POT-Creation-Date: 2010-07-06 14:46+0000\n"
+"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
+"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
+"Language-Team: LANGUAGE <kde-i18n-doc(a)kde.org>\n"
+"MIME-Version: 1.0\n"
+"Content-Type: application/x-xml2pot; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+
+#. Tag: title
+#: usingvalidator.xml:25
+#, no-c-format
+msgid "Validation step by step"
+msgstr ""
+
+#. Tag: para
+#: usingvalidator.xml:27
+#, no-c-format
+msgid "In this chapter we will see in more detail how to use Hibernate Validator to validate constraints for a given entity model. We will also learn which default constraints the Bean Validation specification provides and which additional constraints are only provided by Hibernate Validator. Let's start with how to add constraints to an entity."
+msgstr ""
+
+#. Tag: title
+#: usingvalidator.xml:34
+#, no-c-format
+msgid "Defining constraints"
+msgstr ""
+
+#. Tag: para
+#: usingvalidator.xml:36
+#, no-c-format
+msgid "Constraints in Bean Validation are expressed via Java annotations. In this section we show how to annotate an object model with these annotations. We have to differentiate between three different type of constraint annotations - field-, property-, and class-level annotations."
+msgstr ""
+
+#. Tag: para
+#: usingvalidator.xml:43
+#, no-c-format
+msgid "Not all constraints can be placed on all of these levels. In fact, none of the default constraints defined by Bean Validation can be placed at class level. The <classname>java.lang.annotation.Target</classname> annotation in the constraint annotation itself determines on which elements a constraint can be placed. See <xref linkend=\"validator-customconstraints\"/> for more information."
+msgstr ""
+
+#. Tag: title
+#: usingvalidator.xml:52
+#, no-c-format
+msgid "Field-level constraints"
+msgstr ""
+
+#. Tag: para
+#: usingvalidator.xml:54
+#, no-c-format
+msgid "Constraints can be expressed by annotating a field of a class. <xref linkend=\"example-field-level\"/> shows a field level configuration example:"
+msgstr ""
+
+#. Tag: title
+#: usingvalidator.xml:59
+#, no-c-format
+msgid "Field level constraint"
+msgstr ""
+
+#. Tag: programlisting
+#: usingvalidator.xml:61
+#, no-c-format
+msgid ""
+ "package com.mycompany;\n"
+ "\n"
+ "import javax.validation.constraints.NotNull;\n"
+ "\n"
+ "public class Car {\n"
+ "\n"
+ " @NotNull\n"
+ " private String manufacturer;\n"
+ "\n"
+ " @AssertTrue\n"
+ " private boolean isRegistered;\n"
+ "\n"
+ " public Car(String manufacturer, boolean isRegistered) {\n"
+ " super();\n"
+ " this.manufacturer = manufacturer;\n"
+ " this.isRegistered = isRegistered;\n"
+ " }\n"
+ "}"
+msgstr ""
+
+#. Tag: para
+#: usingvalidator.xml:64
+#, no-c-format
+msgid "When using field level constraints field access strategy is used to access the value to be validated. This means the bean validation provider directly accesses the instance variable and does not invoke the property accessor method also if such a method exists."
+msgstr ""
+
+#. Tag: para
+#: usingvalidator.xml:70
+#, no-c-format
+msgid "The access type (private, protected or public) does not matter."
+msgstr ""
+
+#. Tag: para
+#: usingvalidator.xml:75
+#, no-c-format
+msgid "Static fields and properties cannot be validated."
+msgstr ""
+
+#. Tag: title
+#: usingvalidator.xml:80
+#, no-c-format
+msgid "Property-level constraints"
+msgstr ""
+
+#. Tag: para
+#: usingvalidator.xml:82
+#, no-c-format
+msgid "If your model class adheres to the <ulink type=\"\" url=\"http://java.sun.com/javase/technologies/desktop/javabeans/index.jsp\">JavaBeans</ulink> standard, it is also possible to annotate the properties of a bean class instead of its fields. <xref linkend=\"example-property-level\"/> uses the same entity as in <xref linkend=\"example-field-level\"/>, however, property level constraints are used."
+msgstr ""
+
+#. Tag: para
+#: usingvalidator.xml:88
+#, no-c-format
+msgid "The property's getter method has to be annotated, not its setter."
+msgstr ""
+
+#. Tag: title
+#: usingvalidator.xml:93
+#, no-c-format
+msgid "Property level constraint"
+msgstr ""
+
+#. Tag: programlisting
+#: usingvalidator.xml:95
+#, no-c-format
+msgid ""
+ "package com.mycompany;\n"
+ "\n"
+ "import javax.validation.constraints.AssertTrue;\n"
+ "import javax.validation.constraints.NotNull;\n"
+ "\n"
+ "public class Car {\n"
+ "\n"
+ " private String manufacturer;\n"
+ "\n"
+ " private boolean isRegistered;\n"
+ " \n"
+ " public Car(String manufacturer, boolean isRegistered) {\n"
+ " super();\n"
+ " this.manufacturer = manufacturer;\n"
+ " this.isRegistered = isRegistered;\n"
+ " }\n"
+ "\n"
+ " @NotNull\n"
+ " public String getManufacturer() {\n"
+ " return manufacturer;\n"
+ " }\n"
+ "\n"
+ " public void setManufacturer(String manufacturer) {\n"
+ " this.manufacturer = manufacturer;\n"
+ " }\n"
+ "\n"
+ " @AssertTrue\n"
+ " public boolean isRegistered() {\n"
+ " return isRegistered;\n"
+ " }\n"
+ "\n"
+ " public void setRegistered(boolean isRegistered) {\n"
+ " this.isRegistered = isRegistered;\n"
+ " }\n"
+ "}"
+msgstr ""
+
+#. Tag: para
+#: usingvalidator.xml:98
+#, no-c-format
+msgid "When using property level constraints property access strategy is used to access the value to be validated. This means the bean validation provider accesses the state via the property accessor method."
+msgstr ""
+
+#. Tag: para
+#: usingvalidator.xml:103
+#, no-c-format
+msgid "It is recommended to stick either to field <emphasis>or</emphasis> property annotation within one class. It is not recommended to annotate a field <emphasis>and</emphasis> the accompanying getter method as this would cause the field to be validated twice."
+msgstr ""
+
+#. Tag: title
+#: usingvalidator.xml:112
+#, no-c-format
+msgid "Class-level constraints"
+msgstr ""
+
+#. Tag: para
+#: usingvalidator.xml:115
+#, no-c-format
+msgid "Last but not least, a constraint can also be placed on class level. When a constraint annotation is placed on this level the class instance itself passed to the <classname>ConstraintValidator</classname>. Class level constraints are useful if it is necessary to inspect more than a single property of the class to validate it or if a correlation between different state variables has to be evaluated. In <xref linkend=\"example-class-level\"/> we add the property <property>passengers</property> to the class <classname>Car</classname>. We also add the constraint <classname>PassengerCount</classname> on the class level. We will later see how we can actually create this custom constraint (see <xref linkend=\"validator-customconstraints\"/>). For now we it is enough to know that <classname>PassengerCount</classname> will ensure that there cannot be more passengers in a car than there are seats."
+msgstr ""
+
+#. Tag: title
+#: usingvalidator.xml:131
+#, no-c-format
+msgid "Class level constraint"
+msgstr ""
+
+#. Tag: programlisting
+#: usingvalidator.xml:133
+#, no-c-format
+msgid ""
+ "package com.mycompany;\n"
+ "\n"
+ "import javax.validation.constraints.Min;\n"
+ "import javax.validation.constraints.NotNull;\n"
+ "import javax.validation.constraints.Size;\n"
+ "\n"
+ "@PassengerCount\n"
+ "public class Car {\n"
+ "\n"
+ " @NotNull\n"
+ " private String manufacturer;\n"
+ "\n"
+ " @NotNull\n"
+ " @Size(min = 2, max = 14)\n"
+ " private String licensePlate;\n"
+ "\n"
+ " @Min(2)\n"
+ " private int seatCount;\n"
+ " \n"
+ " private List<Person> passengers;\n"
+ " \n"
+ " public Car(String manufacturer, String licencePlate, int seatCount) {\n"
+ " this.manufacturer = manufacturer;\n"
+ " this.licensePlate = licencePlate;\n"
+ " this.seatCount = seatCount;\n"
+ " }\n"
+ "\n"
+ " //getters and setters ...\n"
+ "}"
+msgstr ""
+
+#. Tag: title
+#: usingvalidator.xml:138
+#, no-c-format
+msgid "Constraint inheritance"
+msgstr ""
+
+#. Tag: para
+#: usingvalidator.xml:140
+#, no-c-format
+msgid "When validating an object that implements an interface or extends another class, all constraint annotations on the implemented interface and parent class apply in the same manner as the constraints specified on the validated object itself. To make things clearer let's have a look at the following example:"
+msgstr ""
+
+#. Tag: title
+#: usingvalidator.xml:147
+#, no-c-format
+msgid "Constraint inheritance using RentalCar"
+msgstr ""
+
+#. Tag: programlisting
+#: usingvalidator.xml:149
+#, no-c-format
+msgid ""
+ "package com.mycompany;\n"
+ "\n"
+ "import javax.validation.constraints.NotNull;\n"
+ "\n"
+ "public class RentalCar extends Car {\n"
+ "\n"
+ " private String rentalStation;\n"
+ " \n"
+ " public RentalCar(String manufacturer, String rentalStation) {\n"
+ " super(manufacturer);\n"
+ " this.rentalStation = rentalStation;\n"
+ " }\n"
+ " \n"
+ " @NotNull\n"
+ " public String getRentalStation() {\n"
+ " return rentalStation;\n"
+ " }\n"
+ "\n"
+ " public void setRentalStation(String rentalStation) {\n"
+ " this.rentalStation = rentalStation;\n"
+ " }\n"
+ "}"
+msgstr ""
+
+#. Tag: para
+#: usingvalidator.xml:152
+#, no-c-format
+msgid "Our well-known class <classname>Car</classname> is now extended by <classname>RentalCar</classname> with the additional property <property>rentalStation</property>. If an instance of <classname>RentalCar</classname> is validated, not only the <classname>@NotNull</classname> constraint on <property>rentalStation</property> is validated, but also the constraint on <property>manufacturer</property> from the parent class."
+msgstr ""
+
+#. Tag: para
+#: usingvalidator.xml:160
+#, no-c-format
+msgid "The same would hold true, if <classname>Car</classname> were an interface implemented by <classname>RentalCar</classname>."
+msgstr ""
+
+#. Tag: para
+#: usingvalidator.xml:163
+#, no-c-format
+msgid "Constraint annotations are aggregated if methods are overridden. If <classname>RentalCar</classname> would override the <methodname>getManufacturer()</methodname> method from <classname>Car</classname> any constraints annotated at the overriding method would be evaluated in addition to the <classname>@NotNull</classname> constraint from the super-class."
+msgstr ""
+
+#. Tag: title
+#: usingvalidator.xml:172
+#, no-c-format
+msgid "Object graphs"
+msgstr ""
+
+#. Tag: para
+#: usingvalidator.xml:174
+#, no-c-format
+msgid "The Bean Validation API does not only allow to validate single class instances but also complete object graphs. To do so, just annotate a field or property representing a reference to another object with <classname>@Valid</classname>. If the parent object is validated, all referenced objects annotated with <classname>@Valid</classname> will be validated as well (as will be their children etc.). See <xref linkend=\"example-car-with-driver\"/>."
+msgstr ""
+
+#. Tag: title
+#: usingvalidator.xml:183
+#, no-c-format
+msgid "Class Person"
+msgstr ""
+
+#. Tag: programlisting
+#: usingvalidator.xml:185
+#, no-c-format
+msgid ""
+ "package com.mycompany;\n"
+ "\n"
+ "import javax.validation.constraints.NotNull;\n"
+ "\n"
+ "public class Person {\n"
+ "\n"
+ " @NotNull\n"
+ " private String name;\n"
+ " \n"
+ " public Person(String name) {\n"
+ " super();\n"
+ " this.name = name;\n"
+ " }\n"
+ "\n"
+ " public String getName() {\n"
+ " return name;\n"
+ " }\n"
+ "\n"
+ " public void setName(String name) {\n"
+ " this.name = name;\n"
+ " }\n"
+ "}"
+msgstr ""
+
+#. Tag: title
+#: usingvalidator.xml:189
+#, no-c-format
+msgid "Adding a driver to the car"
+msgstr ""
+
+#. Tag: programlisting
+#: usingvalidator.xml:191
+#, no-c-format
+msgid ""
+ "package com.mycompany;\n"
+ "\n"
+ "import javax.validation.Valid;\n"
+ "import javax.validation.constraints.NotNull;\n"
+ "\n"
+ "public class Car {\n"
+ "\n"
+ " @NotNull\n"
+ " @Valid\n"
+ " private Person driver;\n"
+ " \n"
+ " public Car(Person driver) {\n"
+ " this.driver = driver;\n"
+ " }\n"
+ "\n"
+ " //getters and setters ...\n"
+ "}"
+msgstr ""
+
+#. Tag: para
+#: usingvalidator.xml:194
+#, no-c-format
+msgid "If an instance of <classname>Car</classname> is validated, the referenced <classname>Person</classname> object will be validated as well, as the <property>driver</property> field is annotated with <classname>@Valid</classname>. Therefore the validation of a <classname>Car</classname> will fail if the <property>name</property> field of the referenced <classname>Person</classname> instance is <code>null</code>."
+msgstr ""
+
+#. Tag: para
+#: usingvalidator.xml:202
+#, no-c-format
+msgid "Object graph validation also works for collection-typed fields. That means any attributes that"
+msgstr ""
+
+#. Tag: para
+#: usingvalidator.xml:207
+#, no-c-format
+msgid "are arrays"
+msgstr ""
+
+#. Tag: para
+#: usingvalidator.xml:211
+#, no-c-format
+msgid "implement <classname>java.lang.Iterable</classname> (especially <classname>Collection</classname>, <classname>List</classname> and <classname>Set</classname>)"
+msgstr ""
+
+#. Tag: para
+#: usingvalidator.xml:217
+#, no-c-format
+msgid "implement <classname>java.util.Map</classname>"
+msgstr ""
+
+#. Tag: para
+#: usingvalidator.xml:221
+#, no-c-format
+msgid "can be annotated with <classname>@Valid</classname>, which will cause each contained element to be validated, when the parent object is validated."
+msgstr ""
+
+#. Tag: title
+#: usingvalidator.xml:226
+#, no-c-format
+msgid "Car with a list of passengers"
+msgstr ""
+
+#. Tag: programlisting
+#: usingvalidator.xml:228
+#, no-c-format
+msgid ""
+ "package com.mycompany;\n"
+ "\n"
+ "import java.util.ArrayList;\n"
+ "import java.util.List;\n"
+ "\n"
+ "import javax.validation.Valid;\n"
+ "import javax.validation.constraints.NotNull;\n"
+ "\n"
+ "public class Car {\n"
+ "\n"
+ " @NotNull\n"
+ " @Valid\n"
+ " private List<Person> passengers = new ArrayList<Person>();\n"
+ "\n"
+ " public Car(List<Person> passengers) {\n"
+ " this.passengers = passengers;\n"
+ " }\n"
+ "\n"
+ " //getters and setters ...\n"
+ "}"
+msgstr ""
+
+#. Tag: para
+#: usingvalidator.xml:231
+#, no-c-format
+msgid "If a <classname>Car</classname> instance is validated, a <classname>ConstraintValidation</classname> will be created, if any of the <classname>Person</classname> objects contained in the <property>passengers</property> list has a <code>null</code> name."
+msgstr ""
+
+#. Tag: para
+#: usingvalidator.xml:235
+#, no-c-format
+msgid "<classname>null</classname> values are getting ignored when validating object graphs."
+msgstr ""
+
+#. Tag: title
+#: usingvalidator.xml:242
+#, no-c-format
+msgid "Validating constraints"
+msgstr ""
+
+#. Tag: para
+#: usingvalidator.xml:244
+#, no-c-format
+msgid "The <classname>Validator</classname> interface is the main entry point to Bean Validation. In <xref linkend=\"section-validator-instance\"/> we will first show how to obtain an <classname>Validator</classname> instance. Afterwards we will learn how to use the different methods of the <classname>Validator</classname> interface."
+msgstr ""
+
+#. Tag: title
+#: usingvalidator.xml:251
+#, no-c-format
+msgid "Obtaining a <classname>Validator</classname> instance"
+msgstr ""
+
+#. Tag: para
+#: usingvalidator.xml:253
+#, no-c-format
+msgid "The first step towards validating an entity instance is to get hold of a <classname>Validator</classname> instance. The road to this instance leads via the <classname>Validation</classname> class and a <classname>ValidatorFactory</classname>. The easiest way is to use the static <methodname>Validation.buildDefaultValidatorFactory()</methodname> method:"
+msgstr ""
+
+#. Tag: title
+#: usingvalidator.xml:262
+#, no-c-format
+msgid "Validation.buildDefaultValidatorFactory()"
+msgstr ""
+
+#. Tag: programlisting
+#: usingvalidator.xml:264
+#, no-c-format
+msgid ""
+ "ValidatorFactory factory = Validation.buildDefaultValidatorFactory();\n"
+ "Validator validator = factory.getValidator();"
+msgstr ""
+
+#. Tag: para
+#: usingvalidator.xml:267
+#, no-c-format
+msgid "For other ways of obtaining a Validator instance see <xref linkend=\"validator-bootstrapping\"/>. For now we just want to see how we can use the <classname>Validator</classname> instance to validate entity instances."
+msgstr ""
+
+#. Tag: title
+#: usingvalidator.xml:274
+#, no-c-format
+msgid "Validator methods"
+msgstr ""
+
+#. Tag: para
+#: usingvalidator.xml:276
+#, no-c-format
+msgid "The <classname>Validator</classname> interface contains three methods that can be used to either validate entire entities or just a single properties of the entity."
+msgstr ""
+
+#. Tag: para
+#: usingvalidator.xml:280
+#, no-c-format
+msgid "All three methods return a <classname>Set<ConstraintViolation></classname>. The set is empty, if the validation succeeds. Otherwise a <classname>ConstraintViolation</classname> instance is added for each violated constraint."
+msgstr ""
+
+#. Tag: para
+#: usingvalidator.xml:286
+#, no-c-format
+msgid "All the validation methods have a var-args parameter which can be used to specify, which validation groups shall be considered when performing the validation. If the parameter is not specified the default validation group (<classname>javax.validation.groups.Default</classname>) will be used. We will go into more detail on the topic of validation groups in"
+msgstr ""
+
+#. Tag: methodname
+#: usingvalidator.xml:295
+#, no-c-format
+msgid "validate"
+msgstr ""
+
+#. Tag: para
+#: usingvalidator.xml:297
+#, no-c-format
+msgid "Use the <methodname>validate()</methodname> method to perform validation of all constraints of a given entity instance (see <xref linkend=\"example-validator-validate\"/> )."
+msgstr ""
+
+#. Tag: title
+#: usingvalidator.xml:302
+#, no-c-format
+msgid "Usage of <methodname>Validator.validate()</methodname>"
+msgstr ""
+
+#. Tag: programlisting
+#: usingvalidator.xml:305
+#, no-c-format
+msgid ""
+ "ValidatorFactory factory = Validation.buildDefaultValidatorFactory();\n"
+ "Validator validator = factory.getValidator();\n"
+ "\n"
+ "Car car = new Car(null);\n"
+ "\n"
+ "Set<ConstraintViolation<Car>> constraintViolations = validator.validate(car);\n"
+ "\n"
+ "assertEquals(1, constraintViolations.size());\n"
+ "assertEquals(\"may not be null\", constraintViolations.iterator().next().getMessage());"
+msgstr ""
+
+#. Tag: methodname
+#: usingvalidator.xml:310
+#, no-c-format
+msgid "validateProperty"
+msgstr ""
+
+#. Tag: para
+#: usingvalidator.xml:312
+#, no-c-format
+msgid "With help of the <methodname>validateProperty()</methodname> a single named property of a given object can be validated. The property name is the JavaBeans property name."
+msgstr ""
+
+#. Tag: title
+#: usingvalidator.xml:317
+#, no-c-format
+msgid "Usage of <methodname>Validator.validateProperty()</methodname>"
+msgstr ""
+
+#. Tag: programlisting
+#: usingvalidator.xml:320
+#, no-c-format
+msgid ""
+ "Validator validator = Validation.buildDefaultValidatorFactory().getValidator();\n"
+ "\n"
+ "Car car = new Car(null);\n"
+ "\n"
+ "Set<ConstraintViolation<Car>> constraintViolations = validator.validateProperty(car, \"manufacturer\");\n"
+ "\n"
+ "assertEquals(1, constraintViolations.size());\n"
+ "assertEquals(\"may not be null\", constraintViolations.iterator().next().getMessage());"
+msgstr ""
+
+#. Tag: para
+#: usingvalidator.xml:323
+#, no-c-format
+msgid "<methodname>Validator.validateProperty</methodname> is for example used in the integration of Bean Validation into JSF 2 (see <xref linkend=\"section-presentation-layer\"/>)."
+msgstr ""
+
+#. Tag: methodname
+#: usingvalidator.xml:329
+#, no-c-format
+msgid "validateValue"
+msgstr ""
+
+#. Tag: para
+#: usingvalidator.xml:331
+#, no-c-format
+msgid "Using the <methodname>validateValue() </methodname>method you can check, whether a single property of a given class can be validated successfully, if the property had the specified value:"
+msgstr ""
+
+#. Tag: title
+#: usingvalidator.xml:336
+#, no-c-format
+msgid "Usage of <methodname>Validator.validateValue()</methodname>"
+msgstr ""
+
+#. Tag: programlisting
+#: usingvalidator.xml:339
+#, no-c-format
+msgid ""
+ "Validator validator = Validation.buildDefaultValidatorFactory().getValidator();\n"
+ "\n"
+ "Set<ConstraintViolation<Car>> constraintViolations = validator.validateValue(Car.class, \"manufacturer\", null);\n"
+ "\n"
+ "assertEquals(1, constraintViolations.size());\n"
+ "assertEquals(\"may not be null\", constraintViolations.iterator().next().getMessage());"
+msgstr ""
+
+#. Tag: para
+#: usingvalidator.xml:343
+#, no-c-format
+msgid "<classname>@Valid</classname> is not honored by <methodname>validateProperty()</methodname> or <methodname>validateValue()</methodname>."
+msgstr ""
+
+#. Tag: title
+#: usingvalidator.xml:351
+#, no-c-format
+msgid "<classname>ConstraintViolation</classname> methods"
+msgstr ""
+
+#. Tag: para
+#: usingvalidator.xml:353
+#, no-c-format
+msgid "Now it is time to have a closer look at what a <classname>ConstraintViolation</classname>. Using the different methods of <classname>ConstraintViolation</classname> a lot of useful information about the cause of the validation failure can be determined. <xref linkend=\"table-constraint-violation\"/> gives an overview of these methods:"
+msgstr ""
+
+#. Tag: title
+#: usingvalidator.xml:361
+#, no-c-format
+msgid "The various <classname>ConstraintViolation</classname> methods"
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:367
+#, no-c-format
+msgid "Method"
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:369
+#, no-c-format
+msgid "Usage"
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:371
+#, no-c-format
+msgid "Example (referring to <xref linkend=\"example-validator-validate\"/>)"
+msgstr ""
+
+#. Tag: methodname
+#: usingvalidator.xml:378
+#, no-c-format
+msgid "getMessage()"
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:380
+#, no-c-format
+msgid "The interpolated error message."
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:382
+#, no-c-format
+msgid "may not be null"
+msgstr ""
+
+#. Tag: methodname
+#: usingvalidator.xml:386
+#, no-c-format
+msgid "getMessageTemplate()"
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:388
+#, no-c-format
+msgid "The non-interpolated error message."
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:390
+#, no-c-format
+msgid "{javax.validation.constraints.NotNull.message}"
+msgstr ""
+
+#. Tag: methodname
+#: usingvalidator.xml:394
+#, no-c-format
+msgid "getRootBean()"
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:396
+#, no-c-format
+msgid "The root bean being validated."
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:398 usingvalidator.xml:416
+#, no-c-format
+msgid "<entry>car</entry>"
+msgstr ""
+
+#. Tag: methodname
+#: usingvalidator.xml:402
+#, no-c-format
+msgid "getRootBeanClass()"
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:404
+#, no-c-format
+msgid "The class of the root bean being validated."
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:406
+#, no-c-format
+msgid "Car.class"
+msgstr ""
+
+#. Tag: methodname
+#: usingvalidator.xml:410
+#, no-c-format
+msgid "getLeafBean()"
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:412
+#, no-c-format
+msgid "If a bean constraint, the bean instance the constraint is applied on. If a property constraint, the bean instance hosting the property the constraint is applied on."
+msgstr ""
+
+#. Tag: methodname
+#: usingvalidator.xml:420
+#, no-c-format
+msgid "getPropertyPath()"
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:422
+#, no-c-format
+msgid "The property path to the value from root bean."
+msgstr ""
+
+#. Tag: methodname
+#: usingvalidator.xml:428
+#, no-c-format
+msgid "getInvalidValue()"
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:430
+#, no-c-format
+msgid "The value failing to pass the constraint."
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:432
+#, no-c-format
+msgid "passengers"
+msgstr ""
+
+#. Tag: methodname
+#: usingvalidator.xml:436
+#, no-c-format
+msgid "getConstraintDescriptor()"
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:438
+#, no-c-format
+msgid "Constraint metadata reported to fail."
+msgstr ""
+
+#. Tag: title
+#: usingvalidator.xml:448
+#, no-c-format
+msgid "Message interpolation"
+msgstr ""
+
+#. Tag: para
+#: usingvalidator.xml:450
+#, no-c-format
+msgid "As we will see in <xref linkend=\"validator-customconstraints\"/> each constraint definition must define a default message descriptor. This message can be overridden at declaration time using the <methodname>message</methodname> attribute of the constraint. You can see this in <xref linkend=\"example-driver\"/>. This message descriptors get interpolated when a constraint validation fails using the configured <classname>MessageInterpolator</classname>. The interpolator will try to resolve any message parameters, meaning string literals enclosed in braces. In order to resolve these parameters Hibernate Validator's default <classname>MessageInterpolator</classname> first recursively resolves parameters against a custom <classname>ResourceBundle</classname> called <filename>ValidationMessages.properties</filename> at the root of the classpath (It is up to you to create this file). If no further replacements are possible against the custom bundle the default <classname>Re!
sourceBundle</classname> under <filename>/org/hibernate/validator/ValidationMessages.properties</filename> gets evaluated. If a replacement occurs against the default bundle the algorithm looks again at the custom bundle (and so on). Once no further replacements against these two resource bundles are possible remaining parameters are getting resolved against the attributes of the constraint to be validated."
+msgstr ""
+
+#. Tag: para
+#: usingvalidator.xml:473
+#, no-c-format
+msgid "Since the braces { and } have special meaning in the messages they need to be escaped if they are used literally. The following The following rules apply:"
+msgstr ""
+
+#. Tag: para
+#: usingvalidator.xml:477
+#, no-c-format
+msgid "\\{ is considered as the literal {"
+msgstr ""
+
+#. Tag: para
+#: usingvalidator.xml:481
+#, no-c-format
+msgid "\\} is considered as the literal }"
+msgstr ""
+
+#. Tag: para
+#: usingvalidator.xml:485
+#, no-c-format
+msgid "\\\\ is considered as the literal \\"
+msgstr ""
+
+#. Tag: para
+#: usingvalidator.xml:489
+#, no-c-format
+msgid "If the default message interpolator does not fit your requirements it is possible to plug a custom <classname>MessageInterpolator</classname> when the <classname>ValidatorFactory</classname> gets created. This can be seen in <xref linkend=\"validator-bootstrapping\"/>."
+msgstr ""
+
+#. Tag: title
+#: usingvalidator.xml:498
+#, no-c-format
+msgid "Validating groups"
+msgstr ""
+
+#. Tag: para
+#: usingvalidator.xml:500
+#, no-c-format
+msgid "Groups allow you to restrict the set of constraints applied during validation. This makes for example wizard like validation possible where in each step only a specified subset of constraints get validated. The groups targeted are passed as var-args parameters to <methodname>validate</methodname>, <methodname>validateProperty</methodname> and <methodname>validateValue</methodname>. Let's have a look at an extended <classname>Car</classname> with <classname>Driver</classname> example. First we have the class <classname>Person</classname> (<xref linkend=\"example-person\"/>) which has a <classname>@NotNull </classname>constraint on <property>name</property>. Since no group is specified for this annotation its default group is <classname>javax.validation.groups.Default</classname>."
+msgstr ""
+
+#. Tag: para
+#: usingvalidator.xml:515
+#, no-c-format
+msgid "When more than one group is requested, the order in which the groups are evaluated is not deterministic. If no group is specified the default group <classname>javax.validation.groups.Default</classname> is assumed."
+msgstr ""
+
+#. Tag: title
+#: usingvalidator.xml:522
+#, no-c-format
+msgid "Person"
+msgstr ""
+
+#. Tag: programlisting
+#: usingvalidator.xml:524
+#, no-c-format
+msgid ""
+ "public class Person {\n"
+ " @NotNull\n"
+ " private String name;\n"
+ "\n"
+ " public Person(String name) {\n"
+ " this.name = name;\n"
+ " }\n"
+ " // getters and setters ...\n"
+ "}"
+msgstr ""
+
+#. Tag: para
+#: usingvalidator.xml:527
+#, no-c-format
+msgid "Next we have the class <classname>Driver</classname> (<xref linkend=\"example-driver\"/>) extending <classname>Person</classname>. Here we are adding the properties <property>age</property> and <property>hasDrivingLicense</property>. In order to drive you must be at least 18 (<classname>@Min(18)</classname>) and you must have a driving license (<classname>@AssertTrue</classname>). Both constraints defined on these properties belong to the group <classname>DriverChecks</classname>. As you can see in <xref linkend=\"example-group-interfaces\"/> the group <classname>DriverChecks</classname> is just a simple tagging interface. Using interfaces makes the usage of groups type safe and allows for easy refactoring. It also means that groups can inherit from each other via class inheritance."
+msgstr ""
+
+#. Tag: para
+#: usingvalidator.xml:541
+#, no-c-format
+msgid "The Bean Validation specification does not enforce that groups have to be interfaces. Non interface classes could be used as well, but we recommend to stick to interfaces."
+msgstr ""
+
+#. Tag: title
+#: usingvalidator.xml:547
+#, no-c-format
+msgid "Driver"
+msgstr ""
+
+#. Tag: programlisting
+#: usingvalidator.xml:549
+#, no-c-format
+msgid ""
+ "public class Driver extends Person {\n"
+ " @Min(value = 18, message = \"You have to be 18 to drive a car\", groups = DriverChecks.class)\n"
+ " public int age;\n"
+ "\n"
+ " @AssertTrue(message = \"You first have to pass the driving test\", groups = DriverChecks.class)\n"
+ " public boolean hasDrivingLicense;\n"
+ "\n"
+ " public Driver(String name) {\n"
+ " super( name );\n"
+ " }\n"
+ "\n"
+ " public void passedDrivingTest(boolean b) {\n"
+ " hasDrivingLicense = b;\n"
+ " }\n"
+ "\n"
+ " public int getAge() {\n"
+ " return age;\n"
+ " }\n"
+ "\n"
+ " public void setAge(int age) {\n"
+ " this.age = age;\n"
+ " }\n"
+ "}"
+msgstr ""
+
+#. Tag: title
+#: usingvalidator.xml:553
+#, no-c-format
+msgid "Group interfaces"
+msgstr ""
+
+#. Tag: programlisting
+#: usingvalidator.xml:555
+#, no-c-format
+msgid ""
+ "public interface DriverChecks {\n"
+ "}\n"
+ "\n"
+ "public interface CarChecks {\n"
+ "}"
+msgstr ""
+
+#. Tag: para
+#: usingvalidator.xml:558
+#, no-c-format
+msgid "Last but not least we add the property <property>passedVehicleInspection</property> to the <classname>Car</classname> class (<xref linkend=\"example-car\"/>) indicating whether a car passed the road worthy tests."
+msgstr ""
+
+#. Tag: title
+#: usingvalidator.xml:564
+#, no-c-format
+msgid "<title>Car</title>"
+msgstr ""
+
+#. Tag: programlisting
+#: usingvalidator.xml:566
+#, no-c-format
+msgid ""
+ "public class Car {\n"
+ " @NotNull\n"
+ " private String manufacturer;\n"
+ "\n"
+ " @NotNull\n"
+ " @Size(min = 2, max = 14)\n"
+ " private String licensePlate;\n"
+ "\n"
+ " @Min(2)\n"
+ " private int seatCount;\n"
+ "\n"
+ " @AssertTrue(message = \"The car has to pass the vehicle inspection first\", groups = CarChecks.class)\n"
+ " private boolean passedVehicleInspection;\n"
+ "\n"
+ " @Valid\n"
+ " private Driver driver;\n"
+ "\n"
+ " public Car(String manufacturer, String licencePlate, int seatCount) {\n"
+ " this.manufacturer = manufacturer;\n"
+ " this.licensePlate = licencePlate;\n"
+ " this.seatCount = seatCount;\n"
+ " }\n"
+ "}"
+msgstr ""
+
+#. Tag: para
+#: usingvalidator.xml:569
+#, no-c-format
+msgid "Overall three different groups are used in our example. <property>Person.name</property>, <property>Car.manufacturer</property>, <property>Car.licensePlate</property> and <property>Car.seatCount</property> all belong to the <classname>Default</classname> group. <property>Driver.age</property> and <property>Driver.hasDrivingLicense</property> belong to <classname>DriverChecks</classname> and last but not least <property>Car.passedVehicleInspection</property> belongs to the group <classname>CarChecks</classname>. <xref linkend=\"example-drive-away\"/> shows how passing different group combinations to the <methodname>Validator.validate</methodname> method result in different validation results."
+msgstr ""
+
+#. Tag: title
+#: usingvalidator.xml:583
+#, no-c-format
+msgid "Drive away"
+msgstr ""
+
+#. Tag: programlisting
+#: usingvalidator.xml:585
+#, no-c-format
+msgid ""
+ "public class GroupTest {\n"
+ "\n"
+ " private static Validator validator;\n"
+ "\n"
+ " @BeforeClass\n"
+ " public static void setUp() {\n"
+ " ValidatorFactory factory = Validation.buildDefaultValidatorFactory();\n"
+ " validator = factory.getValidator();\n"
+ " }\n"
+ "\n"
+ " @Test\n"
+ " public void driveAway() {\n"
+ " // create a car and check that everything is ok with it.\n"
+ " Car car = new Car( \"Morris\", \"DD-AB-123\", 2 );\n"
+ " Set<ConstraintViolation<Car>> constraintViolations = validator.validate( car );\n"
+ " assertEquals( 0, constraintViolations.size() );\n"
+ "\n"
+ " // but has it passed the vehicle inspection?\n"
+ " constraintViolations = validator.validate( car, CarChecks.class );\n"
+ " assertEquals( 1, constraintViolations.size() );\n"
+ " assertEquals(\"The car has to pass the vehicle inspection first\", constraintViolations.iterator().next().getMessage());\n"
+ "\n"
+ " // let's go to the vehicle inspection\n"
+ " car.setPassedVehicleInspection( true );\n"
+ " assertEquals( 0, validator.validate( car ).size() );\n"
+ "\n"
+ " // now let's add a driver. He is 18, but has not passed the driving test yet\n"
+ " Driver john = new Driver( \"John Doe\" );\n"
+ " john.setAge( 18 );\n"
+ " car.setDriver( john );\n"
+ " constraintViolations = validator.validate( car, DriverChecks.class );\n"
+ " assertEquals( 1, constraintViolations.size() );\n"
+ " assertEquals( \"You first have to pass the driving test\", constraintViolations.iterator().next().getMessage() );\n"
+ "\n"
+ " // ok, John passes the test\n"
+ " john.passedDrivingTest( true );\n"
+ " assertEquals( 0, validator.validate( car, DriverChecks.class ).size() );\n"
+ "\n"
+ " // just checking that everything is in order now\n"
+ " assertEquals( 0, validator.validate( car, Default.class, CarChecks.class, DriverChecks.class ).size() );\n"
+ " }\n"
+ "}"
+msgstr ""
+
+#. Tag: para
+#: usingvalidator.xml:588
+#, no-c-format
+msgid "First we create a car and validate it using no explicit group. There are no validation errors, even though the property <property>passedVehicleInspection</property> is per default <constant>false</constant>. However, the constraint defined on this property does not belong to the default group. Next we just validate the <classname>CarChecks</classname> group which will fail until we make sure that the car passes the vehicle inspection. When we then add a driver to the car and validate against <classname>DriverChecks</classname> we get again a constraint violation due to the fact that the driver has not yet passed the driving test. Only after setting <property>passedDrivingTest</property> to true the validation against <classname>DriverChecks</classname> will pass."
+msgstr ""
+
+#. Tag: para
+#: usingvalidator.xml:601
+#, no-c-format
+msgid "Last but not least, we show that all constraints are passing by validating against all defined groups."
+msgstr ""
+
+#. Tag: title
+#: usingvalidator.xml:605
+#, no-c-format
+msgid "Group sequences"
+msgstr ""
+
+#. Tag: para
+#: usingvalidator.xml:607
+#, no-c-format
+msgid "By default, constraints are evaluated in no particular order and this regardless of which groups they belong to. In some situations, however, it is useful to control the order of the constraints evaluation. In our example from <xref linkend=\"validator-usingvalidator-validationgroups\"/> we could for example require that first all default car constraints are passing before we check the road worthiness of the car. Finally before we drive away we check the actual driver constraints. In order to implement such an order one would define a new interface and annotate it with <classname>@GroupSequence</classname> defining the order in which the groups have to be validated."
+msgstr ""
+
+#. Tag: para
+#: usingvalidator.xml:620
+#, no-c-format
+msgid "If at least one constraints fails in a sequenced group none of the constraints of the following groups in the sequence get validated."
+msgstr ""
+
+#. Tag: title
+#: usingvalidator.xml:626
+#, no-c-format
+msgid "Interface with @GroupSequence"
+msgstr ""
+
+#. Tag: programlisting
+#: usingvalidator.xml:628
+#, no-c-format
+msgid ""
+ "@GroupSequence({Default.class, CarChecks.class, DriverChecks.class})\n"
+ "public interface OrderedChecks {\n"
+ "}"
+msgstr ""
+
+#. Tag: para
+#: usingvalidator.xml:632
+#, no-c-format
+msgid "Groups defining a sequence and groups composing a sequence must not be involved in a cyclic dependency either directly or indirectly, either through cascaded sequence definition or group inheritance. If a group containing such a circularity is evaluated, a <classname>GroupDefinitionException</classname> is raised."
+msgstr ""
+
+#. Tag: para
+#: usingvalidator.xml:636
+#, no-c-format
+msgid "The usage of the new sequence could then look like in <xref linkend=\"example-group-sequence\"/>."
+msgstr ""
+
+#. Tag: title
+#: usingvalidator.xml:641
+#, no-c-format
+msgid "Usage of a group sequence"
+msgstr ""
+
+#. Tag: programlisting
+#: usingvalidator.xml:643
+#, no-c-format
+msgid ""
+ "@Test\n"
+ "public void testOrderedChecks() {\n"
+ " Car car = new Car( \"Morris\", \"DD-AB-123\", 2 );\n"
+ " car.setPassedVehicleInspection( true );\n"
+ "\n"
+ " Driver john = new Driver( \"John Doe\" );\n"
+ " john.setAge( 18 );\n"
+ " john.passedDrivingTest( true );\n"
+ " car.setDriver( john );\n"
+ "\n"
+ " assertEquals( 0, validator.validate( car, OrderedChecks.class ).size() );\n"
+ "}"
+msgstr ""
+
+#. Tag: title
+#: usingvalidator.xml:648
+#, no-c-format
+msgid "Redefining the default group sequence of a class"
+msgstr ""
+
+#. Tag: para
+#: usingvalidator.xml:650
+#, no-c-format
+msgid "The @GroupSequence annotation also fulfills a second purpose. It allows you to redefine what the Default group means for a given class. To redefine <classname>Default</classname> for a class, place a <classname>@GroupSequence</classname> annotation on the class. The defined groups in the annotation express the sequence of groups that substitute <classname>Default</classname> for this class. <xref linkend=\"example-rental-car\"/> introduces a new class RentalCar with a redfined default group. With this definition the check for all three groups can be rewritten as seen in <xref linkend=\"example-testOrderedChecksWithRedefinedDefault\"/>."
+msgstr ""
+
+#. Tag: title
+#: usingvalidator.xml:662
+#, no-c-format
+msgid "RentalCar"
+msgstr ""
+
+#. Tag: programlisting
+#: usingvalidator.xml:664
+#, no-c-format
+msgid ""
+ "@GroupSequence({ RentalCar.class, CarChecks.class })\n"
+ "public class RentalCar extends Car {\n"
+ " public RentalCar(String manufacturer, String licencePlate, int seatCount) {\n"
+ " super( manufacturer, licencePlate, seatCount );\n"
+ " }\n"
+ "}"
+msgstr ""
+
+#. Tag: title
+#: usingvalidator.xml:668
+#, no-c-format
+msgid "testOrderedChecksWithRedefinedDefault"
+msgstr ""
+
+#. Tag: programlisting
+#: usingvalidator.xml:670
+#, no-c-format
+msgid ""
+ "@Test\n"
+ "public void testOrderedChecksWithRedefinedDefault() {\n"
+ " RentalCar rentalCar = new RentalCar( \"Morris\", \"DD-AB-123\", 2 );\n"
+ " rentalCar.setPassedVehicleInspection( true );\n"
+ "\n"
+ " Driver john = new Driver( \"John Doe\" );\n"
+ " john.setAge( 18 );\n"
+ " john.passedDrivingTest( true );\n"
+ " rentalCar.setDriver( john );\n"
+ "\n"
+ " assertEquals( 0, validator.validate( rentalCar, Default.class, DriverChecks.class ).size() );\n"
+ "}"
+msgstr ""
+
+#. Tag: para
+#: usingvalidator.xml:674
+#, no-c-format
+msgid "Due to the fact that there cannot be a cyclic dependency in the group and group sequence definitions one cannot just add <classname>Default</classname> to the sequence redefining <classname>Default</classname> for a class. Instead the class itself should be added!"
+msgstr ""
+
+#. Tag: title
+#: usingvalidator.xml:684 usingvalidator.xml:692
+#, no-c-format
+msgid "Built-in constraints"
+msgstr ""
+
+#. Tag: para
+#: usingvalidator.xml:686
+#, no-c-format
+msgid "Hibernate Validator implements all of the default constraints specified in Bean Validation as well as some custom ones. <xref linkend=\"table-builtin-constraints\"/> list all constraints available in Hibernate Validator."
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:699
+#, no-c-format
+msgid "Annotation"
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:701
+#, no-c-format
+msgid "Part of Bean Validation Specification"
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:703
+#, no-c-format
+msgid "Apply on"
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:705
+#, no-c-format
+msgid "<entry>Use</entry>"
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:707
+#, no-c-format
+msgid "Hibernate Metadata impact"
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:713
+#, no-c-format
+msgid "@AssertFalse"
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:715 usingvalidator.xml:728 usingvalidator.xml:758 usingvalidator.xml:778 usingvalidator.xml:798 usingvalidator.xml:830 usingvalidator.xml:858 usingvalidator.xml:876 usingvalidator.xml:894 usingvalidator.xml:936 usingvalidator.xml:949 usingvalidator.xml:963 usingvalidator.xml:995 usingvalidator.xml:1049
+#, no-c-format
+msgid "<entry>yes</entry>"
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:717 usingvalidator.xml:730 usingvalidator.xml:896 usingvalidator.xml:909 usingvalidator.xml:938
+#, no-c-format
+msgid "field/property"
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:719
+#, no-c-format
+msgid "Check that the annotated element is <constant>false</constant>."
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:722 usingvalidator.xml:735 usingvalidator.xml:752 usingvalidator.xml:772 usingvalidator.xml:792 usingvalidator.xml:824 usingvalidator.xml:838 usingvalidator.xml:916 usingvalidator.xml:930 usingvalidator.xml:943 usingvalidator.xml:957 usingvalidator.xml:971 usingvalidator.xml:989 usingvalidator.xml:1026 usingvalidator.xml:1043 usingvalidator.xml:1059
+#, no-c-format
+msgid "none"
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:726
+#, no-c-format
+msgid "@AssertTrue"
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:732
+#, no-c-format
+msgid "Check that the annotated element is <constant>true</constant>."
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:739
+#, no-c-format
+msgid "@CreditCardNumber"
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:741 usingvalidator.xml:817 usingvalidator.xml:844 usingvalidator.xml:907 usingvalidator.xml:922 usingvalidator.xml:977 usingvalidator.xml:1011 usingvalidator.xml:1032
+#, no-c-format
+msgid "<entry>no</entry>"
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:743 usingvalidator.xml:1034
+#, no-c-format
+msgid "field/property. The supported type is <classname>String</classname>."
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:746
+#, no-c-format
+msgid "Check that the annotated string passes the Luhn checksum test. Note, this validation aims to check for user mistake, not credit card validity! See also <ulink url=\"http://www.merriampark.com/anatomycc.htm\">Anatomy of Credit Card Numbers</ulink>."
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:756
+#, no-c-format
+msgid "@DecimalMax"
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:760 usingvalidator.xml:780 usingvalidator.xml:800 usingvalidator.xml:860 usingvalidator.xml:878 usingvalidator.xml:979
+#, no-c-format
+msgid "field/property. Supported types are <classname>BigDecimal</classname>, <classname>BigInteger</classname>, <classname>String</classname>, <classname>byte</classname>, <classname>short</classname>, <classname>int</classname>, <classname>long</classname> and the respective wrappers of the primitive types."
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:767
+#, no-c-format
+msgid "The annotated element must be a number whose value must be lower or equal to the specified maximum. The parameter value is the string representation of the max value according to the <classname>BigDecimal</classname> string representation."
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:776
+#, no-c-format
+msgid "@DecimalMin"
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:787
+#, no-c-format
+msgid "The annotated element must be a number whose value must be higher or equal to the specified minimum. The parameter value is the string representation of the min value according to the <classname>BigDecimal</classname> string representation."
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:796
+#, no-c-format
+msgid "@Digits(integer=, fraction=)"
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:807
+#, no-c-format
+msgid "Check whether the property is a number having up to <literal>integer</literal> digits and <literal>fraction</literal> fractional digits."
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:811
+#, no-c-format
+msgid "Define column precision and scale."
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:815
+#, no-c-format
+msgid "@Email"
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:819 usingvalidator.xml:846 usingvalidator.xml:965
+#, no-c-format
+msgid "field/property. Needs to be a string."
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:821
+#, no-c-format
+msgid "Check whether the specified string is a valid email address."
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:828
+#, no-c-format
+msgid "@Future"
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:832 usingvalidator.xml:951
+#, no-c-format
+msgid "field/property. Supported types are <classname>java.util.Date</classname> and <classname>java.util.Calendar</classname>."
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:836
+#, no-c-format
+msgid "Checks whether the annotated date is in the future."
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:842
+#, no-c-format
+msgid "@Length(min=, max=)"
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:848
+#, no-c-format
+msgid "Validate that the annotated string is between <parameter>min</parameter> and <parameter>max</parameter> included."
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:852 usingvalidator.xml:1005
+#, no-c-format
+msgid "Column length will be set to max."
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:856
+#, no-c-format
+msgid "@Max"
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:867
+#, no-c-format
+msgid "Checks whether the annotated value is less than or equal to the specified maximum."
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:870 usingvalidator.xml:888
+#, no-c-format
+msgid "Add a check constraint on the column."
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:874
+#, no-c-format
+msgid "@Min"
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:885
+#, no-c-format
+msgid "Checks whether the annotated value is higher than or equal to the specified minimum."
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:892
+#, no-c-format
+msgid "@NotNull"
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:898
+#, no-c-format
+msgid "Check that the annotated value is not <constant>null.</constant>"
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:901
+#, no-c-format
+msgid "Column(s) are not null."
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:905
+#, no-c-format
+msgid "@NotBlank"
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:911
+#, no-c-format
+msgid "Check that the annotated string is not null and the trimmed length is greater than 0. The difference to @NotEmpty is that this constraint can only be applied on strings and that trailing whitespaces are ignored."
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:920
+#, no-c-format
+msgid "@NotEmpty"
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:924
+#, no-c-format
+msgid "field/property. Supported types are String, Collection, Map and arrays."
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:927
+#, no-c-format
+msgid "Check whether the annotated element is not <constant>null</constant> nor empty."
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:934
+#, no-c-format
+msgid "@Null"
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:940
+#, no-c-format
+msgid "Check that the annotated value is <constant>null.</constant>"
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:947
+#, no-c-format
+msgid "@Past"
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:955
+#, no-c-format
+msgid "Checks whether the annotated date is in the past."
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:961
+#, no-c-format
+msgid "@Pattern(regex=, flag=)"
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:967
+#, no-c-format
+msgid "Checks if the annotated string matches the regular expression <parameter>regex</parameter> considering the given flag <parameter>match</parameter>."
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:975
+#, no-c-format
+msgid "@Range(min=, max=)"
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:986
+#, no-c-format
+msgid "Check whether the annotated value lies between (inclusive) the specified minimum and maximum."
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:993
+#, no-c-format
+msgid "@Size(min=, max=)"
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:997
+#, no-c-format
+msgid "field/property. Supported types are <classname>String</classname>, <classname>Collection</classname>, <classname>Map</classname> and <classname>arrays</classname>."
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:1002
+#, no-c-format
+msgid "Check if the annotated element size is between min and max (inclusive)."
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:1009
+#, no-c-format
+msgid "@ScriptAssert(lang=, script=, alias=)"
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:1013
+#, no-c-format
+msgid "type"
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:1015
+#, no-c-format
+msgid "Checks whether the given script can successfully be evaluated against the annotated element. In order to use this constraint, an implementation of the Java Scripting API as defined by JSR 223 (\"Scripting for the Java<superscript>TM</superscript> Platform\") must part of the class path. This is automatically the case when running on Java 6. For older Java versions, the JSR 223 RI can be added manually to the class path.The expressions to be evaluated can be written in any scripting or expression language, for which a JSR 223 compatible engine can be found in the class path."
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:1030
+#, no-c-format
+msgid "@URL(protocol=, host=, port=)"
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:1037
+#, no-c-format
+msgid "Check if the annotated string is a valid URL. If any of parameters <parameter>protocol</parameter>, <parameter>host</parameter> or <parameter>port</parameter> is specified the URL must match the specified values in the according part."
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:1047
+#, no-c-format
+msgid "@Valid"
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:1051
+#, no-c-format
+msgid "field/property. Any non-primitive types are supported."
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:1054
+#, no-c-format
+msgid "Performs validation recursively on the associated object. If the object is a collection or an array, the elements are validated recursively. If the object is a map, the value elements are validated recursively."
+msgstr ""
+
+#. Tag: para
+#: usingvalidator.xml:1066
+#, no-c-format
+msgid "On top of the parameters indicated in <xref linkend=\"table-builtin-constraints\"/> each constraint supports the parameters <parameter>message</parameter>, <parameter>groups</parameter> and <parameter>payload</parameter>. This is a requirement of the Bean Validation specification."
+msgstr ""
+
+#. Tag: para
+#: usingvalidator.xml:1073
+#, no-c-format
+msgid "In some cases these built-in constraints will not fulfill your requirements. In this case you can literally in a minute write your own constraints. We will discuss this in"
+msgstr ""
+
Added: validator/trunk/hibernate-validator/src/main/docbook/pot/modules/xmlconfiguration.pot
===================================================================
--- validator/trunk/hibernate-validator/src/main/docbook/pot/modules/xmlconfiguration.pot (rev 0)
+++ validator/trunk/hibernate-validator/src/main/docbook/pot/modules/xmlconfiguration.pot 2010-07-06 15:18:26 UTC (rev 19904)
@@ -0,0 +1,190 @@
+# SOME DESCRIPTIVE TITLE.
+# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
+#
+#, fuzzy
+msgid ""
+msgstr ""
+"Project-Id-Version: PACKAGE VERSION\n"
+"Report-Msgid-Bugs-To: http://bugs.kde.org\n"
+"POT-Creation-Date: 2010-07-06 14:46+0000\n"
+"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
+"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
+"Language-Team: LANGUAGE <kde-i18n-doc(a)kde.org>\n"
+"MIME-Version: 1.0\n"
+"Content-Type: application/x-xml2pot; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+
+#. Tag: title
+#: xmlconfiguration.xml:25
+#, no-c-format
+msgid "XML configuration"
+msgstr ""
+
+#. Tag: filename
+#: xmlconfiguration.xml:28
+#, no-c-format
+msgid "<filename>validation.xml</filename>"
+msgstr ""
+
+#. Tag: para
+#: xmlconfiguration.xml:30
+#, no-c-format
+msgid "The key to enable XML configuration for Hibernate Validator is the file <filename>validation.xml</filename>. If this file exists in the classpath its configuration will be applied when the <classname>ValidationFactory</classname> gets created. <xref linkend=\"image-validation-configuration\"/> shows a model view of the xsd <filename>valiation.xml</filename> has to adhere to."
+msgstr ""
+
+#. Tag: title
+#: xmlconfiguration.xml:37
+#, no-c-format
+msgid "validation-configuration-1.0.xsd"
+msgstr ""
+
+#. Tag: para
+#: xmlconfiguration.xml:52
+#, no-c-format
+msgid "shows the several configuration options of <filename>validation.xml</filename>."
+msgstr ""
+
+#. Tag: title
+#: xmlconfiguration.xml:56
+#, no-c-format
+msgid "<title>validation.xml</title>"
+msgstr ""
+
+#. Tag: programlisting
+#: xmlconfiguration.xml:58
+#, no-c-format
+msgid ""
+ "<validation-config xmlns=\"http://jboss.org/xml/ns/javax/validation/configuration\"\n"
+ " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"
+ " xsi:schemaLocation=\"http://jboss.org/xml/ns/javax/validation/configuration\">\n"
+ " <default-provider>org.hibernate.validator.HibernateValidator</default-provider>\n"
+ " <message-interpolator>org.hibernate.validator.engine.ResourceBundleMessageInterpolator</message-interpolator>\n"
+ " <traversable-resolver>org.hibernate.validator.engine.resolver.DefaultTraversableResolver</traversable-resolver>\n"
+ " <constraint-validator-factory>org.hibernate.validator.engine.ConstraintValidatorFactoryImpl</constraint-validator-factory>\n"
+ " <constraint-mapping>/constraints-car.xml</constraint-mapping>\n"
+ " <property name=\"prop1\">value1</property>\n"
+ " <property name=\"prop2\">value2</property>\n"
+ "</validation-config>"
+msgstr ""
+
+#. Tag: para
+#: xmlconfiguration.xml:62
+#, no-c-format
+msgid "There can only be one <filename>validation.xml</filename> in the classpath. If more than one is found an exception is thrown."
+msgstr ""
+
+#. Tag: para
+#: xmlconfiguration.xml:66
+#, no-c-format
+msgid "All settings shown in the <filename>validation.xml</filename> are optional and in the case of <xref linkend=\"example-validation-xml\"/> show the defaults used within Hibernate Validator. The node <property>default-provider</property> allows to choose the Bean Validation provider. This is useful if there is more than one provider in the classpath. <property>message-interpolator</property>, <property>traversable-resolver</property> and <property>constraint-validator-factory</property> allow to customize the <classname>javax.validation.MessageInterpolator</classname>, <classname>javax.validation.TraversableResolver</classname> resp. <classname>javax.validation.ConstraintValidatorFactory</classname>. The same configuration options are also available programmatically through the <classname>javax.validation.Configuration</classname>. In fact XML configuration will be overridden by values explicitly specified via the API. It is even possible to ignore the XML configuration!
completely via <methodname> Configuration.ignoreXmlConfiguration()</methodname>. See also <xref linkend=\"validator-bootstrapping\"/>."
+msgstr ""
+
+#. Tag: para
+#: xmlconfiguration.xml:84
+#, no-c-format
+msgid "Via the <property>constraint-mapping</property> you can list an arbitrary number of additional XML files containing the actual constraint configuration. See <xref linkend=\"section-mapping-constraints\"/>."
+msgstr ""
+
+#. Tag: para
+#: xmlconfiguration.xml:88
+#, no-c-format
+msgid "Last but not least, you can specify provider specific properties via the <property>property</property> nodes. Hibernate Validator does currently not make use of any custom properties."
+msgstr ""
+
+#. Tag: title
+#: xmlconfiguration.xml:94
+#, no-c-format
+msgid "Mapping constraints"
+msgstr ""
+
+#. Tag: para
+#: xmlconfiguration.xml:96
+#, no-c-format
+msgid "Expressing constraints in XML is possible via files adhering to the xsd seen in <xref linkend=\"image-mapping-configuration\"/>. Note that these mapping files are only processed if listed via <property>constraint-mapping</property> in your <filename>validation.xml</filename>."
+msgstr ""
+
+#. Tag: title
+#: xmlconfiguration.xml:103
+#, no-c-format
+msgid "validation-mapping-1.0.xsd"
+msgstr ""
+
+#. Tag: para
+#: xmlconfiguration.xml:118
+#, no-c-format
+msgid "shows how our classes Car and RentalCar from <xref linkend=\"example-car\"/> resp. <xref linkend=\"example-rental-car\"/> could be mapped in XML."
+msgstr ""
+
+#. Tag: title
+#: xmlconfiguration.xml:123
+#, no-c-format
+msgid "constraints-car.xml"
+msgstr ""
+
+#. Tag: programlisting
+#: xmlconfiguration.xml:125
+#, no-c-format
+msgid ""
+ "<constraint-mappings xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"
+ " xsi:schemaLocation=\"http://jboss.org/xml/ns/javax/validation/mapping validation-mapping-1.0.xsd\"\n"
+ " xmlns=\"http://jboss.org/xml/ns/javax/validation/mapping\">\n"
+ " <default-package>org.hibernate.validator.quickstart</default-package>\n"
+ " <bean class=\"Car\" ignore-annotations=\"true\">\n"
+ " <field name=\"manufacturer\">\n"
+ " <constraint annotation=\"javax.validation.constraints.NotNull\"/>\n"
+ " </field>\n"
+ " <field name=\"licensePlate\">\n"
+ " <constraint annotation=\"javax.validation.constraints.NotNull\"/>\n"
+ " </field>\n"
+ " <field name=\"seatCount\">\n"
+ " <constraint annotation=\"javax.validation.constraints.Min\">\n"
+ " <element name=\"value\">2</element>\n"
+ " </constraint>\n"
+ " </field>\n"
+ " <field name=\"driver\">\n"
+ " <valid/>\n"
+ " </field>\n"
+ " <getter name=\"passedVehicleInspection\" ignore-annotations=\"true\">\n"
+ " <constraint annotation=\"javax.validation.constraints.AssertTrue\">\n"
+ " <message>The car has to pass the vehicle inspection first</message>\n"
+ " <groups>\n"
+ " <value>CarChecks</value>\n"
+ " </groups>\n"
+ " <element name=\"max\">10</element>\n"
+ " </constraint>\n"
+ " </getter>\n"
+ " </bean>\n"
+ " <bean class=\"RentalCar\" ignore-annotations=\"true\">\n"
+ " <class ignore-annotations=\"true\">\n"
+ " <group-sequence>\n"
+ " <value>RentalCar</value>\n"
+ " <value>CarChecks</value>\n"
+ " </group-sequence>\n"
+ " </class>\n"
+ " </bean>\n"
+ " <constraint-definition annotation=\"org.mycompany.CheckCase\" include-existing-validator=\"false\">\n"
+ " <validated-by include-existing-validators=\"false\">\n"
+ " <value>org.mycompany.CheckCaseValidator</value>\n"
+ " </validated-by>\n"
+ " </constraint-definition>\n"
+ "</constraint-mappings>"
+msgstr ""
+
+#. Tag: para
+#: xmlconfiguration.xml:128
+#, no-c-format
+msgid "The XML configuration is closely mirroring the programmatic API. For this reason it should suffice to just add some comments. <property>default-package</property> is used for all fields where a classname is expected. If the specified class is not fully qualified the configured default package will be used. Every mapping file can then have several <property>bean</property> nodes, each describing the constraints on the entity with the specified class name.<warning> <para>A given entity can only be configured once across all configuration files. If the same class is configured more than once an exception is thrown.</para> </warning>Settings <property>ignore-annotations</property> to true means that constraint annotations placed on the configured bean are ignored. The default for this value is <constant>true</constant>. ignore-annotations is also available for the nodes <property>class</property>, <property>fields</property> and <property>getter</property>. If not explic!
itly specified on these levels the configured <property>bean</property> value applies. Otherwise do the nodes <property>class</property>, <property>fields</property> and <property>getter</property> determine on which level the constraints are placed (see <xref linkend=\"validator-usingvalidator-annotate\"/>). The <property>constraint</property> node is then used to add a constraint on the corresponding level. Each constraint definition must define the class via the annotation attribute. The constraint attributes required by the Bean Validation specification (<property>message</property>, <property>groups</property> and <property>payload</property>) have dedicated nodes. All other constraint specific attributes are configured using the the <property>element</property> node."
+msgstr ""
+
+#. Tag: para
+#: xmlconfiguration.xml:156
+#, no-c-format
+msgid "The class node also allows to reconfigure the default group sequence (see <xref linkend=\"section-default-group-class\"/>) via the <property>group-sequence</property> node."
+msgstr ""
+
+#. Tag: para
+#: xmlconfiguration.xml:160
+#, no-c-format
+msgid "Last but not least, the list of <classname>ConstraintValidator</classname>s associated to a given constraint can be altered via the <property>constraint-definition</property> node. The <property>annotation</property> attribute represents the constraint annotation being altered. The <property>validated-by</property> elements represent the (ordered) list of <classname>ConstraintValidator</classname> implementations associated to the constraint. If <property>include-existing-validator</property> is set to <constant>false</constant>, validators defined on the constraint annotation are ignored. If set to <constant>true</constant>, the list of ConstraintValidators described in XML are concatenated to the list of validators described on the annotation."
+msgstr ""
+
Added: validator/trunk/hibernate-validator/src/main/docbook/zh-CN/master.po
===================================================================
--- validator/trunk/hibernate-validator/src/main/docbook/zh-CN/master.po (rev 0)
+++ validator/trunk/hibernate-validator/src/main/docbook/zh-CN/master.po 2010-07-06 15:18:26 UTC (rev 19904)
@@ -0,0 +1,50 @@
+# Language zh-CN translations for PACKAGE package.
+# Automatically generated, 2010.
+#
+msgid ""
+msgstr ""
+"Project-Id-Version: PACKAGE VERSION\n"
+"Report-Msgid-Bugs-To: http://bugs.kde.org\n"
+"POT-Creation-Date: 2010-07-06 14:46+0000\n"
+"PO-Revision-Date: 2010-07-06 14:46+0000\n"
+"Last-Translator: Automatically generated\n"
+"Language-Team: none\n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+
+#. Tag: title
+#: master.xml:26
+#, no-c-format
+msgid "Hibernate Validator"
+msgstr ""
+
+#. Tag: subtitle
+#: master.xml:27
+#, no-c-format
+msgid "JSR 303 Reference Implementation"
+msgstr ""
+
+#. Tag: subtitle
+#: master.xml:28
+#, no-c-format
+msgid "Reference Guide"
+msgstr ""
+
+#. Tag: holder
+#: master.xml:34
+#, no-c-format
+msgid "©rightHolder;"
+msgstr ""
+
+#. Tag: author
+#: master.xml:37
+#, no-c-format
+msgid "<firstname>Hardy</firstname> <surname>Ferentschik</surname>"
+msgstr ""
+
+#. Tag: author
+#: master.xml:41
+#, no-c-format
+msgid "<firstname>Gunnar</firstname> <surname>Morling</surname>"
+msgstr ""
Added: validator/trunk/hibernate-validator/src/main/docbook/zh-CN/modules/annotationprocessor.po
===================================================================
--- validator/trunk/hibernate-validator/src/main/docbook/zh-CN/modules/annotationprocessor.po (rev 0)
+++ validator/trunk/hibernate-validator/src/main/docbook/zh-CN/modules/annotationprocessor.po 2010-07-06 15:18:26 UTC (rev 19904)
@@ -0,0 +1,643 @@
+# Language zh-CN translations for PACKAGE package.
+# Automatically generated, 2010.
+#
+msgid ""
+msgstr ""
+"Project-Id-Version: PACKAGE VERSION\n"
+"Report-Msgid-Bugs-To: http://bugs.kde.org\n"
+"POT-Creation-Date: 2010-07-06 14:46+0000\n"
+"PO-Revision-Date: 2010-07-06 14:46+0000\n"
+"Last-Translator: Automatically generated\n"
+"Language-Team: none\n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+
+#. Tag: title
+#: annotationprocessor.xml:25
+#, no-c-format
+msgid "Annotation Processor (EXPERIMENTAL)"
+msgstr ""
+
+#. Tag: para
+#: annotationprocessor.xml:27
+#, no-c-format
+msgid "Have you ever caught yourself by unintentionally doing things like"
+msgstr ""
+
+#. Tag: para
+#: annotationprocessor.xml:32
+#, no-c-format
+msgid ""
+"annotating Strings with @Min to specify a minimum length (instead of using "
+"@Size)"
+msgstr ""
+
+#. Tag: para
+#: annotationprocessor.xml:37
+#, no-c-format
+msgid ""
+"annotating the setter of a JavaBean property (instead of the getter method)"
+msgstr ""
+
+#. Tag: para
+#: annotationprocessor.xml:42
+#, no-c-format
+msgid ""
+"annotating static fields/methods with constraint annotations (which is not "
+"supported)?"
+msgstr ""
+
+#. Tag: para
+#: annotationprocessor.xml:47
+#, no-c-format
+msgid ""
+"Then the Hibernate Validator Annotation Processor is the right thing for "
+"you. It helps preventing such mistakes by plugging into the build process "
+"and raising compilation errors whenever constraint annotations are "
+"incorrectly used."
+msgstr ""
+
+#. Tag: para
+#: annotationprocessor.xml:53
+#, no-c-format
+msgid ""
+"A first version of the Hibernate Validator Annotation Processor is part of "
+"Hibernate Validator since release 4.1. It is currently still under "
+"development and should therefore be considered as an experimental feature. "
+"Some <link linkend=\"section-known-issues\">known issues</link> can be found "
+"at the end of this chapter. In case any problems arise when using the "
+"processor feel free to ask for help at the <ulink url=\"https://forum."
+"hibernate.org/viewforum.php?f=9\">forum</ulink> or create an issue "
+"within<ulink url=\"http://opensource.atlassian.com/projects/hibernate/browse/"
+"HV/component/10356\"> JIRA</ulink>."
+msgstr ""
+
+#. Tag: title
+#: annotationprocessor.xml:66
+#, no-c-format
+msgid "Prerequisites"
+msgstr ""
+
+#. Tag: para
+#: annotationprocessor.xml:68
+#, no-c-format
+msgid ""
+"The Hibernate Validator Annotation Processor is based on the \"Pluggable "
+"Annotation Processing API\" as defined by <ulink url=\"http://jcp.org/en/jsr/"
+"detail?id=269\">JSR 269</ulink>. This API is part of the Java Platform since "
+"Java 6. So be sure to use this or a later version."
+msgstr ""
+
+#. Tag: title
+#: annotationprocessor.xml:76
+#, no-c-format
+msgid "Features"
+msgstr ""
+
+#. Tag: para
+#: annotationprocessor.xml:78
+#, no-c-format
+msgid ""
+"As of Hibernate Validator 4.1 the Hibernate Validator Annotation Processor "
+"checks that:"
+msgstr ""
+
+#. Tag: para
+#: annotationprocessor.xml:83
+#, no-c-format
+msgid ""
+"constraint annotations are allowed for the type of the annotated element"
+msgstr ""
+
+#. Tag: para
+#: annotationprocessor.xml:88
+#, no-c-format
+msgid "JavaBean getter methods are annotated in case of property validation"
+msgstr ""
+
+#. Tag: para
+#: annotationprocessor.xml:93
+#, no-c-format
+msgid ""
+"only non-static fields or properties are annotated with constraint "
+"annotations"
+msgstr ""
+
+#. Tag: para
+#: annotationprocessor.xml:98
+#, no-c-format
+msgid "only non-primitive fields or properties are annotated with @Valid"
+msgstr ""
+
+#. Tag: para
+#: annotationprocessor.xml:103
+#, no-c-format
+msgid ""
+"only such annotation types are annotated with constraint annotations which "
+"are constraint annotations themselves"
+msgstr ""
+
+#. Tag: title
+#: annotationprocessor.xml:110
+#, no-c-format
+msgid "Options"
+msgstr ""
+
+#. Tag: para
+#: annotationprocessor.xml:112
+#, no-c-format
+msgid ""
+"The behavior of the Hibernate Validator Annotation Processor can be "
+"controlled using the <ulink url=\"http://java.sun.com/javase/6/docs/"
+"technotes/tools/windows/javac.html#options\">processor options</ulink> "
+"listed in table<xref linkend=\"table_processor_options\"/>:"
+msgstr ""
+
+#. Tag: title
+#: annotationprocessor.xml:119
+#, no-c-format
+msgid "Hibernate Validator Annotation Processor options"
+msgstr ""
+
+#. Tag: entry
+#: annotationprocessor.xml:124
+#, no-c-format
+msgid "Option"
+msgstr ""
+
+#. Tag: entry
+#: annotationprocessor.xml:126
+#, no-c-format
+msgid "Explanation"
+msgstr ""
+
+#. Tag: varname
+#: annotationprocessor.xml:132
+#, no-c-format
+msgid "diagnosticKind"
+msgstr ""
+
+#. Tag: entry
+#: annotationprocessor.xml:134
+#, no-c-format
+msgid ""
+"Controls how constraint problems are reported. Must be the string "
+"representation of one of the values from the enum <classname>javax.tools."
+"Diagnostic.Kind</classname>, e.g. <classname>WARNING</classname>. A value of "
+"<classname>ERROR</classname> will cause compilation to halt whenever the AP "
+"detects a constraint problem. Defaults to <classname>ERROR</classname>."
+msgstr ""
+
+#. Tag: varname
+#: annotationprocessor.xml:144
+#, no-c-format
+msgid "verbose"
+msgstr ""
+
+#. Tag: entry
+#: annotationprocessor.xml:146
+#, no-c-format
+msgid ""
+"Controls whether detailed processing information shall be displayed or not, "
+"useful for debugging purposes. Must be either <varname>true</varname> "
+"or<varname>false</varname>. Defaults to <varname>false</varname>."
+msgstr ""
+
+#. Tag: title
+#: annotationprocessor.xml:157
+#, no-c-format
+msgid "Using the Annotation Processor"
+msgstr ""
+
+#. Tag: para
+#: annotationprocessor.xml:159
+#, no-c-format
+msgid ""
+"This section shows in detail how to integrate the Hibernate Validator "
+"Annotation Processor into command line builds (javac, Ant, Maven) as well as "
+"IDE-based builds (Eclipse, IntelliJ IDEA, NetBeans)."
+msgstr ""
+
+#. Tag: title
+#: annotationprocessor.xml:165
+#, no-c-format
+msgid "Command line builds"
+msgstr ""
+
+#. Tag: title
+#: annotationprocessor.xml:168
+#, no-c-format
+msgid "javac"
+msgstr ""
+
+#. Tag: para
+#: annotationprocessor.xml:170
+#, no-c-format
+msgid ""
+"When compiling on the command line using <ulink url=\"http://java.sun.com/"
+"javase/6/docs/technotes/guides/javac/index.html\">javac</ulink>, specify the "
+"following JARs using the \"processorpath\" option:"
+msgstr ""
+
+#. Tag: para
+#: annotationprocessor.xml:176 annotationprocessor.xml:287
+#: annotationprocessor.xml:377
+#, no-c-format
+msgid "validation-api-&bvVersion;.jar"
+msgstr ""
+
+#. Tag: para
+#: annotationprocessor.xml:180 annotationprocessor.xml:291
+#: annotationprocessor.xml:381
+#, no-c-format
+msgid "hibernate-validator-annotation-processor-&version;.jar"
+msgstr ""
+
+#. Tag: para
+#: annotationprocessor.xml:184
+#, no-c-format
+msgid ""
+"The following listing shows an example. The processor will be detected "
+"automatically by the compiler and invoked during compilation."
+msgstr ""
+
+#. Tag: title
+#: annotationprocessor.xml:189
+#, no-c-format
+msgid "Using the annotation processor with javac"
+msgstr ""
+
+#. Tag: programlisting
+#: annotationprocessor.xml:191
+#, no-c-format
+msgid ""
+"javac src/main/java/org/hibernate/validator/ap/demo/Car.java \\\n"
+" -cp /path/to/validation-api-&bvVersion;.jar \\ \n"
+" -processorpath /path/to/validation-api-&bvVersion;.jar:/path/to/hibernate-"
+"validator-annotation-processor-&version;.jar"
+msgstr ""
+
+#. Tag: title
+#: annotationprocessor.xml:196
+#, no-c-format
+msgid "Apache Ant"
+msgstr ""
+
+#. Tag: para
+#: annotationprocessor.xml:198
+#, no-c-format
+msgid ""
+"Similar to directly working with javac, the annotation processor can be "
+"added as as compiler argument when invoking the <ulink url=\"http://ant."
+"apache.org/manual/CoreTasks/javac.html\">javac task</ulink> for <ulink url="
+"\"http://ant.apache.org/\">Apache Ant</ulink>:"
+msgstr ""
+
+#. Tag: title
+#: annotationprocessor.xml:205
+#, no-c-format
+msgid "Using the annotation processor with Ant"
+msgstr ""
+
+#. Tag: programlisting
+#: annotationprocessor.xml:207
+#, no-c-format
+msgid ""
+"<javac srcdir=\"src/main\"\n"
+" destdir=\"build/classes\"\n"
+" classpath=\"/path/to/validation-api-&bvVersion;.jar\">\n"
+" <compilerarg value=\"-processorpath\" />\n"
+" <compilerarg value=\"/path/to/validation-api-&bvVersion;.jar:/path/"
+"to/hibernate-validator-annotation-processor-&version;.jar\"/>\n"
+"</javac>"
+msgstr ""
+
+#. Tag: title
+#: annotationprocessor.xml:212
+#, no-c-format
+msgid "Maven"
+msgstr ""
+
+#. Tag: para
+#: annotationprocessor.xml:214
+#, no-c-format
+msgid ""
+"There are several options for integrating the annotation processor with "
+"<ulink url=\"http://maven.apache.org/\">Apache Maven</ulink>. Generally it "
+"is sufficient to add the Hibernate Validator Annotation Processor as "
+"dependency to your project:"
+msgstr ""
+
+#. Tag: title
+#: annotationprocessor.xml:220
+#, no-c-format
+msgid "Adding the HV Annotation Processor as dependency"
+msgstr ""
+
+#. Tag: programlisting
+#: annotationprocessor.xml:222
+#, no-c-format
+msgid ""
+"...\n"
+"<dependency>\n"
+" <groupId>org.hibernate</groupId>\n"
+" <artifactId>hibernate-validator-annotation-processor</"
+"artifactId>\n"
+" <version>&version;</version>\n"
+" <scope>compile</scope>\n"
+"</dependency>\n"
+"..."
+msgstr ""
+
+#. Tag: para
+#: annotationprocessor.xml:225
+#, no-c-format
+msgid ""
+"The processor will then be executed automatically by the compiler. This "
+"basically works, but comes with the disadavantage that in some cases "
+"messages from the annotation processor are not displayed (see <ulink url="
+"\"http://jira.codehaus.org/browse/MCOMPILER-66\">MCOMPILER-66</ulink>)."
+msgstr ""
+
+#. Tag: para
+#: annotationprocessor.xml:231
+#, no-c-format
+msgid ""
+"Another option is using the <ulink url=\"http://code.google.com/p/maven-"
+"annotation-plugin/\">Maven Annotation Plugin</ulink>. At the time of this "
+"writing the plugin is not yet available in any of the well-known "
+"repositories. Therefore you have to add the project's own repository to your "
+"settings.xml or pom.xml:"
+msgstr ""
+
+#. Tag: title
+#: annotationprocessor.xml:239
+#, no-c-format
+msgid "Adding the Maven Annotation Plugin repository"
+msgstr ""
+
+#. Tag: programlisting
+#: annotationprocessor.xml:241
+#, no-c-format
+msgid ""
+"...\n"
+"<pluginRepositories>\n"
+" <pluginRepository>\n"
+" <id>maven-annotation-plugin-repo</id>\n"
+" <url>http://maven-annotation-plugin.googlecode.com/svn/trunk/"
+"mavenrepo</url>\n"
+" </pluginRepository>\n"
+"</pluginRepositories>\n"
+"..."
+msgstr ""
+
+#. Tag: para
+#: annotationprocessor.xml:242
+#, no-c-format
+msgid ""
+"Now disable the standard annotation processing performed by the compiler "
+"plugin and configure the annotation plugin by specifying an execution and "
+"adding the Hibernate Validator Annotation Processor as plugin dependency "
+"(that way the AP is not visible on the project's actual classpath):"
+msgstr ""
+
+#. Tag: title
+#: annotationprocessor.xml:249
+#, no-c-format
+msgid "Configuring the Maven Annotation Plugin"
+msgstr ""
+
+#. Tag: programlisting
+#: annotationprocessor.xml:251
+#, no-c-format
+msgid ""
+"...\n"
+"<plugin>\n"
+" <artifactId>maven-compiler-plugin</artifactId>\n"
+" <configuration>\n"
+" <source>1.6</source>\n"
+" <target>1.6</target>\n"
+" <compilerArgument>-proc:none</compilerArgument>\n"
+" </configuration>\n"
+"</plugin>\n"
+"<plugin>\n"
+" <groupId>org.bsc.maven</groupId>\n"
+" <artifactId>maven-processor-plugin</artifactId>\n"
+" <version>1.3.4</version>\n"
+" <executions>\n"
+" <execution>\n"
+" <id>process</id>\n"
+" <goals>\n"
+" <goal>process</goal>\n"
+" </goals>\n"
+" <phase>process-sources</phase>\n"
+" </execution>\n"
+" </executions>\n"
+" <dependencies>\n"
+" <dependency>\n"
+" <groupId>org.hibernate</groupId>\n"
+" <artifactId>hibernate-validator-annotation-processor</"
+"artifactId>\n"
+" <version>&version;</version>\n"
+" <scope>compile</scope>\n"
+" </dependency>\n"
+" </dependencies>\n"
+"</plugin>\n"
+"..."
+msgstr ""
+
+#. Tag: title
+#: annotationprocessor.xml:257
+#, no-c-format
+msgid "IDE builds"
+msgstr ""
+
+#. Tag: title
+#: annotationprocessor.xml:260
+#, no-c-format
+msgid "Eclipse"
+msgstr ""
+
+#. Tag: para
+#: annotationprocessor.xml:262
+#, no-c-format
+msgid ""
+"Do the following to use the annotation processor within the <ulink url="
+"\"http://www.eclipse.org/\">Eclipse</ulink> IDE:"
+msgstr ""
+
+#. Tag: para
+#: annotationprocessor.xml:267 annotationprocessor.xml:368
+#, no-c-format
+msgid "Right-click your project, choose \"Properties\""
+msgstr ""
+
+#. Tag: para
+#: annotationprocessor.xml:271
+#, no-c-format
+msgid ""
+"Go to \"Java Compiler\" and make sure, that \"Compiler compliance level\" is "
+"set to \"1.6\". Otherwise the processor won't be activated"
+msgstr ""
+
+#. Tag: para
+#: annotationprocessor.xml:277
+#, no-c-format
+msgid ""
+"Go to \"Java Compiler - Annotation Processing\" and choose \"Enable "
+"annotation processing\""
+msgstr ""
+
+#. Tag: para
+#: annotationprocessor.xml:282
+#, no-c-format
+msgid ""
+"Go to \"Java Compiler - Annotation Processing - Factory Path\" and add the "
+"following JARs:"
+msgstr ""
+
+#. Tag: para
+#: annotationprocessor.xml:297
+#, no-c-format
+msgid "Confirm the workspace rebuild"
+msgstr ""
+
+#. Tag: para
+#: annotationprocessor.xml:301
+#, no-c-format
+msgid ""
+"You now should see any annotation problems as regular error markers within "
+"the editor and in the \"Problem\" view:"
+msgstr ""
+
+#. Tag: title
+#: annotationprocessor.xml:313
+#, no-c-format
+msgid "IntelliJ IDEA"
+msgstr ""
+
+#. Tag: para
+#: annotationprocessor.xml:315
+#, no-c-format
+msgid ""
+"The following steps must be followed to use the annotation processor within "
+"<ulink url=\"http://www.jetbrains.com/idea/\">IntelliJ IDEA</ulink> (version "
+"9 and above):"
+msgstr ""
+
+#. Tag: para
+#: annotationprocessor.xml:321
+#, no-c-format
+msgid "Go to \"File\", then \"Settings\","
+msgstr ""
+
+#. Tag: para
+#: annotationprocessor.xml:325
+#, no-c-format
+msgid "Expand the node \"Compiler\", then \"Annotation Processors\""
+msgstr ""
+
+#. Tag: para
+#: annotationprocessor.xml:330
+#, no-c-format
+msgid ""
+"Choose \"Enable annotation processing\" and enter the following as "
+"\"Processor path\": /path/to/validation-api-&bvVersion;.jar:/path/to/"
+"hibernate-validator-annotation-processor-&version;.jar"
+msgstr ""
+
+#. Tag: para
+#: annotationprocessor.xml:336
+#, no-c-format
+msgid ""
+"Add the processor's fully qualified name <classname>org.hibernate.validator."
+"ap.ConstraintValidationProcessor</classname> to the \"Annotation Processors"
+"\" list"
+msgstr ""
+
+#. Tag: para
+#: annotationprocessor.xml:342
+#, no-c-format
+msgid "If applicable add you module to the \"Processed Modules\" list"
+msgstr ""
+
+#. Tag: para
+#: annotationprocessor.xml:347
+#, no-c-format
+msgid ""
+"Rebuilding your project then should show any erronous constraint annotations:"
+msgstr ""
+
+#. Tag: title
+#: annotationprocessor.xml:359
+#, no-c-format
+msgid "NetBeans"
+msgstr ""
+
+#. Tag: para
+#: annotationprocessor.xml:361
+#, no-c-format
+msgid ""
+"Starting with version 6.9, also the <ulink url=\"http://www.netbeans.org/"
+"\">NetBeans</ulink> IDE supports using annotation processors within the IDE "
+"build. To do so, do the following:"
+msgstr ""
+
+#. Tag: para
+#: annotationprocessor.xml:372
+#, no-c-format
+msgid "Go to \"Libraries\", tab \"Processor\", and add the following two JARs:"
+msgstr ""
+
+#. Tag: para
+#: annotationprocessor.xml:387
+#, no-c-format
+msgid ""
+"Go to \"Build - Compiling\", select \"Enable Annotation Processing\" and "
+"\"Enable Annotation Processing in Editor\". Add the annotation processor by "
+"specifying its fully qualified name <classname>org.hibernate.validator.ap."
+"ConstraintValidationProcessor</classname>"
+msgstr ""
+
+#. Tag: para
+#: annotationprocessor.xml:394
+#, no-c-format
+msgid ""
+"Any constraint annotation problems will then be marked directly within the "
+"editor:"
+msgstr ""
+
+#. Tag: title
+#: annotationprocessor.xml:408
+#, no-c-format
+msgid "Known issues"
+msgstr ""
+
+#. Tag: para
+#: annotationprocessor.xml:410
+#, no-c-format
+msgid "The following known issues exist as of May 2010:"
+msgstr ""
+
+#. Tag: para
+#: annotationprocessor.xml:414
+#, no-c-format
+msgid ""
+"<ulink url=\"http://opensource.atlassian.com/projects/hibernate/browse/HV-308"
+"\">HV-308</ulink>: Additional validators registered for a constraint <ulink "
+"url=\"http://docs.jboss.org/hibernate/stable/validator/reference/en/"
+"html_single/#d0e1957\">using XML</ulink> are not evaluated by the annotation "
+"processor."
+msgstr ""
+
+#. Tag: para
+#: annotationprocessor.xml:422
+#, no-c-format
+msgid ""
+"Sometimes custom constraints can't be <ulink url=\"http://opensource."
+"atlassian.com/projects/hibernate/browse/HV-293\">properly evaluated</ulink> "
+"when using the processor within Eclipse. Cleaning the project can help in "
+"these situations. This seems to be an issue with the Eclipse JSR 269 API "
+"implementation, but further investigation is required here."
+msgstr ""
Added: validator/trunk/hibernate-validator/src/main/docbook/zh-CN/modules/bootstrapping.po
===================================================================
--- validator/trunk/hibernate-validator/src/main/docbook/zh-CN/modules/bootstrapping.po (rev 0)
+++ validator/trunk/hibernate-validator/src/main/docbook/zh-CN/modules/bootstrapping.po 2010-07-06 15:18:26 UTC (rev 19904)
@@ -0,0 +1,564 @@
+# Language zh-CN translations for PACKAGE package.
+# Automatically generated, 2010.
+#
+msgid ""
+msgstr ""
+"Project-Id-Version: PACKAGE VERSION\n"
+"Report-Msgid-Bugs-To: http://bugs.kde.org\n"
+"POT-Creation-Date: 2010-07-06 14:46+0000\n"
+"PO-Revision-Date: 2010-07-06 14:46+0000\n"
+"Last-Translator: Automatically generated\n"
+"Language-Team: none\n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+
+#. Tag: title
+#: bootstrapping.xml:25
+#, no-c-format
+msgid "Bootstrapping"
+msgstr ""
+
+#. Tag: para
+#: bootstrapping.xml:27
+#, no-c-format
+msgid ""
+"We already seen in <xref linkend=\"section-validator-instance\"/> the "
+"easiest way to create a <classname>Validator</classname> instance - "
+"<methodname>Validation.buildDefaultValidatorFactory</methodname>. In this "
+"chapter we have a look at the other methods in <classname>javax.validation."
+"Validation</classname> and how they allow to configure several aspects of "
+"Bean Validation at bootstrapping time."
+msgstr ""
+
+#. Tag: para
+#: bootstrapping.xml:34
+#, no-c-format
+msgid ""
+"The different bootstrapping options allow, amongst other things, to "
+"bootstrap any Bean Validation implementation on the classpath. Generally, an "
+"available provider is discovered by the <ulink url=\"http://java.sun.com/"
+"j2se/1.3/docs/guide/jar/jar.html#Service%20Provider\">Java Service Provider</"
+"ulink> mechanism. A Bean Validation implementation includes the file "
+"<filename>javax.validation.spi.ValidationProvider</filename> in "
+"<filename>META-INF/services</filename>. This file contains the fully "
+"qualified classname of the <classname>ValidationProvider</classname> of the "
+"implementation. In the case of Hibernate Validator this is <classname>org."
+"hibernate.validator.HibernateValidator</classname>."
+msgstr ""
+
+#. Tag: para
+#: bootstrapping.xml:47
+#, no-c-format
+msgid ""
+"If there are more than one Bean Validation implementation providers in the "
+"classpath and <methodname>Validation.buildDefaultValidatorFactory()</"
+"methodname> is used, there is no guarantee which provider will be chosen. To "
+"enforce the provider <methodname>Validation.byProvider()</methodname> should "
+"be used."
+msgstr ""
+
+#. Tag: title
+#: bootstrapping.xml:56
+#, no-c-format
+msgid ""
+"<classname>Configuration</classname> and <classname>ValidatorFactory</"
+"classname>"
+msgstr ""
+
+#. Tag: para
+#: bootstrapping.xml:59
+#, no-c-format
+msgid ""
+"There are three different methods in the Validation class to create a "
+"Validator instance. The easiest in shown in <xref linkend=\"example-build-"
+"default-validator-factory\"/>."
+msgstr ""
+
+#. Tag: title
+#: bootstrapping.xml:64
+#, no-c-format
+msgid "Validation.buildDefaultValidatorFactory()"
+msgstr ""
+
+#. Tag: programlisting
+#: bootstrapping.xml:66
+#, no-c-format
+msgid ""
+"ValidatorFactory factory = Validation.buildDefaultValidatorFactory();\n"
+"Validator validator = factory.getValidator();"
+msgstr ""
+
+#. Tag: para
+#: bootstrapping.xml:69
+#, no-c-format
+msgid ""
+"You can also use the method <methodname>Validation.byDefaultProvider()</"
+"methodname> which will allow you to configure several aspects of the created "
+"Validator instance:"
+msgstr ""
+
+#. Tag: title
+#: bootstrapping.xml:74
+#, no-c-format
+msgid "Validation.byDefaultProvider()"
+msgstr ""
+
+#. Tag: programlisting
+#: bootstrapping.xml:76
+#, no-c-format
+msgid ""
+"Configuration<?> config = Validation.byDefaultProvider().configure();\n"
+"config.messageInterpolator(new MyMessageInterpolator())\n"
+" .traversableResolver( new MyTraversableResolver())\n"
+" .constraintValidatorFactory(new MyConstraintValidatorFactory());\n"
+"\n"
+"ValidatorFactory factory = config.buildValidatorFactory();\n"
+"Validator validator = factory.getValidator();"
+msgstr ""
+
+#. Tag: para
+#: bootstrapping.xml:79
+#, no-c-format
+msgid ""
+"We will learn more about <classname>MessageInterpolator</classname>, "
+"<classname>TraversableResolver</classname> and "
+"<classname>ConstraintValidatorFactory</classname> in the following sections."
+msgstr ""
+
+#. Tag: para
+#: bootstrapping.xml:84
+#, no-c-format
+msgid ""
+"Last but not least you can ask for a Configuration object of a specific Bean "
+"Validation provider. This is useful if you have more than one Bean "
+"Validation provider in your classpath. In this situation you can make an "
+"explicit choice about which implementation to use. In the case of Hibernate "
+"Validator the <classname>Validator</classname> creation looks like:"
+msgstr ""
+
+#. Tag: title
+#: bootstrapping.xml:92
+#, no-c-format
+msgid "Validation.byProvider( HibernateValidator.class )"
+msgstr ""
+
+#. Tag: programlisting
+#: bootstrapping.xml:94
+#, no-c-format
+msgid ""
+"HibernateValidatorConfiguration config = Validation.byProvider"
+"( HibernateValidator.class ).configure();\n"
+"config.messageInterpolator(new MyMessageInterpolator())\n"
+" .traversableResolver( new MyTraversableResolver())\n"
+" .constraintValidatorFactory(new MyConstraintValidatorFactory());\n"
+"\n"
+"ValidatorFactory factory = config.buildValidatorFactory();\n"
+"Validator validator = factory.getValidator();"
+msgstr ""
+
+#. Tag: para
+#: bootstrapping.xml:98
+#, no-c-format
+msgid ""
+"The generated <classname>Validator</classname> instance is thread safe and "
+"can be cached."
+msgstr ""
+
+#. Tag: classname
+#: bootstrapping.xml:104
+#, no-c-format
+msgid "ValidationProviderResolver"
+msgstr ""
+
+#. Tag: para
+#: bootstrapping.xml:106
+#, no-c-format
+msgid ""
+"In the case that the Java Service Provider mechanism does not work in your "
+"environment or you have a special classloader setup, you are able to provide "
+"a custom <classname>ValidationProviderResolver</classname>. An example in an "
+"OSGi environment you could plug your custom provider resolver like seen in "
+"<xref linkend=\"example-provider-resolver\"/>."
+msgstr ""
+
+#. Tag: title
+#: bootstrapping.xml:113
+#, no-c-format
+msgid "Providing a custom ValidationProviderResolver"
+msgstr ""
+
+#. Tag: programlisting
+#: bootstrapping.xml:115
+#, no-c-format
+msgid ""
+"Configuration<?> config = Validation.byDefaultProvider()\n"
+" .providerResolver( new OSGiServiceDiscoverer() )\n"
+" .configure();\n"
+"\n"
+"ValidatorFactory factory = config.buildValidatorFactory();\n"
+"Validator validator = factory.getValidator();"
+msgstr ""
+
+#. Tag: para
+#: bootstrapping.xml:118
+#, no-c-format
+msgid ""
+"Your <classname>OSGiServiceDiscoverer</classname> must in this case "
+"implement the interface <classname>ValidationProviderResolver</classname>:"
+msgstr ""
+
+#. Tag: title
+#: bootstrapping.xml:123
+#, no-c-format
+msgid "ValidationProviderResolver interface"
+msgstr ""
+
+#. Tag: programlisting
+#: bootstrapping.xml:125
+#, no-c-format
+msgid ""
+"public interface ValidationProviderResolver {\n"
+" /**\n"
+" * Returns a list of ValidationProviders available in the runtime "
+"environment.\n"
+" *\n"
+" * @return list of validation providers. \n"
+" */\n"
+" List<ValidationProvider<?>> getValidationProviders();\n"
+"}"
+msgstr ""
+
+#. Tag: classname
+#: bootstrapping.xml:130
+#, no-c-format
+msgid "MessageInterpolator"
+msgstr ""
+
+#. Tag: para
+#: bootstrapping.xml:132
+#, no-c-format
+msgid ""
+"already discussed the default message interpolation algorithm. If you have "
+"special requirements for your message interpolation you can provide a custom "
+"interpolator using <methodname>Configuration.messageInterpolator()</"
+"methodname>. This message interpolator will be shared by all validators "
+"generated by the <classname>ValidatorFactory</classname> created from this "
+"<classname>Configuration</classname>(see <xref linkend=\"example-message-"
+"interpolator\"/>)."
+msgstr ""
+
+#. Tag: title
+#: bootstrapping.xml:143
+#, no-c-format
+msgid "Providing a custom MessageInterpolator"
+msgstr ""
+
+#. Tag: programlisting
+#: bootstrapping.xml:145
+#, no-c-format
+msgid ""
+"Configuration<?> configuration = Validation.byDefaultProvider()."
+"configure();\n"
+"ValidatorFactory factory = configuration\n"
+" .messageInterpolator(new ContextualMessageInterpolator(configuration."
+"getDefaultMessageInterpolator()))\n"
+" .buildValidatorFactory();\n"
+"\n"
+"Validator validator = factory.getValidator();"
+msgstr ""
+
+#. Tag: para
+#: bootstrapping.xml:149
+#, no-c-format
+msgid ""
+"It is recommended that <classname>MessageInterpolator</classname> "
+"implementations delegate final interpolation to the Bean Validation default "
+"<classname>MessageInterpolator</classname> to ensure standard Bean "
+"Validation interpolation rules are followed. The default implementation is "
+"accessible through <methodname>Configuration.getDefaultMessageInterpolator()"
+"</methodname>."
+msgstr ""
+
+#. Tag: title
+#: bootstrapping.xml:158
+#, no-c-format
+msgid "ResourceBundleLocator"
+msgstr ""
+
+#. Tag: para
+#: bootstrapping.xml:160
+#, no-c-format
+msgid ""
+"A common use case is the ability to specify your own resource bundles for "
+"message interpolation. The default <classname>MessageInterpolator</"
+"classname> implementation in Hibernate Validator is called "
+"<classname>ResourceBundleMessageInterpolator</classname> and per default "
+"loads resource bundles via <methodname>ResourceBundle.getBundle</"
+"methodname>. However, <classname>ResourceBundleMessageInterpolator</"
+"classname> also allows you to specify a custom implementation of "
+"<classname>ResourceBundleLocator</classname> allowing you to provide your "
+"own resource bundles. <xref linkend=\"example-resource-bundle-locator\"/> "
+"shows an example. In the example<methodname> HibernateValidatorConfiguration."
+"getDefaultResourceBundleLocator</methodname> is used to retrieve the default "
+"<classname>ResourceBundleLocator</classname> which then can be passed to the "
+"custom implementation in order implement delegation."
+msgstr ""
+
+#. Tag: title
+#: bootstrapping.xml:179
+#, no-c-format
+msgid "Providing a custom ResourceBundleLocator"
+msgstr ""
+
+#. Tag: programlisting
+#: bootstrapping.xml:181
+#, no-c-format
+msgid ""
+"HibernateValidatorConfiguration configure = Validation.byProvider"
+"(HibernateValidator.class).configure();\n"
+"\n"
+"ResourceBundleLocator defaultResourceBundleLocator = configure."
+"getDefaultResourceBundleLocator(); \n"
+"ResourceBundleLocator myResourceBundleLocator = new "
+"MyCustomResourceBundleLocator(defaultResourceBundleLocator);\n"
+"\n"
+"configure.messageInterpolator(new ResourceBundleMessageInterpolator"
+"(myResourceBundleLocator));"
+msgstr ""
+
+#. Tag: para
+#: bootstrapping.xml:184
+#, no-c-format
+msgid ""
+"Hibernate Validator provides the following implementation of "
+"<classname>ResourceBundleLocator</classname> - "
+"<classname>PlatformResourceBundleLocator</classname> (the default) and "
+"<classname>AggregateResourceBundleLocator</classname>. The latter can be "
+"used to specify a list of resource bundle names which will get loaded and "
+"merged into a single resource bundle. Refer to the JavaDoc documentation for "
+"more information."
+msgstr ""
+
+#. Tag: classname
+#: bootstrapping.xml:195
+#, no-c-format
+msgid "TraversableResolver"
+msgstr ""
+
+#. Tag: para
+#: bootstrapping.xml:197
+#, no-c-format
+msgid ""
+"The usage of the <classname>TraversableResolver</classname> has so far not "
+"been discussed. The idea is that in some cases, the state of a property "
+"should not be accessed. The most obvious example for that is a lazy loaded "
+"property or association of a Java Persistence provider. Validating this lazy "
+"property or association would mean that its state would have to be accessed "
+"triggering a load from the database. Bean Validation controls which property "
+"can and cannot be accessed via the <classname>TraversableResolver</"
+"classname> interface (see <xref linkend=\"example-traversable-resolver\"/>). "
+"In the example HibernateValidatorConfiguration."
+msgstr ""
+
+#. Tag: title
+#: bootstrapping.xml:209
+#, no-c-format
+msgid "TraversableResolver interface"
+msgstr ""
+
+#. Tag: programlisting
+#: bootstrapping.xml:211
+#, no-c-format
+msgid ""
+"/**\n"
+" * Contract determining if a property can be accessed by the Bean Validation "
+"provider\n"
+" * This contract is called for each property that is being either validated "
+"or cascaded.\n"
+" *\n"
+" * A traversable resolver implementation must be thread-safe.\n"
+" *\n"
+" */\n"
+"public interface TraversableResolver {\n"
+" /**\n"
+" * Determine if the Bean Validation provider is allowed to reach the "
+"property state\n"
+" *\n"
+" * @param traversableObject object hosting <code>"
+"traversableProperty</code> or null \n"
+" * if validateValue is called\n"
+" * @param traversableProperty the traversable property.\n"
+" * @param rootBeanType type of the root object passed to the Validator.\n"
+" * @param pathToTraversableObject path from the root object to\n"
+" * <code>traversableObject</code>\n"
+" * (using the path specification defined by Bean Validator).\n"
+" * @param elementType either <code>FIELD</code> or <"
+"code>METHOD</code>.\n"
+" *\n"
+" * @return <code>true</code> if the Bean Validation provider "
+"is allowed to\n"
+" * reach the property state, <code>false</code> "
+"otherwise.\n"
+" */\n"
+" boolean isReachable(Object traversableObject,\n"
+" Path.Node traversableProperty,\n"
+" Class<?> rootBeanType,\n"
+" Path pathToTraversableObject,\n"
+" ElementType elementType);\n"
+"\n"
+" /**\n"
+" * Determine if the Bean Validation provider is allowed to cascade "
+"validation on\n"
+" * the bean instance returned by the property value\n"
+" * marked as <code>(a)Valid</code>.\n"
+" * Note that this method is called only if isReachable returns true for "
+"the same set of\n"
+" * arguments and if the property is marked as <code>@Valid</"
+"code>\n"
+" *\n"
+" * @param traversableObject object hosting <code>"
+"traversableProperty</code> or null\n"
+" * if validateValue is called\n"
+" * @param traversableProperty the traversable property.\n"
+" * @param rootBeanType type of the root object passed to the Validator.\n"
+" * @param pathToTraversableObject path from the root object to\n"
+" * <code>traversableObject</code>\n"
+" * (using the path specification defined by Bean Validator).\n"
+" * @param elementType either <code>FIELD</code> or <"
+"code>METHOD</code>.\n"
+" *\n"
+" * @return <code>true</code> if the Bean Validation provider "
+"is allowed to\n"
+" * cascade validation, <code>false</code> "
+"otherwise.\n"
+" */\n"
+" boolean isCascadable(Object traversableObject,\n"
+" Path.Node traversableProperty,\n"
+" Class<?> rootBeanType,\n"
+" Path pathToTraversableObject,\n"
+" ElementType elementType);\n"
+"}"
+msgstr ""
+
+#. Tag: para
+#: bootstrapping.xml:214
+#, no-c-format
+msgid ""
+"Hibernate Validator provides two <classname>TraversableResolver</classname>s "
+"out of the box which will be enabled automatically depending on your "
+"environment. The first is the <classname>DefaultTraversableResolver</"
+"classname> which will always return true for <methodname>isReachable()</"
+"methodname> and i<methodname>sTraversable()</methodname>. The second is the "
+"<classname>JPATraversableResolver</classname> which gets enabled when "
+"Hibernate Validator gets used in combination with JPA 2. In case you have to "
+"provide your own resolver you can do so again using the "
+"<classname>Configuration</classname> object as seen in <xref linkend="
+"\"example-traversable-resolver-config\"/>."
+msgstr ""
+
+#. Tag: title
+#: bootstrapping.xml:227
+#, no-c-format
+msgid "Providing a custom TraversableResolver"
+msgstr ""
+
+#. Tag: programlisting
+#: bootstrapping.xml:229
+#, no-c-format
+msgid ""
+"Configuration<?> configuration = Validation.byDefaultProvider()."
+"configure();\n"
+"ValidatorFactory factory = configuration\n"
+" .traversableResolver(new MyTraversableResolver())\n"
+" .buildValidatorFactory();\n"
+"\n"
+"Validator validator = factory.getValidator();"
+msgstr ""
+
+#. Tag: classname
+#: bootstrapping.xml:234
+#, no-c-format
+msgid "ConstraintValidatorFactory"
+msgstr ""
+
+#. Tag: para
+#: bootstrapping.xml:236
+#, no-c-format
+msgid ""
+"Last but not least, there is one more configuration option to discuss, the "
+"<classname>ConstraintValidatorFactory</classname>. The default "
+"<classname>ConstraintValidatorFactory</classname> provided by Hibernate "
+"Validator requires a public no-arg constructor to instantiate "
+"<classname>ConstraintValidator</classname> instances (see <xref linkend="
+"\"section-constraint-validator\"/>). Using a custom "
+"<classname>ConstraintValidatorFactory</classname> offers for example the "
+"possibility to use dependency injection in constraint implementations. The "
+"configuration of the custom factory is once more via the "
+"<classname>Configuration</classname> (<xref linkend=\"example-constraint-"
+"validator-factory\"/>)."
+msgstr ""
+
+#. Tag: title
+#: bootstrapping.xml:249
+#, no-c-format
+msgid "Providing a custom ConstraintValidatorFactory"
+msgstr ""
+
+#. Tag: programlisting
+#: bootstrapping.xml:251
+#, no-c-format
+msgid ""
+"Configuration<?> configuration = Validation.byDefaultProvider()."
+"configure();\n"
+"ValidatorFactory factory = configuration\n"
+" .constraintValidatorFactory(new IOCConstraintValidatorFactory())\n"
+" .buildValidatorFactory();\n"
+"\n"
+"Validator validator = factory.getValidator();"
+msgstr ""
+
+#. Tag: para
+#: bootstrapping.xml:254
+#, no-c-format
+msgid "The interface you have to implement is:"
+msgstr ""
+
+#. Tag: title
+#: bootstrapping.xml:257
+#, no-c-format
+msgid "ConstraintValidatorFactory interface"
+msgstr ""
+
+#. Tag: programlisting
+#: bootstrapping.xml:259
+#, no-c-format
+msgid ""
+"public interface ConstraintValidatorFactory {\n"
+" /**\n"
+" * @param key The class of the constraint validator to instantiate.\n"
+" *\n"
+" * @return A constraint validator instance of the specified class.\n"
+" */\n"
+" <T extends ConstraintValidator<?,?>> T getInstance(Class<"
+"T> key);\n"
+"}"
+msgstr ""
+
+#. Tag: para
+#: bootstrapping.xml:263
+#, no-c-format
+msgid ""
+"Any constraint implementation relying on "
+"<classname>ConstraintValidatorFactory</classname> behaviors specific to an "
+"implementation (dependency injection, no no-arg constructor and so on) are "
+"not considered portable."
+msgstr ""
+
+#. Tag: para
+#: bootstrapping.xml:270
+#, no-c-format
+msgid ""
+"ConstraintValidatorFactory should not cache instances as the state of each "
+"instance can be altered in the initialize method."
+msgstr ""
Added: validator/trunk/hibernate-validator/src/main/docbook/zh-CN/modules/customconstraints.po
===================================================================
--- validator/trunk/hibernate-validator/src/main/docbook/zh-CN/modules/customconstraints.po (rev 0)
+++ validator/trunk/hibernate-validator/src/main/docbook/zh-CN/modules/customconstraints.po 2010-07-06 15:18:26 UTC (rev 19904)
@@ -0,0 +1,829 @@
+# Language zh-CN translations for PACKAGE package.
+# Automatically generated, 2010.
+#
+msgid ""
+msgstr ""
+"Project-Id-Version: PACKAGE VERSION\n"
+"Report-Msgid-Bugs-To: http://bugs.kde.org\n"
+"POT-Creation-Date: 2010-07-06 14:46+0000\n"
+"PO-Revision-Date: 2010-07-06 14:46+0000\n"
+"Last-Translator: Automatically generated\n"
+"Language-Team: none\n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+
+#. Tag: title
+#: customconstraints.xml:25
+#, no-c-format
+msgid "Creating custom constraints"
+msgstr ""
+
+#. Tag: para
+#: customconstraints.xml:27
+#, no-c-format
+msgid ""
+"Though the Bean Validation API defines a whole set of standard constraint "
+"annotations one can easily think of situations in which these standard "
+"annotations won't suffice. For these cases you are able to create custom "
+"constraints tailored to your specific validation requirements in a simple "
+"manner."
+msgstr ""
+
+#. Tag: title
+#: customconstraints.xml:34
+#, no-c-format
+msgid "Creating a simple constraint"
+msgstr ""
+
+#. Tag: para
+#: customconstraints.xml:36
+#, no-c-format
+msgid "To create a custom constraint, the following three steps are required:"
+msgstr ""
+
+#. Tag: para
+#: customconstraints.xml:41
+#, no-c-format
+msgid "Create a constraint annotation"
+msgstr ""
+
+#. Tag: para
+#: customconstraints.xml:45
+#, no-c-format
+msgid "Implement a validator"
+msgstr ""
+
+#. Tag: para
+#: customconstraints.xml:49
+#, no-c-format
+msgid "Define a default error message"
+msgstr ""
+
+#. Tag: title
+#: customconstraints.xml:54
+#, no-c-format
+msgid "The constraint annotation"
+msgstr ""
+
+#. Tag: para
+#: customconstraints.xml:56
+#, no-c-format
+msgid ""
+"Let's write a constraint annotation, that can be used to express that a "
+"given string shall either be upper case or lower case. We'll apply it later "
+"on to the <property>licensePlate</property> field of the <classname>Car</"
+"classname> class from <xref linkend=\"validator-gettingstarted\"/> to "
+"ensure, that the field is always an upper-case string."
+msgstr ""
+
+#. Tag: para
+#: customconstraints.xml:63
+#, no-c-format
+msgid ""
+"First we need a way to express the two case modes. We might use "
+"<classname>String</classname> constants, but a better way to go is to use a "
+"Java 5 enum for that purpose:"
+msgstr ""
+
+#. Tag: title
+#: customconstraints.xml:68
+#, no-c-format
+msgid "Enum <classname>CaseMode</classname> to express upper vs. lower case"
+msgstr ""
+
+#. Tag: programlisting
+#: customconstraints.xml:71
+#, no-c-format
+msgid ""
+"package com.mycompany;\n"
+"\n"
+"public enum CaseMode {\n"
+" UPPER, \n"
+" LOWER;\n"
+"}"
+msgstr ""
+
+#. Tag: para
+#: customconstraints.xml:74
+#, no-c-format
+msgid ""
+"Now we can define the actual constraint annotation. If you've never designed "
+"an annotation before, this may look a bit scary, but actually it's not that "
+"hard:"
+msgstr ""
+
+#. Tag: title
+#: customconstraints.xml:79
+#, no-c-format
+msgid "Defining CheckCase constraint annotation"
+msgstr ""
+
+#. Tag: programlisting
+#: customconstraints.xml:81
+#, no-c-format
+msgid ""
+"package com.mycompany;\n"
+"\n"
+"import static java.lang.annotation.ElementType.*;\n"
+"import static java.lang.annotation.RetentionPolicy.*;\n"
+"\n"
+"import java.lang.annotation.Documented;\n"
+"import java.lang.annotation.Retention;\n"
+"import java.lang.annotation.Target;\n"
+"\n"
+"import javax.validation.Constraint;\n"
+"import javax.validation.Payload;\n"
+"\n"
+"@Target( { METHOD, FIELD, ANNOTATION_TYPE })\n"
+"@Retention(RUNTIME)\n"
+"@Constraint(validatedBy = CheckCaseValidator.class)\n"
+"@Documented\n"
+"public @interface CheckCase {\n"
+"\n"
+" String message() default \"{com.mycompany.constraints.checkcase}\";\n"
+"\n"
+" Class<?>[] groups() default {};\n"
+"\n"
+" Class<? extends Payload>[] payload() default {};\n"
+" \n"
+" CaseMode value();\n"
+"\n"
+"}"
+msgstr ""
+
+#. Tag: para
+#: customconstraints.xml:84
+#, no-c-format
+msgid ""
+"An annotation type is defined using the <code>@interface</code> keyword. All "
+"attributes of an annotation type are declared in a method-like manner. The "
+"specification of the Bean Validation API demands, that any constraint "
+"annotation defines"
+msgstr ""
+
+#. Tag: para
+#: customconstraints.xml:91
+#, no-c-format
+msgid ""
+"an attribute <property>message</property> that returns the default key for "
+"creating error messages in case the constraint is violated"
+msgstr ""
+
+#. Tag: para
+#: customconstraints.xml:97
+#, no-c-format
+msgid ""
+"an attribute <property>groups</property> that allows the specification of "
+"validation groups, to which this constraint belongs (see <xref linkend="
+"\"validator-usingvalidator-validationgroups\"/>). This must default to an "
+"empty array of type <classname>Class<?></classname>."
+msgstr ""
+
+#. Tag: para
+#: customconstraints.xml:105
+#, no-c-format
+msgid ""
+"an attribute <classname>payload</classname> that can be used by clients of "
+"the Bean Validation API to assign custom payload objects to a constraint. "
+"This attribute is not used by the API itself."
+msgstr ""
+
+#. Tag: para
+#: customconstraints.xml:109
+#, no-c-format
+msgid "An example for a custom payload could be the definition of a severity."
+msgstr ""
+
+#. Tag: programlisting
+#: customconstraints.xml:112
+#, no-c-format
+msgid ""
+"public class Severity {\n"
+" public static class Info extends Payload {};\n"
+" public static class Error extends Payload {};\n"
+"}\n"
+"\n"
+"public class ContactDetails {\n"
+" @NotNull(message=\"Name is mandatory\", payload=Severity.Error.class)\n"
+" private String name;\n"
+"\n"
+" @NotNull(message=\"Phone number not specified, but not mandatory\", "
+"payload=Severity.Info.class)\n"
+" private String phoneNumber;\n"
+"\n"
+" // ...\n"
+"}"
+msgstr ""
+
+#. Tag: para
+#: customconstraints.xml:114
+#, no-c-format
+msgid ""
+"Now a client can after the validation of a <classname>ContactDetails</"
+"classname> instance access the severity of a constraint using "
+"<methodname>ConstraintViolation.getConstraintDescriptor().getPayload()</"
+"methodname> and adjust its behaviour depending on the severity."
+msgstr ""
+
+#. Tag: para
+#: customconstraints.xml:123
+#, no-c-format
+msgid ""
+"Besides those three mandatory attributes (<property>message</property>, "
+"<property>groups</property> and <property>payload</property>) we add another "
+"one allowing for the required case mode to be specified. The name "
+"<property>value</property> is a special one, which can be omitted upon using "
+"the annotation, if it is the only attribute specified, as e.g. in "
+"<code>@CheckCase(CaseMode.UPPER)</code>."
+msgstr ""
+
+#. Tag: para
+#: customconstraints.xml:131
+#, no-c-format
+msgid ""
+"In addition we annotate the annotation type with a couple of so-called meta "
+"annotations:"
+msgstr ""
+
+#. Tag: para
+#: customconstraints.xml:136
+#, no-c-format
+msgid ""
+"<code>@Target({ METHOD, FIELD, ANNOTATION_TYPE })</code>: Says, that "
+"methods, fields and annotation declarations may be annotated with @CheckCase "
+"(but not type declarations e.g.)"
+msgstr ""
+
+#. Tag: para
+#: customconstraints.xml:142
+#, no-c-format
+msgid ""
+"<code>@Retention(RUNTIME)</code>: Specifies, that annotations of this type "
+"will be available at runtime by the means of reflection"
+msgstr ""
+
+#. Tag: para
+#: customconstraints.xml:148
+#, no-c-format
+msgid ""
+"<code>@Constraint(validatedBy = CheckCaseValidator.class)</code>: Specifies "
+"the validator to be used to validate elements annotated with @CheckCase"
+msgstr ""
+
+#. Tag: para
+#: customconstraints.xml:154
+#, no-c-format
+msgid ""
+"<code>@Documented</code>: Says, that the use of <code>@CheckCase</code> will "
+"be contained in the JavaDoc of elements annotated with it"
+msgstr ""
+
+#. Tag: title
+#: customconstraints.xml:162
+#, no-c-format
+msgid "The constraint validator"
+msgstr ""
+
+#. Tag: para
+#: customconstraints.xml:165
+#, no-c-format
+msgid ""
+"Next, we need to implement a constraint validator, that's able to validate "
+"elements with a <classname>@CheckCase</classname> annotation. To do so, we "
+"implement the interface ConstraintValidator as shown below:"
+msgstr ""
+
+#. Tag: title
+#: customconstraints.xml:171
+#, no-c-format
+msgid ""
+"Implementing a constraint validator for the constraint <classname>CheckCase</"
+"classname>"
+msgstr ""
+
+#. Tag: programlisting
+#: customconstraints.xml:174
+#, no-c-format
+msgid ""
+"package com.mycompany;\n"
+"\n"
+"import javax.validation.ConstraintValidator;\n"
+"import javax.validation.ConstraintValidatorContext;\n"
+"\n"
+"public class CheckCaseValidator implements ConstraintValidator<CheckCase, "
+"String> {\n"
+"\n"
+" private CaseMode caseMode;\n"
+"\n"
+" public void initialize(CheckCase constraintAnnotation) {\n"
+" this.caseMode = constraintAnnotation.value();\n"
+" }\n"
+"\n"
+" public boolean isValid(String object, ConstraintValidatorContext "
+"constraintContext) {\n"
+"\n"
+" if (object == null)\n"
+" return true;\n"
+"\n"
+" if (caseMode == CaseMode.UPPER)\n"
+" return object.equals(object.toUpperCase());\n"
+" else\n"
+" return object.equals(object.toLowerCase());\n"
+" }\n"
+"\n"
+"}"
+msgstr ""
+
+#. Tag: para
+#: customconstraints.xml:177
+#, no-c-format
+msgid ""
+"The <classname>ConstraintValidator</classname> interface defines two type "
+"parameters, which we set in our implementation. The first one specifies the "
+"annotation type to be validated (in our example <classname>CheckCase</"
+"classname>), the second one the type of elements, which the validator can "
+"handle (here <classname>String</classname>)."
+msgstr ""
+
+#. Tag: para
+#: customconstraints.xml:184
+#, no-c-format
+msgid ""
+"In case a constraint annotation is allowed at elements of different types, a "
+"<classname>ConstraintValidator</classname> for each allowed type has to be "
+"implemented and registered at the constraint annotation as shown above."
+msgstr ""
+
+#. Tag: para
+#: customconstraints.xml:189
+#, no-c-format
+msgid ""
+"The implementation of the validator is straightforward. The "
+"<methodname>initialize()</methodname> method gives us access to the "
+"attribute values of the annotation to be validated. In the example we store "
+"the <classname>CaseMode</classname> in a field of the validator for further "
+"usage."
+msgstr ""
+
+#. Tag: para
+#: customconstraints.xml:195
+#, no-c-format
+msgid ""
+"In the <methodname>isValid()</methodname> method we implement the logic, "
+"that determines, whether a <classname>String</classname> is valid according "
+"to a given <classname>@CheckCase</classname> annotation or not. This "
+"decision depends on the case mode retrieved in <classname>initialize()</"
+"classname>. As the Bean Validation specification recommends, we consider "
+"<code>null</code> values as being valid. If <code>null</code> is not a valid "
+"value for an element, it should be annotated with <code>@NotNull</code> "
+"explicitly."
+msgstr ""
+
+#. Tag: title
+#: customconstraints.xml:205
+#, no-c-format
+msgid "The ConstraintValidatorContext"
+msgstr ""
+
+#. Tag: para
+#: customconstraints.xml:207
+#, no-c-format
+msgid ""
+"relies on the default error message generation by just returning "
+"<constant>true</constant> or <constant>false</constant> from the "
+"<methodname>isValid</methodname> call. Using the passed "
+"<classname>ConstraintValidatorContext</classname> object it is possible to "
+"either add additional error messages or completely disable the default error "
+"message generation and solely define custom error messages. The "
+"<classname>ConstraintValidatorContext</classname> API is modeled as fluent "
+"interface and is best demonstrated with an example:"
+msgstr ""
+
+#. Tag: title
+#: customconstraints.xml:219
+#, no-c-format
+msgid "Use of ConstraintValidatorContext to define custom error messages"
+msgstr ""
+
+#. Tag: programlisting
+#: customconstraints.xml:222
+#, no-c-format
+msgid ""
+"package com.mycompany;\n"
+"\n"
+"import javax.validation.ConstraintValidator;\n"
+"import javax.validation.ConstraintValidatorContext;\n"
+"\n"
+"public class CheckCaseValidator implements ConstraintValidator<CheckCase, "
+"String> {\n"
+"\n"
+" private CaseMode caseMode;\n"
+"\n"
+" public void initialize(CheckCase constraintAnnotation) {\n"
+" this.caseMode = constraintAnnotation.value();\n"
+" }\n"
+"\n"
+" public boolean isValid(String object, ConstraintValidatorContext "
+"constraintContext) {\n"
+"\n"
+" if (object == null)\n"
+" return true;\n"
+" \n"
+" boolean isValid;\n"
+" if (caseMode == CaseMode.UPPER) {\n"
+" isValid = object.equals(object.toUpperCase());\n"
+" }\n"
+" else {\n"
+" isValid = object.equals(object.toLowerCase());\n"
+" }\n"
+" \n"
+" if(!isValid) {\n"
+" constraintContext.disableDefaultConstraintViolation();\n"
+" constraintContext.buildConstraintViolationWithTemplate( \"{com."
+"mycompany.constraints.CheckCase.message}\" ).addConstraintViolation();\n"
+" }\n"
+" return result;\n"
+" }\n"
+"\n"
+"}"
+msgstr ""
+
+#. Tag: para
+#: customconstraints.xml:225
+#, no-c-format
+msgid ""
+"shows how you can disable the default error message generation and add a "
+"custom error message using a specified message template. In this example the "
+"use of the <classname>ConstraintValidatorContext</classname> results in the "
+"same error message as the default error message generation."
+msgstr ""
+
+#. Tag: para
+#: customconstraints.xml:231
+#, no-c-format
+msgid ""
+"It is important to end each new constraint violation with "
+"<methodname>addConstraintViolation</methodname>. Only after that the new "
+"constraint violation will be created."
+msgstr ""
+
+#. Tag: para
+#: customconstraints.xml:236
+#, no-c-format
+msgid ""
+"In case you are implementing a <classname>ConstraintValidator</classname> a "
+"class level constraint it is also possible to adjust set the property path "
+"for the created constraint violations. This is important for the case where "
+"you validate multiple properties of the class or even traverse the object "
+"graph. A custom property path creation could look like <xref linkend="
+"\"example-custom-error\"/>."
+msgstr ""
+
+#. Tag: title
+#: customconstraints.xml:245
+#, no-c-format
+msgid ""
+"Adding new <classname>ConstraintViolation</classname> with custom property "
+"path"
+msgstr ""
+
+#. Tag: programlisting
+#: customconstraints.xml:248
+#, no-c-format
+msgid ""
+"public boolean isValid(Group group, ConstraintValidatorContext "
+"constraintValidatorContext) {\n"
+" boolean isValid = false;\n"
+" ...\n"
+"\n"
+" if(!isValid) {\n"
+" constraintValidatorContext\n"
+" .buildConstraintViolationWithTemplate( \"{my.custom.template}"
+"\" )\n"
+" .addNode( \"myProperty\" ).addConstraintViolation();\n"
+" }\n"
+" return isValid;\n"
+"}"
+msgstr ""
+
+#. Tag: title
+#: customconstraints.xml:254
+#, no-c-format
+msgid "The error message"
+msgstr ""
+
+#. Tag: para
+#: customconstraints.xml:256
+#, no-c-format
+msgid ""
+"Finally we need to specify the error message, that shall be used, in case a "
+"<classname>@CheckCase</classname> constraint is violated. To do so, we add "
+"the following to our custom <filename>ValidationMessages.properties</"
+"filename> (see also <xref linkend=\"section-message-interpolation\"/>)"
+msgstr ""
+
+#. Tag: title
+#: customconstraints.xml:263
+#, no-c-format
+msgid ""
+"Defining a custom error message for the <classname>CheckCase</classname> "
+"constraint"
+msgstr ""
+
+#. Tag: programlisting
+#: customconstraints.xml:266
+#, no-c-format
+msgid "com.mycompany.constraints.CheckCase.message=Case mode must be {value}."
+msgstr ""
+
+#. Tag: para
+#: customconstraints.xml:269
+#, no-c-format
+msgid ""
+"If a validation error occurs, the validation runtime will use the default "
+"value, that we specified for the message attribute of the "
+"<classname>@CheckCase</classname> annotation to look up the error message in "
+"this file."
+msgstr ""
+
+#. Tag: title
+#: customconstraints.xml:276
+#, no-c-format
+msgid "Using the constraint"
+msgstr ""
+
+#. Tag: para
+#: customconstraints.xml:278
+#, no-c-format
+msgid ""
+"Now that our first custom constraint is completed, we can use it in the "
+"<classname>Car</classname> class from the <xref linkend=\"validator-"
+"gettingstarted\"/> chapter to specify that the <property>licensePlate</"
+"property> field shall only contain upper-case strings:"
+msgstr ""
+
+#. Tag: title
+#: customconstraints.xml:285
+#, no-c-format
+msgid "Applying the <classname>CheckCase</classname> constraint"
+msgstr ""
+
+#. Tag: programlisting
+#: customconstraints.xml:288
+#, no-c-format
+msgid ""
+"package com.mycompany;\n"
+"\n"
+"import javax.validation.constraints.Min;\n"
+"import javax.validation.constraints.NotNull;\n"
+"import javax.validation.constraints.Size;\n"
+"\n"
+"public class Car {\n"
+"\n"
+" @NotNull\n"
+" private String manufacturer;\n"
+"\n"
+" @NotNull\n"
+" @Size(min = 2, max = 14)\n"
+" @CheckCase(CaseMode.UPPER)\n"
+" private String licensePlate;\n"
+"\n"
+" @Min(2)\n"
+" private int seatCount;\n"
+" \n"
+" public Car(String manufacturer, String licencePlate, int seatCount) {\n"
+"\n"
+" this.manufacturer = manufacturer;\n"
+" this.licensePlate = licencePlate;\n"
+" this.seatCount = seatCount;\n"
+" }\n"
+"\n"
+" //getters and setters ...\n"
+"\n"
+"}"
+msgstr ""
+
+#. Tag: para
+#: customconstraints.xml:291
+#, no-c-format
+msgid ""
+"Finally let's demonstrate in a little test that the <classname>@CheckCase</"
+"classname> constraint is properly validated:"
+msgstr ""
+
+#. Tag: title
+#: customconstraints.xml:296
+#, no-c-format
+msgid "Testcase demonstrating the <classname>CheckCase</classname> validation"
+msgstr ""
+
+#. Tag: programlisting
+#: customconstraints.xml:299
+#, no-c-format
+msgid ""
+"package com.mycompany;\n"
+"\n"
+"import static org.junit.Assert.*;\n"
+"\n"
+"import java.util.Set;\n"
+"\n"
+"import javax.validation.ConstraintViolation;\n"
+"import javax.validation.Validation;\n"
+"import javax.validation.Validator;\n"
+"import javax.validation.ValidatorFactory;\n"
+"\n"
+"import org.junit.BeforeClass;\n"
+"import org.junit.Test;\n"
+"\n"
+"public class CarTest {\n"
+"\n"
+" private static Validator validator;\n"
+"\n"
+" @BeforeClass\n"
+" public static void setUp() {\n"
+" ValidatorFactory factory = Validation.buildDefaultValidatorFactory"
+"();\n"
+" validator = factory.getValidator();\n"
+" }\n"
+"\n"
+" @Test\n"
+" public void testLicensePlateNotUpperCase() {\n"
+"\n"
+" Car car = new Car(\"Morris\", \"dd-ab-123\", 4);\n"
+"\n"
+" Set<ConstraintViolation<Car>> constraintViolations =\n"
+" validator.validate(car);\n"
+" assertEquals(1, constraintViolations.size());\n"
+" assertEquals(\n"
+" \"Case mode must be UPPER.\", \n"
+" constraintViolations.iterator().next().getMessage());\n"
+" }\n"
+"\n"
+" @Test\n"
+" public void carIsValid() {\n"
+"\n"
+" Car car = new Car(\"Morris\", \"DD-AB-123\", 4);\n"
+"\n"
+" Set<ConstraintViolation<Car>> constraintViolations =\n"
+" validator.validate(car);\n"
+"\n"
+" assertEquals(0, constraintViolations.size());\n"
+" }\n"
+"}"
+msgstr ""
+
+#. Tag: title
+#: customconstraints.xml:305
+#, no-c-format
+msgid "Constraint composition"
+msgstr ""
+
+#. Tag: para
+#: customconstraints.xml:307
+#, no-c-format
+msgid ""
+"Looking at the <property>licensePlate</property> field of the "
+"<classname>Car</classname> class in <xref linkend=\"example-car-with-"
+"checkcase\"/>, we see three constraint annotations already. In complexer "
+"scenarios, where even more constraints could be applied to one element, this "
+"might become a bit confusing easily. Furthermore, if we had a "
+"<property>licensePlate</property> field in another class, we would have to "
+"copy all constraint declarations to the other class as well, violating the "
+"DRY principle."
+msgstr ""
+
+#. Tag: para
+#: customconstraints.xml:316
+#, no-c-format
+msgid ""
+"This problem can be tackled using compound constraints. In the following we "
+"create a new constraint annotation <classname>@ValidLicensePlate</"
+"classname>, that comprises the constraints <classname>@NotNull</classname>, "
+"<classname>@Size</classname> and <classname>@CheckCase</classname>:"
+msgstr ""
+
+#. Tag: title
+#: customconstraints.xml:323
+#, no-c-format
+msgid ""
+"Creating a composing constraint <classname>ValidLicensePlate</classname>"
+msgstr ""
+
+#. Tag: programlisting
+#: customconstraints.xml:326
+#, no-c-format
+msgid ""
+"package com.mycompany;\n"
+"\n"
+"import static java.lang.annotation.ElementType.*;\n"
+"import static java.lang.annotation.RetentionPolicy.*;\n"
+"\n"
+"import java.lang.annotation.Documented;\n"
+"import java.lang.annotation.Retention;\n"
+"import java.lang.annotation.Target;\n"
+"\n"
+"import javax.validation.Constraint;\n"
+"import javax.validation.Payload;\n"
+"import javax.validation.constraints.NotNull;\n"
+"import javax.validation.constraints.Size;\n"
+"\n"
+"@NotNull\n"
+"@Size(min = 2, max = 14)\n"
+"@CheckCase(CaseMode.UPPER)\n"
+"@Target( { METHOD, FIELD, ANNOTATION_TYPE })\n"
+"@Retention(RUNTIME)\n"
+"@Constraint(validatedBy = {})\n"
+"@Documented\n"
+"public @interface ValidLicensePlate {\n"
+"\n"
+" String message() default \"{com.mycompany.constraints.validlicenseplate}"
+"\";\n"
+"\n"
+" Class<?>[] groups() default {};\n"
+"\n"
+" Class<? extends Payload>[] payload() default {};\n"
+"\n"
+"}"
+msgstr ""
+
+#. Tag: para
+#: customconstraints.xml:329
+#, no-c-format
+msgid ""
+"To do so, we just have to annotate the constraint declaration with its "
+"comprising constraints (btw. that's exactly why we allowed annotation types "
+"as target for the <classname>@CheckCase</classname> annotation). As no "
+"additional validation is required for the <classname>@ValidLicensePlate</"
+"classname> annotation itself, we don't declare a validator within the "
+"<classname>@Constraint </classname>meta annotation."
+msgstr ""
+
+#. Tag: para
+#: customconstraints.xml:337
+#, no-c-format
+msgid ""
+"Using the new compound constraint at the <property>licensePlate</property> "
+"field now is fully equivalent to the previous version, where we declared the "
+"three constraints directly at the field itself:"
+msgstr ""
+
+#. Tag: title
+#: customconstraints.xml:343
+#, no-c-format
+msgid ""
+"Application of composing constraint <classname>ValidLicensePlate</classname>"
+msgstr ""
+
+#. Tag: programlisting
+#: customconstraints.xml:346
+#, no-c-format
+msgid ""
+"package com.mycompany;\n"
+"\n"
+"public class Car {\n"
+"\n"
+" @ValidLicensePlate\n"
+" private String licensePlate;\n"
+"\n"
+" //...\n"
+"\n"
+"}"
+msgstr ""
+
+#. Tag: para
+#: customconstraints.xml:349
+#, no-c-format
+msgid ""
+"The set of <classname>ConstraintViolations</classname> retrieved when "
+"validating a <classname>Car</classname> instance will contain an entry for "
+"each violated composing constraint of the <classname>@ValidLicensePlate</"
+"classname> constraint. If you rather prefer a single "
+"<classname>ConstraintViolation</classname> in case any of the composing "
+"constraints is violated, the <classname>@ReportAsSingleViolation</classname> "
+"meta constraint can be used as follows:"
+msgstr ""
+
+#. Tag: title
+#: customconstraints.xml:359
+#, no-c-format
+msgid "Usage of <classname>@ReportAsSingleViolation</classname>"
+msgstr ""
+
+#. Tag: programlisting
+#: customconstraints.xml:361
+#, no-c-format
+msgid ""
+"//...\n"
+"@ReportAsSingleViolation\n"
+"public @interface ValidLicensePlate {\n"
+"\n"
+" String message() default \"{com.mycompany.constraints.validlicenseplate}"
+"\";\n"
+"\n"
+" Class<?>[] groups() default {};\n"
+"\n"
+" Class<? extends Payload>[] payload() default {};\n"
+"\n"
+"}"
+msgstr ""
Added: validator/trunk/hibernate-validator/src/main/docbook/zh-CN/modules/furtherreading.po
===================================================================
--- validator/trunk/hibernate-validator/src/main/docbook/zh-CN/modules/furtherreading.po (rev 0)
+++ validator/trunk/hibernate-validator/src/main/docbook/zh-CN/modules/furtherreading.po 2010-07-06 15:18:26 UTC (rev 19904)
@@ -0,0 +1,56 @@
+# Language zh-CN translations for PACKAGE package.
+# Automatically generated, 2010.
+#
+msgid ""
+msgstr ""
+"Project-Id-Version: PACKAGE VERSION\n"
+"Report-Msgid-Bugs-To: http://bugs.kde.org\n"
+"POT-Creation-Date: 2010-07-06 14:46+0000\n"
+"PO-Revision-Date: 2010-07-06 14:46+0000\n"
+"Last-Translator: Automatically generated\n"
+"Language-Team: none\n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+
+#. Tag: title
+#: furtherreading.xml:25
+#, no-c-format
+msgid "Further reading"
+msgstr ""
+
+#. Tag: para
+#: furtherreading.xml:27
+#, no-c-format
+msgid ""
+"Last but not least, a few pointers to further information. A great source "
+"for examples is the Bean Validation TCK which can is available for anonymous "
+"access in the Hibernate <ulink url=\"http://anonsvn.jboss.org/repos/"
+"hibernate/validator/trunk\">SVN repository</ulink>. Alternatively you can "
+"view the tests using <ulink url=\"http://fisheye.jboss.org/browse/Hibernate/"
+"beanvalidation/trunk/validation-tck/src/main/java/org/hibernate/jsr303/tck/"
+"tests\">Hibernate's fisheye</ulink> installation. <ulink url=\"http://jcp."
+"org/en/jsr/detail?id=303\">The JSR 303</ulink> specification itself is also "
+"a great way to deepen your understanding of Bean Validation resp. Hibernate "
+"Validator."
+msgstr ""
+
+#. Tag: para
+#: furtherreading.xml:38
+#, no-c-format
+msgid ""
+"If you have any further questions to Hibernate Validator or want to share "
+"some of your use cases have a look at the <ulink url=\"http://community."
+"jboss.org/en/hibernate/validator\">Hibernate Validator Wiki</ulink> and the "
+"<ulink url=\"https://forum.hibernate.org/viewforum.php?f=9\">Hibernate "
+"Validator Forum</ulink>."
+msgstr ""
+
+#. Tag: para
+#: furtherreading.xml:45
+#, no-c-format
+msgid ""
+"In case you would like to report a bug use <ulink url=\"http://opensource."
+"atlassian.com/projects/hibernate/browse/HV\">Hibernate's Jira</ulink> "
+"instance. Feedback is always welcome!"
+msgstr ""
Added: validator/trunk/hibernate-validator/src/main/docbook/zh-CN/modules/gettingstarted.po
===================================================================
--- validator/trunk/hibernate-validator/src/main/docbook/zh-CN/modules/gettingstarted.po (rev 0)
+++ validator/trunk/hibernate-validator/src/main/docbook/zh-CN/modules/gettingstarted.po 2010-07-06 15:18:26 UTC (rev 19904)
@@ -0,0 +1,415 @@
+# Language zh-CN translations for PACKAGE package.
+# Automatically generated, 2010.
+#
+msgid ""
+msgstr ""
+"Project-Id-Version: PACKAGE VERSION\n"
+"Report-Msgid-Bugs-To: http://bugs.kde.org\n"
+"POT-Creation-Date: 2010-07-06 14:46+0000\n"
+"PO-Revision-Date: 2010-07-06 14:46+0000\n"
+"Last-Translator: Automatically generated\n"
+"Language-Team: none\n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+
+#. Tag: title
+#: gettingstarted.xml:25
+#, no-c-format
+msgid "Getting started"
+msgstr ""
+
+#. Tag: para
+#: gettingstarted.xml:27
+#, no-c-format
+msgid ""
+"This chapter will show you how to get started with Hibernate Validator, the "
+"reference implementation (RI) of Bean Validation. For the following "
+"quickstart you need:"
+msgstr ""
+
+#. Tag: para
+#: gettingstarted.xml:33
+#, no-c-format
+msgid "A JDK >= 5"
+msgstr ""
+
+#. Tag: ulink
+#: gettingstarted.xml:37
+#, no-c-format
+msgid "Apache Maven"
+msgstr ""
+
+#. Tag: para
+#: gettingstarted.xml:41
+#, no-c-format
+msgid "An Internet connection (Maven has to download all required libraries)"
+msgstr ""
+
+#. Tag: para
+#: gettingstarted.xml:46
+#, no-c-format
+msgid ""
+"A properly configured remote repository. Add the following to your "
+"<filename>settings.xml</filename>: <example> <title>Configuring the JBoss "
+"Maven repository in <filename>settings.xml</filename></title> "
+"<programlisting><repositories>\n"
+" <repository>\n"
+" <id>jboss</id>\n"
+" <url>http://repository.jboss.com/maven2</url>\n"
+" <releases>\n"
+" <enabled>true</enabled>\n"
+" </releases>\n"
+" <snapshots>\n"
+" <enabled>false</enabled>\n"
+" </snapshots>\n"
+" </repository>\n"
+"</repositories></programlisting> </example>More information about "
+"<filename>settings.xml</filename> can be found in the <ulink url=\"http://"
+"maven.apache.org/ref/2.0.8/maven-settings/settings.html\">Maven Local "
+"Settings Model</ulink>."
+msgstr ""
+
+#. Tag: para
+#: gettingstarted.xml:60
+#, no-c-format
+msgid ""
+"Hibernate Validator uses JAXB for XML parsing. JAXB is part of the Java "
+"Class Library since Java 6 which means that if you run Hibernate Validator "
+"with Java 5 you will have to add additional JAXB dependencies. Using maven "
+"you have to add the following dependencies:<programlisting><"
+"dependency>\n"
+" <groupId>javax.xml.bind</groupId>\n"
+" <artifactId>jaxb-api</artifactId>\n"
+" <version>2.2</version>\n"
+"</dependency>\n"
+"<dependency>\n"
+" <groupId>com.sun.xml.bind</groupId>\n"
+" <artifactId>jaxb-impl</artifactId>\n"
+" <version>2.1.12</version>\n"
+"</dependency>\n"
+"</programlisting> if you are using the SourceForge package you find the "
+"necessary libraries in the <filename>lib/jdk5</filename> directory. In case "
+"you are not using the XML configuration you can also disable it explicitly "
+"by calling <methodname>Configuration.ignoreXmlConfiguration()</methodname> "
+"during <classname>ValidationFactory</classname> creation. In this case the "
+"JAXB dependencies are not needed."
+msgstr ""
+
+#. Tag: title
+#: gettingstarted.xml:73
+#, no-c-format
+msgid "Setting up a new Maven project"
+msgstr ""
+
+#. Tag: para
+#: gettingstarted.xml:75
+#, no-c-format
+msgid ""
+"Start by creating new Maven project using the Maven archetype plugin as "
+"follows:"
+msgstr ""
+
+#. Tag: title
+#: gettingstarted.xml:79
+#, no-c-format
+msgid ""
+"Using Maven's archetype plugin to create a sample project using Hibernate "
+"Validator"
+msgstr ""
+
+#. Tag: programlisting
+#: gettingstarted.xml:82
+#, no-c-format
+msgid ""
+"mvn archetype:create -DarchetypeGroupId=org.hibernate \\\n"
+" -DarchetypeArtifactId=hibernate-validator-quickstart-"
+"archetype \\\n"
+" -DarchetypeVersion=&version; \\\n"
+" -DgroupId=com.mycompany \n"
+" -DartifactId=hv-quickstart"
+msgstr ""
+
+#. Tag: para
+#: gettingstarted.xml:85
+#, no-c-format
+msgid ""
+"Maven will create your project in the directory hv-quickstart. Change into "
+"this directory and run:"
+msgstr ""
+
+#. Tag: programlisting
+#: gettingstarted.xml:88
+#, no-c-format
+msgid "mvn test"
+msgstr ""
+
+#. Tag: para
+#: gettingstarted.xml:88
+#, no-c-format
+msgid ""
+"Maven will compile the example code and run the implemented unit tests. "
+"Let's have a look at the actual code."
+msgstr ""
+
+#. Tag: title
+#: gettingstarted.xml:94
+#, no-c-format
+msgid "Applying constraints"
+msgstr ""
+
+#. Tag: para
+#: gettingstarted.xml:96
+#, no-c-format
+msgid ""
+"Open the project in the IDE of your choice and have a look at the class "
+"<classname>Car</classname>:"
+msgstr ""
+
+#. Tag: title
+#: gettingstarted.xml:100
+#, no-c-format
+msgid "Class Car annotated with constraints"
+msgstr ""
+
+#. Tag: programlisting
+#: gettingstarted.xml:102
+#, no-c-format
+msgid ""
+"package com.mycompany;\n"
+"\n"
+"import javax.validation.constraints.Min;\n"
+"import javax.validation.constraints.NotNull;\n"
+"import javax.validation.constraints.Size;\n"
+"\n"
+"public class Car {\n"
+"\n"
+" @NotNull\n"
+" private String manufacturer;\n"
+"\n"
+" @NotNull\n"
+" @Size(min = 2, max = 14)\n"
+" private String licensePlate;\n"
+"\n"
+" @Min(2)\n"
+" private int seatCount;\n"
+" \n"
+" public Car(String manufacturer, String licencePlate, int seatCount) {\n"
+" this.manufacturer = manufacturer;\n"
+" this.licensePlate = licencePlate;\n"
+" this.seatCount = seatCount;\n"
+" }\n"
+"\n"
+" //getters and setters ...\n"
+"}"
+msgstr ""
+
+#. Tag: para
+#: gettingstarted.xml:105
+#, no-c-format
+msgid ""
+"<classname>@NotNull</classname>, <classname>@Size</classname> and "
+"<classname>@Min</classname> are so-called constraint annotations, that we "
+"use to declare constraints, which shall be applied to the fields of a "
+"<classname>Car</classname> instance:"
+msgstr ""
+
+#. Tag: para
+#: gettingstarted.xml:112
+#, no-c-format
+msgid "<property>manufacturer</property> shall never be null"
+msgstr ""
+
+#. Tag: para
+#: gettingstarted.xml:116
+#, no-c-format
+msgid ""
+"<property>licensePlate</property> shall never be null and must be between 2 "
+"and 14 characters long"
+msgstr ""
+
+#. Tag: para
+#: gettingstarted.xml:121
+#, no-c-format
+msgid "<property>seatCount</property> shall be at least 2."
+msgstr ""
+
+#. Tag: title
+#: gettingstarted.xml:127
+#, no-c-format
+msgid "Validating constraints"
+msgstr ""
+
+#. Tag: para
+#: gettingstarted.xml:129
+#, no-c-format
+msgid ""
+"To perform a validation of these constraints, we use a <classname>Validator</"
+"classname> instance. Let's have a look at the <classname>CarTest</classname> "
+"class:"
+msgstr ""
+
+#. Tag: title
+#: gettingstarted.xml:134
+#, no-c-format
+msgid "Class CarTest showing validation examples"
+msgstr ""
+
+#. Tag: programlisting
+#: gettingstarted.xml:136
+#, no-c-format
+msgid ""
+"package com.mycompany;\n"
+"\n"
+"import static org.junit.Assert.*;\n"
+"\n"
+"import java.util.Set;\n"
+"\n"
+"import javax.validation.ConstraintViolation;\n"
+"import javax.validation.Validation;\n"
+"import javax.validation.Validator;\n"
+"import javax.validation.ValidatorFactory;\n"
+"\n"
+"import org.junit.BeforeClass;\n"
+"import org.junit.Test;\n"
+"\n"
+"public class CarTest {\n"
+"\n"
+" private static Validator validator;\n"
+"\n"
+" @BeforeClass\n"
+" public static void setUp() {\n"
+" ValidatorFactory factory = Validation.buildDefaultValidatorFactory"
+"();\n"
+" validator = factory.getValidator();\n"
+" }\n"
+"\n"
+" @Test\n"
+" public void manufacturerIsNull() {\n"
+" Car car = new Car(null, \"DD-AB-123\", 4);\n"
+"\n"
+" Set<ConstraintViolation<Car>> constraintViolations =\n"
+" validator.validate(car);\n"
+"\n"
+" assertEquals(1, constraintViolations.size());\n"
+" assertEquals(\"may not be null\", constraintViolations.iterator()."
+"next().getMessage());\n"
+" }\n"
+"\n"
+" @Test\n"
+" public void licensePlateTooShort() {\n"
+" Car car = new Car(\"Morris\", \"D\", 4);\n"
+"\n"
+" Set<ConstraintViolation<Car>> constraintViolations = \n"
+" validator.validate(car);\n"
+"\n"
+" assertEquals(1, constraintViolations.size());\n"
+" assertEquals(\"size must be between 2 and 14\", constraintViolations."
+"iterator().next().getMessage());\n"
+" }\n"
+" \n"
+" @Test\n"
+" public void seatCountTooLow() {\n"
+" Car car = new Car(\"Morris\", \"DD-AB-123\", 1);\n"
+"\n"
+" Set<ConstraintViolation<Car>> constraintViolations =\n"
+" validator.validate(car);\n"
+"\n"
+" assertEquals(1, constraintViolations.size());\n"
+" assertEquals(\"must be greater than or equal to 2\", "
+"constraintViolations.iterator().next().getMessage());\n"
+" }\n"
+"\n"
+" @Test\n"
+" public void carIsValid() {\n"
+" Car car = new Car(\"Morris\", \"DD-AB-123\", 2);\n"
+"\n"
+" Set<ConstraintViolation<Car>> constraintViolations =\n"
+" validator.validate(car);\n"
+"\n"
+" assertEquals(0, constraintViolations.size());\n"
+" }\n"
+"}"
+msgstr ""
+
+#. Tag: para
+#: gettingstarted.xml:139
+#, no-c-format
+msgid ""
+"In the <methodname>setUp()</methodname> method we get a "
+"<classname>Validator</classname> instance from the "
+"<classname>ValidatorFactory</classname>. A <classname>Validator</classname> "
+"instance is thread-safe and may be reused multiple times. For this reason we "
+"store it as field of our test class. We can use the <classname>Validator</"
+"classname> now to validate the different car instances in the test methods."
+msgstr ""
+
+#. Tag: para
+#: gettingstarted.xml:147
+#, no-c-format
+msgid ""
+"The <methodname>validate()</methodname> method returns a set of "
+"<classname>ConstraintViolation</classname> instances, which we can iterate "
+"in order to see which validation errors occurred. The first three test "
+"methods show some expected constraint violations:"
+msgstr ""
+
+#. Tag: para
+#: gettingstarted.xml:154
+#, no-c-format
+msgid ""
+"The <classname>@NotNull</classname> constraint on manufacturer is violated "
+"in <methodname>manufacturerIsNull()</methodname>"
+msgstr ""
+
+#. Tag: para
+#: gettingstarted.xml:159
+#, no-c-format
+msgid ""
+"The <classname>@Size</classname> constraint on licensePlate is violated in "
+"<methodname>licensePlateTooShort()</methodname>"
+msgstr ""
+
+#. Tag: para
+#: gettingstarted.xml:164
+#, no-c-format
+msgid ""
+"The <classname>@Min</classname> constraint on seatCount is violated in "
+"<methodname>seatCountTooLow()</methodname>"
+msgstr ""
+
+#. Tag: para
+#: gettingstarted.xml:169
+#, no-c-format
+msgid ""
+"If the object validates successfully, <methodname>validate()</methodname> "
+"returns an empty set."
+msgstr ""
+
+#. Tag: para
+#: gettingstarted.xml:172
+#, no-c-format
+msgid ""
+"Note that we only use classes from the package <package>javax.validation</"
+"package> from the Bean Validation API. As we don't reference any classes of "
+"the RI directly, it would be no problem to switch to another implementation "
+"of the API, should that need arise."
+msgstr ""
+
+#. Tag: title
+#: gettingstarted.xml:180
+#, no-c-format
+msgid "Where to go next?"
+msgstr ""
+
+#. Tag: para
+#: gettingstarted.xml:182
+#, no-c-format
+msgid ""
+"That concludes our 5 minute tour through the world of Hibernate Validator. "
+"Continue exploring the code examples or look at further examples referenced "
+"in <xref linkend=\"chapter-further-reading\"/>. To deepen your understanding "
+"of Hibernate Validator just continue reading <xref linkend=\"validator-"
+"usingvalidator\"/>. In case your application has specific validation "
+"requirements have a look at <xref linkend=\"validator-customconstraints\"/>."
+msgstr ""
Added: validator/trunk/hibernate-validator/src/main/docbook/zh-CN/modules/integration.po
===================================================================
--- validator/trunk/hibernate-validator/src/main/docbook/zh-CN/modules/integration.po (rev 0)
+++ validator/trunk/hibernate-validator/src/main/docbook/zh-CN/modules/integration.po 2010-07-06 15:18:26 UTC (rev 19904)
@@ -0,0 +1,274 @@
+# Language zh-CN translations for PACKAGE package.
+# Automatically generated, 2010.
+#
+msgid ""
+msgstr ""
+"Project-Id-Version: PACKAGE VERSION\n"
+"Report-Msgid-Bugs-To: http://bugs.kde.org\n"
+"POT-Creation-Date: 2010-07-06 14:46+0000\n"
+"PO-Revision-Date: 2010-07-06 14:46+0000\n"
+"Last-Translator: Automatically generated\n"
+"Language-Team: none\n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+
+#. Tag: title
+#: integration.xml:25
+#, no-c-format
+msgid "Integration with other frameworks"
+msgstr ""
+
+#. Tag: para
+#: integration.xml:27
+#, no-c-format
+msgid ""
+"Hibernate Validator is intended to be used to implement multi-layered data "
+"validation, where constraints are expressed in a single place (the annotated "
+"domain model) and checked in various different layers of the application."
+msgstr ""
+
+#. Tag: title
+#: integration.xml:33
+#, no-c-format
+msgid "OSGi"
+msgstr ""
+
+#. Tag: para
+#: integration.xml:35
+#, no-c-format
+msgid ""
+"The Hibernate Validator jar file is conform to the OSGi specification and "
+"can be used within any OSGi container. The classes in the following packages "
+"are exported by Hibernate Validator and are considered part of the public "
+"API - <package>org.hibernate.validator</package>, <package>org.hibernate."
+"validator.constraints</package>, <package>org.hibernate.validator."
+"messageinterpolation</package> and <package>org.hibernate.validator."
+"resourceloading</package>."
+msgstr ""
+
+#. Tag: title
+#: integration.xml:46
+#, no-c-format
+msgid "Database schema-level validation"
+msgstr ""
+
+#. Tag: para
+#: integration.xml:48
+#, no-c-format
+msgid ""
+"Out of the box, Hibernate Annotations (as of Hibernate 3.5.x) will translate "
+"the constraints you have defined for your entities into mapping metadata. "
+"For example, if a property of your entity is annotated <literal>@NotNull</"
+"literal>, its columns will be declared as <literal>not null</literal> in the "
+"DDL schema generated by Hibernate."
+msgstr ""
+
+#. Tag: para
+#: integration.xml:54
+#, no-c-format
+msgid ""
+"If, for some reason, the feature needs to be disabled, set "
+"<literal>hibernate.validator.apply_to_ddl</literal> to <literal>false</"
+"literal>. See also <xref linkend=\"table-builtin-constraints\"/>."
+msgstr ""
+
+#. Tag: para
+#: integration.xml:59
+#, no-c-format
+msgid ""
+"You can also limit the DDL constraint generation to a subset of the defined "
+"constraints by setting the property <property>org.hibernate.validator.group."
+"ddl</property>. The property specifies the comma-separated, fully specified "
+"class names of the groups a constraint has to be part of in order to be "
+"considered for DDL schema generation."
+msgstr ""
+
+#. Tag: title
+#: integration.xml:68
+#, no-c-format
+msgid "ORM integration"
+msgstr ""
+
+#. Tag: para
+#: integration.xml:70
+#, no-c-format
+msgid ""
+"Hibernate Validator integrates with both Hibernate and all pure Java "
+"Persistence providers."
+msgstr ""
+
+#. Tag: title
+#: integration.xml:74
+#, no-c-format
+msgid "Hibernate event-based validation"
+msgstr ""
+
+#. Tag: para
+#: integration.xml:76
+#, no-c-format
+msgid ""
+"Hibernate Validator has a built-in Hibernate event listener - <ulink url="
+"\"http://fisheye.jboss.org/browse/Hibernate/core/trunk/annotations/src/main/"
+"java/org/hibernate/cfg/beanvalidation/BeanValidationEventListener.java"
+"\"><classname>org.hibernate.cfg.beanvalidation.BeanValidationEventListener</"
+"classname></ulink> - which is part of Hibernate Annotations (as of Hibernate "
+"3.5.x). Whenever a <literal>PreInsertEvent</literal>, "
+"<literal>PreUpdateEvent</literal> or <classname>PreDeleteEvent</classname> "
+"occurs, the listener will verify all constraints of the entity instance and "
+"throw an exception if any constraint is violated. Per default objects will "
+"be checked before any inserts or updates are made by Hibernate. Pre deletion "
+"events will per default not trigger a validation. You can configure the "
+"groups to be validated per event type using the properties <property>javax."
+"persistence.validation.group.pre-persist</property>, <property>javax."
+"persistence.validation.group.pre-update</property> and <property>javax."
+"persistence.validation.group.pre-remove</property>. The values of these "
+"properties are the comma-separated, fully specified class names of the "
+"groups to validate. <xref linkend=\"example-beanvalidationeventlistener-"
+"config\"/> shows the default values for these properties. In this case they "
+"could also be omitted."
+msgstr ""
+
+#. Tag: para
+#: integration.xml:97
+#, no-c-format
+msgid ""
+"On constraint violation, the event will raise a runtime "
+"<classname>ConstraintViolationException</classname> which contains a set of "
+"<literal>ConstraintViolation</literal>s describing each failure."
+msgstr ""
+
+#. Tag: para
+#: integration.xml:102
+#, no-c-format
+msgid ""
+"If Hibernate Validator is present in the classpath, Hibernate Annotations "
+"(or Hibernate EntityManager) will use it transparently. To avoid validation "
+"even though Hibernate Validator is in the classpath set <property>javax."
+"persistence.validation.mode</property> to <constant>none</constant>."
+msgstr ""
+
+#. Tag: para
+#: integration.xml:109
+#, no-c-format
+msgid ""
+"If the beans are not annotated with validation annotations, there is no "
+"runtime performance cost."
+msgstr ""
+
+#. Tag: para
+#: integration.xml:113
+#, no-c-format
+msgid ""
+"In case you need to manually set the event listeners for Hibernate Core, use "
+"the following configuration in <literal>hibernate.cfg.xml</literal>:"
+msgstr ""
+
+#. Tag: title
+#: integration.xml:118
+#, no-c-format
+msgid ""
+"Manual configuration of <classname>BeanValidationEvenListener</classname>"
+msgstr ""
+
+#. Tag: programlisting
+#: integration.xml:121
+#, no-c-format
+msgid ""
+"<hibernate-configuration>\n"
+" <session-factory>\n"
+" ...\n"
+" <property name=\"javax.persistence.validation.group.pre-persist"
+"\">javax.validation.groups.Default</property>\n"
+" <property name=\"javax.persistence.validation.group.pre-update"
+"\">javax.validation.groups.Default</property>\n"
+" <property name=\"javax.persistence.validation.group.pre-remove"
+"\"></property>\n"
+" ...\n"
+" <event type=\"pre-update\">\n"
+" <listener class=\"org.hibernate.cfg.beanvalidation."
+"BeanValidationEventListener\"/>\n"
+" </event>\n"
+" <event type=\"pre-insert\">\n"
+" <listener class=\"org.hibernate.cfg.beanvalidation."
+"BeanValidationEventListener\"/>\n"
+" </event>\n"
+" <event type=\"pre-delete\">\n"
+" <listener class=\"org.hibernate.cfg.beanvalidation."
+"BeanValidationEventListener\"/>\n"
+" </event>\n"
+" </session-factory>\n"
+"</hibernate-configuration>"
+msgstr ""
+
+#. Tag: title
+#: integration.xml:126
+#, no-c-format
+msgid "<title>JPA</title>"
+msgstr ""
+
+#. Tag: para
+#: integration.xml:128
+#, no-c-format
+msgid ""
+"If you are using JPA 2 and Hibernate Validator is in the classpath the JPA2 "
+"specification requires that Bean Validation gets enabled. The properties "
+"<property>javax.persistence.validation.group.pre-persist</property>, "
+"<property>javax.persistence.validation.group.pre-update</property> and "
+"<property>javax.persistence.validation.group.pre-remove</property> as "
+"described in <xref linkend=\"validator-checkconstraints-orm-hibernateevent\"/"
+"> can in this case be configured in <filename>persistence.xml</filename>. "
+"<filename>persistence.xml</filename> also defines a node validation-mode "
+"while can be set to <constant>AUTO</constant>, <constant>CALLBACK</"
+"constant>, <constant>NONE</constant>. The default is <constant>AUTO</"
+"constant>."
+msgstr ""
+
+#. Tag: para
+#: integration.xml:142
+#, no-c-format
+msgid ""
+"In a JPA 1 you will have to create and register Hibernate Validator "
+"yourself. In case you are using Hibernate EntityManager you can add a "
+"customized version of the <classname>BeanValidationEventListener</classname> "
+"described in <xref linkend=\"validator-checkconstraints-orm-hibernateevent\"/"
+"> to your project and register it manually."
+msgstr ""
+
+#. Tag: title
+#: integration.xml:152
+#, no-c-format
+msgid "Presentation layer validation"
+msgstr ""
+
+#. Tag: para
+#: integration.xml:154
+#, no-c-format
+msgid ""
+"When working with JSF2 or <productname>JBoss Seam</productname> and "
+"Hibernate Validator (Bean Validation) is present in the runtime environment "
+"validation is triggered for every field in the application. <xref linkend="
+"\"example-jsf2\"/> shows an example of the f:validateBean tag in a JSF page. "
+"For more information refer to the Seam documentation or the JSF 2 "
+"specification."
+msgstr ""
+
+#. Tag: title
+#: integration.xml:162
+#, no-c-format
+msgid "Usage of Bean Validation within JSF2"
+msgstr ""
+
+#. Tag: programlisting
+#: integration.xml:164
+#, no-c-format
+msgid ""
+"<h:form>\n"
+" <emphasis role=\"bold\"><f:validateBean></emphasis>\n"
+" <h:inputText value=”#{model.property}” />\n"
+" <h:selectOneRadio value=”#{model.radioProperty}” > ... </h:"
+"selectOneRadio>\n"
+" <!-- other input components here -->\n"
+" <emphasis role=\"bold\"></f:validateBean></emphasis>\n"
+"</h:form>"
+msgstr ""
Added: validator/trunk/hibernate-validator/src/main/docbook/zh-CN/modules/preface.po
===================================================================
--- validator/trunk/hibernate-validator/src/main/docbook/zh-CN/modules/preface.po (rev 0)
+++ validator/trunk/hibernate-validator/src/main/docbook/zh-CN/modules/preface.po 2010-07-06 15:18:26 UTC (rev 19904)
@@ -0,0 +1,52 @@
+# Language zh-CN translations for PACKAGE package.
+# Automatically generated, 2010.
+#
+msgid ""
+msgstr ""
+"Project-Id-Version: PACKAGE VERSION\n"
+"Report-Msgid-Bugs-To: http://bugs.kde.org\n"
+"POT-Creation-Date: 2010-07-06 14:46+0000\n"
+"PO-Revision-Date: 2010-07-06 14:46+0000\n"
+"Last-Translator: Automatically generated\n"
+"Language-Team: none\n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+
+#. Tag: title
+#: preface.xml:25
+#, no-c-format
+msgid "Preface"
+msgstr ""
+
+#. Tag: para
+#: preface.xml:27
+#, no-c-format
+msgid ""
+"Validating data is a common task that occurs throughout any application, "
+"from the presentation layer to the persistence layer. Often the same "
+"validation logic is implemented in each layer, proving time consuming and "
+"error-prone. To avoid duplication of these validations in each layer, "
+"developers often bundle validation logic directly into the domain model, "
+"cluttering domain classes with validation code which is really metadata "
+"about the class itself."
+msgstr ""
+
+#. Tag: para
+#: preface.xml:46
+#, no-c-format
+msgid ""
+"JSR 303 - Bean Validation - defines a metadata model and API for entity "
+"validation. The default metadata source is annotations, with the ability to "
+"override and extend the meta-data through the use of XML. The API is not "
+"tied to a specific application tier or programming model. It is specifically "
+"not tied to either the web tier or the persistence tier, and is available "
+"for both server-side application programming, as well as rich client Swing "
+"application developers."
+msgstr ""
+
+#. Tag: para
+#: preface.xml:65
+#, no-c-format
+msgid "Hibernate Validator is the reference implementation of this JSR."
+msgstr ""
Added: validator/trunk/hibernate-validator/src/main/docbook/zh-CN/modules/programmaticapi.po
===================================================================
--- validator/trunk/hibernate-validator/src/main/docbook/zh-CN/modules/programmaticapi.po (rev 0)
+++ validator/trunk/hibernate-validator/src/main/docbook/zh-CN/modules/programmaticapi.po 2010-07-06 15:18:26 UTC (rev 19904)
@@ -0,0 +1,163 @@
+# Language zh-CN translations for PACKAGE package.
+# Automatically generated, 2010.
+#
+msgid ""
+msgstr ""
+"Project-Id-Version: PACKAGE VERSION\n"
+"Report-Msgid-Bugs-To: http://bugs.kde.org\n"
+"POT-Creation-Date: 2010-07-06 14:46+0000\n"
+"PO-Revision-Date: 2010-07-06 14:46+0000\n"
+"Last-Translator: Automatically generated\n"
+"Language-Team: none\n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+
+#. Tag: title
+#: programmaticapi.xml:25 programmaticapi.xml:48
+#, no-c-format
+msgid "Programmatic constraint definition"
+msgstr ""
+
+#. Tag: para
+#: programmaticapi.xml:28
+#, no-c-format
+msgid ""
+"Use of the features described in the following sections is not portable "
+"between Bean Validation providers/implementations."
+msgstr ""
+
+#. Tag: para
+#: programmaticapi.xml:32
+#, no-c-format
+msgid ""
+"Hibernate Validator allows to configure constraints not only via annotations "
+"and xml, but also via a programmatic API. This API can be used exclusively "
+"or in combination with annotations and xml. If used in combination "
+"programmatic constraints are additive to otherwise configured constraints."
+msgstr ""
+
+#. Tag: para
+#: programmaticapi.xml:38
+#, no-c-format
+msgid ""
+"The programmatic API is centered around the <classname>ConstraintMapping</"
+"classname> class which can be found together with its supporting classes in "
+"the <package>org.hibernate.validator.cfg</package> package. "
+"<classname>ConstraintMapping</classname> is the entry point to a fluent API "
+"allowing the definition of constraints. <xref lang=\"\" linkend=\"example-"
+"constraint-mapping\"/> shows how the API can be used."
+msgstr ""
+
+#. Tag: programlisting
+#: programmaticapi.xml:50
+#, no-c-format
+msgid ""
+"ConstraintMapping mapping = new ConstraintMapping();\n"
+"mapping.type( Car.class )\n"
+" .property( \"manufacturer\", FIELD )\n"
+" .constraint( NotNullDef.class )\n"
+" .property( \"licensePlate\", FIELD )\n"
+" .constraint( NotNullDef.class )\n"
+" .constraint( SizeDef.class )\n"
+" .min( 2 )\n"
+" .max( 14 )\n"
+" .property( \"seatCount\", FIELD )\n"
+" .constraint( MinDef.class )\n"
+" .value ( 2 )\n"
+".type( RentalCar.class )\n"
+" .property( \"rentalStation\", METHOD)\n"
+" .constraint( NotNullDef.class );"
+msgstr ""
+
+#. Tag: para
+#: programmaticapi.xml:53
+#, no-c-format
+msgid ""
+"As you can see you can configure constraints on multiple classes and "
+"properties using method chaining. The constraint definition classes "
+"<classname>NotNullDef</classname>, <classname>SizeDef</classname> and "
+"<classname>MinDef</classname> are helper classes which allow to configure "
+"constraint parameters in a type-safe fashion. Definition classes exists for "
+"all built-in constraints in the <classname>org.hibernate.validator.cfg.defs</"
+"classname> package. For a custom constraint you can either create your own "
+"definition class extending <classname>ConstraintDef</classname> or you can "
+"use <classname>GenericConstraintDef</classname> as seen in <xref linkend="
+"\"example-generic-constraint-mapping\"/>."
+msgstr ""
+
+#. Tag: title
+#: programmaticapi.xml:66
+#, no-c-format
+msgid ""
+"Programmatic constraint definition using <classname>GenericConstraintDef</"
+"classname>"
+msgstr ""
+
+#. Tag: programlisting
+#: programmaticapi.xml:69
+#, no-c-format
+msgid ""
+"ConstraintMapping mapping = new ConstraintMapping();\n"
+"mapping.type( Car.class )\n"
+" .property( \"licensePlate\", FIELD )\n"
+" .constraint( GenericConstraintDef.class )\n"
+" .constraintType( CheckCase.class )\n"
+" .param( \"value\", CaseMode.UPPER );"
+msgstr ""
+
+#. Tag: para
+#: programmaticapi.xml:72
+#, no-c-format
+msgid ""
+"Last but not least, you can also define cascading constraints as well as the "
+"default group sequence of an entity."
+msgstr ""
+
+#. Tag: title
+#: programmaticapi.xml:76
+#, no-c-format
+msgid "Cascading constraints and group redefinition"
+msgstr ""
+
+#. Tag: programlisting
+#: programmaticapi.xml:78
+#, no-c-format
+msgid ""
+"ConstraintMapping mapping = new ConstraintMapping();\n"
+"mapping.type( Car.class )\n"
+" .valid( \"driver\", FIELD )\n"
+".type( RentalCar.class)\n"
+" .defaultGroupSequence( RentalCar.class, CarChecks.class );"
+msgstr ""
+
+#. Tag: para
+#: programmaticapi.xml:81
+#, no-c-format
+msgid ""
+"Once you have your <classname>ConstraintMapping</classname> you will have to "
+"pass it to the configuration. Since the programmatic configuration is not "
+"part of the official Bean Validation specification you will have to get hold "
+"of the Hibernate Validator specific configuration instance. See <xref "
+"linkend=\"example-hibernate-specific-config\"/>."
+msgstr ""
+
+#. Tag: title
+#: programmaticapi.xml:88
+#, no-c-format
+msgid "Creating a Hibernate Validator specific configuration"
+msgstr ""
+
+#. Tag: programlisting
+#: programmaticapi.xml:90
+#, no-c-format
+msgid ""
+"ConstraintMapping mapping = new ConstraintMapping();\n"
+"// configure mapping instance\n"
+"\n"
+"HibernateValidatorConfiguration config = Validation.byProvider"
+"( HibernateValidator.class ).configure();\n"
+"config.addMapping( mapping );\n"
+"ValidatorFactory factory = config.buildValidatorFactory();\n"
+"Validator validator = factory.getValidator();"
+msgstr ""
Added: validator/trunk/hibernate-validator/src/main/docbook/zh-CN/modules/usingvalidator.po
===================================================================
--- validator/trunk/hibernate-validator/src/main/docbook/zh-CN/modules/usingvalidator.po (rev 0)
+++ validator/trunk/hibernate-validator/src/main/docbook/zh-CN/modules/usingvalidator.po 2010-07-06 15:18:26 UTC (rev 19904)
@@ -0,0 +1,1946 @@
+# Language zh-CN translations for PACKAGE package.
+# Automatically generated, 2010.
+#
+msgid ""
+msgstr ""
+"Project-Id-Version: PACKAGE VERSION\n"
+"Report-Msgid-Bugs-To: http://bugs.kde.org\n"
+"POT-Creation-Date: 2010-07-06 14:46+0000\n"
+"PO-Revision-Date: 2010-07-06 14:46+0000\n"
+"Last-Translator: Automatically generated\n"
+"Language-Team: none\n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+
+#. Tag: title
+#: usingvalidator.xml:25
+#, no-c-format
+msgid "Validation step by step"
+msgstr ""
+
+#. Tag: para
+#: usingvalidator.xml:27
+#, no-c-format
+msgid ""
+"In this chapter we will see in more detail how to use Hibernate Validator to "
+"validate constraints for a given entity model. We will also learn which "
+"default constraints the Bean Validation specification provides and which "
+"additional constraints are only provided by Hibernate Validator. Let's start "
+"with how to add constraints to an entity."
+msgstr ""
+
+#. Tag: title
+#: usingvalidator.xml:34
+#, no-c-format
+msgid "Defining constraints"
+msgstr ""
+
+#. Tag: para
+#: usingvalidator.xml:36
+#, no-c-format
+msgid ""
+"Constraints in Bean Validation are expressed via Java annotations. In this "
+"section we show how to annotate an object model with these annotations. We "
+"have to differentiate between three different type of constraint annotations "
+"- field-, property-, and class-level annotations."
+msgstr ""
+
+#. Tag: para
+#: usingvalidator.xml:43
+#, no-c-format
+msgid ""
+"Not all constraints can be placed on all of these levels. In fact, none of "
+"the default constraints defined by Bean Validation can be placed at class "
+"level. The <classname>java.lang.annotation.Target</classname> annotation in "
+"the constraint annotation itself determines on which elements a constraint "
+"can be placed. See <xref linkend=\"validator-customconstraints\"/> for more "
+"information."
+msgstr ""
+
+#. Tag: title
+#: usingvalidator.xml:52
+#, no-c-format
+msgid "Field-level constraints"
+msgstr ""
+
+#. Tag: para
+#: usingvalidator.xml:54
+#, no-c-format
+msgid ""
+"Constraints can be expressed by annotating a field of a class. <xref linkend="
+"\"example-field-level\"/> shows a field level configuration example:"
+msgstr ""
+
+#. Tag: title
+#: usingvalidator.xml:59
+#, no-c-format
+msgid "Field level constraint"
+msgstr ""
+
+#. Tag: programlisting
+#: usingvalidator.xml:61
+#, no-c-format
+msgid ""
+"package com.mycompany;\n"
+"\n"
+"import javax.validation.constraints.NotNull;\n"
+"\n"
+"public class Car {\n"
+"\n"
+" @NotNull\n"
+" private String manufacturer;\n"
+"\n"
+" @AssertTrue\n"
+" private boolean isRegistered;\n"
+"\n"
+" public Car(String manufacturer, boolean isRegistered) {\n"
+" super();\n"
+" this.manufacturer = manufacturer;\n"
+" this.isRegistered = isRegistered;\n"
+" }\n"
+"}"
+msgstr ""
+
+#. Tag: para
+#: usingvalidator.xml:64
+#, no-c-format
+msgid ""
+"When using field level constraints field access strategy is used to access "
+"the value to be validated. This means the bean validation provider directly "
+"accesses the instance variable and does not invoke the property accessor "
+"method also if such a method exists."
+msgstr ""
+
+#. Tag: para
+#: usingvalidator.xml:70
+#, no-c-format
+msgid "The access type (private, protected or public) does not matter."
+msgstr ""
+
+#. Tag: para
+#: usingvalidator.xml:75
+#, no-c-format
+msgid "Static fields and properties cannot be validated."
+msgstr ""
+
+#. Tag: title
+#: usingvalidator.xml:80
+#, no-c-format
+msgid "Property-level constraints"
+msgstr ""
+
+#. Tag: para
+#: usingvalidator.xml:82
+#, no-c-format
+msgid ""
+"If your model class adheres to the <ulink type=\"\" url=\"http://java.sun."
+"com/javase/technologies/desktop/javabeans/index.jsp\">JavaBeans</ulink> "
+"standard, it is also possible to annotate the properties of a bean class "
+"instead of its fields. <xref linkend=\"example-property-level\"/> uses the "
+"same entity as in <xref linkend=\"example-field-level\"/>, however, property "
+"level constraints are used."
+msgstr ""
+
+#. Tag: para
+#: usingvalidator.xml:88
+#, no-c-format
+msgid "The property's getter method has to be annotated, not its setter."
+msgstr ""
+
+#. Tag: title
+#: usingvalidator.xml:93
+#, no-c-format
+msgid "Property level constraint"
+msgstr ""
+
+#. Tag: programlisting
+#: usingvalidator.xml:95
+#, no-c-format
+msgid ""
+"package com.mycompany;\n"
+"\n"
+"import javax.validation.constraints.AssertTrue;\n"
+"import javax.validation.constraints.NotNull;\n"
+"\n"
+"public class Car {\n"
+"\n"
+" private String manufacturer;\n"
+"\n"
+" private boolean isRegistered;\n"
+" \n"
+" public Car(String manufacturer, boolean isRegistered) {\n"
+" super();\n"
+" this.manufacturer = manufacturer;\n"
+" this.isRegistered = isRegistered;\n"
+" }\n"
+"\n"
+" @NotNull\n"
+" public String getManufacturer() {\n"
+" return manufacturer;\n"
+" }\n"
+"\n"
+" public void setManufacturer(String manufacturer) {\n"
+" this.manufacturer = manufacturer;\n"
+" }\n"
+"\n"
+" @AssertTrue\n"
+" public boolean isRegistered() {\n"
+" return isRegistered;\n"
+" }\n"
+"\n"
+" public void setRegistered(boolean isRegistered) {\n"
+" this.isRegistered = isRegistered;\n"
+" }\n"
+"}"
+msgstr ""
+
+#. Tag: para
+#: usingvalidator.xml:98
+#, no-c-format
+msgid ""
+"When using property level constraints property access strategy is used to "
+"access the value to be validated. This means the bean validation provider "
+"accesses the state via the property accessor method."
+msgstr ""
+
+#. Tag: para
+#: usingvalidator.xml:103
+#, no-c-format
+msgid ""
+"It is recommended to stick either to field <emphasis>or</emphasis> property "
+"annotation within one class. It is not recommended to annotate a field "
+"<emphasis>and</emphasis> the accompanying getter method as this would cause "
+"the field to be validated twice."
+msgstr ""
+
+#. Tag: title
+#: usingvalidator.xml:112
+#, no-c-format
+msgid "Class-level constraints"
+msgstr ""
+
+#. Tag: para
+#: usingvalidator.xml:115
+#, no-c-format
+msgid ""
+"Last but not least, a constraint can also be placed on class level. When a "
+"constraint annotation is placed on this level the class instance itself "
+"passed to the <classname>ConstraintValidator</classname>. Class level "
+"constraints are useful if it is necessary to inspect more than a single "
+"property of the class to validate it or if a correlation between different "
+"state variables has to be evaluated. In <xref linkend=\"example-class-level"
+"\"/> we add the property <property>passengers</property> to the class "
+"<classname>Car</classname>. We also add the constraint "
+"<classname>PassengerCount</classname> on the class level. We will later see "
+"how we can actually create this custom constraint (see <xref linkend="
+"\"validator-customconstraints\"/>). For now we it is enough to know that "
+"<classname>PassengerCount</classname> will ensure that there cannot be more "
+"passengers in a car than there are seats."
+msgstr ""
+
+#. Tag: title
+#: usingvalidator.xml:131
+#, no-c-format
+msgid "Class level constraint"
+msgstr ""
+
+#. Tag: programlisting
+#: usingvalidator.xml:133
+#, no-c-format
+msgid ""
+"package com.mycompany;\n"
+"\n"
+"import javax.validation.constraints.Min;\n"
+"import javax.validation.constraints.NotNull;\n"
+"import javax.validation.constraints.Size;\n"
+"\n"
+"@PassengerCount\n"
+"public class Car {\n"
+"\n"
+" @NotNull\n"
+" private String manufacturer;\n"
+"\n"
+" @NotNull\n"
+" @Size(min = 2, max = 14)\n"
+" private String licensePlate;\n"
+"\n"
+" @Min(2)\n"
+" private int seatCount;\n"
+" \n"
+" private List<Person> passengers;\n"
+" \n"
+" public Car(String manufacturer, String licencePlate, int seatCount) {\n"
+" this.manufacturer = manufacturer;\n"
+" this.licensePlate = licencePlate;\n"
+" this.seatCount = seatCount;\n"
+" }\n"
+"\n"
+" //getters and setters ...\n"
+"}"
+msgstr ""
+
+#. Tag: title
+#: usingvalidator.xml:138
+#, no-c-format
+msgid "Constraint inheritance"
+msgstr ""
+
+#. Tag: para
+#: usingvalidator.xml:140
+#, no-c-format
+msgid ""
+"When validating an object that implements an interface or extends another "
+"class, all constraint annotations on the implemented interface and parent "
+"class apply in the same manner as the constraints specified on the validated "
+"object itself. To make things clearer let's have a look at the following "
+"example:"
+msgstr ""
+
+#. Tag: title
+#: usingvalidator.xml:147
+#, no-c-format
+msgid "Constraint inheritance using RentalCar"
+msgstr ""
+
+#. Tag: programlisting
+#: usingvalidator.xml:149
+#, no-c-format
+msgid ""
+"package com.mycompany;\n"
+"\n"
+"import javax.validation.constraints.NotNull;\n"
+"\n"
+"public class RentalCar extends Car {\n"
+"\n"
+" private String rentalStation;\n"
+" \n"
+" public RentalCar(String manufacturer, String rentalStation) {\n"
+" super(manufacturer);\n"
+" this.rentalStation = rentalStation;\n"
+" }\n"
+" \n"
+" @NotNull\n"
+" public String getRentalStation() {\n"
+" return rentalStation;\n"
+" }\n"
+"\n"
+" public void setRentalStation(String rentalStation) {\n"
+" this.rentalStation = rentalStation;\n"
+" }\n"
+"}"
+msgstr ""
+
+#. Tag: para
+#: usingvalidator.xml:152
+#, no-c-format
+msgid ""
+"Our well-known class <classname>Car</classname> is now extended by "
+"<classname>RentalCar</classname> with the additional property "
+"<property>rentalStation</property>. If an instance of <classname>RentalCar</"
+"classname> is validated, not only the <classname>@NotNull</classname> "
+"constraint on <property>rentalStation</property> is validated, but also the "
+"constraint on <property>manufacturer</property> from the parent class."
+msgstr ""
+
+#. Tag: para
+#: usingvalidator.xml:160
+#, no-c-format
+msgid ""
+"The same would hold true, if <classname>Car</classname> were an interface "
+"implemented by <classname>RentalCar</classname>."
+msgstr ""
+
+#. Tag: para
+#: usingvalidator.xml:163
+#, no-c-format
+msgid ""
+"Constraint annotations are aggregated if methods are overridden. If "
+"<classname>RentalCar</classname> would override the "
+"<methodname>getManufacturer()</methodname> method from <classname>Car</"
+"classname> any constraints annotated at the overriding method would be "
+"evaluated in addition to the <classname>@NotNull</classname> constraint from "
+"the super-class."
+msgstr ""
+
+#. Tag: title
+#: usingvalidator.xml:172
+#, no-c-format
+msgid "Object graphs"
+msgstr ""
+
+#. Tag: para
+#: usingvalidator.xml:174
+#, no-c-format
+msgid ""
+"The Bean Validation API does not only allow to validate single class "
+"instances but also complete object graphs. To do so, just annotate a field "
+"or property representing a reference to another object with "
+"<classname>@Valid</classname>. If the parent object is validated, all "
+"referenced objects annotated with <classname>@Valid</classname> will be "
+"validated as well (as will be their children etc.). See <xref linkend="
+"\"example-car-with-driver\"/>."
+msgstr ""
+
+#. Tag: title
+#: usingvalidator.xml:183
+#, no-c-format
+msgid "Class Person"
+msgstr ""
+
+#. Tag: programlisting
+#: usingvalidator.xml:185
+#, no-c-format
+msgid ""
+"package com.mycompany;\n"
+"\n"
+"import javax.validation.constraints.NotNull;\n"
+"\n"
+"public class Person {\n"
+"\n"
+" @NotNull\n"
+" private String name;\n"
+" \n"
+" public Person(String name) {\n"
+" super();\n"
+" this.name = name;\n"
+" }\n"
+"\n"
+" public String getName() {\n"
+" return name;\n"
+" }\n"
+"\n"
+" public void setName(String name) {\n"
+" this.name = name;\n"
+" }\n"
+"}"
+msgstr ""
+
+#. Tag: title
+#: usingvalidator.xml:189
+#, no-c-format
+msgid "Adding a driver to the car"
+msgstr ""
+
+#. Tag: programlisting
+#: usingvalidator.xml:191
+#, no-c-format
+msgid ""
+"package com.mycompany;\n"
+"\n"
+"import javax.validation.Valid;\n"
+"import javax.validation.constraints.NotNull;\n"
+"\n"
+"public class Car {\n"
+"\n"
+" @NotNull\n"
+" @Valid\n"
+" private Person driver;\n"
+" \n"
+" public Car(Person driver) {\n"
+" this.driver = driver;\n"
+" }\n"
+"\n"
+" //getters and setters ...\n"
+"}"
+msgstr ""
+
+#. Tag: para
+#: usingvalidator.xml:194
+#, no-c-format
+msgid ""
+"If an instance of <classname>Car</classname> is validated, the referenced "
+"<classname>Person</classname> object will be validated as well, as the "
+"<property>driver</property> field is annotated with <classname>@Valid</"
+"classname>. Therefore the validation of a <classname>Car</classname> will "
+"fail if the <property>name</property> field of the referenced "
+"<classname>Person</classname> instance is <code>null</code>."
+msgstr ""
+
+#. Tag: para
+#: usingvalidator.xml:202
+#, no-c-format
+msgid ""
+"Object graph validation also works for collection-typed fields. That means "
+"any attributes that"
+msgstr ""
+
+#. Tag: para
+#: usingvalidator.xml:207
+#, no-c-format
+msgid "are arrays"
+msgstr ""
+
+#. Tag: para
+#: usingvalidator.xml:211
+#, no-c-format
+msgid ""
+"implement <classname>java.lang.Iterable</classname> (especially "
+"<classname>Collection</classname>, <classname>List</classname> and "
+"<classname>Set</classname>)"
+msgstr ""
+
+#. Tag: para
+#: usingvalidator.xml:217
+#, no-c-format
+msgid "implement <classname>java.util.Map</classname>"
+msgstr ""
+
+#. Tag: para
+#: usingvalidator.xml:221
+#, no-c-format
+msgid ""
+"can be annotated with <classname>@Valid</classname>, which will cause each "
+"contained element to be validated, when the parent object is validated."
+msgstr ""
+
+#. Tag: title
+#: usingvalidator.xml:226
+#, no-c-format
+msgid "Car with a list of passengers"
+msgstr ""
+
+#. Tag: programlisting
+#: usingvalidator.xml:228
+#, no-c-format
+msgid ""
+"package com.mycompany;\n"
+"\n"
+"import java.util.ArrayList;\n"
+"import java.util.List;\n"
+"\n"
+"import javax.validation.Valid;\n"
+"import javax.validation.constraints.NotNull;\n"
+"\n"
+"public class Car {\n"
+"\n"
+" @NotNull\n"
+" @Valid\n"
+" private List<Person> passengers = new ArrayList<Person>();\n"
+"\n"
+" public Car(List<Person> passengers) {\n"
+" this.passengers = passengers;\n"
+" }\n"
+"\n"
+" //getters and setters ...\n"
+"}"
+msgstr ""
+
+#. Tag: para
+#: usingvalidator.xml:231
+#, no-c-format
+msgid ""
+"If a <classname>Car</classname> instance is validated, a "
+"<classname>ConstraintValidation</classname> will be created, if any of the "
+"<classname>Person</classname> objects contained in the <property>passengers</"
+"property> list has a <code>null</code> name."
+msgstr ""
+
+#. Tag: para
+#: usingvalidator.xml:235
+#, no-c-format
+msgid ""
+"<classname>null</classname> values are getting ignored when validating "
+"object graphs."
+msgstr ""
+
+#. Tag: title
+#: usingvalidator.xml:242
+#, no-c-format
+msgid "Validating constraints"
+msgstr ""
+
+#. Tag: para
+#: usingvalidator.xml:244
+#, no-c-format
+msgid ""
+"The <classname>Validator</classname> interface is the main entry point to "
+"Bean Validation. In <xref linkend=\"section-validator-instance\"/> we will "
+"first show how to obtain an <classname>Validator</classname> instance. "
+"Afterwards we will learn how to use the different methods of the "
+"<classname>Validator</classname> interface."
+msgstr ""
+
+#. Tag: title
+#: usingvalidator.xml:251
+#, no-c-format
+msgid "Obtaining a <classname>Validator</classname> instance"
+msgstr ""
+
+#. Tag: para
+#: usingvalidator.xml:253
+#, no-c-format
+msgid ""
+"The first step towards validating an entity instance is to get hold of a "
+"<classname>Validator</classname> instance. The road to this instance leads "
+"via the <classname>Validation</classname> class and a "
+"<classname>ValidatorFactory</classname>. The easiest way is to use the "
+"static <methodname>Validation.buildDefaultValidatorFactory()</methodname> "
+"method:"
+msgstr ""
+
+#. Tag: title
+#: usingvalidator.xml:262
+#, no-c-format
+msgid "Validation.buildDefaultValidatorFactory()"
+msgstr ""
+
+#. Tag: programlisting
+#: usingvalidator.xml:264
+#, no-c-format
+msgid ""
+"ValidatorFactory factory = Validation.buildDefaultValidatorFactory();\n"
+"Validator validator = factory.getValidator();"
+msgstr ""
+
+#. Tag: para
+#: usingvalidator.xml:267
+#, no-c-format
+msgid ""
+"For other ways of obtaining a Validator instance see <xref linkend="
+"\"validator-bootstrapping\"/>. For now we just want to see how we can use "
+"the <classname>Validator</classname> instance to validate entity instances."
+msgstr ""
+
+#. Tag: title
+#: usingvalidator.xml:274
+#, no-c-format
+msgid "Validator methods"
+msgstr ""
+
+#. Tag: para
+#: usingvalidator.xml:276
+#, no-c-format
+msgid ""
+"The <classname>Validator</classname> interface contains three methods that "
+"can be used to either validate entire entities or just a single properties "
+"of the entity."
+msgstr ""
+
+#. Tag: para
+#: usingvalidator.xml:280
+#, no-c-format
+msgid ""
+"All three methods return a <classname>Set<ConstraintViolation></"
+"classname>. The set is empty, if the validation succeeds. Otherwise a "
+"<classname>ConstraintViolation</classname> instance is added for each "
+"violated constraint."
+msgstr ""
+
+#. Tag: para
+#: usingvalidator.xml:286
+#, no-c-format
+msgid ""
+"All the validation methods have a var-args parameter which can be used to "
+"specify, which validation groups shall be considered when performing the "
+"validation. If the parameter is not specified the default validation group "
+"(<classname>javax.validation.groups.Default</classname>) will be used. We "
+"will go into more detail on the topic of validation groups in"
+msgstr ""
+
+#. Tag: methodname
+#: usingvalidator.xml:295
+#, no-c-format
+msgid "validate"
+msgstr ""
+
+#. Tag: para
+#: usingvalidator.xml:297
+#, no-c-format
+msgid ""
+"Use the <methodname>validate()</methodname> method to perform validation of "
+"all constraints of a given entity instance (see <xref linkend=\"example-"
+"validator-validate\"/> )."
+msgstr ""
+
+#. Tag: title
+#: usingvalidator.xml:302
+#, no-c-format
+msgid "Usage of <methodname>Validator.validate()</methodname>"
+msgstr ""
+
+#. Tag: programlisting
+#: usingvalidator.xml:305
+#, no-c-format
+msgid ""
+"ValidatorFactory factory = Validation.buildDefaultValidatorFactory();\n"
+"Validator validator = factory.getValidator();\n"
+"\n"
+"Car car = new Car(null);\n"
+"\n"
+"Set<ConstraintViolation<Car>> constraintViolations = validator."
+"validate(car);\n"
+"\n"
+"assertEquals(1, constraintViolations.size());\n"
+"assertEquals(\"may not be null\", constraintViolations.iterator().next()."
+"getMessage());"
+msgstr ""
+
+#. Tag: methodname
+#: usingvalidator.xml:310
+#, no-c-format
+msgid "validateProperty"
+msgstr ""
+
+#. Tag: para
+#: usingvalidator.xml:312
+#, no-c-format
+msgid ""
+"With help of the <methodname>validateProperty()</methodname> a single named "
+"property of a given object can be validated. The property name is the "
+"JavaBeans property name."
+msgstr ""
+
+#. Tag: title
+#: usingvalidator.xml:317
+#, no-c-format
+msgid "Usage of <methodname>Validator.validateProperty()</methodname>"
+msgstr ""
+
+#. Tag: programlisting
+#: usingvalidator.xml:320
+#, no-c-format
+msgid ""
+"Validator validator = Validation.buildDefaultValidatorFactory().getValidator"
+"();\n"
+"\n"
+"Car car = new Car(null);\n"
+"\n"
+"Set<ConstraintViolation<Car>> constraintViolations = validator."
+"validateProperty(car, \"manufacturer\");\n"
+"\n"
+"assertEquals(1, constraintViolations.size());\n"
+"assertEquals(\"may not be null\", constraintViolations.iterator().next()."
+"getMessage());"
+msgstr ""
+
+#. Tag: para
+#: usingvalidator.xml:323
+#, no-c-format
+msgid ""
+"<methodname>Validator.validateProperty</methodname> is for example used in "
+"the integration of Bean Validation into JSF 2 (see <xref linkend=\"section-"
+"presentation-layer\"/>)."
+msgstr ""
+
+#. Tag: methodname
+#: usingvalidator.xml:329
+#, no-c-format
+msgid "validateValue"
+msgstr ""
+
+#. Tag: para
+#: usingvalidator.xml:331
+#, no-c-format
+msgid ""
+"Using the <methodname>validateValue() </methodname>method you can check, "
+"whether a single property of a given class can be validated successfully, if "
+"the property had the specified value:"
+msgstr ""
+
+#. Tag: title
+#: usingvalidator.xml:336
+#, no-c-format
+msgid "Usage of <methodname>Validator.validateValue()</methodname>"
+msgstr ""
+
+#. Tag: programlisting
+#: usingvalidator.xml:339
+#, no-c-format
+msgid ""
+"Validator validator = Validation.buildDefaultValidatorFactory().getValidator"
+"();\n"
+"\n"
+"Set<ConstraintViolation<Car>> constraintViolations = validator."
+"validateValue(Car.class, \"manufacturer\", null);\n"
+"\n"
+"assertEquals(1, constraintViolations.size());\n"
+"assertEquals(\"may not be null\", constraintViolations.iterator().next()."
+"getMessage());"
+msgstr ""
+
+#. Tag: para
+#: usingvalidator.xml:343
+#, no-c-format
+msgid ""
+"<classname>@Valid</classname> is not honored by <methodname>validateProperty"
+"()</methodname> or <methodname>validateValue()</methodname>."
+msgstr ""
+
+#. Tag: title
+#: usingvalidator.xml:351
+#, no-c-format
+msgid "<classname>ConstraintViolation</classname> methods"
+msgstr ""
+
+#. Tag: para
+#: usingvalidator.xml:353
+#, no-c-format
+msgid ""
+"Now it is time to have a closer look at what a "
+"<classname>ConstraintViolation</classname>. Using the different methods of "
+"<classname>ConstraintViolation</classname> a lot of useful information about "
+"the cause of the validation failure can be determined. <xref linkend=\"table-"
+"constraint-violation\"/> gives an overview of these methods:"
+msgstr ""
+
+#. Tag: title
+#: usingvalidator.xml:361
+#, no-c-format
+msgid "The various <classname>ConstraintViolation</classname> methods"
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:367
+#, no-c-format
+msgid "Method"
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:369
+#, no-c-format
+msgid "Usage"
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:371
+#, no-c-format
+msgid "Example (referring to <xref linkend=\"example-validator-validate\"/>)"
+msgstr ""
+
+#. Tag: methodname
+#: usingvalidator.xml:378
+#, no-c-format
+msgid "getMessage()"
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:380
+#, no-c-format
+msgid "The interpolated error message."
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:382
+#, no-c-format
+msgid "may not be null"
+msgstr ""
+
+#. Tag: methodname
+#: usingvalidator.xml:386
+#, no-c-format
+msgid "getMessageTemplate()"
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:388
+#, no-c-format
+msgid "The non-interpolated error message."
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:390
+#, no-c-format
+msgid "{javax.validation.constraints.NotNull.message}"
+msgstr ""
+
+#. Tag: methodname
+#: usingvalidator.xml:394
+#, no-c-format
+msgid "getRootBean()"
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:396
+#, no-c-format
+msgid "The root bean being validated."
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:398 usingvalidator.xml:416
+#, no-c-format
+msgid "<entry>car</entry>"
+msgstr ""
+
+#. Tag: methodname
+#: usingvalidator.xml:402
+#, no-c-format
+msgid "getRootBeanClass()"
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:404
+#, no-c-format
+msgid "The class of the root bean being validated."
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:406
+#, no-c-format
+msgid "Car.class"
+msgstr ""
+
+#. Tag: methodname
+#: usingvalidator.xml:410
+#, no-c-format
+msgid "getLeafBean()"
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:412
+#, no-c-format
+msgid ""
+"If a bean constraint, the bean instance the constraint is applied on. If a "
+"property constraint, the bean instance hosting the property the constraint "
+"is applied on."
+msgstr ""
+
+#. Tag: methodname
+#: usingvalidator.xml:420
+#, no-c-format
+msgid "getPropertyPath()"
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:422
+#, no-c-format
+msgid "The property path to the value from root bean."
+msgstr ""
+
+#. Tag: methodname
+#: usingvalidator.xml:428
+#, no-c-format
+msgid "getInvalidValue()"
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:430
+#, no-c-format
+msgid "The value failing to pass the constraint."
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:432
+#, no-c-format
+msgid "passengers"
+msgstr ""
+
+#. Tag: methodname
+#: usingvalidator.xml:436
+#, no-c-format
+msgid "getConstraintDescriptor()"
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:438
+#, no-c-format
+msgid "Constraint metadata reported to fail."
+msgstr ""
+
+#. Tag: title
+#: usingvalidator.xml:448
+#, no-c-format
+msgid "Message interpolation"
+msgstr ""
+
+#. Tag: para
+#: usingvalidator.xml:450
+#, no-c-format
+msgid ""
+"As we will see in <xref linkend=\"validator-customconstraints\"/> each "
+"constraint definition must define a default message descriptor. This message "
+"can be overridden at declaration time using the <methodname>message</"
+"methodname> attribute of the constraint. You can see this in <xref linkend="
+"\"example-driver\"/>. This message descriptors get interpolated when a "
+"constraint validation fails using the configured "
+"<classname>MessageInterpolator</classname>. The interpolator will try to "
+"resolve any message parameters, meaning string literals enclosed in braces. "
+"In order to resolve these parameters Hibernate Validator's default "
+"<classname>MessageInterpolator</classname> first recursively resolves "
+"parameters against a custom <classname>ResourceBundle</classname> called "
+"<filename>ValidationMessages.properties</filename> at the root of the "
+"classpath (It is up to you to create this file). If no further replacements "
+"are possible against the custom bundle the default "
+"<classname>ResourceBundle</classname> under <filename>/org/hibernate/"
+"validator/ValidationMessages.properties</filename> gets evaluated. If a "
+"replacement occurs against the default bundle the algorithm looks again at "
+"the custom bundle (and so on). Once no further replacements against these "
+"two resource bundles are possible remaining parameters are getting resolved "
+"against the attributes of the constraint to be validated."
+msgstr ""
+
+#. Tag: para
+#: usingvalidator.xml:473
+#, no-c-format
+msgid ""
+"Since the braces { and } have special meaning in the messages they need to "
+"be escaped if they are used literally. The following The following rules "
+"apply:"
+msgstr ""
+
+#. Tag: para
+#: usingvalidator.xml:477
+#, no-c-format
+msgid "\\{ is considered as the literal {"
+msgstr ""
+
+#. Tag: para
+#: usingvalidator.xml:481
+#, no-c-format
+msgid "\\} is considered as the literal }"
+msgstr ""
+
+#. Tag: para
+#: usingvalidator.xml:485
+#, no-c-format
+msgid "\\\\ is considered as the literal \\"
+msgstr ""
+
+#. Tag: para
+#: usingvalidator.xml:489
+#, no-c-format
+msgid ""
+"If the default message interpolator does not fit your requirements it is "
+"possible to plug a custom <classname>MessageInterpolator</classname> when "
+"the <classname>ValidatorFactory</classname> gets created. This can be seen "
+"in <xref linkend=\"validator-bootstrapping\"/>."
+msgstr ""
+
+#. Tag: title
+#: usingvalidator.xml:498
+#, no-c-format
+msgid "Validating groups"
+msgstr ""
+
+#. Tag: para
+#: usingvalidator.xml:500
+#, no-c-format
+msgid ""
+"Groups allow you to restrict the set of constraints applied during "
+"validation. This makes for example wizard like validation possible where in "
+"each step only a specified subset of constraints get validated. The groups "
+"targeted are passed as var-args parameters to <methodname>validate</"
+"methodname>, <methodname>validateProperty</methodname> and "
+"<methodname>validateValue</methodname>. Let's have a look at an extended "
+"<classname>Car</classname> with <classname>Driver</classname> example. First "
+"we have the class <classname>Person</classname> (<xref linkend=\"example-"
+"person\"/>) which has a <classname>@NotNull </classname>constraint on "
+"<property>name</property>. Since no group is specified for this annotation "
+"its default group is <classname>javax.validation.groups.Default</classname>."
+msgstr ""
+
+#. Tag: para
+#: usingvalidator.xml:515
+#, no-c-format
+msgid ""
+"When more than one group is requested, the order in which the groups are "
+"evaluated is not deterministic. If no group is specified the default group "
+"<classname>javax.validation.groups.Default</classname> is assumed."
+msgstr ""
+
+#. Tag: title
+#: usingvalidator.xml:522
+#, no-c-format
+msgid "Person"
+msgstr ""
+
+#. Tag: programlisting
+#: usingvalidator.xml:524
+#, no-c-format
+msgid ""
+"public class Person {\n"
+" @NotNull\n"
+" private String name;\n"
+"\n"
+" public Person(String name) {\n"
+" this.name = name;\n"
+" }\n"
+" // getters and setters ...\n"
+"}"
+msgstr ""
+
+#. Tag: para
+#: usingvalidator.xml:527
+#, no-c-format
+msgid ""
+"Next we have the class <classname>Driver</classname> (<xref linkend="
+"\"example-driver\"/>) extending <classname>Person</classname>. Here we are "
+"adding the properties <property>age</property> and "
+"<property>hasDrivingLicense</property>. In order to drive you must be at "
+"least 18 (<classname>@Min(18)</classname>) and you must have a driving "
+"license (<classname>@AssertTrue</classname>). Both constraints defined on "
+"these properties belong to the group <classname>DriverChecks</classname>. As "
+"you can see in <xref linkend=\"example-group-interfaces\"/> the group "
+"<classname>DriverChecks</classname> is just a simple tagging interface. "
+"Using interfaces makes the usage of groups type safe and allows for easy "
+"refactoring. It also means that groups can inherit from each other via class "
+"inheritance."
+msgstr ""
+
+#. Tag: para
+#: usingvalidator.xml:541
+#, no-c-format
+msgid ""
+"The Bean Validation specification does not enforce that groups have to be "
+"interfaces. Non interface classes could be used as well, but we recommend to "
+"stick to interfaces."
+msgstr ""
+
+#. Tag: title
+#: usingvalidator.xml:547
+#, no-c-format
+msgid "Driver"
+msgstr ""
+
+#. Tag: programlisting
+#: usingvalidator.xml:549
+#, no-c-format
+msgid ""
+"public class Driver extends Person {\n"
+" @Min(value = 18, message = \"You have to be 18 to drive a car\", groups "
+"= DriverChecks.class)\n"
+" public int age;\n"
+"\n"
+" @AssertTrue(message = \"You first have to pass the driving test\", "
+"groups = DriverChecks.class)\n"
+" public boolean hasDrivingLicense;\n"
+"\n"
+" public Driver(String name) {\n"
+" super( name );\n"
+" }\n"
+"\n"
+" public void passedDrivingTest(boolean b) {\n"
+" hasDrivingLicense = b;\n"
+" }\n"
+"\n"
+" public int getAge() {\n"
+" return age;\n"
+" }\n"
+"\n"
+" public void setAge(int age) {\n"
+" this.age = age;\n"
+" }\n"
+"}"
+msgstr ""
+
+#. Tag: title
+#: usingvalidator.xml:553
+#, no-c-format
+msgid "Group interfaces"
+msgstr ""
+
+#. Tag: programlisting
+#: usingvalidator.xml:555
+#, no-c-format
+msgid ""
+"public interface DriverChecks {\n"
+"}\n"
+"\n"
+"public interface CarChecks {\n"
+"}"
+msgstr ""
+
+#. Tag: para
+#: usingvalidator.xml:558
+#, no-c-format
+msgid ""
+"Last but not least we add the property <property>passedVehicleInspection</"
+"property> to the <classname>Car</classname> class (<xref linkend=\"example-"
+"car\"/>) indicating whether a car passed the road worthy tests."
+msgstr ""
+
+#. Tag: title
+#: usingvalidator.xml:564
+#, no-c-format
+msgid "<title>Car</title>"
+msgstr ""
+
+#. Tag: programlisting
+#: usingvalidator.xml:566
+#, no-c-format
+msgid ""
+"public class Car {\n"
+" @NotNull\n"
+" private String manufacturer;\n"
+"\n"
+" @NotNull\n"
+" @Size(min = 2, max = 14)\n"
+" private String licensePlate;\n"
+"\n"
+" @Min(2)\n"
+" private int seatCount;\n"
+"\n"
+" @AssertTrue(message = \"The car has to pass the vehicle inspection first"
+"\", groups = CarChecks.class)\n"
+" private boolean passedVehicleInspection;\n"
+"\n"
+" @Valid\n"
+" private Driver driver;\n"
+"\n"
+" public Car(String manufacturer, String licencePlate, int seatCount) {\n"
+" this.manufacturer = manufacturer;\n"
+" this.licensePlate = licencePlate;\n"
+" this.seatCount = seatCount;\n"
+" }\n"
+"}"
+msgstr ""
+
+#. Tag: para
+#: usingvalidator.xml:569
+#, no-c-format
+msgid ""
+"Overall three different groups are used in our example. <property>Person."
+"name</property>, <property>Car.manufacturer</property>, <property>Car."
+"licensePlate</property> and <property>Car.seatCount</property> all belong to "
+"the <classname>Default</classname> group. <property>Driver.age</property> "
+"and <property>Driver.hasDrivingLicense</property> belong to "
+"<classname>DriverChecks</classname> and last but not least <property>Car."
+"passedVehicleInspection</property> belongs to the group "
+"<classname>CarChecks</classname>. <xref linkend=\"example-drive-away\"/> "
+"shows how passing different group combinations to the <methodname>Validator."
+"validate</methodname> method result in different validation results."
+msgstr ""
+
+#. Tag: title
+#: usingvalidator.xml:583
+#, no-c-format
+msgid "Drive away"
+msgstr ""
+
+#. Tag: programlisting
+#: usingvalidator.xml:585
+#, no-c-format
+msgid ""
+"public class GroupTest {\n"
+"\n"
+" private static Validator validator;\n"
+"\n"
+" @BeforeClass\n"
+" public static void setUp() {\n"
+" ValidatorFactory factory = Validation.buildDefaultValidatorFactory"
+"();\n"
+" validator = factory.getValidator();\n"
+" }\n"
+"\n"
+" @Test\n"
+" public void driveAway() {\n"
+" // create a car and check that everything is ok with it.\n"
+" Car car = new Car( \"Morris\", \"DD-AB-123\", 2 );\n"
+" Set<ConstraintViolation<Car>> constraintViolations = "
+"validator.validate( car );\n"
+" assertEquals( 0, constraintViolations.size() );\n"
+"\n"
+" // but has it passed the vehicle inspection?\n"
+" constraintViolations = validator.validate( car, CarChecks.class );\n"
+" assertEquals( 1, constraintViolations.size() );\n"
+" assertEquals(\"The car has to pass the vehicle inspection first\", "
+"constraintViolations.iterator().next().getMessage());\n"
+"\n"
+" // let's go to the vehicle inspection\n"
+" car.setPassedVehicleInspection( true );\n"
+" assertEquals( 0, validator.validate( car ).size() );\n"
+"\n"
+" // now let's add a driver. He is 18, but has not passed the driving "
+"test yet\n"
+" Driver john = new Driver( \"John Doe\" );\n"
+" john.setAge( 18 );\n"
+" car.setDriver( john );\n"
+" constraintViolations = validator.validate( car, DriverChecks."
+"class );\n"
+" assertEquals( 1, constraintViolations.size() );\n"
+" assertEquals( \"You first have to pass the driving test\", "
+"constraintViolations.iterator().next().getMessage() );\n"
+"\n"
+" // ok, John passes the test\n"
+" john.passedDrivingTest( true );\n"
+" assertEquals( 0, validator.validate( car, DriverChecks.class ).size"
+"() );\n"
+"\n"
+" // just checking that everything is in order now\n"
+" assertEquals( 0, validator.validate( car, Default.class, CarChecks."
+"class, DriverChecks.class ).size() );\n"
+" }\n"
+"}"
+msgstr ""
+
+#. Tag: para
+#: usingvalidator.xml:588
+#, no-c-format
+msgid ""
+"First we create a car and validate it using no explicit group. There are no "
+"validation errors, even though the property "
+"<property>passedVehicleInspection</property> is per default <constant>false</"
+"constant>. However, the constraint defined on this property does not belong "
+"to the default group. Next we just validate the <classname>CarChecks</"
+"classname> group which will fail until we make sure that the car passes the "
+"vehicle inspection. When we then add a driver to the car and validate "
+"against <classname>DriverChecks</classname> we get again a constraint "
+"violation due to the fact that the driver has not yet passed the driving "
+"test. Only after setting <property>passedDrivingTest</property> to true the "
+"validation against <classname>DriverChecks</classname> will pass."
+msgstr ""
+
+#. Tag: para
+#: usingvalidator.xml:601
+#, no-c-format
+msgid ""
+"Last but not least, we show that all constraints are passing by validating "
+"against all defined groups."
+msgstr ""
+
+#. Tag: title
+#: usingvalidator.xml:605
+#, no-c-format
+msgid "Group sequences"
+msgstr ""
+
+#. Tag: para
+#: usingvalidator.xml:607
+#, no-c-format
+msgid ""
+"By default, constraints are evaluated in no particular order and this "
+"regardless of which groups they belong to. In some situations, however, it "
+"is useful to control the order of the constraints evaluation. In our example "
+"from <xref linkend=\"validator-usingvalidator-validationgroups\"/> we could "
+"for example require that first all default car constraints are passing "
+"before we check the road worthiness of the car. Finally before we drive away "
+"we check the actual driver constraints. In order to implement such an order "
+"one would define a new interface and annotate it with "
+"<classname>@GroupSequence</classname> defining the order in which the groups "
+"have to be validated."
+msgstr ""
+
+#. Tag: para
+#: usingvalidator.xml:620
+#, no-c-format
+msgid ""
+"If at least one constraints fails in a sequenced group none of the "
+"constraints of the following groups in the sequence get validated."
+msgstr ""
+
+#. Tag: title
+#: usingvalidator.xml:626
+#, no-c-format
+msgid "Interface with @GroupSequence"
+msgstr ""
+
+#. Tag: programlisting
+#: usingvalidator.xml:628
+#, no-c-format
+msgid ""
+"@GroupSequence({Default.class, CarChecks.class, DriverChecks.class})\n"
+"public interface OrderedChecks {\n"
+"}"
+msgstr ""
+
+#. Tag: para
+#: usingvalidator.xml:632
+#, no-c-format
+msgid ""
+"Groups defining a sequence and groups composing a sequence must not be "
+"involved in a cyclic dependency either directly or indirectly, either "
+"through cascaded sequence definition or group inheritance. If a group "
+"containing such a circularity is evaluated, a "
+"<classname>GroupDefinitionException</classname> is raised."
+msgstr ""
+
+#. Tag: para
+#: usingvalidator.xml:636
+#, no-c-format
+msgid ""
+"The usage of the new sequence could then look like in <xref linkend="
+"\"example-group-sequence\"/>."
+msgstr ""
+
+#. Tag: title
+#: usingvalidator.xml:641
+#, no-c-format
+msgid "Usage of a group sequence"
+msgstr ""
+
+#. Tag: programlisting
+#: usingvalidator.xml:643
+#, no-c-format
+msgid ""
+"@Test\n"
+"public void testOrderedChecks() {\n"
+" Car car = new Car( \"Morris\", \"DD-AB-123\", 2 );\n"
+" car.setPassedVehicleInspection( true );\n"
+"\n"
+" Driver john = new Driver( \"John Doe\" );\n"
+" john.setAge( 18 );\n"
+" john.passedDrivingTest( true );\n"
+" car.setDriver( john );\n"
+"\n"
+" assertEquals( 0, validator.validate( car, OrderedChecks.class ).size"
+"() );\n"
+"}"
+msgstr ""
+
+#. Tag: title
+#: usingvalidator.xml:648
+#, no-c-format
+msgid "Redefining the default group sequence of a class"
+msgstr ""
+
+#. Tag: para
+#: usingvalidator.xml:650
+#, no-c-format
+msgid ""
+"The @GroupSequence annotation also fulfills a second purpose. It allows you "
+"to redefine what the Default group means for a given class. To redefine "
+"<classname>Default</classname> for a class, place a "
+"<classname>@GroupSequence</classname> annotation on the class. The defined "
+"groups in the annotation express the sequence of groups that substitute "
+"<classname>Default</classname> for this class. <xref linkend=\"example-"
+"rental-car\"/> introduces a new class RentalCar with a redfined default "
+"group. With this definition the check for all three groups can be rewritten "
+"as seen in <xref linkend=\"example-testOrderedChecksWithRedefinedDefault\"/>."
+msgstr ""
+
+#. Tag: title
+#: usingvalidator.xml:662
+#, no-c-format
+msgid "RentalCar"
+msgstr ""
+
+#. Tag: programlisting
+#: usingvalidator.xml:664
+#, no-c-format
+msgid ""
+"@GroupSequence({ RentalCar.class, CarChecks.class })\n"
+"public class RentalCar extends Car {\n"
+" public RentalCar(String manufacturer, String licencePlate, int "
+"seatCount) {\n"
+" super( manufacturer, licencePlate, seatCount );\n"
+" }\n"
+"}"
+msgstr ""
+
+#. Tag: title
+#: usingvalidator.xml:668
+#, no-c-format
+msgid "testOrderedChecksWithRedefinedDefault"
+msgstr ""
+
+#. Tag: programlisting
+#: usingvalidator.xml:670
+#, no-c-format
+msgid ""
+"@Test\n"
+"public void testOrderedChecksWithRedefinedDefault() {\n"
+" RentalCar rentalCar = new RentalCar( \"Morris\", \"DD-AB-123\", 2 );\n"
+" rentalCar.setPassedVehicleInspection( true );\n"
+"\n"
+" Driver john = new Driver( \"John Doe\" );\n"
+" john.setAge( 18 );\n"
+" john.passedDrivingTest( true );\n"
+" rentalCar.setDriver( john );\n"
+"\n"
+" assertEquals( 0, validator.validate( rentalCar, Default.class, "
+"DriverChecks.class ).size() );\n"
+"}"
+msgstr ""
+
+#. Tag: para
+#: usingvalidator.xml:674
+#, no-c-format
+msgid ""
+"Due to the fact that there cannot be a cyclic dependency in the group and "
+"group sequence definitions one cannot just add <classname>Default</"
+"classname> to the sequence redefining <classname>Default</classname> for a "
+"class. Instead the class itself should be added!"
+msgstr ""
+
+#. Tag: title
+#: usingvalidator.xml:684 usingvalidator.xml:692
+#, no-c-format
+msgid "Built-in constraints"
+msgstr ""
+
+#. Tag: para
+#: usingvalidator.xml:686
+#, no-c-format
+msgid ""
+"Hibernate Validator implements all of the default constraints specified in "
+"Bean Validation as well as some custom ones. <xref linkend=\"table-builtin-"
+"constraints\"/> list all constraints available in Hibernate Validator."
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:699
+#, no-c-format
+msgid "Annotation"
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:701
+#, no-c-format
+msgid "Part of Bean Validation Specification"
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:703
+#, no-c-format
+msgid "Apply on"
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:705
+#, no-c-format
+msgid "<entry>Use</entry>"
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:707
+#, no-c-format
+msgid "Hibernate Metadata impact"
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:713
+#, no-c-format
+msgid "@AssertFalse"
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:715 usingvalidator.xml:728 usingvalidator.xml:758
+#: usingvalidator.xml:778 usingvalidator.xml:798 usingvalidator.xml:830
+#: usingvalidator.xml:858 usingvalidator.xml:876 usingvalidator.xml:894
+#: usingvalidator.xml:936 usingvalidator.xml:949 usingvalidator.xml:963
+#: usingvalidator.xml:995 usingvalidator.xml:1049
+#, no-c-format
+msgid "<entry>yes</entry>"
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:717 usingvalidator.xml:730 usingvalidator.xml:896
+#: usingvalidator.xml:909 usingvalidator.xml:938
+#, no-c-format
+msgid "field/property"
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:719
+#, no-c-format
+msgid "Check that the annotated element is <constant>false</constant>."
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:722 usingvalidator.xml:735 usingvalidator.xml:752
+#: usingvalidator.xml:772 usingvalidator.xml:792 usingvalidator.xml:824
+#: usingvalidator.xml:838 usingvalidator.xml:916 usingvalidator.xml:930
+#: usingvalidator.xml:943 usingvalidator.xml:957 usingvalidator.xml:971
+#: usingvalidator.xml:989 usingvalidator.xml:1026 usingvalidator.xml:1043
+#: usingvalidator.xml:1059
+#, no-c-format
+msgid "none"
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:726
+#, no-c-format
+msgid "@AssertTrue"
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:732
+#, no-c-format
+msgid "Check that the annotated element is <constant>true</constant>."
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:739
+#, no-c-format
+msgid "@CreditCardNumber"
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:741 usingvalidator.xml:817 usingvalidator.xml:844
+#: usingvalidator.xml:907 usingvalidator.xml:922 usingvalidator.xml:977
+#: usingvalidator.xml:1011 usingvalidator.xml:1032
+#, no-c-format
+msgid "<entry>no</entry>"
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:743 usingvalidator.xml:1034
+#, no-c-format
+msgid "field/property. The supported type is <classname>String</classname>."
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:746
+#, no-c-format
+msgid ""
+"Check that the annotated string passes the Luhn checksum test. Note, this "
+"validation aims to check for user mistake, not credit card validity! See "
+"also <ulink url=\"http://www.merriampark.com/anatomycc.htm\">Anatomy of "
+"Credit Card Numbers</ulink>."
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:756
+#, no-c-format
+msgid "@DecimalMax"
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:760 usingvalidator.xml:780 usingvalidator.xml:800
+#: usingvalidator.xml:860 usingvalidator.xml:878 usingvalidator.xml:979
+#, no-c-format
+msgid ""
+"field/property. Supported types are <classname>BigDecimal</classname>, "
+"<classname>BigInteger</classname>, <classname>String</classname>, "
+"<classname>byte</classname>, <classname>short</classname>, <classname>int</"
+"classname>, <classname>long</classname> and the respective wrappers of the "
+"primitive types."
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:767
+#, no-c-format
+msgid ""
+"The annotated element must be a number whose value must be lower or equal to "
+"the specified maximum. The parameter value is the string representation of "
+"the max value according to the <classname>BigDecimal</classname> string "
+"representation."
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:776
+#, no-c-format
+msgid "@DecimalMin"
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:787
+#, no-c-format
+msgid ""
+"The annotated element must be a number whose value must be higher or equal "
+"to the specified minimum. The parameter value is the string representation "
+"of the min value according to the <classname>BigDecimal</classname> string "
+"representation."
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:796
+#, no-c-format
+msgid "@Digits(integer=, fraction=)"
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:807
+#, no-c-format
+msgid ""
+"Check whether the property is a number having up to <literal>integer</"
+"literal> digits and <literal>fraction</literal> fractional digits."
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:811
+#, no-c-format
+msgid "Define column precision and scale."
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:815
+#, no-c-format
+msgid "@Email"
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:819 usingvalidator.xml:846 usingvalidator.xml:965
+#, no-c-format
+msgid "field/property. Needs to be a string."
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:821
+#, no-c-format
+msgid "Check whether the specified string is a valid email address."
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:828
+#, no-c-format
+msgid "@Future"
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:832 usingvalidator.xml:951
+#, no-c-format
+msgid ""
+"field/property. Supported types are <classname>java.util.Date</classname> "
+"and <classname>java.util.Calendar</classname>."
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:836
+#, no-c-format
+msgid "Checks whether the annotated date is in the future."
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:842
+#, no-c-format
+msgid "@Length(min=, max=)"
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:848
+#, no-c-format
+msgid ""
+"Validate that the annotated string is between <parameter>min</parameter> and "
+"<parameter>max</parameter> included."
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:852 usingvalidator.xml:1005
+#, no-c-format
+msgid "Column length will be set to max."
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:856
+#, no-c-format
+msgid "@Max"
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:867
+#, no-c-format
+msgid ""
+"Checks whether the annotated value is less than or equal to the specified "
+"maximum."
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:870 usingvalidator.xml:888
+#, no-c-format
+msgid "Add a check constraint on the column."
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:874
+#, no-c-format
+msgid "@Min"
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:885
+#, no-c-format
+msgid ""
+"Checks whether the annotated value is higher than or equal to the specified "
+"minimum."
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:892
+#, no-c-format
+msgid "@NotNull"
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:898
+#, no-c-format
+msgid "Check that the annotated value is not <constant>null.</constant>"
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:901
+#, no-c-format
+msgid "Column(s) are not null."
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:905
+#, no-c-format
+msgid "@NotBlank"
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:911
+#, no-c-format
+msgid ""
+"Check that the annotated string is not null and the trimmed length is "
+"greater than 0. The difference to @NotEmpty is that this constraint can only "
+"be applied on strings and that trailing whitespaces are ignored."
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:920
+#, no-c-format
+msgid "@NotEmpty"
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:924
+#, no-c-format
+msgid "field/property. Supported types are String, Collection, Map and arrays."
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:927
+#, no-c-format
+msgid ""
+"Check whether the annotated element is not <constant>null</constant> nor "
+"empty."
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:934
+#, no-c-format
+msgid "@Null"
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:940
+#, no-c-format
+msgid "Check that the annotated value is <constant>null.</constant>"
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:947
+#, no-c-format
+msgid "@Past"
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:955
+#, no-c-format
+msgid "Checks whether the annotated date is in the past."
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:961
+#, no-c-format
+msgid "@Pattern(regex=, flag=)"
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:967
+#, no-c-format
+msgid ""
+"Checks if the annotated string matches the regular expression "
+"<parameter>regex</parameter> considering the given flag <parameter>match</"
+"parameter>."
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:975
+#, no-c-format
+msgid "@Range(min=, max=)"
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:986
+#, no-c-format
+msgid ""
+"Check whether the annotated value lies between (inclusive) the specified "
+"minimum and maximum."
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:993
+#, no-c-format
+msgid "@Size(min=, max=)"
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:997
+#, no-c-format
+msgid ""
+"field/property. Supported types are <classname>String</classname>, "
+"<classname>Collection</classname>, <classname>Map</classname> and "
+"<classname>arrays</classname>."
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:1002
+#, no-c-format
+msgid "Check if the annotated element size is between min and max (inclusive)."
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:1009
+#, no-c-format
+msgid "@ScriptAssert(lang=, script=, alias=)"
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:1013
+#, no-c-format
+msgid "type"
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:1015
+#, no-c-format
+msgid ""
+"Checks whether the given script can successfully be evaluated against the "
+"annotated element. In order to use this constraint, an implementation of the "
+"Java Scripting API as defined by JSR 223 (\"Scripting for the "
+"Java<superscript>TM</superscript> Platform\") must part of the class path. "
+"This is automatically the case when running on Java 6. For older Java "
+"versions, the JSR 223 RI can be added manually to the class path.The "
+"expressions to be evaluated can be written in any scripting or expression "
+"language, for which a JSR 223 compatible engine can be found in the class "
+"path."
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:1030
+#, no-c-format
+msgid "@URL(protocol=, host=, port=)"
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:1037
+#, no-c-format
+msgid ""
+"Check if the annotated string is a valid URL. If any of parameters "
+"<parameter>protocol</parameter>, <parameter>host</parameter> or "
+"<parameter>port</parameter> is specified the URL must match the specified "
+"values in the according part."
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:1047
+#, no-c-format
+msgid "@Valid"
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:1051
+#, no-c-format
+msgid "field/property. Any non-primitive types are supported."
+msgstr ""
+
+#. Tag: entry
+#: usingvalidator.xml:1054
+#, no-c-format
+msgid ""
+"Performs validation recursively on the associated object. If the object is a "
+"collection or an array, the elements are validated recursively. If the "
+"object is a map, the value elements are validated recursively."
+msgstr ""
+
+#. Tag: para
+#: usingvalidator.xml:1066
+#, no-c-format
+msgid ""
+"On top of the parameters indicated in <xref linkend=\"table-builtin-"
+"constraints\"/> each constraint supports the parameters <parameter>message</"
+"parameter>, <parameter>groups</parameter> and <parameter>payload</"
+"parameter>. This is a requirement of the Bean Validation specification."
+msgstr ""
+
+#. Tag: para
+#: usingvalidator.xml:1073
+#, no-c-format
+msgid ""
+"In some cases these built-in constraints will not fulfill your requirements. "
+"In this case you can literally in a minute write your own constraints. We "
+"will discuss this in"
+msgstr ""
Added: validator/trunk/hibernate-validator/src/main/docbook/zh-CN/modules/xmlconfiguration.po
===================================================================
--- validator/trunk/hibernate-validator/src/main/docbook/zh-CN/modules/xmlconfiguration.po (rev 0)
+++ validator/trunk/hibernate-validator/src/main/docbook/zh-CN/modules/xmlconfiguration.po 2010-07-06 15:18:26 UTC (rev 19904)
@@ -0,0 +1,283 @@
+# Language zh-CN translations for PACKAGE package.
+# Automatically generated, 2010.
+#
+msgid ""
+msgstr ""
+"Project-Id-Version: PACKAGE VERSION\n"
+"Report-Msgid-Bugs-To: http://bugs.kde.org\n"
+"POT-Creation-Date: 2010-07-06 14:46+0000\n"
+"PO-Revision-Date: 2010-07-06 14:46+0000\n"
+"Last-Translator: Automatically generated\n"
+"Language-Team: none\n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+
+#. Tag: title
+#: xmlconfiguration.xml:25
+#, no-c-format
+msgid "XML configuration"
+msgstr ""
+
+#. Tag: filename
+#: xmlconfiguration.xml:28
+#, no-c-format
+msgid "<filename>validation.xml</filename>"
+msgstr ""
+
+#. Tag: para
+#: xmlconfiguration.xml:30
+#, no-c-format
+msgid ""
+"The key to enable XML configuration for Hibernate Validator is the file "
+"<filename>validation.xml</filename>. If this file exists in the classpath "
+"its configuration will be applied when the <classname>ValidationFactory</"
+"classname> gets created. <xref linkend=\"image-validation-configuration\"/> "
+"shows a model view of the xsd <filename>valiation.xml</filename> has to "
+"adhere to."
+msgstr ""
+
+#. Tag: title
+#: xmlconfiguration.xml:37
+#, no-c-format
+msgid "validation-configuration-1.0.xsd"
+msgstr ""
+
+#. Tag: para
+#: xmlconfiguration.xml:52
+#, no-c-format
+msgid ""
+"shows the several configuration options of <filename>validation.xml</"
+"filename>."
+msgstr ""
+
+#. Tag: title
+#: xmlconfiguration.xml:56
+#, no-c-format
+msgid "<title>validation.xml</title>"
+msgstr ""
+
+#. Tag: programlisting
+#: xmlconfiguration.xml:58
+#, no-c-format
+msgid ""
+"<validation-config xmlns=\"http://jboss.org/xml/ns/javax/validation/"
+"configuration\"\n"
+" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"
+" xsi:schemaLocation=\"http://jboss.org/xml/ns/javax/validation/configuration"
+"\">\n"
+" <default-provider>org.hibernate.validator.HibernateValidator</"
+"default-provider>\n"
+" <message-interpolator>org.hibernate.validator.engine."
+"ResourceBundleMessageInterpolator</message-interpolator>\n"
+" <traversable-resolver>org.hibernate.validator.engine.resolver."
+"DefaultTraversableResolver</traversable-resolver>\n"
+" <constraint-validator-factory>org.hibernate.validator.engine."
+"ConstraintValidatorFactoryImpl</constraint-validator-factory>\n"
+" <constraint-mapping>/constraints-car.xml</constraint-"
+"mapping>\n"
+" <property name=\"prop1\">value1</property>\n"
+" <property name=\"prop2\">value2</property>\n"
+"</validation-config>"
+msgstr ""
+
+#. Tag: para
+#: xmlconfiguration.xml:62
+#, no-c-format
+msgid ""
+"There can only be one <filename>validation.xml</filename> in the classpath. "
+"If more than one is found an exception is thrown."
+msgstr ""
+
+#. Tag: para
+#: xmlconfiguration.xml:66
+#, no-c-format
+msgid ""
+"All settings shown in the <filename>validation.xml</filename> are optional "
+"and in the case of <xref linkend=\"example-validation-xml\"/> show the "
+"defaults used within Hibernate Validator. The node <property>default-"
+"provider</property> allows to choose the Bean Validation provider. This is "
+"useful if there is more than one provider in the classpath. "
+"<property>message-interpolator</property>, <property>traversable-resolver</"
+"property> and <property>constraint-validator-factory</property> allow to "
+"customize the <classname>javax.validation.MessageInterpolator</classname>, "
+"<classname>javax.validation.TraversableResolver</classname> resp. "
+"<classname>javax.validation.ConstraintValidatorFactory</classname>. The same "
+"configuration options are also available programmatically through the "
+"<classname>javax.validation.Configuration</classname>. In fact XML "
+"configuration will be overridden by values explicitly specified via the API. "
+"It is even possible to ignore the XML configuration completely via "
+"<methodname> Configuration.ignoreXmlConfiguration()</methodname>. See also "
+"<xref linkend=\"validator-bootstrapping\"/>."
+msgstr ""
+
+#. Tag: para
+#: xmlconfiguration.xml:84
+#, no-c-format
+msgid ""
+"Via the <property>constraint-mapping</property> you can list an arbitrary "
+"number of additional XML files containing the actual constraint "
+"configuration. See <xref linkend=\"section-mapping-constraints\"/>."
+msgstr ""
+
+#. Tag: para
+#: xmlconfiguration.xml:88
+#, no-c-format
+msgid ""
+"Last but not least, you can specify provider specific properties via the "
+"<property>property</property> nodes. Hibernate Validator does currently not "
+"make use of any custom properties."
+msgstr ""
+
+#. Tag: title
+#: xmlconfiguration.xml:94
+#, no-c-format
+msgid "Mapping constraints"
+msgstr ""
+
+#. Tag: para
+#: xmlconfiguration.xml:96
+#, no-c-format
+msgid ""
+"Expressing constraints in XML is possible via files adhering to the xsd seen "
+"in <xref linkend=\"image-mapping-configuration\"/>. Note that these mapping "
+"files are only processed if listed via <property>constraint-mapping</"
+"property> in your <filename>validation.xml</filename>."
+msgstr ""
+
+#. Tag: title
+#: xmlconfiguration.xml:103
+#, no-c-format
+msgid "validation-mapping-1.0.xsd"
+msgstr ""
+
+#. Tag: para
+#: xmlconfiguration.xml:118
+#, no-c-format
+msgid ""
+"shows how our classes Car and RentalCar from <xref linkend=\"example-car\"/> "
+"resp. <xref linkend=\"example-rental-car\"/> could be mapped in XML."
+msgstr ""
+
+#. Tag: title
+#: xmlconfiguration.xml:123
+#, no-c-format
+msgid "constraints-car.xml"
+msgstr ""
+
+#. Tag: programlisting
+#: xmlconfiguration.xml:125
+#, no-c-format
+msgid ""
+"<constraint-mappings xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance"
+"\"\n"
+" xsi:schemaLocation=\"http://jboss.org/xml/ns/javax/"
+"validation/mapping validation-mapping-1.0.xsd\"\n"
+" xmlns=\"http://jboss.org/xml/ns/javax/validation/mapping"
+"\">\n"
+" <default-package>org.hibernate.validator.quickstart</default-"
+"package>\n"
+" <bean class=\"Car\" ignore-annotations=\"true\">\n"
+" <field name=\"manufacturer\">\n"
+" <constraint annotation=\"javax.validation.constraints.NotNull"
+"\"/>\n"
+" </field>\n"
+" <field name=\"licensePlate\">\n"
+" <constraint annotation=\"javax.validation.constraints.NotNull"
+"\"/>\n"
+" </field>\n"
+" <field name=\"seatCount\">\n"
+" <constraint annotation=\"javax.validation.constraints.Min"
+"\">\n"
+" <element name=\"value\">2</element>\n"
+" </constraint>\n"
+" </field>\n"
+" <field name=\"driver\">\n"
+" <valid/>\n"
+" </field>\n"
+" <getter name=\"passedVehicleInspection\" ignore-annotations=\"true"
+"\">\n"
+" <constraint annotation=\"javax.validation.constraints."
+"AssertTrue\">\n"
+" <message>The car has to pass the vehicle inspection "
+"first</message>\n"
+" <groups>\n"
+" <value>CarChecks</value>\n"
+" </groups>\n"
+" <element name=\"max\">10</element>\n"
+" </constraint>\n"
+" </getter>\n"
+" </bean>\n"
+" <bean class=\"RentalCar\" ignore-annotations=\"true\">\n"
+" <class ignore-annotations=\"true\">\n"
+" <group-sequence>\n"
+" <value>RentalCar</value>\n"
+" <value>CarChecks</value>\n"
+" </group-sequence>\n"
+" </class>\n"
+" </bean>\n"
+" <constraint-definition annotation=\"org.mycompany.CheckCase\" include-"
+"existing-validator=\"false\">\n"
+" <validated-by include-existing-validators=\"false\">\n"
+" <value>org.mycompany.CheckCaseValidator</value>\n"
+" </validated-by>\n"
+" </constraint-definition>\n"
+"</constraint-mappings>"
+msgstr ""
+
+#. Tag: para
+#: xmlconfiguration.xml:128
+#, no-c-format
+msgid ""
+"The XML configuration is closely mirroring the programmatic API. For this "
+"reason it should suffice to just add some comments. <property>default-"
+"package</property> is used for all fields where a classname is expected. If "
+"the specified class is not fully qualified the configured default package "
+"will be used. Every mapping file can then have several <property>bean</"
+"property> nodes, each describing the constraints on the entity with the "
+"specified class name.<warning> <para>A given entity can only be configured "
+"once across all configuration files. If the same class is configured more "
+"than once an exception is thrown.</para> </warning>Settings <property>ignore-"
+"annotations</property> to true means that constraint annotations placed on "
+"the configured bean are ignored. The default for this value is "
+"<constant>true</constant>. ignore-annotations is also available for the "
+"nodes <property>class</property>, <property>fields</property> and "
+"<property>getter</property>. If not explicitly specified on these levels the "
+"configured <property>bean</property> value applies. Otherwise do the nodes "
+"<property>class</property>, <property>fields</property> and "
+"<property>getter</property> determine on which level the constraints are "
+"placed (see <xref linkend=\"validator-usingvalidator-annotate\"/>). The "
+"<property>constraint</property> node is then used to add a constraint on the "
+"corresponding level. Each constraint definition must define the class via "
+"the annotation attribute. The constraint attributes required by the Bean "
+"Validation specification (<property>message</property>, <property>groups</"
+"property> and <property>payload</property>) have dedicated nodes. All other "
+"constraint specific attributes are configured using the the "
+"<property>element</property> node."
+msgstr ""
+
+#. Tag: para
+#: xmlconfiguration.xml:156
+#, no-c-format
+msgid ""
+"The class node also allows to reconfigure the default group sequence (see "
+"<xref linkend=\"section-default-group-class\"/>) via the <property>group-"
+"sequence</property> node."
+msgstr ""
+
+#. Tag: para
+#: xmlconfiguration.xml:160
+#, no-c-format
+msgid ""
+"Last but not least, the list of <classname>ConstraintValidator</classname>s "
+"associated to a given constraint can be altered via the <property>constraint-"
+"definition</property> node. The <property>annotation</property> attribute "
+"represents the constraint annotation being altered. The <property>validated-"
+"by</property> elements represent the (ordered) list of "
+"<classname>ConstraintValidator</classname> implementations associated to the "
+"constraint. If <property>include-existing-validator</property> is set to "
+"<constant>false</constant>, validators defined on the constraint annotation "
+"are ignored. If set to <constant>true</constant>, the list of "
+"ConstraintValidators described in XML are concatenated to the list of "
+"validators described on the annotation."
+msgstr ""
14 years, 7 months
Hibernate SVN: r19902 - in core/branches/Branch_3_5/envers/src: main/java/org/hibernate/envers/configuration/metadata and 25 other directories.
by hibernate-commits@lists.jboss.org
Author: adamw
Date: 2010-07-06 02:31:40 -0400 (Tue, 06 Jul 2010)
New Revision: 19902
Added:
core/branches/Branch_3_5/envers/src/test/java/org/hibernate/envers/test/AbstractSessionTest.java
core/branches/Branch_3_5/envers/src/test/java/org/hibernate/envers/test/entityNames/
core/branches/Branch_3_5/envers/src/test/java/org/hibernate/envers/test/entityNames/auditedEntity/
core/branches/Branch_3_5/envers/src/test/java/org/hibernate/envers/test/entityNames/auditedEntity/Person.java
core/branches/Branch_3_5/envers/src/test/java/org/hibernate/envers/test/entityNames/auditedEntity/ReadEntityWhtiEntityNameTest.java
core/branches/Branch_3_5/envers/src/test/java/org/hibernate/envers/test/entityNames/manyToManyAudited/
core/branches/Branch_3_5/envers/src/test/java/org/hibernate/envers/test/entityNames/manyToManyAudited/Car.java
core/branches/Branch_3_5/envers/src/test/java/org/hibernate/envers/test/entityNames/manyToManyAudited/Person.java
core/branches/Branch_3_5/envers/src/test/java/org/hibernate/envers/test/entityNames/manyToManyAudited/ReadEntityWithAuditedManyToManyTest.java
core/branches/Branch_3_5/envers/src/test/java/org/hibernate/envers/test/entityNames/oneToManyAudited/
core/branches/Branch_3_5/envers/src/test/java/org/hibernate/envers/test/entityNames/oneToManyAudited/Car.java
core/branches/Branch_3_5/envers/src/test/java/org/hibernate/envers/test/entityNames/oneToManyAudited/Person.java
core/branches/Branch_3_5/envers/src/test/java/org/hibernate/envers/test/entityNames/oneToManyAudited/ReadEntityWithAuditedCollectionTest.java
core/branches/Branch_3_5/envers/src/test/java/org/hibernate/envers/test/entityNames/oneToManyNotAudited/
core/branches/Branch_3_5/envers/src/test/java/org/hibernate/envers/test/entityNames/oneToManyNotAudited/Car.java
core/branches/Branch_3_5/envers/src/test/java/org/hibernate/envers/test/entityNames/oneToManyNotAudited/Person.java
core/branches/Branch_3_5/envers/src/test/java/org/hibernate/envers/test/entityNames/oneToManyNotAudited/ReadEntityWithAuditedCollectionTest.java
core/branches/Branch_3_5/envers/src/test/java/org/hibernate/envers/test/entityNames/singleAssociatedAudited/
core/branches/Branch_3_5/envers/src/test/java/org/hibernate/envers/test/entityNames/singleAssociatedAudited/Car.java
core/branches/Branch_3_5/envers/src/test/java/org/hibernate/envers/test/entityNames/singleAssociatedAudited/Person.java
core/branches/Branch_3_5/envers/src/test/java/org/hibernate/envers/test/entityNames/singleAssociatedAudited/ReadEntityAssociatedAuditedTest.java
core/branches/Branch_3_5/envers/src/test/java/org/hibernate/envers/test/entityNames/singleAssociatedNotAudited/
core/branches/Branch_3_5/envers/src/test/java/org/hibernate/envers/test/entityNames/singleAssociatedNotAudited/Car.java
core/branches/Branch_3_5/envers/src/test/java/org/hibernate/envers/test/entityNames/singleAssociatedNotAudited/Person.java
core/branches/Branch_3_5/envers/src/test/java/org/hibernate/envers/test/entityNames/singleAssociatedNotAudited/ReadEntityAssociatedNotAuditedTest.java
core/branches/Branch_3_5/envers/src/test/resources/hibernate.test.session-cfg.xml
core/branches/Branch_3_5/envers/src/test/resources/mappings/entityNames/
core/branches/Branch_3_5/envers/src/test/resources/mappings/entityNames/auditedEntity/
core/branches/Branch_3_5/envers/src/test/resources/mappings/entityNames/auditedEntity/mappings.hbm.xml
core/branches/Branch_3_5/envers/src/test/resources/mappings/entityNames/manyToManyAudited/
core/branches/Branch_3_5/envers/src/test/resources/mappings/entityNames/manyToManyAudited/mappings.hbm.xml
core/branches/Branch_3_5/envers/src/test/resources/mappings/entityNames/oneToManyAudited/
core/branches/Branch_3_5/envers/src/test/resources/mappings/entityNames/oneToManyAudited/mappings.hbm.xml
core/branches/Branch_3_5/envers/src/test/resources/mappings/entityNames/oneToManyNotAudited/
core/branches/Branch_3_5/envers/src/test/resources/mappings/entityNames/oneToManyNotAudited/mappings.hbm.xml
core/branches/Branch_3_5/envers/src/test/resources/mappings/entityNames/singleAssociatedAudited/
core/branches/Branch_3_5/envers/src/test/resources/mappings/entityNames/singleAssociatedAudited/mappings.hbm.xml
core/branches/Branch_3_5/envers/src/test/resources/mappings/entityNames/singleAssociatedNotAudited/
core/branches/Branch_3_5/envers/src/test/resources/mappings/entityNames/singleAssociatedNotAudited/mappings.hbm.xml
Modified:
core/branches/Branch_3_5/envers/src/main/java/org/hibernate/envers/AuditReader.java
core/branches/Branch_3_5/envers/src/main/java/org/hibernate/envers/configuration/metadata/AuditMetadataGenerator.java
core/branches/Branch_3_5/envers/src/main/java/org/hibernate/envers/configuration/metadata/CollectionMetadataGenerator.java
core/branches/Branch_3_5/envers/src/main/java/org/hibernate/envers/entities/EntityConfiguration.java
core/branches/Branch_3_5/envers/src/main/java/org/hibernate/envers/entities/EntityInstantiator.java
core/branches/Branch_3_5/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/OneToOneNotOwningMapper.java
core/branches/Branch_3_5/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/ToOneIdMapper.java
core/branches/Branch_3_5/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/lazy/ToOneDelegateSessionImplementor.java
core/branches/Branch_3_5/envers/src/main/java/org/hibernate/envers/event/AuditEventListener.java
core/branches/Branch_3_5/envers/src/main/java/org/hibernate/envers/query/AuditQueryCreator.java
core/branches/Branch_3_5/envers/src/main/java/org/hibernate/envers/query/impl/AbstractAuditQuery.java
core/branches/Branch_3_5/envers/src/main/java/org/hibernate/envers/query/impl/EntitiesAtRevisionQuery.java
core/branches/Branch_3_5/envers/src/main/java/org/hibernate/envers/query/impl/RevisionsOfEntityQuery.java
core/branches/Branch_3_5/envers/src/main/java/org/hibernate/envers/reader/AuditReaderImpl.java
core/branches/Branch_3_5/envers/src/main/java/org/hibernate/envers/tools/Tools.java
core/branches/Branch_3_5/envers/src/test/resources/testng.xml
Log:
HHH-4716:
- backporting the fix from trunk
- supporting entity name concept
Modified: core/branches/Branch_3_5/envers/src/main/java/org/hibernate/envers/AuditReader.java
===================================================================
--- core/branches/Branch_3_5/envers/src/main/java/org/hibernate/envers/AuditReader.java 2010-07-05 17:36:04 UTC (rev 19901)
+++ core/branches/Branch_3_5/envers/src/main/java/org/hibernate/envers/AuditReader.java 2010-07-06 06:31:40 UTC (rev 19902)
@@ -32,7 +32,7 @@
/**
* @author Adam Warski (adam at warski dot org)
- * @author Hernan Chanfreau
+ * @author Hern�n Chanfreau
*/
public interface AuditReader {
/**
@@ -49,6 +49,23 @@
*/
<T> T find(Class<T> cls, Object primaryKey, Number revision) throws
IllegalArgumentException, NotAuditedException, IllegalStateException;
+
+ /**
+ * Find an entity by primary key at the given revision with the specified entityName.
+ * @param cls Class of the entity.
+ * @param entityName EntityName to find.
+ * @param primaryKey Primary key of the entity.
+ * @param revision Revision in which to get the entity.
+ * @return The found entity instance at the given revision (its properties may be partially filled
+ * if not all properties are audited) or null, if an entity with that id didn't exist at that
+ * revision.
+ * @throws IllegalArgumentException If cls or primaryKey is null or revision is less or equal to 0.
+ * @throws NotAuditedException When entities of the given class are not audited.
+ * @throws IllegalStateException If the associated entity manager is closed.
+ */
+ <T> T find(Class<T> cls, String entityName, Object primaryKey,
+ Number revision) throws IllegalArgumentException,
+ NotAuditedException, IllegalStateException;
/**
* Get a list of revision numbers, at which an entity was modified.
@@ -62,6 +79,21 @@
*/
List<Number> getRevisions(Class<?> cls, Object primaryKey)
throws IllegalArgumentException, NotAuditedException, IllegalStateException;
+
+ /**
+ * Get a list of revision numbers, at which an entity was modified, looking by entityName.
+ * @param cls Class of the entity.
+ * @param entityName EntityName to find.
+ * @param primaryKey Primary key of the entity.
+ * @return A list of revision numbers, at which the entity was modified, sorted in ascending order (so older
+ * revisions come first).
+ * @throws NotAuditedException When entities of the given class are not audited.
+ * @throws IllegalArgumentException If cls or primaryKey is null.
+ * @throws IllegalStateException If the associated entity manager is closed.
+ */
+ List<Number> getRevisions(Class<?> cls, String entityName, Object primaryKey)
+ throws IllegalArgumentException, NotAuditedException,
+ IllegalStateException;
/**
* Get the date, at which a revision was created.
Modified: core/branches/Branch_3_5/envers/src/main/java/org/hibernate/envers/configuration/metadata/AuditMetadataGenerator.java
===================================================================
--- core/branches/Branch_3_5/envers/src/main/java/org/hibernate/envers/configuration/metadata/AuditMetadataGenerator.java 2010-07-05 17:36:04 UTC (rev 19901)
+++ core/branches/Branch_3_5/envers/src/main/java/org/hibernate/envers/configuration/metadata/AuditMetadataGenerator.java 2010-07-06 06:31:40 UTC (rev 19902)
@@ -53,6 +53,7 @@
* @author Adam Warski (adam at warski dot org)
* @author Sebastian Komander
* @author Tomasz Bech
+ * @author Hern�n Chanfreau
*/
public final class AuditMetadataGenerator {
private static final Logger log = LoggerFactory.getLogger(AuditMetadataGenerator.class);
@@ -353,7 +354,7 @@
ExtendedPropertyMapper propertyMapper = null;
String parentEntityName = null;
- EntityConfiguration entityCfg = new EntityConfiguration(entityName, idMapper, propertyMapper,
+ EntityConfiguration entityCfg = new EntityConfiguration(entityName, pc.getClassName(), idMapper, propertyMapper,
parentEntityName);
notAuditedEntitiesConfigurations.put(entityName, entityCfg);
return;
@@ -427,7 +428,7 @@
addJoins(pc, propertyMapper, auditingData, pc.getEntityName(), xmlMappingData, true);
// Storing the generated configuration
- EntityConfiguration entityCfg = new EntityConfiguration(auditEntityName, idMapper,
+ EntityConfiguration entityCfg = new EntityConfiguration(auditEntityName,pc.getClassName(), idMapper,
propertyMapper, parentEntityName);
entitiesConfigurations.put(pc.getEntityName(), entityCfg);
}
Modified: core/branches/Branch_3_5/envers/src/main/java/org/hibernate/envers/configuration/metadata/CollectionMetadataGenerator.java
===================================================================
--- core/branches/Branch_3_5/envers/src/main/java/org/hibernate/envers/configuration/metadata/CollectionMetadataGenerator.java 2010-07-05 17:36:04 UTC (rev 19901)
+++ core/branches/Branch_3_5/envers/src/main/java/org/hibernate/envers/configuration/metadata/CollectionMetadataGenerator.java 2010-07-06 06:31:40 UTC (rev 19902)
@@ -80,7 +80,7 @@
/**
* Generates metadata for a collection-valued property.
* @author Adam Warski (adam at warski dot org)
- * @author Hern�n Chanfreau
+ * @author Hern�n Chanfreau
*/
public final class CollectionMetadataGenerator {
private static final Logger log = LoggerFactory.getLogger(CollectionMetadataGenerator.class);
@@ -209,7 +209,7 @@
// The mapper will only be used to map from entity to map, so no need to provide other details
// when constructing the PropertyData.
new PropertyData(auditMappedBy, null, null, null),
- referencedEntityName, false);
+ referencingEntityName, false);
// Checking if there's an index defined. If so, adding a mapper for it.
if (propertyAuditingData.getPositionMappedBy() != null) {
Modified: core/branches/Branch_3_5/envers/src/main/java/org/hibernate/envers/entities/EntityConfiguration.java
===================================================================
--- core/branches/Branch_3_5/envers/src/main/java/org/hibernate/envers/entities/EntityConfiguration.java 2010-07-05 17:36:04 UTC (rev 19901)
+++ core/branches/Branch_3_5/envers/src/main/java/org/hibernate/envers/entities/EntityConfiguration.java 2010-07-06 06:31:40 UTC (rev 19902)
@@ -32,18 +32,22 @@
/**
* @author Adam Warski (adam at warski dot org)
+ * @author Hern�n Chanfreau
*/
public class EntityConfiguration {
private String versionsEntityName;
- private IdMappingData idMappingData;
+ /** Holds the className for instantiation the configured entity */
+ private String entityClassName;
+ private IdMappingData idMappingData;
private ExtendedPropertyMapper propertyMapper;
// Maps from property name
private Map<String, RelationDescription> relations;
private String parentEntityName;
- public EntityConfiguration(String versionsEntityName, IdMappingData idMappingData,
+ public EntityConfiguration(String versionsEntityName, String entityClassName, IdMappingData idMappingData,
ExtendedPropertyMapper propertyMapper, String parentEntityName) {
this.versionsEntityName = versionsEntityName;
+ this.entityClassName = entityClassName;
this.idMappingData = idMappingData;
this.propertyMapper = propertyMapper;
this.parentEntityName = parentEntityName;
@@ -113,4 +117,11 @@
Iterable<RelationDescription> getRelationsIterator() {
return relations.values();
}
+
+ /**
+ * @return the className for the configured entity
+ */
+ public String getEntityClassName() {
+ return entityClassName;
+ }
}
Modified: core/branches/Branch_3_5/envers/src/main/java/org/hibernate/envers/entities/EntityInstantiator.java
===================================================================
--- core/branches/Branch_3_5/envers/src/main/java/org/hibernate/envers/entities/EntityInstantiator.java 2010-07-05 17:36:04 UTC (rev 19901)
+++ core/branches/Branch_3_5/envers/src/main/java/org/hibernate/envers/entities/EntityInstantiator.java 2010-07-06 06:31:40 UTC (rev 19902)
@@ -36,6 +36,7 @@
/**
* @author Adam Warski (adam at warski dot org)
+ * @author Hern�n Chanfreau
*/
public class EntityInstantiator {
private final AuditConfiguration verCfg;
@@ -80,7 +81,13 @@
// If it is not in the cache, creating a new entity instance
Object ret;
try {
- Class<?> cls = ReflectionTools.loadClass(entityName);
+ EntityConfiguration entCfg = verCfg.getEntCfg().get(entityName);
+ if(entCfg == null) {
+ // a relation marked as RelationTargetAuditMode.NOT_AUDITED
+ entCfg = verCfg.getEntCfg().getNotVersionEntityConfiguration(entityName);
+ }
+
+ Class<?> cls = ReflectionTools.loadClass(entCfg.getEntityClassName());
ret = ReflectHelper.getDefaultConstructor(cls).newInstance();
} catch (Exception e) {
throw new AuditException(e);
Modified: core/branches/Branch_3_5/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/OneToOneNotOwningMapper.java
===================================================================
--- core/branches/Branch_3_5/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/OneToOneNotOwningMapper.java 2010-07-05 17:36:04 UTC (rev 19901)
+++ core/branches/Branch_3_5/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/OneToOneNotOwningMapper.java 2010-07-06 06:31:40 UTC (rev 19902)
@@ -31,6 +31,7 @@
import org.hibernate.envers.configuration.AuditConfiguration;
import org.hibernate.envers.entities.mapper.PersistentCollectionChangeData;
import org.hibernate.envers.entities.mapper.PropertyMapper;
+import org.hibernate.envers.entities.EntityConfiguration;
import org.hibernate.envers.entities.PropertyData;
import org.hibernate.envers.exception.AuditException;
import org.hibernate.envers.query.AuditEntity;
@@ -44,6 +45,7 @@
/**
* @author Adam Warski (adam at warski dot org)
+ * @author Hern�n Chanfreau
*/
public class OneToOneNotOwningMapper implements PropertyMapper {
private String owningReferencePropertyName;
@@ -66,12 +68,18 @@
return;
}
- Class<?> entityClass = ReflectionTools.loadClass(owningEntityName);
+ EntityConfiguration entCfg = verCfg.getEntCfg().get(owningEntityName);
+ if(entCfg == null) {
+ // a relation marked as RelationTargetAuditMode.NOT_AUDITED
+ entCfg = verCfg.getEntCfg().getNotVersionEntityConfiguration(owningEntityName);
+ }
+ Class<?> entityClass = ReflectionTools.loadClass(entCfg.getEntityClassName());
+
Object value;
try {
- value = versionsReader.createQuery().forEntitiesAtRevision(entityClass, revision)
+ value = versionsReader.createQuery().forEntitiesAtRevision(entityClass, owningEntityName, revision)
.add(AuditEntity.relatedId(owningReferencePropertyName).eq(primaryKey)).getSingleResult();
} catch (NoResultException e) {
value = null;
Modified: core/branches/Branch_3_5/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/ToOneIdMapper.java
===================================================================
--- core/branches/Branch_3_5/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/ToOneIdMapper.java 2010-07-05 17:36:04 UTC (rev 19901)
+++ core/branches/Branch_3_5/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/ToOneIdMapper.java 2010-07-06 06:31:40 UTC (rev 19902)
@@ -33,6 +33,7 @@
import org.hibernate.envers.entities.mapper.PropertyMapper;
import org.hibernate.envers.entities.mapper.id.IdMapper;
import org.hibernate.envers.entities.mapper.relation.lazy.ToOneDelegateSessionImplementor;
+import org.hibernate.envers.entities.EntityConfiguration;
import org.hibernate.envers.entities.PropertyData;
import org.hibernate.envers.reader.AuditReaderImplementor;
import org.hibernate.envers.tools.Tools;
@@ -44,6 +45,7 @@
/**
* @author Adam Warski (adam at warski dot org)
+ * @author Hern�n Chanfreau
*/
public class ToOneIdMapper implements PropertyMapper {
private final IdMapper delegate;
@@ -68,7 +70,7 @@
delegate.mapToMapFromEntity(newData, nonInsertableFake ? oldObj : newObj);
//noinspection SimplifiableConditionalExpression
- return nonInsertableFake ? false : !Tools.entitiesEqual(session, newObj, oldObj);
+ return nonInsertableFake ? false : !Tools.entitiesEqual(session, referencedEntityName, newObj, oldObj);
}
public void mapToEntityFromMap(AuditConfiguration verCfg, Object obj, Map data, Object primaryKey,
@@ -85,7 +87,13 @@
if (versionsReader.getFirstLevelCache().contains(referencedEntityName, revision, entityId)) {
value = versionsReader.getFirstLevelCache().get(referencedEntityName, revision, entityId);
} else {
- Class<?> entityClass = ReflectionTools.loadClass(referencedEntityName);
+ EntityConfiguration entCfg = verCfg.getEntCfg().get(referencedEntityName);
+ if(entCfg == null) {
+ // a relation marked as RelationTargetAuditMode.NOT_AUDITED
+ entCfg = verCfg.getEntCfg().getNotVersionEntityConfiguration(referencedEntityName);
+ }
+
+ Class<?> entityClass = ReflectionTools.loadClass(entCfg.getEntityClassName());
value = versionsReader.getSessionImplementor().getFactory().getEntityPersister(referencedEntityName).
createProxy((Serializable)entityId, new ToOneDelegateSessionImplementor(versionsReader, entityClass, entityId, revision, verCfg));
Modified: core/branches/Branch_3_5/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/lazy/ToOneDelegateSessionImplementor.java
===================================================================
--- core/branches/Branch_3_5/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/lazy/ToOneDelegateSessionImplementor.java 2010-07-05 17:36:04 UTC (rev 19901)
+++ core/branches/Branch_3_5/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/lazy/ToOneDelegateSessionImplementor.java 2010-07-06 06:31:40 UTC (rev 19902)
@@ -27,7 +27,6 @@
import org.hibernate.envers.configuration.AuditConfiguration;
import org.hibernate.envers.entities.EntitiesConfigurations;
-import org.hibernate.envers.entities.EntityConfiguration;
import org.hibernate.envers.reader.AuditReaderImplementor;
import org.hibernate.HibernateException;
@@ -35,6 +34,7 @@
/**
* @author Adam Warski (adam at warski dot org)
* @author Tomasz Bech
+ * @author Hern�n Chanfreau
*/
public class ToOneDelegateSessionImplementor extends AbstractDelegateSessionImplementor {
private static final long serialVersionUID = 4770438372940785488L;
@@ -43,7 +43,7 @@
private final Class<?> entityClass;
private final Object entityId;
private final Number revision;
- private EntityConfiguration notVersionedEntityConfiguration;
+ private EntitiesConfigurations entCfg;
public ToOneDelegateSessionImplementor(AuditReaderImplementor versionsReader,
Class<?> entityClass, Object entityId, Number revision,
@@ -53,14 +53,15 @@
this.entityClass = entityClass;
this.entityId = entityId;
this.revision = revision;
- EntitiesConfigurations entCfg = verCfg.getEntCfg();
- notVersionedEntityConfiguration = entCfg.getNotVersionEntityConfiguration(entityClass.getName());
+ this.entCfg = verCfg.getEntCfg();
}
public Object doImmediateLoad(String entityName) throws HibernateException {
- if (notVersionedEntityConfiguration == null) {
- return versionsReader.find(entityClass, entityId, revision);
+ if(entCfg.getNotVersionEntityConfiguration(entityName) == null){
+ // audited relation, look up entity with envers
+ return versionsReader.find(entityClass, entityName, entityId, revision);
} else {
+ // notAudited relation, look up entity with hibernate
return delegate.immediateLoad(entityName, (Serializable) entityId);
}
}
Modified: core/branches/Branch_3_5/envers/src/main/java/org/hibernate/envers/event/AuditEventListener.java
===================================================================
--- core/branches/Branch_3_5/envers/src/main/java/org/hibernate/envers/event/AuditEventListener.java 2010-07-05 17:36:04 UTC (rev 19901)
+++ core/branches/Branch_3_5/envers/src/main/java/org/hibernate/envers/event/AuditEventListener.java 2010-07-06 06:31:40 UTC (rev 19902)
@@ -61,6 +61,7 @@
/**
* @author Adam Warski (adam at warski dot org)
+ * @author Hern�n Chanfreau
*/
public class AuditEventListener implements PostInsertEventListener, PostUpdateEventListener,
PostDeleteEventListener, PreCollectionUpdateEventListener, PreCollectionRemoveEventListener,
@@ -91,7 +92,7 @@
Object oldValue = oldState == null ? null : oldState[i];
Object newValue = newState == null ? null : newState[i];
- if (!Tools.entitiesEqual(session, oldValue, newValue)) {
+ if (!Tools.entitiesEqual(session, relDesc.getToEntityName(), oldValue, newValue)) {
// We have to generate changes both in the old collection (size decreses) and new collection
// (size increases).
if (newValue != null) {
Modified: core/branches/Branch_3_5/envers/src/main/java/org/hibernate/envers/query/AuditQueryCreator.java
===================================================================
--- core/branches/Branch_3_5/envers/src/main/java/org/hibernate/envers/query/AuditQueryCreator.java 2010-07-05 17:36:04 UTC (rev 19901)
+++ core/branches/Branch_3_5/envers/src/main/java/org/hibernate/envers/query/AuditQueryCreator.java 2010-07-06 06:31:40 UTC (rev 19902)
@@ -32,6 +32,7 @@
/**
* @author Adam Warski (adam at warski dot org)
+ * @author Hern�n Chanfreau
*/
public class AuditQueryCreator {
private final AuditConfiguration auditCfg;
@@ -56,6 +57,22 @@
checkPositive(revision, "Entity revision");
return new EntitiesAtRevisionQuery(auditCfg, auditReaderImplementor, c, revision);
}
+
+ /**
+ * Creates a query, which will return entities satisfying some conditions (specified later),
+ * at a given revision and a given entityName.
+ * @param c Class of the entities for which to query.
+ * @param entityName EntityName of the entities for which to query.
+ * @param revision Revision number at which to execute the query.
+ * @return A query for entities at a given revision, to which conditions can be added and which
+ * can then be executed. The result of the query will be a list of entities (beans), unless a
+ * projection is added.
+ */
+ public AuditQuery forEntitiesAtRevision(Class<?> c, String entityName, Number revision) {
+ checkNotNull(revision, "Entity revision");
+ checkPositive(revision, "Entity revision");
+ return new EntitiesAtRevisionQuery(auditCfg, auditReaderImplementor, c, entityName, revision);
+ }
/**
* Creates a query, which selects the revisions, at which the given entity was modified.
@@ -80,4 +97,30 @@
public AuditQuery forRevisionsOfEntity(Class<?> c, boolean selectEntitiesOnly, boolean selectDeletedEntities) {
return new RevisionsOfEntityQuery(auditCfg, auditReaderImplementor, c, selectEntitiesOnly,selectDeletedEntities);
}
+
+ /**
+ * Creates a query, which selects the revisions, at which the given entity was modified and with a given entityName.
+ * Unless an explicit projection is set, the result will be a list of three-element arrays, containing:
+ * <ol>
+ * <li>the entity instance</li>
+ * <li>revision entity, corresponding to the revision at which the entity was modified. If no custom
+ * revision entity is used, this will be an instance of {@link org.hibernate.envers.DefaultRevisionEntity}</li>
+ * <li>type of the revision (an enum instance of class {@link org.hibernate.envers.RevisionType})</li>.
+ * </ol>
+ * Additional conditions that the results must satisfy may be specified.
+ * @param c Class of the entities for which to query.
+ * @param entityName EntityName of the entities for which to query.
+ * @param selectEntitiesOnly If true, instead of a list of three-element arrays, a list of entites will be
+ * returned as a result of executing this query.
+ * @param selectDeletedEntities If true, also revisions where entities were deleted will be returned. The additional
+ * entities will have revision type "delete", and contain no data (all fields null), except for the id field.
+ * @return A query for revisions at which instances of the given entity were modified, to which
+ * conditions can be added (for example - a specific id of an entity of class <code>c</code>), and which
+ * can then be executed. The results of the query will be sorted in ascending order by the revision number,
+ * unless an order or projection is added.
+ */
+ public AuditQuery forRevisionsOfEntity(Class<?> c, String entityName, boolean selectEntitiesOnly, boolean selectDeletedEntities) {
+ return new RevisionsOfEntityQuery(auditCfg, auditReaderImplementor, c, entityName, selectEntitiesOnly,selectDeletedEntities);
+ }
+
}
Modified: core/branches/Branch_3_5/envers/src/main/java/org/hibernate/envers/query/impl/AbstractAuditQuery.java
===================================================================
--- core/branches/Branch_3_5/envers/src/main/java/org/hibernate/envers/query/impl/AbstractAuditQuery.java 2010-07-05 17:36:04 UTC (rev 19901)
+++ core/branches/Branch_3_5/envers/src/main/java/org/hibernate/envers/query/impl/AbstractAuditQuery.java 2010-07-06 06:31:40 UTC (rev 19902)
@@ -50,12 +50,14 @@
/**
* @author Adam Warski (adam at warski dot org)
+ * @author Hern�n Chanfreau
*/
public abstract class AbstractAuditQuery implements AuditQuery {
protected EntityInstantiator entityInstantiator;
protected List<AuditCriterion> criterions;
protected String entityName;
+ protected String entityClassName;
protected String versionsEntityName;
protected QueryBuilder qb;
@@ -67,18 +69,25 @@
protected AbstractAuditQuery(AuditConfiguration verCfg, AuditReaderImplementor versionsReader,
Class<?> cls) {
- this.verCfg = verCfg;
- this.versionsReader = versionsReader;
+ this(verCfg, versionsReader, cls, cls.getName());
+ }
- criterions = new ArrayList<AuditCriterion>();
- entityInstantiator = new EntityInstantiator(verCfg, versionsReader);
+ protected AbstractAuditQuery(AuditConfiguration verCfg,
+ AuditReaderImplementor versionsReader, Class<?> cls, String entityName) {
+ this.verCfg = verCfg;
+ this.versionsReader = versionsReader;
- entityName = cls.getName();
- versionsEntityName = verCfg.getAuditEntCfg().getAuditEntityName(entityName);
+ criterions = new ArrayList<AuditCriterion>();
+ entityInstantiator = new EntityInstantiator(verCfg, versionsReader);
- qb = new QueryBuilder(versionsEntityName, "e");
- }
+ entityClassName = cls.getName();
+ this.entityName = entityName;
+ versionsEntityName = verCfg.getAuditEntCfg().getAuditEntityName(
+ entityName);
+ qb = new QueryBuilder(versionsEntityName, "e");
+ }
+
protected List buildAndExecuteQuery() {
StringBuilder querySb = new StringBuilder();
Map<String, Object> queryParamValues = new HashMap<String, Object>();
Modified: core/branches/Branch_3_5/envers/src/main/java/org/hibernate/envers/query/impl/EntitiesAtRevisionQuery.java
===================================================================
--- core/branches/Branch_3_5/envers/src/main/java/org/hibernate/envers/query/impl/EntitiesAtRevisionQuery.java 2010-07-05 17:36:04 UTC (rev 19901)
+++ core/branches/Branch_3_5/envers/src/main/java/org/hibernate/envers/query/impl/EntitiesAtRevisionQuery.java 2010-07-06 06:31:40 UTC (rev 19902)
@@ -35,6 +35,7 @@
/**
* @author Adam Warski (adam at warski dot org)
+ * @author Hern�n Chanfreau
*/
public class EntitiesAtRevisionQuery extends AbstractAuditQuery {
private final Number revision;
@@ -45,6 +46,12 @@
super(verCfg, versionsReader, cls);
this.revision = revision;
}
+
+ public EntitiesAtRevisionQuery(AuditConfiguration verCfg,
+ AuditReaderImplementor versionsReader, Class<?> cls, String entityName, Number revision) {
+ super(verCfg, versionsReader, cls, entityName);
+ this.revision = revision;
+ }
@SuppressWarnings({"unchecked"})
public List list() {
Modified: core/branches/Branch_3_5/envers/src/main/java/org/hibernate/envers/query/impl/RevisionsOfEntityQuery.java
===================================================================
--- core/branches/Branch_3_5/envers/src/main/java/org/hibernate/envers/query/impl/RevisionsOfEntityQuery.java 2010-07-05 17:36:04 UTC (rev 19901)
+++ core/branches/Branch_3_5/envers/src/main/java/org/hibernate/envers/query/impl/RevisionsOfEntityQuery.java 2010-07-06 06:31:40 UTC (rev 19902)
@@ -33,11 +33,11 @@
import org.hibernate.envers.exception.AuditException;
import org.hibernate.envers.query.criteria.AuditCriterion;
import org.hibernate.envers.reader.AuditReaderImplementor;
-
import org.hibernate.proxy.HibernateProxy;
/**
* @author Adam Warski (adam at warski dot org)
+ * @author Hern�n Chanfreau
*/
public class RevisionsOfEntityQuery extends AbstractAuditQuery {
private final boolean selectEntitiesOnly;
@@ -53,6 +53,15 @@
this.selectDeletedEntities = selectDeletedEntities;
}
+ public RevisionsOfEntityQuery(AuditConfiguration verCfg,
+ AuditReaderImplementor versionsReader, Class<?> cls, String entityName,
+ boolean selectEntitiesOnly, boolean selectDeletedEntities) {
+ super(verCfg, versionsReader, cls, entityName);
+
+ this.selectEntitiesOnly = selectEntitiesOnly;
+ this.selectDeletedEntities = selectDeletedEntities;
+ }
+
private Number getRevisionNumber(Map versionsEntity) {
AuditEntitiesConfiguration verEntCfg = verCfg.getAuditEntCfg();
Modified: core/branches/Branch_3_5/envers/src/main/java/org/hibernate/envers/reader/AuditReaderImpl.java
===================================================================
--- core/branches/Branch_3_5/envers/src/main/java/org/hibernate/envers/reader/AuditReaderImpl.java 2010-07-05 17:36:04 UTC (rev 19901)
+++ core/branches/Branch_3_5/envers/src/main/java/org/hibernate/envers/reader/AuditReaderImpl.java 2010-07-06 06:31:40 UTC (rev 19902)
@@ -46,7 +46,7 @@
/**
* @author Adam Warski (adam at warski dot org)
- * @author Hernan Chanfreau
+ * @author Hern�n Chanfreau
*/
public class AuditReaderImpl implements AuditReaderImplementor {
private final AuditConfiguration verCfg;
@@ -81,17 +81,22 @@
return firstLevelCache;
}
- @SuppressWarnings({"unchecked"})
public <T> T find(Class<T> cls, Object primaryKey, Number revision) throws
IllegalArgumentException, NotAuditedException, IllegalStateException {
+
+ return this.find(cls, cls.getName(), primaryKey, revision);
+ }
+
+ @SuppressWarnings({"unchecked"})
+ public <T> T find(Class<T> cls, String entityName, Object primaryKey, Number revision) throws
+ IllegalArgumentException, NotAuditedException, IllegalStateException {
checkNotNull(cls, "Entity class");
+ checkNotNull(entityName, "Entity name");
checkNotNull(primaryKey, "Primary key");
checkNotNull(revision, "Entity revision");
checkPositive(revision, "Entity revision");
checkSession();
- String entityName = cls.getName();
-
if (!verCfg.getEntCfg().isVersioned(entityName)) {
throw new NotAuditedException(entityName, entityName + " is not versioned!");
}
@@ -103,7 +108,7 @@
Object result;
try {
// The result is put into the cache by the entity instantiator called from the query
- result = createQuery().forEntitiesAtRevision(cls, revision)
+ result = createQuery().forEntitiesAtRevision(cls, entityName, revision)
.add(AuditEntity.id().eq(primaryKey)).getSingleResult();
} catch (NoResultException e) {
result = null;
@@ -112,23 +117,28 @@
}
return (T) result;
+ }
+
+ public List<Number> getRevisions(Class<?> cls, Object primaryKey)
+ throws IllegalArgumentException, NotAuditedException, IllegalStateException {
+
+ return this.getRevisions(cls, cls.getName(), primaryKey);
}
@SuppressWarnings({"unchecked"})
- public List<Number> getRevisions(Class<?> cls, Object primaryKey)
+ public List<Number> getRevisions(Class<?> cls, String entityName, Object primaryKey)
throws IllegalArgumentException, NotAuditedException, IllegalStateException {
// todo: if a class is not versioned from the beginning, there's a missing ADD rev - what then?
checkNotNull(cls, "Entity class");
+ checkNotNull(entityName, "Entity name");
checkNotNull(primaryKey, "Primary key");
checkSession();
- String entityName = cls.getName();
-
if (!verCfg.getEntCfg().isVersioned(entityName)) {
throw new NotAuditedException(entityName, entityName + " is not versioned!");
}
- return createQuery().forRevisionsOfEntity(cls, false, true)
+ return createQuery().forRevisionsOfEntity(cls, entityName, false, true)
.addProjection(AuditEntity.revisionNumber())
.add(AuditEntity.id().eq(primaryKey))
.getResultList();
Modified: core/branches/Branch_3_5/envers/src/main/java/org/hibernate/envers/tools/Tools.java
===================================================================
--- core/branches/Branch_3_5/envers/src/main/java/org/hibernate/envers/tools/Tools.java 2010-07-05 17:36:04 UTC (rev 19901)
+++ core/branches/Branch_3_5/envers/src/main/java/org/hibernate/envers/tools/Tools.java 2010-07-06 06:31:40 UTC (rev 19902)
@@ -32,6 +32,7 @@
/**
* @author Adam Warski (adam at warski dot org)
+ * @author Hern�n Chanfreau
*/
public class Tools {
public static <K,V> Map<K,V> newHashMap() {
@@ -46,14 +47,14 @@
return new LinkedHashMap<K,V>();
}
- public static boolean entitiesEqual(SessionImplementor session, Object obj1, Object obj2) {
- Object id1 = getIdentifier(session, obj1);
- Object id2 = getIdentifier(session, obj2);
+ public static boolean entitiesEqual(SessionImplementor session, String entityName, Object obj1, Object obj2) {
+ Object id1 = getIdentifier(session, entityName, obj1);
+ Object id2 = getIdentifier(session, entityName, obj2);
return objectsEqual(id1, id2);
- }
+ }
- public static Object getIdentifier(SessionImplementor session, Object obj) {
+ public static Object getIdentifier(SessionImplementor session, String entityName, Object obj) {
if (obj == null) {
return null;
}
@@ -63,9 +64,9 @@
return hibernateProxy.getHibernateLazyInitializer().getIdentifier();
}
+ return session.getEntityPersister(entityName, obj).getIdentifier(obj, session);
+ }
- return session.getEntityPersister( null, obj ).getIdentifier( obj, session );
- }
public static Object getTargetFromProxy(SessionFactoryImplementor sessionFactoryImplementor, HibernateProxy proxy) {
if (!proxy.getHibernateLazyInitializer().isUninitialized()) {
Added: core/branches/Branch_3_5/envers/src/test/java/org/hibernate/envers/test/AbstractSessionTest.java
===================================================================
--- core/branches/Branch_3_5/envers/src/test/java/org/hibernate/envers/test/AbstractSessionTest.java (rev 0)
+++ core/branches/Branch_3_5/envers/src/test/java/org/hibernate/envers/test/AbstractSessionTest.java 2010-07-06 06:31:40 UTC (rev 19902)
@@ -0,0 +1,79 @@
+package org.hibernate.envers.test;
+
+import java.io.File;
+import java.net.URISyntaxException;
+import java.net.URL;
+
+import org.hibernate.MappingException;
+import org.hibernate.Session;
+import org.hibernate.SessionFactory;
+import org.hibernate.cfg.AnnotationConfiguration;
+import org.hibernate.cfg.Configuration;
+import org.hibernate.envers.AuditReader;
+import org.hibernate.envers.AuditReaderFactory;
+import org.testng.annotations.AfterClass;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.BeforeMethod;
+
+/**
+ * Base class for testing envers with Session.
+ *
+ * @author Hern�n Chanfreau
+ *
+ */
+public abstract class AbstractSessionTest {
+
+ protected Configuration config;
+ private SessionFactory sessionFactory;
+ private Session session ;
+ private AuditReader auditReader;
+
+
+ @BeforeClass
+ public void init() {
+ config = new AnnotationConfiguration();
+ try {
+ URL url = Thread.currentThread().getContextClassLoader().getResource("hibernate.test.session-cfg.xml");
+ config.configure(new File(url.toURI()));
+ this.initMappings();
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ sessionFactory = config.buildSessionFactory();
+ }
+
+ protected abstract void initMappings() throws MappingException, URISyntaxException ;
+
+
+
+ private SessionFactory getSessionFactory(){
+ return sessionFactory;
+ }
+
+
+ @BeforeMethod
+ public void newSessionFactory() {
+ session = getSessionFactory().openSession();
+ auditReader = AuditReaderFactory.get(session);
+ }
+
+ @AfterClass
+ public void closeSessionFactory() {
+ sessionFactory.close();
+ }
+
+
+ protected Session getSession() {
+ return session;
+ }
+
+
+
+ protected AuditReader getAuditReader() {
+ return auditReader;
+ }
+
+}
+
Added: core/branches/Branch_3_5/envers/src/test/java/org/hibernate/envers/test/entityNames/auditedEntity/Person.java
===================================================================
--- core/branches/Branch_3_5/envers/src/test/java/org/hibernate/envers/test/entityNames/auditedEntity/Person.java (rev 0)
+++ core/branches/Branch_3_5/envers/src/test/java/org/hibernate/envers/test/entityNames/auditedEntity/Person.java 2010-07-06 06:31:40 UTC (rev 19902)
@@ -0,0 +1,51 @@
+package org.hibernate.envers.test.entityNames.auditedEntity;
+
+import org.hibernate.envers.Audited;
+
+/**
+ * @author Hern�n Chanfreau
+ *
+ */
+
+@Audited
+public class Person {
+
+ private long id;
+
+ private String name;
+
+ private int age;
+
+ public Person(){ }
+
+ public Person(String name, int age){
+ this.name = name;
+ this.age = age;
+ }
+
+
+ public long getId() {
+ return id;
+ }
+
+ public void setId(long id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public int getAge() {
+ return age;
+ }
+
+ public void setAge(int age) {
+ this.age = age;
+ }
+
+}
Added: core/branches/Branch_3_5/envers/src/test/java/org/hibernate/envers/test/entityNames/auditedEntity/ReadEntityWhtiEntityNameTest.java
===================================================================
--- core/branches/Branch_3_5/envers/src/test/java/org/hibernate/envers/test/entityNames/auditedEntity/ReadEntityWhtiEntityNameTest.java (rev 0)
+++ core/branches/Branch_3_5/envers/src/test/java/org/hibernate/envers/test/entityNames/auditedEntity/ReadEntityWhtiEntityNameTest.java 2010-07-06 06:31:40 UTC (rev 19902)
@@ -0,0 +1,99 @@
+package org.hibernate.envers.test.entityNames.auditedEntity;
+
+import java.io.File;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.List;
+
+import org.hibernate.MappingException;
+import org.hibernate.envers.test.AbstractSessionTest;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+/**
+ * @author Hern�n Chanfreau
+ *
+ */
+
+public class ReadEntityWhtiEntityNameTest extends AbstractSessionTest{
+
+ private long id_pers1;
+ private long id_pers2;
+ private long id_pers3;
+
+
+ protected void initMappings() throws MappingException, URISyntaxException {
+ URL url = Thread.currentThread().getContextClassLoader().getResource("mappings/entityNames/auditedEntity/mappings.hbm.xml");
+ config.addFile(new File(url.toURI()));
+ }
+
+
+ @BeforeClass(dependsOnMethods = "init")
+ public void initData() {
+
+ newSessionFactory();
+
+ Person pers1 = new Person("Hernan", 28);
+ Person pers2 = new Person("Leandro", 29);
+ Person pers3 = new Person("Barba", 30);
+
+ //REV 1
+ getSession().getTransaction().begin();
+ getSession().persist("Personaje",pers1);
+ id_pers1 = pers1.getId();
+ getSession().getTransaction().commit();
+
+ //REV 2
+ getSession().getTransaction().begin();
+ pers1 = (Person)getSession().get("Personaje", id_pers1);
+ pers1.setAge(29);
+ getSession().persist("Personaje",pers1);
+ getSession().persist("Personaje",pers2);
+ id_pers2 = pers2.getId();
+ getSession().getTransaction().commit();
+
+ //REV
+ getSession().getTransaction().begin();
+ pers1 = (Person)getSession().get("Personaje", id_pers1);
+ pers1.setName("Hernan David");
+ pers2 = (Person)getSession().get("Personaje", id_pers2);
+ pers2.setAge(30);
+ getSession().persist("Personaje",pers1);
+ getSession().persist("Personaje",pers2);
+ getSession().persist("Personaje",pers3);
+ id_pers3 = pers3.getId();
+ getSession().getTransaction().commit();
+
+ }
+
+
+ @Test
+ public void testRetrieveRevisionsWithEntityName() {
+ List<Number> pers1Revs = getAuditReader().getRevisions(Person.class,"Personaje", id_pers1);
+ List<Number> pers2Revs = getAuditReader().getRevisions(Person.class,"Personaje", id_pers2);
+ List<Number> pers3Revs = getAuditReader().getRevisions(Person.class,"Personaje", id_pers3);
+
+ assert(pers1Revs.size() == 3);
+ assert(pers2Revs.size() == 2);
+ assert(pers3Revs.size() == 1);
+ }
+
+ @Test
+ public void testRetrieveAuditedEntityWithEntityName() {
+ Person Person1 = getAuditReader().find(Person.class, "Personaje", id_pers1, 1);
+ Person Person2 = getAuditReader().find(Person.class, "Personaje", id_pers1, 2);
+ Person Person3 = getAuditReader().find(Person.class, "Personaje", id_pers1, 3);
+
+ System.out.println("Revision 1:");
+ System.out.println(" > Name: " + Person1.getName());
+ System.out.println(" > Age: " + Person1.getAge());
+ System.out.println("Revision 2:");
+ System.out.println(" > Name: " + Person2.getName());
+ System.out.println(" > Age: " + Person2.getAge());
+ System.out.println("Revision 3:");
+ System.out.println(" > Name: " + Person3.getName());
+ System.out.println(" > Age: " + Person3.getAge());
+ }
+
+
+}
Added: core/branches/Branch_3_5/envers/src/test/java/org/hibernate/envers/test/entityNames/manyToManyAudited/Car.java
===================================================================
--- core/branches/Branch_3_5/envers/src/test/java/org/hibernate/envers/test/entityNames/manyToManyAudited/Car.java (rev 0)
+++ core/branches/Branch_3_5/envers/src/test/java/org/hibernate/envers/test/entityNames/manyToManyAudited/Car.java 2010-07-06 06:31:40 UTC (rev 19902)
@@ -0,0 +1,56 @@
+package org.hibernate.envers.test.entityNames.manyToManyAudited;
+
+import java.util.List;
+
+import org.hibernate.envers.Audited;
+
+/**
+ * @author Hern�n Chanfreau
+ *
+ */
+
+@Audited
+public class Car {
+
+ private long id;
+
+ private int number;
+
+ private List<Person> owners;
+
+
+ public Car() { }
+
+ public Car(int number, List<Person> owners) {
+ this.number = number;
+ this.owners = owners;
+ }
+
+
+ public long getId() {
+ return id;
+ }
+
+ public void setId(long id) {
+ this.id = id;
+ }
+
+ public List<Person> getOwners() {
+ return owners;
+ }
+
+ public void setOwners(List<Person> owners) {
+ this.owners = owners;
+ }
+
+ public int getNumber() {
+ return number;
+ }
+
+ public void setNumber(int number) {
+ this.number = number;
+ }
+
+
+
+}
Added: core/branches/Branch_3_5/envers/src/test/java/org/hibernate/envers/test/entityNames/manyToManyAudited/Person.java
===================================================================
--- core/branches/Branch_3_5/envers/src/test/java/org/hibernate/envers/test/entityNames/manyToManyAudited/Person.java (rev 0)
+++ core/branches/Branch_3_5/envers/src/test/java/org/hibernate/envers/test/entityNames/manyToManyAudited/Person.java 2010-07-06 06:31:40 UTC (rev 19902)
@@ -0,0 +1,63 @@
+package org.hibernate.envers.test.entityNames.manyToManyAudited;
+
+import java.util.List;
+
+import org.hibernate.envers.Audited;
+
+/**
+ * @author Hern�n Chanfreau
+ *
+ */
+
+@Audited
+public class Person {
+
+ private long id;
+
+ private String name;
+
+ private int age;
+
+ private List<Car> cars;
+
+ public Person(){ }
+
+ public Person(String name, int age){
+ this.name = name;
+ this.age = age;
+ }
+
+
+ public long getId() {
+ return id;
+ }
+
+ public void setId(long id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public int getAge() {
+ return age;
+ }
+
+ public void setAge(int age) {
+ this.age = age;
+ }
+
+ public List<Car> getCars() {
+ return cars;
+ }
+
+ public void setCars(List<Car> cars) {
+ this.cars = cars;
+ }
+
+}
Added: core/branches/Branch_3_5/envers/src/test/java/org/hibernate/envers/test/entityNames/manyToManyAudited/ReadEntityWithAuditedManyToManyTest.java
===================================================================
--- core/branches/Branch_3_5/envers/src/test/java/org/hibernate/envers/test/entityNames/manyToManyAudited/ReadEntityWithAuditedManyToManyTest.java (rev 0)
+++ core/branches/Branch_3_5/envers/src/test/java/org/hibernate/envers/test/entityNames/manyToManyAudited/ReadEntityWithAuditedManyToManyTest.java 2010-07-06 06:31:40 UTC (rev 19902)
@@ -0,0 +1,99 @@
+package org.hibernate.envers.test.entityNames.manyToManyAudited;
+
+import java.io.File;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.hibernate.MappingException;
+import org.hibernate.envers.test.AbstractSessionTest;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+/**
+ * @author Hern�n Chanfreau
+ *
+ */
+
+public class ReadEntityWithAuditedManyToManyTest extends AbstractSessionTest{
+
+ private long id_car1;
+ private long id_car2;
+
+ private long id_pers1;
+
+ protected void initMappings() throws MappingException, URISyntaxException {
+ URL url = Thread.currentThread().getContextClassLoader().getResource("mappings/entityNames/manyToManyAudited/mappings.hbm.xml");
+ config.addFile(new File(url.toURI()));
+ }
+
+
+ @BeforeClass(dependsOnMethods = "init")
+ public void initData() {
+
+ newSessionFactory();
+
+ Person pers1 = new Person("Hernan", 28);
+ Person pers2 = new Person("Leandro", 29);
+ Person pers3 = new Person("Barba", 32);
+ Person pers4 = new Person("Camomo", 15);
+
+ //REV 1
+ getSession().getTransaction().begin();
+ List<Person > owners = new ArrayList<Person>();
+ owners.add(pers1);
+ owners.add(pers2);
+ owners.add(pers3);
+ Car car1 = new Car(5, owners);
+
+ getSession().persist(car1);
+ getSession().getTransaction().commit();
+ id_pers1 = pers1.getId();
+ id_car1 = car1.getId();
+
+ owners = new ArrayList<Person>();
+ owners.add(pers2);
+ owners.add(pers3);
+ owners.add(pers4);
+ Car car2 = new Car(27, owners);
+ //REV 2
+ getSession().getTransaction().begin();
+ Person person1 = (Person)getSession().get("Personaje", id_pers1);
+ person1.setName("Hernan David");
+ person1.setAge(40);
+ getSession().persist(car1);
+ getSession().persist(car2);
+ getSession().getTransaction().commit();
+ id_car2 = car2.getId();
+
+ }
+
+ @Test
+ public void testObtainManyYoManyWithEntityName() {
+
+ Car car1 = getAuditReader().find(Car.class, id_car1, 2);
+ Car car2 = getAuditReader().find(Car.class, id_car2, 2);
+
+ System.out.println(" > Car: " + car1.getNumber());
+ System.out.println(" > Owners:");
+ for (Person owner : car1.getOwners()) {
+ System.out.println(" > Name: " + owner.getName() + " - Age:" + owner.getAge());
+ System.out.println(" > Cars owned:");
+ for (Car ownedCar : owner.getCars()) {
+ System.out.println(" o Car: " + ownedCar.getNumber());
+ }
+ }
+ System.out.println(" > Car: " + car2.getNumber());
+ System.out.println(" > Owners:");
+ for (Person owner : car2.getOwners()) {
+ System.out.println(" > Name: " + owner.getName() + " - Age:" + owner.getAge());
+ System.out.println(" > Cars owned:");
+ for (Car ownedCar : owner.getCars()) {
+ System.out.println(" o Car: " + ownedCar.getNumber());
+ }
+ }
+ }
+
+
+}
Added: core/branches/Branch_3_5/envers/src/test/java/org/hibernate/envers/test/entityNames/oneToManyAudited/Car.java
===================================================================
--- core/branches/Branch_3_5/envers/src/test/java/org/hibernate/envers/test/entityNames/oneToManyAudited/Car.java (rev 0)
+++ core/branches/Branch_3_5/envers/src/test/java/org/hibernate/envers/test/entityNames/oneToManyAudited/Car.java 2010-07-06 06:31:40 UTC (rev 19902)
@@ -0,0 +1,56 @@
+package org.hibernate.envers.test.entityNames.oneToManyAudited;
+
+import java.util.List;
+
+import org.hibernate.envers.Audited;
+
+/**
+ * @author Hern�n Chanfreau
+ *
+ */
+
+@Audited
+public class Car {
+
+ private long id;
+
+ private int number;
+
+ private List<Person> owners;
+
+
+ public Car() { }
+
+ public Car(int number, List<Person> owners) {
+ this.number = number;
+ this.owners = owners;
+ }
+
+
+ public long getId() {
+ return id;
+ }
+
+ public void setId(long id) {
+ this.id = id;
+ }
+
+ public List<Person> getOwners() {
+ return owners;
+ }
+
+ public void setOwners(List<Person> owners) {
+ this.owners = owners;
+ }
+
+ public int getNumber() {
+ return number;
+ }
+
+ public void setNumber(int number) {
+ this.number = number;
+ }
+
+
+
+}
Added: core/branches/Branch_3_5/envers/src/test/java/org/hibernate/envers/test/entityNames/oneToManyAudited/Person.java
===================================================================
--- core/branches/Branch_3_5/envers/src/test/java/org/hibernate/envers/test/entityNames/oneToManyAudited/Person.java (rev 0)
+++ core/branches/Branch_3_5/envers/src/test/java/org/hibernate/envers/test/entityNames/oneToManyAudited/Person.java 2010-07-06 06:31:40 UTC (rev 19902)
@@ -0,0 +1,51 @@
+package org.hibernate.envers.test.entityNames.oneToManyAudited;
+
+import org.hibernate.envers.Audited;
+
+/**
+ * @author Hern�n Chanfreau
+ *
+ */
+
+@Audited
+public class Person {
+
+ private long id;
+
+ private String name;
+
+ private int age;
+
+ public Person(){ }
+
+ public Person(String name, int age){
+ this.name = name;
+ this.age = age;
+ }
+
+
+ public long getId() {
+ return id;
+ }
+
+ public void setId(long id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public int getAge() {
+ return age;
+ }
+
+ public void setAge(int age) {
+ this.age = age;
+ }
+
+}
Added: core/branches/Branch_3_5/envers/src/test/java/org/hibernate/envers/test/entityNames/oneToManyAudited/ReadEntityWithAuditedCollectionTest.java
===================================================================
--- core/branches/Branch_3_5/envers/src/test/java/org/hibernate/envers/test/entityNames/oneToManyAudited/ReadEntityWithAuditedCollectionTest.java (rev 0)
+++ core/branches/Branch_3_5/envers/src/test/java/org/hibernate/envers/test/entityNames/oneToManyAudited/ReadEntityWithAuditedCollectionTest.java 2010-07-06 06:31:40 UTC (rev 19902)
@@ -0,0 +1,89 @@
+package org.hibernate.envers.test.entityNames.oneToManyAudited;
+
+import java.io.File;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.hibernate.MappingException;
+import org.hibernate.envers.test.AbstractSessionTest;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+/**
+ * @author Hern�n Chanfreau
+ *
+ */
+
+public class ReadEntityWithAuditedCollectionTest extends AbstractSessionTest{
+
+ private long id_car1;
+ private long id_car2;
+
+ private long id_pers1;
+
+ protected void initMappings() throws MappingException, URISyntaxException {
+ URL url = Thread.currentThread().getContextClassLoader().getResource("mappings/entityNames/oneToManyAudited/mappings.hbm.xml");
+ config.addFile(new File(url.toURI()));
+ }
+
+
+ @BeforeClass(dependsOnMethods = "init")
+ public void initData() {
+
+ newSessionFactory();
+
+ Person pers1 = new Person("Hernan", 28);
+ Person pers2 = new Person("Leandro", 29);
+ Person pers3 = new Person("Barba", 32);
+ Person pers4 = new Person("Camomo", 15);
+
+ List<Person > owners = new ArrayList<Person>();
+ owners.add(pers1);
+ owners.add(pers2);
+ Car car1 = new Car(5, owners);
+
+ //REV 1
+ getSession().getTransaction().begin();
+ getSession().persist(car1);
+ getSession().getTransaction().commit();
+ id_pers1 = pers1.getId();
+ id_car1 = car1.getId();
+
+ owners = new ArrayList<Person>();
+ owners.add(pers2);
+ owners.add(pers4);
+ Car car2 = new Car(27, owners);
+ //REV 2
+ getSession().getTransaction().begin();
+ Person person1 = (Person)getSession().get("Personaje", id_pers1);
+ person1.setName("Hernan David");
+ person1.setAge(40);
+ getSession().persist(car1);
+ getSession().persist(car2);
+ getSession().getTransaction().commit();
+ id_car2 = car2.getId();
+
+ }
+
+ @Test
+ public void testObtainCollectionWithEntityName() {
+
+ Car car1 = getAuditReader().find(Car.class, id_car1, 2);
+ Car car2 = getAuditReader().find(Car.class, id_car2, 2);
+
+ System.out.println(" > Car: " + car1.getNumber());
+ System.out.println(" > Owners:");
+ for (Person owner : car1.getOwners()) {
+ System.out.println(" > Name: " + owner.getName() + " - Age:" + owner.getAge());
+ }
+ System.out.println(" > Car: " + car2.getNumber());
+ System.out.println(" > Owners:");
+ for (Person owner : car2.getOwners()) {
+ System.out.println(" > Name: " + owner.getName() + " - Age:" + owner.getAge());
+ }
+ }
+
+
+}
Added: core/branches/Branch_3_5/envers/src/test/java/org/hibernate/envers/test/entityNames/oneToManyNotAudited/Car.java
===================================================================
--- core/branches/Branch_3_5/envers/src/test/java/org/hibernate/envers/test/entityNames/oneToManyNotAudited/Car.java (rev 0)
+++ core/branches/Branch_3_5/envers/src/test/java/org/hibernate/envers/test/entityNames/oneToManyNotAudited/Car.java 2010-07-06 06:31:40 UTC (rev 19902)
@@ -0,0 +1,58 @@
+package org.hibernate.envers.test.entityNames.oneToManyNotAudited;
+
+import java.util.List;
+
+import org.hibernate.envers.Audited;
+import org.hibernate.envers.RelationTargetAuditMode;
+
+/**
+ * @author Hern�n Chanfreau
+ *
+ */
+
+public class Car {
+
+ private long id;
+
+ private int number;
+
+ private List<Person> owners;
+
+
+ public Car() { }
+
+ public Car(int number, List<Person> owners) {
+ this.number = number;
+ this.owners = owners;
+ }
+
+
+ public long getId() {
+ return id;
+ }
+
+ public void setId(long id) {
+ this.id = id;
+ }
+
+ @Audited(targetAuditMode=RelationTargetAuditMode.NOT_AUDITED)
+ public List<Person> getOwners() {
+ return owners;
+ }
+
+ public void setOwners(List<Person> owners) {
+ this.owners = owners;
+ }
+
+ @Audited
+ public int getNumber() {
+ return number;
+ }
+
+ public void setNumber(int number) {
+ this.number = number;
+ }
+
+
+
+}
Added: core/branches/Branch_3_5/envers/src/test/java/org/hibernate/envers/test/entityNames/oneToManyNotAudited/Person.java
===================================================================
--- core/branches/Branch_3_5/envers/src/test/java/org/hibernate/envers/test/entityNames/oneToManyNotAudited/Person.java (rev 0)
+++ core/branches/Branch_3_5/envers/src/test/java/org/hibernate/envers/test/entityNames/oneToManyNotAudited/Person.java 2010-07-06 06:31:40 UTC (rev 19902)
@@ -0,0 +1,48 @@
+package org.hibernate.envers.test.entityNames.oneToManyNotAudited;
+
+/**
+ * @author Hern�n Chanfreau
+ *
+ */
+
+public class Person {
+
+ private long id;
+
+ private String name;
+
+ private int age;
+
+ public Person(){ }
+
+ public Person(String name, int age){
+ this.name = name;
+ this.age = age;
+ }
+
+
+ public long getId() {
+ return id;
+ }
+
+ public void setId(long id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public int getAge() {
+ return age;
+ }
+
+ public void setAge(int age) {
+ this.age = age;
+ }
+
+}
Added: core/branches/Branch_3_5/envers/src/test/java/org/hibernate/envers/test/entityNames/oneToManyNotAudited/ReadEntityWithAuditedCollectionTest.java
===================================================================
--- core/branches/Branch_3_5/envers/src/test/java/org/hibernate/envers/test/entityNames/oneToManyNotAudited/ReadEntityWithAuditedCollectionTest.java (rev 0)
+++ core/branches/Branch_3_5/envers/src/test/java/org/hibernate/envers/test/entityNames/oneToManyNotAudited/ReadEntityWithAuditedCollectionTest.java 2010-07-06 06:31:40 UTC (rev 19902)
@@ -0,0 +1,84 @@
+package org.hibernate.envers.test.entityNames.oneToManyNotAudited;
+
+import java.io.File;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.hibernate.MappingException;
+import org.hibernate.envers.test.AbstractSessionTest;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+public class ReadEntityWithAuditedCollectionTest extends AbstractSessionTest{
+
+ private long id_car1;
+ private long id_car2;
+
+ private long id_pers1;
+
+ protected void initMappings() throws MappingException, URISyntaxException {
+ URL url = Thread.currentThread().getContextClassLoader().getResource("mappings/entityNames/oneToManyNotAudited/mappings.hbm.xml");
+ config.addFile(new File(url.toURI()));
+ }
+
+
+ @BeforeClass(dependsOnMethods = "init")
+ public void initData() {
+
+ newSessionFactory();
+
+ Person pers1 = new Person("Hernan", 28);
+ Person pers2 = new Person("Leandro", 29);
+ Person pers3 = new Person("Barba", 32);
+ Person pers4 = new Person("Camomo", 15);
+
+ List<Person > owners = new ArrayList<Person>();
+ owners.add(pers1);
+ owners.add(pers2);
+ Car car1 = new Car(5, owners);
+
+ //REV 1
+ getSession().getTransaction().begin();
+ getSession().persist(car1);
+ getSession().getTransaction().commit();
+ id_pers1 = pers1.getId();
+ id_car1 = car1.getId();
+
+ owners = new ArrayList<Person>();
+ owners.add(pers2);
+ owners.add(pers4);
+ Car car2 = new Car(27, owners);
+ //REV 2
+ getSession().getTransaction().begin();
+ Person person1 = (Person)getSession().get("Personaje", id_pers1);
+ person1.setName("Hernan David");
+ person1.setAge(40);
+ getSession().persist(car1);
+ getSession().persist(car2);
+ getSession().getTransaction().commit();
+ id_car2 = car2.getId();
+
+ }
+
+ @Test
+ public void testObtainCollectionWithEntityNameAndNotAuditedMode() {
+
+ Car car1 = getAuditReader().find(Car.class, id_car1, 2);
+ Car car2 = getAuditReader().find(Car.class, id_car2, 2);
+
+ System.out.println(" > Car: " + car1.getNumber());
+ System.out.println(" > Owners:");
+ for (Person owner : car1.getOwners()) {
+ System.out.println(" > Name: " + owner.getName() + " - Age:" + owner.getAge());
+ }
+ System.out.println(" > Car: " + car2.getNumber());
+ System.out.println(" > Owners:");
+ for (Person owner : car2.getOwners()) {
+ System.out.println(" > Name: " + owner.getName() + " - Age:" + owner.getAge());
+ }
+ }
+
+
+}
Added: core/branches/Branch_3_5/envers/src/test/java/org/hibernate/envers/test/entityNames/singleAssociatedAudited/Car.java
===================================================================
--- core/branches/Branch_3_5/envers/src/test/java/org/hibernate/envers/test/entityNames/singleAssociatedAudited/Car.java (rev 0)
+++ core/branches/Branch_3_5/envers/src/test/java/org/hibernate/envers/test/entityNames/singleAssociatedAudited/Car.java 2010-07-06 06:31:40 UTC (rev 19902)
@@ -0,0 +1,54 @@
+package org.hibernate.envers.test.entityNames.singleAssociatedAudited;
+
+import org.hibernate.envers.Audited;
+
+/**
+ * @author Hern�n Chanfreau
+ *
+ */
+
+@Audited
+public class Car {
+
+ private long id;
+
+ private int number;
+
+ private Person owner;
+
+
+ public Car() { }
+
+ public Car(int number, Person owner) {
+ this.number = number;
+ this.owner = owner;
+ }
+
+
+ public long getId() {
+ return id;
+ }
+
+ public void setId(long id) {
+ this.id = id;
+ }
+
+ public Person getOwner() {
+ return owner;
+ }
+
+ public void setOwner(Person owner) {
+ this.owner = owner;
+ }
+
+ public int getNumber() {
+ return number;
+ }
+
+ public void setNumber(int number) {
+ this.number = number;
+ }
+
+
+
+}
Added: core/branches/Branch_3_5/envers/src/test/java/org/hibernate/envers/test/entityNames/singleAssociatedAudited/Person.java
===================================================================
--- core/branches/Branch_3_5/envers/src/test/java/org/hibernate/envers/test/entityNames/singleAssociatedAudited/Person.java (rev 0)
+++ core/branches/Branch_3_5/envers/src/test/java/org/hibernate/envers/test/entityNames/singleAssociatedAudited/Person.java 2010-07-06 06:31:40 UTC (rev 19902)
@@ -0,0 +1,51 @@
+package org.hibernate.envers.test.entityNames.singleAssociatedAudited;
+
+import org.hibernate.envers.Audited;
+
+/**
+ * @author Hern�n Chanfreau
+ *
+ */
+
+@Audited
+public class Person {
+
+ private long id;
+
+ private String name;
+
+ private int age;
+
+ public Person(){ }
+
+ public Person(String name, int age){
+ this.name = name;
+ this.age = age;
+ }
+
+
+ public long getId() {
+ return id;
+ }
+
+ public void setId(long id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public int getAge() {
+ return age;
+ }
+
+ public void setAge(int age) {
+ this.age = age;
+ }
+
+}
Added: core/branches/Branch_3_5/envers/src/test/java/org/hibernate/envers/test/entityNames/singleAssociatedAudited/ReadEntityAssociatedAuditedTest.java
===================================================================
--- core/branches/Branch_3_5/envers/src/test/java/org/hibernate/envers/test/entityNames/singleAssociatedAudited/ReadEntityAssociatedAuditedTest.java (rev 0)
+++ core/branches/Branch_3_5/envers/src/test/java/org/hibernate/envers/test/entityNames/singleAssociatedAudited/ReadEntityAssociatedAuditedTest.java 2010-07-06 06:31:40 UTC (rev 19902)
@@ -0,0 +1,77 @@
+package org.hibernate.envers.test.entityNames.singleAssociatedAudited;
+
+import java.io.File;
+import java.net.URISyntaxException;
+import java.net.URL;
+
+import org.hibernate.MappingException;
+import org.hibernate.envers.test.AbstractSessionTest;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+/**
+ * @author Hern�n Chanfreau
+ *
+ */
+
+public class ReadEntityAssociatedAuditedTest extends AbstractSessionTest{
+
+ private long id_car1;
+ private long id_car2;
+
+ private long id_pers1;
+ private long id_pers2;
+
+
+ protected void initMappings() throws MappingException, URISyntaxException {
+ URL url = Thread.currentThread().getContextClassLoader().getResource("mappings/entityNames/singleAssociatedAudited/mappings.hbm.xml");
+ config.addFile(new File(url.toURI()));
+ }
+
+
+ @BeforeClass(dependsOnMethods = "init")
+ public void initData() {
+
+ newSessionFactory();
+
+ Person pers1 = new Person("Hernan", 15);
+ Person pers2 = new Person("Leandro", 19);
+
+ Car car1 = new Car(1, pers1);
+ Car car2 = new Car(2, pers2);
+
+ //REV 1
+ getSession().getTransaction().begin();
+ getSession().persist("Personaje",pers1);
+ getSession().persist(car1);
+ getSession().getTransaction().commit();
+ id_car1 = car1.getId();
+ id_pers1 = pers1.getId();
+
+ //REV 2
+ getSession().getTransaction().begin();
+ pers1.setAge(50);
+ getSession().persist("Personaje", pers1);
+ getSession().persist("Personaje", pers2);
+ getSession().persist(car2);
+ getSession().getTransaction().commit();
+ id_car2 = car2.getId();
+ id_pers2 = pers2.getId();
+
+ }
+
+ @Test
+ public void testGetAssociationWithEntityName() {
+
+ Person person1 = (Person)getSession().get("Personaje", id_pers1);
+ Car car1 = getAuditReader().find(Car.class, id_car1, 1);
+ Person person1_1 = car1.getOwner();
+ assert(person1.getAge() != person1_1.getAge());
+
+ Person person2 = (Person)getSession().get("Personaje", id_pers2);
+ Car car2 = getAuditReader().find(Car.class, id_car2, 2);
+ Person person2_1 = car2.getOwner();
+ assert(person2.getAge() == person2_1.getAge());
+ }
+
+}
Added: core/branches/Branch_3_5/envers/src/test/java/org/hibernate/envers/test/entityNames/singleAssociatedNotAudited/Car.java
===================================================================
--- core/branches/Branch_3_5/envers/src/test/java/org/hibernate/envers/test/entityNames/singleAssociatedNotAudited/Car.java (rev 0)
+++ core/branches/Branch_3_5/envers/src/test/java/org/hibernate/envers/test/entityNames/singleAssociatedNotAudited/Car.java 2010-07-06 06:31:40 UTC (rev 19902)
@@ -0,0 +1,56 @@
+package org.hibernate.envers.test.entityNames.singleAssociatedNotAudited;
+
+import org.hibernate.envers.Audited;
+import org.hibernate.envers.RelationTargetAuditMode;
+
+/**
+ * @author Hern�n Chanfreau
+ *
+ */
+
+public class Car {
+
+ private long id;
+
+ private int number;
+
+ private Person owner;
+
+
+ public Car() { }
+
+ public Car(int number, Person owner) {
+ this.number = number;
+ this.owner = owner;
+ }
+
+
+ public long getId() {
+ return id;
+ }
+
+ public void setId(long id) {
+ this.id = id;
+ }
+
+ @Audited(targetAuditMode=RelationTargetAuditMode.NOT_AUDITED)
+ public Person getOwner() {
+ return owner;
+ }
+
+ public void setOwner(Person owner) {
+ this.owner = owner;
+ }
+
+ @Audited
+ public int getNumber() {
+ return number;
+ }
+
+ public void setNumber(int number) {
+ this.number = number;
+ }
+
+
+
+}
Added: core/branches/Branch_3_5/envers/src/test/java/org/hibernate/envers/test/entityNames/singleAssociatedNotAudited/Person.java
===================================================================
--- core/branches/Branch_3_5/envers/src/test/java/org/hibernate/envers/test/entityNames/singleAssociatedNotAudited/Person.java (rev 0)
+++ core/branches/Branch_3_5/envers/src/test/java/org/hibernate/envers/test/entityNames/singleAssociatedNotAudited/Person.java 2010-07-06 06:31:40 UTC (rev 19902)
@@ -0,0 +1,48 @@
+package org.hibernate.envers.test.entityNames.singleAssociatedNotAudited;
+
+/**
+ * @author Hern�n Chanfreau
+ *
+ */
+
+public class Person {
+
+ private long id;
+
+ private String name;
+
+ private int age;
+
+ public Person(){ }
+
+ public Person(String name, int age){
+ this.name = name;
+ this.age = age;
+ }
+
+
+ public long getId() {
+ return id;
+ }
+
+ public void setId(long id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public int getAge() {
+ return age;
+ }
+
+ public void setAge(int age) {
+ this.age = age;
+ }
+
+}
Added: core/branches/Branch_3_5/envers/src/test/java/org/hibernate/envers/test/entityNames/singleAssociatedNotAudited/ReadEntityAssociatedNotAuditedTest.java
===================================================================
--- core/branches/Branch_3_5/envers/src/test/java/org/hibernate/envers/test/entityNames/singleAssociatedNotAudited/ReadEntityAssociatedNotAuditedTest.java (rev 0)
+++ core/branches/Branch_3_5/envers/src/test/java/org/hibernate/envers/test/entityNames/singleAssociatedNotAudited/ReadEntityAssociatedNotAuditedTest.java 2010-07-06 06:31:40 UTC (rev 19902)
@@ -0,0 +1,80 @@
+package org.hibernate.envers.test.entityNames.singleAssociatedNotAudited;
+
+import java.io.File;
+import java.net.URISyntaxException;
+import java.net.URL;
+
+import org.hibernate.MappingException;
+import org.hibernate.envers.test.AbstractSessionTest;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+/**
+ * @author Hern�n Chanfreau
+ *
+ */
+
+public class ReadEntityAssociatedNotAuditedTest extends AbstractSessionTest{
+
+ private long id_car1;
+ private long id_car2;
+
+ private long id_pers1;
+ private long id_pers2;
+
+
+ protected void initMappings() throws MappingException, URISyntaxException {
+ URL url = Thread.currentThread().getContextClassLoader().getResource("mappings/entityNames/singleAssociatedNotAudited/mappings.hbm.xml");
+ config.addFile(new File(url.toURI()));
+ }
+
+
+ @BeforeClass(dependsOnMethods = "init")
+ public void initData() {
+
+ newSessionFactory();
+
+ Person pers1 = new Person("Hernan", 15);
+ Person pers2 = new Person("Leandro", 19);
+
+ Car car1 = new Car(1, pers1);
+ Car car2 = new Car(2, pers2);
+
+ //REV 1
+ getSession().getTransaction().begin();
+ getSession().persist("Personaje",pers1);
+ getSession().persist(car1);
+ getSession().getTransaction().commit();
+ id_car1 = car1.getId();
+ id_pers1 = pers1.getId();
+
+ //REV 2
+ getSession().getTransaction().begin();
+ pers1.setAge(50);
+ getSession().persist("Personaje", pers1);
+ getSession().persist("Personaje", pers2);
+ getSession().persist(car2);
+ getSession().getTransaction().commit();
+ id_car2 = car2.getId();
+ id_pers2 = pers2.getId();
+
+ }
+
+ @Test
+ public void testGetAssociationWithEntityNameAndNotAuditedMode() {
+ // persons from "actual" model
+ Person person1 = (Person)getSession().get("Personaje", id_pers1);
+ Person person2 = (Person)getSession().get("Personaje", id_pers2);
+
+ Car car1 = getAuditReader().find(Car.class, id_car1, 1);
+ Car car2 = getAuditReader().find(Car.class, id_car2, 2);
+
+ // persons from "historic" model
+ Person person1_1 = car1.getOwner();
+ Person person2_1 = car2.getOwner();
+
+ assert(person1.getAge() == person1_1.getAge());
+ assert(person2.getAge() == person2_1.getAge());
+ }
+
+}
Added: core/branches/Branch_3_5/envers/src/test/resources/hibernate.test.session-cfg.xml
===================================================================
--- core/branches/Branch_3_5/envers/src/test/resources/hibernate.test.session-cfg.xml (rev 0)
+++ core/branches/Branch_3_5/envers/src/test/resources/hibernate.test.session-cfg.xml 2010-07-06 06:31:40 UTC (rev 19902)
@@ -0,0 +1,46 @@
+<?xml version='1.0' encoding='utf-8'?>
+<!DOCTYPE hibernate-configuration PUBLIC
+ "-//Hibernate/Hibernate Configuration DTD//EN"
+ "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
+
+<hibernate-configuration>
+ <session-factory>
+ <property name="hbm2ddl.auto">create-drop</property>
+
+ <property name="show_sql">false</property>
+ <property name="format_sql">false</property>
+
+ <property name="dialect">org.hibernate.dialect.H2Dialect</property>
+ <property name="connection.url">jdbc:h2:mem:envers</property>
+ <property name="connection.driver_class">org.h2.Driver</property>
+ <property name="connection.username">sa</property>
+ <property name="connection.password"></property>
+
+ <!--<property name="dialect">org.hibernate.dialect.MySQL5InnoDBDialect</property>-->
+ <!--<property name="connection.url">jdbc:mysql:///hibernate_tests?useUnicode=true&characterEncoding=UTF-8</property>-->
+ <!--<property name="connection.driver_class">com.mysql.jdbc.Driver</property>-->
+ <!--<property name="connection.username">root</property>-->
+ <!--<property name="connection.password"></property>-->
+
+ <!--<property name="hibernate.jdbc.batch_size">100</property>-->
+
+ <event type="post-insert">
+ <listener class="org.hibernate.envers.event.AuditEventListener" />
+ </event>
+ <event type="post-update">
+ <listener class="org.hibernate.envers.event.AuditEventListener" />
+ </event>
+ <event type="post-delete">
+ <listener class="org.hibernate.envers.event.AuditEventListener" />
+ </event>
+ <event type="pre-collection-update">
+ <listener class="org.hibernate.envers.event.AuditEventListener" />
+ </event>
+ <event type="pre-collection-remove">
+ <listener class="org.hibernate.envers.event.AuditEventListener" />
+ </event>
+ <event type="post-collection-recreate">
+ <listener class="org.hibernate.envers.event.AuditEventListener" />
+ </event>
+ </session-factory>
+</hibernate-configuration>
\ No newline at end of file
Added: core/branches/Branch_3_5/envers/src/test/resources/mappings/entityNames/auditedEntity/mappings.hbm.xml
===================================================================
--- core/branches/Branch_3_5/envers/src/test/resources/mappings/entityNames/auditedEntity/mappings.hbm.xml (rev 0)
+++ core/branches/Branch_3_5/envers/src/test/resources/mappings/entityNames/auditedEntity/mappings.hbm.xml 2010-07-06 06:31:40 UTC (rev 19902)
@@ -0,0 +1,18 @@
+<?xml version="1.0"?>
+<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
+<hibernate-mapping>
+
+ <class name="org.hibernate.envers.test.entityNames.auditedEntity.Person" entity-name="Personaje">
+
+ <id name="id" column="ID_person" type="long" >
+ <generator class="native" />
+ </id>
+
+ <property name="name" type="string" length="255"
+ column="NAME" not-null="true" />
+
+ <property name="age" type="int" column="AGE"/>
+
+ </class>
+
+</hibernate-mapping>
\ No newline at end of file
Added: core/branches/Branch_3_5/envers/src/test/resources/mappings/entityNames/manyToManyAudited/mappings.hbm.xml
===================================================================
--- core/branches/Branch_3_5/envers/src/test/resources/mappings/entityNames/manyToManyAudited/mappings.hbm.xml (rev 0)
+++ core/branches/Branch_3_5/envers/src/test/resources/mappings/entityNames/manyToManyAudited/mappings.hbm.xml 2010-07-06 06:31:40 UTC (rev 19902)
@@ -0,0 +1,40 @@
+<?xml version="1.0"?>
+<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
+<hibernate-mapping>
+
+ <class name="org.hibernate.envers.test.entityNames.manyToManyAudited.Person"
+ entity-name="Personaje">
+
+ <id name="id" column="ID_PERSON" type="long">
+ <generator class="native" />
+ </id>
+
+ <property name="name" type="string" length="255" column="NAME"
+ not-null="true" />
+
+ <property name="age" type="int" column="AGE" />
+
+ <bag name="cars" inverse="true" table="PERSON_CAR" >
+ <key column="ID_CAR" />
+ <many-to-many
+ class="org.hibernate.envers.test.entityNames.manyToManyAudited.Car" column="ID_PERSON"/>
+ </bag>
+
+ </class>
+
+ <class name="org.hibernate.envers.test.entityNames.manyToManyAudited.Car">
+
+ <id name="id" column="ID_CAR" type="long">
+ <generator class="native" />
+ </id>
+
+ <property name="number" type="int" not-null="true" />
+
+ <bag name="owners" cascade="all" table="PERSON_CAR" >
+ <key column="ID_PERSON" />
+ <many-to-many entity-name="Personaje" column="ID_CAR"/>
+ </bag>
+
+ </class>
+
+</hibernate-mapping>
\ No newline at end of file
Added: core/branches/Branch_3_5/envers/src/test/resources/mappings/entityNames/oneToManyAudited/mappings.hbm.xml
===================================================================
--- core/branches/Branch_3_5/envers/src/test/resources/mappings/entityNames/oneToManyAudited/mappings.hbm.xml (rev 0)
+++ core/branches/Branch_3_5/envers/src/test/resources/mappings/entityNames/oneToManyAudited/mappings.hbm.xml 2010-07-06 06:31:40 UTC (rev 19902)
@@ -0,0 +1,48 @@
+<?xml version="1.0"?>
+<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
+<hibernate-mapping>
+
+ <class name="org.hibernate.envers.test.entityNames.oneToManyAudited.Person" entity-name="Personaje">
+
+ <id name="id" column="ID_PERSON" type="long" >
+ <generator class="native" />
+ </id>
+
+ <property name="name" type="string" length="255"
+ column="NAME" not-null="true" />
+
+ <property name="age" type="int" column="AGE"/>
+
+ </class>
+
+ <class name="org.hibernate.envers.test.entityNames.oneToManyAudited.Car" >
+
+ <id name="id" column="ID_CAR" type="long">
+ <generator class="native" />
+ </id>
+
+ <property name="number" type="int" column="int" not-null="true" />
+
+ <bag name="owners" cascade="save-update">
+ <key column="ID_GARAGE" not-null="true" update="false" />
+ <one-to-many entity-name="Personaje"/>
+ </bag>
+
+ </class>
+
+<!-- <class name="org.hibernate.envers.test.entityNames.oneToManyAudited.Garage" >-->
+<!---->
+<!-- <id name="id" column="ID_GARAGE" type="long">-->
+<!-- <generator class="native" />-->
+<!-- </id>-->
+<!---->
+<!-- <property name="name" type="int" column="int" not-null="true" />-->
+<!---->
+<!-- <bag name="cars" cascade="save-update">-->
+<!-- <key column="ID_GARAGE" not-null="true" update="false" />-->
+<!-- <one-to-many class="org.hibernate.envers.test.entityNames.oneToManyAudited.Car" />-->
+<!-- </bag>-->
+<!-- -->
+<!-- </class> -->
+
+</hibernate-mapping>
\ No newline at end of file
Added: core/branches/Branch_3_5/envers/src/test/resources/mappings/entityNames/oneToManyNotAudited/mappings.hbm.xml
===================================================================
--- core/branches/Branch_3_5/envers/src/test/resources/mappings/entityNames/oneToManyNotAudited/mappings.hbm.xml (rev 0)
+++ core/branches/Branch_3_5/envers/src/test/resources/mappings/entityNames/oneToManyNotAudited/mappings.hbm.xml 2010-07-06 06:31:40 UTC (rev 19902)
@@ -0,0 +1,34 @@
+<?xml version="1.0"?>
+<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
+<hibernate-mapping>
+
+ <class name="org.hibernate.envers.test.entityNames.oneToManyNotAudited.Person" entity-name="Personaje">
+
+ <id name="id" column="ID_PERSON" type="long" >
+ <generator class="native" />
+ </id>
+
+ <property name="name" type="string" length="255"
+ column="NAME" not-null="true" />
+
+ <property name="age" type="int" column="AGE"/>
+
+ </class>
+
+ <class name="org.hibernate.envers.test.entityNames.oneToManyNotAudited.Car" >
+
+ <id name="id" column="ID_CAR" type="long">
+ <generator class="native" />
+ </id>
+
+ <property name="number" type="int" column="int" not-null="true" />
+
+ <bag name="owners" cascade="save-update">
+ <key column="ID_GARAGE" not-null="true" update="false" />
+ <one-to-many entity-name="Personaje"/>
+ </bag>
+
+ </class>
+
+
+</hibernate-mapping>
\ No newline at end of file
Added: core/branches/Branch_3_5/envers/src/test/resources/mappings/entityNames/singleAssociatedAudited/mappings.hbm.xml
===================================================================
--- core/branches/Branch_3_5/envers/src/test/resources/mappings/entityNames/singleAssociatedAudited/mappings.hbm.xml (rev 0)
+++ core/branches/Branch_3_5/envers/src/test/resources/mappings/entityNames/singleAssociatedAudited/mappings.hbm.xml 2010-07-06 06:31:40 UTC (rev 19902)
@@ -0,0 +1,30 @@
+<?xml version="1.0"?>
+<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
+<hibernate-mapping>
+
+ <class name="org.hibernate.envers.test.entityNames.singleAssociatedAudited.Person" entity-name="Personaje">
+
+ <id name="id" column="ID_person" type="long" >
+ <generator class="native" />
+ </id>
+
+ <property name="name" type="string" length="255"
+ column="NAME" not-null="true" />
+
+ <property name="age" type="int" column="AGE"/>
+
+ </class>
+
+ <class name="org.hibernate.envers.test.entityNames.singleAssociatedAudited.Car" >
+
+ <id name="id" column="ID_BED" type="long">
+ <generator class="native" />
+ </id>
+
+ <property name="number" type="int" column="int" not-null="true" />
+
+ <many-to-one name="owner" entity-name="Personaje"/>
+
+ </class>
+
+</hibernate-mapping>
\ No newline at end of file
Added: core/branches/Branch_3_5/envers/src/test/resources/mappings/entityNames/singleAssociatedNotAudited/mappings.hbm.xml
===================================================================
--- core/branches/Branch_3_5/envers/src/test/resources/mappings/entityNames/singleAssociatedNotAudited/mappings.hbm.xml (rev 0)
+++ core/branches/Branch_3_5/envers/src/test/resources/mappings/entityNames/singleAssociatedNotAudited/mappings.hbm.xml 2010-07-06 06:31:40 UTC (rev 19902)
@@ -0,0 +1,30 @@
+<?xml version="1.0"?>
+<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
+<hibernate-mapping>
+
+ <class name="org.hibernate.envers.test.entityNames.singleAssociatedNotAudited.Person" entity-name="Personaje">
+
+ <id name="id" column="ID_person" type="long" >
+ <generator class="native" />
+ </id>
+
+ <property name="name" type="string" length="255"
+ column="NAME" not-null="true" />
+
+ <property name="age" type="int" column="AGE"/>
+
+ </class>
+
+ <class name="org.hibernate.envers.test.entityNames.singleAssociatedNotAudited.Car" >
+
+ <id name="id" column="ID_BED" type="long">
+ <generator class="native" />
+ </id>
+
+ <property name="number" type="int" column="int" not-null="true" />
+
+ <many-to-one name="owner" entity-name="Personaje"/>
+
+ </class>
+
+</hibernate-mapping>
\ No newline at end of file
Modified: core/branches/Branch_3_5/envers/src/test/resources/testng.xml
===================================================================
--- core/branches/Branch_3_5/envers/src/test/resources/testng.xml 2010-07-05 17:36:04 UTC (rev 19901)
+++ core/branches/Branch_3_5/envers/src/test/resources/testng.xml 2010-07-06 06:31:40 UTC (rev 19902)
@@ -71,6 +71,13 @@
<package name="org.hibernate.envers.test.integration.secondary.ids" />
<package name="org.hibernate.envers.test.integration.serialization" />
<package name="org.hibernate.envers.test.integration.superclass" />
+
+ <package name="org.hibernate.envers.test.entityNames.auditedEntity" />
+ <package name="org.hibernate.envers.test.entityNames.manyToManyAudited" />
+ <package name="org.hibernate.envers.test.entityNames.oneToManyAudited" />
+ <package name="org.hibernate.envers.test.entityNames.oneToManyNotAudited" />
+ <package name="org.hibernate.envers.test.entityNames.singleAssociatedAudited" />
+ <package name="org.hibernate.envers.test.entityNames.singleAssociatedNotAudited" />
</packages>
</test>
</suite>
14 years, 7 months
Hibernate SVN: r19901 - in core/trunk/cache-infinispan/src: test/java/org/hibernate/test/cache/infinispan and 1 other directories.
by hibernate-commits@lists.jboss.org
Author: galder.zamarreno(a)jboss.com
Date: 2010-07-05 13:36:04 -0400 (Mon, 05 Jul 2010)
New Revision: 19901
Modified:
core/trunk/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/InfinispanRegionFactory.java
core/trunk/cache-infinispan/src/test/java/org/hibernate/test/cache/infinispan/InfinispanRegionFactoryTestCase.java
core/trunk/cache-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/classloader/IsolatedClassLoaderTest.java
Log:
[HHH-5260] (Allow query region name specific eviction settings) Ported to trunk.
Modified: core/trunk/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/InfinispanRegionFactory.java
===================================================================
--- core/trunk/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/InfinispanRegionFactory.java 2010-07-05 17:25:32 UTC (rev 19900)
+++ core/trunk/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/InfinispanRegionFactory.java 2010-07-05 17:36:04 UTC (rev 19901)
@@ -99,7 +99,7 @@
/**
* Name of the configuration that should be used for timestamp caches.
*
- * @see #DEF_TS_RESOURCE
+ * @see #DEF_TIMESTAMPS_RESOURCE
*/
public static final String TIMESTAMPS_CACHE_RESOURCE_PROP = PREFIX + TIMESTAMPS_KEY + CONFIG_SUFFIX;
@@ -113,7 +113,7 @@
public static final String QUERY_CACHE_RESOURCE_PROP = PREFIX + QUERY_KEY + CONFIG_SUFFIX;
/**
- * Default value for {@link #INFINISPAN_RESOURCE_PROP}. Specifies the "infinispan-configs.xml" file in this package.
+ * Default value for {@link #INFINISPAN_CONFIG_RESOURCE_PROP}. Specifies the "infinispan-configs.xml" file in this package.
*/
public static final String DEF_INFINISPAN_CONFIG_RESOURCE = "org/hibernate/cache/infinispan/builder/infinispan-configs.xml";
@@ -184,7 +184,12 @@
throws CacheException {
if (log.isDebugEnabled()) log.debug("Building query results cache region [" + regionName + "]");
String cacheName = typeOverrides.get(QUERY_KEY).getCacheName();
- CacheAdapter cacheAdapter = CacheAdapterImpl.newInstance(manager.getCache(cacheName));
+ // If region name is not default one, lookup a cache for that region name
+ if (!regionName.equals("org.hibernate.cache.StandardQueryCache"))
+ cacheName = regionName;
+
+ Cache cache = getCache(cacheName, QUERY_KEY, properties);
+ CacheAdapter cacheAdapter = CacheAdapterImpl.newInstance(cache);
QueryResultsRegionImpl region = new QueryResultsRegionImpl(cacheAdapter, regionName, properties, transactionManager, this);
region.start();
return region;
@@ -369,7 +374,7 @@
String templateCacheName = null;
Configuration regionCacheCfg = null;
if (regionOverride != null) {
- if (log.isDebugEnabled()) log.debug("Entity cache region specific configuration exists: " + regionOverride);
+ if (log.isDebugEnabled()) log.debug("Cache region specific configuration exists: " + regionOverride);
regionOverride = overrideStatisticsIfPresent(regionOverride, properties);
regionCacheCfg = regionOverride.createInfinispanConfiguration();
String cacheName = regionOverride.getCacheName();
@@ -412,4 +417,4 @@
}
return override;
}
-}
\ No newline at end of file
+}
Modified: core/trunk/cache-infinispan/src/test/java/org/hibernate/test/cache/infinispan/InfinispanRegionFactoryTestCase.java
===================================================================
--- core/trunk/cache-infinispan/src/test/java/org/hibernate/test/cache/infinispan/InfinispanRegionFactoryTestCase.java 2010-07-05 17:25:32 UTC (rev 19900)
+++ core/trunk/cache-infinispan/src/test/java/org/hibernate/test/cache/infinispan/InfinispanRegionFactoryTestCase.java 2010-07-05 17:36:04 UTC (rev 19901)
@@ -415,6 +415,32 @@
}
}
+ public void testBuildQueryRegionWithCustomRegionName() {
+ final String queryRegionName = "myquery";
+ Properties p = new Properties();
+ InfinispanRegionFactory factory = new InfinispanRegionFactory();
+ p.setProperty("hibernate.cache.infinispan.myquery.cfg", "timestamps-none-eviction");
+ p.setProperty("hibernate.cache.infinispan.myquery.eviction.strategy", "FIFO");
+ p.setProperty("hibernate.cache.infinispan.myquery.eviction.wake_up_interval", "2222");
+ p.setProperty("hibernate.cache.infinispan.myquery.eviction.max_entries", "11111");
+ factory.start(null, p);
+ CacheManager manager = factory.getCacheManager();
+ manager.getGlobalConfiguration().setTransportClass(null);
+ try {
+ assertTrue(factory.getDefinedConfigurations().contains("local-query"));
+ QueryResultsRegionImpl region = (QueryResultsRegionImpl) factory.buildQueryResultsRegion(queryRegionName, p);
+ assertNotNull(factory.getTypeOverrides().get(queryRegionName));
+ assertTrue(factory.getDefinedConfigurations().contains(queryRegionName));
+ CacheAdapter cache = region.getCacheAdapter();
+ Configuration cacheCfg = cache.getConfiguration();
+ assertEquals(EvictionStrategy.FIFO, cacheCfg.getEvictionStrategy());
+ assertEquals(2222, cacheCfg.getEvictionWakeUpInterval());
+ assertEquals(11111, cacheCfg.getEvictionMaxEntries());
+ } finally {
+ factory.stop();
+ }
+ }
+
public void testEnableStatistics() {
Properties p = new Properties();
p.setProperty("hibernate.cache.infinispan.statistics", "true");
Modified: core/trunk/cache-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/classloader/IsolatedClassLoaderTest.java
===================================================================
--- core/trunk/cache-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/classloader/IsolatedClassLoaderTest.java 2010-07-05 17:25:32 UTC (rev 19900)
+++ core/trunk/cache-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/classloader/IsolatedClassLoaderTest.java 2010-07-05 17:36:04 UTC (rev 19901)
@@ -88,6 +88,7 @@
protected void standardConfigure(Configuration cfg) {
super.standardConfigure(cfg);
cfg.setProperty(InfinispanRegionFactory.QUERY_CACHE_RESOURCE_PROP, "replicated-query");
+ cfg.setProperty("hibernate.cache.infinispan.AccountRegion.cfg", "replicated-query");
}
@@ -164,15 +165,25 @@
// Bind a listener to the "local" cache
// Our region factory makes its CacheManager available to us
CacheManager localManager = ClusterAwareRegionFactory.getCacheManager(DualNodeTestCase.LOCAL);
- localQueryCache = localManager.getCache("replicated-query");
+ // Bind a listener to the "remote" cache
+ CacheManager remoteManager = ClusterAwareRegionFactory.getCacheManager(DualNodeTestCase.REMOTE);
+ String cacheName;
+ if (useNamedRegion) {
+ cacheName = "AccountRegion"; // As defined by ClassLoaderTestDAO via calls to query.setCacheRegion
+ // Define cache configurations for region early to avoid ending up with local caches for this region
+ localManager.defineConfiguration(cacheName, "replicated-query", new org.infinispan.config.Configuration());
+ remoteManager.defineConfiguration(cacheName, "replicated-query", new org.infinispan.config.Configuration());
+ } else {
+ cacheName = "replicated-query";
+ }
+
+ localQueryCache = localManager.getCache(cacheName);
localQueryListener = new CacheAccessListener();
localQueryCache.addListener(localQueryListener);
TransactionManager localTM = DualNodeJtaTransactionManagerImpl.getInstance(DualNodeTestCase.LOCAL);
- // Bind a listener to the "remote" cache
- CacheManager remoteManager = ClusterAwareRegionFactory.getCacheManager(DualNodeTestCase.REMOTE);
- remoteQueryCache = remoteManager.getCache("replicated-query");
+ remoteQueryCache = remoteManager.getCache(cacheName);
remoteQueryListener = new CacheAccessListener();
remoteQueryCache.addListener(remoteQueryListener);
14 years, 7 months
Hibernate SVN: r19900 - in core/branches/Branch_3_5/cache-infinispan/src: test/java/org/hibernate/test/cache/infinispan/functional/classloader and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: galder.zamarreno(a)jboss.com
Date: 2010-07-05 13:25:32 -0400 (Mon, 05 Jul 2010)
New Revision: 19900
Modified:
core/branches/Branch_3_5/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/InfinispanRegionFactory.java
core/branches/Branch_3_5/cache-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/classloader/IsolatedClassLoaderTest.java
Log:
[HHH-5260] (Allow query region name specific eviction settings) Fix regression in query cache tests.
Modified: core/branches/Branch_3_5/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/InfinispanRegionFactory.java
===================================================================
--- core/branches/Branch_3_5/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/InfinispanRegionFactory.java 2010-07-05 17:04:29 UTC (rev 19899)
+++ core/branches/Branch_3_5/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/InfinispanRegionFactory.java 2010-07-05 17:25:32 UTC (rev 19900)
@@ -183,7 +183,12 @@
public QueryResultsRegion buildQueryResultsRegion(String regionName, Properties properties)
throws CacheException {
if (log.isDebugEnabled()) log.debug("Building query results cache region [" + regionName + "]");
- Cache cache = getCache(regionName, QUERY_KEY, properties);
+ String cacheName = typeOverrides.get(QUERY_KEY).getCacheName();
+ // If region name is not default one, lookup a cache for that region name
+ if (!regionName.equals("org.hibernate.cache.StandardQueryCache"))
+ cacheName = regionName;
+
+ Cache cache = getCache(cacheName, QUERY_KEY, properties);
CacheAdapter cacheAdapter = CacheAdapterImpl.newInstance(cache);
QueryResultsRegionImpl region = new QueryResultsRegionImpl(cacheAdapter, regionName, properties, transactionManager, this);
region.start();
@@ -369,7 +374,7 @@
String templateCacheName = null;
Configuration regionCacheCfg = null;
if (regionOverride != null) {
- if (log.isDebugEnabled()) log.debug("Entity cache region specific configuration exists: " + regionOverride);
+ if (log.isDebugEnabled()) log.debug("Cache region specific configuration exists: " + regionOverride);
regionOverride = overrideStatisticsIfPresent(regionOverride, properties);
regionCacheCfg = regionOverride.createInfinispanConfiguration();
String cacheName = regionOverride.getCacheName();
Modified: core/branches/Branch_3_5/cache-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/classloader/IsolatedClassLoaderTest.java
===================================================================
--- core/branches/Branch_3_5/cache-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/classloader/IsolatedClassLoaderTest.java 2010-07-05 17:04:29 UTC (rev 19899)
+++ core/branches/Branch_3_5/cache-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/classloader/IsolatedClassLoaderTest.java 2010-07-05 17:25:32 UTC (rev 19900)
@@ -88,6 +88,7 @@
protected void standardConfigure(Configuration cfg) {
super.standardConfigure(cfg);
cfg.setProperty(InfinispanRegionFactory.QUERY_CACHE_RESOURCE_PROP, "replicated-query");
+ cfg.setProperty("hibernate.cache.infinispan.AccountRegion.cfg", "replicated-query");
}
@@ -164,15 +165,25 @@
// Bind a listener to the "local" cache
// Our region factory makes its CacheManager available to us
CacheManager localManager = ClusterAwareRegionFactory.getCacheManager(DualNodeTestCase.LOCAL);
- localQueryCache = localManager.getCache("replicated-query");
+ // Bind a listener to the "remote" cache
+ CacheManager remoteManager = ClusterAwareRegionFactory.getCacheManager(DualNodeTestCase.REMOTE);
+ String cacheName;
+ if (useNamedRegion) {
+ cacheName = "AccountRegion"; // As defined by ClassLoaderTestDAO via calls to query.setCacheRegion
+ // Define cache configurations for region early to avoid ending up with local caches for this region
+ localManager.defineConfiguration(cacheName, "replicated-query", new org.infinispan.config.Configuration());
+ remoteManager.defineConfiguration(cacheName, "replicated-query", new org.infinispan.config.Configuration());
+ } else {
+ cacheName = "replicated-query";
+ }
+
+ localQueryCache = localManager.getCache(cacheName);
localQueryListener = new CacheAccessListener();
localQueryCache.addListener(localQueryListener);
TransactionManager localTM = DualNodeJtaTransactionManagerImpl.getInstance(DualNodeTestCase.LOCAL);
- // Bind a listener to the "remote" cache
- CacheManager remoteManager = ClusterAwareRegionFactory.getCacheManager(DualNodeTestCase.REMOTE);
- remoteQueryCache = remoteManager.getCache("replicated-query");
+ remoteQueryCache = remoteManager.getCache(cacheName);
remoteQueryListener = new CacheAccessListener();
remoteQueryCache.addListener(remoteQueryListener);
14 years, 7 months
Hibernate SVN: r19899 - in core/trunk/envers/src: main/java/org/hibernate/envers/configuration/metadata and 25 other directories.
by hibernate-commits@lists.jboss.org
Author: adamw
Date: 2010-07-05 13:04:29 -0400 (Mon, 05 Jul 2010)
New Revision: 19899
Added:
core/trunk/envers/src/test/java/org/hibernate/envers/test/AbstractSessionTest.java
core/trunk/envers/src/test/java/org/hibernate/envers/test/entityNames/
core/trunk/envers/src/test/java/org/hibernate/envers/test/entityNames/auditedEntity/
core/trunk/envers/src/test/java/org/hibernate/envers/test/entityNames/auditedEntity/Person.java
core/trunk/envers/src/test/java/org/hibernate/envers/test/entityNames/auditedEntity/ReadEntityWhtiEntityNameTest.java
core/trunk/envers/src/test/java/org/hibernate/envers/test/entityNames/manyToManyAudited/
core/trunk/envers/src/test/java/org/hibernate/envers/test/entityNames/manyToManyAudited/Car.java
core/trunk/envers/src/test/java/org/hibernate/envers/test/entityNames/manyToManyAudited/Person.java
core/trunk/envers/src/test/java/org/hibernate/envers/test/entityNames/manyToManyAudited/ReadEntityWithAuditedManyToManyTest.java
core/trunk/envers/src/test/java/org/hibernate/envers/test/entityNames/oneToManyAudited/
core/trunk/envers/src/test/java/org/hibernate/envers/test/entityNames/oneToManyAudited/Car.java
core/trunk/envers/src/test/java/org/hibernate/envers/test/entityNames/oneToManyAudited/Person.java
core/trunk/envers/src/test/java/org/hibernate/envers/test/entityNames/oneToManyAudited/ReadEntityWithAuditedCollectionTest.java
core/trunk/envers/src/test/java/org/hibernate/envers/test/entityNames/oneToManyNotAudited/
core/trunk/envers/src/test/java/org/hibernate/envers/test/entityNames/oneToManyNotAudited/Car.java
core/trunk/envers/src/test/java/org/hibernate/envers/test/entityNames/oneToManyNotAudited/Person.java
core/trunk/envers/src/test/java/org/hibernate/envers/test/entityNames/oneToManyNotAudited/ReadEntityWithAuditedCollectionTest.java
core/trunk/envers/src/test/java/org/hibernate/envers/test/entityNames/singleAssociatedAudited/
core/trunk/envers/src/test/java/org/hibernate/envers/test/entityNames/singleAssociatedAudited/Car.java
core/trunk/envers/src/test/java/org/hibernate/envers/test/entityNames/singleAssociatedAudited/Person.java
core/trunk/envers/src/test/java/org/hibernate/envers/test/entityNames/singleAssociatedAudited/ReadEntityAssociatedAuditedTest.java
core/trunk/envers/src/test/java/org/hibernate/envers/test/entityNames/singleAssociatedNotAudited/
core/trunk/envers/src/test/java/org/hibernate/envers/test/entityNames/singleAssociatedNotAudited/Car.java
core/trunk/envers/src/test/java/org/hibernate/envers/test/entityNames/singleAssociatedNotAudited/Person.java
core/trunk/envers/src/test/java/org/hibernate/envers/test/entityNames/singleAssociatedNotAudited/ReadEntityAssociatedNotAuditedTest.java
core/trunk/envers/src/test/resources/hibernate.test.session-cfg.xml
core/trunk/envers/src/test/resources/mappings/entityNames/
core/trunk/envers/src/test/resources/mappings/entityNames/auditedEntity/
core/trunk/envers/src/test/resources/mappings/entityNames/auditedEntity/mappings.hbm.xml
core/trunk/envers/src/test/resources/mappings/entityNames/manyToManyAudited/
core/trunk/envers/src/test/resources/mappings/entityNames/manyToManyAudited/mappings.hbm.xml
core/trunk/envers/src/test/resources/mappings/entityNames/oneToManyAudited/
core/trunk/envers/src/test/resources/mappings/entityNames/oneToManyAudited/mappings.hbm.xml
core/trunk/envers/src/test/resources/mappings/entityNames/oneToManyNotAudited/
core/trunk/envers/src/test/resources/mappings/entityNames/oneToManyNotAudited/mappings.hbm.xml
core/trunk/envers/src/test/resources/mappings/entityNames/singleAssociatedAudited/
core/trunk/envers/src/test/resources/mappings/entityNames/singleAssociatedAudited/mappings.hbm.xml
core/trunk/envers/src/test/resources/mappings/entityNames/singleAssociatedNotAudited/
core/trunk/envers/src/test/resources/mappings/entityNames/singleAssociatedNotAudited/mappings.hbm.xml
Modified:
core/trunk/envers/src/main/java/org/hibernate/envers/AuditReader.java
core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata/AuditMetadataGenerator.java
core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata/CollectionMetadataGenerator.java
core/trunk/envers/src/main/java/org/hibernate/envers/entities/EntityConfiguration.java
core/trunk/envers/src/main/java/org/hibernate/envers/entities/EntityInstantiator.java
core/trunk/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/OneToOneNotOwningMapper.java
core/trunk/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/ToOneIdMapper.java
core/trunk/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/lazy/ToOneDelegateSessionImplementor.java
core/trunk/envers/src/main/java/org/hibernate/envers/event/AuditEventListener.java
core/trunk/envers/src/main/java/org/hibernate/envers/query/AuditQueryCreator.java
core/trunk/envers/src/main/java/org/hibernate/envers/query/impl/AbstractAuditQuery.java
core/trunk/envers/src/main/java/org/hibernate/envers/query/impl/EntitiesAtRevisionQuery.java
core/trunk/envers/src/main/java/org/hibernate/envers/query/impl/RevisionsOfEntityQuery.java
core/trunk/envers/src/main/java/org/hibernate/envers/reader/AuditReaderImpl.java
core/trunk/envers/src/main/java/org/hibernate/envers/tools/Tools.java
core/trunk/envers/src/test/resources/testng.xml
Log:
HHH-4716:
- applying patch - thanks to Hernan Chanfreau!
- supporting the entity-name concept of Hibernate - when guessing from the class name doesn't work
Modified: core/trunk/envers/src/main/java/org/hibernate/envers/AuditReader.java
===================================================================
--- core/trunk/envers/src/main/java/org/hibernate/envers/AuditReader.java 2010-07-05 16:52:21 UTC (rev 19898)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/AuditReader.java 2010-07-05 17:04:29 UTC (rev 19899)
@@ -32,7 +32,7 @@
/**
* @author Adam Warski (adam at warski dot org)
- * @author Hernan Chanfreau
+ * @author Hern�n Chanfreau
*/
public interface AuditReader {
/**
@@ -49,6 +49,23 @@
*/
<T> T find(Class<T> cls, Object primaryKey, Number revision) throws
IllegalArgumentException, NotAuditedException, IllegalStateException;
+
+ /**
+ * Find an entity by primary key at the given revision with the specified entityName.
+ * @param cls Class of the entity.
+ * @param entityName Name of the entity (if can't be guessed basing on the {@code cls}).
+ * @param primaryKey Primary key of the entity.
+ * @param revision Revision in which to get the entity.
+ * @return The found entity instance at the given revision (its properties may be partially filled
+ * if not all properties are audited) or null, if an entity with that id didn't exist at that
+ * revision.
+ * @throws IllegalArgumentException If cls or primaryKey is null or revision is less or equal to 0.
+ * @throws NotAuditedException When entities of the given class are not audited.
+ * @throws IllegalStateException If the associated entity manager is closed.
+ */
+ <T> T find(Class<T> cls, String entityName, Object primaryKey,
+ Number revision) throws IllegalArgumentException,
+ NotAuditedException, IllegalStateException;
/**
* Get a list of revision numbers, at which an entity was modified.
@@ -62,6 +79,21 @@
*/
List<Number> getRevisions(Class<?> cls, Object primaryKey)
throws IllegalArgumentException, NotAuditedException, IllegalStateException;
+
+ /**
+ * Get a list of revision numbers, at which an entity was modified, looking by entityName.
+ * @param cls Class of the entity.
+ * @param entityName Name of the entity (if can't be guessed basing on the {@code cls}).
+ * @param primaryKey Primary key of the entity.
+ * @return A list of revision numbers, at which the entity was modified, sorted in ascending order (so older
+ * revisions come first).
+ * @throws NotAuditedException When entities of the given class are not audited.
+ * @throws IllegalArgumentException If cls or primaryKey is null.
+ * @throws IllegalStateException If the associated entity manager is closed.
+ */
+ List<Number> getRevisions(Class<?> cls, String entityName, Object primaryKey)
+ throws IllegalArgumentException, NotAuditedException,
+ IllegalStateException;
/**
* Get the date, at which a revision was created.
Modified: core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata/AuditMetadataGenerator.java
===================================================================
--- core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata/AuditMetadataGenerator.java 2010-07-05 16:52:21 UTC (rev 19898)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata/AuditMetadataGenerator.java 2010-07-05 17:04:29 UTC (rev 19899)
@@ -55,6 +55,7 @@
* @author Sebastian Komander
* @author Tomasz Bech
* @author Stephanie Pau at Markit Group Plc
+ * @author Hern�n Chanfreau
*/
public final class AuditMetadataGenerator {
private static final Logger log = LoggerFactory.getLogger(AuditMetadataGenerator.class);
@@ -370,7 +371,7 @@
ExtendedPropertyMapper propertyMapper = null;
String parentEntityName = null;
- EntityConfiguration entityCfg = new EntityConfiguration(entityName, idMapper, propertyMapper,
+ EntityConfiguration entityCfg = new EntityConfiguration(entityName, pc.getClassName(), idMapper, propertyMapper,
parentEntityName);
notAuditedEntitiesConfigurations.put(entityName, entityCfg);
return;
@@ -444,7 +445,7 @@
addJoins(pc, propertyMapper, auditingData, pc.getEntityName(), xmlMappingData, true);
// Storing the generated configuration
- EntityConfiguration entityCfg = new EntityConfiguration(auditEntityName, idMapper,
+ EntityConfiguration entityCfg = new EntityConfiguration(auditEntityName,pc.getClassName(), idMapper,
propertyMapper, parentEntityName);
entitiesConfigurations.put(pc.getEntityName(), entityCfg);
}
Modified: core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata/CollectionMetadataGenerator.java
===================================================================
--- core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata/CollectionMetadataGenerator.java 2010-07-05 16:52:21 UTC (rev 19898)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/configuration/metadata/CollectionMetadataGenerator.java 2010-07-05 17:04:29 UTC (rev 19899)
@@ -209,7 +209,7 @@
// The mapper will only be used to map from entity to map, so no need to provide other details
// when constructing the PropertyData.
new PropertyData(auditMappedBy, null, null, null),
- referencedEntityName, false);
+ referencingEntityName, false);
// Checking if there's an index defined. If so, adding a mapper for it.
if (propertyAuditingData.getPositionMappedBy() != null) {
Modified: core/trunk/envers/src/main/java/org/hibernate/envers/entities/EntityConfiguration.java
===================================================================
--- core/trunk/envers/src/main/java/org/hibernate/envers/entities/EntityConfiguration.java 2010-07-05 16:52:21 UTC (rev 19898)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/entities/EntityConfiguration.java 2010-07-05 17:04:29 UTC (rev 19899)
@@ -32,18 +32,22 @@
/**
* @author Adam Warski (adam at warski dot org)
+ * @author Hern�n Chanfreau
*/
public class EntityConfiguration {
private String versionsEntityName;
- private IdMappingData idMappingData;
+ /** Holds the className for instantiation the configured entity */
+ private String entityClassName;
+ private IdMappingData idMappingData;
private ExtendedPropertyMapper propertyMapper;
// Maps from property name
private Map<String, RelationDescription> relations;
private String parentEntityName;
- public EntityConfiguration(String versionsEntityName, IdMappingData idMappingData,
+ public EntityConfiguration(String versionsEntityName, String entityClassName, IdMappingData idMappingData,
ExtendedPropertyMapper propertyMapper, String parentEntityName) {
this.versionsEntityName = versionsEntityName;
+ this.entityClassName = entityClassName;
this.idMappingData = idMappingData;
this.propertyMapper = propertyMapper;
this.parentEntityName = parentEntityName;
@@ -113,4 +117,11 @@
Iterable<RelationDescription> getRelationsIterator() {
return relations.values();
}
+
+ /**
+ * @return the className for the configured entity
+ */
+ public String getEntityClassName() {
+ return entityClassName;
+ }
}
Modified: core/trunk/envers/src/main/java/org/hibernate/envers/entities/EntityInstantiator.java
===================================================================
--- core/trunk/envers/src/main/java/org/hibernate/envers/entities/EntityInstantiator.java 2010-07-05 16:52:21 UTC (rev 19898)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/entities/EntityInstantiator.java 2010-07-05 17:04:29 UTC (rev 19899)
@@ -36,6 +36,7 @@
/**
* @author Adam Warski (adam at warski dot org)
+ * @author Hern�n Chanfreau
*/
public class EntityInstantiator {
private final AuditConfiguration verCfg;
@@ -80,7 +81,13 @@
// If it is not in the cache, creating a new entity instance
Object ret;
try {
- Class<?> cls = ReflectionTools.loadClass(entityName);
+ EntityConfiguration entCfg = verCfg.getEntCfg().get(entityName);
+ if(entCfg == null) {
+ // a relation marked as RelationTargetAuditMode.NOT_AUDITED
+ entCfg = verCfg.getEntCfg().getNotVersionEntityConfiguration(entityName);
+ }
+
+ Class<?> cls = ReflectionTools.loadClass(entCfg.getEntityClassName());
ret = ReflectHelper.getDefaultConstructor(cls).newInstance();
} catch (Exception e) {
throw new AuditException(e);
Modified: core/trunk/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/OneToOneNotOwningMapper.java
===================================================================
--- core/trunk/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/OneToOneNotOwningMapper.java 2010-07-05 16:52:21 UTC (rev 19898)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/OneToOneNotOwningMapper.java 2010-07-05 17:04:29 UTC (rev 19899)
@@ -31,6 +31,7 @@
import org.hibernate.envers.configuration.AuditConfiguration;
import org.hibernate.envers.entities.mapper.PersistentCollectionChangeData;
import org.hibernate.envers.entities.mapper.PropertyMapper;
+import org.hibernate.envers.entities.EntityConfiguration;
import org.hibernate.envers.entities.PropertyData;
import org.hibernate.envers.exception.AuditException;
import org.hibernate.envers.query.AuditEntity;
@@ -44,6 +45,7 @@
/**
* @author Adam Warski (adam at warski dot org)
+ * @author Hern�n Chanfreau
*/
public class OneToOneNotOwningMapper implements PropertyMapper {
private String owningReferencePropertyName;
@@ -66,12 +68,18 @@
return;
}
- Class<?> entityClass = ReflectionTools.loadClass(owningEntityName);
+ EntityConfiguration entCfg = verCfg.getEntCfg().get(owningEntityName);
+ if(entCfg == null) {
+ // a relation marked as RelationTargetAuditMode.NOT_AUDITED
+ entCfg = verCfg.getEntCfg().getNotVersionEntityConfiguration(owningEntityName);
+ }
+ Class<?> entityClass = ReflectionTools.loadClass(entCfg.getEntityClassName());
+
Object value;
try {
- value = versionsReader.createQuery().forEntitiesAtRevision(entityClass, revision)
+ value = versionsReader.createQuery().forEntitiesAtRevision(entityClass, owningEntityName, revision)
.add(AuditEntity.relatedId(owningReferencePropertyName).eq(primaryKey)).getSingleResult();
} catch (NoResultException e) {
value = null;
Modified: core/trunk/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/ToOneIdMapper.java
===================================================================
--- core/trunk/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/ToOneIdMapper.java 2010-07-05 16:52:21 UTC (rev 19898)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/ToOneIdMapper.java 2010-07-05 17:04:29 UTC (rev 19899)
@@ -33,6 +33,7 @@
import org.hibernate.envers.entities.mapper.PropertyMapper;
import org.hibernate.envers.entities.mapper.id.IdMapper;
import org.hibernate.envers.entities.mapper.relation.lazy.ToOneDelegateSessionImplementor;
+import org.hibernate.envers.entities.EntityConfiguration;
import org.hibernate.envers.entities.PropertyData;
import org.hibernate.envers.reader.AuditReaderImplementor;
import org.hibernate.envers.tools.Tools;
@@ -44,6 +45,7 @@
/**
* @author Adam Warski (adam at warski dot org)
+ * @author Hern�n Chanfreau
*/
public class ToOneIdMapper implements PropertyMapper {
private final IdMapper delegate;
@@ -68,7 +70,7 @@
delegate.mapToMapFromEntity(newData, nonInsertableFake ? oldObj : newObj);
//noinspection SimplifiableConditionalExpression
- return nonInsertableFake ? false : !Tools.entitiesEqual(session, newObj, oldObj);
+ return nonInsertableFake ? false : !Tools.entitiesEqual(session, referencedEntityName, newObj, oldObj);
}
public void mapToEntityFromMap(AuditConfiguration verCfg, Object obj, Map data, Object primaryKey,
@@ -85,7 +87,13 @@
if (versionsReader.getFirstLevelCache().contains(referencedEntityName, revision, entityId)) {
value = versionsReader.getFirstLevelCache().get(referencedEntityName, revision, entityId);
} else {
- Class<?> entityClass = ReflectionTools.loadClass(referencedEntityName);
+ EntityConfiguration entCfg = verCfg.getEntCfg().get(referencedEntityName);
+ if(entCfg == null) {
+ // a relation marked as RelationTargetAuditMode.NOT_AUDITED
+ entCfg = verCfg.getEntCfg().getNotVersionEntityConfiguration(referencedEntityName);
+ }
+
+ Class<?> entityClass = ReflectionTools.loadClass(entCfg.getEntityClassName());
value = versionsReader.getSessionImplementor().getFactory().getEntityPersister(referencedEntityName).
createProxy((Serializable)entityId, new ToOneDelegateSessionImplementor(versionsReader, entityClass, entityId, revision, verCfg));
Modified: core/trunk/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/lazy/ToOneDelegateSessionImplementor.java
===================================================================
--- core/trunk/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/lazy/ToOneDelegateSessionImplementor.java 2010-07-05 16:52:21 UTC (rev 19898)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/lazy/ToOneDelegateSessionImplementor.java 2010-07-05 17:04:29 UTC (rev 19899)
@@ -27,7 +27,6 @@
import org.hibernate.envers.configuration.AuditConfiguration;
import org.hibernate.envers.entities.EntitiesConfigurations;
-import org.hibernate.envers.entities.EntityConfiguration;
import org.hibernate.envers.reader.AuditReaderImplementor;
import org.hibernate.HibernateException;
@@ -35,6 +34,7 @@
/**
* @author Adam Warski (adam at warski dot org)
* @author Tomasz Bech
+ * @author Hern�n Chanfreau
*/
public class ToOneDelegateSessionImplementor extends AbstractDelegateSessionImplementor {
private static final long serialVersionUID = 4770438372940785488L;
@@ -43,7 +43,7 @@
private final Class<?> entityClass;
private final Object entityId;
private final Number revision;
- private EntityConfiguration notVersionedEntityConfiguration;
+ private EntitiesConfigurations entCfg;
public ToOneDelegateSessionImplementor(AuditReaderImplementor versionsReader,
Class<?> entityClass, Object entityId, Number revision,
@@ -53,14 +53,15 @@
this.entityClass = entityClass;
this.entityId = entityId;
this.revision = revision;
- EntitiesConfigurations entCfg = verCfg.getEntCfg();
- notVersionedEntityConfiguration = entCfg.getNotVersionEntityConfiguration(entityClass.getName());
+ this.entCfg = verCfg.getEntCfg();
}
public Object doImmediateLoad(String entityName) throws HibernateException {
- if (notVersionedEntityConfiguration == null) {
- return versionsReader.find(entityClass, entityId, revision);
+ if(entCfg.getNotVersionEntityConfiguration(entityName) == null){
+ // audited relation, look up entity with envers
+ return versionsReader.find(entityClass, entityName, entityId, revision);
} else {
+ // notAudited relation, look up entity with hibernate
return delegate.immediateLoad(entityName, (Serializable) entityId);
}
}
Modified: core/trunk/envers/src/main/java/org/hibernate/envers/event/AuditEventListener.java
===================================================================
--- core/trunk/envers/src/main/java/org/hibernate/envers/event/AuditEventListener.java 2010-07-05 16:52:21 UTC (rev 19898)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/event/AuditEventListener.java 2010-07-05 17:04:29 UTC (rev 19899)
@@ -61,6 +61,7 @@
/**
* @author Adam Warski (adam at warski dot org)
+ * @author Hern�n Chanfreau
*/
public class AuditEventListener implements PostInsertEventListener, PostUpdateEventListener,
PostDeleteEventListener, PreCollectionUpdateEventListener, PreCollectionRemoveEventListener,
@@ -91,7 +92,7 @@
Object oldValue = oldState == null ? null : oldState[i];
Object newValue = newState == null ? null : newState[i];
- if (!Tools.entitiesEqual(session, oldValue, newValue)) {
+ if (!Tools.entitiesEqual(session, relDesc.getToEntityName(), oldValue, newValue)) {
// We have to generate changes both in the old collection (size decreses) and new collection
// (size increases).
if (newValue != null) {
Modified: core/trunk/envers/src/main/java/org/hibernate/envers/query/AuditQueryCreator.java
===================================================================
--- core/trunk/envers/src/main/java/org/hibernate/envers/query/AuditQueryCreator.java 2010-07-05 16:52:21 UTC (rev 19898)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/query/AuditQueryCreator.java 2010-07-05 17:04:29 UTC (rev 19899)
@@ -32,6 +32,7 @@
/**
* @author Adam Warski (adam at warski dot org)
+ * @author Hern�n Chanfreau
*/
public class AuditQueryCreator {
private final AuditConfiguration auditCfg;
@@ -56,6 +57,22 @@
checkPositive(revision, "Entity revision");
return new EntitiesAtRevisionQuery(auditCfg, auditReaderImplementor, c, revision);
}
+
+ /**
+ * Creates a query, which will return entities satisfying some conditions (specified later),
+ * at a given revision and a given entityName.
+ * @param c Class of the entities for which to query.
+ * @param entityName Name of the entity (if can't be guessed basing on the {@code c}).
+ * @param revision Revision number at which to execute the query.
+ * @return A query for entities at a given revision, to which conditions can be added and which
+ * can then be executed. The result of the query will be a list of entities (beans), unless a
+ * projection is added.
+ */
+ public AuditQuery forEntitiesAtRevision(Class<?> c, String entityName, Number revision) {
+ checkNotNull(revision, "Entity revision");
+ checkPositive(revision, "Entity revision");
+ return new EntitiesAtRevisionQuery(auditCfg, auditReaderImplementor, c, entityName, revision);
+ }
/**
* Creates a query, which selects the revisions, at which the given entity was modified.
@@ -80,4 +97,30 @@
public AuditQuery forRevisionsOfEntity(Class<?> c, boolean selectEntitiesOnly, boolean selectDeletedEntities) {
return new RevisionsOfEntityQuery(auditCfg, auditReaderImplementor, c, selectEntitiesOnly,selectDeletedEntities);
}
+
+ /**
+ * Creates a query, which selects the revisions, at which the given entity was modified and with a given entityName.
+ * Unless an explicit projection is set, the result will be a list of three-element arrays, containing:
+ * <ol>
+ * <li>the entity instance</li>
+ * <li>revision entity, corresponding to the revision at which the entity was modified. If no custom
+ * revision entity is used, this will be an instance of {@link org.hibernate.envers.DefaultRevisionEntity}</li>
+ * <li>type of the revision (an enum instance of class {@link org.hibernate.envers.RevisionType})</li>.
+ * </ol>
+ * Additional conditions that the results must satisfy may be specified.
+ * @param c Class of the entities for which to query.
+ * @param entityName Name of the entity (if can't be guessed basing on the {@code c}).
+ * @param selectEntitiesOnly If true, instead of a list of three-element arrays, a list of entites will be
+ * returned as a result of executing this query.
+ * @param selectDeletedEntities If true, also revisions where entities were deleted will be returned. The additional
+ * entities will have revision type "delete", and contain no data (all fields null), except for the id field.
+ * @return A query for revisions at which instances of the given entity were modified, to which
+ * conditions can be added (for example - a specific id of an entity of class <code>c</code>), and which
+ * can then be executed. The results of the query will be sorted in ascending order by the revision number,
+ * unless an order or projection is added.
+ */
+ public AuditQuery forRevisionsOfEntity(Class<?> c, String entityName, boolean selectEntitiesOnly, boolean selectDeletedEntities) {
+ return new RevisionsOfEntityQuery(auditCfg, auditReaderImplementor, c, entityName, selectEntitiesOnly,selectDeletedEntities);
+ }
+
}
Modified: core/trunk/envers/src/main/java/org/hibernate/envers/query/impl/AbstractAuditQuery.java
===================================================================
--- core/trunk/envers/src/main/java/org/hibernate/envers/query/impl/AbstractAuditQuery.java 2010-07-05 16:52:21 UTC (rev 19898)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/query/impl/AbstractAuditQuery.java 2010-07-05 17:04:29 UTC (rev 19899)
@@ -48,12 +48,14 @@
/**
* @author Adam Warski (adam at warski dot org)
+ * @author Hern�n Chanfreau
*/
public abstract class AbstractAuditQuery implements AuditQuery {
protected EntityInstantiator entityInstantiator;
protected List<AuditCriterion> criterions;
protected String entityName;
+ protected String entityClassName;
protected String versionsEntityName;
protected QueryBuilder qb;
@@ -65,18 +67,25 @@
protected AbstractAuditQuery(AuditConfiguration verCfg, AuditReaderImplementor versionsReader,
Class<?> cls) {
- this.verCfg = verCfg;
- this.versionsReader = versionsReader;
+ this(verCfg, versionsReader, cls, cls.getName());
+ }
- criterions = new ArrayList<AuditCriterion>();
- entityInstantiator = new EntityInstantiator(verCfg, versionsReader);
+ protected AbstractAuditQuery(AuditConfiguration verCfg,
+ AuditReaderImplementor versionsReader, Class<?> cls, String entityName) {
+ this.verCfg = verCfg;
+ this.versionsReader = versionsReader;
- entityName = cls.getName();
- versionsEntityName = verCfg.getAuditEntCfg().getAuditEntityName(entityName);
+ criterions = new ArrayList<AuditCriterion>();
+ entityInstantiator = new EntityInstantiator(verCfg, versionsReader);
- qb = new QueryBuilder(versionsEntityName, "e");
- }
+ entityClassName = cls.getName();
+ this.entityName = entityName;
+ versionsEntityName = verCfg.getAuditEntCfg().getAuditEntityName(
+ entityName);
+ qb = new QueryBuilder(versionsEntityName, "e");
+ }
+
protected List buildAndExecuteQuery() {
Query query = qb.toQuery(versionsReader.getSession());
Modified: core/trunk/envers/src/main/java/org/hibernate/envers/query/impl/EntitiesAtRevisionQuery.java
===================================================================
--- core/trunk/envers/src/main/java/org/hibernate/envers/query/impl/EntitiesAtRevisionQuery.java 2010-07-05 16:52:21 UTC (rev 19898)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/query/impl/EntitiesAtRevisionQuery.java 2010-07-05 17:04:29 UTC (rev 19899)
@@ -35,6 +35,7 @@
/**
* @author Adam Warski (adam at warski dot org)
+ * @author Hern�n Chanfreau
*/
public class EntitiesAtRevisionQuery extends AbstractAuditQuery {
private final Number revision;
@@ -45,6 +46,12 @@
super(verCfg, versionsReader, cls);
this.revision = revision;
}
+
+ public EntitiesAtRevisionQuery(AuditConfiguration verCfg,
+ AuditReaderImplementor versionsReader, Class<?> cls, String entityName, Number revision) {
+ super(verCfg, versionsReader, cls, entityName);
+ this.revision = revision;
+ }
@SuppressWarnings({"unchecked"})
public List list() {
Modified: core/trunk/envers/src/main/java/org/hibernate/envers/query/impl/RevisionsOfEntityQuery.java
===================================================================
--- core/trunk/envers/src/main/java/org/hibernate/envers/query/impl/RevisionsOfEntityQuery.java 2010-07-05 16:52:21 UTC (rev 19898)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/query/impl/RevisionsOfEntityQuery.java 2010-07-05 17:04:29 UTC (rev 19899)
@@ -33,11 +33,11 @@
import org.hibernate.envers.exception.AuditException;
import org.hibernate.envers.query.criteria.AuditCriterion;
import org.hibernate.envers.reader.AuditReaderImplementor;
-
import org.hibernate.proxy.HibernateProxy;
/**
* @author Adam Warski (adam at warski dot org)
+ * @author Hern�n Chanfreau
*/
public class RevisionsOfEntityQuery extends AbstractAuditQuery {
private final boolean selectEntitiesOnly;
@@ -53,6 +53,15 @@
this.selectDeletedEntities = selectDeletedEntities;
}
+ public RevisionsOfEntityQuery(AuditConfiguration verCfg,
+ AuditReaderImplementor versionsReader, Class<?> cls, String entityName,
+ boolean selectEntitiesOnly, boolean selectDeletedEntities) {
+ super(verCfg, versionsReader, cls, entityName);
+
+ this.selectEntitiesOnly = selectEntitiesOnly;
+ this.selectDeletedEntities = selectDeletedEntities;
+ }
+
private Number getRevisionNumber(Map versionsEntity) {
AuditEntitiesConfiguration verEntCfg = verCfg.getAuditEntCfg();
Modified: core/trunk/envers/src/main/java/org/hibernate/envers/reader/AuditReaderImpl.java
===================================================================
--- core/trunk/envers/src/main/java/org/hibernate/envers/reader/AuditReaderImpl.java 2010-07-05 16:52:21 UTC (rev 19898)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/reader/AuditReaderImpl.java 2010-07-05 17:04:29 UTC (rev 19899)
@@ -46,7 +46,7 @@
/**
* @author Adam Warski (adam at warski dot org)
- * @author Hernan Chanfreau
+ * @author Hern�n Chanfreau
*/
public class AuditReaderImpl implements AuditReaderImplementor {
private final AuditConfiguration verCfg;
@@ -81,17 +81,22 @@
return firstLevelCache;
}
- @SuppressWarnings({"unchecked"})
public <T> T find(Class<T> cls, Object primaryKey, Number revision) throws
IllegalArgumentException, NotAuditedException, IllegalStateException {
+
+ return this.find(cls, cls.getName(), primaryKey, revision);
+ }
+
+ @SuppressWarnings({"unchecked"})
+ public <T> T find(Class<T> cls, String entityName, Object primaryKey, Number revision) throws
+ IllegalArgumentException, NotAuditedException, IllegalStateException {
checkNotNull(cls, "Entity class");
+ checkNotNull(entityName, "Entity name");
checkNotNull(primaryKey, "Primary key");
checkNotNull(revision, "Entity revision");
checkPositive(revision, "Entity revision");
checkSession();
- String entityName = cls.getName();
-
if (!verCfg.getEntCfg().isVersioned(entityName)) {
throw new NotAuditedException(entityName, entityName + " is not versioned!");
}
@@ -103,7 +108,7 @@
Object result;
try {
// The result is put into the cache by the entity instantiator called from the query
- result = createQuery().forEntitiesAtRevision(cls, revision)
+ result = createQuery().forEntitiesAtRevision(cls, entityName, revision)
.add(AuditEntity.id().eq(primaryKey)).getSingleResult();
} catch (NoResultException e) {
result = null;
@@ -112,23 +117,28 @@
}
return (T) result;
+ }
+
+ public List<Number> getRevisions(Class<?> cls, Object primaryKey)
+ throws IllegalArgumentException, NotAuditedException, IllegalStateException {
+
+ return this.getRevisions(cls, cls.getName(), primaryKey);
}
@SuppressWarnings({"unchecked"})
- public List<Number> getRevisions(Class<?> cls, Object primaryKey)
+ public List<Number> getRevisions(Class<?> cls, String entityName, Object primaryKey)
throws IllegalArgumentException, NotAuditedException, IllegalStateException {
// todo: if a class is not versioned from the beginning, there's a missing ADD rev - what then?
checkNotNull(cls, "Entity class");
+ checkNotNull(entityName, "Entity name");
checkNotNull(primaryKey, "Primary key");
checkSession();
- String entityName = cls.getName();
-
if (!verCfg.getEntCfg().isVersioned(entityName)) {
throw new NotAuditedException(entityName, entityName + " is not versioned!");
}
- return createQuery().forRevisionsOfEntity(cls, false, true)
+ return createQuery().forRevisionsOfEntity(cls, entityName, false, true)
.addProjection(AuditEntity.revisionNumber())
.add(AuditEntity.id().eq(primaryKey))
.getResultList();
Modified: core/trunk/envers/src/main/java/org/hibernate/envers/tools/Tools.java
===================================================================
--- core/trunk/envers/src/main/java/org/hibernate/envers/tools/Tools.java 2010-07-05 16:52:21 UTC (rev 19898)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/tools/Tools.java 2010-07-05 17:04:29 UTC (rev 19899)
@@ -32,6 +32,7 @@
/**
* @author Adam Warski (adam at warski dot org)
+ * @author Hern�n Chanfreau
*/
public class Tools {
public static <K,V> Map<K,V> newHashMap() {
@@ -46,14 +47,14 @@
return new LinkedHashMap<K,V>();
}
- public static boolean entitiesEqual(SessionImplementor session, Object obj1, Object obj2) {
- Object id1 = getIdentifier(session, obj1);
- Object id2 = getIdentifier(session, obj2);
+ public static boolean entitiesEqual(SessionImplementor session, String entityName, Object obj1, Object obj2) {
+ Object id1 = getIdentifier(session, entityName, obj1);
+ Object id2 = getIdentifier(session, entityName, obj2);
return objectsEqual(id1, id2);
- }
+ }
- public static Object getIdentifier(SessionImplementor session, Object obj) {
+ public static Object getIdentifier(SessionImplementor session, String entityName, Object obj) {
if (obj == null) {
return null;
}
@@ -63,9 +64,9 @@
return hibernateProxy.getHibernateLazyInitializer().getIdentifier();
}
+ return session.getEntityPersister(entityName, obj).getIdentifier(obj, session);
+ }
- return session.getEntityPersister( null, obj ).getIdentifier( obj, session );
- }
public static Object getTargetFromProxy(SessionFactoryImplementor sessionFactoryImplementor, HibernateProxy proxy) {
if (!proxy.getHibernateLazyInitializer().isUninitialized()) {
Added: core/trunk/envers/src/test/java/org/hibernate/envers/test/AbstractSessionTest.java
===================================================================
--- core/trunk/envers/src/test/java/org/hibernate/envers/test/AbstractSessionTest.java (rev 0)
+++ core/trunk/envers/src/test/java/org/hibernate/envers/test/AbstractSessionTest.java 2010-07-05 17:04:29 UTC (rev 19899)
@@ -0,0 +1,78 @@
+package org.hibernate.envers.test;
+
+import java.io.File;
+import java.net.URISyntaxException;
+import java.net.URL;
+
+import org.hibernate.MappingException;
+import org.hibernate.Session;
+import org.hibernate.SessionFactory;
+import org.hibernate.cfg.AnnotationConfiguration;
+import org.hibernate.cfg.Configuration;
+import org.hibernate.envers.AuditReader;
+import org.hibernate.envers.AuditReaderFactory;
+import org.testng.annotations.*;
+
+/**
+ * Base class for testing envers with Session.
+ *
+ * @author Hern�n Chanfreau
+ *
+ */
+public abstract class AbstractSessionTest {
+
+ protected Configuration config;
+ private SessionFactory sessionFactory;
+ private Session session ;
+ private AuditReader auditReader;
+
+
+ @BeforeClass
+ @Parameters("auditStrategy")
+ public void init(@Optional String auditStrategy) throws URISyntaxException {
+ config = new AnnotationConfiguration();
+ URL url = Thread.currentThread().getContextClassLoader().getResource("hibernate.test.session-cfg.xml");
+ config.configure(new File(url.toURI()));
+
+ if (auditStrategy != null && !"".equals(auditStrategy)) {
+ config.setProperty("org.hibernate.envers.audit_strategy", auditStrategy);
+ }
+
+ this.initMappings();
+
+ sessionFactory = config.buildSessionFactory();
+ }
+
+ protected abstract void initMappings() throws MappingException, URISyntaxException ;
+
+
+
+ private SessionFactory getSessionFactory(){
+ return sessionFactory;
+ }
+
+
+ @BeforeMethod
+ public void newSessionFactory() {
+ session = getSessionFactory().openSession();
+ auditReader = AuditReaderFactory.get(session);
+ }
+
+ @AfterClass
+ public void closeSessionFactory() {
+ sessionFactory.close();
+ }
+
+
+ protected Session getSession() {
+ return session;
+ }
+
+
+
+ protected AuditReader getAuditReader() {
+ return auditReader;
+ }
+
+}
+
Added: core/trunk/envers/src/test/java/org/hibernate/envers/test/entityNames/auditedEntity/Person.java
===================================================================
--- core/trunk/envers/src/test/java/org/hibernate/envers/test/entityNames/auditedEntity/Person.java (rev 0)
+++ core/trunk/envers/src/test/java/org/hibernate/envers/test/entityNames/auditedEntity/Person.java 2010-07-05 17:04:29 UTC (rev 19899)
@@ -0,0 +1,51 @@
+package org.hibernate.envers.test.entityNames.auditedEntity;
+
+import org.hibernate.envers.Audited;
+
+/**
+ * @author Hern�n Chanfreau
+ *
+ */
+
+@Audited
+public class Person {
+
+ private long id;
+
+ private String name;
+
+ private int age;
+
+ public Person(){ }
+
+ public Person(String name, int age){
+ this.name = name;
+ this.age = age;
+ }
+
+
+ public long getId() {
+ return id;
+ }
+
+ public void setId(long id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public int getAge() {
+ return age;
+ }
+
+ public void setAge(int age) {
+ this.age = age;
+ }
+
+}
Added: core/trunk/envers/src/test/java/org/hibernate/envers/test/entityNames/auditedEntity/ReadEntityWhtiEntityNameTest.java
===================================================================
--- core/trunk/envers/src/test/java/org/hibernate/envers/test/entityNames/auditedEntity/ReadEntityWhtiEntityNameTest.java (rev 0)
+++ core/trunk/envers/src/test/java/org/hibernate/envers/test/entityNames/auditedEntity/ReadEntityWhtiEntityNameTest.java 2010-07-05 17:04:29 UTC (rev 19899)
@@ -0,0 +1,99 @@
+package org.hibernate.envers.test.entityNames.auditedEntity;
+
+import java.io.File;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.List;
+
+import org.hibernate.MappingException;
+import org.hibernate.envers.test.AbstractSessionTest;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+/**
+ * @author Hern�n Chanfreau
+ *
+ */
+
+public class ReadEntityWhtiEntityNameTest extends AbstractSessionTest{
+
+ private long id_pers1;
+ private long id_pers2;
+ private long id_pers3;
+
+
+ protected void initMappings() throws MappingException, URISyntaxException {
+ URL url = Thread.currentThread().getContextClassLoader().getResource("mappings/entityNames/auditedEntity/mappings.hbm.xml");
+ config.addFile(new File(url.toURI()));
+ }
+
+
+ @BeforeClass(dependsOnMethods = "init")
+ public void initData() {
+
+ newSessionFactory();
+
+ Person pers1 = new Person("Hernan", 28);
+ Person pers2 = new Person("Leandro", 29);
+ Person pers3 = new Person("Barba", 30);
+
+ //REV 1
+ getSession().getTransaction().begin();
+ getSession().persist("Personaje",pers1);
+ id_pers1 = pers1.getId();
+ getSession().getTransaction().commit();
+
+ //REV 2
+ getSession().getTransaction().begin();
+ pers1 = (Person)getSession().get("Personaje", id_pers1);
+ pers1.setAge(29);
+ getSession().persist("Personaje",pers1);
+ getSession().persist("Personaje",pers2);
+ id_pers2 = pers2.getId();
+ getSession().getTransaction().commit();
+
+ //REV
+ getSession().getTransaction().begin();
+ pers1 = (Person)getSession().get("Personaje", id_pers1);
+ pers1.setName("Hernan David");
+ pers2 = (Person)getSession().get("Personaje", id_pers2);
+ pers2.setAge(30);
+ getSession().persist("Personaje",pers1);
+ getSession().persist("Personaje",pers2);
+ getSession().persist("Personaje",pers3);
+ id_pers3 = pers3.getId();
+ getSession().getTransaction().commit();
+
+ }
+
+
+ @Test
+ public void testRetrieveRevisionsWithEntityName() {
+ List<Number> pers1Revs = getAuditReader().getRevisions(Person.class,"Personaje", id_pers1);
+ List<Number> pers2Revs = getAuditReader().getRevisions(Person.class,"Personaje", id_pers2);
+ List<Number> pers3Revs = getAuditReader().getRevisions(Person.class,"Personaje", id_pers3);
+
+ assert(pers1Revs.size() == 3);
+ assert(pers2Revs.size() == 2);
+ assert(pers3Revs.size() == 1);
+ }
+
+ @Test
+ public void testRetrieveAuditedEntityWithEntityName() {
+ Person Person1 = getAuditReader().find(Person.class, "Personaje", id_pers1, 1);
+ Person Person2 = getAuditReader().find(Person.class, "Personaje", id_pers1, 2);
+ Person Person3 = getAuditReader().find(Person.class, "Personaje", id_pers1, 3);
+
+ System.out.println("Revision 1:");
+ System.out.println(" > Name: " + Person1.getName());
+ System.out.println(" > Age: " + Person1.getAge());
+ System.out.println("Revision 2:");
+ System.out.println(" > Name: " + Person2.getName());
+ System.out.println(" > Age: " + Person2.getAge());
+ System.out.println("Revision 3:");
+ System.out.println(" > Name: " + Person3.getName());
+ System.out.println(" > Age: " + Person3.getAge());
+ }
+
+
+}
Added: core/trunk/envers/src/test/java/org/hibernate/envers/test/entityNames/manyToManyAudited/Car.java
===================================================================
--- core/trunk/envers/src/test/java/org/hibernate/envers/test/entityNames/manyToManyAudited/Car.java (rev 0)
+++ core/trunk/envers/src/test/java/org/hibernate/envers/test/entityNames/manyToManyAudited/Car.java 2010-07-05 17:04:29 UTC (rev 19899)
@@ -0,0 +1,56 @@
+package org.hibernate.envers.test.entityNames.manyToManyAudited;
+
+import java.util.List;
+
+import org.hibernate.envers.Audited;
+
+/**
+ * @author Hern�n Chanfreau
+ *
+ */
+
+@Audited
+public class Car {
+
+ private long id;
+
+ private int number;
+
+ private List<Person> owners;
+
+
+ public Car() { }
+
+ public Car(int number, List<Person> owners) {
+ this.number = number;
+ this.owners = owners;
+ }
+
+
+ public long getId() {
+ return id;
+ }
+
+ public void setId(long id) {
+ this.id = id;
+ }
+
+ public List<Person> getOwners() {
+ return owners;
+ }
+
+ public void setOwners(List<Person> owners) {
+ this.owners = owners;
+ }
+
+ public int getNumber() {
+ return number;
+ }
+
+ public void setNumber(int number) {
+ this.number = number;
+ }
+
+
+
+}
Added: core/trunk/envers/src/test/java/org/hibernate/envers/test/entityNames/manyToManyAudited/Person.java
===================================================================
--- core/trunk/envers/src/test/java/org/hibernate/envers/test/entityNames/manyToManyAudited/Person.java (rev 0)
+++ core/trunk/envers/src/test/java/org/hibernate/envers/test/entityNames/manyToManyAudited/Person.java 2010-07-05 17:04:29 UTC (rev 19899)
@@ -0,0 +1,63 @@
+package org.hibernate.envers.test.entityNames.manyToManyAudited;
+
+import java.util.List;
+
+import org.hibernate.envers.Audited;
+
+/**
+ * @author Hern�n Chanfreau
+ *
+ */
+
+@Audited
+public class Person {
+
+ private long id;
+
+ private String name;
+
+ private int age;
+
+ private List<Car> cars;
+
+ public Person(){ }
+
+ public Person(String name, int age){
+ this.name = name;
+ this.age = age;
+ }
+
+
+ public long getId() {
+ return id;
+ }
+
+ public void setId(long id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public int getAge() {
+ return age;
+ }
+
+ public void setAge(int age) {
+ this.age = age;
+ }
+
+ public List<Car> getCars() {
+ return cars;
+ }
+
+ public void setCars(List<Car> cars) {
+ this.cars = cars;
+ }
+
+}
Added: core/trunk/envers/src/test/java/org/hibernate/envers/test/entityNames/manyToManyAudited/ReadEntityWithAuditedManyToManyTest.java
===================================================================
--- core/trunk/envers/src/test/java/org/hibernate/envers/test/entityNames/manyToManyAudited/ReadEntityWithAuditedManyToManyTest.java (rev 0)
+++ core/trunk/envers/src/test/java/org/hibernate/envers/test/entityNames/manyToManyAudited/ReadEntityWithAuditedManyToManyTest.java 2010-07-05 17:04:29 UTC (rev 19899)
@@ -0,0 +1,99 @@
+package org.hibernate.envers.test.entityNames.manyToManyAudited;
+
+import java.io.File;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.hibernate.MappingException;
+import org.hibernate.envers.test.AbstractSessionTest;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+/**
+ * @author Hern�n Chanfreau
+ *
+ */
+
+public class ReadEntityWithAuditedManyToManyTest extends AbstractSessionTest{
+
+ private long id_car1;
+ private long id_car2;
+
+ private long id_pers1;
+
+ protected void initMappings() throws MappingException, URISyntaxException {
+ URL url = Thread.currentThread().getContextClassLoader().getResource("mappings/entityNames/manyToManyAudited/mappings.hbm.xml");
+ config.addFile(new File(url.toURI()));
+ }
+
+
+ @BeforeClass(dependsOnMethods = "init")
+ public void initData() {
+
+ newSessionFactory();
+
+ Person pers1 = new Person("Hernan", 28);
+ Person pers2 = new Person("Leandro", 29);
+ Person pers3 = new Person("Barba", 32);
+ Person pers4 = new Person("Camomo", 15);
+
+ //REV 1
+ getSession().getTransaction().begin();
+ List<Person > owners = new ArrayList<Person>();
+ owners.add(pers1);
+ owners.add(pers2);
+ owners.add(pers3);
+ Car car1 = new Car(5, owners);
+
+ getSession().persist(car1);
+ getSession().getTransaction().commit();
+ id_pers1 = pers1.getId();
+ id_car1 = car1.getId();
+
+ owners = new ArrayList<Person>();
+ owners.add(pers2);
+ owners.add(pers3);
+ owners.add(pers4);
+ Car car2 = new Car(27, owners);
+ //REV 2
+ getSession().getTransaction().begin();
+ Person person1 = (Person)getSession().get("Personaje", id_pers1);
+ person1.setName("Hernan David");
+ person1.setAge(40);
+ getSession().persist(car1);
+ getSession().persist(car2);
+ getSession().getTransaction().commit();
+ id_car2 = car2.getId();
+
+ }
+
+ @Test
+ public void testObtainManyYoManyWithEntityName() {
+
+ Car car1 = getAuditReader().find(Car.class, id_car1, 2);
+ Car car2 = getAuditReader().find(Car.class, id_car2, 2);
+
+ System.out.println(" > Car: " + car1.getNumber());
+ System.out.println(" > Owners:");
+ for (Person owner : car1.getOwners()) {
+ System.out.println(" > Name: " + owner.getName() + " - Age:" + owner.getAge());
+ System.out.println(" > Cars owned:");
+ for (Car ownedCar : owner.getCars()) {
+ System.out.println(" o Car: " + ownedCar.getNumber());
+ }
+ }
+ System.out.println(" > Car: " + car2.getNumber());
+ System.out.println(" > Owners:");
+ for (Person owner : car2.getOwners()) {
+ System.out.println(" > Name: " + owner.getName() + " - Age:" + owner.getAge());
+ System.out.println(" > Cars owned:");
+ for (Car ownedCar : owner.getCars()) {
+ System.out.println(" o Car: " + ownedCar.getNumber());
+ }
+ }
+ }
+
+
+}
Added: core/trunk/envers/src/test/java/org/hibernate/envers/test/entityNames/oneToManyAudited/Car.java
===================================================================
--- core/trunk/envers/src/test/java/org/hibernate/envers/test/entityNames/oneToManyAudited/Car.java (rev 0)
+++ core/trunk/envers/src/test/java/org/hibernate/envers/test/entityNames/oneToManyAudited/Car.java 2010-07-05 17:04:29 UTC (rev 19899)
@@ -0,0 +1,56 @@
+package org.hibernate.envers.test.entityNames.oneToManyAudited;
+
+import java.util.List;
+
+import org.hibernate.envers.Audited;
+
+/**
+ * @author Hern�n Chanfreau
+ *
+ */
+
+@Audited
+public class Car {
+
+ private long id;
+
+ private int number;
+
+ private List<Person> owners;
+
+
+ public Car() { }
+
+ public Car(int number, List<Person> owners) {
+ this.number = number;
+ this.owners = owners;
+ }
+
+
+ public long getId() {
+ return id;
+ }
+
+ public void setId(long id) {
+ this.id = id;
+ }
+
+ public List<Person> getOwners() {
+ return owners;
+ }
+
+ public void setOwners(List<Person> owners) {
+ this.owners = owners;
+ }
+
+ public int getNumber() {
+ return number;
+ }
+
+ public void setNumber(int number) {
+ this.number = number;
+ }
+
+
+
+}
Added: core/trunk/envers/src/test/java/org/hibernate/envers/test/entityNames/oneToManyAudited/Person.java
===================================================================
--- core/trunk/envers/src/test/java/org/hibernate/envers/test/entityNames/oneToManyAudited/Person.java (rev 0)
+++ core/trunk/envers/src/test/java/org/hibernate/envers/test/entityNames/oneToManyAudited/Person.java 2010-07-05 17:04:29 UTC (rev 19899)
@@ -0,0 +1,51 @@
+package org.hibernate.envers.test.entityNames.oneToManyAudited;
+
+import org.hibernate.envers.Audited;
+
+/**
+ * @author Hern�n Chanfreau
+ *
+ */
+
+@Audited
+public class Person {
+
+ private long id;
+
+ private String name;
+
+ private int age;
+
+ public Person(){ }
+
+ public Person(String name, int age){
+ this.name = name;
+ this.age = age;
+ }
+
+
+ public long getId() {
+ return id;
+ }
+
+ public void setId(long id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public int getAge() {
+ return age;
+ }
+
+ public void setAge(int age) {
+ this.age = age;
+ }
+
+}
Added: core/trunk/envers/src/test/java/org/hibernate/envers/test/entityNames/oneToManyAudited/ReadEntityWithAuditedCollectionTest.java
===================================================================
--- core/trunk/envers/src/test/java/org/hibernate/envers/test/entityNames/oneToManyAudited/ReadEntityWithAuditedCollectionTest.java (rev 0)
+++ core/trunk/envers/src/test/java/org/hibernate/envers/test/entityNames/oneToManyAudited/ReadEntityWithAuditedCollectionTest.java 2010-07-05 17:04:29 UTC (rev 19899)
@@ -0,0 +1,89 @@
+package org.hibernate.envers.test.entityNames.oneToManyAudited;
+
+import java.io.File;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.hibernate.MappingException;
+import org.hibernate.envers.test.AbstractSessionTest;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+/**
+ * @author Hern�n Chanfreau
+ *
+ */
+
+public class ReadEntityWithAuditedCollectionTest extends AbstractSessionTest{
+
+ private long id_car1;
+ private long id_car2;
+
+ private long id_pers1;
+
+ protected void initMappings() throws MappingException, URISyntaxException {
+ URL url = Thread.currentThread().getContextClassLoader().getResource("mappings/entityNames/oneToManyAudited/mappings.hbm.xml");
+ config.addFile(new File(url.toURI()));
+ }
+
+
+ @BeforeClass(dependsOnMethods = "init")
+ public void initData() {
+
+ newSessionFactory();
+
+ Person pers1 = new Person("Hernan", 28);
+ Person pers2 = new Person("Leandro", 29);
+ Person pers3 = new Person("Barba", 32);
+ Person pers4 = new Person("Camomo", 15);
+
+ List<Person > owners = new ArrayList<Person>();
+ owners.add(pers1);
+ owners.add(pers2);
+ Car car1 = new Car(5, owners);
+
+ //REV 1
+ getSession().getTransaction().begin();
+ getSession().persist(car1);
+ getSession().getTransaction().commit();
+ id_pers1 = pers1.getId();
+ id_car1 = car1.getId();
+
+ owners = new ArrayList<Person>();
+ owners.add(pers2);
+ owners.add(pers4);
+ Car car2 = new Car(27, owners);
+ //REV 2
+ getSession().getTransaction().begin();
+ Person person1 = (Person)getSession().get("Personaje", id_pers1);
+ person1.setName("Hernan David");
+ person1.setAge(40);
+ getSession().persist(car1);
+ getSession().persist(car2);
+ getSession().getTransaction().commit();
+ id_car2 = car2.getId();
+
+ }
+
+ @Test
+ public void testObtainCollectionWithEntityName() {
+
+ Car car1 = getAuditReader().find(Car.class, id_car1, 2);
+ Car car2 = getAuditReader().find(Car.class, id_car2, 2);
+
+ System.out.println(" > Car: " + car1.getNumber());
+ System.out.println(" > Owners:");
+ for (Person owner : car1.getOwners()) {
+ System.out.println(" > Name: " + owner.getName() + " - Age:" + owner.getAge());
+ }
+ System.out.println(" > Car: " + car2.getNumber());
+ System.out.println(" > Owners:");
+ for (Person owner : car2.getOwners()) {
+ System.out.println(" > Name: " + owner.getName() + " - Age:" + owner.getAge());
+ }
+ }
+
+
+}
Added: core/trunk/envers/src/test/java/org/hibernate/envers/test/entityNames/oneToManyNotAudited/Car.java
===================================================================
--- core/trunk/envers/src/test/java/org/hibernate/envers/test/entityNames/oneToManyNotAudited/Car.java (rev 0)
+++ core/trunk/envers/src/test/java/org/hibernate/envers/test/entityNames/oneToManyNotAudited/Car.java 2010-07-05 17:04:29 UTC (rev 19899)
@@ -0,0 +1,58 @@
+package org.hibernate.envers.test.entityNames.oneToManyNotAudited;
+
+import java.util.List;
+
+import org.hibernate.envers.Audited;
+import org.hibernate.envers.RelationTargetAuditMode;
+
+/**
+ * @author Hern�n Chanfreau
+ *
+ */
+
+public class Car {
+
+ private long id;
+
+ private int number;
+
+ private List<Person> owners;
+
+
+ public Car() { }
+
+ public Car(int number, List<Person> owners) {
+ this.number = number;
+ this.owners = owners;
+ }
+
+
+ public long getId() {
+ return id;
+ }
+
+ public void setId(long id) {
+ this.id = id;
+ }
+
+ @Audited(targetAuditMode=RelationTargetAuditMode.NOT_AUDITED)
+ public List<Person> getOwners() {
+ return owners;
+ }
+
+ public void setOwners(List<Person> owners) {
+ this.owners = owners;
+ }
+
+ @Audited
+ public int getNumber() {
+ return number;
+ }
+
+ public void setNumber(int number) {
+ this.number = number;
+ }
+
+
+
+}
Added: core/trunk/envers/src/test/java/org/hibernate/envers/test/entityNames/oneToManyNotAudited/Person.java
===================================================================
--- core/trunk/envers/src/test/java/org/hibernate/envers/test/entityNames/oneToManyNotAudited/Person.java (rev 0)
+++ core/trunk/envers/src/test/java/org/hibernate/envers/test/entityNames/oneToManyNotAudited/Person.java 2010-07-05 17:04:29 UTC (rev 19899)
@@ -0,0 +1,48 @@
+package org.hibernate.envers.test.entityNames.oneToManyNotAudited;
+
+/**
+ * @author Hern�n Chanfreau
+ *
+ */
+
+public class Person {
+
+ private long id;
+
+ private String name;
+
+ private int age;
+
+ public Person(){ }
+
+ public Person(String name, int age){
+ this.name = name;
+ this.age = age;
+ }
+
+
+ public long getId() {
+ return id;
+ }
+
+ public void setId(long id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public int getAge() {
+ return age;
+ }
+
+ public void setAge(int age) {
+ this.age = age;
+ }
+
+}
Added: core/trunk/envers/src/test/java/org/hibernate/envers/test/entityNames/oneToManyNotAudited/ReadEntityWithAuditedCollectionTest.java
===================================================================
--- core/trunk/envers/src/test/java/org/hibernate/envers/test/entityNames/oneToManyNotAudited/ReadEntityWithAuditedCollectionTest.java (rev 0)
+++ core/trunk/envers/src/test/java/org/hibernate/envers/test/entityNames/oneToManyNotAudited/ReadEntityWithAuditedCollectionTest.java 2010-07-05 17:04:29 UTC (rev 19899)
@@ -0,0 +1,84 @@
+package org.hibernate.envers.test.entityNames.oneToManyNotAudited;
+
+import java.io.File;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.hibernate.MappingException;
+import org.hibernate.envers.test.AbstractSessionTest;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+public class ReadEntityWithAuditedCollectionTest extends AbstractSessionTest{
+
+ private long id_car1;
+ private long id_car2;
+
+ private long id_pers1;
+
+ protected void initMappings() throws MappingException, URISyntaxException {
+ URL url = Thread.currentThread().getContextClassLoader().getResource("mappings/entityNames/oneToManyNotAudited/mappings.hbm.xml");
+ config.addFile(new File(url.toURI()));
+ }
+
+
+ @BeforeClass(dependsOnMethods = "init")
+ public void initData() {
+
+ newSessionFactory();
+
+ Person pers1 = new Person("Hernan", 28);
+ Person pers2 = new Person("Leandro", 29);
+ Person pers3 = new Person("Barba", 32);
+ Person pers4 = new Person("Camomo", 15);
+
+ List<Person > owners = new ArrayList<Person>();
+ owners.add(pers1);
+ owners.add(pers2);
+ Car car1 = new Car(5, owners);
+
+ //REV 1
+ getSession().getTransaction().begin();
+ getSession().persist(car1);
+ getSession().getTransaction().commit();
+ id_pers1 = pers1.getId();
+ id_car1 = car1.getId();
+
+ owners = new ArrayList<Person>();
+ owners.add(pers2);
+ owners.add(pers4);
+ Car car2 = new Car(27, owners);
+ //REV 2
+ getSession().getTransaction().begin();
+ Person person1 = (Person)getSession().get("Personaje", id_pers1);
+ person1.setName("Hernan David");
+ person1.setAge(40);
+ getSession().persist(car1);
+ getSession().persist(car2);
+ getSession().getTransaction().commit();
+ id_car2 = car2.getId();
+
+ }
+
+ @Test
+ public void testObtainCollectionWithEntityNameAndNotAuditedMode() {
+
+ Car car1 = getAuditReader().find(Car.class, id_car1, 2);
+ Car car2 = getAuditReader().find(Car.class, id_car2, 2);
+
+ System.out.println(" > Car: " + car1.getNumber());
+ System.out.println(" > Owners:");
+ for (Person owner : car1.getOwners()) {
+ System.out.println(" > Name: " + owner.getName() + " - Age:" + owner.getAge());
+ }
+ System.out.println(" > Car: " + car2.getNumber());
+ System.out.println(" > Owners:");
+ for (Person owner : car2.getOwners()) {
+ System.out.println(" > Name: " + owner.getName() + " - Age:" + owner.getAge());
+ }
+ }
+
+
+}
Added: core/trunk/envers/src/test/java/org/hibernate/envers/test/entityNames/singleAssociatedAudited/Car.java
===================================================================
--- core/trunk/envers/src/test/java/org/hibernate/envers/test/entityNames/singleAssociatedAudited/Car.java (rev 0)
+++ core/trunk/envers/src/test/java/org/hibernate/envers/test/entityNames/singleAssociatedAudited/Car.java 2010-07-05 17:04:29 UTC (rev 19899)
@@ -0,0 +1,54 @@
+package org.hibernate.envers.test.entityNames.singleAssociatedAudited;
+
+import org.hibernate.envers.Audited;
+
+/**
+ * @author Hern�n Chanfreau
+ *
+ */
+
+@Audited
+public class Car {
+
+ private long id;
+
+ private int number;
+
+ private Person owner;
+
+
+ public Car() { }
+
+ public Car(int number, Person owner) {
+ this.number = number;
+ this.owner = owner;
+ }
+
+
+ public long getId() {
+ return id;
+ }
+
+ public void setId(long id) {
+ this.id = id;
+ }
+
+ public Person getOwner() {
+ return owner;
+ }
+
+ public void setOwner(Person owner) {
+ this.owner = owner;
+ }
+
+ public int getNumber() {
+ return number;
+ }
+
+ public void setNumber(int number) {
+ this.number = number;
+ }
+
+
+
+}
Added: core/trunk/envers/src/test/java/org/hibernate/envers/test/entityNames/singleAssociatedAudited/Person.java
===================================================================
--- core/trunk/envers/src/test/java/org/hibernate/envers/test/entityNames/singleAssociatedAudited/Person.java (rev 0)
+++ core/trunk/envers/src/test/java/org/hibernate/envers/test/entityNames/singleAssociatedAudited/Person.java 2010-07-05 17:04:29 UTC (rev 19899)
@@ -0,0 +1,51 @@
+package org.hibernate.envers.test.entityNames.singleAssociatedAudited;
+
+import org.hibernate.envers.Audited;
+
+/**
+ * @author Hern�n Chanfreau
+ *
+ */
+
+@Audited
+public class Person {
+
+ private long id;
+
+ private String name;
+
+ private int age;
+
+ public Person(){ }
+
+ public Person(String name, int age){
+ this.name = name;
+ this.age = age;
+ }
+
+
+ public long getId() {
+ return id;
+ }
+
+ public void setId(long id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public int getAge() {
+ return age;
+ }
+
+ public void setAge(int age) {
+ this.age = age;
+ }
+
+}
Added: core/trunk/envers/src/test/java/org/hibernate/envers/test/entityNames/singleAssociatedAudited/ReadEntityAssociatedAuditedTest.java
===================================================================
--- core/trunk/envers/src/test/java/org/hibernate/envers/test/entityNames/singleAssociatedAudited/ReadEntityAssociatedAuditedTest.java (rev 0)
+++ core/trunk/envers/src/test/java/org/hibernate/envers/test/entityNames/singleAssociatedAudited/ReadEntityAssociatedAuditedTest.java 2010-07-05 17:04:29 UTC (rev 19899)
@@ -0,0 +1,77 @@
+package org.hibernate.envers.test.entityNames.singleAssociatedAudited;
+
+import java.io.File;
+import java.net.URISyntaxException;
+import java.net.URL;
+
+import org.hibernate.MappingException;
+import org.hibernate.envers.test.AbstractSessionTest;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+/**
+ * @author Hern�n Chanfreau
+ *
+ */
+
+public class ReadEntityAssociatedAuditedTest extends AbstractSessionTest{
+
+ private long id_car1;
+ private long id_car2;
+
+ private long id_pers1;
+ private long id_pers2;
+
+
+ protected void initMappings() throws MappingException, URISyntaxException {
+ URL url = Thread.currentThread().getContextClassLoader().getResource("mappings/entityNames/singleAssociatedAudited/mappings.hbm.xml");
+ config.addFile(new File(url.toURI()));
+ }
+
+
+ @BeforeClass(dependsOnMethods = "init")
+ public void initData() {
+
+ newSessionFactory();
+
+ Person pers1 = new Person("Hernan", 15);
+ Person pers2 = new Person("Leandro", 19);
+
+ Car car1 = new Car(1, pers1);
+ Car car2 = new Car(2, pers2);
+
+ //REV 1
+ getSession().getTransaction().begin();
+ getSession().persist("Personaje",pers1);
+ getSession().persist(car1);
+ getSession().getTransaction().commit();
+ id_car1 = car1.getId();
+ id_pers1 = pers1.getId();
+
+ //REV 2
+ getSession().getTransaction().begin();
+ pers1.setAge(50);
+ getSession().persist("Personaje", pers1);
+ getSession().persist("Personaje", pers2);
+ getSession().persist(car2);
+ getSession().getTransaction().commit();
+ id_car2 = car2.getId();
+ id_pers2 = pers2.getId();
+
+ }
+
+ @Test
+ public void testGetAssociationWithEntityName() {
+
+ Person person1 = (Person)getSession().get("Personaje", id_pers1);
+ Car car1 = getAuditReader().find(Car.class, id_car1, 1);
+ Person person1_1 = car1.getOwner();
+ assert(person1.getAge() != person1_1.getAge());
+
+ Person person2 = (Person)getSession().get("Personaje", id_pers2);
+ Car car2 = getAuditReader().find(Car.class, id_car2, 2);
+ Person person2_1 = car2.getOwner();
+ assert(person2.getAge() == person2_1.getAge());
+ }
+
+}
Added: core/trunk/envers/src/test/java/org/hibernate/envers/test/entityNames/singleAssociatedNotAudited/Car.java
===================================================================
--- core/trunk/envers/src/test/java/org/hibernate/envers/test/entityNames/singleAssociatedNotAudited/Car.java (rev 0)
+++ core/trunk/envers/src/test/java/org/hibernate/envers/test/entityNames/singleAssociatedNotAudited/Car.java 2010-07-05 17:04:29 UTC (rev 19899)
@@ -0,0 +1,56 @@
+package org.hibernate.envers.test.entityNames.singleAssociatedNotAudited;
+
+import org.hibernate.envers.Audited;
+import org.hibernate.envers.RelationTargetAuditMode;
+
+/**
+ * @author Hern�n Chanfreau
+ *
+ */
+
+public class Car {
+
+ private long id;
+
+ private int number;
+
+ private Person owner;
+
+
+ public Car() { }
+
+ public Car(int number, Person owner) {
+ this.number = number;
+ this.owner = owner;
+ }
+
+
+ public long getId() {
+ return id;
+ }
+
+ public void setId(long id) {
+ this.id = id;
+ }
+
+ @Audited(targetAuditMode=RelationTargetAuditMode.NOT_AUDITED)
+ public Person getOwner() {
+ return owner;
+ }
+
+ public void setOwner(Person owner) {
+ this.owner = owner;
+ }
+
+ @Audited
+ public int getNumber() {
+ return number;
+ }
+
+ public void setNumber(int number) {
+ this.number = number;
+ }
+
+
+
+}
Added: core/trunk/envers/src/test/java/org/hibernate/envers/test/entityNames/singleAssociatedNotAudited/Person.java
===================================================================
--- core/trunk/envers/src/test/java/org/hibernate/envers/test/entityNames/singleAssociatedNotAudited/Person.java (rev 0)
+++ core/trunk/envers/src/test/java/org/hibernate/envers/test/entityNames/singleAssociatedNotAudited/Person.java 2010-07-05 17:04:29 UTC (rev 19899)
@@ -0,0 +1,48 @@
+package org.hibernate.envers.test.entityNames.singleAssociatedNotAudited;
+
+/**
+ * @author Hern�n Chanfreau
+ *
+ */
+
+public class Person {
+
+ private long id;
+
+ private String name;
+
+ private int age;
+
+ public Person(){ }
+
+ public Person(String name, int age){
+ this.name = name;
+ this.age = age;
+ }
+
+
+ public long getId() {
+ return id;
+ }
+
+ public void setId(long id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public int getAge() {
+ return age;
+ }
+
+ public void setAge(int age) {
+ this.age = age;
+ }
+
+}
Added: core/trunk/envers/src/test/java/org/hibernate/envers/test/entityNames/singleAssociatedNotAudited/ReadEntityAssociatedNotAuditedTest.java
===================================================================
--- core/trunk/envers/src/test/java/org/hibernate/envers/test/entityNames/singleAssociatedNotAudited/ReadEntityAssociatedNotAuditedTest.java (rev 0)
+++ core/trunk/envers/src/test/java/org/hibernate/envers/test/entityNames/singleAssociatedNotAudited/ReadEntityAssociatedNotAuditedTest.java 2010-07-05 17:04:29 UTC (rev 19899)
@@ -0,0 +1,80 @@
+package org.hibernate.envers.test.entityNames.singleAssociatedNotAudited;
+
+import java.io.File;
+import java.net.URISyntaxException;
+import java.net.URL;
+
+import org.hibernate.MappingException;
+import org.hibernate.envers.test.AbstractSessionTest;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+/**
+ * @author Hern�n Chanfreau
+ *
+ */
+
+public class ReadEntityAssociatedNotAuditedTest extends AbstractSessionTest{
+
+ private long id_car1;
+ private long id_car2;
+
+ private long id_pers1;
+ private long id_pers2;
+
+
+ protected void initMappings() throws MappingException, URISyntaxException {
+ URL url = Thread.currentThread().getContextClassLoader().getResource("mappings/entityNames/singleAssociatedNotAudited/mappings.hbm.xml");
+ config.addFile(new File(url.toURI()));
+ }
+
+
+ @BeforeClass(dependsOnMethods = "init")
+ public void initData() {
+
+ newSessionFactory();
+
+ Person pers1 = new Person("Hernan", 15);
+ Person pers2 = new Person("Leandro", 19);
+
+ Car car1 = new Car(1, pers1);
+ Car car2 = new Car(2, pers2);
+
+ //REV 1
+ getSession().getTransaction().begin();
+ getSession().persist("Personaje",pers1);
+ getSession().persist(car1);
+ getSession().getTransaction().commit();
+ id_car1 = car1.getId();
+ id_pers1 = pers1.getId();
+
+ //REV 2
+ getSession().getTransaction().begin();
+ pers1.setAge(50);
+ getSession().persist("Personaje", pers1);
+ getSession().persist("Personaje", pers2);
+ getSession().persist(car2);
+ getSession().getTransaction().commit();
+ id_car2 = car2.getId();
+ id_pers2 = pers2.getId();
+
+ }
+
+ @Test
+ public void testGetAssociationWithEntityNameAndNotAuditedMode() {
+ // persons from "actual" model
+ Person person1 = (Person)getSession().get("Personaje", id_pers1);
+ Person person2 = (Person)getSession().get("Personaje", id_pers2);
+
+ Car car1 = getAuditReader().find(Car.class, id_car1, 1);
+ Car car2 = getAuditReader().find(Car.class, id_car2, 2);
+
+ // persons from "historic" model
+ Person person1_1 = car1.getOwner();
+ Person person2_1 = car2.getOwner();
+
+ assert(person1.getAge() == person1_1.getAge());
+ assert(person2.getAge() == person2_1.getAge());
+ }
+
+}
Added: core/trunk/envers/src/test/resources/hibernate.test.session-cfg.xml
===================================================================
--- core/trunk/envers/src/test/resources/hibernate.test.session-cfg.xml (rev 0)
+++ core/trunk/envers/src/test/resources/hibernate.test.session-cfg.xml 2010-07-05 17:04:29 UTC (rev 19899)
@@ -0,0 +1,46 @@
+<?xml version='1.0' encoding='utf-8'?>
+<!DOCTYPE hibernate-configuration PUBLIC
+ "-//Hibernate/Hibernate Configuration DTD//EN"
+ "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
+
+<hibernate-configuration>
+ <session-factory>
+ <property name="hbm2ddl.auto">create-drop</property>
+
+ <property name="show_sql">false</property>
+ <property name="format_sql">false</property>
+
+ <property name="dialect">org.hibernate.dialect.H2Dialect</property>
+ <property name="connection.url">jdbc:h2:mem:envers</property>
+ <property name="connection.driver_class">org.h2.Driver</property>
+ <property name="connection.username">sa</property>
+ <property name="connection.password"></property>
+
+ <!--<property name="dialect">org.hibernate.dialect.MySQL5InnoDBDialect</property>-->
+ <!--<property name="connection.url">jdbc:mysql:///hibernate_tests?useUnicode=true&characterEncoding=UTF-8</property>-->
+ <!--<property name="connection.driver_class">com.mysql.jdbc.Driver</property>-->
+ <!--<property name="connection.username">root</property>-->
+ <!--<property name="connection.password"></property>-->
+
+ <!--<property name="hibernate.jdbc.batch_size">100</property>-->
+
+ <event type="post-insert">
+ <listener class="org.hibernate.envers.event.AuditEventListener" />
+ </event>
+ <event type="post-update">
+ <listener class="org.hibernate.envers.event.AuditEventListener" />
+ </event>
+ <event type="post-delete">
+ <listener class="org.hibernate.envers.event.AuditEventListener" />
+ </event>
+ <event type="pre-collection-update">
+ <listener class="org.hibernate.envers.event.AuditEventListener" />
+ </event>
+ <event type="pre-collection-remove">
+ <listener class="org.hibernate.envers.event.AuditEventListener" />
+ </event>
+ <event type="post-collection-recreate">
+ <listener class="org.hibernate.envers.event.AuditEventListener" />
+ </event>
+ </session-factory>
+</hibernate-configuration>
Added: core/trunk/envers/src/test/resources/mappings/entityNames/auditedEntity/mappings.hbm.xml
===================================================================
--- core/trunk/envers/src/test/resources/mappings/entityNames/auditedEntity/mappings.hbm.xml (rev 0)
+++ core/trunk/envers/src/test/resources/mappings/entityNames/auditedEntity/mappings.hbm.xml 2010-07-05 17:04:29 UTC (rev 19899)
@@ -0,0 +1,18 @@
+<?xml version="1.0"?>
+<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
+<hibernate-mapping>
+
+ <class name="org.hibernate.envers.test.entityNames.auditedEntity.Person" entity-name="Personaje">
+
+ <id name="id" column="ID_person" type="long" >
+ <generator class="native" />
+ </id>
+
+ <property name="name" type="string" length="255"
+ column="NAME" not-null="true" />
+
+ <property name="age" type="int" column="AGE"/>
+
+ </class>
+
+</hibernate-mapping>
Added: core/trunk/envers/src/test/resources/mappings/entityNames/manyToManyAudited/mappings.hbm.xml
===================================================================
--- core/trunk/envers/src/test/resources/mappings/entityNames/manyToManyAudited/mappings.hbm.xml (rev 0)
+++ core/trunk/envers/src/test/resources/mappings/entityNames/manyToManyAudited/mappings.hbm.xml 2010-07-05 17:04:29 UTC (rev 19899)
@@ -0,0 +1,40 @@
+<?xml version="1.0"?>
+<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
+<hibernate-mapping>
+
+ <class name="org.hibernate.envers.test.entityNames.manyToManyAudited.Person"
+ entity-name="Personaje">
+
+ <id name="id" column="ID_PERSON" type="long">
+ <generator class="native" />
+ </id>
+
+ <property name="name" type="string" length="255" column="NAME"
+ not-null="true" />
+
+ <property name="age" type="int" column="AGE" />
+
+ <bag name="cars" inverse="true" table="PERSON_CAR" >
+ <key column="ID_CAR" />
+ <many-to-many
+ class="org.hibernate.envers.test.entityNames.manyToManyAudited.Car" column="ID_PERSON"/>
+ </bag>
+
+ </class>
+
+ <class name="org.hibernate.envers.test.entityNames.manyToManyAudited.Car">
+
+ <id name="id" column="ID_CAR" type="long">
+ <generator class="native" />
+ </id>
+
+ <property name="number" type="int" not-null="true" />
+
+ <bag name="owners" cascade="all" table="PERSON_CAR" >
+ <key column="ID_PERSON" />
+ <many-to-many entity-name="Personaje" column="ID_CAR"/>
+ </bag>
+
+ </class>
+
+</hibernate-mapping>
Added: core/trunk/envers/src/test/resources/mappings/entityNames/oneToManyAudited/mappings.hbm.xml
===================================================================
--- core/trunk/envers/src/test/resources/mappings/entityNames/oneToManyAudited/mappings.hbm.xml (rev 0)
+++ core/trunk/envers/src/test/resources/mappings/entityNames/oneToManyAudited/mappings.hbm.xml 2010-07-05 17:04:29 UTC (rev 19899)
@@ -0,0 +1,48 @@
+<?xml version="1.0"?>
+<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
+<hibernate-mapping>
+
+ <class name="org.hibernate.envers.test.entityNames.oneToManyAudited.Person" entity-name="Personaje">
+
+ <id name="id" column="ID_PERSON" type="long" >
+ <generator class="native" />
+ </id>
+
+ <property name="name" type="string" length="255"
+ column="NAME" not-null="true" />
+
+ <property name="age" type="int" column="AGE"/>
+
+ </class>
+
+ <class name="org.hibernate.envers.test.entityNames.oneToManyAudited.Car" >
+
+ <id name="id" column="ID_CAR" type="long">
+ <generator class="native" />
+ </id>
+
+ <property name="number" type="int" column="int" not-null="true" />
+
+ <bag name="owners" cascade="save-update">
+ <key column="ID_GARAGE" not-null="true" update="false" />
+ <one-to-many entity-name="Personaje"/>
+ </bag>
+
+ </class>
+
+<!-- <class name="org.hibernate.envers.test.entityNames.oneToManyAudited.Garage" >-->
+<!---->
+<!-- <id name="id" column="ID_GARAGE" type="long">-->
+<!-- <generator class="native" />-->
+<!-- </id>-->
+<!---->
+<!-- <property name="name" type="int" column="int" not-null="true" />-->
+<!---->
+<!-- <bag name="cars" cascade="save-update">-->
+<!-- <key column="ID_GARAGE" not-null="true" update="false" />-->
+<!-- <one-to-many class="org.hibernate.envers.test.entityNames.oneToManyAudited.Car" />-->
+<!-- </bag>-->
+<!-- -->
+<!-- </class> -->
+
+</hibernate-mapping>
Added: core/trunk/envers/src/test/resources/mappings/entityNames/oneToManyNotAudited/mappings.hbm.xml
===================================================================
--- core/trunk/envers/src/test/resources/mappings/entityNames/oneToManyNotAudited/mappings.hbm.xml (rev 0)
+++ core/trunk/envers/src/test/resources/mappings/entityNames/oneToManyNotAudited/mappings.hbm.xml 2010-07-05 17:04:29 UTC (rev 19899)
@@ -0,0 +1,34 @@
+<?xml version="1.0"?>
+<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
+<hibernate-mapping>
+
+ <class name="org.hibernate.envers.test.entityNames.oneToManyNotAudited.Person" entity-name="Personaje">
+
+ <id name="id" column="ID_PERSON" type="long" >
+ <generator class="native" />
+ </id>
+
+ <property name="name" type="string" length="255"
+ column="NAME" not-null="true" />
+
+ <property name="age" type="int" column="AGE"/>
+
+ </class>
+
+ <class name="org.hibernate.envers.test.entityNames.oneToManyNotAudited.Car" >
+
+ <id name="id" column="ID_CAR" type="long">
+ <generator class="native" />
+ </id>
+
+ <property name="number" type="int" column="int" not-null="true" />
+
+ <bag name="owners" cascade="save-update">
+ <key column="ID_GARAGE" not-null="true" update="false" />
+ <one-to-many entity-name="Personaje"/>
+ </bag>
+
+ </class>
+
+
+</hibernate-mapping>
Added: core/trunk/envers/src/test/resources/mappings/entityNames/singleAssociatedAudited/mappings.hbm.xml
===================================================================
--- core/trunk/envers/src/test/resources/mappings/entityNames/singleAssociatedAudited/mappings.hbm.xml (rev 0)
+++ core/trunk/envers/src/test/resources/mappings/entityNames/singleAssociatedAudited/mappings.hbm.xml 2010-07-05 17:04:29 UTC (rev 19899)
@@ -0,0 +1,30 @@
+<?xml version="1.0"?>
+<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
+<hibernate-mapping>
+
+ <class name="org.hibernate.envers.test.entityNames.singleAssociatedAudited.Person" entity-name="Personaje">
+
+ <id name="id" column="ID_person" type="long" >
+ <generator class="native" />
+ </id>
+
+ <property name="name" type="string" length="255"
+ column="NAME" not-null="true" />
+
+ <property name="age" type="int" column="AGE"/>
+
+ </class>
+
+ <class name="org.hibernate.envers.test.entityNames.singleAssociatedAudited.Car" >
+
+ <id name="id" column="ID_BED" type="long">
+ <generator class="native" />
+ </id>
+
+ <property name="number" type="int" column="int" not-null="true" />
+
+ <many-to-one name="owner" entity-name="Personaje"/>
+
+ </class>
+
+</hibernate-mapping>
Added: core/trunk/envers/src/test/resources/mappings/entityNames/singleAssociatedNotAudited/mappings.hbm.xml
===================================================================
--- core/trunk/envers/src/test/resources/mappings/entityNames/singleAssociatedNotAudited/mappings.hbm.xml (rev 0)
+++ core/trunk/envers/src/test/resources/mappings/entityNames/singleAssociatedNotAudited/mappings.hbm.xml 2010-07-05 17:04:29 UTC (rev 19899)
@@ -0,0 +1,30 @@
+<?xml version="1.0"?>
+<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
+<hibernate-mapping>
+
+ <class name="org.hibernate.envers.test.entityNames.singleAssociatedNotAudited.Person" entity-name="Personaje">
+
+ <id name="id" column="ID_person" type="long" >
+ <generator class="native" />
+ </id>
+
+ <property name="name" type="string" length="255"
+ column="NAME" not-null="true" />
+
+ <property name="age" type="int" column="AGE"/>
+
+ </class>
+
+ <class name="org.hibernate.envers.test.entityNames.singleAssociatedNotAudited.Car" >
+
+ <id name="id" column="ID_BED" type="long">
+ <generator class="native" />
+ </id>
+
+ <property name="number" type="int" column="int" not-null="true" />
+
+ <many-to-one name="owner" entity-name="Personaje"/>
+
+ </class>
+
+</hibernate-mapping>
Modified: core/trunk/envers/src/test/resources/testng.xml
===================================================================
--- core/trunk/envers/src/test/resources/testng.xml 2010-07-05 16:52:21 UTC (rev 19898)
+++ core/trunk/envers/src/test/resources/testng.xml 2010-07-05 17:04:29 UTC (rev 19899)
@@ -67,7 +67,13 @@
<package name="org.hibernate.envers.test.integration.secondary" />
<package name="org.hibernate.envers.test.integration.secondary.ids" />
<package name="org.hibernate.envers.test.integration.serialization" />
- <package name="org.hibernate.envers.test.integration.superclass" />
+ <package name="org.hibernate.envers.test.integration.superclass" />
+ <package name="org.hibernate.envers.test.entityNames.auditedEntity" />
+ <package name="org.hibernate.envers.test.entityNames.manyToManyAudited" />
+ <package name="org.hibernate.envers.test.entityNames.oneToManyAudited" />
+ <package name="org.hibernate.envers.test.entityNames.oneToManyNotAudited" />
+ <package name="org.hibernate.envers.test.entityNames.singleAssociatedAudited" />
+ <package name="org.hibernate.envers.test.entityNames.singleAssociatedNotAudited" />
'>
]>
14 years, 7 months
Hibernate SVN: r19898 - in search/trunk: hibernate-search and 46 other directories.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2010-07-05 12:52:21 -0400 (Mon, 05 Jul 2010)
New Revision: 19898
Removed:
search/trunk/hibernate-search-testing/src/main/java/org/hibernate/search/test/TestCase.java
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/TestCase.java
Modified:
search/trunk/hibernate-search-testing/pom.xml
search/trunk/hibernate-search-testing/src/main/java/org/hibernate/search/test/SearchTestCase.java
search/trunk/hibernate-search/pom.xml
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/FSDirectoryTest.java
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/PurgeTest.java
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/RamDirectoryTest.java
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/SearchTestCase.java
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/TransactionTest.java
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/analyzer/AnalyzerTest.java
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/analyzer/DoubleAnalyzerTest.java
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/analyzer/inheritance/AnalyzerInheritanceTest.java
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/analyzer/solr/SolrAnalyzerTest.java
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/backend/SyncBackendLongWorklistsStressTest.java
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/batchindexing/AvoidDuplicatesTest.java
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/bridge/BridgeTest.java
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/bridge/ClassBridgeAndProjectionTest.java
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/bridge/ClassBridgeTest.java
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/bridge/UnresolvedBridgeTest.java
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/classloading/NoAnnotationsTest.java
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/compression/CompressionTest.java
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/configuration/LuceneIndexingParametersTest.java
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/configuration/ProgrammaticMappingTest.java
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/configuration/ShardsConfigurationTest.java
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/directoryProvider/FSSlaveAndMasterDPTest.java
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/directoryProvider/MultipleSFTestCase.java
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/embedded/EmbeddedTest.java
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/embedded/doubleinsert/DoubleInsertEmbeddedTest.java
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/embedded/graph/RecursiveGraphTest.java
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/embedded/nested/NestedEmbeddedTest.java
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/embedded/nested/containedIn/LazyM2OContainedInTest.java
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/embedded/nested/containedIn/NestedContainedInTest.java
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/engine/LazyCollectionsUpdatingTest.java
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/engine/RollbackTransactionTest.java
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/errorhandling/LuceneErrorHandlingTest.java
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/fieldAccess/FieldAccessTest.java
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/filter/FilterTest.java
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/id/EmbeddedIdTest.java
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/id/ImplicitIdTest.java
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/indexingStrategy/ManualIndexingStrategyTest.java
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/inheritance/InheritanceTest.java
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/jgroups/common/JGroupsCommonTest.java
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/jgroups/common/MultipleSessionsSearchTestCase.java
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/jgroups/master/JGroupsMasterTest.java
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/jgroups/slave/JGroupsSlaveTest.java
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/jms/master/JMSMasterTest.java
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/jms/slave/JMSSlaveTest.java
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/jmx/ConfigInfoMBeanTest.java
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/jmx/IndexCtrlMBeanTest.java
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/jmx/NoMBeansEnabledTest.java
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/optimizer/OptimizerPerfTest.java
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/perf/IndexTestDontRun.java
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/query/LuceneQuerySortTest.java
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/query/LuceneQueryTest.java
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/query/MultiClassesQueryLoaderTest.java
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/query/ProjectionQueryTest.java
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/query/QueryLoaderTest.java
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/query/QueryUnindexedEntityTest.java
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/query/TermVectorTest.java
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/query/boost/DynamicBoostingTest.java
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/query/boost/FieldBoostTest.java
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/query/criteria/MixedCriteriaTest.java
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/query/dsl/DSLTest.java
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/query/explain/ExplanationTest.java
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/reader/ReaderPerfTestCase.java
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/reader/functionality/FilterOnDirectoryTest.java
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/reader/performance/ReaderPerformance.java
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/session/MassIndexTest.java
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/session/MassIndexUsingManualFlushTest.java
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/session/OptimizeTest.java
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/session/SessionTest.java
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/shards/DirectoryProviderForQueryTest.java
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/shards/ShardsTest.java
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/similarity/SimilarityTest.java
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/worker/ConcurrencyTest.java
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/worker/WorkerTestCase.java
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/worker/duplication/WorkDuplicationTest.java
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/worker/duplication/WorkSequencesTest.java
search/trunk/pom.xml
Log:
HSEARCH-538 (Allow Hibernate Search to use the @FailureExpected test framework)
* hibernate-search depends now on hibernate-testing
* SearchTestCase extends now HibernateTestCase
* Removed obsolete org.hibernate.search.test.TestCase
* Renamed getMappings() to getAnnoatedClasses() in the tests to align with HibernateTestCase
Modified: search/trunk/hibernate-search/pom.xml
===================================================================
--- search/trunk/hibernate-search/pom.xml 2010-07-05 14:46:01 UTC (rev 19897)
+++ search/trunk/hibernate-search/pom.xml 2010-07-05 16:52:21 UTC (rev 19898)
@@ -89,6 +89,12 @@
<scope>test</scope>
</dependency>
<dependency>
+ <groupId>org.hibernate</groupId>
+ <artifactId>hibernate-testing</artifactId>
+ <version>${hibernateVersion}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
Modified: search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/FSDirectoryTest.java
===================================================================
--- search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/FSDirectoryTest.java 2010-07-05 14:46:01 UTC (rev 19897)
+++ search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/FSDirectoryTest.java 2010-07-05 16:52:21 UTC (rev 19898)
@@ -53,19 +53,19 @@
File sub = getBaseIndexDir();
sub.mkdir();
File[] files = sub.listFiles();
- for (File file : files) {
+ for ( File file : files ) {
if ( file.isDirectory() ) {
FileHelper.delete( file );
}
}
- //super.setUp(); //we need a fresh session factory each time for index set up
- buildSessionFactory( getMappings(), getAnnotatedPackages(), getXmlFiles() );
+ super.setUp();
}
protected void tearDown() throws Exception {
super.tearDown();
File sub = getBaseIndexDir();
FileHelper.delete( sub );
+ setCfg( null ); // we need a fresh session factory each time for index set up
}
public void testEventIntegration() throws Exception {
@@ -100,7 +100,7 @@
s = getSessions().openSession();
s.getTransaction().begin();
- Document entity = (Document) s.get( Document.class, Long.valueOf( 1 ) );
+ Document entity = ( Document ) s.get( Document.class, Long.valueOf( 1 ) );
entity.setSummary( "Object/relational mapping with EJB3" );
s.persist( new Document( "Seam in Action", "", "blah blah blah blah" ) );
s.getTransaction().commit();
@@ -181,7 +181,7 @@
s = getSessions().openSession();
s.getTransaction().begin();
List list = s.createQuery( "from Document" ).list();
- for (Document document : (List<Document>) list) {
+ for ( Document document : ( List<Document> ) list ) {
s.delete( document );
}
s.getTransaction().commit();
@@ -210,7 +210,7 @@
dir.close();
}
- protected Class<?>[] getMappings() {
+ protected Class<?>[] getAnnotatedClasses() {
return new Class[] {
Document.class
};
Modified: search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/PurgeTest.java
===================================================================
--- search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/PurgeTest.java 2010-07-05 14:46:01 UTC (rev 19897)
+++ search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/PurgeTest.java 2010-07-05 16:52:21 UTC (rev 19898)
@@ -126,7 +126,7 @@
s.close();
}
- protected Class<?>[] getMappings() {
+ protected Class<?>[] getAnnotatedClasses() {
return new Class[] {
Book.class,
AlternateBook.class,
Modified: search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/RamDirectoryTest.java
===================================================================
--- search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/RamDirectoryTest.java 2010-07-05 14:46:01 UTC (rev 19897)
+++ search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/RamDirectoryTest.java 2010-07-05 16:52:21 UTC (rev 19898)
@@ -82,7 +82,7 @@
}
}
- protected Class<?>[] getMappings() {
+ protected Class<?>[] getAnnotatedClasses() {
return new Class[]{
Document.class,
AlternateDocument.class
Modified: search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/SearchTestCase.java
===================================================================
--- search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/SearchTestCase.java 2010-07-05 14:46:01 UTC (rev 19897)
+++ search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/SearchTestCase.java 2010-07-05 16:52:21 UTC (rev 19898)
@@ -1,8 +1,7 @@
-/* $Id$
- *
+/*
* Hibernate, Relational Persistence for Idiomatic Java
*
- * Copyright (c) 2009, Red Hat, Inc. and/or its affiliates or third-party contributors as
+ * Copyright (c) 2010, Red Hat, Inc. and/or its affiliates 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, Inc.
@@ -38,14 +37,14 @@
import org.slf4j.Logger;
import org.hibernate.HibernateException;
+import org.hibernate.Interceptor;
import org.hibernate.Session;
+import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.cfg.Configuration;
-import org.hibernate.dialect.Dialect;
import org.hibernate.event.PostInsertEventListener;
import org.hibernate.impl.SessionFactoryImpl;
-import org.hibernate.search.Environment;
import org.hibernate.search.FullTextSession;
import org.hibernate.search.Search;
import org.hibernate.search.SearchFactory;
@@ -53,14 +52,15 @@
import org.hibernate.search.engine.SearchFactoryImplementor;
import org.hibernate.search.event.FullTextIndexEventListener;
import org.hibernate.search.store.RAMDirectoryProvider;
-import org.hibernate.tool.hbm2ddl.SchemaExport;
+import org.hibernate.test.annotations.HibernateTestCase;
/**
* Base class for Hibernate Search unit tests.
*
* @author Emmanuel Bernard
+ * @author Hardy Ferentschik
*/
-public abstract class SearchTestCase extends TestCase {
+public abstract class SearchTestCase extends HibernateTestCase {
private static final Logger log = org.hibernate.search.util.LoggerFactory.make();
@@ -69,6 +69,9 @@
public static final Analyzer simpleAnalyzer = new SimpleAnalyzer();
public static final Analyzer keywordAnalyzer = new KeywordAnalyzer();
+ protected static SessionFactory sessions;
+ protected Session session;
+
private static File indexDir;
private SearchFactoryImplementor searchFactory;
@@ -83,21 +86,80 @@
log.debug( "Using {} as index directory.", indexDir.getAbsolutePath() );
}
- protected void setUp() throws Exception {
- buildSessionFactory( getMappings(), getAnnotatedPackages(), getXmlFiles() );
- ensureIndexesAreEmpty();
+ public SearchTestCase() {
+ super();
}
- protected void tearDown() throws Exception {
- super.tearDown();
- SchemaExport export = new SchemaExport( cfg );
- export.drop( false, true );
- if ( searchFactory != null ) {
- searchFactory.close();
+ public SearchTestCase(String x) {
+ super( x );
+ }
+
+ @Override
+ protected void handleUnclosedResources() {
+ if ( session != null && session.isOpen() ) {
+ if ( session.isConnected() ) {
+ session.doWork( new RollbackWork() );
+ }
+ session.close();
+ session = null;
+ fail( "unclosed session" );
}
- searchFactory = null;
+ else {
+ session = null;
+ }
}
+ @Override
+ protected void closeResources() {
+ try {
+ if ( session != null && session.isOpen() ) {
+ if ( session.isConnected() ) {
+ session.doWork( new RollbackWork() );
+ }
+ session.close();
+ }
+ }
+ catch ( Exception ignore ) {
+ }
+ try {
+ if ( sessions != null ) {
+ sessions.close();
+ sessions = null;
+ }
+ }
+ catch ( Exception ignore ) {
+ }
+ }
+
+ public Session openSession() throws HibernateException {
+ session = getSessions().openSession();
+ return session;
+ }
+
+ public Session openSession(Interceptor interceptor) throws HibernateException {
+ session = getSessions().openSession( interceptor );
+ return session;
+ }
+
+ protected void setSessions(SessionFactory sessions) {
+ SearchTestCase.sessions = sessions;
+ }
+
+ protected SessionFactory getSessions() {
+ return sessions;
+ }
+
+ protected void configure(Configuration cfg) {
+ super.configure( cfg );
+
+ cfg.setProperty( "hibernate.search.default.directory_provider", RAMDirectoryProvider.class.getName() );
+ cfg.setProperty( "hibernate.search.default.indexBase", indexDir.getAbsolutePath() );
+ cfg.setProperty( org.hibernate.search.Environment.ANALYZER_CLASS, StopAnalyzer.class.getName() );
+
+ cfg.setProperty( "hibernate.search.default.transaction.merge_factor", "100" );
+ cfg.setProperty( "hibernate.search.default.batch.max_buffered_docs", "1000" );
+ }
+
protected Directory getDirectory(Class<?> clazz) {
return getLuceneEventListener().getSearchFactoryImplementor().getDirectoryProviders( clazz )[0].getDirectory();
}
@@ -119,6 +181,11 @@
return listener;
}
+ protected void setUp() throws Exception {
+ super.setUp();
+ ensureIndexesAreEmpty();
+ }
+
protected void ensureIndexesAreEmpty() {
if ( "jms".equals( getCfg().getProperty( "hibernate.search.worker.backend" ) ) ) {
log.debug( "JMS based test. Skipping index emptying" );
@@ -127,7 +194,7 @@
FullTextSession s = Search.getFullTextSession( openSession() );
Transaction tx;
tx = s.beginTransaction();
- for ( Class<?> clazz : getMappings() ) {
+ for ( Class<?> clazz : getAnnotatedClasses() ) {
if ( clazz.getAnnotation( Indexed.class ) != null ) {
s.purgeAll( clazz );
}
@@ -146,19 +213,11 @@
return searchFactory;
}
- protected void configure(Configuration cfg) {
- cfg.setProperty( "hibernate.search.default.directory_provider", RAMDirectoryProvider.class.getName() );
- cfg.setProperty( "hibernate.search.default.indexBase", indexDir.getAbsolutePath() );
- cfg.setProperty( Environment.ANALYZER_CLASS, StopAnalyzer.class.getName() );
- cfg.setProperty( "hibernate.search.default.transaction.merge_factor", "100" );
- cfg.setProperty( "hibernate.search.default.batch.max_buffered_docs", "1000" );
- }
-
protected File getBaseIndexDir() {
return indexDir;
}
- protected void buildSessionFactory(Class<?>[] classes, String[] packages, String[] xmlFiles) throws Exception {
+ protected void buildConfiguration() throws Exception {
if ( getSessions() != null ) {
getSessions().close();
}
@@ -168,17 +227,16 @@
if ( recreateSchema() ) {
cfg.setProperty( org.hibernate.cfg.Environment.HBM2DDL_AUTO, "create-drop" );
}
- for ( String aPackage : packages ) {
+ for ( String aPackage : getAnnotatedPackages() ) {
( ( AnnotationConfiguration ) getCfg() ).addPackage( aPackage );
}
- for ( Class<?> aClass : classes ) {
+ for ( Class<?> aClass : getAnnotatedClasses() ) {
( ( AnnotationConfiguration ) getCfg() ).addAnnotatedClass( aClass );
}
- for ( String xmlFile : xmlFiles ) {
+ for ( String xmlFile : getXmlFiles() ) {
InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream( xmlFile );
getCfg().addInputStream( is );
}
- setDialect( Dialect.getDialect() );
setSessions( getCfg().buildSessionFactory( /*new TestInterceptor()*/ ) );
}
catch ( Exception e ) {
@@ -187,16 +245,10 @@
}
}
- protected abstract Class<?>[] getMappings();
-
protected String[] getAnnotatedPackages() {
return new String[] { };
}
- protected static File getIndexDir() {
- return indexDir;
- }
-
public static Version getTargetLuceneVersion() {
return Version.LUCENE_29;
}
Deleted: search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/TestCase.java
===================================================================
--- search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/TestCase.java 2010-07-05 14:46:01 UTC (rev 19897)
+++ search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/TestCase.java 2010-07-05 16:52:21 UTC (rev 19898)
@@ -1,196 +0,0 @@
-/* $Id$
- *
- * Hibernate, Relational Persistence for Idiomatic Java
- *
- * Copyright (c) 2009, Red Hat, Inc. and/or its affiliates 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, Inc.
- *
- * 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.search.test;
-
-import java.io.InputStream;
-
-import org.apache.lucene.analysis.StopAnalyzer;
-
-import org.hibernate.HibernateException;
-import org.hibernate.Interceptor;
-import org.hibernate.Session;
-import org.hibernate.SessionFactory;
-import org.hibernate.search.store.RAMDirectoryProvider;
-import org.hibernate.cfg.Configuration;
-import org.hibernate.cfg.Environment;
-import org.hibernate.dialect.Dialect;
-import org.hibernate.event.FlushEventListener;
-import org.hibernate.event.def.DefaultFlushEventListener;
-import org.hibernate.search.event.FullTextIndexEventListener;
-
-/**
- * A modified base class for tests without annotations.
- *
- * @author Hardy Ferentschik
- */
-public abstract class TestCase extends junit.framework.TestCase {
-
- protected static SessionFactory sessions;
- protected static Configuration cfg;
- protected static Dialect dialect;
- protected static Class lastTestClass;
- protected Session session;
-
- public TestCase() {
- super();
- }
-
- public TestCase(String x) {
- super( x );
- }
-
- protected void buildSessionFactory(String[] xmlFiles) throws Exception {
-
- if ( getSessions() != null ) {
- getSessions().close();
- }
- try {
- setCfg( new Configuration() );
- configure( cfg );
- if ( recreateSchema() ) {
- cfg.setProperty( Environment.HBM2DDL_AUTO, "create-drop" );
- }
- for ( String xmlFile : xmlFiles ) {
- InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream( xmlFile );
- getCfg().addInputStream( is );
- }
- setDialect( Dialect.getDialect() );
- setSessions( getCfg().buildSessionFactory() );
- }
- catch ( Exception e ) {
- e.printStackTrace();
- throw e;
- }
- }
-
- protected void setUp() throws Exception {
- if ( getSessions() == null || getSessions().isClosed() || lastTestClass != getClass() ) {
- buildSessionFactory( getXmlFiles() );
- lastTestClass = getClass();
- }
- }
-
- protected void tearDown() throws Exception {
- super.tearDown();
- if ( sessions != null ) {
- sessions.close();
- }
- }
-
- protected void runTest() throws Throwable {
- try {
- super.runTest();
- if ( session != null && session.isOpen() ) {
- if ( session.isConnected() ) {
- session.connection().rollback();
- }
- session.close();
- session = null;
- fail( "unclosed session" );
- }
- else {
- session = null;
- }
- }
- catch ( Throwable e ) {
- try {
- if ( session != null && session.isOpen() ) {
- if ( session.isConnected() ) {
- session.connection().rollback();
- }
- session.close();
- }
- }
- catch ( Exception ignore ) {
- }
- try {
- if ( sessions != null ) {
- sessions.close();
- sessions = null;
- }
- }
- catch ( Exception ignore ) {
- }
- throw e;
- }
- }
-
- public Session openSession() throws HibernateException {
- session = getSessions().openSession();
- return session;
- }
-
- public Session openSession(Interceptor interceptor) throws HibernateException {
- session = getSessions().openSession( interceptor );
- return session;
- }
-
- protected String[] getXmlFiles() {
- return new String[] { };
- }
-
- protected void setSessions(SessionFactory sessions) {
- TestCase.sessions = sessions;
- }
-
- protected SessionFactory getSessions() {
- return sessions;
- }
-
- protected void setDialect(Dialect dialect) {
- TestCase.dialect = dialect;
- }
-
- protected Dialect getDialect() {
- return dialect;
- }
-
- protected static void setCfg(Configuration cfg) {
- TestCase.cfg = cfg;
- }
-
- protected static Configuration getCfg() {
- return cfg;
- }
-
- protected void configure(Configuration cfg) {
- //needs to register all event listeners:
- cfg.setListener( "post-update", "org.hibernate.search.event.FullTextIndexEventListener" );
- cfg.setListener( "post-insert", "org.hibernate.search.event.FullTextIndexEventListener" );
- cfg.setListener( "post-delete", "org.hibernate.search.event.FullTextIndexEventListener" );
- cfg.setListener( "post-collection-recreate", "org.hibernate.search.event.FullTextIndexEventListener" );
- cfg.setListener( "post-collection-remove", "org.hibernate.search.event.FullTextIndexEventListener" );
- cfg.setListener( "post-collection-update", "org.hibernate.search.event.FullTextIndexEventListener" );
-
- cfg.setListeners( "flush", new FlushEventListener[]{new DefaultFlushEventListener(), new FullTextIndexEventListener()} );
-
- cfg.setProperty( "hibernate.search.default.directory_provider", RAMDirectoryProvider.class.getName() );
- cfg.setProperty( org.hibernate.search.Environment.ANALYZER_CLASS, StopAnalyzer.class.getName() );
- }
-
- protected boolean recreateSchema() {
- return true;
- }
-}
Modified: search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/TransactionTest.java
===================================================================
--- search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/TransactionTest.java 2010-07-05 14:46:01 UTC (rev 19897)
+++ search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/TransactionTest.java 2010-07-05 16:52:21 UTC (rev 19898)
@@ -89,7 +89,7 @@
}
}
- protected Class<?>[] getMappings() {
+ protected Class<?>[] getAnnotatedClasses() {
return new Class[] { Document.class };
}
Modified: search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/analyzer/AnalyzerTest.java
===================================================================
--- search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/analyzer/AnalyzerTest.java 2010-07-05 14:46:01 UTC (rev 19897)
+++ search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/analyzer/AnalyzerTest.java 2010-07-05 16:52:21 UTC (rev 19898)
@@ -193,7 +193,7 @@
session.close();
}
- protected Class<?>[] getMappings() {
+ protected Class<?>[] getAnnotatedClasses() {
return new Class[] { MyEntity.class, Article.class };
}
}
Modified: search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/analyzer/DoubleAnalyzerTest.java
===================================================================
--- search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/analyzer/DoubleAnalyzerTest.java 2010-07-05 14:46:01 UTC (rev 19897)
+++ search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/analyzer/DoubleAnalyzerTest.java 2010-07-05 16:52:21 UTC (rev 19898)
@@ -44,7 +44,7 @@
public static final Logger log = LoggerFactory.make();
- protected Class<?>[] getMappings() {
+ protected Class<?>[] getAnnotatedClasses() {
return new Class[] { MyEntity.class, AlarmEntity.class };
}
Modified: search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/analyzer/inheritance/AnalyzerInheritanceTest.java
===================================================================
--- search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/analyzer/inheritance/AnalyzerInheritanceTest.java 2010-07-05 14:46:01 UTC (rev 19897)
+++ search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/analyzer/inheritance/AnalyzerInheritanceTest.java 2010-07-05 16:52:21 UTC (rev 19898)
@@ -100,7 +100,7 @@
}
- protected Class<?>[] getMappings() {
+ protected Class<?>[] getAnnotatedClasses() {
return new Class[] { SubClass.class };
}
}
Modified: search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/analyzer/solr/SolrAnalyzerTest.java
===================================================================
--- search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/analyzer/solr/SolrAnalyzerTest.java 2010-07-05 14:46:01 UTC (rev 19897)
+++ search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/analyzer/solr/SolrAnalyzerTest.java 2010-07-05 16:52:21 UTC (rev 19898)
@@ -183,7 +183,7 @@
fts.close();
}
- protected Class<?>[] getMappings() {
+ protected Class<?>[] getAnnotatedClasses() {
return new Class[] {
Team.class
};
Modified: search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/backend/SyncBackendLongWorklistsStressTest.java
===================================================================
--- search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/backend/SyncBackendLongWorklistsStressTest.java 2010-07-05 14:46:01 UTC (rev 19897)
+++ search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/backend/SyncBackendLongWorklistsStressTest.java 2010-07-05 16:52:21 UTC (rev 19898)
@@ -1,8 +1,7 @@
-/* $Id$
- *
+/*
* Hibernate, Relational Persistence for Idiomatic Java
*
- * Copyright (c) 2009, Red Hat, Inc. and/or its affiliates or third-party contributors as
+ * Copyright (c) 2010, Red Hat, Inc. and/or its affiliates 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, Inc.
@@ -27,9 +26,9 @@
import java.io.File;
import junit.framework.Assert;
-
import org.apache.lucene.analysis.StopAnalyzer;
import org.apache.lucene.search.MatchAllDocsQuery;
+
import org.hibernate.Transaction;
import org.hibernate.criterion.Projections;
import org.hibernate.search.Environment;
@@ -41,31 +40,33 @@
import org.hibernate.search.util.FileHelper;
public class SyncBackendLongWorklistsStressTest extends SearchTestCase {
-
+
/* needs to be sensibly higher than org.hibernate.search.batchindexing.Executors.QUEUE_MAX_LENGTH */
private static final int NUM_SAVED_ENTITIES = 3000;
public void testWorkLongerThanMaxQueueSize() throws Exception {
FullTextSession s = Search.getFullTextSession( openSession() );
- for (int i = 0; i < NUM_SAVED_ENTITIES; i++ ) {
+ for ( int i = 0; i < NUM_SAVED_ENTITIES; i++ ) {
Transaction tx = s.beginTransaction();
- Clock clock = new Clock( i, "brand num° " + i);
+ Clock clock = new Clock( i, "brand num° " + i );
s.persist( clock );
tx.commit();
s.clear();
}
-
+
Transaction tx = s.beginTransaction();
// count of entities in database needs to be checked before SF is closed (HSQLDB will forget the entities)
- Number count = (Number) s.createCriteria( Clock.class ).setProjection( Projections.rowCount() ).uniqueResult();
+ Number count = ( Number ) s.createCriteria( Clock.class )
+ .setProjection( Projections.rowCount() )
+ .uniqueResult();
Assert.assertEquals( NUM_SAVED_ENTITIES, count.intValue() );
tx.commit();
s.close();
-
+
//we need to close the session to wait for all async work to be flushed
sessions.close();
- buildSessionFactory( getMappings(), getAnnotatedPackages(), getXmlFiles() );
-
+ buildConfiguration();
+
s = Search.getFullTextSession( openSession() );
tx = s.beginTransaction();
int fullTextCount = s.createFullTextQuery( new MatchAllDocsQuery(), Clock.class ).getResultSize();
@@ -75,10 +76,10 @@
}
@Override
- protected Class<?>[] getMappings() {
+ protected Class<?>[] getAnnotatedClasses() {
return new Class[] { Clock.class };
}
-
+
protected void configure(org.hibernate.cfg.Configuration cfg) {
super.configure( cfg );
File sub = getBaseIndexDir();
@@ -89,12 +90,11 @@
cfg.setProperty( "hibernate.show_sql", "false" );
cfg.setProperty( "hibernate.format_sql", "false" );
}
-
+
protected void tearDown() throws Exception {
super.tearDown();
File sub = getBaseIndexDir();
FileHelper.delete( sub );
}
-
}
Modified: search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/batchindexing/AvoidDuplicatesTest.java
===================================================================
--- search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/batchindexing/AvoidDuplicatesTest.java 2010-07-05 14:46:01 UTC (rev 19897)
+++ search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/batchindexing/AvoidDuplicatesTest.java 2010-07-05 16:52:21 UTC (rev 19898)
@@ -25,8 +25,8 @@
package org.hibernate.search.test.batchindexing;
import junit.framework.Assert;
+import org.apache.lucene.search.MatchAllDocsQuery;
-import org.apache.lucene.search.MatchAllDocsQuery;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.search.FullTextQuery;
@@ -36,34 +36,34 @@
import org.hibernate.search.test.SearchTestCase;
public class AvoidDuplicatesTest extends SearchTestCase {
-
+
@Override
public void setUp() throws Exception {
super.setUp();
Session session = openSession();
Transaction transaction = session.beginTransaction();
-
+
Nation italy = new Nation( "Italy", "IT" );
session.persist( italy );
-
+
AncientBook aeneid = new AncientBook();
aeneid.setTitle( "Aeneid" );
aeneid.getAlternativeTitles().add( "Aeneis" );
aeneid.getAlternativeTitles().add( "Eneide" );
aeneid.setFirstPublishedIn( italy );
session.persist( aeneid );
-
+
AncientBook commedia = new AncientBook();
commedia.setTitle( "Commedia" );
commedia.getAlternativeTitles().add( "La Commedia" );
commedia.getAlternativeTitles().add( "La Divina Commedia" );
commedia.setFirstPublishedIn( italy );
session.persist( commedia );
-
+
transaction.commit();
session.close();
}
-
+
public void testReindexedOnce() throws InterruptedException {
Assert.assertEquals( 2, countBooksInIndex() );
Session session = openSession();
@@ -86,7 +86,7 @@
}
@Override
- protected Class<?>[] getMappings() {
+ protected Class<?>[] getAnnotatedClasses() {
return new Class[] {
AncientBook.class,
Book.class,
Modified: search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/bridge/BridgeTest.java
===================================================================
--- search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/bridge/BridgeTest.java 2010-07-05 14:46:01 UTC (rev 19897)
+++ search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/bridge/BridgeTest.java 2010-07-05 16:52:21 UTC (rev 19898)
@@ -271,7 +271,7 @@
}
- protected Class<?>[] getMappings() {
+ protected Class<?>[] getAnnotatedClasses() {
return new Class[] {
Cloud.class
};
Modified: search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/bridge/ClassBridgeAndProjectionTest.java
===================================================================
--- search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/bridge/ClassBridgeAndProjectionTest.java 2010-07-05 14:46:01 UTC (rev 19897)
+++ search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/bridge/ClassBridgeAndProjectionTest.java 2010-07-05 16:52:21 UTC (rev 19898)
@@ -65,7 +65,7 @@
}
@Override
- protected Class<?>[] getMappings() {
+ protected Class<?>[] getAnnotatedClasses() {
return new Class<?>[] {
Student.class,
Teacher.class
Modified: search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/bridge/ClassBridgeTest.java
===================================================================
--- search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/bridge/ClassBridgeTest.java 2010-07-05 14:46:01 UTC (rev 19897)
+++ search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/bridge/ClassBridgeTest.java 2010-07-05 16:52:21 UTC (rev 19898)
@@ -321,7 +321,7 @@
return depts;
}
- protected Class<?>[] getMappings() {
+ protected Class<?>[] getAnnotatedClasses() {
return new Class[] {
Department.class,
Departments.class
Modified: search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/bridge/UnresolvedBridgeTest.java
===================================================================
--- search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/bridge/UnresolvedBridgeTest.java 2010-07-05 14:46:01 UTC (rev 19897)
+++ search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/bridge/UnresolvedBridgeTest.java 2010-07-05 16:52:21 UTC (rev 19898)
@@ -36,8 +36,8 @@
public void testSerializableType() throws Exception {
AnnotationConfiguration cfg = new AnnotationConfiguration();
- for (int i = 0; i < getMappings().length; i++) {
- cfg.addAnnotatedClass( getMappings()[i] );
+ for (int i = 0; i < getAnnotatedClasses().length; i++) {
+ cfg.addAnnotatedClass( getAnnotatedClasses()[i] );
}
cfg.setProperty( "hibernate.search.default.directory_provider", RAMDirectoryProvider.class.getName() );
try {
@@ -62,7 +62,7 @@
}
@SuppressWarnings("unchecked")
- protected Class<?>[] getMappings() {
+ protected Class<?>[] getAnnotatedClasses() {
return new Class[] {
Gangster.class
};
Modified: search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/classloading/NoAnnotationsTest.java
===================================================================
--- search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/classloading/NoAnnotationsTest.java 2010-07-05 14:46:01 UTC (rev 19897)
+++ search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/classloading/NoAnnotationsTest.java 2010-07-05 16:52:21 UTC (rev 19898)
@@ -24,6 +24,7 @@
*/
package org.hibernate.search.test.classloading;
+import java.io.InputStream;
import java.util.List;
import org.apache.lucene.index.Term;
@@ -31,25 +32,21 @@
import org.hibernate.Session;
import org.hibernate.Transaction;
+import org.hibernate.cfg.Configuration;
+import org.hibernate.cfg.Environment;
import org.hibernate.search.Search;
-import org.hibernate.search.jpa.FullTextEntityManager;
-import org.hibernate.search.test.TestCase;
+import org.hibernate.search.test.SearchTestCase;
/**
* @author Hardy Ferentschik
*/
-public class NoAnnotationsTest extends TestCase {
+public class NoAnnotationsTest extends SearchTestCase {
/**
* Tests that @DocumentId is optional. See HSEARCH-104.
*
* @throws Exception in case the test fails.
*/
public void testConfigurationWithoutAnnotations() throws Exception {
- FullTextEntityManager em = org.hibernate
- .search
- .jpa
- .Search
- .getFullTextEntityManager( null );
Animal dog = new Animal();
dog.setName( "Dog" );
@@ -88,9 +85,35 @@
s.close();
}
+ protected void buildConfiguration() throws Exception {
+ if ( getSessions() != null ) {
+ getSessions().close();
+ }
+ try {
+ setCfg( new Configuration() );
+ configure( cfg );
+ if ( recreateSchema() ) {
+ cfg.setProperty( Environment.HBM2DDL_AUTO, "create-drop" );
+ }
+ for ( String xmlFile : getXmlFiles() ) {
+ InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream( xmlFile );
+ getCfg().addInputStream( is );
+ }
+ setSessions( getCfg().buildSessionFactory() );
+ }
+ catch ( Exception e ) {
+ e.printStackTrace();
+ throw e;
+ }
+ }
+
protected String[] getXmlFiles() {
return new String[] {
"org/hibernate/search/test/classloading/Animal.hbm.xml"
};
}
+
+ protected Class<?>[] getAnnotatedClasses() {
+ return new Class[] { };
+ }
}
Modified: search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/compression/CompressionTest.java
===================================================================
--- search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/compression/CompressionTest.java 2010-07-05 14:46:01 UTC (rev 19897)
+++ search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/compression/CompressionTest.java 2010-07-05 16:52:21 UTC (rev 19898)
@@ -170,7 +170,7 @@
// test setup:
- protected Class<?>[] getMappings() {
+ protected Class<?>[] getAnnotatedClasses() {
return new Class[] {
LargeDocument.class
};
Modified: search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/configuration/LuceneIndexingParametersTest.java
===================================================================
--- search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/configuration/LuceneIndexingParametersTest.java 2010-07-05 14:46:01 UTC (rev 19897)
+++ search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/configuration/LuceneIndexingParametersTest.java 2010-07-05 16:52:21 UTC (rev 19898)
@@ -131,7 +131,7 @@
assertEquals( param.getTransactionIndexParameters(), paramCopy.getTransactionIndexParameters() );
}
- protected Class<?>[] getMappings() {
+ protected Class<?>[] getAnnotatedClasses() {
return new Class[] {
Book.class,
Author.class,
Modified: search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/configuration/ProgrammaticMappingTest.java
===================================================================
--- search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/configuration/ProgrammaticMappingTest.java 2010-07-05 14:46:01 UTC (rev 19897)
+++ search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/configuration/ProgrammaticMappingTest.java 2010-07-05 16:52:21 UTC (rev 19898)
@@ -740,7 +740,7 @@
}
- protected Class<?>[] getMappings() {
+ protected Class<?>[] getAnnotatedClasses() {
return new Class<?>[] {
Address.class,
Country.class,
Modified: search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/configuration/ShardsConfigurationTest.java
===================================================================
--- search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/configuration/ShardsConfigurationTest.java 2010-07-05 14:46:01 UTC (rev 19897)
+++ search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/configuration/ShardsConfigurationTest.java 2010-07-05 16:52:21 UTC (rev 19898)
@@ -42,12 +42,10 @@
* @author Sanne Grinovero
*/
public class ShardsConfigurationTest extends ConfigurationReadTestCase {
-
+
protected void configure(org.hibernate.cfg.Configuration cfg) {
super.configure( cfg );
- //super contains these:
-// cfg.setProperty( "hibernate.search.default.transaction.merge_factor", "100" );
-// cfg.setProperty( "hibernate.search.default.batch.max_buffered_docs", "1000" );
+
cfg.setProperty( "hibernate.search.default.sharding_strategy.nbr_of_shards", "2" );// permit this?
cfg.setProperty( "hibernate.search.default.directory_provider", FSDirectoryProvider.class.getCanonicalName() );
cfg.setProperty( "hibernate.search.default.2.directory_provider", RAMDirectoryProvider.class.getCanonicalName() );
@@ -64,8 +62,12 @@
cfg.setProperty( "hibernate.search.Documents.1.batch.max_merge_docs", "11" );
cfg.setProperty( "hibernate.search.Documents.1.transaction.max_buffered_docs", "12" );
cfg.setProperty( "hibernate.search.Documents.1.transaction.term_index_interval", "12" );
+
+ //super contains these:
+ //cfg.setProperty( "hibernate.search.default.transaction.merge_factor", "100" );
+ //cfg.setProperty( "hibernate.search.default.batch.max_buffered_docs", "1000" );
}
-
+
public void testCorrectNumberOfShardsDetected() {
DirectoryProvider[] docDirProviders = getSearchFactory()
.getDirectoryProviders( Document.class );
@@ -76,14 +78,14 @@
assertNotNull( bookDirProviders );
assertEquals( 2, bookDirProviders.length );
}
-
+
public void testSelectionOfShardingStrategy() {
IndexShardingStrategy shardingStrategy = getSearchFactory().getDocumentBuilderIndexedEntity( Document.class )
.getDirectoryProviderSelectionStrategy();
assertNotNull( shardingStrategy );
assertEquals( shardingStrategy.getClass(), UselessShardingStrategy.class );
}
-
+
public void testShardingSettingsInherited() {
DirectoryProvider[] docDirProviders = getSearchFactory().getDirectoryProviders( Document.class );
assertTrue( docDirProviders[0] instanceof RAMDirectoryProvider );
@@ -91,7 +93,7 @@
assertTrue( docDirProviders[2] instanceof RAMDirectoryProvider );
assertValueIsSet( Document.class, 0, BATCH, MAX_BUFFERED_DOCS, 4 );
}
-
+
public void testShardN2UsesDefaults() {
assertValueIsSet( Document.class, 2, TRANSACTION, MAX_BUFFERED_DOCS, 6 );
assertValueIsDefault( Document.class, 2, TRANSACTION, MAX_MERGE_DOCS );
@@ -102,18 +104,18 @@
assertValueIsDefault( Document.class, 2, BATCH, MERGE_FACTOR );
assertValueIsDefault( Document.class, 2, BATCH, RAM_BUFFER_SIZE );
}
-
+
public void testShardN1_ExplicitParams() {
assertValueIsSet( Document.class, 1, TRANSACTION, MAX_BUFFERED_DOCS, 12 );
assertValueIsSet( Document.class, 1, BATCH, MAX_MERGE_DOCS, 11 );
}
-
+
@Override
protected void ensureIndexesAreEmpty() {
// skips index emptying to prevent a problem with UselessShardingStrategy
}
-
- protected Class<?>[] getMappings() {
+
+ protected Class<?>[] getAnnotatedClasses() {
return new Class[] {
Book.class,
Author.class,
Modified: search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/directoryProvider/FSSlaveAndMasterDPTest.java
===================================================================
--- search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/directoryProvider/FSSlaveAndMasterDPTest.java 2010-07-05 14:46:01 UTC (rev 19897)
+++ search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/directoryProvider/FSSlaveAndMasterDPTest.java 2010-07-05 16:52:21 UTC (rev 19898)
@@ -212,7 +212,7 @@
return 2;
}
- protected Class<?>[] getMappings() {
+ protected Class<?>[] getAnnotatedClasses() {
return new Class[] {
SnowStorm.class
};
Modified: search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/directoryProvider/MultipleSFTestCase.java
===================================================================
--- search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/directoryProvider/MultipleSFTestCase.java 2010-07-05 14:46:01 UTC (rev 19897)
+++ search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/directoryProvider/MultipleSFTestCase.java 2010-07-05 16:52:21 UTC (rev 19898)
@@ -94,7 +94,7 @@
protected void setUp() throws Exception {
if ( sessionFactories == null || sessionFactories[0] == null || lastTestClass != getClass() ) {
- buildSessionFactories( getMappings(), getAnnotatedPackages(), getXmlFiles() );
+ buildSessionFactories( getAnnotatedClasses(), getAnnotatedPackages(), getXmlFiles() );
lastTestClass = getClass();
}
}
@@ -105,7 +105,7 @@
}
}
- protected abstract Class[] getMappings();
+ protected abstract Class[] getAnnotatedClasses();
protected String[] getAnnotatedPackages() {
return new String[] { };
Modified: search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/embedded/EmbeddedTest.java
===================================================================
--- search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/embedded/EmbeddedTest.java 2010-07-05 14:46:01 UTC (rev 19897)
+++ search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/embedded/EmbeddedTest.java 2010-07-05 16:52:21 UTC (rev 19898)
@@ -335,7 +335,7 @@
super.configure( cfg );
}
- protected Class<?>[] getMappings() {
+ protected Class<?>[] getAnnotatedClasses() {
return new Class[] { Tower.class, Address.class, Product.class, Order.class, Author.class, Country.class,
State.class, StateCandidate.class, NonIndexedEntity.class
};
Modified: search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/embedded/doubleinsert/DoubleInsertEmbeddedTest.java
===================================================================
--- search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/embedded/doubleinsert/DoubleInsertEmbeddedTest.java 2010-07-05 14:46:01 UTC (rev 19897)
+++ search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/embedded/doubleinsert/DoubleInsertEmbeddedTest.java 2010-07-05 16:52:21 UTC (rev 19898)
@@ -93,7 +93,7 @@
s.close();
}
- protected Class<?>[] getMappings() {
+ protected Class<?>[] getAnnotatedClasses() {
return new Class[] {
Address.class,
Contact.class,
Modified: search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/embedded/graph/RecursiveGraphTest.java
===================================================================
--- search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/embedded/graph/RecursiveGraphTest.java 2010-07-05 14:46:01 UTC (rev 19897)
+++ search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/embedded/graph/RecursiveGraphTest.java 2010-07-05 16:52:21 UTC (rev 19898)
@@ -66,7 +66,7 @@
}
@Override
- protected Class<?>[] getMappings() {
+ protected Class<?>[] getAnnotatedClasses() {
return new Class[]{
Event.class,
Person.class,
Modified: search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/embedded/nested/NestedEmbeddedTest.java
===================================================================
--- search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/embedded/nested/NestedEmbeddedTest.java 2010-07-05 14:46:01 UTC (rev 19897)
+++ search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/embedded/nested/NestedEmbeddedTest.java 2010-07-05 16:52:21 UTC (rev 19898)
@@ -156,7 +156,7 @@
super.configure( cfg );
}
- protected Class<?>[] getMappings() {
+ protected Class<?>[] getAnnotatedClasses() {
return new Class[] {
Product.class, Attribute.class, AttributeValue.class, Person.class, Place.class, Address.class
};
Modified: search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/embedded/nested/containedIn/LazyM2OContainedInTest.java
===================================================================
--- search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/embedded/nested/containedIn/LazyM2OContainedInTest.java 2010-07-05 14:46:01 UTC (rev 19897)
+++ search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/embedded/nested/containedIn/LazyM2OContainedInTest.java 2010-07-05 16:52:21 UTC (rev 19898)
@@ -118,7 +118,7 @@
@Override
- protected Class<?>[] getMappings() {
+ protected Class<?>[] getAnnotatedClasses() {
return new Class<?>[] {
Entity1ForDoc0.class,
Entity2ForDoc0.class,
Modified: search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/embedded/nested/containedIn/NestedContainedInTest.java
===================================================================
--- search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/embedded/nested/containedIn/NestedContainedInTest.java 2010-07-05 14:46:01 UTC (rev 19897)
+++ search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/embedded/nested/containedIn/NestedContainedInTest.java 2010-07-05 16:52:21 UTC (rev 19898)
@@ -79,7 +79,7 @@
}
@Override
- protected Class<?>[] getMappings() {
+ protected Class<?>[] getAnnotatedClasses() {
return new Class<?>[] {
HelpItem.class,
HelpItemTag.class,
Modified: search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/engine/LazyCollectionsUpdatingTest.java
===================================================================
--- search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/engine/LazyCollectionsUpdatingTest.java 2010-07-05 14:46:01 UTC (rev 19897)
+++ search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/engine/LazyCollectionsUpdatingTest.java 2010-07-05 16:52:21 UTC (rev 19898)
@@ -133,7 +133,7 @@
// Test setup options - Entities
@Override
- protected Class<?>[] getMappings() {
+ protected Class<?>[] getAnnotatedClasses() {
return new Class[] { BusLine.class, BusStop.class };
}
Modified: search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/engine/RollbackTransactionTest.java
===================================================================
--- search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/engine/RollbackTransactionTest.java 2010-07-05 14:46:01 UTC (rev 19897)
+++ search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/engine/RollbackTransactionTest.java 2010-07-05 16:52:21 UTC (rev 19898)
@@ -98,7 +98,7 @@
// Test setup options - Entities
@Override
- protected Class<?>[] getMappings() {
+ protected Class<?>[] getAnnotatedClasses() {
return new Class[] { BusLine.class, BusStop.class };
}
Modified: search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/errorhandling/LuceneErrorHandlingTest.java
===================================================================
--- search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/errorhandling/LuceneErrorHandlingTest.java 2010-07-05 14:46:01 UTC (rev 19897)
+++ search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/errorhandling/LuceneErrorHandlingTest.java 2010-07-05 16:52:21 UTC (rev 19898)
@@ -105,7 +105,7 @@
Assert.assertEquals( "failed work message", exception.getMessage() );
}
- protected Class<?>[] getMappings() {
+ protected Class<?>[] getAnnotatedClasses() {
return new Class[] { Document.class };
}
Modified: search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/fieldAccess/FieldAccessTest.java
===================================================================
--- search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/fieldAccess/FieldAccessTest.java 2010-07-05 14:46:01 UTC (rev 19897)
+++ search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/fieldAccess/FieldAccessTest.java 2010-07-05 16:52:21 UTC (rev 19898)
@@ -83,7 +83,7 @@
}
- protected Class<?>[] getMappings() {
+ protected Class<?>[] getAnnotatedClasses() {
return new Class[] {
Document.class
};
Modified: search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/filter/FilterTest.java
===================================================================
--- search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/filter/FilterTest.java 2010-07-05 14:46:01 UTC (rev 19897)
+++ search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/filter/FilterTest.java 2010-07-05 16:52:21 UTC (rev 19898)
@@ -198,8 +198,13 @@
s.close();
}
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ setCfg( null ); // force a configuration rebuild
+ }
+
@SuppressWarnings("unchecked")
- protected Class<?>[] getMappings() {
+ protected Class<?>[] getAnnotatedClasses() {
return new Class[] {
Driver.class,
Soap.class
Modified: search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/id/EmbeddedIdTest.java
===================================================================
--- search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/id/EmbeddedIdTest.java 2010-07-05 14:46:01 UTC (rev 19897)
+++ search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/id/EmbeddedIdTest.java 2010-07-05 16:52:21 UTC (rev 19898)
@@ -112,7 +112,7 @@
s.close();
}
- protected Class<?>[] getMappings() {
+ protected Class<?>[] getAnnotatedClasses() {
return new Class[] {
Person.class
};
Modified: search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/id/ImplicitIdTest.java
===================================================================
--- search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/id/ImplicitIdTest.java 2010-07-05 14:46:01 UTC (rev 19897)
+++ search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/id/ImplicitIdTest.java 2010-07-05 16:52:21 UTC (rev 19898)
@@ -63,7 +63,7 @@
s.close();
}
- protected Class<?>[] getMappings() {
+ protected Class<?>[] getAnnotatedClasses() {
return new Class[] {
Animal.class
};
Modified: search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/indexingStrategy/ManualIndexingStrategyTest.java
===================================================================
--- search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/indexingStrategy/ManualIndexingStrategyTest.java 2010-07-05 14:46:01 UTC (rev 19897)
+++ search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/indexingStrategy/ManualIndexingStrategyTest.java 2010-07-05 16:52:21 UTC (rev 19898)
@@ -77,7 +77,7 @@
}
}
- protected Class<?>[] getMappings() {
+ protected Class<?>[] getAnnotatedClasses() {
return new Class[] {
Document.class,
AlternateDocument.class
Modified: search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/inheritance/InheritanceTest.java
===================================================================
--- search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/inheritance/InheritanceTest.java 2010-07-05 14:46:01 UTC (rev 19897)
+++ search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/inheritance/InheritanceTest.java 2010-07-05 16:52:21 UTC (rev 19898)
@@ -303,7 +303,7 @@
assertEquals( "Wrong animal name", "Elephant", mammal.getName() );
}
- protected Class<?>[] getMappings() {
+ protected Class<?>[] getAnnotatedClasses() {
return new Class[] {
Animal.class,
Mammal.class,
Modified: search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/jgroups/common/JGroupsCommonTest.java
===================================================================
--- search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/jgroups/common/JGroupsCommonTest.java 2010-07-05 14:46:01 UTC (rev 19897)
+++ search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/jgroups/common/JGroupsCommonTest.java 2010-07-05 16:52:21 UTC (rev 19898)
@@ -28,6 +28,7 @@
import org.apache.lucene.queryParser.QueryParser;
import org.apache.lucene.search.Query;
+
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
@@ -42,12 +43,12 @@
* In case of running test outside Hibernate Search Maven configuration set following VM configuration:
* <br>
* <code>
- * -Djava.net.preferIPv4Stack=true -Djgroups.bind_addr=127.0.0.1
+ * -Djava.net.preferIPv4Stack=true -Djgroups.bind_addr=127.0.0.1
* </code>
+ *
* @author Lukasz Moren
*/
-public class
- JGroupsCommonTest extends MultipleSessionsSearchTestCase {
+public class JGroupsCommonTest extends MultipleSessionsSearchTestCase {
private static final String DEFAULT_JGROUPS_CONFIGURATION_FILE = "flush-udp.xml";
@@ -127,13 +128,13 @@
}
@Override
- protected Class<?>[] getMappings() {
+ protected Class<?>[] getAnnotatedClasses() {
return new Class[] {
TShirt.class
};
}
- protected Class<?>[] getCommonMappings() {
+ protected Class<?>[] getCommonAnnotatedClasses() {
return new Class[] {
TShirt.class
};
Modified: search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/jgroups/common/MultipleSessionsSearchTestCase.java
===================================================================
--- search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/jgroups/common/MultipleSessionsSearchTestCase.java 2010-07-05 14:46:01 UTC (rev 19897)
+++ search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/jgroups/common/MultipleSessionsSearchTestCase.java 2010-07-05 16:52:21 UTC (rev 19898)
@@ -30,7 +30,6 @@
import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.cfg.Configuration;
import org.hibernate.classic.Session;
-import org.hibernate.dialect.Dialect;
import org.hibernate.search.test.SearchTestCase;
import org.hibernate.search.util.FileHelper;
@@ -66,8 +65,8 @@
super.configure( cfg );
//master
- cfg.setProperty( "hibernate.search.default.sourceBase", getIndexDir().getAbsolutePath() + masterCopy );
- cfg.setProperty( "hibernate.search.default.indexBase", getIndexDir().getAbsolutePath() + masterMain );
+ cfg.setProperty( "hibernate.search.default.sourceBase", getBaseIndexDir().getAbsolutePath() + masterCopy );
+ cfg.setProperty( "hibernate.search.default.indexBase", getBaseIndexDir().getAbsolutePath() + masterMain );
cfg.setProperty( "hibernate.search.default.refresh", "1" );
cfg.setProperty(
"hibernate.search.default.directory_provider", "org.hibernate.search.store.FSMasterDirectoryProvider"
@@ -78,8 +77,8 @@
super.configure( cfg );
//slave(s)
- cfg.setProperty( "hibernate.search.default.sourceBase", getIndexDir().getAbsolutePath() + masterCopy );
- cfg.setProperty( "hibernate.search.default.indexBase", getIndexDir().getAbsolutePath() + slave );
+ cfg.setProperty( "hibernate.search.default.sourceBase", getBaseIndexDir().getAbsolutePath() + masterCopy );
+ cfg.setProperty( "hibernate.search.default.indexBase", getBaseIndexDir().getAbsolutePath() + slave );
cfg.setProperty( "hibernate.search.default.refresh", "1" );
cfg.setProperty(
"hibernate.search.default.directory_provider", "org.hibernate.search.store.FSSlaveDirectoryProvider"
@@ -88,11 +87,11 @@
@Override
protected void setUp() throws Exception {
- if ( getIndexDir().exists() ) {
- FileHelper.delete( getIndexDir() );
+ if ( getBaseIndexDir().exists() ) {
+ FileHelper.delete( getBaseIndexDir() );
}
super.setUp();
- buildCommonSessionFactory( getCommonMappings(), getCommonAnnotatedPackages(), getCommonXmlFiles() );
+ buildCommonSessionFactory();
}
@Override
@@ -103,10 +102,10 @@
if ( slaveSessionFactory != null ) {
slaveSessionFactory.close();
}
- FileHelper.delete( getIndexDir() );
+ FileHelper.delete( getBaseIndexDir() );
}
- private void buildCommonSessionFactory(Class<?>[] classes, String[] packages, String[] xmlFiles) throws Exception {
+ private void buildCommonSessionFactory() throws Exception {
if ( getSlaveSessionFactory() != null ) {
getSlaveSessionFactory().close();
}
@@ -116,17 +115,16 @@
if ( recreateSchema() ) {
commonCfg.setProperty( org.hibernate.cfg.Environment.HBM2DDL_AUTO, "create-drop" );
}
- for ( String aPackage : packages ) {
- ((AnnotationConfiguration) getCommonConfiguration()).addPackage( aPackage );
+ for ( String aPackage : getCommonAnnotatedPackages() ) {
+ ( ( AnnotationConfiguration ) getCommonConfiguration() ).addPackage( aPackage );
}
- for ( Class<?> aClass : classes ) {
- ((AnnotationConfiguration) getCommonConfiguration()).addAnnotatedClass( aClass );
+ for ( Class<?> aClass : getCommonAnnotatedClasses() ) {
+ ( ( AnnotationConfiguration ) getCommonConfiguration() ).addAnnotatedClass( aClass );
}
- for ( String xmlFile : xmlFiles ) {
+ for ( String xmlFile : getCommonXmlFiles() ) {
InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream( xmlFile );
getCommonConfiguration().addInputStream( is );
}
- setDialect( Dialect.getDialect() );
slaveSessionFactory = getCommonConfiguration().buildSessionFactory();
}
@@ -154,7 +152,7 @@
return new String[] { };
}
- protected abstract Class<?>[] getMappings();
+ protected abstract Class<?>[] getAnnotatedClasses();
- protected abstract Class<?>[] getCommonMappings();
+ protected abstract Class<?>[] getCommonAnnotatedClasses();
}
Modified: search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/jgroups/master/JGroupsMasterTest.java
===================================================================
--- search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/jgroups/master/JGroupsMasterTest.java 2010-07-05 14:46:01 UTC (rev 19897)
+++ search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/jgroups/master/JGroupsMasterTest.java 2010-07-05 16:52:21 UTC (rev 19898)
@@ -183,7 +183,7 @@
"shun=false;print_local_addr=true)";
}
- protected Class<?>[] getMappings() {
+ protected Class<?>[] getAnnotatedClasses() {
return new Class[] {
TShirt.class
};
Modified: search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/jgroups/slave/JGroupsSlaveTest.java
===================================================================
--- search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/jgroups/slave/JGroupsSlaveTest.java 2010-07-05 14:46:01 UTC (rev 19897)
+++ search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/jgroups/slave/JGroupsSlaveTest.java 2010-07-05 16:52:21 UTC (rev 19898)
@@ -118,7 +118,7 @@
super.tearDown();
}
- protected Class<?>[] getMappings() {
+ protected Class<?>[] getAnnotatedClasses() {
return new Class[] {
TShirt.class
};
Modified: search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/jms/master/JMSMasterTest.java
===================================================================
--- search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/jms/master/JMSMasterTest.java 2010-07-05 14:46:01 UTC (rev 19897)
+++ search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/jms/master/JMSMasterTest.java 2010-07-05 16:52:21 UTC (rev 19898)
@@ -213,7 +213,7 @@
cfg.setProperty( Environment.WORKER_BACKEND, "lucene" );
}
- protected Class<?>[] getMappings() {
+ protected Class<?>[] getAnnotatedClasses() {
return new Class[] {
TShirt.class
};
Modified: search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/jms/slave/JMSSlaveTest.java
===================================================================
--- search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/jms/slave/JMSSlaveTest.java 2010-07-05 14:46:01 UTC (rev 19897)
+++ search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/jms/slave/JMSSlaveTest.java 2010-07-05 16:52:21 UTC (rev 19898)
@@ -171,7 +171,7 @@
cfg.setProperty( "hibernate.search.worker.jndi.queue.queue/searchtest", "searchQueue" );
}
- protected Class<?>[] getMappings() {
+ protected Class<?>[] getAnnotatedClasses() {
return new Class[] {
TShirt.class
};
Modified: search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/jmx/ConfigInfoMBeanTest.java
===================================================================
--- search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/jmx/ConfigInfoMBeanTest.java 2010-07-05 14:46:01 UTC (rev 19897)
+++ search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/jmx/ConfigInfoMBeanTest.java 2010-07-05 16:52:21 UTC (rev 19898)
@@ -131,6 +131,7 @@
if ( mbeanServer.isRegistered( configBeanObjectName ) ) {
mbeanServer.unregisterMBean( configBeanObjectName );
}
+ setCfg( null ); // force a rebuild of the configuration
}
protected void configure(Configuration cfg) {
@@ -139,7 +140,7 @@
}
@Override
- protected Class<?>[] getMappings() {
+ protected Class<?>[] getAnnotatedClasses() {
return new Class<?>[] { Counter.class };
}
}
Modified: search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/jmx/IndexCtrlMBeanTest.java
===================================================================
--- search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/jmx/IndexCtrlMBeanTest.java 2010-07-05 14:46:01 UTC (rev 19897)
+++ search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/jmx/IndexCtrlMBeanTest.java 2010-07-05 16:52:21 UTC (rev 19898)
@@ -123,6 +123,7 @@
if ( mbeanServer.isRegistered( indexBeanObjectName ) ) {
mbeanServer.unregisterMBean( indexBeanObjectName );
}
+ setCfg( null ); // force a rebuild of the configuration
}
protected void configure(Configuration cfg) {
@@ -141,7 +142,7 @@
}
@Override
- protected Class<?>[] getMappings() {
+ protected Class<?>[] getAnnotatedClasses() {
return new Class<?>[] { Counter.class };
}
Modified: search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/jmx/NoMBeansEnabledTest.java
===================================================================
--- search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/jmx/NoMBeansEnabledTest.java 2010-07-05 14:46:01 UTC (rev 19897)
+++ search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/jmx/NoMBeansEnabledTest.java 2010-07-05 16:52:21 UTC (rev 19898)
@@ -69,7 +69,7 @@
}
@Override
- protected Class<?>[] getMappings() {
+ protected Class<?>[] getAnnotatedClasses() {
return new Class<?>[] { Counter.class };
}
}
\ No newline at end of file
Modified: search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/optimizer/OptimizerPerfTest.java
===================================================================
--- search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/optimizer/OptimizerPerfTest.java 2010-07-05 14:46:01 UTC (rev 19897)
+++ search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/optimizer/OptimizerPerfTest.java 2010-07-05 16:52:21 UTC (rev 19898)
@@ -32,6 +32,7 @@
import org.apache.lucene.queryParser.ParseException;
import org.apache.lucene.queryParser.QueryParser;
import org.apache.lucene.search.Query;
+
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
@@ -52,19 +53,19 @@
FileHelper.delete( sub );
sub.mkdir();
File[] files = sub.listFiles();
- for (File file : files) {
+ for ( File file : files ) {
if ( file.isDirectory() ) {
FileHelper.delete( file );
}
}
- //super.setUp(); //we need a fresh session factory each time for index set up
- buildSessionFactory( getMappings(), getAnnotatedPackages(), getXmlFiles() );
+ super.setUp();
}
protected void tearDown() throws Exception {
super.tearDown();
File sub = getBaseIndexDir();
FileHelper.delete( sub );
+ setCfg( null ); //we need a fresh session factory each time for index set up
}
public void testConcurrency() throws Exception {
@@ -74,15 +75,17 @@
ReverseWork reverseWork = new ReverseWork( getSessions() );
long start = System.currentTimeMillis();
int iteration = 100;
- for (int i = 0; i < iteration; i++) {
+ for ( int i = 0; i < iteration; i++ ) {
es.execute( work );
es.execute( reverseWork );
}
while ( work.count < iteration - 1 ) {
Thread.sleep( 20 );
}
- System.out.println( iteration + " iterations (8 tx per iteration) in " + nThreads + " threads: " + ( System
- .currentTimeMillis() - start ) );
+ System.out.println(
+ iteration + " iterations (8 tx per iteration) in " + nThreads + " threads: " + ( System
+ .currentTimeMillis() - start )
+ );
}
protected static class Work implements Runnable {
@@ -106,9 +109,9 @@
s = sf.openSession();
tx = s.beginTransaction();
- w = (Worker) s.get( Worker.class, w.getId() );
+ w = ( Worker ) s.get( Worker.class, w.getId() );
w.setName( "Gavin" );
- c = (Construction) s.get( Construction.class, c.getId() );
+ c = ( Construction ) s.get( Construction.class, c.getId() );
c.setName( "W Hotel" );
tx.commit();
s.close();
@@ -116,7 +119,7 @@
try {
Thread.sleep( 50 );
}
- catch (InterruptedException e) {
+ catch ( InterruptedException e ) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
}
@@ -128,7 +131,7 @@
try {
query = parser.parse( "name:Gavin" );
}
- catch (ParseException e) {
+ catch ( ParseException e ) {
throw new RuntimeException( e );
}
boolean results = fts.createFullTextQuery( query ).list().size() > 0;
@@ -139,16 +142,17 @@
s = sf.openSession();
tx = s.beginTransaction();
- w = (Worker) s.get( Worker.class, w.getId() );
+ w = ( Worker ) s.get( Worker.class, w.getId() );
s.delete( w );
- c = (Construction) s.get( Construction.class, c.getId() );
+ c = ( Construction ) s.get( Construction.class, c.getId() );
s.delete( c );
tx.commit();
s.close();
count++;
- } catch (Throwable t) {
- t.printStackTrace( );
}
+ catch ( Throwable t ) {
+ t.printStackTrace();
+ }
}
}
@@ -172,24 +176,25 @@
s = sf.openSession();
tx = s.beginTransaction();
- w = (Worker) s.get( Worker.class, w.getId() );
+ w = ( Worker ) s.get( Worker.class, w.getId() );
w.setName( "Remi" );
- c = (Construction) s.get( Construction.class, c.getId() );
+ c = ( Construction ) s.get( Construction.class, c.getId() );
c.setName( "Palais des festivals" );
tx.commit();
s.close();
s = sf.openSession();
tx = s.beginTransaction();
- w = (Worker) s.get( Worker.class, w.getId() );
+ w = ( Worker ) s.get( Worker.class, w.getId() );
s.delete( w );
- c = (Construction) s.get( Construction.class, c.getId() );
+ c = ( Construction ) s.get( Construction.class, c.getId() );
s.delete( c );
tx.commit();
s.close();
- } catch (Throwable t) {
- t.printStackTrace( );
}
+ catch ( Throwable t ) {
+ t.printStackTrace();
+ }
}
}
@@ -201,7 +206,7 @@
cfg.setProperty( Environment.ANALYZER_CLASS, StopAnalyzer.class.getName() );
}
- protected Class<?>[] getMappings() {
+ protected Class<?>[] getAnnotatedClasses() {
return new Class[] {
Worker.class,
Construction.class
Modified: search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/perf/IndexTestDontRun.java
===================================================================
--- search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/perf/IndexTestDontRun.java 2010-07-05 14:46:01 UTC (rev 19897)
+++ search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/perf/IndexTestDontRun.java 2010-07-05 16:52:21 UTC (rev 19898)
@@ -108,7 +108,7 @@
return indexsearcher;
}
- protected Class<?>[] getMappings() {
+ protected Class<?>[] getAnnotatedClasses() {
return new Class[] {
Boat.class
};
Modified: search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/query/LuceneQuerySortTest.java
===================================================================
--- search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/query/LuceneQuerySortTest.java 2010-07-05 14:46:01 UTC (rev 19897)
+++ search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/query/LuceneQuerySortTest.java 2010-07-05 16:52:21 UTC (rev 19898)
@@ -157,7 +157,7 @@
s.clear();
}
- protected Class<?>[] getMappings() {
+ protected Class<?>[] getAnnotatedClasses() {
return new Class[] {
Book.class,
Author.class
Modified: search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/query/LuceneQueryTest.java
===================================================================
--- search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/query/LuceneQueryTest.java 2010-07-05 14:46:01 UTC (rev 19897)
+++ search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/query/LuceneQueryTest.java 2010-07-05 16:52:21 UTC (rev 19898)
@@ -671,7 +671,7 @@
}
- protected Class<?>[] getMappings() {
+ protected Class<?>[] getAnnotatedClasses() {
return new Class[] {
Book.class,
AlternateBook.class,
Modified: search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/query/MultiClassesQueryLoaderTest.java
===================================================================
--- search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/query/MultiClassesQueryLoaderTest.java 2010-07-05 14:46:01 UTC (rev 19897)
+++ search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/query/MultiClassesQueryLoaderTest.java 2010-07-05 16:52:21 UTC (rev 19898)
@@ -104,7 +104,7 @@
s.close();
}
- protected Class<?>[] getMappings() {
+ protected Class<?>[] getAnnotatedClasses() {
return new Class[] {
Author.class,
Music.class,
Modified: search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/query/ProjectionQueryTest.java
===================================================================
--- search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/query/ProjectionQueryTest.java 2010-07-05 14:46:01 UTC (rev 19897)
+++ search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/query/ProjectionQueryTest.java 2010-07-05 16:52:21 UTC (rev 19898)
@@ -486,7 +486,7 @@
s.close();
}
- protected Class<?>[] getMappings() {
+ protected Class<?>[] getAnnotatedClasses() {
return new Class[] {
Book.class,
Author.class,
Modified: search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/query/QueryLoaderTest.java
===================================================================
--- search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/query/QueryLoaderTest.java 2010-07-05 14:46:01 UTC (rev 19897)
+++ search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/query/QueryLoaderTest.java 2010-07-05 16:52:21 UTC (rev 19898)
@@ -109,7 +109,7 @@
s.close();
}
- protected Class<?>[] getMappings() {
+ protected Class<?>[] getAnnotatedClasses() {
return new Class[] {
Author.class,
Music.class
Modified: search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/query/QueryUnindexedEntityTest.java
===================================================================
--- search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/query/QueryUnindexedEntityTest.java 2010-07-05 14:46:01 UTC (rev 19897)
+++ search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/query/QueryUnindexedEntityTest.java 2010-07-05 16:52:21 UTC (rev 19898)
@@ -66,7 +66,7 @@
s.close();
}
- protected Class<?>[] getMappings() {
+ protected Class<?>[] getAnnotatedClasses() {
return new Class[] {
Person.class,
};
Modified: search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/query/TermVectorTest.java
===================================================================
--- search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/query/TermVectorTest.java 2010-07-05 14:46:01 UTC (rev 19897)
+++ search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/query/TermVectorTest.java 2010-07-05 16:52:21 UTC (rev 19898)
@@ -120,7 +120,7 @@
tx.commit();
}
- protected Class<?>[] getMappings() {
+ protected Class<?>[] getAnnotatedClasses() {
return new Class[]{
ElectricalProperties.class,
Employee.class
Modified: search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/query/boost/DynamicBoostingTest.java
===================================================================
--- search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/query/boost/DynamicBoostingTest.java 2010-07-05 14:46:01 UTC (rev 19897)
+++ search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/query/boost/DynamicBoostingTest.java 2010-07-05 16:52:21 UTC (rev 19898)
@@ -124,7 +124,7 @@
return score;
}
- protected Class<?>[] getMappings() {
+ protected Class<?>[] getAnnotatedClasses() {
return new Class[] {
DynamicBoostedDescriptionLibrary.class
};
Modified: search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/query/boost/FieldBoostTest.java
===================================================================
--- search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/query/boost/FieldBoostTest.java 2010-07-05 14:46:01 UTC (rev 19897)
+++ search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/query/boost/FieldBoostTest.java 2010-07-05 16:52:21 UTC (rev 19898)
@@ -210,7 +210,7 @@
tx.commit();
}
- protected Class<?>[] getMappings() {
+ protected Class<?>[] getAnnotatedClasses() {
return new Class[] {
BoostedDescriptionLibrary.class,
BoostedFieldDescriptionLibrary.class,
Modified: search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/query/criteria/MixedCriteriaTest.java
===================================================================
--- search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/query/criteria/MixedCriteriaTest.java 2010-07-05 14:46:01 UTC (rev 19897)
+++ search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/query/criteria/MixedCriteriaTest.java 2010-07-05 16:52:21 UTC (rev 19898)
@@ -141,7 +141,7 @@
}
- protected Class<?>[] getMappings() {
+ protected Class<?>[] getAnnotatedClasses() {
return new Class[] {
AbstractCar.class, CombiCar.class, SportCar.class, Bike.class
};
Modified: search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/query/dsl/DSLTest.java
===================================================================
--- search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/query/dsl/DSLTest.java 2010-07-05 14:46:01 UTC (rev 19897)
+++ search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/query/dsl/DSLTest.java 2010-07-05 16:52:21 UTC (rev 19898)
@@ -562,7 +562,7 @@
}
@Override
- protected Class<?>[] getMappings() {
+ protected Class<?>[] getAnnotatedClasses() {
return new Class<?>[] {
Month.class
};
Modified: search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/query/explain/ExplanationTest.java
===================================================================
--- search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/query/explain/ExplanationTest.java 2010-07-05 14:46:01 UTC (rev 19897)
+++ search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/query/explain/ExplanationTest.java 2010-07-05 16:52:21 UTC (rev 19898)
@@ -69,7 +69,7 @@
s.close();
}
- protected Class<?>[] getMappings() {
+ protected Class<?>[] getAnnotatedClasses() {
return new Class[] {
Dvd.class
};
Modified: search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/reader/ReaderPerfTestCase.java
===================================================================
--- search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/reader/ReaderPerfTestCase.java 2010-07-05 14:46:01 UTC (rev 19897)
+++ search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/reader/ReaderPerfTestCase.java 2010-07-05 16:52:21 UTC (rev 19898)
@@ -65,12 +65,11 @@
FileHelper.delete( file );
}
}
- //super.setUp(); //we need a fresh session factory each time for index set up
- buildSessionFactory( getMappings(), getAnnotatedPackages(), getXmlFiles() );
+ super.setUp();
}
@SuppressWarnings("unchecked")
- protected Class<?>[] getMappings() {
+ protected Class<?>[] getAnnotatedClasses() {
return new Class[] {
Detective.class,
Suspect.class
@@ -84,6 +83,7 @@
}
File sub = getBaseIndexDir();
FileHelper.delete( sub );
+ setCfg( null ); //we need a fresh session factory each time for index set up
}
public boolean insert = true;
@@ -136,7 +136,7 @@
private Random random = new Random();
private SessionFactory sf;
// public volatile int count = 0;
- public AtomicInteger count = new AtomicInteger(0);
+ public AtomicInteger count = new AtomicInteger( 0 );
public Work(SessionFactory sf) {
this.sf = sf;
@@ -148,9 +148,11 @@
try {
s = sf.openSession();
tx = s.beginTransaction();
- QueryParser parser = new MultiFieldQueryParser( getTargetLuceneVersion(),
+ QueryParser parser = new MultiFieldQueryParser(
+ getTargetLuceneVersion(),
new String[] { "name", "physicalDescription", "suspectCharge" },
- SearchTestCase.standardAnalyzer );
+ SearchTestCase.standardAnalyzer
+ );
FullTextQuery query = getQuery( "John Doe", parser, s );
assertTrue( query.getResultSize() != 0 );
@@ -175,28 +177,37 @@
List result = query.list();
Object object = result.get( 0 );
if ( insert && object instanceof Detective ) {
- Detective detective = (Detective) object;
- detective.setPhysicalDescription( detective.getPhysicalDescription() + " Eye"
- + firstResult );
+ Detective detective = ( Detective ) object;
+ detective.setPhysicalDescription(
+ detective.getPhysicalDescription() + " Eye"
+ + firstResult
+ );
}
else if ( insert && object instanceof Suspect ) {
- Suspect suspect = (Suspect) object;
- suspect.setPhysicalDescription( suspect.getPhysicalDescription() + " Eye"
- + firstResult );
+ Suspect suspect = ( Suspect ) object;
+ suspect.setPhysicalDescription(
+ suspect.getPhysicalDescription() + " Eye"
+ + firstResult
+ );
}
tx.commit();
s.close();
// count++;
- } catch ( Throwable t ) {
+ }
+ catch ( Throwable t ) {
t.printStackTrace();
- } finally {
+ }
+ finally {
count.incrementAndGet();
try {
- if ( tx != null && tx.isActive() )
+ if ( tx != null && tx.isActive() ) {
tx.rollback();
- if ( s != null && s.isOpen() )
+ }
+ if ( s != null && s.isOpen() ) {
s.close();
- } catch ( Throwable t ) {
+ }
+ }
+ catch ( Throwable t ) {
t.printStackTrace();
}
}
@@ -225,7 +236,8 @@
public void run() {
Session s = sf.openSession();
Transaction tx = s.beginTransaction();
- QueryParser parser = new MultiFieldQueryParser( getTargetLuceneVersion(),
+ QueryParser parser = new MultiFieldQueryParser(
+ getTargetLuceneVersion(),
new String[] { "name", "physicalDescription", "suspectCharge" },
SearchTestCase.standardAnalyzer
);
Modified: search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/reader/functionality/FilterOnDirectoryTest.java
===================================================================
--- search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/reader/functionality/FilterOnDirectoryTest.java 2010-07-05 14:46:01 UTC (rev 19897)
+++ search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/reader/functionality/FilterOnDirectoryTest.java 2010-07-05 16:52:21 UTC (rev 19898)
@@ -84,7 +84,7 @@
cfg.setProperty( Environment.READER_STRATEGY, SharingBufferReaderProvider.class.getName() );
}
- protected Class<?>[] getMappings() {
+ protected Class<?>[] getAnnotatedClasses() {
return new Class[] {
Detective.class,
Suspect.class
Modified: search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/reader/performance/ReaderPerformance.java
===================================================================
--- search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/reader/performance/ReaderPerformance.java 2010-07-05 14:46:01 UTC (rev 19897)
+++ search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/reader/performance/ReaderPerformance.java 2010-07-05 16:52:21 UTC (rev 19898)
@@ -90,7 +90,7 @@
}
@SuppressWarnings("unchecked")
- protected Class<?>[] getMappings() {
+ protected Class<?>[] getAnnotatedClasses() {
return new Class[] {
Detective.class,
Suspect.class
Modified: search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/session/MassIndexTest.java
===================================================================
--- search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/session/MassIndexTest.java 2010-07-05 14:46:01 UTC (rev 19897)
+++ search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/session/MassIndexTest.java 2010-07-05 16:52:21 UTC (rev 19898)
@@ -217,7 +217,7 @@
cfg.setProperty( Environment.ANALYZER_CLASS, StopAnalyzer.class.getName() );
}
- protected Class<?>[] getMappings() {
+ protected Class<?>[] getAnnotatedClasses() {
return new Class[] {
Email.class,
Entite.class,
Modified: search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/session/MassIndexUsingManualFlushTest.java
===================================================================
--- search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/session/MassIndexUsingManualFlushTest.java 2010-07-05 14:46:01 UTC (rev 19897)
+++ search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/session/MassIndexUsingManualFlushTest.java 2010-07-05 16:52:21 UTC (rev 19898)
@@ -89,7 +89,7 @@
cfg.setProperty( Environment.ANALYZER_CLASS, StopAnalyzer.class.getName() );
}
- protected Class<?>[] getMappings() {
+ protected Class<?>[] getAnnotatedClasses() {
return new Class[] {
Email.class,
Domain.class
Modified: search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/session/OptimizeTest.java
===================================================================
--- search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/session/OptimizeTest.java 2010-07-05 14:46:01 UTC (rev 19897)
+++ search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/session/OptimizeTest.java 2010-07-05 16:52:21 UTC (rev 19898)
@@ -28,6 +28,7 @@
import org.apache.lucene.analysis.StopAnalyzer;
import org.apache.lucene.queryParser.QueryParser;
+
import org.hibernate.Transaction;
import org.hibernate.search.Environment;
import org.hibernate.search.FullTextSession;
@@ -46,9 +47,9 @@
FullTextSession s = Search.getFullTextSession( openSession() );
Transaction tx = s.beginTransaction();
int loop = 2000;
- for (int i = 0; i < loop; i++) {
+ for ( int i = 0; i < loop; i++ ) {
Email email = new Email();
- email.setId( (long) i + 1 );
+ email.setId( ( long ) i + 1 );
email.setTitle( "JBoss World Berlin" );
email.setBody( "Meet the guys who wrote the software" );
s.persist( email );
@@ -85,23 +86,23 @@
File sub = getBaseIndexDir();
sub.mkdir();
File[] files = sub.listFiles();
- for (File file : files) {
+ for ( File file : files ) {
if ( file.isDirectory() ) {
FileHelper.delete( file );
}
}
- //super.setUp(); //we need a fresh session factory each time for index set up
- buildSessionFactory( getMappings(), getAnnotatedPackages(), getXmlFiles() );
+ super.setUp();
}
protected void tearDown() throws Exception {
super.tearDown();
File sub = getBaseIndexDir();
FileHelper.delete( sub );
+ setCfg( null ); //we need a fresh session factory each time for index set up
}
@SuppressWarnings("unchecked")
- protected Class<?>[] getMappings() {
+ protected Class<?>[] getAnnotatedClasses() {
return new Class[] {
Email.class,
Domain.class
Modified: search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/session/SessionTest.java
===================================================================
--- search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/session/SessionTest.java 2010-07-05 14:46:01 UTC (rev 19897)
+++ search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/session/SessionTest.java 2010-07-05 16:52:21 UTC (rev 19898)
@@ -91,7 +91,7 @@
}
}
- protected Class<?>[] getMappings() {
+ protected Class<?>[] getAnnotatedClasses() {
return new Class[] {
Email.class,
Domain.class
Modified: search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/shards/DirectoryProviderForQueryTest.java
===================================================================
--- search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/shards/DirectoryProviderForQueryTest.java 2010-07-05 14:46:01 UTC (rev 19897)
+++ search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/shards/DirectoryProviderForQueryTest.java 2010-07-05 16:52:21 UTC (rev 19898)
@@ -87,7 +87,7 @@
}
@SuppressWarnings("unchecked")
- protected Class<?>[] getMappings() {
+ protected Class<?>[] getAnnotatedClasses() {
return new Class[] {
Email.class
};
Modified: search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/shards/ShardsTest.java
===================================================================
--- search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/shards/ShardsTest.java 2010-07-05 14:46:01 UTC (rev 19897)
+++ search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/shards/ShardsTest.java 2010-07-05 16:52:21 UTC (rev 19898)
@@ -27,25 +27,26 @@
import java.io.File;
import java.util.List;
-import org.hibernate.search.test.SearchTestCase;
-import org.hibernate.search.util.FileHelper;
-import org.hibernate.search.store.RAMDirectoryProvider;
-import org.hibernate.search.store.FSDirectoryProvider;
-import org.hibernate.search.store.IdHashShardingStrategy;
-import org.hibernate.search.store.DirectoryProvider;
-import org.hibernate.search.Environment;
-import org.hibernate.search.FullTextSession;
-import org.hibernate.search.Search;
-import org.hibernate.cfg.Configuration;
-import org.hibernate.Session;
-import org.hibernate.Transaction;
import org.apache.lucene.analysis.StopAnalyzer;
+import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.index.Term;
+import org.apache.lucene.index.TermDocs;
import org.apache.lucene.queryParser.QueryParser;
import org.apache.lucene.store.FSDirectory;
-import org.apache.lucene.index.IndexReader;
-import org.apache.lucene.index.TermDocs;
-import org.apache.lucene.index.Term;
+import org.hibernate.Session;
+import org.hibernate.Transaction;
+import org.hibernate.cfg.Configuration;
+import org.hibernate.search.Environment;
+import org.hibernate.search.FullTextSession;
+import org.hibernate.search.Search;
+import org.hibernate.search.store.DirectoryProvider;
+import org.hibernate.search.store.FSDirectoryProvider;
+import org.hibernate.search.store.IdHashShardingStrategy;
+import org.hibernate.search.store.RAMDirectoryProvider;
+import org.hibernate.search.test.SearchTestCase;
+import org.hibernate.search.util.FileHelper;
+
/**
* @author Emmanuel Bernard
*/
@@ -66,13 +67,13 @@
public void testIdShardingStrategy() {
DirectoryProvider[] dps = new DirectoryProvider[] { new RAMDirectoryProvider(), new RAMDirectoryProvider() };
IdHashShardingStrategy shardingStrategy = new IdHashShardingStrategy();
- shardingStrategy.initialize( null, dps);
- assertTrue( dps[1] == shardingStrategy.getDirectoryProviderForAddition( Animal.class, 1, "1", null) );
- assertTrue( dps[0] == shardingStrategy.getDirectoryProviderForAddition( Animal.class, 2, "2", null) );
+ shardingStrategy.initialize( null, dps );
+ assertTrue( dps[1] == shardingStrategy.getDirectoryProviderForAddition( Animal.class, 1, "1", null ) );
+ assertTrue( dps[0] == shardingStrategy.getDirectoryProviderForAddition( Animal.class, 2, "2", null ) );
}
public void testBehavior() throws Exception {
- Session s = openSession( );
+ Session s = openSession();
Transaction tx = s.beginTransaction();
Animal a = new Animal();
a.setId( 1 );
@@ -87,10 +88,10 @@
s.clear();
tx = s.beginTransaction();
- a = (Animal) s.get(Animal.class, 1);
+ a = ( Animal ) s.get( Animal.class, 1 );
a.setName( "Mouse" );
Furniture fur = new Furniture();
- fur.setColor( "dark blue");
+ fur.setColor( "dark blue" );
s.persist( fur );
tx.commit();
@@ -107,13 +108,15 @@
assertEquals( "Mixing shared and non sharded properties fails", 3, results.size() );
results = fts.createFullTextQuery( parser.parse( "name:mouse OR name:bear OR color:blue" ) ).list();
assertEquals( "Mixing shared and non sharded properties fails with indexreader reuse", 3, results.size() );
- for (Object o : results) s.delete( o );
+ for ( Object o : results ) {
+ s.delete( o );
+ }
tx.commit();
s.close();
}
public void testInternalSharding() throws Exception {
- Session s = openSession( );
+ Session s = openSession();
Transaction tx = s.beginTransaction();
Animal a = new Animal();
a.setId( 1 );
@@ -141,7 +144,7 @@
finally {
animal00Directory.close();
}
-
+
FSDirectory animal01Directory = FSDirectory.open( new File( getBaseIndexDir(), "Animal.1" ) );
try {
IndexReader reader = IndexReader.open( animal01Directory );
@@ -158,7 +161,7 @@
}
tx = s.beginTransaction();
- a = (Animal) s.get(Animal.class, 1);
+ a = ( Animal ) s.get( Animal.class, 1 );
a.setName( "Mouse" );
tx.commit();
@@ -189,7 +192,9 @@
List results = fts.createFullTextQuery( parser.parse( "name:mouse OR name:bear" ) ).list();
assertEquals( "Either double insert, single update, or query fails with shards", 2, results.size() );
- for (Object o : results) s.delete( o );
+ for ( Object o : results ) {
+ s.delete( o );
+ }
tx.commit();
s.close();
}
@@ -198,23 +203,23 @@
File sub = getBaseIndexDir();
sub.mkdir();
File[] files = sub.listFiles();
- for (File file : files) {
+ for ( File file : files ) {
if ( file.isDirectory() ) {
FileHelper.delete( file );
}
}
- //super.setUp(); //we need a fresh session factory each time for index set up
- buildSessionFactory( getMappings(), getAnnotatedPackages(), getXmlFiles() );
+ super.setUp();
}
protected void tearDown() throws Exception {
super.tearDown();
File sub = getBaseIndexDir();
FileHelper.delete( sub );
+ setCfg( null ); //we need a fresh session factory each time for index set up
}
@SuppressWarnings("unchecked")
- protected Class<?>[] getMappings() {
+ protected Class<?>[] getAnnotatedClasses() {
return new Class[] {
Animal.class,
Furniture.class
Modified: search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/similarity/SimilarityTest.java
===================================================================
--- search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/similarity/SimilarityTest.java 2010-07-05 14:46:01 UTC (rev 19897)
+++ search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/similarity/SimilarityTest.java 2010-07-05 16:52:21 UTC (rev 19898)
@@ -80,7 +80,7 @@
}
- protected Class<?>[] getMappings() {
+ protected Class<?>[] getAnnotatedClasses() {
return new Class[] {
Trash.class,
Can.class
Modified: search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/worker/ConcurrencyTest.java
===================================================================
--- search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/worker/ConcurrencyTest.java 2010-07-05 14:46:01 UTC (rev 19897)
+++ search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/worker/ConcurrencyTest.java 2010-07-05 16:52:21 UTC (rev 19898)
@@ -69,7 +69,7 @@
}
- protected Class<?>[] getMappings() {
+ protected Class<?>[] getAnnotatedClasses() {
return new Class[] {
Drink.class,
Food.class
Modified: search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/worker/WorkerTestCase.java
===================================================================
--- search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/worker/WorkerTestCase.java 2010-07-05 14:46:01 UTC (rev 19897)
+++ search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/worker/WorkerTestCase.java 2010-07-05 16:52:21 UTC (rev 19898)
@@ -33,6 +33,7 @@
import org.apache.lucene.queryParser.ParseException;
import org.apache.lucene.queryParser.QueryParser;
import org.apache.lucene.search.Query;
+
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
@@ -57,14 +58,14 @@
FileHelper.delete( file );
}
}
- //super.setUp(); //we need a fresh session factory each time for index set up
- buildSessionFactory( getMappings(), getAnnotatedPackages(), getXmlFiles() );
+ super.setUp();
}
protected void tearDown() throws Exception {
super.tearDown();
File sub = getBaseIndexDir();
FileHelper.delete( sub );
+ setCfg( null ); //we need a fresh session factory each time for index set up
}
public void testConcurrency() throws Exception {
@@ -82,14 +83,16 @@
Thread.sleep( 20 );
}
getSessions().close();
- System.out.println( iteration + " iterations (8 tx per iteration) in " + nThreads + " threads: " + ( System
- .currentTimeMillis() - start ) );
+ System.out.println(
+ iteration + " iterations (8 tx per iteration) in " + nThreads + " threads: " + ( System
+ .currentTimeMillis() - start )
+ );
}
protected static class Work implements Runnable {
private SessionFactory sf;
//public volatile int count = 0;
- public AtomicInteger count = new AtomicInteger(0);
+ public AtomicInteger count = new AtomicInteger( 0 );
public Work(SessionFactory sf) {
this.sf = sf;
@@ -112,9 +115,9 @@
s = sf.openSession();
tx = s.beginTransaction();
- ee = (Employee) s.get( Employee.class, ee.getId() );
+ ee = ( Employee ) s.get( Employee.class, ee.getId() );
ee.setName( "Emmanuel2" );
- er = (Employer) s.get( Employer.class, er.getId() );
+ er = ( Employer ) s.get( Employer.class, er.getId() );
er.setName( "RH2" );
tx.commit();
s.close();
@@ -130,12 +133,15 @@
s = sf.openSession();
tx = s.beginTransaction();
FullTextSession fts = new FullTextSessionImpl( s );
- QueryParser parser = new QueryParser( getTargetLuceneVersion(), "id",
- SearchTestCase.stopAnalyzer );
+ QueryParser parser = new QueryParser(
+ getTargetLuceneVersion(), "id",
+ SearchTestCase.stopAnalyzer
+ );
Query query;
try {
query = parser.parse( "name:emmanuel2" );
- } catch ( ParseException e ) {
+ }
+ catch ( ParseException e ) {
throw new RuntimeException( e );
}
boolean results = fts.createFullTextQuery( query ).list().size() > 0;
@@ -147,23 +153,28 @@
s = sf.openSession();
tx = s.beginTransaction();
- ee = (Employee) s.get( Employee.class, ee.getId() );
+ ee = ( Employee ) s.get( Employee.class, ee.getId() );
s.delete( ee );
- er = (Employer) s.get( Employer.class, er.getId() );
+ er = ( Employer ) s.get( Employer.class, er.getId() );
s.delete( er );
tx.commit();
s.close();
// count++;
- } catch ( Throwable t ) {
+ }
+ catch ( Throwable t ) {
t.printStackTrace();
- } finally {
+ }
+ finally {
count.incrementAndGet();
try {
- if ( tx != null && tx.isActive() )
+ if ( tx != null && tx.isActive() ) {
tx.rollback();
- if ( s != null && s.isOpen() )
+ }
+ if ( s != null && s.isOpen() ) {
s.close();
- } catch ( Throwable t ) {
+ }
+ }
+ catch ( Throwable t ) {
t.printStackTrace();
}
}
@@ -191,18 +202,18 @@
s = sf.openSession();
tx = s.beginTransaction();
- er = (Employer) s.get( Employer.class, er.getId() );
+ er = ( Employer ) s.get( Employer.class, er.getId() );
er.setName( "RH2" );
- ee = (Employee) s.get( Employee.class, ee.getId() );
+ ee = ( Employee ) s.get( Employee.class, ee.getId() );
ee.setName( "Emmanuel2" );
tx.commit();
s.close();
s = sf.openSession();
tx = s.beginTransaction();
- er = (Employer) s.get( Employer.class, er.getId() );
+ er = ( Employer ) s.get( Employer.class, er.getId() );
s.delete( er );
- ee = (Employee) s.get( Employee.class, ee.getId() );
+ ee = ( Employee ) s.get( Employee.class, ee.getId() );
s.delete( ee );
tx.commit();
s.close();
@@ -220,8 +231,8 @@
}
@SuppressWarnings("unchecked")
- protected Class<?>[] getMappings() {
- return new Class[]{
+ protected Class<?>[] getAnnotatedClasses() {
+ return new Class[] {
Employee.class,
Employer.class
};
Modified: search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/worker/duplication/WorkDuplicationTest.java
===================================================================
--- search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/worker/duplication/WorkDuplicationTest.java 2010-07-05 14:46:01 UTC (rev 19897)
+++ search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/worker/duplication/WorkDuplicationTest.java 2010-07-05 16:52:21 UTC (rev 19898)
@@ -153,7 +153,7 @@
}
- protected Class<?>[] getMappings() {
+ protected Class<?>[] getAnnotatedClasses() {
return new Class[] { Person.class, EmailAddress.class, SpecialPerson.class };
}
}
Modified: search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/worker/duplication/WorkSequencesTest.java
===================================================================
--- search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/worker/duplication/WorkSequencesTest.java 2010-07-05 14:46:01 UTC (rev 19897)
+++ search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/worker/duplication/WorkSequencesTest.java 2010-07-05 16:52:21 UTC (rev 19898)
@@ -139,7 +139,7 @@
}
@Override
- protected Class<?>[] getMappings() {
+ protected Class<?>[] getAnnotatedClasses() {
return new Class[] {
Domain.class
};
Modified: search/trunk/hibernate-search-testing/pom.xml
===================================================================
--- search/trunk/hibernate-search-testing/pom.xml 2010-07-05 14:46:01 UTC (rev 19897)
+++ search/trunk/hibernate-search-testing/pom.xml 2010-07-05 16:52:21 UTC (rev 19898)
@@ -46,8 +46,13 @@
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
- </dependency>
+ </dependency>
<dependency>
+ <groupId>org.hibernate</groupId>
+ <artifactId>hibernate-testing</artifactId>
+ <version>${hibernateVersion}</version>
+ </dependency>
+ <dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
Modified: search/trunk/hibernate-search-testing/src/main/java/org/hibernate/search/test/SearchTestCase.java
===================================================================
--- search/trunk/hibernate-search-testing/src/main/java/org/hibernate/search/test/SearchTestCase.java 2010-07-05 14:46:01 UTC (rev 19897)
+++ search/trunk/hibernate-search-testing/src/main/java/org/hibernate/search/test/SearchTestCase.java 2010-07-05 16:52:21 UTC (rev 19898)
@@ -1,21 +1,20 @@
-/* $Id$
- *
+/*
* Hibernate, Relational Persistence for Idiomatic Java
- *
- * Copyright (c) 2009, Red Hat, Inc. and/or its affiliates or third-party contributors as
+ *
+ * Copyright (c) 2010, Red Hat, Inc. and/or its affiliates 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, Inc.
- *
+ *
* 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.
@@ -38,39 +37,44 @@
import org.slf4j.Logger;
import org.hibernate.HibernateException;
+import org.hibernate.Interceptor;
import org.hibernate.Session;
+import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.cfg.Configuration;
-import org.hibernate.dialect.Dialect;
import org.hibernate.event.PostInsertEventListener;
import org.hibernate.impl.SessionFactoryImpl;
-import org.hibernate.search.Environment;
import org.hibernate.search.FullTextSession;
import org.hibernate.search.Search;
import org.hibernate.search.SearchFactory;
import org.hibernate.search.annotations.Indexed;
+import org.hibernate.search.engine.SearchFactoryImplementor;
import org.hibernate.search.event.FullTextIndexEventListener;
import org.hibernate.search.store.RAMDirectoryProvider;
-import org.hibernate.tool.hbm2ddl.SchemaExport;
+import org.hibernate.test.annotations.HibernateTestCase;
/**
* Base class for Hibernate Search unit tests.
*
* @author Emmanuel Bernard
+ * @author Hardy Ferentschik
*/
-public abstract class SearchTestCase extends TestCase {
+public abstract class SearchTestCase extends HibernateTestCase {
private static final Logger log = org.hibernate.search.util.LoggerFactory.make();
- public static Analyzer standardAnalyzer = new StandardAnalyzer( getTargetLuceneVersion() );
- public static Analyzer stopAnalyzer = new StopAnalyzer( getTargetLuceneVersion() );
- public static Analyzer simpleAnalyzer = new SimpleAnalyzer();
- public static Analyzer keywordAnalyzer = new KeywordAnalyzer();
+ public static final Analyzer standardAnalyzer = new StandardAnalyzer( getTargetLuceneVersion() );
+ public static final Analyzer stopAnalyzer = new StopAnalyzer( getTargetLuceneVersion() );
+ public static final Analyzer simpleAnalyzer = new SimpleAnalyzer();
+ public static final Analyzer keywordAnalyzer = new KeywordAnalyzer();
+ protected static SessionFactory sessions;
+ protected Session session;
+
private static File indexDir;
- private SearchFactory searchFactory;
+ private SearchFactoryImplementor searchFactory;
static {
String buildDir = System.getProperty( "build.dir" );
@@ -82,17 +86,80 @@
log.debug( "Using {} as index directory.", indexDir.getAbsolutePath() );
}
- protected void setUp() throws Exception {
- buildSessionFactory( getMappings(), getAnnotatedPackages(), getXmlFiles() );
- ensureIndexesAreEmpty();
+ public SearchTestCase() {
+ super();
}
- protected void tearDown() throws Exception {
- SchemaExport export = new SchemaExport( cfg );
- export.drop( false, true );
- searchFactory = null;
+ public SearchTestCase(String x) {
+ super( x );
}
+ @Override
+ protected void handleUnclosedResources() {
+ if ( session != null && session.isOpen() ) {
+ if ( session.isConnected() ) {
+ session.doWork( new RollbackWork() );
+ }
+ session.close();
+ session = null;
+ fail( "unclosed session" );
+ }
+ else {
+ session = null;
+ }
+ }
+
+ @Override
+ protected void closeResources() {
+ try {
+ if ( session != null && session.isOpen() ) {
+ if ( session.isConnected() ) {
+ session.doWork( new RollbackWork() );
+ }
+ session.close();
+ }
+ }
+ catch ( Exception ignore ) {
+ }
+ try {
+ if ( sessions != null ) {
+ sessions.close();
+ sessions = null;
+ }
+ }
+ catch ( Exception ignore ) {
+ }
+ }
+
+ public Session openSession() throws HibernateException {
+ session = getSessions().openSession();
+ return session;
+ }
+
+ public Session openSession(Interceptor interceptor) throws HibernateException {
+ session = getSessions().openSession( interceptor );
+ return session;
+ }
+
+ protected void setSessions(SessionFactory sessions) {
+ SearchTestCase.sessions = sessions;
+ }
+
+ protected SessionFactory getSessions() {
+ return sessions;
+ }
+
+ protected void configure(Configuration cfg) {
+ super.configure( cfg );
+
+ cfg.setProperty( "hibernate.search.default.directory_provider", RAMDirectoryProvider.class.getName() );
+ cfg.setProperty( "hibernate.search.default.indexBase", indexDir.getAbsolutePath() );
+ cfg.setProperty( org.hibernate.search.Environment.ANALYZER_CLASS, StopAnalyzer.class.getName() );
+
+ cfg.setProperty( "hibernate.search.default.transaction.merge_factor", "100" );
+ cfg.setProperty( "hibernate.search.default.batch.max_buffered_docs", "1000" );
+ }
+
protected Directory getDirectory(Class<?> clazz) {
return getLuceneEventListener().getSearchFactoryImplementor().getDirectoryProviders( clazz )[0].getDirectory();
}
@@ -114,6 +181,11 @@
return listener;
}
+ protected void setUp() throws Exception {
+ super.setUp();
+ ensureIndexesAreEmpty();
+ }
+
protected void ensureIndexesAreEmpty() {
if ( "jms".equals( getCfg().getProperty( "hibernate.search.worker.backend" ) ) ) {
log.debug( "JMS based test. Skipping index emptying" );
@@ -122,7 +194,7 @@
FullTextSession s = Search.getFullTextSession( openSession() );
Transaction tx;
tx = s.beginTransaction();
- for ( Class<?> clazz : getMappings() ) {
+ for ( Class<?> clazz : getAnnotatedClasses() ) {
if ( clazz.getAnnotation( Indexed.class ) != null ) {
s.purgeAll( clazz );
}
@@ -135,25 +207,17 @@
if ( searchFactory == null ) {
Session session = openSession();
FullTextSession fullTextSession = Search.getFullTextSession( session );
- searchFactory = fullTextSession.getSearchFactory();
+ searchFactory = ( SearchFactoryImplementor ) fullTextSession.getSearchFactory();
fullTextSession.close();
}
return searchFactory;
}
- protected void configure(Configuration cfg) {
- cfg.setProperty( "hibernate.search.default.directory_provider", RAMDirectoryProvider.class.getName() );
- cfg.setProperty( "hibernate.search.default.indexBase", indexDir.getAbsolutePath() );
- cfg.setProperty( Environment.ANALYZER_CLASS, StopAnalyzer.class.getName() );
- cfg.setProperty( "hibernate.search.default.transaction.merge_factor", "100" );
- cfg.setProperty( "hibernate.search.default.batch.max_buffered_docs", "1000" );
- }
-
protected File getBaseIndexDir() {
return indexDir;
}
- protected void buildSessionFactory(Class<?>[] classes, String[] packages, String[] xmlFiles) throws Exception {
+ protected void buildConfiguration() throws Exception {
if ( getSessions() != null ) {
getSessions().close();
}
@@ -163,17 +227,16 @@
if ( recreateSchema() ) {
cfg.setProperty( org.hibernate.cfg.Environment.HBM2DDL_AUTO, "create-drop" );
}
- for ( String aPackage : packages ) {
+ for ( String aPackage : getAnnotatedPackages() ) {
( ( AnnotationConfiguration ) getCfg() ).addPackage( aPackage );
}
- for ( Class<?> aClass : classes ) {
+ for ( Class<?> aClass : getAnnotatedClasses() ) {
( ( AnnotationConfiguration ) getCfg() ).addAnnotatedClass( aClass );
}
- for ( String xmlFile : xmlFiles ) {
+ for ( String xmlFile : getXmlFiles() ) {
InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream( xmlFile );
getCfg().addInputStream( is );
}
- setDialect( Dialect.getDialect() );
setSessions( getCfg().buildSessionFactory( /*new TestInterceptor()*/ ) );
}
catch ( Exception e ) {
@@ -182,16 +245,10 @@
}
}
- protected abstract Class<?>[] getMappings();
-
protected String[] getAnnotatedPackages() {
return new String[] { };
}
- protected static File getIndexDir() {
- return indexDir;
- }
-
public static Version getTargetLuceneVersion() {
return Version.LUCENE_29;
}
@@ -215,5 +272,4 @@
.getParentFile() // target/classes/
.getParentFile(); // target
}
-
}
Deleted: search/trunk/hibernate-search-testing/src/main/java/org/hibernate/search/test/TestCase.java
===================================================================
--- search/trunk/hibernate-search-testing/src/main/java/org/hibernate/search/test/TestCase.java 2010-07-05 14:46:01 UTC (rev 19897)
+++ search/trunk/hibernate-search-testing/src/main/java/org/hibernate/search/test/TestCase.java 2010-07-05 16:52:21 UTC (rev 19898)
@@ -1,189 +0,0 @@
-/* $Id$
- *
- * Hibernate, Relational Persistence for Idiomatic Java
- *
- * Copyright (c) 2009, Red Hat, Inc. and/or its affiliates 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, Inc.
- *
- * 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.search.test;
-
-import java.io.InputStream;
-
-import org.apache.lucene.analysis.StopAnalyzer;
-
-import org.hibernate.HibernateException;
-import org.hibernate.Interceptor;
-import org.hibernate.Session;
-import org.hibernate.SessionFactory;
-import org.hibernate.search.store.RAMDirectoryProvider;
-import org.hibernate.cfg.Configuration;
-import org.hibernate.cfg.Environment;
-import org.hibernate.dialect.Dialect;
-import org.hibernate.event.FlushEventListener;
-import org.hibernate.event.def.DefaultFlushEventListener;
-import org.hibernate.search.event.FullTextIndexEventListener;
-
-/**
- * A modified base class for tests without annotations.
- *
- * @author Hardy Ferentschik
- */
-public abstract class TestCase extends junit.framework.TestCase {
-
- protected static SessionFactory sessions;
- protected static Configuration cfg;
- protected static Dialect dialect;
- protected static Class lastTestClass;
- protected Session session;
-
- public TestCase() {
- super();
- }
-
- public TestCase(String x) {
- super( x );
- }
-
- protected void buildSessionFactory(String[] xmlFiles) throws Exception {
-
- if ( getSessions() != null ) {
- getSessions().close();
- }
- try {
- setCfg( new Configuration() );
- configure( cfg );
- if ( recreateSchema() ) {
- cfg.setProperty( Environment.HBM2DDL_AUTO, "create-drop" );
- }
- for ( String xmlFile : xmlFiles ) {
- InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream( xmlFile );
- getCfg().addInputStream( is );
- }
- setDialect( Dialect.getDialect() );
- setSessions( getCfg().buildSessionFactory() );
- }
- catch ( Exception e ) {
- e.printStackTrace();
- throw e;
- }
- }
-
- protected void setUp() throws Exception {
- if ( getSessions() == null || getSessions().isClosed() || lastTestClass != getClass() ) {
- buildSessionFactory( getXmlFiles() );
- lastTestClass = getClass();
- }
- }
-
- protected void runTest() throws Throwable {
- try {
- super.runTest();
- if ( session != null && session.isOpen() ) {
- if ( session.isConnected() ) {
- session.connection().rollback();
- }
- session.close();
- session = null;
- fail( "unclosed session" );
- }
- else {
- session = null;
- }
- }
- catch ( Throwable e ) {
- try {
- if ( session != null && session.isOpen() ) {
- if ( session.isConnected() ) {
- session.connection().rollback();
- }
- session.close();
- }
- }
- catch ( Exception ignore ) {
- }
- try {
- if ( sessions != null ) {
- sessions.close();
- sessions = null;
- }
- }
- catch ( Exception ignore ) {
- }
- throw e;
- }
- }
-
- public Session openSession() throws HibernateException {
- session = getSessions().openSession();
- return session;
- }
-
- public Session openSession(Interceptor interceptor) throws HibernateException {
- session = getSessions().openSession( interceptor );
- return session;
- }
-
- protected String[] getXmlFiles() {
- return new String[] { };
- }
-
- protected void setSessions(SessionFactory sessions) {
- TestCase.sessions = sessions;
- }
-
- protected SessionFactory getSessions() {
- return sessions;
- }
-
- protected void setDialect(Dialect dialect) {
- TestCase.dialect = dialect;
- }
-
- protected Dialect getDialect() {
- return dialect;
- }
-
- protected static void setCfg(Configuration cfg) {
- TestCase.cfg = cfg;
- }
-
- protected static Configuration getCfg() {
- return cfg;
- }
-
- protected void configure(Configuration cfg) {
- //needs to register all event listeners:
- cfg.setListener( "post-update", "org.hibernate.search.event.FullTextIndexEventListener" );
- cfg.setListener( "post-insert", "org.hibernate.search.event.FullTextIndexEventListener" );
- cfg.setListener( "post-delete", "org.hibernate.search.event.FullTextIndexEventListener" );
- cfg.setListener( "post-collection-recreate", "org.hibernate.search.event.FullTextIndexEventListener" );
- cfg.setListener( "post-collection-remove", "org.hibernate.search.event.FullTextIndexEventListener" );
- cfg.setListener( "post-collection-update", "org.hibernate.search.event.FullTextIndexEventListener" );
-
- cfg.setListeners( "flush", new FlushEventListener[]{new DefaultFlushEventListener(), new FullTextIndexEventListener()} );
-
- cfg.setProperty( "hibernate.search.default.directory_provider", RAMDirectoryProvider.class.getName() );
- cfg.setProperty( org.hibernate.search.Environment.ANALYZER_CLASS, StopAnalyzer.class.getName() );
- }
-
- protected boolean recreateSchema() {
- return true;
- }
-}
Modified: search/trunk/pom.xml
===================================================================
--- search/trunk/pom.xml 2010-07-05 14:46:01 UTC (rev 19897)
+++ search/trunk/pom.xml 2010-07-05 16:52:21 UTC (rev 19898)
@@ -195,6 +195,11 @@
<version>${hibernateVersion}</version>
</dependency>
<dependency>
+ <groupId>org.hibernate</groupId>
+ <artifactId>hibernate-testing</artifactId>
+ <version>${hibernateVersion}</version>
+ </dependency>
+ <dependency>
<groupId>org.apache.solr</groupId>
<artifactId>solr-core</artifactId>
<version>1.4.0</version>
14 years, 7 months
Hibernate SVN: r19897 - in search/trunk: hibernate-search/src/main/java/org/hibernate/search and 11 other directories.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2010-07-05 10:46:01 -0400 (Mon, 05 Jul 2010)
New Revision: 19897
Added:
search/trunk/hibernate-search/src/main/java/org/hibernate/search/jmx/
search/trunk/hibernate-search/src/main/java/org/hibernate/search/jmx/HibernateSearchConfigInfo.java
search/trunk/hibernate-search/src/main/java/org/hibernate/search/jmx/HibernateSearchConfigInfoMBean.java
search/trunk/hibernate-search/src/main/java/org/hibernate/search/jmx/HibernateSearchIndexCtrl.java
search/trunk/hibernate-search/src/main/java/org/hibernate/search/jmx/HibernateSearchIndexCtrlMBean.java
search/trunk/hibernate-search/src/main/java/org/hibernate/search/util/JNDIHelper.java
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/jmx/
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/jmx/ConfigInfoMBeanTest.java
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/jmx/Counter.java
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/jmx/IndexCtrlMBeanTest.java
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/jmx/NoMBeansEnabledTest.java
Removed:
search/trunk/hibernate-search/src/test/resources/jndi.properties
Modified:
search/trunk/hibernate-search-testing/src/main/java/org/hibernate/search/test/SearchTestCase.java
search/trunk/hibernate-search/pom.xml
search/trunk/hibernate-search/src/main/java/org/hibernate/search/Environment.java
search/trunk/hibernate-search/src/main/java/org/hibernate/search/Search.java
search/trunk/hibernate-search/src/main/java/org/hibernate/search/backend/LuceneIndexingParameters.java
search/trunk/hibernate-search/src/main/java/org/hibernate/search/backend/impl/jms/JMSBackendQueueProcessorFactory.java
search/trunk/hibernate-search/src/main/java/org/hibernate/search/impl/ImmutableSearchFactory.java
search/trunk/hibernate-search/src/main/java/org/hibernate/search/impl/SearchFactoryBuilder.java
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/SearchTestCase.java
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/jms/master/JMSMasterTest.java
search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/jms/slave/JMSSlaveTest.java
Log:
HSEARCH-278 (Create a Search Statistic JMX Bean)
* Added two MBeans - HibernateSearchConfigInfoMBean and HibernateSearchIndexCtrlMBean - with their implementing classes and tests
* Introduced simple-jndi as new dependecy for testing of MBean functionaly
* Refactored all JNDI based tests to not rely on jndi.properties, but rather pass jndi related setting as config parameters
* Some minor formatting
Modified: search/trunk/hibernate-search/pom.xml
===================================================================
--- search/trunk/hibernate-search/pom.xml 2010-07-05 14:30:38 UTC (rev 19896)
+++ search/trunk/hibernate-search/pom.xml 2010-07-05 14:46:01 UTC (rev 19897)
@@ -22,7 +22,9 @@
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
-->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
@@ -76,11 +78,11 @@
<artifactId>jms</artifactId>
<scope>provided</scope>
</dependency>
- <dependency>
- <groupId>javax.annotation</groupId>
- <artifactId>jsr250-api</artifactId>
+ <dependency>
+ <groupId>javax.annotation</groupId>
+ <artifactId>jsr250-api</artifactId>
<scope>provided</scope>
- </dependency>
+ </dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
@@ -96,6 +98,12 @@
<artifactId>activemq-core</artifactId>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>simple-jndi</groupId>
+ <artifactId>simple-jndi</artifactId>
+ <version>0.11.4</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<build>
@@ -139,6 +147,10 @@
<name>java.net.preferIPv4Stack</name>
<value>true</value>
</property>
+ <property>
+ <name>com.sun.management.jmxremote</name>
+ <value>true</value>
+ </property>
</systemProperties>
<excludes>
<exclude>**/classloading/*.java</exclude>
@@ -187,7 +199,10 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<configuration>
- <goals>deploy javadoc:javadoc org.jboss.maven.plugins:maven-jdocbook-plugin:2.2.3:translate org.jboss.maven.plugins:maven-jdocbook-plugin:2.2.3:resources org.jboss.maven.plugins:maven-jdocbook-plugin:2.2.3:generate assembly:assembly</goals>
+ <goals>deploy javadoc:javadoc org.jboss.maven.plugins:maven-jdocbook-plugin:2.2.3:translate
+ org.jboss.maven.plugins:maven-jdocbook-plugin:2.2.3:resources
+ org.jboss.maven.plugins:maven-jdocbook-plugin:2.2.3:generate assembly:assembly
+ </goals>
</configuration>
</plugin>
<plugin>
Modified: search/trunk/hibernate-search/src/main/java/org/hibernate/search/Environment.java
===================================================================
--- search/trunk/hibernate-search/src/main/java/org/hibernate/search/Environment.java 2010-07-05 14:30:38 UTC (rev 19896)
+++ search/trunk/hibernate-search/src/main/java/org/hibernate/search/Environment.java 2010-07-05 14:46:01 UTC (rev 19897)
@@ -66,12 +66,12 @@
* default 1
*/
public static final String WORKER_THREADPOOL_SIZE = Environment.WORKER_PREFIX + "thread_pool.size";
-
+
/**
* Size of the buffer queue (besides the thread pool size)
* <ul>
- * <li>only used then execution is async</li>
- * <li>default infinite</li>
+ * <li>only used then execution is async</li>
+ * <li>default infinite</li>
* </ul>
*/
public static final String WORKER_WORKQUEUE_SIZE = Environment.WORKER_PREFIX + "buffer_queue.max";
@@ -80,28 +80,28 @@
* define the reader prefix
*/
public static final String READER_PREFIX = "hibernate.search.reader.";
-
+
/**
* define the reader strategy used
*/
public static final String READER_STRATEGY = READER_PREFIX + "strategy";
-
+
/**
* filter caching strategy class (must have a no-arg constructor and implement FilterCachingStrategy)
*/
public static final String FILTER_CACHING_STRATEGY = "hibernate.search.filter.cache_strategy";
-
+
/**
* number of docidresults cached in hard reference.
*/
public static final String CACHE_DOCIDRESULTS_SIZE = "hibernate.search.filter.cache_docidresults.size";
-
+
/**
* batch backend implementation class (must have a no-arg constructor and implement BatchBackend)
* also prefix for configuration settings of the batch backend
*/
public static final String BATCH_BACKEND = "hibernate.search.batchbackend";
-
+
/**
* When set to true a lock on the index will not be released until the
* SearchFactory (or SessionFactory) is closed.
@@ -111,17 +111,19 @@
*/
public static final String EXCLUSIVE_INDEX_USE = "exclusive_index_use";
- /**
- *
- */
public static final String MODEL_MAPPING = "hibernate.search.model_mapping";
-
/**
* Set to a fully qualified classname of a type implementing org.hibernate.search.exception.ErrorHandler
* to override the error strategy used during processing of the Lucene updates.
* Default is to log errors.
*/
public static final String ERROR_HANDLER = "hibernate.search.error_handler";
-
+
+ /**
+ * If set to {@code true} the JMX Statistics bean gets enabled. For all other values the bean does not
+ * get enabled.
+ */
+ public static final String JMX_ENABLED = "hibernate.search.jmx_enabled";
+
}
Modified: search/trunk/hibernate-search/src/main/java/org/hibernate/search/Search.java
===================================================================
--- search/trunk/hibernate-search/src/main/java/org/hibernate/search/Search.java 2010-07-05 14:30:38 UTC (rev 19896)
+++ search/trunk/hibernate-search/src/main/java/org/hibernate/search/Search.java 2010-07-05 14:46:01 UTC (rev 19897)
@@ -29,7 +29,7 @@
/**
* Helper class to get a FullTextSession out of a regular session.
- *
+ *
* @author Emmanuel Bernard
* @author Hardy Ferentschik
*/
@@ -39,19 +39,19 @@
}
public static FullTextSession getFullTextSession(Session session) {
- if (session instanceof FullTextSessionImpl) {
- return (FullTextSession) session;
+ if ( session instanceof FullTextSessionImpl ) {
+ return ( FullTextSession ) session;
}
else {
- return new FullTextSessionImpl(session);
+ return new FullTextSessionImpl( session );
}
}
-
+
/**
* @deprecated As of release 3.1.0, replaced by {@link #getFullTextSession(Session)}
*/
- @Deprecated
+ @Deprecated
public static FullTextSession createFullTextSession(Session session) {
- return getFullTextSession(session);
+ return getFullTextSession( session );
}
}
Modified: search/trunk/hibernate-search/src/main/java/org/hibernate/search/backend/LuceneIndexingParameters.java
===================================================================
--- search/trunk/hibernate-search/src/main/java/org/hibernate/search/backend/LuceneIndexingParameters.java 2010-07-05 14:30:38 UTC (rev 19896)
+++ search/trunk/hibernate-search/src/main/java/org/hibernate/search/backend/LuceneIndexingParameters.java 2010-07-05 14:46:01 UTC (rev 19897)
@@ -107,6 +107,16 @@
return batchIndexParameters;
}
+ @Override
+ public String toString() {
+ final StringBuilder sb = new StringBuilder();
+ sb.append( "LuceneIndexingParameters" );
+ sb.append( "{batchIndexParameters=" ).append( batchIndexParameters );
+ sb.append( ", transactionIndexParameters=" ).append( transactionIndexParameters );
+ sb.append( '}' );
+ return sb.toString();
+ }
+
public static class ParameterSet implements Serializable {
private static final long serialVersionUID = -6121723702279869524L;
@@ -182,9 +192,17 @@
return false;
return true;
}
-
- }
+ @Override
+ public String toString() {
+ final StringBuilder sb = new StringBuilder();
+ sb.append( "ParameterSet" );
+ sb.append( "{parameters=" ).append( parameters );
+ sb.append( '}' );
+ return sb.toString();
+ }
+ }
+
public void applyToWriter(IndexWriter writer, boolean batch) {
if ( batch ) {
getBatchIndexParameters().applyToWriter( writer );
Modified: search/trunk/hibernate-search/src/main/java/org/hibernate/search/backend/impl/jms/JMSBackendQueueProcessorFactory.java
===================================================================
--- search/trunk/hibernate-search/src/main/java/org/hibernate/search/backend/impl/jms/JMSBackendQueueProcessorFactory.java 2010-07-05 14:30:38 UTC (rev 19896)
+++ search/trunk/hibernate-search/src/main/java/org/hibernate/search/backend/impl/jms/JMSBackendQueueProcessorFactory.java 2010-07-05 14:46:01 UTC (rev 19897)
@@ -1,8 +1,7 @@
-/* $Id$
- *
+/*
* Hibernate, Relational Persistence for Idiomatic Java
*
- * Copyright (c) 2009, Red Hat, Inc. and/or its affiliates or third-party contributors as
+ * Copyright (c) 2010, Red Hat, Inc. and/or its affiliates 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, Inc.
@@ -24,26 +23,25 @@
*/
package org.hibernate.search.backend.impl.jms;
-import java.util.HashSet;
-import java.util.Iterator;
import java.util.List;
import java.util.Properties;
import java.util.Set;
import javax.jms.Queue;
import javax.jms.QueueConnectionFactory;
-import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import org.hibernate.search.Environment;
-import org.hibernate.search.backend.UpdatableBackendQueueProcessorFactory;
-import org.hibernate.search.spi.WorkerBuildContext;
import org.hibernate.search.SearchException;
import org.hibernate.search.backend.LuceneWork;
+import org.hibernate.search.backend.UpdatableBackendQueueProcessorFactory;
+import org.hibernate.search.spi.WorkerBuildContext;
import org.hibernate.search.store.DirectoryProvider;
+import org.hibernate.search.util.JNDIHelper;
/**
* @author Emmanuel Bernard
+ * @author Hardy Ferentschik
*/
public class JMSBackendQueueProcessorFactory implements UpdatableBackendQueueProcessorFactory {
private String jmsQueueName;
@@ -56,7 +54,7 @@
public static final String JMS_QUEUE = Environment.WORKER_PREFIX + "jms.queue";
public void initialize(Properties props, WorkerBuildContext context) {
- //TODO proper exception if jms queues and connecitons are not there
+ //TODO proper exception if jms queues and connections are not there
this.properties = props;
this.jmsConnectionFactoryName = props.getProperty( JMS_CONNECTION_FACTORY );
this.jmsQueueName = props.getProperty( JMS_QUEUE );
@@ -86,67 +84,30 @@
}
public void prepareJMSTools() {
- if ( jmsQueue != null && factory != null ) return;
+ if ( jmsQueue != null && factory != null ) {
+ return;
+ }
try {
- InitialContext initialContext = getInitialContext( properties );
- factory = (QueueConnectionFactory) initialContext.lookup( jmsConnectionFactoryName );
- jmsQueue = (Queue) initialContext.lookup( jmsQueueName );
+ InitialContext initialContext = JNDIHelper.getInitialContext( properties, JNDI_PREFIX );
+ factory = ( QueueConnectionFactory ) initialContext.lookup( jmsConnectionFactoryName );
+ jmsQueue = ( Queue ) initialContext.lookup( jmsQueueName );
}
- catch (NamingException e) {
- throw new SearchException( "Unable to lookup Search queue ("
- + ( jmsQueueName != null ?
- jmsQueueName :
- "null" ) + ") and connection factory ("
- + ( jmsConnectionFactoryName != null ?
- jmsConnectionFactoryName :
- "null" ) + ")",
+ catch ( NamingException e ) {
+ throw new SearchException(
+ "Unable to lookup Search queue ("
+ + ( jmsQueueName != null ?
+ jmsQueueName :
+ "null" ) + ") and connection factory ("
+ + ( jmsConnectionFactoryName != null ?
+ jmsConnectionFactoryName :
+ "null" ) + ")",
e
);
}
}
- private InitialContext getInitialContext(Properties properties) throws NamingException {
- Properties jndiProps = getJndiProperties( properties );
- if ( jndiProps.size() == 0 ) {
- return new InitialContext();
- }
- else {
- return new InitialContext( jndiProps );
- }
- }
-
- private static Properties getJndiProperties(Properties properties) {
-
- HashSet specialProps = new HashSet();
- specialProps.add( JNDI_PREFIX + "class" );
- specialProps.add( JNDI_PREFIX + "url" );
-
- Iterator iter = properties.keySet().iterator();
- Properties result = new Properties();
- while ( iter.hasNext() ) {
- String prop = (String) iter.next();
- if ( prop.indexOf( JNDI_PREFIX ) > -1 && !specialProps.contains( prop ) ) {
- result.setProperty(
- prop.substring( JNDI_PREFIX.length() ),
- properties.getProperty( prop )
- );
- }
- }
-
- String jndiClass = properties.getProperty( JNDI_PREFIX + "class" );
- String jndiURL = properties.getProperty( JNDI_PREFIX + "url" );
- // we want to be able to just use the defaults,
- // if JNDI environment properties are not supplied
- // so don't put null in anywhere
- if ( jndiClass != null ) result.put( Context.INITIAL_CONTEXT_FACTORY, jndiClass );
- if ( jndiURL != null ) result.put( Context.PROVIDER_URL, jndiURL );
-
- return result;
- }
-
public void close() {
// no need to release anything
}
-
}
Modified: search/trunk/hibernate-search/src/main/java/org/hibernate/search/impl/ImmutableSearchFactory.java
===================================================================
--- search/trunk/hibernate-search/src/main/java/org/hibernate/search/impl/ImmutableSearchFactory.java 2010-07-05 14:30:38 UTC (rev 19896)
+++ search/trunk/hibernate-search/src/main/java/org/hibernate/search/impl/ImmutableSearchFactory.java 2010-07-05 14:46:01 UTC (rev 19897)
@@ -35,9 +35,6 @@
import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.search.Similarity;
-import org.hibernate.search.spi.internals.DirectoryProviderData;
-import org.hibernate.search.spi.internals.PolymorphicIndexHierarchy;
-import org.hibernate.search.spi.internals.StateSearchFactoryImplementor;
import org.slf4j.Logger;
import org.hibernate.annotations.common.AssertionFailure;
@@ -63,6 +60,9 @@
import org.hibernate.search.query.dsl.v2.impl.ConnectedQueryContextBuilder;
import org.hibernate.search.reader.ReaderProvider;
import org.hibernate.search.spi.WorkerBuildContext;
+import org.hibernate.search.spi.internals.DirectoryProviderData;
+import org.hibernate.search.spi.internals.PolymorphicIndexHierarchy;
+import org.hibernate.search.spi.internals.StateSearchFactoryImplementor;
import org.hibernate.search.store.DirectoryProvider;
import org.hibernate.search.store.optimization.OptimizerStrategy;
import org.hibernate.search.util.LoggerFactory;
@@ -71,7 +71,7 @@
/**
* This implementation is never directly exposed to the user, it is always wrapped into a {@link org.hibernate.search.impl.MutableSearchFactory}
- *
+ *
* @author Emmanuel Bernard
*/
public class ImmutableSearchFactory implements StateSearchFactoryImplementor, WorkerBuildContext {
@@ -122,7 +122,6 @@
this.worker = cfg.worker;
}
-
public BackendQueueProcessorFactory getBackendQueueProcessorFactory() {
return backendQueueProcessorFactory;
}
@@ -202,7 +201,7 @@
}
public void setBackendQueueProcessorFactory(BackendQueueProcessorFactory backendQueueProcessorFactory) {
- throw new AssertionFailure( "ImmutableSearchFactory is immutable: should never be called");
+ throw new AssertionFailure( "ImmutableSearchFactory is immutable: should never be called" );
}
public OptimizerStrategy getOptimizerStrategy(DirectoryProvider<?> provider) {
@@ -296,7 +295,7 @@
public Set<Class<?>> getIndexedTypesPolymorphic(Class<?>[] classes) {
return indexHierarchy.getIndexedClasses( classes );
}
-
+
public BatchBackend makeBatchBackend(MassIndexerProgressMonitor progressMonitor) {
BatchBackend batchBackend;
String impl = configurationProperties.getProperty( Environment.BATCH_BACKEND );
@@ -304,18 +303,23 @@
batchBackend = new LuceneBatchBackend();
}
else {
- batchBackend = PluginLoader.instanceFromName( BatchBackend.class, impl, ImmutableSearchFactory.class,
- "batchbackend" );
+ batchBackend = PluginLoader.instanceFromName(
+ BatchBackend.class, impl, ImmutableSearchFactory.class,
+ "batchbackend"
+ );
}
Properties batchBackendConfiguration = new MaskedProperty(
- this.configurationProperties, Environment.BATCH_BACKEND );
+ this.configurationProperties, Environment.BATCH_BACKEND
+ );
batchBackend.initialize( batchBackendConfiguration, progressMonitor, this );
return batchBackend;
}
public Similarity getSimilarity(DirectoryProvider<?> provider) {
Similarity similarity = dirProviderData.get( provider ).getSimilarity();
- if ( similarity == null ) throw new SearchException( "Assertion error: a similarity should be defined for each provider" );
+ if ( similarity == null ) {
+ throw new SearchException( "Assertion error: a similarity should be defined for each provider" );
+ }
return similarity;
}
Modified: search/trunk/hibernate-search/src/main/java/org/hibernate/search/impl/SearchFactoryBuilder.java
===================================================================
--- search/trunk/hibernate-search/src/main/java/org/hibernate/search/impl/SearchFactoryBuilder.java 2010-07-05 14:30:38 UTC (rev 19896)
+++ search/trunk/hibernate-search/src/main/java/org/hibernate/search/impl/SearchFactoryBuilder.java 2010-07-05 14:46:01 UTC (rev 19897)
@@ -1,6 +1,30 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2010, Red Hat, Inc. and/or its affiliates 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, Inc.
+ *
+ * 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.search.impl;
import java.beans.Introspector;
+import java.lang.management.ManagementFactory;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collections;
@@ -12,16 +36,12 @@
import java.util.Properties;
import java.util.Set;
import java.util.concurrent.locks.ReentrantLock;
+import javax.management.MBeanServer;
+import javax.management.MalformedObjectNameException;
+import javax.management.ObjectName;
import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.search.Similarity;
-
-import org.hibernate.search.backend.UpdatableBackendQueueProcessorFactory;
-import org.hibernate.search.spi.WorkerBuildContext;
-import org.hibernate.search.spi.WritableBuildContext;
-import org.hibernate.search.spi.internals.DirectoryProviderData;
-import org.hibernate.search.spi.internals.PolymorphicIndexHierarchy;
-import org.hibernate.search.spi.internals.StateSearchFactoryImplementor;
import org.slf4j.Logger;
import org.hibernate.annotations.common.reflection.MetadataProvider;
@@ -40,6 +60,7 @@
import org.hibernate.search.annotations.Key;
import org.hibernate.search.backend.BackendQueueProcessorFactory;
import org.hibernate.search.backend.LuceneIndexingParameters;
+import org.hibernate.search.backend.UpdatableBackendQueueProcessorFactory;
import org.hibernate.search.backend.Worker;
import org.hibernate.search.backend.WorkerFactory;
import org.hibernate.search.backend.configuration.ConfigurationParseHelper;
@@ -56,8 +77,16 @@
import org.hibernate.search.filter.FilterCachingStrategy;
import org.hibernate.search.filter.MRUFilterCachingStrategy;
import org.hibernate.search.filter.ShardSensitiveOnlyFilter;
+import org.hibernate.search.jmx.HibernateSearchConfigInfo;
+import org.hibernate.search.jmx.HibernateSearchConfigInfoMBean;
+import org.hibernate.search.jmx.HibernateSearchIndexCtrl;
import org.hibernate.search.reader.ReaderProvider;
import org.hibernate.search.reader.ReaderProviderFactory;
+import org.hibernate.search.spi.WorkerBuildContext;
+import org.hibernate.search.spi.WritableBuildContext;
+import org.hibernate.search.spi.internals.DirectoryProviderData;
+import org.hibernate.search.spi.internals.PolymorphicIndexHierarchy;
+import org.hibernate.search.spi.internals.StateSearchFactoryImplementor;
import org.hibernate.search.store.DirectoryProvider;
import org.hibernate.search.store.DirectoryProviderFactory;
import org.hibernate.search.store.optimization.OptimizerStrategy;
@@ -67,8 +96,10 @@
import org.hibernate.util.StringHelper;
/**
- * Build a search factory
+ * Build a search factory.
+ *
* @author Emmanuel Bernard
+ * @author Hardy Ferentschik
*/
public class SearchFactoryBuilder {
private static final Logger log = LoggerFactory.make();
@@ -111,25 +142,75 @@
Map<DirectoryProvider, LuceneIndexingParameters> dirProviderIndexingParams;
public SearchFactoryImplementor buildSearchFactory() {
- if (rootFactory == null) {
- if (classes.size() > 0) {
- throw new SearchException( "Cannot add a class if the original SearchFactory is not passed");
+ SearchFactoryImplementor searchFactoryImplementor;
+ if ( rootFactory == null ) {
+ if ( classes.size() > 0 ) {
+ throw new SearchException( "Cannot add a class if the original SearchFactory is not passed" );
}
- return buildNewSearchFactory();
+ searchFactoryImplementor = buildNewSearchFactory();
}
else {
- return buildIncrementalSearchFactory();
+ searchFactoryImplementor = buildIncrementalSearchFactory();
}
+
+ String enableJMX = configurationProperties.getProperty( Environment.JMX_ENABLED );
+ if ( "true".equalsIgnoreCase( enableJMX ) ) {
+ enableJMXStatistics( searchFactoryImplementor );
+ }
+ return searchFactoryImplementor;
}
+ private void enableJMXStatistics(SearchFactoryImplementor searchFactoryImplementor) {
+ HibernateSearchConfigInfo statsBean = new HibernateSearchConfigInfo( searchFactoryImplementor );
+ ObjectName name = createObjectName( HibernateSearchConfigInfoMBean.CONFIG_MBEAN_OBJECT_NAME );
+ registerMBean( statsBean, name );
+
+ // if we have a JNDI bound SessionFactory we can also enable the index control bean
+ if ( StringHelper.isNotEmpty( configurationProperties.getProperty( "hibernate.session_factory_name" ) ) ) {
+ HibernateSearchIndexCtrl indexCtrlBean = new HibernateSearchIndexCtrl( configurationProperties );
+ name = createObjectName( HibernateSearchIndexCtrl.INDEX_CTRL_MBEAN_OBJECT_NAME );
+ registerMBean( indexCtrlBean, name );
+ }
+ }
+
+ private ObjectName createObjectName(String name) {
+ ObjectName objectName;
+ try {
+ objectName = new ObjectName( name );
+ }
+ catch ( MalformedObjectNameException e ) {
+ throw new SearchException( "Invalid JMX Bean name: " + name, e );
+ }
+ return objectName;
+ }
+
+ private void registerMBean(Object stats, ObjectName name) {
+ MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
+ if ( mbs.isRegistered( name ) ) {
+ try {
+ mbs.unregisterMBean( name );
+ }
+ catch ( Exception e ) {
+ log.warn( "Unable to un-register existing MBean: " + name, e );
+ }
+ }
+
+ try {
+ mbs.registerMBean( stats, name );
+ }
+ catch ( Exception e ) {
+ throw new SearchException( "Unable to enable MBean for Hibernate Search", e );
+ }
+ }
+
private SearchFactoryImplementor buildIncrementalSearchFactory() {
removeClassesAlreadyManaged();
- if (classes.size() == 0) {
+ if ( classes.size() == 0 ) {
return rootFactory;
}
BuildContext buildContext = new BuildContext();
- copyStateFromOldFactory(rootFactory);
+ copyStateFromOldFactory( rootFactory );
//TODO we don't keep the reflectionManager. Is that an issue?
IncrementalSearchConfiguration cfg = new IncrementalSearchConfiguration( classes, configurationProperties );
reflectionManager = getReflectionManager( cfg );
@@ -152,7 +233,7 @@
//update backend
final BackendQueueProcessorFactory backend = this.backendQueueProcessorFactory;
- if ( backend instanceof UpdatableBackendQueueProcessorFactory) {
+ if ( backend instanceof UpdatableBackendQueueProcessorFactory ) {
final UpdatableBackendQueueProcessorFactory updatableBackend = ( UpdatableBackendQueueProcessorFactory ) backend;
updatableBackend.updateDirectoryProviders( this.dirProviderData.keySet(), buildContext );
}
@@ -168,13 +249,13 @@
private void removeClassesAlreadyManaged() {
Set<Class<?>> remove = new HashSet<Class<?>>();
final Map<Class<?>, DocumentBuilderContainedEntity<?>> containedEntities = rootFactory.getDocumentBuildersContainedEntities();
- final Map<Class<?>, DocumentBuilderIndexedEntity<?>> indexedEntities = rootFactory.getDocumentBuildersIndexedEntities();
- for (Class<?> entity : classes) {
- if ( indexedEntities.containsKey( entity ) || containedEntities.containsKey(entity) ) {
+ final Map<Class<?>, DocumentBuilderIndexedEntity<?>> indexedEntities = rootFactory.getDocumentBuildersIndexedEntities();
+ for ( Class<?> entity : classes ) {
+ if ( indexedEntities.containsKey( entity ) || containedEntities.containsKey( entity ) ) {
remove.add( entity );
}
}
- for(Class<?> entity : remove) {
+ for ( Class<?> entity : remove ) {
classes.remove( entity );
}
}
@@ -202,16 +283,18 @@
configurationProperties = cfg.getProperties();
errorHandler = createErrorHandler( configurationProperties );
- reflectionManager = getReflectionManager(cfg);
+ reflectionManager = getReflectionManager( cfg );
BuildContext buildContext = new BuildContext();
- final SearchMapping mapping = SearchMappingBuilder.getSearchMapping(cfg);
- if ( mapping != null) {
- if ( ! ( reflectionManager instanceof MetadataProviderInjector )) {
- throw new SearchException("Programmatic mapping model used but ReflectionManager does not implement "
- + MetadataProviderInjector.class.getName() );
+ final SearchMapping mapping = SearchMappingBuilder.getSearchMapping( cfg );
+ if ( mapping != null ) {
+ if ( !( reflectionManager instanceof MetadataProviderInjector ) ) {
+ throw new SearchException(
+ "Programmatic mapping model used but ReflectionManager does not implement "
+ + MetadataProviderInjector.class.getName()
+ );
}
- MetadataProviderInjector injector = (MetadataProviderInjector) reflectionManager;
+ MetadataProviderInjector injector = ( MetadataProviderInjector ) reflectionManager;
MetadataProvider original = injector.getMetadataProvider();
injector.setMetadataProvider( new MappingModelMetadataProvider( original, mapping ) );
}
@@ -248,10 +331,12 @@
DocumentBuilderIndexedEntity<?> documentBuilder = documentBuildersIndexedEntities.get( indexedType );
Similarity similarity = documentBuilder.getSimilarity();
Similarity prevSimilarity = directoryConfiguration.getSimilarity();
- if ( prevSimilarity != null && ! prevSimilarity.getClass().equals( similarity.getClass() ) ) {
- throw new SearchException( "Multiple entities are sharing the same index but are declaring an " +
- "inconsistent Similarity. When overrriding default Similarity make sure that all types sharing a same index " +
- "declare the same Similarity implementation." );
+ if ( prevSimilarity != null && !prevSimilarity.getClass().equals( similarity.getClass() ) ) {
+ throw new SearchException(
+ "Multiple entities are sharing the same index but are declaring an " +
+ "inconsistent Similarity. When overrriding default Similarity make sure that all types sharing a same index " +
+ "declare the same Similarity implementation."
+ );
}
else {
directoryConfiguration.setSimilarity( similarity );
@@ -267,8 +352,10 @@
filterCachingStrategy = new MRUFilterCachingStrategy();
}
else {
- filterCachingStrategy = PluginLoader.instanceFromName( FilterCachingStrategy.class,
- impl, ImmutableSearchFactory.class, "filterCachingStrategy" );
+ filterCachingStrategy = PluginLoader.instanceFromName(
+ FilterCachingStrategy.class,
+ impl, ImmutableSearchFactory.class, "filterCachingStrategy"
+ );
}
filterCachingStrategy.initialize( properties );
return filterCachingStrategy;
@@ -289,20 +376,21 @@
* Initialize the document builder
* This algorithm seems to be safe for incremental search factories.
*/
+
private void initDocumentBuilders(SearchConfiguration cfg, ReflectionManager reflectionManager, BuildContext buildContext) {
ConfigContext context = new ConfigContext( cfg );
Iterator<Class<?>> iter = cfg.getClassMappings();
DirectoryProviderFactory factory = new DirectoryProviderFactory();
- initProgrammaticAnalyzers(context, reflectionManager);
- initProgrammaticallyDefinedFilterDef(reflectionManager);
+ initProgrammaticAnalyzers( context, reflectionManager );
+ initProgrammaticallyDefinedFilterDef( reflectionManager );
while ( iter.hasNext() ) {
Class<?> mappedClass = iter.next();
if ( mappedClass == null ) {
continue;
}
- @SuppressWarnings( "unchecked" )
+ @SuppressWarnings("unchecked")
XClass mappedXClass = reflectionManager.toXClass( mappedClass );
if ( mappedXClass == null ) {
continue;
@@ -367,7 +455,7 @@
);
}
- bindFullTextFilterDef(defAnn);
+ bindFullTextFilterDef( defAnn );
}
private void bindFullTextFilterDef(FullTextFilterDef defAnn) {
@@ -419,10 +507,10 @@
private void initProgrammaticAnalyzers(ConfigContext context, ReflectionManager reflectionManager) {
final Map defaults = reflectionManager.getDefaults();
- if (defaults != null) {
- AnalyzerDef[] defs = (AnalyzerDef[]) defaults.get( AnalyzerDefs.class );
+ if ( defaults != null ) {
+ AnalyzerDef[] defs = ( AnalyzerDef[] ) defaults.get( AnalyzerDefs.class );
if ( defs != null ) {
- for (AnalyzerDef def : defs) {
+ for ( AnalyzerDef def : defs ) {
context.addAnalyzerDef( def );
}
}
@@ -431,13 +519,13 @@
private void initProgrammaticallyDefinedFilterDef(ReflectionManager reflectionManager) {
@SuppressWarnings("unchecked") Map defaults = reflectionManager.getDefaults();
- FullTextFilterDef[] filterDefs = (FullTextFilterDef[]) defaults.get( FullTextFilterDefs.class);
- if (filterDefs != null && filterDefs.length != 0) {
- for (FullTextFilterDef defAnn : filterDefs) {
+ FullTextFilterDef[] filterDefs = ( FullTextFilterDef[] ) defaults.get( FullTextFilterDefs.class );
+ if ( filterDefs != null && filterDefs.length != 0 ) {
+ for ( FullTextFilterDef defAnn : filterDefs ) {
if ( filterDefinitions.containsKey( defAnn.name() ) ) {
- throw new SearchException("Multiple definition of @FullTextFilterDef.name=" + defAnn.name());
+ throw new SearchException( "Multiple definition of @FullTextFilterDef.name=" + defAnn.name() );
}
- bindFullTextFilterDef(defAnn);
+ bindFullTextFilterDef( defAnn );
}
}
}
@@ -451,8 +539,10 @@
return new LogErrorHandler();
}
else {
- return PluginLoader.instanceFromName( ErrorHandler.class, errorHandlerClassName,
- ImmutableSearchFactory.class, "Error Handler" );
+ return PluginLoader.instanceFromName(
+ ErrorHandler.class, errorHandlerClassName,
+ ImmutableSearchFactory.class, "Error Handler"
+ );
}
}
@@ -534,7 +624,9 @@
public Similarity getSimilarity(DirectoryProvider<?> provider) {
Similarity similarity = dirProviderData.get( provider ).getSimilarity();
- if ( similarity == null ) throw new SearchException( "Assertion error: a similarity should be defined for each provider" );
+ if ( similarity == null ) {
+ throw new SearchException( "Assertion error: a similarity should be defined for each provider" );
+ }
return similarity;
}
@@ -550,6 +642,6 @@
public <T> DocumentBuilderIndexedEntity<T> getDocumentBuilderIndexedEntity(Class<T> entityType) {
return ( DocumentBuilderIndexedEntity<T> ) documentBuildersIndexedEntities.get( entityType );
}
-
+
}
}
Added: search/trunk/hibernate-search/src/main/java/org/hibernate/search/jmx/HibernateSearchConfigInfo.java
===================================================================
--- search/trunk/hibernate-search/src/main/java/org/hibernate/search/jmx/HibernateSearchConfigInfo.java (rev 0)
+++ search/trunk/hibernate-search/src/main/java/org/hibernate/search/jmx/HibernateSearchConfigInfo.java 2010-07-05 14:46:01 UTC (rev 19897)
@@ -0,0 +1,131 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2010, Red Hat, Inc. and/or its affiliates 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, Inc.
+ *
+ * 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.search.jmx;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.index.Term;
+import org.apache.lucene.search.BooleanClause;
+import org.apache.lucene.search.BooleanQuery;
+import org.apache.lucene.search.IndexSearcher;
+import org.apache.lucene.search.MatchAllDocsQuery;
+import org.apache.lucene.search.TermQuery;
+import org.apache.lucene.search.TopDocs;
+
+import org.hibernate.search.ProjectionConstants;
+import org.hibernate.search.engine.SearchFactoryImplementor;
+import org.hibernate.search.reader.ReaderProvider;
+import org.hibernate.search.store.DirectoryProvider;
+import org.hibernate.util.ReflectHelper;
+
+/**
+ * Implementation of the {@code HibernateSearchConfigInfoMBean} JMX attributes and operations.
+ *
+ * @author Hardy Ferentschik
+ */
+public class HibernateSearchConfigInfo implements HibernateSearchConfigInfoMBean {
+
+ private final SearchFactoryImplementor searchFactoryImplementor;
+
+ public HibernateSearchConfigInfo(SearchFactoryImplementor searchFactoryImplementor) {
+ this.searchFactoryImplementor = searchFactoryImplementor;
+ }
+
+ public Set<String> getIndexedClassNames() {
+ Set<String> indexedClasses = new HashSet<String>();
+ for ( Class clazz : searchFactoryImplementor.getDocumentBuildersIndexedEntities().keySet() ) {
+ indexedClasses.add( clazz.getName() );
+ }
+ return indexedClasses;
+ }
+
+ public String getIndexingStrategy() {
+ return searchFactoryImplementor.getIndexingStrategy();
+ }
+
+ public int getNumberOfIndexedEntities(String entity) {
+ Class<?> clazz = getEntityClass( entity );
+ DirectoryProvider[] directoryProviders = searchFactoryImplementor.getDirectoryProviders( clazz );
+ ReaderProvider readerProvider = searchFactoryImplementor.getReaderProvider();
+
+ int count = 0;
+ for ( DirectoryProvider directoryProvider : directoryProviders ) {
+ IndexReader reader = readerProvider.openReader( directoryProvider );
+ IndexSearcher searcher = new IndexSearcher( reader );
+ BooleanQuery boolQuery = new BooleanQuery();
+ boolQuery.add( new MatchAllDocsQuery(), BooleanClause.Occur.MUST );
+ boolQuery.add(
+ new TermQuery( new Term( ProjectionConstants.OBJECT_CLASS, entity ) ), BooleanClause.Occur.MUST
+ );
+ try {
+ TopDocs topdocs = searcher.search( boolQuery, 1 );
+ count += topdocs.totalHits;
+ }
+ catch ( IOException e ) {
+ throw new RuntimeException( "Unable to execute count query for entity " + entity, e );
+ }
+ finally {
+ readerProvider.closeReader( reader );
+ }
+ }
+ return count;
+ }
+
+ public Map<String, Integer> indexedEntitiesCount() {
+ Map<String, Integer> countPerEntity = new HashMap<String, Integer>();
+ for ( String className : getIndexedClassNames() ) {
+ countPerEntity.put( className, getNumberOfIndexedEntities( className ) );
+ }
+ return countPerEntity;
+ }
+
+ public List<String> getIndexingParameters(String entity) {
+ Class<?> clazz = getEntityClass( entity );
+ List<String> indexingParameters = new ArrayList<String>();
+ for ( DirectoryProvider directoryProvider : searchFactoryImplementor.getDirectoryProviders( clazz ) ) {
+ indexingParameters.add( searchFactoryImplementor.getIndexingParameters( directoryProvider ).toString() );
+ }
+ return indexingParameters;
+ }
+
+ private Class<?> getEntityClass(String entity) {
+ Class<?> clazz;
+ try {
+ clazz = ReflectHelper.classForName( entity, HibernateSearchConfigInfo.class );
+ }
+ catch ( ClassNotFoundException e ) {
+ throw new IllegalArgumentException( entity + "not a indexed entity" );
+ }
+ return clazz;
+ }
+}
+
+
Added: search/trunk/hibernate-search/src/main/java/org/hibernate/search/jmx/HibernateSearchConfigInfoMBean.java
===================================================================
--- search/trunk/hibernate-search/src/main/java/org/hibernate/search/jmx/HibernateSearchConfigInfoMBean.java (rev 0)
+++ search/trunk/hibernate-search/src/main/java/org/hibernate/search/jmx/HibernateSearchConfigInfoMBean.java 2010-07-05 14:46:01 UTC (rev 19897)
@@ -0,0 +1,83 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2010, Red Hat, Inc. and/or its affiliates 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, Inc.
+ *
+ * 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.search.jmx;
+
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * Defines the Hibernate Search exposed JMX attributes and operations for index configuration.
+ *
+ * @author Hardy Ferentschik
+ */
+public interface HibernateSearchConfigInfoMBean {
+
+ public static final String CONFIG_MBEAN_OBJECT_NAME = "org.hibernate.search.jmx:type=HibernateSearchConfigInfoMBean";
+
+ /**
+ * Returns a list of all indexed classes.
+ *
+ * @return list of all indexed classes
+ */
+ Set<String> getIndexedClassNames();
+
+ /**
+ * Returns the indexing strategy - <i>manual</i> vs. event <i>event</i>.
+ *
+ * @return the indexing strategy
+ */
+ String getIndexingStrategy();
+
+ /**
+ * Returns the number of documents for the given entity.
+ *
+ * @param entity the fqc of the entity
+ *
+ * @return number of documents for the specified entity name
+ *
+ * @throws IllegalArgumentException in case the entity name is not valid
+ */
+ int getNumberOfIndexedEntities(String entity);
+
+ /**
+ * A list of string representations of the indexing parameters for each directory of the specified entity.
+ * Defaults are not displayed, but only parameters which are explicitly set via the configuration.
+ *
+ * @param entity the fqc of the entity
+ *
+ * @return A list of string representations of the indexing parameters for each directory of the specified entity
+ *
+ * @throws IllegalArgumentException in case the entity name is not valid
+ */
+ List<String> getIndexingParameters(String entity);
+
+ /**
+ * Returns a map of all indexed entities and their document count in the index.
+ *
+ * @return a map of all indexed entities and their document count. The map key is the fqc of the entity and
+ * the map value is the document count.
+ */
+ Map<String, Integer> indexedEntitiesCount();
+}
Added: search/trunk/hibernate-search/src/main/java/org/hibernate/search/jmx/HibernateSearchIndexCtrl.java
===================================================================
--- search/trunk/hibernate-search/src/main/java/org/hibernate/search/jmx/HibernateSearchIndexCtrl.java (rev 0)
+++ search/trunk/hibernate-search/src/main/java/org/hibernate/search/jmx/HibernateSearchIndexCtrl.java 2010-07-05 14:46:01 UTC (rev 19897)
@@ -0,0 +1,115 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2010, Red Hat, Inc. and/or its affiliates 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, Inc.
+ *
+ * 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.search.jmx;
+
+import java.util.Properties;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+
+import org.hibernate.CacheMode;
+import org.hibernate.Session;
+import org.hibernate.SessionFactory;
+import org.hibernate.search.FullTextSession;
+import org.hibernate.search.Search;
+import org.hibernate.search.util.JNDIHelper;
+import org.hibernate.util.ReflectHelper;
+
+
+/**
+ * Implementation of the {@code HibernateSearchIndexCtrlMBean} JMX attributes and operations.
+ *
+ * @author Hardy Ferentschik
+ */
+public class HibernateSearchIndexCtrl implements HibernateSearchIndexCtrlMBean {
+ private static final String HIBERNATE_JNDI_PREFIX = "hibernate.jndi.";
+
+ private final Properties jndiProperties;
+ private final String sessionFactoryJndiName;
+
+ public HibernateSearchIndexCtrl(Properties props) {
+ this.sessionFactoryJndiName = props.getProperty( "hibernate.session_factory_name" );
+ this.jndiProperties = JNDIHelper.getJndiProperties( props, HIBERNATE_JNDI_PREFIX );
+ }
+
+ public void index(String entity) {
+ Class<?> clazz = getEntityClass( entity );
+
+ SessionFactory factory = getSessionFactory();
+ Session session = factory.openSession();
+ FullTextSession fulltextSession = Search.getFullTextSession( session );
+ try {
+ fulltextSession.createIndexer( clazz )
+ .batchSizeToLoadObjects( 25 )
+ .cacheMode( CacheMode.NORMAL )
+ .threadsToLoadObjects( 5 )
+ .threadsForSubsequentFetching( 20 )
+ .startAndWait();
+ }
+ catch ( InterruptedException e ) {
+ throw new RuntimeException( "Unable to complete indexing" );
+ }
+ session.close();
+ }
+
+ public void purge(String entity) {
+ Class<?> clazz = getEntityClass( entity );
+
+ SessionFactory factory = getSessionFactory();
+ Session session = factory.openSession();
+ FullTextSession fullTextSession = Search.getFullTextSession( session );
+ fullTextSession.beginTransaction();
+ fullTextSession.purgeAll( clazz );
+ fullTextSession.getTransaction().commit();
+ session.close();
+ }
+
+ private Class<?> getEntityClass(String entity) {
+ Class<?> clazz;
+ try {
+ clazz = ReflectHelper.classForName( entity, HibernateSearchIndexCtrl.class );
+ }
+ catch ( ClassNotFoundException e ) {
+ throw new IllegalArgumentException( entity + "not a indexed entity" );
+ }
+ return clazz;
+ }
+
+ private SessionFactory getSessionFactory() {
+ try {
+ Context initialContext;
+ if ( jndiProperties.isEmpty() ) {
+ initialContext = new InitialContext();
+ }
+ else {
+ initialContext = new InitialContext( jndiProperties );
+ }
+ return ( SessionFactory ) initialContext.lookup( sessionFactoryJndiName );
+ }
+ catch ( Exception e ) {
+ throw new UnsupportedOperationException(
+ "In order for this operation to work the SessionFactory must be bound to JNDI"
+ );
+ }
+ }
+}
\ No newline at end of file
Added: search/trunk/hibernate-search/src/main/java/org/hibernate/search/jmx/HibernateSearchIndexCtrlMBean.java
===================================================================
--- search/trunk/hibernate-search/src/main/java/org/hibernate/search/jmx/HibernateSearchIndexCtrlMBean.java (rev 0)
+++ search/trunk/hibernate-search/src/main/java/org/hibernate/search/jmx/HibernateSearchIndexCtrlMBean.java 2010-07-05 14:46:01 UTC (rev 19897)
@@ -0,0 +1,62 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2010, Red Hat, Inc. and/or its affiliates 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, Inc.
+ *
+ * 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.search.jmx;
+
+/**
+ * Defines the Hibernate Search exposed JMX attributes and operations for index creation and purging.
+ *
+ * @author Hardy Ferentschik
+ */
+public interface HibernateSearchIndexCtrlMBean {
+
+ public static final String INDEX_CTRL_MBEAN_OBJECT_NAME = "org.hibernate.search.jmx:type=HibernateSearchIndexCtrlMBean";
+
+ /**
+ * Index the specified entity using the mass indexer.
+ * <p><b>Note:<br/>
+ * This method is only available if the Hibernate {@code SessionFactory}
+ * is available via JNDI.
+ * </p>
+ *
+ * @param entity The fqc of the entity to index
+ *
+ * @throws IllegalArgumentException in case the entity name is not valid
+ * @throws UnsupportedOperationException in case the Hibernate {@code SessionFactory} is not bound via JNDI.
+ */
+ void index(String entity);
+
+ /**
+ * Purge the index of the specified entity.
+ * <p><b>Note:<br/>
+ * This method is only available if the Hibernate {@code SessionFactory}
+ * is available via JNDI.
+ * </p>
+ *
+ * @param entity The fqc of the entity to index
+ *
+ * @throws IllegalArgumentException in case the entity name is not valid
+ * @throws UnsupportedOperationException in case the Hibernate {@code SessionFactory} is not bound via JNDI.
+ */
+ void purge(String entity);
+}
\ No newline at end of file
Added: search/trunk/hibernate-search/src/main/java/org/hibernate/search/util/JNDIHelper.java
===================================================================
--- search/trunk/hibernate-search/src/main/java/org/hibernate/search/util/JNDIHelper.java (rev 0)
+++ search/trunk/hibernate-search/src/main/java/org/hibernate/search/util/JNDIHelper.java 2010-07-05 14:46:01 UTC (rev 19897)
@@ -0,0 +1,112 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2010, Red Hat, Inc. and/or its affiliates 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, Inc.
+ *
+ * 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.search.util;
+
+import java.util.HashSet;
+import java.util.Properties;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+
+/**
+ * Helper class for creating an JNDI {@code InitialContext}.
+ *
+ * @author Hardy Ferentschik
+ */
+public class JNDIHelper {
+ private JNDIHelper() {
+ }
+
+ /**
+ * Creates an initial context
+ *
+ * @param properties Configuration properties to check for JNDI specific properties
+ * @param prefix The prefix used to designate JDNI properties. If a property from {@code property} contains
+ * a property which matches the prefix, the prefix gets removed and the property passed to the initial context creation.
+ *
+ * @return the initial context
+ *
+ * @throws NamingException in case an error occurs creating the {@code InitialContext}
+ */
+ public static InitialContext getInitialContext(Properties properties, String prefix) throws NamingException {
+ Properties jndiProps = getJndiProperties( properties, prefix );
+ if ( jndiProps.size() == 0 ) {
+ return new InitialContext();
+ }
+ else {
+ return new InitialContext( jndiProps );
+ }
+ }
+
+ public static Properties getJndiProperties(Properties properties, String prefix) {
+
+ HashSet<String> specialProps = new HashSet<String>();
+ specialProps.add( prefix + "class" );
+ specialProps.add( prefix + "url" );
+
+ Properties result = addJNDIProperties( properties, prefix, specialProps );
+
+ handleSpecialPropertyTranslation( properties, prefix + "class", result, Context.INITIAL_CONTEXT_FACTORY );
+ handleSpecialPropertyTranslation( properties, prefix + "url", result, Context.PROVIDER_URL );
+
+ return result;
+ }
+
+ /**
+ * Creates a new {@code Properties} instance with all properties from {@code properties} which start with the given
+ *
+ * @param properties the original properties
+ * @param prefix the prefix indicating JNDI specific properties
+ * @param specialProps a set of property names to ignore
+ *
+ * @return Creates a new {@code Properties} instance with JNDI specific properties
+ *
+ * @{code prefix}. In the new instance the prefix is removed. If a property matches a value in {@code specialProps}
+ * it gets ignored.
+ */
+ private static Properties addJNDIProperties(Properties properties, String prefix, HashSet<String> specialProps) {
+ Properties result = new Properties();
+ for ( Object property : properties.keySet() ) {
+ if ( property instanceof String ) {
+ String s = ( String ) property;
+ if ( s.indexOf( prefix ) > -1 && !specialProps.contains( s ) ) {
+ result.setProperty( s.substring( prefix.length() ), properties.getProperty( s ) );
+ }
+ }
+ }
+ return result;
+ }
+
+ private static void handleSpecialPropertyTranslation(Properties originalProperties, String oldKey, Properties newProperties, String newKey) {
+ String value = originalProperties.getProperty( oldKey );
+ // we want to be able to just use the defaults,
+ // if JNDI environment properties are not supplied
+ // so don't put null in anywhere
+ if ( value != null ) {
+ newProperties.put( newKey, value );
+ }
+ }
+}
+
+
Modified: search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/SearchTestCase.java
===================================================================
--- search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/SearchTestCase.java 2010-07-05 14:30:38 UTC (rev 19896)
+++ search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/SearchTestCase.java 2010-07-05 14:46:01 UTC (rev 19897)
@@ -26,6 +26,7 @@
import java.io.File;
import java.io.InputStream;
+import java.net.URL;
import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.KeywordAnalyzer;
@@ -62,14 +63,14 @@
public abstract class SearchTestCase extends TestCase {
private static final Logger log = org.hibernate.search.util.LoggerFactory.make();
-
+
public static final Analyzer standardAnalyzer = new StandardAnalyzer( getTargetLuceneVersion() );
public static final Analyzer stopAnalyzer = new StopAnalyzer( getTargetLuceneVersion() );
public static final Analyzer simpleAnalyzer = new SimpleAnalyzer();
public static final Analyzer keywordAnalyzer = new KeywordAnalyzer();
private static File indexDir;
-
+
private SearchFactoryImplementor searchFactory;
static {
@@ -134,12 +135,12 @@
tx.commit();
s.close();
}
-
+
protected SearchFactory getSearchFactory() {
if ( searchFactory == null ) {
Session session = openSession();
FullTextSession fullTextSession = Search.getFullTextSession( session );
- searchFactory = ( SearchFactoryImplementor) fullTextSession.getSearchFactory();
+ searchFactory = ( SearchFactoryImplementor ) fullTextSession.getSearchFactory();
fullTextSession.close();
}
return searchFactory;
@@ -195,9 +196,28 @@
protected static File getIndexDir() {
return indexDir;
}
-
+
public static Version getTargetLuceneVersion() {
return Version.LUCENE_29;
}
-
+
+ /**
+ * Returns the target directory of the build.
+ *
+ * @return the target directory of the build
+ */
+ public File getTargetDir() {
+ ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
+ // get a URL reference to something we now is part of the classpath (us)
+ URL myUrl = contextClassLoader.getResource( SearchTestCase.class.getName().replace( '.', '/' ) + ".class" );
+ File myPath = new File( myUrl.getFile() );
+ // navigate back to '/target'
+ return myPath
+ .getParentFile() // target/classes/org/hibernate/search/test
+ .getParentFile() // target/classes/org/hibernate/search
+ .getParentFile() // target/classes/org/hibernate/
+ .getParentFile() // target/classes/org
+ .getParentFile() // target/classes/
+ .getParentFile(); // target
+ }
}
Modified: search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/jms/master/JMSMasterTest.java
===================================================================
--- search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/jms/master/JMSMasterTest.java 2010-07-05 14:30:38 UTC (rev 19896)
+++ search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/jms/master/JMSMasterTest.java 2010-07-05 14:46:01 UTC (rev 19897)
@@ -29,6 +29,7 @@
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
+import java.util.Properties;
import javax.jms.MessageConsumer;
import javax.jms.ObjectMessage;
import javax.jms.Queue;
@@ -37,12 +38,14 @@
import javax.jms.QueueSender;
import javax.jms.QueueSession;
import javax.naming.Context;
+import javax.naming.NamingException;
import org.apache.activemq.broker.BrokerService;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
import org.apache.lucene.queryParser.QueryParser;
import org.apache.lucene.search.Query;
+
import org.hibernate.Session;
import org.hibernate.cfg.Configuration;
import org.hibernate.search.Environment;
@@ -114,13 +117,13 @@
}
private Queue getMessageQueue() throws Exception {
- Context ctx = new javax.naming.InitialContext();
+ Context ctx = getJndiInitialContext();
return ( Queue ) ctx.lookup( QUEUE_NAME );
}
private QueueSession getQueueSession() throws Exception {
if ( queueSession == null ) {
- Context ctx = new javax.naming.InitialContext();
+ Context ctx = getJndiInitialContext();
QueueConnectionFactory factory = ( QueueConnectionFactory ) ctx.lookup( CONNECTION_FACTORY_NAME );
QueueConnection conn = factory.createQueueConnection();
conn.start();
@@ -130,6 +133,18 @@
return queueSession;
}
+ private Context getJndiInitialContext() throws NamingException {
+ Properties props = new Properties();
+ props.setProperty(
+ Context.INITIAL_CONTEXT_FACTORY, "org.apache.activemq.jndi.ActiveMQInitialContextFactory"
+ );
+ props.setProperty( Context.PROVIDER_URL, "vm://localhost" );
+ props.setProperty( "connectionFactoryNames", "ConnectionFactory, java:/ConnectionFactory" );
+ props.setProperty( "queue.queue/searchtest", "searchQueue" );
+ Context ctx = new javax.naming.InitialContext( props );
+ return ctx;
+ }
+
/**
* Manually create the work queue. This lists gets send by the Slaves to the Master for indexing.
*
@@ -194,7 +209,7 @@
protected void configure(Configuration cfg) {
super.configure( cfg );
- // explcitily set the backend even though lucene is default.
+ // explicitly set the backend even though lucene is default.
cfg.setProperty( Environment.WORKER_BACKEND, "lucene" );
}
Modified: search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/jms/slave/JMSSlaveTest.java
===================================================================
--- search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/jms/slave/JMSSlaveTest.java 2010-07-05 14:30:38 UTC (rev 19896)
+++ search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/jms/slave/JMSSlaveTest.java 2010-07-05 14:46:01 UTC (rev 19897)
@@ -24,21 +24,23 @@
*/
package org.hibernate.search.test.jms.slave;
+import java.util.Properties;
import javax.jms.MessageConsumer;
import javax.jms.Queue;
import javax.jms.QueueConnection;
import javax.jms.QueueConnectionFactory;
import javax.jms.QueueSession;
import javax.naming.Context;
+import javax.naming.NamingException;
import org.apache.activemq.broker.BrokerService;
+import org.hibernate.Session;
+import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
import org.hibernate.search.Environment;
import org.hibernate.search.backend.impl.jms.JMSBackendQueueProcessorFactory;
import org.hibernate.search.test.SearchTestCase;
-import org.hibernate.Session;
-import org.hibernate.Transaction;
/**
* Checks that the Slave in a JMS configuration proplerly places index jobs onto the queue.
@@ -68,7 +70,7 @@
public void testMessageSend() throws Exception {
registerMessageListener();
SearchQueueChecker.reset();
-
+
Session s = openSession();
Transaction tx = s.beginTransaction();
TShirt ts = new TShirt();
@@ -82,7 +84,7 @@
tx.commit();
//need to sleep for the message consumption
- Thread.sleep(500);
+ Thread.sleep( 500 );
assertEquals( 1, SearchQueueChecker.queues );
assertEquals( 2, SearchQueueChecker.works );
@@ -90,12 +92,12 @@
SearchQueueChecker.reset();
s = openSession();
tx = s.beginTransaction();
- ts = (TShirt) s.get( TShirt.class, ts.getId() );
+ ts = ( TShirt ) s.get( TShirt.class, ts.getId() );
ts.setLogo( "Peter pan" );
tx.commit();
//need to sleep for the message consumption
- Thread.sleep(500);
+ Thread.sleep( 500 );
assertEquals( 1, SearchQueueChecker.queues );
assertEquals( 2, SearchQueueChecker.works ); //one update = 2 works
@@ -108,8 +110,8 @@
tx.commit();
//Need to sleep for the message consumption
- Thread.sleep(500);
-
+ Thread.sleep( 500 );
+
assertEquals( 1, SearchQueueChecker.queues );
assertEquals( 2, SearchQueueChecker.works );
s.close();
@@ -137,13 +139,13 @@
}
private Queue getMessageQueue() throws Exception {
- Context ctx = new javax.naming.InitialContext();
+ Context ctx = getJndiInitialContext();
return ( Queue ) ctx.lookup( QUEUE_NAME );
}
private QueueSession getQueueSession() throws Exception {
if ( queueSession == null ) {
- Context ctx = new javax.naming.InitialContext();
+ Context ctx = getJndiInitialContext();
QueueConnectionFactory factory = ( QueueConnectionFactory ) ctx.lookup( CONNECTION_FACTORY_NAME );
QueueConnection conn = factory.createQueueConnection();
conn.start();
@@ -158,6 +160,15 @@
cfg.setProperty( Environment.WORKER_BACKEND, "jms" );
cfg.setProperty( JMSBackendQueueProcessorFactory.JMS_CONNECTION_FACTORY, CONNECTION_FACTORY_NAME );
cfg.setProperty( JMSBackendQueueProcessorFactory.JMS_QUEUE, QUEUE_NAME );
+
+ // use the hibernate.search.worker.jndi prefix to pass a whole bunch of jndi properties to create the InitialContext
+ // for the queue processor
+ cfg.setProperty(
+ "hibernate.search.worker.jndi.class", "org.apache.activemq.jndi.ActiveMQInitialContextFactory"
+ );
+ cfg.setProperty( "hibernate.search.worker.jndi.url", "vm://localhost" );
+ cfg.setProperty( "hibernate.search.worker.jndi.connectionFactoryNames", "ConnectionFactory, java:/ConnectionFactory" );
+ cfg.setProperty( "hibernate.search.worker.jndi.queue.queue/searchtest", "searchQueue" );
}
protected Class<?>[] getMappings() {
@@ -165,4 +176,17 @@
TShirt.class
};
}
+
+ private Context getJndiInitialContext() throws NamingException {
+ Properties props = new Properties();
+ props.setProperty(
+ Context.INITIAL_CONTEXT_FACTORY, "org.apache.activemq.jndi.ActiveMQInitialContextFactory"
+ );
+ props.setProperty( Context.PROVIDER_URL, "vm://localhost" );
+ props.setProperty( "connectionFactoryNames", "ConnectionFactory, java:/ConnectionFactory" );
+ props.setProperty( "queue.queue/searchtest", "searchQueue" );
+
+ Context ctx = new javax.naming.InitialContext( props );
+ return ctx;
+ }
}
Added: search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/jmx/ConfigInfoMBeanTest.java
===================================================================
--- search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/jmx/ConfigInfoMBeanTest.java (rev 0)
+++ search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/jmx/ConfigInfoMBeanTest.java 2010-07-05 14:46:01 UTC (rev 19897)
@@ -0,0 +1,147 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2010, Red Hat, Inc. and/or its affiliates 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, Inc.
+ *
+ * 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.search.test.jmx;
+
+import java.lang.management.ManagementFactory;
+import java.util.HashSet;
+import java.util.Set;
+import javax.management.InstanceNotFoundException;
+import javax.management.MBeanAttributeInfo;
+import javax.management.MBeanException;
+import javax.management.MBeanInfo;
+import javax.management.MBeanOperationInfo;
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
+import javax.management.ReflectionException;
+
+import org.hibernate.Transaction;
+import org.hibernate.cfg.Configuration;
+import org.hibernate.search.Environment;
+import org.hibernate.search.FullTextSession;
+import org.hibernate.search.Search;
+import org.hibernate.search.jmx.HibernateSearchConfigInfoMBean;
+import org.hibernate.search.test.SearchTestCase;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class ConfigInfoMBeanTest extends SearchTestCase {
+ MBeanServer mbeanServer;
+ ObjectName configBeanObjectName;
+
+ public void testConfigInfoMBeanRegistered() throws Exception {
+ assertTrue(
+ "With the right property set the Search MBean should be registered",
+ mbeanServer.isRegistered( configBeanObjectName )
+ );
+ }
+
+ public void testAttributesAndOperations() throws Exception {
+ MBeanInfo info = mbeanServer.getMBeanInfo( configBeanObjectName );
+ MBeanAttributeInfo[] attributes = info.getAttributes();
+ assertEquals( "Wrong number of attributes", 2, attributes.length );
+ Set<String> attributeNames = new HashSet<String>();
+ attributeNames.add( "IndexedClassNames" );
+ attributeNames.add( "IndexingStrategy" );
+ for ( MBeanAttributeInfo attribute : attributes ) {
+ assertTrue( attributeNames.contains( attribute.getName() ) );
+ }
+
+ MBeanOperationInfo[] operations = info.getOperations();
+ assertEquals( "Wrong number of operations", 3, operations.length );
+ Set<String> operationNames = new HashSet<String>();
+ operationNames.add( "getNumberOfIndexedEntities" );
+ operationNames.add( "indexedEntitiesCount" );
+ operationNames.add( "getIndexingParameters" );
+ for ( MBeanOperationInfo operation : operations ) {
+ assertTrue( operationNames.contains( operation.getName() ) );
+ }
+ }
+
+ public void testIndexingStrategy() throws Exception {
+ assertEquals(
+ "wrong even type", "event", mbeanServer.getAttribute( configBeanObjectName, "IndexingStrategy" )
+ );
+ }
+
+ public void testIndexedClassNames() throws Exception {
+ assertEquals(
+ "wrong class name",
+ Counter.class.getName(),
+ ( ( Set ) mbeanServer.getAttribute( configBeanObjectName, "IndexedClassNames" ) ).iterator().next()
+ );
+ }
+
+
+ public void testNumberOfIndexedEntities() throws Exception {
+ assertNumberOfIndexedEntities( Counter.class.getName(), 0 );
+
+ FullTextSession s = Search.getFullTextSession( openSession() );
+ Transaction tx = s.beginTransaction();
+ Counter counter = new Counter();
+ s.save( counter );
+ tx.commit();
+ s.close();
+
+ assertNumberOfIndexedEntities( Counter.class.getName(), 1 );
+ }
+
+ private void assertNumberOfIndexedEntities(String entity, int count)
+ throws InstanceNotFoundException, MBeanException, ReflectionException {
+ assertEquals(
+ "wrong number of indexed entities", count,
+ mbeanServer.invoke(
+ configBeanObjectName,
+ "getNumberOfIndexedEntities",
+ new String[] { entity },
+ new String[] { String.class.getName() }
+ )
+ );
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ mbeanServer = ManagementFactory.getPlatformMBeanServer();
+ configBeanObjectName = new ObjectName( HibernateSearchConfigInfoMBean.CONFIG_MBEAN_OBJECT_NAME );
+ }
+
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ if ( mbeanServer.isRegistered( configBeanObjectName ) ) {
+ mbeanServer.unregisterMBean( configBeanObjectName );
+ }
+ }
+
+ protected void configure(Configuration cfg) {
+ super.configure( cfg );
+ cfg.setProperty( Environment.JMX_ENABLED, "true" );
+ }
+
+ @Override
+ protected Class<?>[] getMappings() {
+ return new Class<?>[] { Counter.class };
+ }
+}
+
+
Added: search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/jmx/Counter.java
===================================================================
--- search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/jmx/Counter.java (rev 0)
+++ search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/jmx/Counter.java 2010-07-05 14:46:01 UTC (rev 19897)
@@ -0,0 +1,47 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2010, Red Hat, Inc. and/or its affiliates 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, Inc.
+ *
+ * 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.search.test.jmx;
+
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+
+import org.hibernate.search.annotations.Indexed;
+
+/**
+ * @author Hardy Ferentschik
+ */
+@Entity
+@Indexed
+public class Counter {
+ @Id
+ @GeneratedValue
+ private long id;
+
+ public long getId() {
+ return id;
+ }
+}
+
+
Added: search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/jmx/IndexCtrlMBeanTest.java
===================================================================
--- search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/jmx/IndexCtrlMBeanTest.java (rev 0)
+++ search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/jmx/IndexCtrlMBeanTest.java 2010-07-05 14:46:01 UTC (rev 19897)
@@ -0,0 +1,160 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2010, Red Hat, Inc. and/or its affiliates 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, Inc.
+ *
+ * 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.search.test.jmx;
+
+import java.io.File;
+import java.lang.management.ManagementFactory;
+import java.util.HashSet;
+import java.util.Set;
+import javax.management.InstanceNotFoundException;
+import javax.management.MBeanAttributeInfo;
+import javax.management.MBeanException;
+import javax.management.MBeanInfo;
+import javax.management.MBeanOperationInfo;
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
+import javax.management.ReflectionException;
+
+import org.hibernate.Transaction;
+import org.hibernate.cfg.Configuration;
+import org.hibernate.search.Environment;
+import org.hibernate.search.FullTextSession;
+import org.hibernate.search.Search;
+import org.hibernate.search.jmx.HibernateSearchConfigInfoMBean;
+import org.hibernate.search.jmx.HibernateSearchIndexCtrlMBean;
+import org.hibernate.search.test.SearchTestCase;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class IndexCtrlMBeanTest extends SearchTestCase {
+ MBeanServer mbeanServer;
+ ObjectName configBeanObjectName;
+ ObjectName indexBeanObjectName;
+
+ public void testIndexCtrlMBeanRegistered() throws Exception {
+ assertTrue(
+ "With the right property set the Search MBean should be registered",
+ mbeanServer.isRegistered( indexBeanObjectName )
+ );
+ }
+
+ public void testAttributesAndOperations() throws Exception {
+ MBeanInfo info = mbeanServer.getMBeanInfo( indexBeanObjectName );
+ MBeanAttributeInfo[] attributes = info.getAttributes();
+ assertEquals( "Wrong number of attributes", 0, attributes.length );
+
+ MBeanOperationInfo[] operations = info.getOperations();
+ assertEquals( "Wrong number of operations", 2, operations.length );
+ Set<String> operationNames = new HashSet<String>();
+ operationNames.add( "index" );
+ operationNames.add( "purge" );
+ for ( MBeanOperationInfo operation : operations ) {
+ assertTrue( operationNames.contains( operation.getName() ) );
+ }
+ }
+
+ public void testIndexAndPurge() throws Exception {
+ assertEquals(
+ "wrong even type", "manual", mbeanServer.getAttribute( configBeanObjectName, "IndexingStrategy" )
+ );
+
+ FullTextSession s = Search.getFullTextSession( openSession() );
+ Transaction tx = s.beginTransaction();
+ Counter counter = new Counter();
+ s.save( counter );
+ tx.commit();
+ s.close();
+
+ assertNumberOfIndexedEntities( Counter.class.getName(), 0 ); // manual indexing!
+
+ mbeanServer.invoke(
+ indexBeanObjectName,
+ "index",
+ new String[] { Counter.class.getName() },
+ new String[] { String.class.getName() }
+ );
+
+ assertNumberOfIndexedEntities( Counter.class.getName(), 1 );
+
+ mbeanServer.invoke(
+ indexBeanObjectName,
+ "purge",
+ new String[] { Counter.class.getName() },
+ new String[] { String.class.getName() }
+ );
+
+ assertNumberOfIndexedEntities( Counter.class.getName(), 0 );
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ mbeanServer = ManagementFactory.getPlatformMBeanServer();
+ configBeanObjectName = new ObjectName( HibernateSearchConfigInfoMBean.CONFIG_MBEAN_OBJECT_NAME );
+ indexBeanObjectName = new ObjectName( HibernateSearchIndexCtrlMBean.INDEX_CTRL_MBEAN_OBJECT_NAME );
+ }
+
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ if ( mbeanServer.isRegistered( configBeanObjectName ) ) {
+ mbeanServer.unregisterMBean( configBeanObjectName );
+ }
+ if ( mbeanServer.isRegistered( indexBeanObjectName ) ) {
+ mbeanServer.unregisterMBean( indexBeanObjectName );
+ }
+ }
+
+ protected void configure(Configuration cfg) {
+ super.configure( cfg );
+ File targetDir = getTargetDir();
+ File simpleJndiDir = new File( targetDir, "simpleJndi" );
+ simpleJndiDir.mkdir();
+
+ cfg.setProperty( "hibernate.session_factory_name", "java:comp/SessionFactory" );
+ cfg.setProperty( "hibernate.jndi.class", "org.osjava.sj.SimpleContextFactory" );
+ cfg.setProperty( "hibernate.jndi.org.osjava.sj.root", simpleJndiDir.getAbsolutePath() );
+ cfg.setProperty( "hibernate.jndi.org.osjava.sj.jndi.shared", "true" );
+
+ cfg.setProperty( "hibernate.search.indexing_strategy", "manual" );
+ cfg.setProperty( Environment.JMX_ENABLED, "true" );
+ }
+
+ @Override
+ protected Class<?>[] getMappings() {
+ return new Class<?>[] { Counter.class };
+ }
+
+ private void assertNumberOfIndexedEntities(String entity, int count)
+ throws InstanceNotFoundException, MBeanException, ReflectionException {
+ assertEquals(
+ "wrong number of indexed entities", count,
+ mbeanServer.invoke(
+ configBeanObjectName,
+ "getNumberOfIndexedEntities",
+ new String[] { entity },
+ new String[] { String.class.getName() }
+ )
+ );
+ }
+}
\ No newline at end of file
Added: search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/jmx/NoMBeansEnabledTest.java
===================================================================
--- search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/jmx/NoMBeansEnabledTest.java (rev 0)
+++ search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/jmx/NoMBeansEnabledTest.java 2010-07-05 14:46:01 UTC (rev 19897)
@@ -0,0 +1,75 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2010, Red Hat, Inc. and/or its affiliates 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, Inc.
+ *
+ * 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.search.test.jmx;
+
+import java.io.File;
+import java.lang.management.ManagementFactory;
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
+
+import org.hibernate.cfg.Configuration;
+import org.hibernate.search.Environment;
+import org.hibernate.search.jmx.HibernateSearchConfigInfoMBean;
+import org.hibernate.search.jmx.HibernateSearchIndexCtrlMBean;
+import org.hibernate.search.test.SearchTestCase;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class NoMBeansEnabledTest extends SearchTestCase {
+
+ public void testMBeanNotRegisteredWithoutExplicitProperty() throws Exception {
+ MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
+
+ ObjectName name = new ObjectName( HibernateSearchConfigInfoMBean.CONFIG_MBEAN_OBJECT_NAME );
+ assertFalse(
+ "Without '" + Environment.JMX_ENABLED + "' set the configuration info MBean should not be registered",
+ mbs.isRegistered( name )
+ );
+
+ name = new ObjectName( HibernateSearchIndexCtrlMBean.INDEX_CTRL_MBEAN_OBJECT_NAME );
+ assertFalse(
+ "Without '" + Environment.JMX_ENABLED + "' set the index control MBean should not be registered",
+ mbs.isRegistered( name )
+ );
+ }
+
+
+ protected void configure(Configuration cfg) {
+ super.configure( cfg );
+ File targetDir = getTargetDir();
+ File simpleJndiDir = new File( targetDir, "simpleJndi" );
+ simpleJndiDir.mkdir();
+
+ cfg.setProperty( "hibernate.session_factory_name", "java:comp/SessionFactory" );
+ cfg.setProperty( "hibernate.jndi.class", "org.osjava.sj.SimpleContextFactory" );
+ cfg.setProperty( "hibernate.jndi.org.osjava.sj.root", simpleJndiDir.getAbsolutePath() );
+ cfg.setProperty( "hibernate.jndi.org.osjava.sj.jndi.shared", "true" );
+ }
+
+ @Override
+ protected Class<?>[] getMappings() {
+ return new Class<?>[] { Counter.class };
+ }
+}
\ No newline at end of file
Deleted: search/trunk/hibernate-search/src/test/resources/jndi.properties
===================================================================
--- search/trunk/hibernate-search/src/test/resources/jndi.properties 2010-07-05 14:30:38 UTC (rev 19896)
+++ search/trunk/hibernate-search/src/test/resources/jndi.properties 2010-07-05 14:46:01 UTC (rev 19897)
@@ -1,12 +0,0 @@
-java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory
-java.naming.provider.url=vm://localhost
-
-# use the following property to specify the JNDI name the connection factory
-# should appear as.
-connectionFactoryNames = ConnectionFactory, java:/ConnectionFactory
-
-# register some queues in JNDI using the form
-# queue.[jndiName] = [physicalName]
-queue.queue/searchtest = searchQueue
-
-
Modified: search/trunk/hibernate-search-testing/src/main/java/org/hibernate/search/test/SearchTestCase.java
===================================================================
--- search/trunk/hibernate-search-testing/src/main/java/org/hibernate/search/test/SearchTestCase.java 2010-07-05 14:30:38 UTC (rev 19896)
+++ search/trunk/hibernate-search-testing/src/main/java/org/hibernate/search/test/SearchTestCase.java 2010-07-05 14:46:01 UTC (rev 19897)
@@ -26,6 +26,7 @@
import java.io.File;
import java.io.InputStream;
+import java.net.URL;
import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.KeywordAnalyzer;
@@ -61,14 +62,14 @@
public abstract class SearchTestCase extends TestCase {
private static final Logger log = org.hibernate.search.util.LoggerFactory.make();
-
+
public static Analyzer standardAnalyzer = new StandardAnalyzer( getTargetLuceneVersion() );
public static Analyzer stopAnalyzer = new StopAnalyzer( getTargetLuceneVersion() );
public static Analyzer simpleAnalyzer = new SimpleAnalyzer();
public static Analyzer keywordAnalyzer = new KeywordAnalyzer();
private static File indexDir;
-
+
private SearchFactory searchFactory;
static {
@@ -129,7 +130,7 @@
tx.commit();
s.close();
}
-
+
protected SearchFactory getSearchFactory() {
if ( searchFactory == null ) {
Session session = openSession();
@@ -190,9 +191,29 @@
protected static File getIndexDir() {
return indexDir;
}
-
+
public static Version getTargetLuceneVersion() {
return Version.LUCENE_29;
}
-
+
+ /**
+ * Returns the target directory of the build.
+ *
+ * @return the target directory of the build
+ */
+ public File getTargetDir() {
+ ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
+ // get a URL reference to something we now is part of the classpath (us)
+ URL myUrl = contextClassLoader.getResource( SearchTestCase.class.getName().replace( '.', '/' ) + ".class" );
+ File myPath = new File( myUrl.getFile() );
+ // navigate back to '/target'
+ return myPath
+ .getParentFile() // target/classes/org/hibernate/search/test
+ .getParentFile() // target/classes/org/hibernate/search
+ .getParentFile() // target/classes/org/hibernate/
+ .getParentFile() // target/classes/org
+ .getParentFile() // target/classes/
+ .getParentFile(); // target
+ }
+
}
14 years, 7 months