Example usage for org.hibernate Query setInteger

List of usage examples for org.hibernate Query setInteger

Introduction

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

Prototype

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

Source Link

Document

Bind a named int-valued parameter.

Usage

From source file:acc_r3_javier_gonzalez.Consultas.java

/**
 * Metodo que devuelve una cerveza concreta buscada por ID.
 * @param id (int) - id de la cerveza que se quiere recuperar.
 * @return (R3Cerveza) - cerveza que se devuelve, null si no est.
 *//*from w  ww .j a  v  a 2 s . c o m*/
public static R3Cerveza searchById(int id) {
    Session s = Conexion.getSession();
    String hql = "from R3Cerveza where cid = :id";
    Query q = s.createQuery(hql);
    q.setInteger("id", id);
    R3Cerveza cerve = (R3Cerveza) q.uniqueResult();
    Conexion.desconecta();
    return cerve;
}

From source file:angeldx.manager.EstudianteManager.java

public Estudiante buscarPorId(int id) {
    Estudiante est = null;/*from   www . j  a  v a2s. c  o m*/
    Transaction tran = null;
    Session session = HibernateUtil.openSession();
    try {
        tran = session.beginTransaction();
        String queryString = "from Estudiante where id = :id";
        Query query = session.createQuery(queryString);
        query.setInteger("id", id);
        est = (Estudiante) query.uniqueResult();
    } catch (RuntimeException e) {
        e.printStackTrace();
    } finally {
        session.flush();
        session.close();
    }
    return est;
}

From source file:aseguradora.VistaVentana.java

