HHH-7907 Bind filter

This commit is contained in:
Strong Liu 2013-01-07 00:19:47 +08:00
parent 81089bab2b
commit fc1c6b6d41
4 changed files with 28 additions and 26 deletions

View File

@ -701,10 +701,7 @@ public final class SessionFactoryImpl
this.typeResolver = metadata.getTypeResolver().scope( this );
this.typeHelper = new TypeLocatorImpl( typeResolver );
this.filters = new HashMap<String, FilterDefinition>();
for ( FilterDefinition filterDefinition : metadata.getFilterDefinitions() ) {
filters.put( filterDefinition.getFilterName(), filterDefinition );
}
this.filters = Collections.unmodifiableMap( metadata.getFilterDefinitions() );
LOG.debugf( "Session factory constructed with filter configurations : %s", filters );
LOG.debugf( "Instantiating session factory with properties: %s", properties );

View File

@ -114,7 +114,7 @@ public interface Metadata {
public Iterable<TypeDefinition> getTypeDefinitions();
public Iterable<FilterDefinition> getFilterDefinitions();
public Map<String, FilterDefinition> getFilterDefinitions();
public Iterable<NamedQueryDefinition> getNamedQueryDefinitions();

View File

@ -48,6 +48,7 @@ import org.hibernate.engine.FetchTiming;
import org.hibernate.engine.config.spi.ConfigurationService;
import org.hibernate.engine.spi.CascadeStyle;
import org.hibernate.engine.spi.CascadeStyles;
import org.hibernate.engine.spi.FilterDefinition;
import org.hibernate.id.EntityIdentifierNature;
import org.hibernate.id.IdentifierGenerator;
import org.hibernate.id.IdentityGenerator;
@ -387,15 +388,7 @@ public class Binder {
resolveEntityLaziness( entityBinding, entitySource );
if ( entitySource.getFilterSources() != null ) {
for ( FilterSource filterSource : entitySource.getFilterSources() ) {
FilterConfiguration filterConfiguration = new FilterConfiguration(
filterSource.getName(),
filterSource.getCondition(),
filterSource.shouldAutoInjectAliases(),
filterSource.getAliasToTableMap(),
filterSource.getAliasToEntityMap(),
entityBinding
);
entityBinding.addFilterConfiguration( filterConfiguration );
entityBinding.addFilterConfiguration( createFilterConfiguration( filterSource, entityBinding ) );
}
}
// Register binding with metadata
@ -403,6 +396,26 @@ public class Binder {
return entityBinding;
}
private FilterConfiguration createFilterConfiguration(FilterSource filterSource, EntityBinding entityBinding){
String condition = filterSource.getCondition();
if(StringHelper.isEmpty( condition )){
FilterDefinition filterDefinition = metadata.getFilterDefinitions().get( filterSource.getName() );
if(filterDefinition == null){
throw bindingContext().makeMappingException( String.format( "Filter[$s] doesn't have a condition", filterSource.getName() ) );
}
condition = filterDefinition.getDefaultFilterCondition();
}
FilterConfiguration filterConfiguration = new FilterConfiguration(
filterSource.getName(),
condition,
filterSource.shouldAutoInjectAliases(),
filterSource.getAliasToTableMap(),
filterSource.getAliasToEntityMap(),
entityBinding
);
return filterConfiguration;
}
private void resolveEntityLaziness(
final EntityBinding entityBinding,
final EntitySource entitySource) {
@ -1354,15 +1367,7 @@ public class Binder {
if ( attributeSource.getFilterSources() != null ) {
for ( final FilterSource filterSource : attributeSource.getFilterSources() ) {
FilterConfiguration filterConfiguration = new FilterConfiguration(
filterSource.getName(),
filterSource.getCondition(),
filterSource.shouldAutoInjectAliases(),
filterSource.getAliasToTableMap(),
filterSource.getAliasToEntityMap(),
attributeBindingContainer.seekEntityBinding()
);
attributeBinding.addFilterConfiguration( filterConfiguration );
attributeBinding.addFilterConfiguration( createFilterConfiguration( filterSource, attributeBindingContainer.seekEntityBinding() ) );
}
}

View File

@ -320,9 +320,9 @@ public class MetadataImpl implements MetadataImplementor, Serializable {
}
filterDefinitionMap.put( filterDefinition.getFilterName(), filterDefinition );
}
public Iterable<FilterDefinition> getFilterDefinitions() {
return filterDefinitionMap.values();
@Override
public Map<String, FilterDefinition> getFilterDefinitions() {
return filterDefinitionMap;
}