HHH-6495 Implementing ComponentAttributeSource#getPath and re-enabling EmbeddableBinding test. Still not sure about all the different implementation in ComponentAttributeSourceImpl. Most of them just don't seem to be relevant.

This commit is contained in:
Hardy Ferentschik 2011-07-29 12:43:37 +02:00
parent 85c63dbaf0
commit 425f41f5d6
3 changed files with 63 additions and 49 deletions

View File

@ -42,15 +42,25 @@ import org.hibernate.metamodel.source.binder.RelationalValueSource;
import org.hibernate.metamodel.source.binder.SingularAttributeNature;
/**
* Annotation backed implementation of {@code ComponentAttributeSource}.
*
* @author Steve Ebersole
* @author Hardy Ferentschik
*/
public class ComponentAttributeSourceImpl implements ComponentAttributeSource {
private final EmbeddableClass embeddableClass;
private final Value<Class<?>> classReference;
private final String path;
public ComponentAttributeSourceImpl(EmbeddableClass embeddableClass) {
this.embeddableClass = embeddableClass;
this.classReference = new Value<Class<?>>( embeddableClass.getClass() );
String tmpPath = embeddableClass.getEmbeddedAttributeName();
ConfiguredClass parent = embeddableClass.getParent();
while ( parent != null && parent instanceof EmbeddableClass ) {
tmpPath = ( (EmbeddableClass) parent ).getEmbeddedAttributeName() + "." + tmpPath;
}
path = tmpPath;
}
@Override
@ -79,16 +89,18 @@ public class ComponentAttributeSourceImpl implements ComponentAttributeSource {
}
@Override
public String getParentReferenceAttributeName() {
// see HHH-6501
return null;
public String getName() {
return embeddableClass.getEmbeddedAttributeName();
}
@Override
public String getPath() {
// todo : implement
// do not see how this is possible currently given how annotations currently handle components
return null;
public String getPropertyAccessorName() {
return embeddableClass.getClassAccessType().toString().toLowerCase();
}
@Override
public LocalBindingContext getLocalBindingContext() {
return embeddableClass.getLocalBindingContext();
}
@Override
@ -107,8 +119,26 @@ public class ComponentAttributeSourceImpl implements ComponentAttributeSource {
}
@Override
public LocalBindingContext getLocalBindingContext() {
return embeddableClass.getLocalBindingContext();
public String getPath() {
return path;
}
@Override
public Iterable<MetaAttributeSource> metaAttributes() {
// not relevant for annotations
return Collections.emptySet();
}
@Override
public List<RelationalValueSource> relationalValueSources() {
// none, they are defined on the simple sub-attributes
return null;
}
@Override
public String getParentReferenceAttributeName() {
// see HHH-6501
return null;
}
@Override
@ -117,32 +147,18 @@ public class ComponentAttributeSourceImpl implements ComponentAttributeSource {
return null;
}
@Override
public String getName() {
return embeddableClass.getEmbeddedAttributeName();
}
@Override
public String getPropertyAccessorName() {
// todo : implement
return null;
}
@Override
public boolean isInsertable() {
// todo : implement
return true;
}
@Override
public boolean isUpdatable() {
// todo : implement
return true;
}
@Override
public PropertyGeneration getGeneration() {
// todo : implement
return null;
}
@ -158,31 +174,18 @@ public class ComponentAttributeSourceImpl implements ComponentAttributeSource {
return true;
}
@Override
public Iterable<MetaAttributeSource> metaAttributes() {
return Collections.emptySet();
}
@Override
public boolean areValuesIncludedInInsertByDefault() {
// todo : implement
return true;
}
@Override
public boolean areValuesIncludedInUpdateByDefault() {
// todo : implement
return true;
}
@Override
public boolean areValuesNullableByDefault() {
// todo : implement
return true;
}
@Override
public List<RelationalValueSource> relationalValueSources() {
return null;
}
}

View File

@ -200,6 +200,10 @@ public class ConfiguredClass {
return attributeOverrideMap;
}
public AccessType getClassAccessType() {
return classAccessType;
}
@Override
public String toString() {
final StringBuilder sb = new StringBuilder();

View File

@ -30,34 +30,41 @@ import javax.persistence.Id;
import org.junit.Test;
import org.hibernate.metamodel.binding.ComponentAttributeBinding;
import org.hibernate.metamodel.binding.EntityBinding;
import org.hibernate.metamodel.domain.Component;
import org.hibernate.metamodel.domain.SingularAttribute;
import org.hibernate.testing.FailureExpected;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertNotNull;
import static junit.framework.Assert.assertTrue;
/**
* Tests for {@code j.p.Embeddable}.
* Tests for {@code javax.persistence.Embeddable}.
*
* @author Hardy Ferentschik
*/
@FailureExpected(jiraKey = "HHH-6447", message = "Work in progress")
public class EmbeddableBindingTest extends BaseAnnotationBindingTestCase {
@Test
//@Resources(annotatedClasses = { User.class, Address.class })
@Resources(annotatedClasses = { User.class, Address.class })
public void testEmbeddable() {
EntityBinding binding = getEntityBinding( User.class );
assertNotNull( binding.locateAttributeBinding( "street" ) );
assertNotNull( binding.locateAttributeBinding( "city" ) );
assertNotNull( binding.locateAttributeBinding( "postCode" ) );
SingularAttribute attribute = (SingularAttribute) binding.getEntity().locateAttribute( "address" );
assertTrue(
"Wrong container type. Should be a component",
attribute.getSingularAttributeType() instanceof Component
assertNotNull( binding.locateAttributeBinding( "address" ) );
assertTrue( binding.locateAttributeBinding( "address" ) instanceof ComponentAttributeBinding );
ComponentAttributeBinding componentBinding = (ComponentAttributeBinding) binding.locateAttributeBinding(
"address"
);
// todo - is this really correct? Does the path start w/ the class name
assertEquals(
"Wrong path",
"org.hibernate.metamodel.source.annotations.entity.EmbeddableBindingTest$User.address",
componentBinding.getPathBase()
);
assertNotNull( componentBinding.locateAttributeBinding( "street" ) );
assertNotNull( componentBinding.locateAttributeBinding( "city" ) );
assertNotNull( componentBinding.locateAttributeBinding( "postCode" ) );
}
@Entity