org.hibernate.impl.FilterImpl Java Examples

The following examples show how to use org.hibernate.impl.FilterImpl. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PersistentOwnedList.java    From webdsl with Apache License 2.0 6 votes vote down vote up
protected FilterImpl getAffectingFilter(utils.AbstractOwnedListType type) {
	SessionImplementor session = getSession();
	FilterImpl filter = null;
	LoadQueryInfluencers lqi = session.getLoadQueryInfluencers();
	if(lqi != null) {
		java.util.Map filters = lqi.getEnabledFilters();
		for(Object entry : filters.entrySet()) {
			if(!(entry instanceof java.util.Map.Entry)) continue;
			Object key = ((java.util.Map.Entry)entry).getKey();
			Object value = ((java.util.Map.Entry)entry).getValue();
			if(key != null && value != null && value instanceof org.hibernate.impl.FilterImpl && type.isAffectedBy(key.toString())) {
				if(filter == null) {
					filter = (org.hibernate.impl.FilterImpl) value;
				} else {
					throw new java.lang.UnsupportedOperationException("Filters '" + filter.getName() + "' and '" + key.toString() + "' both filter the same collection role" + (getRole() == null ? "." : " (" + getRole() + ")."));
				}
			}
		}
	}
	return filter;
}
 
Example #2
Source File: PersistentOwnedList.java    From webdsl with Apache License 2.0 6 votes vote down vote up
@Override
public boolean endRead() {
	boolean result = super.endRead();
	((utils.OwnedList)list).setDoEvents(true); // We should resume updating the inverse, because initialization is complete

	if(this.restoreFilter != null) {
		// Restore the filter that was enabled before enabling the filter hint
		SessionImplementor session = getSession();
		org.hibernate.engine.LoadQueryInfluencers lqi = session.getLoadQueryInfluencers();
		org.hibernate.impl.FilterImpl oldFilter = this.getAffectingFilter();
		if(oldFilter != null) lqi.disableFilter(oldFilter.getName());
		utils.QueryOptimization.restoreFilter(lqi, this.restoreFilter);
		this.restoreFilter = null;
	}

	return result;
}
 
Example #3
Source File: PersistentOwnedSet.java    From webdsl with Apache License 2.0 6 votes vote down vote up
protected FilterImpl getAffectingFilter(utils.AbstractOwnedSetType type) {
	SessionImplementor session = getSession();
	FilterImpl filter = null;
	LoadQueryInfluencers lqi = session.getLoadQueryInfluencers();
	if(lqi != null) {
		java.util.Map filters = lqi.getEnabledFilters();
		for(Object entry : filters.entrySet()) {
			if(!(entry instanceof java.util.Map.Entry)) continue;
			Object key = ((java.util.Map.Entry)entry).getKey();
			Object value = ((java.util.Map.Entry)entry).getValue();
			if(key != null && value != null && value instanceof org.hibernate.impl.FilterImpl && type.isAffectedBy(key.toString())) {
				if(filter == null) {
					filter = (org.hibernate.impl.FilterImpl) value;
				} else {
					throw new java.lang.UnsupportedOperationException("Filters '" + filter.getName() + "' and '" + key.toString() + "' both filter the same collection role" + (getRole() == null ? "." : " (" + getRole() + ")."));
				}
			}
		}
	}
	return filter;
}
 
Example #4
Source File: PersistentOwnedSet.java    From webdsl with Apache License 2.0 6 votes vote down vote up
@Override
public boolean endRead() {
	//afterInitialize(); // Needed for DelayedOperations
	boolean result = super.endRead();
	((utils.OwnedSet)set).setDoEvents(true); // We should resume updating the inverse, because initialization is complete

	if(this.restoreFilter != null) {
		// Restore the filter that was enabled before enabling the filter hint
		SessionImplementor session = getSession();
		org.hibernate.engine.LoadQueryInfluencers lqi = session.getLoadQueryInfluencers();
		org.hibernate.impl.FilterImpl oldFilter = this.getAffectingFilter();
		if(oldFilter != null) lqi.disableFilter(oldFilter.getName());
		utils.QueryOptimization.restoreFilter(lqi, this.restoreFilter);
		this.restoreFilter = null;
	}

	return result;
}
 
