db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kahat...@apache.org
Subject svn commit: r1428305 - in /db/derby/code/trunk/java/engine/org/apache/derby/iapi/types: CollationElementsInterface.java CollatorSQLChar.java CollatorSQLClob.java CollatorSQLLongvarchar.java CollatorSQLVarchar.java WorkHorseForCollatorDatatypes.java
Date Thu, 03 Jan 2013 11:50:03 GMT
Author: kahatlen
Date: Thu Jan  3 11:50:03 2013
New Revision: 1428305

URL: http://svn.apache.org/viewvc?rev=1428305&view=rev
Log:
DERBY-2699: Change how collation elements for ESCAPE clause are calculated

Since we only need to know whether or not there is a single collation
element, just look at the first two elements to see if we have none, one
or many.

Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/CollationElementsInterface.java
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/CollatorSQLChar.java
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/CollatorSQLClob.java
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/CollatorSQLLongvarchar.java
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/CollatorSQLVarchar.java
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/WorkHorseForCollatorDatatypes.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/CollationElementsInterface.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/CollationElementsInterface.java?rev=1428305&r1=1428304&r2=1428305&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/CollationElementsInterface.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/CollationElementsInterface.java
Thu Jan  3 11:50:03 2013
@@ -31,22 +31,13 @@ import org.apache.derby.iapi.error.Stand
  */
 interface CollationElementsInterface
 {
-	/**
-	 * This method translates the string into a series of collation elements.
-	 * These elements will get used in the like method.
-	 * 
-	 * @return an array of collation elements for the string
-	 * @throws StandardException
-	 */
-	public int[] getCollationElementsForString() throws StandardException; 
-
-	/**
-	 * This method returns the count of collation elements for this instance of
-	 * CollationElementsInterface. This method will return the correct value only if  
-	 * method getCollationElementsForString has been called previously on this 
-	 * instance of CollationElementsInterface. 
-	 *
-	 * @return count of collation elements for this instance of CollatorSQLChar
-	 */
-	public int getCountOfCollationElements();
+    /**
+     * Check if this instance represents a value that has a single
+     * collation element.
+     *
+     * @return {@code true} if the value has exactly one collation element,
+     * or {@code false} otherwise
+     * @throws StandardException if an error occurs when accessing the value
+     */
+    boolean hasSingleCollationElement() throws StandardException;
 }

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/CollatorSQLChar.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/CollatorSQLChar.java?rev=1428305&r1=1428304&r2=1428305&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/CollatorSQLChar.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/CollatorSQLChar.java Thu Jan
 3 11:50:03 2013
@@ -86,18 +86,12 @@ class CollatorSQLChar extends SQLChar im
 	{
 		return holderForCollationSensitiveInfo.getCollatorForCollation();
 	}
-	
-	/** @see CollationElementsInterface#getCollationElementsForString */
-	public int[] getCollationElementsForString() throws StandardException 
-	{
-		return holderForCollationSensitiveInfo.getCollationElementsForString();
-	}
 
-	/** @see CollationElementsInterface#getCountOfCollationElements */
-	public int getCountOfCollationElements()
-	{
-		return holderForCollationSensitiveInfo.getCountOfCollationElements();
-	}
+    // Implementation of CollationElementsInterface interface
+
+    public boolean hasSingleCollationElement() throws StandardException {
+        return holderForCollationSensitiveInfo.hasSingleCollationElement();
+    }
 
 	/*
 	 * DataValueDescriptor interface

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/CollatorSQLClob.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/CollatorSQLClob.java?rev=1428305&r1=1428304&r2=1428305&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/CollatorSQLClob.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/CollatorSQLClob.java Thu Jan
 3 11:50:03 2013
@@ -100,17 +100,11 @@ class CollatorSQLClob extends SQLClob im
 		return holderForCollationSensitiveInfo.getCollatorForCollation();
 	}
 	
-	/** @see CollationElementsInterface#getCollationElementsForString */
-	public int[] getCollationElementsForString() throws StandardException 
-	{
-		return holderForCollationSensitiveInfo.getCollationElementsForString();
-	}
+    // Implementation of CollationElementsInterface interface
 
