HHH-6300 Creating initial version of EntityBindingStateImpl. Removing un-used setters in EntityBinding

This commit is contained in:
Hardy Ferentschik 2011-06-13 14:28:50 +02:00
parent 671a6a38db
commit cbd92d05bc
3 changed files with 279 additions and 81 deletions

View File

@ -245,10 +245,6 @@ public class EntityBinding {
return caching;
}
public void setCaching(Caching caching) {
this.caching = caching;
}
public MetaAttributeContext getMetaAttributeContext() {
return metaAttributeContext;
}
@ -257,10 +253,6 @@ public class EntityBinding {
return mutable;
}
public void setMutable(boolean mutable) {
this.mutable = mutable;
}
public boolean isLazy() {
return lazy;
}
@ -269,10 +261,6 @@ public class EntityBinding {
this.lazy = lazy;
}
public void setProxyInterfaceName(String proxyInterfaceName) {
this.proxyInterfaceName = proxyInterfaceName;
}
public String getProxyInterfaceName() {
return proxyInterfaceName;
}
@ -281,26 +269,14 @@ public class EntityBinding {
return whereFilter;
}
public void setWhereFilter(String whereFilter) {
this.whereFilter = whereFilter;
}
public boolean isExplicitPolymorphism() {
return explicitPolymorphism;
}
public void setExplicitPolymorphism(boolean explicitPolymorphism) {
this.explicitPolymorphism = explicitPolymorphism;
}
public String getRowId() {
return rowId;
}
public void setRowId(String rowId) {
this.rowId = rowId;
}
public String getDiscriminatorValue() {
return entityDiscriminator == null ? null : entityDiscriminator.getDiscriminatorValue();
}
@ -309,34 +285,18 @@ public class EntityBinding {
return dynamicUpdate;
}
public void setDynamicUpdate(boolean dynamicUpdate) {
this.dynamicUpdate = dynamicUpdate;
}
public boolean isDynamicInsert() {
return dynamicInsert;
}
public void setDynamicInsert(boolean dynamicInsert) {
this.dynamicInsert = dynamicInsert;
}
public int getBatchSize() {
return batchSize;
}
public void setBatchSize(int batchSize) {
this.batchSize = batchSize;
}
public boolean isSelectBeforeUpdate() {
return selectBeforeUpdate;
}
public void setSelectBeforeUpdate(Boolean selectBeforeUpdate) {
this.selectBeforeUpdate = selectBeforeUpdate;
}
public boolean hasSubselectLoadableCollections() {
return hasSubselectLoadableCollections;
}
@ -350,18 +310,10 @@ public class EntityBinding {
return optimisticLockMode;
}
public void setOptimisticLockMode(int optimisticLockMode) {
this.optimisticLockMode = optimisticLockMode;
}
public Class getEntityPersisterClass() {
return entityPersisterClass;
}
public void setEntityPersisterClass(Class entityPersisterClass) {
this.entityPersisterClass = entityPersisterClass;
}
public Boolean isAbstract() {
return isAbstract;
}

View File

