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.headsupdev.agile.app.docs.FigureResource.java

License:Open Source License

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

    Transaction tx = session.beginTransaction();
    Query 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();/*from w w  w . j a  va  2s  .  c  o  m*/

    return ret;
}

From source file:org.headsupdev.agile.app.files.BrowseApplication.java

License:Open Source License

public List<File> getProjectFiles(Project project) {
    Session session = ((HibernateStorage) Manager.getStorageInstance()).getHibernateSession();
    Query q = session.createQuery("from File f where name.project = :project");
    q.setEntity("project", project);
    List<File> files = q.list();

    return files;
}

From source file:org.headsupdev.agile.app.files.BrowseApplication.java

License:Open Source License

public static boolean getFileExists(Project project, String fileName) {
    Session session = ((HibernateStorage) Manager.getStorageInstance()).getHibernateSession();

    Query q = session
            .createQuery("select count(*) from File f where f.name.project = :project and f.name.name = :name");
    q.setEntity("project", project);
    q.setString("name", fileName);

    return ((Long) q.uniqueResult()) > 0;
}

From source file:org.headsupdev.agile.app.files.BrowseApplication.java

License:Open Source License

public static List<ScmChange> getChanges(Project project, String path) {
    Session session = ((HibernateStorage) Manager.getStorageInstance()).getHibernateSession();

    String prefix = "";
    java.io.File searchDir = Manager.getStorageInstance().getWorkingDirectory(project);
    while (project.getParent() != null) {
        prefix = searchDir.getName() + java.io.File.separatorChar + prefix;
        project = project.getParent();//from  ww  w.ja v a  2  s.  co m
        searchDir = searchDir.getParentFile();
    }

    Query q = session.createQuery(
            "from ScmChange c where c.set.id.project = :project and name = :path order by c.set.date desc");
    q.setEntity("project", project);
    q.setString("path", prefix + path);

    return q.list();
}

From source file:org.headsupdev.agile.app.files.BrowseApplication.java

License:Open Source License

public static boolean getChangeSetExists(Project project, String changeId) {
    Session session = ((HibernateStorage) Manager.getStorageInstance()).getHibernateSession();

    Query q = session.createQuery(
            "select count(*) from ScmChangeSet s where s.id.project = :project and s.revision = :rev");
    q.setEntity("project", project);
    q.setString("rev", changeId);

    return ((Long) q.uniqueResult()) > 0;
}

From source file:org.headsupdev.agile.app.files.BrowseApplication.java

License:Open Source License

public static boolean getChangeExists(Project project, String changeId) {
    Session session = ((HibernateStorage) Manager.getStorageInstance()).getHibernateSession();

    // TODO should we check name?
    Query q = session.createQuery(
            "select count(*) from ScmChange c where c.set.id.project = :project and c.revision = :rev");
    q.setEntity("project", project);
    q.setString("rev", changeId);

    return ((Long) q.uniqueResult()) > 0;
}

From source file:org.headsupdev.agile.app.files.BrowseScmService.java

License:Open Source License

public ChangeSet getChangeSet(Project project, String revision) {
    Session session = ((HibernateStorage) Manager.getStorageInstance()).getHibernateSession();

    Query q = session.createQuery("from ScmChangeSet c where id.project = :project and id.name = :revision");
    q.setEntity("project", project);
    q.setString("revision", revision);

    return (ScmChangeSet) q.uniqueResult();
}

From source file:org.headsupdev.agile.web.components.AccountSummaryPanel.java

License:Open Source License

public static List<Issue> getIssuesAssignedTo(User user) {
    Session session = ((HibernateStorage) Manager.getStorageInstance()).getHibernateSession();

    Transaction tx = session.beginTransaction();
    Query q = session
            .createQuery("from Issue i where status < 250 and assignee = :user order by priority, status");
    q.setEntity("user", user);
    List<Issue> list = q.list();
    tx.commit();//from   ww  w.  j  av  a2s. c o m

    return list;
}

From source file:org.headsupdev.agile.web.model.UserDashboardModel.java

License:Open Source License

protected List<Issue> getIssuesAssignedTo(User user) {
    Session session = ((HibernateStorage) Manager.getStorageInstance()).getHibernateSession();

    Query q = session
            .createQuery("from Issue i where status < 250 and assignee = :user order by priority, status");
    q.setEntity("user", user);
    List<Issue> list = q.list();

    // force loading...
    for (Issue issue : list) {
        if (issue.getMilestone() != null) {
            // force a load
            issue.getMilestone().getIssues().size();
        }/*from   w w  w. ja  v  a  2s  . co m*/
        issue.getAttachments().size();
    }

    return list;
}

From source file:org.infoglue.calendar.controllers.EventController.java

License:Open Source License

/**
 * This method returns a list of Events based on a number of parameters within a transaction
 * @return List/*from w w  w  .  j  a  v  a 2s.  c  om*/
 * @throws Exception
 */

public Set getEventList(Calendar calendar, Integer stateId, java.util.Calendar startDate,
        java.util.Calendar endDate, Session session) throws Exception {
    Query q = session.createQuery(
            "from Event as event inner join fetch event.owningCalendar as calendar where event.owningCalendar = ? AND event.stateId = ? AND event.startDateTime >= ? AND event.endDateTime <= ? order by event.startDateTime");
    q.setEntity(0, calendar);
    q.setInteger(1, stateId.intValue());
    q.setCalendar(2, startDate);
    q.setCalendar(3, endDate);

    List list = q.list();

    Set set = new LinkedHashSet();
    set.addAll(list);

    return set;
}