cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From abulat...@apache.org
Subject [cayenne] 01/02: CAY-2568 Class Generation: Superclass Package setting persistence
Date Wed, 24 Apr 2019 11:55:39 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

commit 305611267b9bdb6870b3d3f794341f277c6f2d8a
Author: Arseni Bulatski <ancarseni@gmail.com>
AuthorDate: Wed Apr 24 13:17:24 2019 +0300

    CAY-2568 Class Generation: Superclass Package setting persistence
---
 RELEASE-NOTES.txt                                  |  1 +
 .../apache/cayenne/gen/ClassGenerationAction.java  |  2 +-
 .../apache/cayenne/gen/xml/CgenConfigHandler.java  | 21 ++++++++++++----
 .../org/apache/cayenne/schema/10/cgen.xsd          |  1 +
 .../src/test/resources/cgen/testCgen.map.xml       |  1 +
 .../editor/cgen/CodeGeneratorController.java       |  7 +++---
 .../modeler/editor/cgen/CustomModeController.java  |  1 +
 .../modeler/editor/cgen/CustomModePanel.java       | 29 +++++++++++++++++++---
 8 files changed, 51 insertions(+), 12 deletions(-)

diff --git a/RELEASE-NOTES.txt b/RELEASE-NOTES.txt
index 357de43..f0aacf0 100644
--- a/RELEASE-NOTES.txt
+++ b/RELEASE-NOTES.txt
@@ -29,6 +29,7 @@ CAY-2543 Move ResultSetMapping generation from metadata to translator
 CAY-2549 Modeler: Redesign ObjAttribute editor dialog
 CAY-2555 Use explicit ArcId in GraphChangeHandler methods
 CAY-2563 Deprecate old scalarQuery methods in SQLSelect
