public static Statement createStatement(final Connection connection) throws SQLException { checkConnection(connection); return connection.createStatement(); }
throws SchemaCrawlerException try (final Statement statement = createStatement(connection); final ResultSet resultSet = executeSql(statement, sql);)
private static void checkResultSet(final ResultSet resultSet) throws SchemaCrawlerException { try { DatabaseUtility.checkResultSet(resultSet); } catch (final SchemaCrawlerSQLException e) { throw new SchemaCrawlerException("Bad result-set", e); } }
logSQLWarnings(statement); if (hasResults)
public static ResultSet executeAgainstSchema(final Query query, final Statement statement, final InclusionRule schemaInclusionRule) throws SQLException { requireNonNull(query, "No query provided"); final String sql = getQuery(query, schemaInclusionRule); LOGGER.log(Level.FINE, new StringFormat("Executing %s: %n%s", query.getName(), sql)); return executeSql(statement, sql); }
public static long executeSqlForLong(final Connection connection, final String sql) throws SchemaCrawlerException { final Object longValue = executeSqlForScalar(connection, sql); // Error checking if (longValue == null || !(longValue instanceof Number)) { throw new SchemaCrawlerException("Cannot get an integer value result from SQL"); } return ((Number) longValue).longValue(); }
/** * Moves the cursor down one row from its current position. A * <code>ResultSet</code> cursor is initially positioned before the * first row; the first call to the method <code>next</code> makes the * first row the current row; the second call makes the second row the * current row, and so on. * * @return <code>true</code> if the new current row is valid; * <code>false</code> if there are no more rows * @throws SQLException * On a database access error */ boolean next() throws SQLException { readColumns = new HashSet<>(); final boolean next = results.next(); logSQLWarnings(results); if (next) { rowCount = rowCount + 1; } return next; }
/** * Obtain a collection of tables types for a database system, as * returned by the database server itself. */ public TableTypes(final Connection connection) { requireNonNull(connection, "No connection provided"); tableTypes = new HashSet<>(); try (final ResultSet tableTypesResults = connection.getMetaData() .getTableTypes();) { final List<String> tableTypeStrings = readResultsVector(tableTypesResults); for (final String tableTypeString: tableTypeStrings) { if (!isBlank(tableTypeString)) { tableTypes.add(new TableType(tableTypeString)); } } } catch (final Exception e) { LOGGER .log(Level.WARNING, "Could not obtain table types from connection", e); } }
public static long executeForLong(final Query query, final Connection connection, final Table table, final Identifiers identifiers) throws SchemaCrawlerException { requireNonNull(query, "No query provided"); final String sql = getQuery(query, table, true, identifiers); LOGGER.log(Level.FINE, new StringFormat("Executing %s: %n%s", query.getName(), sql)); return executeSqlForLong(connection, sql); }
public static ResultSet executeAgainstSchema(final Query query, final Statement statement, final InclusionRule schemaInclusionRule) throws SQLException { requireNonNull(query, "No query provided"); final String sql = getQuery(query, schemaInclusionRule); LOGGER.log(Level.FINE, new StringFormat("Executing %s: %n%s", query.getName(), sql)); return executeSql(statement, sql); }
logSQLWarnings(statement); if (hasResults)
public static long executeSqlForLong(final Connection connection, final String sql) throws SchemaCrawlerException { final Object longValue = executeSqlForScalar(connection, sql); // Error checking if (longValue == null || !(longValue instanceof Number)) { throw new SchemaCrawlerException("Cannot get an integer value result from SQL"); } return ((Number) longValue).longValue(); }
/** * Moves the cursor down one row from its current position. A * <code>ResultSet</code> cursor is initially positioned before the * first row; the first call to the method <code>next</code> makes the * first row the current row; the second call makes the second row the * current row, and so on. * * @return <code>true</code> if the new current row is valid; * <code>false</code> if there are no more rows * @throws SQLException * On a database access error */ boolean next() throws SQLException { readColumns = new HashSet<>(); final boolean next = results.next(); logSQLWarnings(results); if (next) { rowCount = rowCount + 1; } return next; }
/** * Obtain a collection of tables types for a database system, as * returned by the database server itself. */ public TableTypes(final Connection connection) { requireNonNull(connection, "No connection provided"); tableTypes = new HashSet<>(); try (final ResultSet tableTypesResults = connection.getMetaData() .getTableTypes();) { final List<String> tableTypeStrings = readResultsVector(tableTypesResults); for (final String tableTypeString: tableTypeStrings) { if (!isBlank(tableTypeString)) { tableTypes.add(new TableType(tableTypeString)); } } } catch (final Exception e) { LOGGER .log(Level.WARNING, "Could not obtain table types from connection", e); } }
public static long executeForLong(final Query query, final Connection connection, final Table table, final Identifiers identifiers) throws SchemaCrawlerException { requireNonNull(query, "No query provided"); final String sql = getQuery(query, table, true, identifiers); LOGGER.log(Level.FINE, new StringFormat("Executing %s: %n%s", query.getName(), sql)); return executeSqlForLong(connection, sql); }
throws SchemaCrawlerException try (final Statement statement = createStatement(connection); final ResultSet resultSet = executeSql(statement, sql);)
public static Statement createStatement(final Connection connection) throws SQLException { checkConnection(connection); return connection.createStatement(); }
public static ResultSet executeAgainstTable(final Query query, final Statement statement, final Table table, final boolean isAlphabeticalSortForTableColumns, final Identifiers identifiers) throws SQLException { requireNonNull(query, "No query provided"); requireNonNull(identifiers, "No identifiers provided"); final String sql = getQuery(query, table, isAlphabeticalSortForTableColumns, identifiers); LOGGER.log(Level.FINE, new StringFormat("Executing %s: %n%s", query.getName(), sql)); return executeSql(statement, sql); }
logSQLWarnings(statement); if (hasResults)
public static Object executeForScalar(final Query query, final Connection connection) throws SchemaCrawlerException { requireNonNull(query, "No query provided"); final String sql = getQuery(query); LOGGER.log(Level.FINE, new StringFormat("Executing %s: %n%s", query.getName(), sql)); return executeSqlForScalar(connection, sql); }