[hibernate-commits] Hibernate SVN: r18522 - in core/trunk/annotations/src: test/java/org/hibernate/test/annotations/access/xml and 1 other directories.

hibernate-commits at lists.jboss.org hibernate-commits at lists.jboss.org
Tue Jan 12 15:14:31 EST 2010


Author: hardy.ferentschik
Date: 2010-01-12 15:14:31 -0500 (Tue, 12 Jan 2010)
New Revision: 18522

Added:
   core/trunk/annotations/src/test/java/org/hibernate/test/annotations/access/xml/Boy.java
   core/trunk/annotations/src/test/resources/org/hibernate/test/annotations/access/xml/Boy.xml
Modified:
   core/trunk/annotations/src/main/java/org/hibernate/cfg/annotations/reflection/JPAOverridenAnnotationReader.java
   core/trunk/annotations/src/test/java/org/hibernate/test/annotations/access/xml/XmlAccessTest.java
Log:
HHH-4691 - xml access type support for element collection. As side effect started to suport element-collection in xml. Needs to be completed though.

Modified: core/trunk/annotations/src/main/java/org/hibernate/cfg/annotations/reflection/JPAOverridenAnnotationReader.java
===================================================================
--- core/trunk/annotations/src/main/java/org/hibernate/cfg/annotations/reflection/JPAOverridenAnnotationReader.java	2010-01-12 19:44:37 UTC (rev 18521)
+++ core/trunk/annotations/src/main/java/org/hibernate/cfg/annotations/reflection/JPAOverridenAnnotationReader.java	2010-01-12 20:14:31 UTC (rev 18522)
@@ -372,6 +372,7 @@
 					getAssociation( OneToOne.class, annotationList, defaults );
 					getAssociation( OneToMany.class, annotationList, defaults );
 					getAssociation( ManyToMany.class, annotationList, defaults );
+					getElementCollection( annotationList, defaults );
 					addIfNotNull( annotationList, getSequenceGenerator( elementsForProperty, defaults ) );
 					addIfNotNull( annotationList, getTableGenerator( elementsForProperty, defaults ) );
 					addIfNotNull( annotationList, getAttributeOverrides( elementsForProperty, defaults ) );
@@ -647,22 +648,7 @@
 		for (Element element : elementsForProperty) {
 			if ( xmlName.equals( element.getName() ) ) {
 				AnnotationDescriptor ad = new AnnotationDescriptor( annotationType );
-				String className = element.attributeValue( "target-entity" );
-				if ( className != null ) {
-					Class clazz;
-					try {
-						clazz = ReflectHelper.classForName(
-								XMLContext.buildSafeClassName( className, defaults ),
-								this.getClass()
-						);
-					}
-					catch (ClassNotFoundException e) {
-						throw new AnnotationException(
-								"Unable to find " + element.getPath() + "target-entity: " + className, e
-						);
-					}
-					ad.setValue( "targetEntity", clazz );
-				}
+				addTargetClass( element, ad, "target-entity", defaults );
 				getFetchType( ad, element );
 				getCascades( ad, element, defaults );
 				getJoinTable( annotationList, element, defaults );
@@ -785,6 +771,38 @@
 		}
 	}
 
