Example usage for org.hibernate Query setString

List of usage examples for org.hibernate Query setString

Introduction

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

Prototype

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

Source Link

Document

Bind a named String-valued parameter.

Usage

From source file:au.com.nicta.ct.db.entities.CtEntityPropertiesTypesUtil.java

License:Open Source License

public static List<CtEntityPropertiesTypes> find(Session s, Class entityName, String propertyName) {

    String qs = " SELECT ctEPT" + " FROM CtEntityPropertiesTypes as ctEPT" + " WHERE";

    String prefix = "";
    if (entityName != null) {
        qs += prefix + " ctEPT.entityName = :entityName";
        prefix = " AND";
    }//ww  w. j a  v  a 2s. c o m
    if (propertyName != null) {
        qs += prefix + " ctEPT.name = :name";
        prefix = " AND";
    }

    Query q = s.createQuery(qs);

    if (entityName != null) {
        q.setString("entityName", CtEntityPropertiesUtil.getClassName(entityName));
    }
    if (propertyName != null) {
        q.setString("name", propertyName);
    }

    List<CtEntityPropertiesTypes> l = (List<CtEntityPropertiesTypes>) q.list();

    return l;
}

From source file:au.com.nicta.ct.db.entities.CtEntityPropertiesUtil.java

License:Open Source License

public static List<CtEntityProperties> find(Session s, Integer solutionPk, Class entityName, Integer entityPk,
        String propertyName) {/* w ww.  ja va  2  s .c  o m*/

    String qs = " SELECT ctEP" + " FROM CtEntityProperties as ctEP" + " WHERE";

    String prefix = "";
    if (solutionPk != null) {
        qs += prefix + " ctEP.ctSolutions = :ctSolutions";
        prefix = " AND";
    }
    if (entityName != null) {
        qs += prefix + " ctEP.entityName = :entityName";
        prefix = " AND";
    }
    if (entityPk != null) {
        qs += prefix + " ctEP.entityPk = :entityPk";
        prefix = " AND";
    }
    if (propertyName != null) {
        qs += prefix + " ctEP.name = :name";
        prefix = " AND";
    }

    Query q = s.createQuery(qs);

    if (solutionPk != null) {
        q.setInteger("ctSolutions", solutionPk);
        //            System.out.println( solutionPk );
    }
    if (entityName != null) {
        q.setString("entityName", getClassName(entityName));
        //            System.out.println( getClassName(entityName) );
    }
    if (entityPk != null) {
        q.setInteger("entityPk", entityPk);
        //            System.out.println( entityPk );
    }
    if (propertyName != null) {
        q.setString("name", propertyName);
        //            System.out.println( propertyName );
    }
    List<CtEntityProperties> l = (List<CtEntityProperties>) q.list();

    //        long end = System.nanoTime();
    //        System.out.println( "Time(ms): " + (end-sta)/1000000.0 );

    return l;
}

From source file:au.com.nicta.ct.solution.tracking.CtSolutionManager.java

License:Open Source License

protected void copyEntityProperties(Map<Integer, ?> oldToNewMap, Class tableCls,
        Map<Integer, Integer> entityPropertiesMap) {

    // get all properties
    Query q = session.createQuery(
            "FROM CtEntityProperties ctEntityProperties" + " WHERE ctEntityProperties.ctSolutions = :pkSolution"
                    + " AND ctEntityProperties.entityName = :entityName");

    q.setInteger("pkSolution", oldSolution.getPkSolution());
    q.setString("entityName", CtEntityPropertiesUtil.getClassName(tableCls));
    List<CtEntityProperties> allEntityProperties = (List<CtEntityProperties>) q.list();

    for (Map.Entry<Integer, ?> e : oldToNewMap.entrySet()) {

        Integer oldObjPk = e.getKey();
        Integer newObjPk = getPk(e.getValue());

        //            System.out.println("oldPk: " + (oldObjPk) );

        //            List<CtEntityProperties> l = CtEntityPropertiesUtil.find(session, oldSolution, tableCls, oldObjPk, null);
        for (CtEntityProperties ep : findEntityProperties(allEntityProperties, oldObjPk)) {
            //                System.out.println( "Name: " + ep.getName() + "  Value: " + ep.getValue() );

            CtEntityProperties ep2 = new CtEntityProperties();
            ep2.setCtSolutions(newSolution);
            ep2.setEntityName(ep.getEntityName());
            ep2.setEntityPk(newObjPk);/*from   w ww  .j  a va 2  s.  c  o  m*/
            ep2.setName(ep.getName());
            ep2.setValue(ep.getValue());

            session.save(ep2);
            int oldPk = ep.getPkEntityProperty();
            int newPk = ep2.getPkEntityProperty();
            entityPropertiesMap.put(oldPk, newPk);
            assert oldPk != newPk;
            //                session.evict( ep2 );
        }
    }
}

From source file:au.edu.uts.eng.remotelabs.schedserver.rigprovider.RigProviderActivator.java

License:Open Source License

