Skip to content

Commit dadcc04

Browse files
Identity Field Pattern
1 parent dc6b31a commit dadcc04

File tree

6 files changed

+58
-53
lines changed

6 files changed

+58
-53
lines changed

Identity_Field/pom.xml

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131

3232
<artifactId>Identity_Field</artifactId>
3333

34+
3435
<properties>
3536
<maven.compiler.source>17</maven.compiler.source>
3637
<maven.compiler.target>17</maven.compiler.target>
@@ -39,27 +40,23 @@
3940
<dependencies>
4041
<dependency>
4142
<groupId>org.junit.jupiter</groupId>
42-
<artifactId>junit-jupiter-api</artifactId>
43+
<artifactId>junit-jupiter-engine</artifactId>
4344
<scope>test</scope>
4445
</dependency>
45-
<dependency>
46-
<groupId>com.iluwatar</groupId>
47-
<artifactId>update-method</artifactId>
48-
<version>1.26.0-SNAPSHOT</version>
49-
<scope>compile</scope>
50-
</dependency>
5146
<dependency>
5247
<groupId>com.fasterxml.jackson.core</groupId>
5348
<artifactId>jackson-annotations</artifactId>
5449
</dependency>
5550

56-
<dependency>
57-
<groupId>org.hibernate</groupId>
58-
<artifactId>hibernate-core</artifactId>
59-
</dependency>
51+
6052
<dependency>
6153
<groupId>jakarta.persistence</groupId>
6254
<artifactId>jakarta.persistence-api</artifactId>
55+
<version>3.1.0</version>
56+
</dependency>
57+
<dependency>
58+
<groupId>javax.persistence</groupId>
59+
<artifactId>javax.persistence-api</artifactId>
6360
</dependency>
6461
</dependencies>
6562

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
1+
/*
2+
* The Book class represents a book entity in the application.
3+
*
4+
* <p>This class extends DomainObject and inherits its unique identifier.
5+
* It includes additional fields and methods specific to a book's attributes,
6+
* such as title and author.</p>
7+
*/
18
package com.iluwater.fieild;
9+
import lombok.Getter;
10+
import lombok.Setter;
211

12+
@Setter
13+
@Getter
314
public class Book extends DomainObject {
415
private String title;
516
private String author;
@@ -10,19 +21,4 @@ public Book(String title, String author) {
1021
this.author = author;
1122
}
1223

13-
public String getTitle() {
14-
return title;
15-
}
16-
17-
public void setTitle(String title) {
18-
this.title = title;
19-
}
20-
21-
public String getAuthor() {
22-
return author;
23-
}
24-
25-
public void setAuthor(String author) {
26-
this.author = author;
27-
}
2824
}
Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,17 @@
11
package com.iluwater.fieild;
22

3+
import lombok.Getter;
4+
import lombok.Setter;
5+
6+
@Setter
7+
@Getter
38
public class Client extends DomainObject{
49
private String name;
510
private String Email;
611

7-
812
public Client(String name,String Email) {
913
this.name = name;
10-
this.Email=Email;
11-
}
12-
13-
public void setEmail(String email) {
14-
Email = email;
15-
}
16-
17-
public String getName() {
18-
return name;
19-
}
20-
21-
public void setName(String name) {
22-
this.name = name;
23-
}
24-
25-
public String getEmail() {
26-
return Email;
14+
this.Email = Email;
2715
}
2816

2917
}
Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,25 @@
1-
package com.iluwater.fieild;
21

3-
import javax.persistence.Id;
2+
/*
3+
* The DomainObject class provides a base for domain entities
4+
* that require unique identification within the application.
5+
*
6+
* <p>All child classes inherit the unique identifier field
7+
* and associated functionality.</p>
8+
*/
9+
package com.iluwater.fieild;
410
import javax.persistence.GeneratedValue;
511
import javax.persistence.GenerationType;
12+
import javax.persistence.Id;
613
import javax.persistence.MappedSuperclass;
14+
import lombok.Getter;
15+
import lombok.Setter;
16+
@Getter
17+
@Setter
718
@MappedSuperclass
819
public abstract class DomainObject {
9-
@lombok.Setter
10-
@lombok.Getter
11-
@Id
12-
@GeneratedValue(strategy = GenerationType.IDENTITY) // automatically generate unique values for primary key columns
13-
//strategy = GenerationType.IDENTITY generate the primary key value by the database itself using the auto-increment column option
14-
private Integer id;
20+
@Id
21+
@GeneratedValue(strategy = GenerationType.IDENTITY) // automatically generate unique values for primary key columns
22+
//strategy = GenerationType.IDENTITY generate the primary key value by the database itself using the auto-increment column option
23+
private Integer id;
1524

1625
}

Identity_Field/src/test/java/com/iluwater/fieild/BookTest.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,15 @@ void checkTwoIdsNotEqual()
1717
Book book2= new Book("Head first","someone");
1818
assertNotEquals(book.getId(),book2.getId());
1919
}
20+
void checkTitleNotNull()
21+
{
22+
Book book= new Book("Design patterns","someone");
23+
assertNotNull(book.getTitle());
24+
}
25+
void checkAuthorNotNull()
26+
{
27+
Book book= new Book("Design patterns","someone");
28+
assertNotNull(book.getAuthor());
29+
}
2030

2131
}

Identity_Field/src/test/java/com/iluwater/fieild/ClientTest.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
class ClientTest {
66
void checkIdNotNull()
77
{
8-
Client client= new Client("John","jhon9201@gmail.com");
8+
Client client= new Client("John","Jhon9201@gmail.com");
99
assertNotNull(client.getId());
1010
}
1111
void checkTwoIdsNotEqual()
@@ -20,4 +20,9 @@ void checkEmails()
2020
Client client2= new Client("Sara","[email protected]");
2121
assertNotEquals(client.getEmail(),client2.getEmail());
2222
}
23+
void checkEmailNotNull()
24+
{
25+
Client client= new Client("John","[email protected]");
26+
assertNotNull(client.getEmail());
27+
}
2328
}

0 commit comments

Comments
 (0)