HHH-2394 Got filters working on sub-classes.

This commit is contained in:
Rob Worsnop 2012-05-15 15:44:32 -04:00 committed by Strong Liu
parent 1d2877838b
commit dbff4c1839
21 changed files with 350 additions and 38 deletions

View File

@ -1297,7 +1297,7 @@ public abstract class CollectionBinder {
private static void checkFilterConditions(Collection collValue) {
//for now it can't happen, but sometime soon...
if ( ( collValue.getFilterMap().size() != 0 || StringHelper.isNotEmpty( collValue.getWhere() ) ) &&
if ( ( collValue.getFilters().size() != 0 || StringHelper.isNotEmpty( collValue.getWhere() ) ) &&
collValue.getFetchMode() == FetchMode.JOIN &&
!( collValue.getElement() instanceof SimpleValue ) && //SimpleValue (CollectionOfElements) are always SELECT but it does not matter
collValue.getElement().getFetchMode() != FetchMode.JOIN ) {

View File

@ -0,0 +1,32 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2010, 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.internal;
/**
*
* @author Rob Worsnop
*
*/
public interface FilterAliasGenerator {
String getAlias(String table);
}

View File

@ -0,0 +1,48 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2010, 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.internal;
import org.hibernate.engine.spi.SessionFactoryImplementor;
/**
*
* @author Rob Worsnop
*/
public abstract class FilterConfiguration {
private final String name;
private final String condition;
protected FilterConfiguration(String name, String condition) {
this.name = name;
this.condition = condition;
}
public String getName() {
return name;
}
public String getCondition() {
return condition;
}
public abstract String getQualifiedTableName(SessionFactoryImplementor factory);
}

View File

@ -25,22 +25,27 @@
package org.hibernate.internal;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.hibernate.dialect.Dialect;
import org.hibernate.dialect.function.SQLFunctionRegistry;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.internal.util.StringHelper;
import org.hibernate.mapping.Table;
import org.hibernate.sql.Template;
/**
* Implementation of FilterHelper.
*
* @author Steve Ebersole
* @author Rob Worsnop
*/
public class FilterHelper {
private final String[] filterNames;
private final String[] filterConditions;
private final String[] filterTables;
/**
* The map of defined filters. This is expected to be in format
@ -49,28 +54,30 @@ public class FilterHelper {
*
* @param filters The map of defined filters.
* @param dialect The sql dialect
* @param functionRegistry The SQL function registry
* @param factory The session factory
*/
public FilterHelper(Map filters, Dialect dialect, SQLFunctionRegistry functionRegistry) {
public FilterHelper(List filters, Dialect dialect, SessionFactoryImplementor factory) {
int filterCount = filters.size();
filterNames = new String[filterCount];
filterConditions = new String[filterCount];
Iterator iter = filters.entrySet().iterator();
filterTables = new String[filterCount];
Iterator iter = filters.iterator();
filterCount = 0;
while ( iter.hasNext() ) {
final Map.Entry entry = (Map.Entry) iter.next();
filterNames[filterCount] = (String) entry.getKey();
final FilterConfiguration filter = (FilterConfiguration) iter.next();
filterNames[filterCount] = (String) filter.getName();
filterConditions[filterCount] = Template.renderWhereStringTemplate(
(String) entry.getValue(),
filter.getCondition(),
FilterImpl.MARKER,
dialect,
functionRegistry
factory.getSqlFunctionRegistry()
);
filterConditions[filterCount] = StringHelper.replace(
filterConditions[filterCount],
":",
":" + filterNames[filterCount] + "."
);
filterTables[filterCount] = filter.getQualifiedTableName(factory);
filterCount++;
}
}
@ -84,20 +91,20 @@ public class FilterHelper {
return false;
}
public String render(String alias, Map enabledFilters) {
public String render(FilterAliasGenerator aliasGenerator, Map enabledFilters) {
StringBuilder buffer = new StringBuilder();
render( buffer, alias, enabledFilters );
render( buffer, aliasGenerator, enabledFilters );
return buffer.toString();
}
public void render(StringBuilder buffer, String alias, Map enabledFilters) {
public void render(StringBuilder buffer, FilterAliasGenerator aliasGenerator, Map enabledFilters) {
if ( filterNames != null && filterNames.length > 0 ) {
for ( int i = 0, max = filterNames.length; i < max; i++ ) {
if ( enabledFilters.containsKey( filterNames[i] ) ) {
final String condition = filterConditions[i];
if ( StringHelper.isNotEmpty( condition ) ) {
buffer.append( " and " )
.append( StringHelper.replace( condition, FilterImpl.MARKER, alias ) );
.append( StringHelper.replace( condition, FilterImpl.MARKER, aliasGenerator.getAlias(filterTables[i]) ) );
}
}
}

View File

@ -0,0 +1,48 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2010, 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.internal;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.mapping.PersistentClass;
/**
*
* @author Rob Worsnop
*/
public class PersistentClassFilterConfiguration extends FilterConfiguration {
private final PersistentClass persistentClass;
public PersistentClassFilterConfiguration(String name, PersistentClass persistentClass, String condition) {
super(name, condition);
this.persistentClass = persistentClass;;
}
@Override
public String getQualifiedTableName(SessionFactoryImplementor factory) {
return persistentClass.getTable().getQualifiedName(factory.getDialect(),
factory.getSettings().getDefaultCatalogName(),
factory.getSettings().getDefaultSchemaName());
}
}

View File

@ -0,0 +1,45 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2010, 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.internal;
import org.hibernate.engine.spi.SessionFactoryImplementor;
/**
*
* @author Rob Worsnop
*/
public class QualifiedTableNameFilterConfiguration extends FilterConfiguration {
private final String tableName;
public QualifiedTableNameFilterConfiguration(String name, String tableName, String condition) {
super(name, condition);
this.tableName = tableName;
}
@Override
public String getQualifiedTableName(SessionFactoryImplementor factory) {
return tableName;
}
}

View File

@ -0,0 +1,45 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2010, 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.internal;
/**
*
* @author Rob Worsnop
*
*/
public class StaticFilterAliasGenerator implements FilterAliasGenerator{
private final String alias;
public StaticFilterAliasGenerator(String alias) {
this.alias = alias;
}
@Override
public String getAlias(String table) {
return alias;
}
}

View File

@ -22,6 +22,7 @@
* Boston, MA 02110-1301 USA
*/
package org.hibernate.mapping;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
@ -33,6 +34,8 @@ import org.hibernate.MappingException;
import org.hibernate.cfg.Mappings;
import org.hibernate.engine.spi.ExecuteUpdateResultCheckStyle;
import org.hibernate.engine.spi.Mapping;
import org.hibernate.internal.FilterConfiguration;
import org.hibernate.internal.QualifiedTableNameFilterConfiguration;
import org.hibernate.internal.util.ReflectHelper;
import org.hibernate.internal.util.collections.ArrayHelper;
import org.hibernate.internal.util.collections.EmptyIterator;
@ -81,8 +84,8 @@ public abstract class Collection implements Fetchable, Value, Filterable {
private Class collectionPersisterClass;
private String typeName;
private Properties typeParameters;
private final java.util.Map filters = new HashMap();
private final java.util.Map manyToManyFilters = new HashMap();
private final java.util.List filters = new ArrayList();
private final java.util.List manyToManyFilters = new ArrayList();
private final java.util.Set synchronizedTables = new HashSet();
private String customSQLInsert;
@ -520,18 +523,30 @@ public abstract class Collection implements Fetchable, Value, Filterable {
}
public void addFilter(String name, String condition) {
filters.put( name, condition );
filters.add(toFilterConfiguration(name, condition));
}
public java.util.Map getFilterMap() {
public java.util.List getFilters() {
return filters;
}
public void addManyToManyFilter(String name, String condition) {
manyToManyFilters.put( name, condition );
manyToManyFilters.add(toFilterConfiguration(name, condition));
}
private static FilterConfiguration toFilterConfiguration(String name, String condition){
String tableName = null;
String actualCondition = condition;
int pos = condition.lastIndexOf('.');
if (pos > -1){
tableName = condition.substring(0, pos);
actualCondition = condition.substring(pos+1);
}
return new QualifiedTableNameFilterConfiguration(name, tableName, actualCondition);
}
public java.util.Map getManyToManyFilterMap() {
public java.util.List getManyToManyFilters() {
return manyToManyFilters;
}

View File

@ -32,5 +32,5 @@ package org.hibernate.mapping;
public interface Filterable {
public void addFilter(String name, String condition);
public java.util.Map getFilterMap();
public java.util.List getFilters();
}

View File

@ -35,6 +35,8 @@ import org.hibernate.MappingException;
import org.hibernate.dialect.Dialect;
import org.hibernate.engine.spi.ExecuteUpdateResultCheckStyle;
import org.hibernate.engine.spi.Mapping;
import org.hibernate.internal.FilterConfiguration;
import org.hibernate.internal.PersistentClassFilterConfiguration;
import org.hibernate.internal.util.ReflectHelper;
import org.hibernate.internal.util.StringHelper;
import org.hibernate.internal.util.collections.EmptyIterator;
@ -76,7 +78,7 @@ public abstract class PersistentClass implements Serializable, Filterable, MetaA
private java.util.Map metaAttributes;
private ArrayList joins = new ArrayList();
private final ArrayList subclassJoins = new ArrayList();
private final java.util.Map filters = new HashMap();
private final java.util.List filters = new ArrayList();
protected final java.util.Set synchronizedTables = new HashSet();
private String loaderName;
private Boolean isAbstract;
@ -636,10 +638,10 @@ public abstract class PersistentClass implements Serializable, Filterable, MetaA
}
public void addFilter(String name, String condition) {
filters.put(name, condition);
filters.add(new PersistentClassFilterConfiguration(name, this, condition));
}
public java.util.Map getFilterMap() {
public java.util.List getFilters() {
return filters;
}

View File

@ -22,6 +22,7 @@
* Boston, MA 02110-1301 USA
*/
package org.hibernate.mapping;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
@ -254,8 +255,10 @@ public class Subclass extends PersistentClass {
return mv.accept(this);
}
public Map getFilterMap() {
return getSuperclass().getFilterMap();
public java.util.List getFilters() {
java.util.List filters = new ArrayList(super.getFilters());
filters.addAll(getSuperclass().getFilters());
return filters;
}
public boolean hasSubselectLoadableCollections() {

View File

@ -62,7 +62,9 @@ import org.hibernate.engine.spi.SubselectFetch;
import org.hibernate.exception.spi.SQLExceptionConverter;
import org.hibernate.id.IdentifierGenerator;
import org.hibernate.internal.CoreMessageLogger;
import org.hibernate.internal.FilterAliasGenerator;
import org.hibernate.internal.FilterHelper;
import org.hibernate.internal.StaticFilterAliasGenerator;
import org.hibernate.internal.util.StringHelper;
import org.hibernate.internal.util.collections.ArrayHelper;
import org.hibernate.jdbc.Expectation;
@ -573,10 +575,10 @@ public abstract class AbstractCollectionPersister
}
// Handle any filters applied to this collection
filterHelper = new FilterHelper( collection.getFilterMap(), dialect, factory.getSqlFunctionRegistry() );
filterHelper = new FilterHelper( collection.getFilters(), dialect, factory);
// Handle any filters applied to this collection for many-to-many
manyToManyFilterHelper = new FilterHelper( collection.getManyToManyFilterMap(), dialect, factory.getSqlFunctionRegistry() );
manyToManyFilterHelper = new FilterHelper( collection.getManyToManyFilters(), dialect, factory);
manyToManyWhereString = StringHelper.isNotEmpty( collection.getManyToManyWhere() ) ?
"( " + collection.getManyToManyWhere() + ")" :
null;
@ -1544,7 +1546,7 @@ public abstract class AbstractCollectionPersister
public String getManyToManyFilterFragment(String alias, Map enabledFilters) {
StringBuilder buffer = new StringBuilder();
manyToManyFilterHelper.render( buffer, alias, enabledFilters );
manyToManyFilterHelper.render( buffer, elementPersister.getFilterAliasGenerator(alias), enabledFilters );
if ( manyToManyWhereString != null ) {
buffer.append( " and " )
@ -1649,7 +1651,7 @@ public abstract class AbstractCollectionPersister
public String filterFragment(String alias, Map enabledFilters) throws MappingException {
StringBuilder sessionFilterFragment = new StringBuilder();
filterHelper.render( sessionFilterFragment, alias, enabledFilters );
filterHelper.render( sessionFilterFragment, getFilterAliasGenerator(alias), enabledFilters );
return sessionFilterFragment.append( filterFragment( alias ) ).toString();
}
@ -1929,4 +1931,6 @@ public abstract class AbstractCollectionPersister
}
}
}
public abstract FilterAliasGenerator getFilterAliasGenerator(final String rootAlias);
}

View File

@ -39,6 +39,8 @@ import org.hibernate.engine.spi.LoadQueryInfluencers;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.engine.spi.SubselectFetch;
import org.hibernate.internal.FilterAliasGenerator;
import org.hibernate.internal.StaticFilterAliasGenerator;
import org.hibernate.internal.util.collections.ArrayHelper;
import org.hibernate.jdbc.Expectation;
import org.hibernate.jdbc.Expectations;
@ -354,4 +356,9 @@ public class BasicCollectionPersister extends AbstractCollectionPersister {
);
}
@Override
public FilterAliasGenerator getFilterAliasGenerator(String rootAlias) {
return new StaticFilterAliasGenerator(rootAlias);
}
}

View File

@ -39,6 +39,7 @@ import org.hibernate.engine.spi.LoadQueryInfluencers;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.engine.spi.SubselectFetch;
import org.hibernate.internal.FilterAliasGenerator;
import org.hibernate.internal.util.collections.ArrayHelper;
import org.hibernate.jdbc.Expectation;
import org.hibernate.jdbc.Expectations;
@ -407,4 +408,9 @@ public class OneToManyPersister extends AbstractCollectionPersister {
.loadElement( session, key, incrementIndexByBase(index) );
}
@Override
public FilterAliasGenerator getFilterAliasGenerator(String rootAlias) {
return getElementPersister().getFilterAliasGenerator(rootAlias);
}
}

View File

@ -37,8 +37,6 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import org.jboss.logging.Logger;
import org.hibernate.AssertionFailure;
import org.hibernate.EntityMode;
import org.hibernate.FetchMode;
@ -73,7 +71,6 @@ import org.hibernate.engine.spi.ExecuteUpdateResultCheckStyle;
import org.hibernate.engine.spi.FilterDefinition;
import org.hibernate.engine.spi.LoadQueryInfluencers;
import org.hibernate.engine.spi.Mapping;
import org.hibernate.engine.spi.PersistenceContext;
import org.hibernate.engine.spi.PersistenceContext.NaturalIdHelper;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.engine.spi.SessionImplementor;
@ -84,7 +81,11 @@ import org.hibernate.id.PostInsertIdentityPersister;
import org.hibernate.id.insert.Binder;
import org.hibernate.id.insert.InsertGeneratedIdentifierDelegate;
import org.hibernate.internal.CoreMessageLogger;
import org.hibernate.internal.FilterAliasGenerator;
import org.hibernate.internal.FilterConfiguration;
import org.hibernate.internal.FilterHelper;
import org.hibernate.internal.StaticFilterAliasGenerator;
import org.hibernate.internal.PersistentClassFilterConfiguration;
import org.hibernate.internal.util.StringHelper;
import org.hibernate.internal.util.collections.ArrayHelper;
import org.hibernate.jdbc.Expectation;
@ -99,6 +100,7 @@ import org.hibernate.mapping.Component;
import org.hibernate.mapping.PersistentClass;
import org.hibernate.mapping.Property;
import org.hibernate.mapping.Selectable;
import org.hibernate.mapping.Table;
import org.hibernate.metadata.ClassMetadata;
import org.hibernate.metamodel.binding.AssociationAttributeBinding;
import org.hibernate.metamodel.binding.AttributeBinding;
@ -127,6 +129,7 @@ import org.hibernate.type.EntityType;
import org.hibernate.type.Type;
import org.hibernate.type.TypeHelper;
import org.hibernate.type.VersionType;
import org.jboss.logging.Logger;
/**
* Basic functionality for persisting an entity via JDBC
@ -767,7 +770,7 @@ public abstract class AbstractEntityPersister
}
// Handle any filters applied to the class level
filterHelper = new FilterHelper( persistentClass.getFilterMap(), factory.getDialect(), factory.getSqlFunctionRegistry() );
filterHelper = new FilterHelper( persistentClass.getFilters(), factory.getDialect(), factory );
temporaryIdTableName = persistentClass.getTemporaryIdTableName();
temporaryIdTableDDL = persistentClass.getTemporaryIdTableDDL();
@ -1086,11 +1089,13 @@ public abstract class AbstractEntityPersister
propertyDefinedOnSubclass = ArrayHelper.toBooleanArray( definedBySubclass );
Map<String, String> filterDefaultConditionsByName = new HashMap<String, String>();
List<FilterConfiguration> filterDefaultConditions = new ArrayList<FilterConfiguration>();
for ( FilterDefinition filterDefinition : entityBinding.getFilterDefinitions() ) {
filterDefaultConditionsByName.put( filterDefinition.getFilterName(), filterDefinition.getDefaultFilterCondition() );
filterDefaultConditions.add(new PersistentClassFilterConfiguration(filterDefinition.getFilterName(),
null,
filterDefinition.getDefaultFilterCondition()));
}
filterHelper = new FilterHelper( filterDefaultConditionsByName, factory.getDialect(), factory.getSqlFunctionRegistry() );
filterHelper = new FilterHelper( filterDefaultConditions, factory.getDialect(), factory);
temporaryIdTableName = null;
temporaryIdTableDDL = null;
@ -3416,8 +3421,7 @@ public abstract class AbstractEntityPersister
public String filterFragment(String alias, Map enabledFilters) throws MappingException {
final StringBuilder sessionFilterFragment = new StringBuilder();
filterHelper.render( sessionFilterFragment, generateFilterConditionAlias( alias ), enabledFilters );
filterHelper.render( sessionFilterFragment, getFilterAliasGenerator(alias), enabledFilters );
return sessionFilterFragment.append( filterFragment( alias ) ).toString();
}
@ -4734,6 +4738,10 @@ public abstract class AbstractEntityPersister
public void setPropertyValue(Object object, String propertyName, Object value) {
getEntityTuplizer().setPropertyValue( object, propertyName, value );
}
public FilterAliasGenerator getFilterAliasGenerator(final String rootAlias){
return new StaticFilterAliasGenerator(rootAlias);
}
@Override
public EntityMode getEntityMode() {

View File

@ -41,6 +41,7 @@ import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.engine.spi.ValueInclusion;
import org.hibernate.id.IdentifierGenerator;
import org.hibernate.internal.FilterAliasGenerator;
import org.hibernate.metadata.ClassMetadata;
import org.hibernate.tuple.entity.EntityMetamodel;
import org.hibernate.tuple.entity.EntityTuplizer;
@ -747,4 +748,6 @@ public interface EntityPersister extends OptimisticCacheSource {
public EntityTuplizer getEntityTuplizer();
public EntityInstrumentationMetadata getInstrumentationMetadata();
public FilterAliasGenerator getFilterAliasGenerator(final String rootAlias);
}

View File

@ -39,6 +39,7 @@ import org.hibernate.engine.OptimisticLockStyle;
import org.hibernate.engine.spi.ExecuteUpdateResultCheckStyle;
import org.hibernate.engine.spi.Mapping;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.internal.FilterAliasGenerator;
import org.hibernate.internal.util.collections.ArrayHelper;
import org.hibernate.mapping.Column;
import org.hibernate.mapping.Join;
@ -835,7 +836,7 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister {
public Declarer getSubclassPropertyDeclarer(String propertyPath) {
if ( "class".equals( propertyPath ) ) {
// special case where we need to force incloude all subclass joins
// special case where we need to force include all subclass joins
return Declarer.SUBCLASS;
}
return super.getSubclassPropertyDeclarer( propertyPath );
@ -860,4 +861,19 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister {
}
throw new HibernateException( "Could not locate table which owns column [" + columnName + "] referenced in order-by mapping" );
}
public FilterAliasGenerator getFilterAliasGenerator(final String rootAlias) {
return new FilterAliasGenerator() {
@Override
public String getAlias(String table) {
if (table == null){
return rootAlias;
} else{
JoinedSubclassEntityPersister outer = JoinedSubclassEntityPersister.this;
int tableNumber = JoinedSubclassEntityPersister.getTableId(table, outer.subclassTableNameClosure);
return outer.generateTableAlias(rootAlias, tableNumber);
}
}
};
}
}

View File

@ -818,6 +818,7 @@ arbitrary number of queries, and import declarations of arbitrary classes.
<xs:element name="sql-insert" minOccurs="0" type="sql-insert-element"/>
<xs:element name="sql-update" minOccurs="0" type="sql-update-element"/>
<xs:element name="sql-delete" minOccurs="0" type="sql-delete-element"/>
<xs:element name="filter" minOccurs="0" maxOccurs="unbounded" type="filter-element"/>
<xs:element name="fetch-profile" minOccurs="0" maxOccurs="unbounded" type="fetch-profile-element"/>
<xs:element name="resultset" minOccurs="0" maxOccurs="unbounded" type="resultset-element"/>
<xs:choice minOccurs="0" maxOccurs="unbounded">
@ -1586,6 +1587,7 @@ arbitrary number of queries, and import declarations of arbitrary classes.
<xs:element name="sql-insert" minOccurs="0" type="sql-insert-element"/>
<xs:element name="sql-update" minOccurs="0" type="sql-update-element"/>
<xs:element name="sql-delete" minOccurs="0" type="sql-delete-element"/>
<xs:element name="filter" minOccurs="0" maxOccurs="unbounded" type="filter-element"/>
<xs:element name="fetch-profile" minOccurs="0" maxOccurs="unbounded" type="fetch-profile-element"/>
<xs:element name="resultset" minOccurs="0" maxOccurs="unbounded" type="resultset-element"/>
<xs:choice minOccurs="0" maxOccurs="unbounded">
@ -1670,6 +1672,7 @@ arbitrary number of queries, and import declarations of arbitrary classes.
<xs:element name="sql-insert" minOccurs="0" type="sql-insert-element"/>
<xs:element name="sql-update" minOccurs="0" type="sql-update-element"/>
<xs:element name="sql-delete" minOccurs="0" type="sql-delete-element"/>
<xs:element name="filter" minOccurs="0" maxOccurs="unbounded" type="filter-element"/>
<xs:element name="fetch-profile" minOccurs="0" maxOccurs="unbounded" type="fetch-profile-element"/>
<xs:element name="resultset" minOccurs="0" maxOccurs="unbounded" type="resultset-element"/>
<xs:choice minOccurs="0" maxOccurs="unbounded">

View File

@ -43,6 +43,7 @@ import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.engine.spi.ValueInclusion;
import org.hibernate.id.IdentifierGenerator;
import org.hibernate.internal.FilterAliasGenerator;
import org.hibernate.mapping.Collection;
import org.hibernate.mapping.PersistentClass;
import org.hibernate.metadata.ClassMetadata;
@ -560,6 +561,12 @@ public class GoofyPersisterClassProvider implements PersisterClassResolver {
public EntityPersister getSubclassEntityPersister(Object instance, SessionFactoryImplementor factory) {
return null;
}
@Override
public FilterAliasGenerator getFilterAliasGenerator(String rootAlias) {
// TODO Auto-generated method stub
return null;
}
}
public static class NoopCollectionPersister implements CollectionPersister {

View File

@ -26,6 +26,8 @@ import org.hibernate.event.spi.PostLoadEvent;
import org.hibernate.event.spi.PreLoadEvent;
import org.hibernate.id.IdentifierGenerator;
import org.hibernate.id.UUIDHexGenerator;
import org.hibernate.internal.FilterAliasGenerator;
import org.hibernate.internal.StaticFilterAliasGenerator;
import org.hibernate.internal.util.compare.EqualsHelper;
import org.hibernate.mapping.PersistentClass;
import org.hibernate.metadata.ClassMetadata;
@ -644,4 +646,9 @@ public class CustomPersister implements EntityPersister {
public EntityInstrumentationMetadata getInstrumentationMetadata() {
return new NonPojoInstrumentationMetadata( getEntityName() );
}
@Override
public FilterAliasGenerator getFilterAliasGenerator(String rootAlias) {
return new StaticFilterAliasGenerator(rootAlias);
}
}

View File

@ -45,6 +45,7 @@ import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.engine.spi.ValueInclusion;
import org.hibernate.id.IdentifierGenerator;
import org.hibernate.internal.FilterAliasGenerator;
import org.hibernate.mapping.Collection;
import org.hibernate.mapping.PersistentClass;
import org.hibernate.metadata.ClassMetadata;
@ -582,6 +583,11 @@ public class PersisterClassProviderTest {
public EntityPersister getSubclassEntityPersister(Object instance, SessionFactoryImplementor factory) {
return null;
}
@Override
public FilterAliasGenerator getFilterAliasGenerator(String rootAlias) {
return null;
}
}
public static class GoofyException extends RuntimeException {