HHH-6171 Collecting information for relational state of attributes

This commit is contained in:
Hardy Ferentschik 2011-05-03 16:53:19 +02:00
parent 95802a0e93
commit d48010643b
10 changed files with 730 additions and 116 deletions

View File

@ -0,0 +1,217 @@
/*
* 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;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.jboss.jandex.AnnotationInstance;
import org.hibernate.AnnotationException;
import org.hibernate.AssertionFailure;
import org.hibernate.cfg.NamingStrategy;
import org.hibernate.metamodel.binding.SimpleAttributeBinding;
import org.hibernate.metamodel.relational.Size;
import org.hibernate.metamodel.source.internal.MetadataImpl;
/**
* @author Hardy Ferentschik
*/
public class AttributeColumnRelationalState implements SimpleAttributeBinding.ColumnRelationalState {
private final NamingStrategy namingStrategy;
private final String columnName;
private final boolean unique;
private final boolean nullable;
private final Size size;
private final String checkCondition;
private final String customWriteFragment;
private final String customReadFragment;
// todo - what about these annotations !?
private String defaultString;
private String sqlType;
private String comment;
private Set<String> uniqueKeys = new HashSet<String>();
private Set<String> indexes = new HashSet<String>();
AttributeColumnRelationalState(MappedAttribute attribute, MetadataImpl meta) {
ColumnValues columnValues = attribute.getColumnValues();
namingStrategy = meta.getNamingStrategy();
columnName = columnValues.getName().isEmpty() ? attribute.getName() : columnValues.getName();
unique = columnValues.isUnique();
nullable = columnValues.isNullable();
size = createSize( columnValues.getLength(), columnValues.getScale(), columnValues.getPrecision() );
List<AnnotationInstance> checkAnnotations = attribute.annotations( HibernateDotNames.CHECK );
if ( checkAnnotations.size() > 1 ) {
throw new AssertionFailure( "There cannot be more than one @Check annotation per mapped attribute" );
}
if ( checkAnnotations.size() == 1 ) {
checkCondition = checkAnnotations.get( 0 ).value( "constraints" ).toString();
}
else {
checkCondition = null;
}
String[] readWrite;
List<AnnotationInstance> columnTransformerAnnotations = getAllColumnTransformerAnnotations( attribute );
readWrite = createCustomReadWrite( columnTransformerAnnotations );
customReadFragment = readWrite[0];
customWriteFragment = readWrite[1];
}
@Override
public NamingStrategy getNamingStrategy() {
return namingStrategy;
}
@Override
public String getExplicitColumnName() {
return columnName;
}
@Override
public boolean isUnique() {
return unique;
}
@Override
public Size getSize() {
return size;
}
@Override
public boolean isNullable() {
return nullable;
}
@Override
public String getCheckCondition() {
return checkCondition;
}
@Override
public String getDefault() {
return defaultString;
}
@Override
public String getSqlType() {
return sqlType;
}
@Override
public String getCustomWriteFragment() {
return customWriteFragment;
}
@Override
public String getCustomReadFragment() {
return customReadFragment;
}
@Override
public String getComment() {
return comment;
}
@Override
public Set<String> getUniqueKeys() {
return uniqueKeys;
}
@Override
public Set<String> getIndexes() {
return indexes;
}
private Size createSize(int length, int scale, int precision) {
Size size = new Size();
size.setLength( length );
size.setScale( scale );
size.setPrecision( precision );
return size;
}
private List<AnnotationInstance> getAllColumnTransformerAnnotations(MappedAttribute attribute) {
List<AnnotationInstance> allColumnTransformerAnnotations = new ArrayList<AnnotationInstance>();
// not quite sure about the usefulness of @ColumnTransformers (HF)
List<AnnotationInstance> columnTransformersAnnotations = attribute.annotations( HibernateDotNames.COLUMN_TRANSFORMERS );
if ( columnTransformersAnnotations.size() > 1 ) {
throw new AssertionFailure(
"There cannot be more than one @ColumnTransformers annotation per mapped attribute"
);
}
if ( columnTransformersAnnotations.size() == 1 ) {
AnnotationInstance[] annotationInstances = allColumnTransformerAnnotations.get( 0 ).value().asNestedArray();
allColumnTransformerAnnotations.addAll( Arrays.asList( annotationInstances ) );
}
List<AnnotationInstance> columnTransformerAnnotations = attribute.annotations( HibernateDotNames.COLUMN_TRANSFORMER );
if ( columnTransformerAnnotations.size() > 1 ) {
throw new AssertionFailure(
"There cannot be more than one @ColumnTransformer annotation per mapped attribute"
);
}
if ( columnTransformerAnnotations.size() == 1 ) {
allColumnTransformerAnnotations.add( columnTransformerAnnotations.get( 0 ) );
}
return allColumnTransformerAnnotations;
}
private String[] createCustomReadWrite(List<AnnotationInstance> columnTransformerAnnotations) {
String[] readWrite = new String[2];
boolean alreadyProcessedForColumn = false;
for ( AnnotationInstance annotationInstance : columnTransformerAnnotations ) {
String forColumn = annotationInstance.value( "forColumn" ) == null ?
null : annotationInstance.value( "forColumn" ).asString();
if ( forColumn != null && !forColumn.equals( columnName ) ) {
continue;
}
if ( alreadyProcessedForColumn ) {
throw new AnnotationException( "Multiple definition of read/write conditions for column " + columnName );
}
readWrite[0] = annotationInstance.value( "read" ) == null ?
null : annotationInstance.value( "read" ).asString();
readWrite[1] = annotationInstance.value( "write" ) == null ?
null : annotationInstance.value( "write" ).asString();
alreadyProcessedForColumn = true;
}
return readWrite;
}
}

