HHH-6171 Switching to Map<String,String> as type parameters in HibernateTypeDescriptor (needs maybe to change to Map<String, Object>). Properties is the wrong class to use.

Also fixed several variable and method typos, eg updatable instead of updateable. And we are talking about a discriminator not descriminator.
This commit is contained in:
Hardy Ferentschik 2011-05-18 14:21:23 +02:00
parent bf4d8ad290
commit 2b694d7a86
22 changed files with 238 additions and 114 deletions

View File

@ -31,6 +31,7 @@ import java.util.Map;
import java.util.Set;
import org.hibernate.MappingException;
import org.hibernate.metamodel.binding.state.AttributeBindingState;
import org.hibernate.metamodel.domain.Attribute;
import org.hibernate.metamodel.domain.MetaAttribute;
import org.hibernate.metamodel.relational.Column;
@ -39,11 +40,10 @@ import org.hibernate.metamodel.relational.SimpleValue;
import org.hibernate.metamodel.relational.TableSpecification;
import org.hibernate.metamodel.relational.Tuple;
import org.hibernate.metamodel.relational.Value;
import org.hibernate.metamodel.binding.state.AttributeBindingState;
import org.hibernate.metamodel.relational.state.ValueCreator;
import org.hibernate.metamodel.relational.state.SimpleValueRelationalState;
import org.hibernate.metamodel.relational.state.ValueRelationalState;
import org.hibernate.metamodel.relational.state.TupleRelationalState;
import org.hibernate.metamodel.relational.state.ValueCreator;
import org.hibernate.metamodel.relational.state.ValueRelationalState;
/**
* TODO : javadoc
@ -51,11 +51,9 @@ import org.hibernate.metamodel.relational.state.TupleRelationalState;
* @author Steve Ebersole
*/
public abstract class AbstractAttributeBinding implements AttributeBinding {
private final HibernateTypeDescriptor hibernateTypeDescriptor = new HibernateTypeDescriptor();
private final EntityBinding entityBinding;
private final Set<EntityReferencingAttributeBinding> entityReferencingAttributeBindings =
new HashSet<EntityReferencingAttributeBinding>();
private final Set<EntityReferencingAttributeBinding> entityReferencingAttributeBindings = new HashSet<EntityReferencingAttributeBinding>();
private Attribute attribute;
private Value value;
@ -83,7 +81,7 @@ public abstract class AbstractAttributeBinding implements AttributeBinding {
isAlternateUniqueKey = state.isAlternateUniqueKey();
cascade = state.getCascade();
optimisticLockable = state.isOptimisticLockable();
nodeName = state.getNodeName() ;
nodeName = state.getNodeName();
metaAttributes = state.getMetaAttributes();
}
@ -125,14 +123,15 @@ public abstract class AbstractAttributeBinding implements AttributeBinding {
// TODO: not sure I like this here...
if ( isPrimaryKey() ) {
if ( SimpleValue.class.isInstance( value ) ) {
if ( ! Column.class.isInstance( value ) ) {
// this should never ever happen..
if ( !Column.class.isInstance( value ) ) {
// this should never ever happen..
throw new MappingException( "Simple ID is not a column." );
}
entityBinding.getBaseTable().getPrimaryKey().addColumn( Column.class.cast( value ) );
}
else {
for ( SimpleValueRelationalState val : TupleRelationalState.class.cast( state ).getRelationalStates() ) {
for ( SimpleValueRelationalState val : TupleRelationalState.class.cast( state )
.getRelationalStates() ) {
if ( Column.class.isInstance( val ) ) {
entityBinding.getBaseTable().getPrimaryKey().addColumn( Column.class.cast( val ) );
}
@ -169,8 +168,8 @@ public abstract class AbstractAttributeBinding implements AttributeBinding {
return value == null
? Collections.<SimpleValue>emptyList()
: value instanceof Tuple
? ( (Tuple) value ).values()
: Collections.singletonList( (SimpleValue) value );
? ( (Tuple) value ).values()
: Collections.singletonList( (SimpleValue) value );
}
@Override
@ -220,9 +219,9 @@ public abstract class AbstractAttributeBinding implements AttributeBinding {
public boolean[] getColumnInsertability() {
List<Boolean> tmp = new ArrayList<Boolean>();
for ( SimpleValue simpleValue : getValues() ) {
tmp.add( ! ( simpleValue instanceof DerivedValue ) );
tmp.add( !( simpleValue instanceof DerivedValue ) );
}
boolean[] rtn = new boolean[ tmp.size() ];
boolean[] rtn = new boolean[tmp.size()];
int i = 0;
for ( Boolean insertable : tmp ) {
rtn[i++] = insertable.booleanValue();
@ -253,11 +252,10 @@ public abstract class AbstractAttributeBinding implements AttributeBinding {
}
public void validate() {
if ( ! entityReferencingAttributeBindings.isEmpty() ) {
if ( !entityReferencingAttributeBindings.isEmpty() ) {
// TODO; validate that this AttributeBinding can be a target of an entity reference
// (e.g., this attribute is the primary key or there is a unique-key)
// can a unique attribute be used as a target? if so, does it need to be non-null?
}
}
}

View File

@ -23,7 +23,7 @@
*/
package org.hibernate.metamodel.binding;
import java.util.Properties;
import java.util.Map;
import org.hibernate.type.Type;
@ -35,7 +35,7 @@ import org.hibernate.type.Type;
public class HibernateTypeDescriptor {
private String typeName;
private Type explicitType;
private Properties typeParameters;
private Map<String, String> typeParameters;
public String getTypeName() {
return typeName;
@ -55,12 +55,12 @@ public class HibernateTypeDescriptor {
this.explicitType = explicitType;
}
public Properties getTypeParameters() {
public Map<String, String> getTypeParameters() {
return typeParameters;
}
/* package-protected */
void setTypeParameters(Properties typeParameters) {
void setTypeParameters(Map<String, String> typeParameters) {
this.typeParameters = typeParameters;
}
}

View File

@ -29,9 +29,9 @@ package org.hibernate.metamodel.binding;
* @author Steve Ebersole
*/
public interface KeyValueBinding extends AttributeBinding {
public boolean isKeyCasadeDeleteEnabled();
public boolean isKeyCascadeDeleteEnabled();
public String getUnsavedValue();
public boolean isUpdateable();
public boolean isUpdatable();
}

View File

@ -34,14 +34,24 @@ import org.hibernate.service.ServiceRegistry;
*/
public interface MappingDefaults {
Map<String, MetaAttribute> getMappingMetas();
String getPackageName();
String getDefaultSchemaName();
String getDefaultCatalogName();
String getDefaultIdColumnName();
String getDefaultDescriminatorColumnName();
String getDefaultDiscriminatorColumnName();
String getDefaultCascade();
String getDefaultAccess();
boolean isDefaultLazy();
ServiceRegistry getServiceRegistry();
NamingStrategy getNamingStrategy();
}

View File

@ -25,8 +25,8 @@ package org.hibernate.metamodel.binding;
import org.hibernate.mapping.PropertyGeneration;
import org.hibernate.metamodel.binding.state.SimpleAttributeBindingState;
import org.hibernate.metamodel.relational.state.ValueRelationalState;
import org.hibernate.metamodel.relational.state.ColumnRelationalState;
import org.hibernate.metamodel.relational.state.ValueRelationalState;
/**
* TODO : javadoc
@ -37,8 +37,8 @@ public class SimpleAttributeBinding extends AbstractAttributeBinding implements
private final boolean forceNonNullable;
private final boolean forceUnique;
private boolean insertable;
private boolean updateable;
private boolean keyCasadeDeleteEnabled;
private boolean updatable;
private boolean keyCascadeDeleteEnabled;
private String unsavedValue;
private PropertyGeneration generation;
@ -51,8 +51,8 @@ public class SimpleAttributeBinding extends AbstractAttributeBinding implements
public final SimpleAttributeBinding initialize(SimpleAttributeBindingState state) {
super.initialize( state );
insertable = state.isInsertable();
updateable = state.isUpdateable();
keyCasadeDeleteEnabled = state.isKeyCascadeDeleteEnabled();
updatable = state.isUpdatable();
keyCascadeDeleteEnabled = state.isKeyCascadeDeleteEnabled();
unsavedValue = state.getUnsavedValue();
generation = state.getPropertyGeneration() == null ? PropertyGeneration.NEVER : state.getPropertyGeneration();
return this;
@ -80,21 +80,21 @@ public class SimpleAttributeBinding extends AbstractAttributeBinding implements
this.insertable = insertable;
}
public boolean isUpdateable() {
return updateable;
public boolean isUpdatable() {
return updatable;
}
protected void setUpdateable(boolean updateable) {
this.updateable = updateable;
protected void setUpdatable(boolean updatable) {
this.updatable = updatable;
}
@Override
public boolean isKeyCasadeDeleteEnabled() {
return keyCasadeDeleteEnabled;
public boolean isKeyCascadeDeleteEnabled() {
return keyCascadeDeleteEnabled;
}
public void setKeyCasadeDeleteEnabled(boolean keyCasadeDeleteEnabled) {
this.keyCasadeDeleteEnabled = keyCasadeDeleteEnabled;
public void setKeyCascadeDeleteEnabled(boolean keyCascadeDeleteEnabled) {
this.keyCascadeDeleteEnabled = keyCascadeDeleteEnabled;
}
@Override
@ -117,5 +117,4 @@ public class SimpleAttributeBinding extends AbstractAttributeBinding implements
public PropertyGeneration getGeneration() {
return generation;
}
}

View File

@ -24,7 +24,6 @@
package org.hibernate.metamodel.binding.state;
import java.util.Map;
import java.util.Properties;
import org.hibernate.metamodel.domain.MetaAttribute;
@ -36,7 +35,7 @@ public interface AttributeBindingState {
String getTypeName();
Properties getTypeParameters();
Map<String, String> getTypeParameters();
boolean isLazy();

View File

@ -31,7 +31,7 @@ import org.hibernate.mapping.PropertyGeneration;
public interface SimpleAttributeBindingState extends AttributeBindingState {
boolean isInsertable();
boolean isUpdateable();
boolean isUpdatable();
boolean isKeyCascadeDeleteEnabled();

View File

@ -23,7 +23,6 @@
*/
package org.hibernate.metamodel.source.annotations;
import java.util.Iterator;
import java.util.Set;
import org.jboss.jandex.Index;
@ -44,36 +43,37 @@ import org.hibernate.metamodel.source.internal.MetadataImpl;
* are added to the annotation index.
*
* @author Hardy Ferentschik
* @todo On top of the index we probably needs to pass some sort of XMLContext for global configuration data
* @todo The annotation index should really be passed at construction time
*/
public class AnnotationBinder {
private static final Logger log = LoggerFactory.getLogger( AnnotationBinder.class );
private final MetadataImpl metadata;
private final Index index;
public AnnotationBinder(MetadataImpl metadata) {
public AnnotationBinder(MetadataImpl metadata, Index index) {
this.metadata = metadata;
this.index = index;
}
public void bind(Index annotationIndex) {
preEntityBindings( annotationIndex );
bindMappedClasses( annotationIndex );
postEntityBindings( annotationIndex );
public void bind() {
preEntityBindings();
bindMappedClasses();
postEntityBindings();
}
/**
* Binds global configuration data prior to entity binding. This includes generators and type definitions
*
* @param annotationIndex the annotation repository/index
* Binds global configuration data prior to entity binding. This includes generators and type definitions.
*/
private void preEntityBindings(Index annotationIndex) {
FetchProfileBinder.bind( metadata, annotationIndex );
private void preEntityBindings() {
FetchProfileBinder.bind( metadata, index );
}
private void bindMappedClasses(Index annotationIndex) {
/**
* Does the actual entity binding (see {@link org.hibernate.metamodel.binding.EntityBinding}.
*/
private void bindMappedClasses() {
// need to order our annotated entities into an order we can process
Set<ConfiguredClassHierarchy> hierarchies = ConfiguredClassHierarchyBuilder.createEntityHierarchies(
annotationIndex, metadata.getServiceRegistry()
index, metadata.getServiceRegistry()
);
// now we process each hierarchy one at the time
@ -89,11 +89,9 @@ public class AnnotationBinder {
/**
* Binds global configuration data post entity binding. This includes mappings which live outside of the configuration for a single
* entity or entity hierarchy, for example sequence generators, fetch profiles, etc
*
* @param annotationIndex the annotation repository/index
*/
private void postEntityBindings(Index annotationIndex) {
TableBinder.bind( metadata, annotationIndex );
private void postEntityBindings() {
TableBinder.bind( metadata, index );
}
}

View File

@ -380,7 +380,7 @@ public class ConfiguredClass {
final Map<DotName, List<AnnotationInstance>> annotations = JandexHelper.getMemberAnnotations(
classInfo, member.getName()
);
return MappedAttribute.createMappedAttribute( name, (Class) type, annotations );
return MappedAttribute.createMappedAttribute( name, ( (Class) type ).getName(), annotations );
}
private Type findResolvedType(String name, ResolvedMember[] resolvedMembers) {

View File

@ -196,7 +196,7 @@ public class ConfiguredClassHierarchy implements Iterable<ConfiguredClass> {
private AccessType throwIdNotFoundAnnotationException(List<ClassInfo> classes) {
StringBuilder builder = new StringBuilder();
builder.append( "Unable to determine identifier attribute for class hierarchy " );
builder.append( "Unable to determine identifier attribute for class hierarchy consisting of the classe(s) " );
builder.append( hierarchyListString( classes ) );
throw new AnnotationException( builder.toString() );
}

View File

@ -85,11 +85,13 @@ public class EntityBinder {
bindJpaCaching( entityBinding );
bindHibernateCaching( entityBinding );
// take care of the id, attributes and relations
if ( configuredClass.isRoot() ) {
bindId( entityBinding );
}
bindAttributes( entityBinding );
// last, but not least we register the new EntityBinding with the metadata
meta.addEntity( entityBinding );
}

View File

@ -23,6 +23,7 @@
*/
package org.hibernate.metamodel.source.annotations.entity;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.persistence.DiscriminatorType;
@ -43,15 +44,20 @@ import org.hibernate.metamodel.source.annotations.util.JandexHelper;
* @author Hardy Ferentschik
*/
public class MappedAttribute implements Comparable<MappedAttribute> {
private final String name;
private final Class<?> type;
private final Map<DotName, List<AnnotationInstance>> annotations;
private final String name;
private final String type;
private final Map<String, String> typeParameters;
private final ColumnValues columnValues;
private final boolean isId;
private final boolean isVersioned;
private final boolean isDiscriminator;
static MappedAttribute createMappedAttribute(String name, Class<?> type, Map<DotName, List<AnnotationInstance>> annotations) {
static MappedAttribute createMappedAttribute(String name, String type, Map<DotName, List<AnnotationInstance>> annotations) {
return new MappedAttribute( name, type, annotations, false );
}
@ -68,7 +74,7 @@ public class MappedAttribute implements Comparable<MappedAttribute> {
annotations, JPADotNames.DISCRIMINATOR_COLUMN
);
String name = DiscriminatorColumnValues.DEFAULT_DISCRIMINATOR_COLUMN_NAME;
Class<?> type = String.class; // string is the discriminator default
String type = String.class.toString(); // string is the discriminator default
if ( discriminatorOptionsAnnotation != null ) {
name = discriminatorOptionsAnnotation.value( "name" ).asString();
@ -77,15 +83,15 @@ public class MappedAttribute implements Comparable<MappedAttribute> {
);
switch ( discriminatorType ) {
case STRING: {
type = String.class;
type = String.class.toString();
break;
}
case CHAR: {
type = Character.class;
type = Character.class.toString();
break;
}
case INTEGER: {
type = Integer.class;
type = Integer.class.toString();
break;
}
default: {
@ -96,12 +102,14 @@ public class MappedAttribute implements Comparable<MappedAttribute> {
return new MappedAttribute( name, type, discriminatorAnnotations, true );
}
private MappedAttribute(String name, Class<?> type, Map<DotName, List<AnnotationInstance>> annotations, boolean isDiscriminator) {
private MappedAttribute(String name, String type, Map<DotName, List<AnnotationInstance>> annotations, boolean isDiscriminator) {
this.name = name;
this.type = type;
this.annotations = annotations;
this.isDiscriminator = isDiscriminator;
this.typeParameters = new HashMap<String, String>();
this.type = determineType( type, typeParameters );
AnnotationInstance idAnnotation = JandexHelper.getSingleAnnotation( annotations, JPADotNames.ID );
isId = idAnnotation != null;
@ -127,7 +135,7 @@ public class MappedAttribute implements Comparable<MappedAttribute> {
return name;
}
public final Class<?> getType() {
public final String getType() {
return type;
}
@ -135,6 +143,10 @@ public class MappedAttribute implements Comparable<MappedAttribute> {
return columnValues;
}
public Map<String, String> getTypeParameters() {
return typeParameters;
}
public boolean isId() {
return isId;
}
@ -155,7 +167,7 @@ public class MappedAttribute implements Comparable<MappedAttribute> {
* @return Returns the annotation with the specified name or {@code null}. Note, since these are the
* annotations defined on a single attribute there can never be more than one.
*/
public final AnnotationInstance annotations(DotName annotationDotName) {
public final AnnotationInstance getIfExists(DotName annotationDotName) {
if ( annotations.containsKey( annotationDotName ) ) {
List<AnnotationInstance> instanceList = annotations.get( annotationDotName );
if ( instanceList.size() > 1 ) {
@ -176,12 +188,27 @@ public class MappedAttribute implements Comparable<MappedAttribute> {
@Override
public String toString() {
final StringBuilder sb = new StringBuilder();
sb.append( "MappedProperty" );
sb.append( "MappedAttribute" );
sb.append( "{name='" ).append( name ).append( '\'' );
sb.append( ", type=" ).append( type );
sb.append( ", type='" ).append( type ).append( '\'' );
sb.append( ", isId=" ).append( isId );
sb.append( ", isVersioned=" ).append( isVersioned );
sb.append( ", isDiscriminator=" ).append( isDiscriminator );
sb.append( '}' );
return sb.toString();
}
/**
* We need to check whether the is an explicit type specified via {@link org.hibernate.annotations.Type}.
*
* @param type the type specified via the constructor
* @param typeParameters map for type parameters in case there are any
*
* @return the final type for this mapped attribute
*/
private String determineType(String type, Map<String, String> typeParameters) {
return type;
}
}

View File

@ -24,7 +24,6 @@
package org.hibernate.metamodel.source.annotations.entity.state.binding;
import java.util.Map;
import java.util.Properties;
import org.hibernate.mapping.PropertyGeneration;
import org.hibernate.metamodel.binding.state.SimpleAttributeBindingState;
@ -40,13 +39,12 @@ public class AttributeBindingStateImpl implements SimpleAttributeBindingState {
private final MappedAttribute mappedAttribute;
private final PropertyGeneration propertyGeneration = null;
private final String typeName;
private final Properties typeParameters;
private final Map<String, String> typeParameters;
public AttributeBindingStateImpl(MappedAttribute mappedAttribute) {
this.mappedAttribute = mappedAttribute;
typeName = mappedAttribute.getType().getName();
// TODO: implement....
typeParameters = null;
typeName = mappedAttribute.getType();
typeParameters = mappedAttribute.getTypeParameters();
}
@Override
@ -73,7 +71,7 @@ public class AttributeBindingStateImpl implements SimpleAttributeBindingState {
}
@Override
public boolean isUpdateable() {
public boolean isUpdatable() {
return false; //To change body of implemented methods use File | Settings | File Templates.
}
@ -93,7 +91,7 @@ public class AttributeBindingStateImpl implements SimpleAttributeBindingState {
}
@Override
public Properties getTypeParameters() {
public Map<String, String> getTypeParameters() {
return typeParameters;
}

View File

@ -155,13 +155,13 @@ public class AttributeColumnRelationalState implements ColumnRelationalState {
List<AnnotationInstance> allColumnTransformerAnnotations = new ArrayList<AnnotationInstance>();
// not quite sure about the usefulness of @ColumnTransformers (HF)
AnnotationInstance columnTransformersAnnotations = attribute.annotations( HibernateDotNames.COLUMN_TRANSFORMERS );
AnnotationInstance columnTransformersAnnotations = attribute.getIfExists( HibernateDotNames.COLUMN_TRANSFORMERS );
if ( columnTransformersAnnotations != null ) {
AnnotationInstance[] annotationInstances = allColumnTransformerAnnotations.get( 0 ).value().asNestedArray();
allColumnTransformerAnnotations.addAll( Arrays.asList( annotationInstances ) );
}
AnnotationInstance columnTransformerAnnotation = attribute.annotations( HibernateDotNames.COLUMN_TRANSFORMER );
AnnotationInstance columnTransformerAnnotation = attribute.getIfExists( HibernateDotNames.COLUMN_TRANSFORMER );
if ( columnTransformerAnnotation != null ) {
allColumnTransformerAnnotations.add( columnTransformerAnnotation );
}
@ -196,7 +196,7 @@ public class AttributeColumnRelationalState implements ColumnRelationalState {
private String parseCheckAnnotation(MappedAttribute attribute) {
String checkCondition = null;
AnnotationInstance checkAnnotation = attribute.annotations( HibernateDotNames.CHECK );
AnnotationInstance checkAnnotation = attribute.getIfExists( HibernateDotNames.CHECK );
if ( checkAnnotation != null ) {
checkCondition = checkAnnotation.value( "constraints" ).toString();
}
@ -205,7 +205,7 @@ public class AttributeColumnRelationalState implements ColumnRelationalState {
private Set<String> parseIndexAnnotation(MappedAttribute attribute) {
Set<String> indexNames = new HashSet<String>();
AnnotationInstance indexAnnotation = attribute.annotations( HibernateDotNames.INDEX );
AnnotationInstance indexAnnotation = attribute.getIfExists( HibernateDotNames.INDEX );
if ( indexAnnotation != null ) {
String indexName = indexAnnotation.value( "name" ).toString();
indexNames.add( indexName );

View File

@ -112,7 +112,7 @@ public class HibernateMappingBinder implements MappingDefaults {
}
public String getDefaultDescriminatorColumnName() {
public String getDefaultDiscriminatorColumnName() {
return DEFAULT_DISCRIMINATOR_COLUMN_NAME;
}

View File

@ -24,15 +24,14 @@
package org.hibernate.metamodel.source.hbm.state.binding;
import java.util.Map;
import java.util.Properties;
import org.hibernate.MappingException;
import org.hibernate.internal.util.ReflectHelper;
import org.hibernate.mapping.PropertyGeneration;
import org.hibernate.metamodel.binding.MappingDefaults;
import org.hibernate.metamodel.binding.state.AttributeBindingState;
import org.hibernate.metamodel.domain.MetaAttribute;
import org.hibernate.metamodel.source.util.MappingHelper;
import org.hibernate.metamodel.binding.state.AttributeBindingState;
/**
* @author Gail Badner
@ -63,7 +62,7 @@ public abstract class AbstractHbmAttributeBindingState implements AttributeBindi
this.ownerClassName = ownerClassName;
this.attributeName = attributeName;
this.defaults = defaults;
this.nodeName = nodeName;
this.nodeName = nodeName;
this.metaAttributes = metaAttributes;
this.accessorName = accessorName;
this.isOptimisticLockable = isOptimisticLockable;
@ -121,7 +120,7 @@ public abstract class AbstractHbmAttributeBindingState implements AttributeBindi
return null;
}
public Properties getTypeParameters() {
public Map<String, String> getTypeParameters() {
return null;
}
}

View File

@ -24,8 +24,8 @@
package org.hibernate.metamodel.source.hbm.state.binding;
import org.hibernate.metamodel.binding.MappingDefaults;
import org.hibernate.metamodel.source.hbm.xml.mapping.XMLHibernateMapping.XMLClass.XMLDiscriminator;
import org.hibernate.metamodel.binding.state.DiscriminatorBindingState;
import org.hibernate.metamodel.source.hbm.xml.mapping.XMLHibernateMapping.XMLClass.XMLDiscriminator;
/**
* @author Gail Badner
@ -41,7 +41,7 @@ public class HbmDiscriminatorBindingState extends AbstractHbmAttributeBindingSta
// Discriminator.getName() is not defined, so the attribute will always be
// defaults.getDefaultDescriminatorColumnName()
super(
ownerClassName, defaults.getDefaultDescriminatorColumnName(), defaults, null, null, null, true
ownerClassName, defaults.getDefaultDiscriminatorColumnName(), defaults, null, null, null, true
);
this.discriminator = discriminator;
}
@ -66,7 +66,7 @@ public class HbmDiscriminatorBindingState extends AbstractHbmAttributeBindingSta
return discriminator.isInsert();
}
public boolean isUpdateable() {
public boolean isUpdatable() {
return false;
}

View File

@ -160,7 +160,7 @@ public class HbmManyToOneAttributeBindingState
return isInsertable;
}
public boolean isUpdateable() {
public boolean isUpdatable() {
return isUpdateable;
}

View File

@ -23,12 +23,13 @@
*/
package org.hibernate.metamodel.source.hbm.state.binding;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import org.hibernate.MappingException;
import org.hibernate.mapping.PropertyGeneration;
import org.hibernate.metamodel.binding.MappingDefaults;
import org.hibernate.metamodel.binding.state.SimpleAttributeBindingState;
import org.hibernate.metamodel.domain.MetaAttribute;
import org.hibernate.metamodel.source.hbm.HbmHelper;
import org.hibernate.metamodel.source.hbm.xml.mapping.XMLHibernateMapping.XMLClass.XMLId;
@ -37,7 +38,6 @@ import org.hibernate.metamodel.source.hbm.xml.mapping.XMLHibernateMapping.XMLCla
import org.hibernate.metamodel.source.hbm.xml.mapping.XMLParamElement;
import org.hibernate.metamodel.source.hbm.xml.mapping.XMLPropertyElement;
import org.hibernate.metamodel.source.util.MappingHelper;
import org.hibernate.metamodel.binding.state.SimpleAttributeBindingState;
/**
* @author Gail Badner
@ -45,12 +45,12 @@ import org.hibernate.metamodel.binding.state.SimpleAttributeBindingState;
public class HbmSimpleAttributeBindingState extends AbstractHbmAttributeBindingState
implements SimpleAttributeBindingState {
private final String typeName;
private final Properties typeParameters = new Properties();
private final Map<String, String> typeParameters = new HashMap<String, String>();
private final boolean isLazy;
private final PropertyGeneration propertyGeneration;
private final boolean isInsertable;
private final boolean isUpdateable;
private final boolean isUpdatable;
public HbmSimpleAttributeBindingState(
String ownerClassName,
@ -69,7 +69,7 @@ public class HbmSimpleAttributeBindingState extends AbstractHbmAttributeBindingS
this.isLazy = false;
if ( id.getTypeAttribute() != null ) {
typeName = maybeConvertToTypeDefName( id.getTypeAttribute(), defaults );
typeName = maybeConvertToTypeDefName( id.getTypeAttribute(), defaults );
}
else if ( id.getType() != null ) {
typeName = maybeConvertToTypeDefName( id.getType().getName(), defaults );
@ -82,7 +82,7 @@ public class HbmSimpleAttributeBindingState extends AbstractHbmAttributeBindingS
this.propertyGeneration = PropertyGeneration.parse( null );
this.isInsertable = true;
this.isUpdateable = false;
this.isUpdatable = false;
}
private static String maybeConvertToTypeDefName(String typeName, MappingDefaults defaults) {
@ -121,7 +121,7 @@ public class HbmSimpleAttributeBindingState extends AbstractHbmAttributeBindingS
throw new MappingException( "'generated' attribute cannot be 'insert' for versioning property" );
}
this.isInsertable = MappingHelper.getBooleanValue( version.isInsert(), true );
this.isUpdateable = true;
this.isUpdatable = true;
}
public HbmSimpleAttributeBindingState(
@ -152,7 +152,7 @@ public class HbmSimpleAttributeBindingState extends AbstractHbmAttributeBindingS
throw new MappingException( "'generated' attribute cannot be 'insert' for versioning property" );
}
this.isInsertable = true; //TODO: is this right????
this.isUpdateable = true;
this.isUpdatable = true;
}
public HbmSimpleAttributeBindingState(
@ -197,10 +197,10 @@ public class HbmSimpleAttributeBindingState extends AbstractHbmAttributeBindingS
property.getName()
);
}
isUpdateable = false;
isUpdatable = false;
}
else {
isUpdateable = MappingHelper.getBooleanValue( property.isUpdate(), true );
isUpdatable = MappingHelper.getBooleanValue( property.isUpdate(), true );
}
if ( property.getTypeAttribute() != null ) {
@ -241,7 +241,7 @@ public class HbmSimpleAttributeBindingState extends AbstractHbmAttributeBindingS
return typeName;
}
public Properties getTypeParameters() {
public Map<String, String> getTypeParameters() {
return typeParameters;
}
@ -257,8 +257,8 @@ public class HbmSimpleAttributeBindingState extends AbstractHbmAttributeBindingS
return isInsertable;
}
public boolean isUpdateable() {
return isUpdateable;
public boolean isUpdatable() {
return isUpdatable;
}
public String getCascade() {

View File

@ -134,8 +134,8 @@ public class MetadataImpl implements Metadata, MetadataImplementor, Serializable
index = ormParser.parseAndUpdateIndex( mappings, index );
// create the annotation binder and pass it the final annotation index
final AnnotationBinder annotationBinder = new AnnotationBinder( this );
annotationBinder.bind( index );
final AnnotationBinder annotationBinder = new AnnotationBinder( this, index );
annotationBinder.bind();
}
/**

View File

@ -41,8 +41,6 @@ import org.junit.Test;
import org.hibernate.metamodel.source.annotations.entity.ConfiguredClass;
import org.hibernate.metamodel.source.annotations.entity.ConfiguredClassHierarchy;
import org.hibernate.metamodel.source.annotations.entity.MappedAttribute;
import org.hibernate.metamodel.source.annotations.entity.ConfiguredClass;
import org.hibernate.metamodel.source.annotations.entity.ConfiguredClassHierarchy;
import org.hibernate.service.ServiceRegistryBuilder;
import org.hibernate.service.classloading.spi.ClassLoaderService;
import org.hibernate.service.internal.BasicServiceRegistryImpl;
@ -83,7 +81,7 @@ public class GenericTypeDiscoveryTest extends BaseUnitTestCase {
ClassInfo info = configuredClass.getClassInfo();
assertEquals( "wrong class", DotName.createSimple( Stuff.class.getName() ), info.name() );
MappedAttribute property = configuredClass.getMappedProperty( "value" );
assertEquals( Price.class, property.getType() );
assertEquals( Price.class.getName(), property.getType() );
assertTrue( iter.hasNext() );
configuredClass = iter.next();
@ -99,9 +97,9 @@ public class GenericTypeDiscoveryTest extends BaseUnitTestCase {
assertEquals( "wrong class", DotName.createSimple( Item.class.getName() ), info.name() );
// properties are alphabetically ordered!
property = configuredClass.getMappedProperty( "owner" );
assertEquals( SomeGuy.class, property.getType() );
assertEquals( SomeGuy.class.getName(), property.getType() );
property = configuredClass.getMappedProperty( "type" );
assertEquals( PaperType.class, property.getType() );
assertEquals( PaperType.class.getName(), property.getType() );
assertTrue( iter.hasNext() );
configuredClass = iter.next();

View File

@ -0,0 +1,96 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2011, 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.metamodel.source.annotations.util;
import java.util.Iterator;
import java.util.Set;
import javax.persistence.Id;
import org.jboss.jandex.ClassInfo;
import org.jboss.jandex.DotName;
import org.jboss.jandex.Index;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.hibernate.metamodel.source.annotations.entity.ConfiguredClass;
import org.hibernate.metamodel.source.annotations.entity.ConfiguredClassHierarchy;
import org.hibernate.metamodel.source.annotations.entity.MappedAttribute;
import org.hibernate.service.ServiceRegistryBuilder;
import org.hibernate.service.classloading.spi.ClassLoaderService;
import org.hibernate.service.internal.BasicServiceRegistryImpl;
import org.hibernate.testing.junit4.BaseUnitTestCase;
import static junit.framework.Assert.assertEquals;
/**
* @author Hardy Ferentschik
*/
public class TypeDiscoveryTest extends BaseUnitTestCase {
private BasicServiceRegistryImpl serviceRegistry;
private ClassLoaderService service;
@Before
public void setUp() {
serviceRegistry = (BasicServiceRegistryImpl) new ServiceRegistryBuilder().buildServiceRegistry();
service = serviceRegistry.getService( ClassLoaderService.class );
}
@After
public void tearDown() {
serviceRegistry.destroy();
}
@Test
public void testImplicitAndExplicitType() {
Index index = JandexHelper.indexForClass( service, Entity.class );
Set<ConfiguredClassHierarchy> hierarchies = ConfiguredClassHierarchyBuilder.createEntityHierarchies(
index, serviceRegistry
);
assertEquals( "There should be only one hierarchy", 1, hierarchies.size() );
Iterator<ConfiguredClass> iter = hierarchies.iterator().next().iterator();
ConfiguredClass configuredClass = iter.next();
ClassInfo info = configuredClass.getClassInfo();
assertEquals( "wrong class", DotName.createSimple( Entity.class.getName() ), info.name() );
MappedAttribute property = configuredClass.getMappedProperty( "id" );
assertEquals( "Unexpected property type", "int", property.getType() );
property = configuredClass.getMappedProperty( "string" );
assertEquals( "Unexpected property type", String.class.getName(), property.getType() );
property = configuredClass.getMappedProperty( "customString" );
assertEquals( "Unexpected property type", String.class.getName(), property.getType() );
}
@javax.persistence.Entity
class Entity {
@Id
private int id;
private String string;
private String customString;
}
}