db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rhille...@apache.org
Subject svn commit: r1606719 - in /db/derby/code/trunk/java: engine/org/apache/derby/loc/ optional/org/apache/derby/optional/lucene/ shared/org/apache/derby/shared/common/reference/ testing/org/apache/derbyTesting/functionTests/tests/lang/
Date Mon, 30 Jun 2014 13:04:24 GMT
Author: rhillegas
Date: Mon Jun 30 13:04:24 2014
New Revision: 1606719

URL: http://svn.apache.org/r1606719
Log:
DERBY-590: Add checks for legal field names for Lucene indexes; commit derby-590-32-aa-vetFieldNames.diff.

Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/loc/messages.xml
    db/derby/code/trunk/java/optional/org/apache/derby/optional/lucene/LuceneSupport.java
    db/derby/code/trunk/java/shared/org/apache/derby/shared/common/reference/SQLState.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/LuceneSupportPermsTest.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/loc/messages.xml
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/loc/messages.xml?rev=1606719&r1=1606718&r2=1606719&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/loc/messages.xml (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/loc/messages.xml Mon Jun 30 13:04:24
2014
@@ -2423,6 +2423,18 @@ Guide.
                 <arg>argumentName</arg>
             </msg>
 
+	        <msg>
+                <name>42XBN</name>
+                <text>A field and a key have the same name: '{0}'</text>
+                <arg>fieldName</arg>
+            </msg>
+
+	        <msg>
+                <name>42XBO</name>
+                <text>Duplicate or null field name: '{0}'</text>
+                <arg>fieldName</arg>
+            </msg>
+
             <msg>
                 <name>42Y00</name>
                 <text>Class '{0}' does not implement org.apache.derby.iapi.db.AggregateDefinition
and thus cannot be used as an aggregate expression.</text>

Modified: db/derby/code/trunk/java/optional/org/apache/derby/optional/lucene/LuceneSupport.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/optional/org/apache/derby/optional/lucene/LuceneSupport.java?rev=1606719&r1=1606718&r2=1606719&view=diff
==============================================================================
--- db/derby/code/trunk/java/optional/org/apache/derby/optional/lucene/LuceneSupport.java
(original)
+++ db/derby/code/trunk/java/optional/org/apache/derby/optional/lucene/LuceneSupport.java
Mon Jun 30 13:04:24 2014
@@ -43,6 +43,7 @@ import java.sql.Timestamp;
 import java.sql.Types;
 import java.util.Arrays;
 import java.util.ArrayList;
+import java.util.HashSet;
 import java.util.Properties;
 
 import org.apache.derby.database.Database;
@@ -490,6 +491,9 @@ public class LuceneSupport implements Op
         String[]  fieldNames = indexDescriptor.getFieldNames();
         Analyzer    analyzer = indexDescriptor.getAnalyzer();
 
+        // make sure the field names don't overlap with the key names
+        sortAndVetFieldNames( fieldNames, primaryKeys );
+
         Properties  indexProperties = new Properties();
         indexProperties.setProperty( LUCENE_VERSION, luceneVersion.toString() );
         indexProperties.setProperty( UPDATE_TIMESTAMP, Long.toString( System.currentTimeMillis()
) );
@@ -592,6 +596,41 @@ public class LuceneSupport implements Op
         checkNotNull( "TABLENAME", table );
         checkNotNull( "TEXTCOLUMN", textcol );
     }
+
+    /**
+     * Raise an exception if a field has the same name as a key or if two
+     * fields have the same name.
+     */
+    private static  void    sortAndVetFieldNames( String[] fieldNames, VTITemplate.ColumnDescriptor[]
keys )
+        throws SQLException
+    {
+        for ( String fieldName : fieldNames )
+        {
+            if ( fieldName == null )
+            {
+                throw newSQLException( SQLState.LUCENE_DUPLICATE_FIELD_NAME, fieldName );
+            }
+        }
+        Arrays.sort( fieldNames );
+        
+        HashSet<String>   keyNames = new HashSet<String>();
+        for ( VTITemplate.ColumnDescriptor cd : keys ) { keyNames.add( cd.columnName ); }
+
+        String  previousFieldName = null;
+        for ( String fieldName : fieldNames )
+        {
+            if ( fieldName.equals( previousFieldName ) )
+            {
+                throw newSQLException( SQLState.LUCENE_DUPLICATE_FIELD_NAME, fieldName );
+            }
+            previousFieldName = fieldName;
+
+            if ( keyNames.contains( fieldName ) )
+            {
+                throw newSQLException( SQLState.LUCENE_FIELD_KEY_CONFLICT, fieldName );
+            }
+        }
+    }
     
     /////////////////////////////////////////////////////////////////////
     //

