Giter Site home page Giter Site logo

valentinsoare / bookslibrarywithcrudinmind Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 45 KB

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

Home Page: https://moviesondemand.io

Java 100.00%
anonymousclass crud-application generics lambdas singleton-pattern streams template-method-pattern docker docker-compose mysql prepared-statements sql state-management

bookslibrarywithcrudinmind's Introduction

๐Ÿ“š 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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.