HHH-6503 HHH-6525 : Integrate basic non-indexed collectiosn into persisters

This commit is contained in:
Gail Badner 2012-02-27 22:01:35 -08:00
parent 5c59a8c93e
commit 136540b4c4
5 changed files with 20 additions and 18 deletions

View File

@ -23,7 +23,8 @@
*/ */
package org.hibernate.metamodel.spi.binding; package org.hibernate.metamodel.spi.binding;
import org.hibernate.metamodel.spi.relational.Value; import java.util.Collections;
import java.util.List;
/** /**
* Basic contract describing the commonality between the various types of collection element mappings. * Basic contract describing the commonality between the various types of collection element mappings.
@ -33,7 +34,7 @@ import org.hibernate.metamodel.spi.relational.Value;
public abstract class AbstractPluralAttributeElementBinding implements PluralAttributeElementBinding { public abstract class AbstractPluralAttributeElementBinding implements PluralAttributeElementBinding {
private final AbstractPluralAttributeBinding pluralAttributeBinding; private final AbstractPluralAttributeBinding pluralAttributeBinding;
private final HibernateTypeDescriptor hibernateTypeDescriptor = new HibernateTypeDescriptor(); private final HibernateTypeDescriptor hibernateTypeDescriptor = new HibernateTypeDescriptor();
private Value relationalValue; private List<RelationalValueBinding> relationalValueBindings;
AbstractPluralAttributeElementBinding(AbstractPluralAttributeBinding pluralAttributeBinding) { AbstractPluralAttributeElementBinding(AbstractPluralAttributeBinding pluralAttributeBinding) {
this.pluralAttributeBinding = pluralAttributeBinding; this.pluralAttributeBinding = pluralAttributeBinding;
@ -50,7 +51,11 @@ public abstract class AbstractPluralAttributeElementBinding implements PluralAtt
} }
@Override @Override
public Value getRelationalValue() { public List<RelationalValueBinding> getRelationalValueBindings() {
return relationalValue; return relationalValueBindings;
}
protected void setRelationalValueBindings(List<RelationalValueBinding> relationalValueBindings) {
this.relationalValueBindings = Collections.unmodifiableList( relationalValueBindings );
} }
} }

View File

@ -23,7 +23,6 @@
*/ */
package org.hibernate.metamodel.spi.binding; package org.hibernate.metamodel.spi.binding;
import java.util.Collections;
import java.util.List; import java.util.List;
/** /**
@ -33,7 +32,6 @@ import java.util.List;
* @author Gail Badner * @author Gail Badner
*/ */
public class BasicPluralAttributeElementBinding extends AbstractPluralAttributeElementBinding { public class BasicPluralAttributeElementBinding extends AbstractPluralAttributeElementBinding {
private List<RelationalValueBinding> relationalValueBindings;
private boolean hasDerivedValue; private boolean hasDerivedValue;
private boolean isNullable = true; private boolean isNullable = true;
@ -42,18 +40,14 @@ public class BasicPluralAttributeElementBinding extends AbstractPluralAttributeE
super( binding ); super( binding );
} }
public List<RelationalValueBinding> getRelationalValueBindings() {
return relationalValueBindings;
}
@Override @Override
public PluralAttributeElementNature getPluralAttributeElementNature() { public PluralAttributeElementNature getPluralAttributeElementNature() {
return PluralAttributeElementNature.BASIC; return PluralAttributeElementNature.BASIC;
} }
public void setRelationalValueBindings(List<RelationalValueBinding> relationalValueBindings) { public void setRelationalValueBindings(List<RelationalValueBinding> relationalValueBindings) {
this.relationalValueBindings = Collections.unmodifiableList( relationalValueBindings ); super.setRelationalValueBindings( relationalValueBindings );
for ( RelationalValueBinding relationalValueBinding : relationalValueBindings ) { for ( RelationalValueBinding relationalValueBinding : getRelationalValueBindings() ) {
this.hasDerivedValue = this.hasDerivedValue || relationalValueBinding.isDerived(); this.hasDerivedValue = this.hasDerivedValue || relationalValueBinding.isDerived();
this.isNullable = this.isNullable && relationalValueBinding.isNullable(); this.isNullable = this.isNullable && relationalValueBinding.isNullable();
} }

View File

@ -23,7 +23,7 @@
*/ */
package org.hibernate.metamodel.spi.binding; package org.hibernate.metamodel.spi.binding;
import org.hibernate.metamodel.spi.relational.Value; import java.util.List;
/** /**
* Common information pertaining to the binding of the various plural attribute natures (one-to-many, basic, etc). * Common information pertaining to the binding of the various plural attribute natures (one-to-many, basic, etc).
@ -44,7 +44,7 @@ public interface PluralAttributeElementBinding {
* *
* @return The relation information. * @return The relation information.
*/ */
public Value getRelationalValue(); public List<RelationalValueBinding> getRelationalValueBindings();
/** /**
* Retrieves an enumeration describing the mapping nature of the collection's elements. * Retrieves an enumeration describing the mapping nature of the collection's elements.

View File

@ -83,6 +83,7 @@ import org.hibernate.metamodel.spi.binding.CustomSQL;
import org.hibernate.metamodel.spi.binding.PluralAttributeAssociationElementBinding; import org.hibernate.metamodel.spi.binding.PluralAttributeAssociationElementBinding;
import org.hibernate.metamodel.spi.binding.PluralAttributeElementBinding; import org.hibernate.metamodel.spi.binding.PluralAttributeElementBinding;
import org.hibernate.metamodel.spi.binding.PluralAttributeKeyBinding; import org.hibernate.metamodel.spi.binding.PluralAttributeKeyBinding;
import org.hibernate.metamodel.spi.binding.RelationalValueBinding;
import org.hibernate.metamodel.spi.domain.PluralAttributeNature; import org.hibernate.metamodel.spi.domain.PluralAttributeNature;
import org.hibernate.metamodel.spi.relational.DerivedValue; import org.hibernate.metamodel.spi.relational.DerivedValue;
import org.hibernate.metamodel.spi.relational.TableSpecification; import org.hibernate.metamodel.spi.relational.TableSpecification;
@ -737,7 +738,9 @@ public abstract class AbstractCollectionPersister
} }
elementNodeName = elemNode; elementNodeName = elemNode;
int elementSpan = collection.getCollectionTable() == null ? 0 : collection.getCollectionTable().values().size(); int elementSpan = collection.getPluralAttributeElementBinding().getRelationalValueBindings() == null ?
0 :
collection.getPluralAttributeElementBinding().getRelationalValueBindings().size();
elementColumnAliases = new String[elementSpan]; elementColumnAliases = new String[elementSpan];
elementColumnNames = new String[elementSpan]; elementColumnNames = new String[elementSpan];
elementColumnWriters = new String[elementSpan]; elementColumnWriters = new String[elementSpan];
@ -751,7 +754,8 @@ public abstract class AbstractCollectionPersister
boolean hasNotNullableColumns = false; boolean hasNotNullableColumns = false;
int j = 0; int j = 0;
if ( elementSpan > 0 ) { if ( elementSpan > 0 ) {
for ( Value value : collection.getCollectionTable().values() ) { for ( RelationalValueBinding relationalValueBinding : collection.getPluralAttributeElementBinding().getRelationalValueBindings() ) {
final Value value = relationalValueBinding.getValue();
elementColumnAliases[j] = value.getAlias( dialect ); elementColumnAliases[j] = value.getAlias( dialect );
if ( DerivedValue.class.isInstance( value ) ) { if ( DerivedValue.class.isInstance( value ) ) {
DerivedValue form = (DerivedValue) value; DerivedValue form = (DerivedValue) value;

View File

@ -55,7 +55,6 @@ public class SimpleElementSetTest extends BaseCoreFunctionalTestCase {
} }
@Test @Test
@FailureExpected( jiraKey = "HHH-6525")
public void testLoad() throws HibernateException, SQLException { public void testLoad() throws HibernateException, SQLException {
Session s = openSession(); Session s = openSession();
Transaction t = s.beginTransaction(); Transaction t = s.beginTransaction();
@ -69,7 +68,7 @@ public class SimpleElementSetTest extends BaseCoreFunctionalTestCase {
s = openSession(); s = openSession();
t = s.beginTransaction(); t = s.beginTransaction();
u = (User) s.get( User.class, "username" ); u = (User) s.get( User.class, "username" );
assertFalse( Hibernate.isInitialized( u.getSessionAttributeNames() ) ); assertTrue( Hibernate.isInitialized( u.getSessionAttributeNames() ) );
assertEquals( 2, u.getSessionAttributeNames().size() ); assertEquals( 2, u.getSessionAttributeNames().size() );
assertTrue( Hibernate.isInitialized( u.getSessionAttributeNames() ) ); assertTrue( Hibernate.isInitialized( u.getSessionAttributeNames() ) );
assertTrue( u.getSessionAttributeNames().contains( "name" ) ); assertTrue( u.getSessionAttributeNames().contains( "name" ) );