Easy JDBC is a library built to facilitate the use of JDBC for data persistence in Java projects.
Latest version of the library: 1.8-beta
How to incorporate into your project?
Incorporate using Maven:
<dependency> <groupId>com.github.tadeuespindolapalermo.easyjdbc</groupId> <artifactId>easy-jdbc</artifactId> <version>1.8-beta</version> </dependency>
Incorporate using Gradle:
implementation 'com.github.tadeuespindolapalermo.easyjdbc:easy-jdbc:1.8-beta'
Main links:
MVN Repository:
https://mvnrepository.com/artifact/com.github.tadeuespindolapalermo.easyjdbc/easy-jdbc
Sonatype:
https://search.maven.org/artifact/com.github.tadeuespindolapalermo.easyjdbc/easy-jdbc
Video presentation of the library at the event FLISOL DF 2020 (02/05/2020):
https://www.youtube.com/watch?v=Vg-VT86z65Q
Source code used to present the library at the FLISOL event:
https://github.com/tadeuespindolapalermo/flisol-easyjdbc
Be part of this project reporting bug's or becoming a committer!
Support this project and be part of the Easy JDBC community!
Send e-mail to tadeupalermoti@gmail.com and make your request!
PRODUCT SEQUENCER - PostgreSQL
CREATE SEQUENCE public.product_sequence INCREMENT 1 START 1 MINVALUE 1 MAXVALUE 9223372036854775807 CACHE 1;
PRODUCT TABLE - PostgreSQL
CREATE TABLE public.tb_product ( id bigint NOT NULL DEFAULT nextval('product_sequence'::regclass), desc_product character varying COLLATE pg_catalog."default" NOT NULL, amt bigint NOT NULL, value numeric NOT NULL, CONSTRAINT product_pkey PRIMARY KEY (id) )
PRODUCT ENTITY - PERSISTENT CLASS
import com.github.tadeuespindolapalermo.easyjdbc.annotation.ColumnConfig; import com.github.tadeuespindolapalermo.easyjdbc.annotation.Identifier; import com.github.tadeuespindolapalermo.easyjdbc.annotation.NotColumn; import com.github.tadeuespindolapalermo.easyjdbc.annotation.PersistentClassNamed; @PersistentClassNamed("tb_product") public class Product { private Long id; @ColumnConfig(columnName = "desc_product") private String name; private double value; @ColumnConfig(columnName = "amt") private int amount; @NotColumn private boolean bestSeller; public Product() { } public Product(String name, double value, int amount) { this.name = name; this.value = value; this.amount = amount; } @Identifier(autoIncrement = true) public Long getId() { return id; } public void setId(Long id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public double getValue() { return value; } public void setValue(double value) { this.value = value; } public int getAmount() { return amount; } public void setAmount(int amount) { this.amount = amount; } @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((id == null) ? 0 : id.hashCode()); return result; } @Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; Product other = (Product) obj; if (id == null) { if (other.id != null) return false; } else if (!id.equals(other.id)) return false; return true; } @Override public String toString() { return "Product - id: " + id + " | name: " + name + " | value: " + value + " | amount: " + amount; } }
OPERATIONS WITH THE PRODUCT ENTITY
import java.util.List; import com.github.tadeuespindolapalermo.easyjdbc.connection.InfoConnection; import com.github.tadeuespindolapalermo.easyjdbc.crud.CrudEntity; import com.github.tadeuespindolapalermo.easyjdbc.enumeration.EnumDatabase; import br.com.productregistration.model.Product; public class Main { public static void main(String[] args) throws Exception { toConnect(); CrudEntity<Product> crudEntity = new CrudEntity<>(Product.class); crudEntity.save(createProduct("Product A", 400.0, 30)); crudEntity.save(createProduct("Product B", 800.5, 45)); crudEntity.save(createProduct("Product C", 1900.3, 02)); crudEntity.save(createProduct("Product D", 50.1, 15)); Product product = crudEntity.searchById(1L); product.setName("Product A Update"); crudEntity.update(product); List<Product> products = crudEntity.getAll(); products.forEach(System.out::println); crudEntity.deleteById(2L); crudEntity.search("select * from tb_product").forEach(System.out::println); } private static void toConnect() { InfoConnection.setDatabase(EnumDatabase.POSTGRE); InfoConnection.setNameDatabase("product-registration"); InfoConnection.setUser("your-user-db"); InfoConnection.setPassword("your-password-db"); } private static Product createProduct(String name, double value, int amount) { return new Product(name, value, amount); } }
Output result:
22:44:02,729 INFO -> Connection successful!
Bank: POSTGRE
Database: product-registration
Product - id: 2 | name: Product B | value: 800.5 | amount: 45
Product - id: 3 | name: Product C | value: 1900.3 | amount: 2
Product - id: 4 | name: Product D | value: 50.1 | amount: 15
Product - id: 1 | name: Product A Update | value: 400.0 | amount: 30
Product - id: 3 | name: Product C | value: 1900.3 | amount: 2
Product - id: 4 | name: Product D | value: 50.1 | amount: 15
Product - id: 1 | name: Product A Update | value: 400.0 | amount: 30
PEOPLE SEQUENCER - PostgreSQL
CREATE SEQUENCE public.people_sequence INCREMENT 1 START 1 MINVALUE 1 MAXVALUE 9223372036854775807 CACHE 1;
PEOPLE TABLE - PostgreSQL
CREATE TABLE public.people ( id bigint NOT NULL DEFAULT nextval('people_sequence'::regclass), name character varying COLLATE pg_catalog."default" NOT NULL, age bigint NOT NULL, CONSTRAINT people_pkey PRIMARY KEY (id) )
PEOPLE ENTITY - PERSISTENT CLASS
import com.github.tadeuespindolapalermo.easyjdbc.annotation.Identifier; import com.github.tadeuespindolapalermo.easyjdbc.annotation.PersistentClass; @PersistentClass public class People { private Long id; private String name; private int age; public People() { } public People(String name, int age) { this.name = name; this.age = age; } @Identifier(autoIncrement = true) public Long getId() { return id; } public void setId(Long id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } }
OPERATIONS WITH THE PEOPLE ENTITY
import java.util.List; import com.github.tadeuespindolapalermo.easyjdbc.connection.InfoConnection; import com.github.tadeuespindolapalermo.easyjdbc.crud.CrudEntity; import com.github.tadeuespindolapalermo.easyjdbc.enumeration.EnumDatabase; import br.com.peopleregistration.model.People; public class Main { public static void main(String[] args) throws Exception { toConnect(); CrudEntity<People> crudEntity = new CrudEntity<>(People.class); crudEntity.save(createPeople("Tadeu", 35)); crudEntity.save(createPeople("Joseph", 95)); printPeople(crudEntity.getAll()); } private static void toConnect() { InfoConnection.setDatabase(EnumDatabase.POSTGRE); InfoConnection.setNameDatabase("people-registration"); InfoConnection.setUser("your-user-db"); InfoConnection.setPassword("your-password-db"); } private static People createPeople(String name, int age) { return new People(name, age); } private static void printPeople(List<People> peoples) { peoples.forEach(p -> System.out.println("Name: " + p.getName() + " - Age: " + p.getAge())); } }
Output result:
14:38:31,597 INFO -> Connection successful!
Bank: POSTGRE
Database: people-registration
Name: Tadeu - Age: 35
Name: Joseph - Age: 95
PEOPLE SEQUENCER - PostgreSQL
CREATE SEQUENCE public.user_sequence INCREMENT 1 START 1 MINVALUE 1 MAXVALUE 9223372036854775807 CACHE 1;
USER TABLE - PostgreSQL
CREATE TABLE public.tb_user ( id bigint NOT NULL DEFAULT nextval('user_sequence'::regclass), name character varying COLLATE pg_catalog."default" NOT NULL, email character varying COLLATE pg_catalog."default" NOT NULL, password character varying COLLATE pg_catalog."default" NOT NULL, phone character varying COLLATE pg_catalog."default" NOT NULL, children bigint NOT NULL, CONSTRAINT user_pkey PRIMARY KEY (id) )
OPERATIONS WITH THE USER TABLE
import java.util.HashMap; import java.util.Map; import com.github.tadeuespindolapalermo.easyjdbc.connection.InfoConnection; import com.github.tadeuespindolapalermo.easyjdbc.crud.Crud; import com.github.tadeuespindolapalermo.easyjdbc.enumeration.EnumDatabase; public class Main { public static void main(String[] args) throws Exception { toConnect(); Crud crud = new Crud(); crud.save(createColumnsAndValues(), "tb_user"); crud.save(createColumnsAndValues(), "tb_user"); crud.save(createColumnsAndValues(), "tb_user"); crud.update(updateColumnsAndValues(), clauseColumnAndValue(), "tb_user"); crud.delete("tb_user", "id", 3); } private static void toConnect() { InfoConnection.setDatabase(EnumDatabase.POSTGRE); InfoConnection.setNameDatabase("user-registration"); InfoConnection.setUser("your-user-db"); InfoConnection.setPassword("your-password-db"); } private static Map<String, Object> createColumnsAndValues() { Map<String, Object> columnsAndValues = new HashMap<>(); columnsAndValues.put("name", "User Pool"); columnsAndValues.put("email", "user@user.com"); columnsAndValues.put("password", "123"); columnsAndValues.put("phone", "96521456"); columnsAndValues.put("children", 3); return columnsAndValues; } private static Map<String, Object> clauseColumnAndValue() { Map<String, Object> columnsAndValues = new HashMap<>(); columnsAndValues.put("id", 2); return columnsAndValues; } private static Map<String, Object> updateColumnsAndValues() { Map<String, Object> columnsAndValues = new HashMap<>(); columnsAndValues.put("name", "User Pool Update"); columnsAndValues.put("email", "userupdate@userupdate.com"); columnsAndValues.put("password", "123update"); columnsAndValues.put("phone", "96521456000"); columnsAndValues.put("children", 6); return columnsAndValues; } }
Output result:
20:00:35,570 INFO -> Connection successful!
Bank: POSTGRE
Database: user-registration