Skip to content

Persistence

Lukas Celius edited this page Apr 9, 2026 · 1 revision

This project uses a local database solution by SQLite.

Structure:

  • The Database class is responsible for two things: initializing the database on startup, and providing connections for queries. These are two separate operations.
  • It has a static block that runs automatically the first time the class is used. This block reads schema.sql and creates the tables if they don't already exist.
  • All DAO classes call Database.getConnection() whenever they need to interact with the database. The connection opens, the query runs, and the connection closes. This happens for every single operation.
  • The DAOs act as the only layer that communicates with the database. Services and controllers never access the database directly, always through a DAO. There are Dao classes for each model object/class that needs to communicate with the database.
  • On application startup, testdata.sql is loaded via the init() method in the GUI class, inserting example users and donations. Using INSERT OR IGNORE makes this safe to run every time the application starts.
  • Organization data is fetched through "InnsamlingsKontrollonClient", which is a API that contains verified organizations. The organizations are then added to the database in init() method, when the application i launched.

Reasoning: This solution is used mainly in relation to course curriculum, and an easier implementation, rather than creating and connecting a external database. The local database solutions matches the groups current knowledge, and works well for the project.

Clone this wiki locally