This is a simple framework that creates a relational database system and maps given classes inside packages into database tables.
This framework only works with the MySQL relational database management system.
- @Table annotation must be used over the class name to create the database table. The name of the database table is the class name.
- @PrimaryKey annotation must be used over the one instance field in the class to create the table's primary key.
- The column names of the database tables are matched to the instance field names of the class.
- Database tables can be created with only using instance variables.
- String -> VARCHAR(256)
- int -> INT
- Integer -> INT
- double -> DOUBLE(10,2)
- Double -> DOUBLE(10,2)
- BigDecimal -> DECIMAL(10,2)
- Date -> DATE
- Time -> TIME
The goal of this project was to improve the knowledge of java annotations and java reflection API.
- Java SE 11
- Apache Maven 3.8.6
- Added dependencies to pom.xml
- mysql-connector-j 8.0.31
- junit-jupiter-api 5.8.2
- junit-jupiter-engine 5.8.2
- IntelliJ IDEA
This project can be used by cloning the project to your local computer.
- Clone the project using
git clone https://github.com/PubuduJ/simple-orm-framework.git
terminal command. - Open the
pom.xml
file from IntelliJ IDEA, make sure to open this as a project. - To install this framework to local jar repository execute
mvn install
command. - Once the framework is installed in local JAR repository, it can be used with any Java project.
- Inorder to use the framework add below dependency to your Java project pom.xml file.
<dependency> <groupId>lk.ijse.dep9</groupId> <artifactId>simple-orm</artifactId> <version>1.0.2</version> </dependency>
- call the
InitializeDB.initialize()
method in the source code by passing the correct arguments. InitializeDB.initialize()
method requires host, port, database name, username, password and package list to scan as String arguments.
The scanning packages in the example are dto and entity, and tables are automatically built for the User and Student classes inside those packages.
This project was carried out under the guidance of the IJSE Direct Entry Program 9.
v1.0.2
Copyright © 2023 Pubudu Janith. All Rights Reserved.
This project is licensed under the MIT license.