Example usage for org.hibernate.criterion Restrictions ne

List of usage examples for org.hibernate.criterion Restrictions ne

Introduction

In this page you can find the example usage for org.hibernate.criterion Restrictions ne.

Prototype

public static SimpleExpression ne(String propertyName, Object value) 

Source Link

Document

Apply a "not equal" constraint to the named property

Usage

From source file:com.denimgroup.threadfix.data.dao.hibernate.HibernateUserDao.java

License:Mozilla Public License

@Override
public boolean canRemovePermissionFromUserAndGroup(Integer userId, Integer groupId, String string) {
    Long result = (Long) sessionFactory.getCurrentSession().createCriteria(User.class)
            .createAlias("globalRole", "roleAlias").add(Restrictions.eq("active", true))
            .add(Restrictions.eq("isLdapUser", false)).add(Restrictions.eq("roleAlias." + string, true))
            .add(Restrictions.ne("id", userId)).setProjection(Projections.rowCount()).uniqueResult();

    if (result == null || result == 0) {
        // we also need to do a lookup on groups
        result += (Long) sessionFactory.getCurrentSession().createCriteria(User.class)
                .createAlias("groups", "groupAlias").createAlias("groupAlias.globalRole", "roleAlias")
                .add(Restrictions.eq("active", true)).add(Restrictions.eq("isLdapUser", false))
                .add(Restrictions.eq("groupAlias.active", true)).add(Restrictions.ne("groupAlias.id", groupId))
                .add(Restrictions.eq("roleAlias." + string, true)).add(Restrictions.ne("id", userId))
                .setProjection(Projections.rowCount()).uniqueResult();
    }/*from  www.  j  av  a2s . c o  m*/

    return result != null && result > 0;
}

From source file:com.eharmony.matching.seeking.translator.hibernate.HibernateQueryTranslator.java

License:Apache License

@Override
public Criterion ne(String fieldName, Object value) {
    return Restrictions.ne(fieldName, value);
}

From source file:com.enonic.cms.store.dao.UserEntityDao.java

License:Open Source License

public List<UserEntity> findByQuery(final UserStoreKey userStoreKey, final String queryStr,
        final String orderBy, final boolean orderAscending) {

    return (List<UserEntity>) getHibernateTemplate().execute(new HibernateCallback() {

        public Object doInHibernate(Session session) throws HibernateException, SQLException {

            Criteria crit = session.createCriteria(UserEntity.class).setCacheable(true);
            crit.add(Restrictions.eq("deleted", 0));
            crit.add(Restrictions.ne("type", UserType.ADMINISTRATOR.getKey()));
            if (userStoreKey != null) {
                crit.add(Restrictions.eq("userStore.key", userStoreKey.toInt()));
            }/*from   w ww.j  ava 2  s.com*/

            if (queryStr != null && queryStr.length() > 0) {
                crit.add(Restrictions.or(
                        Restrictions.or(Restrictions.ilike("name", queryStr, MatchMode.ANYWHERE),
                                Restrictions.ilike("displayName", queryStr, MatchMode.ANYWHERE)),
                        Restrictions.ilike("email", queryStr, MatchMode.ANYWHERE)));

            }

            if (orderBy != null) {
                if (orderAscending) {
                    crit.addOrder(Order.asc(orderBy).ignoreCase());
                } else {
                    crit.addOrder(Order.desc(orderBy).ignoreCase());
                }
            }

            return crit.list();
        }
    });
}

From source file:com.ephesoft.dcma.da.dao.hibernate.BatchInstanceDaoImpl.java

License:Open Source License

/**
 * API to fetch running batch instances.
 * //www .  j  a v  a 2s.  c  o m
 * @param lockOwner ServerRegistry
 * @return List<BatchInstance>
 */
@Override
public List<BatchInstance> getRunningBatchInstancesFor(ServerRegistry lockOwner) {
    DetachedCriteria criteria = criteria();
    criteria.add(Restrictions.ne(STATUS, BatchInstanceStatus.NEW));
    criteria.add(Restrictions.ne(STATUS, BatchInstanceStatus.ERROR));
    criteria.add(Restrictions.ne(STATUS, BatchInstanceStatus.FINISHED));
    criteria.add(Restrictions.ne(STATUS, BatchInstanceStatus.READY_FOR_REVIEW));
    criteria.add(Restrictions.ne(STATUS, BatchInstanceStatus.READY_FOR_VALIDATION));
    criteria.add(Restrictions.eq("lockOwner", lockOwner));
    return find(criteria);
}

