List of usage examples for org.hibernate SQLQuery setInteger
@Deprecated @SuppressWarnings("unchecked") default Query<R> setInteger(int position, int val)
From source file:simtra.simtraadmin.dao.TelemetriaLogDao.java
public List<TelemetriaLog> listar(String fechaActual, Integer idRuta) { sesionActual();//w w w . j a v a 2 s. c o m StringBuilder sql = new StringBuilder(); sql.append("SELECT log.* "); sql.append("FROM telemetriaLog log "); sql.append("WHERE log.telDistancia <= 30 "); sql.append("AND to_char(log.telFecha,'dd/MM/yyyy') = :fechaActual "); sql.append( "AND traId IN (SELECT trayecto.traId FROM trayecto, ruta WHERE trayecto.ruId = ruta.ruId AND ruta.ruId = :idRuta) "); SQLQuery query = sesion.createSQLQuery(sql.toString()).addEntity(TelemetriaLog.class); query.setString("fechaActual", fechaActual); query.setInteger("idRuta", idRuta); List<TelemetriaLog> objeto = (List<TelemetriaLog>) query.list(); return objeto; }
From source file:simtra.simtraadmin.dao.TelemetriaLogDao.java
public void agregarPorServicio(Integer idTrayecto, Integer idServicio) { sesionActual();//from w w w. jav a 2s . co m StringBuilder sql = new StringBuilder(); sql.append("SELECT * "); sql.append("FROM telemetria "); sql.append("WHERE serId = :idServicio "); sql.append("AND traId = :idTrayecto "); SQLQuery query = sesion.createSQLQuery(sql.toString()).addEntity(Telemetria.class); query.setInteger("idServicio", idServicio); query.setInteger("idTrayecto", idTrayecto); List<Telemetria> objeto = (List<Telemetria>) query.list(); if (objeto == null) { System.out.println("es nulo"); } for (Telemetria t : objeto) { System.out.println("Telemetria Log"); TelemetriaLog log = new TelemetriaLog(t.getServicio().getSerId(), t.getTrayecto().getTraId(), t.getTelCoordenada(), t.getTelFecha(), t.getTelDistancia(), t.getTelVelocidad()); crear(log); } }
From source file:simtra.simtraadmin.dao.TrayectoDao.java
public List<Trayecto> listarPorRuta(Integer idRuta) { sesionActual();/*w ww. j ava 2s.c o m*/ StringBuilder sql = new StringBuilder(); sql.append("SELECT trayecto.* "); sql.append("FROM trayecto, ruta "); sql.append("WHERE ruta.ruId = trayecto.ruId "); sql.append("AND ruta.ruId = :idRuta "); SQLQuery query = sesion.createSQLQuery(sql.toString()).addEntity(Trayecto.class); query.setInteger("idRuta", idRuta); List<Trayecto> objeto = (List<Trayecto>) query.list(); return objeto; }
From source file:uk.ac.kcl.iop.brc.core.pipeline.dncpipeline.data.FullPipelineIntegrationTests.java
License:Open Source License
private void insertBinaries(Session session) { String sql = "INSERT INTO tblTestDocs (patient_id, doc_id, doc) VALUES(?,?,?)"; int i = 1;/*from w w w.j a va2 s . c om*/ for (byte[] object : ba) { SQLQuery query = session.createSQLQuery(sql); query.setInteger(0, 1); query.setInteger(1, i); query.setBinary(2, object); query.executeUpdate(); i++; } }
From source file:vn.edu.vnu.uet.fit.model.CourseReportModel.java
public List<StudentReportByCourse> getStudentResultByCourse(int courseId) { Session session = HibernateUtil.getSessionFactory().openSession(); Transaction trans = session.beginTransaction(); String queryStr = "SELECT @s\\:=@s+1 as reportId, courseId, userId, COALESCE(sum(isActive),0) as summitedExercise, COALESCE(SUM(score), 0) as courseScore FROM\n" + " (SELECT \n" + " courseusers.courseId as courseId, \n" + " courseusers.userId as userId, \n" + " B.problemId as problemId, \n" + " B.submitId as submitId, \n" + " B.result as result, \n" + " B.resultScore as score,\n" + " B.isActive as isActive\n" + " FROM courseusers left outer join (\n" + " select submitId, courseId, problemId, userId, result, max(resultScore) as resultScore, isActive from submissions \n" + " where submissions.courseId is not null and isActive != 0\n" + " GROUP BY courseId, problemId, userId) as B on courseusers.courseId = B.courseId and courseusers.userId = B.userId\n" + " ) as C,\n" + " (SELECT @s\\:= 0) AS s\n" + "GROUP BY courseId, userId \n" + "HAVING C.courseId = :courseId"; SQLQuery query = session.createSQLQuery(queryStr); query.setInteger("courseId", courseId); query.addEntity(StudentReportByCourse.class); List<StudentReportByCourse> result = query.list(); trans.commit();//from w w w. j a v a 2s .c om session.close(); return result; }
From source file:vn.edu.vnu.uet.fit.model.CourseReportModel.java
public List<StudentDetailReportByCourse> getStudentDetailResultByCourse(int courseId, int userId) { Session session = HibernateUtil.getSessionFactory().openSession(); Transaction trans = session.beginTransaction(); String queryStr = "select @s\\:=@s+1 as reportId, submissions.submitId, submissions.courseId, submissions.problemId, submissions.userId, submissions.result, submissions.resultScore, submissions.isActive \n" + " from submissions\n" + " inner join (select courseId, problemId, userId, max(resultScore) as maxscore from submissions where submissions.courseId is not null and isActive != 0 GROUP BY courseId, problemId, userId) as B\n" + " on submissions.courseId = B.courseId and submissions.problemId = B.problemId and submissions.userId = B.userId,\n" + " (SELECT @s\\:= 0) AS s\n" + " where submissions.resultScore = B.maxscore and submissions.isActive != 0 and submissions.userId = :userId and submissions.courseId = :courseId"; SQLQuery query = session.createSQLQuery(queryStr); query.setInteger("courseId", courseId); query.setInteger("userId", userId); query.addEntity(StudentDetailReportByCourse.class); List<StudentDetailReportByCourse> result = query.list(); trans.commit();//from w ww. j av a 2 s . c o m session.close(); return result; }
From source file:vn.edu.vnu.uet.fit.model.ReportModel.java
public List<StudentDetailReportByCourse> getStudentDetailResultByCourse(int courseId) { Session session = HibernateUtil.getSessionFactory().openSession(); Transaction trans = session.beginTransaction(); String queryStr = "SELECT C.* FROM \n" + " (SELECT\n" + " @s\\:=@s+1 as reportId, \n" + " courseusers.courseId as courseId, \n" + " courseusers.userId as userId, \n" + " B.problemId as problemId, \n" + " B.submitId as submitId, \n" + " B.result as result, \n" + " B.resultScore as score,\n" + " B.isActive as isActive\n" + " FROM courseusers left outer join \n" + " (SELECT * FROM submissions\n" + " WHERE courseId = 1 and isActive != 0) as B on courseusers.courseId = B.courseId and courseusers.userId = B.userId,\n" + " (SELECT @s\\:= 0) AS s\n" + " WHERE courseusers.courseId = :courseId\n" + " ORDER BY userId, problemId, score desc) AS C\n" + " GROUP BY courseId, userId, problemId"; SQLQuery query = session.createSQLQuery(queryStr); query.setInteger("courseId", courseId); query.addEntity(StudentDetailReportByCourse.class); List<StudentDetailReportByCourse> result = query.list(); trans.commit();// www .j av a2 s .c o m session.close(); return result; }