Example usage for org.hibernate Query setEntity

List of usage examples for org.hibernate Query setEntity

Introduction

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

Prototype

@Deprecated
@SuppressWarnings("unchecked")
Query<R> setEntity(String name, Object val);

Source Link

Document

Bind an instance of a mapped persistent class to a named query parameter.

Usage

From source file:org.glite.security.voms.admin.persistence.dao.VOMSGroupDAO.java

License:Apache License

public SearchResults getMembers(VOMSGroup g, int firstResult, int maxResults) {

    Set groupMembers = g.getMembers();
    // int count = g.getMembers().size(); // Maybe the HQL query is more
    // efficient//from ww  w  . j  a  v a2 s  .co m

    int count = groupMembers.size();

    SearchResults results = SearchResults.instance();

    String queryString = "select m.user as user from org.glite.security.voms.admin.persistence.model.VOMSMapping m where m.group = :group and m.role is null";

    Query q = HibernateFactory.getSession().createQuery(queryString).setFirstResult(firstResult)
            .setMaxResults(maxResults);

    q.setEntity("group", g);

    List res = q.list();

    results.setSearchString(null);
    results.setResults(res);
    results.setCount(count);
    results.setFirstResult(firstResult);
    results.setResultsPerPage(maxResults);

    return results;

}

From source file:org.glite.security.voms.admin.persistence.dao.VOMSGroupDAO.java

License:Apache License

public int countMatchingMembers(VOMSGroup g, String searchString) {

    if (g == null)
        throw new NullArgumentException("Cannot search members in a null group!");

    String sString = "%" + searchString + "%";

    String queryString = "select count(m.user) as u from VOMSMapping m join m.user.certificates as cert where "
            + "m.group = :group and m.role is null and " + "(cert.subjectString like :searchString "
            + "or cert.ca.subjectString like :searchString " + "or m.user.name like :searchString "
            + "or m.user.surname like :searchString " + "or m.user.emailAddress like :searchString "
            + "or m.user.institution like :searchString)";

    // String queryString =
    // "select count(m.user) from
    // org.glite.security.voms.admin.persistence.model.VOMSMapping m where
    // m.group = :group and m.role is null "+
    // "and m.user.dn like :searchString";

    Query q = HibernateFactory.getSession().createQuery(queryString).setString("searchString", sString);

    q.setEntity("group", g);

    return ((Long) q.uniqueResult()).intValue();

}

From source file:org.glite.security.voms.admin.persistence.dao.VOMSGroupDAO.java

License:Apache License

public SearchResults searchMembers(VOMSGroup g, String searchString, int firstResult, int maxResults) {

    if (g == null)
        throw new NullArgumentException("Cannot search members in a null group!");

    if (searchString == null || searchString.equals("") || searchString.length() == 0)
        return getMembers(g, firstResult, maxResults);

    SearchResults results = SearchResults.instance();
    String sString = "%" + searchString + "%";

    String queryString = "select m.user as u from VOMSMapping m join m.user.certificates as cert where "
            + "m.group = :group and m.role is null and " + "(cert.subjectString like :searchString "
            + "or cert.ca.subjectString like :searchString " + "or m.user.name like :searchString "
            + "or m.user.surname like :searchString " + "or m.user.emailAddress like :searchString "
            + "or m.user.institution like :searchString)";

    // String queryString =
    // "select m.user as user from
    // org.glite.security.voms.admin.persistence.model.VOMSMapping m where
    // m.group = :group and m.role is null "+
    // "and (m.user.dn like :searchString or m.user.ca.subjectString like
    // :searchString) order by m.user.dn asc";

    Query q = HibernateFactory.getSession().createQuery(queryString).setString("searchString", sString);

    q.setEntity("group", g);

    q.setFirstResult(firstResult);//w  w  w  .j ava 2 s  .c  o  m
    q.setMaxResults(maxResults);

    List res = q.list();

    results.setSearchString(searchString);
    results.setResults(res);
    results.setCount(countMatchingMembers(g, searchString));
    results.setFirstResult(firstResult);
    results.setResultsPerPage(maxResults);

    return results;

}

From source file:org.glite.security.voms.admin.persistence.dao.VOMSGroupDAO.java

License:Apache License

@SuppressWarnings("unchecked")
public List<VOMSGroup> getChildren(VOMSGroup parentGroup) {

    String query = "from org.glite.security.voms.admin.persistence.model.VOMSGroup g where g.parent = :parentGroup and g != :parentGroup order by g.name";
    Query q = HibernateFactory.getSession().createQuery(query);

    q.setEntity("parentGroup", parentGroup);

    return q.list();

}

From source file:org.glite.security.voms.admin.persistence.dao.VOMSRoleDAO.java

License:Apache License

