db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rhille...@apache.org
Subject svn commit: r1693818 - in /db/derby/code/trunk/java: build/org/apache/derbyBuild/lastgoodjarcontents/ optional/org/apache/derby/optional/api/ optional/org/apache/derby/optional/json/ optional/org/apache/derby/optional/lucene/ optional/org/apache/derby/...
Date Sun, 02 Aug 2015 17:33:17 GMT
Author: rhillegas
Date: Sun Aug  2 17:33:17 2015
New Revision: 1693818

URL: http://svn.apache.org/r1693818
Log:
DERBY-6825: Grant public privileges to the users of the UDT and FUNCTIONS created by the simpleJson optional tool. Tests passed cleanly for me on derby-6825-04-aa-grantPrivileges.diff.

Added:
    db/derby/code/trunk/java/optional/org/apache/derby/optional/utils/
    db/derby/code/trunk/java/optional/org/apache/derby/optional/utils/ToolUtilities.java   (with props)
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/SimpleJsonPermsTest.java   (with props)
Modified:
    db/derby/code/trunk/java/build/org/apache/derbyBuild/lastgoodjarcontents/insane.derbyTesting.jar.lastcontents
    db/derby/code/trunk/java/build/org/apache/derbyBuild/lastgoodjarcontents/insane.derbyoptionaltools.jar.lastcontents
    db/derby/code/trunk/java/build/org/apache/derbyBuild/lastgoodjarcontents/sane.derbyTesting.jar.lastcontents
    db/derby/code/trunk/java/build/org/apache/derbyBuild/lastgoodjarcontents/sane.derbyoptionaltools.jar.lastcontents
    db/derby/code/trunk/java/optional/org/apache/derby/optional/api/LuceneUtils.java
    db/derby/code/trunk/java/optional/org/apache/derby/optional/api/SimpleJsonUtils.java
    db/derby/code/trunk/java/optional/org/apache/derby/optional/api/SimpleJsonVTI.java
    db/derby/code/trunk/java/optional/org/apache/derby/optional/json/SimpleJsonTool.java
    db/derby/code/trunk/java/optional/org/apache/derby/optional/lucene/DerbyLuceneDir.java
    db/derby/code/trunk/java/optional/org/apache/derby/optional/lucene/LuceneListIndexesVTI.java
    db/derby/code/trunk/java/optional/org/apache/derby/optional/lucene/LuceneQueryVTI.java
    db/derby/code/trunk/java/optional/org/apache/derby/optional/lucene/LuceneSupport.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/JsonSuite.java

Modified: db/derby/code/trunk/java/build/org/apache/derbyBuild/lastgoodjarcontents/insane.derbyTesting.jar.lastcontents
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/build/org/apache/derbyBuild/lastgoodjarcontents/insane.derbyTesting.jar.lastcontents?rev=1693818&r1=1693817&r2=1693818&view=diff
==============================================================================
--- db/derby/code/trunk/java/build/org/apache/derbyBuild/lastgoodjarcontents/insane.derbyTesting.jar.lastcontents (original)
+++ db/derby/code/trunk/java/build/org/apache/derbyBuild/lastgoodjarcontents/insane.derbyTesting.jar.lastcontents Sun Aug  2 17:33:17 2015
@@ -435,6 +435,7 @@ org.apache.derbyTesting.functionTests.te
 org.apache.derbyTesting.functionTests.tests.lang.SequencePermsTest.class
 org.apache.derbyTesting.functionTests.tests.lang.SequenceTest.class
 org.apache.derbyTesting.functionTests.tests.lang.ShutdownDatabaseTest.class
+org.apache.derbyTesting.functionTests.tests.lang.SimpleJsonPermsTest.class
 org.apache.derbyTesting.functionTests.tests.lang.SimpleJsonTest.class
 org.apache.derbyTesting.functionTests.tests.lang.SimpleTest.class
 org.apache.derbyTesting.functionTests.tests.lang.SpillHashTest.class

Modified: db/derby/code/trunk/java/build/org/apache/derbyBuild/lastgoodjarcontents/insane.derbyoptionaltools.jar.lastcontents
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/build/org/apache/derbyBuild/lastgoodjarcontents/insane.derbyoptionaltools.jar.lastcontents?rev=1693818&r1=1693817&r2=1693818&view=diff
==============================================================================
--- db/derby/code/trunk/java/build/org/apache/derbyBuild/lastgoodjarcontents/insane.derbyoptionaltools.jar.lastcontents (original)
+++ db/derby/code/trunk/java/build/org/apache/derbyBuild/lastgoodjarcontents/insane.derbyoptionaltools.jar.lastcontents Sun Aug  2 17:33:17 2015
@@ -9,3 +9,4 @@ org.apache.derby.optional.lucene.DerbyLu
 org.apache.derby.optional.lucene.LuceneListIndexesVTI.class
 org.apache.derby.optional.lucene.LuceneQueryVTI.class
 org.apache.derby.optional.lucene.LuceneSupport.class
+org.apache.derby.optional.utils.ToolUtilities.class

Modified: db/derby/code/trunk/java/build/org/apache/derbyBuild/lastgoodjarcontents/sane.derbyTesting.jar.lastcontents
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/build/org/apache/derbyBuild/lastgoodjarcontents/sane.derbyTesting.jar.lastcontents?rev=1693818&r1=1693817&r2=1693818&view=diff
==============================================================================
--- db/derby/code/trunk/java/build/org/apache/derbyBuild/lastgoodjarcontents/sane.derbyTesting.jar.lastcontents (original)
+++ db/derby/code/trunk/java/build/org/apache/derbyBuild/lastgoodjarcontents/sane.derbyTesting.jar.lastcontents Sun Aug  2 17:33:17 2015
@@ -435,6 +435,7 @@ org.apache.derbyTesting.functionTests.te
 org.apache.derbyTesting.functionTests.tests.lang.SequencePermsTest.class
 org.apache.derbyTesting.functionTests.tests.lang.SequenceTest.class
 org.apache.derbyTesting.functionTests.tests.lang.ShutdownDatabaseTest.class
+org.apache.derbyTesting.functionTests.tests.lang.SimpleJsonPermsTest.class
 org.apache.derbyTesting.functionTests.tests.lang.SimpleJsonTest.class
 org.apache.derbyTesting.functionTests.tests.lang.SimpleTest.class
 org.apache.derbyTesting.functionTests.tests.lang.SpillHashTest.class

Modified: db/derby/code/trunk/java/build/org/apache/derbyBuild/lastgoodjarcontents/sane.derbyoptionaltools.jar.lastcontents
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/build/org/apache/derbyBuild/lastgoodjarcontents/sane.derbyoptionaltools.jar.lastcontents?rev=1693818&r1=1693817&r2=1693818&view=diff
==============================================================================
--- db/derby/code/trunk/java/build/org/apache/derbyBuild/lastgoodjarcontents/sane.derbyoptionaltools.jar.lastcontents (original)
+++ db/derby/code/trunk/java/build/org/apache/derbyBuild/lastgoodjarcontents/sane.derbyoptionaltools.jar.lastcontents Sun Aug  2 17:33:17 2015
@@ -9,3 +9,4 @@ org.apache.derby.optional.lucene.DerbyLu
 org.apache.derby.optional.lucene.LuceneListIndexesVTI.class
 org.apache.derby.optional.lucene.LuceneQueryVTI.class
 org.apache.derby.optional.lucene.LuceneSupport.class
+org.apache.derby.optional.utils.ToolUtilities.class

