Minor code cleanup

Project: http://git-wip-us.apache.org/repos/asf/cayenne/repo
Commit: http://git-wip-us.apache.org/repos/asf/cayenne/commit/b7189498
Tree: http://git-wip-us.apache.org/repos/asf/cayenne/tree/b7189498
Diff: http://git-wip-us.apache.org/repos/asf/cayenne/diff/b7189498

Branch: refs/heads/master
Commit: b7189498dbbee1edb11d92183223d451b0f48b11
Parents: ac25d87
Author: Nikita Timofeev <stari...@gmail.com>
Authored: Fri Feb 9 11:37:08 2018 +0300
Committer: Nikita Timofeev <stari...@gmail.com>
Committed: Fri Feb 9 11:37:08 2018 +0300

----------------------------------------------------------------------
 .../validation/DbAttributeValidator.java        |  9 +--
 .../validation/DbRelationshipValidator.java     |  9 ++-
 .../validation/DefaultProjectValidator.java     |  2 -
 .../validation/NameValidationHelper.java        |  5 +-
 .../project/validation/ObjEntityValidator.java  | 14 +----
 .../validation/ObjRelationshipValidator.java    | 65 ++++++++------------
 6 files changed, 39 insertions(+), 65 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cayenne/blob/b7189498/cayenne-project/src/main/java/org/apache/cayenne/project/validation/DbAttributeValidator.java
----------------------------------------------------------------------
diff --git 
a/cayenne-project/src/main/java/org/apache/cayenne/project/validation/DbAttributeValidator.java
 