View File

@ -0,0 +1,170 @@
/*
* 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;
import org.jboss.jandex.AnnotationInstance;
import org.jboss.jandex.AnnotationValue;
import org.hibernate.AssertionFailure;
/**
* Container for the properties defined by {@code @Column}.
*
* @author Hardy Ferentschik
*/
public final class ColumnValues {
private String name = "";
private boolean unique = false;
private boolean nullable = true;
private boolean insertable = true;
private boolean updatable = true;
private String columnDefinition = "";
private String table = "";
private int length = 255;
private int precision = 0;
private int scale = 0;
public ColumnValues(AnnotationInstance columnAnnotation) {
if ( columnAnnotation != null && !JPADotNames.COLUMN.equals( columnAnnotation.name() ) ) {
throw new AssertionFailure( "A @Column annotation needs to be passed to the constructor" );
}
applyColumnValues( columnAnnotation );
}
private void applyColumnValues(AnnotationInstance columnAnnotation) {
if ( columnAnnotation == null ) {
return;
}
AnnotationValue nameValue = columnAnnotation.value( "name" );
if ( nameValue != null ) {
this.name = nameValue.asString();
}
AnnotationValue uniqueValue = columnAnnotation.value( "unique" );
if ( uniqueValue != null ) {
this.unique = nameValue.asBoolean();
}
AnnotationValue nullableValue = columnAnnotation.value( "nullable" );
if ( nullableValue != null ) {
this.nullable = nullableValue.asBoolean();
}
AnnotationValue insertableValue = columnAnnotation.value( "insertable" );
if ( insertableValue != null ) {
this.insertable = insertableValue.asBoolean();
}
AnnotationValue updatableValue = columnAnnotation.value( "updatable" );
if ( updatableValue != null ) {
this.updatable = updatableValue.asBoolean();
}
AnnotationValue columnDefinition = columnAnnotation.value( "columnDefinition" );
if ( columnDefinition != null ) {
this.columnDefinition = columnDefinition.asString();
}
AnnotationValue tableValue = columnAnnotation.value( "table" );
if ( tableValue != null ) {
this.table = tableValue.asString();
}
AnnotationValue lengthValue = columnAnnotation.value( "length" );
if ( lengthValue != null ) {
this.length = lengthValue.asInt();
}
AnnotationValue precisionValue = columnAnnotation.value( "precision" );
if ( precisionValue != null ) {
this.precision = precisionValue.asInt();
}
AnnotationValue scaleValue = columnAnnotation.value( "scale" );
if ( scaleValue != null ) {
this.scale = scaleValue.asInt();
}
}
public final String getName() {
return name;
}
public final boolean isUnique() {
return unique;
}
public final boolean isNullable() {
return nullable;
}
public final boolean isInsertable() {
return insertable;
}
public final boolean isUpdatable() {
return updatable;
}
public final String getColumnDefinition() {
return columnDefinition;
}
public final String getTable() {
return table;
}
public final int getLength() {
return length;
}
public final int getPrecision() {
return precision;
}
public final int getScale() {
return scale;
}
@Override
public String toString() {
final StringBuilder sb = new StringBuilder();
sb.append( "ColumnValues" );
sb.append( "{name='" ).append( name ).append( '\'' );
sb.append( ", unique=" ).append( unique );
sb.append( ", nullable=" ).append( nullable );
sb.append( ", insertable=" ).append( insertable );
sb.append( ", updatable=" ).append( updatable );
sb.append( ", columnDefinition='" ).append( columnDefinition ).append( '\'' );
sb.append( ", table='" ).append( table ).append( '\'' );
sb.append( ", length=" ).append( length );
sb.append( ", precision=" ).append( precision );
sb.append( ", scale=" ).append( scale );
sb.append( '}' );
return sb.toString();
}
}

View File

