HHH-2394 Prefixes won't work; need table set explicitly

This commit is contained in:
Rob Worsnop 2012-05-18 10:00:59 -04:00 committed by Strong Liu
parent dbff4c1839
commit ee01d80677
8 changed files with 24 additions and 31 deletions

View File

@ -36,11 +36,12 @@ import static java.lang.annotation.RetentionPolicy.RUNTIME;
* @author Emmanuel Bernard
* @author Matthew Inger
* @author Magnus Sandberg
* @author Rob Worsnop
*/
@Target({TYPE, METHOD, FIELD})
@Retention(RUNTIME)
public @interface Filter {
String name();
String table() default "";
String condition() default "";
}

View File

@ -2614,6 +2614,7 @@ public final class HbmBinder {
while ( filters.hasNext() ) {
final Element filterElement = ( Element ) filters.next();
final String name = filterElement.attributeValue( "name" );
final String tableName = filterElement.attributeValue("table");
String condition = filterElement.getTextTrim();
if ( StringHelper.isEmpty(condition) ) condition = filterElement.attributeValue( "condition" );
if ( StringHelper.isEmpty(condition) ) {
@ -2625,7 +2626,7 @@ public final class HbmBinder {
if ( LOG.isDebugEnabled() ) {
LOG.debugf( "Applying many-to-many filter [%s] as [%s] to role [%s]", name, condition, collection.getRole() );
}
collection.addManyToManyFilter( name, condition );
collection.addManyToManyFilter( name, tableName, condition );
}
}
@ -3014,6 +3015,7 @@ public final class HbmBinder {
private static void parseFilter(Element filterElement, Filterable filterable, Mappings model) {
final String name = filterElement.attributeValue( "name" );
final String tableName = filterElement.attributeValue("table");
String condition = filterElement.getTextTrim();
if ( StringHelper.isEmpty(condition) ) {
condition = filterElement.attributeValue( "condition" );
@ -3031,7 +3033,7 @@ public final class HbmBinder {
throw new MappingException("no filter condition found for filter: " + name);
}
LOG.debugf( "Applying filter [%s] as [%s]", name, condition );
filterable.addFilter( name, condition );
filterable.addFilter( name, tableName, condition );
}
private static void parseFetchProfile(Element element, Mappings mappings, String containingEntityName) {

View File

@ -810,27 +810,27 @@ public abstract class CollectionBinder {
//if ( StringHelper.isNotEmpty( where ) ) collection.setWhere( where );
if ( simpleFilter != null ) {
if ( hasAssociationTable ) {
collection.addManyToManyFilter( simpleFilter.name(), getCondition( simpleFilter ) );
collection.addManyToManyFilter( simpleFilter.name(), getTableName(simpleFilter), getCondition( simpleFilter ) );
}
else {
collection.addFilter( simpleFilter.name(), getCondition( simpleFilter ) );
collection.addFilter( simpleFilter.name(), getTableName(simpleFilter), getCondition( simpleFilter ) );
}
}
Filters filters = property.getAnnotation( Filters.class );
if ( filters != null ) {
for (Filter filter : filters.value()) {
if ( hasAssociationTable ) {
collection.addManyToManyFilter( filter.name(), getCondition( filter ) );
collection.addManyToManyFilter( filter.name(), getTableName(simpleFilter), getCondition( filter ) );
}
else {
collection.addFilter( filter.name(), getCondition( filter ) );
collection.addFilter( filter.name(), getTableName(simpleFilter), getCondition( filter ) );
}
}
}
FilterJoinTable simpleFilterJoinTable = property.getAnnotation( FilterJoinTable.class );
if ( simpleFilterJoinTable != null ) {
if ( hasAssociationTable ) {
collection.addFilter( simpleFilterJoinTable.name(), getCondition( simpleFilterJoinTable ) );
collection.addFilter( simpleFilterJoinTable.name(), null, getCondition( simpleFilterJoinTable ) );
}
else {
throw new AnnotationException(
@ -843,7 +843,7 @@ public abstract class CollectionBinder {
if ( filterJoinTables != null ) {
for (FilterJoinTable filter : filterJoinTables.value()) {
if ( hasAssociationTable ) {
collection.addFilter( filter.name(), getCondition( filter ) );
collection.addFilter( filter.name(), null, getCondition( filter ) );
}
else {
throw new AnnotationException(
@ -896,6 +896,10 @@ public abstract class CollectionBinder {
return getCondition( cond, name );
}
private String getTableName(Filter filter){
return BinderHelper.isEmptyAnnotationValue(filter.table())? null : filter.table();
}
private String getCondition(Filter filter) {
//set filtering
String name = filter.name();

View File

@ -384,7 +384,7 @@ public class EntityBinder {
);
}
}
persistentClass.addFilter( filterName, cond );
persistentClass.addFilter( filterName, null, cond );
}
}
else if ( filters.size() > 0 ) {

View File

@ -24,7 +24,6 @@
package org.hibernate.mapping;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Properties;
@ -34,7 +33,6 @@ 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;
@ -522,30 +520,18 @@ public abstract class Collection implements Fetchable, Value, Filterable {
return deleteAllCheckStyle;
}
public void addFilter(String name, String condition) {
filters.add(toFilterConfiguration(name, condition));
public void addFilter(String name, String tableName, String condition) {
filters.add(new QualifiedTableNameFilterConfiguration(name, tableName, condition));
}
public java.util.List getFilters() {
return filters;
}
public void addManyToManyFilter(String name, String condition) {
manyToManyFilters.add(toFilterConfiguration(name, condition));
public void addManyToManyFilter(String name, String tableName, String condition) {
manyToManyFilters.add(new QualifiedTableNameFilterConfiguration(name, tableName, 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.List getManyToManyFilters() {
return manyToManyFilters;
}

View File

@ -30,7 +30,7 @@ package org.hibernate.mapping;
* @author Steve Ebersole
*/
public interface Filterable {
public void addFilter(String name, String condition);
public void addFilter(String name, String tableName, String condition);
public java.util.List getFilters();
}

View File

@ -35,7 +35,6 @@ 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;
@ -637,7 +636,7 @@ public abstract class PersistentClass implements Serializable, Filterable, MetaA
return deleteCheckStyle;
}
public void addFilter(String name, String condition) {
public void addFilter(String name, String tableName, String condition) {
filters.add(new PersistentClassFilterConfiguration(name, this, condition));
}

View File

@ -677,6 +677,7 @@ arbitrary number of queries, and import declarations of arbitrary classes.
<xs:complexType name="filter-element" mixed="true">
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="table" type="xs:string"/>
<xs:attribute name="condition" type="xs:string"/>
<xs:attribute name="name" use="required" type="xs:string"/>
</xs:extension>