Author: steve.ebersole(a)jboss.com
Date: 2010-02-18 14:19:45 -0500 (Thu, 18 Feb 2010)
New Revision: 18840
Modified:
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/AttributeFactory.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/MetadataContext.java
Log:
HHH-4934 - Improve logging in MetadataContext and AttributeFactory
Modified:
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/AttributeFactory.java
===================================================================
---
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/AttributeFactory.java 2010-02-18
17:00:47 UTC (rev 18839)
+++
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/AttributeFactory.java 2010-02-18
19:19:45 UTC (rev 18840)
@@ -36,6 +36,9 @@
import javax.persistence.metamodel.Type;
import javax.persistence.metamodel.IdentifiableType;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
import org.hibernate.EntityMode;
import org.hibernate.type.EmbeddedComponentType;
import org.hibernate.type.ComponentType;
@@ -61,6 +64,8 @@
* @author Emmanuel Bernard
*/
public class AttributeFactory {
+ private static final Logger log = LoggerFactory.getLogger( AttributeFactory.class );
+
private final MetadataContext context;
public AttributeFactory(MetadataContext context) {
@@ -78,6 +83,7 @@
*/
@SuppressWarnings({ "unchecked" })
public <X, Y> AttributeImplementor<X, Y>
buildAttribute(AbstractManagedType<X> ownerType, Property property) {
+ log.trace( "Building attribute [{}.{}]", ownerType.getJavaType().getName(),
property.getName() );
//a back ref is a virtual property created by Hibernate, let's hide it from the JPA
model.
if ( property.isBackRef() ) return null;
final AttributeContext<X> attributeContext = wrap( ownerType, property );
@@ -128,6 +134,7 @@
*/
@SuppressWarnings({ "unchecked" })
public <X, Y> SingularAttributeImpl<X, Y>
buildIdAttribute(AbstractIdentifiableType<X> ownerType, Property property) {
+ log.trace( "Building identifier attribute [{}.{}]",
ownerType.getJavaType().getName(), property.getName() );
final AttributeContext<X> attributeContext = wrap( ownerType, property );
final SingularAttributeMetadata<X,Y> attributeMetadata =
(SingularAttributeMetadata<X, Y>) determineAttributeMetadata( attributeContext,
IDENTIFIER_MEMBER_RESOLVER );
@@ -153,6 +160,7 @@
*/
@SuppressWarnings({ "unchecked" })
public <X, Y> SingularAttributeImpl<X, Y>
buildVersionAttribute(AbstractIdentifiableType<X> ownerType, Property property) {
+ log.trace( "Building version attribute [{}.{}]",
ownerType.getJavaType().getName(), property.getName() );
final AttributeContext<X> attributeContext = wrap( ownerType, property );
final SingularAttributeMetadata<X,Y> attributeMetadata =
(SingularAttributeMetadata<X, Y>) determineAttributeMetadata( attributeContext,
VERSION_MEMBER_RESOLVER );
@@ -429,14 +437,14 @@
private <X,Y> AttributeMetadata<X,Y> determineAttributeMetadata(
AttributeContext<X> attributeContext,
MemberResolver memberResolver) {
+ log.trace( "Starting attribute metadata determination [{}]",
attributeContext.getPropertyMapping().getName() );
final Member member = memberResolver.resolveMember( attributeContext );
- // TODO (steve->emmanuel) not so sure this is true any longer...
- // FIXME the logical level for *To* is different from the Hibernate physical model.
- // ie a @ManyToOne @AssocTable is a many-to-many for hibernate
- // and a @OneToMany @AssocTable is a many-to-many for hibernate
- // FIXME so basically Attribute.PersistentAttributeType is crap at the moment
+ log.trace( " Determined member [{}]", member );
+
final Value value = attributeContext.getPropertyMapping().getValue();
final org.hibernate.type.Type type = value.getType();
+ log.trace( " determined type [name={}, class={}]", type.getName(),
type.getClass().getName() );
+
if ( type.isAnyType() ) {
throw new UnsupportedOperationException( "any not supported yet" );
}
Modified:
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/MetadataContext.java
===================================================================
---
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/MetadataContext.java 2010-02-18
17:00:47 UTC (rev 18839)
+++
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/MetadataContext.java 2010-02-18
19:19:45 UTC (rev 18840)
@@ -21,29 +21,30 @@
*/
package org.hibernate.ejb.metamodel;
+import java.lang.reflect.Field;
+import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
+import java.util.List;
import java.util.Map;
import java.util.Set;
-import java.util.List;
-import java.util.ArrayList;
-import java.lang.reflect.Field;
import javax.persistence.metamodel.Attribute;
+import javax.persistence.metamodel.IdentifiableType;
import javax.persistence.metamodel.SingularAttribute;
-import javax.persistence.metamodel.IdentifiableType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.slf4j.MDC;
+import org.hibernate.annotations.common.AssertionFailure;
+import org.hibernate.engine.SessionFactoryImplementor;
import org.hibernate.mapping.Component;
import org.hibernate.mapping.KeyValue;
import org.hibernate.mapping.MappedSuperclass;
import org.hibernate.mapping.PersistentClass;
import org.hibernate.mapping.Property;
-import org.hibernate.engine.SessionFactoryImplementor;
-import org.hibernate.annotations.common.AssertionFailure;
/**
* Defines a context for storing information during the building of the {@link
MetamodelImpl}.
@@ -52,8 +53,8 @@
* cross-references into the built metamodel classes.
* <p/>
* At the end of the day, clients are interested in the {@link #getEntityTypeMap} and
{@link #getEmbeddableTypeMap}
- * results, which represent all the registered {@link #registerEntityType entities} and
- * {@link #registerEmbeddedableType embeddabled} respectively.
+ * results, which represent all the registered {@linkplain #registerEntityType entities}
and
+ * {@linkplain #registerEmbeddedableType embeddables} respectively.
*
* @author Steve Ebersole
* @author Emmanuel Bernard
@@ -94,9 +95,9 @@
}
/**
- * Retrieves the {@link Class java type} to {@link EntityType} map.
+ * Retrieves the {@linkplain Class java type} to {@link EntityTypeImpl} map.
*
- * @return The {@link Class java type} to {@link EntityType} map.
+ * @return The {@linkplain Class java type} to {@link EntityTypeImpl} map.
*/
public Map<Class<?>, EntityTypeImpl<?>> getEntityTypeMap() {
return Collections.unmodifiableMap( entityTypes );
@@ -159,49 +160,62 @@
@SuppressWarnings({ "unchecked" })
public void wrapUp() {
+ log.trace( "Wrapping up metadata context..." );
//we need to process types from superclasses to subclasses
for (Object mapping : orderedMappings) {
if ( PersistentClass.class.isAssignableFrom( mapping.getClass() ) ) {
@SuppressWarnings( "unchecked" )
final PersistentClass safeMapping = (PersistentClass) mapping;
- final EntityTypeImpl<?> jpa2Mapping = entityTypesByPersistentClass.get(
safeMapping );
- applyIdMetadata( safeMapping, jpa2Mapping );
- applyVersionAttribute( safeMapping, jpa2Mapping );
- Iterator<Property> properties = ( Iterator<Property> )
safeMapping.getDeclaredPropertyIterator();
- while ( properties.hasNext() ) {
- final Property property = properties.next();
- if ( property.getValue() == safeMapping.getIdentifierMapper() ) {
- // property represents special handling for id-class mappings but we have already
- // accounted for the embedded property mappings in #applyIdMetadata &&
- // #buildIdClassAttributes
- continue;
+ log.trace( "Starting entity [{}]", safeMapping.getEntityName() );
+ try {
+ final EntityTypeImpl<?> jpa2Mapping = entityTypesByPersistentClass.get(
safeMapping );
+ applyIdMetadata( safeMapping, jpa2Mapping );
+ applyVersionAttribute( safeMapping, jpa2Mapping );
+ Iterator<Property> properties = ( Iterator<Property> )
safeMapping.getDeclaredPropertyIterator();
+ while ( properties.hasNext() ) {
+ final Property property = properties.next();
+ if ( property.getValue() == safeMapping.getIdentifierMapper() ) {
+ // property represents special handling for id-class mappings but we have already
+ // accounted for the embedded property mappings in #applyIdMetadata &&
+ // #buildIdClassAttributes
+ continue;
+ }
+ final Attribute attribute = attributeFactory.buildAttribute( jpa2Mapping, property
);
+ if ( attribute != null ) {
+ jpa2Mapping.getBuilder().addAttribute( attribute );
+ }
}
- final Attribute attribute = attributeFactory.buildAttribute( jpa2Mapping, property
);
- if ( attribute != null ) {
- jpa2Mapping.getBuilder().addAttribute( attribute );
- }
+ jpa2Mapping.lock();
+ populateStaticMetamodel( jpa2Mapping );
}
- jpa2Mapping.lock();
- populateStaticMetamodel( jpa2Mapping );
+ finally {
+ log.trace( "Completed entity [{}]", safeMapping.getEntityName() );
+ }
}
else if ( MappedSuperclass.class.isAssignableFrom( mapping.getClass() ) ) {
@SuppressWarnings( "unchecked" )
final MappedSuperclass safeMapping = (MappedSuperclass) mapping;
- final MappedSuperclassTypeImpl<?> jpa2Mapping =
mappedSuperclassByMappedSuperclassMapping.get(
- safeMapping
- );
- applyIdMetadata( safeMapping, jpa2Mapping );
- applyVersionAttribute( safeMapping, jpa2Mapping );
- Iterator<Property> properties = ( Iterator<Property> )
safeMapping.getDeclaredPropertyIterator();
- while ( properties.hasNext() ) {
- final Property property = properties.next();
- final Attribute attribute = attributeFactory.buildAttribute( jpa2Mapping, property
);
- if ( attribute != null ) {
- jpa2Mapping.getBuilder().addAttribute( attribute );
+ log.trace( "Starting mapped superclass [{}]",
safeMapping.getMappedClass().getName() );
+ try {
+ final MappedSuperclassTypeImpl<?> jpa2Mapping =
mappedSuperclassByMappedSuperclassMapping.get(
+ safeMapping
+ );
+ applyIdMetadata( safeMapping, jpa2Mapping );
+ applyVersionAttribute( safeMapping, jpa2Mapping );
+ Iterator<Property> properties = ( Iterator<Property> )
safeMapping.getDeclaredPropertyIterator();
+ while ( properties.hasNext() ) {
+ final Property property = properties.next();
+ final Attribute attribute = attributeFactory.buildAttribute( jpa2Mapping, property
);
+ if ( attribute != null ) {
+ jpa2Mapping.getBuilder().addAttribute( attribute );
+ }
}
+ jpa2Mapping.lock();
+ populateStaticMetamodel( jpa2Mapping );
}
- jpa2Mapping.lock();
- populateStaticMetamodel( jpa2Mapping );
+ finally {
+ log.trace( "Completed mapped superclass [{}]",
safeMapping.getMappedClass().getName() );
+ }
}
else {
throw new AssertionFailure( "Unexpected mapping type: " +
mapping.getClass() );
@@ -296,6 +310,7 @@
private <X> Set<SingularAttribute<? super X, ?>>
buildIdClassAttributes(
MappedSuperclassTypeImpl<X> jpaMappingType,
MappedSuperclass mappingType) {
+ log.trace( "Building old-school composite identifier [{}]",
mappingType.getMappedClass().getName() );
Set<SingularAttribute<? super X, ?>> attributes = new
HashSet<SingularAttribute<? super X, ?>>();
@SuppressWarnings( "unchecked" )
Iterator<Property> properties =
mappingType.getIdentifierMapper().getPropertyIterator();