db-torque-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tfisc...@apache.org
Subject svn commit: r326224 - in /db/torque: generator/trunk/src/java/org/apache/torque/engine/database/model/ runtime/trunk/src/java/org/apache/torque/map/ runtime/trunk/xdocs/ templates/trunk/src/templates/om/ test/trunk/test-project/src/schema/
Date Tue, 18 Oct 2005 20:35:47 GMT
Author: tfischer
Date: Tue Oct 18 13:35:33 2005
New Revision: 326224

URL: http://svn.apache.org/viewcvs?rev=326224&view=rev
Log:
The generator now builds the MapBuilders such that the columns of the TableMap contain the
correct size and scale as provided in the schema.xml.
Fixes TRQS323.
Thanks to Greg Monroe for the patch.

Modified:
    db/torque/generator/trunk/src/java/org/apache/torque/engine/database/model/Column.java
    db/torque/runtime/trunk/src/java/org/apache/torque/map/ColumnMap.java
    db/torque/runtime/trunk/src/java/org/apache/torque/map/TableMap.java
    db/torque/runtime/trunk/xdocs/changes.xml
    db/torque/templates/trunk/src/templates/om/MapBuilder.vm
    db/torque/test/trunk/test-project/src/schema/test-schema.xml

Modified: db/torque/generator/trunk/src/java/org/apache/torque/engine/database/model/Column.java
URL: http://svn.apache.org/viewcvs/db/torque/generator/trunk/src/java/org/apache/torque/engine/database/model/Column.java?rev=326224&r1=326223&r2=326224&view=diff
==============================================================================
--- db/torque/generator/trunk/src/java/org/apache/torque/engine/database/model/Column.java
(original)
+++ db/torque/generator/trunk/src/java/org/apache/torque/engine/database/model/Column.java
Tue Oct 18 13:35:33 2005
@@ -739,11 +739,88 @@
     }
 
     /**
-     * Returns the scale of the column
+     * Try to determine the precision of the field from the size attribute.
+     * If size attribute is an integer number, it will be returned.
+     * If size attribute is of the format "Precision,Scale", then Precision
+     * will be returned.
+     * If size is null or the size value is not an valid integer, 
+     * null is returned.
+     * <p>
+     * Note: Unparseable values will be logged as a warning.
+     * 
+     * @return The precision portion of the size attribute.  
+     */
+    public String getPrecision()
+    {
+        String size = getSize();
+        if ( size == null )
+        {
+            return size;
+        }
+        int cLoc = size.indexOf(',');
+        if ( cLoc > 0 )
+        {
+            size = size.substring(0, cLoc);
+        }
+        try 
+        {
+            Integer.parseInt(size);
+        } 
+        catch ( NumberFormatException e  ) 
+        {
+            log.warn("getPrecision(): Size attribute found ("
+                    + getSize()
+                    + ") was not an integer number, using default of null!");
+            size = null;
+        }
+        return size;
+    }
+
+    /**
+     * Try to determine the scale of the field from the scale and size 
+     * attribute.
+     * If scale attribute is an integer number, it will be returned.
+     * If size attribute is of the format "Precision,Scale", then Scale
+     * will be returned.
+     * If scale and size attributes are null or the scale value found 
+     * is not an valid integer, a null value is returned.
+     * <p>
+     * Note: Unparseable values will be logged as a warning.
+     * 
+     * @return The precision portion of the size attribute.  
      */
     public String getScale()
     {
-        return domain.getScale();
+        String scale = domain.getScale();
+        // Check for scale on size attribute if no scale attribute
+        if ( scale == null )
+        {
+            scale = getSize();
+            if ( scale == null )   // No scale or size attribute set.
+            {
+                return scale;
+            }
+            int cLoc = scale.indexOf(',');
+            if ( cLoc < 0 )        // Size did not have "P,S" format
+            {
+                return null;
+            }
+            scale = scale.substring(cLoc + 1 );
+        }
+
+        // Validate that scale string found is integer.
+        try 
+        {
+            Integer.parseInt(scale);
+        }
+        catch ( NumberFormatException e  ) 
+        {
+            log.warn("getScale(): Scale (or size=\"p,s\") attribute found ("
+                    + scale
+                    + ") was not an integer number, using default of null.");
+            scale = null;
+        }
+        return scale;
     }
 
     /**

Modified: db/torque/runtime/trunk/src/java/org/apache/torque/map/ColumnMap.java
URL: http://svn.apache.org/viewcvs/db/torque/runtime/trunk/src/java/org/apache/torque/map/ColumnMap.java?rev=326224&r1=326223&r2=326224&view=diff
==============================================================================
--- db/torque/runtime/trunk/src/java/org/apache/torque/map/ColumnMap.java (original)
+++ db/torque/runtime/trunk/src/java/org/apache/torque/map/ColumnMap.java Tue Oct 18 13:35:33
2005
@@ -29,6 +29,9 @@
 
     /** Size of the column. */
     private int size = 0;