public SearchResults searchMembers(VOMSGroup g, VOMSRole r, String searchString, int firstResult,
        int maxResults) {

    if (g == null)
        throw new NullArgumentException("Cannot search members in a null group!");

    if (r == null)
        throw new NullArgumentException("Cannot search members in a null role!");

    if (searchString == null || searchString.equals("") || searchString.length() == 0)
        return getMembers(g, r, firstResult, maxResults);

    SearchResults results = SearchResults.instance();
    String sString = "%" + searchString + "%";

    String queryString = "select m.user as user from org.glite.security.voms.admin.persistence.model.VOMSMapping m where m.group = :group and m.role is :role "
            + "and m.user.dn like :searchString order by m.user.dn asc";

    Query q = HibernateFactory.getSession().createQuery(queryString).setString("searchString", sString);

    q.setEntity("group", g);
    q.setEntity("role", r);

    q.setFirstResult(firstResult);/*from   w  ww  . ja v  a  2s  . c  om*/
    q.setMaxResults(maxResults);

    List res = q.list();

    results.setSearchString(searchString);
    results.setResults(res);
    results.setCount(countMatchingMembers(g, r, searchString));
    results.setFirstResult(firstResult);
    results.setResultsPerPage(maxResults);

    return results;

}

From source file:org.glite.security.voms.admin.persistence.dao.VOMSRoleDAO.java

License:Apache License

private int countMatchingMembers(VOMSGroup g, VOMSRole r, String searchString) {

    if (g == null)
        throw new NullArgumentException("Cannot search members in a null group!");

    if (r == null)
        throw new NullArgumentException("Cannot search members in a null role!");

    String sString;// w  ww  .j  a v  a  2s.  c  o  m

    if (searchString == null)
        sString = "%";
    else
        sString = "%" + searchString + "%";

    String queryString = "select count(m.user) from org.glite.security.voms.admin.persistence.model.VOMSMapping m where m.group = :group and m.role is :role "
            + "and m.user.dn like :searchString order by m.user.dn asc";

    Query q = HibernateFactory.getSession().createQuery(queryString);

    q.setString("searchString", sString);
    q.setEntity("group", g);
    q.setEntity("role", r);

    return ((Long) q.uniqueResult()).intValue();
}

From source file:org.glite.security.voms.admin.persistence.dao.VOMSRoleDAO.java

License:Apache License

private SearchResults getMembers(VOMSGroup g, VOMSRole r, int firstResult, int maxResults) {

    if (g == null)
        throw new NullArgumentException("Cannot search members in a null group!");

    if (r == null)
        throw new NullArgumentException("Cannot search members in a null role!");

    int membersCount = r.getUsers(g).size();

    SearchResults results = SearchResults.instance();

    String queryString = "select m.user as user from org.glite.security.voms.admin.persistence.model.VOMSMapping m where m.group = :group and m.role is :role "
            + "order by m.user.dn asc";

    Query q = HibernateFactory.getSession().createQuery(queryString);

    q.setEntity("group", g);
    q.setEntity("role", r);

    q.setFirstResult(firstResult);//from w ww  . jav a2s  .  com
    q.setMaxResults(maxResults);

    List res = q.list();

    results.setSearchString(null);
    results.setResults(res);
    results.setCount(membersCount);
    results.setFirstResult(firstResult);
    results.setResultsPerPage(maxResults);

    return results;

}

From source file:org.glite.security.voms.admin.persistence.dao.VOMSUserDAO.java

License:Apache License

@SuppressWarnings("unchecked")
public List<VOMSUser> findUsersWithPendingSignAUPTask(AUP aup) {

    String queryString = "from VOMSUser u join u.tasks t where t.class = SignAUPTask and t.status != 'COMPLETED' and t.aup = :aup";

    Query q = HibernateFactory.getSession().createQuery(queryString);
    q.setEntity("aup", aup);

    return q.list();

}

From source file:org.headsupdev.agile.app.docs.DocsApplication.java

License:Open Source License

public List<Document> getDocuments(Project project) {
    Session session = ((HibernateStorage) Manager.getStorageInstance()).getHibernateSession();

    Query q;
    if (project == null) {
        q = session.createQuery("from Document d where name.project is null");
    } else {//from  ww  w  .  ja v a2 s.  c  o  m
        q = session.createQuery("from Document d where name.project = :project");
        q.setEntity("project", project);
    }
    return q.list();
}

From source file:org.headsupdev.agile.app.docs.DocsApplication.java

License:Open Source License

public static Document getDocument(String name, Project project) {
    Session session = ((HibernateStorage) Manager.getStorageInstance()).getHibernateSession();

    Transaction tx = session.beginTransaction();
    Query q;
    if (project == null) {
        q = session.createQuery("from Document d where name.name = :name and name.project is null");
    } else {//w w  w.java2  s  .c o  m
        q = session.createQuery("from Document d where name.name = :name and name.project = :project");
        q.setEntity("project", project);
    }
    q.setString("name", name);
    Document ret = (Document) q.uniqueResult();
    tx.commit();

    return ret;
}