HHH-6502: Added support for lists to new metamodel up to Binder processing. Still need to modify persisters.
This commit is contained in:
parent
edcc34a291
commit
1ced2784d5
|
@ -45,12 +45,14 @@ import org.hibernate.id.factory.IdentifierGeneratorFactory;
|
|||
import org.hibernate.internal.util.ReflectHelper;
|
||||
import org.hibernate.internal.util.StringHelper;
|
||||
import org.hibernate.metamodel.internal.HibernateTypeHelper.ReflectedCollectionJavaTypes;
|
||||
import org.hibernate.metamodel.internal.source.hbm.ListAttributeSourceImpl;
|
||||
import org.hibernate.metamodel.spi.binding.AbstractPluralAttributeBinding;
|
||||
import org.hibernate.metamodel.spi.binding.AttributeBinding;
|
||||
import org.hibernate.metamodel.spi.binding.AttributeBindingContainer;
|
||||
import org.hibernate.metamodel.spi.binding.BagBinding;
|
||||
import org.hibernate.metamodel.spi.binding.BasicAttributeBinding;
|
||||
import org.hibernate.metamodel.spi.binding.BasicPluralAttributeElementBinding;
|
||||
import org.hibernate.metamodel.spi.binding.BasicPluralAttributeIndexBinding;
|
||||
import org.hibernate.metamodel.spi.binding.CompositeAttributeBinding;
|
||||
import org.hibernate.metamodel.spi.binding.EntityBinding;
|
||||
import org.hibernate.metamodel.spi.binding.EntityDiscriminator;
|
||||
|
@ -59,10 +61,12 @@ import org.hibernate.metamodel.spi.binding.HibernateTypeDescriptor;
|
|||
import org.hibernate.metamodel.spi.binding.IdGenerator;
|
||||
import org.hibernate.metamodel.spi.binding.IndexedPluralAttributeBinding;
|
||||
import org.hibernate.metamodel.spi.binding.InheritanceType;
|
||||
import org.hibernate.metamodel.spi.binding.ListBinding;
|
||||
import org.hibernate.metamodel.spi.binding.ManyToOneAttributeBinding;
|
||||
import org.hibernate.metamodel.spi.binding.MetaAttribute;
|
||||
import org.hibernate.metamodel.spi.binding.PluralAttributeBinding;
|
||||
import org.hibernate.metamodel.spi.binding.PluralAttributeElementNature;
|
||||
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.binding.SecondaryTable;
|
||||
|
@ -107,6 +111,7 @@ import org.hibernate.metamodel.spi.source.MetaAttributeContext;
|
|||
import org.hibernate.metamodel.spi.source.MetaAttributeSource;
|
||||
import org.hibernate.metamodel.spi.source.MetadataImplementor;
|
||||
import org.hibernate.metamodel.spi.source.Orderable;
|
||||
import org.hibernate.metamodel.spi.source.PluralAttributeIndexSource;
|
||||
import org.hibernate.metamodel.spi.source.PluralAttributeKeySource;
|
||||
import org.hibernate.metamodel.spi.source.PluralAttributeNature;
|
||||
import org.hibernate.metamodel.spi.source.PluralAttributeSource;
|
||||
|
@ -292,7 +297,7 @@ public class Binder {
|
|||
bindJdbcDataType( resolvedElementType, ( AbstractValue ) elementBinding.getRelationalValueBindings().get( 0 ).getValue() );
|
||||
}
|
||||
|
||||
private void bindBasicElementSetTablePrimaryKey( final SetBinding attributeBinding ) {
|
||||
private void bindBasicElementTablePrimaryKey( final PluralAttributeBinding attributeBinding ) {
|
||||
final PrimaryKey primaryKey = attributeBinding.getPluralAttributeKeyBinding().getCollectionTable().getPrimaryKey();
|
||||
final ForeignKey foreignKey = attributeBinding.getPluralAttributeKeyBinding().getForeignKey();
|
||||
final BasicPluralAttributeElementBinding elementBinding =
|
||||
|
@ -328,16 +333,24 @@ public class Binder {
|
|||
}
|
||||
|
||||
private void bindCollectionIndex(
|
||||
final AbstractPluralAttributeBinding attributeBinding,
|
||||
final PluralAttributeSource attributeSource,
|
||||
final String defaultElementJavaTypeName ) {
|
||||
if ( !IndexedPluralAttributeBinding.class.isInstance( attributeBinding ) ) {
|
||||
return;
|
||||
}
|
||||
// final PluralAttributeIndexBinding indexBinding =
|
||||
( ( IndexedPluralAttributeBinding ) attributeBinding ).getPluralAttributeIndexBinding();
|
||||
// todo : implement
|
||||
throw new NotYetImplementedException();
|
||||
final IndexedPluralAttributeBinding attributeBinding,
|
||||
final PluralAttributeIndexSource attributeSource,
|
||||
final String defaultIndexJavaTypeName ) {
|
||||
IndexedPluralAttributeBinding indexedAttributeBinding = attributeBinding;
|
||||
final BasicPluralAttributeIndexBinding indexBinding =
|
||||
( BasicPluralAttributeIndexBinding ) indexedAttributeBinding.getPluralAttributeIndexBinding();
|
||||
indexBinding.setIndexRelationalValue( bindValues(
|
||||
indexedAttributeBinding.getContainer(),
|
||||
attributeSource,
|
||||
indexedAttributeBinding.getAttribute(),
|
||||
indexedAttributeBinding.getPluralAttributeKeyBinding().getCollectionTable() ).get( 0 ).getValue() );
|
||||
bindHibernateTypeDescriptor(
|
||||
indexBinding.getHibernateTypeDescriptor(),
|
||||
attributeSource.explicitHibernateTypeSource(),
|
||||
defaultIndexJavaTypeName );
|
||||
Type resolvedElementType = heuristicType( indexBinding.getHibernateTypeDescriptor() );
|
||||
bindHibernateResolvedType( indexBinding.getHibernateTypeDescriptor(), resolvedElementType );
|
||||
bindJdbcDataType( resolvedElementType, ( AbstractValue ) indexBinding.getIndexRelationalValue() );
|
||||
}
|
||||
|
||||
private void bindCollectionKey(
|
||||
|
@ -468,13 +481,16 @@ public class Binder {
|
|||
final AbstractPluralAttributeBinding attributeBinding,
|
||||
final PluralAttributeSource attributeSource,
|
||||
final HibernateTypeHelper.ReflectedCollectionJavaTypes reflectedCollectionJavaTypes ) {
|
||||
PluralAttributeNature pluralAttributeNature = attributeSource.getPluralAttributeNature();
|
||||
if ( attributeSource.getElementSource().getNature() == org.hibernate.metamodel.spi.source.PluralAttributeElementNature.ONE_TO_MANY
|
||||
|| attributeSource.getPluralAttributeNature() == PluralAttributeNature.BAG ) {
|
||||
|| pluralAttributeNature == PluralAttributeNature.BAG ) {
|
||||
return;
|
||||
}
|
||||
if ( attributeBinding.getPluralAttributeElementBinding().getPluralAttributeElementNature() == PluralAttributeElementNature.BASIC ) {
|
||||
if ( attributeSource.getPluralAttributeNature() == PluralAttributeNature.SET ) {
|
||||
bindBasicElementSetTablePrimaryKey( ( SetBinding ) attributeBinding );
|
||||
if ( pluralAttributeNature == PluralAttributeNature.SET ) {
|
||||
bindBasicElementTablePrimaryKey( attributeBinding );
|
||||
} else if ( pluralAttributeNature == PluralAttributeNature.LIST ) {
|
||||
bindIndexedTablePrimaryKey( ( IndexedPluralAttributeBinding ) attributeBinding );
|
||||
} else {
|
||||
throw new NotYetImplementedException( "Only Sets with basic elements are supported so far." );
|
||||
}
|
||||
|
@ -747,6 +763,19 @@ public class Binder {
|
|||
}
|
||||
}
|
||||
|
||||
private void bindIndexedTablePrimaryKey( IndexedPluralAttributeBinding attributeBinding ) {
|
||||
final PrimaryKey primaryKey = attributeBinding.getPluralAttributeKeyBinding().getCollectionTable().getPrimaryKey();
|
||||
final ForeignKey foreignKey = attributeBinding.getPluralAttributeKeyBinding().getForeignKey();
|
||||
final PluralAttributeIndexBinding indexBinding = attributeBinding.getPluralAttributeIndexBinding();
|
||||
for ( final Column foreignKeyColumn : foreignKey.getSourceColumns() ) {
|
||||
primaryKey.addColumn( foreignKeyColumn );
|
||||
}
|
||||
final Value value = indexBinding.getIndexRelationalValue();
|
||||
if ( value instanceof Column ) {
|
||||
primaryKey.addColumn( ( Column ) value );
|
||||
}
|
||||
}
|
||||
|
||||
LocalBindingContext bindingContext() {
|
||||
return bindingContexts.peek();
|
||||
}
|
||||
|
@ -764,6 +793,24 @@ public class Binder {
|
|||
}
|
||||
}
|
||||
|
||||
private AbstractPluralAttributeBinding bindListAttribute(
|
||||
final AttributeBindingContainer attributeBindingContainer,
|
||||
final PluralAttributeSource attributeSource,
|
||||
PluralAttribute attribute ) {
|
||||
if ( attribute == null ) {
|
||||
attribute = attributeBindingContainer.getAttributeContainer().createList( attributeSource.getName() );
|
||||
}
|
||||
return attributeBindingContainer.makeListAttributeBinding(
|
||||
attribute,
|
||||
pluralAttributeElementNature( attributeSource ),
|
||||
pluralAttributeKeyBinding( attributeBindingContainer, attributeSource ),
|
||||
propertyAccessorName( attributeSource ),
|
||||
attributeSource.isIncludedInOptimisticLocking(),
|
||||
false,
|
||||
createMetaAttributeContext( attributeBindingContainer, attributeSource ),
|
||||
((ListAttributeSourceImpl)attributeSource).getIndexSource().base() );
|
||||
}
|
||||
|
||||
private ManyToOneAttributeBinding bindManyToOneAttribute(
|
||||
final AttributeBindingContainer attributeBindingContainer,
|
||||
final ToOneAttributeSource attributeSource,
|
||||
|
@ -854,6 +901,9 @@ public class Binder {
|
|||
} else if ( nature == PluralAttributeNature.SET ) {
|
||||
attributeBinding = bindSetAttribute( attributeBindingContainer, attributeSource, attribute );
|
||||
resolvedType = resolveSetType( ( SetBinding ) attributeBinding );
|
||||
} else if ( nature == PluralAttributeNature.LIST ) {
|
||||
attributeBinding = bindListAttribute( attributeBindingContainer, attributeSource, attribute );
|
||||
resolvedType = resolveListType( ( ListBinding ) attributeBinding );
|
||||
} else {
|
||||
throw new NotYetImplementedException( nature.toString() );
|
||||
}
|
||||
|
@ -894,7 +944,12 @@ public class Binder {
|
|||
attributeSource.getElementSource().getNature() ) );
|
||||
}
|
||||
|
||||
bindCollectionIndex( attributeBinding, attributeSource, defaultCollectionIndexJavaTypeName( reflectedCollectionJavaTypes ) );
|
||||
if (attributeSource instanceof ListAttributeSourceImpl) {
|
||||
bindCollectionIndex(
|
||||
(IndexedPluralAttributeBinding) attributeBinding,
|
||||
( (ListAttributeSourceImpl) attributeSource ).getIndexSource(),
|
||||
defaultCollectionIndexJavaTypeName( reflectedCollectionJavaTypes ) );
|
||||
}
|
||||
|
||||
bindCollectionTablePrimaryKey( attributeBinding, attributeSource, reflectedCollectionJavaTypes );
|
||||
metadata.addCollection( attributeBinding );
|
||||
|
@ -1540,6 +1595,17 @@ public class Binder {
|
|||
pluralAttributeBinding.getPluralAttributeElementBinding().getPluralAttributeElementNature() == PluralAttributeElementNature.COMPOSITE );
|
||||
}
|
||||
|
||||
private Type resolveListType( ListBinding listBinding ) {
|
||||
if ( listBinding.getHibernateTypeDescriptor().getExplicitTypeName() != null ) {
|
||||
return resolveCustomCollectionType( listBinding );
|
||||
} else {
|
||||
return metadata.getTypeResolver().getTypeFactory().list(
|
||||
listBinding.getAttribute().getRole(),
|
||||
listBinding.getReferencedPropertyName(),
|
||||
listBinding.getPluralAttributeElementBinding().getPluralAttributeElementNature() == PluralAttributeElementNature.COMPOSITE );
|
||||
}
|
||||
}
|
||||
|
||||
private Type resolveSetType( SetBinding setBinding ) {
|
||||
if ( setBinding.getHibernateTypeDescriptor().getExplicitTypeName() != null ) {
|
||||
return resolveCustomCollectionType( setBinding );
|
||||
|
|
|
@ -180,7 +180,13 @@ public abstract class AbstractEntitySourceImpl
|
|||
);
|
||||
}
|
||||
else if ( JaxbListElement.class.isInstance( attributeElement ) ) {
|
||||
// todo : implement
|
||||
results.add(
|
||||
new ListAttributeSourceImpl(
|
||||
sourceMappingDocument(),
|
||||
JaxbListElement.class.cast( attributeElement ),
|
||||
this
|
||||
)
|
||||
);
|
||||
}
|
||||
else if ( JaxbMapElement.class.isInstance( attributeElement ) ) {
|
||||
// todo : implement
|
||||
|
|
|
@ -0,0 +1,69 @@
|
|||
/*
|
||||
* 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.internal.source.hbm;
|
||||
|
||||
import org.hibernate.internal.jaxb.mapping.hbm.JaxbListElement;
|
||||
import org.hibernate.metamodel.spi.source.AttributeSourceContainer;
|
||||
import org.hibernate.metamodel.spi.source.PluralAttributeIndexSource;
|
||||
import org.hibernate.metamodel.spi.source.PluralAttributeNature;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class ListAttributeSourceImpl extends AbstractPluralAttributeSourceImpl {
|
||||
|
||||
private final PluralAttributeIndexSource indexSource;
|
||||
|
||||
/**
|
||||
* @param sourceMappingDocument
|
||||
* @param listElement
|
||||
* @param container
|
||||
*/
|
||||
public ListAttributeSourceImpl(
|
||||
MappingDocument sourceMappingDocument,
|
||||
JaxbListElement listElement,
|
||||
AttributeSourceContainer container ) {
|
||||
super( sourceMappingDocument, listElement, container );
|
||||
this.indexSource = new PluralAttributeIndexSourceImpl( sourceMappingDocument(), listElement.getListIndex(), container );
|
||||
}
|
||||
|
||||
public PluralAttributeIndexSource getIndexSource() {
|
||||
return indexSource;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JaxbListElement getPluralAttributeElement() {
|
||||
return ( JaxbListElement ) super.getPluralAttributeElement();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* @see org.hibernate.metamodel.spi.source.PluralAttributeSource#getPluralAttributeNature()
|
||||
*/
|
||||
@Override
|
||||
public PluralAttributeNature getPluralAttributeNature() {
|
||||
return PluralAttributeNature.LIST;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,163 @@
|
|||
/*
|
||||
* 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.internal.source.hbm;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.hibernate.internal.jaxb.mapping.hbm.JaxbColumnElement;
|
||||
import org.hibernate.internal.jaxb.mapping.hbm.JaxbListIndexElement;
|
||||
import org.hibernate.metamodel.spi.source.AttributeSourceContainer;
|
||||
import org.hibernate.metamodel.spi.source.ExplicitHibernateTypeSource;
|
||||
import org.hibernate.metamodel.spi.source.PluralAttributeIndexSource;
|
||||
import org.hibernate.metamodel.spi.source.RelationalValueSource;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class PluralAttributeIndexSourceImpl extends AbstractHbmSourceNode implements PluralAttributeIndexSource {
|
||||
|
||||
private final List< RelationalValueSource > valueSources;
|
||||
private final ExplicitHibernateTypeSource typeSource;
|
||||
private final int base;
|
||||
|
||||
public PluralAttributeIndexSourceImpl(
|
||||
MappingDocument mappingDocument,
|
||||
final JaxbListIndexElement 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 = Integer.parseInt( indexElement.getBase() );
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* @see org.hibernate.metamodel.spi.source.ColumnBindingDefaults#areValuesIncludedInInsertByDefault()
|
||||
*/
|
||||
@Override
|
||||
public boolean areValuesIncludedInInsertByDefault() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* @see org.hibernate.metamodel.spi.source.ColumnBindingDefaults#areValuesIncludedInUpdateByDefault()
|
||||
*/
|
||||
@Override
|
||||
public boolean areValuesIncludedInUpdateByDefault() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* @see org.hibernate.metamodel.spi.source.ColumnBindingDefaults#areValuesNullableByDefault()
|
||||
*/
|
||||
@Override
|
||||
public boolean areValuesNullableByDefault() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* @see org.hibernate.metamodel.spi.source.PluralAttributeIndexSource#base()
|
||||
*/
|
||||
@Override
|
||||
public int base() {
|
||||
return base;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* @see org.hibernate.metamodel.spi.source.PluralAttributeIndexSource#explicitHibernateTypeSource()
|
||||
*/
|
||||
@Override
|
||||
public ExplicitHibernateTypeSource explicitHibernateTypeSource() {
|
||||
return typeSource;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* @see org.hibernate.metamodel.spi.source.RelationalValueSourceContainer#relationalValueSources()
|
||||
*/
|
||||
@Override
|
||||
public List< RelationalValueSource > relationalValueSources() {
|
||||
return valueSources;
|
||||
}
|
||||
}
|
|
@ -73,6 +73,12 @@ public interface AttributeBindingContainer {
|
|||
* Factory method for basic attribute bindings.
|
||||
*
|
||||
* @param attribute The attribute for which to make a binding.
|
||||
* @param relationalValueBindings
|
||||
* @param propertyAccessorName
|
||||
* @param includedInOptimisticLocking
|
||||
* @param lazy
|
||||
* @param metaAttributeContext
|
||||
* @param generation
|
||||
*
|
||||
* @return The attribute binding instance.
|
||||
*/
|
||||
|
@ -89,6 +95,11 @@ public interface AttributeBindingContainer {
|
|||
* Factory method for component attribute bindings.
|
||||
*
|
||||
* @param attribute The attribute for which to make a binding.
|
||||
* @param parentReferenceAttribute
|
||||
* @param propertyAccessorName
|
||||
* @param includedInOptimisticLocking
|
||||
* @param lazy
|
||||
* @param metaAttributeContext
|
||||
*
|
||||
* @return The attribute binding instance.
|
||||
*/
|
||||
|
@ -105,7 +116,12 @@ public interface AttributeBindingContainer {
|
|||
*
|
||||
*
|
||||
* @param attribute The attribute for which to make a binding.
|
||||
* @param propertyAccessorName
|
||||
* @param includedInOptimisticLocking
|
||||
* @param lazy
|
||||
* @param metaAttributeContext
|
||||
* @param referencedAttributeBinding
|
||||
* @param valueBindings
|
||||
*
|
||||
* @return The attribute binding instance.
|
||||
*/
|
||||
|
@ -123,6 +139,11 @@ public interface AttributeBindingContainer {
|
|||
*
|
||||
* @param attribute The attribute for which to make a binding.
|
||||
* @param nature The nature of the collection elements.
|
||||
* @param referencedAttributeBinding
|
||||
* @param propertyAccessorName
|
||||
* @param includedInOptimisticLocking
|
||||
* @param lazy
|
||||
* @param metaAttributeContext
|
||||
*
|
||||
* @return The attribute binding instance.
|
||||
*/
|
||||
|
@ -140,6 +161,36 @@ public interface AttributeBindingContainer {
|
|||
*
|
||||
* @param attribute The attribute for which to make a binding.
|
||||
* @param nature The nature of the collection elements.
|
||||
* @param referencedAttributeBinding
|
||||
* @param propertyAccessorName
|
||||
* @param includedInOptimisticLocking
|
||||
* @param lazy
|
||||
* @param metaAttributeContext
|
||||
* @param base
|
||||
*
|
||||
* @return The attribute binding instance.
|
||||
*/
|
||||
public ListBinding makeListAttributeBinding(
|
||||
PluralAttribute attribute,
|
||||
PluralAttributeElementNature nature,
|
||||
SingularAttributeBinding referencedAttributeBinding,
|
||||
String propertyAccessorName,
|
||||
boolean includedInOptimisticLocking,
|
||||
boolean lazy,
|
||||
MetaAttributeContext metaAttributeContext,
|
||||
int base );
|
||||
|
||||
/**
|
||||
* Factory method for bag attribute bindings.
|
||||
*
|
||||
* @param attribute The attribute for which to make a binding.
|
||||
* @param nature The nature of the collection elements.
|
||||
* @param referencedAttributeBinding
|
||||
* @param propertyAccessorName
|
||||
* @param includedInOptimisticLocking
|
||||
* @param lazy
|
||||
* @param metaAttributeContext
|
||||
* @param comparator
|
||||
*
|
||||
* @return The attribute binding instance.
|
||||
*/
|
||||
|
|
|
@ -0,0 +1,90 @@
|
|||
/*
|
||||
* 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.spi.binding;
|
||||
|
||||
import org.hibernate.metamodel.spi.relational.Value;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class BasicPluralAttributeIndexBinding implements PluralAttributeIndexBinding {
|
||||
|
||||
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 ) {
|
||||
this.pluralAttributeBinding = pluralAttributeBinding;
|
||||
this.base = base;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* @see org.hibernate.metamodel.spi.binding.PluralAttributeIndexBinding#base()
|
||||
*/
|
||||
@Override
|
||||
public int base() {
|
||||
return base;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* @see org.hibernate.metamodel.spi.binding.PluralAttributeIndexBinding#getHibernateTypeDescriptor()
|
||||
*/
|
||||
@Override
|
||||
public HibernateTypeDescriptor getHibernateTypeDescriptor() {
|
||||
return hibernateTypeDescriptor;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* @see org.hibernate.metamodel.spi.binding.PluralAttributeIndexBinding#getIndexRelationalValue()
|
||||
*/
|
||||
@Override
|
||||
public Value getIndexRelationalValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* @see org.hibernate.metamodel.spi.binding.PluralAttributeIndexBinding#getPluralAttributeBinding()
|
||||
*/
|
||||
@Override
|
||||
public PluralAttributeBinding getPluralAttributeBinding() {
|
||||
return pluralAttributeBinding;
|
||||
}
|
||||
|
||||
public void setIndexRelationalValue( Value value ) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
|
@ -225,6 +225,31 @@ public class CompositeAttributeBinding
|
|||
return binding;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ListBinding makeListAttributeBinding(
|
||||
PluralAttribute attribute,
|
||||
PluralAttributeElementNature nature,
|
||||
SingularAttributeBinding referencedAttributeBinding,
|
||||
String propertyAccessorName,
|
||||
boolean includedInOptimisticLocking,
|
||||
boolean lazy,
|
||||
MetaAttributeContext metaAttributeContext,
|
||||
int base ) {
|
||||
Helper.checkPluralAttributeNature( attribute, PluralAttributeNature.LIST );
|
||||
final ListBinding binding = new ListBinding(
|
||||
this,
|
||||
attribute,
|
||||
nature,
|
||||
referencedAttributeBinding,
|
||||
propertyAccessorName,
|
||||
includedInOptimisticLocking,
|
||||
lazy,
|
||||
metaAttributeContext,
|
||||
base );
|
||||
registerAttributeBinding( attribute.getName(), binding );
|
||||
return binding;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SetBinding makeSetAttributeBinding(
|
||||
PluralAttribute attribute,
|
||||
|
|
|
@ -571,6 +571,31 @@ public class EntityBinding implements AttributeBindingContainer {
|
|||
return binding;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ListBinding makeListAttributeBinding(
|
||||
PluralAttribute attribute,
|
||||
PluralAttributeElementNature nature,
|
||||
SingularAttributeBinding referencedAttributeBinding,
|
||||
String propertyAccessorName,
|
||||
boolean includedInOptimisticLocking,
|
||||
boolean lazy,
|
||||
MetaAttributeContext metaAttributeContext,
|
||||
int base ) {
|
||||
Helper.checkPluralAttributeNature( attribute, PluralAttributeNature.LIST );
|
||||
final ListBinding binding = new ListBinding(
|
||||
this,
|
||||
attribute,
|
||||
nature,
|
||||
referencedAttributeBinding,
|
||||
propertyAccessorName,
|
||||
includedInOptimisticLocking,
|
||||
lazy,
|
||||
metaAttributeContext,
|
||||
base );
|
||||
registerAttributeBinding( attribute.getName(), binding );
|
||||
return binding;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SetBinding makeSetAttributeBinding(
|
||||
PluralAttribute attribute,
|
||||
|
@ -644,10 +669,9 @@ public class EntityBinding implements AttributeBindingContainer {
|
|||
}
|
||||
|
||||
/**
|
||||
* Gets the attribute bindings for this EntityBinding and all of its
|
||||
* @return the attribute bindings for this EntityBinding and all of its
|
||||
* sub-EntityBinding, starting from the root of the hierarchy; includes
|
||||
* the identifier and attribute bindings defined as part of a join.
|
||||
* @return
|
||||
*/
|
||||
public Iterable<AttributeBinding> getSubEntityAttributeBindingClosure() {
|
||||
List<Iterable<AttributeBinding>> iterables = new ArrayList<Iterable<AttributeBinding>>();
|
||||
|
|
|
@ -0,0 +1,67 @@
|
|||
/*
|
||||
* 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.spi.binding;
|
||||
|
||||
import org.hibernate.metamodel.spi.domain.PluralAttribute;
|
||||
import org.hibernate.metamodel.spi.source.MetaAttributeContext;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class ListBinding extends AbstractPluralAttributeBinding implements IndexedPluralAttributeBinding {
|
||||
|
||||
private PluralAttributeIndexBinding pluralAttributeIndexBinding;
|
||||
|
||||
public ListBinding(
|
||||
AttributeBindingContainer container,
|
||||
PluralAttribute attribute,
|
||||
PluralAttributeElementNature pluralAttributeElementNature,
|
||||
SingularAttributeBinding referencedAttributeBinding,
|
||||
String propertyAccessorName,
|
||||
boolean includedInOptimisticLocking,
|
||||
boolean isLazy,
|
||||
MetaAttributeContext metaAttributeContext,
|
||||
int base ) {
|
||||
super(
|
||||
container,
|
||||
attribute,
|
||||
pluralAttributeElementNature,
|
||||
referencedAttributeBinding,
|
||||
propertyAccessorName,
|
||||
includedInOptimisticLocking,
|
||||
isLazy,
|
||||
metaAttributeContext );
|
||||
this.pluralAttributeIndexBinding = new BasicPluralAttributeIndexBinding( this, base );
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* @see org.hibernate.metamodel.spi.binding.IndexedPluralAttributeBinding#getPluralAttributeIndexBinding()
|
||||
*/
|
||||
@Override
|
||||
public PluralAttributeIndexBinding getPluralAttributeIndexBinding() {
|
||||
return pluralAttributeIndexBinding;
|
||||
}
|
||||
}
|
|
@ -26,11 +26,15 @@ package org.hibernate.metamodel.spi.binding;
|
|||
import org.hibernate.metamodel.spi.relational.Value;
|
||||
|
||||
/**
|
||||
* De
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public interface PluralAttributeIndexBinding {
|
||||
public PluralAttributeBinding getPluralAttributeBinding();
|
||||
public Value getIndexRelationalValue();
|
||||
public HibernateTypeDescriptor getHibernateTypeDescriptor();
|
||||
|
||||
int base();
|
||||
|
||||
PluralAttributeBinding getPluralAttributeBinding();
|
||||
|
||||
Value getIndexRelationalValue();
|
||||
|
||||
HibernateTypeDescriptor getHibernateTypeDescriptor();
|
||||
}
|
||||
|
|
|
@ -23,11 +23,10 @@
|
|||
*/
|
||||
package org.hibernate.metamodel.spi.source;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public interface BasicPluralAttributeElementSource extends PluralAttributeElementSource, RelationalValueSourceContainer {
|
||||
|
||||
public ExplicitHibernateTypeSource getExplicitHibernateTypeSource();
|
||||
}
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
/*
|
||||
* 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.spi.source;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public interface PluralAttributeIndexSource extends RelationalValueSourceContainer {
|
||||
|
||||
int base();
|
||||
|
||||
ExplicitHibernateTypeSource explicitHibernateTypeSource();
|
||||
}
|
|
@ -26,6 +26,12 @@
|
|||
<element column="set_stuff" type="string"/>
|
||||
</set>
|
||||
|
||||
<list name="theList">
|
||||
<key column="pid"/>
|
||||
<list-index column="list_index"/>
|
||||
<element column="list_stuff" type="string"/>
|
||||
</list>
|
||||
|
||||
</class>
|
||||
|
||||
</hibernate-mapping>
|
||||
|
|
|
@ -26,7 +26,9 @@ package org.hibernate.metamodel.spi.binding;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.persistence.ElementCollection;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
|
@ -42,6 +44,7 @@ public class EntityWithBasicCollections {
|
|||
private Collection<String> theBag = new ArrayList<String>();
|
||||
private Set<String> theSet = new HashSet<String>();
|
||||
private Set<Integer> thePropertyRefSet = new HashSet<Integer>();
|
||||
private List<String> theList = new ArrayList<String>();
|
||||
|
||||
public EntityWithBasicCollections() {
|
||||
}
|
||||
|
@ -93,4 +96,13 @@ public class EntityWithBasicCollections {
|
|||
public void setThePropertyRefSet(Set<Integer> thePropertyRefSet) {
|
||||
this.thePropertyRefSet = thePropertyRefSet;
|
||||
}
|
||||
|
||||
@ElementCollection
|
||||
public List<String> getTheList() {
|
||||
return theList;
|
||||
}
|
||||
|
||||
public void setTheList(List<String> theList) {
|
||||
this.theList = theList;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue