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:databaseUtility.Database.java

public Utente getUtente(String utente) {
    Session session = factory.openSession();
    Transaction tx = session.beginTransaction();
    SQLQuery query = session.createSQLQuery("SELECT * FROM WA2P_UTENTI WHERE nickname= :username")
            .addEntity(Utente.class);
    query.setString("username", utente);
    Utente u = (Utente) query.uniqueResult();
    tx.commit();/* ww  w.  ja  va2 s  .  c om*/
    session.close();
    return u;
}

From source file:de.csw.expertfinder.expertise.ExpertiseModel.java

License:Open Source License

/**
 * Returns the TF/IDF weighting for the given word in the given document.
 * Does no word normalization in terms of lemmatization or stemming! If
 * normalization is needed, it has to be done on the word before calling
 * this method.//from   w ww.  j  a  v a 2  s .  c  o  m
 * 
 * @param documentId
 *            the id of the document
 * @param word
 *            the word (lemma or stem)
 * @return the TF/IDF
 */
public double getTFIDFWeight(Long documentId, String word) {
    persistenceStore.beginTransaction();

    SQLQuery q = persistenceStore
            .createSQLQuery("select count(*) as count from ( " + "select word from word w,  revision r "
                    + "where w.id_revision_created = r.id " + "and w.id_revision_deleted is null "
                    + "and r.id_document = :documentId " + "and word = :word) words");

    q.setLong("documentId", documentId).setString("word", word);
    q.addScalar("count", Hibernate.INTEGER);

    int wordDocumentFreq = (Integer) q.uniqueResult();

    q = persistenceStore.createSQLQuery("select count(*) as count from ( "
            + "select word from word w,  revision r " + "where w.id_revision_created = r.id "
            + "and w.id_revision_deleted is null " + "and r.id_document = :documentId) words");

    q.setLong("documentId", documentId);
    q.addScalar("count", Hibernate.INTEGER);

    int allDocumentFreq = (Integer) q.uniqueResult();

    q = persistenceStore.createSQLQuery("select count(*) as count from document");
    q.addScalar("count", Hibernate.INTEGER);

    int documentCount = (Integer) q.uniqueResult();

    q = persistenceStore.createSQLQuery(
            "select count(*) as count from ( " + "   select distinct d.id from document d, revision rc, word w "
                    + "   where w.word=:word " + "   and w.id_revision_created = rc.id "
                    + "   and w.id_revision_deleted is null " + "   and rc.id_document = d.id) word");

    q.setString("word", word);
    q.addScalar("count", Hibernate.INTEGER);

    int wordCorpusFreq = (Integer) q.uniqueResult();

    persistenceStore.endTransaction();

    double tf = (double) wordDocumentFreq / (double) allDocumentFreq;
    double idf = Math.log((double) documentCount / (double) wordCorpusFreq);

    return tf * idf;
}

From source file:edu.uiowa.icts.bluebutton.dao.LabTestHome.java

License:Apache License

private List<LoincCode> labTestQuery(String sex, Double age, String loincCodeCsvList) {
    List<LoincCode> list = new ArrayList<LoincCode>();
    if (sex != null && sex.length() > 0 && age != null) {
        sex = sex.substring(0, 1).toUpperCase();

        String sql = "select loinc_code as \"loinc_code\", min_normal as \"min_normal\", max_normal as \"max_normal\""
                + "   from bluebutton.lab_test lt, bluebutton.lab_test_range ltr "
                + "   where lt.lab_test_id = ltr.lab_test_id " + "   and ltr.sex like :sex "
                + "   and :age >= ltr.min_age_years  " + "   and :age < ltr.max_age_years "
                + "   and loinc_code IS NOT NULL ";
        if (loincCodeCsvList != null) {
            sql += "and loinc_code in (:loincCodeCsvList) ";
        }/*from  w w  w .  j a  v a 2s.  co  m*/
        SQLQuery query = this.sessionFactory.getCurrentSession().createSQLQuery(sql);
        query.setResultTransformer(Criteria.ALIAS_TO_ENTITY_MAP);
        query.setString("sex", "%" + sex + "%");
        query.setDouble("age", age);
        if (loincCodeCsvList != null) {
            query.setParameterList("loincCodeCsvList", loincCodeCsvList.split(","));
        }
        List data = query.list();

        for (Object object : data) {
            Map row = (Map) object;
            LoincCode lc = new LoincCode(row.get("loinc_code").toString(),
                    new Double((double) row.get("min_normal")), new Double((double) row.get("max_normal")));
            list.add(lc);
        }
    }
    return list;
}

