Skip to content

Commit

Permalink
HHH-7037 Adding toString implementation EntityHierarchyImpl (mainly f…
Browse files Browse the repository at this point in the history
…or debugging)

Formatting, Javadocs and removal of obsolete methods
  • Loading branch information
hferentschik committed May 18, 2012
1 parent a046cc7 commit 2cd5752
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 40 deletions.
Expand Up @@ -48,6 +48,16 @@ public InheritanceType getHierarchyInheritanceType() {
public RootEntitySource getRootEntitySource() {
return rootEntitySource;
}

@Override
public String toString() {
final StringBuilder sb = new StringBuilder();
sb.append( "EntityHierarchyImpl" );
sb.append( "{rootEntitySource=" ).append( rootEntitySource.getEntityName() );
sb.append( ", inheritanceType=" ).append( inheritanceType );
sb.append( '}' );
return sb.toString();
}
}


Expand Up @@ -237,6 +237,20 @@ public List<JpaCallbackSource> getJpaCallbackClasses() {
public Set<SecondaryTableSource> getSecondaryTables() {
return entityClass.getSecondaryTableSources();
}

@Override
public String toString() {
final StringBuilder sb = new StringBuilder();
sb.append( "EntitySourceImpl" );
sb.append( "{entityClass=" ).append( entityClass.getName() );

sb.append( ", subclassEntitySources={" );
for(SubclassEntitySource subClass : subclassEntitySources) {
sb.append( subClass.getClassName() ).append( "," );
}
sb.append( "}}" );
return sb.toString();
}
}


Expand Up @@ -146,14 +146,13 @@ public Caching getCaching() {
return getEntityClass().getCaching();
}


private class AggregatedCompositeIdentifierSourceImpl implements AggregatedCompositeIdentifierSource {
private final ComponentAttributeSourceImpl componentAttributeSource;

public AggregatedCompositeIdentifierSourceImpl(RootEntitySourceImpl rootEntitySource) {
// the entity class reference should contain one single id attribute...
Iterator<BasicAttribute> idAttributes = rootEntitySource.getEntityClass ().getIdAttributes().iterator();
if ( ! idAttributes.hasNext() ) {
Iterator<BasicAttribute> idAttributes = rootEntitySource.getEntityClass().getIdAttributes().iterator();
if ( !idAttributes.hasNext() ) {
throw rootEntitySource.getLocalBindingContext().makeMappingException(
String.format(
"Could not locate identifier attributes on entity %s",
Expand Down Expand Up @@ -276,7 +275,6 @@ public Iterable<MetaAttributeSource> getMetaAttributeSources() {
return null; //To change body of implemented methods use File | Settings | File Templates.
}
}

}


Expand Up @@ -23,8 +23,6 @@
*/
package org.hibernate.metamodel.spi.binding;

import java.util.Set;

import org.hibernate.metamodel.spi.domain.Attribute;
import org.hibernate.metamodel.spi.source.MetaAttributeContext;

Expand All @@ -51,8 +49,8 @@ public interface AttributeBinding {
/**
* Obtain the descriptor for the Hibernate {@link org.hibernate.type.Type} for this binding.
* <p/>
* For information about the Java type, query the {@link org.hibernate.metamodel.spi.domain.Attribute} obtained from {@link #getAttribute()}
* instead.
* For information about the Java type, query the {@link org.hibernate.metamodel.spi.domain.Attribute}
* obtained from {@link #getAttribute()} instead.
*
* @return The type descriptor
*/
Expand All @@ -76,6 +74,4 @@ public interface AttributeBinding {
public boolean isAlternateUniqueKey();

public boolean isLazy();

public void validate();
}
Expand Up @@ -48,8 +48,6 @@ public class ManyToOneAttributeBinding
private final SingularAttributeBinding referencedAttributeBinding;
private final List<RelationalValueBinding> relationalValueBindings;

private boolean isLogicalOneToOne;

private CascadeStyle cascadeStyle;
private FetchTiming fetchTiming;
private FetchStyle fetchStyle;
Expand All @@ -71,9 +69,16 @@ public ManyToOneAttributeBinding(
lazy,
metaAttributeContext
);

if ( referencedAttributeBinding == null ) {
throw new IllegalArgumentException( "referencedAttributeBinding must be non-null." );
}
if ( !EntityBinding.class.isInstance( referencedAttributeBinding.getContainer() ) ) {
throw new AssertionFailure( "Illegal attempt to resolve many-to-one reference based on non-entity attribute" );
}

this.referencedAttributeBinding = referencedAttributeBinding;
this.relationalValueBindings = Collections.unmodifiableList( relationalValueBindings );
// buildForeignKey();
}

@Override
Expand Down Expand Up @@ -124,7 +129,7 @@ else if ( cascadeStyleList.size() == 1 ) {
}
else {
cascadeStyle = new CascadeStyle.MultipleCascadeStyle(
cascadeStyleList.toArray( new CascadeStyle[ cascadeStyleList.size() ] )
cascadeStyleList.toArray( new CascadeStyle[cascadeStyleList.size()] )
);
}
}
Expand Down Expand Up @@ -173,18 +178,6 @@ public final EntityBinding getReferencedEntityBinding() {
return referencedAttributeBinding.getContainer().seekEntityBinding();
}

// public void validate() {
// // can't check this until both the domain and relational states are initialized...
// if ( getCascadeTypes().contains( CascadeType.DELETE_ORPHAN ) ) {
// if ( !isLogicalOneToOne ) {
// throw new MappingException(
// "many-to-one attribute [" + locateAttribute().getName() + "] does not support orphan delete as it is not unique"
// );
// }
// }
// //TODO: validate that the entity reference is resolved
// }

@Override
protected void collectRelationalValueBindings(List<RelationalValueBinding> valueBindings) {
valueBindings.addAll( relationalValueBindings );
Expand Down
Expand Up @@ -173,13 +173,7 @@ public String getAlias(Dialect dialect) {
! columnName.isQuoted() &&
! columnName.getName().toLowerCase().equals( "rowid" );
if ( ! useRawName ) {
String unique =
new StringBuilder()
.append( getPosition() )
.append( '_' )
.append( getTable().getTableNumber() )
.append( '_' )
.toString();
String unique = String.valueOf( getPosition() ) + '_' + getTable().getTableNumber() + '_';
if ( unique.length() >= dialect.getMaxAliasLength() ) {
throw new MappingException(
"Unique suffix [" + unique + "] length must be less than maximum [" + dialect.getMaxAliasLength() + "]"
Expand Down
Expand Up @@ -23,8 +23,6 @@
*/
package org.hibernate.metamodel.spi.binding;

import org.junit.Test;

import org.hibernate.metamodel.MetadataSources;

/**
Expand All @@ -48,9 +46,4 @@ public void addSourcesForManyToOne(MetadataSources sources) {
public void addSourcesForComponentBinding(MetadataSources sources) {
sources.addResource( "org/hibernate/metamodel/spi/binding/SimpleEntityWithSimpleComponent.hbm.xml" );
}

@Test
public void testSimpleEntityWithSimpleComponentMapping() {
super.testSimpleEntityWithSimpleComponentMapping();
}
}

0 comments on commit 2cd5752

Please sign in to comment.