Modified: db/derby/code/trunk/java/optional/org/apache/derby/optional/api/LuceneUtils.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/optional/org/apache/derby/optional/api/LuceneUtils.java?rev=1693818&r1=1693817&r2=1693818&view=diff
==============================================================================
--- db/derby/code/trunk/java/optional/org/apache/derby/optional/api/LuceneUtils.java (original)
+++ db/derby/code/trunk/java/optional/org/apache/derby/optional/api/LuceneUtils.java Sun Aug  2 17:33:17 2015
@@ -37,6 +37,7 @@ import org.apache.derby.iapi.error.Publi
 import org.apache.derby.iapi.error.StandardException;
 import org.apache.derby.iapi.sql.conn.ConnectionUtil;
 import org.apache.derby.iapi.sql.conn.LanguageConnectionContext;
+import org.apache.derby.optional.utils.ToolUtilities;
 
 /**
  * <p>
@@ -157,10 +158,10 @@ public abstract class LuceneUtils
                 return constructor.newInstance( currentVersion() );
             }
         }
-        catch (IllegalAccessException iae) { throw wrap( iae ); }
-        catch (InstantiationException ie)   { throw wrap( ie ); }
-        catch (InvocationTargetException ite)   { throw wrap( ite ); }
-        catch (NoSuchMethodException nsme)  { throw wrap( nsme ); }
+        catch (IllegalAccessException iae) { throw ToolUtilities.wrap( iae ); }
+        catch (InstantiationException ie)   { throw ToolUtilities.wrap( ie ); }
+        catch (InvocationTargetException ite)   { throw ToolUtilities.wrap( ite ); }
+        catch (NoSuchMethodException nsme)  { throw ToolUtilities.wrap( nsme ); }
     }
 
     /**
@@ -226,18 +227,6 @@ public abstract class LuceneUtils
         return languageCode;
     }
 
-    /** Wrap an external exception */
-    private  static  SQLException    wrap( Throwable t )
-    {
-        return sqlException( StandardException.plainWrapException( t ) );
-    }
-    
-    /** Turn a StandardException into a SQLException */
-    private  static  SQLException    sqlException( StandardException se )
-    {
-        return PublicAPI.wrapStandardException( se );
-    }
-
     /////////////////////////////////////////////////////////////////
     //
     //  NESTED CLASSES

Modified: db/derby/code/trunk/java/optional/org/apache/derby/optional/api/SimpleJsonUtils.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/optional/org/apache/derby/optional/api/SimpleJsonUtils.java?rev=1693818&r1=1693817&r2=1693818&view=diff
==============================================================================
--- db/derby/code/trunk/java/optional/org/apache/derby/optional/api/SimpleJsonUtils.java (original)
+++ db/derby/code/trunk/java/optional/org/apache/derby/optional/api/SimpleJsonUtils.java Sun Aug  2 17:33:17 2015
@@ -47,6 +47,7 @@ import org.json.simple.JSONObject;
 import org.json.simple.parser.JSONParser;
 
 import org.apache.derby.iapi.util.StringUtil;
+import org.apache.derby.optional.utils.ToolUtilities;
 
 /**
  * <p>
@@ -142,7 +143,7 @@ public abstract class SimpleJsonUtils
         try {
             obj = parser.parse( reader );
         }
-        catch( Throwable t) { throw wrap( t ); }
+        catch( Throwable t) { throw ToolUtilities.wrap( t ); }
 
         if ( (obj == null) || !(obj instanceof JSONArray) )
         {
@@ -177,13 +178,13 @@ public abstract class SimpleJsonUtils
         try {
             return readArray( new InputStreamReader( inputStream, characterSetName ) );
         }
-        catch (UnsupportedEncodingException uee) { throw wrap( uee ); }
+        catch (UnsupportedEncodingException uee) { throw ToolUtilities.wrap( uee ); }
         finally
         {
             try {
                 inputStream.close();
             }
-            catch (IOException ioe) { throw wrap( ioe ); }
+            catch (IOException ioe) { throw ToolUtilities.wrap( ioe ); }
         }
     }
 
@@ -209,7 +210,7 @@ public abstract class SimpleJsonUtils
              }
              );
         }
-        catch (PrivilegedActionException pae) { throw wrap( pae ); }
+        catch (PrivilegedActionException pae) { throw ToolUtilities.wrap( pae ); }
 
         return readArrayFromStream( fis, characterSetName );
     }
@@ -237,7 +238,7 @@ public abstract class SimpleJsonUtils
              }
              );
         }
-        catch (PrivilegedActionException pae) { throw wrap( pae ); }
+        catch (PrivilegedActionException pae) { throw ToolUtilities.wrap( pae ); }
         
         return readArrayFromStream( inputStream, characterSetName );
     }
@@ -308,20 +309,4 @@ public abstract class SimpleJsonUtils
         return DriverManager.getConnection( "jdbc:default:connection" );
     }
     
-    /**
-     * <p>
-     * Wrap an exception in a SQLException.
-     * </p>
-     */
-    static SQLException wrap( Throwable t )
-    {
-        String  message = t.getMessage();
-        if ( (message == null) || (message.length() == 0) )
-        {
-            message = t.toString();
-        }
-        
-        return new SQLException( message, t );
-    }
-    
 }

Modified: db/derby/code/trunk/java/optional/org/apache/derby/optional/api/SimpleJsonVTI.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/optional/org/apache/derby/optional/api/SimpleJsonVTI.java?rev=1693818&r1=1693817&r2=1693818&view=diff
==============================================================================
--- db/derby/code/trunk/java/optional/org/apache/derby/optional/api/SimpleJsonVTI.java (original)
+++ db/derby/code/trunk/java/optional/org/apache/derby/optional/api/SimpleJsonVTI.java Sun Aug  2 17:33:17 2015
@@ -33,6 +33,8 @@ import org.json.simple.JSONObject;
 
 import org.apache.derby.vti.VTITemplate;
 
