A Java-based library management system that implements the DAO (Data Access Object) pattern to manage books, members, and borrowing records. The system uses PostgreSQL for data persistence and follows clean code principles with a clear separation of concerns.
assessment/src/main/java/com/week2assessment/
├── Main.java # Application entry point
├── LibraryManagementSystem.java # Business logic layer
├── LibraryUI.java # User interface layer
├── LibraryManagement.java # Entity definitions (Book, Member, BorrowingRecords)
├── BookDAO.java # Book Data Access Interface
├── BookDAOImpl.java # Book Data Access Implementation
├── MemberDAO.java # Member Data Access Interface
├── MemberDAOImpl.java # Member Data Access Implementation
├── BorrowingRecordsDAO.java # Borrowing Records Data Access Interface
└── BorrowingRecordsDAOImpl.java # Borrowing Records Data Access Implementation
The application follows several key design principles:
-
DAO Pattern
- Separates data persistence logic from business logic
- Each entity (Book, Member, BorrowingRecords) has its own DAO interface and implementation
- Makes the system flexible for different storage implementations
-
Separation of Concerns
- UI Layer (
LibraryUI.java): Handles all user interactions - Business Layer (
LibraryManagementSystem.java): Contains business logic and orchestrates operations - Data Access Layer (DAOs): Manages database operations
- Entity Layer (
LibraryManagement.java): Defines data models
- UI Layer (
-
Clean Code Principles
- Single Responsibility Principle: Each class has a specific purpose
- Interface Segregation: Separate interfaces for different entities
- Dependency Injection: DAOs are injected into the LibraryManagementSystem
-
Transaction Management
- Proper handling of database transactions
- Rollback support for failed operations
- Connection management using try-with-resources
- Book Management (Add, Update, Delete, View)
- Member Management (Add, Update, Delete, View)
- Borrowing System
- Borrow books with return date
- Return books
- View borrowing history
- Input Validation
- Error Handling
- Transaction Management
- Java 17 or higher
- PostgreSQL 12 or higher
- Maven
docker run -it --rm --network postgres postgres:17.2 psql -h postgres -U daniel;
-
Create a PostgreSQL database named 'daniel'
-
Update the database connection details in
Main.java:String connectionString = "jdbc:postgresql://localhost:5432/daniel"; String user = "daniel"; String password = "password";
-
Create the required tables:
CREATE TABLE books ( id SERIAL PRIMARY KEY, title VARCHAR(255) NOT NULL, author VARCHAR(255) NOT NULL, genre VARCHAR(100), available_copies INT NOT NULL ); CREATE TABLE members ( id SERIAL PRIMARY KEY, name VARCHAR(255) NOT NULL, email VARCHAR(255) UNIQUE NOT NULL, phone VARCHAR(20) ); CREATE TABLE borrowing_records ( record_id SERIAL PRIMARY KEY, book_id INT REFERENCES books(id), member_id INT REFERENCES members(id), borrow_date DATE NOT NULL, return_date DATE, FOREIGN KEY (book_id) REFERENCES books(id), FOREIGN KEY (member_id) REFERENCES members(id) );
-
Clone the repository:
git clone <repository-url> cd library-management-system
-
Build the project using Maven:
mvn clean install
-
Run the application:
mvn exec:java -Dexec.mainClass="com.week2assessment.Main"
The system presents a menu-driven interface with the following options:
- Add Book
- Update Book
- Delete Book
- View All Books
- Add Member
- Update Member
- Delete Member
- View All Members
- Borrow Book
- Return Book
- View Borrowing Records
- Exit
Follow the on-screen prompts to perform various operations.
The system includes comprehensive error handling for:
- Database connection issues
- Invalid input
- Business rule violations
- Transaction failures
- Resource management
- Fork the repository
- Create your feature branch
- Commit your changes
- Push to the branch
- Create a new Pull Request