Search in sources :

Example 51 with SQLQuery

use of org.hibernate.SQLQuery in project KeDou by XiaoBai518.

the class BaseDao method find4PageBySql2.

public List<Map<String, Object>> find4PageBySql2(String sql, Map params, int pageNum, int pageSize) throws Exception {
    SQLQuery query = sessionFactory.getCurrentSession().createSQLQuery(sql);
    query.setResultTransformer(CriteriaSpecification.ALIAS_TO_ENTITY_MAP);
    Iterator<String> keys = params.keySet().iterator();
    while (keys.hasNext()) {
        String key = keys.next();
        Object value = params.get(key);
        if (value instanceof Collection)
            query.setParameterList(key, (Collection) value);
        else
            query.setParameter(key, value);
    }
    query.setFirstResult((pageNum - 1) * pageSize);
    query.setMaxResults(pageSize);
    List<Map<String, Object>> list = query.list();
    return list;
}
Also used : Collection(java.util.Collection) SQLQuery(org.hibernate.SQLQuery) Map(java.util.Map)

Example 52 with SQLQuery

use of org.hibernate.SQLQuery in project KeDou by XiaoBai518.

the class BaseDao method findCount4PageBySql2.

public Long findCount4PageBySql2(String sql, Map params) throws Exception {
    SQLQuery query = this.sessionFactory.getCurrentSession().createSQLQuery(sql);
    Iterator<String> keys = params.keySet().iterator();
    while (keys.hasNext()) {
        String key = keys.next();
        Object value = params.get(key);
        if (value instanceof Collection)
            query.setParameterList(key, (Collection) value);
        else
            query.setParameter(key, value);
    }
    return Long.parseLong(query.uniqueResult().toString());
}
Also used : Collection(java.util.Collection) SQLQuery(org.hibernate.SQLQuery)

Example 53 with SQLQuery

use of org.hibernate.SQLQuery in project openmrs-core by openmrs.

the class HibernatePersonDAO method getSavedPersonAttributeTypeName.

/**
 * @see org.openmrs.api.db.PersonDAO#getSavedPersonAttributeTypeName(org.openmrs.PersonAttributeType)
 */
@Override
public String getSavedPersonAttributeTypeName(PersonAttributeType personAttributeType) {
    SQLQuery sql = sessionFactory.getCurrentSession().createSQLQuery("select name from person_attribute_type where person_attribute_type_id = :personAttributeTypeId");
    sql.setInteger("personAttributeTypeId", personAttributeType.getId());
    return (String) sql.uniqueResult();
}
Also used : SQLQuery(org.hibernate.SQLQuery)

Example 54 with SQLQuery

use of org.hibernate.SQLQuery in project openmrs-core by openmrs.

the class HibernateEncounterDAO method getSavedEncounterLocation.

/**
 * @see org.openmrs.api.db.EncounterDAO#getSavedEncounterLocation(org.openmrs.Encounter)
 */
@Override
public Location getSavedEncounterLocation(Encounter encounter) {
    Session session = sessionFactory.getCurrentSession();
    FlushMode flushMode = session.getFlushMode();
    session.setFlushMode(FlushMode.MANUAL);
    try {
        SQLQuery sql = session.createSQLQuery("select location_id from encounter where encounter_id = :encounterId");
        sql.setInteger("encounterId", encounter.getEncounterId());
        return Context.getLocationService().getLocation((Integer) sql.uniqueResult());
    } finally {
        session.setFlushMode(flushMode);
    }
}
Also used : SQLQuery(org.hibernate.SQLQuery) FlushMode(org.hibernate.FlushMode) Session(org.hibernate.Session)

Example 55 with SQLQuery

use of org.hibernate.SQLQuery in project candlepin by candlepin.

the class AbstractHibernateCurator method safeSQLUpdateWithCollection.

/**
 * Performs a direct SQL update or delete operation with a collection by breaking the collection
 * into chunks and repeatedly performing the update.
 * <p></p>
 * The parameter receiving the collection chunks must be the last parameter in the query and the
 * provided collection must support the subList operation.
 *
 * @param sql
 *  The SQL statement to execute; must be an UPDATE or DELETE operation
 *
 * @param collection
 *  The collection to be broken up into chunks
 *
 * @return
 *  the number of rows updated as a result of this query
 */
protected int safeSQLUpdateWithCollection(String sql, Collection<?> collection, Object... params) {
    int count = 0;
    Session session = this.currentSession();
    SQLQuery query = session.createSQLQuery(sql);
    for (List<?> block : this.partition(collection)) {
        int index = 1;
        if (params != null) {
            for (; index <= params.length; ++index) {
                query.setParameter(String.valueOf(index), params[index - 1]);
            }
        }
        query.setParameterList(String.valueOf(index), block);
        count += query.executeUpdate();
    }
    return count;
}
Also used : SQLQuery(org.hibernate.SQLQuery) Session(org.hibernate.Session)

Aggregations

SQLQuery (org.hibernate.SQLQuery)58 Session (org.hibernate.Session)26 Test (org.junit.Test)16 List (java.util.List)13 Map (java.util.Map)9 ArrayList (java.util.ArrayList)7 Collection (java.util.Collection)5 Paint (javafx.scene.paint.Paint)5 Cohort (org.openmrs.Cohort)5 EvaluatedCohort (org.openmrs.module.reporting.cohort.EvaluatedCohort)5 HibernateException (org.hibernate.HibernateException)4 JFXButton (com.jfoenix.controls.JFXButton)3 MaterialDesignIconView (de.jensd.fx.glyphs.materialdesignicons.MaterialDesignIconView)3 MaterialIconView (de.jensd.fx.glyphs.materialicons.MaterialIconView)3 SimpleDateFormat (java.text.SimpleDateFormat)3 Date (java.util.Date)3 Insets (javafx.geometry.Insets)3 ScrollPane (javafx.scene.control.ScrollPane)3 Tooltip (javafx.scene.control.Tooltip)3 GridPane (javafx.scene.layout.GridPane)3