+	private void addTargetClass(Element element, AnnotationDescriptor ad, String nodeName, XMLContext.Default defaults) {
+		String className = element.attributeValue( nodeName );
+		if ( className != null ) {
+			Class clazz;
+			try {
+				clazz = ReflectHelper.classForName(
+						XMLContext.buildSafeClassName( className, defaults ),
+						this.getClass()
+				);
+			}
+			catch (ClassNotFoundException e) {
+				throw new AnnotationException(
+						"Unable to find " + element.getPath() + " " + nodeName + ": " + className, e
+				);
+			}
+			ad.setValue( getJavaAttributeNameFromXMLOne(nodeName), clazz );
+		}
+	}
+
+	// TODO: Complete parsing of all element-collection related xml
+	private void getElementCollection(List<Annotation> annotationList, XMLContext.Default defaults) {
+		for ( Element element : elementsForProperty ) {
+			if ( "element-collection".equals( element.getName() ) ) {
+				AnnotationDescriptor ad = new AnnotationDescriptor( ElementCollection.class );
+				addTargetClass( element, ad, "target-class", defaults );
+				annotationList.add( AnnotationFactory.create( ad ) );
+
+				getAccessType( annotationList, element );
+			}
+		}
+	}
+
 	private void getOrderBy(List<Annotation> annotationList, Element element) {
 		Element subelement = element != null ? element.element( "order-by" ) : null;
 		if ( subelement != null ) {

Added: core/trunk/annotations/src/test/java/org/hibernate/test/annotations/access/xml/Boy.java
===================================================================
--- core/trunk/annotations/src/test/java/org/hibernate/test/annotations/access/xml/Boy.java	                        (rev 0)
+++ core/trunk/annotations/src/test/java/org/hibernate/test/annotations/access/xml/Boy.java	2010-01-12 20:14:31 UTC (rev 18522)
@@ -0,0 +1,54 @@
+// $Id:$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat, Inc. and/or its affiliates, and individual contributors
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+* http://www.apache.org/licenses/LICENSE-2.0
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.hibernate.test.annotations.access.xml;
+
+import java.util.Set;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+
+import org.hibernate.annotations.Entity;
+
+/**
+ * @author Hardy Ferentschik
+ */
+ at Entity
+public class Boy {
+	@Id
+	@GeneratedValue
+	private long id;
+
+	private Set<String> nickNames;
+
+	public long getId() {
+		return id;
+	}
+
+	public void setId(long id) {
+		this.id = id;
+	}
+
+	public Set<String> getNickNames() {
+		return nickNames;
+	}
+
+	public void setNickNames(Set<String> nickNames) {
+		this.nickNames = nickNames;
+	}
+}
+
+

Modified: core/trunk/annotations/src/test/java/org/hibernate/test/annotations/access/xml/XmlAccessTest.java
===================================================================
--- core/trunk/annotations/src/test/java/org/hibernate/test/annotations/access/xml/XmlAccessTest.java	2010-01-12 19:44:37 UTC (rev 18521)
+++ core/trunk/annotations/src/test/java/org/hibernate/test/annotations/access/xml/XmlAccessTest.java	2010-01-12 20:14:31 UTC (rev 18522)
@@ -143,12 +143,22 @@
 		List<Class<?>> classes = new ArrayList<Class<?>>();
 		classes.add( classUnderTest );
 		classes.add( Knive.class );
-		List<String> configFiles =  new ArrayList<String>();
+		List<String> configFiles = new ArrayList<String>();
 		configFiles.add( "org/hibernate/test/annotations/access/xml/Cook.xml" );
 		SessionFactoryImplementor factory = buildSessionFactory( classes, configFiles );
 		assertAccessType( factory, classUnderTest, AccessType.PROPERTY );
 	}
 
+	public void testAccessOnElementCollectionXmlElement() throws Exception {
+		Class<?> classUnderTest = Boy.class;
+		List<Class<?>> classes = new ArrayList<Class<?>>();
+		classes.add( classUnderTest );
+		List<String> configFiles = new ArrayList<String>();
+		configFiles.add( "org/hibernate/test/annotations/access/xml/Boy.xml" );
+		SessionFactoryImplementor factory = buildSessionFactory( classes, configFiles );
+		assertAccessType( factory, classUnderTest, AccessType.PROPERTY );
+	}
+
 	private SessionFactoryImplementor buildSessionFactory(List<Class<?>> classesUnderTest, List<String> configFiles) {
 		assert classesUnderTest != null;
 		assert configFiles != null;

Copied: core/trunk/annotations/src/test/resources/org/hibernate/test/annotations/access/xml/Boy.xml (from rev 18519, core/trunk/annotations/src/test/resources/org/hibernate/test/annotations/access/xml/Crew.xml)
===================================================================
--- core/trunk/annotations/src/test/resources/org/hibernate/test/annotations/access/xml/Boy.xml	                        (rev 0)
+++ core/trunk/annotations/src/test/resources/org/hibernate/test/annotations/access/xml/Boy.xml	2010-01-12 20:14:31 UTC (rev 18522)
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<entity-mappings xmlns="http://java.sun.com/xml/ns/persistence/orm"
+                 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+                 xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm file:/Users/hardy/work/hibernate/core/trunk/annotations/src/main/resources/org/hibernate/ejb/orm_2_0.xsd"
+                 version="2.0">
+    <package>org.hibernate.test.annotations.access.xml</package>
+    <entity class="Boy" metadata-complete="false">
+        <attributes>
+            <element-collection name="nickNames" target-class="java.lang.String" access="PROPERTY"/>
+        </attributes>
+    </entity>
+</entity-mappings>



More information about the hibernate-commits mailing list