Example #5
Source File: FilterHelper.java    From cacheonix-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * The map of defined filters.  This is expected to be in format
 * where the filter names are the map keys, and the defined
 * conditions are the values.
 *
 * @param filters The map of defined filters.
 * @param dialect The sql dialect
 * @param functionRegistry The SQL function registry
 */
public FilterHelper(Map filters, Dialect dialect, SQLFunctionRegistry functionRegistry) {
	int filterCount = filters.size();
	filterNames = new String[filterCount];
	filterConditions = new String[filterCount];
	Iterator iter = filters.entrySet().iterator();
	filterCount = 0;
	while ( iter.hasNext() ) {
		final Map.Entry entry = (Map.Entry) iter.next();
		filterNames[filterCount] = (String) entry.getKey();
		filterConditions[filterCount] = Template.renderWhereStringTemplate(
				(String) entry.getValue(),
				FilterImpl.MARKER,
				dialect,
				functionRegistry
			);
		filterConditions[filterCount] = StringHelper.replace( filterConditions[filterCount],
				":",
				":" + filterNames[filterCount] + "." );
		filterCount++;
	}
}
 
Example #6
Source File: FilterKey.java    From cacheonix-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
public static Set createFilterKeys(Map enabledFilters, EntityMode entityMode) {
	if ( enabledFilters.size()==0 ) return null;
	Set result = new HashSet();
	Iterator iter = enabledFilters.values().iterator();
	while ( iter.hasNext() ) {
		FilterImpl filter = (FilterImpl) iter.next();
		FilterKey key = new FilterKey(
				filter.getName(), 
				filter.getParameters(), 
				filter.getFilterDefinition().getParameterTypes(), 
				entityMode
			);
		result.add(key);
	}
	return result;
}
 
Example #7
Source File: PersistentOwnedSet.java    From webdsl with Apache License 2.0 5 votes vote down vote up
public void unfiltered(boolean writing) {
	if(wasInitialized() && getFilter() == null) return; // The collection was already initialized without filters
	if(wasInitialized()) { // Cleaning the filtered collection
		try{
			Field f = org.hibernate.collection.AbstractPersistentCollection.class.getDeclaredField("initialized");
			f.setAccessible(true);
			f.setBoolean(this, Boolean.FALSE);
			set = null;
		}catch(Exception e) {
			org.webdsl.logging.Logger.error("EXCEPTION",e);
		}
	}
	SessionImplementor session = getSession();

	// Disable the affecting filter
	FilterImpl oldFilter = getAffectingFilter();
	if(oldFilter != null) {
		session.getLoadQueryInfluencers().disableFilter(oldFilter.getName());
	}

	// Initialize the collection
	initialize(writing);
	session.initializeCollection(this, writing);

	// Enable the affecting filter again
	if(oldFilter != null) {
		utils.QueryOptimization.restoreFilter(session.getLoadQueryInfluencers(), oldFilter);
	}
	if(writing) dirty();
}
 
Example #8
Source File: PersistentOwnedList.java    From webdsl with Apache License 2.0 5 votes vote down vote up
public void unfiltered(boolean writing) {
	if(wasInitialized() && getFilter() == null) return; // The collection was already initialized without filters
	if(wasInitialized()) { // Cleaning the filtered collection
		try{
			Field f = org.hibernate.collection.AbstractPersistentCollection.class.getDeclaredField("initialized");
			f.setAccessible(true);
			f.setBoolean(this, Boolean.FALSE);
			list = null;
		}catch(Exception e) {
			org.webdsl.logging.Logger.error("EXCEPTION",e);
		}
	}
	SessionImplementor session = getSession();

	// Disable the affecting filter
	FilterImpl oldFilter = getAffectingFilter();
	if(oldFilter != null) {
		session.getLoadQueryInfluencers().disableFilter(oldFilter.getName());
	}

	// Initialize the collection
	initialize(writing);
	session.initializeCollection(this, writing);

	// Enable the affecting filter again
	if(oldFilter != null) {
		utils.QueryOptimization.restoreFilter(session.getLoadQueryInfluencers(), oldFilter);
	}
	if(writing) dirty();
}
 
Example #9
Source File: FilterHelper.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void render(StringBuffer buffer, String alias, 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 ) );
				}
			}
		}
	}
}
 
Example #10
Source File: PersistentOwnedSet.java    From webdsl with Apache License 2.0 4 votes vote down vote up
public void setFilterHint(org.hibernate.impl.FilterImpl filterHint) {
	this.filterHint = filterHint;
}
 
