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.online.restful.UsersSrv.java

License:Apache License

@GET
@Produces({ MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON })
public String getUsers(@Context LinkBuilders linkProcessor, @Context UriInfo uriInfo) {

    String json = "";

    String userName = uriInfo.getQueryParameters().get("user").get(0);
    if (userName == null || userName.equals("null"))
        return "{}";

    List<Users> userFounds = (List<Users>) getHibernateTemplate().find("from Users u where u.username = ?",
            userName);/* w  w  w.  j  a  v  a  2  s  . c  o  m*/
    if (userFounds == null || userFounds.isEmpty())
        return "{}";
    Users userFound = userFounds.get(0);

    Session session = this.getSessionFactory().openSession();
    session.beginTransaction();
    List<Users> userList = new ArrayList<Users>();
    List<UsersTO> userTOList = new ArrayList<UsersTO>();
    if (userFound.getUserRole().getRole().equals("ROLE_SUPER_ADMIN")) {
        userList = (List<Users>) session.createQuery("from Users").list();
    } else if (userFound.getUserRole().getRole().equals("ROLE_ADMIN")) {
        Integer idCompany = userFound.getCompany().getId();
        userList = (List<Users>) session.createCriteria(Users.class)
                .add(Restrictions.eq("company.id", idCompany))
                .add(Restrictions.ne("userRole.role", "ROLE_SUPER_ADMIN")).list();
    } else if (userFound.getUserRole().getRole().equals("ROLE_CLIENT")) {
        Integer idCompany = userFound.getCompany().getId();
        userList = (List<Users>) session.createCriteria(Users.class)
                .add(Restrictions.eq("company.id", idCompany))
                .add(Restrictions.ne("userRole.role", "ROLE_CLIENT")).list();
    }
    for (Users user : userList) {
        userTOList.add(new UsersTO(user.getUsername(), user.getUserRole().getRole()));
    }

    Gson gson = new GsonBuilder().setPrettyPrinting().excludeFieldsWithoutExposeAnnotation().create();
    json = gson.toJson(userTOList);

    session.close();

    return json;
}

From source file:com.orig.gls.group.dao.Group.java

public static ArrayList getUnverifiedGroups(String username) {
    ArrayList arr = new ArrayList();
    Session session = HibernateUtil.getSessionFactory().openSession();
    Transaction tx = null;/*from w w  w  .j  ava  2s.  co m*/
    List<GroupsTableMod> list;
    try {
        tx = session.beginTransaction();
        Criteria cr = session.createCriteria(GroupsTableMod.class);
        cr.add(Restrictions.ne("rcreUserId", username));
        list = cr.list();
        for (GroupsTableMod group : list) {
            ArrayList one = new ArrayList();
            one.add(group.getGroupCode());
            one.add(String.valueOf(group.getGroupId()));
            one.add(group.getGroupName());
            one.add(sdf.format(group.getRcreTime()));
            one.add(group.getRcreUserId());
            one.add(String.valueOf(group.getSolId()));//5
            one.add(group.getBranchName());//6
            one.add(group.getGrpMgrId());//7
            one.add(group.getGrpRegNo());//8
            one.add(sdf.format(group.getFormationDate()));//9
            one.add(group.getGpRegion());//10
            one.add(group.getGroupCenter());//11
            one.add(group.getGroupVillage());//12
            one.add(group.getGroupAddress());//13
            one.add(group.getGroupPhone());//14
            one.add(sdf.format(group.getFirstMeetDate()));//15
            one.add(sdf.format(group.getNxtMeetDate()));//16
            one.add(group.getMeetTime());//17
            one.add(group.getMeetPlace());//18
            one.add(String.valueOf(group.getMaxAllowedMembers()));//19
            one.add(String.valueOf(group.getMaxAllowedSubGrps()));//20
            String groupchair = "";
            String grouptre = "";
            String groupsec = "";
            if (group.getGpChair() != null) {
                groupchair = group.getGpChair();
            }
            if (group.getGpTreasurer() != null) {
                grouptre = group.getGpTreasurer();
            }
            if (group.getGpSecretary() != null) {
                groupsec = group.getGpSecretary();
            }
            one.add(groupchair);//21
            one.add(grouptre);//22
            one.add(groupsec);//23
            one.add(group.getGpStatus());//24
            one.add(group.getGpStatusCode());//25
            one.add(String.valueOf(group.getNoOfMembers()));//26
            one.add(group.getMeetFrequency());//27
            one.add(String.valueOf(group.getSavingAccounts()));//28
            one.add(String.valueOf(group.getSavingsAmt()));//29
            one.add(String.valueOf(group.getLoanAccounts()));//30
            one.add(String.valueOf(group.getOutstandingBal()));//31
            arr.add(one);
        }
        tx.commit();
    } catch (Exception asd) {
        log.debug(asd.getMessage());
        if (tx != null) {
            tx.rollback();
        }
    } finally {
        session.close();
    }
    return arr;
}

