diff --git a/active-record/README.md b/active-record/README.md new file mode 100644 index 000000000000..7215e7de7bf2 --- /dev/null +++ b/active-record/README.md @@ -0,0 +1,30 @@ +--- # this is so-called 'YAML front matter' used to categorize the patterns and format the web pages. Fill it as follows: +title: Best Pattern Ever # the properly formatted title +category: Creational # usable categories and tags are listed here: https://github.com/iluwatar/java-design-patterns/wiki/07.-Categories-and-Tags +language: en # Provide the language in which the pattern is done. Mostly it is in English, so we would put *en* over here. +tag: +- awesome # usable categories and tags are listed here: https://github.com/iluwatar/java-design-patterns/wiki/07.-Categories-and-Tags +- blue +--- + +## Name / classification + +## Also known as + +## Intent + +## Explanation + +## Class diagram + +## Applicability + +## Tutorials + +## Known uses + +## Consequences + +## Related patterns + +## Credits \ No newline at end of file diff --git a/active-record/etc/active-record.urm.puml b/active-record/etc/active-record.urm.puml new file mode 100644 index 000000000000..5972f8095e2b --- /dev/null +++ b/active-record/etc/active-record.urm.puml @@ -0,0 +1,3 @@ +@startuml + +@enduml \ No newline at end of file diff --git a/active-record/pom.xml b/active-record/pom.xml new file mode 100644 index 000000000000..42a615e0084c --- /dev/null +++ b/active-record/pom.xml @@ -0,0 +1,56 @@ + + + 4.0.0 + + com.iluwatar + java-design-patterns + 1.26.0-SNAPSHOT + + + active-record + + + 17 + 17 + UTF-8 + + + + + org.junit.jupiter + junit-jupiter-engine + test + + + com.h2database + h2 + + + org.mockito + mockito-core + test + + + + + + org.apache.maven.plugins + maven-assembly-plugin + + + + + + com.iluwatar.dao.App + + + + + + + + + + \ No newline at end of file diff --git a/active-record/src/main/java/com/iluwatar/activerecord/Customer.java b/active-record/src/main/java/com/iluwatar/activerecord/Customer.java new file mode 100644 index 000000000000..afe08b22600a --- /dev/null +++ b/active-record/src/main/java/com/iluwatar/activerecord/Customer.java @@ -0,0 +1,37 @@ +package com.iluwatar.activerecord; + +import java.util.List; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import lombok.Setter; + +@Getter +@Setter +@RequiredArgsConstructor +@EqualsAndHashCode(onlyExplicitlyIncluded = true) +public class Customer { + + private Long id; + private String customerNumber; + private String firstName; + private String lastName; + private List orders; + + public Customer findById(Long id) { + return new Customer(); + } + + public Customer findByNumber(String customerNumber) { + return new Customer(); + } + + public List findAll() { + return List.of(); + } + + public void save(Customer customer) { + + } + +} diff --git a/active-record/src/main/java/com/iluwatar/activerecord/Order.java b/active-record/src/main/java/com/iluwatar/activerecord/Order.java new file mode 100644 index 000000000000..b149c240af8f --- /dev/null +++ b/active-record/src/main/java/com/iluwatar/activerecord/Order.java @@ -0,0 +1,18 @@ +package com.iluwatar.activerecord; + +import lombok.AllArgsConstructor; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +@Getter +@Setter +@EqualsAndHashCode(onlyExplicitlyIncluded = true) +@NoArgsConstructor +@AllArgsConstructor +public class Order { + + private Long id; + private String orderNumber; +} diff --git a/active-record/src/main/java/com/iluwatar/activerecord/RecordBase.java b/active-record/src/main/java/com/iluwatar/activerecord/RecordBase.java new file mode 100644 index 000000000000..32fcc39a0dc5 --- /dev/null +++ b/active-record/src/main/java/com/iluwatar/activerecord/RecordBase.java @@ -0,0 +1,11 @@ +package com.iluwatar.activerecord; + +import javax.sql.DataSource; +import lombok.RequiredArgsConstructor; + +@RequiredArgsConstructor +public abstract class RecordBase { + + private final DataSource dataSource; + +} diff --git a/pom.xml b/pom.xml index b6bf99140e1d..53bb2dd8a437 100644 --- a/pom.xml +++ b/pom.xml @@ -220,6 +220,7 @@ gateway slob server-session + active-record