Example usage for org.apache.ibatis.session SqlSession selectOne

List of usage examples for org.apache.ibatis.session SqlSession selectOne

Introduction

In this page you can find the example usage for org.apache.ibatis.session SqlSession selectOne.

Prototype

<T> T selectOne(String statement, Object parameter);

Source Link

Document

Retrieve a single row mapped from the statement key and parameter.

Usage

From source file:pecosa.daoImpl.VistaDaoImpl.java

@Override
public Integer getIdProductoInterno(Date fecha, String bien, Integer codigo) {
    Map<Object, Object> map = new HashMap<Object, Object>();
    map.put("fecha", fecha);
    map.put("bien", bien);
    map.put("codigo", codigo);
    Integer inte = null;/*from  w w w.j a v a  2s .  c  o  m*/
    SqlSession session = sqlSessionFactory.openSession();
    try {
        inte = session.selectOne("VistaData.getIdProdInterno", map);
    } catch (Exception e) {
        System.out.println(e.getMessage());
    } finally {
        session.close();
    }
    return inte;
}

From source file:py.pol.una.ii.pw.data.ProductoRepository.java

License:Apache License

public Producto findById(Long id) {
    SqlSession session = MyBatisSqlSessionFactory.getSqlSessionFactory().openSession();
    Producto pro = session.selectOne("getProductoById", id);
    return pro;/*w  w w. j  av  a 2  s.  c  o m*/
    //return em.find(Producto.class, id);
}

From source file:py.pol.una.ii.pw.data.ProveedorRepository.java

License:Apache License

public Proveedor findById(Long id) {
    SqlSession session = MyBatisSqlSessionFactory.getSqlSessionFactory().openSession();
    Proveedor prov = session.selectOne("getProveedorById", id);
    return prov;/*from   w  w  w . j  a  v  a 2s  .  c o  m*/
    //return em.find(Proveedor.class, id);
}

From source file:py.pol.una.ii.pw.service.Producto_DuplicadoRegistration.java

License:Apache License

public Producto_Duplicado getDuplicadoById(long id) {

    Producto_Duplicado duplicado = new Producto_Duplicado();
    try {/*  w  ww .  ja v a 2 s.com*/
        String resource = "mybatis/myBatisConfig.xml";
        InputStream inputStream;
        inputStream = Resources.getResourceAsStream(resource);
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
        SqlSession session = sqlSessionFactory.openSession();
        duplicado = session.selectOne("mybatis.duplicadoMapper.getDuplicadoById", id);
        session.close();

    } catch (IOException ioe) {

    }
    return duplicado;
}

From source file:py.pol.una.ii.pw.service.Producto_DuplicadoRegistration.java

License:Apache License

public void remove(long id) throws IOException {
    String resource = "mybatis/myBatisConfig.xml";
    InputStream inputStream;/*from   w  ww. ja  v  a 2s. c  om*/
    inputStream = Resources.getResourceAsStream(resource);
    SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
    SqlSession session = sqlSessionFactory.openSession();

    try {

        session.selectOne("mybatis.duplicadoMapper.removeDuplicado", id);

    } finally {
        session.close();
    }

}

From source file:py.pol.una.ii.pw.service.Producto_DuplicadoRegistration.java

License:Apache License

public void createProducto(Producto_Duplicado duplicado) {

    try {/* w  w  w .j av a2s. c  o  m*/
        String resource = "mybatis/myBatisConfig.xml";
        InputStream inputStream;
        inputStream = Resources.getResourceAsStream(resource);
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
        SqlSession session = sqlSessionFactory.openSession();
        session.selectOne("mybatis.duplicadoMapper.createDuplicado", duplicado);
        session.close();
    } catch (IOException ioe) {

    }

}

From source file:py.pol.una.ii.pw.service.Producto_DuplicadoRegistration.java

License:Apache License

public void updateDuplicado(Producto_Duplicado duplicado) {

    try {//from   ww w.ja  va  2s.c  o m
        String resource = "mybatis/myBatisConfig.xml";
        InputStream inputStream;
        inputStream = Resources.getResourceAsStream(resource);
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
        SqlSession session = sqlSessionFactory.openSession();
        session.selectOne("mybatis.duplicadoMapper.updateDuplicado", duplicado);
        session.close();

    } catch (IOException ioe) {

    }

}

From source file:shfq.constructor.xml.AddressConstructorTest.java

License:Apache License

private static Address queryAddressById(int id) {
    SqlSession session = null;
    try {//from   www . jav a 2s.c o  m
        Reader reader = Resources.getResourceAsReader("shfq/constructor/xml/mybatis-config.xml");
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);
        session = sqlSessionFactory.openSession();
        Address address = session.selectOne("shfq.constructor.xml.Address.selectAddress", id);
        session.commit();
        System.out.println("record queried successfully");
        return address;
    } catch (IOException e) {
        e.printStackTrace();
        session.rollback();
        return null;

    } finally {
        if (session != null) {
            session.close();
        }
    }
}

From source file:shfq.discriminator.xml.VehicleTest.java

License:Apache License

private static Car queryCarById(int id) {
    SqlSession session = null;
    try {//from   w  w  w . ja  va 2 s.com
        Reader reader = Resources.getResourceAsReader("shfq/discriminator/xml/mybatis-config.xml");
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);
        session = sqlSessionFactory.openSession();
        Car vehicle = session.selectOne("shfq.discriminator.vo.Vehicle.selectVehicle", id);
        session.commit();
        System.out.println("record queried successfully");
        return vehicle;
    } catch (IOException e) {
        e.printStackTrace();
        session.rollback();
        return null;

    } finally {
        if (session != null) {
            session.close();
        }
    }
}

From source file:shfq.discriminator.xml.VehicleTest.java

License:Apache License

private static Bus queryBusById(int id) {
    SqlSession session = null;
    try {//ww w . j  a va  2  s.c  om
        Reader reader = Resources.getResourceAsReader("shfq/discriminator/xml/mybatis-config.xml");
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);
        session = sqlSessionFactory.openSession();
        Bus vehicle = session.selectOne("shfq.discriminator.vo.Vehicle.selectVehicle", id);
        session.commit();
        System.out.println("record queried successfully");
        return vehicle;
    } catch (IOException e) {
        e.printStackTrace();
        session.rollback();
        return null;

    } finally {
        if (session != null) {
            session.close();
        }
    }
}