List of usage examples for org.hibernate JDBCException getSQLException
public SQLException getSQLException()
From source file:com.simple.cms.dao.ArticleDaoImpl.java
@Override public boolean addArticle(Article Article) { if (!dbSession.isOpen()) { dbSession = HibernateUtil.getSessionFactory().openSession(); }// w w w . j ava2 s . c o m dbSession.beginTransaction(); try { dbSession.persist(Article); dbSession.getTransaction().commit(); dbSession.flush(); return true; } catch (JDBCException ex) { dbSession.getTransaction().rollback(); dbSession.close(); throw new JDBCException(ex.getCause().getMessage(), ex.getSQLException()); } }
From source file:com.simple.cms.dao.ArticleDaoImpl.java
@Override public boolean deleteArticle(Article Article) { if (!dbSession.isOpen()) { dbSession = HibernateUtil.getSessionFactory().openSession(); }//from www.ja va 2s. c om try { dbSession.beginTransaction(); dbSession.delete(Article); dbSession.getTransaction().commit(); dbSession.flush(); } catch (JDBCException ex) { dbSession.getTransaction().rollback(); dbSession.close(); throw new JDBCException(ex.getCause().getMessage(), ex.getSQLException()); } return true; }
From source file:com.simple.cms.dao.ArticleDaoImpl.java
@Override public boolean updateArticle(Article newArticle) { if (!dbSession.isOpen()) { dbSession = HibernateUtil.getSessionFactory().openSession(); }/*from www .ja v a2 s . c o m*/ try { dbSession.beginTransaction(); dbSession.saveOrUpdate(newArticle); dbSession.getTransaction().commit(); dbSession.flush(); } catch (JDBCException ex) { dbSession.getTransaction().rollback(); dbSession.close(); throw new JDBCException(ex.getCause().getMessage(), ex.getSQLException()); } return true; }
From source file:com.simple.cms.dao.ArticleDaoImpl.java
@Override public List<Article> findArticleByNumber(int number) { List<Article> Articles; if (!dbSession.isOpen()) { dbSession = HibernateUtil.getSessionFactory().openSession(); }//from ww w . ja va 2 s . co m try { dbSession.beginTransaction(); Articles = dbSession.createCriteria(Article.class) .add(Restrictions.ilike("number", number + "", MatchMode.ANYWHERE)).list(); dbSession.getTransaction().commit(); dbSession.flush(); return Articles; } catch (JDBCException ex) { dbSession.getTransaction().rollback(); dbSession.close(); throw new JDBCException(ex.getCause().getMessage(), ex.getSQLException()); } }
From source file:com.simple.cms.dao.ArticleDaoImpl.java
@Override public Article findArticleByID(int ArticleId) { Article Article;/* w ww . j av a 2 s . c om*/ if (!dbSession.isOpen()) { dbSession = HibernateUtil.getSessionFactory().openSession(); } try { dbSession.beginTransaction(); Article = (Article) dbSession.get(Article.class, ArticleId); dbSession.getTransaction().commit(); dbSession.flush(); return Article; } catch (JDBCException ex) { dbSession.getTransaction().rollback(); dbSession.close(); throw new JDBCException(ex.getCause().getMessage(), ex.getSQLException()); } }
From source file:com.simple.cms.dao.ArticleDaoImpl.java
@Override public List<Article> findArticleByName(String name) { List<Article> Articles; if (!dbSession.isOpen()) { dbSession = HibernateUtil.getSessionFactory().openSession(); }// w w w . j a v a2s . c om try { dbSession.beginTransaction(); Articles = dbSession.createCriteria(Article.class) .add(Restrictions.ilike("name", name, MatchMode.ANYWHERE)).list(); dbSession.getTransaction().commit(); dbSession.flush(); return Articles; } catch (JDBCException ex) { dbSession.getTransaction().rollback(); dbSession.close(); throw new JDBCException(ex.getCause().getMessage(), ex.getSQLException()); } }
From source file:com.simple.cms.dao.ArticleDaoImpl.java
@Override public List<Article> findAllArticle() { if (!dbSession.isOpen()) { dbSession = HibernateUtil.getSessionFactory().openSession(); }/*from w ww.j a va2 s .co m*/ try { List<Article> Articles = dbSession.createCriteria(Article.class).list(); return Articles; } catch (JDBCException ex) { dbSession.getTransaction().rollback(); dbSession.close(); throw new JDBCException(ex.getCause().getMessage(), ex.getSQLException()); } }
From source file:com.simple.cms.dao.UserDaoImpl.java
@Override public boolean addUser(User user) { if (!dbSession.isOpen()) { dbSession = HibernateUtil.getSessionFactory().openSession(); }/* w w w . ja v a 2 s. c om*/ try { dbSession.beginTransaction(); dbSession.persist(user); dbSession.getTransaction().commit(); return true; } catch (JDBCException ex) { dbSession.getTransaction().rollback(); dbSession.close(); throw new JDBCException(ex.getCause().getMessage(), ex.getSQLException()); } }
From source file:com.simple.cms.dao.UserDaoImpl.java
@Override public boolean updateUser(User user) { if (!dbSession.isOpen()) { dbSession = HibernateUtil.getSessionFactory().openSession(); }/*from w w w .j a va 2 s. co m*/ try { dbSession.beginTransaction(); dbSession.saveOrUpdate(user); dbSession.getTransaction().commit(); return true; } catch (JDBCException ex) { dbSession.getTransaction().rollback(); dbSession.close(); throw new JDBCException(ex.getCause().getMessage(), ex.getSQLException()); } }
From source file:com.simple.cms.dao.UserDaoImpl.java
@Override public boolean deleteUser(User user) { if (!dbSession.isOpen()) { dbSession = HibernateUtil.getSessionFactory().openSession(); }/*from w ww. j av a 2 s . c o m*/ try { dbSession.beginTransaction(); dbSession.delete(user); dbSession.getTransaction().commit(); return true; } catch (JDBCException ex) { dbSession.getTransaction().rollback(); dbSession.close(); throw new JDBCException(ex.getCause().getMessage(), ex.getSQLException()); } }