db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rhille...@apache.org
Subject svn commit: r1469948 - in /db/derby/code/trunk/java: engine/org/apache/derby/iapi/services/io/ engine/org/apache/derby/iapi/types/ engine/org/apache/derby/impl/services/monitor/ engine/org/apache/derby/impl/sql/depend/ testing/org/apache/derbyTesting/j...
Date Fri, 19 Apr 2013 16:39:06 GMT
Author: rhillegas
Date: Fri Apr 19 16:39:05 2013
New Revision: 1469948

URL: http://svn.apache.org/r1469948
Log:
DERBY-6188: Improve encapsulation in Formatable machinery.

Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/io/ArrayUtil.java
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/io/FormatableBitSet.java
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/io/RegisteredFormatIds.java
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/DataValueFactoryImpl.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/services/monitor/BaseMonitor.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/depend/BasicDependencyManager.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/BaseTestCase.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/unitTests/junit/FormatableBitSetTest.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/io/ArrayUtil.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/io/ArrayUtil.java?rev=1469948&r1=1469947&r2=1469948&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/io/ArrayUtil.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/io/ArrayUtil.java Fri Apr
19 16:39:05 2013
@@ -48,7 +48,7 @@ public abstract class ArrayUtil
         return (original == null) ? null : (Object[]) original.clone();
     }
 
-    /** Copy an array of strings; the original array could be null */
+    /** Copy a (possibly null) array of strings */
     public  static  String[]    copy( String[] original )
     {
         return (original == null) ? null : (String[]) original.clone();
@@ -60,6 +60,12 @@ public abstract class ArrayUtil
         return (original == null) ? null : (boolean[]) original.clone();
     }
 
+    /** Copy a (possibly null) array of bytes */
+    public  static  byte[]   copy( byte[] original )
+    {
+        return (original == null) ? null : (byte[]) original.clone();
+    }
+
     /** Copy a (possibly null) array of ints */
     public  static  int[]   copy( int[] original )
     {

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/io/FormatableBitSet.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/io/FormatableBitSet.java?rev=1469948&r1=1469947&r2=1469948&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/io/FormatableBitSet.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/io/FormatableBitSet.java
Fri Apr 19 16:39:05 2013
@@ -21,6 +21,7 @@
 
 package org.apache.derby.iapi.services.io;
 
+import org.apache.derby.iapi.services.io.ArrayUtil;
 import org.apache.derby.iapi.services.sanity.SanityManager;
 import org.apache.derby.iapi.util.ReuseFactory;
 
@@ -133,7 +134,7 @@ public final class FormatableBitSet impl
 	 */
 	public FormatableBitSet(byte[] newValue)
 	{
-		value = newValue;
+		value = ArrayUtil.copy( newValue );
 		bitsInLastByte = 8;
 		lengthAsBits = calculateLength(newValue.length);
 	}
@@ -273,7 +274,7 @@ public final class FormatableBitSet impl
 			value = data;
 		}
 
-		return value;
+		return ArrayUtil.copy( value );
 	}
 
 	/**
@@ -746,6 +747,15 @@ public final class FormatableBitSet impl
 		}
 	}
 
+    /**
+     * Copy the bytes from another FormatableBitSet. Assumes that this bit set
+     * is at least as large as the argument's bit set.
+     */
+    public  void    copyFrom( FormatableBitSet that )
+    {
+        System.arraycopy( that.getByteArray(), 0, value, 0, that.getLengthInBytes());
+    }
+
 	/**
 	 * Bitwise AND this FormatableBitSet with another
 	 * FormatableBitSet. The result is stored in this bitset. The

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/io/RegisteredFormatIds.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/io/RegisteredFormatIds.java?rev=1469948&r1=1469947&r2=1469948&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/io/RegisteredFormatIds.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/io/RegisteredFormatIds.java
Fri Apr 19 16:39:05 2013
@@ -41,14 +41,14 @@ package org.apache.derby.iapi.services.i
         </UL>
 */
 
