Example usage for org.hibernate SQLQuery setString

List of usage examples for org.hibernate SQLQuery setString

Introduction

In this page you can find the example usage for org.hibernate SQLQuery setString.

Prototype

@Deprecated
@SuppressWarnings("unchecked")
default Query<R> setString(int position, String val) 

Source Link

Document

Bind a positional String-valued parameter.

Usage

From source file:com.redprairie.moca.task.dao.hibernate.TU_TaskDefinitionHibernateDAO.java

License:Open Source License

/**
 * This test is here to confirm that since task_definition can be a 
 * nvarchar that we are able to do a select for it using sql query.
 *///from w w  w  .ja  v a2  s  . c  om
@Test
public void testIsEntryAvailableHibernate() {
    Session hibernateSession = HibernateTools.getSession();

    SQLQuery query = hibernateSession
            .createSQLQuery("select task_id from task_definition" + "  where task_id = ?");

    query.setString(0, "NOT-PRESENT");

    Assert.assertTrue("There shouldn't be a NOT-PRESENT task in the db.", query.list().isEmpty());
}

From source file:com.siemens.scr.avt.ad.api.impl.DefaultADFacadeImpl.java

License:Open Source License

@SuppressWarnings("unchecked")
@Override/*from   w w w.  j  a  va2  s .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/*  www .j  a v  a2 s .c o m*/
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/*from  w  w  w.  j  ava 2  s. com*/
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.thoughtworks.go.server.persistence.MaterialRepository.java

License:Apache License

private Long findLastBuiltModificationId(final Pipeline pipeline, final MaterialInstance materialInstance) {
    BigInteger result = (BigInteger) getHibernateTemplate().execute((HibernateCallback) session -> {
        String sql = "SELECT fromRevisionId " + " FROM pipelineMaterialRevisions pmr "
                + "     INNER JOIN pipelines p on p.id = pmr.pipelineId " + " WHERE materialId = ? "
                + "     AND p.name = ? " + "     AND pipelineId < ? " + " ORDER BY pmr.id DESC" + " LIMIT 1";
        SQLQuery query = session.createSQLQuery(sql);
        query.setLong(0, materialInstance.getId());
        query.setString(1, pipeline.getName());
        query.setLong(2, pipeline.getId());
        return query.uniqueResult();
    });//from ww  w .jav a2  s . c o  m
    return result == null ? null : result.longValue();
}

From source file:com.thoughtworks.go.server.persistence.MaterialRepository.java

License:Apache License

public boolean hasPipelineEverRunWith(final String pipelineName, final MaterialRevisions revisions) {
    return (Boolean) getHibernateTemplate().execute((HibernateCallback) session -> {
        int numberOfMaterials = revisions.getRevisions().size();
        int match = 0;
        for (MaterialRevision revision : revisions) {
            long materialId = findOrCreateFrom(revision.getMaterial()).getId();
            long modificationId = revision.getLatestModification().getId();
            String key = cacheKeyForHasPipelineEverRunWithModification(pipelineName, materialId,
                    modificationId);/*from  w w w  .j av  a 2s . c  o m*/
            if (goCache.get(key) != null) {
                match++;
                continue;
            }
            String sql = "SELECT materials.id" + " FROM pipelineMaterialRevisions"
                    + " INNER JOIN pipelines ON pipelineMaterialRevisions.pipelineId = pipelines.id"
                    + " INNER JOIN modifications on modifications.id  = pipelineMaterialRevisions.torevisionId"
                    + " INNER JOIN materials on modifications.materialId = materials.id"
                    + " WHERE materials.id = ? AND pipelineMaterialRevisions.toRevisionId >= ? AND pipelineMaterialRevisions.fromRevisionId <= ? AND pipelines.name = ?"
                    + " GROUP BY materials.id;";
            SQLQuery query = session.createSQLQuery(sql);
            query.setLong(0, materialId);
            query.setLong(1, modificationId);
            query.setLong(2, modificationId);
            query.setString(3, pipelineName);
            if (!query.list().isEmpty()) {
                match++;
                goCache.put(key, Boolean.TRUE);
            }
        }
        return match == numberOfMaterials;
    });
}

