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.green.modules.cms.service.ArticleService.java

License:Open Source License

@Transactional(readOnly = false)
public Page<Article> find(Page<Article> page, Article article, boolean isDataScopeFilter) {
    // ??6??/*from  w  w  w .ja  v  a  2s. c  om*/
    Date updateExpiredWeightDate = (Date) CacheUtils.get("updateExpiredWeightDateByArticle");
    if (updateExpiredWeightDate == null
            || (updateExpiredWeightDate != null && updateExpiredWeightDate.getTime() < new Date().getTime())) {
        articleDao.updateExpiredWeight();
        CacheUtils.put("updateExpiredWeightDateByArticle", DateUtils.addHours(new Date(), 6));
    }
    DetachedCriteria dc = articleDao.createDetachedCriteria();
    dc.createAlias("category", "category");
    dc.createAlias("category.site", "category.site");
    if (article.getCategory() != null && StringUtils.isNotBlank(article.getCategory().getId())
            && !Category.isRoot(article.getCategory().getId())) {
        Category category = categoryDao.get(article.getCategory().getId());
        if (category != null) {
            dc.add(Restrictions.or(Restrictions.eq("category.id", category.getId()),
                    Restrictions.like("category.parentIds", "%," + category.getId() + ",%")));
            dc.add(Restrictions.eq("category.site.id", category.getSite().getId()));
            article.setCategory(category);
        } else {
            dc.add(Restrictions.eq("category.site.id", Site.getCurrentSiteId()));
        }
    } else {
        dc.add(Restrictions.eq("category.site.id", Site.getCurrentSiteId()));
    }
    if (StringUtils.isNotEmpty(article.getTitle())) {
        dc.add(Restrictions.like("title", "%" + article.getTitle() + "%"));
    }
    if (StringUtils.isNotEmpty(article.getPosid())) {
        dc.add(Restrictions.like("posid", "%," + article.getPosid() + ",%"));
    }
    if (StringUtils.isNotEmpty(article.getImage()) && Article.YES.equals(article.getImage())) {
        dc.add(Restrictions.and(Restrictions.isNotNull("image"), Restrictions.ne("image", "")));
    }
    if (article.getCreateBy() != null && StringUtils.isNotBlank(article.getCreateBy().getId())) {
        dc.add(Restrictions.eq("createBy.id", article.getCreateBy().getId()));
    }
    if (isDataScopeFilter) {
        dc.createAlias("category.office", "categoryOffice").createAlias("createBy", "createBy");
        dc.add(dataScopeFilter(UserUtils.getUser(), "categoryOffice", "createBy"));
    }
    dc.add(Restrictions.eq(Article.FIELD_DEL_FLAG, article.getDelFlag()));
    if (StringUtils.isBlank(page.getOrderBy())) {
        dc.addOrder(Order.desc("weight"));
        dc.addOrder(Order.desc("updateDate"));
    }
    return articleDao.find(page, dc);
}

From source file:com.green.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 && StringUtils.isNotBlank(user.getCompany().getId())) {
        dc.add(Restrictions.or(Restrictions.eq("company.id", user.getCompany().getId()),
                Restrictions.like("company.parentIds", "%," + user.getCompany().getId() + ",%")));
    }//from w w w. j  av a 2  s.  c  o  m
    dc.createAlias("office", "office");
    if (user.getOffice() != null && StringUtils.isNotBlank(user.getOffice().getId())) {
        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", "1"));
    }
    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.FIELD_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("name"));
    }
    return userDao.find(page, dc);
}

From source file:com.griffinslogistics.book.BookService.java