+    
+    /** Scale of the column */
+    private int scale = 0;
 
     /** Is it a primary key? */
     private boolean pk = false;
@@ -185,7 +188,14 @@
     }
 
     /**
-     * Get the size of this column.
+     * The "precision" value from the XML 
+     * size="&lt;precision&gt;[,&lt;scale&gt;]"
+     * attribute. Where [,&lt;scale&gt;] is optional. 
+     * 
+     * If the size attribute has not been set in the XML, it will return 0.<p>
+     * 
+     * Note that the size="P,S" format should be replaced with 
+     * size="P" scale="S".
      *
      * @return An int specifying the size.
      */
@@ -252,5 +262,26 @@
     public String getRelatedColumnName()
     {
         return relatedColumnName;
+    }
+
+    /**
+     * Gets the scale set for this column (if any) as set in the XML database
+     * definition.  E.g., the value of the scale attribute or the scale portion
+     * of a size="P,S" attribute. 
+     * (Note: size="P,S" format is being deprecated!).
+     *
+     * @return Returns the scale.
+     */
+    public int getScale() 
+    {
+        return scale;
+    }
+
+    /**
+     * @param scale The scale to set.
+     */
+    public void setScale(int scale) 
+    {
+        this.scale = scale;
     }
 }

Modified: db/torque/runtime/trunk/src/java/org/apache/torque/map/TableMap.java
URL: http://svn.apache.org/viewcvs/db/torque/runtime/trunk/src/java/org/apache/torque/map/TableMap.java?rev=326224&r1=326223&r2=326224&view=diff
==============================================================================
--- db/torque/runtime/trunk/src/java/org/apache/torque/map/TableMap.java (original)
+++ db/torque/runtime/trunk/src/java/org/apache/torque/map/TableMap.java Tue Oct 18 13:35:33
2005
@@ -291,6 +291,19 @@
     }
 
     /**
+     * Add a column to this table of a certain type, size, and scale.
+     *
+     * @param columnName A String with the column name.
+     * @param type An Object specifying the type.
+     * @param size An int specifying the size.
+     * @param scale An int specifying the scale.
+     */
+    public void addColumn(String columnName, Object type, int size, int scale)
+    {
+        addColumn(columnName, type, false, null, null, size, scale);
+    }
+    
+    /**
      * Add a column to this table of a certain type and size.
      *
      * @param columnName A String with the column name.
@@ -410,6 +423,28 @@
                            String fkColumn,
                            int size)
     {
+        addColumn(name, type, pk, fkTable,fkColumn, size, 0 );
+    }
+
+    /**
+     * Add a column to the table.
+     *
+     * @param name A String with the column name.
+     * @param type An Object specifying the type.
+     * @param pk True if column is a primary key.
+     * @param fkTable A String with the foreign key table name.
+     * @param fkColumn A String with the foreign key column name.
+     * @param size An int specifying the size.
+     * @param scale An int specifying the scale.
+     */
+    private void addColumn(String name,
+                           Object type,
+                           boolean pk,
+                           String fkTable,
+                           String fkColumn,
+                           int size,
+                           int scale)
+    {
         // If the tablename is prefixed with the name of the column,
         // remove it ie: SCARAB_PROJECT.PROJECT_ID remove the
         // SCARAB_PROJECT.
@@ -430,6 +465,7 @@
         col.setPrimaryKey(pk);
         col.setForeignKey(fkTable, fkColumn);
         col.setSize(size);
+        col.setScale(scale);
         columns.put(name, col);
     }
 