From source file:edu.vt.vbi.patric.dao.DBDisease.java

License:Apache License

public List<ResultType> getMeshHierarchy(String ncbi_taxon_id, String tree_node) {
    String sql = "select c.disease_name, c.disease_id, c.pathogen, c.taxon_id, c.tree_node, length(tree_node) lvl, "
            + "   (select decode(count (*), 0, 1,0)  from  diseasedb.pathogen_disease where parent_node = c.tree_node and disease_db='MESH') is_leaf, "
            + "   c.vfg, c.gad_genes, c.ctd_genes " + " from diseasedb.disease_summary c  where 1=1";

    if (tree_node != null && !tree_node.equals("-1") && !tree_node.equals("") && !tree_node.equals("root"))
        sql += " and (c.tree_node like '" + tree_node + ".%')";
    else/*from www  .  jav a  2 s  .  c om*/
        sql += " and (c.tree_node like 'C01.252.400%' or tree_node like 'C01.252.410%')";

    sql += " and c.disease_db='MESH' and c.taxon_id in  (select gi.ncbi_tax_id from cas.genomeinfo gi "
            + " where gi.ncbi_tax_id in ( " + " select " + " ncbi_tax_id " + " from "
            + "     sres.taxon connect " + " by "
            + "     prior taxon_id = parent_id    start with ncbi_tax_id = ?)"
            + " ) group by  c.disease_name, c.disease_id, c.pathogen, c.taxon_id, c.tree_node, c.vfg, c.gad_genes, c.ctd_genes  order by lvl, is_leaf, c.disease_name ASC";

    Session session = factory.getCurrentSession();
    session.beginTransaction();
    SQLQuery q = session.createSQLQuery(sql);
    q.setString(0, ncbi_taxon_id);
    List<?> rset = q.list();
    session.getTransaction().commit();

    DataApiHandler dataApi = new DataApiHandler();

    List<ResultType> results = new ArrayList<>();
    for (Object aRset : rset) {
        Object[] obj = (Object[]) aRset;

        ResultType row = new ResultType();
        row.put("disease_name", obj[0]);
        row.put("disease_id", obj[1]);
        row.put("pathogen", obj[2]);
        row.put("taxon_id", obj[3]);
        row.put("tree_node", obj[4]);
        row.put("lvl", obj[5]);
        row.put("leaf", obj[6]);
        row.put("vfdb", obj[7]);
        row.put("gad", obj[8]);
        row.put("ctd", obj[9]);

        // for genome count
        Taxonomy taxonomy = dataApi.getTaxonomy(Integer.parseInt(obj[3].toString()));
        row.put("genome", taxonomy.getGenomeCount());

        results.add(row);
    }
    return results;
}

From source file:edu.vt.vbi.patric.dao.DBDisease.java

License:Apache License

public SQLQuery bindGraphGADSQLValues(SQLQuery q, Map<String, String> key) {

    if (key.containsKey("name") && key.get("name") != null && !key.get("name").equals("")) {
        q.setString("name", key.get("name").toLowerCase());
    }/*from   w w w . j  a  v a2 s .  c om*/

    return q;
}

From source file:edu.vt.vbi.patric.dao.DBDisease.java

License:Apache License

public SQLQuery bindGraphCTDSQLValues(SQLQuery q, Map<String, String> key) {

    if (key.containsKey("name") && key.get("name") != null && !key.get("name").equals("")) {
        q.setString("name", key.get("name"));
    }/*from w  w w . ja  v  a2  s .  c o m*/

    return q;
}

From source file:edu.vt.vbi.patric.dao.DBDisease.java

License:Apache License

public SQLQuery bindSQLValues(SQLQuery q, Map<String, String> key) {

    if (key.containsKey("name") && key.get("name") != null && !key.get("name").equals("")) {
        q.setString("name", key.get("name").toLowerCase() + "%");
    }/*  w ww .jav  a 2  s . c o  m*/

    return q;
}

