Class SqlUserDao

java.lang.Object
tk.airshipcraft.commonlib.db.dao.impl.SqlUserDao
All Implemented Interfaces:
UserDao, GenericDao<User,UUID>

public class SqlUserDao extends Object implements UserDao

SQL implementation of the UserDao interface for accessing and manipulating user data in a database.

This class is responsible for performing CRUD operations on User entities in the database.

Since:
2023-12-27
Version:
1.0.0
Author:
notzune
  • Constructor Details

    • SqlUserDao

      public SqlUserDao(SqlConnectionManager connectionManager)
      Constructs a new SqlUserDao with a specified SqlConnectionManager.
      Parameters:
      connectionManager - The manager responsible for providing database connections.
  • Method Details

    • findById

      public Optional<User> findById(UUID id)
      Retrieves a user by their unique identifier (UUID).
      Specified by:
      findById in interface GenericDao<User,UUID>
      Parameters:
      id - The unique identifier of the user.
      Returns:
      An Optional<User> containing the user if found, otherwise empty.
    • findAll

      public List<User> findAll()
      Retrieves all users from the database.
      Specified by:
      findAll in interface GenericDao<User,UUID>
      Returns:
      A List<User> containing all users.
    • create

      public User create(User user)
      Inserts a new user into the database.
      Specified by:
      create in interface GenericDao<User,UUID>
      Parameters:
      user - The User object to insert.
      Returns:
      The User object after insertion, with any auto-generated keys filled in.
    • update

      public User update(User user)
      Updates an existing user in the database.
      Specified by:
      update in interface GenericDao<User,UUID>
      Parameters:
      user - The User object to update.
      Returns:
      The User object after it has been updated.
    • deleteById

      public void deleteById(UUID id)
      Deletes a user from the database by their UUID.
      Specified by:
      deleteById in interface GenericDao<User,UUID>
      Parameters:
      id - The UUID of the user to delete.
    • findByUsername

      public User findByUsername(String username)
      Finds a user by their username.
      Specified by:
      findByUsername in interface UserDao
      Parameters:
      username - The username to search for.
      Returns:
      The User object if found, otherwise null.