Example usage for org.hibernate Query getQueryString

List of usage examples for org.hibernate Query getQueryString

Introduction

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

Prototype

String getQueryString();

Source Link

Document

Get the query string.

Usage

From source file:uk.ac.kcl.iop.brc.core.pipeline.dncpipeline.data.DNCWorkUnitDao.java

License:Open Source License

/**
 *
 * @param coordinate The original coordinate of the text
 * @param processedText The processed text to be saved via saveTextToCoordinate named-query.
 *//* www  .ja  va2 s .c o  m*/
public void saveConvertedText(DNCWorkCoordinate coordinate, String processedText) {
    SessionWrapper sessionWrapper = getCurrentTargetSession();
    try {
        Query query = sessionWrapper.getNamedQuery("saveTextToCoordinate");
        String queryString = query.getQueryString();
        SQLQuery sqlQuery = sessionWrapper.createSQLQuery(queryString);
        sqlQuery.setParameter(0, coordinate.getSourceTable());
        sqlQuery.setParameter(1, coordinate.getSourceColumn());
        sqlQuery.setParameter(2, coordinate.getIdInSourceTable());
        sqlQuery.setParameter(3, processedText);
        sqlQuery.executeUpdate();
    } finally {
        sessionWrapper.closeSession();
    }
}

From source file:us.mn.state.health.lims.test.daoimpl.TestDAOImpl.java

License:Mozilla Public License

/**
 * @see us.mn.state.health.lims.test.dao.TestDAO#getAllOrderBy(java.lang.String)
 *      Read all entities from the database sorted by an appropriate
 *      property/*from w  w  w .  j a v  a  2 s .c om*/
 */
@SuppressWarnings("unchecked")
public List<Test> getAllOrderBy(String columnName) throws LIMSRuntimeException {
    List<Test> entities;
    try {
        if (!StringUtil.isJavaIdentifier(columnName)) {
            throw new IllegalArgumentException("\"" + columnName + "\" is not valid syntax for a column name");
        }
        // I didn't manage to get a query parameter to be used as a column
        // name to sort by (because ORDER BY "my_column" is not valid SQL).
        // so I had to generate the HQL manually, but only after the above
        // check.
        String hql = "from Test t where t.isActive='Y' ORDER BY " + columnName;
        org.hibernate.Query query = HibernateUtil.getSession().createQuery(hql);
        hql = query.getQueryString();
        entities = query.list();
        closeSession();
    } catch (Exception e) {
        LogEvent.logError("TestDAOImpl", "getAllOrderBy()", e.toString());
        throw new LIMSRuntimeException("Error in getAllOrderBy()", e);
    }

    return entities;
}

From source file:vn.vnpttech.ssdc.nms.dao.hibernate.FirmwareDaoHibernate.java

License:Apache License

@Override
public void updateDefaultFw(Long id, Long modelId) {
    Query query = getSession()
            .createQuery("update Firmware set fwDefault= 0 where id <> :id and deviceModel.id = :model_id ");
    query.setParameter("id", id);
    query.setParameter("model_id", modelId);
    System.out.println(query.getQueryString() + "-------------------");
    int result = query.executeUpdate();
}