empire-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From doeb...@apache.org
Subject svn commit: r1626155 - in /empire-db/trunk/empire-db/src/main/java/org/apache/empire/db: DBDDLGenerator.java DBTableColumn.java
Date Fri, 19 Sep 2014 09:19:34 GMT
Author: doebele
Date: Fri Sep 19 09:19:34 2014
New Revision: 1626155

URL: http://svn.apache.org/r1626155
Log:
EMPIREDB-208

Modified:
    empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBDDLGenerator.java
    empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBTableColumn.java

Modified: empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBDDLGenerator.java
URL: http://svn.apache.org/viewvc/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBDDLGenerator.java?rev=1626155&r1=1626154&r2=1626155&view=diff
==============================================================================
--- empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBDDLGenerator.java (original)
+++ empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBDDLGenerator.java Fri Sep
19 09:19:34 2014
@@ -143,7 +143,7 @@ public abstract class DBDDLGenerator<T e
             case DECIMAL:
             {   sql.append(DATATYPE_DECIMAL);
                 int prec  = (int) size;
-                int scale = (int) ((size - prec) * 10 + 0.5);
+                int scale = c.getDecimalScale();
                 if (prec>0) {
                     // append precision and scale
                     sql.append("(");

Modified: empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBTableColumn.java
URL: http://svn.apache.org/viewvc/empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBTableColumn.java?rev=1626155&r1=1626154&r2=1626155&view=diff
==============================================================================
--- empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBTableColumn.java (original)
+++ empire-db/trunk/empire-db/src/main/java/org/apache/empire/db/DBTableColumn.java Fri Sep
19 09:19:34 2014
@@ -58,6 +58,7 @@ public class DBTableColumn extends DBCol
     protected double    size;
     protected DataMode  dataMode;
     protected Object    defValue;
+    protected int 		decimalScale = 0;
 
     /**
      * Constructs a DBTableColumn object set the specified parameters to this object.
@@ -208,6 +209,32 @@ public class DBTableColumn extends DBCol
         }
         // set now
         this.size = size;
+        // set scale
+    	if (getDataType()==DataType.DECIMAL)
+    	{	// set scale from size
+		    int reqPrec = (int)size;
+		    this.decimalScale = ((int)(size*10)-(reqPrec*10));
+    	}
+    }
+    
+    /**
+     * Returns the scale of the Decimal or 0 if the DataType is not DataType.DECIMAL.
+     * @return the decimal scale
+     */
+    public int getDecimalScale()
+    {
+	    return this.decimalScale;
+    }
+    
+    /**
+     * Sets the scale of a decimal. The DataType must be set to DataType.DECIMAL otherwise
an exception is thrown. 
+     */
+    public void setDecimalScale(int scale)
+    {
+    	if (getDataType()!=DataType.DECIMAL)
+    		throw new NotSupportedException(this, "setDecimalScale");
+    	// return scale
+	    this.decimalScale = scale;
     }
 
     /**
@@ -457,7 +484,7 @@ public class DBTableColumn extends DBCol
             // check precision and scale
             double size = getSize();
             int reqPrec = (int)size;
-            int reqScale =((int)(size*10)-(reqPrec*10));
+            int reqScale = getDecimalScale();
             if ((prec-scale)>(reqPrec-reqScale) || scale>reqScale)
                 throw new FieldValueOutOfRangeException(this);
         }



Mime
View raw message