use of org.apache.ibatis.session.SqlSession in project HackTutorial by linrongbin16.
the class UserTest method findUserById.
private void findUserById(int id) {
SqlSession sqlSession = null;
User user = null;
try {
sqlSession = sqlSessionFactory.openSession();
UserMapper mapper = sqlSession.getMapper(UserMapper.class);
user = mapper.findUserById(id);
} catch (Exception ex) {
logger.info("findUserById exception, id:{}, exception:{}", id, ex);
} finally {
if (sqlSession != null) {
sqlSession.close();
}
}
if (user == null) {
logger.info("findUserById fail, id {} not exist", id);
} else {
logger.info("findUserById success, User: {}", user);
}
}
use of org.apache.ibatis.session.SqlSession in project HackTutorial by linrongbin16.
the class UserTest method deleteUserById.
private void deleteUserById(int id) {
SqlSession sqlSession = null;
int result = 0;
try {
sqlSession = sqlSessionFactory.openSession();
UserMapper mapper = sqlSession.getMapper(UserMapper.class);
result = mapper.delete(id);
sqlSession.commit();
} catch (Exception ex) {
logger.info("deleteUserById exception, id:{}, exception:{}", id, ex);
} finally {
if (sqlSession != null) {
sqlSession.close();
}
}
if (result <= 0) {
logger.info("deleteUserById fail, id {} not exist, result:{}", id, result);
} else {
logger.info("deleteUserById success, result:{}", result);
}
}
use of org.apache.ibatis.session.SqlSession in project HackTutorial by linrongbin16.
the class UserTest method update.
private void update(User user) {
SqlSession sqlSession = null;
int result = 0;
try {
sqlSession = sqlSessionFactory.openSession();
UserMapper mapper = sqlSession.getMapper(UserMapper.class);
result = mapper.update(user);
sqlSession.commit();
} catch (Exception ex) {
logger.info("update exception, exception:{}, User:{}", ex, user);
} finally {
if (sqlSession != null) {
sqlSession.close();
}
}
if (result <= 0) {
logger.info("update fail, result:{}", result);
} else {
logger.info("update success, result:{}", result);
}
}
use of org.apache.ibatis.session.SqlSession in project HackTutorial by linrongbin16.
the class UserTest method insertUser.
private void insertUser(int id, String name, String email, Integer age) {
SqlSession sqlSession = null;
User u = new User(name, email, age);
try {
sqlSession = sqlSessionFactory.openSession();
UserMapper mapper = sqlSession.getMapper(UserMapper.class);
int result = mapper.insert(u);
sqlSession.commit();
logger.info("insert success, result:{}, User:{}", result, u);
} catch (Exception ex) {
logger.info("insert exception, exception:{}, User:{}", ex, u);
if (sqlSession != null) {
sqlSession.rollback();
}
} finally {
if (sqlSession != null) {
sqlSession.close();
}
}
}
use of org.apache.ibatis.session.SqlSession in project HackTutorial by linrongbin16.
the class App method insertUser.
private void insertUser(int id, String name, String email, Integer age) {
SqlSession sqlSession = null;
User u = new User(id, name, email, age);
try {
sqlSession = sqlSessionFactory.openSession();
UserMapper mapper = sqlSession.getMapper(UserMapper.class);
int result = mapper.insert(u);
sqlSession.commit();
logger.info("insert success, result:{}, User:{}", result, u);
} catch (Exception ex) {
logger.info("insert exception, exception:{}, User:{}", ex, u);
if (sqlSession != null) {
sqlSession.rollback();
}
} finally {
if (sqlSession != null) {
sqlSession.close();
}
}
}
Aggregations