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;
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.
@ -33,7 +34,7 @@ import org.hibernate.metamodel.spi.relational.Value;
public abstract class AbstractPluralAttributeElementBinding implements PluralAttributeElementBinding {
private final AbstractPluralAttributeBinding pluralAttributeBinding;
private final HibernateTypeDescriptor hibernateTypeDescriptor = new HibernateTypeDescriptor();
private Value relationalValue;
private List<RelationalValueBinding> relationalValueBindings;
AbstractPluralAttributeElementBinding(AbstractPluralAttributeBinding pluralAttributeBinding) {
this.pluralAttributeBinding = pluralAttributeBinding;
@ -50,7 +51,11 @@ public abstract class AbstractPluralAttributeElementBinding implements PluralAtt
}
@Override
public Value getRelationalValue() {
return relationalValue;
public List<RelationalValueBinding> getRelationalValueBindings() {
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;
import java.util.Collections;
import java.util.List;
/**
@ -33,7 +32,6 @@ import java.util.List;
* @author Gail Badner
*/
public class BasicPluralAttributeElementBinding extends AbstractPluralAttributeElementBinding {
private List<RelationalValueBinding> relationalValueBindings;
private boolean hasDerivedValue;
private boolean isNullable = true;
@ -42,18 +40,14 @@ public class BasicPluralAttributeElementBinding extends AbstractPluralAttributeE
super( binding );
}
public List<RelationalValueBinding> getRelationalValueBindings() {
return relationalValueBindings;
}
@Override
public PluralAttributeElementNature getPluralAttributeElementNature() {
return PluralAttributeElementNature.BASIC;
}
public void setRelationalValueBindings(List<RelationalValueBinding> relationalValueBindings) {
this.relationalValueBindings = Collections.unmodifiableList( relationalValueBindings );
for ( RelationalValueBinding relationalValueBinding : relationalValueBindings ) {
super.setRelationalValueBindings( relationalValueBindings );
for ( RelationalValueBinding relationalValueBinding : getRelationalValueBindings() ) {
this.hasDerivedValue = this.hasDerivedValue || relationalValueBinding.isDerived();
this.isNullable = this.isNullable && relationalValueBinding.isNullable();
}

View File

@ -23,7 +23,7 @@
*/
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).
@ -44,7 +44,7 @@ public interface PluralAttributeElementBinding {
*
* @return The relation information.
*/
public Value getRelationalValue();
public List<RelationalValueBinding> getRelationalValueBindings();
/**
* 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.PluralAttributeElementBinding;
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.relational.DerivedValue;
import org.hibernate.metamodel.spi.relational.TableSpecification;
@ -737,7 +738,9 @@ public abstract class AbstractCollectionPersister
}
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];
elementColumnNames = new String[elementSpan];
elementColumnWriters = new String[elementSpan];
@ -751,7 +754,8 @@ public abstract class AbstractCollectionPersister
boolean hasNotNullableColumns = false;
int j = 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 );
if ( DerivedValue.class.isInstance( value ) ) {
DerivedValue form = (DerivedValue) value;

View File

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