+import org.apache.derby.optional.utils.ToolUtilities;
+
 /**
  * <p>
  * This is a table function which turns a JSON array into a relational
@@ -302,7 +304,7 @@ public class SimpleJsonVTI extends VTITe
         try {
             return new BigDecimal( stringValue );
         }
-        catch (Throwable t) { throw SimpleJsonUtils.wrap( t ); }
+        catch (Throwable t) { throw ToolUtilities.wrap( t ); }
     }
     
     ////////////////////////////////////////////////////////////////////////

Modified: db/derby/code/trunk/java/optional/org/apache/derby/optional/json/SimpleJsonTool.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/optional/org/apache/derby/optional/json/SimpleJsonTool.java?rev=1693818&r1=1693817&r2=1693818&view=diff
==============================================================================
--- db/derby/code/trunk/java/optional/org/apache/derby/optional/json/SimpleJsonTool.java (original)
+++ db/derby/code/trunk/java/optional/org/apache/derby/optional/json/SimpleJsonTool.java Sun Aug  2 17:33:17 2015
@@ -35,6 +35,7 @@ import org.apache.derby.iapi.tools.i18n.
 import org.apache.derby.iapi.util.IdUtil;
 import org.apache.derby.iapi.util.StringUtil;
 import org.apache.derby.optional.api.SimpleJsonUtils;
+import org.apache.derby.optional.utils.ToolUtilities;
 
 /**
  * <p>
@@ -159,6 +160,22 @@ public	class   SimpleJsonTool  implement
 
         createUDT( derbyConn );
         createFunctions( derbyConn );
+        
+        boolean sqlAuthorizationEnabled = ToolUtilities.sqlAuthorizationEnabled( derbyConn );
+        if ( sqlAuthorizationEnabled ) { grantPermissions( derbyConn ); }
+    }
+
+    /**
+     * Grant permissions to use the newly loaded UDT and FUNCTIONs.
+     */
+    private void    grantPermissions( Connection conn )  throws SQLException
+    {
+        executeDDL( conn, "grant usage on type JSONArray to public" );
+
+        for ( FunctionDescriptor desc : _functionDescriptors )
+        {
+            executeDDL( conn, "grant execute on function " + desc.functionName + " to public" );
+        }
     }
 
     /**

Modified: db/derby/code/trunk/java/optional/org/apache/derby/optional/lucene/DerbyLuceneDir.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/optional/org/apache/derby/optional/lucene/DerbyLuceneDir.java?rev=1693818&r1=1693817&r2=1693818&view=diff
==============================================================================
--- db/derby/code/trunk/java/optional/org/apache/derby/optional/lucene/DerbyLuceneDir.java (original)
+++ db/derby/code/trunk/java/optional/org/apache/derby/optional/lucene/DerbyLuceneDir.java Sun Aug  2 17:33:17 2015
@@ -41,6 +41,8 @@ import org.apache.derby.io.StorageFactor
 import org.apache.derby.io.StorageFile;
 import org.apache.derby.shared.common.reference.SQLState;
 
+import org.apache.derby.optional.utils.ToolUtilities;
+
 /**
  * <p>
  * Derby implementation of Lucene Directory.
@@ -343,7 +345,7 @@ class DerbyLuceneDir extends Directory
     /** Make an IOException with the given SQLState and args */
     private IOException newIOException( String sqlState, Object... args )
     {
-        return new IOException( LuceneSupport.newSQLException( sqlState, args ).getMessage() );
+        return new IOException( ToolUtilities.newSQLException( sqlState, args ).getMessage() );
     }
 
     /** Raise an exception if this directory is closed */
@@ -383,7 +385,7 @@ class DerbyLuceneDir extends Directory
              {
                  public StorageFile run() throws SQLException
                  {
-                     String         normalizedName = LuceneSupport.derbyIdentifier( fileName );
+                     String         normalizedName = ToolUtilities.derbyIdentifier( fileName );
                      StorageFile    file = parentDir == null ?
                          storageFactory.newStorageFile( normalizedName  ) :
                          storageFactory.newStorageFile( parentDir, normalizedName );
@@ -391,7 +393,8 @@ class DerbyLuceneDir extends Directory
                      if ( !file.exists() ) { file.mkdir(); }
                      if ( !file.exists() )
                      {
-                         throw LuceneSupport.newSQLException( SQLState.SERVICE_DIRECTORY_CREATE_ERROR, normalizedName );
+                         throw ToolUtilities.newSQLException
+                             ( SQLState.SERVICE_DIRECTORY_CREATE_ERROR, normalizedName );
                      }
                      else { return file; }
                  }

Modified: db/derby/code/trunk/java/optional/org/apache/derby/optional/lucene/LuceneListIndexesVTI.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/optional/org/apache/derby/optional/lucene/LuceneListIndexesVTI.java?rev=1693818&r1=1693817&r2=1693818&view=diff
==============================================================================
--- db/derby/code/trunk/java/optional/org/apache/derby/optional/lucene/LuceneListIndexesVTI.java (original)
+++ db/derby/code/trunk/java/optional/org/apache/derby/optional/lucene/LuceneListIndexesVTI.java Sun Aug  2 17:33:17 2015
@@ -39,6 +39,8 @@ import org.apache.derby.io.StorageFile;
 import org.apache.derby.shared.common.reference.SQLState;
 import org.apache.derby.vti.StringColumnVTI;
 
+import org.apache.derby.optional.utils.ToolUtilities;
+
 /**
  * Provides a table interface to the Lucene indexes in this database.
  * See org.apache.derby.optional.lucene.LuceneSupport.listIndexes.
@@ -146,7 +148,7 @@ class LuceneListIndexesVTI extends Strin
         case 6: return getProperty( LuceneSupport.ANALYZER );
         case 7: return getProperty( LuceneSupport.INDEX_DESCRIPTOR_MAKER );
         default:
-            throw LuceneSupport.newSQLException
+            throw ToolUtilities.newSQLException
                 (
                  SQLState.LANG_INVALID_COLUMN_POSITION,
                  new Integer( col ),
@@ -160,7 +162,7 @@ class LuceneListIndexesVTI extends Strin
     {
         if ( col != 4 )
         {
-            throw LuceneSupport.newSQLException
+            throw ToolUtilities.newSQLException
                 (
                  SQLState.LANG_INVALID_COLUMN_POSITION,
                  new Integer( col ),
@@ -173,7 +175,7 @@ class LuceneListIndexesVTI extends Strin
 
             return new Timestamp( timestampMillis );
         }
-        catch (NumberFormatException nfe) { throw LuceneSupport.wrap( nfe ); }
+        catch (NumberFormatException nfe) { throw ToolUtilities.wrap( nfe ); }
     }
     
     /** Fill in the schema, table, and column names */
@@ -209,8 +211,8 @@ class LuceneListIndexesVTI extends Strin
                 StorageFile    indexPropertiesFile = LuceneSupport.getIndexPropertiesFile( connection, schema, table, delimitedColumnName );
                 rowProperties = readIndexProperties( indexPropertiesFile );
             }
-            catch (IOException ioe) { throw LuceneSupport.wrap( ioe ); }
-            catch (PrivilegedActionException pae) { throw LuceneSupport.wrap( pae ); }
+            catch (IOException ioe) { throw ToolUtilities.wrap( ioe ); }
+            catch (PrivilegedActionException pae) { throw ToolUtilities.wrap( pae ); }
         }
 
         return rowProperties;

Modified: db/derby/code/trunk/java/optional/org/apache/derby/optional/lucene/LuceneQueryVTI.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/optional/org/apache/derby/optional/lucene/LuceneQueryVTI.java?rev=1693818&r1=1693817&r2=1693818&view=diff
==============================================================================
--- db/derby/code/trunk/java/optional/org/apache/derby/optional/lucene/LuceneQueryVTI.java (original)
+++ db/derby/code/trunk/java/optional/org/apache/derby/optional/lucene/LuceneQueryVTI.java Sun Aug  2 17:33:17 2015
@@ -58,6 +58,8 @@ import org.apache.lucene.search.TopScore
 import org.apache.lucene.util.BytesRef;
 import org.apache.lucene.util.Version;
 
+import org.apache.derby.optional.utils.ToolUtilities;
+
 /**
  * A VTI that provides the results of Lucene queries and
  * associated Lucene assigned document ids. 
@@ -154,7 +156,7 @@ class LuceneQueryVTI extends StringColum
 			if ( isKeyID( columnid ) ) { return _searcher.doc( docID ).get( getColumnName( columnid ) ); }
 			else { throw invalidColumnPosition( columnid ); }
 		}
-        catch (IOException e)   { throw LuceneSupport.wrap( e ); }
+        catch (IOException e)   { throw ToolUtilities.wrap( e ); }
 	}
 
     /** Handle boolean columns */
@@ -187,7 +189,7 @@ class LuceneQueryVTI extends StringColum
             }
 			else { throw invalidColumnPosition( columnid ); }
 		}
-        catch (IOException e)   { throw LuceneSupport.wrap( e ); }
+        catch (IOException e)   { throw ToolUtilities.wrap( e ); }
     }
 
     /** Handle double columns */