@ -96,12 +96,12 @@ public class ConfiguredClass {
this.clazz = serviceRegistry.getService( ClassLoaderService.class ).classForName( info.toString() );
AnnotationInstance mappedSuperClassAnnotation = JandexHelper.getSingleAnnotation(
classInfo, JPADotNames.MAPPED_SUPER_CLASS
classInfo, JPADotNames.MAPPED_SUPERCLASS
);
isMappedSuperClass = mappedSuperClassAnnotation != null;
AnnotationInstance embeddableAnnotation = JandexHelper.getSingleAnnotation(
classInfo, JPADotNames.MAPPED_SUPER_CLASS
classInfo, JPADotNames.MAPPED_SUPERCLASS
);
isEmbeddable = embeddableAnnotation != null;

View File

@ -26,17 +26,14 @@ package org.hibernate.metamodel.source.annotations;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.jboss.jandex.AnnotationInstance;
import org.jboss.jandex.AnnotationValue;
import org.hibernate.AssertionFailure;
import org.hibernate.MappingException;
import org.hibernate.cfg.NamingStrategy;
import org.hibernate.internal.util.StringHelper;
import org.hibernate.mapping.PropertyGeneration;
import org.hibernate.metamodel.binding.AbstractAttributeBinding;
import org.hibernate.metamodel.binding.AttributeBinding;
import org.hibernate.metamodel.binding.EntityBinding;
import org.hibernate.metamodel.binding.HibernateTypeDescriptor;
@ -46,7 +43,6 @@ import org.hibernate.metamodel.domain.Entity;
import org.hibernate.metamodel.domain.Hierarchical;
import org.hibernate.metamodel.relational.Identifier;
import org.hibernate.metamodel.relational.Schema;
import org.hibernate.metamodel.relational.Size;
import org.hibernate.metamodel.source.annotations.util.JandexHelper;
import org.hibernate.metamodel.source.internal.MetadataImpl;
@ -76,8 +72,8 @@ public class EntityBinder {
}
private Schema.Name createSchemaName() {
String schema = "";
String catalog = "";
String schema = null;
String catalog = null;
AnnotationInstance tableAnnotation = JandexHelper.getSingleAnnotation(
configuredClass.getClassInfo(), JPADotNames.TABLE
@ -86,8 +82,8 @@ public class EntityBinder {
AnnotationValue schemaValue = tableAnnotation.value( "schema" );
AnnotationValue catalogValue = tableAnnotation.value( "catalog" );
schema = schemaValue != null ? schemaValue.asString() : "";
catalog = catalogValue != null ? catalogValue.asString() : "";
schema = schemaValue != null ? schemaValue.asString() : null;
catalog = catalogValue != null ? catalogValue.asString() : null;
}
return new Schema.Name( schema, catalog );
@ -171,12 +167,7 @@ public class EntityBinder {
idBinding.initialize( domainState );
AnnotationColumnRelationalState columnRelationsState = new AnnotationColumnRelationalState();
columnRelationsState.namingStrategy = meta.getNamingStrategy();
columnRelationsState.columnName = idAttribute.getColumnName();
columnRelationsState.unique = true;
columnRelationsState.nullable = false;
AttributeColumnRelationalState columnRelationsState = new AttributeColumnRelationalState( idAttribute, meta );
AnnotationSimpleAttributeRelationalState relationalState = new AnnotationSimpleAttributeRelationalState();
relationalState.valueStates.add( columnRelationsState );
idBinding.initializeSimpleTupleValue( relationalState );
@ -358,80 +349,6 @@ public class EntityBinder {
return valueStates;
}
}
public static class AnnotationColumnRelationalState
implements SimpleAttributeBinding.ColumnRelationalState {
NamingStrategy namingStrategy;
String columnName;
boolean unique;
boolean nullable;
@Override
public NamingStrategy getNamingStrategy() {
return namingStrategy;
}
@Override
public String getExplicitColumnName() {
return columnName;
}
@Override
public boolean isUnique() {
return unique;
}
@Override
public Size getSize() {
return null; //To change body of implemented methods use File | Settings | File Templates.
}
@Override
public boolean isNullable() {
return nullable;
}
@Override
public String getCheckCondition() {
return null; //To change body of implemented methods use File | Settings | File Templates.
}
@Override
public String getDefault() {
return null; //To change body of implemented methods use File | Settings | File Templates.
}
@Override
public String getSqlType() {
return null; //To change body of implemented methods use File | Settings | File Templates.
}
@Override
public String getCustomWriteFragment() {
return null; //To change body of implemented methods use File | Settings | File Templates.
}
@Override
public String getCustomReadFragment() {
return null; //To change body of implemented methods use File | Settings | File Templates.
}
@Override
public String getComment() {
return null; //To change body of implemented methods use File | Settings | File Templates.
}
@Override
public Set<String> getUniqueKeys() {
return null; //To change body of implemented methods use File | Settings | File Templates.
}
@Override
public Set<String> getIndexes() {
return null; //To change body of implemented methods use File | Settings | File Templates.
}
}
}

View File

@ -25,25 +25,171 @@ package org.hibernate.metamodel.source.annotations;
import org.jboss.jandex.DotName;
import org.hibernate.annotations.AccessType;
import org.hibernate.annotations.Any;
import org.hibernate.annotations.AnyMetaDef;
import org.hibernate.annotations.AnyMetaDefs;
import org.hibernate.annotations.BatchSize;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.Check;
import org.hibernate.annotations.CollectionId;
import org.hibernate.annotations.CollectionOfElements;
import org.hibernate.annotations.ColumnTransformer;
import org.hibernate.annotations.ColumnTransformers;
import org.hibernate.annotations.Columns;
import org.hibernate.annotations.DiscriminatorFormula;
import org.hibernate.annotations.DiscriminatorOptions;
import org.hibernate.annotations.Entity;
import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchProfile;
import org.hibernate.annotations.FetchProfiles;
import org.hibernate.annotations.Filter;
import org.hibernate.annotations.FilterDef;
import org.hibernate.annotations.FilterDefs;
import org.hibernate.annotations.FilterJoinTable;
import org.hibernate.annotations.FilterJoinTables;
import org.hibernate.annotations.Filters;
import org.hibernate.annotations.ForceDiscriminator;
import org.hibernate.annotations.ForeignKey;
import org.hibernate.annotations.Formula;
import org.hibernate.annotations.Generated;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.GenericGenerators;
import org.hibernate.annotations.Immutable;
import org.hibernate.annotations.Index;
import org.hibernate.annotations.IndexColumn;
import org.hibernate.annotations.JoinColumnOrFormula;
import org.hibernate.annotations.JoinColumnsOrFormulas;
import org.hibernate.annotations.JoinFormula;
import org.hibernate.annotations.LazyCollection;
import org.hibernate.annotations.LazyToOne;
import org.hibernate.annotations.Loader;
import org.hibernate.annotations.ManyToAny;
import org.hibernate.annotations.MapKey;
import org.hibernate.annotations.MapKeyManyToMany;
import org.hibernate.annotations.MapKeyType;
import org.hibernate.annotations.MetaValue;
import org.hibernate.annotations.NamedNativeQueries;
import org.hibernate.annotations.NamedNativeQuery;
import org.hibernate.annotations.NamedQueries;
import org.hibernate.annotations.NamedQuery;
import org.hibernate.annotations.NaturalId;
import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.OnDelete;
import org.hibernate.annotations.OptimisticLock;
import org.hibernate.annotations.OrderBy;
import org.hibernate.annotations.ParamDef;
import org.hibernate.annotations.Parameter;
import org.hibernate.annotations.Parent;
import org.hibernate.annotations.Persister;
import org.hibernate.annotations.Proxy;
import org.hibernate.annotations.RowId;
import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.SQLDeleteAll;
import org.hibernate.annotations.SQLInsert;
import org.hibernate.annotations.SQLUpdate;
import org.hibernate.annotations.Sort;
import org.hibernate.annotations.Source;
import org.hibernate.annotations.Subselect;
import org.hibernate.annotations.Synchronize;
import org.hibernate.annotations.Table;
import org.hibernate.annotations.Tables;
import org.hibernate.annotations.Target;
import org.hibernate.annotations.Tuplizer;
import org.hibernate.annotations.Tuplizers;
import org.hibernate.annotations.Type;
import org.hibernate.annotations.TypeDef;
import org.hibernate.annotations.TypeDefs;
import org.hibernate.annotations.Where;
import org.hibernate.annotations.WhereJoinTable;
/**
* Defines the dot names for the Hibernate specific annotations.
* Defines the dot names for the Hibernate specific mapping annotations.
*
* @author Hardy Ferentschik
*/
public interface HibernateDotNames {
public static final DotName ENTITY = DotName.createSimple( Entity.class.getName() );
public static final DotName TABLE = DotName.createSimple( Table.class.getName() );
public static final DotName FETCH_PROFILES = DotName.createSimple( FetchProfiles.class.getName() );
public static final DotName FETCH_PROFILE = DotName.createSimple( FetchProfile.class.getName() );
public static final DotName ACCESS_TYPE = DotName.createSimple( AccessType.class.getName() );
public static final DotName ANY = DotName.createSimple( Any.class.getName() );
public static final DotName ANY_META_DEF = DotName.createSimple( AnyMetaDef.class.getName() );
public static final DotName ANY_META_DEFS = DotName.createSimple( AnyMetaDefs.class.getName() );
public static final DotName BATCH_SIZE = DotName.createSimple( BatchSize.class.getName() );
public static final DotName CACHE = DotName.createSimple( Cache.class.getName() );
public static final DotName CASCADE = DotName.createSimple( Cascade.class.getName() );
public static final DotName CHECK = DotName.createSimple( Check.class.getName() );
public static final DotName COLLECTION_ID = DotName.createSimple( CollectionId.class.getName() );
public static final DotName COLLECTION_OF_ELEMENTS = DotName.createSimple( CollectionOfElements.class.getName() );
public static final DotName COLUMNS = DotName.createSimple( Columns.class.getName() );
public static final DotName COLUMN_TRANSFORMER = DotName.createSimple( ColumnTransformer.class.getName() );
public static final DotName COLUMN_TRANSFORMERS = DotName.createSimple( ColumnTransformers.class.getName() );
public static final DotName DISCRIMINATOR_FORMULA = DotName.createSimple( DiscriminatorFormula.class.getName() );
public static final DotName DISCRIMINATOR_OPTIONS = DotName.createSimple( DiscriminatorOptions.class.getName() );
public static final DotName ENTITY = DotName.createSimple( Entity.class.getName() );
public static final DotName FETCH = DotName.createSimple( Fetch.class.getName() );
public static final DotName FETCH_PROFILE = DotName.createSimple( FetchProfile.class.getName() );
public static final DotName FETCH_PROFILES = DotName.createSimple( FetchProfiles.class.getName() );
public static final DotName FILTER = DotName.createSimple( Filter.class.getName() );
public static final DotName FILTER_DEF = DotName.createSimple( FilterDef.class.getName() );
public static final DotName FILTER_DEFS = DotName.createSimple( FilterDefs.class.getName() );
public static final DotName FILTER_JOIN_TABLE = DotName.createSimple( FilterJoinTable.class.getName() );
public static final DotName FILTER_JOIN_TABLES = DotName.createSimple( FilterJoinTables.class.getName() );
public static final DotName FILTERS = DotName.createSimple( Filters.class.getName() );
public static final DotName FORCE_DISCRIMINATOR = DotName.createSimple( ForceDiscriminator.class.getName() );
public static final DotName FOREIGN_KEY = DotName.createSimple( ForeignKey.class.getName() );
public static final DotName FORMULA = DotName.createSimple( Formula.class.getName() );
public static final DotName GENERATED = DotName.createSimple( Generated.class.getName() );
public static final DotName GENERIC_GENERATOR = DotName.createSimple( GenericGenerator.class.getName() );
public static final DotName GENERIC_GENERATORS = DotName.createSimple( GenericGenerators.class.getName() );
public static final DotName IMMUTABLE = DotName.createSimple( Immutable.class.getName() );
public static final DotName INDEX = DotName.createSimple( Index.class.getName() );
public static final DotName INDEX_COLUMN = DotName.createSimple( IndexColumn.class.getName() );
public static final DotName JOIN_COLUMN_OR_FORMULA = DotName.createSimple( JoinColumnOrFormula.class.getName() );
public static final DotName JOIN_COLUMNS_OR_FORMULAS = DotName.createSimple( JoinColumnsOrFormulas.class.getName() );
public static final DotName JOIN_FORMULA = DotName.createSimple( JoinFormula.class.getName() );
public static final DotName LAZY_COLLECTION = DotName.createSimple( LazyCollection.class.getName() );
public static final DotName LAZY_TO_ONE = DotName.createSimple( LazyToOne.class.getName() );
public static final DotName LOADER = DotName.createSimple( Loader.class.getName() );
public static final DotName MANY_TO_ANY = DotName.createSimple( ManyToAny.class.getName() );
public static final DotName MAP_KEY = DotName.createSimple( MapKey.class.getName() );
public static final DotName MAP_KEY_MANY_TO_MANY = DotName.createSimple( MapKeyManyToMany.class.getName() );
public static final DotName MAP_KEY_TYPE = DotName.createSimple( MapKeyType.class.getName() );
public static final DotName META_VALUE = DotName.createSimple( MetaValue.class.getName() );
public static final DotName NAMED_NATIVE_QUERIES = DotName.createSimple( NamedNativeQueries.class.getName() );
public static final DotName NAMED_NATIVE_QUERY = DotName.createSimple( NamedNativeQuery.class.getName() );
public static final DotName NAMED_QUERIES = DotName.createSimple( NamedQueries.class.getName() );
public static final DotName NAMED_QUERY = DotName.createSimple( NamedQuery.class.getName() );
public static final DotName NATURAL_ID = DotName.createSimple( NaturalId.class.getName() );
public static final DotName NOT_FOUND = DotName.createSimple( NotFound.class.getName() );
public static final DotName ON_DELETE = DotName.createSimple( OnDelete.class.getName() );
public static final DotName OPTIMISTIC_LOCK = DotName.createSimple( OptimisticLock.class.getName() );
public static final DotName ORDER_BY = DotName.createSimple( OrderBy.class.getName() );
public static final DotName PARAM_DEF = DotName.createSimple( ParamDef.class.getName() );
public static final DotName PARAMETER = DotName.createSimple( Parameter.class.getName() );
public static final DotName PARENT = DotName.createSimple( Parent.class.getName() );
public static final DotName PERSISTER = DotName.createSimple( Persister.class.getName() );
public static final DotName PROXY = DotName.createSimple( Proxy.class.getName() );
public static final DotName ROW_ID = DotName.createSimple( RowId.class.getName() );
public static final DotName SORT = DotName.createSimple( Sort.class.getName() );
public static final DotName SOURCE = DotName.createSimple( Source.class.getName() );
public static final DotName SQL_DELETE = DotName.createSimple( SQLDelete.class.getName() );
public static final DotName SQL_DELETE_ALL = DotName.createSimple( SQLDeleteAll.class.getName() );
public static final DotName SQL_INSERT = DotName.createSimple( SQLInsert.class.getName() );
public static final DotName SQL_UPDATE = DotName.createSimple( SQLUpdate.class.getName() );
public static final DotName SUB_SELECT = DotName.createSimple( Subselect.class.getName() );
public static final DotName SYNCHRONIZE = DotName.createSimple( Synchronize.class.getName() );
public static final DotName TABLE = DotName.createSimple( Table.class.getName() );
public static final DotName TABLES = DotName.createSimple( Tables.class.getName() );
public static final DotName TARGET = DotName.createSimple( Target.class.getName() );
public static final DotName TUPLIZER = DotName.createSimple( Tuplizer.class.getName() );
public static final DotName TUPLIZERS = DotName.createSimple( Tuplizers.class.getName() );
public static final DotName TYPE = DotName.createSimple( Type.class.getName() );
public static final DotName TYPE_DEF = DotName.createSimple( TypeDef.class.getName() );
public static final DotName TYPE_DEFS = DotName.createSimple( TypeDefs.class.getName() );
public static final DotName WHERE = DotName.createSimple( Where.class.getName() );
public static final DotName WHERE_JOIN_TABLE = DotName.createSimple( WhereJoinTable.class.getName() );
}

View File

@ -24,14 +24,81 @@
package org.hibernate.metamodel.source.annotations;
import javax.persistence.Access;
import javax.persistence.AssociationOverride;
import javax.persistence.AssociationOverrides;
import javax.persistence.AttributeOverride;
import javax.persistence.AttributeOverrides;
import javax.persistence.Basic;
import javax.persistence.Cacheable;
import javax.persistence.CollectionTable;
import javax.persistence.Column;
import javax.persistence.ColumnResult;
import javax.persistence.DiscriminatorColumn;
import javax.persistence.DiscriminatorValue;
import javax.persistence.ElementCollection;
import javax.persistence.Embeddable;
import javax.persistence.Embedded;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.EntityListeners;
import javax.persistence.EntityResult;
import javax.persistence.Enumerated;
import javax.persistence.ExcludeDefaultListeners;
import javax.persistence.ExcludeSuperclassListeners;
import javax.persistence.FieldResult;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.IdClass;
import javax.persistence.Inheritance;
import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns;
import javax.persistence.JoinTable;
import javax.persistence.Lob;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.MapKey;
import javax.persistence.MapKeyClass;
import javax.persistence.MapKeyColumn;
import javax.persistence.MapKeyEnumerated;
import javax.persistence.MapKeyJoinColumn;
import javax.persistence.MapKeyJoinColumns;
import javax.persistence.MapKeyTemporal;
import javax.persistence.MappedSuperclass;
import javax.persistence.MapsId;
import javax.persistence.NamedNativeQueries;
import javax.persistence.NamedNativeQuery;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.OrderBy;
import javax.persistence.OrderColumn;
import javax.persistence.PersistenceContext;
import javax.persistence.PersistenceContexts;
import javax.persistence.PersistenceProperty;
import javax.persistence.PersistenceUnit;
import javax.persistence.PersistenceUnits;
import javax.persistence.PostLoad;
import javax.persistence.PostPersist;
import javax.persistence.PostRemove;
import javax.persistence.PostUpdate;
import javax.persistence.PrePersist;
import javax.persistence.PreRemove;
import javax.persistence.PreUpdate;
import javax.persistence.PrimaryKeyJoinColumn;
import javax.persistence.PrimaryKeyJoinColumns;
import javax.persistence.QueryHint;
import javax.persistence.SecondaryTable;
import javax.persistence.SecondaryTables;
import javax.persistence.SequenceGenerator;
import javax.persistence.SqlResultSetMapping;
import javax.persistence.SqlResultSetMappings;
import javax.persistence.Table;
import javax.persistence.TableGenerator;
import javax.persistence.Temporal;
import javax.persistence.Transient;
import javax.persistence.UniqueConstraint;
import javax.persistence.Version;
import org.jboss.jandex.DotName;
@ -41,18 +108,82 @@ import org.jboss.jandex.DotName;
* @author Hardy Ferentschik
*/
public interface JPADotNames {
public static final DotName ENTITY = DotName.createSimple( Entity.class.getName() );
public static final DotName MAPPED_SUPER_CLASS = DotName.createSimple( MappedSuperclass.class.getName() );
public static final DotName EMBEDDABLE = DotName.createSimple( Embeddable.class.getName() );
public static final DotName INHERITANCE = DotName.createSimple( Inheritance.class.getName() );
public static final DotName ID = DotName.createSimple( Id.class.getName() );
public static final DotName EMBEDDED_ID = DotName.createSimple( EmbeddedId.class.getName() );
public static final DotName ACCESS = DotName.createSimple( Access.class.getName() );
public static final DotName TRANSIENT = DotName.createSimple( Transient.class.getName() );
public static final DotName ASSOCIATION_OVERRIDE = DotName.createSimple( AssociationOverride.class.getName() );
public static final DotName ASSOCIATION_OVERRIDES = DotName.createSimple( AssociationOverrides.class.getName() );
public static final DotName ATTRIBUTE_OVERRIDE = DotName.createSimple( AttributeOverride.class.getName() );
public static final DotName ATTRIBUTE_OVERRIDES = DotName.createSimple( AttributeOverrides.class.getName() );
public static final DotName BASIC = DotName.createSimple( Basic.class.getName() );
public static final DotName CACHEABLE = DotName.createSimple( Cacheable.class.getName() );
public static final DotName COLLECTION_TABLE = DotName.createSimple( CollectionTable.class.getName() );
public static final DotName COLUMN = DotName.createSimple( Column.class.getName() );
public static final DotName COLUMN_RESULT = DotName.createSimple( ColumnResult.class.getName() );
public static final DotName DISCRIMINATOR_COLUMN = DotName.createSimple( DiscriminatorColumn.class.getName() );
public static final DotName DISCRIMINATOR_VALUE = DotName.createSimple( DiscriminatorValue.class.getName() );
public static final DotName ELEMENT_COLLECTION = DotName.createSimple( ElementCollection.class.getName() );
public static final DotName EMBEDDABLE = DotName.createSimple( Embeddable.class.getName() );
public static final DotName EMBEDDED = DotName.createSimple( Embedded.class.getName() );
public static final DotName EMBEDDED_ID = DotName.createSimple( EmbeddedId.class.getName() );
public static final DotName ENTITY = DotName.createSimple( Entity.class.getName() );
public static final DotName ENTITY_LISTENERS = DotName.createSimple( EntityListeners.class.getName() );
public static final DotName ENTITY_RESULT = DotName.createSimple( EntityResult.class.getName() );
public static final DotName ENUMERATED = DotName.createSimple( Enumerated.class.getName() );
public static final DotName EXCLUDE_DEFAULT_LISTENERS = DotName.createSimple( ExcludeDefaultListeners.class.getName() );
public static final DotName EXCLUDE_SUPERCLASS_LISTENERS = DotName.createSimple( ExcludeSuperclassListeners.class.getName() );
public static final DotName FIELD_RESULT = DotName.createSimple( FieldResult.class.getName() );
public static final DotName GENERATED_VALUE = DotName.createSimple( GeneratedValue.class.getName() );
public static final DotName ID = DotName.createSimple( Id.class.getName() );
public static final DotName ID_CLASS = DotName.createSimple( IdClass.class.getName() );
public static final DotName JOIN_COLUMN = DotName.createSimple( JoinColumn.class.getName() );
public static final DotName INHERITANCE = DotName.createSimple( Inheritance.class.getName() );
public static final DotName JOIN_COLUMNS = DotName.createSimple( JoinColumns.class.getName() );
public static final DotName JOIN_TABLE = DotName.createSimple( JoinTable.class.getName() );
public static final DotName LOB = DotName.createSimple( Lob.class.getName() );
public static final DotName MANY_TO_MANY = DotName.createSimple( ManyToMany.class.getName() );
public static final DotName MANY_TO_ONE = DotName.createSimple( ManyToOne.class.getName() );
public static final DotName MAP_KEY = DotName.createSimple( MapKey.class.getName() );
public static final DotName MAP_KEY_CLASS = DotName.createSimple( MapKeyClass.class.getName() );
public static final DotName MAP_KEY_COLUMN = DotName.createSimple( MapKeyColumn.class.getName() );
public static final DotName MAP_KEY_ENUMERATED = DotName.createSimple( MapKeyEnumerated.class.getName() );
public static final DotName MAP_KEY_JOIN_COLUMN = DotName.createSimple( MapKeyJoinColumn.class.getName() );
public static final DotName MAP_KEY_JOIN_COLUMNS = DotName.createSimple( MapKeyJoinColumns.class.getName() );
public static final DotName MAP_KEY_TEMPORAL = DotName.createSimple( MapKeyTemporal.class.getName() );
public static final DotName MAPPED_SUPERCLASS = DotName.createSimple( MappedSuperclass.class.getName() );
public static final DotName MAPS_ID = DotName.createSimple( MapsId.class.getName() );
public static final DotName NAMED_NATIVE_QUERIES = DotName.createSimple( NamedNativeQueries.class.getName() );
public static final DotName NAMED_NATIVE_QUERY = DotName.createSimple( NamedNativeQuery.class.getName() );
public static final DotName NAMED_QUERIES = DotName.createSimple( NamedQueries.class.getName() );
public static final DotName NAMED_QUERY = DotName.createSimple( NamedQuery.class.getName() );
public static final DotName ONE_TO_MANY = DotName.createSimple( OneToMany.class.getName() );
public static final DotName ONE_TO_ONE = DotName.createSimple( OneToOne.class.getName() );
public static final DotName ORDER_BY = DotName.createSimple( OrderBy.class.getName() );
public static final DotName ORDER_COLUMN = DotName.createSimple( OrderColumn.class.getName() );
public static final DotName PERSISTENCE_CONTEXT = DotName.createSimple( PersistenceContext.class.getName() );
public static final DotName PERSISTENCE_CONTEXTS = DotName.createSimple( PersistenceContexts.class.getName() );
public static final DotName PERSISTENCE_PROPERTY = DotName.createSimple( PersistenceProperty.class.getName() );
public static final DotName PERSISTENCE_UNIT = DotName.createSimple( PersistenceUnit.class.getName() );
public static final DotName PERSISTENCE_UNITS = DotName.createSimple( PersistenceUnits.class.getName() );
public static final DotName POST_LOAD = DotName.createSimple( PostLoad.class.getName() );
public static final DotName POST_PERSIST = DotName.createSimple( PostPersist.class.getName() );
public static final DotName POST_REMOVE = DotName.createSimple( PostRemove.class.getName() );
public static final DotName POST_UPDATE = DotName.createSimple( PostUpdate.class.getName() );
public static final DotName PRE_PERSIST = DotName.createSimple( PrePersist.class.getName() );
public static final DotName PRE_REMOVE = DotName.createSimple( PreRemove.class.getName() );
public static final DotName PRE_UPDATE = DotName.createSimple( PreUpdate.class.getName() );
public static final DotName PRIMARY_KEY_JOIN_COLUMN = DotName.createSimple( PrimaryKeyJoinColumn.class.getName() );
public static final DotName PRIMARY_KEY_JOIN_COLUMNS = DotName.createSimple( PrimaryKeyJoinColumns.class.getName() );
public static final DotName QUERY_HINT = DotName.createSimple( QueryHint.class.getName() );
public static final DotName SECONDARY_TABLE = DotName.createSimple( SecondaryTable.class.getName() );
public static final DotName SECONDARY_TABLES = DotName.createSimple( SecondaryTables.class.getName() );
public static final DotName SEQUENCE_GENERATOR = DotName.createSimple( SequenceGenerator.class.getName() );
public static final DotName SQL_RESULT_SET_MAPPING = DotName.createSimple( SqlResultSetMapping.class.getName() );
public static final DotName SQL_RESULT_SET_MAPPINGS = DotName.createSimple( SqlResultSetMappings.class.getName() );
public static final DotName TABLE = DotName.createSimple( Table.class.getName() );
public static final DotName TABLE_GENERATOR = DotName.createSimple( TableGenerator.class.getName() );
public static final DotName TEMPORAL = DotName.createSimple( Temporal.class.getName() );
public static final DotName TRANSIENT = DotName.createSimple( Transient.class.getName() );
public static final DotName UNIQUE_CONSTRAINT = DotName.createSimple( UniqueConstraint.class.getName() );
public static final DotName VERSION = DotName.createSimple( Version.class.getName() );
}

View File

@ -30,6 +30,8 @@ import java.util.Map;
import org.jboss.jandex.AnnotationInstance;
import org.jboss.jandex.DotName;
import org.hibernate.AssertionFailure;
/**
* Represent a mapped attribute (explicitly or implicitly mapped).
*
@ -39,25 +41,33 @@ public class MappedAttribute implements Comparable<MappedAttribute> {
private final String name;
private final Class<?> type;
private final Map<DotName, List<AnnotationInstance>> annotations;
private final ColumnValues columnValues;
MappedAttribute(String name, Class<?> type, Map<DotName, List<AnnotationInstance>> annotations) {
this.name = name;
this.type = type;
this.annotations = annotations;
List<AnnotationInstance> columnAnnotations = annotations.get( JPADotNames.COLUMN );
if ( columnAnnotations != null && columnAnnotations.size() > 1 ) {
throw new AssertionFailure( "There can only be one @Column annotation per mapped attribute" );
}
AnnotationInstance columnAnnotation = columnAnnotations == null ? null : columnAnnotations.get( 0 );
columnValues = new ColumnValues( columnAnnotation );
}
final public String getName() {
public final String getName() {
return name;
}
final public String getColumnName() {
return name;
}
final public Class<?> getType() {
public final Class<?> getType() {
return type;
}
public final ColumnValues getColumnValues() {
return columnValues;
}
public final List<AnnotationInstance> annotations(DotName annotationDotName) {
if ( annotations.containsKey( annotationDotName ) ) {
return annotations.get( annotationDotName );

View File

@ -110,7 +110,7 @@ public class ConfiguredClassHierarchyBuilder {
boolean isConfiguredClass = true;
AnnotationInstance jpaEntityAnnotation = JandexHelper.getSingleAnnotation( info, JPADotNames.ENTITY );
AnnotationInstance mappedSuperClassAnnotation = JandexHelper.getSingleAnnotation(
info, JPADotNames.MAPPED_SUPER_CLASS
info, JPADotNames.MAPPED_SUPERCLASS
);
AnnotationInstance embeddableAnnotation = JandexHelper.getSingleAnnotation(
info, JPADotNames.EMBEDDABLE

View File

@ -38,7 +38,7 @@ import org.hibernate.testing.FailureExpected;
*/
public class BasicAnnotationBindingTests extends AbstractBasicBindingTests {
//@FailureExpected(jiraKey = "HHH-5672", message = "Work in progress")
@FailureExpected(jiraKey = "HHH-5672", message = "Work in progress")
@Test
public void testSimpleEntityMapping() {
super.testSimpleEntityMapping();
@ -76,6 +76,6 @@ public class BasicAnnotationBindingTests extends AbstractBasicBindingTests {
MetadataSources sources = new MetadataSources( new ServiceRegistryBuilder().buildServiceRegistry() );
sources.addAnnotatedClass( EntityWithManyToOne.class );
sources.addAnnotatedClass( SimpleVersionedEntity.class );
return ( MetadataImplementor ) sources.buildMetadata();
return (MetadataImplementor) sources.buildMetadata();
}
}

View File

@ -1,3 +1,26 @@
/*
* 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.List;