From source file:com.orig.gls.subgroup.dao.SubGroup.java

public static ArrayList getUnverifiedSubGroups(String username) {
    ArrayList arr = new ArrayList();
    Session session = HibernateUtil.getSessionFactory().openSession();
    Transaction tx = null;// w w w.j  a v  a  2  s .com
    List<SubGrpTableMod> list;
    try {
        tx = session.beginTransaction();
        Criteria cr = session.createCriteria(SubGrpTableMod.class);
        cr.add(Restrictions.ne("rcreUserId", username));
        list = cr.list();
        for (SubGrpTableMod group : list) {
            ArrayList one = new ArrayList();
            one.add(group.getSubGroupCode());//0
            one.add(String.valueOf(group.getSubGroupId()));//1
            one.add(group.getSubGroupName());//2
            one.add(sdf.format(group.getRcreTime()));//3
            one.add(group.getRcreUserId());//4
            one.add(String.valueOf(group.getSolId()));//5
            one.add(group.getBranchName());//6
            one.add(group.getSubGrpMgrId());//7
            one.add(group.getSubGrpRegNo());//8
            one.add(sdf.format(group.getFormationDate()));//9
            one.add(group.getSubGpRegion());//10
            one.add(group.getSubGroupCenter());//11
            one.add(group.getSubGroupVillage());//12
            one.add(group.getSubGroupAddress());//13
            one.add(group.getSubGroupPhone());//14
            one.add(sdf.format(group.getFirstMeetDate()));//15
            one.add(sdf.format(group.getNxtMeetDate()));//16
            one.add(group.getMeetTime());//17
            one.add(group.getMeetPlace());//18
            one.add(String.valueOf(group.getMaxAllowedMembers()));//19
            String groupchair = "";
            String grouptre = "";
            String groupsec = "";
            if (group.getSubGpChair() != null) {
                groupchair = group.getSubGpChair();
            }
            if (group.getSubGpTreasurer() != null) {
                grouptre = group.getSubGpTreasurer();
            }
            if (group.getSubGpSecretary() != null) {
                groupsec = group.getSubGpSecretary();
            }
            one.add(groupchair);//20
            one.add(grouptre);//21
            one.add(groupsec);//22
            one.add(group.getSubGpStatus());//23
            one.add(group.getSubGpStatusCode());//24
            one.add(String.valueOf(group.getNoOfMembers()));//25
            one.add(group.getMeetFrequency());//26
            one.add(String.valueOf(group.getSavingAccounts()));//27
            one.add(String.valueOf(group.getSavingsAmt()));//28
            one.add(String.valueOf(group.getLoanAccounts()));//29
            one.add(String.valueOf(group.getOutstandingBal()));//30
            List<GroupsTable> lgs = Group.getgroupDetails(group.getGroupId());
            String groupcode = "";
            String groupname = "";
            for (GroupsTable lg : lgs) {
                groupcode = lg.getGroupCode();
                groupname = lg.getGroupName();
            }
            one.add(groupcode);
            one.add(groupname);
            arr.add(one);
        }
        tx.commit();
    } catch (Exception asd) {
        log.debug(asd.getMessage());
        if (tx != null) {
            tx.rollback();
        }
    } finally {
        session.close();
    }
    return arr;
}

