@Test public void CheckEmptyCommandIsNotExecutedTest() throws SQLException { String[] inputs = {}; CommandLine.run(spySQL, printStream, inputs); verify(spyDBManager, times(0)).getStandardSqlConnection(); }
@Override public void run() { if (allParams == null) { outputStream.print("No SQL input, please enter a valid SQL command"); return; } if (dbManager == null) { if (State.getCurrentStorageType() != DataStorageType.PUREDB) { outputStream.print("Currently not connected to the database, cannot execute SQL"); return; } else { dbManager = DBManager.getInstance(); } } String sql = String.join(" ", allParams); try (Connection connection = dbManager.getStandardSqlConnection()) { connection.setReadOnly(true); executeQuery(connection, sql, outputStream); } catch (SQLException e) { LOGGER.log(Level.WARNING, e.getMessage(), e); outputStream.print("Couldn't connect to the database"); } }
SQL implements Runnable { @Override public void run() { if (allParams == null) { outputStream.print("No SQL input, please enter a valid SQL command"); return; } if (dbManager == null) { if (State.getCurrentStorageType() != DataStorageType.PUREDB) { outputStream.print("Currently not connected to the database, cannot execute SQL"); return; } else { dbManager = DBManager.getInstance(); } } String sql = String.join(" ", allParams); try (Connection connection = dbManager.getStandardSqlConnection()) { connection.setReadOnly(true); executeQuery(connection, sql, outputStream); } catch (SQLException e) { LOGGER.log(Level.WARNING, e.getMessage(), e); outputStream.print("Couldn't connect to the database"); } } }
SQL implements Runnable { @Override public void run() { if (allParams == null) { outputStream.print("No SQL input, please enter a valid SQL command"); return; } if (dbManager == null) { if (State.getCurrentStorageType() != DataStorageType.PUREDB) { outputStream.print("Currently not connected to the database, cannot execute SQL"); return; } else { dbManager = DBManager.getInstance(); } } String sql = String.join(" ", allParams); try (Connection connection = dbManager.getStandardSqlConnection()) { connection.setReadOnly(true); executeQuery(connection, sql, outputStream); } catch (SQLException e) { LOGGER.log(Level.WARNING, e.getMessage(), e); outputStream.print("Couldn't connect to the database"); } } SQL(DBManager dbManager);  SQL(PrintStream outputStream);  SQL(DBManager dbManager, PrintStream outputStream);  SQL(); }
SQL implements Runnable { @Override public void run() { if (allParams == null) { outputStream.print("No SQL input, please enter a valid SQL command"); return; } if (dbManager == null) { if (State.getCurrentStorageType() != DataStorageType.PUREDB) { outputStream.print("Currently not connected to the database, cannot execute SQL"); return; } else { dbManager = DBManager.getInstance(); } } String sql = String.join(" ", allParams); try (Connection connection = dbManager.getStandardSqlConnection()) { connection.setReadOnly(true); executeQuery(connection, sql, outputStream); } catch (SQLException e) { LOGGER.log(Level.WARNING, e.getMessage(), e); outputStream.print("Couldn't connect to the database"); } } SQL(DBManager dbManager);  SQL(PrintStream outputStream);  SQL(DBManager dbManager, PrintStream outputStream);  SQL(); @Override void run(); }
SQL implements Runnable { @Override public void run() { if (allParams == null) { outputStream.print("No SQL input, please enter a valid SQL command"); return; } if (dbManager == null) { if (State.getCurrentStorageType() != DataStorageType.PUREDB) { outputStream.print("Currently not connected to the database, cannot execute SQL"); return; } else { dbManager = DBManager.getInstance(); } } String sql = String.join(" ", allParams); try (Connection connection = dbManager.getStandardSqlConnection()) { connection.setReadOnly(true); executeQuery(connection, sql, outputStream); } catch (SQLException e) { LOGGER.log(Level.WARNING, e.getMessage(), e); outputStream.print("Couldn't connect to the database"); } } SQL(DBManager dbManager);  SQL(PrintStream outputStream);  SQL(DBManager dbManager, PrintStream outputStream);  SQL(); @Override void run();  }