db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rhille...@apache.org
Subject svn commit: r648232 - in /db/derby/code/trunk/java/engine/org/apache/derby: iapi/services/io/FormatIdUtil.java impl/sql/compile/FromVTI.java impl/sql/execute/VTIResultSet.java
Date Tue, 15 Apr 2008 13:06:16 GMT
Author: rhillegas
Date: Tue Apr 15 06:06:10 2008
New Revision: 648232

URL: http://svn.apache.org/viewvc?rev=648232&view=rev
Log:
DERBY-3616: Devise a platform-independent encoding for passing the Table Function signature
from the compiler to the execution machinery.

Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/io/FormatIdUtil.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/FromVTI.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/VTIResultSet.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/io/FormatIdUtil.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/io/FormatIdUtil.java?rev=648232&r1=648231&r2=648232&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/io/FormatIdUtil.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/io/FormatIdUtil.java Tue
Apr 15 06:06:10 2008
@@ -48,6 +48,11 @@
  */
 public final class FormatIdUtil
 {
+	private	static	final	int		BYTE_MASK = 0xFF;
+	private	static	final	int		NIBBLE_MASK = 0xF;
+	private	static	final	int		NIBBLE_SHIFT = 4;
+	private	static	final	int		HEX_RADIX = 16;
+
 	private FormatIdUtil() {
 	}
 
@@ -76,4 +81,61 @@
 
 		return Integer.toString(fmtId);
 	}
+
+	/**
+	 * <p>
+	 * Encode a byte array as a string.
+	 * </p>
+	 */
+	public	static	String	toString( byte[] written, int count )
+	{
+		char[]	chars = new char[ count * 2 ];
+		int		charIdx = 0;
+
+		for ( int i = 0; i < count; i++ )
+		{
+			int		current = written[ i ] & BYTE_MASK;
+			int		lowNibble = current & NIBBLE_MASK;
+			int		highNibble = current >>> NIBBLE_SHIFT;
+
+			chars[ charIdx++ ] = encodeNibble( lowNibble );
+			chars[ charIdx++ ] = encodeNibble( highNibble );
+		}
+
+		return new String( chars );
+	}
+
+	/**
+	 * <p>
+	 * Decode a byte array which had been encoded as a string.
+	 * </p>
+	 */
+	public	static	byte[]	fromString( String objString )
+	{
+		char[]	chars = objString.toCharArray();
+		int		count = chars.length;
+		byte[]	bytes = new byte[ count / 2 ];
+		int		byteIdx = 0;
+
+		for ( int i = 0; i < count; i = i + 2 )
+		{
+			int lowNibble = decodeNibble( chars[ i ] );
+			int highNibble = decodeNibble( chars[ i + 1 ] );
+
+			bytes[ byteIdx++ ] = (byte) ( ( highNibble << NIBBLE_SHIFT ) | lowNibble );
+		}
+
+		return bytes;
+	}
+
+	private	static	char	encodeNibble( int nibble )
+	{
+		return Character.forDigit( nibble, HEX_RADIX );
+	}
+
+	private	static	int		decodeNibble( char c )
+	{
+		return Character.digit( c, HEX_RADIX );
+	}
+    
 }

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/FromVTI.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/FromVTI.java?rev=648232&r1=648231&r2=648232&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/FromVTI.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/compile/FromVTI.java Tue Apr
15 06:06:10 2008
@@ -23,6 +23,7 @@
 
 import org.apache.derby.iapi.services.io.DynamicByteArrayOutputStream;
 import org.apache.derby.iapi.services.io.FormatIdOutputStream;
+import org.apache.derby.iapi.services.io.FormatIdUtil;
 import org.apache.derby.iapi.services.loader.ClassInspector;
 import org.apache.derby.iapi.services.loader.GeneratedMethod;
 
@@ -1702,13 +1703,17 @@
             dbaos.flush();
 
             byte[]      rawResult = dbaos.getByteArray();
+            int         count = dbaos.getUsed();
 
-            return new String( rawResult );
+            String  retval = FormatIdUtil.toString( rawResult, count );
+
+            return retval;
             
         } catch (Throwable t)
         {
             throw StandardException.unexpectedUserException( t );
         }
     }
-    
+
+   
 }

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/VTIResultSet.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/VTIResultSet.java?rev=648232&r1=648231&r2=648232&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/VTIResultSet.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/VTIResultSet.java Tue
Apr 15 06:06:10 2008
@@ -49,6 +49,7 @@
 import org.apache.derby.iapi.error.StandardException;
 
 import org.apache.derby.iapi.services.io.FormatIdInputStream;
+import org.apache.derby.iapi.services.io.FormatIdUtil;
 import org.apache.derby.iapi.services.loader.GeneratedMethod;
 
 import org.apache.derby.iapi.types.RowLocation;
@@ -690,7 +691,7 @@
         throws StandardException
     {
         try {
-            byte[]                                          bytes = ice.getBytes();
+            byte[]                                          bytes = FormatIdUtil.fromString(
ice );
             ByteArrayInputStream                    bais = new ByteArrayInputStream( bytes
);
             FormatIdInputStream                     fiis = new FormatIdInputStream( bais
);
             TypeDescriptor                              td = (TypeDescriptor) fiis.readObject();
@@ -785,6 +786,5 @@
             
         vsdv.setWidth( dtd.getPrecision(), dtd.getScale(), false );
     }
-    
     
 }



Mime
View raw message