Example #11
Source File: JoinProcessor.java    From Knowage-Server with GNU Affero General Public License v3.0 4 votes vote down vote up
public static void processDynamicFilterParameters(
		final String sqlFragment,
		final ParameterContainer container,
		final HqlSqlWalker walker) {
	if ( walker.getEnabledFilters().isEmpty()
			&& ( ! hasDynamicFilterParam( sqlFragment ) )
			&& ( ! ( hasCollectionFilterParam( sqlFragment ) ) ) ) {
		return;
	}

	Dialect dialect = walker.getSessionFactoryHelper().getFactory().getDialect();
	String symbols = new StringBuffer().append( ParserHelper.HQL_SEPARATORS )
			.append( dialect.openQuote() )
			.append( dialect.closeQuote() )
			.toString();
	StringTokenizer tokens = new StringTokenizer( sqlFragment, symbols, true );
	StringBuffer result = new StringBuffer();

	while ( tokens.hasMoreTokens() ) {
		final String token = tokens.nextToken();
		if ( token.startsWith( ParserHelper.HQL_VARIABLE_PREFIX ) ) {
			final String filterParameterName = token.substring( 1 );
			final String[] parts = LoadQueryInfluencers.parseFilterParameterName( filterParameterName );
			final FilterImpl filter = ( FilterImpl ) walker.getEnabledFilters().get( parts[0] );
			final Object value = filter.getParameter( parts[1] );
			final Type type = filter.getFilterDefinition().getParameterType( parts[1] );
			final String typeBindFragment = StringHelper.join(
					",",
					ArrayHelper.fillArray( "?", type.getColumnSpan( walker.getSessionFactoryHelper().getFactory() ) )
			);
			final String bindFragment = ( value != null && Collection.class.isInstance( value ) )
					? StringHelper.join( ",", ArrayHelper.fillArray( typeBindFragment, ( ( Collection ) value ).size() ) )
					: typeBindFragment;
			result.append( bindFragment );
			container.addEmbeddedParameter( new DynamicFilterParameterSpecification( parts[0], parts[1], type ) );
		}
		else {
			result.append( token );
		}
	}

	container.setText( result.toString() );
}
 
Example #12
Source File: PersistentOwnedList.java    From webdsl with Apache License 2.0 4 votes vote down vote up
protected FilterImpl getAffectingFilter() {
	return getAffectingFilter(getOwnedListType());
}
 
Example #13
Source File: PersistentOwnedList.java    From webdsl with Apache License 2.0 4 votes vote down vote up
public void setFilterHint(org.hibernate.impl.FilterImpl filterHint) {
	this.filterHint = filterHint;
}
 
Example #14
Source File: PersistentOwnedList.java    From webdsl with Apache License 2.0 4 votes vote down vote up
public org.hibernate.impl.FilterImpl getFilterHint() {
	return this.filterHint;
}
 
Example #15
Source File: PersistentOwnedList.java    From webdsl with Apache License 2.0 4 votes vote down vote up
public void setFilter(org.hibernate.impl.FilterImpl filter) {
	this.filter = filter;
	this.filterHint = null; // 
}
 
Example #16
Source File: PersistentOwnedList.java    From webdsl with Apache License 2.0 4 votes vote down vote up
public org.hibernate.impl.FilterImpl getFilter() {
	return this.filter;
}
 