From source file:com.eryansky.common.orm.core.hibernate.restriction.support.NeRestriction.java

License:Apache License

public Criterion build(String propertyName, Object value) {

    return value == null ? Restrictions.isNotNull(propertyName) : Restrictions.ne(propertyName, value);

}

From source file:com.eucalyptus.cloudformation.entity.StackResourceEntityManager.java

License:Open Source License

public static StackResourceEntity describeStackResource(String accountId, String stackNameOrId,
        String logicalResourceId) throws CloudFormationException {
    StackResourceEntity matchingStackResourceEntity = null;
    String stackId = null;/*from   w w  w  . j  ava2  s  .c  o m*/
    try (TransactionResource db = Entities.transactionFor(StackResourceEntity.class)) {
        // There is some weirdness in this request.  The stack name represents either the stack name of the
        // non-deleted stack or the stack id of the deleted or non-deleted stack.
        Criteria criteria = Entities.createCriteria(StackResourceEntity.class)
                .add(Restrictions.eq("accountId", accountId))
                .add(Restrictions.or(
                        Restrictions.and(Restrictions.eq("recordDeleted", Boolean.FALSE),
                                Restrictions.eq("stackName", stackNameOrId)),
                        Restrictions.eq("stackId", stackNameOrId)))
                .add(Restrictions.ne("resourceStatus", StackResourceEntity.Status.NOT_STARTED)); // placeholder, AWS doesn't return these
        List<StackResourceEntity> result = criteria.list();
        if (result == null || result.isEmpty()) {
            // TODO: in theory the stack may exist but with no resources.  Either way though there is an error, so this is ok.
            throw new ValidationErrorException("Stack with name " + stackNameOrId + " does not exist");
        }
        for (StackResourceEntity stackResourceEntity : result) {
            if (stackId == null) {
                stackId = stackResourceEntity.getStackId();
            } else if (!stackId.equals(stackResourceEntity.getStackId())) {
                throw new InternalFailureException("Got results from more than one stack");
            }
            if (logicalResourceId.equals(stackResourceEntity.getLogicalResourceId())) {
                if (matchingStackResourceEntity != null) {
                    throw new InternalFailureException("More than one record exists for Resource "
                            + logicalResourceId + " on stack " + stackId);
                } else {
                    matchingStackResourceEntity = stackResourceEntity;
                }
            }
        }
        if (matchingStackResourceEntity == null) {
            throw new ValidationErrorException(
                    "Resource " + logicalResourceId + " does not exist for stack " + stackId);
        }
        db.commit();
    }
    return matchingStackResourceEntity;
}

From source file:com.eucalyptus.cloudformation.entity.StackResourceEntityManager.java

License:Open Source License

public static List<StackResourceEntity> describeStackResources(String accountId, String stackNameOrId,
        String physicalResourceId, String logicalResourceId) {
    List<StackResourceEntity> returnValue = null;
    String stackId = null;//w  w w  .j a v a  2 s  . c  o m
    try (TransactionResource db = Entities.transactionFor(StackResourceEntity.class)) {
        // There is some weirdness in this request.  The stack name represents either the stack name of the
        // non-deleted stack or the stack id of the deleted or non-deleted stack.
        Criteria criteria = Entities.createCriteria(StackResourceEntity.class)
                .add(Restrictions.eq("accountId", accountId));
        if (stackNameOrId != null) {
            criteria.add(Restrictions.or(
                    Restrictions.and(Restrictions.eq("recordDeleted", Boolean.FALSE),
                            Restrictions.eq("stackName", stackNameOrId)),
                    Restrictions.eq("stackId", stackNameOrId)));
        }
        if (logicalResourceId != null) {
            criteria.add(Restrictions.eq("logicalResourceId", logicalResourceId));
        }
        if (physicalResourceId != null) {
            criteria.add(Restrictions.eq("physicalResourceId", logicalResourceId));
        }
        criteria.add(Restrictions.ne("resourceStatus", StackResourceEntity.Status.NOT_STARTED)); // placeholder, AWS doesn't return these
        returnValue = criteria.list();
        db.commit();
    }
    return returnValue;
}

