Skip to content

A small library with CRUD operations in mind using OOP, genercis, lambda functions, streams, anonymous classes...you can find more info if you will close the repo :P

Notifications You must be signed in to change notification settings

valentinsoare/BooksLibraryWithCRUDInMind

Repository files navigation

📚 BooksLibraryWithCRUDInMind

with create, read, update, delete operations and several flavors of them


▶️ Small library applications interacting with a MysQL application within a docker container on port 3306 using only JDBC driver, no framework, from the Java standard point of view.

▶️ When developing these methods around CRUD principles I followed the Data Access Object Generic Interface (where I defined the methods) and the template method pattern from the Gang of Four design patterns. and SOLID design principles. Also there is a way in the code when I extend a generic class using anonymous classes in order to be able to define an object which in the class is a generic one T.

▶️ In the source code you can see that there are two ways of writing a method, the naive way without design patterns implemented and the one with all things necessary in order to be able to test the code and function properly.

▶️ More information will be down bellow.

personal_branding

Technologies and concepts:

  1. OOP Principles (composition, inheritance, polymorphism, abstraction);
  2. Data Structures - Array, Deque, ArrayList, LinkedList;
  3. Third Party Libraries - Lombok and JDBC;
  4. Generic, anonymous classes. An anonymous class was made to extend a generic one;
  5. Optional class and Comparable in order to be able to avoid null pointer and to compare objects, Book object;
  6. SOLID design principles and template method pattern;
  7. Docker and MySQL 8.0;
  8. Fedora 38;

Project is 💯 completed!


👉 Here are the CRUD methods defined in the Data Access Object generic interface.

DataAccessObjectGenericInterfaceMethods


👉 This is the generic abstract class QueryTemplate that extends the ConnectionToDb to easily access the open/close connection and getConnection methods.

QueryTemplateClass


👉 For the link with DB we have an abstract class that is extended by various classes where we need the connection.

ConnectionToDB


👉 With BookDAO we implement those CRUD operations, naive way is the first version which it's difficult to make tests for and the second one where I followed design pattern and SOLID principles in order to have a better build. With this class we extend the generic QueryTemplate one with an anonymous class.

BookDAO


🧑‍💻 How To Set Up:

  1. Clone the repo: git clone https://github.com/valentinsoare/LibraryWithCRUDInMind.git

  2. Ensure that you have Docker and Docker-compose installed/

  3. Make sure that you have the YML file called docker-compose.yml, and it is written to deploy the Mysql Server.

    • Docker file:
     version: '3.8'
    
     networks:
     default:
    
     services:
     db:
     image: mysql:8.0
     container_name: library
     ports:
     - 3306:3306
     volumes:
       - "./.data/db:/var/lib/mysql"
       environment:
       MYSQL_ROOT_PASSWORD: "XXXXX"
       MYSQL_DATABASE: "library_db"
  4. Then please run docker-compose up -d in order to fetch the Mysql Server and deploy it. Then you can connect to it.

Note

It is recommended you modify the docker-compose.yml file but only the user and password for DB.

💻 Dependencies and plugins for Maven

✅ For the pom.xml file we only have two dependencies (Lombok and JDBC) and
the necessary plugins for build (jar make) and download dependencies sources and documentation automatically.

  1. Dependencies
<dependencies>
    <!-- LOMBOK -->
    <dependency>
      <groupId>org.projectlombok</groupId>
      <artifactId>lombok</artifactId>
      <version>1.18.28</version>
      <scope>provided</scope>
    </dependency>


    <!-- JDBC Driver for MySQL -->
    <dependency>
      <groupId>com.mysql</groupId>
      <artifactId>mysql-connector-j</artifactId>
      <version>8.1.0</version>
    </dependency>

  </dependencies>
  1. Plugins
<plugins>
        <!--_________________________________________________________________________________________________________-->
        <!--Used to build JAR with dependencies inside....with command # mvn compile assembly:single-->

        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-assembly-plugin</artifactId>
          <configuration>
            <archive>
              <manifest>
                <addClasspath>true</addClasspath>
                <mainClass>org.clibankinjava.App</mainClass>
              </manifest>
            </archive>
            <descriptorRefs>
              <descriptorRef>jar-with-dependencies</descriptorRef>
            </descriptorRefs>
          </configuration>
          <executions>
            <execution>
              <id>make-my-jar-with-dependencies</id>
              <phase>package</phase>
              <goals>
                <goal>single</goal>
              </goals>
            </execution>
          </executions>
        </plugin>

        <!--        To Download sources and documentation automatically-->
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-dependency-plugin</artifactId>
          <version>3.1.2</version>
          <executions>
            <execution>
              <goals>
                <goal>sources</goal>
                <goal>resolve</goal>
              </goals>
              <configuration>
                <classifier>javadoc</classifier>
              </configuration>
            </execution>
          </executions>
        </plugin>

        <!--_________________________________________________________________________________________________________-->
</plugins>

Statistics

HitCount

Social buttons

valentinsoare - LibraryWithCRUDInMind stars - LibraryWithCRUDInMind forks - LibraryWithCRUDInMind

Repo metadata

GitHub tag

License

Released under MIT by @valentinsoare 📫 Contact me