+CAY-2568 Class Generation: Superclass Package setting persistence
 
 Bug Fixes:
 
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 e149b34..b52fe42 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
@@ -145,7 +145,7 @@ public class ClassGenerationAction {
         String superClassName = SUPERCLASS_PREFIX + stringUtils.stripPackageName(qualifiedClassName);
 
         String superPackageName = cgenConfiguration.getSuperPkg();
-        if (superPackageName == null) {
+        if (superPackageName == null || superPackageName.isEmpty()) {
             superPackageName = packageName + ".auto";
         }
 
diff --git a/cayenne-cgen/src/main/java/org/apache/cayenne/gen/xml/CgenConfigHandler.java
b/cayenne-cgen/src/main/java/org/apache/cayenne/gen/xml/CgenConfigHandler.java
index c73e24b..612ffb4 100644
--- a/cayenne-cgen/src/main/java/org/apache/cayenne/gen/xml/CgenConfigHandler.java
+++ b/cayenne-cgen/src/main/java/org/apache/cayenne/gen/xml/CgenConfigHandler.java
@@ -18,6 +18,11 @@
  ****************************************************************/
 package org.apache.cayenne.gen.xml;
 
+import java.net.URL;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+
 import org.apache.cayenne.configuration.xml.DataChannelMetaData;
 import org.apache.cayenne.configuration.xml.NamespaceAwareNestedTagHandler;
 import org.apache.cayenne.gen.CgenConfiguration;
@@ -25,11 +30,6 @@ import org.apache.cayenne.map.DataMap;
 import org.xml.sax.Attributes;
 import org.xml.sax.SAXException;
 
-import java.net.URL;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.nio.file.Paths;
-
 /**
  * @since 4.1
  */
@@ -50,6 +50,7 @@ public class CgenConfigHandler extends NamespaceAwareNestedTagHandler{
     private static final String EXCLUDE_EMBEDDABLES_TAG = "excludeEmbeddables";
     private static final String CREATE_PK_PROPERTIES = "createPKProperties";
     private static final String CLIENT_TAG = "client";
+    private static final String SUPER_PKG_TAG = "superPkg";
 
     public static final String TRUE = "true";
 
@@ -115,6 +116,9 @@ public class CgenConfigHandler extends NamespaceAwareNestedTagHandler{
             case CLIENT_TAG:
                 createClient(data);
                 break;
+            case SUPER_PKG_TAG:
+                createSuperPkg(data);
+                break;
         }
     }
 
@@ -236,6 +240,13 @@ public class CgenConfigHandler extends NamespaceAwareNestedTagHandler{
         }
     }
 
+    private void createSuperPkg(String data) {
+        if(data.trim().length() == 0) {
+            return;
+        }
+        configuration.setSuperPkg(data);
+    }
+
     private void createConfig() {
         loaderContext.addDataMapListener(dataMap -> {
             configuration.setDataMap(dataMap);
diff --git a/cayenne-server/src/main/resources/org/apache/cayenne/schema/10/cgen.xsd b/cayenne-server/src/main/resources/org/apache/cayenne/schema/10/cgen.xsd
index 7b26e92..b24afb9 100644
--- a/cayenne-server/src/main/resources/org/apache/cayenne/schema/10/cgen.xsd
+++ b/cayenne-server/src/main/resources/org/apache/cayenne/schema/10/cgen.xsd
@@ -38,6 +38,7 @@
                     <xs:element name="usePkgPath" minOccurs="0" type="xs:boolean"/>
                     <xs:element name="overwrite" minOccurs="0" type="xs:boolean"/>
                     <xs:element name="createPropertyNames" minOccurs="0" type="xs:boolean"/>
+                    <xs:element name="superPkg" minOccurs="0" type="xs:string"/>
                     <xs:element name="createPKProperties" minOccurs="0" type="xs:boolean"/>
                     <xs:element name="client" minOccurs="0" type="xs:boolean"/>
                 </xs:sequence>
diff --git a/maven-plugins/cayenne-maven-plugin/src/test/resources/cgen/testCgen.map.xml b/maven-plugins/cayenne-maven-plugin/src/test/resources/cgen/testCgen.map.xml
index 6986022..9374713 100644
--- a/maven-plugins/cayenne-maven-plugin/src/test/resources/cgen/testCgen.map.xml
+++ b/maven-plugins/cayenne-maven-plugin/src/test/resources/cgen/testCgen.map.xml
@@ -16,6 +16,7 @@
         <outputPattern>*.txt</outputPattern>
         <makePairs>true</makePairs>
         <usePkgPath>true</usePkgPath>
+        <superPkg>test</superPkg>
         <overwrite>false</overwrite>
         <createPropertyNames>false</createPropertyNames>
     </cgen>
diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/cgen/CodeGeneratorController.java
b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/cgen/CodeGeneratorController.java
index ba6ab60..eb20df9 100644
--- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/cgen/CodeGeneratorController.java
+++ b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/cgen/CodeGeneratorController.java
@@ -19,8 +19,8 @@
 
 package org.apache.cayenne.modeler.editor.cgen;
 
-import javax.swing.*;
-import java.awt.*;
+import javax.swing.JOptionPane;
+import java.awt.Component;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ConcurrentMap;
 import java.util.function.Predicate;
@@ -90,7 +90,8 @@ public class CodeGeneratorController extends CodeGeneratorControllerBase
impleme
                 !cgenConfiguration.isCreatePKProperties() && !cgenConfiguration.isCreatePropertyNames()
&&
                 cgenConfiguration.getOutputPattern().equals("*.java") &&
                 cgenConfiguration.getTemplate().equals(ClassGenerationAction.SUBCLASS_TEMPLATE)
&&
-                cgenConfiguration.getSuperTemplate().equals(ClassGenerationAction.SUPERCLASS_TEMPLATE);
+                cgenConfiguration.getSuperTemplate().equals(ClassGenerationAction.SUPERCLASS_TEMPLATE)
&&
+                (cgenConfiguration.getSuperPkg() == null || cgenConfiguration.getSuperPkg().isEmpty());
 
     }
 
diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/cgen/CustomModeController.java
b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/cgen/CustomModeController.java
index f1d807b..f1a8a65 100644
--- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/cgen/CustomModeController.java
+++ b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/cgen/CustomModeController.java
@@ -177,6 +177,7 @@ public class CustomModeController extends GeneratorController {
         view.getOverwrite().setSelected(cgenConfiguration.isOverwrite());
         view.getCreatePropertyNames().setSelected(cgenConfiguration.isCreatePropertyNames());
         view.getPkProperties().setSelected(cgenConfiguration.isCreatePKProperties());
+        view.getSuperPkg().setText(cgenConfiguration.getSuperPkg());
         updateComboBoxes();
         getParentController().setInitFromModel(false);
     }
diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/cgen/CustomModePanel.java
b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/cgen/CustomModePanel.java
index d29c3c4..cb2cb25 100644
--- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/cgen/CustomModePanel.java
+++ b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/cgen/CustomModePanel.java
@@ -19,6 +19,14 @@
 
 package org.apache.cayenne.modeler.editor.cgen;
 
+import javax.swing.JButton;
+import javax.swing.JCheckBox;
+import javax.swing.JComboBox;
+import javax.swing.JPanel;
+import javax.swing.JTextField;
+import java.awt.BorderLayout;
+import java.awt.FlowLayout;
+
 import com.jgoodies.forms.builder.DefaultFormBuilder;
 import com.jgoodies.forms.layout.FormLayout;
 import org.apache.cayenne.gen.CgenConfiguration;
@@ -29,9 +37,6 @@ import org.apache.cayenne.modeler.util.TextAdapter;
 import org.apache.cayenne.swing.components.JCayenneCheckBox;
 import org.apache.cayenne.validation.ValidationException;
 
-import javax.swing.*;
-import java.awt.*;
-
 /**
  * @since 4.1
  */
@@ -45,6 +50,7 @@ public class CustomModePanel extends GeneratorControllerPanel {
     private TextAdapter outputPattern;
     private JCheckBox createPropertyNames;
     private JCheckBox pkProperties;
+    private TextAdapter superPkg;
 
     private JButton manageTemplatesLink;
 
@@ -90,6 +96,17 @@ public class CustomModePanel extends GeneratorControllerPanel {
             }
         };
 
+        JTextField superPkgField = new JTextField();
+        this.superPkg = new TextAdapter(superPkgField) {
+            @Override
+            protected void updateModel(String text) throws ValidationException {
+                getCgenByDataMap().setSuperPkg(text);
+                if(!codeGeneratorControllerBase.isInitFromModel()) {
+                    projectController.setDirty(true);
+                }
+            }
+        };
+
         this.createPropertyNames = new JCayenneCheckBox();
         this.pkProperties = new JCayenneCheckBox();
         this.manageTemplatesLink = new JButton("Customize Templates...");
@@ -133,6 +150,8 @@ public class CustomModePanel extends GeneratorControllerPanel {
         builder.append("Create PK properties:", pkProperties);
         builder.nextLine();
 
+        builder.append("Superclass package:", superPkg.getComponent());
+
         setLayout(new BorderLayout());
         add(builder.getPanel(), BorderLayout.CENTER);
 
@@ -178,4 +197,8 @@ public class CustomModePanel extends GeneratorControllerPanel {
     public JCheckBox getPkProperties() {
         return pkProperties;
     }
+
+    public TextAdapter getSuperPkg() {
+        return superPkg;
+    }
 }


Mime
View raw message