Class DatabaseSchema
java.lang.Object
org.gcube.accounting.utility.postgresql.DatabaseSchema
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
FieldsModifier and TypeFieldDescriptionprotected static final longThe 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 -
Method Summary
Modifier and TypeMethodDescriptionstatic voidcreateIfMissing(Connection connection) 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
-
Field Details
-
SCHEMA_SCRIPT
- See Also:
-
SCHEMA_LOCK_KEY
protected static final long SCHEMA_LOCK_KEYThe 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
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
- Throws:
Exception
-