mirror of
https://github.com/hibernate/hibernate-orm
synced 2025-02-09 04:34:49 +00:00
HHH-6447 - Develop shared binding creation approach
This commit is contained in:
parent
acc93a3d8c
commit
2abfe3de23
@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* Hibernate, Relational Persistence for Idiomatic Java
|
* Hibernate, Relational Persistence for Idiomatic Java
|
||||||
*
|
*
|
||||||
* Copyright (c) 2010, Red Hat Inc. or third-party contributors as
|
* Copyright (c) 2011, Red Hat Inc. or third-party contributors as
|
||||||
* indicated by the @author tags or express copyright attribution
|
* indicated by the @author tags or express copyright attribution
|
||||||
* statements applied by the authors. All third-party contributions are
|
* statements applied by the authors. All third-party contributions are
|
||||||
* distributed under license by Red Hat Inc.
|
* distributed under license by Red Hat Inc.
|
||||||
@ -26,13 +26,14 @@
|
|||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
import org.hibernate.MappingException;
|
import org.hibernate.MappingException;
|
||||||
import org.hibernate.cfg.AvailableSettings;
|
|
||||||
import org.hibernate.id.IdentifierGenerator;
|
import org.hibernate.id.IdentifierGenerator;
|
||||||
import org.hibernate.id.PersistentIdentifierGenerator;
|
import org.hibernate.id.PersistentIdentifierGenerator;
|
||||||
import org.hibernate.id.factory.IdentifierGeneratorFactory;
|
import org.hibernate.id.factory.IdentifierGeneratorFactory;
|
||||||
import org.hibernate.mapping.PropertyGeneration;
|
import org.hibernate.mapping.PropertyGeneration;
|
||||||
import org.hibernate.metamodel.domain.SingularAttribute;
|
import org.hibernate.metamodel.domain.SingularAttribute;
|
||||||
import org.hibernate.metamodel.relational.state.ColumnRelationalState;
|
import org.hibernate.metamodel.relational.Column;
|
||||||
|
import org.hibernate.metamodel.relational.Schema;
|
||||||
|
import org.hibernate.metamodel.relational.SimpleValue;
|
||||||
import org.hibernate.metamodel.source.MetaAttributeContext;
|
import org.hibernate.metamodel.source.MetaAttributeContext;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -154,10 +155,10 @@ IdentifierGenerator createIdentifierGenerator(
|
|||||||
params.setProperty( PersistentIdentifierGenerator.TABLE, tableName );
|
params.setProperty( PersistentIdentifierGenerator.TABLE, tableName );
|
||||||
|
|
||||||
//pass the column name (a generated id almost always has a single column)
|
//pass the column name (a generated id almost always has a single column)
|
||||||
if ( getValuesSpan() != 1 ) {
|
if ( getSimpleValueSpan() > 1 ) {
|
||||||
throw new MappingException( "A SimpleAttributeBinding has a more than 1 Value: " + getAttribute().getName() );
|
throw new MappingException( "A SimpleAttributeBinding used for an identifier has a more than 1 Value: " + getAttribute().getName() );
|
||||||
}
|
}
|
||||||
SimpleValue simpleValue = getValues().iterator().next();
|
SimpleValue simpleValue = (SimpleValue) getValue();
|
||||||
if ( ! Column.class.isInstance( simpleValue ) ) {
|
if ( ! Column.class.isInstance( simpleValue ) ) {
|
||||||
throw new MappingException(
|
throw new MappingException(
|
||||||
"Cannot create an IdentifierGenerator because the value is not a column: " +
|
"Cannot create an IdentifierGenerator because the value is not a column: " +
|
||||||
|
@ -969,30 +969,38 @@ public AbstractEntityPersister(
|
|||||||
|
|
||||||
// TODO: fix this when EntityBinding.getSubclassAttributeBindingClosure() is working
|
// TODO: fix this when EntityBinding.getSubclassAttributeBindingClosure() is working
|
||||||
// for ( AttributeBinding prop : entityBinding.getSubclassAttributeBindingClosure() ) {
|
// for ( AttributeBinding prop : entityBinding.getSubclassAttributeBindingClosure() ) {
|
||||||
for ( AttributeBinding prop : entityBinding.getAttributeBindingClosure() ) {
|
for ( AttributeBinding attributeBinding : entityBinding.getAttributeBindingClosure() ) {
|
||||||
if ( prop == entityBinding.getEntityIdentifier().getValueBinding() ) {
|
if ( attributeBinding == entityBinding.getEntityIdentifier().getValueBinding() ) {
|
||||||
// entity identifier is not considered a "normal" property
|
// entity identifier is not considered a "normal" property
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
names.add( prop.getAttribute().getName() );
|
if ( ! attributeBinding.getAttribute().isSingular() ) {
|
||||||
classes.add( prop.getEntityBinding().getEntity().getName() );
|
// collections handled separately
|
||||||
boolean isDefinedBySubclass = ! thisClassProperties.contains( prop );
|
continue;
|
||||||
definedBySubclass.add( isDefinedBySubclass );
|
}
|
||||||
propNullables.add( prop.isNullable() || isDefinedBySubclass ); //TODO: is this completely correct?
|
|
||||||
types.add( prop.getHibernateTypeDescriptor().getResolvedTypeMapping() );
|
|
||||||
|
|
||||||
String[] cols = new String[ prop.getValuesSpan() ];
|
final SingularAttributeBinding singularAttributeBinding = (SingularAttributeBinding) attributeBinding;
|
||||||
String[] readers = new String[ prop.getValuesSpan() ];
|
|
||||||
String[] readerTemplates = new String[ prop.getValuesSpan() ];
|
names.add( singularAttributeBinding.getAttribute().getName() );
|
||||||
String[] forms = new String[ prop.getValuesSpan() ];
|
classes.add( singularAttributeBinding.getEntityBinding().getEntity().getName() );
|
||||||
int[] colnos = new int[ prop.getValuesSpan() ];
|
boolean isDefinedBySubclass = ! thisClassProperties.contains( singularAttributeBinding );
|
||||||
int[] formnos = new int[ prop.getValuesSpan() ];
|
definedBySubclass.add( isDefinedBySubclass );
|
||||||
|
propNullables.add( singularAttributeBinding.isNullable() || isDefinedBySubclass ); //TODO: is this completely correct?
|
||||||
|
types.add( singularAttributeBinding.getHibernateTypeDescriptor().getResolvedTypeMapping() );
|
||||||
|
|
||||||
|
final int span = singularAttributeBinding.getSimpleValueSpan();
|
||||||
|
String[] cols = new String[ span ];
|
||||||
|
String[] readers = new String[ span ];
|
||||||
|
String[] readerTemplates = new String[ span ];
|
||||||
|
String[] forms = new String[ span ];
|
||||||
|
int[] colnos = new int[ span ];
|
||||||
|
int[] formnos = new int[ span ];
|
||||||
int l = 0;
|
int l = 0;
|
||||||
Boolean lazy = prop.isLazy() && lazyAvailable;
|
Boolean lazy = singularAttributeBinding.isLazy() && lazyAvailable;
|
||||||
for ( SimpleValue thing : prop.getValues() ) {
|
for ( SimpleValueBinding valueBinding : singularAttributeBinding.getSimpleValueBindings() ) {
|
||||||
if ( DerivedValue.class.isInstance( thing ) ) {
|
if ( valueBinding.isDerived() ) {
|
||||||
DerivedValue derivedValue = DerivedValue.class.cast( thing );
|
DerivedValue derivedValue = DerivedValue.class.cast( valueBinding.getSimpleValue() );
|
||||||
String template = getTemplateFromString( derivedValue.getExpression(), factory );
|
String template = getTemplateFromString( derivedValue.getExpression(), factory );
|
||||||
formnos[l] = formulaTemplates.size();
|
formnos[l] = formulaTemplates.size();
|
||||||
colnos[l] = -1;
|
colnos[l] = -1;
|
||||||
@ -1002,17 +1010,17 @@ public AbstractEntityPersister(
|
|||||||
formulaAliases.add( derivedValue.getAlias( factory.getDialect() ) );
|
formulaAliases.add( derivedValue.getAlias( factory.getDialect() ) );
|
||||||
formulasLazy.add( lazy );
|
formulasLazy.add( lazy );
|
||||||
}
|
}
|
||||||
else if ( org.hibernate.metamodel.relational.Column.class.isInstance( thing )) {
|
else {
|
||||||
org.hibernate.metamodel.relational.Column col = org.hibernate.metamodel.relational.Column.class.cast( thing );
|
org.hibernate.metamodel.relational.Column col = org.hibernate.metamodel.relational.Column.class.cast( valueBinding.getSimpleValue() );
|
||||||
String colName = col.getColumnName().encloseInQuotesIfQuoted( factory.getDialect() );
|
String colName = col.getColumnName().encloseInQuotesIfQuoted( factory.getDialect() );
|
||||||
colnos[l] = columns.size(); //before add :-)
|
colnos[l] = columns.size(); //before add :-)
|
||||||
formnos[l] = -1;
|
formnos[l] = -1;
|
||||||
columns.add( colName );
|
columns.add( colName );
|
||||||
cols[l] = colName;
|
cols[l] = colName;
|
||||||
aliases.add( thing.getAlias( factory.getDialect() ) );
|
aliases.add( col.getAlias( factory.getDialect() ) );
|
||||||
columnsLazy.add( lazy );
|
columnsLazy.add( lazy );
|
||||||
// TODO: properties only selectable if they are non-plural???
|
// TODO: properties only selectable if they are non-plural???
|
||||||
columnSelectables.add( prop.isSimpleValue() );
|
columnSelectables.add( singularAttributeBinding.getAttribute().isSingular() );
|
||||||
|
|
||||||
readers[l] =
|
readers[l] =
|
||||||
col.getReadFragment() == null ?
|
col.getReadFragment() == null ?
|
||||||
@ -1032,10 +1040,10 @@ else if ( org.hibernate.metamodel.relational.Column.class.isInstance( thing )) {
|
|||||||
propFormulaNumbers.add( formnos );
|
propFormulaNumbers.add( formnos );
|
||||||
|
|
||||||
// TODO: fix this when HHH-6357 is fixed; for now, assume FetchMode.DEFAULT
|
// TODO: fix this when HHH-6357 is fixed; for now, assume FetchMode.DEFAULT
|
||||||
//joinedFetchesList.add( prop.getValue().getFetchMode() );
|
//joinedFetchesList.add( singularAttributeBinding.getValue().getFetchMode() );
|
||||||
joinedFetchesList.add( FetchMode.DEFAULT );
|
joinedFetchesList.add( FetchMode.DEFAULT );
|
||||||
// TODO: fix this when HHH-6355 is fixed; for now assume CascadeStyle.NONE
|
// TODO: fix this when HHH-6355 is fixed; for now assume CascadeStyle.NONE
|
||||||
//cascades.add( prop.getCascadeStyle() );
|
//cascades.add( singularAttributeBinding.getCascadeStyle() );
|
||||||
cascades.add( CascadeStyle.NONE );
|
cascades.add( CascadeStyle.NONE );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user