[hibernate-commits] Hibernate SVN: r20271 - in core/trunk: core/src/main/java/org/hibernate/cfg and 2 other directories.
hibernate-commits at lists.jboss.org
hibernate-commits at lists.jboss.org
Thu Aug 26 17:00:47 EDT 2010
Author: steve.ebersole at jboss.com
Date: 2010-08-26 17:00:47 -0400 (Thu, 26 Aug 2010)
New Revision: 20271
Added:
core/trunk/core/src/main/java/org/hibernate/annotations/MapKeyType.java
Modified:
core/trunk/core/src/main/java/org/hibernate/cfg/AnnotationBinder.java
core/trunk/core/src/main/java/org/hibernate/cfg/annotations/MapBinder.java
core/trunk/testsuite/src/test/java/org/hibernate/test/annotations/collectionelement/Matrix.java
Log:
HHH-5507 - Add @MapKeyType annotation
Added: core/trunk/core/src/main/java/org/hibernate/annotations/MapKeyType.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/annotations/MapKeyType.java (rev 0)
+++ core/trunk/core/src/main/java/org/hibernate/annotations/MapKeyType.java 2010-08-26 21:00:47 UTC (rev 20271)
@@ -0,0 +1,41 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2010, Red Hat Inc. 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.annotations;
+
+import java.lang.annotation.*;
+
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+/**
+ * Allows defining the type of the key of a persistent map.
+ *
+ * @author Steve Ebersole
+ */
+ at java.lang.annotation.Target({METHOD, FIELD})
+ at Retention(RUNTIME)
+public @interface MapKeyType {
+ Type value();
+}
Modified: core/trunk/core/src/main/java/org/hibernate/cfg/AnnotationBinder.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/cfg/AnnotationBinder.java 2010-08-26 20:24:12 UTC (rev 20270)
+++ core/trunk/core/src/main/java/org/hibernate/cfg/AnnotationBinder.java 2010-08-26 21:00:47 UTC (rev 20271)
@@ -112,6 +112,7 @@
import org.hibernate.annotations.LazyToOne;
import org.hibernate.annotations.LazyToOneOption;
import org.hibernate.annotations.ManyToAny;
+import org.hibernate.annotations.MapKeyType;
import org.hibernate.annotations.NaturalId;
import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;
@@ -1682,11 +1683,12 @@
!indexColumn.isImplicit(),
property.isAnnotationPresent( CollectionOfElements.class )
|| property.isAnnotationPresent( org.hibernate.annotations.MapKey.class )
+ || property.isAnnotationPresent( MapKeyType.class )
+
// || property.isAnnotationPresent( ManyToAny.class )
);
collectionBinder.setIndexColumn( indexColumn );
- MapKey mapKeyAnn = property.getAnnotation( MapKey.class );
- collectionBinder.setMapKey( mapKeyAnn );
+ collectionBinder.setMapKey( property.getAnnotation( MapKey.class ) );
collectionBinder.setPropertyName( inferredData.getPropertyName() );
BatchSize batchAnn = property.getAnnotation( BatchSize.class );
collectionBinder.setBatchSize( batchAnn );
Modified: core/trunk/core/src/main/java/org/hibernate/cfg/annotations/MapBinder.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/cfg/annotations/MapBinder.java 2010-08-26 20:24:12 UTC (rev 20270)
+++ core/trunk/core/src/main/java/org/hibernate/cfg/annotations/MapBinder.java 2010-08-26 21:00:47 UTC (rev 20271)
@@ -37,6 +37,7 @@
import org.hibernate.MappingException;
import org.hibernate.annotations.MapKey;
import org.hibernate.annotations.MapKeyManyToMany;
+import org.hibernate.annotations.MapKeyType;
import org.hibernate.annotations.common.reflection.XClass;
import org.hibernate.annotations.common.reflection.XProperty;
import org.hibernate.cfg.AccessType;
@@ -288,7 +289,13 @@
elementBinder.setExplicitType( mapKeyAnn.type() );
}
else {
- elementBinder.setType( property, elementClass );
+ MapKeyType mapKeyTypeAnnotation = property.getAnnotation( MapKeyType.class );
+ if ( mapKeyTypeAnnotation != null && ! BinderHelper.isDefault( mapKeyTypeAnnotation.value().type() ) ) {
+ elementBinder.setExplicitType( mapKeyTypeAnnotation.value() );
+ }
+ else {
+ elementBinder.setType( property, elementClass );
+ }
}
mapValue.setIndex( elementBinder.make() );
}
Modified: core/trunk/testsuite/src/test/java/org/hibernate/test/annotations/collectionelement/Matrix.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/annotations/collectionelement/Matrix.java 2010-08-26 20:24:12 UTC (rev 20270)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/annotations/collectionelement/Matrix.java 2010-08-26 21:00:47 UTC (rev 20271)
@@ -9,7 +9,7 @@
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
-import org.hibernate.annotations.MapKey;
+import org.hibernate.annotations.MapKeyType;
import org.hibernate.annotations.Sort;
import org.hibernate.annotations.SortType;
import org.hibernate.annotations.Type;
@@ -22,8 +22,8 @@
@Id
@GeneratedValue
private Integer id;
-
- @MapKey(type = @Type(type="integer") )
+
+ @MapKeyType( @Type(type="integer") )
@ElementCollection
@Sort(type = SortType.NATURAL)
@Type(type = "float")
More information about the hibernate-commits
mailing list