From source file:edu.vt.vbi.patric.dao.DBDisease.java

License:Apache License

public SQLQuery bindVFDBSQLValues(SQLQuery q, Map<?, ?> key) {

    if (key.containsKey("cId")) {

        String cId = (String) key.get("cId");

        if (!cId.equals("")) {

            q.setString("id", cId);

        }//  ww  w.  j  a v a2 s  .  c o  m
    }

    if (key.containsKey("vfgId")) {

        String vfgId = (String) key.get("vfgId");

        if (!vfgId.equals("")) {

            q.setString("vfgId", vfgId);

        }
    }

    return q;
}

From source file:edu.vt.vbi.patric.dao.DBDisease.java

License:Apache License

public SQLQuery bindVFDBFeatureSQLValues(SQLQuery q, Map<String, String> key) {

    if (key.containsKey("vfgId")) {
        String vfgId = key.get("vfgId");
        if (vfgId != null && !vfgId.equals("")) {
            q.setString("vfgId", vfgId);
        }//from w ww  .ja va2 s .c om
    }

    return q;
}

From source file:edu.vt.vbi.patric.dao.DBDisease.java

License:Apache License

public List<ResultType> getMeshTermGraphData(String ncbi_taxon_id) {

    String sql = "select distinct t.ncbi_tax_id taxon_id, replace(replace(tn.name, '['), ']') organism_name, t.rank organism_rank"
            + "   from sres.taxon t, sres.taxonname tn" + "   where t.taxon_id = tn.taxon_id"
            + "   and t.ncbi_tax_id = ? " + "   and tn.name_class = 'scientific name'";

    Session session = factory.getCurrentSession();
    session.beginTransaction();//from  w  w  w .  j av  a2 s . c  o m
    SQLQuery q = session.createSQLQuery(sql);
    q.setString(0, ncbi_taxon_id);
    List<?> rset = q.list();
    session.getTransaction().commit();

    List<ResultType> results = new ArrayList<>();
    for (Object aRset1 : rset) {
        Object[] obj = (Object[]) aRset1;
        ResultType row = new ResultType();
        row.put("taxon_id", obj[0]);
        row.put("organism_name", obj[1]);
        row.put("organism_rank", obj[2]);
        row.put("parent_id", "");
        row.put("mesh_disease_id", "");
        row.put("mesh_disease_name", "");
        row.put("mesh_tree_node", "");
        row.put("parent_tree_node", "");
        row.put("description", "");

        results.add(row);
    }

    sql = "select distinct t.ncbi_tax_id taxon_id, tn.name organism_name, t.rank organism_rank, tp.ncbi_tax_id parent_id, pd.disease_id mesh_disease_id, pd.disease_name mesh_disease_name, pd.tree_node mesh_tree_node, pd.parent_node parent_tree_node, pd.description description "
            + "   from sres.taxon t, sres.taxonname tn, sres.taxon tp, diseasedb.disease_summary pd "
            + "   where t.taxon_id = tn.taxon_id " + "   and t.parent_id = tp.taxon_id "
            + "   and t.ncbi_tax_id = pd.taxon_id " + "   and t.taxon_id in "
            + "   (select distinct taxon_id from sres.taxon  connect by prior taxon_id = parent_id start with ncbi_tax_id = ?) "
            + "   and tn.name_class = 'scientific name' "
            + "   and (pd.tree_node like 'C01.252.400%' OR pd.tree_node like 'C01.252.410%') "
            + "   and pd.disease_db = 'MESH'";

    session = factory.getCurrentSession();
    session.beginTransaction();
    q = session.createSQLQuery(sql);
    q.setString(0, ncbi_taxon_id);
    rset = q.list();
    session.getTransaction().commit();

    for (Object aRset : rset) {
        Object[] obj = (Object[]) aRset;
        ResultType row = new ResultType();
        row.put("taxon_id", obj[0]);
        row.put("organism_name", obj[1]);
        row.put("organism_rank", obj[2]);
        row.put("parent_id", obj[3]);
        row.put("mesh_disease_id", obj[4]);
        row.put("mesh_disease_name", obj[5]);
        row.put("mesh_tree_node", obj[6]);
        row.put("parent_tree_node", obj[7]);
        row.put("description", obj[8]);

        results.add(row);
    }
    return results;

}