private boolean throwSqlException = false; @Given("The data base calling return sqlexception$") public void returnsSqlExcception() { throwSqlException = true; } @When("do something") public void doSomething() { if(throwSqlException) { throw new SqlException(); } // ... }
public void rollback() { try { sqlTransaction.rollback(); } catch (SqlException e) { log.warn(e.getMessage(), e); } finally { clearState(); } }
if (continueOnError) { if (debug) { ex.printStackTrace();
if (continueOnError) { if (debug) { ex.printStackTrace();
@Given("The data base calling return sqlexception$") public void sqlExceptionThrownOnDbCall() { expect(mockedDao.methodToBecalled(...)).andThrow(new SqlException()); }
public boolean deleteIdentity() { boolean successful = false; try { sqlTemplate.update(getSql("deleteNodeIdentitySql")); successful = true; } catch (SqlException ex) { log.debug(ex.getMessage()); } finally { cachedNodeIdentity = null; } return successful; }
if (continueOnError) { if (debug) { ex.printStackTrace();
public static String getDatabaseProductVersion(DataSource dataSource) { Connection connection = null; try { connection = dataSource.getConnection(); DatabaseMetaData metaData = connection.getMetaData(); return metaData.getDatabaseProductVersion(); } catch (SQLException ex) { throw new SqlException("Error while reading the database metadata: " + ex.getMessage(), ex); } finally { if (connection != null) { try { connection.close(); } catch (SQLException ex) { // we ignore this one } } } }
public Node findIdentity(boolean useCache, boolean logSqlError) { if (cachedNodeIdentity == null || useCache == false) { try { List<Node> list = sqlTemplate.query( getSql("selectNodePrefixSql", "findNodeIdentitySql"), new NodeRowMapper()); cachedNodeIdentity = (Node) getFirstEntry(list); } catch (SqlException ex) { if (logSqlError) { log.info("Failed to load the node identity because: {}. Returning {}", ex.getMessage(), cachedNodeIdentity); } } } return cachedNodeIdentity; }
public static int getDatabaseMajorVersion(DataSource dataSource) { Connection connection = null; try { connection = dataSource.getConnection(); DatabaseMetaData metaData = connection.getMetaData(); return metaData.getDatabaseMajorVersion(); } catch (SQLException ex) { throw new SqlException("Error while reading the database metadata: " + ex.getMessage(), ex); } finally { if (connection != null) { try { connection.close(); } catch (SQLException ex) { // we ignore this one } } } }
if (e.getMessage()!=null && StringUtils.containsIgnoreCase(e.getMessage(), "does not exist")) { return null; } else {
public static int getDatabaseMinorVersion(DataSource dataSource) { Connection connection = null; try { connection = dataSource.getConnection(); DatabaseMetaData metaData = connection.getMetaData(); return metaData.getDatabaseMinorVersion(); } catch (SQLException ex) { throw new SqlException("Error while reading the database metadata: " + ex.getMessage(), ex); } finally { if (connection != null) { try { connection.close(); } catch (SQLException ex) { // we ignore this one } } } }
public void truncateTable(String tableName) { String quote = platform.getDdlBuilder().isDelimitedIdentifierModeOn() ? platform .getDatabaseInfo().getDelimiterToken() : ""; boolean success = false; int tryCount = 5; while (!success && tryCount > 0) { try { Table table = platform.getTableFromCache(tableName, false); if (table != null) { platform.getSqlTemplate().update( String.format("truncate table %s%s%s", quote, table.getName(), quote)); success = true; } else { throw new RuntimeException(String.format("Could not find %s to trunate", tableName)); } } catch (SqlException ex) { log.warn(ex.getMessage(), ex); AppUtils.sleep(5000); tryCount--; } } }
throw new SqlException("Error while reading the database metadata: " + ex.getMessage(), ex); } finally {
@Override public void truncateTable(String tableName) { String quote = platform.getDdlBuilder().isDelimitedIdentifierModeOn() ? platform .getDatabaseInfo().getDelimiterToken() : ""; boolean success = false; int tryCount = 5; while (!success && tryCount > 0) { try { Table table = platform.getTableFromCache(tableName, false); if (table != null) { platform.getSqlTemplate().update( String.format("delete from %s%s%s", quote, table.getName(), quote)); success = true; } else { throw new RuntimeException(String.format("Could not find %s to trunate", tableName)); } } catch (SqlException ex) { log.warn(ex.getMessage(), ex); AppUtils.sleep(5000); tryCount--; } } }
obj = IOUtils.toByteArray(is); } catch (IOException e) { throw new SqlException(e); } finally { IOUtils.closeQuietly(is); obj = IOUtils.toString(reader); } catch (IOException e) { throw new SqlException(e); } finally { IOUtils.closeQuietly(reader);
if (sourceTable != null) { throw new SqlException(String.format("Could not find the target table %s", sourceTable.getFullyQualifiedTableName())); } else { throw new SqlException("The target table was not specified");