@Override
public void stop(final BundleContext context) throws Exception {
    this.logger.info("Stopping " + context.getBundle().getSymbolicName() + " bundle.");
    this.serverReg.unregister();

    /* Clean up identity tokens. */
    this.idenTokReg.unregister();
    IdentityTokenRegister.getInstance().expunge();

    this.runnableReg.unregister();

    /* Take all rigs offline. */
    Session ses = DataAccessActivator.getNewSession();
    if (ses != null) {
        Query qu = ses.createQuery("UPDATE Rig SET active=:false, in_session=:false, online=:false, "
                + "session_id=:null, offline_reason=:offline");
        qu.setBoolean("false", false);
        qu.setParameter("null", null, Hibernate.BIG_INTEGER);
        qu.setString("offline", "Scheduling Server shutting down.");

        ses.beginTransaction();/*from   w  w  w  . j  a v a 2 s  .co  m*/
        int num = qu.executeUpdate();
        ses.getTransaction().commit();
        this.logger.info("Took " + num + " rigs offline for shutdown.");
        ses.close();
    }

    /* Cleanup the configuration service tracker. */
    RigProviderActivator.configTracker.close();
    RigProviderActivator.configTracker = null;
}

From source file:au.edu.uts.eng.remotelabs.schedserver.session.SessionActivator.java

License:Open Source License

@Override
public void stop(BundleContext context) throws Exception {
    this.logger.info("Stopping the Session bundle...");
    this.soapReg.unregister();
    this.terminatorService.unregister();
    this.sessionCheckerReg.unregister();
    SessionActivator.bookingsTracker.close();

    /* Terminate all in progress sessions. */
    Session ses = DataAccessActivator.getNewSession();
    if (ses != null) {
        Query qu = ses
                .createQuery("UPDATE Session SET active=:false, removal_reason=:reason, removal_time=:time "
                        + " WHERE active=:true");
        qu.setBoolean("false", false);
        qu.setBoolean("true", true);
        qu.setString("reason", "Scheduling Server shutting down.");
        qu.setTimestamp("time", new Date());

        ses.beginTransaction();//  w  w  w. j a  v  a2s  .  c o m
        int num = qu.executeUpdate();
        ses.getTransaction().commit();
        this.logger.info("Terminated " + num + " sessions for shutdown.");
        ses.close();
    }
}

From source file:au.org.theark.lims.model.dao.BioCollectionDao.java

License:Open Source License

public BioCollection getBioCollectionByUID(final String biocollectionUid, final Long studyId,
        final String subjectUID) {
    String GET_BIO_COLLECTION_BY_UID_AND_STUDY_ID_AND_SUBJECTUID = "select bio from BioCollection as bio "
            + "left outer join bio.linkSubjectStudy as linkStudy " + "left outer join linkStudy.study as study "
            + "where bio.biocollectionUid = :biocollectionUid " + "and study.id = :studyId "
            + " and linkStudy.subjectUID = :subjectUID";
    Query query = getSession().createQuery(GET_BIO_COLLECTION_BY_UID_AND_STUDY_ID_AND_SUBJECTUID);
    query.setString("biocollectionUid", biocollectionUid);
    query.setLong("studyId", studyId);
    query.setString("subjectUID", subjectUID);
    BioCollection bioCollection = (BioCollection) query.uniqueResult();
    return bioCollection;
}

From source file:boeken.BoekenDao.java

List getBoekenVanUitgever(String uitgeverij) {
    Query query = sessie.createQuery("from Boek where uitgeverij.naam = ?");
    query.setString(0, uitgeverij);
    return query.list();
}

From source file:br.cafw.si2at.dao.LoginDAO.java

public Usuarios login(String nome, String senha) {
    String hql = "from Usuarios u where u.login = :login and u.senha = md5(:senha)";
    Query q = HibernateUtil.getSession().createQuery(hql);
    q.setString("login", nome);
    q.setString("senha", senha);
    return (Usuarios) q.uniqueResult();
}

From source file:br.com.bibliotecasj.DAO.FrequenciaDAO.java

@Override
public Frequencia buscar(String cpf) {
    Session sessao = HibernateUtil.getSessionFactory().openSession();
    Frequencia fre = null;//from  w  w w . j a v a  2 s  .  c o  m
    try {

        Query consulta = sessao.getNamedQuery("frequencia.BuscarCpf");
        consulta.setString("cpf", cpf);
        fre = (Frequencia) consulta.uniqueResult();
    } catch (RuntimeException ex) {
        throw ex;

    } finally {
        sessao.close();
    }
    return fre;
}

From source file:br.com.bibliotecasj.DAO.LoginDAO.java

@Override
public Login buscar(String login) {
    Session sessao = HibernateUtil.getSessionFactory().openSession();
    Login log = null;/*w w  w.java 2  s.  c om*/
    try {

        Query consulta = sessao.getNamedQuery("Login.Buscarlog");
        consulta.setString("login", login);
        log = (Login) consulta.uniqueResult();
    } catch (RuntimeException ex) {
        throw ex;

    } finally {
        sessao.close();
    }
    return log;
}