Example usage for org.hibernate Session createSQLQuery

List of usage examples for org.hibernate Session createSQLQuery

Introduction

In this page you can find the example usage for org.hibernate Session createSQLQuery.

Prototype

@Override
    NativeQuery createSQLQuery(String queryString);

Source Link

Usage

From source file:com.grselectronics.inventario.controller.HibernateUtil.java

public List<Object> autenticarUsuario(String email, String password) {
    List<Object> resultado = new ArrayList<>();
    Session sesion = sessionFactory.openSession();
    sesion.beginTransaction();/*from w  w  w  .j  av a 2 s .c  om*/
    resultado = sesion.createSQLQuery("CALL sp_autenticarUsuario(:email,:pass);").addEntity(Usuario.class)
            .setParameter("email", email).setParameter("pass", password).list();
    sesion.getTransaction().commit();
    sesion.close();
    return resultado;
}

From source file:com.gwac.dao.ConfigFileDaoImpl.java

public void moveDataToHisTable() {

    Session session = getCurrentSession();
    String sql = "WITH moved_rows AS ( DELETE FROM config_file RETURNING * ) INSERT INTO config_file_his SELECT * FROM moved_rows;";
    session.createSQLQuery(sql).executeUpdate();
}

From source file:com.gwac.dao.ConfigFileDaoImpl.java

public Boolean exist(ConfigFile obj) {
    Boolean flag = false;// w ww .j a v a2  s  .  c  o  m
    Session session = getCurrentSession();
    String sql = "select cf_id from config_file where file_name='" + obj.getFileName() + "' ";
    Query q = session.createSQLQuery(sql);
    if (!q.list().isEmpty()) {
        BigInteger cfId = (BigInteger) q.list().get(0);
        obj.setCfId(cfId.longValue());
        flag = true;
    }
    return flag;
}

From source file:com.gwac.dao.ConfigFileDaoImpl.java

public List<ConfigFile> getTopNUnSync(int topn) {

    String sql = "with updated_rows as"
            + "(with tmp as (select min(cf_id) min_id from config_file where is_sync=false) "
            + "update config_file set is_sync=true " + "where cf_id<(select min_id+" + topn
            + " from tmp) and cf_id>=(select min_id from tmp) returning *) " + "select * from updated_rows;";

    Session session = getCurrentSession();
    Query q = session.createSQLQuery(sql).addEntity(ConfigFile.class);
    return q.list();
}

From source file:com.gwac.dao.CVSQueryDaoImpl.java

@Override
public List<Cvs> queryByOt2(OtLevel2 ot2, float searchRadius, float mag) {

    SearchBoxSphere sbs = new SearchBoxSphere(ot2.getRa(), ot2.getDec(), searchRadius);
    int tflag = sbs.calSearchBox();
    if (tflag != 0) {
        Session session = getCurrentSession();
        String sql = "select * from cvs where mag < " + mag + " and ";
        if (tflag == 1) {
            sql += "RAdeg between " + sbs.getMinRa() + " and " + sbs.getMaxRa() + " and ";
            sql += "DEdeg between " + sbs.getMinDec() + " and " + sbs.getMaxDec() + " ";
        } else {// w  ww . ja  va2 s  .  co  m
            sql += "(RAdeg > " + sbs.getMinRa() + " or RAdeg <" + sbs.getMaxRa() + ") and ";
            sql += "DEdeg between " + sbs.getMinDec() + " and " + sbs.getMaxDec() + " ";
        }

        Query q = session.createSQLQuery(sql).addEntity(Cvs.class);
        return q.list();
    }
    return new ArrayList();
}

From source file:com.gwac.dao.MatchTableDaoImpl.java

@Override
public MatchTable getMatchTableByTypeName(String typeName) {

    String sql = "select * from match_table where match_type_name='" + typeName + "'";
    Session session = getCurrentSession();
    Query q = session.createSQLQuery(sql).addEntity(MatchTable.class);
    List<MatchTable> otts = q.list();
    MatchTable tobj = null;/*from   w  w  w.  j  a  va 2s . co  m*/
    if (otts.size() > 0) {
        tobj = otts.get(0);
    }
    return tobj;
}

