cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r690145 - in /cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src: main/java/org/apache/cayenne/gen/ main/resources/dotemplates/v1_2/ test/java/org/apache/cayenne/gen/
Date Fri, 29 Aug 2008 08:24:13 GMT
Author: aadamchik
Date: Fri Aug 29 01:24:11 2008
New Revision: 690145

URL: http://svn.apache.org/viewvc?rev=690145&view=rev
Log:
CAY-1097 Attribute types are not generated for primitive ints (patches by Dima Loiko)

Modified:
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/gen/ImportUtils.java
    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/superclass.vm
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/gen/ClassGenerationActionTest.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/gen/ImportUtilsTest.java

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/gen/ImportUtils.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/gen/ImportUtils.java?rev=690145&r1=690144&r2=690145&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/gen/ImportUtils.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/gen/ImportUtils.java
Fri Aug 29 01:24:11 2008
@@ -40,13 +40,13 @@
     };
 
     static final String primitives[] = new String[] {
-            "long", "double", "byte", "boolean", "float", "short", "int"
+            "long", "double", "byte", "boolean", "float", "short", "int", "char"
     };
 
     static final String primitiveClasses[] = new String[] {
             Long.class.getName(), Double.class.getName(), Byte.class.getName(),
             Boolean.class.getName(), Float.class.getName(), Short.class.getName(),
-            Integer.class.getName()
+            Integer.class.getName(), Character.class.getName()
     };
 
     static Map<String, String> classesForPrimitives = Util.toMap(

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=690145&r1=690144&r2=690145&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
Fri Aug 29 01:24:11 2008
@@ -70,11 +70,22 @@
         writeProperty("${attr.Name}", $stringUtils.formatVariableName(${attr.Name}));
     }
 #end
+#if ( $importUtils.isBoolean(${attr.Type}) )
+	public boolean is${stringUtils.capitalized($attr.Name)}() {
+        Boolean value = (Boolean)readProperty("${attr.Name}");
+        return (value != null) ? value.booleanValue() : false;
+    }
+#elseif ( $importUtils.isNonBooleanPrimitive(${attr.Type}) )
+    public ${importUtils.formatJavaType($attr.Type)} get${stringUtils.capitalized($attr.Name)}()
{
+        Object value = readProperty("${attr.Name}");
+        return (value != null) ? ($importUtils.formatJavaTypeAsNonBooleanPrimitive(${attr.Type}))
value : 0;
+    }
+#else
     public $importUtils.formatJavaType(${attr.Type}) get${stringUtils.capitalized($attr.Name)}()
{
         return ($importUtils.formatJavaType(${attr.Type}))readProperty("${attr.Name}");
     }
-    
-    
+#end
+
 #end
 ##
 ## Create list add/remove/get methods

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/resources/dotemplates/v1_2/superclass.vm
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/resources/dotemplates/v1_2/superclass.vm?rev=690145&r1=690144&r2=690145&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/resources/dotemplates/v1_2/superclass.vm
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/resources/dotemplates/v1_2/superclass.vm
Fri Aug 29 01:24:11 2008
@@ -81,7 +81,7 @@
         return (value != null) ? value.booleanValue() : false;
     }
 #elseif ( $importUtils.isNonBooleanPrimitive(${attr.Type}) )
-    public $classGen.formatJavaType(${attr.Type}) get${stringUtils.capitalized($attr.Name)}()
{
+    public ${importUtils.formatJavaType($attr.Type)} get${stringUtils.capitalized($attr.Name)}()
{
         Object value = readProperty("${attr.Name}");
         return (value != null) ? ($importUtils.formatJavaTypeAsNonBooleanPrimitive(${attr.Type}))
value : 0;
     }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/gen/ClassGenerationActionTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/gen/ClassGenerationActionTest.java?rev=690145&r1=690144&r2=690145&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/gen/ClassGenerationActionTest.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/gen/ClassGenerationActionTest.java
Fri Aug 29 01:24:11 2008
@@ -24,7 +24,9 @@
 import java.util.Collection;
 import java.util.List;
 
+
 import org.apache.cayenne.map.Entity;
+import org.apache.cayenne.map.ObjAttribute;
 import org.apache.cayenne.map.ObjEntity;
 import org.apache.cayenne.map.ObjRelationship;
 import org.apache.cayenne.unit.BasicCase;
@@ -112,6 +114,47 @@
         String superclass = generated.get(0);
         assertTrue(superclass, superclass.contains("import java.util.Map;"));
     }
+    
+    
+    public void testExecuteArtifactPairsAttribute() throws Exception {
+
+        ObjEntity testEntity1 = new ObjEntity("TE1");
+        testEntity1.setClassName("org.example.TestClass1");
+        
+        ObjAttribute attr = new ObjAttribute();
+        attr.setName("ID");
+        attr.setType("int");
+
+        ObjAttribute attr1 = new ObjAttribute();
+        attr1.setName("name");
+        attr1.setType("char");
+        
+        testEntity1.addAttribute(attr);
+        testEntity1.addAttribute(attr1);
+
+        action.setMakePairs(true);
+
+        List<String> generated = execute(new EntityArtifact(testEntity1));
+        assertNotNull(generated);
+        assertEquals(2, generated.size());
+        String superclass = generated.get(0);
+        
+        assertTrue(superclass, superclass.contains("public void setID(int ID)"));
+        assertTrue(superclass, superclass.contains("writeProperty(\"ID\", ID);"));
+        
+        assertTrue(superclass, superclass.contains("public int getID()"));
+        assertTrue(superclass, superclass.contains("Object value = readProperty(\"ID\");"));
+        assertTrue(superclass, superclass.contains("return (value != null) ? (Integer) value
: 0;"));
+        
+        assertTrue(superclass, superclass.contains("public void setName(char name)"));
+        assertTrue(superclass, superclass.contains("writeProperty(\"name\", name);"));
+        
+        assertTrue(superclass, superclass.contains("public char getName()"));
+        assertTrue(superclass, superclass.contains("Object value = readProperty(\"name\");"));
+        assertTrue(superclass, superclass.contains("return (value != null) ? (Character)
value : 0;"));
+
+    }
+    
 
     protected List<String> execute(Artifact artifact) throws Exception {
 

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/gen/ImportUtilsTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/gen/ImportUtilsTest.java?rev=690145&r1=690144&r2=690145&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/gen/ImportUtilsTest.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/gen/ImportUtilsTest.java
Fri Aug 29 01:24:11 2008
@@ -191,6 +191,9 @@
         assertEquals("int", importUtils.formatJavaType("int", true));
         assertEquals("Integer", importUtils.formatJavaType("int", false));
         
+        assertEquals("char", importUtils.formatJavaType("char", true));
+        assertEquals("Character", importUtils.formatJavaType("java.lang.Character", false));
+        
         assertEquals("double", importUtils.formatJavaType("java.lang.Double", true));
         assertEquals("Double", importUtils.formatJavaType("java.lang.Double", false));
         



Mime
View raw message