Browse Source

implemented table creation

featue/module_registry
Stephan Richter 3 months ago
parent
commit
8c08af39fe
  1. 61
      company/src/main/java/de/srsoftware/umbrella/company/SqliteDb.java

61
company/src/main/java/de/srsoftware/umbrella/company/SqliteDb.java

@ -9,8 +9,12 @@ import static de.srsoftware.umbrella.company.Constants.TABLE_COMPANIES; @@ -9,8 +9,12 @@ import static de.srsoftware.umbrella.company.Constants.TABLE_COMPANIES;
import static de.srsoftware.umbrella.company.Constants.TABLE_COMPANIES_USERS;
import static de.srsoftware.umbrella.core.Constants.*;
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.databaseException;
import static de.srsoftware.umbrella.core.model.Status.OPEN;
import static java.lang.System.Logger.Level.ERROR;
import static java.text.MessageFormat.format;
import de.srsoftware.umbrella.company.api.CompanyDb;
import de.srsoftware.umbrella.core.BaseDb;
import de.srsoftware.umbrella.core.exceptions.UmbrellaException;
import de.srsoftware.umbrella.core.model.Company;
import java.sql.Connection;
@ -21,12 +25,61 @@ import java.util.HashSet; @@ -21,12 +25,61 @@ import java.util.HashSet;
import java.util.Map;
import org.json.JSONObject;
public class SqliteDb implements CompanyDb {
private final Connection db;
public class SqliteDb extends BaseDb implements CompanyDb {
public SqliteDb(Connection connection) {
db = connection;
super(connection);
}
protected int createTables() {
int currentVersion = createSettingsTable();
switch (currentVersion){
case 0:
createCompanyTable();
createCompaniesUsersTable();
}
return setCurrentVersion(1);
}
private void createCompanyTable() {
var sql = """
CREATE TABLE IF NOT EXISTS "companies" (
id INTEGER PRIMARY KEY,
name VARCHAR(255) NOT NULL,
address TEXT,
email VARCHAR(255),
phone VARCHAR(255),
bank_account TEXT,
court TEXT,
currency VARCHAR(10) DEFAULT "€",
logo TEXT,
tax_number VARCHAR(255),
decimals INT NOT NULL DEFAULT "2",
decimal_separator VARCHAR(10) DEFAULT ",",
thousands_separator VARCHAR(10) DEFAULT ".",
last_customer_number INT DEFAULT NULL,
customer_number_prefix VARCHAR(255))""";
try {
var stmt = db.prepareStatement(sql);
stmt.execute();
stmt.close();
} catch (SQLException e) {
LOG.log(ERROR, ERROR_FAILED_CREATE_TABLE, TABLE_COMPANIES, e);
throw new RuntimeException(e);
}
}
private void createCompaniesUsersTable() {
var sql = "CREATE TABLE IF NOT EXISTS companies_users (company_id INT NOT NULL, user_id INT NOT NULL)";
try {
var stmt = db.prepareStatement(sql);
stmt.execute();
stmt.close();
} catch (SQLException e) {
LOG.log(ERROR, ERROR_FAILED_CREATE_TABLE, TABLE_COMPANIES_USERS, e);
throw new RuntimeException(e);
}
}
@Override

Loading…
Cancel
Save