@@ -203,7 +205,7 @@ class LuceneQueryVTI extends StringColum
             }
 			else { throw invalidColumnPosition( columnid ); }
 		}
-        catch (IOException e)   { throw LuceneSupport.wrap( e ); }
+        catch (IOException e)   { throw ToolUtilities.wrap( e ); }
     }
 
     /** Handle bytecolumns */
@@ -233,7 +235,7 @@ class LuceneQueryVTI extends StringColum
             }
 			else { throw invalidColumnPosition( columnid ); }
 		}
-        catch (IOException e)   { throw LuceneSupport.wrap( e ); }
+        catch (IOException e)   { throw ToolUtilities.wrap( e ); }
     }
     
     /** Handle Date columns */
@@ -251,7 +253,7 @@ class LuceneQueryVTI extends StringColum
             }
 			else { throw invalidColumnPosition( columnid ); }
 		}
-        catch (IOException e)   { throw LuceneSupport.wrap( e ); }
+        catch (IOException e)   { throw ToolUtilities.wrap( e ); }
     }
     
     /** Handle Time columns */
@@ -269,7 +271,7 @@ class LuceneQueryVTI extends StringColum
             }
 			else { throw invalidColumnPosition( columnid ); }
 		}
-        catch (IOException e)   { throw LuceneSupport.wrap( e ); }
+        catch (IOException e)   { throw ToolUtilities.wrap( e ); }
     }
     
     /** Handle Timestamp columns */
@@ -287,7 +289,7 @@ class LuceneQueryVTI extends StringColum
             }
 			else { throw invalidColumnPosition( columnid ); }
 		}
-        catch (IOException e)   { throw LuceneSupport.wrap( e ); }
+        catch (IOException e)   { throw ToolUtilities.wrap( e ); }
     }
     
     /** Handle integer columns */
@@ -308,7 +310,7 @@ class LuceneQueryVTI extends StringColum
             }
 			else { throw invalidColumnPosition( columnid ); }
 		}
-        catch (IOException e)   { throw LuceneSupport.wrap( e ); }
+        catch (IOException e)   { throw ToolUtilities.wrap( e ); }
     }
     private Number getNumberValue( int columnid ) throws IOException
     {
@@ -352,12 +354,12 @@ class LuceneQueryVTI extends StringColum
             }
 			else { throw invalidColumnPosition( columnid ); }
 		}
-        catch (IOException e)   { throw LuceneSupport.wrap( e ); }
+        catch (IOException e)   { throw ToolUtilities.wrap( e ); }
     }
 
     private SQLException    invalidColumnPosition( int columnid )
     {
-        return LuceneSupport.newSQLException
+        return ToolUtilities.newSQLException
             (
              SQLState.LANG_INVALID_COLUMN_POSITION,
              new Integer( columnid ),
@@ -419,7 +421,7 @@ class LuceneQueryVTI extends StringColum
 		try {
 			_indexReader.close();
 		}
-        catch (IOException e) { throw LuceneSupport.wrap( e ); }
+        catch (IOException e) { throw ToolUtilities.wrap( e ); }
         finally
         {
             _indexReader = null;
@@ -479,9 +481,9 @@ class LuceneQueryVTI extends StringColum
 
             searchAndScore( luceneQuery, tsdc );
         }
-        catch (IOException ioe) { throw LuceneSupport.wrap( ioe ); }
-        catch (ParseException pe) { throw LuceneSupport.wrap( pe ); }
-        catch (PrivilegedActionException pae) { throw LuceneSupport.wrap( pae ); }
+        catch (IOException ioe) { throw ToolUtilities.wrap( ioe ); }
+        catch (ParseException pe) { throw ToolUtilities.wrap( pe ); }
+        catch (PrivilegedActionException pae) { throw ToolUtilities.wrap( pae ); }
     }
 
     /**
@@ -503,7 +505,7 @@ class LuceneQueryVTI extends StringColum
 
         if ( (indexVersion == null) || !currentVersion.onOrAfter( indexVersion ) )
         {
-            throw LuceneSupport.newSQLException
+            throw ToolUtilities.newSQLException
                 ( SQLState.LUCENE_BAD_VERSION, currentVersion.toString(), indexVersionString );
         }
     }

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=1693818&r1=1693817&r2=1693818&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 Sun Aug  2 17:33:17 2015
@@ -50,7 +50,6 @@ import org.apache.derby.database.Databas
 import org.apache.derby.iapi.sql.conn.ConnectionUtil;
 import org.apache.derby.iapi.sql.dictionary.DataDictionary;
 import org.apache.derby.iapi.sql.dictionary.OptionalTool;
-import org.apache.derby.iapi.error.PublicAPI;
 import org.apache.derby.iapi.error.StandardException;
 import org.apache.derby.iapi.reference.Property;
 import org.apache.derby.iapi.services.loader.ClassFactory;
@@ -64,6 +63,7 @@ import org.apache.derby.io.StorageFile;
 import org.apache.derby.shared.common.reference.SQLState;
 import org.apache.derby.optional.api.LuceneIndexDescriptor;
 import org.apache.derby.optional.api.LuceneUtils;
+import org.apache.derby.optional.utils.ToolUtilities;
 import org.apache.derby.vti.VTITemplate;
 
 import org.apache.lucene.analysis.Analyzer;
@@ -146,10 +146,10 @@ public class LuceneSupport implements Op
             ConnectionUtil.getCurrentLCC().getDataDictionary().checkVersion
                 ( DataDictionary.DD_VERSION_DERBY_10_11, "luceneSupport" );
         }
-        catch (StandardException se)    { throw sqlException( se ); }
+        catch (StandardException se)    { throw ToolUtilities.sqlException( se ); }
         
         Connection  conn = getDefaultConnection();
-        mustBeDBO( conn );
+        ToolUtilities.mustBeDBO( conn );
 
         //
         // Lucene indexes are not allowed in encrypted databases. They leak
@@ -157,15 +157,15 @@ public class LuceneSupport implements Op
         //
         if ( getDataFactory( conn ).databaseEncrypted() )
         {
-            throw newSQLException( SQLState.LUCENE_ENCRYPTED_DB );
+            throw ToolUtilities.newSQLException( SQLState.LUCENE_ENCRYPTED_DB );
         }
 
         if ( luceneSchemaExists( conn ) )
         {
-            throw newSQLException( SQLState.LUCENE_ALREADY_LOADED );
+            throw ToolUtilities.newSQLException( SQLState.LUCENE_ALREADY_LOADED );
         }
 
-        boolean sqlAuthorizationEnabled = sqlAuthorizationEnabled( conn );
+        boolean sqlAuthorizationEnabled = ToolUtilities.sqlAuthorizationEnabled( conn );
         
 		StringBuilder listFunction = new StringBuilder();
 		listFunction.append("create function " + LIST_INDEXES );
@@ -248,11 +248,11 @@ public class LuceneSupport implements Op
         forbidReadOnlyConnections();
         
         Connection  conn = getDefaultConnection();
-        mustBeDBO( conn );
+        ToolUtilities.mustBeDBO( conn );
 
         if ( !luceneSchemaExists( conn ) )
         {
-            throw newSQLException( SQLState.LUCENE_ALREADY_UNLOADED );
+            throw ToolUtilities.newSQLException( SQLState.LUCENE_ALREADY_UNLOADED );
         }
 
         //
@@ -371,11 +371,11 @@ public class LuceneSupport implements Op
         vetIdentifiers( schema, table, textcol );
 
         // only the dbo or the schema owner can perform this function
-        mustBeOwner( conn, schema );
+        ToolUtilities.mustBeOwner( conn, schema );
 
         if ( !tableFunctionExists( conn, schema, table, textcol ) )
         {
-            throw newSQLException( SQLState.LUCENE_INDEX_DOES_NOT_EXIST );
+            throw ToolUtilities.newSQLException( SQLState.LUCENE_INDEX_DOES_NOT_EXIST );
         }
 
         createOrRecreateIndex( conn, schema, table, textcol, indexDescriptorMaker, false );
@@ -458,11 +458,11 @@ public class LuceneSupport implements Op
         // can't create an index without specifying keys for joining it back to Derby data
         if ( primaryKeys.length == 0 )
         {
-            throw newSQLException( SQLState.LUCENE_NO_PRIMARY_KEY );
+            throw ToolUtilities.newSQLException( SQLState.LUCENE_NO_PRIMARY_KEY );
         }
 
         // don't let the user create a table function with duplicate column names
-        vetColumnName( derbyIdentifier( textcol ) );
+        vetColumnName( ToolUtilities.derbyIdentifier( textcol ) );
         for ( VTITemplate.ColumnDescriptor key : primaryKeys )
         {
             vetColumnName(  key.columnName );
@@ -540,7 +540,7 @@ public class LuceneSupport implements Op
             }
         
             query.append(", ");
-            query.append( delimitID( derbyIdentifier( textcol ) ) );
+            query.append( delimitID( ToolUtilities.derbyIdentifier( textcol ) ) );
             query.append(" from " + makeTableName( schema, table ) );
 
             ps = conn.prepareStatement( query.toString() );
@@ -608,7 +608,7 @@ public class LuceneSupport implements Op
         {
             if ( fieldName == null )
             {
-                throw newSQLException( SQLState.LUCENE_DUPLICATE_FIELD_NAME, fieldName );
+                throw ToolUtilities.newSQLException( SQLState.LUCENE_DUPLICATE_FIELD_NAME, fieldName );
             }
         }
         Arrays.sort( fieldNames );
@@ -621,13 +621,13 @@ public class LuceneSupport implements Op
         {
             if ( fieldName.equals( previousFieldName ) )
             {
-                throw newSQLException( SQLState.LUCENE_DUPLICATE_FIELD_NAME, fieldName );
+                throw ToolUtilities.newSQLException( SQLState.LUCENE_DUPLICATE_FIELD_NAME, fieldName );
             }
             previousFieldName = fieldName;
 
             if ( keyNames.contains( fieldName ) )
             {
-                throw newSQLException( SQLState.LUCENE_FIELD_KEY_CONFLICT, fieldName );
+                throw ToolUtilities.newSQLException( SQLState.LUCENE_FIELD_KEY_CONFLICT, fieldName );
             }
         }
     }
@@ -686,31 +686,6 @@ public class LuceneSupport implements Op
 
     /////////////////////////////////////////////////////////////////////
     //
-    //  ERROR HANDLING
-    //
-    /////////////////////////////////////////////////////////////////////
-
-    /** Make a SQLException from a SQLState and optional args */
-    public  static  SQLException    newSQLException( String sqlState, Object... args )
-    {
-        StandardException   se = StandardException.newException( sqlState, args );
-        return sqlException( se );
-    }
-    
-    /** Turn a StandardException into a SQLException */
-    public  static  SQLException    sqlException( StandardException se )
-    {
-        return PublicAPI.wrapStandardException( se );
-    }
-
-    /** Wrap an external exception */
-    public  static  SQLException    wrap( Throwable t )
-    {
-        return sqlException( StandardException.plainWrapException( t ) );
-    }
-    
-    /////////////////////////////////////////////////////////////////////
-    //
     //  TYPE HANDLING
     //
     /////////////////////////////////////////////////////////////////////
@@ -762,7 +737,7 @@ public class LuceneSupport implements Op
         case    Types.VARBINARY:        return "varchar " + precisionToLength( precision ) + "  for bit data";
         case    Types.VARCHAR:          return "varchar" + precisionToLength( precision );
  
-        default:                throw newSQLException( SQLState.LUCENE_UNSUPPORTED_TYPE, typeName );
+        default:  throw ToolUtilities.newSQLException( SQLState.LUCENE_UNSUPPORTED_TYPE, typeName );
         }
     }
 