From source file:com.gwac.dao.MergedOtherDaoImpl.java

@Override
public List<MergedOther> queryByOt2(OtLevel2 ot2, float searchRadius, float mag) {

    SearchBoxSphere sbs = new SearchBoxSphere(ot2.getRa(), ot2.getDec(), searchRadius);
    int tflag = sbs.calSearchBox();
    if (tflag != 0) {
        Session session = getCurrentSession();
        String sql = "select * from merged_other where mag < " + mag + " and ";
        if (tflag == 1) {
            sql += "RAdeg between " + sbs.getMinRa() + " and " + sbs.getMaxRa() + " and ";
            sql += "DEdeg between " + sbs.getMinDec() + " and " + sbs.getMaxDec() + " ";
        } else {/*from w  w  w  . j av a 2s.c o m*/
            sql += "(RAdeg > " + sbs.getMinRa() + " or RAdeg <" + sbs.getMaxRa() + ") and ";
            sql += "DEdeg between " + sbs.getMinDec() + " and " + sbs.getMaxDec() + " ";
        }

        Query q = session.createSQLQuery(sql).addEntity(MergedOther.class);
        return q.list();
    }
    return new ArrayList();
}

From source file:com.gwac.dao.MinorPlanetDaoImpl.java

@Override
public List<MinorPlanet> queryByOt2(OtLevel2 ot2, float searchRadius, float mag, String tableName) {

    double maxRaSpeed = getMaxAbsValue(tableName, "DLON", mag);
    double maxDecSpeed = getMaxAbsValue(tableName, "DLAT", mag);
    if (maxRaSpeed > 20) {
        log.error("maxRaSpeed is " + maxRaSpeed + ",force set to 19.9");
        maxRaSpeed = 19.9;//  w  w w  .  ja v a2s  . c  om
    }
    if (maxDecSpeed > 20) {
        log.error("maxDecSpeed is " + maxDecSpeed + ",force set to 19.9");
        maxDecSpeed = 19.9;
    }

    SearchBoxSphere sbs1 = new SearchBoxSphere(ot2.getRa(), ot2.getDec(), maxRaSpeed + searchRadius);
    SearchBoxSphere sbs2 = new SearchBoxSphere(ot2.getRa(), ot2.getDec(), maxDecSpeed + searchRadius);
    int tflag1 = sbs1.calSearchBox();
    int tflag2 = sbs2.calSearchBox();
    if (tflag1 != 0 && tflag2 != 0) {
        Session session = getCurrentSession();
        String sql = "select * from " + tableName + " where VMAG<" + mag;
        if (tflag1 == 1) {
            sql += " and LON between " + sbs1.getMinRa() + " and " + sbs1.getMaxRa() + " ";
        } else {
            sql += " and ( LON > " + sbs1.getMinRa() + " or LON <" + sbs1.getMaxRa() + ") ";
        }
        if (tflag2 == 1) {
            sql += " and LAT between " + sbs2.getMinDec() + " and " + sbs2.getMaxDec() + " ";
        } else {
            sql += " and LAT between " + sbs2.getMinDec() + " and " + sbs2.getMaxDec() + " ";
        }

        Query q = session.createSQLQuery(sql).addEntity(MinorPlanet.class);
        return q.list();
    }
    return new ArrayList();
}

From source file:com.gwac.dao.MinorPlanetDaoImpl.java

public double getMaxAbsValue(String tableName, String name, float maxMag) {

    double val = 19.9;
    Session session = getCurrentSession();
    String sql = "select max(abs(" + name + ")) from " + tableName + " where VMAG<" + maxMag + " and abs("
            + name + ")<20;";
    Query q = session.createSQLQuery(sql);
    if (q.list().size() > 0) {
        val = (double) q.list().get(0);
    } else {/*from w  w  w.  j a  v  a  2s . c o  m*/
        log.error("MinorPlanet table " + tableName + " is empty!");
    }
    return val;
}