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

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

Introduction

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

Prototype

@Override
void close();

Source Link

Document

Closes the session.

Usage

From source file:com.company.project.service.UserMapperImpl.java

License:Apache License

public int update(Map user) {
    SqlSession session = sqlSessionFactory.openSession();
    try {//from www . ja  v a2s  . com
        return session.update("com.company.project.persistence.UserMapper.update", user);
    } catch (Exception e) {
        e.printStackTrace();
        session.rollback();
    } finally {
        session.close();
    }

    return 0;
}

From source file:com.company.project.service.UserMapperImpl.java

License:Apache License

public int delete(String username) {
    SqlSession session = sqlSessionFactory.openSession();
    try {//from w  w w .ja va 2  s.  c  om
        return session.delete("com.company.project.persistence.UserMapper.delete", username);
    } catch (Exception e) {
        e.printStackTrace();
        session.rollback();
    } finally {
        session.close();
    }

    return 0;
}

From source file:com.DAO.VehicleDAOImpl.java

@Override
public Vehicle getVehicle(String license) {
    SqlSession session = sqlSessionFactory.openSession();
    try {// w  ww .  ja  va  2 s  .  c o m
        Vehicle vehicle = session.selectOne("Vehicle.getVehicle", license);
        return vehicle;
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        session.close();
    }
    return null;
}

From source file:com.DAO.VehicleDAOImpl.java

@Override
public Integer registerVehicle(Vehicle vehicle) {
    SqlSession session = sqlSessionFactory.openSession();
    try {/*from w w  w . ja v a2s . c  om*/
        Integer vehicleID = session.insert("Vehicle.insert", vehicle);
        log.info("Vehicle registration ID is : " + vehicle.getVehicleId());
        session.commit();
        if (vehicleID > 0)
            return vehicle.getVehicleId();
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        session.close();
    }
    return Integer.MIN_VALUE;
}

From source file:com.ehensin.paypal.account.repository.AccountRepository.java

License:Apache License

public CustomerAccountEntity getCustomerAccount(String entityId) throws Exception {
    String dbRepName = entityDBRepNameMap.get(CustomerAccountEntity.class);
    SplitFactor factor = new SplitFactor(SplitAlg.Hash, entityId);
    SqlSessionFactory factory = dbRepository.getSessionFactory(dbRepName, factor, false);
    SqlSession session = factory.openSession();
    try {//from w ww  .  j  a  v a 2  s.c om
        AccountMapper mapper = (AccountMapper) session.getMapper(AccountMapper.class);
        CustomerAccountORMapping orm = mapper.getCustomerAccount(entityId);
        if (orm == null)
            throw new Exception("cannot find entity for uuid :" + entityId);
        CustomerAccountEntity entity = new CustomerAccountEntity(orm.getUuid(), orm.getPhone(),
                orm.getLoginName(), orm.getMail(), orm.getPassword(), orm.getStatus(), orm.getBalance1(),
                orm.getBalance2(), orm.getBalance3(), orm.getBalance4(), orm.getBalance5(),
                orm.getLastUpdateTime());
        return entity;

    } catch (Exception e) {
        logger.error(e.getMessage(), e);
        throw e;
    } finally {
        session.close();
    }
}

From source file:com.ehensin.paypal.account.repository.AccountRepository.java

License:Apache License

public void addCustomerAccount(CustomerAccountEntity entity) throws Exception {
    String dbRepName = entityDBRepNameMap.get(CustomerAccountEntity.class);
    SplitFactor factor = new SplitFactor(SplitAlg.Hash, entity.getUuid());
    SqlSessionFactory factory = dbRepository.getSessionFactory(dbRepName, factor, true);
    SqlSession session = factory.openSession();
    try {//from w  ww.  ja  v  a 2s  . c  om
        AccountMapper mapper = (AccountMapper) session.getMapper(AccountMapper.class);
        CustomerAccountORMapping orm = new CustomerAccountORMapping(entity.getUuid(), entity.getPhone(),
                entity.getLoginName(), entity.getMail(), entity.getPassword(), entity.getStatus(),
                entity.getBalance1(), entity.getBalance2(), entity.getBalance3(), entity.getBalance4(),
                entity.getBalance5(), entity.getLastUpdateTime());
        mapper.insert(orm);
        session.commit(true);
    } catch (PersistenceException e) {
        logger.error(e.getMessage(), e);
        throw e;
    } finally {
        session.close();
    }
}

From source file:com.ehensin.paypal.account.test.CustomerAccountTest.java

License:Apache License