@@ -862,7 +837,8 @@ public class LuceneSupport implements Op
             break;
             
         default:
-            throw newSQLException( SQLState.LUCENE_UNSUPPORTED_TYPE, keyDescriptor.typeName );
+            throw ToolUtilities.newSQLException
+                ( SQLState.LUCENE_UNSUPPORTED_TYPE, keyDescriptor.typeName );
         }
 
         // Lucene fields do not allow null values
@@ -1049,9 +1025,9 @@ public class LuceneSupport implements Op
 	private static void vetTextColumn( DatabaseMetaData dbmd, String schema, String table, String textcol )
         throws SQLException
     {
-        schema = derbyIdentifier( schema );
-        table = derbyIdentifier( table );
-        textcol = derbyIdentifier( textcol );
+        schema = ToolUtilities.derbyIdentifier( schema );
+        table = ToolUtilities.derbyIdentifier( table );
+        textcol = ToolUtilities.derbyIdentifier( textcol );
         
         ResultSet   rs = dbmd.getColumns( null, schema, table, textcol );
 
@@ -1068,7 +1044,8 @@ public class LuceneSupport implements Op
                 }
             }
 
-            throw sqlException( StandardException.newException( SQLState.LUCENE_NOT_A_STRING_TYPE ) );
+            throw ToolUtilities.sqlException
+                ( StandardException.newException( SQLState.LUCENE_NOT_A_STRING_TYPE ) );
         }
         finally
         {
@@ -1097,7 +1074,7 @@ public class LuceneSupport implements Op
             SCORE.equals( derbyColumnName )
             )
         {
-            throw newSQLException( SQLState.LUCENE_BAD_COLUMN_NAME, derbyColumnName );
+            throw ToolUtilities.newSQLException( SQLState.LUCENE_BAD_COLUMN_NAME, derbyColumnName );
         }
     }
 
@@ -1107,8 +1084,8 @@ public class LuceneSupport implements Op
 	static String   makeTableName( String schema, String table )
         throws SQLException
     {
-        schema = derbyIdentifier( schema );
-        table = derbyIdentifier( table );
+        schema = ToolUtilities.derbyIdentifier( schema );
+        table = ToolUtilities.derbyIdentifier( table );
 
         return IdUtil.mkQualifiedName( schema, table );
     }
@@ -1123,7 +1100,7 @@ public class LuceneSupport implements Op
         forbidCharacter( schema, table, textcol, "/" );
         forbidCharacter( schema, table, textcol, "\\" );
 		
-        schema = derbyIdentifier( schema );
+        schema = ToolUtilities.derbyIdentifier( schema );
         String  function = makeUnqualifiedTableFunctionName( table, textcol );
 
         return IdUtil.mkQualifiedName( schema, function );
