Example usage for org.hibernate Query setString

List of usage examples for org.hibernate Query setString

Introduction

In this page you can find the example usage for org.hibernate Query setString.

Prototype

@Deprecated
@SuppressWarnings("unchecked")
default Query<R> setString(String name, String val) 

Source Link

Document

Bind a named String-valued parameter.

Usage

From source file:com.edgenius.core.dao.hibernate.CrFileNodeDAOHibernate.java

License:Open Source License

public boolean removeByIdentifier(final String identifierUuid) {
    Query query = getCurrentSesssion().createQuery(REMOVE_BY_IDENTIFIER_UUID);
    query.setString("identifierUuid", identifierUuid);
    int size = query.executeUpdate();
    return size > 0 ? true : false;

}

From source file:com.edgenius.core.dao.hibernate.CrWorkspaceDAOHibernate.java

License:Open Source License

public void updateWorkspacesQuota(final String spacename, final long size) {
    Query query = getCurrentSesssion().createQuery(UPDATE_SPACE_QUOTA);
    query.setLong(0, size);/*from  w ww  .jav a2  s .  co m*/
    query.setString(1, spacename);
    query.executeUpdate();

}

From source file:com.edgenius.core.dao.hibernate.RoleDAOHibernate.java

License:Open Source License

@SuppressWarnings("unchecked")
public List<Role> getRoles(final int roleType, final String filter) {

    String filterWith = "";
    if (!StringUtils.isBlank(filter)) {
        filterWith = " and (r.displayName like :filter or r.description like :filter) ";
    }/*from   w w w.ja v a2 s  .  c  om*/
    Query query = getCurrentSesssion().createQuery(GET_BY_TYPE + filterWith + GET_BY_TYPE_ORDERBY);
    query.setInteger("type", roleType);
    if (!StringUtils.isBlank(filter)) {
        query.setString("filter", "%" + filter.trim() + "%");
    }

    return query.list();
}

From source file:com.edgenius.core.dao.hibernate.UserDAOHibernate.java

License:Open Source License

public int getUserTotalCount(final String filter) {

    String filterWith = "";
    if (!StringUtils.isBlank(filter)) {
        filterWith = " where u.username like :filter or u.fullname like :filter or u.contact.email like :filter ";
    }/*w  ww  .j  a  v  a 2 s .co  m*/
    Query query = getCurrentSesssion().createQuery(GET_USERS_COUNT + filterWith);
    if (!StringUtils.isBlank(filter)) {
        query.setString("filter", "%" + filter.trim() + "%");
    }
    List list = query.list();
    if (list != null && list.size() > 0) {
        return (int) ((Long) list.get(0)).longValue();
    }
    return 0;
}

From source file:com.edgenius.core.dao.hibernate.UserDAOHibernate.java

License:Open Source License

@SuppressWarnings("unchecked")
//JDK1.6 @Override
public List<User> getUsers(final int start, final int returnSize, String sortBy, final String filter,
        boolean sortByDesc) {
    String orderBy = "";
    String filterWith = "";

    if (!StringUtils.isBlank(filter)) {
        filterWith = " where u.username like :filter or u.fullname like :filter or u.contact.email like :filter ";
    }/*w  ww .  j ava  2s.  co m*/
    if (!StringUtils.isBlank(sortBy)) {
        StringBuffer orderSb = new StringBuffer(" order by ");
        String[] sortStr = sortBy.split("\\|");
        String seq = (sortByDesc ? " desc" : " asc");
        for (String str : sortStr) {
            int sort = NumberUtils.toInt(str, -1);
            if (sort == -1)
                continue;
            if (sort == User.SORT_BY_CREATED_DATE)
                orderSb.append("u.createdDate ").append(seq).append(",");
            else if (sort == User.SORT_BY_EMAIL)
                orderSb.append("u.contact.email ").append(seq).append(",");
            else if (sort == User.SORT_BY_USERNAME)
                orderSb.append("u.username ").append(seq).append(",");
            else if (sort == User.SORT_BY_FULL_NAME)
                orderSb.append("u.fullname ").append(seq).append(",");
        }
        if (orderSb.length() > 0) {
            orderBy = orderSb.toString();
            if (orderBy.endsWith(",")) {
                //remove last ","
                orderBy = orderBy.substring(0, orderBy.length() - 1);
            }
        }
    } else {
        //default order
        orderBy = " order by u.createdDate desc";
    }

    final String sql = SQL_GET_USERS + filterWith + orderBy;
    Query query = getCurrentSesssion().createQuery(sql);
    if (!StringUtils.isBlank(filter)) {
        query.setString("filter", "%" + filter.trim() + "%");
    }
    query.setFirstResult(start);
    if (returnSize > 0)
        query.setMaxResults(returnSize);

    return query.list();
}

From source file:com.edgenius.wiki.dao.hibernate.HistoryDAOHibernate.java

License:Open Source License

@SuppressWarnings("unchecked")
public List<History> getByUuid(final String uuid, final int startVer, final int returnCount,
        final Date touchedDate) {
    Query query;
    if (touchedDate == null) {
        query = getCurrentSesssion().createQuery(GET_HISTORY_BY_UUID);
        query.setString(0, uuid);
        query.setInteger(1, startVer <= 0 ? Integer.MAX_VALUE : startVer);
    } else {//from  w w w  .  ja  v  a 2 s .  com
        query = getCurrentSesssion().createQuery(GET_HISTORY_BY_UUID_OLDER_DATE);
        query.setString(0, uuid);
        query.setDate(1, touchedDate);
        query.setInteger(2, startVer <= 0 ? Integer.MAX_VALUE : startVer);
    }
    if (returnCount > 0) {
        query.setMaxResults(returnCount);
    }
    return query.list();

}

