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.openmrs.module.mergeconcepts.api.db.hibernate.HibernateMergeConceptsDAO.java

License:Open Source License

/**
 * @see org.openmrs.api.db.ProgramWorkflowDAO#getProgramsByConcept(org.openmrs.Concept)
 *//* w  w  w  . j  a v a2s.  c o m*/
@Transactional
@Override
public List<Program> getProgramsByConcept(Concept concept) {

    String pq = "select distinct p from Program p where p.concept = :concept";
    Query pquery = sessionFactory.getCurrentSession().createQuery(pq);
    pquery.setEntity("concept", concept);

    return (List<Program>) pquery.list();

}

From source file:org.openmrs.module.mergeconcepts.api.db.hibernate.HibernateMergeConceptsDAO.java

License:Open Source License

/**
 * @see org.openmrs.api.db.ProgramWorkflowDAO#getProgramWorkflowsByConcept(org.openmrs.Concept)
 *//* w  ww.j  a v  a2s . c o m*/
@Transactional
@Override
public List<ProgramWorkflow> getProgramWorkflowsByConcept(Concept concept) {

    String wq = "select distinct w from ProgramWorkflow w where w.concept = :concept";
    Query wquery = sessionFactory.getCurrentSession().createQuery(wq);
    wquery.setEntity("concept", concept);

    return (List<ProgramWorkflow>) wquery.list();

}

From source file:org.openmrs.module.mergeconcepts.api.db.hibernate.HibernateMergeConceptsDAO.java

License:Open Source License

/**
 * @see org.openmrs.api.db.ProgramWorkflowDAO#getProgramWorkflowStatesByConcept(org.openmrs.Concept)
 *//*from   ww w  .j av a2s  .c om*/
@Transactional
@Override
public List<ProgramWorkflowState> getProgramWorkflowStatesByConcept(Concept concept) {

    String sq = "select distinct s from ProgramWorkflowState s where s.concept = :concept";
    Query squery = sessionFactory.getCurrentSession().createQuery(sq);
    squery.setEntity("concept", concept);

    return (List<ProgramWorkflowState>) squery.list();

}

From source file:org.opensafety.hishare.dao.implementation.HibernatePermissionDao.java

License:Apache License

public boolean deleteAllWithParcel(Parcel parcel) {
    String deleteQuery = "DELETE FROM Permission WHERE parcel = :parcel";

    Query delete = getSession().createQuery(deleteQuery);

    delete.setEntity("parcel", parcel);

    int rowCount = delete.executeUpdate();

    return rowCount > 0;
}

From source file:org.pentaho.platform.repository.content.ContentLocation.java

License:Open Source License

public IContentItem getContentItemByName(final String itemName) {
    Session session = HibernateUtil.getSession();
    Query qry = session.getNamedQuery("org.pentaho.platform.repository.content.ContentItem.findItemByName"); //$NON-NLS-1$
    qry.setEntity("parent", this); //$NON-NLS-1$
    qry.setString("name", itemName); //$NON-NLS-1$
    Object rtn = null;//from w w  w. j a  va 2 s.  c  om
    try {
        rtn = qry.uniqueResult();
    } catch (Exception ignored) {
        ContentLocation.logger.debug(ignored);
    }
    return (ContentItem) rtn;
}

From source file:org.pentaho.platform.repository.subscription.SubscriptionRepository.java

License:Open Source License

@SuppressWarnings("unchecked")
public List<ISubscription> getSubscriptionsForSchedule(final ISchedule schedule) {
    if (schedule == null) {
        return new ArrayList<ISubscription>();
    }/*from   w w  w .  j  ava  2 s. c  o  m*/
    Session session = HibernateUtil.getSession();
    Query qry = session
            .getNamedQuery("org.pentaho.platform.repository.subscription.Schedule.findSubscriptionsBySchedule") //$NON-NLS-1$
            .setCacheable(true);
    qry.setEntity("schedule", schedule); //$NON-NLS-1$
    return qry.list();
}

From source file:org.pentaho.platform.repository.subscription.SubscriptionRepository.java

License:Open Source License

@SuppressWarnings("unchecked")
public List<ISubscription> getUserSubscriptionsToContentReference(final String user, final String contentId) {
    Session session = HibernateUtil.getSession();
    ISubscribeContent content = this.getContentByActionReference(contentId);
    if (content == null) {
        return new ArrayList<ISubscription>();
    }/*w  w  w . j  a v a2  s.c  o  m*/
    Query qry = session
            .getNamedQuery("org.pentaho.platform.repository.subscription.Subscription.findUserSubscriptions") //$NON-NLS-1$
            .setCacheable(true);
    qry.setString("searchUser", user); //$NON-NLS-1$
    qry.setEntity("searchContent", content); //$NON-NLS-1$
    return qry.list();
}

From source file:org.sakaiproject.component.gradebook.BaseHibernateManager.java

License:Educational Community License

/**
 * /*from  ww w  .j  a  v a2 s.c om*/
 * @param session an active Hibernate session
 * @param name the assignment name (will not be trimmed)
 * @param gradebook the gradebook to check
 * @return true if an assignment with the given name already exists in this gradebook.
 */
protected boolean assignmentNameExists(Session session, String name, Gradebook gradebook) {
    final String HQL_ASSIGNMENTS_BY_NAME = "select go from GradableObject as go where go.name = :name and go.gradebook = :gb and go.removed=false";
    Query q = session.createQuery(HQL_ASSIGNMENTS_BY_NAME);
    q.setString("name", name);
    q.setEntity("gb", gradebook);

    return !q.list().isEmpty();
}

From source file:storybook.model.dao.ChapterDAOImpl.java

License:Open Source License

@SuppressWarnings("unchecked")
public List<Chapter> findAll(Part part) {
    StringBuffer buf = new StringBuffer("from Chapter");
    if (part != null) {
        buf.append(" where part=:part");
    }//from w  w  w  .j ava2 s . com
    buf.append(" order by chapterno");
    Query query = session.createQuery(buf.toString());
    if (part != null) {
        query.setEntity("part", part);
    }
    List<Chapter> ret = (List<Chapter>) query.list();
    return ret;
}

From source file:storybook.model.dao.ChapterDAOImpl.java

License:Open Source License

@SuppressWarnings("unchecked")
public List<Location> findLocations(Chapter chapter) {
    Query query = session.createQuery("select s.locations from Scene as s" + " join s.chapter as ch"
            + " where s.chapter=:chapter" + " order by ch.chapterno, s.sceneno");
    query.setEntity("chapter", chapter);
    List<Location> locations = (List<Location>) query.list();
    locations = LangUtil.removeNullAndDuplicates(locations);
    return locations;
}