stringnull-sparetime / jpa-origins

Edge of JPA History
0 stars 0 forks source link

πŸ¦–

jpaorigins-stringnull-variation. This project is my Brother's challenge to me. Lets say that I am living at the age of dinosaur, around 200BC(Before Cornedbeef) where then I need to create my OWN persistence framework without the aid of Spring Data JPA. You can normally compare this from an ORM framework Hibernate, SQLAlchemy, Active Record, Doctrine ORM ... and more.

Protest? this is not a full-pledge framework. These demonstrate advance technique such as dynamic proxy, invocation handling, reflection, annotation processing and query generation.

Getting Started
//add dependency to your pom.xml
<dependency>
     <groupId>org.stringnull</groupId>
     <artifactId>jpaorigins-stringnull-variation</artifactId>
     <version>1.0-SNAPSHOT</version>
</dependency>

//Create file "stringnull.properties under root/Resource/
jpaorigins.url=jdbc:postgresql://localhost:5432/dbname
jpaorigins.username=dbusername
jpaorigins.password=dbpassword

//Run our framework from your main application. 
StringnullFramework.build(YourProjectMain.class)

//This will automatically build your database configuration(limited to PostgreSQL).
//Resource file stringnull.properties load the neccessary fields 
//to a connector class org.stringnull.core.database.DatabaseManager

---------------------------------------------------------------------------
OUTPUT
---------------------------------------------------------------------------
πŸ†‚πŸ†ƒπŸ†πŸ…ΈπŸ…½πŸ…ΆπŸ…½πŸ†„πŸ…»πŸ…» - πŸ…΅πŸ†πŸ…°πŸ…ΌπŸ…΄πŸ††πŸ…ΎπŸ†πŸ…Ί
:::::: πŸ¦– ::::::   obtaining PostgreSQL configuration properties
:::::: πŸ¦– ::::::   database url jdbc:postgresql://localhost:5432/xjpa-test
:::::: πŸ¦– ::::::   starting connection ....
:::::: πŸ¦– ::::::   database connection open
:::::: πŸ¦– ::::::   Successfully connected!
Setting up Entity
//add this to the stringnull.properties
//this will drop and create schema
jpaorigins.schema=auto-create

//From your entity class e.g Student 
//add our annotation our framework will generate schema for us. 

@JPAOriginsTable(name = "Students") //responsible for handling table properties
public class Student {
    @JPAOriginsID //determining the primary key also added as SERIAL (for now)
    @JPAOriginsColumn(name = "id") // dont forget to add this annotation which allow the framework to evaluate and generate valid table column and type.
    private int id;

    @JPAOriginsColumn()
    private String name;
}

---------------------------------------------------------------------------
OUTPUT
---------------------------------------------------------------------------
πŸ†‚πŸ†ƒπŸ†πŸ…ΈπŸ…½πŸ…ΆπŸ…½πŸ†„πŸ…»πŸ…» - πŸ…΅πŸ†πŸ…°πŸ…ΌπŸ…΄πŸ††πŸ…ΎπŸ†πŸ…Ί
:::::: πŸ¦– ::::::   obtaining PostgreSQL configuration properties
:::::: πŸ¦– ::::::   database url jdbc:postgresql://localhost:5432/xjpa-test
:::::: πŸ¦– ::::::   startitng connection ....
:::::: πŸ¦– ::::::   database connection open
:::::: πŸ¦– ::::::   Successfully connected!
:::::: πŸ¦– ::::::   starting schema creator...
:::::: πŸ¦– ::::::   βœ”οΈtable dropped -> Students
:::::: πŸ¦– ::::::   βœ”οΈcreated table -> CREATE TABLE Students( id SERIAL PRIMARY KEY, name VARCHAR);
Using repository
JPAOriginsCRUDRepository<T, ID>
- use this class for standard operation 'findById' 'save' 'delete' 'update'

Example Usage

JPAOriginsFactory factory = new JPAOriginsFactory();
JPAOriginsCrudRepository<Student, Integer> studentRepository = factory.build(Student.class);
Student s = studentRepository.findById(1);
Processors

Utility that automatically created builder pattern to our entity.

@BuilderProperty
- this annotation generates a BuilderPattern for your entity.