Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Hibernate, Relational Persistence for Idiomatic Java
   *
   * Copyright (c) 2009 by Red Hat Inc and/or its affiliates or by
   * third-party contributors as indicated by either @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.ejb.criteria.predicate;
 
 import java.util.List;
 
A compound predicate is a grouping of other predicates in order to convert either a conjunction (logical AND) or a disjunction (logical OR).

Author(s):
Steve Ebersole
 
 public class CompoundPredicate
 		implements Serializable {
 	private final List<Expression<Boolean>> expressions = new ArrayList<Expression<Boolean>>();

Constructs an empty conjunction or disjunction.

Parameters:
criteriaBuilder The query builder from which this originates.
operator Indicates whether this predicate will function as a conjunction or disjunction.
 
 	public CompoundPredicate(CriteriaBuilderImpl criteriaBuilderBooleanOperator operator) {
 		supercriteriaBuilder );
 		this. = operator;
 	}

Constructs a conjunction or disjunction over the given expressions.

Parameters:
criteriaBuilder The query builder from which this originates.
operator Indicates whether this predicate will function as a conjunction or disjunction.
expressions The expressions to be grouped.
 
 			CriteriaBuilderImpl criteriaBuilder,
 			BooleanOperator operator,
 			Expression<Boolean>... expressions) {
 		thiscriteriaBuilderoperator );
 		applyExpressionsexpressions );
 	}

Constructs a conjunction or disjunction over the given expressions.

Parameters:
criteriaBuilder The query builder from which this originates.
operator Indicates whether this predicate will function as a conjunction or disjunction.
expressions The expressions to be grouped.
 
 			CriteriaBuilderImpl criteriaBuilder,
 			BooleanOperator operator,
 			List<Expression<Boolean>> expressions) {
 		thiscriteriaBuilderoperator );
 		applyExpressionsexpressions );
 	}
 
 	private void applyExpressions(Expression<Boolean>... expressions) {
 		applyExpressions( Arrays.asListexpressions ) );
 	}
 
 	private void applyExpressions(List<Expression<Boolean>> expressions) {
 		this..clear();
		this..addAllexpressions );
	}
		return ;
	}
		return ;
	}
	public void registerParameters(ParameterRegistry registry) {
		for ( Expression expression : getExpressions() ) {
			Helper.possibleParameterexpressionregistry );
		}
	}
	public String render(CriteriaQueryCompiler.RenderingContext renderingContext) {
		if ( getExpressions().size() == 0 ) {
			boolean implicitTrue = getOperator() == .;
			if ( isNegated() ) {
				implicitTrue = !implicitTrue;
			}
			return implicitTrue
"1=1" // true
"0=1"// false
		}
		if ( getExpressions().size() == 1 ) {
			return ( (RenderablegetExpressions().get( 0 ) ).renderrenderingContext );
		}
		final StringBuilder buffer = new StringBuilder();
		String sep = "";
		for ( Expression expression : getExpressions() ) {
			buffer.appendsep )
					.append"( " )
					.append( ( (Renderableexpression ).renderrenderingContext ) )
					.append" )" );
		}
		return buffer.toString();
	}
" and "
" or ";
	}
		return renderrenderingContext );
	}

Create negation of compound predicate by using logic rules: 1. not (x || y) is (not x && not y) 2. not (x && y) is (not x || not y)
	public Predicate not() {
		for ( Expression expr : this.getExpressions() ) {
			if ( Predicate.class.isInstanceexpr ) ) {
				( (Predicateexpr ).not();
			}
		}
		return this;
	}
	private void toggleOperator() {
		if ( this. == . ) {
		}
		else {
		}
	}
New to GrepCode? Check out our FAQ X