Modified: db/derby/code/trunk/java/shared/org/apache/derby/shared/common/reference/SQLState.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/shared/org/apache/derby/shared/common/reference/SQLState.java?rev=1606719&r1=1606718&r2=1606719&view=diff
==============================================================================
--- db/derby/code/trunk/java/shared/org/apache/derby/shared/common/reference/SQLState.java
(original)
+++ db/derby/code/trunk/java/shared/org/apache/derby/shared/common/reference/SQLState.java
Mon Jun 30 13:04:24 2014
@@ -1193,6 +1193,8 @@ public interface SQLState {
     String LUCENE_BAD_VERSION                                           = "42XBK";
     String LUCENE_ENCRYPTED_DB                                           = "42XBL";
     String ARGUMENT_MAY_NOT_BE_NULL                                = "42XBM";
+    String LUCENE_FIELD_KEY_CONFLICT                                = "42XBN";
+    String LUCENE_DUPLICATE_FIELD_NAME                                = "42XBO";
     
 	// org.apache.derby.impl.sql.execute.rts
 	String RTS_ATTACHED_TO											   = "43X00.U";

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/LuceneSupportPermsTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/LuceneSupportPermsTest.java?rev=1606719&r1=1606718&r2=1606719&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/LuceneSupportPermsTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/LuceneSupportPermsTest.java
Mon Jun 30 13:04:24 2014
@@ -105,6 +105,8 @@ public class LuceneSupportPermsTest exte
     private static  final   String      NONEXISTENT_TABLE_FUNCTION  ="42ZB4";
     private static  final   String      INCOMPATIBLE_ENCRYPTION = "42XBL";
     private static  final   String      ILLEGAL_NULL_ARG = "42XBM";
+    private static  final   String      BAD_FIELD_NAME = "42XBN";
+    private static  final   String      DUPLICATE_FIELD_NAME = "42XBO";
     private static  final   String      NULL_PRIMITIVE_ARG = "39004";
 
     private static  final   String      POLICY_FILE = "org/apache/derbyTesting/functionTests/tests/lang/luceneSupport.policy";
@@ -131,6 +133,8 @@ public class LuceneSupportPermsTest exte
     //
     ///////////////////////////////////////////////////////////////////////////////////
 
+    static  String[]    _fieldNames;
+
     ///////////////////////////////////////////////////////////////////////////////////
     //
     // CONSTRUCTOR
@@ -1026,6 +1030,54 @@ public class LuceneSupportPermsTest exte
     
    /**
      * <p>
+     * Test restrictions on field names.
+     * </p>
+     */
+    public  void    test_011_fieldNames()
+        throws Exception
+    {
+        Connection  dboConnection = openUserConnection( TEST_DBO );
+        Connection  ruthConnection = openUserConnection( RUTH );
+
+        loadTestTable( ruthConnection );
+        goodStatement( dboConnection, LOAD_TOOL );
+
+        String  indexTestTable =
+            "call LuceneSupport.createIndex\n" +
+            "(\n" +
+            "    'ruth', 'textTable', 'textCol',\n" +
+            "    'org.apache.derbyTesting.functionTests.tests.lang.LuceneSupportPermsTest.makeFieldNameIndexDescriptor'\n"
+
+            ")\n";
+        
+        goodStatement
+            (
+             ruthConnection,
+             "create procedure setFieldNames( fieldName varchar( 32672 )... )\n" +
+             "language java parameter style derby no sql\n" +
+             "external name 'org.apache.derbyTesting.functionTests.tests.lang.LuceneSupportPermsTest.setFieldNames'\n"
+             );
+
+        // Field and key name conflict.
+        goodStatement( ruthConnection, "call setFieldNames( 'KEYCOL' )" );
+        expectExecutionError( ruthConnection, BAD_FIELD_NAME, indexTestTable );
+
+        // Duplicate field names.
+        goodStatement( ruthConnection, "call setFieldNames( 'FOO', 'FOO' )" );
+        expectExecutionError( ruthConnection, DUPLICATE_FIELD_NAME, indexTestTable );
+
+        // Null field name.
+        goodStatement( ruthConnection, "call setFieldNames( 'FOO', null )" );
+        expectExecutionError( ruthConnection, DUPLICATE_FIELD_NAME, indexTestTable );
+        goodStatement( ruthConnection, "call setFieldNames( null, 'FOO' )" );
+        expectExecutionError( ruthConnection, DUPLICATE_FIELD_NAME, indexTestTable );
+
+        goodStatement( ruthConnection, "drop procedure setFieldNames" );
+        goodStatement( dboConnection, UNLOAD_TOOL );
+        unloadTestTable( ruthConnection );
+    }
+
+   /**
+     * <p>
      * Test that nulls are allowed in keys. See DERBY-6602.
      * </p>
      */
@@ -1500,6 +1552,10 @@ public class LuceneSupportPermsTest exte
              );
     }
 
+    public  static  void    setFieldNames( String... fieldNames ) { _fieldNames = fieldNames;
}
+
+    public  static  LuceneIndexDescriptor   makeFieldNameIndexDescriptor() { return new FieldNameIndexDescriptor();
}
+
     ///////////////////////////////////////////////////////////////////////////////////
     //
     // NESTED CLASSES
@@ -1554,4 +1610,10 @@ public class LuceneSupportPermsTest exte
         }
     }
 
+    public  static  class   FieldNameIndexDescriptor extends LuceneUtils.DefaultIndexDescriptor
+    {
+        public  FieldNameIndexDescriptor() { super(); }
+        public  String[]    getFieldNames() { return LuceneSupportPermsTest._fieldNames;
}
+    }
+    
 }



Mime
View raw message