b/cayenne-project/src/main/java/org/apache/cayenne/project/validation/DbAttributeValidator.java
index 0936cdc..ef48cc4 100644
--- 
a/cayenne-project/src/main/java/org/apache/cayenne/project/validation/DbAttributeValidator.java
+++ 
b/cayenne-project/src/main/java/org/apache/cayenne/project/validation/DbAttributeValidator.java
@@ -30,8 +30,7 @@ class DbAttributeValidator extends ConfigurationNodeValidator 
{
         // Must have name
         if (Util.isEmptyString(attribute.getName())) {
             addFailure(validationResult, attribute, "Unnamed DbAttribute");
-        }
-        else {
+        } else {
             NameValidationHelper helper = NameValidationHelper.getInstance();
             String invalidChars = 
helper.invalidCharsInDbPathComponent(attribute
                     .getName());
@@ -49,14 +48,12 @@ class DbAttributeValidator extends 
ConfigurationNodeValidator {
         // all attributes must have type
         if (attribute.getType() == TypesMapping.NOT_DEFINED) {
             addFailure(validationResult, attribute, "DbAttribute has no type");
-        }
-
-        // VARCHAR and CHAR attributes must have max length
-        else if (attribute.getMaxLength() < 0
+        } else if (attribute.getMaxLength() < 0
                 && (attribute.getType() == java.sql.Types.VARCHAR
                     || attribute.getType() == java.sql.Types.NVARCHAR
                     || attribute.getType() == java.sql.Types.CHAR
                     || attribute.getType() == java.sql.Types.NCHAR)) {
+            // VARCHAR and CHAR attributes must have max length
 
             addFailure(
                     validationResult,

http://git-wip-us.apache.org/repos/asf/cayenne/blob/b7189498/cayenne-project/src/main/java/org/apache/cayenne/project/validation/DbRelationshipValidator.java
----------------------------------------------------------------------
diff --git 
a/cayenne-project/src/main/java/org/apache/cayenne/project/validation/DbRelationshipValidator.java
 
b/cayenne-project/src/main/java/org/apache/cayenne/project/validation/DbRelationshipValidator.java
index 51d868c..68854fb 100644
--- 
a/cayenne-project/src/main/java/org/apache/cayenne/project/validation/DbRelationshipValidator.java
+++ 
b/cayenne-project/src/main/java/org/apache/cayenne/project/validation/DbRelationshipValidator.java
@@ -99,16 +99,17 @@ class DbRelationshipValidator extends 
ConfigurationNodeValidator {
     }
 
     private void checkToMany(DbRelationship relationship, ValidationResult 
validationResult) {
-        if (relationship != null && relationship.getReverseRelationship() != 
null) {
-            if (relationship.isToMany() && 
relationship.getReverseRelationship().isToMany()) {
+        if(relationship != null) {
+            if(relationship.getReverseRelationship() != null
+                    && relationship.isToMany() && 
relationship.getReverseRelationship().isToMany()) {
                 addFailure(
                         validationResult,
                         relationship,
                         "Relationship '%s' and reverse '%s' are both toMany",
                         relationship.getName(), 
relationship.getReverseRelationship().getName());
             }
+            checkTypesOfAttributesInRelationship(relationship, 
validationResult);
         }
-        checkTypesOfAttributesInRelationship(relationship, validationResult);
     }
 
     private void checkTypesOfAttributesInRelationship(DbRelationship 
relationship, ValidationResult validationResult) {
@@ -128,7 +129,6 @@ class DbRelationshipValidator extends 
ConfigurationNodeValidator {
         if (relationship.isToDependentPK()) {
             Collection<DbAttribute> attributes = 
relationship.getTargetEntity().getGeneratedAttributes();
             for (DbAttribute attribute : attributes) {
-
                 if (attribute.isGenerated()) {
                     addFailure(
                             validationResult,
@@ -136,7 +136,6 @@ class DbRelationshipValidator extends 
ConfigurationNodeValidator {
                             "'To Dep Pk' incompatible with Database-Generated 
on '%s' relationship",
                             toString(relationship));
                 }
-
             }
         }
     }

http://git-wip-us.apache.org/repos/asf/cayenne/blob/b7189498/cayenne-project/src/main/java/org/apache/cayenne/project/validation/DefaultProjectValidator.java
----------------------------------------------------------------------
diff --git 
a/cayenne-project/src/main/java/org/apache/cayenne/project/validation/DefaultProjectValidator.java
 
b/cayenne-project/src/main/java/org/apache/cayenne/project/validation/DefaultProjectValidator.java
index 3f6876f..0a2be28 100644
--- 
a/cayenne-project/src/main/java/org/apache/cayenne/project/validation/DefaultProjectValidator.java
+++ 
b/cayenne-project/src/main/java/org/apache/cayenne/project/validation/DefaultProjectValidator.java
@@ -18,8 +18,6 @@
  ****************************************************************/
 package org.apache.cayenne.project.validation;
 
-import java.util.Iterator;
-
 import org.apache.cayenne.configuration.ConfigurationNode;
 import org.apache.cayenne.configuration.ConfigurationNodeVisitor;
 import org.apache.cayenne.configuration.DataChannelDescriptor;

http://git-wip-us.apache.org/repos/asf/cayenne/blob/b7189498/cayenne-project/src/main/java/org/apache/cayenne/project/validation/NameValidationHelper.java
----------------------------------------------------------------------
diff --git 
a/cayenne-project/src/main/java/org/apache/cayenne/project/validation/NameValidationHelper.java
 
b/cayenne-project/src/main/java/org/apache/cayenne/project/validation/NameValidationHelper.java
index 49d23fd..254c580 100644
--- 
a/cayenne-project/src/main/java/org/apache/cayenne/project/validation/NameValidationHelper.java
+++ 
b/cayenne-project/src/main/java/org/apache/cayenne/project/validation/NameValidationHelper.java
@@ -153,9 +153,8 @@ public class NameValidationHelper {
     }
 
     private String validateJavaIdentifier(String id, String invalidChars) {
-        // TODO: Java spec seems to allow "$" char in identifiers... Cayenne 
expressions
-        // do
-        // not, so we should probably check for this char presence...
+        // TODO: Java spec seems to allow "$" char in identifiers...
+        // Cayenne expressions do not, so we should probably check for this 
char presence...
 
         int len = (id != null) ? id.length() : 0;
         if (len == 0) {

http://git-wip-us.apache.org/repos/asf/cayenne/blob/b7189498/cayenne-project/src/main/java/org/apache/cayenne/project/validation/ObjEntityValidator.java
----------------------------------------------------------------------
diff --git 
a/cayenne-project/src/main/java/org/apache/cayenne/project/validation/ObjEntityValidator.java
 
b/cayenne-project/src/main/java/org/apache/cayenne/project/validation/ObjEntityValidator.java
index ab9076a..5c1cc88 100644
--- 
a/cayenne-project/src/main/java/org/apache/cayenne/project/validation/ObjEntityValidator.java
+++ 
b/cayenne-project/src/main/java/org/apache/cayenne/project/validation/ObjEntityValidator.java
@@ -61,16 +61,14 @@ class ObjEntityValidator extends ConfigurationNodeValidator 
{
                     entity.getName(),
                     className,
                     invalidChars);
-        }
-        else if (helper.invalidDataObjectClass(className)) {
+        } else if (helper.invalidDataObjectClass(className)) {
             addFailure(
                     validationResult,
                     entity,
                     "Java class '%s' of ObjEntity '%s' is a reserved word",
                     className,
                     entity.getName());
-        }
-        else if (className.indexOf('.') < 0) {
+        } else if (className.indexOf('.') < 0) {
             addFailure(
                     validationResult,
                     entity,
@@ -98,8 +96,7 @@ class ObjEntityValidator extends ConfigurationNodeValidator {
                     entity.getName(),
                     superClassName,
                     invalidChars);
-        }
-        else if (helper.invalidDataObjectClass(superClassName)) {
+        } else if (helper.invalidDataObjectClass(superClassName)) {
             addFailure(
                     validationResult,
                     entity,
@@ -116,11 +113,6 @@ class ObjEntityValidator extends 
ConfigurationNodeValidator {
                     entity.getName(),
                     entity.getSuperEntityName());
         }
-
-        DataMap map = entity.getDataMap();
-        if (map == null) {
-            return;
-        }
     }
 
     void validateName(ObjEntity entity, ValidationResult validationResult) {

http://git-wip-us.apache.org/repos/asf/cayenne/blob/b7189498/cayenne-project/src/main/java/org/apache/cayenne/project/validation/ObjRelationshipValidator.java
----------------------------------------------------------------------
diff --git 
a/cayenne-project/src/main/java/org/apache/cayenne/project/validation/ObjRelationshipValidator.java
 
b/cayenne-project/src/main/java/org/apache/cayenne/project/validation/ObjRelationshipValidator.java
index b860751..733c300 100644
--- 
a/cayenne-project/src/main/java/org/apache/cayenne/project/validation/ObjRelationshipValidator.java
+++ 
b/cayenne-project/src/main/java/org/apache/cayenne/project/validation/ObjRelationshipValidator.java
@@ -36,17 +36,14 @@ class ObjRelationshipValidator extends 
ConfigurationNodeValidator {
 
         if (Util.isEmptyString(relationship.getName())) {
             addFailure(validationResult, relationship, "Unnamed 
ObjRelationship");
-        }
-
-        // check if there are attributes having the same name
-        else if 
(relationship.getSourceEntity().getAttribute(relationship.getName()) != null) {
+        } else if 
(relationship.getSourceEntity().getAttribute(relationship.getName()) != null) {
+            // check if there are attributes having the same name
             addFailure(
                     validationResult,
                     relationship,
                     "ObjRelationship '%s' has the same name as one of 
ObjAttributes",
                     toString(relationship));
-        }
-        else {
+        } else {
             NameValidationHelper helper = NameValidationHelper.getInstance();
             String invalidChars = 
helper.invalidCharsInObjPathComponent(relationship
                     .getName());
@@ -58,8 +55,7 @@ class ObjRelationshipValidator extends 
ConfigurationNodeValidator {
                         "ObjRelationship name '%s' contains invalid 
characters: %s",
                         toString(relationship),
                         invalidChars);
-            }
-            else if (helper.invalidDataObjectProperty(relationship.getName())) 
{
+            } else if 
(helper.invalidDataObjectProperty(relationship.getName())) {
                 addFailure(
                         validationResult,
                         relationship,
@@ -74,8 +70,7 @@ class ObjRelationshipValidator extends 
ConfigurationNodeValidator {
                     relationship,
                     "ObjRelationship '%s' has no target entity",
                     toString(relationship));
-        }
-        else {
+        } else {
 
             // check for missing DbRelationship mappings
             List<DbRelationship> dbRels = relationship.getDbRelationships();
@@ -85,12 +80,9 @@ class ObjRelationshipValidator extends 
ConfigurationNodeValidator {
                         relationship,
                         "ObjRelationship '%s' has no DbRelationship mapping",
                         toString(relationship));
-            }
-            else {
-                DbEntity expectedSrc = ((ObjEntity) 
relationship.getSourceEntity())
-                        .getDbEntity();
-                DbEntity expectedTarget = ((ObjEntity) 
relationship.getTargetEntity())
-                        .getDbEntity();
+            } else {
+                DbEntity expectedSrc = 
relationship.getSourceEntity().getDbEntity();
+                DbEntity expectedTarget = 
relationship.getTargetEntity().getDbEntity();
 
                 if ((dbRels.get(0)).getSourceEntity() != expectedSrc
                         || (dbRels.get(dbRels.size() - 1)).getTargetEntity() 
!= expectedTarget) {
@@ -135,7 +127,7 @@ class ObjRelationshipValidator extends 
ConfigurationNodeValidator {
         }
 
         // check for relationships with same source and target entities
-        ObjEntity entity = (ObjEntity) relationship.getSourceEntity();
+        ObjEntity entity = relationship.getSourceEntity();
         for (ObjRelationship rel : entity.getRelationships()) {
             if (relationship.getDbRelationshipPath() != null && 
relationship.getDbRelationshipPath().equals(rel.getDbRelationshipPath())) {
                 if (relationship != rel &&
@@ -171,8 +163,7 @@ class ObjRelationshipValidator extends 
ConfigurationNodeValidator {
      * Per CAY-1813, make sure two (or more) ObjRelationships do not map to the
      * same database path.
      */
-    private void checkForDuplicates(ObjRelationship  relationship,
-                                    ValidationResult validationResult) {
+    private void checkForDuplicates(ObjRelationship  relationship, 
ValidationResult validationResult) {
         if (relationship                       != null &&
             relationship.getName()             != null &&
             relationship.getTargetEntityName() != null) {
@@ -182,25 +173,23 @@ class ObjRelationshipValidator extends 
ConfigurationNodeValidator {
                        "." +
                        relationship.getDbRelationshipPath();
 
-            if (dbRelationshipPath != null) {
-                ObjEntity entity = (ObjEntity) relationship.getSourceEntity();
-
-                for (ObjRelationship comparisonRelationship : 
entity.getRelationships()) {
-                    if (relationship != comparisonRelationship) {
-                        String comparisonDbRelationshipPath =
-                                   
comparisonRelationship.getTargetEntityName() +
-                                   "." +
-                                   
comparisonRelationship.getDbRelationshipPath();
-
-                        if 
(dbRelationshipPath.equals(comparisonDbRelationshipPath)) {
-                            addFailure(validationResult,
-                                       relationship,
-                                       "ObjEntity '%s' contains a duplicate 
ObjRelationship mapping ('%s' -> '%s')",
-                                       entity.getName(),
-                                       relationship.getName(),
-                                       dbRelationshipPath);
-                            return; // Duplicate found, stop.
-                        }
+            ObjEntity entity = relationship.getSourceEntity();
+
+            for (ObjRelationship comparisonRelationship : 
entity.getRelationships()) {
+                if (relationship != comparisonRelationship) {
+                    String comparisonDbRelationshipPath =
+                               comparisonRelationship.getTargetEntityName() +
+                               "." +
+                               comparisonRelationship.getDbRelationshipPath();
+
+                    if 
(dbRelationshipPath.equals(comparisonDbRelationshipPath)) {
+                        addFailure(validationResult,
+                                   relationship,
+                                   "ObjEntity '%s' contains a duplicate 
ObjRelationship mapping ('%s' -> '%s')",
+                                   entity.getName(),
+                                   relationship.getName(),
+                                   dbRelationshipPath);
+                        return; // Duplicate found, stop.
                     }
                 }
             }

Reply via email to