private void eliminarAsegurado() {
    try {//from  www  .j ava  2s  .  c  om
        Session session = sesion.openSession();
        Transaction tx = session.beginTransaction();
        PolizasAsegurados pa;

        Query q = session
                .createQuery("from PolizasAsegurados as pa " + "where pa.id.codP = ? " + "and pa.id.num = ?");

        q.setInteger(0, Integer.parseInt(etCodPoliza.getText()));
        q.setInteger(1, Integer.parseInt(etNumAsegurado.getText()));

        pa = (PolizasAsegurados) q.uniqueResult();

        session.delete(pa);
        tx.commit();
        session.close();
        cargarVista();
    } catch (JDBCException e) {
        e.printStackTrace();
        if (e.getErrorCode() == ERROR_EDITAR_CLAVE_AJENA) {
            JOptionPane.showMessageDialog(rootPane,
                    "No puedes borrar este asegurado, restriccin clave primeria/ajena");
        }
    }
}

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) {/*from  ww w  .  j a 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.export.concrete.CtAnnotationsExportProcess.java

License:Open Source License

public String apply(CtSolutions sol, String filePath) {

    ecsv.clear();//from w w w.j a  v a2 s  . co m

    // make list of events, ordered by time.
    ecsv.addHeader(getFields());

    Session s = CtSession.Current();
    CtManualFlush mf = new CtManualFlush(s);

    Query q = s
            .createQuery(" SELECT ctA" + " FROM CtAnnotations as ctA" + " WHERE ctA.ctSolutions = :solution");

    q.setInteger("solution", sol.getPkSolution());

    List<CtAnnotations> l = (List<CtAnnotations>) q.list();
    for (CtAnnotations a : l) {
        ArrayList<String> fields = new ArrayList<String>();

        fields.add(String.valueOf(a.getPkAnnotation()));
        fields.add(String.valueOf(a.getCtAnnotationsTypes().getValue()));
        fields.add(String.valueOf(a.getCtSolutions().getPkSolution()));
        fields.add(String.valueOf(a.getCtImages().getPkImage()));
        fields.add(String.valueOf(a.getCtImages().getUri()));
        fields.add(String.valueOf(a.getValue()));
        fields.add(String.valueOf(a.getX()));
        fields.add(String.valueOf(a.getY()));

        ecsv.addRow(fields);
    }

    mf.restore();

    // save events to file..
    String result = ecsv.write(filePath);
    return result;
}

From source file:au.com.nicta.ct.solution.graphics.canvas.tools.annotations.CtAnnotationsModel.java

License:Open Source License

public void setSolution(CtSolutions s) {

    if (s == null) {
        clear();//from  www . jav  a  2  s .  c  om
        return;
    }

    Session session = CtSession.Current();
    session.beginTransaction();

    Query q = session
            .createQuery(" SELECT ctA" + " FROM CtAnnotations as ctA" + " WHERE ctA.ctSolutions = :solutionPk");
    q.setInteger("solutionPk", s.getPkSolution());

    for (CtAnnotations a : (List<CtAnnotations>) q.list()) {
        addToMaps(a);
    }

    session.getTransaction().commit();
}

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

License:Open Source License

protected void deleteFromTables(int solutionPk) {
    // delete from CtTracksDetections
    Query q = session.createQuery(" SELECT ctTD" + " FROM CtTracksDetections as ctTD"
            + " JOIN ctTD.ctTracks as ctT" + " WHERE ctT.ctSolutions = :solutionPk");
    q.setInteger("solutionPk", solutionPk);
    deleteRows(q.list());//from  w  w  w  . j a va 2s .  c o  m

    // delete from CtTracks
    q = session.createQuery(" SELECT ctT" + " FROM CtTracks as ctT" + " WHERE ctT.ctSolutions = :solutionPk");
    q.setInteger("solutionPk", solutionPk);
    deleteRows(q.list());

    // delete from CtDetections
    q = session
            .createQuery(" SELECT ctD" + " FROM CtDetections as ctD" + " WHERE ctD.ctSolutions = :solutionPk");
    q.setInteger("solutionPk", solutionPk);
    deleteRows(q.list());

    // delete from CtSolutions
    session.delete(session.load(CtSolutions.class, solutionPk));
}

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

License:Open Source License

/**
 * TODO: rewrite so that any property without a valid fk in other tables are
 * removed.//  w w w  .  ja  v a 2  s.  com
 * @param solutionPk
 */
protected void deleteProperties(int solutionPk) {
    // delete properties of CtDetections
    Query q = session.createQuery(
            " SELECT ctD.pkDetection" + " FROM CtDetections as ctD" + " WHERE ctD.ctSolutions = :solutionPk");
    q.setInteger("solutionPk", solutionPk);
    deleteProperties(CtDetections.class, q.list());

    // delete properties of CtTracks
    q = session.createQuery(
            " SELECT ctT.pkTrack" + " FROM CtTracks as ctT" + " WHERE ctT.ctSolutions = :solutionPk");
    q.setInteger("solutionPk", solutionPk);
    deleteProperties(CtTracks.class, q.list());

    // delete properties of CtTracksDetections
    q = session.createQuery(" SELECT ctTD.pkTrackDetection" + " FROM CtTracksDetections as ctTD"
            + " JOIN ctTD.ctTracks as ctT" + " WHERE ctT.ctSolutions = :solutionPk");
    q.setInteger("solutionPk", solutionPk);
    deleteProperties(CtTracksDetections.class, q.list());

    // delete entity properties
    q = session.createQuery(
            " DELETE " + " FROM CtEntityProperties as ctEP" + " WHERE ctEP.ctSolutions = :solutionPk");
    q.setInteger("solutionPk", solutionPk);
    q.executeUpdate();
}

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

License:Open Source License

protected void copyTracksDetections(Map<Integer, CtTracks> tracksMap, Map<Integer, CtDetections> detectionsMap,
        Map<Integer, CtTracksDetections> tracksDetectionsMap) {

    Query q = session.createQuery(" SELECT ctTD" + " FROM CtTracksDetections as ctTD"
            + " JOIN ctTD.ctTracks as ctT" + " WHERE ctT.ctSolutions = :solutionPk");

    q.setInteger("solutionPk", oldSolution.getPkSolution());

    for (CtTracksDetections td : (List<CtTracksDetections>) q.list()) {
        CtTracksDetections td2 = new CtTracksDetections();

        CtTracks newT = tracksMap.get(td.getCtTracks().getPkTrack());
        CtDetections newD = detectionsMap.get(td.getCtDetections().getPkDetection());
        td2.setCtTracks(newT);//from  www. ja v  a2 s.co  m
        td2.setCtDetections(newD);
        session.save(td2);
        int oldPk = td.getPkTrackDetection();
        int newPk = td2.getPkTrackDetection();
        tracksDetectionsMap.put(oldPk, td2);
        assert oldPk != newPk;
        //            session.evict(t);
        //            session.evict(d);
        //            session.get(CtTracks    .class, newPkT);
        //            session.get(CtDetections.class, newPkD);
    }
}

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

License:Open Source License

protected void copyAnnotations() {
    Query q = session
            .createQuery(" SELECT ctA" + " FROM CtAnnotations as ctA" + " WHERE ctA.ctSolutions = :solutionPk");

    q.setInteger("solutionPk", oldSolution.getPkSolution());

    for (CtAnnotations a : (List<CtAnnotations>) q.list()) {
        CtAnnotations a2 = new CtAnnotations(0, a.getCtAnnotationsTypes(), a.getCtImages(), newSolution,
                a.getValue(), a.getX(), a.getY());
        session.saveOrUpdate(a2);// ww  w .j  a v  a2 s  .  c  om
    }
}