@Test
public void testInsert() throws Exception {
    DBRepositoryBuilder builder = new DBRepositoryBuilder();
    DBRepository repository = builder.build(new String[] { "com.ehensin.paypal.account.service" });
    SplitFactor factor = new SplitFactor(SplitAlg.Hash, 1);
    SqlSessionFactory factory = repository.getSessionFactory("account", factor, true);
    SqlSession session = factory.openSession();
    AccountMapper mapper = (AccountMapper) session.getMapper(AccountMapper.class);
    int count = mapper.getCount();
    System.out.println("hash customer count : " + count);
    CustomerAccountORMapping orm = new CustomerAccountORMapping();
    orm.setBalance1(0);/*w  w  w.  ja va 2s. c o  m*/
    orm.setBalance2(0);
    orm.setLastUpdateTime(new Timestamp(System.currentTimeMillis()));
    orm.setLoginName("hhb");
    orm.setMail("huanghaibo@newcosoft.com");
    orm.setPhone("13917310925");
    orm.setStatus(0);
    orm.setUuid("123");
    orm.setPassword("123456");
    mapper.insert(orm);
    count = mapper.getCount();
    System.out.println("hash customer count : " + count);
    session.commit(true);
    session.close();
}

From source file:com.ehensin.paypal.account.test.CustomerAccountTest.java

License:Apache License

@Test
public void testSelect() {
    DBRepositoryBuilder builder = new DBRepositoryBuilder();
    DBRepository repository = builder.build(new String[] { "com.ehensin.paypal.account.service" });
    SplitFactor factor = new SplitFactor(SplitAlg.Hash, 1);
    SqlSessionFactory factory = repository.getSessionFactory("account", factor, true);
    SqlSession session = factory.openSession();
    AccountMapper mapper = (AccountMapper) session.getMapper(AccountMapper.class);
    int count = mapper.getCount();
    System.out.println("hash customer count : " + count);
    CustomerAccountORMapping orm = mapper.getCustomerAccount("123");
    /*new CustomerAccountORMapping();
    orm.setBalance1(0);/*w  w w. j a v  a 2  s .c  om*/
    orm.setBalance2(0);
    orm.setLastUpdateTime(new Timestamp(System.currentTimeMillis()));
    orm.setLoginName("hhb");
    orm.setMail("huanghaibo@newcosoft.com");
    orm.setPhone("13917310925");
    orm.setStatus(0);
    orm.setUuid("123");
    orm.setPassword("123456");
    mapper.insert(orm);
    count = mapper.getCount();*/
    System.out.println("login name : " + orm.getLoginName());
    session.close();
}

From source file:com.ehensin.paypal.account.test.DBRepositoryTest.java

License:Apache License

@Test
public void testHash() {
    DBRepositoryBuilder builder = new DBRepositoryBuilder();
    DBRepository repository = builder.build(new String[] { "com.ehensin.paypal.account.service" });
    SplitFactor factor = new SplitFactor(SplitAlg.Hash, 1);
    SqlSessionFactory factory = repository.getSessionFactory("account", factor, true);
    SqlSession session = factory.openSession();
    AccountMapper mapper = (AccountMapper) session.getMapper(AccountMapper.class);
    int count = mapper.getCount();
    System.out.println("hash customer count : " + count);
    session.close();

    factory = repository.getSessionFactory("account", factor, false);
    session = factory.openSession();//  ww w .  j  ava 2  s .  com
    mapper = (AccountMapper) session.getMapper(AccountMapper.class);
    mapper.getCount();
    session.close();

    factory = repository.getSessionFactory("account", factor, false);
    session = factory.openSession();
    mapper = (AccountMapper) session.getMapper(AccountMapper.class);
    mapper.getCount();
    session.close();

}

From source file:com.ehensin.paypal.account.test.DBRepositoryTest.java

License:Apache License

@Test
public void testName() {
    DBRepositoryBuilder builder = new DBRepositoryBuilder();
    DBRepository repository = builder.build(new String[] { "com.ehensin.paypal.account.service" });
    SplitFactor factor = new SplitFactor(SplitAlg.Named, "portion1");
    SqlSessionFactory factory = repository.getSessionFactory("account", factor, true);
    SqlSession session = factory.openSession();
    AccountMapper mapper = (AccountMapper) session.getMapper(AccountMapper.class);
    mapper.getCount();//  w  w w  .ja va2  s . c o m
    session.close();

    factory = repository.getSessionFactory("account", factor, false);
    session = factory.openSession();
    mapper = (AccountMapper) session.getMapper(AccountMapper.class);
    mapper.getCount();
    session.close();

    factory = repository.getSessionFactory("account", factor, false);
    session = factory.openSession();
    mapper = (AccountMapper) session.getMapper(AccountMapper.class);
    mapper.getCount();
    session.close();

}