@Override
public boolean updateBook(Book book) {

    // update all Titles for the same bookNumber in the same transport
    DetachedCriteria criteria = DetachedCriteria.forClass(Book.class);
    criteria.add(Restrictions.eq("transportId", book.getTransportId()));
    criteria.add(Restrictions.eq("bookNumber", book.getBookNumber()));
    criteria.add(Restrictions.ne("id", book.getId()));

    List<Book> toBeUpdatedList = this.dao.getAllByDetachedCriteria(criteria);

    for (Book bookToBeUpdated : toBeUpdatedList) {
        bookToBeUpdated.setTitle(book.getTitle());
        this.dao.update(bookToBeUpdated);
    }/*from   w ww . ja v a  2 s . co  m*/

    return this.dao.update(book);
}

From source file:com.headstrong.teevra.services.process.dao.impl.ProcessDAOImpl.java

License:Open Source License

public void saveProcess(ProcessEO processToSave) throws ProcessServiceException {

    DetachedCriteria criteria = DetachedCriteria.forClass(ProcessEO.class);
    criteria.add(Restrictions.eq("prcsName", processToSave.getPrcsName()));
    // processToSave.getPrcsId() != null, it means the process is not new so
    // we set the modified details whenever the process is to be saved
    if (processToSave.getPrcsId() != null) {
        criteria.add(Restrictions.ne("prcsId", processToSave.getPrcsId()));
        // set process modified details
        processToSave.setModifiedBy(System.getProperty("user.name"));
        processToSave.setModifiedDate(new Timestamp(System.currentTimeMillis()));
    }/*  w w  w  .  j  a  v a  2 s  . co m*/

    List<ProcessEO> processList = super.getByCriteria(criteria);

    if (!processList.isEmpty()) {
        logger.error("Couldn't save process: " + processToSave.getPrcsName()
                + ". A process with the same name already exists in the system");
        throw new UniqueProcessException("A process with the name " + "'" + processToSave.getPrcsName() + "'"
                + " already exists in the system");
    } else {
        super.saveOrUpdate(processToSave);
    }

}

From source file:com.headstrong.teevra.services.refdata.dao.impl.DataSourceConfigDAOImpl.java

License:Open Source License

public void saveDataSourceConfig(DataSourceConfigEO dataSourceConfigToSave) throws RefDataServiceException {

    DetachedCriteria criteria = DetachedCriteria.forClass(DataSourceConfigEO.class);
    criteria.add(Restrictions.eq("dataSourceName", dataSourceConfigToSave.getDataSourceName()));
    if (dataSourceConfigToSave.getDataSourceId() != null) {
        criteria.add(Restrictions.ne("dataSourceId", dataSourceConfigToSave.getDataSourceId()));
    }//from  w  ww.j  a  v  a  2 s  .co m
    List<DataSourceConfigEO> configList = super.getByCriteria(criteria);

    if (!configList.isEmpty()) {
        logger.error("A process with the same name already exists in the system");
        throw new UniqueDataSourceConfigException("A data source with the name " + "'"
                + dataSourceConfigToSave.getDataSourceName() + "'" + " is already exists in the system");
    } else {
        super.saveOrUpdate(dataSourceConfigToSave);

    }

}

From source file:com.headstrong.teevra.services.refdata.dao.impl.RefDataConfigDAOImpl.java

License:Open Source License

public void saveRefDataConfig(RefDataConfigEO refDataConfigToSave) throws RefDataServiceException {
    DetachedCriteria criteria = DetachedCriteria.forClass(RefDataConfigEO.class);
    criteria.add(Restrictions.eq("refDataName", refDataConfigToSave.getRefDataName()));
    if (refDataConfigToSave.getRefDataId() != null) {
        criteria.add(Restrictions.ne("refDataId", refDataConfigToSave.getRefDataId()));
    }/*from  w ww  .  j  a  v a 2 s . c  om*/
    List<RefDataConfigEO> configList = super.getByCriteria(criteria);

    if (!configList.isEmpty()) {
        logger.error("A Refdata with the same name already exists in the system");
        throw new UniqueRefDataConfigException("A reference data with the name " + "'"
                + refDataConfigToSave.getRefDataName() + "'" + " is already exists in the system");
    } else {
        super.saveOrUpdate(refDataConfigToSave);

    }

}

