Class DatabaseConnectionFactory


  • public class DatabaseConnectionFactory
    extends java.lang.Object
    This class is a helper class that provides the connection to the embedded HSQLDB database. It is mainly used by the data access objects.

    The class provides methods to create Connection objects, retrieve SQL statements from the resources, and create the initial tables when the application is first started.

    • Method Detail

      • createConnection

        public static java.sql.Connection createConnection​(java.io.File databaseFile,
                                                           boolean readOnly)
        Creates a database connection using the given database file. If the database exists and the application tables are present, a valid connection is returned. If not, the database is created and the application tables are created.
        Parameters:
        databaseFile - File at which to create/load the database
        readOnly - True if this connection is only used for reading.
        Returns:
        Returns a valid database connection
      • getStatement

        public static java.lang.String getStatement​(java.lang.String resourceIdentifier)
        Retrieves a SQL statement template from a resource using the given resource identifier. From this template, a PreparedStatement can be created.

        The statement is either loaded from the resource (if it is first encountered), or loaded from the cache if it has been seen before.

        Parameters:
        resourceIdentifier - Path to the resource, e.g. "create.all.sql"
        Returns:
        Returns the SQL statement read from the resource
      • getStatementInputStream

        public static java.io.InputStream getStatementInputStream​(java.lang.String resourceIdentifier)