Skip to content

Commit

Permalink
Changed sql executor
Browse files Browse the repository at this point in the history
  • Loading branch information
ValentinoAvonEFSA committed Jan 24, 2018
1 parent 212315e commit de3f206
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 195 deletions.
2 changes: 1 addition & 1 deletion src/formula/FunctionFormula.java
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ private String solveSum() throws FormulaException {

// return empty value if empty operand
if (operand.isEmpty()) {
LOGGER.warn("Warning: An operand of the SUM function is empty. Operands: " + operands + ". Returning empty value");
LOGGER.info("Warning: An operand of the SUM function is empty. Operands: " + operands + ". Returning empty value");
return "";
}

Expand Down
46 changes: 26 additions & 20 deletions src/table_database/DatabaseBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

import app_config.AppPaths;
import app_config.PropertiesReader;
import sql.SQLExecutor;
import table_skeleton.TableColumn;
import xlsx_reader.TableSchema;
import xlsx_reader.TableSchemaList;
Expand Down Expand Up @@ -41,19 +42,13 @@ public void create(String path) throws IOException {
String query = queryCreator.getCreateDatabaseQuery(TableSchemaList.getAll());

// create the database
try {

// set a "create" connection
DriverManager.getConnection(DB_URL);

// sql script to create the database
SQLScriptExec script = new SQLScriptExec(DB_URL);

script.exec(query);
try(Connection con = DriverManager.getConnection(DB_URL);
SQLExecutor executor = new SQLExecutor(con);) {
executor.exec(query);

addDbInfo();

} catch ( IOException | SQLException e ) {
} catch (IOException | SQLException e) {
e.printStackTrace();
LOGGER.error("Cannot create database in folder=" + path, e);
return;
Expand All @@ -71,40 +66,49 @@ public void createTable(TableSchema table) throws SQLException, IOException {

DatabaseStructureCreator creator = new DatabaseStructureCreator();
String query = creator.getNewTableQuery(table);
SQLScriptExec script = new SQLScriptExec(DB_URL);
script.exec(query);

try(Connection con = DriverManager.getConnection(DB_URL);
SQLExecutor executor = new SQLExecutor(con);) {
executor.exec(query);
}
}

/**
* Add a column to a table
* @param schema
* @param column
* @throws IOException
* @throws SQLException
*/
public void addColumnToTable(TableSchema schema, TableColumn column) throws IOException {
public void addColumnToTable(TableSchema schema, TableColumn column) throws IOException, SQLException {

DatabaseStructureCreator creator = new DatabaseStructureCreator();

String query = creator.getAddNewColumnQuery(schema.getSheetName(), column);

SQLScriptExec script = new SQLScriptExec(DB_URL);
script.exec(query);
try(Connection con = DriverManager.getConnection(DB_URL);
SQLExecutor executor = new SQLExecutor(con);) {
executor.exec(query);
}
}

/**
* Add a foreign key to the database
* @param schema
* @param foreignKey
* @throws IOException
* @throws SQLException
*/
public void addForeignKey(TableSchema schema, TableColumn foreignKey) throws IOException {
public void addForeignKey(TableSchema schema, TableColumn foreignKey) throws IOException, SQLException {

DatabaseStructureCreator creator = new DatabaseStructureCreator();

String query = creator.getAddForeignKeyQuery(schema.getSheetName(), foreignKey);

SQLScriptExec script = new SQLScriptExec(DB_URL);
script.exec(query);
try(Connection con = DriverManager.getConnection(DB_URL);
SQLExecutor executor = new SQLExecutor(con);) {
executor.exec(query);
}
}

/**
Expand All @@ -122,8 +126,10 @@ public void removeForeignKey(TableSchema schema, TableColumn foreignKey)
String query = creator.getRemoveForeignKeyQuery(schema.getSheetName(),
foreignKey.getId());

SQLScriptExec script = new SQLScriptExec(DB_URL);
script.exec(query);
try(Connection con = DriverManager.getConnection(DB_URL);
SQLExecutor executor = new SQLExecutor(con);) {
executor.exec(query);
}
}

/**
Expand Down
3 changes: 2 additions & 1 deletion src/table_database/DatabaseUpdater.java
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,9 @@ private void addTable(TableSchema table) throws SQLException, IOException {
* @param newTable
* @param newCol
* @throws IOException
* @throws SQLException
*/
private void addColumn(TableSchema newTable, TableColumn newCol) throws IOException {
private void addColumn(TableSchema newTable, TableColumn newCol) throws IOException, SQLException {
DatabaseBuilder db = new DatabaseBuilder();
db.addColumnToTable(newTable, newCol);
}
Expand Down
173 changes: 0 additions & 173 deletions src/table_database/SQLScriptExec.java

This file was deleted.

0 comments on commit de3f206

Please sign in to comment.