@@ -1133,14 +1110,15 @@ public class LuceneSupport implements Op
     private static  String  makeUnqualifiedTableFunctionName( String table, String textcol )
         throws SQLException
     {
-        return derbyIdentifier( table ) + SEPARATOR + derbyIdentifier( textcol );
+        return ToolUtilities.derbyIdentifier( table ) + SEPARATOR +
+            ToolUtilities.derbyIdentifier( textcol );
     }
 
     /** Return true if the table function exists */
     private static  boolean tableFunctionExists( Connection conn, String schema, String table, String textcol )
         throws SQLException
     {
-        schema = derbyIdentifier( schema );
+        schema = ToolUtilities.derbyIdentifier( schema );
         String  function = makeUnqualifiedTableFunctionName( table, textcol );
 
         ResultSet   rs = conn.getMetaData().getFunctions( null, schema, function );
@@ -1247,7 +1225,7 @@ public class LuceneSupport implements Op
     {
         if ( ConnectionUtil.getCurrentLCC().getAuthorizer().isReadOnlyConnection() )
         {
-            throw newSQLException( SQLState.AUTH_WRITE_WITH_READ_ONLY_CONNECTION );
+            throw ToolUtilities.newSQLException( SQLState.AUTH_WRITE_WITH_READ_ONLY_CONNECTION );
         }
     }
 
@@ -1263,86 +1241,6 @@ public class LuceneSupport implements Op
 		return DriverManager.getConnection( "jdbc:default:connection" );
 	}
 
-    /**
-     * <p>
-     * Raise an exception if SQL authorization is enabled and the current user
-     * isn't the DBO or the owner of the indicated schema or if the indicated schema
-     * doesn't exist.
-     * </p>
-     */
-    private static  void    mustBeOwner( Connection conn, String schema )
-        throws SQLException
-    {
-        if ( !sqlAuthorizationEnabled( conn ) ) { return; }
-
-        String  dbo = getOwner( conn, "SYS" );
-        String  schemaOwner = getOwner( conn, schema );
-        String  currentUser = getCurrentUser( conn );
-
-        if (
-            (schemaOwner != null) &&
-            (
-             schemaOwner.equals( currentUser ) ||
-             dbo.equals( currentUser )
-             )
-            )   { return; }
-        else
-        {
-            throw newSQLException( SQLState.LUCENE_MUST_OWN_SCHEMA );
-        }
-    }
-
-    /**
-     * <p>
-     * Raise an exception if SQL authorization is enabled and the current user
-     * isn't the DBO.
-     * </p>
-     */
-    private static  void    mustBeDBO( Connection conn )
-        throws SQLException
-    {
-        if ( !sqlAuthorizationEnabled( conn ) ) { return; }
-
-        String  dbo = getOwner( conn, "SYS" );
-        String  currentUser = getCurrentUser( conn );
-
-        if ( dbo.equals( currentUser ) )   { return; }
-        else
-        {
-            throw newSQLException( SQLState.DBO_ONLY );
-        }
-    }
-
-    /** Get the current user */
-    private static  String  getCurrentUser( Connection conn )
-        throws SQLException
-    {
-        ResultSet   rs = conn.prepareStatement( "values current_user" ).executeQuery();
-        try {
-            rs.next();
-            return rs.getString( 1 );
-        } finally { rs.close(); }
-    }
-
-    /**
-     * <p>
-     * Get the owner of the indicated schema. Returns null if the schema doesn't exist.
-     * </p>
-     */
-    private static  String  getOwner( Connection conn, String schema )
-        throws SQLException
-    {
-        PreparedStatement   ps = conn.prepareStatement
-            ( "select authorizationID from sys.sysschemas where schemaName = ?" );
-        ps.setString( 1, derbyIdentifier( schema ) );
-
-        ResultSet   rs = ps.executeQuery();
-        try {
-            if ( rs.next() ) { return rs.getString( 1 ); }
-            else { return null; }
-        } finally { rs.close(); }
-    }
-
     /** Return true if the LuceneSupport schema exists already */
     private static  boolean luceneSchemaExists( Connection conn )
         throws SQLException
@@ -1362,41 +1260,6 @@ public class LuceneSupport implements Op
         }
     }
 
-    /**
-     * Returns true if SQL authorization is enabled in the connected database.
-     */
-    public  static  boolean sqlAuthorizationEnabled( Connection conn )
-        throws SQLException
-    {
-        try {
-            ResultSet   rs;
-        
-            // first check to see if NATIVE authentication is on
-            rs = conn.prepareStatement( "select count(*) from sys.sysusers" ).executeQuery();
-            rs.next();
-            try {
-                if ( rs.getInt( 1 ) > 0 ) { return true; }
-            }
-            finally { rs.close(); }
-        }
-        catch (SQLException se)
-        {
-            if ( SQLState.DBO_ONLY.equals( se.getSQLState() ) ) { return true; }
-        }
-        
-        ResultSet   rs = conn.prepareStatement
-            (
-             "values syscs_util.syscs_get_database_property( 'derby.database.sqlAuthorization' )"
-             ).executeQuery();
-
-        try {
-            if ( !( rs.next() ) ) { return false; }
-
-            return ( "true".equals( rs.getString( 1 ) ) );
-        }
-        finally { rs.close(); }
-    }
-    
 	/**
 	 * Execute a DDL statement
 	 * 
@@ -1410,16 +1273,6 @@ public class LuceneSupport implements Op
     	ddl.close();
     }
 	
-    /** Convert a raw string into a properly cased and escaped Derby identifier */
-    static  String  derbyIdentifier( String rawString )
-        throws SQLException
-    {
-        try {
-            return IdUtil.parseSQLIdentifier( rawString );
-        }
-        catch (StandardException se)  { throw sqlException( se ); }
-    }
-
     /** Double quote an identifier in order to preserver casing */
     static String delimitID( String id )
     {
@@ -1432,7 +1285,7 @@ public class LuceneSupport implements Op
     {
         if ( argumentValue == null )
         {
-            throw newSQLException( SQLState.ARGUMENT_MAY_NOT_BE_NULL, argumentName );
+            throw ToolUtilities.newSQLException( SQLState.ARGUMENT_MAY_NOT_BE_NULL, argumentName );
         }
     }
 
@@ -1447,7 +1300,8 @@ public class LuceneSupport implements Op
          )
         throws SQLException
     {
-        ResultSet   keysRS = conn.getMetaData().getPrimaryKeys( null, derbyIdentifier( schema ), derbyIdentifier( table ) );
+        ResultSet   keysRS = conn.getMetaData().getPrimaryKeys
+            ( null, ToolUtilities.derbyIdentifier( schema ), ToolUtilities.derbyIdentifier( table ) );
         ArrayList<VTITemplate.ColumnDescriptor>    keyArray = new ArrayList<VTITemplate.ColumnDescriptor>();
         try {
             while ( keysRS.next() )
@@ -1495,7 +1349,7 @@ public class LuceneSupport implements Op
          )
         throws SQLException
     {
-        schema = derbyIdentifier( schema );
+        schema = ToolUtilities.derbyIdentifier( schema );
         String  functionName = makeUnqualifiedTableFunctionName( table, textcol );
         ArrayList<VTITemplate.ColumnDescriptor>    keyArray = new ArrayList<VTITemplate.ColumnDescriptor>();
 
@@ -1558,7 +1412,7 @@ public class LuceneSupport implements Op
 
             if ( counter > 0 ) { buffer.append( ", " ); }
             counter++;
-            buffer.append( delimitID( derbyIdentifier( key ) ) );
+            buffer.append( delimitID( ToolUtilities.derbyIdentifier( key ) ) );
         }
         buffer.append( "\nfrom " + qualifiedName );
         buffer.append( "\nwhere 1=2" );
@@ -1646,8 +1500,8 @@ public class LuceneSupport implements Op
         });
 
         if (!result) {
-            throw newSQLException(SQLState.UNABLE_TO_DELETE_FILE,
-                                  file.getPath());
+            throw ToolUtilities.newSQLException
+                ( SQLState.UNABLE_TO_DELETE_FILE, file.getPath() );
         }
 
         return result;
