Package tk.airshipcraft.commonlib.db
package tk.airshipcraft.commonlib.db
Provides classes for database operations within the AirshipCraft plugin framework.
It includes models for entity representation, DAOs for data manipulation, and utilities
for managing database connections and table schemas.
DAO Interfaces:
Define contracts for CRUD operations on specific models:
AuthDataDao
- Access and modify authentication data.UserDao
- Retrieve and manage user information.WarningDao
- Handle warnings issued to users.
DAO Implementations:
Provide SQL-based implementations of the DAO interfaces:
SqlAuthDataDao
- Implements AuthDataDao with SQL operations.SqlUserDao
- Implements UserDao for SQL databases.SqlWarningDao
- Manages Warning records in an SQL context.
Model Classes:
Represent entities within the database:
AuthData
- Stores authentication-related information.User
- Represents a user in the system.Warning
- Tracks warnings assigned to users.
Utility Classes:
Facilitate database configuration and connection pooling:
DatabaseConfig
- Manages database settings for connection setup.SqlConnectionManager
- Handles pooled connections for efficient database access.ITableConfiguration
- Interface for defining table schemas and migrations.TableManager
- Registers and initializes plugin-specific tables in the database.
Core Interfaces:
Define a generic template for DAOs:
GenericDao
- Generic interface for CRUD operations applicable to all models.
Example Usage:
// Initialize DatabaseConfig with connection details
DatabaseConfig dbConfig = new DatabaseConfig();
dbConfig.loadFromFile("db.properties");
// Set up connection pooling with HikariCP
SqlConnectionManager connectionManager = new SqlConnectionManager(dbConfig);
// Register table configurations for plugin-specific tables
TableManager tableManager = new TableManager(connectionManager);
tableManager.registerPluginTableConfiguration(new PluginTableConfig());
tableManager.setupPluginTables();
// Use DAO to interact with the database
UserDao userDao = new SqlUserDao(connectionManager);
User user = userDao.findById(userId).orElseThrow();
user.setUsername("newUsername");
userDao.update(user);
The above usage demonstrates initializing the database connection, registering table configurations, setting up plugin-specific tables, and performing CRUD operations using a DAO. This encapsulates data access within well-defined interfaces and implementations, promoting clean, maintainable, and scalable code.
- Since:
- 2024-01-06
- Version:
- 1.0.0
- Author:
- notzune
-
ClassDescriptionManages database configuration settings, providing methods to load from external sources and to access individual configuration properties.GenericDao<T,
ID> The GenericDao interface defines the standard CRUD operations to be performed on a model object.The ITableConfiguration interface specifies the methods that must be implemented to define the SQL table creation and migration commands for a plugin.Manages SQL database connections using HikariCP for connection pooling.The TableManager class manages the creation and updating of database tables for various plugins using the CommonLib library.