-public interface RegisteredFormatIds {
+public class RegisteredFormatIds {
 
 /* one byte  format identifiers never used
-String[] OneByte = {
+private static final String[] OneByte = {
 };
 */
 
-String[] TwoByte = {
+private static final    String[] TwoByte = {
         /* 0 */         null, // null marker
         /* 1 */         null, // String marker
         /* 2 */         null, // Serializable marker
@@ -535,4 +535,19 @@ String[] TwoByte = {
         /* 474 */       "org.apache.derby.catalog.types.UDTAliasInfo",
         /* 475 */       "org.apache.derby.catalog.types.AggregateAliasInfo",
 };
+
+    /** Return the number of two-byte format ids */
+    public  static  int countTwoByteIDs() { return TwoByte.length; }
+
+    /** Return the class name bound to an index into TwoByte */
+    public  static  String  classNameForTwoByteID( int idx ) { return TwoByte[ idx ]; }
+
+    /**
+     * Set the class name associated with the DECIMAL datatype. When we
+     * stop supporting CDC, we can remove this method.
+     */
+    public  static  void    setDecimalClassName( String decimalClassName )
+    {
+        TwoByte[ StoredFormatIds.SQL_DECIMAL_ID ] = decimalClassName;
+    }
 }

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/DataValueFactoryImpl.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/DataValueFactoryImpl.java?rev=1469948&r1=1469947&r2=1469948&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/DataValueFactoryImpl.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/DataValueFactoryImpl.java
Fri Apr 19 16:39:05 2013
@@ -102,8 +102,7 @@ abstract class DataValueFactoryImpl impl
     		DataValueDescriptor decimalImplementation = getNullDecimal(null);
     		
     		TypeId.decimalImplementation = decimalImplementation;
-    		RegisteredFormatIds.TwoByte[StoredFormatIds.SQL_DECIMAL_ID]
-    									= decimalImplementation.getClass().getName();
+    		RegisteredFormatIds.setDecimalClassName( decimalImplementation.getClass().getName()
);
     		    		
     		// Generate a DECIMAL value represetentation of 0
     		decimalImplementation = decimalImplementation.getNewNull();

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/services/monitor/BaseMonitor.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/services/monitor/BaseMonitor.java?rev=1469948&r1=1469947&r2=1469948&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/services/monitor/BaseMonitor.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/services/monitor/BaseMonitor.java
Fri Apr 19 16:39:05 2013
@@ -602,14 +602,14 @@ abstract class BaseMonitor
 			off = fmtId - StoredFormatIds.MIN_TWO_BYTE_FORMAT_ID;
 			iga = rc2;
 			if (iga == null) {
-				iga = rc2 = new InstanceGetter[RegisteredFormatIds.TwoByte.length];
+				iga = rc2 = new InstanceGetter[ RegisteredFormatIds.countTwoByteIDs() ];
 			}
 
 			ig = iga[off];
 			if (ig != null) {
 				return ig;
 			}
-			className = RegisteredFormatIds.TwoByte[off];
+			className = RegisteredFormatIds.classNameForTwoByteID( off );
 
 		} catch (ArrayIndexOutOfBoundsException aioobe) {
 			className = null;

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/depend/BasicDependencyManager.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/depend/BasicDependencyManager.java?rev=1469948&r1=1469947&r2=1469948&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/depend/BasicDependencyManager.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/depend/BasicDependencyManager.java
Fri Apr 19 16:39:05 2013
@@ -404,9 +404,7 @@ public class BasicDependencyManager impl
 
 									if (tab.getObjectID().equals(td.getObjectID()))
 									{
-										System.arraycopy(affectedCols.getByteArray(), 0, 
-											subsetCols.getByteArray(), 0, 
-											affectedCols.getLengthInBytes());
+                                        subsetCols.copyFrom( affectedCols );
 										subsetCols.and(colMap);
 										if (subsetCols.anySetBit() != -1)
 										{
@@ -424,7 +422,7 @@ public class BasicDependencyManager impl
 					}	// if providingCols == null
 					else
 					{
-						System.arraycopy(affectedCols.getByteArray(), 0, subsetCols.getByteArray(), 0, affectedCols.getLengthInBytes());
+                        subsetCols.copyFrom( affectedCols );
 						subsetCols.and(providingCols);
 						if (subsetCols.anySetBit() == -1)
 							continue;

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/BaseTestCase.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/BaseTestCase.java?rev=1469948&r1=1469947&r2=1469948&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/BaseTestCase.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/BaseTestCase.java Fri Apr
19 16:39:05 2013
@@ -470,11 +470,47 @@ public abstract class BaseTestCase
     
     /**
      * <p>
+     * Assert the equivalence of two byte arrays.
+     * </p>
+     */
+    public  static  void    assertEquals( byte[] expected, byte[] actual )
+    {
+        if ( assertSameNullness( expected, actual ) ) { return; }
+        
+        assertEquals( expected.length, actual.length );
+        for ( int i = 0; i < expected.length; i++ )
+        {
+            assertEquals( Integer.toString( i ), expected[ i ], actual[ i ] );
+        }
+    }
+
+    /**
+     * Assert that two objects are either both null or neither null.
+     * Returns true if they are null.
+     */
+    public  static  boolean assertSameNullness( Object expected, Object actual )
+    {
+        if ( expected ==  null )
+        {
+            assertNull( actual );
+            return true;
+        }
+        else
+        {
+            assertNotNull( actual );
+            return false;
+        }
+    }
+
+    /**
+     * <p>
      * Assert the equivalence of two int arrays.
      * </p>
      */
     public  static  void    assertEquals( int[] expected, int[] actual )
     {
+        if ( assertSameNullness( expected, actual ) ) { return; }
+        
         assertEquals( expected.length, actual.length );
         for ( int i = 0; i < expected.length; i++ )
         {
@@ -489,6 +525,8 @@ public abstract class BaseTestCase
      */
     public  static  void    assertEquals( long[] expected, long[] actual )
     {
+        if ( assertSameNullness( expected, actual ) ) { return; }
+        
         assertEquals( expected.length, actual.length );
         for ( int i = 0; i < expected.length; i++ )
         {

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/unitTests/junit/FormatableBitSetTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/unitTests/junit/FormatableBitSetTest.java?rev=1469948&r1=1469947&r2=1469948&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/unitTests/junit/FormatableBitSetTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/unitTests/junit/FormatableBitSetTest.java
Fri Apr 19 16:39:05 2013
@@ -1,6 +1,6 @@
 /*
 
-   Derby - Class org.apache.derbyTesting.unitTests.junit.FormatableBitSet
+   Derby - Class org.apache.derbyTesting.unitTests.junit.FormatableBitSetTest
 
    Licensed to the Apache Software Foundation (ASF) under one or more
    contributor license agreements.  See the NOTICE file distributed with



Mime
View raw message