@@ -1659,7 +1513,7 @@ public class LuceneSupport implements Op
     {
 		if (schema.indexOf( invalidCharacter ) > 0 || table.indexOf( invalidCharacter ) > 0 || textcol.indexOf( invalidCharacter ) > 0)
         {
-            throw newSQLException( SQLState.LUCENE_INVALID_CHARACTER, invalidCharacter );
+            throw ToolUtilities.newSQLException( SQLState.LUCENE_INVALID_CHARACTER, invalidCharacter );
 		}		
     }
 
@@ -1864,7 +1718,7 @@ public class LuceneSupport implements Op
                 ( Property.DATABASE_MODULE, ((EmbedConnection) conn).getDBName() ) ;
             return (DataFactory) findServiceModule( monitor, DataFactory.MODULE );
         }
-        catch (StandardException se) { throw wrap( se ); }
+        catch (StandardException se) { throw ToolUtilities.wrap( se ); }
     }
 
 	/**

Added: db/derby/code/trunk/java/optional/org/apache/derby/optional/utils/ToolUtilities.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/optional/org/apache/derby/optional/utils/ToolUtilities.java?rev=1693818&view=auto
==============================================================================
--- db/derby/code/trunk/java/optional/org/apache/derby/optional/utils/ToolUtilities.java (added)
+++ db/derby/code/trunk/java/optional/org/apache/derby/optional/utils/ToolUtilities.java Sun Aug  2 17:33:17 2015
@@ -0,0 +1,209 @@
+/*
+
+   Class org.apache.derby.optional.utils.ToolUtilities
+
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+
+*/
+
+package org.apache.derby.optional.utils;
+
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+
+import org.apache.derby.iapi.error.PublicAPI;
+import org.apache.derby.iapi.error.StandardException;
+import org.apache.derby.iapi.util.IdUtil;
+import org.apache.derby.shared.common.reference.SQLState;
+
+/**
+ * Utility functions shared across the optional tools.
+ * 
+ */
+public class ToolUtilities
+{
+    ////////////////////////////////////////////////////////////////////////
+    //
+    //	CONSTANTS
+    //
+    ////////////////////////////////////////////////////////////////////////
+
+    ////////////////////////////////////////////////////////////////////////
+    //
+    //	STATE
+    //
+    ////////////////////////////////////////////////////////////////////////
+
+    ////////////////////////////////////////////////////////////////////////
+    //
+    //	ENTRY POINTS
+    //
+    ////////////////////////////////////////////////////////////////////////
+
+    /**
+     * Returns true if SQL authorization is enabled in the connected database.
+     */
+    public  static  boolean sqlAuthorizationEnabled( Connection conn )
+        throws SQLException
+    {
+        try {
+            ResultSet   rs;
+        
+            // first check to see if NATIVE authentication is on
+            rs = conn.prepareStatement( "select count(*) from sys.sysusers" ).executeQuery();
+            rs.next();
+            try {
+                if ( rs.getInt( 1 ) > 0 ) { return true; }
+            }
+            finally { rs.close(); }
+        }
+        catch (SQLException se)
+        {
+            if ( SQLState.DBO_ONLY.equals( se.getSQLState() ) ) { return true; }
+        }
+        
+        ResultSet   rs = conn.prepareStatement
+            (
+             "values syscs_util.syscs_get_database_property( 'derby.database.sqlAuthorization' )"
+             ).executeQuery();
+
+        try {
+            if ( !( rs.next() ) ) { return false; }
+
+            return ( "true".equals( rs.getString( 1 ) ) );
+        }
+        finally { rs.close(); }
+    }
+    
+    /**
+     * <p>
+     * Raise an exception if SQL authorization is enabled and the current user
+     * isn't the DBO or the owner of the indicated schema or if the indicated schema
+     * doesn't exist.
+     * </p>
+     */
+    public static  void    mustBeOwner( Connection conn, String schema )
+        throws SQLException
+    {
+        if ( !sqlAuthorizationEnabled( conn ) ) { return; }
+
+        String  dbo = getOwner( conn, "SYS" );
+        String  schemaOwner = getOwner( conn, schema );
+        String  currentUser = getCurrentUser( conn );
+
+        if (
+            (schemaOwner != null) &&
+            (
+             schemaOwner.equals( currentUser ) ||
+             dbo.equals( currentUser )
+             )
+            )   { return; }
+        else
+        {
+            throw newSQLException( SQLState.LUCENE_MUST_OWN_SCHEMA );
+        }
+    }
+
+    /**
+     * <p>
+     * Raise an exception if SQL authorization is enabled and the current user
+     * isn't the DBO.
+     * </p>
+     */
+    public static  void    mustBeDBO( Connection conn )
+        throws SQLException
+    {
+        if ( !sqlAuthorizationEnabled( conn ) ) { return; }
+
+        String  dbo = getOwner( conn, "SYS" );
+        String  currentUser = getCurrentUser( conn );
+
+        if ( dbo.equals( currentUser ) )   { return; }
+        else
+        {
+            throw newSQLException( SQLState.DBO_ONLY );
+        }
+    }
+
+    /** Get the current user */
+    public static  String  getCurrentUser( Connection conn )
+        throws SQLException
+    {
+        ResultSet   rs = conn.prepareStatement( "values current_user" ).executeQuery();
+        try {
+            rs.next();
+            return rs.getString( 1 );
+        } finally { rs.close(); }
+    }
+
+    /**
+     * <p>
+     * Get the owner of the indicated schema. Returns null if the schema doesn't exist.
+     * </p>
+     */
+    public static  String  getOwner( Connection conn, String schema )
+        throws SQLException
+    {
+        PreparedStatement   ps = conn.prepareStatement
+            ( "select authorizationID from sys.sysschemas where schemaName = ?" );
+        ps.setString( 1, derbyIdentifier( schema ) );
+
+        ResultSet   rs = ps.executeQuery();
+        try {
+            if ( rs.next() ) { return rs.getString( 1 ); }
+            else { return null; }
+        } finally { rs.close(); }
+    }
+
+    /** Make a SQLException from a SQLState and optional args */
+    public  static  SQLException    newSQLException( String sqlState, Object... args )
+    {
+        StandardException   se = StandardException.newException( sqlState, args );
+        return sqlException( se );
+    }
+    
+    /** Convert a raw string into a properly cased and escaped Derby identifier */
+    public static  String  derbyIdentifier( String rawString )
+        throws SQLException
+    {
+        try {
+            return IdUtil.parseSQLIdentifier( rawString );
+        }
+        catch (StandardException se)  { throw ToolUtilities.sqlException( se ); }
+    }
+
+    /////////////////////////////////////////////////////////////////////
+    //
+    //  ERROR HANDLING
+    //
+    /////////////////////////////////////////////////////////////////////
+
+    /** Turn a StandardException into a SQLException */
+    public  static  SQLException    sqlException( StandardException se )
+    {
+        return PublicAPI.wrapStandardException( se );
+    }
+
+    /** Wrap an external exception */
+    public  static  SQLException    wrap( Throwable t )
+    {
+        return sqlException( StandardException.plainWrapException( t ) );
+    }
+    
+}
+

