You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jena.apache.org by an...@apache.org on 2012/09/06 14:38:17 UTC

svn commit: r1381581 - in /jena/trunk/jena-tdb: ReleaseNotes.txt src/main/java/com/hp/hpl/jena/tdb/store/DecimalNode.java src/main/java/com/hp/hpl/jena/tdb/store/IntegerNode.java

Author: andy
Date: Thu Sep  6 12:38:17 2012
New Revision: 1381581

URL: http://svn.apache.org/viewvc?rev=1381581&view=rev
Log:
Use constants everywhere

Modified:
    jena/trunk/jena-tdb/ReleaseNotes.txt
    jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/store/DecimalNode.java
    jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/store/IntegerNode.java

Modified: jena/trunk/jena-tdb/ReleaseNotes.txt
URL: http://svn.apache.org/viewvc/jena/trunk/jena-tdb/ReleaseNotes.txt?rev=1381581&r1=1381580&r2=1381581&view=diff
==============================================================================
--- jena/trunk/jena-tdb/ReleaseNotes.txt (original)
+++ jena/trunk/jena-tdb/ReleaseNotes.txt Thu Sep  6 12:38:17 2012
@@ -3,6 +3,7 @@ ChangeLog for TDB
 
 ==== TDB 0.9.4
 
++ JENA_317 : Fix to handling decimal numbers.  Decimals of around 15 digits could be corrupted.  
 + JENA-301 : Recovery did not reset internal file state under certain conditions.  
 + Bug fix: out-of-range derived integers (e.g. xsd:int)
 + Cache read transaction datastructures and reuse view when possible.

Modified: jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/store/DecimalNode.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/store/DecimalNode.java?rev=1381581&r1=1381580&r2=1381581&view=diff
==============================================================================
--- jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/store/DecimalNode.java (original)
+++ jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/store/DecimalNode.java Thu Sep  6 12:38:17 2012
@@ -37,6 +37,7 @@ public class DecimalNode
     
     static final int SCALE_LEN  = 8 ; 
     static final int VALUE_LEN  = 48 ; 
+    static final int ENC_LEN  = 48+SCALE_LEN ;
     
     static final long MAX_VALUE =   (1L<< (VALUE_LEN-1) )-1 ;
     static final long MIN_VALUE =  -(1L<< (VALUE_LEN-1) ) ;
@@ -96,7 +97,7 @@ public class DecimalNode
     public static long pack(long value, int scale)
     {
         // pack : DECIMAL , sign, scale, value
-        long v = BitsLong.pack(0, NodeId.DECIMAL, 56, 64) ;
+        long v = BitsLong.pack(0, NodeId.DECIMAL, ENC_LEN, Long.SIZE) ;
         v = BitsLong.pack(v, scale, SCALE_LO, SCALE_HI) ;
         v = BitsLong.pack(v, value, VALUE_LO, VALUE_HI) ;
         // No need to do something about negative numbers
@@ -118,8 +119,8 @@ public class DecimalNode
         int scale =  (int)BitsLong.unpack(v, SCALE_LO, SCALE_HI) ;
         long value = BitsLong.unpack(v, VALUE_LO, VALUE_HI) ;
         // Sign extend value.
-        if ( BitsLong.isSet(value, VALUE_LEN-1) )
-            value = value | -1L<<(VALUE_LEN) ;
+        if ( BitsLong.isSet(value, VALUE_HI-1) )
+            value = value | -1L<<(VALUE_HI) ;
         
         return BigDecimal.valueOf(value, scale) ;
     }

Modified: jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/store/IntegerNode.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/store/IntegerNode.java?rev=1381581&r1=1381580&r2=1381581&view=diff
==============================================================================
--- jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/store/IntegerNode.java (original)
+++ jena/trunk/jena-tdb/src/main/java/com/hp/hpl/jena/tdb/store/IntegerNode.java Thu Sep  6 12:38:17 2012
@@ -22,26 +22,30 @@ import org.openjena.atlas.lib.BitsLong ;
 
 public class IntegerNode
 {
+    // 56 bits of value, including sign bit.
+    public static int LEN = 56 ;
+    public static int LBITS = Long.SIZE ;
+    public static long MAX = (1L<< (LEN-1) ) ;
+    public static long MIN = (1L<< (LEN-1) ) ;
+
     public static long pack(long v) 
     {
-        // 56 bits of value, including sign bit.
-        if ( Math.abs(v) < (1L<<55) )
+        if ( v < MIN || v > MAX )
         {
-            v = BitsLong.clear(v, 56, 64) ;
+            v = BitsLong.clear(v, LEN, LBITS) ;
             v = NodeId.setType(v, NodeId.INTEGER) ;
             return v ;
         }
         else
             return -1 ;
     }
-    
+
     public static long unpack(long v) 
     {
-        long val = BitsLong.clear(v, 56, 64) ;
+        long val = BitsLong.clear(v, LEN, LBITS) ;
         // Sign extends to 64 bits.
-        if ( BitsLong.isSet(val, 55) )
-            val = BitsLong.set(v, 56, 64) ;
+        if ( BitsLong.isSet(val, LEN-1) )
+            val = BitsLong.set(v, LEN, LBITS) ;
         return val ;
     }
-
 }