From hibernate-commits at lists.jboss.org Wed Feb 20 12:14:31 2008 Content-Type: multipart/mixed; boundary="===============5439602169124012347==" MIME-Version: 1.0 From: hibernate-commits at lists.jboss.org To: hibernate-commits at lists.jboss.org Subject: [hibernate-commits] Hibernate SVN: r14344 - in annotations/trunk: src/java/org/hibernate/annotations and 2 other directories. Date: Wed, 20 Feb 2008 12:14:31 -0500 Message-ID: --===============5439602169124012347== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Author: epbernard Date: 2008-02-20 12:14:31 -0500 (Wed, 20 Feb 2008) New Revision: 14344 Added: annotations/trunk/src/java/org/hibernate/annotations/GenericGenerators.j= ava annotations/trunk/src/test/org/hibernate/test/annotations/id/Monkey.java Modified: annotations/trunk/doc/reference/en/modules/entity.xml annotations/trunk/src/java/org/hibernate/cfg/AnnotationBinder.java annotations/trunk/src/test/org/hibernate/test/annotations/id/IdTest.java annotations/trunk/src/test/org/hibernate/test/annotations/id/package-inf= o.java Log: ANN-442 add @GenericGenerators (Paul Cowan) Modified: annotations/trunk/doc/reference/en/modules/entity.xml =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- annotations/trunk/doc/reference/en/modules/entity.xml 2008-02-20 13:46:= 43 UTC (rev 14343) +++ annotations/trunk/doc/reference/en/modules/entity.xml 2008-02-20 17:14:= 31 UTC (rev 14344) @@ -2394,10 +2394,11 @@ public class Carrot extends Vegetable { ... } = - + Identifier = @org.hibernate.annotations.GenericGenerator<= /literal> + and @org.hibernate.annotations.GenericGenerators allows you to define an Hibernate specific id generator. = @@ -2420,16 +2421,23 @@ some parameters through the parameters attribute. = - Contrary to its standard counterpart, - @GenericGenerator can be used in package level - annotations, making it an application level generator (just like if = it - were in a JPA XML file). + Contrary to their standard counterpart, + @GenericGenerator and @GenericGenerators= + can be used in package level annotations, making them application le= vel generators + (just like if they were in a JPA XML file). = - @GenericGenerator(name=3D"hibseq", strategy =3D "seq= hilo", - parameters =3D { - @Parameter(name=3D"max_lo", value =3D "5"), - @Parameter(name=3D"sequence", value=3D"heybabyhey") - } + @GenericGenerators( + { + @GenericGenerator( + name=3D"hibseq", + strategy =3D "seqhilo", + parameters =3D { + @Parameter(name=3D"max_lo", value =3D "5"), + @Parameter(name=3D"sequence", value=3D"heybabyhey") + } + ), + @GenericGenerator(...) + } ) package org.hibernate.test.model Added: annotations/trunk/src/java/org/hibernate/annotations/GenericGenerato= rs.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- annotations/trunk/src/java/org/hibernate/annotations/GenericGenerators.= java (rev 0) +++ annotations/trunk/src/java/org/hibernate/annotations/GenericGenerators.= java 2008-02-20 17:14:31 UTC (rev 14344) @@ -0,0 +1,21 @@ +//$ +package org.hibernate.annotations; + +import static java.lang.annotation.ElementType.PACKAGE; +import static java.lang.annotation.ElementType.TYPE; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +/** + * Array of generic generator definitions + * + * @author Paul Cowan + */ +(a)Target({PACKAGE, TYPE}) +(a)Retention(RUNTIME) +public @interface GenericGenerators { + GenericGenerator[] value(); +} + Modified: annotations/trunk/src/java/org/hibernate/cfg/AnnotationBinder.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- annotations/trunk/src/java/org/hibernate/cfg/AnnotationBinder.java 2008= -02-20 13:46:43 UTC (rev 14343) +++ annotations/trunk/src/java/org/hibernate/cfg/AnnotationBinder.java 2008= -02-20 17:14:31 UTC (rev 14344) @@ -96,6 +96,7 @@ import org.hibernate.annotations.TypeDef; import org.hibernate.annotations.TypeDefs; import org.hibernate.annotations.Where; +import org.hibernate.annotations.GenericGenerators; import org.hibernate.annotations.common.reflection.ReflectionManager; import org.hibernate.annotations.common.reflection.XAnnotatedElement; import org.hibernate.annotations.common.reflection.XClass; @@ -233,17 +234,31 @@ mappings.addGenerator( idGen ); = } - if ( pckg.isAnnotationPresent( GenericGenerator.class ) ) { - GenericGenerator ann =3D pckg.getAnnotation( GenericGenerator.class ); - IdGenerator idGen =3D buildIdGenerator( ann, mappings ); - mappings.addGenerator( idGen ); - } + bindGenericGenerators(pckg, mappings); bindQueries( pckg, mappings ); bindFilterDefs( pckg, mappings ); bindTypeDefs( pckg, mappings ); BinderHelper.bindAnyMetaDefs( pckg, mappings ); } = + private static void bindGenericGenerators(XAnnotatedElement annotatedElem= ent, ExtendedMappings mappings) { + GenericGenerator defAnn =3D annotatedElement.getAnnotation( GenericGener= ator.class ); + GenericGenerators defsAnn =3D annotatedElement.getAnnotation( GenericGen= erators.class ); + if ( defAnn !=3D null ) { + bindGenericGenerator( defAnn, mappings ); + } + if ( defsAnn !=3D null ) { + for (GenericGenerator def : defsAnn.value() ) { + bindGenericGenerator( def, mappings ); + } + } + } + + private static void bindGenericGenerator(GenericGenerator def, ExtendedMa= ppings mappings) { + IdGenerator idGen =3D buildIdGenerator( def, mappings ); + mappings.addGenerator( idGen ); + } + private static void bindQueries(XAnnotatedElement annotatedElement, Exten= dedMappings mappings) { { SqlResultSetMapping ann =3D annotatedElement.getAnnotation( SqlResultSe= tMapping.class ); Modified: annotations/trunk/src/test/org/hibernate/test/annotations/id/IdTe= st.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- annotations/trunk/src/test/org/hibernate/test/annotations/id/IdTest.jav= a 2008-02-20 13:46:43 UTC (rev 14343) +++ annotations/trunk/src/test/org/hibernate/test/annotations/id/IdTest.jav= a 2008-02-20 17:14:31 UTC (rev 14344) @@ -41,6 +41,21 @@ = } = + /* + * Ensures that GenericGenerator annotations wrapped inside a GenericGene= rators holder are + * bound correctly + */ + public void testGenericGenerators() throws Exception { + Session s =3D openSession(); + Transaction tx =3D s.beginTransaction(); + Monkey monkey =3D new Monkey(); + s.persist( monkey ); + s.flush(); + assertNotNull(monkey.getId()); + tx.rollback(); + s.close(); + } + public void testTableGenerator() throws Exception { Session s =3D openSession(); Transaction tx =3D s.beginTransaction(); @@ -264,7 +279,8 @@ SoundSystem.class, Furniture.class, GoalKeeper.class, - BreakDance.class + BreakDance.class, + Monkey.class }; } = Added: annotations/trunk/src/test/org/hibernate/test/annotations/id/Monkey.= java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- annotations/trunk/src/test/org/hibernate/test/annotations/id/Monkey.jav= a (rev 0) +++ annotations/trunk/src/test/org/hibernate/test/annotations/id/Monkey.jav= a 2008-02-20 17:14:31 UTC (rev 14344) @@ -0,0 +1,24 @@ +//$ +package org.hibernate.test.annotations.id; + +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; + +/** + * @author Paul Cowan + */ +(a)Entity +public class Monkey { + private String id; + + @Id + @GeneratedValue(generator =3D "system-uuid-2") + public String getId() { + return id; + } + + public void setId(String id) { + this.id =3D id; + } +} Modified: annotations/trunk/src/test/org/hibernate/test/annotations/id/pack= age-info.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- annotations/trunk/src/test/org/hibernate/test/annotations/id/package-in= fo.java 2008-02-20 13:46:43 UTC (rev 14343) +++ annotations/trunk/src/test/org/hibernate/test/annotations/id/package-in= fo.java 2008-02-20 17:14:31 UTC (rev 14344) @@ -3,7 +3,9 @@ * Test package for metatata facilities * It contains an example of package level metadata */ +(a)org.hibernate.annotations.GenericGenerator(name =3D "system-uuid", stra= tegy =3D "uuid") +(a)org.hibernate.annotations.GenericGenerators( + @org.hibernate.annotations.GenericGenerator(name =3D "system-uuid-2", st= rategy =3D "uuid") +) +package org.hibernate.test.annotations.id; = -(a)org.hibernate.annotations.GenericGenerator(name =3D "system-uuid", - strategy =3D "uuid") package org.hibernate.test.annotations.id; - --===============5439602169124012347==--