Skip to content

Persistence

Fredrik Jonathan Marjoni edited this page Apr 23, 2026 · 15 revisions

Database Structure


image

Persistence in this project is achieved using an H2 database, which stores donation history and user accounts.

Users

CREATE TABLE IF NOT EXISTS
users (
user_id INT PRIMARY KEY,
role VARCHAR(32) NOT NULL,
first_name VARCHAR(32) NOT NULL,
last_name VARCHAR(32) NOT NULL,
email VARCHAR(32) NOT NULL,
password_hash VARCHAR(72) NOT NULL
);

This table contains information about each user, and is accessed by the DbWrapper's importUsers() method and modified with exportUsers(List<Object[]> data).

Donations

CREATE TABLE IF NOT EXISTS
donations (
donation_id INT PRIMARY KEY,
user_id INT NOT NULL,
organization_id INT NOT NULL,
amount DECIMAL(32, 16) NOT NULL,
dating TIMESTAMP NOT NULL,
payment_method VARCHAR(32) NOT NULL,
CONSTRAINT fk_user
FOREIGN KEY (user_id)
REFERENCES users(user_id)
);

This table contains information about each donation, and is accessed by the DbWrapper's fetchAllDonations() and importDonations(int user_id) methods, and modified by the exportDonations(List<Object[]> data) method. The table contains a foreign key user_id, which connects to the user table's primary key of the same name.

DbWrapper

This class functions as a wrapper around the database and manages interaction with the user and the donation table.