-	/** @see CollationElementsInterface#getCountOfCollationElements */
-	public int getCountOfCollationElements()
-	{
-		return holderForCollationSensitiveInfo.getCountOfCollationElements();
-	}
+    public boolean hasSingleCollationElement() throws StandardException {
+        return holderForCollationSensitiveInfo.hasSingleCollationElement();
+    }
 
 	/*
 	 * DataValueDescriptor interface

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/CollatorSQLLongvarchar.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/CollatorSQLLongvarchar.java?rev=1428305&r1=1428304&r2=1428305&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/CollatorSQLLongvarchar.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/CollatorSQLLongvarchar.java
Thu Jan  3 11:50:03 2013
@@ -89,17 +89,11 @@ class CollatorSQLLongvarchar extends SQL
 		return holderForCollationSensitiveInfo.getCollatorForCollation();
 	}
 	
-	/** @see CollationElementsInterface#getCollationElementsForString */
-	public int[] getCollationElementsForString() throws StandardException 
-	{
-		return holderForCollationSensitiveInfo.getCollationElementsForString();
-	}
+    // Implementation of CollationElementsInterface interface
 
-	/** @see CollationElementsInterface#getCountOfCollationElements */
-	public int getCountOfCollationElements()
-	{
-		return holderForCollationSensitiveInfo.getCountOfCollationElements();
-	}
+    public boolean hasSingleCollationElement() throws StandardException {
+        return holderForCollationSensitiveInfo.hasSingleCollationElement();
+    }
 
 	/*
 	 * DataValueDescriptor interface

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/CollatorSQLVarchar.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/CollatorSQLVarchar.java?rev=1428305&r1=1428304&r2=1428305&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/CollatorSQLVarchar.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/CollatorSQLVarchar.java Thu
Jan  3 11:50:03 2013
@@ -88,17 +88,11 @@ class CollatorSQLVarchar extends SQLVarc
 		return holderForCollationSensitiveInfo.getCollatorForCollation();
 	}
 	
-	/** @see CollationElementsInterface#getCollationElementsForString */
-	public int[] getCollationElementsForString() throws StandardException 
-	{
-		return holderForCollationSensitiveInfo.getCollationElementsForString();
-	}
+    // Implementation of CollationElementsInterface interface
 
-	/** @see CollationElementsInterface#getCountOfCollationElements */
-	public int getCountOfCollationElements()
-	{
-		return holderForCollationSensitiveInfo.getCountOfCollationElements();
-	}
+    public boolean hasSingleCollationElement() throws StandardException {
+        return holderForCollationSensitiveInfo.hasSingleCollationElement();
+    }
 
 	/*
 	 * DataValueDescriptor interface

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/WorkHorseForCollatorDatatypes.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/WorkHorseForCollatorDatatypes.java?rev=1428305&r1=1428304&r2=1428305&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/WorkHorseForCollatorDatatypes.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/types/WorkHorseForCollatorDatatypes.java
Thu Jan  3 11:50:03 2013
@@ -21,9 +21,6 @@
 
 package org.apache.derby.iapi.types;
 
-import org.apache.derby.iapi.types.DataValueDescriptor;
-import org.apache.derby.iapi.types.BooleanDataValue;
-
 import org.apache.derby.iapi.reference.SQLState;
 
 import org.apache.derby.iapi.error.StandardException;
@@ -57,21 +54,6 @@ final class WorkHorseForCollatorDatatype
 	 * This SQLChar object is passed as a parameter to the constructor.
 	 */
 	private SQLChar stringData;