Modified: db/torque/runtime/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewcvs/db/torque/runtime/trunk/xdocs/changes.xml?rev=326224&r1=326223&r2=326224&view=diff
==============================================================================
--- db/torque/runtime/trunk/xdocs/changes.xml (original)
+++ db/torque/runtime/trunk/xdocs/changes.xml Tue Oct 18 13:35:33 2005
@@ -25,6 +25,13 @@
 
   <body>
 
+  <release version="3.2-rc3-dev" date="in SVN">
+    <action type="add" dev="tfischer" issue="TRQS323">
+      The size and scale attributes from the schema.xml are now used
+      to fill the fields size and scale in the column objects
+      created by the generated map builder objects.
+    </action>
+  </release>
   <release version="3.2-rc2" date="2005-09-13">
     <action type="fix" dev="tfischer" issue="TRQS318">
       LargeSelect now also works for databases which do not support

Modified: db/torque/templates/trunk/src/templates/om/MapBuilder.vm
URL: http://svn.apache.org/viewcvs/db/torque/templates/trunk/src/templates/om/MapBuilder.vm?rev=326224&r1=326223&r2=326224&view=diff
==============================================================================
--- db/torque/templates/trunk/src/templates/om/MapBuilder.vm (original)
+++ db/torque/templates/trunk/src/templates/om/MapBuilder.vm Tue Oct 18 13:35:33 2005
@@ -107,7 +107,7 @@
                 "${table.Name}.$cup", $col.JavaObject , "$col.RelatedTableName" ,
                 "$col.RelatedColumnName");
     #else
-        tMap.addPrimaryKey("${table.Name}.$cup", $col.JavaObject);
+        tMap.addPrimaryKey("${table.Name}.$cup", $col.JavaObject );
     #end
   #else
     #if($col.isForeignKey())
@@ -115,7 +115,15 @@
                 "${table.Name}.$cup", $col.JavaObject , "$col.RelatedTableName" ,
                 "$col.RelatedColumnName");
     #else
-        tMap.addColumn("${table.Name}.$cup", $col.JavaObject);
+      #if( $col.Precision )
+      	#if( $col.Scale )
+          tMap.addColumn("${table.Name}.$cup", $col.JavaObject, $col.Precision, $col.Scale
);
+        #else
+          tMap.addColumn("${table.Name}.$cup", $col.JavaObject, $col.Precision );
+        #end
+      #else
+        tMap.addColumn("${table.Name}.$cup", $col.JavaObject );
+      #end
     #end
   #end
 #end

Modified: db/torque/test/trunk/test-project/src/schema/test-schema.xml
URL: http://svn.apache.org/viewcvs/db/torque/test/trunk/test-project/src/schema/test-schema.xml?rev=326224&r1=326223&r2=326224&view=diff
==============================================================================
--- db/torque/test/trunk/test-project/src/schema/test-schema.xml (original)
+++ db/torque/test/trunk/test-project/src/schema/test-schema.xml Tue Oct 18 13:35:33 2005
@@ -310,4 +310,20 @@
     />
   </table>
 
+  <table name="SCALE_TEST" idMethod="none" description="Table to test scale attribute">
+    <column
+      name="SCALE_TEST_ID"
+      required="true"
+      primaryKey="true"
+      type="BIGINT"
+    />
+    <column
+      name="NUMERIC_1"
+      type="NUMERIC"
+      size="10"
+      scale="2"
+      required="false"
+    />
+  </table>
+
 </database>



---------------------------------------------------------------------
To unsubscribe, e-mail: torque-dev-unsubscribe@db.apache.org
For additional commands, e-mail: torque-dev-help@db.apache.org


Mime
View raw message