cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From abulat...@apache.org
Subject [cayenne] branch master updated: Add logger to PropertyUtils.
Date Mon, 10 Jun 2019 14:34:22 GMT
This is an automated email from the ASF dual-hosted git repository.

abulatski pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cayenne.git


The following commit(s) were added to refs/heads/master by this push:
     new 39d6c56  Add logger to PropertyUtils.
39d6c56 is described below

commit 39d6c566b175367dc10d8ae158a12f123e3e6349
Author: Arseni Bulatski <ancarseni@gmail.com>
AuthorDate: Mon Jun 10 17:17:53 2019 +0300

    Add logger to PropertyUtils.
---
 .../main/java/org/apache/cayenne/gen/Artifact.java   |  2 +-
 .../apache/cayenne/gen/ClassGenerationAction.java    |  6 +++---
 .../apache/cayenne/gen/DefaultToolsUtilsFactory.java |  5 +++--
 .../java/org/apache/cayenne/gen/PropertyUtils.java   | 14 ++++++++++++--
 .../org/apache/cayenne/gen/ToolsUtilsFactory.java    |  4 +++-
 .../cayenne/gen/ClientSuperClassGenerationTest.java  | 12 ++++++++++--
 .../org/apache/cayenne/gen/PropertyUtilsTest.java    |  5 ++++-
 .../cayenne/gen/SingleClassGenerationTest.java       | 20 ++++++++++++++++----
 .../apache/cayenne/gen/SuperClassGenerationTest.java | 20 ++++++++++++++++----
 9 files changed, 68 insertions(+), 20 deletions(-)

