List of usage examples for org.hibernate JDBCException JDBCException
public JDBCException(String message, SQLException cause)
From source file:com.gu.management.database.checking.ConnectionCheckResultClassifierTest.java
License:Apache License
@Test public void testShouldClassifyAsSevereIfResultIsNotSuccessfulAndHasSevereSQLErrorCode() throws Exception { SQLException sqlException = new SQLException("ORA-12345: the database is exploding", "industry standard exception code", 12345); JDBCException exception = new JDBCException("some sql exception occured", sqlException); ConnectionCheckResult result = new ConnectionCheckResult(exception); ConnectionCheckResultClassifier classifer = new ConnectionCheckResultClassifier(Arrays.asList(12345), emptySQLErrorMessageList);/*from w w w . ja v a2 s .c o m*/ assertThat(classifer.isSevere(result), equalTo(true)); }
From source file:com.gu.management.database.checking.ConnectionCheckResultClassifierTest.java
License:Apache License
@Test public void testShouldClassifyAsSevereIfResultIsNotSuccessfulAndMatchesSevereErrorMessage() throws Exception { SQLException sqlException = new SQLException("the database is levitating on a sea of jelly"); JDBCException exception = new JDBCException("some sql exception occured", sqlException); ConnectionCheckResult result = new ConnectionCheckResult(exception); ConnectionCheckResultClassifier classifer = new ConnectionCheckResultClassifier(emptySQLErrorCodeList, Arrays.asList("the database is levitating on a sea of jelly")); assertThat(classifer.isSevere(result), equalTo(true)); }
From source file:com.gu.management.database.checking.ConnectionCheckResultClassifierTest.java
License:Apache License
@Test public void testShouldNotClassifyAsSevereIfResultIsNotSuccessfulAndIsNotSevereSQLErrorCodeOrMessage() throws Exception { SQLException sqlException = new SQLException("ORA-987765: the database is out to lunch", "industry standard exception code", 987765); JDBCException exception = new JDBCException("some sql exception occured", sqlException); ConnectionCheckResult result = new ConnectionCheckResult(exception); ConnectionCheckResultClassifier classifer = new ConnectionCheckResultClassifier(Arrays.asList(12345), emptySQLErrorMessageList);/*from www . ja va 2s .c o m*/ assertThat(classifer.isSevere(result), equalTo(false)); }
From source file:com.simple.cms.dao.ArticleDaoImpl.java
@Override public boolean addArticle(Article Article) { if (!dbSession.isOpen()) { dbSession = HibernateUtil.getSessionFactory().openSession(); }//from w ww. j a va2 s.c om 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 w w w . j a va2 s . c o m*/ 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 w w w.j a v a 2 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(); }// w w w .j a v a 2s .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;//from w ww . j a v a 2s. c o m 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(); }// www . j a v a 2 s . 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(); }// www .j a v a2 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()); } }