Class DatabaseSchema

java.lang.Object
org.gcube.accounting.utility.postgresql.DatabaseSchema

public class DatabaseSchema extends Object
Creates the schema of the accounting database (types and tables) where it is missing, by running the script "accounting-schema.sql". The script only creates what does not exist, so it is run every time the connection is prepared, also on a database that already holds the records. The database itself and its user are created by the provisioning.
Author:
Luca Frosini (ISTI - CNR)
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected static final long
    The key of the PostgreSQL advisory lock held while the script runs, so that two nodes preparing their connection at the same time create the schema one after the other.
    static final String
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    Creates what is missing of the schema, in one transaction of the given connection, which is committed on success and rolled back on failure.
    protected static String
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • SCHEMA_SCRIPT

      public static final String SCHEMA_SCRIPT
      See Also:
    • SCHEMA_LOCK_KEY

      protected static final long SCHEMA_LOCK_KEY
      The key of the PostgreSQL advisory lock held while the script runs, so that two nodes preparing their connection at the same time create the schema one after the other. Any constant shared by the nodes will do: this one spells "accountg" in ASCII.
      See Also:
  • Constructor Details

    • DatabaseSchema

      public DatabaseSchema()
  • Method Details

    • createIfMissing

      public static void createIfMissing(Connection connection) throws Exception
      Creates what is missing of the schema, in one transaction of the given connection, which is committed on success and rolled back on failure. The connection is left open.
      Parameters:
      connection - a connection to the accounting database, not in auto-commit mode
      Throws:
      Exception - if the script cannot be read or the database refuses it
    • readScript

      protected static String readScript() throws Exception
      Throws:
      Exception