Example #17
Source File: JoinProcessor.java    From Knowage-Server with GNU Affero General Public License v3.0 4 votes vote down vote up
public static void processDynamicFilterParameters(
		final String sqlFragment,
		final ParameterContainer container,
		final HqlSqlWalker walker) {
	if ( walker.getEnabledFilters().isEmpty()
			&& ( ! hasDynamicFilterParam( sqlFragment ) )
			&& ( ! ( hasCollectionFilterParam( sqlFragment ) ) ) ) {
		return;
	}

	Dialect dialect = walker.getSessionFactoryHelper().getFactory().getDialect();
	String symbols = new StringBuffer().append( ParserHelper.HQL_SEPARATORS )
			.append( dialect.openQuote() )
			.append( dialect.closeQuote() )
			.toString();
	StringTokenizer tokens = new StringTokenizer( sqlFragment, symbols, true );
	StringBuffer result = new StringBuffer();

	while ( tokens.hasMoreTokens() ) {
		final String token = tokens.nextToken();
		if ( token.startsWith( ParserHelper.HQL_VARIABLE_PREFIX ) ) {
			final String filterParameterName = token.substring( 1 );
			final String[] parts = LoadQueryInfluencers.parseFilterParameterName( filterParameterName );
			final FilterImpl filter = ( FilterImpl ) walker.getEnabledFilters().get( parts[0] );
			final Object value = filter.getParameter( parts[1] );
			final Type type = filter.getFilterDefinition().getParameterType( parts[1] );
			final String typeBindFragment = StringHelper.join(
					",",
					ArrayHelper.fillArray( "?", type.getColumnSpan( walker.getSessionFactoryHelper().getFactory() ) )
			);
			final String bindFragment = ( value != null && Collection.class.isInstance( value ) )
					? StringHelper.join( ",", ArrayHelper.fillArray( typeBindFragment, ( ( Collection ) value ).size() ) )
					: typeBindFragment;
			result.append( bindFragment );
			container.addEmbeddedParameter( new DynamicFilterParameterSpecification( parts[0], parts[1], type ) );
		}
		else {
			result.append( token );
		}
	}

	container.setText( result.toString() );
}
 
Example #18
Source File: JoinProcessor.java    From Knowage-Server with GNU Affero General Public License v3.0 4 votes vote down vote up
public static void processDynamicFilterParameters(
		final String sqlFragment,
		final ParameterContainer container,
		final HqlSqlWalker walker) {
	if ( walker.getEnabledFilters().isEmpty()
			&& ( ! hasDynamicFilterParam( sqlFragment ) )
			&& ( ! ( hasCollectionFilterParam( sqlFragment ) ) ) ) {
		return;
	}

	Dialect dialect = walker.getSessionFactoryHelper().getFactory().getDialect();
	String symbols = new StringBuffer().append( ParserHelper.HQL_SEPARATORS )
			.append( dialect.openQuote() )
			.append( dialect.closeQuote() )
			.toString();
	StringTokenizer tokens = new StringTokenizer( sqlFragment, symbols, true );
	StringBuffer result = new StringBuffer();

	while ( tokens.hasMoreTokens() ) {
		final String token = tokens.nextToken();
		if ( token.startsWith( ParserHelper.HQL_VARIABLE_PREFIX ) ) {
			final String filterParameterName = token.substring( 1 );
			final String[] parts = LoadQueryInfluencers.parseFilterParameterName( filterParameterName );
			final FilterImpl filter = ( FilterImpl ) walker.getEnabledFilters().get( parts[0] );
			final Object value = filter.getParameter( parts[1] );
			final Type type = filter.getFilterDefinition().getParameterType( parts[1] );
			final String typeBindFragment = StringHelper.join(
					",",
					ArrayHelper.fillArray( "?", type.getColumnSpan( walker.getSessionFactoryHelper().getFactory() ) )
			);
			final String bindFragment = ( value != null && Collection.class.isInstance( value ) )
					? StringHelper.join( ",", ArrayHelper.fillArray( typeBindFragment, ( ( Collection ) value ).size() ) )
					: typeBindFragment;
			result.append( bindFragment );
			container.addEmbeddedParameter( new DynamicFilterParameterSpecification( parts[0], parts[1], type ) );
		}
		else {
			result.append( token );
		}
	}

	container.setText( result.toString() );
}
 
