GraphNoOpExecutor(final GraphOutputFormat graphOutputFormat) throws SchemaCrawlerException { requireNonNull(graphOutputFormat, "No graph output format provided"); if (graphOutputFormat != GraphOutputFormat.scdot) { throw new SchemaCrawlerException("Format should be " + GraphOutputFormat.scdot); } }
private String getCatalogScope(final Connection connection) { String catalogScope = "ALL"; try { final Query query = new Query("Check access to DBA tables", "SELECT TABLE_NAME FROM DBA_TABLES WHERE ROWNUM = 1"); final Object scalar = executeForScalar(query, connection); if (scalar != null) { catalogScope = "DBA"; } } catch (final SchemaCrawlerException e) { LOGGER.log(Level.FINE, e.getMessage(), e); catalogScope = "ALL"; } LOGGER .log(Level.INFO, new StringFormat("Using Oracle data dictionary catalog scope <%s>", catalogScope)); return catalogScope; }
private static Catalog readCatalog(final InputStream in) throws SchemaCrawlerException { requireNonNull(in, "No input stream provided"); try (final ObjectInputStream objIn = new ObjectInputStream(in);) { return (Catalog) objIn.readObject(); } catch (ClassNotFoundException | IOException e) { throw new SchemaCrawlerException("Cannot deserialize catalog", e); } }
/** * Handles an aggregate operation, such as a count, for a given table. * * @param results * Results */ private long handleAggregateOperationForTable(final ResultSet results) throws SchemaCrawlerException { try { long aggregate = 0; if (results.next()) { aggregate = results.getLong(1); } return aggregate; } catch (final SQLException e) { throw new SchemaCrawlerException("Could not obtain aggregate data", e); } }
private static void checkResultSet(final ResultSet resultSet) throws SchemaCrawlerException { try { DatabaseUtility.checkResultSet(resultSet); } catch (final SchemaCrawlerSQLException e) { throw new SchemaCrawlerException("Bad result-set", e); } }
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(); }
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(); }
private static void checkConnection(final Connection connection) throws SchemaCrawlerException { try { DatabaseUtility.checkConnection(connection); } catch (final SchemaCrawlerSQLException e) { throw new SchemaCrawlerException("Bad database connection", e); } }
public void write(final JSONObject jsonObject) throws SchemaCrawlerException { try { jsonObject.write(out, 2); } catch (final JSONException e) { throw new SchemaCrawlerException("Could not write database", e); } }
/** * Serializes the database to the writer, as XML. * * @param out * Writer to save to * @throws SchemaCrawlerException * On an exception */ @Override public void save(final OutputStream out) throws SchemaCrawlerException { requireNonNull(out, "No output stream provided"); try (final ObjectOutputStream objOut = new ObjectOutputStream(out);) { objOut.writeObject(catalog); } catch (final IOException e) { throw new SchemaCrawlerException("Could not serialize catalog", e); } }
/** * {@inheritDoc} */ @Override public ConnectionOptions newDatabaseConnectionOptions(final UserCredentials userCredentials, final Config additionalConfig) throws SchemaCrawlerException { try { Class.forName("org.sqlite.JDBC"); } catch (final ClassNotFoundException e) { throw new SchemaCrawlerException("Could not load SQLite JDBC driver", e); } return super.newDatabaseConnectionOptions(userCredentials, additionalConfig); }
protected AbstractGraphProcessExecutor(final Path dotFile, final Path outputFile, final GraphOutputFormat graphOutputFormat) throws SchemaCrawlerException { requireNonNull(dotFile, "No DOT file provided"); requireNonNull(outputFile, "No graph output file provided"); requireNonNull(graphOutputFormat, "No graph output format provided"); this.dotFile = dotFile.normalize().toAbsolutePath(); this.outputFile = outputFile.normalize().toAbsolutePath(); this.graphOutputFormat = graphOutputFormat; if (!isFileReadable(this.dotFile)) { throw new SchemaCrawlerException("Cannot read DOT file, " + this.dotFile); } if (!isFileWritable(this.outputFile)) { throw new SchemaCrawlerException("Cannot write output file, " + this.outputFile); } }
public Connection createDatabaseConnection() throws SchemaCrawlerException { try { return createConnectionOptions().getConnection(); } catch (final SQLException e) { throw new SchemaCrawlerException("Cannot load database file", e); } }
throw new SchemaCrawlerException("Could not load class " + executableClassName, e); throw new SchemaCrawlerException("Could not instantiate executable for command '" + command + "'", e1);
throw new SchemaCrawlerException("Too many columns of data returned"); throw new SchemaCrawlerException("Too many rows of data returned"); throw new SchemaCrawlerException(sql, e);
throw new SchemaCrawlerException("Too many columns of data returned"); throw new SchemaCrawlerException("Too many rows of data returned"); throw new SchemaCrawlerException(sql, e);
/** * Handles an aggregate operation, such as a count, for a given table. * * @param title * Title * @param results * Results */ private void handleAggregateOperationForTable(final String title, final ResultSet results) throws SchemaCrawlerException { long aggregate = 0; try { if (results.next()) { aggregate = results.getLong(1); } } catch (final SQLException e) { throw new SchemaCrawlerException("Could not obtain aggregate data", e); } final String message = getMessage(aggregate); // formattingHelper.writeNameValueRow(title, message, Alignment.right); }
@Override public void checkAvailibility() throws Exception { if (graphOutputFormat == GraphOutputFormat.scdot) { return; } else if (GraphvizUtility.isGraphvizAvailable()) { return; } else if (GraphvizJavaExecutorUtility .isGraphvizJavaAvailable(graphOutputFormat)) { return; } else { throw new SchemaCrawlerException(String .format("Cannot generate graph in %s output format", graphOutputFormat)); } }
@Override public void checkAvailibility() throws Exception { if (GraphvizUtility.isGraphvizAvailable()) { return; } else if (GraphvizJavaExecutorUtility .isGraphvizJavaAvailable(GraphOutputFormat.svg)) { return; } else { throw new SchemaCrawlerException("Cannot generate graph in SVG format"); } }
private static List<CommandProvider> loadCommandRegistry() throws SchemaCrawlerException { final List<CommandProvider> commandProviders = new ArrayList<>(); commandProviders.add(new SchemaExecutableCommandProvider()); commandProviders.add(new OperationExecutableCommandProvider()); try { final ServiceLoader<CommandProvider> serviceLoader = ServiceLoader .load(CommandProvider.class); for (final CommandProvider commandProvider: serviceLoader) { LOGGER.log(Level.CONFIG, new StringFormat("Loading commands %s, provided by %s", commandProvider.getSupportedCommands(), commandProvider.getClass().getName())); commandProviders.add(commandProvider); } } catch (final Exception e) { throw new SchemaCrawlerException("Could not load extended command registry", e); } return commandProviders; }