This repository has been archived by the owner on May 31, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #40 from hardingadonis/vuong-code-base
- Loading branch information
Showing
22 changed files
with
661 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
src/main/java/io/hardingadonis/saledock/dao/ICategoryDAO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package io.hardingadonis.saledock.dao; | ||
|
||
import io.hardingadonis.saledock.model.*; | ||
|
||
public interface ICategoryDAO extends IDAO<Category> { | ||
} |
6 changes: 6 additions & 0 deletions
6
src/main/java/io/hardingadonis/saledock/dao/ICustomerDAO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package io.hardingadonis.saledock.dao; | ||
|
||
import io.hardingadonis.saledock.model.*; | ||
|
||
public interface ICustomerDAO extends IDAO<Customer> { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package io.hardingadonis.saledock.dao; | ||
|
||
import java.util.*; | ||
|
||
public interface IDAO<T> { | ||
|
||
public void add(T obj); | ||
|
||
public Optional<T> getByID(Integer ID); | ||
|
||
public List<T> getAll(); | ||
|
||
void update(T obj); | ||
} |
6 changes: 6 additions & 0 deletions
6
src/main/java/io/hardingadonis/saledock/dao/IEmployeeDAO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package io.hardingadonis.saledock.dao; | ||
|
||
import io.hardingadonis.saledock.model.*; | ||
|
||
public interface IEmployeeDAO extends IDAO<Employee> { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package io.hardingadonis.saledock.dao; | ||
|
||
import io.hardingadonis.saledock.model.*; | ||
|
||
public interface IOrderDAO extends IDAO<Order> { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package io.hardingadonis.saledock.dao; | ||
|
||
import io.hardingadonis.saledock.model.*; | ||
|
||
public interface IProductDAO extends IDAO<Product> { | ||
} |
48 changes: 48 additions & 0 deletions
48
src/main/java/io/hardingadonis/saledock/dao/impl/CategoryDAOImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package io.hardingadonis.saledock.dao.impl; | ||
|
||
import io.hardingadonis.saledock.dao.*; | ||
import io.hardingadonis.saledock.model.*; | ||
import io.hardingadonis.saledock.utils.*; | ||
import java.util.*; | ||
import org.hibernate.*; | ||
|
||
public class CategoryDAOImpl implements ICategoryDAO { | ||
|
||
private final SessionFactory sessionFactory; | ||
|
||
public CategoryDAOImpl() { | ||
this.sessionFactory = HibernateUtil.getSessionFactory(); | ||
} | ||
|
||
@Override | ||
public void add(Category obj) { | ||
try (Session session = sessionFactory.openSession()) { | ||
session.beginTransaction(); | ||
session.persist(obj); | ||
session.getTransaction().commit(); | ||
} | ||
} | ||
|
||
@Override | ||
public Optional<Category> getByID(Integer ID) { | ||
try (Session session = sessionFactory.openSession()) { | ||
return Optional.ofNullable(session.get(Category.class, ID)); | ||
} | ||
} | ||
|
||
@Override | ||
public List<Category> getAll() { | ||
try (Session session = sessionFactory.openSession()) { | ||
return session.createQuery("FROM Category", Category.class).getResultList(); | ||
} | ||
} | ||
|
||
@Override | ||
public void update(Category obj) { | ||
try (Session session = sessionFactory.openSession()) { | ||
session.beginTransaction(); | ||
session.merge(obj); | ||
session.getTransaction().commit(); | ||
} | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
src/main/java/io/hardingadonis/saledock/dao/impl/CustomerDAOImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package io.hardingadonis.saledock.dao.impl; | ||
|
||
import io.hardingadonis.saledock.dao.*; | ||
import io.hardingadonis.saledock.model.*; | ||
import io.hardingadonis.saledock.utils.*; | ||
import java.util.*; | ||
import org.hibernate.*; | ||
|
||
public class CustomerDAOImpl implements ICustomerDAO { | ||
|
||
private final SessionFactory sessionFactory; | ||
|
||
public CustomerDAOImpl() { | ||
this.sessionFactory = HibernateUtil.getSessionFactory(); | ||
} | ||
|
||
@Override | ||
public void add(Customer obj) { | ||
try (Session session = sessionFactory.openSession()) { | ||
session.beginTransaction(); | ||
session.persist(obj); | ||
session.getTransaction().commit(); | ||
} | ||
} | ||
|
||
@Override | ||
public Optional<Customer> getByID(Integer ID) { | ||
try (Session session = sessionFactory.openSession()) { | ||
return Optional.ofNullable(session.get(Customer.class, ID)); | ||
} | ||
} | ||
|
||
@Override | ||
public List<Customer> getAll() { | ||
try (Session session = sessionFactory.openSession()) { | ||
return session.createQuery("FROM Customer", Customer.class).getResultList(); | ||
} | ||
} | ||
|
||
@Override | ||
public void update(Customer obj) { | ||
try (Session session = sessionFactory.openSession()) { | ||
session.beginTransaction(); | ||
session.merge(obj); | ||
session.getTransaction().commit(); | ||
} | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
src/main/java/io/hardingadonis/saledock/dao/impl/EmployeeDAOImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package io.hardingadonis.saledock.dao.impl; | ||
|
||
import io.hardingadonis.saledock.dao.*; | ||
import io.hardingadonis.saledock.model.*; | ||
import io.hardingadonis.saledock.utils.*; | ||
import java.util.*; | ||
import org.hibernate.*; | ||
|
||
public class EmployeeDAOImpl implements IEmployeeDAO { | ||
|
||
private final SessionFactory sessionFactory; | ||
|
||
public EmployeeDAOImpl() { | ||
this.sessionFactory = HibernateUtil.getSessionFactory(); | ||
} | ||
|
||
@Override | ||
public void add(Employee obj) { | ||
try (Session session = sessionFactory.openSession()) { | ||
session.beginTransaction(); | ||
session.persist(obj); | ||
session.getTransaction().commit(); | ||
} | ||
} | ||
|
||
@Override | ||
public Optional<Employee> getByID(Integer ID) { | ||
try (Session session = sessionFactory.openSession()) { | ||
return Optional.ofNullable(session.get(Employee.class, ID)); | ||
} | ||
} | ||
|
||
@Override | ||
public List<Employee> getAll() { | ||
try (Session session = sessionFactory.openSession()) { | ||
return session.createQuery("FROM Employee", Employee.class).getResultList(); | ||
} | ||
} | ||
|
||
@Override | ||
public void update(Employee obj) { | ||
try (Session session = sessionFactory.openSession()) { | ||
session.beginTransaction(); | ||
session.merge(obj); | ||
session.getTransaction().commit(); | ||
} | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
src/main/java/io/hardingadonis/saledock/dao/impl/OrderDAOImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package io.hardingadonis.saledock.dao.impl; | ||
|
||
import io.hardingadonis.saledock.dao.*; | ||
import io.hardingadonis.saledock.model.*; | ||
import io.hardingadonis.saledock.utils.*; | ||
import java.util.*; | ||
import org.hibernate.*; | ||
|
||
public class OrderDAOImpl implements IOrderDAO { | ||
|
||
private final SessionFactory sessionFactory; | ||
|
||
public OrderDAOImpl() { | ||
this.sessionFactory = HibernateUtil.getSessionFactory(); | ||
} | ||
|
||
@Override | ||
public void add(Order obj) { | ||
try (Session session = sessionFactory.openSession()) { | ||
session.beginTransaction(); | ||
session.persist(obj); | ||
session.getTransaction().commit(); | ||
} | ||
} | ||
|
||
@Override | ||
public Optional<Order> getByID(Integer ID) { | ||
try (Session session = sessionFactory.openSession()) { | ||
return Optional.ofNullable(session.get(Order.class, ID)); | ||
} | ||
} | ||
|
||
@Override | ||
public List<Order> getAll() { | ||
try (Session session = sessionFactory.openSession()) { | ||
return session.createQuery("FROM Order", Order.class).getResultList(); | ||
} | ||
} | ||
|
||
@Override | ||
public void update(Order obj) { | ||
try (Session session = sessionFactory.openSession()) { | ||
session.beginTransaction(); | ||
session.merge(obj); | ||
session.getTransaction().commit(); | ||
} | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
src/main/java/io/hardingadonis/saledock/dao/impl/ProductDAOImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package io.hardingadonis.saledock.dao.impl; | ||
|
||
import io.hardingadonis.saledock.dao.*; | ||
import io.hardingadonis.saledock.model.*; | ||
import io.hardingadonis.saledock.utils.*; | ||
import java.util.*; | ||
import org.hibernate.*; | ||
|
||
public class ProductDAOImpl implements IProductDAO { | ||
|
||
private final SessionFactory sessionFactory; | ||
|
||
public ProductDAOImpl() { | ||
this.sessionFactory = HibernateUtil.getSessionFactory(); | ||
} | ||
|
||
@Override | ||
public void add(Product obj) { | ||
try (Session session = sessionFactory.openSession()) { | ||
session.beginTransaction(); | ||
session.persist(obj); | ||
session.getTransaction().commit(); | ||
} | ||
} | ||
|
||
@Override | ||
public Optional<Product> getByID(Integer ID) { | ||
try (Session session = sessionFactory.openSession()) { | ||
return Optional.ofNullable(session.get(Product.class, ID)); | ||
} | ||
} | ||
|
||
@Override | ||
public List<Product> getAll() { | ||
try (Session session = sessionFactory.openSession()) { | ||
return session.createQuery("FROM Product", Product.class).getResultList(); | ||
} | ||
} | ||
|
||
@Override | ||
public void update(Product obj) { | ||
try (Session session = sessionFactory.openSession()) { | ||
session.beginTransaction(); | ||
session.merge(obj); | ||
session.getTransaction().commit(); | ||
} | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
src/main/java/io/hardingadonis/saledock/model/Category.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package io.hardingadonis.saledock.model; | ||
|
||
import jakarta.persistence.*; | ||
import java.time.*; | ||
import lombok.*; | ||
|
||
@Entity(name = "Category") | ||
@Table(name = "`category`") | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
@Getter | ||
@Setter | ||
@EqualsAndHashCode | ||
@ToString | ||
public class Category { | ||
|
||
@Id | ||
@Column(name = "`id`") | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Integer ID; | ||
|
||
@Column(name = "`name`") | ||
private String name; | ||
|
||
@Column(name = "`created_at`") | ||
private LocalDateTime createdAt; | ||
|
||
@PrePersist | ||
protected void onCreate() { | ||
this.createdAt = LocalDateTime.now(ZoneId.of("Asia/Ho_Chi_Minh")); | ||
} | ||
} |
Oops, something went wrong.