From source file:com.edgenius.wiki.dao.hibernate.NotificationDAOHibernate.java

License:Open Source License

@SuppressWarnings("unchecked")
public List<Notification> getResourceMessages(final User user, final boolean sysAdmin,
        final List<Resource> spaceResList, final List<Resource> adminResList, final int start,
        final int retCount) {
    StringBuffer sql = new StringBuffer(GET_MESSAGES_PREFIX);

    Map<Integer, String> queryParams = new HashMap<Integer, String>();
    int queryPos = 0;
    //if users is instance admin, then get all messages... is it good????
    if (!sysAdmin) {
        //first, get messages to all users and specified to given user
        sql.append(" where n.targetType=").append(SharedConstants.MSG_TARGET_ALL_USERS).append(" or ");
        sql.append(" (n.targetType=").append(SharedConstants.MSG_TARGET_USER).append(" and n.targetName=:p")
                .append(queryPos).append(") ");
        queryParams.put(queryPos++, user.getUsername());

        if (adminResList != null && adminResList.size() > 0) {
            sql.append(" or ");

            for (int idx = 0; idx < adminResList.size(); idx++) {
                Resource resource = adminResList.get(idx);
                if (SecurityValues.RESOURCE_TYPES.SPACE.equals(resource.getType())) {
                    //spaces admin permissions
                    sql.append(" (n.targetType=").append(SharedConstants.MSG_TARGET_SPACE_ADMIN_ONLY)
                            .append(" and ");
                    sql.append(" n.targetName=:p").append(queryPos + idx).append(") or ");
                    queryParams.put(queryPos + idx, resource.getResource());
                }//w w w. ja v a  2 s.  c  om
            }
            //remove last "or"
            sql.delete(sql.length() - 3, sql.length());
        }

        if (spaceResList != null && spaceResList.size() > 0) {
            sql.append(" or ");
            queryPos = queryParams.size();
            for (int idx = 0; idx < spaceResList.size(); idx++) {
                Resource resource = spaceResList.get(idx);
                if (SecurityValues.RESOURCE_TYPES.SPACE.equals(resource.getType())) {
                    //spaces all users
                    sql.append(" (n.targetType=").append(SharedConstants.MSG_TARGET_SPACE_CONTRIBUTE_USERS)
                            .append(" and ");
                    sql.append(" n.targetName=:p").append(queryPos + idx).append(") or ");
                    queryParams.put(queryPos + idx, resource.getResource());
                }
            }
            //remove last "or"
            sql.delete(sql.length() - 3, sql.length());
        }

    }

    sql.append(GET_MESSAGES_SUFFIX);
    Query query = getCurrentSesssion().createQuery(sql.toString());
    for (Entry<Integer, String> entry : queryParams.entrySet()) {
        query.setString("p" + entry.getKey(), entry.getValue());
    }

    if (start > 0)
        query.setFirstResult(start);
    if (retCount > 0)
        query.setMaxResults(retCount);

    return query.list();
}

From source file:com.edgenius.wiki.dao.hibernate.PageDAOHibernate.java

License:Open Source License

public List<Page> getRecentPages(final String spaceUname, final int start, final int count,
        final boolean sortByModify) {
    if (StringUtils.isBlank(spaceUname)) {
        String sql;// ww w. ja  v a  2s  . c  om
        if (!sortByModify) {
            sql = GET_INSTANCE_CURRENT_PAGES + "order by p.createdDate  desc";
        } else {
            sql = GET_INSTANCE_CURRENT_PAGES + "order by p.modifiedDate desc";
        }
        Query query = getCurrentSesssion().createQuery(sql);
        if (start > 0)
            query.setFirstResult(start);
        return query.setMaxResults(count).list();
    } else {
        String sql;
        if (!sortByModify) {
            sql = GET_SPACE_CURRNET_PAGES + "order by p.createdDate  desc";
        } else {
            sql = GET_SPACE_CURRNET_PAGES + "order by p.modifiedDate desc";
        }
        Query query = getCurrentSesssion().createQuery(sql);
        query.setString("spaceUname", spaceUname);
        if (start > 0)
            query.setFirstResult(start);
        return query.setMaxResults(count).list();
    }
}

From source file:com.edgenius.wiki.dao.hibernate.PageDAOHibernate.java

License:Open Source License

public List<Page> getUserUpdatedPagesInSpace(final String spaceUname, final User user, final int returnNum) {

    Query query;
    if (user == null || user.isAnonymous()) {
        query = getCurrentSesssion().createQuery(GET_ANONYMOUS_PAGES);
        query.setString(0, spaceUname);
    } else {//from   w ww. ja  va 2 s . c  om
        query = getCurrentSesssion().createQuery(GET_USER_PAGES);
        query.setEntity(0, user);
        query.setEntity(1, user);
        query.setString(2, spaceUname);
    }
    if (returnNum > 0)
        query.setMaxResults(returnNum);

    return query.list();
}

From source file:com.edgenius.wiki.dao.hibernate.PageDAOHibernate.java

License:Open Source License

public List<Page> getPagesInSpace(final String spaceUname, final Date touchedDate, final int returnNum) {
    Query query;
    if (touchedDate == null) {
        query = getCurrentSesssion().createQuery(GET_PAGES);
        query.setString(0, spaceUname);
    } else {//from w ww .  jav a  2 s  . c o  m
        query = getCurrentSesssion().createQuery(GET_PAGES_AFTER_TOUCHED);
        query.setString(0, spaceUname);
        //DON'T user query.setDate()!!! It only compare Date rather than time, it means the time part is truncated!
        //or use query.setTimestamp();
        query.setParameter(1, touchedDate);
    }
    if (returnNum > 0)
        query.setMaxResults(returnNum);

    return query.list();
}