From source file:com.orig.gls.tran.dao.Transact.java

public static ArrayList getAllAccountsMappedtoSubGroup(String groupCode, String subgroupCode) {
    ArrayList arr = new ArrayList();
    Session session = HibernateUtil.getSessionFactory().openSession();
    Transaction tx = null;/*from  www  .j ava  2 s  .  co  m*/
    List<GeneralAcctMastTable> list;
    try {
        tx = session.beginTransaction();
        Criteria cr = session.createCriteria(GeneralAcctMastTable.class);
        GlsProp pr = new GlsProp();
        String schm = pr.getDBProperty().getProperty("wholesale.schmecode");
        cr.add(Restrictions.eq("subGroupId", subgroupCode));
        cr.add(Restrictions.eq("groupId", groupCode));
        cr.add(Restrictions.ne("schmCode", schm));
        list = cr.list();
        for (GeneralAcctMastTable group : list) {
            ArrayList one = new ArrayList();
            one.add(group.getForacid());//0
            one.add(group.getAcctName());//1
            one.add(group.getGroupId());//2
            one.add(group.getSubGroupId());//3
            arr.add(one);
        }
        tx.commit();
    } catch (Exception asd) {
        log.debug(asd.getMessage());
        if (tx != null) {
            tx.rollback();
        }
    } finally {
        session.close();
    }
    return arr;
}

From source file:com.orig.gls.tran.dao.Transact.java

public static ArrayList getAccountMappedtoSubGroup(String groupCode, String subgroupCode) {
    Session session = HibernateUtil.getSessionFactory().openSession();
    Transaction tx = null;/*w  w  w  . ja v a  2  s.c  o  m*/
    ArrayList arr = new ArrayList();
    List<GeneralAcctMastTable> list;
    try {
        tx = session.beginTransaction();
        Criteria cr = session.createCriteria(GeneralAcctMastTable.class);
        GlsProp pr = new GlsProp();
        String schm = pr.getDBProperty().getProperty("operative.schmecode");
        cr.add(Restrictions.eq("subGroupId", subgroupCode));
        cr.add(Restrictions.eq("groupId", groupCode));
        cr.add(Restrictions.ne("schmCode", schm));
        list = cr.list();
        for (GeneralAcctMastTable group : list) {
            ArrayList one = new ArrayList();
            one.add(group.getForacid());//0
            one.add(group.getAcctName());//1
            arr.add(one);
        }
        tx.commit();
    } catch (Exception asd) {
        log.debug(asd.getMessage());
        if (tx != null) {
            tx.rollback();
        }
    } finally {
        session.close();
    }
    return arr;
}

From source file:com.ourlife.dev.modules.sys.service.SystemService.java

License:Open Source License

