HHH-6392 Introducing a container for the attribute override values

This commit is contained in:
Hardy Ferentschik 2011-07-08 18:56:42 +02:00
parent b413299847
commit a353d34f78
3 changed files with 139 additions and 4 deletions

View File

@ -0,0 +1,73 @@
package org.hibernate.metamodel.source.annotations.attribute;
import org.jboss.jandex.AnnotationInstance;
import org.hibernate.AssertionFailure;
import org.hibernate.metamodel.source.annotations.JPADotNames;
/**
* Contains the information about a single {@link javax.persistence.AttributeOverride}. Instances of this class
* are creating during annotation processing and then applied onto the persistence attributes.
*
* @author Hardy Ferentschik
*/
public class AttributeOverride {
private final ColumnValues columnValues;
private final String attributePath;
public AttributeOverride(AnnotationInstance attributeOverrideAnnotation) {
this(null, attributeOverrideAnnotation);
}
public AttributeOverride(String prefix, AnnotationInstance attributeOverrideAnnotation) {
if ( attributeOverrideAnnotation != null && !JPADotNames.ATTRIBUTE_OVERRIDE.equals( attributeOverrideAnnotation.name() ) ) {
throw new AssertionFailure( "A @Column annotation needs to be passed to the constructor" );
}
columnValues = null;
attributePath = "";
}
@Override
public String toString() {
final StringBuilder sb = new StringBuilder();
sb.append( "AttributeOverride" );
sb.append( "{columnValues=" ).append( columnValues );
sb.append( ", attributePath='" ).append( attributePath ).append( '\'' );
sb.append( '}' );
return sb.toString();
}
@Override
public boolean equals(Object o) {
if ( this == o ) {
return true;
}
if ( o == null || getClass() != o.getClass() ) {
return false;
}
AttributeOverride that = (AttributeOverride) o;
if ( attributePath != null ? !attributePath.equals( that.attributePath ) : that.attributePath != null ) {
return false;
}
if ( columnValues != null ? !columnValues.equals( that.columnValues ) : that.columnValues != null ) {
return false;
}
return true;
}
@Override
public int hashCode() {
int result = columnValues != null ? columnValues.hashCode() : 0;
result = 31 * result + ( attributePath != null ? attributePath.hashCode() : 0 );
return result;
}
}

View File

@ -30,7 +30,7 @@ import org.hibernate.AssertionFailure;
import org.hibernate.metamodel.source.annotations.JPADotNames; import org.hibernate.metamodel.source.annotations.JPADotNames;
/** /**
* Container for the properties defined by {@code @Column}. * Container for the properties defined by {@link javax.persistence.Column}.
* *
* @author Hardy Ferentschik * @author Hardy Ferentschik
*/ */
@ -46,7 +46,7 @@ public class ColumnValues {
private int precision = 0; private int precision = 0;
private int scale = 0; private int scale = 0;
public ColumnValues() { ColumnValues() {
this( null ); this( null );
} }
@ -58,6 +58,7 @@ public class ColumnValues {
} }
private void applyColumnValues(AnnotationInstance columnAnnotation) { private void applyColumnValues(AnnotationInstance columnAnnotation) {
// if the column annotation is null we don't have to do anything. Everything is already defaulted.
if ( columnAnnotation == null ) { if ( columnAnnotation == null ) {
return; return;
} }
@ -210,6 +211,66 @@ public class ColumnValues {
sb.append( '}' ); sb.append( '}' );
return sb.toString(); return sb.toString();
} }
@Override
public boolean equals(Object o) {
if ( this == o ) {
return true;
}
if ( o == null || getClass() != o.getClass() ) {
return false;
}
ColumnValues that = (ColumnValues) o;
if ( insertable != that.insertable ) {
return false;
}
if ( length != that.length ) {
return false;
}
if ( nullable != that.nullable ) {
return false;
}
if ( precision != that.precision ) {
return false;
}
if ( scale != that.scale ) {
return false;
}
if ( unique != that.unique ) {
return false;
}
if ( updatable != that.updatable ) {
return false;
}
if ( columnDefinition != null ? !columnDefinition.equals( that.columnDefinition ) : that.columnDefinition != null ) {
return false;
}
if ( name != null ? !name.equals( that.name ) : that.name != null ) {
return false;
}
if ( table != null ? !table.equals( that.table ) : that.table != null ) {
return false;
}
return true;
}
@Override
public int hashCode() {
int result = name != null ? name.hashCode() : 0;
result = 31 * result + ( unique ? 1 : 0 );
result = 31 * result + ( nullable ? 1 : 0 );
result = 31 * result + ( insertable ? 1 : 0 );
result = 31 * result + ( updatable ? 1 : 0 );
result = 31 * result + ( columnDefinition != null ? columnDefinition.hashCode() : 0 );
result = 31 * result + ( table != null ? table.hashCode() : 0 );
result = 31 * result + length;
result = 31 * result + precision;
result = 31 * result + scale;
return result;
}
} }

View File

@ -146,8 +146,6 @@ public class ConfiguredClass {
this.idAttributeMap = new TreeMap<String, SimpleAttribute>(); this.idAttributeMap = new TreeMap<String, SimpleAttribute>();
this.associationAttributeMap = new TreeMap<String, AssociationAttribute>(); this.associationAttributeMap = new TreeMap<String, AssociationAttribute>();
// find transient field and method names
findTransientFieldAndMethodNames();
collectAttributes(); collectAttributes();
} }
@ -244,6 +242,9 @@ public class ConfiguredClass {
* Find all attributes for this configured class and add them to the corresponding map * Find all attributes for this configured class and add them to the corresponding map
*/ */
private void collectAttributes() { private void collectAttributes() {
// find transient field and method names
findTransientFieldAndMethodNames();
// use the class mate library to generic types // use the class mate library to generic types
ResolvedTypeWithMembers resolvedType = context.resolveMemberTypes( context.getResolvedType( clazz ) ); ResolvedTypeWithMembers resolvedType = context.resolveMemberTypes( context.getResolvedType( clazz ) );
for ( HierarchicType hierarchicType : resolvedType.allTypesAndOverrides() ) { for ( HierarchicType hierarchicType : resolvedType.allTypesAndOverrides() ) {