-	/**
-	 * Following is the array holding a series of collation elements for the
-	 * string. It will be used in the like method. This gets initialized when
-	 * the like method is first invoked. 
-	 */
-	private int[]	collationElementsForString;
-	/** 
-	 * Number of valid collation elements in the array above. Note that this 
-	 * might be smaller than the actual size of the array above. Gets 
-	 * initialized when the like method is first invoked.
-	 */
-	private int		countOfCollationElements;
-
-	// For null strings, cKey = null.
-	private CollationKey cKey; 
 
 	WorkHorseForCollatorDatatypes(
 			RuleBasedCollator collatorForCharacterDatatypes,
@@ -171,8 +153,7 @@ final class WorkHorseForCollatorDatatype
 
 		CollationElementsInterface escapeCharacter = (CollationElementsInterface) escape;
 
-		if (escapeCharacter.getCollationElementsForString() != null && 
-				(escapeCharacter.getCountOfCollationElements() != 1))
+		if (!escapeCharacter.hasSingleCollationElement())
 		{
 			throw StandardException.newException(SQLState.LANG_INVALID_ESCAPE_CHARACTER,
 					escapeCharacter.toString());
@@ -199,87 +180,23 @@ final class WorkHorseForCollatorDatatype
 		return(collatorForCharacterDatatypes);
 	}
 
-	/**
-	 * This method returns the count of collation elements for SQLChar object.
-	 * It method will return the correct value only if method   
-	 * getCollationElementsForString has been called previously on the SQLChar
-	 * object. 
-	 *
-	 * @return count of collation elements for this instance of CollatorSQLChar
-	 */
-	int getCountOfCollationElements()
-	{
-		return countOfCollationElements;
-	}
-
-	/**
-	 * This method translates the string into a series of collation elements.
-	 * These elements will get used in the like method.
-	 * 
-	 * @return an array of collation elements for the string
-	 * @throws StandardException
-	 */
-	int[] getCollationElementsForString()
-		throws StandardException
-	{
-		if (stringData.isNull())
-		{
-			return (int[]) null;
-		}
-
-
-
-        // Caching of collationElementsForString is not working properly, in 
-        // order to cache it needs to get invalidated everytime the container
-        // type's value is changed - through any interface, eg: readExternal, 
-        // setValue, ...  To get proper behavior, disabling caching, and will
-        // file a performance enhancement to implement correct caching.
-        collationElementsForString = null;
-        countOfCollationElements   = 0;
-
+    /**
+     * Check if the string consists of a single collation element.
+     * @return {@code true} iff it's a single collation element
+     * @see CollationElementsInterface#hasSingleCollationElement()
+     */
+    boolean hasSingleCollationElement() throws StandardException {
+        if (stringData.isNull()) {
+            return false;
+        }
 
-		if (collationElementsForString != null)
-		{
-			return collationElementsForString;
-		}
-
-		// countOfCollationElements should always be 0 when 
-        // collationElementsForString is null
-		if (SanityManager.DEBUG)
-		{
-			if (countOfCollationElements != 0)
-			{
-				SanityManager.THROWASSERT(
-					"countOfCollationElements expected to be 0, not " + 
-                    countOfCollationElements);
-			}
-		}
-        
-
-		collationElementsForString = new int[stringData.getLength()];
-
-		CollationElementIterator cei = 
+        CollationElementIterator cei =
             collatorForCharacterDatatypes.getCollationElementIterator(
                 stringData.getString());
 
-		int nextInt;
-		while ((nextInt = cei.next()) != CollationElementIterator.NULLORDER)
-		{
-			/* Believe it or not, a String might have more
-			 * collation elements than characters.
-			 * So, we handle that case by increasing the int array
-			 * by 5 and copying array elements.
-			 */
-			if (countOfCollationElements == collationElementsForString.length)
-			{
-				int[] expandedArray = new int[countOfCollationElements + 5];
-				System.arraycopy(collationElementsForString, 0, expandedArray, 
-						0, collationElementsForString.length);
-				collationElementsForString = expandedArray;
-			}
-			collationElementsForString[countOfCollationElements++] = nextInt;
-		}
-
-		return collationElementsForString;
-	}
+        // First call next() to see that there is at least one element, and
+        // then call next() to see that there is no more than one element.
+        return cei.next() != CollationElementIterator.NULLORDER &&
+                cei.next() == CollationElementIterator.NULLORDER;
+    }
 }



Mime
View raw message