diff --git a/cayenne-cgen/src/main/java/org/apache/cayenne/gen/Artifact.java b/cayenne-cgen/src/main/java/org/apache/cayenne/gen/Artifact.java
index 42a06ec..b04c9a3 100644
--- a/cayenne-cgen/src/main/java/org/apache/cayenne/gen/Artifact.java
+++ b/cayenne-cgen/src/main/java/org/apache/cayenne/gen/Artifact.java
@@ -59,7 +59,7 @@ public interface Artifact {
     /**
      * A callback method that allows each artifact to add its own special keys to the
      * context. Invoked from
-     * {@link ClassGenerationAction#resetContextForArtifactTemplate(Artifact, TemplateType)},
+     * {@link ClassGenerationAction#resetContextForArtifactTemplate(Artifact)},
      * after the context is initialized by code generator, so this method can use
      * predefined keys from the context.
      */
diff --git a/cayenne-cgen/src/main/java/org/apache/cayenne/gen/ClassGenerationAction.java
b/cayenne-cgen/src/main/java/org/apache/cayenne/gen/ClassGenerationAction.java
index 79500ec..1363685 100644
--- a/cayenne-cgen/src/main/java/org/apache/cayenne/gen/ClassGenerationAction.java
+++ b/cayenne-cgen/src/main/java/org/apache/cayenne/gen/ClassGenerationAction.java
@@ -169,10 +169,10 @@ public class ClassGenerationAction {
 	 * VelocityContext initialization method called once per each artifact and
 	 * template type combination.
 	 */
-	void resetContextForArtifactTemplate(Artifact artifact, TemplateType templateType) {
+	void resetContextForArtifactTemplate(Artifact artifact) {
         ImportUtils importUtils = utilsFactory.createImportUtils();
         context.put(Artifact.IMPORT_UTILS_KEY, importUtils);
-		context.put(Artifact.PROPERTY_UTILS_KEY, utilsFactory.createPropertyUtils(importUtils));
+		context.put(Artifact.PROPERTY_UTILS_KEY, utilsFactory.createPropertyUtils(logger, importUtils));
 		artifact.postInitContext(context);
 	}
 
@@ -260,7 +260,7 @@ public class ClassGenerationAction {
 			try (Writer out = openWriter(type)) {
 				if (out != null) {
 
-					resetContextForArtifactTemplate(artifact, type);
+					resetContextForArtifactTemplate(artifact);
 					getTemplate(type).merge(context, out);
 				}
 			}
diff --git a/cayenne-cgen/src/main/java/org/apache/cayenne/gen/DefaultToolsUtilsFactory.java
b/cayenne-cgen/src/main/java/org/apache/cayenne/gen/DefaultToolsUtilsFactory.java
index ed8e141..57a4d93 100644
--- a/cayenne-cgen/src/main/java/org/apache/cayenne/gen/DefaultToolsUtilsFactory.java
+++ b/cayenne-cgen/src/main/java/org/apache/cayenne/gen/DefaultToolsUtilsFactory.java
@@ -24,6 +24,7 @@ import org.apache.cayenne.di.AdhocObjectFactory;
 import org.apache.cayenne.di.Inject;
 import org.apache.cayenne.gen.property.PropertyDescriptorCreator;
 import org.apache.cayenne.tools.ToolsConstants;
+import org.slf4j.Logger;
 
 /**
  * @since 4.2
@@ -42,7 +43,7 @@ public class DefaultToolsUtilsFactory implements ToolsUtilsFactory {
     }
 
     @Override
-    public PropertyUtils createPropertyUtils(ImportUtils importUtils) {
-        return new PropertyUtils(importUtils, objectFactory, propertyList);
+    public PropertyUtils createPropertyUtils(Logger logger, ImportUtils importUtils) {
+        return new PropertyUtils(importUtils, objectFactory, propertyList, logger);
     }
 }
diff --git a/cayenne-cgen/src/main/java/org/apache/cayenne/gen/PropertyUtils.java b/cayenne-cgen/src/main/java/org/apache/cayenne/gen/PropertyUtils.java
index 6d42984..dfef034 100644
--- a/cayenne-cgen/src/main/java/org/apache/cayenne/gen/PropertyUtils.java
+++ b/cayenne-cgen/src/main/java/org/apache/cayenne/gen/PropertyUtils.java
@@ -50,6 +50,7 @@ import org.apache.cayenne.map.EmbeddedAttribute;
 import org.apache.cayenne.map.ObjAttribute;
 import org.apache.cayenne.map.ObjEntity;
 import org.apache.cayenne.map.ObjRelationship;
+import org.slf4j.Logger;
 
 /**
  * @since 4.2
@@ -85,15 +86,22 @@ public class PropertyUtils {
     private List<PropertyDescriptorCreator> propertyList;
     private AdhocObjectFactory adhocObjectFactory;
 
+    private Logger logger;
+
     public PropertyUtils(ImportUtils importUtils) {
         this.importUtils = importUtils;
         this.propertyList = new ArrayList<>();
+
     }
 
-    public PropertyUtils(ImportUtils importUtils, AdhocObjectFactory adhocObjectFactory,
List<PropertyDescriptorCreator> propertyList) {
+    public PropertyUtils(ImportUtils importUtils,
+                         AdhocObjectFactory adhocObjectFactory,
+                         List<PropertyDescriptorCreator> propertyList,
+                         Logger logger) {
         this.importUtils = importUtils;
         this.adhocObjectFactory = adhocObjectFactory;
         this.propertyList = propertyList;
+        this.logger = logger;
     }
 
     public void addImportForPK(EntityUtils entityUtils) throws ClassNotFoundException {
@@ -371,7 +379,9 @@ public class PropertyUtils {
                 }
             }
         } catch (DIRuntimeException ex) {
-            System.out.println("WARN: Class not found: " + attrType + ". Will use default
PropertyDescriptor.");
+            if(logger != null) {
+                logger.warn("WARN: Class not found: " + attrType + ". Will use default PropertyDescriptor.");
+            }
             return PropertyDescriptor.defaultDescriptor();
         }
         return PropertyDescriptor.defaultDescriptor();
diff --git a/cayenne-cgen/src/main/java/org/apache/cayenne/gen/ToolsUtilsFactory.java b/cayenne-cgen/src/main/java/org/apache/cayenne/gen/ToolsUtilsFactory.java
index 512ee13..a82e4ec 100644
--- a/cayenne-cgen/src/main/java/org/apache/cayenne/gen/ToolsUtilsFactory.java
+++ b/cayenne-cgen/src/main/java/org/apache/cayenne/gen/ToolsUtilsFactory.java
@@ -18,6 +18,8 @@
  ****************************************************************/
 package org.apache.cayenne.gen;
 
+import org.slf4j.Logger;
+
 /**
  * @since 4.2
  */
@@ -25,5 +27,5 @@ public interface ToolsUtilsFactory {
 
     ImportUtils createImportUtils();
 
-    PropertyUtils createPropertyUtils(ImportUtils importUtils);
+    PropertyUtils createPropertyUtils(Logger logger, ImportUtils importUtils);
 }
diff --git a/cayenne-cgen/src/test/java/org/apache/cayenne/gen/ClientSuperClassGenerationTest.java
b/cayenne-cgen/src/test/java/org/apache/cayenne/gen/ClientSuperClassGenerationTest.java
index 543e11f..a37d69b 100644
--- a/cayenne-cgen/src/test/java/org/apache/cayenne/gen/ClientSuperClassGenerationTest.java
+++ b/cayenne-cgen/src/test/java/org/apache/cayenne/gen/ClientSuperClassGenerationTest.java
@@ -24,12 +24,16 @@ import org.apache.cayenne.map.ObjEntity;
 import org.apache.cayenne.map.ObjRelationship;
 import org.apache.velocity.VelocityContext;
 import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
 
 public class ClientSuperClassGenerationTest extends ClassGenerationCase {
 
+    Logger logger = LoggerFactory.getLogger(ClientSuperClassGenerationTest.class);
+
     @Test
     public void testNotContainsPropertyImport() throws Exception {
         ObjEntity objEntity = new ObjEntity("TEST1");
@@ -53,7 +57,9 @@ public class ClientSuperClassGenerationTest extends ClassGenerationCase
{
         context.put(Artifact.OBJECT_KEY, objEntity);
         context.put(Artifact.IMPORT_UTILS_KEY, importUtils);
         context.put(Artifact.STRING_UTILS_KEY, StringUtils.getInstance());
-        context.put(Artifact.PROPERTY_UTILS_KEY, getInjector().getInstance(ToolsUtilsFactory.class).createPropertyUtils(importUtils));
+        context.put(Artifact.PROPERTY_UTILS_KEY,
+                getInjector().getInstance(ToolsUtilsFactory.class)
+                        .createPropertyUtils(logger, importUtils));
 
         String res = renderTemplate(ClientClassGenerationAction.SUPERCLASS_TEMPLATE, context);
         assertTrue(res.contains("org.apache.cayenne.exp.property.NumericProperty"));
@@ -91,7 +97,9 @@ public class ClientSuperClassGenerationTest extends ClassGenerationCase
{
         context.put(Artifact.OBJECT_KEY, objEntity);
         context.put(Artifact.IMPORT_UTILS_KEY, importUtils);
         context.put(Artifact.STRING_UTILS_KEY, StringUtils.getInstance());
-        context.put(Artifact.PROPERTY_UTILS_KEY, getInjector().getInstance(ToolsUtilsFactory.class).createPropertyUtils(importUtils));
+        context.put(Artifact.PROPERTY_UTILS_KEY,
+                getInjector().getInstance(ToolsUtilsFactory.class)
+                        .createPropertyUtils(logger, importUtils));
 
         String res = renderTemplate(ClientClassGenerationAction.SUPERCLASS_TEMPLATE, context);
         assertTrue(res.contains("org.apache.cayenne.exp.property.NumericProperty"));
diff --git a/cayenne-cgen/src/test/java/org/apache/cayenne/gen/PropertyUtilsTest.java b/cayenne-cgen/src/test/java/org/apache/cayenne/gen/PropertyUtilsTest.java
index cfe5508..7b75365 100644
--- a/cayenne-cgen/src/test/java/org/apache/cayenne/gen/PropertyUtilsTest.java
+++ b/cayenne-cgen/src/test/java/org/apache/cayenne/gen/PropertyUtilsTest.java
@@ -44,6 +44,8 @@ import org.apache.cayenne.map.ObjEntity;
 import org.apache.cayenne.map.ObjRelationship;
 import org.junit.Before;
 import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import static org.junit.Assert.assertEquals;
 import static org.mockito.ArgumentMatchers.anyString;
@@ -57,6 +59,7 @@ public class PropertyUtilsTest {
 
     PropertyUtils propertyUtils;
     ImportUtils importUtils;
+    Logger logger = LoggerFactory.getLogger(PropertyUtilsTest.class);
 
     @Before
     public void setup() {
@@ -68,7 +71,7 @@ public class PropertyUtilsTest {
                         ServerModule.contributeUserTypes(binder)
                                 .add(new TimestampType()))
                 .getInstance(ToolsUtilsFactory.class)
-                .createPropertyUtils(importUtils);
+                .createPropertyUtils(logger, importUtils);
     }
 
     @Test
diff --git a/cayenne-cgen/src/test/java/org/apache/cayenne/gen/SingleClassGenerationTest.java
b/cayenne-cgen/src/test/java/org/apache/cayenne/gen/SingleClassGenerationTest.java
index bb85218..202ee62 100644
--- a/cayenne-cgen/src/test/java/org/apache/cayenne/gen/SingleClassGenerationTest.java
+++ b/cayenne-cgen/src/test/java/org/apache/cayenne/gen/SingleClassGenerationTest.java
@@ -24,12 +24,16 @@ import org.apache.cayenne.map.ObjEntity;
 import org.apache.cayenne.map.ObjRelationship;
 import org.apache.velocity.VelocityContext;
 import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
 
 public class SingleClassGenerationTest extends ClassGenerationCase {
 
+    Logger logger = LoggerFactory.getLogger(SingleClassGenerationTest.class);
+
     @Test
     public void testNotContainsPropertyImport() throws Exception {
         ObjEntity objEntity = new ObjEntity("TEST1");
@@ -39,7 +43,9 @@ public class SingleClassGenerationTest extends ClassGenerationCase {
         context.put(Artifact.OBJECT_KEY, objEntity);
         context.put(Artifact.IMPORT_UTILS_KEY, importUtils);
         context.put(Artifact.STRING_UTILS_KEY, StringUtils.getInstance());
-        context.put(Artifact.PROPERTY_UTILS_KEY, getInjector().getInstance(ToolsUtilsFactory.class).createPropertyUtils(importUtils));
+        context.put(Artifact.PROPERTY_UTILS_KEY,
+                getInjector().getInstance(ToolsUtilsFactory.class)
+                        .createPropertyUtils(logger, importUtils));
 
         String res = renderTemplate(ClassGenerationAction.SINGLE_CLASS_TEMPLATE, context);
         assertFalse(res.contains("org.apache.cayenne.exp.property.NumericProperty"));
@@ -58,7 +64,9 @@ public class SingleClassGenerationTest extends ClassGenerationCase {
         context.put(Artifact.OBJECT_KEY, objEntity);
         context.put(Artifact.IMPORT_UTILS_KEY, importUtils);
         context.put(Artifact.STRING_UTILS_KEY, StringUtils.getInstance());
-        context.put(Artifact.PROPERTY_UTILS_KEY, getInjector().getInstance(ToolsUtilsFactory.class).createPropertyUtils(importUtils));
+        context.put(Artifact.PROPERTY_UTILS_KEY,
+                getInjector().getInstance(ToolsUtilsFactory.class)
+                        .createPropertyUtils(logger, importUtils));
 
         String res = renderTemplate(ClassGenerationAction.SINGLE_CLASS_TEMPLATE, context);
         assertTrue(res.contains("org.apache.cayenne.exp.property.NumericProperty"));
@@ -76,7 +84,9 @@ public class SingleClassGenerationTest extends ClassGenerationCase {
         context.put(Artifact.OBJECT_KEY, objEntity);
         context.put(Artifact.IMPORT_UTILS_KEY, importUtils);
         context.put(Artifact.STRING_UTILS_KEY, StringUtils.getInstance());
-        context.put(Artifact.PROPERTY_UTILS_KEY, getInjector().getInstance(ToolsUtilsFactory.class).createPropertyUtils(importUtils));
+        context.put(Artifact.PROPERTY_UTILS_KEY,
+                getInjector().getInstance(ToolsUtilsFactory.class)
+                        .createPropertyUtils(logger, importUtils));
 
         String res = renderTemplate(ClassGenerationAction.SINGLE_CLASS_TEMPLATE, context);
         assertFalse(res.contains("org.apache.cayenne.exp.property.NumericProperty"));
@@ -99,7 +109,9 @@ public class SingleClassGenerationTest extends ClassGenerationCase {
         context.put(Artifact.OBJECT_KEY, objEntity);
         context.put(Artifact.IMPORT_UTILS_KEY, importUtils);
         context.put(Artifact.STRING_UTILS_KEY, StringUtils.getInstance());
-        context.put(Artifact.PROPERTY_UTILS_KEY, getInjector().getInstance(ToolsUtilsFactory.class).createPropertyUtils(importUtils));
+        context.put(Artifact.PROPERTY_UTILS_KEY,
+                getInjector().getInstance(ToolsUtilsFactory.class)
+                        .createPropertyUtils(logger, importUtils));
 
         String res = renderTemplate(ClassGenerationAction.SINGLE_CLASS_TEMPLATE, context);
         assertTrue(res.contains("org.apache.cayenne.exp.property.NumericProperty"));
diff --git a/cayenne-cgen/src/test/java/org/apache/cayenne/gen/SuperClassGenerationTest.java
b/cayenne-cgen/src/test/java/org/apache/cayenne/gen/SuperClassGenerationTest.java
index a81be6a..ca72518 100644
--- a/cayenne-cgen/src/test/java/org/apache/cayenne/gen/SuperClassGenerationTest.java
+++ b/cayenne-cgen/src/test/java/org/apache/cayenne/gen/SuperClassGenerationTest.java
@@ -26,12 +26,16 @@ import org.apache.cayenne.map.ObjEntity;
 import org.apache.cayenne.map.ObjRelationship;
 import org.apache.velocity.VelocityContext;
 import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
 
 public class SuperClassGenerationTest extends ClassGenerationCase {
 
+    Logger logger = LoggerFactory.getLogger(SuperClassGenerationTest.class);
+
     @Test
     public void testNotContainsPropertyImport() throws Exception {
         ObjEntity objEntity = new ObjEntity("TEST1");
@@ -41,7 +45,9 @@ public class SuperClassGenerationTest extends ClassGenerationCase {
         context.put(Artifact.OBJECT_KEY, objEntity);
         context.put(Artifact.IMPORT_UTILS_KEY, importUtils);
         context.put(Artifact.STRING_UTILS_KEY, StringUtils.getInstance());
-        context.put(Artifact.PROPERTY_UTILS_KEY, getInjector().getInstance(ToolsUtilsFactory.class).createPropertyUtils(importUtils));
+        context.put(Artifact.PROPERTY_UTILS_KEY,
+                getInjector().getInstance(ToolsUtilsFactory.class)
+                        .createPropertyUtils(logger, importUtils));
 
         String res = renderTemplate(ClassGenerationAction.SUPERCLASS_TEMPLATE, context);
         assertFalse(res.contains(NumericProperty.class.getName()));
@@ -60,7 +66,9 @@ public class SuperClassGenerationTest extends ClassGenerationCase {
         context.put(Artifact.OBJECT_KEY, objEntity);
         context.put(Artifact.IMPORT_UTILS_KEY, importUtils);
         context.put(Artifact.STRING_UTILS_KEY, StringUtils.getInstance());
-        context.put(Artifact.PROPERTY_UTILS_KEY, getInjector().getInstance(ToolsUtilsFactory.class).createPropertyUtils(importUtils));
+        context.put(Artifact.PROPERTY_UTILS_KEY,
+                getInjector().getInstance(ToolsUtilsFactory.class)
+                        .createPropertyUtils(logger, importUtils));
 
         String res = renderTemplate(ClassGenerationAction.SUPERCLASS_TEMPLATE, context);
         assertTrue(res.contains(NumericProperty.class.getName()));
@@ -78,7 +86,9 @@ public class SuperClassGenerationTest extends ClassGenerationCase {
         context.put(Artifact.OBJECT_KEY, objEntity);
         context.put(Artifact.IMPORT_UTILS_KEY, importUtils);
         context.put(Artifact.STRING_UTILS_KEY, StringUtils.getInstance());
-        context.put(Artifact.PROPERTY_UTILS_KEY, getInjector().getInstance(ToolsUtilsFactory.class).createPropertyUtils(importUtils));
+        context.put(Artifact.PROPERTY_UTILS_KEY,
+                getInjector().getInstance(ToolsUtilsFactory.class)
+                        .createPropertyUtils(logger, importUtils));
 
         String res = renderTemplate(ClassGenerationAction.SUPERCLASS_TEMPLATE, context);
         assertFalse(res.contains(NumericProperty.class.getName()));
@@ -102,7 +112,9 @@ public class SuperClassGenerationTest extends ClassGenerationCase {
         context.put(Artifact.OBJECT_KEY, objEntity);
         context.put(Artifact.IMPORT_UTILS_KEY, importUtils);
         context.put(Artifact.STRING_UTILS_KEY, StringUtils.getInstance());
-        context.put(Artifact.PROPERTY_UTILS_KEY, getInjector().getInstance(ToolsUtilsFactory.class).createPropertyUtils(importUtils));
+        context.put(Artifact.PROPERTY_UTILS_KEY,
+                getInjector().getInstance(ToolsUtilsFactory.class)
+                        .createPropertyUtils(logger, importUtils));
 
         String res = renderTemplate(ClassGenerationAction.SUPERCLASS_TEMPLATE, context);
         assertTrue(res.contains(NumericProperty.class.getName()));


Mime
View raw message