Propchange: db/derby/code/trunk/java/optional/org/apache/derby/optional/utils/ToolUtilities.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/JsonSuite.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/JsonSuite.java?rev=1693818&r1=1693817&r2=1693818&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/JsonSuite.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/JsonSuite.java Sun Aug  2 17:33:17 2015
@@ -57,6 +57,7 @@ public class JsonSuite extends BaseTestC
         else
         {
             suite.addTest(SimpleJsonTest.suite());
+            suite.addTest(SimpleJsonPermsTest.suite());
         }
 
         return suite;

Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/SimpleJsonPermsTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/SimpleJsonPermsTest.java?rev=1693818&view=auto
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/SimpleJsonPermsTest.java (added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/SimpleJsonPermsTest.java Sun Aug  2 17:33:17 2015
@@ -0,0 +1,220 @@
+/*
+
+   Derby - Class org.apache.derbyTesting.functionTests.tests.lang.SimpleJsonPermsTest
+
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to you under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+     http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+
+ */
+
+package org.apache.derbyTesting.functionTests.tests.lang;
+
+import java.io.File;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import junit.framework.Test;
+import org.apache.derby.iapi.sql.conn.ConnectionUtil;
+import org.apache.derbyTesting.junit.BaseJDBCTestCase;
+import org.apache.derbyTesting.junit.BaseTestSuite;
+import org.apache.derbyTesting.junit.DatabasePropertyTestSetup;
+import org.apache.derbyTesting.junit.SupportFilesSetup;
+import org.apache.derbyTesting.junit.TestConfiguration;
+import org.apache.derbyTesting.functionTests.util.PrivilegedFileOpsForTests;
+
+/**
+ * <p>
+ * Test permissions on objects created by the simpleJson optional tool.
+ * </p>
+ */
+public class SimpleJsonPermsTest extends BaseJDBCTestCase
+{
+    ///////////////////////////////////////////////////////////////////////////////////
+    //
+    // CONSTANTS
+    //
+    ///////////////////////////////////////////////////////////////////////////////////
+
+    private static  final   String      DB_NAME = "simplejsonpermsdb";
+
+    private static  final   String      TEST_DBO = "TEST_DBO";
+    private static  final   String      ALICE = "ALICE";
+    private static  final   String[]    LEGAL_USERS = { TEST_DBO, ALICE  };
+
+    private static  final   String      LOAD_TOOL = "call syscs_util.syscs_register_tool( 'simpleJson', true )";
+    private static  final   String      UNLOAD_TOOL = "call syscs_util.syscs_register_tool( 'simpleJson', false )";
+
+    private static  final   String      LACK_EXECUTE_PRIV = "42504";
+
+    ///////////////////////////////////////////////////////////////////////////////////
+    //
+    // STATE
+    //
+    ///////////////////////////////////////////////////////////////////////////////////
+
+    ///////////////////////////////////////////////////////////////////////////////////
+    //
+    // CONSTRUCTOR
+    //
+    ///////////////////////////////////////////////////////////////////////////////////
+
+    /**
+     * Create a new instance.
+     */
+
+    public SimpleJsonPermsTest(String name)
+    {
+        super(name);
+    }
+
+    ///////////////////////////////////////////////////////////////////////////////////
+    //
+    // JUnit BEHAVIOR
+    //
+    ///////////////////////////////////////////////////////////////////////////////////
+
+
+    /**
+     * Construct top level suite in this JUnit test
+     */
+    public static Test suite()
+    {
+        BaseTestSuite suite = (BaseTestSuite) TestConfiguration.embeddedSuite
+            ( SimpleJsonPermsTest.class );
+
+        Test    customTest = new SupportFilesSetup
+            (
+             suite,
+             new String[]
+             { 
+                "functionTests/tests/lang/json.dat",
+             }
+            );
+        Test        authenticatedTest = DatabasePropertyTestSetup.builtinAuthentication
+            ( customTest, LEGAL_USERS, "SimpleJsonPermissions" );
+        Test        authorizedTest = TestConfiguration.sqlAuthorizationDecoratorSingleUse( authenticatedTest, DB_NAME, true );
+
+        return authorizedTest;
+    }
+
+    ///////////////////////////////////////////////////////////////////////////////////
+    //
+    // TESTS
+    //
+    ///////////////////////////////////////////////////////////////////////////////////
+
+    /**
+     * <p>
+     * Test that the simpleJson tool granst public access to its UDT and FUNCTIONs.
+     * </p>
+     */
+    public  void    test_001_basic()
+        throws Exception
+    {
+        Connection  dboConnection = openUserConnection( TEST_DBO );
+        Connection  aliceConnection = openUserConnection( ALICE );
+
+        // create a dummy table in order to create the schema
+        goodStatement( aliceConnection, "create table t( a int )" );
+
+        // alice does not have permission to load the tool
+        expectExecutionError( aliceConnection, LACK_EXECUTE_PRIV, LOAD_TOOL );
+
+        // but the dbo has permission
+        goodStatement( dboConnection, LOAD_TOOL );
+
+        // alice can create a table function referencing the JSONArray udt
+        goodStatement
+            (
+             aliceConnection,
+             "create function f_double( jsonArray test_dbo.JSONArray )\n" +
+             "returns table\n" +
+             "(\n" +
+             "  str_col varchar( 10 ),\n" +
+             "  bool_col boolean,\n" +
+             "  num_col double\n" +
+             ")\n" +
+             "language java parameter style derby_jdbc_result_set contains sql\n" +
+             "external name 'org.apache.derby.optional.api.SimpleJsonVTI.readArray'\n"
+             );
+
+        // alice can use the simpleJson functions
+        String[][]  stringResults = new String[][]
+            {
+                { "abc","true", "127.0" },
+            };
+        String[][]  fileResults = new String[][]
+            {
+                { "abc","true", "127.0" },
+                { "def", "false", "1.2" },
+                { "ghi", null, "345.67" },
+                { "lmn", "true", "9.223372036854776E18" },    
+            };
+        
+        assertResults
+            (
+             aliceConnection,
+             "select * from table\n" +
+             "(\n" +
+             "    f_double\n" +
+             "    (\n" +
+             "        test_dbo.readArrayFromString\n" +
+             "        ( '[{ \"STR_COL\" : \"abc\", \"BOOL_COL\" : true, \"NUM_COL\" : 127 }]' )\n" +
+             "    )\n" +
+             ") t\n",
+             stringResults,
+             false
+             );
+
+        PreparedStatement   ps = null;
+        ResultSet           rs = null;
+        File                inputFile = SupportFilesSetup.getReadOnly( "json.dat" );
+        
+        ps = aliceConnection.prepareStatement
+            (
+             "select * from table\n" +
+             "( f_double( test_dbo.readArrayFromFile( ?, 'UTF-8' ) ) ) t"
+             );
+        ps.setString( 1, PrivilegedFileOpsForTests.getAbsolutePath( inputFile ) );
+        rs = ps.executeQuery();
+        assertResults( rs, fileResults, false );
+        rs.close();
+        ps.close();
+
+        ps = aliceConnection.prepareStatement
+            (
+             "select * from table\n" +
+             "( f_double( test_dbo.readArrayFromURL( ?, 'UTF-8' ) ) ) t"
+             );
+        String  inputFileURL = PrivilegedFileOpsForTests.toURI( inputFile ).toURL().toString();
+        ps.setString( 1, inputFileURL);
+        rs = ps.executeQuery();
+        assertResults( rs, fileResults, false );
+        rs.close();
+        ps.close();
+
+        // tear down the test
+        goodStatement( aliceConnection, "drop table t" );
+        goodStatement( aliceConnection, "drop function f_double" );
+
+        // alice cannot unload the tool
+        expectExecutionError( aliceConnection, LACK_EXECUTE_PRIV, UNLOAD_TOOL );
+
+        // but the dbo can
+        goodStatement( dboConnection, UNLOAD_TOOL );
+    }
+
+}

Propchange: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/SimpleJsonPermsTest.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message