[LIB-9] Some domain classes improvements
authorgotty <gotty@hedgecode.org>
Thu, 20 Dec 2018 16:10:16 +0000 (19:10 +0300)
committergotty <gotty@hedgecode.org>
Thu, 20 Dec 2018 16:10:16 +0000 (19:10 +0300)
chesshog-db-etude/src/main/java/org/hedgecode/chess/domain/Author.java
chesshog-db-etude/src/main/java/org/hedgecode/chess/domain/DomainObject.java
chesshog-db-etude/src/main/java/org/hedgecode/chess/domain/Etude.java
chesshog-db-etude/src/main/java/org/hedgecode/chess/domain/EtudeType.java

index 7aab668..7d5fd08 100644 (file)
@@ -56,15 +56,15 @@ import javax.persistence.TemporalType;
                 query = "select a from Author a where a.birthdate = :birthdate"
         )
 })
-public class Author extends DomainObject {
+public class Author extends DomainObject<Author> {
 
     public static final String FIND_ALL = "Author.findAll";
     public static final String FIND_BY_ID = "Author.findById";
     public static final String FIND_BY_NAME = "Author.findByName";
     public static final String FIND_BY_BIRTHDATE = "Author.findByBirthDate";
 
-    public static final String NAME_PROPERTY = "name";
-    public static final String BIRTHDATE_PROPERTY = "birthdate";
+    public static final String NAME_PARAMETER = "name";
+    public static final String BIRTHDATE_PARAMETER = "birthdate";
 
     @Id
     @Column(
@@ -117,4 +117,9 @@ public class Author extends DomainObject {
         return target;
     }
 
+    @Override
+    public Long getId() {
+        return id;
+    }
+
 }
index 923e4f5..4bef7a1 100644 (file)
@@ -21,8 +21,25 @@ package org.hedgecode.chess.domain;
  *
  * @author Dmitry Samoshin aka gotty
  */
-public abstract class DomainObject {
+public abstract class DomainObject<DomainObjectType extends DomainObject> {
 
-    public static final String ID_PROPERTY = "id";
+    public static final String ID_PARAMETER = "id";
+
+    public abstract Long getId();
+
+    public boolean isIdentical(DomainObjectType another) {
+        if (another == null)
+            return false;
+
+        if ((getId() == null) != (another.getId() == null))
+            return false;
+
+        if ((getId() == null) && (another.getId() == null))
+            return true;
+
+        return getId().equals(
+                another.getId()
+        );
+    }
 
 }
index eccbd44..eb601af 100644 (file)
@@ -72,7 +72,7 @@ import org.hedgecode.chess.position.Position;
                 query = "select e from Etude e where e.blob = :blob"
         )
 })
-public class Etude extends DomainObject {
+public class Etude extends DomainObject<Etude> {
 
     public static final String FIND_ALL = "Etude.findAll";
     public static final String FIND_BY_ID = "Etude.findById";
@@ -81,10 +81,10 @@ public class Etude extends DomainObject {
     public static final String FIND_BY_AUTHOR = "Etude.findByAuthor";
     public static final String FIND_BY_BLOB = "Etude.findByBlob";
 
-    public static final String HASH_PROPERTY = "hash";
-    public static final String TYPE_PROPERTY = "type";
-    public static final String AUTHOR_PROPERTY = "author";
-    public static final String BLOB_PROPERTY = "blob";
+    public static final String HASH_PARAMETER = "hash";
+    public static final String TYPE_PARAMETER = "type";
+    public static final String AUTHOR_PARAMETER = "author";
+    public static final String BLOB_PARAMETER = "blob";
 
     @Id
     @Column(
@@ -197,4 +197,9 @@ public class Etude extends DomainObject {
         return position;
     }
 
+    @Override
+    public Long getId() {
+        return id;
+    }
+
 }
index a9de8aa..e717fe5 100644 (file)
@@ -48,13 +48,13 @@ import javax.persistence.Table;
                 query = "select et from EtudeType et where et.brief = :brief"
         )
 })
-public class EtudeType extends DomainObject {
+public class EtudeType extends DomainObject<EtudeType> {
 
     public static final String FIND_ALL = "EtudeType.findAll";
     public static final String FIND_BY_ID = "EtudeType.findById";
     public static final String FIND_BY_BRIEF = "EtudeType.findByBrief";
 
-    public static final String BRIEF_PROPERTY = "brief";
+    public static final String BRIEF_PARAMETER = "brief";
 
     @Id
     @Column(
@@ -89,4 +89,9 @@ public class EtudeType extends DomainObject {
         return target;
     }
 
+    @Override
+    public Long getId() {
+        return id;
+    }
+
 }