HHH-6172 Adding annotation placeholders for annotation based state impls

This commit is contained in:
Hardy Ferentschik 2011-05-20 12:49:11 +02:00
parent 5385cc5cc0
commit 335eb1c231
8 changed files with 151 additions and 15 deletions

View File

@ -35,11 +35,11 @@ import java.util.Set;
*
* @author Steve Ebersole
*/
public abstract class AbstractAttributeContainer implements AttributeContainer, Hierarchical {
public abstract class AbstractAttributeContainer implements AttributeContainer, Hierarchical {
private final String name;
private final Hierarchical superType;
private LinkedHashSet<Attribute> attributeSet = new LinkedHashSet<Attribute>();
private HashMap<String,Attribute> attributeMap = new HashMap<String,Attribute>();
private HashMap<String, Attribute> attributeMap = new HashMap<String, Attribute>();
public AbstractAttributeContainer(String name, Hierarchical superType) {
this.name = name;
@ -108,6 +108,16 @@ public abstract class AbstractAttributeContainer implements AttributeContainer,
return attribute;
}
@Override
public String toString() {
final StringBuilder sb = new StringBuilder();
sb.append( "AbstractAttributeContainer" );
sb.append( "{name='" ).append( name ).append( '\'' );
sb.append( ", superType=" ).append( superType );
sb.append( '}' );
return sb.toString();
}
protected void addAttribute(Attribute attribute) {
// todo : how to best "secure" this?
if ( attributeMap.put( attribute.getName(), attribute ) != null ) {
@ -168,7 +178,7 @@ public abstract class AbstractAttributeContainer implements AttributeContainer,
private Type elementType;
public PluralAttributeImpl(String name, PluralAttributeNature nature, AttributeContainer attributeContainer) {
public PluralAttributeImpl(String name, PluralAttributeNature nature, AttributeContainer attributeContainer) {
this.name = name;
this.nature = nature;
this.attributeContainer = attributeContainer;

View File

@ -0,0 +1,41 @@
/*
* 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.source.annotations.entity;
/**
* @author Hardy Ferentschik
*/
public class AssociationAttribute {
private final MappedAttribute mappedAttribute;
public AssociationAttribute(MappedAttribute mappedAttribute) {
this.mappedAttribute = mappedAttribute;
}
public MappedAttribute getMappedAttribute() {
return mappedAttribute;
}
}

View File

@ -49,8 +49,8 @@ import org.hibernate.metamodel.source.annotations.HibernateDotNames;
import org.hibernate.metamodel.source.annotations.JPADotNames;
import org.hibernate.metamodel.source.annotations.entity.state.binding.AttributeBindingStateImpl;
import org.hibernate.metamodel.source.annotations.entity.state.binding.DiscriminatorBindingStateImpl;
import org.hibernate.metamodel.source.annotations.entity.state.relational.AttributeColumnRelationalState;
import org.hibernate.metamodel.source.annotations.entity.state.relational.AttributeTupleRelationalState;
import org.hibernate.metamodel.source.annotations.entity.state.relational.ColumnRelationalStateImpl;
import org.hibernate.metamodel.source.annotations.entity.state.relational.TupleRelationalStateImpl;
import org.hibernate.metamodel.source.annotations.util.JandexHelper;
import org.hibernate.metamodel.source.internal.MetadataImpl;
import org.hibernate.service.classloading.spi.ClassLoaderService;
@ -310,7 +310,7 @@ public class EntityBinder {
SimpleAttributeBinding attributeBinding = entityBinding.makeSimpleIdAttributeBinding( idName );
attributeBinding.initialize( new AttributeBindingStateImpl( idAttribute ) );
attributeBinding.initialize( new AttributeColumnRelationalState( idAttribute, meta ) );
attributeBinding.initialize( new ColumnRelationalStateImpl( idAttribute, meta ) );
}
private void bindAttributes(EntityBinding entityBinding) {
@ -344,10 +344,10 @@ public class EntityBinder {
attributeBinding.initialize( bindingState );
if ( configuredClass.hasOwnTable() ) {
AttributeColumnRelationalState columnRelationsState = new AttributeColumnRelationalState(
ColumnRelationalStateImpl columnRelationsState = new ColumnRelationalStateImpl(
mappedAttribute, meta
);
AttributeTupleRelationalState relationalState = new AttributeTupleRelationalState();
TupleRelationalStateImpl relationalState = new TupleRelationalStateImpl();
relationalState.addValueState( columnRelationsState );
// TODO: if this really just binds a column, then it can be changed to

View File

@ -0,0 +1,58 @@
/*
* 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.source.annotations.entity.state.binding;
import org.hibernate.metamodel.binding.state.ManyToOneAttributeBindingState;
import org.hibernate.metamodel.source.annotations.entity.AssociationAttribute;
/**
* @author Hardy Ferentschik
*/
public class ManyToOneBindingStateImpl extends AttributeBindingStateImpl implements ManyToOneAttributeBindingState {
public ManyToOneBindingStateImpl(AssociationAttribute associationAttribute) {
super( associationAttribute.getMappedAttribute() );
}
@Override
public boolean isUnwrapProxy() {
return false; //To change body of implemented methods use File | Settings | File Templates.
}
@Override
public String getReferencedAttributeName() {
return null; //To change body of implemented methods use File | Settings | File Templates.
}
@Override
public String getReferencedEntityName() {
return null; //To change body of implemented methods use File | Settings | File Templates.
}
@Override
public boolean ignoreNotFound() {
return false; //To change body of implemented methods use File | Settings | File Templates.
}
}

View File

@ -43,7 +43,7 @@ import org.hibernate.metamodel.source.internal.MetadataImpl;
/**
* @author Hardy Ferentschik
*/
public class AttributeColumnRelationalState implements ColumnRelationalState {
public class ColumnRelationalStateImpl implements ColumnRelationalState {
private final NamingStrategy namingStrategy;
private final String columnName;
private final boolean unique;
@ -61,7 +61,7 @@ public class AttributeColumnRelationalState implements ColumnRelationalState {
private Set<String> uniqueKeys = new HashSet<String>();
public AttributeColumnRelationalState(MappedAttribute attribute, MetadataImpl meta) {
public ColumnRelationalStateImpl(MappedAttribute attribute, MetadataImpl meta) {
ColumnValues columnValues = attribute.getColumnValues();
namingStrategy = meta.getNamingStrategy();
columnName = columnValues.getName().isEmpty() ? attribute.getName() : columnValues.getName();

View File

@ -0,0 +1,20 @@
package org.hibernate.metamodel.source.annotations.entity.state.relational;
import org.hibernate.metamodel.relational.state.ManyToOneRelationalState;
/**
* @author Hardy Ferentschik
*/
public class ManyToOneRelationalStateImpl extends TupleRelationalStateImpl implements ManyToOneRelationalState {
@Override
public boolean isLogicalOneToOne() {
return false; //To change body of implemented methods use File | Settings | File Templates.
}
@Override
public String getForeignKeyName() {
return null; //To change body of implemented methods use File | Settings | File Templates.
}
}

View File

@ -32,7 +32,7 @@ import org.hibernate.metamodel.relational.state.TupleRelationalState;
/**
* @author Hardy Ferentschik
*/
public class AttributeTupleRelationalState implements TupleRelationalState {
public class TupleRelationalStateImpl implements TupleRelationalState {
List<SimpleValueRelationalState> valueStates = new ArrayList<SimpleValueRelationalState>();
public void addValueState(SimpleValueRelationalState state) {

View File

@ -24,6 +24,7 @@
package org.hibernate.metamodel.binding;
import java.util.Iterator;
import java.util.Set;
import org.junit.After;
import org.junit.Before;
@ -37,6 +38,7 @@ import org.hibernate.service.ServiceRegistryBuilder;
import org.hibernate.service.internal.BasicServiceRegistryImpl;
import org.hibernate.testing.junit4.BaseUnitTestCase;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertFalse;
import static junit.framework.Assert.assertNotNull;
import static junit.framework.Assert.assertNull;
@ -94,11 +96,16 @@ public abstract class AbstractBasicBindingTests extends BaseUnitTestCase {
EntityBinding simpleEntityBinding = metadata.getEntityBinding( SimpleEntity.class.getName() );
assertIdAndSimpleProperty( simpleEntityBinding );
EntityBinding entityWithManyToOneBinding = metadata.getEntityBinding( ManyToOneEntity.class.getName() );
Set<EntityReferencingAttributeBinding> referenceBindings = simpleEntityBinding.getAttributeBinding( "id" )
.getEntityReferencingAttributeBindings();
assertEquals( "There should be only one reference binding", 1, referenceBindings.size() );
assertTrue(
1 == simpleEntityBinding.getAttributeBinding( "id" ).getEntityReferencingAttributeBindings().size()
);
EntityReferencingAttributeBinding referenceBinding = referenceBindings.iterator().next();
EntityBinding referencedEntityBinding = referenceBinding.getReferencedEntityBinding();
// TODO - Is this assertion correct (HF)?
assertEquals( "Should be the same entity binding", referencedEntityBinding, simpleEntityBinding );
EntityBinding entityWithManyToOneBinding = metadata.getEntityBinding( ManyToOneEntity.class.getName() );
Iterator<EntityReferencingAttributeBinding> it = entityWithManyToOneBinding.getEntityReferencingAttributeBindings()
.iterator();
assertTrue( it.hasNext() );