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:
parent
bf4d8ad290
commit
2b694d7a86
|
@ -31,6 +31,7 @@ import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.hibernate.MappingException;
|
import org.hibernate.MappingException;
|
||||||
|
import org.hibernate.metamodel.binding.state.AttributeBindingState;
|
||||||
import org.hibernate.metamodel.domain.Attribute;
|
import org.hibernate.metamodel.domain.Attribute;
|
||||||
import org.hibernate.metamodel.domain.MetaAttribute;
|
import org.hibernate.metamodel.domain.MetaAttribute;
|
||||||
import org.hibernate.metamodel.relational.Column;
|
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.TableSpecification;
|
||||||
import org.hibernate.metamodel.relational.Tuple;
|
import org.hibernate.metamodel.relational.Tuple;
|
||||||
import org.hibernate.metamodel.relational.Value;
|
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.SimpleValueRelationalState;
|
||||||
import org.hibernate.metamodel.relational.state.ValueRelationalState;
|
|
||||||
import org.hibernate.metamodel.relational.state.TupleRelationalState;
|
import org.hibernate.metamodel.relational.state.TupleRelationalState;
|
||||||
|
import org.hibernate.metamodel.relational.state.ValueCreator;
|
||||||
|
import org.hibernate.metamodel.relational.state.ValueRelationalState;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO : javadoc
|
* TODO : javadoc
|
||||||
|
@ -51,11 +51,9 @@ import org.hibernate.metamodel.relational.state.TupleRelationalState;
|
||||||
* @author Steve Ebersole
|
* @author Steve Ebersole
|
||||||
*/
|
*/
|
||||||
public abstract class AbstractAttributeBinding implements AttributeBinding {
|
public abstract class AbstractAttributeBinding implements AttributeBinding {
|
||||||
|
|
||||||
private final HibernateTypeDescriptor hibernateTypeDescriptor = new HibernateTypeDescriptor();
|
private final HibernateTypeDescriptor hibernateTypeDescriptor = new HibernateTypeDescriptor();
|
||||||
private final EntityBinding entityBinding;
|
private final EntityBinding entityBinding;
|
||||||
private final Set<EntityReferencingAttributeBinding> entityReferencingAttributeBindings =
|
private final Set<EntityReferencingAttributeBinding> entityReferencingAttributeBindings = new HashSet<EntityReferencingAttributeBinding>();
|
||||||
new HashSet<EntityReferencingAttributeBinding>();
|
|
||||||
|
|
||||||
private Attribute attribute;
|
private Attribute attribute;
|
||||||
private Value value;
|
private Value value;
|
||||||
|
@ -83,7 +81,7 @@ public abstract class AbstractAttributeBinding implements AttributeBinding {
|
||||||
isAlternateUniqueKey = state.isAlternateUniqueKey();
|
isAlternateUniqueKey = state.isAlternateUniqueKey();
|
||||||
cascade = state.getCascade();
|
cascade = state.getCascade();
|
||||||
optimisticLockable = state.isOptimisticLockable();
|
optimisticLockable = state.isOptimisticLockable();
|
||||||
nodeName = state.getNodeName() ;
|
nodeName = state.getNodeName();
|
||||||
metaAttributes = state.getMetaAttributes();
|
metaAttributes = state.getMetaAttributes();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -125,14 +123,15 @@ public abstract class AbstractAttributeBinding implements AttributeBinding {
|
||||||
// TODO: not sure I like this here...
|
// TODO: not sure I like this here...
|
||||||
if ( isPrimaryKey() ) {
|
if ( isPrimaryKey() ) {
|
||||||
if ( SimpleValue.class.isInstance( value ) ) {
|
if ( SimpleValue.class.isInstance( value ) ) {
|
||||||
if ( ! Column.class.isInstance( value ) ) {
|
if ( !Column.class.isInstance( value ) ) {
|
||||||
// this should never ever happen..
|
// this should never ever happen..
|
||||||
throw new MappingException( "Simple ID is not a column." );
|
throw new MappingException( "Simple ID is not a column." );
|
||||||
}
|
}
|
||||||
entityBinding.getBaseTable().getPrimaryKey().addColumn( Column.class.cast( value ) );
|
entityBinding.getBaseTable().getPrimaryKey().addColumn( Column.class.cast( value ) );
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
for ( SimpleValueRelationalState val : TupleRelationalState.class.cast( state ).getRelationalStates() ) {
|
for ( SimpleValueRelationalState val : TupleRelationalState.class.cast( state )
|
||||||
|
.getRelationalStates() ) {
|
||||||
if ( Column.class.isInstance( val ) ) {
|
if ( Column.class.isInstance( val ) ) {
|
||||||
entityBinding.getBaseTable().getPrimaryKey().addColumn( Column.class.cast( val ) );
|
entityBinding.getBaseTable().getPrimaryKey().addColumn( Column.class.cast( val ) );
|
||||||
}
|
}
|
||||||
|
@ -169,8 +168,8 @@ public abstract class AbstractAttributeBinding implements AttributeBinding {
|
||||||
return value == null
|
return value == null
|
||||||
? Collections.<SimpleValue>emptyList()
|
? Collections.<SimpleValue>emptyList()
|
||||||
: value instanceof Tuple
|
: value instanceof Tuple
|
||||||
? ( (Tuple) value ).values()
|
? ( (Tuple) value ).values()
|
||||||
: Collections.singletonList( (SimpleValue) value );
|
: Collections.singletonList( (SimpleValue) value );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -220,9 +219,9 @@ public abstract class AbstractAttributeBinding implements AttributeBinding {
|
||||||
public boolean[] getColumnInsertability() {
|
public boolean[] getColumnInsertability() {
|
||||||
List<Boolean> tmp = new ArrayList<Boolean>();
|
List<Boolean> tmp = new ArrayList<Boolean>();
|
||||||
for ( SimpleValue simpleValue : getValues() ) {
|
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;
|
int i = 0;
|
||||||
for ( Boolean insertable : tmp ) {
|
for ( Boolean insertable : tmp ) {
|
||||||
rtn[i++] = insertable.booleanValue();
|
rtn[i++] = insertable.booleanValue();
|
||||||
|
@ -253,11 +252,10 @@ public abstract class AbstractAttributeBinding implements AttributeBinding {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void validate() {
|
public void validate() {
|
||||||
if ( ! entityReferencingAttributeBindings.isEmpty() ) {
|
if ( !entityReferencingAttributeBindings.isEmpty() ) {
|
||||||
// TODO; validate that this AttributeBinding can be a target of an entity reference
|
// 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)
|
// (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?
|
// can a unique attribute be used as a target? if so, does it need to be non-null?
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,7 @@
|
||||||
*/
|
*/
|
||||||
package org.hibernate.metamodel.binding;
|
package org.hibernate.metamodel.binding;
|
||||||
|
|
||||||
import java.util.Properties;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.hibernate.type.Type;
|
import org.hibernate.type.Type;
|
||||||
|
|
||||||
|
@ -35,7 +35,7 @@ import org.hibernate.type.Type;
|
||||||
public class HibernateTypeDescriptor {
|
public class HibernateTypeDescriptor {
|
||||||
private String typeName;
|
private String typeName;
|
||||||
private Type explicitType;
|
private Type explicitType;
|
||||||
private Properties typeParameters;
|
private Map<String, String> typeParameters;
|
||||||
|
|
||||||
public String getTypeName() {
|
public String getTypeName() {
|
||||||
return typeName;
|
return typeName;
|
||||||
|
@ -55,12 +55,12 @@ public class HibernateTypeDescriptor {
|
||||||
this.explicitType = explicitType;
|
this.explicitType = explicitType;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Properties getTypeParameters() {
|
public Map<String, String> getTypeParameters() {
|
||||||
return typeParameters;
|
return typeParameters;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* package-protected */
|
/* package-protected */
|
||||||
void setTypeParameters(Properties typeParameters) {
|
void setTypeParameters(Map<String, String> typeParameters) {
|
||||||
this.typeParameters = typeParameters;
|
this.typeParameters = typeParameters;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,9 +29,9 @@ package org.hibernate.metamodel.binding;
|
||||||
* @author Steve Ebersole
|
* @author Steve Ebersole
|
||||||
*/
|
*/
|
||||||
public interface KeyValueBinding extends AttributeBinding {
|
public interface KeyValueBinding extends AttributeBinding {
|
||||||
public boolean isKeyCasadeDeleteEnabled();
|
public boolean isKeyCascadeDeleteEnabled();
|
||||||
|
|
||||||
public String getUnsavedValue();
|
public String getUnsavedValue();
|
||||||
|
|
||||||
public boolean isUpdateable();
|
public boolean isUpdatable();
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,14 +34,24 @@ import org.hibernate.service.ServiceRegistry;
|
||||||
*/
|
*/
|
||||||
public interface MappingDefaults {
|
public interface MappingDefaults {
|
||||||
Map<String, MetaAttribute> getMappingMetas();
|
Map<String, MetaAttribute> getMappingMetas();
|
||||||
|
|
||||||
String getPackageName();
|
String getPackageName();
|
||||||
|
|
||||||
String getDefaultSchemaName();
|
String getDefaultSchemaName();
|
||||||
|
|
||||||
String getDefaultCatalogName();
|
String getDefaultCatalogName();
|
||||||
|
|
||||||
String getDefaultIdColumnName();
|
String getDefaultIdColumnName();
|
||||||
String getDefaultDescriminatorColumnName();
|
|
||||||
|
String getDefaultDiscriminatorColumnName();
|
||||||
|
|
||||||
String getDefaultCascade();
|
String getDefaultCascade();
|
||||||
|
|
||||||
String getDefaultAccess();
|
String getDefaultAccess();
|
||||||
|
|
||||||
boolean isDefaultLazy();
|
boolean isDefaultLazy();
|
||||||
|
|
||||||
ServiceRegistry getServiceRegistry();
|
ServiceRegistry getServiceRegistry();
|
||||||
|
|
||||||
NamingStrategy getNamingStrategy();
|
NamingStrategy getNamingStrategy();
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,8 +25,8 @@ package org.hibernate.metamodel.binding;
|
||||||
|
|
||||||
import org.hibernate.mapping.PropertyGeneration;
|
import org.hibernate.mapping.PropertyGeneration;
|
||||||
import org.hibernate.metamodel.binding.state.SimpleAttributeBindingState;
|
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.ColumnRelationalState;
|
||||||
|
import org.hibernate.metamodel.relational.state.ValueRelationalState;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO : javadoc
|
* TODO : javadoc
|
||||||
|
@ -37,8 +37,8 @@ public class SimpleAttributeBinding extends AbstractAttributeBinding implements
|
||||||
private final boolean forceNonNullable;
|
private final boolean forceNonNullable;
|
||||||
private final boolean forceUnique;
|
private final boolean forceUnique;
|
||||||
private boolean insertable;
|
private boolean insertable;
|
||||||
private boolean updateable;
|
private boolean updatable;
|
||||||
private boolean keyCasadeDeleteEnabled;
|
private boolean keyCascadeDeleteEnabled;
|
||||||
private String unsavedValue;
|
private String unsavedValue;
|
||||||
private PropertyGeneration generation;
|
private PropertyGeneration generation;
|
||||||
|
|
||||||
|
@ -51,8 +51,8 @@ public class SimpleAttributeBinding extends AbstractAttributeBinding implements
|
||||||
public final SimpleAttributeBinding initialize(SimpleAttributeBindingState state) {
|
public final SimpleAttributeBinding initialize(SimpleAttributeBindingState state) {
|
||||||
super.initialize( state );
|
super.initialize( state );
|
||||||
insertable = state.isInsertable();
|
insertable = state.isInsertable();
|
||||||
updateable = state.isUpdateable();
|
updatable = state.isUpdatable();
|
||||||
keyCasadeDeleteEnabled = state.isKeyCascadeDeleteEnabled();
|
keyCascadeDeleteEnabled = state.isKeyCascadeDeleteEnabled();
|
||||||
unsavedValue = state.getUnsavedValue();
|
unsavedValue = state.getUnsavedValue();
|
||||||
generation = state.getPropertyGeneration() == null ? PropertyGeneration.NEVER : state.getPropertyGeneration();
|
generation = state.getPropertyGeneration() == null ? PropertyGeneration.NEVER : state.getPropertyGeneration();
|
||||||
return this;
|
return this;
|
||||||
|
@ -80,21 +80,21 @@ public class SimpleAttributeBinding extends AbstractAttributeBinding implements
|
||||||
this.insertable = insertable;
|
this.insertable = insertable;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isUpdateable() {
|
public boolean isUpdatable() {
|
||||||
return updateable;
|
return updatable;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void setUpdateable(boolean updateable) {
|
protected void setUpdatable(boolean updatable) {
|
||||||
this.updateable = updateable;
|
this.updatable = updatable;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isKeyCasadeDeleteEnabled() {
|
public boolean isKeyCascadeDeleteEnabled() {
|
||||||
return keyCasadeDeleteEnabled;
|
return keyCascadeDeleteEnabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setKeyCasadeDeleteEnabled(boolean keyCasadeDeleteEnabled) {
|
public void setKeyCascadeDeleteEnabled(boolean keyCascadeDeleteEnabled) {
|
||||||
this.keyCasadeDeleteEnabled = keyCasadeDeleteEnabled;
|
this.keyCascadeDeleteEnabled = keyCascadeDeleteEnabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -117,5 +117,4 @@ public class SimpleAttributeBinding extends AbstractAttributeBinding implements
|
||||||
public PropertyGeneration getGeneration() {
|
public PropertyGeneration getGeneration() {
|
||||||
return generation;
|
return generation;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,7 +24,6 @@
|
||||||
package org.hibernate.metamodel.binding.state;
|
package org.hibernate.metamodel.binding.state;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Properties;
|
|
||||||
|
|
||||||
import org.hibernate.metamodel.domain.MetaAttribute;
|
import org.hibernate.metamodel.domain.MetaAttribute;
|
||||||
|
|
||||||
|
@ -36,7 +35,7 @@ public interface AttributeBindingState {
|
||||||
|
|
||||||
String getTypeName();
|
String getTypeName();
|
||||||
|
|
||||||
Properties getTypeParameters();
|
Map<String, String> getTypeParameters();
|
||||||
|
|
||||||
boolean isLazy();
|
boolean isLazy();
|
||||||
|
|
||||||
|
|
|
@ -31,7 +31,7 @@ import org.hibernate.mapping.PropertyGeneration;
|
||||||
public interface SimpleAttributeBindingState extends AttributeBindingState {
|
public interface SimpleAttributeBindingState extends AttributeBindingState {
|
||||||
boolean isInsertable();
|
boolean isInsertable();
|
||||||
|
|
||||||
boolean isUpdateable();
|
boolean isUpdatable();
|
||||||
|
|
||||||
boolean isKeyCascadeDeleteEnabled();
|
boolean isKeyCascadeDeleteEnabled();
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,6 @@
|
||||||
*/
|
*/
|
||||||
package org.hibernate.metamodel.source.annotations;
|
package org.hibernate.metamodel.source.annotations;
|
||||||
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.jboss.jandex.Index;
|
import org.jboss.jandex.Index;
|
||||||
|
@ -44,36 +43,37 @@ import org.hibernate.metamodel.source.internal.MetadataImpl;
|
||||||
* are added to the annotation index.
|
* are added to the annotation index.
|
||||||
*
|
*
|
||||||
* @author Hardy Ferentschik
|
* @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 {
|
public class AnnotationBinder {
|
||||||
private static final Logger log = LoggerFactory.getLogger( AnnotationBinder.class );
|
private static final Logger log = LoggerFactory.getLogger( AnnotationBinder.class );
|
||||||
private final MetadataImpl metadata;
|
private final MetadataImpl metadata;
|
||||||
|
private final Index index;
|
||||||
|
|
||||||
public AnnotationBinder(MetadataImpl metadata) {
|
public AnnotationBinder(MetadataImpl metadata, Index index) {
|
||||||
this.metadata = metadata;
|
this.metadata = metadata;
|
||||||
|
this.index = index;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void bind(Index annotationIndex) {
|
public void bind() {
|
||||||
preEntityBindings( annotationIndex );
|
preEntityBindings();
|
||||||
bindMappedClasses( annotationIndex );
|
bindMappedClasses();
|
||||||
postEntityBindings( annotationIndex );
|
postEntityBindings();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Binds global configuration data prior to entity binding. This includes generators and type definitions
|
* Binds global configuration data prior to entity binding. This includes generators and type definitions.
|
||||||
*
|
|
||||||
* @param annotationIndex the annotation repository/index
|
|
||||||
*/
|
*/
|
||||||
private void preEntityBindings(Index annotationIndex) {
|
private void preEntityBindings() {
|
||||||
FetchProfileBinder.bind( metadata, annotationIndex );
|
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
|
// need to order our annotated entities into an order we can process
|
||||||
Set<ConfiguredClassHierarchy> hierarchies = ConfiguredClassHierarchyBuilder.createEntityHierarchies(
|
Set<ConfiguredClassHierarchy> hierarchies = ConfiguredClassHierarchyBuilder.createEntityHierarchies(
|
||||||
annotationIndex, metadata.getServiceRegistry()
|
index, metadata.getServiceRegistry()
|
||||||
);
|
);
|
||||||
|
|
||||||
// now we process each hierarchy one at the time
|
// 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
|
* 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
|
* entity or entity hierarchy, for example sequence generators, fetch profiles, etc
|
||||||
*
|
|
||||||
* @param annotationIndex the annotation repository/index
|
|
||||||
*/
|
*/
|
||||||
private void postEntityBindings(Index annotationIndex) {
|
private void postEntityBindings() {
|
||||||
TableBinder.bind( metadata, annotationIndex );
|
TableBinder.bind( metadata, index );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -380,7 +380,7 @@ public class ConfiguredClass {
|
||||||
final Map<DotName, List<AnnotationInstance>> annotations = JandexHelper.getMemberAnnotations(
|
final Map<DotName, List<AnnotationInstance>> annotations = JandexHelper.getMemberAnnotations(
|
||||||
classInfo, member.getName()
|
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) {
|
private Type findResolvedType(String name, ResolvedMember[] resolvedMembers) {
|
||||||
|
|
|
@ -196,7 +196,7 @@ public class ConfiguredClassHierarchy implements Iterable<ConfiguredClass> {
|
||||||
|
|
||||||
private AccessType throwIdNotFoundAnnotationException(List<ClassInfo> classes) {
|
private AccessType throwIdNotFoundAnnotationException(List<ClassInfo> classes) {
|
||||||
StringBuilder builder = new StringBuilder();
|
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 ) );
|
builder.append( hierarchyListString( classes ) );
|
||||||
throw new AnnotationException( builder.toString() );
|
throw new AnnotationException( builder.toString() );
|
||||||
}
|
}
|
||||||
|
|
|
@ -85,11 +85,13 @@ public class EntityBinder {
|
||||||
bindJpaCaching( entityBinding );
|
bindJpaCaching( entityBinding );
|
||||||
bindHibernateCaching( entityBinding );
|
bindHibernateCaching( entityBinding );
|
||||||
|
|
||||||
|
// take care of the id, attributes and relations
|
||||||
if ( configuredClass.isRoot() ) {
|
if ( configuredClass.isRoot() ) {
|
||||||
bindId( entityBinding );
|
bindId( entityBinding );
|
||||||
}
|
}
|
||||||
bindAttributes( entityBinding );
|
bindAttributes( entityBinding );
|
||||||
|
|
||||||
|
// last, but not least we register the new EntityBinding with the metadata
|
||||||
meta.addEntity( entityBinding );
|
meta.addEntity( entityBinding );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
*/
|
*/
|
||||||
package org.hibernate.metamodel.source.annotations.entity;
|
package org.hibernate.metamodel.source.annotations.entity;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import javax.persistence.DiscriminatorType;
|
import javax.persistence.DiscriminatorType;
|
||||||
|
@ -43,15 +44,20 @@ import org.hibernate.metamodel.source.annotations.util.JandexHelper;
|
||||||
* @author Hardy Ferentschik
|
* @author Hardy Ferentschik
|
||||||
*/
|
*/
|
||||||
public class MappedAttribute implements Comparable<MappedAttribute> {
|
public class MappedAttribute implements Comparable<MappedAttribute> {
|
||||||
private final String name;
|
|
||||||
private final Class<?> type;
|
|
||||||
private final Map<DotName, List<AnnotationInstance>> annotations;
|
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 ColumnValues columnValues;
|
||||||
|
|
||||||
private final boolean isId;
|
private final boolean isId;
|
||||||
private final boolean isVersioned;
|
private final boolean isVersioned;
|
||||||
private final boolean isDiscriminator;
|
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 );
|
return new MappedAttribute( name, type, annotations, false );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -68,7 +74,7 @@ public class MappedAttribute implements Comparable<MappedAttribute> {
|
||||||
annotations, JPADotNames.DISCRIMINATOR_COLUMN
|
annotations, JPADotNames.DISCRIMINATOR_COLUMN
|
||||||
);
|
);
|
||||||
String name = DiscriminatorColumnValues.DEFAULT_DISCRIMINATOR_COLUMN_NAME;
|
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 ) {
|
if ( discriminatorOptionsAnnotation != null ) {
|
||||||
name = discriminatorOptionsAnnotation.value( "name" ).asString();
|
name = discriminatorOptionsAnnotation.value( "name" ).asString();
|
||||||
|
|
||||||
|
@ -77,15 +83,15 @@ public class MappedAttribute implements Comparable<MappedAttribute> {
|
||||||
);
|
);
|
||||||
switch ( discriminatorType ) {
|
switch ( discriminatorType ) {
|
||||||
case STRING: {
|
case STRING: {
|
||||||
type = String.class;
|
type = String.class.toString();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case CHAR: {
|
case CHAR: {
|
||||||
type = Character.class;
|
type = Character.class.toString();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case INTEGER: {
|
case INTEGER: {
|
||||||
type = Integer.class;
|
type = Integer.class.toString();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
|
@ -96,12 +102,14 @@ public class MappedAttribute implements Comparable<MappedAttribute> {
|
||||||
return new MappedAttribute( name, type, discriminatorAnnotations, true );
|
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.name = name;
|
||||||
this.type = type;
|
|
||||||
this.annotations = annotations;
|
this.annotations = annotations;
|
||||||
this.isDiscriminator = isDiscriminator;
|
this.isDiscriminator = isDiscriminator;
|
||||||
|
|
||||||
|
this.typeParameters = new HashMap<String, String>();
|
||||||
|
this.type = determineType( type, typeParameters );
|
||||||
|
|
||||||
AnnotationInstance idAnnotation = JandexHelper.getSingleAnnotation( annotations, JPADotNames.ID );
|
AnnotationInstance idAnnotation = JandexHelper.getSingleAnnotation( annotations, JPADotNames.ID );
|
||||||
isId = idAnnotation != null;
|
isId = idAnnotation != null;
|
||||||
|
|
||||||
|
@ -127,7 +135,7 @@ public class MappedAttribute implements Comparable<MappedAttribute> {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public final Class<?> getType() {
|
public final String getType() {
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -135,6 +143,10 @@ public class MappedAttribute implements Comparable<MappedAttribute> {
|
||||||
return columnValues;
|
return columnValues;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Map<String, String> getTypeParameters() {
|
||||||
|
return typeParameters;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isId() {
|
public boolean isId() {
|
||||||
return 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
|
* @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.
|
* 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 ) ) {
|
if ( annotations.containsKey( annotationDotName ) ) {
|
||||||
List<AnnotationInstance> instanceList = annotations.get( annotationDotName );
|
List<AnnotationInstance> instanceList = annotations.get( annotationDotName );
|
||||||
if ( instanceList.size() > 1 ) {
|
if ( instanceList.size() > 1 ) {
|
||||||
|
@ -176,12 +188,27 @@ public class MappedAttribute implements Comparable<MappedAttribute> {
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
final StringBuilder sb = new StringBuilder();
|
final StringBuilder sb = new StringBuilder();
|
||||||
sb.append( "MappedProperty" );
|
sb.append( "MappedAttribute" );
|
||||||
sb.append( "{name='" ).append( name ).append( '\'' );
|
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( '}' );
|
sb.append( '}' );
|
||||||
return sb.toString();
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,6 @@
|
||||||
package org.hibernate.metamodel.source.annotations.entity.state.binding;
|
package org.hibernate.metamodel.source.annotations.entity.state.binding;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Properties;
|
|
||||||
|
|
||||||
import org.hibernate.mapping.PropertyGeneration;
|
import org.hibernate.mapping.PropertyGeneration;
|
||||||
import org.hibernate.metamodel.binding.state.SimpleAttributeBindingState;
|
import org.hibernate.metamodel.binding.state.SimpleAttributeBindingState;
|
||||||
|
@ -40,13 +39,12 @@ public class AttributeBindingStateImpl implements SimpleAttributeBindingState {
|
||||||
private final MappedAttribute mappedAttribute;
|
private final MappedAttribute mappedAttribute;
|
||||||
private final PropertyGeneration propertyGeneration = null;
|
private final PropertyGeneration propertyGeneration = null;
|
||||||
private final String typeName;
|
private final String typeName;
|
||||||
private final Properties typeParameters;
|
private final Map<String, String> typeParameters;
|
||||||
|
|
||||||
public AttributeBindingStateImpl(MappedAttribute mappedAttribute) {
|
public AttributeBindingStateImpl(MappedAttribute mappedAttribute) {
|
||||||
this.mappedAttribute = mappedAttribute;
|
this.mappedAttribute = mappedAttribute;
|
||||||
typeName = mappedAttribute.getType().getName();
|
typeName = mappedAttribute.getType();
|
||||||
// TODO: implement....
|
typeParameters = mappedAttribute.getTypeParameters();
|
||||||
typeParameters = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -73,7 +71,7 @@ public class AttributeBindingStateImpl implements SimpleAttributeBindingState {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isUpdateable() {
|
public boolean isUpdatable() {
|
||||||
return false; //To change body of implemented methods use File | Settings | File Templates.
|
return false; //To change body of implemented methods use File | Settings | File Templates.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -93,7 +91,7 @@ public class AttributeBindingStateImpl implements SimpleAttributeBindingState {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Properties getTypeParameters() {
|
public Map<String, String> getTypeParameters() {
|
||||||
return typeParameters;
|
return typeParameters;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -155,13 +155,13 @@ public class AttributeColumnRelationalState implements ColumnRelationalState {
|
||||||
List<AnnotationInstance> allColumnTransformerAnnotations = new ArrayList<AnnotationInstance>();
|
List<AnnotationInstance> allColumnTransformerAnnotations = new ArrayList<AnnotationInstance>();
|
||||||
|
|
||||||
// not quite sure about the usefulness of @ColumnTransformers (HF)
|
// 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 ) {
|
if ( columnTransformersAnnotations != null ) {
|
||||||
AnnotationInstance[] annotationInstances = allColumnTransformerAnnotations.get( 0 ).value().asNestedArray();
|
AnnotationInstance[] annotationInstances = allColumnTransformerAnnotations.get( 0 ).value().asNestedArray();
|
||||||
allColumnTransformerAnnotations.addAll( Arrays.asList( annotationInstances ) );
|
allColumnTransformerAnnotations.addAll( Arrays.asList( annotationInstances ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
AnnotationInstance columnTransformerAnnotation = attribute.annotations( HibernateDotNames.COLUMN_TRANSFORMER );
|
AnnotationInstance columnTransformerAnnotation = attribute.getIfExists( HibernateDotNames.COLUMN_TRANSFORMER );
|
||||||
if ( columnTransformerAnnotation != null ) {
|
if ( columnTransformerAnnotation != null ) {
|
||||||
allColumnTransformerAnnotations.add( columnTransformerAnnotation );
|
allColumnTransformerAnnotations.add( columnTransformerAnnotation );
|
||||||
}
|
}
|
||||||
|
@ -196,7 +196,7 @@ public class AttributeColumnRelationalState implements ColumnRelationalState {
|
||||||
|
|
||||||
private String parseCheckAnnotation(MappedAttribute attribute) {
|
private String parseCheckAnnotation(MappedAttribute attribute) {
|
||||||
String checkCondition = null;
|
String checkCondition = null;
|
||||||
AnnotationInstance checkAnnotation = attribute.annotations( HibernateDotNames.CHECK );
|
AnnotationInstance checkAnnotation = attribute.getIfExists( HibernateDotNames.CHECK );
|
||||||
if ( checkAnnotation != null ) {
|
if ( checkAnnotation != null ) {
|
||||||
checkCondition = checkAnnotation.value( "constraints" ).toString();
|
checkCondition = checkAnnotation.value( "constraints" ).toString();
|
||||||
}
|
}
|
||||||
|
@ -205,7 +205,7 @@ public class AttributeColumnRelationalState implements ColumnRelationalState {
|
||||||
|
|
||||||
private Set<String> parseIndexAnnotation(MappedAttribute attribute) {
|
private Set<String> parseIndexAnnotation(MappedAttribute attribute) {
|
||||||
Set<String> indexNames = new HashSet<String>();
|
Set<String> indexNames = new HashSet<String>();
|
||||||
AnnotationInstance indexAnnotation = attribute.annotations( HibernateDotNames.INDEX );
|
AnnotationInstance indexAnnotation = attribute.getIfExists( HibernateDotNames.INDEX );
|
||||||
if ( indexAnnotation != null ) {
|
if ( indexAnnotation != null ) {
|
||||||
String indexName = indexAnnotation.value( "name" ).toString();
|
String indexName = indexAnnotation.value( "name" ).toString();
|
||||||
indexNames.add( indexName );
|
indexNames.add( indexName );
|
||||||
|
|
|
@ -112,7 +112,7 @@ public class HibernateMappingBinder implements MappingDefaults {
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
public String getDefaultDescriminatorColumnName() {
|
public String getDefaultDiscriminatorColumnName() {
|
||||||
return DEFAULT_DISCRIMINATOR_COLUMN_NAME;
|
return DEFAULT_DISCRIMINATOR_COLUMN_NAME;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,15 +24,14 @@
|
||||||
package org.hibernate.metamodel.source.hbm.state.binding;
|
package org.hibernate.metamodel.source.hbm.state.binding;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Properties;
|
|
||||||
|
|
||||||
import org.hibernate.MappingException;
|
import org.hibernate.MappingException;
|
||||||
import org.hibernate.internal.util.ReflectHelper;
|
import org.hibernate.internal.util.ReflectHelper;
|
||||||
import org.hibernate.mapping.PropertyGeneration;
|
import org.hibernate.mapping.PropertyGeneration;
|
||||||
import org.hibernate.metamodel.binding.MappingDefaults;
|
import org.hibernate.metamodel.binding.MappingDefaults;
|
||||||
|
import org.hibernate.metamodel.binding.state.AttributeBindingState;
|
||||||
import org.hibernate.metamodel.domain.MetaAttribute;
|
import org.hibernate.metamodel.domain.MetaAttribute;
|
||||||
import org.hibernate.metamodel.source.util.MappingHelper;
|
import org.hibernate.metamodel.source.util.MappingHelper;
|
||||||
import org.hibernate.metamodel.binding.state.AttributeBindingState;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Gail Badner
|
* @author Gail Badner
|
||||||
|
@ -63,7 +62,7 @@ public abstract class AbstractHbmAttributeBindingState implements AttributeBindi
|
||||||
this.ownerClassName = ownerClassName;
|
this.ownerClassName = ownerClassName;
|
||||||
this.attributeName = attributeName;
|
this.attributeName = attributeName;
|
||||||
this.defaults = defaults;
|
this.defaults = defaults;
|
||||||
this.nodeName = nodeName;
|
this.nodeName = nodeName;
|
||||||
this.metaAttributes = metaAttributes;
|
this.metaAttributes = metaAttributes;
|
||||||
this.accessorName = accessorName;
|
this.accessorName = accessorName;
|
||||||
this.isOptimisticLockable = isOptimisticLockable;
|
this.isOptimisticLockable = isOptimisticLockable;
|
||||||
|
@ -121,7 +120,7 @@ public abstract class AbstractHbmAttributeBindingState implements AttributeBindi
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Properties getTypeParameters() {
|
public Map<String, String> getTypeParameters() {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,8 +24,8 @@
|
||||||
package org.hibernate.metamodel.source.hbm.state.binding;
|
package org.hibernate.metamodel.source.hbm.state.binding;
|
||||||
|
|
||||||
import org.hibernate.metamodel.binding.MappingDefaults;
|
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.binding.state.DiscriminatorBindingState;
|
||||||
|
import org.hibernate.metamodel.source.hbm.xml.mapping.XMLHibernateMapping.XMLClass.XMLDiscriminator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Gail Badner
|
* @author Gail Badner
|
||||||
|
@ -41,7 +41,7 @@ public class HbmDiscriminatorBindingState extends AbstractHbmAttributeBindingSta
|
||||||
// Discriminator.getName() is not defined, so the attribute will always be
|
// Discriminator.getName() is not defined, so the attribute will always be
|
||||||
// defaults.getDefaultDescriminatorColumnName()
|
// defaults.getDefaultDescriminatorColumnName()
|
||||||
super(
|
super(
|
||||||
ownerClassName, defaults.getDefaultDescriminatorColumnName(), defaults, null, null, null, true
|
ownerClassName, defaults.getDefaultDiscriminatorColumnName(), defaults, null, null, null, true
|
||||||
);
|
);
|
||||||
this.discriminator = discriminator;
|
this.discriminator = discriminator;
|
||||||
}
|
}
|
||||||
|
@ -66,7 +66,7 @@ public class HbmDiscriminatorBindingState extends AbstractHbmAttributeBindingSta
|
||||||
return discriminator.isInsert();
|
return discriminator.isInsert();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isUpdateable() {
|
public boolean isUpdatable() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -160,7 +160,7 @@ public class HbmManyToOneAttributeBindingState
|
||||||
return isInsertable;
|
return isInsertable;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isUpdateable() {
|
public boolean isUpdatable() {
|
||||||
return isUpdateable;
|
return isUpdateable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,12 +23,13 @@
|
||||||
*/
|
*/
|
||||||
package org.hibernate.metamodel.source.hbm.state.binding;
|
package org.hibernate.metamodel.source.hbm.state.binding;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Properties;
|
|
||||||
|
|
||||||
import org.hibernate.MappingException;
|
import org.hibernate.MappingException;
|
||||||
import org.hibernate.mapping.PropertyGeneration;
|
import org.hibernate.mapping.PropertyGeneration;
|
||||||
import org.hibernate.metamodel.binding.MappingDefaults;
|
import org.hibernate.metamodel.binding.MappingDefaults;
|
||||||
|
import org.hibernate.metamodel.binding.state.SimpleAttributeBindingState;
|
||||||
import org.hibernate.metamodel.domain.MetaAttribute;
|
import org.hibernate.metamodel.domain.MetaAttribute;
|
||||||
import org.hibernate.metamodel.source.hbm.HbmHelper;
|
import org.hibernate.metamodel.source.hbm.HbmHelper;
|
||||||
import org.hibernate.metamodel.source.hbm.xml.mapping.XMLHibernateMapping.XMLClass.XMLId;
|
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.XMLParamElement;
|
||||||
import org.hibernate.metamodel.source.hbm.xml.mapping.XMLPropertyElement;
|
import org.hibernate.metamodel.source.hbm.xml.mapping.XMLPropertyElement;
|
||||||
import org.hibernate.metamodel.source.util.MappingHelper;
|
import org.hibernate.metamodel.source.util.MappingHelper;
|
||||||
import org.hibernate.metamodel.binding.state.SimpleAttributeBindingState;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Gail Badner
|
* @author Gail Badner
|
||||||
|
@ -45,12 +45,12 @@ import org.hibernate.metamodel.binding.state.SimpleAttributeBindingState;
|
||||||
public class HbmSimpleAttributeBindingState extends AbstractHbmAttributeBindingState
|
public class HbmSimpleAttributeBindingState extends AbstractHbmAttributeBindingState
|
||||||
implements SimpleAttributeBindingState {
|
implements SimpleAttributeBindingState {
|
||||||
private final String typeName;
|
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 boolean isLazy;
|
||||||
private final PropertyGeneration propertyGeneration;
|
private final PropertyGeneration propertyGeneration;
|
||||||
private final boolean isInsertable;
|
private final boolean isInsertable;
|
||||||
private final boolean isUpdateable;
|
private final boolean isUpdatable;
|
||||||
|
|
||||||
public HbmSimpleAttributeBindingState(
|
public HbmSimpleAttributeBindingState(
|
||||||
String ownerClassName,
|
String ownerClassName,
|
||||||
|
@ -69,7 +69,7 @@ public class HbmSimpleAttributeBindingState extends AbstractHbmAttributeBindingS
|
||||||
|
|
||||||
this.isLazy = false;
|
this.isLazy = false;
|
||||||
if ( id.getTypeAttribute() != null ) {
|
if ( id.getTypeAttribute() != null ) {
|
||||||
typeName = maybeConvertToTypeDefName( id.getTypeAttribute(), defaults );
|
typeName = maybeConvertToTypeDefName( id.getTypeAttribute(), defaults );
|
||||||
}
|
}
|
||||||
else if ( id.getType() != null ) {
|
else if ( id.getType() != null ) {
|
||||||
typeName = maybeConvertToTypeDefName( id.getType().getName(), defaults );
|
typeName = maybeConvertToTypeDefName( id.getType().getName(), defaults );
|
||||||
|
@ -82,7 +82,7 @@ public class HbmSimpleAttributeBindingState extends AbstractHbmAttributeBindingS
|
||||||
this.propertyGeneration = PropertyGeneration.parse( null );
|
this.propertyGeneration = PropertyGeneration.parse( null );
|
||||||
this.isInsertable = true;
|
this.isInsertable = true;
|
||||||
|
|
||||||
this.isUpdateable = false;
|
this.isUpdatable = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String maybeConvertToTypeDefName(String typeName, MappingDefaults defaults) {
|
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" );
|
throw new MappingException( "'generated' attribute cannot be 'insert' for versioning property" );
|
||||||
}
|
}
|
||||||
this.isInsertable = MappingHelper.getBooleanValue( version.isInsert(), true );
|
this.isInsertable = MappingHelper.getBooleanValue( version.isInsert(), true );
|
||||||
this.isUpdateable = true;
|
this.isUpdatable = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public HbmSimpleAttributeBindingState(
|
public HbmSimpleAttributeBindingState(
|
||||||
|
@ -152,7 +152,7 @@ public class HbmSimpleAttributeBindingState extends AbstractHbmAttributeBindingS
|
||||||
throw new MappingException( "'generated' attribute cannot be 'insert' for versioning property" );
|
throw new MappingException( "'generated' attribute cannot be 'insert' for versioning property" );
|
||||||
}
|
}
|
||||||
this.isInsertable = true; //TODO: is this right????
|
this.isInsertable = true; //TODO: is this right????
|
||||||
this.isUpdateable = true;
|
this.isUpdatable = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public HbmSimpleAttributeBindingState(
|
public HbmSimpleAttributeBindingState(
|
||||||
|
@ -197,10 +197,10 @@ public class HbmSimpleAttributeBindingState extends AbstractHbmAttributeBindingS
|
||||||
property.getName()
|
property.getName()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
isUpdateable = false;
|
isUpdatable = false;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
isUpdateable = MappingHelper.getBooleanValue( property.isUpdate(), true );
|
isUpdatable = MappingHelper.getBooleanValue( property.isUpdate(), true );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( property.getTypeAttribute() != null ) {
|
if ( property.getTypeAttribute() != null ) {
|
||||||
|
@ -241,7 +241,7 @@ public class HbmSimpleAttributeBindingState extends AbstractHbmAttributeBindingS
|
||||||
return typeName;
|
return typeName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Properties getTypeParameters() {
|
public Map<String, String> getTypeParameters() {
|
||||||
return typeParameters;
|
return typeParameters;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -257,8 +257,8 @@ public class HbmSimpleAttributeBindingState extends AbstractHbmAttributeBindingS
|
||||||
return isInsertable;
|
return isInsertable;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isUpdateable() {
|
public boolean isUpdatable() {
|
||||||
return isUpdateable;
|
return isUpdatable;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getCascade() {
|
public String getCascade() {
|
||||||
|
|
|
@ -134,8 +134,8 @@ public class MetadataImpl implements Metadata, MetadataImplementor, Serializable
|
||||||
index = ormParser.parseAndUpdateIndex( mappings, index );
|
index = ormParser.parseAndUpdateIndex( mappings, index );
|
||||||
|
|
||||||
// create the annotation binder and pass it the final annotation index
|
// create the annotation binder and pass it the final annotation index
|
||||||
final AnnotationBinder annotationBinder = new AnnotationBinder( this );
|
final AnnotationBinder annotationBinder = new AnnotationBinder( this, index );
|
||||||
annotationBinder.bind( index );
|
annotationBinder.bind();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -41,8 +41,6 @@ import org.junit.Test;
|
||||||
import org.hibernate.metamodel.source.annotations.entity.ConfiguredClass;
|
import org.hibernate.metamodel.source.annotations.entity.ConfiguredClass;
|
||||||
import org.hibernate.metamodel.source.annotations.entity.ConfiguredClassHierarchy;
|
import org.hibernate.metamodel.source.annotations.entity.ConfiguredClassHierarchy;
|
||||||
import org.hibernate.metamodel.source.annotations.entity.MappedAttribute;
|
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.ServiceRegistryBuilder;
|
||||||
import org.hibernate.service.classloading.spi.ClassLoaderService;
|
import org.hibernate.service.classloading.spi.ClassLoaderService;
|
||||||
import org.hibernate.service.internal.BasicServiceRegistryImpl;
|
import org.hibernate.service.internal.BasicServiceRegistryImpl;
|
||||||
|
@ -83,7 +81,7 @@ public class GenericTypeDiscoveryTest extends BaseUnitTestCase {
|
||||||
ClassInfo info = configuredClass.getClassInfo();
|
ClassInfo info = configuredClass.getClassInfo();
|
||||||
assertEquals( "wrong class", DotName.createSimple( Stuff.class.getName() ), info.name() );
|
assertEquals( "wrong class", DotName.createSimple( Stuff.class.getName() ), info.name() );
|
||||||
MappedAttribute property = configuredClass.getMappedProperty( "value" );
|
MappedAttribute property = configuredClass.getMappedProperty( "value" );
|
||||||
assertEquals( Price.class, property.getType() );
|
assertEquals( Price.class.getName(), property.getType() );
|
||||||
|
|
||||||
assertTrue( iter.hasNext() );
|
assertTrue( iter.hasNext() );
|
||||||
configuredClass = iter.next();
|
configuredClass = iter.next();
|
||||||
|
@ -99,9 +97,9 @@ public class GenericTypeDiscoveryTest extends BaseUnitTestCase {
|
||||||
assertEquals( "wrong class", DotName.createSimple( Item.class.getName() ), info.name() );
|
assertEquals( "wrong class", DotName.createSimple( Item.class.getName() ), info.name() );
|
||||||
// properties are alphabetically ordered!
|
// properties are alphabetically ordered!
|
||||||
property = configuredClass.getMappedProperty( "owner" );
|
property = configuredClass.getMappedProperty( "owner" );
|
||||||
assertEquals( SomeGuy.class, property.getType() );
|
assertEquals( SomeGuy.class.getName(), property.getType() );
|
||||||
property = configuredClass.getMappedProperty( "type" );
|
property = configuredClass.getMappedProperty( "type" );
|
||||||
assertEquals( PaperType.class, property.getType() );
|
assertEquals( PaperType.class.getName(), property.getType() );
|
||||||
|
|
||||||
assertTrue( iter.hasNext() );
|
assertTrue( iter.hasNext() );
|
||||||
configuredClass = iter.next();
|
configuredClass = iter.next();
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue