HHH-6502: Added support for lists to persister that deals with new metamodel.
This commit is contained in:
parent
1ced2784d5
commit
d8f9372fbf
|
@ -24,6 +24,7 @@
|
|||
package org.hibernate.metamodel.internal.source.hbm;
|
||||
|
||||
import org.hibernate.internal.jaxb.mapping.hbm.JaxbListElement;
|
||||
import org.hibernate.internal.jaxb.mapping.hbm.JaxbListIndexElement;
|
||||
import org.hibernate.metamodel.spi.source.AttributeSourceContainer;
|
||||
import org.hibernate.metamodel.spi.source.PluralAttributeIndexSource;
|
||||
import org.hibernate.metamodel.spi.source.PluralAttributeNature;
|
||||
|
@ -45,7 +46,12 @@ public class ListAttributeSourceImpl extends AbstractPluralAttributeSourceImpl {
|
|||
JaxbListElement listElement,
|
||||
AttributeSourceContainer container ) {
|
||||
super( sourceMappingDocument, listElement, container );
|
||||
this.indexSource = new PluralAttributeIndexSourceImpl( sourceMappingDocument(), listElement.getListIndex(), container );
|
||||
JaxbListIndexElement listIndexElement = listElement.getListIndex();
|
||||
if ( listIndexElement == null ) {
|
||||
this.indexSource = new PluralAttributeIndexSourceImpl( sourceMappingDocument(), listElement.getIndex(), container );
|
||||
} else {
|
||||
this.indexSource = new PluralAttributeIndexSourceImpl( sourceMappingDocument(), listIndexElement, container );
|
||||
}
|
||||
}
|
||||
|
||||
public PluralAttributeIndexSource getIndexSource() {
|
||||
|
|
|
@ -28,6 +28,7 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
|
||||
import org.hibernate.internal.jaxb.mapping.hbm.JaxbColumnElement;
|
||||
import org.hibernate.internal.jaxb.mapping.hbm.JaxbIndexElement;
|
||||
import org.hibernate.internal.jaxb.mapping.hbm.JaxbListIndexElement;
|
||||
import org.hibernate.metamodel.spi.source.AttributeSourceContainer;
|
||||
import org.hibernate.metamodel.spi.source.ExplicitHibernateTypeSource;
|
||||
|
@ -101,6 +102,64 @@ public class PluralAttributeIndexSourceImpl extends AbstractHbmSourceNode implem
|
|||
base = Integer.parseInt( indexElement.getBase() );
|
||||
}
|
||||
|
||||
public PluralAttributeIndexSourceImpl(
|
||||
MappingDocument mappingDocument,
|
||||
final JaxbIndexElement indexElement,
|
||||
final AttributeSourceContainer container ) {
|
||||
super( mappingDocument );
|
||||
valueSources = Helper.buildValueSources( sourceMappingDocument(), new Helper.ValueSourcesAdapter() {
|
||||
|
||||
List< JaxbColumnElement > columnElements = indexElement.getColumn() == null
|
||||
? Collections.EMPTY_LIST
|
||||
: Collections.singletonList( indexElement.getColumn() );
|
||||
|
||||
@Override
|
||||
public String getColumnAttribute() {
|
||||
return indexElement.getColumnAttribute();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List getColumnOrFormulaElements() {
|
||||
return columnElements;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getContainingTableName() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFormulaAttribute() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isIncludedInInsertByDefault() {
|
||||
return areValuesIncludedInInsertByDefault();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isIncludedInUpdateByDefault() {
|
||||
return areValuesIncludedInUpdateByDefault();
|
||||
}
|
||||
} );
|
||||
|
||||
typeSource = new ExplicitHibernateTypeSource() {
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "integer";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map< String, String > getParameters() {
|
||||
return java.util.Collections.< String, String >emptyMap();
|
||||
}
|
||||
};
|
||||
|
||||
base = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
|
|
|
@ -33,25 +33,12 @@ public class BasicPluralAttributeIndexBinding implements PluralAttributeIndexBin
|
|||
private final AbstractPluralAttributeBinding pluralAttributeBinding;
|
||||
private final HibernateTypeDescriptor hibernateTypeDescriptor = new HibernateTypeDescriptor();
|
||||
private Value value;
|
||||
private int base;
|
||||
|
||||
/**
|
||||
* @param pluralAttributeBinding
|
||||
* @param base
|
||||
*/
|
||||
public BasicPluralAttributeIndexBinding( final AbstractPluralAttributeBinding pluralAttributeBinding, int base ) {
|
||||
public BasicPluralAttributeIndexBinding( final AbstractPluralAttributeBinding pluralAttributeBinding ) {
|
||||
this.pluralAttributeBinding = pluralAttributeBinding;
|
||||
this.base = base;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* @see org.hibernate.metamodel.spi.binding.PluralAttributeIndexBinding#base()
|
||||
*/
|
||||
@Override
|
||||
public int base() {
|
||||
return base;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -32,6 +32,7 @@ import org.hibernate.metamodel.spi.source.MetaAttributeContext;
|
|||
public class ListBinding extends AbstractPluralAttributeBinding implements IndexedPluralAttributeBinding {
|
||||
|
||||
private PluralAttributeIndexBinding pluralAttributeIndexBinding;
|
||||
private int base;
|
||||
|
||||
public ListBinding(
|
||||
AttributeBindingContainer container,
|
||||
|
@ -52,7 +53,12 @@ public class ListBinding extends AbstractPluralAttributeBinding implements Index
|
|||
includedInOptimisticLocking,
|
||||
isLazy,
|
||||
metaAttributeContext );
|
||||
this.pluralAttributeIndexBinding = new BasicPluralAttributeIndexBinding( this, base );
|
||||
this.pluralAttributeIndexBinding = new BasicPluralAttributeIndexBinding( this );
|
||||
this.base = base;
|
||||
}
|
||||
|
||||
public int base() {
|
||||
return base;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -30,8 +30,6 @@ import org.hibernate.metamodel.spi.relational.Value;
|
|||
*/
|
||||
public interface PluralAttributeIndexBinding {
|
||||
|
||||
int base();
|
||||
|
||||
PluralAttributeBinding getPluralAttributeBinding();
|
||||
|
||||
Value getIndexRelationalValue();
|
||||
|
|
|
@ -80,8 +80,10 @@ import org.hibernate.mapping.Table;
|
|||
import org.hibernate.metadata.CollectionMetadata;
|
||||
import org.hibernate.metamodel.spi.binding.AbstractPluralAttributeBinding;
|
||||
import org.hibernate.metamodel.spi.binding.CustomSQL;
|
||||
import org.hibernate.metamodel.spi.binding.IndexedPluralAttributeBinding;
|
||||
import org.hibernate.metamodel.spi.binding.ListBinding;
|
||||
import org.hibernate.metamodel.spi.binding.PluralAttributeAssociationElementBinding;
|
||||
import org.hibernate.metamodel.spi.binding.PluralAttributeElementBinding;
|
||||
import org.hibernate.metamodel.spi.binding.PluralAttributeIndexBinding;
|
||||
import org.hibernate.metamodel.spi.binding.PluralAttributeKeyBinding;
|
||||
import org.hibernate.metamodel.spi.binding.RelationalValueBinding;
|
||||
import org.hibernate.metamodel.spi.domain.PluralAttributeNature;
|
||||
|
@ -720,7 +722,7 @@ public abstract class AbstractCollectionPersister
|
|||
|
||||
// ELEMENT
|
||||
|
||||
PluralAttributeElementBinding elementBinding = collection.getPluralAttributeElementBinding();
|
||||
// PluralAttributeElementBinding elementBinding = collection.getPluralAttributeElementBinding();
|
||||
//TODO: is elemNode needed?
|
||||
String elemNode = null;
|
||||
//String elemNode = collection.getElementNodeName();
|
||||
|
@ -792,14 +794,22 @@ public abstract class AbstractCollectionPersister
|
|||
// INDEX AND ROW SELECT
|
||||
|
||||
hasIndex = collection.getAttribute().getNature().isIndexed();
|
||||
// TODO: Fix this when index relational binding is created
|
||||
//if ( hasIndex ) {
|
||||
// // NativeSQL: collect index column and auto-aliases
|
||||
// PluralAttributeIndexBinding indexBinding = ( (IndexedPluralAttributeBinding) collection ).getPluralAttributeIndexBinding();
|
||||
// indexType = indexBinding.getHibernateTypeDescriptor().getResolvedTypeMapping();
|
||||
//}
|
||||
//else {
|
||||
indexContainsFormula = false;
|
||||
indexNodeName = null;
|
||||
if ( hasIndex ) {
|
||||
// NativeSQL: collect index column and auto-aliases
|
||||
IndexedPluralAttributeBinding indexedBinding = (IndexedPluralAttributeBinding) collection;
|
||||
// TODO: indexNodeName = indexedBinding.getIndexNodeName();
|
||||
PluralAttributeIndexBinding indexBinding = indexedBinding.getPluralAttributeIndexBinding();
|
||||
indexType = indexBinding.getHibernateTypeDescriptor().getResolvedTypeMapping();
|
||||
baseIndex = indexBinding instanceof ListBinding ? ( ( ListBinding ) indexBinding ).base() : 0;
|
||||
Column column = (Column) indexBinding.getIndexRelationalValue();
|
||||
indexColumnNames = new String[] { column.getQuotedName( dialect ) };
|
||||
indexColumnAliases = new String[] { column.getAlias( dialect ) };
|
||||
indexFormulaTemplates = new String[1];
|
||||
indexFormulas = new String[1];
|
||||
indexColumnIsSettable = new boolean[] { true };
|
||||
} else {
|
||||
indexColumnIsSettable = null;
|
||||
indexFormulaTemplates = null;
|
||||
indexFormulas = null;
|
||||
|
@ -807,8 +817,7 @@ public abstract class AbstractCollectionPersister
|
|||
indexColumnNames = null;
|
||||
indexColumnAliases = null;
|
||||
baseIndex = 0;
|
||||
indexNodeName = null;
|
||||
//}
|
||||
}
|
||||
|
||||
hasIdentifier = collection.getAttribute().getNature() == PluralAttributeNature.IDBAG;
|
||||
// TODO: fix this when IdBags are supported.
|
||||
|
@ -1777,12 +1786,12 @@ public abstract class AbstractCollectionPersister
|
|||
expectation
|
||||
);
|
||||
}
|
||||
if ( st == null ) {
|
||||
// if ( st == null ) {
|
||||
st = session.getTransactionCoordinator()
|
||||
.getJdbcCoordinator()
|
||||
.getBatch( insertBatchKey )
|
||||
.getBatchStatement( sql, callable );
|
||||
}
|
||||
// }
|
||||
}
|
||||
else {
|
||||
st = session.getTransactionCoordinator()
|
||||
|
|
Loading…
Reference in New Issue