Class DBCreateTables

java.lang.Object
org.eclnt.ccee.db.DBCreateTables
All Implemented Interfaces:
ICCEEConstants

public class DBCreateTables extends Object implements ICCEEConstants
Executes a SQL script for creating database artifacts (tables, views, ...). The main method for execution are createTables() and createTables(String).

The SQL script is contained in the resource file "ccee_dbcreatetables.sql" for the default context and in the file "ccee_dbcreatetables_<contextName>.txt" for additional contexts.

Database statements are separated by one or several ";" delimiters. Example:
CREATE TABLE xxx ...;
CREATE TABLE yyy ...;
...

The statements of the file are executed one after the next. In case of failing there is some log output - but the script is continued to be executed.

Typical usage: you first define inside "ccee_dbcreatetables.sql" the tables you want to create. After running this class the tables are created. - At a later point of time you decide to append a field to a table definition (ALTER TABLE ... ADD COLUMN ...) or you create a new table (CREATE TABLE ...). When now running this class these statements (e.g. CREATE TABLE for already existing tables) will fail - and only the new statements will be successfully executed.

As result you have a simple but efficient way to update the database structure throughout various application versions in a consistent way.
  • Constructor Details

    • DBCreateTables

      public DBCreateTables()
  • Method Details

    • main

      public static void main(String[] args)
    • execute

      public void execute()
      Internally just calls createTables().
    • createTables

      public void createTables()
      Creates the tables in default resource file "ccee_dbcreatetables.sql".
    • createTables

      public void createTables(String contextName)
      Creates the tables in default resource file "ccee_dbcreatetables.sql" for the DEFAULT_CONTEXT and in "ccee_dbcreatetables_<contextName>.sql" for other contexts.
    • creatTablesByExplicitResourceFile

      public void creatTablesByExplicitResourceFile(String resourceName)
      Create tables according to statements that are contained in the resource that is passed.
    • creatTablesByExplicitResourceFile

      public void creatTablesByExplicitResourceFile(String contextName, String resourceName)
      Create tables according to statements that are contained in the resource that is passed.
    • createTablesBySqlSequence

      public void createTablesBySqlSequence(String contextName, String allSql)
    • removeComments

      protected String removeComments(String allSql)