From source file:com.eucalyptus.objectstorage.metadata.DbBucketMetadataManagerImpl.java

License:Open Source License

@Override
public long countBucketsByUser(String userIamId) throws MetadataOperationFailureException {
    Bucket searchBucket = new Bucket();
    searchBucket.setOwnerIamUserId(userIamId);
    try (TransactionResource db = Entities.transactionFor(Bucket.class)) {
        return Entities.count(searchBucket, Restrictions.ne("state", BucketState.deleting),
                new HashMap<String, String>());
    } catch (Exception e) {
        LOG.warn("Error counting buckets for user " + userIamId + " due to DB transaction error", e);
        throw new MetadataOperationFailureException(e);
    }/*w  w w. j av a 2  s.  c  o m*/
}

From source file:com.eucalyptus.objectstorage.metadata.DbBucketMetadataManagerImpl.java

License:Open Source License

@Override
public long countBucketsByAccount(String canonicalId) throws MetadataOperationFailureException {
    Bucket searchBucket = new Bucket();
    searchBucket.setOwnerCanonicalId(canonicalId);
    try (TransactionResource db = Entities.transactionFor(Bucket.class)) {
        return Entities.count(searchBucket, Restrictions.ne("state", BucketState.deleting),
                new HashMap<String, String>());
    } catch (Exception e) {
        LOG.warn("Error counting buckets for account canonicalId " + canonicalId
                + " due to DB transaction error", e);
        throw new MetadataOperationFailureException(e);
    }/*from  w  ww.j  a v a  2 s.  c o m*/
}

From source file:com.evolveum.midpoint.repo.sql.query.restriction.OrgRestriction.java

License:Apache License

@Override
public Criterion interpret(OrgFilter filter) throws QueryException {
    if (filter.isRoot()) {
        //         Criteria pCriteria = getInterpreter().getCriteria(null);
        DetachedCriteria dc = DetachedCriteria.forClass(ROrgClosure.class);
        String[] strings = new String[1];
        strings[0] = "descendant.oid";
        Type[] type = new Type[1];
        type[0] = StringType.INSTANCE;//  w ww.  ja v  a2  s. c  o m
        dc.setProjection(Projections.sqlGroupProjection("descendant_oid",
                "descendant_oid having count(descendant_oid)=1", strings, type));
        //         pCriteria.add(Subqueries.in("this.oid", dc));
        return Subqueries.propertyIn("oid", dc);
        //         Query rootOrgQuery = session.createQuery("select org from ROrg as org where org.oid in (select descendant.oid from ROrgClosure group by descendant.oid having count(descendant.oid)=1)");
    }

    if (filter.getOrgRef() == null) {
        throw new QueryException("No organization reference defined in the search query.");
    }

    if (filter.getOrgRef().getOid() == null) {
        throw new QueryException(
                "No oid specified in organization reference " + filter.getOrgRef().debugDump());
    }

    DetachedCriteria detached;
    switch (filter.getScope()) {
    case ONE_LEVEL:
        detached = DetachedCriteria.forClass(RParentOrgRef.class, "p");
        detached.setProjection(Projections.distinct(Projections.property("p.ownerOid")));
        detached.add(Restrictions.eq("p.targetOid", filter.getOrgRef().getOid()));
        break;
    case SUBTREE:
    default:
        detached = DetachedCriteria.forClass(ROrgClosure.class, "cl");
        detached.setProjection(Projections.distinct(Projections.property("cl.descendantOid")));
        detached.add(Restrictions.eq("cl.ancestorOid", filter.getOrgRef().getOid()));
        detached.add(Restrictions.ne("cl.descendantOid", filter.getOrgRef().getOid()));
    }
    String mainAlias = getContext().getAlias(null);
    return Subqueries.propertyIn(mainAlias + ".oid", detached);
}