List of usage examples for org.hibernate SQLQuery addEntity
SQLQuery<T> addEntity(Class entityType);
From source file:com.school.dao.UserImplement.java
@Override public Stuff getUser(String userEmail, String userPassword) { Stuff user = null;/*from ww w .ja v a 2s .c o m*/ try { hibernateDriver.openSession(); String getUserSql = "Select u.REC_ID , u.USER_TYPE ,u.JOIN_DATE,u.FAMILY_INFO_ID,u.PERSONAL_INFO_ID,u.CLASS_ID,u.STAGE_ID from USERS u INNER JOIN PERSONAL_INFO p ON p.EMAIL= :userEmail and p.PASSWORD= :userPassword"; SQLQuery query = hibernateDriver.getSession().createSQLQuery(getUserSql); query.addEntity(Stuff.class); query.setResultTransformer(Criteria.PROJECTION); query.setParameter("userEmail", userEmail); query.setParameter("userPassword", userPassword); user = (Stuff) query.uniqueResult(); hibernateDriver.closeSession(); } catch (Exception ex) { ex.printStackTrace(); } return user; }
From source file:com.school.dao.UserImplement.java
@Override public List<Student> getAllStudents() { hibernateDriver.openSession();// w w w . j a v a 2 s .com String sql = "SELECT * FROM USERS where USER_TYPE='Student' order by JOIN_DATE asc"; SQLQuery query = hibernateDriver.getSession().createSQLQuery(sql); query.addEntity(Student.class); List<Student> students = query.list(); hibernateDriver.closeSession(); return students; }
From source file:com.siemens.scr.avt.ad.api.impl.DefaultADFacadeImpl.java
License:Open Source License
@SuppressWarnings("unchecked") @Override// www . j ava2s.c o m public List<ImageAnnotation> retrieveAnnotationsInSeries(String seriesInstanceUID) { String queryString = "SELECT i.* FROM AD.IMAGE_ANNOTATION i WHERE annotation_id IN (" + "SELECT DISTINCT ia.annotation_id FROM AD.IMAGE_ANNOTATION ia, AD.REFERENCE_IMAGES ri, AD.GENERAL_IMAGE gi, AD.GENERAL_SERIES gs " + "WHERE ia.annotation_id = ri.annotation_id AND ri.image_pk_id = gi.image_pk_id " + "AND gi.general_series_pk_id = gs.general_series_pk_id " + "AND gs.series_instance_uid = ?)"; Session session = HibernateUtil.currentSession(); SQLQuery query = session.createSQLQuery(queryString); query.setString(0, seriesInstanceUID); query.addEntity(ImageAnnotation.class); List<ImageAnnotation> queryResult = query.list(); return queryResult; }
From source file:com.siemens.scr.avt.ad.api.impl.DefaultADFacadeImpl.java
License:Open Source License
@SuppressWarnings("unchecked") @Override/*from w ww . j a va 2 s . c om*/ public List<ImageAnnotation> retrieveAnnotationsInSeries(String seriesInstanceUID, String roleInTrial) { String queryString = "SELECT i.* FROM AD.IMAGE_ANNOTATION i WHERE annotation_id IN (" + "SELECT DISTINCT ia.annotation_id FROM AD.IMAGE_ANNOTATION ia, AD.REFERENCE_IMAGES ri, AD.GENERAL_IMAGE gi, AD.GENERAL_SERIES gs " + "WHERE ia.annotation_id = ri.annotation_id AND ri.image_pk_id = gi.image_pk_id " + "AND gi.general_series_pk_id = gs.general_series_pk_id " + "AND gs.series_instance_uid = ? AND role_in_trial = ?)"; Session session = HibernateUtil.currentSession(); SQLQuery query = session.createSQLQuery(queryString); query.setString(0, seriesInstanceUID); query.setString(1, roleInTrial); query.addEntity(ImageAnnotation.class); List<ImageAnnotation> queryResult = query.list(); return queryResult; }
From source file:com.siemens.scr.avt.ad.api.impl.DefaultADFacadeImpl.java
License:Open Source License
@SuppressWarnings("unchecked") @Override/*w w w . jav a2 s . c o m*/ public List<DicomObject> retrieveSegmentationObjects(String annotationUID) { Session session = HibernateUtil.currentSession(); String queryString = "SELECT * FROM AD.GENERAL_IMAGE i, AD.GENERAL_SERIES s, AD.STUDY st, AD.PATIENT p " + "WHERE p.PATIENT_PK_ID = st.PATIENT_PK_ID " + "AND st.STUDY_PK_ID = s.STUDY_PK_ID " + "AND s.GENERAL_SERIES_PK_ID = i.GENERAL_SERIES_PK_ID " + "AND SOP_INSTANCE_UID IN " + "(SELECT X.SEGMENTATION_UID FROM AD.IMAGE_ANNOTATION a, " + " XMLTABLE ('declare default element namespace \"gme://caCORE.caCORE/3.2/edu.northwestern.radiology.AIM\"; " + "$aim/imageAnnotation/probabilityMapCollection/ProbabilityMap' passing a.AIM_OBJECT as \"aim\" " + "COLUMNS SEGMENTATION_UID VARCHAR(64) PATH '@referencedInstanceUID') AS X WHERE a.ANNOTATION_UID = ?) " + "UNION ALL " + "SELECT * FROM AD.GENERAL_IMAGE i, AD.GENERAL_SERIES s, AD.STUDY st, AD.PATIENT p " + "WHERE p.PATIENT_PK_ID = st.PATIENT_PK_ID " + "AND st.STUDY_PK_ID = s.STUDY_PK_ID " + "AND s.GENERAL_SERIES_PK_ID = i.GENERAL_SERIES_PK_ID " + "AND SOP_INSTANCE_UID IN " + "(SELECT X.SEGMENTATION_UID FROM AD.IMAGE_ANNOTATION a, " + " XMLTABLE ('declare default element namespace \"gme://caCORE.caCORE/3.2/edu.northwestern.radiology.AIM\"; " + "$aim/ImageAnnotation/segmentationCollection/Segmentation' passing a.AIM_OBJECT as \"aim\" " + "COLUMNS SEGMENTATION_UID VARCHAR(64) PATH '@referencedSopInstanceUID') AS X WHERE a.ANNOTATION_UID = ?)"; SQLQuery query = session.createSQLQuery(queryString); query.setString(0, annotationUID); query.setString(1, annotationUID); query.addEntity(GeneralImage.class).addEntity(GeneralSeries.class).addEntity(GeneralStudy.class) .addEntity(Patient.class); List<Object[]> queryResult = new ArrayList<Object[]>(); List<Object[]> tmpqueryResult = query.list(); queryResult.addAll(tmpqueryResult); LinkedList<DicomObject> result = new LinkedList<DicomObject>(); for (Object[] tuple : queryResult) { BasicDicomObject dcmObj = new BasicDicomObject(); GeneralImage image = (GeneralImage) tuple[0]; GeneralSeries series = (GeneralSeries) tuple[1]; GeneralStudy study = (GeneralStudy) tuple[2]; Patient patient = (Patient) tuple[3]; image.getDicomObject().copyTo(dcmObj); series.getDicomObject().copyTo(dcmObj); study.getDicomObject().copyTo(dcmObj); patient.getDicomObject().copyTo(dcmObj); result.add(dcmObj); } return result; }
From source file:com.siemens.scr.avt.ad.query.Queries.java
License:Open Source License
/** * Find all the DICOM object in the database satisfying given criteria. * // w ww .j av a2 s.c o m * @param dicomCriteria a map from DICOM tag to java.lang.Object representing a conjunctive query. * @param annotationCriteria a map from predefined keys to java.lang.Object representing a conjunctive query. * @param includingPixel indicating whether to include pixel data. * @return a list of DicomObject satisfying given criteria. */ @SuppressWarnings("unchecked") public static List<DicomObject> findDicomByCriteria(Map<Integer, Object> dicomCriteria, Map<String, Object> annotationCriteria, boolean includingPixel) { AbstractQueryBuilder builder = new DB2QueryBuilder(); LinkedList<String> output = new LinkedList<String>(); output.add(Patient.class.getCanonicalName()); output.add(GeneralStudy.class.getCanonicalName()); output.add(GeneralSeries.class.getCanonicalName()); output.add(GeneralImage.class.getCanonicalName()); String queryString = builder.buildQuery(dicomCriteria, annotationCriteria, output); logger.debug("Query:" + queryString); Session session = HibernateUtil.getSessionFactory().openSession(); SQLQuery query = session.createSQLQuery(queryString); query.addEntity(Patient.class).addEntity(GeneralStudy.class).addEntity(GeneralSeries.class) .addEntity(GeneralImage.class); List<Object[]> queryResult = query.list(); LinkedList<DicomObject> result = new LinkedList<DicomObject>(); for (Object[] tuple : queryResult) { BasicDicomObject dcmObj = new BasicDicomObject(); Patient patient = (Patient) tuple[0]; GeneralStudy study = (GeneralStudy) tuple[1]; GeneralSeries series = (GeneralSeries) tuple[2]; GeneralImage image = (GeneralImage) tuple[3]; image.getDicomObject().copyTo(dcmObj); series.getDicomObject().copyTo(dcmObj); study.getDicomObject().copyTo(dcmObj); patient.getDicomObject().copyTo(dcmObj); if (includingPixel) { File file = new File( Config.getConfig().getAdDicomStore() + File.separator + dcmObj.getString(0x00080018)); try { FileInputStream input = new FileInputStream(file); DicomInputStream dcmInput = new DicomInputStream(input); DicomObject dcm = dcmInput.readDicomObject(); result.add(dcm); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } else result.add(dcmObj); } session.close(); return result; }
From source file:com.siemens.scr.avt.ad.query.Queries.java
License:Open Source License
/** * Retrieving a list of entities satisfying the given criteria. * // w ww . j a v a2 s . c om * @param <T> The type of the entities. * @param dicomCriteria a map from DICOM tag to java.lang.Object representing a conjunctive query. * @param annotationCriteria a map from predefined keys to java.lang.Object representing a conjunctive query. * @param entityClass the java.lang.Class representation of the entity type. * @return a list of entities. */ public static <T> List<T> findEntityByCriteria(Map<Integer, Object> dicomCriteria, Map<String, Object> annotationCriteria, Class<T> entityClass) { AbstractQueryBuilder builder = new DB2QueryBuilder(); String outputKey = entityClass.getCanonicalName(); String queryString = builder.buildQuery(dicomCriteria, annotationCriteria, Collections.singletonList(outputKey)); logger.debug("Query:" + queryString); Session session = HibernateUtil.currentSession(); SQLQuery query = session.createSQLQuery(queryString); query.addEntity(entityClass); List<Object> queryResult = query.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY).list(); LinkedList<T> result = new LinkedList<T>(); for (Object entity : queryResult) { result.add((T) entity); } return result; }
From source file:com.sistcontable.dao.CuentaDAO.java
public void searchCuentaByID(String id) { Session session = HibernateUtil.getSessionFactory().getCurrentSession(); session.beginTransaction();//from w w w.ja v a 2 s . c o m List<Cuenta> lista = new ArrayList(); try { String query = "select * from cuenta where ID_CUENTA=:idCuenta"; SQLQuery sqlQuery = session.createSQLQuery(query); sqlQuery.addEntity(Cuenta.class); sqlQuery.setParameter("idCuenta", id); List result = sqlQuery.list(); for (int i = 0; i < result.size(); i++) { System.out.println("id: "); Cuenta cuenta = (Cuenta) result.get(i); System.out.println("idCuenta: " + cuenta.getIdCuenta()); System.out.println("estado: " + cuenta.getEstado().getNombreEstado()); System.out.println("rubro: " + cuenta.getRubro().getNombreRubro()); System.out.println("nombreCuenta: " + cuenta.getNombreCuenta()); System.out.println("cuentaMayor: " + cuenta.getCuentaMayor()); } } catch (Exception e) { System.out.println("ERROR " + e); lista = null; } finally { session.close(); } }
From source file:com.sistcontable.dao.CuentaDAO.java
public Cuenta obtenerCuentaByID(String id) { Session session = HibernateUtil.getSessionFactory().getCurrentSession(); session.beginTransaction();//ww w. j a v a2 s .c om List<Cuenta> lista = new ArrayList(); try { String query = "select * from cuenta where ID_CUENTA=:idCuenta"; SQLQuery sqlQuery = session.createSQLQuery(query); sqlQuery.addEntity(Cuenta.class); sqlQuery.setParameter("idCuenta", id); List result = sqlQuery.list(); for (int i = 0; i < result.size(); i++) { System.out.println("id: "); Cuenta cuenta = (Cuenta) result.get(i); System.out.println("idCuenta: " + cuenta.getIdCuenta()); System.out.println("estado: " + cuenta.getEstado().getNombreEstado()); System.out.println("rubro: " + cuenta.getRubro().getNombreRubro()); System.out.println("nombreCuenta: " + cuenta.getNombreCuenta()); System.out.println("cuentaMayor: " + cuenta.getCuentaMayor()); } return (Cuenta) result.get(0); } catch (Exception e) { System.out.println("ERROR " + e); lista = null; return null; } finally { session.close(); } }
From source file:com.sistcontable.dao.CuentaDAO.java
public List<Cuenta> searchAllCuentas() { Session session = HibernateUtil.getSessionFactory().getCurrentSession(); session.beginTransaction();// www. j a va 2s . c om List<Cuenta> lista = new ArrayList(); try { String query = "select * from cuenta order by ID_CUENTA"; SQLQuery sqlQuery = session.createSQLQuery(query); sqlQuery.addEntity(Cuenta.class); lista = sqlQuery.list(); for (int i = 0; i < lista.size(); i++) { System.out.println("-------------------------------------------------"); System.out.println("idCuenta: " + lista.get(i).getIdCuenta()); System.out.println("estado: " + lista.get(i).getEstado().getNombreEstado()); System.out.println("rubro: " + lista.get(i).getRubro().getNombreRubro()); System.out.println("nombreCuenta: " + lista.get(i).getNombreCuenta()); System.out.println("cuentaMayor: " + lista.get(i).getCuentaMayor()); } } catch (Exception e) { System.out.println("ERROR " + e); lista = null; } finally { session.close(); } return lista; }