public Page<User> findUser(Page<User> page, User user) {
    DetachedCriteria dc = userDao.createDetachedCriteria();
    User currentUser = UserUtils.getUser();
    dc.createAlias("company", "company");
    if (user.getCompany() != null && user.getCompany().getId() != null) {
        dc.add(Restrictions.or(Restrictions.eq("company.id", user.getCompany().getId()),
                Restrictions.like("company.parentIds", "%," + user.getCompany().getId() + ",%")));
    }/*from w  w  w. j  av  a2  s .c o m*/
    dc.createAlias("office", "office");
    if (user.getOffice() != null && user.getOffice().getId() != null) {
        dc.add(Restrictions.or(Restrictions.eq("office.id", user.getOffice().getId()),
                Restrictions.like("office.parentIds", "%," + user.getOffice().getId() + ",%")));
    }
    // ????
    if (!currentUser.isAdmin()) {
        dc.add(Restrictions.ne("id", 1L));
    }
    dc.add(dataScopeFilter(currentUser, "office", ""));
    // System.out.println(dataScopeFilterString(currentUser, "office", ""));
    if (StringUtils.isNotEmpty(user.getLoginName())) {
        dc.add(Restrictions.like("loginName", "%" + user.getLoginName() + "%"));
    }
    if (StringUtils.isNotEmpty(user.getName())) {
        dc.add(Restrictions.like("name", "%" + user.getName() + "%"));
    }
    dc.add(Restrictions.eq(User.DEL_FLAG, User.DEL_FLAG_NORMAL));
    if (!StringUtils.isNotEmpty(page.getOrderBy())) {
        dc.addOrder(Order.asc("company.code")).addOrder(Order.asc("office.code")).addOrder(Order.desc("id"));
    }
    return userDao.find(page, dc);
}

From source file:com.ponysdk.hibernate.query.decorator.AbstractCriteriaDecorator.java

License:Apache License

@SuppressWarnings("rawtypes")
@Override/*from w w w .  ja  v  a2s . co m*/
public void render(final CriteriaContext context) {
    final Criterion field = context.getCriterion();
    Criteria criteria = context.getOrderingCriteria();

    final List<String> propertyNamePath = Arrays.asList(field.getPojoProperty().split(REGEX_SPLIT));
    final Iterator<String> iter = propertyNamePath.iterator();
    String key = null;
    String associationPath = null;
    if (propertyNamePath.size() == 1) {
        associationPath = iter.next();
    } else
        while (iter.hasNext()) {
            key = iter.next();
            if (associationPath == null) {
                associationPath = new String(key);
            } else {
                associationPath += "." + key;
            }
            if (iter.hasNext()) {
                criteria = criteria.createCriteria(associationPath, key, CriteriaSpecification.INNER_JOIN);
                associationPath = new String(key);
            }
        }

    final T value = getObjectValue(field);
    ComparatorType comparator = field.getComparator();

    if (value != null) {
        if (value.toString().contains("%")) {
            comparator = ComparatorType.LIKE;
        }
    }

    if (field.getValue() != null || field.getComparator() == ComparatorType.IS_NULL
            || field.getComparator() == ComparatorType.IS_NOT_NULL) {

        switch (comparator) {
        case EQ:
            criteria.add(Restrictions.eq(associationPath, value));
            break;
        case GE:
            criteria.add(Restrictions.ge(associationPath, value));
            break;
        case GT:
            criteria.add(Restrictions.gt(associationPath, value));
            break;
        case LE:
            criteria.add(Restrictions.le(associationPath, value));
            break;
        case LT:
            criteria.add(Restrictions.lt(associationPath, value));
            break;
        case NE:
            criteria.add(Restrictions.ne(associationPath, value));
            break;
        case LIKE:
            criteria.add(Restrictions.ilike(associationPath, value));
            break;
        case IS_NULL:
            criteria.add(Restrictions.isNull(associationPath));
            break;
        case IS_NOT_NULL:
            criteria.add(Restrictions.isNotNull(associationPath));
            break;
        case IN:
            if (value instanceof Collection) {
                criteria.add(Restrictions.in(associationPath, (Collection) value));
            } else if (value instanceof Object[]) {
                criteria.add(Restrictions.in(associationPath, (Object[]) value));
            } else {
                log.warn("Type not allowed for IN clause: " + value.getClass() + ", value: " + value);
            }
            break;

        default:
            log.warn("Restriction not supported: " + comparator);
            break;
        }
    }

    switch (field.getSortingType()) {
    case ASCENDING:
        criteria.addOrder(Order.asc(associationPath));
        break;
    case DESCENDING:
        criteria.addOrder(Order.desc(associationPath));
        break;
    case NONE:
        break;
    }

}