Example #19
Source File: JoinProcessor.java    From Knowage-Server with GNU Affero General Public License v3.0 4 votes vote down vote up
public static void processDynamicFilterParameters(
		final String sqlFragment,
		final ParameterContainer container,
		final HqlSqlWalker walker) {
	if ( walker.getEnabledFilters().isEmpty()
			&& ( ! hasDynamicFilterParam( sqlFragment ) )
			&& ( ! ( hasCollectionFilterParam( sqlFragment ) ) ) ) {
		return;
	}

	Dialect dialect = walker.getSessionFactoryHelper().getFactory().getDialect();
	String symbols = new StringBuffer().append( ParserHelper.HQL_SEPARATORS )
			.append( dialect.openQuote() )
			.append( dialect.closeQuote() )
			.toString();
	StringTokenizer tokens = new StringTokenizer( sqlFragment, symbols, true );
	StringBuffer result = new StringBuffer();

	while ( tokens.hasMoreTokens() ) {
		final String token = tokens.nextToken();
		if ( token.startsWith( ParserHelper.HQL_VARIABLE_PREFIX ) ) {
			final String filterParameterName = token.substring( 1 );
			final String[] parts = LoadQueryInfluencers.parseFilterParameterName( filterParameterName );
			final FilterImpl filter = ( FilterImpl ) walker.getEnabledFilters().get( parts[0] );
			final Object value = filter.getParameter( parts[1] );
			final Type type = filter.getFilterDefinition().getParameterType( parts[1] );
			final String typeBindFragment = StringHelper.join(
					",",
					ArrayHelper.fillArray( "?", type.getColumnSpan( walker.getSessionFactoryHelper().getFactory() ) )
			);
			final String bindFragment = ( value != null && Collection.class.isInstance( value ) )
					? StringHelper.join( ",", ArrayHelper.fillArray( typeBindFragment, ( ( Collection ) value ).size() ) )
					: typeBindFragment;
			result.append( bindFragment );
			container.addEmbeddedParameter( new DynamicFilterParameterSpecification( parts[0], parts[1], type ) );
		}
		else {
			result.append( token );
		}
	}

	container.setText( result.toString() );
}
 
Example #20
Source File: PersistentOwnedSet.java    From webdsl with Apache License 2.0 4 votes vote down vote up
protected FilterImpl getAffectingFilter() {
   	return getAffectingFilter(getOwnedSetType());
}
 
Example #21
Source File: JoinProcessor.java    From Knowage-Server with GNU Affero General Public License v3.0 4 votes vote down vote up
public static void processDynamicFilterParameters(
		final String sqlFragment,
		final ParameterContainer container,
		final HqlSqlWalker walker) {
	if ( walker.getEnabledFilters().isEmpty()
			&& ( ! hasDynamicFilterParam( sqlFragment ) )
			&& ( ! ( hasCollectionFilterParam( sqlFragment ) ) ) ) {
		return;
	}

	Dialect dialect = walker.getSessionFactoryHelper().getFactory().getDialect();
	String symbols = new StringBuffer().append( ParserHelper.HQL_SEPARATORS )
			.append( dialect.openQuote() )
			.append( dialect.closeQuote() )
			.toString();
	StringTokenizer tokens = new StringTokenizer( sqlFragment, symbols, true );
	StringBuffer result = new StringBuffer();

	while ( tokens.hasMoreTokens() ) {
		final String token = tokens.nextToken();
		if ( token.startsWith( ParserHelper.HQL_VARIABLE_PREFIX ) ) {
			final String filterParameterName = token.substring( 1 );
			final String[] parts = LoadQueryInfluencers.parseFilterParameterName( filterParameterName );
			final FilterImpl filter = ( FilterImpl ) walker.getEnabledFilters().get( parts[0] );
			final Object value = filter.getParameter( parts[1] );
			final Type type = filter.getFilterDefinition().getParameterType( parts[1] );
			final String typeBindFragment = StringHelper.join(
					",",
					ArrayHelper.fillArray( "?", type.getColumnSpan( walker.getSessionFactoryHelper().getFactory() ) )
			);
			final String bindFragment = ( value != null && Collection.class.isInstance( value ) )
					? StringHelper.join( ",", ArrayHelper.fillArray( typeBindFragment, ( ( Collection ) value ).size() ) )
					: typeBindFragment;
			result.append( bindFragment );
			container.addEmbeddedParameter( new DynamicFilterParameterSpecification( parts[0], parts[1], type ) );
		}
		else {
			result.append( token );
		}
	}

	container.setText( result.toString() );
}
 
Example #22
Source File: PersistentOwnedSet.java    From webdsl with Apache License 2.0 4 votes vote down vote up
public org.hibernate.impl.FilterImpl getFilterHint() {
	return this.filterHint;
}
 
Example #23
Source File: PersistentOwnedSet.java    From webdsl with Apache License 2.0 4 votes vote down vote up
public void setFilter(org.hibernate.impl.FilterImpl filter) {
	this.filter = filter;
	this.filterHint = null; // 
}
 
Example #24
Source File: PersistentOwnedSet.java    From webdsl with Apache License 2.0 4 votes vote down vote up
public org.hibernate.impl.FilterImpl getFilter() {
	return this.filter;
}
 