From source file:com.thoughtworks.go.server.persistence.MaterialRepository.java

License:Apache License

@SuppressWarnings("unchecked")
public List<MatchedRevision> findRevisionsMatching(final MaterialConfig materialConfig,
        final String searchString) {
    return (List<MatchedRevision>) getHibernateTemplate().execute((HibernateCallback) session -> {
        String sql = "SELECT m.*" + " FROM modifications AS m"
                + " INNER JOIN materials mat ON mat.id = m.materialId"
                + " WHERE mat.fingerprint = :finger_print"
                + " AND (m.revision || ' ' || COALESCE(m.username, '') || ' ' || COALESCE(m.comment, '') LIKE :search_string OR m.pipelineLabel LIKE :search_string)"
                + " ORDER BY m.id DESC" + " LIMIT 5";
        SQLQuery query = session.createSQLQuery(sql);
        query.addEntity("m", Modification.class);
        Material material = materialConfigConverter.toMaterial(materialConfig);
        query.setString("finger_print", material.getFingerprint());
        query.setString("search_string", "%" + searchString + "%");
        final List<MatchedRevision> list = new ArrayList<>();
        for (Modification mod : (List<Modification>) query.list()) {
            list.add(material.createMatchedRevision(mod, searchString));
        }//from  www.  ja v  a 2  s.c  om
        return list;
    });
}

From source file:Consultas.FrmBuscarProducto.java

private void btnBuscarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnBuscarActionPerformed
    // TODO add your handling code here:

    String textoBusqueda = this.txtNombreID.getText();

    Session session = HibernateUtil.getInstance().getSession();
    session.beginTransaction();//from  w w w.  j a v  a2s .  c o m

    SQLQuery query = session
            .createSQLQuery("SELECT * FROM producto WHERE codigo = :codigo OR nombre LIKE :nombre");
    query.addEntity(ClsEntidadProductoHib.class);
    query.setString("codigo", textoBusqueda);
    query.setString("nombre", "%" + textoBusqueda + "%");
    this.resultados = query.list();

    DefaultTableModel dtm = new DefaultTableModel();
    String titulos[] = { "ID", "Codigo", "Nombre", "Descripcion", "Precio Venta" };
    dtm.setColumnIdentifiers(titulos);

    for (ClsEntidadProductoHib producto : this.resultados) {
        String datos[] = { producto.getIdProducto().toString(), producto.getCodigo(), producto.getNombre(),
                producto.getDescripcion(), producto.getPrecioVenta().toString() };
        dtm.addRow(datos);
    }

    this.tblResultados.setModel(dtm);
    this.tblResultados.changeSelection(0, 0, false, false);

    session.close();
}

From source file:dao.CompoundDao.java

public List<Compound> searchCompoundByName(String str) {
    List<Compound> objects = null;
    SQLQuery sqlq = null;

    try {/*from   w  w  w.  j  a  v a2  s. c o  m*/
        tx = session.beginTransaction();
        sqlq = session.createSQLQuery("call searchCompoundByName(:str)");
        sqlq.setString("str", str);
        objects = sqlq.addEntity(Compound.class).list();
        tx.commit();
    } catch (HibernateException e) {
        tx.rollback();
    }
    return objects;
}

From source file:dao.CompoundDao.java

public List<Compound> searchCompoundByFomula(String str) {
    List<Compound> objects = null;
    SQLQuery sqlq = null;

    try {// w  ww .j  a  va 2s  . c  o  m
        tx = session.beginTransaction();
        sqlq = session.createSQLQuery("call searchCompoundByFomula(:str)");
        sqlq.setString("str", str);
        List<Compound> list = objects = sqlq.addEntity(Compound.class).list();
        tx.commit();
    } catch (HibernateException e) {
        tx.rollback();
    }
    return objects;
}