@ -58,13 +58,13 @@ 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.binding.EntityBindingStateImpl;
import org.hibernate.metamodel.source.annotations.entity.state.binding.ManyToOneBindingStateImpl;
import org.hibernate.metamodel.source.annotations.entity.state.relational.ColumnRelationalStateImpl;
import org.hibernate.metamodel.source.annotations.entity.state.relational.ManyToOneRelationalStateImpl;
import org.hibernate.metamodel.source.annotations.entity.state.relational.TupleRelationalStateImpl;
import org.hibernate.metamodel.source.annotations.global.IdGeneratorBinder;
import org.hibernate.metamodel.source.annotations.util.JandexHelper;
import org.hibernate.metamodel.source.internal.MetadataImpl;
import org.hibernate.metamodel.source.spi.MetadataImplementor;
import org.hibernate.service.classloading.spi.ClassLoaderService;
@ -86,19 +86,20 @@ public class EntityBinder {
public void bind() {
EntityBinding entityBinding = new EntityBinding();
EntityBindingStateImpl entityBindingState = new EntityBindingStateImpl( configuredClass );
bindJpaEntityAnnotation( entityBinding );
bindHibernateEntityAnnotation( entityBinding ); // optional hibernate specific @org.hibernate.annotations.Entity
bindJpaEntityAnnotation( entityBinding, entityBindingState );
bindHibernateEntityAnnotation( entityBindingState ); // optional hibernate specific @org.hibernate.annotations.Entity
schemaName = createSchemaName();
bindTable( entityBinding );
bindInheritance( entityBinding );
bindWhereFilter( entityBinding );
bindJpaCaching( entityBinding );
bindHibernateCaching( entityBinding );
bindProxy( entityBinding );
bindWhereFilter( entityBindingState );
bindJpaCaching( entityBindingState );
bindHibernateCaching( entityBindingState );
bindProxy( entityBindingState );
// take care of the id, attributes and relations
if ( configuredClass.isRoot() ) {
@ -108,7 +109,8 @@ public class EntityBinder {
// bind all attributes - simple as well as associations
bindAttributes( entityBinding );
// last, but not least we register the new EntityBinding with the metadata
// last, but not least we initialize and register the new EntityBinding
entityBinding.initialize( entityBindingState );
meta.addEntity( entityBinding );
}
@ -146,18 +148,18 @@ public class EntityBinder {
}
}
private void bindWhereFilter(EntityBinding entityBinding) {
private void bindWhereFilter(EntityBindingStateImpl entityBindingState) {
AnnotationInstance whereAnnotation = JandexHelper.getSingleAnnotation(
configuredClass.getClassInfo(), HibernateDotNames.WHERE
);
if ( whereAnnotation != null ) {
// no null check needed, it is a required attribute
String clause = whereAnnotation.value( "clause" ).asString();
entityBinding.setWhereFilter( clause );
entityBindingState.setWhereFilter( clause );
}
}
private void bindHibernateCaching(EntityBinding entityBinding) {
private void bindHibernateCaching(EntityBindingStateImpl entityBindingState) {
AnnotationInstance cacheAnnotation = JandexHelper.getSingleAnnotation(
configuredClass.getClassInfo(), HibernateDotNames.CACHE
);
@ -170,7 +172,7 @@ public class EntityBinder {
region = cacheAnnotation.value( "region" ).asString();
}
else {
region = entityBinding.getEntity().getName();
region = entityBindingState.getEntityName();
}
boolean cacheLazyProperties = true;
@ -191,12 +193,12 @@ public class EntityBinder {
cacheAnnotation.value( "usage" ).asEnum()
);
Caching caching = new Caching( region, strategy.toAccessType(), cacheLazyProperties );
entityBinding.setCaching( caching );
entityBindingState.setCaching( caching );
}
// This does not take care of any inheritance of @Cacheable within a class hierarchy as specified in JPA2.
// This is currently not supported (HF)
private void bindJpaCaching(EntityBinding entityBinding) {
private void bindJpaCaching(EntityBindingStateImpl entityBindingState) {
AnnotationInstance cacheAnnotation = JandexHelper.getSingleAnnotation(
configuredClass.getClassInfo(), JPADotNames.CACHEABLE
);
@ -209,18 +211,18 @@ public class EntityBinder {
Caching caching = null;
switch ( meta.getOptions().getSharedCacheMode() ) {
case ALL: {
caching = createCachingForCacheableAnnotation( entityBinding );
caching = createCachingForCacheableAnnotation( entityBindingState );
break;
}
case ENABLE_SELECTIVE: {
if ( cacheable ) {
caching = createCachingForCacheableAnnotation( entityBinding );
caching = createCachingForCacheableAnnotation( entityBindingState );
}
break;
}
case DISABLE_SELECTIVE: {
if ( cacheAnnotation == null || cacheable ) {
caching = createCachingForCacheableAnnotation( entityBinding );
caching = createCachingForCacheableAnnotation( entityBindingState );
}
break;
}
@ -230,11 +232,11 @@ public class EntityBinder {
}
}
if ( caching != null ) {
entityBinding.setCaching( caching );
entityBindingState.setCaching( caching );
}
}
private void bindProxy(EntityBinding entityBinding) {
private void bindProxy(EntityBindingStateImpl entityBindingState) {
AnnotationInstance proxyAnnotation = JandexHelper.getSingleAnnotation(
configuredClass.getClassInfo(), HibernateDotNames.PROXY
);
@ -253,12 +255,12 @@ public class EntityBinder {
}
}
entityBinding.setLazy( lazy );
entityBinding.setProxyInterfaceName( proxyInterfaceClass );
entityBindingState.setLazy( lazy );
entityBindingState.setProxyInterfaceName( proxyInterfaceClass );
}
private Caching createCachingForCacheableAnnotation(EntityBinding entityBinding) {
String region = entityBinding.getEntity().getName();
private Caching createCachingForCacheableAnnotation(EntityBindingStateImpl entityBindingState) {
String region = entityBindingState.getEntityName();
RegionFactory regionFactory = meta.getServiceRegistry().getService( RegionFactory.class );
AccessType defaultAccessType = regionFactory.getDefaultAccessType();
return new Caching( region, defaultAccessType, true );
@ -300,7 +302,6 @@ public class EntityBinder {
}
private void bindId(EntityBinding entityBinding) {
entityBinding.setRoot( true );
switch ( configuredClass.getIdType() ) {
case SIMPLE: {
bindSingleIdAnnotation( entityBinding );
@ -320,7 +321,7 @@ public class EntityBinder {
}
private void bindJpaEntityAnnotation(EntityBinding entityBinding) {
private void bindJpaEntityAnnotation(EntityBinding entityBinding, EntityBindingStateImpl entityBindingState) {
AnnotationInstance jpaEntityAnnotation = JandexHelper.getSingleAnnotation(
configuredClass.getClassInfo(), JPADotNames.ENTITY
);
@ -331,6 +332,7 @@ public class EntityBinder {
else {
name = jpaEntityAnnotation.value( "name" ).asString();
}
entityBindingState.setEntityName( name );
entityBinding.setEntity( new Entity( name, getSuperType() ) );
}
@ -489,7 +491,7 @@ public class EntityBinder {
}
}
private void bindHibernateEntityAnnotation(EntityBinding entityBinding) {
private void bindHibernateEntityAnnotation(EntityBindingStateImpl entityBindingState) {
// initialize w/ the defaults
boolean mutable = true;
boolean dynamicInsert = false;
@ -534,7 +536,7 @@ public class EntityBinder {
ClassLoaderService classLoaderService = meta.getServiceRegistry()
.getService( ClassLoaderService.class );
Class<?> persisterClass = classLoaderService.classForName( persister );
entityBinding.setEntityPersisterClass( persisterClass );
entityBindingState.setPersisterClass( persisterClass );
}
}
@ -546,12 +548,12 @@ public class EntityBinder {
mutable = false;
}
entityBinding.setMutable( mutable );
entityBinding.setDynamicInsert( dynamicInsert );
entityBinding.setDynamicUpdate( dynamicUpdate );
entityBinding.setSelectBeforeUpdate( selectBeforeUpdate );
entityBinding.setExplicitPolymorphism( PolymorphismType.EXPLICIT.equals( polymorphism ) );
entityBinding.setOptimisticLockMode( optimisticLock.ordinal() );
entityBindingState.setMutable( mutable );
entityBindingState.setDynamicInsert( dynamicInsert );
entityBindingState.setDynamicUpdate( dynamicUpdate );
entityBindingState.setSelectBeforeUpdate( selectBeforeUpdate );
entityBindingState.setExplicitPolymorphism( PolymorphismType.EXPLICIT.equals( polymorphism ) );
entityBindingState.setOptimisticLock( optimisticLock );
}
private Hierarchical getSuperType() {

View File

@ -0,0 +1,244 @@
/*
* 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 java.util.List;
import org.hibernate.annotations.OptimisticLockType;
import org.hibernate.metamodel.binding.Caching;
import org.hibernate.metamodel.binding.CustomSQL;
import org.hibernate.metamodel.binding.InheritanceType;
import org.hibernate.metamodel.binding.state.EntityBindingState;
import org.hibernate.metamodel.source.annotations.entity.ConfiguredClass;
import org.hibernate.metamodel.source.spi.MetaAttributeContext;
/**
* @author Hardy Ferentschik
*/
public class EntityBindingStateImpl implements EntityBindingState {
private final boolean isRoot;
private final InheritanceType inheritanceType;
private String entityName;
private Caching caching;
private MetaAttributeContext metaAttributeContext;
private boolean mutable;
private boolean explicitPolymorphism;
private String whereFilter;
private String rowId;
private boolean dynamicUpdate;
private boolean dynamicInsert;
private int batchSize;
private boolean selectBeforeUpdate;
private OptimisticLockType optimisticLock;
private Class<?> persisterClass;
private boolean isAbstract;
private boolean lazy;
private String proxyInterfaceName;
private CustomSQL customInsert;
private CustomSQL customUpdate;
private CustomSQL customDelete;
private List<String> synchronizedTableNames;
public EntityBindingStateImpl(ConfiguredClass configuredClass) {
this.isRoot = configuredClass.isRoot();
this.inheritanceType = configuredClass.getInheritanceType();
// TODO: where do these values come from?
this.metaAttributeContext = null;
this.rowId = null;
this.batchSize = -1;
this.isAbstract = false;
this.customInsert = null;
this.customUpdate = null;
this.customDelete = null;
this.synchronizedTableNames = null;
}
public void setEntityName(String entityName) {
this.entityName = entityName;
}
public String getEntityName() {
return entityName;
}
public void setCaching(Caching caching) {
this.caching = caching;
}
public void setMutable(boolean mutable) {
this.mutable = mutable;
}
public void setExplicitPolymorphism(boolean explicitPolymorphism) {
this.explicitPolymorphism = explicitPolymorphism;
}
public void setWhereFilter(String whereFilter) {
this.whereFilter = whereFilter;
}
public void setDynamicUpdate(boolean dynamicUpdate) {
this.dynamicUpdate = dynamicUpdate;
}
public void setDynamicInsert(boolean dynamicInsert) {
this.dynamicInsert = dynamicInsert;
}
public void setSelectBeforeUpdate(boolean selectBeforeUpdate) {
this.selectBeforeUpdate = selectBeforeUpdate;
}
public void setOptimisticLock(OptimisticLockType optimisticLock) {
this.optimisticLock = optimisticLock;
}
public void setPersisterClass(Class<?> persisterClass) {
this.persisterClass = persisterClass;
}
public void setLazy(boolean lazy) {
this.lazy = lazy;
}
public void setProxyInterfaceName(String proxyInterfaceName) {
this.proxyInterfaceName = proxyInterfaceName;
}
@Override
public boolean isRoot() {
return isRoot;
}
@Override
public InheritanceType getEntityInheritanceType() {
return inheritanceType;
}
@Override
public Caching getCaching() {
return caching;
}
@Override
public MetaAttributeContext getMetaAttributeContext() {
return metaAttributeContext;
}
@Override
public String getProxyInterfaceName() {
return proxyInterfaceName;
}
@Override
public boolean isLazy() {
return lazy;
}
@Override
public boolean isMutable() {
return mutable;
}
@Override
public boolean isExplicitPolymorphism() {
return explicitPolymorphism;
}
@Override
public String getWhereFilter() {
return whereFilter;
}
@Override
public String getRowId() {
return rowId;
}
@Override
public boolean isDynamicUpdate() {
return dynamicUpdate;
}
@Override
public boolean isDynamicInsert() {
return dynamicInsert;
}
@Override
public int getBatchSize() {
return batchSize;
}
@Override
public boolean isSelectBeforeUpdate() {
return selectBeforeUpdate;
}
@Override
public int getOptimisticLockMode() {
return optimisticLock.ordinal();
}
@Override
public Class getEntityPersisterClass() {
return persisterClass;
}
@Override
public Boolean isAbstract() {
return isAbstract;
}
@Override
public CustomSQL getCustomInsert() {
return customInsert;
}
@Override
public CustomSQL getCustomUpdate() {
return customUpdate;
}
@Override
public CustomSQL getCustomDelete() {
return customDelete;
}
@Override
public List<String> getSynchronizedTableNames() {
return synchronizedTableNames;
}
}