Example #25
Source File: JoinProcessor.java    From Knowage-Server with GNU Affero General Public License v3.0 4 votes vote down vote up
public static void processDynamicFilterParameters(
		final String sqlFragment,
		final ParameterContainer container,
		final HqlSqlWalker walker) {
	if ( walker.getEnabledFilters().isEmpty()
			&& ( ! hasDynamicFilterParam( sqlFragment ) )
			&& ( ! ( hasCollectionFilterParam( sqlFragment ) ) ) ) {
		return;
	}

	Dialect dialect = walker.getSessionFactoryHelper().getFactory().getDialect();
	String symbols = new StringBuffer().append( ParserHelper.HQL_SEPARATORS )
			.append( dialect.openQuote() )
			.append( dialect.closeQuote() )
			.toString();
	StringTokenizer tokens = new StringTokenizer( sqlFragment, symbols, true );
	StringBuffer result = new StringBuffer();

	while ( tokens.hasMoreTokens() ) {
		final String token = tokens.nextToken();
		if ( token.startsWith( ParserHelper.HQL_VARIABLE_PREFIX ) ) {
			final String filterParameterName = token.substring( 1 );
			final String[] parts = LoadQueryInfluencers.parseFilterParameterName( filterParameterName );
			final FilterImpl filter = ( FilterImpl ) walker.getEnabledFilters().get( parts[0] );
			final Object value = filter.getParameter( parts[1] );
			final Type type = filter.getFilterDefinition().getParameterType( parts[1] );
			final String typeBindFragment = StringHelper.join(
					",",
					ArrayHelper.fillArray( "?", type.getColumnSpan( walker.getSessionFactoryHelper().getFactory() ) )
			);
			final String bindFragment = ( value != null && Collection.class.isInstance( value ) )
					? StringHelper.join( ",", ArrayHelper.fillArray( typeBindFragment, ( ( Collection ) value ).size() ) )
					: typeBindFragment;
			result.append( bindFragment );
			container.addEmbeddedParameter( new DynamicFilterParameterSpecification( parts[0], parts[1], type ) );
		}
		else {
			result.append( token );
		}
	}

	container.setText( result.toString() );
}
 
Example #26
Source File: JoinProcessor.java    From Knowage-Server with GNU Affero General Public License v3.0 4 votes vote down vote up
public static void processDynamicFilterParameters(
		final String sqlFragment,
		final ParameterContainer container,
		final HqlSqlWalker walker) {
	if ( walker.getEnabledFilters().isEmpty()
			&& ( ! hasDynamicFilterParam( sqlFragment ) )
			&& ( ! ( hasCollectionFilterParam( sqlFragment ) ) ) ) {
		return;
	}

	Dialect dialect = walker.getSessionFactoryHelper().getFactory().getDialect();
	String symbols = new StringBuffer().append( ParserHelper.HQL_SEPARATORS )
			.append( dialect.openQuote() )
			.append( dialect.closeQuote() )
			.toString();
	StringTokenizer tokens = new StringTokenizer( sqlFragment, symbols, true );
	StringBuffer result = new StringBuffer();

	while ( tokens.hasMoreTokens() ) {
		final String token = tokens.nextToken();
		if ( token.startsWith( ParserHelper.HQL_VARIABLE_PREFIX ) ) {
			final String filterParameterName = token.substring( 1 );
			final String[] parts = LoadQueryInfluencers.parseFilterParameterName( filterParameterName );
			final FilterImpl filter = ( FilterImpl ) walker.getEnabledFilters().get( parts[0] );
			final Object value = filter.getParameter( parts[1] );
			final Type type = filter.getFilterDefinition().getParameterType( parts[1] );
			final String typeBindFragment = StringHelper.join(
					",",
					ArrayHelper.fillArray( "?", type.getColumnSpan( walker.getSessionFactoryHelper().getFactory() ) )
			);
			final String bindFragment = ( value != null && Collection.class.isInstance( value ) )
					? StringHelper.join( ",", ArrayHelper.fillArray( typeBindFragment, ( ( Collection ) value ).size() ) )
					: typeBindFragment;
			result.append( bindFragment );
			container.addEmbeddedParameter( new DynamicFilterParameterSpecification( parts[0], parts[1], type ) );
		}
		else {
			result.append( token );
		}
	}

	container.setText( result.toString() );
}
 
