cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From amania...@apache.org
Subject svn commit: r685375 - in /cayenne/main/trunk/framework: cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/gen/ cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/ cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/projec...
Date Tue, 12 Aug 2008 23:41:04 GMT
Author: amaniatis
Date: Tue Aug 12 16:41:02 2008
New Revision: 685375

URL: http://svn.apache.org/viewvc?rev=685375&view=rev
Log:
CAY-794 Patch from Marcin Skladaniec.

Allow abstract object entities in the model.

Modified:
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/gen/EntityUtils.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/MapLoader.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/ObjEntity.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/project/validator/ObjAttributeValidator.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/project/validator/ObjEntityValidator.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/resources/dotemplates/v1_2/client-subclass.vm
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/resources/dotemplates/v1_2/embeddable-subclass.vm
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/resources/dotemplates/v1_2/singleclass.vm
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/resources/dotemplates/v1_2/subclass.vm
    cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/ObjEntityTab.java

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/gen/EntityUtils.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/gen/EntityUtils.java?rev=685375&r1=685374&r2=685375&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/gen/EntityUtils.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/gen/EntityUtils.java
Tue Aug 12 16:41:02 2008
@@ -162,6 +162,23 @@
     public MappingNamespace getEntityResolver() {
         return primaryDataMap.getNamespace();
     }
+    
+    /**
+     * Returns true if current ObjEntity is defined as abstract.
+     */
+    public boolean isAbstract() {
+        return isAbstract(objEntity);
+    }
+    
+    /**
+     * Returns true if current ObjEntity is defined as abstract.
+     */
+    public boolean isAbstract(ObjEntity anObjEntity) {
+        if (anObjEntity == null) 
+            return false;
+        
+        return objEntity.getIsAbstract();
+    }
 
     /**
      * Returns true if current ObjEntity contains at least one toMany relationship.
@@ -169,6 +186,7 @@
     public boolean hasToManyRelationships() {
         return hasToManyRelationships(objEntity);
     }
+    
 
     /**
      * Returns true if an ObjEntity contains at least one toMany relationship.

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/MapLoader.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/MapLoader.java?rev=685375&r1=685374&r2=685375&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/MapLoader.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/MapLoader.java
Tue Aug 12 16:41:02 2008
@@ -869,6 +869,9 @@
         objEntity.setClassName(atts.getValue("", "className"));
         objEntity.setClientClassName(atts.getValue("", "clientClassName"));
 
+        String isAbstract = atts.getValue("", "abstract");
+        objEntity.setIsAbstract(TRUE.equalsIgnoreCase(isAbstract));
+        
         String readOnly = atts.getValue("", "readOnly");
         objEntity.setReadOnly(TRUE.equalsIgnoreCase(readOnly));
 

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/ObjEntity.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/ObjEntity.java?rev=685375&r1=685374&r2=685375&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/ObjEntity.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/ObjEntity.java
Tue Aug 12 16:41:02 2008
@@ -74,6 +74,7 @@
     protected boolean readOnly;
     protected int lockType;
 
+    protected boolean isAbstract;
     protected boolean serverOnly;
     protected String clientClassName;
     protected String clientSuperClassName;
@@ -108,6 +109,10 @@
             encoder.print("\" superEntityName=\"");
             encoder.print(getSuperEntityName());
         }
+        
+        if (getIsAbstract()) {
+            encoder.print("\" abstract=\"true");
+        }
 
         if (isServerOnly()) {
             encoder.print("\" serverOnly=\"true");
@@ -408,6 +413,18 @@
         return (getDataMap() == null || isServerOnly()) ? false : getDataMap()
                 .isClientSupported();
     }
+    
+    public boolean getIsAbstract() {
+        return isAbstract;
+    }
+    
+    /**
+     * Sets whether this entity is abstract only.
+     * 
+     */
+    public void setIsAbstract(boolean isAbstract) {
+        this.isAbstract = isAbstract;
+    }
 
     /**
      * Returns true if this entity is not available on the client.

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/project/validator/ObjAttributeValidator.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/project/validator/ObjAttributeValidator.java?rev=685375&r1=685374&r2=685375&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/project/validator/ObjAttributeValidator.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/project/validator/ObjAttributeValidator.java
Tue Aug 12 16:41:02 2008
@@ -20,6 +20,7 @@
 package org.apache.cayenne.project.validator;
 
 import org.apache.cayenne.map.ObjAttribute;
+import org.apache.cayenne.map.ObjEntity;
 import org.apache.cayenne.project.ProjectPath;
 import org.apache.cayenne.util.Util;
 
@@ -70,7 +71,9 @@
             validator.registerWarning("ObjAttribute has no type.", path);
         }
 
-        if (attribute.getDbAttribute() == null) {
+        if (attribute.getEntity() instanceof ObjEntity && ((ObjEntity)attribute.getEntity()).getIsAbstract())
{
+            //nothing, abstract entity does not have to define a dbAttribute
+        } else if (attribute.getDbAttribute() == null) {
             validator.registerWarning("ObjAttribute has no DbAttribute mapping.", path);
         }
         // can't support generated meaningful attributes for now; besides they don't make

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/project/validator/ObjEntityValidator.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/project/validator/ObjEntityValidator.java?rev=685375&r1=685374&r2=685375&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/project/validator/ObjEntityValidator.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/project/validator/ObjEntityValidator.java
Tue Aug 12 16:41:02 2008
@@ -45,7 +45,7 @@
         validateSuperClassName(ent, path, validator);
 
         // validate DbEntity presence
-        if (ent.getDbEntity() == null) {
+        if (ent.getDbEntity() == null && !ent.getIsAbstract()) {
             validator.registerWarning("ObjEntity has no DbEntity mapping.", path);
         }
     }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/resources/dotemplates/v1_2/client-subclass.vm
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/resources/dotemplates/v1_2/client-subclass.vm?rev=685375&r1=685374&r2=685375&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/resources/dotemplates/v1_2/client-subclass.vm
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/resources/dotemplates/v1_2/client-subclass.vm
Tue Aug 12 16:41:02 2008
@@ -42,6 +42,6 @@
 /**
  * A persistent class mapped as "${object.name}" Cayenne entity.
  */