From source file:com.prueba.spring.dao.impl.EventoDAO.java

@Transactional(readOnly = true)
public RespuestaGenerica<List<Evento>> obtenerEventosSinColaborador(int idColaborador) {
    RespuestaGenerica<List<Evento>> respuesta;
    try {/*from w  w  w.  ja v  a2 s . co m*/
        this.iniciaOperacion();
        Criteria criteria = session.createCriteria(Evento.class);
        criteria.createAlias("colaboradores", "c", JoinType.LEFT_OUTER_JOIN).add(Restrictions
                .or(Restrictions.ne("c.idColaborador", idColaborador), Restrictions.isNull("c.idColaborador")));
        List<Evento> eventos = criteria.list();
        respuesta = new RespuestaGenerica<List<Evento>>(eventos);
    } catch (Exception ex) {
        Logger.getLogger(EventoDAO.class.getName()).log(Level.SEVERE, null, ex);
        respuesta = new RespuestaGenerica(ex);
    } finally {
        try {
            session.close();
        } catch (Exception ex) {
            Logger.getLogger(EventoDAO.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    return respuesta;
}

From source file:com.qcadoo.model.api.search.SearchRestrictions.java

License:Open Source License

/**
 * Creates criterion which checks if field isn't equal to given value.
 * //w  w  w .jav  a  2s. com
 * @param field
 *            field
 * @param value
 *            value
 * @return criterion
 */
public static SearchCriterion ne(final String field, final Object value) {
    return new SearchCriterionImpl(Restrictions.ne(field, value));
}

From source file:com.reignite.parser.QueryParser.java

License:Open Source License

private Criterion processField(JSONObject where) throws ParserException {
    String field = JSONObject.getNames(where)[0];
    JSONObject exp;/*from w  ww  . j ava2 s .  co  m*/
    try {
        exp = where.getJSONObject(field);
    } catch (JSONException e) {
        throw new ParserException("field expressions must be JSON Object: " + field);
    }
    ExpressionType type = ExpressionType.get(JSONObject.getNames(exp)[0]);
    Object value = null;
    // if the field is a join
    if (field.indexOf(".") > -1) {
        String join = field.substring(0, field.indexOf("."));
        query.createJoin(join);
    }
    switch (type) {
    case IN:
    case NOT_IN:
        try {
            value = createArray(exp.getJSONArray(type.getName()));
        } catch (JSONException e) {
            throw new ParserException("in and not in expressions must be arrays: " + exp);
        }
        break;
    default:
        try {
            value = createValue(exp.get(type.getName()));
        } catch (JSONException e) {
            throw new ParserException("expressions must have a value: " + exp);
        }
    }

    switch (type) {
    case GREATER_THAN:
        return Restrictions.gt(field, value);
    case IN:
        return Restrictions.in(field, (Object[]) value);
    case LESS_THAN:
        return Restrictions.lt(field, value);
    case LIKE:
        MatchMode match = MatchMode.EXACT;
        String toMatch = value.toString();
        if (value.toString().startsWith("%")) {
            match = MatchMode.END;
            toMatch = toMatch.substring(1);
        }
        if (value.toString().endsWith("%")) {
            toMatch = toMatch.substring(0, toMatch.length() - 1);
            if (match == MatchMode.END) {
                match = MatchMode.ANYWHERE;
            } else {
                match = MatchMode.START;
            }
        }
        return Restrictions.ilike(field, toMatch, match);
    case NOT_EQUAL:
        if (value == null) {
            return Restrictions.isNotNull(field);
        }
        return Restrictions.ne(field, value);
    case NOT_IN:
        return Restrictions.not(Restrictions.in(field, (Object[]) value));
    case EQUAL:
    default:
        if (value == null) {
            return Restrictions.isNull(field);
        }
        return Restrictions.eq(field, value);
    }

}