Example #27
Source File: JoinProcessor.java    From Knowage-Server with GNU Affero General Public License v3.0 4 votes vote down vote up
public static void processDynamicFilterParameters(
		final String sqlFragment,
		final ParameterContainer container,
		final HqlSqlWalker walker) {
	if ( walker.getEnabledFilters().isEmpty()
			&& ( ! hasDynamicFilterParam( sqlFragment ) )
			&& ( ! ( hasCollectionFilterParam( sqlFragment ) ) ) ) {
		return;
	}

	Dialect dialect = walker.getSessionFactoryHelper().getFactory().getDialect();
	String symbols = new StringBuffer().append( ParserHelper.HQL_SEPARATORS )
			.append( dialect.openQuote() )
			.append( dialect.closeQuote() )
			.toString();
	StringTokenizer tokens = new StringTokenizer( sqlFragment, symbols, true );
	StringBuffer result = new StringBuffer();

	while ( tokens.hasMoreTokens() ) {
		final String token = tokens.nextToken();
		if ( token.startsWith( ParserHelper.HQL_VARIABLE_PREFIX ) ) {
			final String filterParameterName = token.substring( 1 );
			final String[] parts = LoadQueryInfluencers.parseFilterParameterName( filterParameterName );
			final FilterImpl filter = ( FilterImpl ) walker.getEnabledFilters().get( parts[0] );
			final Object value = filter.getParameter( parts[1] );
			final Type type = filter.getFilterDefinition().getParameterType( parts[1] );
			final String typeBindFragment = StringHelper.join(
					",",
					ArrayHelper.fillArray( "?", type.getColumnSpan( walker.getSessionFactoryHelper().getFactory() ) )
			);
			final String bindFragment = ( value != null && Collection.class.isInstance( value ) )
					? StringHelper.join( ",", ArrayHelper.fillArray( typeBindFragment, ( ( Collection ) value ).size() ) )
					: typeBindFragment;
			result.append( bindFragment );
			container.addEmbeddedParameter( new DynamicFilterParameterSpecification( parts[0], parts[1], type ) );
		}
		else {
			result.append( token );
		}
	}

	container.setText( result.toString() );
}
 
Example #28
Source File: JoinProcessor.java    From Knowage-Server with GNU Affero General Public License v3.0 4 votes vote down vote up
public static void processDynamicFilterParameters(
		final String sqlFragment,
		final ParameterContainer container,
		final HqlSqlWalker walker) {
	if ( walker.getEnabledFilters().isEmpty()
			&& ( ! hasDynamicFilterParam( sqlFragment ) )
			&& ( ! ( hasCollectionFilterParam( sqlFragment ) ) ) ) {
		return;
	}

	Dialect dialect = walker.getSessionFactoryHelper().getFactory().getDialect();
	String symbols = new StringBuffer().append( ParserHelper.HQL_SEPARATORS )
			.append( dialect.openQuote() )
			.append( dialect.closeQuote() )
			.toString();
	StringTokenizer tokens = new StringTokenizer( sqlFragment, symbols, true );
	StringBuffer result = new StringBuffer();

	while ( tokens.hasMoreTokens() ) {
		final String token = tokens.nextToken();
		if ( token.startsWith( ParserHelper.HQL_VARIABLE_PREFIX ) ) {
			final String filterParameterName = token.substring( 1 );
			final String[] parts = LoadQueryInfluencers.parseFilterParameterName( filterParameterName );
			final FilterImpl filter = ( FilterImpl ) walker.getEnabledFilters().get( parts[0] );
			final Object value = filter.getParameter( parts[1] );
			final Type type = filter.getFilterDefinition().getParameterType( parts[1] );
			final String typeBindFragment = StringHelper.join(
					",",
					ArrayHelper.fillArray( "?", type.getColumnSpan( walker.getSessionFactoryHelper().getFactory() ) )
			);
			final String bindFragment = ( value != null && Collection.class.isInstance( value ) )
					? StringHelper.join( ",", ArrayHelper.fillArray( typeBindFragment, ( ( Collection ) value ).size() ) )
					: typeBindFragment;
			result.append( bindFragment );
			container.addEmbeddedParameter( new DynamicFilterParameterSpecification( parts[0], parts[1], type ) );
		}
		else {
			result.append( token );
		}
	}

	container.setText( result.toString() );
}
 