-public class ${subClassName} extends ${superClassName} {
+public#if("true" == "${object.getIsAbstract()}") abstract#end class ${subClassName} extends
${superClassName} {
 
 }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/resources/dotemplates/v1_2/embeddable-subclass.vm
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/resources/dotemplates/v1_2/embeddable-subclass.vm?rev=685375&r1=685374&r2=685375&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/resources/dotemplates/v1_2/embeddable-subclass.vm
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/resources/dotemplates/v1_2/embeddable-subclass.vm
Tue Aug 12 16:41:02 2008
@@ -40,6 +40,6 @@
 ${importUtils.generate()}
 
 
-public class ${subClassName} extends ${superClassName} {
+public#if("true" == "${object.getIsAbstract()}") abstract#end class ${subClassName} extends
${superClassName} {
 
 }
\ No newline at end of file

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/resources/dotemplates/v1_2/singleclass.vm
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/resources/dotemplates/v1_2/singleclass.vm?rev=685375&r1=685374&r2=685375&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/resources/dotemplates/v1_2/singleclass.vm
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/resources/dotemplates/v1_2/singleclass.vm
Tue Aug 12 16:41:02 2008
@@ -47,7 +47,7 @@
 #end
 ${importUtils.generate()}
 
-public class ${subClassName} extends ${baseClassName} {
+public#if("true" == "${object.getIsAbstract()}") abstract#end class ${subClassName} extends
${baseClassName} {
 
 ## Create property names
 #foreach( $attr in ${object.DeclaredAttributes} )

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/resources/dotemplates/v1_2/subclass.vm
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/resources/dotemplates/v1_2/subclass.vm?rev=685375&r1=685374&r2=685375&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/resources/dotemplates/v1_2/subclass.vm
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/resources/dotemplates/v1_2/subclass.vm
Tue Aug 12 16:41:02 2008
@@ -32,6 +32,6 @@
 ${importUtils.addType("${entityUtils.superPackageName}.${entityUtils.superClassName}")}##
 ${importUtils.generate()}
 
-public class ${entityUtils.subClassName} extends ${entityUtils.superClassName} {
+public#if("true" == "${object.getIsAbstract()}") abstract#end class ${entityUtils.subClassName}
extends ${entityUtils.superClassName} {
 
 }

Modified: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/ObjEntityTab.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/ObjEntityTab.java?rev=685375&r1=685374&r2=685375&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/ObjEntityTab.java
(original)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/ObjEntityTab.java
Tue Aug 12 16:41:02 2008
@@ -103,11 +103,13 @@
     protected JCheckBox excludeDefaultListeners;
 
     protected JComponent clientSeparator;
+    protected JLabel isAbstractLabel;
     protected JLabel serverOnlyLabel;
     protected JLabel clientClassNameLabel;
     protected JLabel clientSuperClassNameLabel;
 
     protected JCheckBox serverOnly;
+    protected JCheckBox isAbstract;
     protected TextAdapter clientClassName;
     protected TextAdapter clientSuperClassName;
 
@@ -176,6 +178,7 @@
         syncWithDbEntityButton.setIcon(ModelerUtil.buildIcon("icon-sync.gif"));
         syncWithDbEntityButton.setToolTipText("Sync this ObjEntity with its DBEntity");
 
+        isAbstract = new JCheckBox();
         serverOnly = new JCheckBox();
         clientClassName = new TextAdapter(new JTextField()) {
 
@@ -203,6 +206,7 @@
         builder.append("ObjEntity Name:", name.getComponent(), 3);
         builder.append("Inheritance:", superEntityCombo, 3);
         builder.append(tableLabel, dbEntityCombo, syncWithDbEntityButton);
+        isAbstractLabel = builder.append("Abstract class:", isAbstract, 3);
 
         builder.appendSeparator();
 
@@ -360,6 +364,17 @@
                 }
             }
         });
+        
+        isAbstract.addActionListener(new ActionListener() {
+
+            public void actionPerformed(ActionEvent e) {
+                ObjEntity entity = mediator.getCurrentObjEntity();
+                if (entity != null) {
+                    entity.setIsAbstract(isAbstract.isSelected());
+                    mediator.fireObjEntityEvent(new EntityEvent(this, entity));
+                }
+            }
+        });
     }
 
     /**
@@ -376,7 +391,8 @@
         superClassName.setText(entity.getSuperClassName());
         className.setText(entity.getClassName());
         readOnly.setSelected(entity.isReadOnly());
-
+        
+        isAbstract.setSelected(entity.getIsAbstract());
         serverOnly.setSelected(entity.isServerOnly());
         clientClassName.setText(entity.getClientClassName());
         clientSuperClassName.setText(entity.getClientSuperClassName());



Mime
View raw message