Java Code Examples for org.hibernate.criterion.Restrictions#not()

The following examples show how to use org.hibernate.criterion.Restrictions#not() . 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: CriteriaParameter.java    From Knowage-Server with GNU Affero General Public License v3.0 6 votes vote down vote up
public Criterion toHibernateCriterion() {
	Criterion restriction = null;
	switch (getMatch()) {
	case LIKE:
		restriction = Restrictions.like(getName(), (String) getValue(), MatchMode.ANYWHERE);
		break;
	case ILIKE:
		restriction = Restrictions.like(getName(), (String) getValue(), MatchMode.ANYWHERE).ignoreCase();
		break;
	case NOT_EQ:
		restriction = Restrictions.ne(getName(), getValue());
		break;
	case IN:
		restriction = Restrictions.in(getName(), (Object[]) getValue());
		break;
	case NOT_IN:
		restriction = Restrictions.not(Restrictions.in(getName(), (Object[]) getValue()));
		break;
	default:
		restriction = Restrictions.eq(getName(), getValue());
		break;
	}
	return restriction;
}
 
Example 2
Source File: CategoryCriterion.java    From ctsms with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static Criterion getCategoryCriterionRestriction(CategoryCriterion categoryCriterion) {
	Criterion restriction = null;
	if (categoryCriterion.prefix != null && categoryCriterion.prefix.length() > 0) {
		if (categoryCriterion.caseSensitive) {
			restriction = Restrictions.like(categoryCriterion.field, categoryCriterion.prefix, categoryCriterion.matchMode);
		} else {
			restriction = Restrictions.ilike(categoryCriterion.field, categoryCriterion.prefix, categoryCriterion.matchMode);
		}
	} else if (EmptyPrefixModes.NON_EMPTY_ROWS.equals(categoryCriterion.emptyPrefixMode)) {
		restriction = Restrictions.not(Restrictions.or(Restrictions.eq(categoryCriterion.field, ""), Restrictions.isNull(categoryCriterion.field)));
	} else if (EmptyPrefixModes.EMPTY_ROWS.equals(categoryCriterion.emptyPrefixMode)) {
		restriction = Restrictions.or(Restrictions.eq(categoryCriterion.field, ""), Restrictions.isNull(categoryCriterion.field));
	}
	return restriction;
}
 
Example 3
Source File: AbstractHibernateCriteriaBuilder.java    From gorm-hibernate5 with Apache License 2.0 5 votes vote down vote up
public Criterion toCriterion() {
    if (name.equals(NOT)) {
        switch (args.size()) {
            case 0:
                throwRuntimeException(new IllegalArgumentException("Logical expression [not] must contain at least 1 expression"));
                return null;

            case 1:
                return Restrictions.not(args.get(0));

            default:
                // treat multiple sub-criteria as an implicit "OR"
                return Restrictions.not(buildJunction(Restrictions.disjunction(), args));
        }
    }

    if (name.equals(AND)) {
        return buildJunction(Restrictions.conjunction(), args);
    }

    if (name.equals(OR)) {
        return buildJunction(Restrictions.disjunction(), args);
    }

    throwRuntimeException(new IllegalStateException("Logical expression [" + name + "] not handled!"));
    return null;
}
 
Example 4
Source File: SQLVisitor.java    From DataHubSystem with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public Object visitUnary(UnaryExpression unary_expression,
      UnaryOperator operator, Object operand)
{
   switch (operator)
   {
      case MINUS:
      {
         if (operand instanceof Long)
         {
            return -((Long) operand);
         }
         else if (operand instanceof Double)
         {
            return -((Double) operand);
         }
         else
         {
            throw new UnsupportedOperationException("Invalid expression: " +
                  unary_expression.getUriLiteral());
         }
      }
      case NOT:
      {
         return Restrictions.not((Criterion) operand);
      }
      default:
         break;
   }
   throw new UnsupportedOperationException("Unsupported operator: " +
         operator.toUriLiteral());
}
 
Example 5
Source File: HibernateUtil.java    From SensorWebClient with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public static List<BasicRule> getAllOtherBasicRules(String userID) {
    Session session = getSessionFactory().getCurrentSession();
    session.beginTransaction();
    Criteria crit = session.createCriteria(BasicRule.class);
    Criterion restriction = Restrictions.not(Restrictions.eq(OWNER_ID, Integer.valueOf(userID)));
    List<BasicRule> rules = crit.add(restriction).list();
    session.getTransaction().commit();
    return rules;
}
 
Example 6
Source File: HibernateUtil.java    From SensorWebClient with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public static List<BasicRule> getAllOtherPublishedBasicRules(String userID) {
    Session session = getSessionFactory().getCurrentSession();
    session.beginTransaction();
    Criteria crit = session.createCriteria(BasicRule.class);
    Criterion isOwner = Restrictions.not(Restrictions.eq(OWNER_ID, valueOf(userID)));
    SimpleExpression isPublished = Restrictions.eq(PUBLISHED, true);
    List<BasicRule> rules = crit.add(Restrictions.and(isOwner, isPublished)).list();
    session.getTransaction().commit();
    return rules;
}
 
Example 7
Source File: HibernateUtil.java    From SensorWebClient with GNU General Public License v2.0 5 votes vote down vote up
@Deprecated
@SuppressWarnings("unchecked")
public static List<ComplexRule> getAllOtherPublishedComplexRules(String userID) {
    Session session = getSessionFactory().getCurrentSession();
    session.beginTransaction();
    Criteria crit = session.createCriteria(ComplexRule.class);
    Criterion isOwner = Restrictions.not(Restrictions.eq(OWNER_ID, valueOf(userID)));
    SimpleExpression isPublished = Restrictions.eq(PUBLISHED, true);
    List<ComplexRule> rules = crit.add(Restrictions.and(isOwner, isPublished)).list();
    session.getTransaction().commit();
    return rules;
}
 
Example 8
Source File: NotLikeOperator.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public Criterion getHibernateCriterion( QueryPath queryPath )
{
    return Restrictions.not( super.getHibernateCriterion( queryPath ) );
}
 
Example 9
Source File: NotEqualOperator.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public Criterion getHibernateCriterion( QueryPath queryPath )
{
    return Restrictions.not( super.getHibernateCriterion( queryPath ) );
}
 
Example 10
Source File: NotInOperator.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public Criterion getHibernateCriterion( QueryPath queryPath )
{
    return Restrictions.not( super.getHibernateCriterion( queryPath ) );
}
 
Example 11
Source File: CriteriaVisitor.java    From geomajas-project-server with GNU Affero General Public License v3.0 4 votes vote down vote up
/** {@inheritDoc} */
@Override
public Object visit(Not filter, Object userData) {
	Criterion c = (Criterion) filter.getFilter().accept(this, userData);
	return Restrictions.not(c);
}
 
Example 12
Source File: CriteriaVisitor.java    From geomajas-project-server with GNU Affero General Public License v3.0 4 votes vote down vote up
/** {@inheritDoc} */
@Override
public Object visit(ExcludeFilter filter, Object userData) {
	return Restrictions.not(Restrictions.conjunction());
}
 
Example 13
Source File: NinRestriction.java    From base-framework with Apache License 2.0 2 votes vote down vote up
public Criterion buildRestriction(String propertyName, Object[] values) {
	
	return Restrictions.not(Restrictions.in(propertyName, values));
}