Example #29
Source File: JoinProcessor.java    From Knowage-Server with GNU Affero General Public License v3.0 4 votes vote down vote up
public static void processDynamicFilterParameters(
		final String sqlFragment,
		final ParameterContainer container,
		final HqlSqlWalker walker) {
	if ( walker.getEnabledFilters().isEmpty()
			&& ( ! hasDynamicFilterParam( sqlFragment ) )
			&& ( ! ( hasCollectionFilterParam( sqlFragment ) ) ) ) {
		return;
	}

	Dialect dialect = walker.getSessionFactoryHelper().getFactory().getDialect();
	String symbols = new StringBuffer().append( ParserHelper.HQL_SEPARATORS )
			.append( dialect.openQuote() )
			.append( dialect.closeQuote() )
			.toString();
	StringTokenizer tokens = new StringTokenizer( sqlFragment, symbols, true );
	StringBuffer result = new StringBuffer();

	while ( tokens.hasMoreTokens() ) {
		final String token = tokens.nextToken();
		if ( token.startsWith( ParserHelper.HQL_VARIABLE_PREFIX ) ) {
			final String filterParameterName = token.substring( 1 );
			final String[] parts = LoadQueryInfluencers.parseFilterParameterName( filterParameterName );
			final FilterImpl filter = ( FilterImpl ) walker.getEnabledFilters().get( parts[0] );
			final Object value = filter.getParameter( parts[1] );
			final Type type = filter.getFilterDefinition().getParameterType( parts[1] );
			final String typeBindFragment = StringHelper.join(
					",",
					ArrayHelper.fillArray( "?", type.getColumnSpan( walker.getSessionFactoryHelper().getFactory() ) )
			);
			final String bindFragment = ( value != null && Collection.class.isInstance( value ) )
					? StringHelper.join( ",", ArrayHelper.fillArray( typeBindFragment, ( ( Collection ) value ).size() ) )
					: typeBindFragment;
			result.append( bindFragment );
			container.addEmbeddedParameter( new DynamicFilterParameterSpecification( parts[0], parts[1], type ) );
		}
		else {
			result.append( token );
		}
	}

	container.setText( result.toString() );
}
 
Example #30
Source File: JoinProcessor.java    From Knowage-Server with GNU Affero General Public License v3.0 4 votes vote down vote up
public static void processDynamicFilterParameters(
		final String sqlFragment,
		final ParameterContainer container,
		final HqlSqlWalker walker) {
	if ( walker.getEnabledFilters().isEmpty()
			&& ( ! hasDynamicFilterParam( sqlFragment ) )
			&& ( ! ( hasCollectionFilterParam( sqlFragment ) ) ) ) {
		return;
	}

	Dialect dialect = walker.getSessionFactoryHelper().getFactory().getDialect();
	String symbols = new StringBuffer().append( ParserHelper.HQL_SEPARATORS )
			.append( dialect.openQuote() )
			.append( dialect.closeQuote() )
			.toString();
	StringTokenizer tokens = new StringTokenizer( sqlFragment, symbols, true );
	StringBuffer result = new StringBuffer();

	while ( tokens.hasMoreTokens() ) {
		final String token = tokens.nextToken();
		if ( token.startsWith( ParserHelper.HQL_VARIABLE_PREFIX ) ) {
			final String filterParameterName = token.substring( 1 );
			final String[] parts = LoadQueryInfluencers.parseFilterParameterName( filterParameterName );
			final FilterImpl filter = ( FilterImpl ) walker.getEnabledFilters().get( parts[0] );
			final Object value = filter.getParameter( parts[1] );
			final Type type = filter.getFilterDefinition().getParameterType( parts[1] );
			final String typeBindFragment = StringHelper.join(
					",",
					ArrayHelper.fillArray( "?", type.getColumnSpan( walker.getSessionFactoryHelper().getFactory() ) )
			);
			final String bindFragment = ( value != null && Collection.class.isInstance( value ) )
					? StringHelper.join( ",", ArrayHelper.fillArray( typeBindFragment, ( ( Collection ) value ).size() ) )
					: typeBindFragment;
			result.append( bindFragment );
			container.addEmbeddedParameter( new DynamicFilterParameterSpecification( parts[0], parts[1], type ) );
		}
		else {
			result.append( token );
		}
	}

	container.setText( result.toString() );
}