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 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); } }
@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; }
@Override public void startServer() throws SchemaCrawlerException { try { final String homeDirectory = System.getProperty("user.home"); final Path cachedPostgreSQL = Paths.get(homeDirectory, ".embedpostgresql") .toAbsolutePath(); cachedPostgreSQL.toFile().mkdirs(); final IRuntimeConfig runtimeConfig = EmbeddedPostgres .cachedRuntimeConfig(cachedPostgreSQL); postgreSQL = new EmbeddedPostgres(postgreSQLVersion); postgreSQL.start(runtimeConfig, "localhost", findFreePort(), getDatabase(), getUser(), getPassword(), Arrays.asList("-E", "'UTF-8'")); Runtime.getRuntime().addShutdownHook(hook); } catch (final Exception e) { throw new SchemaCrawlerException("Could not start PostgreSQL server", e); } }
protected final SchemaCrawlerCommand addNextAndConfigureForExecution(final String command, final OutputOptions outputOptions) throws SchemaCrawlerException { try { final SchemaCrawlerCommand scCommand = commandRegistry .configureNewCommand(command, schemaCrawlerOptions, outputOptions); if (scCommand == null) { return null; } scCommand.setAdditionalConfiguration(additionalConfiguration); scCommand.setCatalog(catalog); scCommand.setConnection(connection); scCommand.setIdentifiers(identifiers); scCommands.add(scCommand); return scCommand; } catch (final Exception e) { throw new SchemaCrawlerException(String .format("Cannot chain commands, unknown command <%s>", command)); } }
@Override public ConnectionOptions createConnectionOptions() throws SchemaCrawlerException { requireNonNull(databaseFile, "Database file not loaded"); final Config config = new Config(); config.put("server", "sqlite"); config.put("database", databaseFile.toString()); try { final ConnectionOptions connectionOptions = new SQLiteDatabaseConnector() .newDatabaseConnectionOptions(new SingleUseUserCredentials(), config); return connectionOptions; } catch (final IOException e) { throw new SchemaCrawlerException("Cannot read datad database file, " + databaseFile, e); } }
@Override public ConnectionOptions createConnectionOptions() throws SchemaCrawlerException { try { requireNonNull(postgreSQL, "Database server not started"); final Config config = new Config(); config.put("url", getConnectionUrl()); final UserCredentials userCredentials = new SingleUseUserCredentials(getUser(), getPassword()); final ConnectionOptions connectionOptions = new DatabaseConnectionOptions(userCredentials, config); return connectionOptions; } catch (final Throwable e) { throw new SchemaCrawlerException("Cannot read file, " + databaseFile, e); } }
private ScriptEngine getScriptEngine() throws SchemaCrawlerException { final String scriptFileName = outputOptions.getOutputFormatValue(); if (isBlank(scriptFileName)) { throw new SchemaCrawlerCommandLineException("Please specify a script to execute"); } final String scriptExtension = getFileExtension(scriptFileName); final ScriptEngineManager scriptEngineManager = new ScriptEngineManager(); final ScriptEngine scriptEngine; if (isBlank(scriptExtension)) { scriptEngine = scriptEngineManager.getEngineByName("nashorn"); } else { scriptEngine = scriptEngineManager.getEngineByExtension(scriptExtension); } if (scriptEngine == null) { throw new SchemaCrawlerException("Script engine not found"); } logScriptEngineDetails(Level.CONFIG, scriptEngine.getFactory()); return scriptEngine; }