Class Database


  • public final class Database
    extends java.lang.Object
    Manages the application's single file-based H2 database instance. The database file is stored in ~/.wfh-billing/data.mv.db and persists across application launches. Schema and seed scripts are run only on first launch.

    Call init() once at startup before any DAO is used. init() is idempotent — subsequent calls are no-ops. get() throws IllegalStateException if called before init().

    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static javax.sql.DataSource get()
      Returns the initialized DataSource.
      static void init()
      Initializes the file-based H2 database.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • init

        public static void init()
        Initializes the file-based H2 database. On first launch, creates the database directory and runs the schema and seed scripts. Subsequent launches skip seeding. Safe to call multiple times; only the first call has any effect.
      • get

        public static javax.sql.DataSource get()
        Returns the initialized DataSource.
        Returns:
        the application DataSource
        Throws:
        java.lang.IllegalStateException - if init() has not been called