From source file:com.headstrong.teevra.services.serveradmin.dao.impl.ServerConfigDAOImpl.java

License:Open Source License

public void registerServer(ServerConfigEO serverToRegister) throws ServerAdminServiceException {
    DetachedCriteria criteria = DetachedCriteria.forClass(ServerConfigEO.class);
    criteria.add(Restrictions.eq("serverName", serverToRegister.getServerName()));
    if (serverToRegister.getServerId() != null) {
        criteria.add(Restrictions.ne("serverId", serverToRegister.getServerId()));
    }//from w w w  .  j av a 2 s .c o  m
    List<ServerConfigEO> serverList = super.getByCriteria(criteria);

    if (!serverList.isEmpty()) {
        logger.error("A server with the same name already exists in the system");
        throw new UniqueServerException("A server with the name " + "'" + serverToRegister.getServerName() + "'"
                + " is already exists in the system");
    } else {
        super.saveOrUpdate(serverToRegister);
    }

}

From source file:com.headstrong.teevra.services.statemachine.dao.impl.StateMachineDAOImpl.java

License:Open Source License

public void saveStateMachine(StateMachineEO stateMachineToSave) throws StateMachineServiceException {
    DetachedCriteria criteria = DetachedCriteria.forClass(StateMachineEO.class);
    criteria.add(Restrictions.eq("stateMachineName", stateMachineToSave.getStateMachineName()));
    if (stateMachineToSave.getStateMachineId() != null) {
        criteria.add(Restrictions.ne("stateMachineId", stateMachineToSave.getStateMachineId()));
    }/*from  w w w.  j av a 2 s.c  om*/
    List<StateMachineEO> stateMachineList = super.getByCriteria(criteria);

    if (!stateMachineList.isEmpty()) {
        logger.error("A state machine with the same name already exists in the system");
        throw new UniqueStateMachineException("A state machine with the name " + "'"
                + stateMachineToSave.getStateMachineName() + "'" + " already exists in the system");
    } else {
        super.saveOrUpdate(stateMachineToSave);
    }

}

From source file:com.headstrong.teevra.services.useradmin.dao.impl.RoleDAOImpl.java

License:Open Source License

public void saveRole(RoleEO roleToSave) throws UserAdminServiceException {
    DetachedCriteria criteria = DetachedCriteria.forClass(RoleEO.class);
    criteria.add(Restrictions.eq("roleName", roleToSave.getRoleName()));
    if (roleToSave.getRoleId() != null) {
        criteria.add(Restrictions.ne("roleId", roleToSave.getRoleId()));
    }//w w  w .j  a va2  s  . c om
    List<RoleEO> roleList = super.getByCriteria(criteria);

    if (!roleList.isEmpty()) {
        logger.error("Couldn't save role: " + roleToSave.getRoleName()
                + " A role with the same name already exists in the system");
        throw new UniqueRoleException("A role with the name " + "'" + roleToSave.getRoleName() + "'"
                + " already exists in the system");
    } else {
        super.saveOrUpdate(roleToSave);
    }

}

From source file:com.headstrong.teevra.services.useradmin.dao.impl.UserDAOImpl.java

License:Open Source License

public void saveUser(UserEO userToSave) throws UserAdminServiceException {

    DetachedCriteria criteria = DetachedCriteria.forClass(UserEO.class);
    criteria.add(Restrictions.eq("userName", userToSave.getUserName()));
    if (userToSave.getUserId() != null) {
        criteria.add(Restrictions.ne("userId", userToSave.getUserId()));
    }//from ww w  . j  a va  2  s.  c  o  m
    List<UserEO> userList = super.getByCriteria(criteria);

    if (!userList.isEmpty()) {
        logger.error("Couldn't register user: " + userToSave.getUserName()
                + "A user with the same name already exists in the system");
        throw new UniqueUserException("A user with the name " + "'" + userToSave.getUserName() + "'"
                + " already exists in the system");
    } else {
        super.saveOrUpdate(userToSave);
    }
}