db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rhille...@apache.org
Subject svn commit: r1427859 - in /db/derby/code/trunk: java/engine/org/apache/derby/catalog/ java/engine/org/apache/derby/iapi/sql/ java/engine/org/apache/derby/iapi/sql/dictionary/ java/engine/org/apache/derby/impl/sql/catalog/ java/engine/org/apache/derby/l...
Date Wed, 02 Jan 2013 16:55:39 GMT
Author: rhillegas
Date: Wed Jan  2 16:55:38 2013
New Revision: 1427859

URL: http://svn.apache.org/viewvc?rev=1427859&view=rev
Log:
DERBY-6022: Add a system procedure for (un)registering optional packages of tools.

Added:
    db/derby/code/trunk/java/engine/org/apache/derby/catalog/Java5SystemProcedures.java  
(with props)
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/OptionalTool.java
  (with props)
Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/catalog/build.xml
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/build.xml
    db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/DataDictionaryImpl.java
    db/derby/code/trunk/java/engine/org/apache/derby/loc/messages.xml
    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/upgradeTests/Changes10_10.java
    db/derby/code/trunk/tools/jar/extraDBMSclasses.properties

Added: db/derby/code/trunk/java/engine/org/apache/derby/catalog/Java5SystemProcedures.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/catalog/Java5SystemProcedures.java?rev=1427859&view=auto
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/catalog/Java5SystemProcedures.java (added)
+++ db/derby/code/trunk/java/engine/org/apache/derby/catalog/Java5SystemProcedures.java Wed
Jan  2 16:55:38 2013
@@ -0,0 +1,125 @@
+/*
+
+   Derby - Class org.apache.derby.catalog.Java5SystemProcedures
+
+   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.catalog;
+
+import java.sql.SQLException;
+
+import org.apache.derby.iapi.sql.compile.CompilerContext;
+import org.apache.derby.iapi.sql.conn.ConnectionUtil;
+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.SQLState;
+import org.apache.derby.iapi.services.context.ContextService;
+import org.apache.derby.iapi.services.loader.ClassFactory;
+import org.apache.derby.iapi.services.sanity.SanityManager;
+
+/**
+ * <p>
+ * System procedures which run only on Java 5 or higher.
+ * </p>
+ */
+public  class   Java5SystemProcedures
+{
+    ///////////////////////////////////////////////////////////////////////////////////
+    //
+    // CONSTANTS
+    //
+    ///////////////////////////////////////////////////////////////////////////////////
+
+    /** Offsets into arrays in OPTIONAL_TOOLS */
+    private static  final   int TOOL_NAME = 0;
+    private static  final   int TOOL_CLASS_NAME = TOOL_NAME + 1;
+
+    ///////////////////////////////////////////////////////////////////////////////////
+    //
+    // STATE
+    //
+    ///////////////////////////////////////////////////////////////////////////////////
+
+    /** Mapping of tool names to their implementing classes for use by SYSCS_REGISTER_TOOL
*/
+    private static  final   String[][]  OPTIONAL_TOOLS = new String[][]
+    {
+    };
+
+    ///////////////////////////////////////////////////////////////////////////////////
+    //
+    // PUBLIC BEHAVIOR
+    //
+    ///////////////////////////////////////////////////////////////////////////////////
+
+    /**
+     * <p>
+     * Load or unload an optional tool package.
+     * </p>
+     *
+     * @param toolName  Name of the tool package.
+     * @param register  True if the package should be loaded, false otherwise.
+     * @param optionalArgs  Tool-specific configuration parameters.
+     */
+    public  static  void    SYSCS_REGISTER_TOOL
+        (
+         String toolName,
+         boolean    register,
+         String...  optionalArgs
+         )
+        throws SQLException
+    {
+        try {
+			CompilerContext cc = (CompilerContext) ContextService.getContext( CompilerContext.CONTEXT_ID
);
+            ClassFactory    classFactory = cc.getClassFactory();
+
+            String              toolClassName = findToolClassName( toolName );          
 
+            OptionalTool    tool = null;
+
+            try {
+                tool = (OptionalTool) classFactory.loadApplicationClass( toolClassName ).newInstance();
+            }
+            catch (ClassNotFoundException cnfe) { throw wrap( cnfe ); }
+            catch (InstantiationException ie) { throw wrap( ie ); }
+            catch (IllegalAccessException iae) { throw wrap( iae ); }
+
+            if ( register ) { tool.loadTool( optionalArgs ); }
+            else { tool.unloadTool( optionalArgs ); }
+        }
+        catch (StandardException se) { throw PublicAPI.wrapStandardException( se ); }
+    }
+    /** Lookup the class name corresponding to the name of an optional tool */
+    private static  String  findToolClassName( String toolName ) throws StandardException
+    {
+        for ( String[] descriptor : OPTIONAL_TOOLS )
+        {
+            if ( descriptor[ TOOL_NAME ].equals( toolName ) ) { return descriptor[ TOOL_CLASS_NAME
]; }
+        }
+
+        throw StandardException.newException( SQLState.LANG_UNKNOWN_TOOL_NAME,  toolName
);
+    }
+
+    ///////////////////////////////////////////////////////////////////////////////////
+    //
+    // MINIONS
+    //
+    ///////////////////////////////////////////////////////////////////////////////////
+
+    private static  StandardException wrap( Throwable t )   { return StandardException.plainWrapException(
t ); }
+}
+

Propchange: db/derby/code/trunk/java/engine/org/apache/derby/catalog/Java5SystemProcedures.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: db/derby/code/trunk/java/engine/org/apache/derby/catalog/build.xml
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/catalog/build.xml?rev=1427859&r1=1427858&r2=1427859&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/catalog/build.xml (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/catalog/build.xml Wed Jan  2 16:55:38
2013
@@ -33,7 +33,7 @@
   <property file="${properties.dir}/compilepath.properties"/>
 
 <!-- Targets -->
-  <target name="catalog" depends="compile_catalog"/>
+  <target name="catalog" depends="compile_catalog,java5"/>
 
   <target name="compile_catalog">
     <javac
@@ -53,6 +53,28 @@
         <pathelement path="${compile.classpath}"/>
       </classpath>
       <include name="${derby.dir}/catalog/**"/>
+      <exclude name="${derby.dir}/catalog/Java5*"/>
+    </javac>
+  </target>
+
+  <target name="java5">
+    <javac
+      source="1.5"
+      target="1.5"
+      bootclasspath="${empty}"
+      nowarn="on"
+      debug="${debug}"
+      depend="${depend}"
+      deprecation="${deprecation}"
+      optimize="${optimize}"
+      proceed="${proceed}"
+      verbose="${verbose}"
+      srcdir="${derby.engine.src.dir}"
+      destdir="${out.dir}">
+      <classpath>
+        <pathelement path="${java15compile.classpath}"/>
+      </classpath>
+      <include name="${derby.dir}/catalog/Java5*"/>
     </javac>
   </target>
 

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/build.xml
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/build.xml?rev=1427859&r1=1427858&r2=1427859&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/build.xml (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/build.xml Wed Jan  2 16:55:38
2013
@@ -34,7 +34,7 @@
 
 <!-- Targets -->
 
-  <target name="compile" depends="compile_iapi_sql_jsr169"/>
+  <target name="compile" depends="compile_iapi_sql_jsr169,java5"/>
 
   <target name="compile_iapi_sql_jsr169">
     <javac
@@ -54,6 +54,28 @@
         <pathelement path="${compile.classpath}"/>
       </classpath>
       <include name="${derby.dir}/iapi/sql/**"/>
+      <exclude name="${derby.dir}/iapi/sql/dictionary/OptionalTool.java"/>
+    </javac>
+  </target>
+
+  <target name="java5">
+    <javac
+      source="1.5"
+      target="1.5"
+      bootclasspath="${empty}"
+      nowarn="on"
+      debug="${debug}"
+      depend="${depend}"
+      deprecation="${deprecation}"
+      optimize="${optimize}"
+      proceed="${proceed}"
+      verbose="${verbose}"
+      srcdir="${derby.engine.src.dir}"
+      destdir="${out.dir}">
+      <classpath>
+        <pathelement path="${java15compile.classpath}"/>
+      </classpath>
+      <include name="${derby.dir}/iapi/sql/dictionary/OptionalTool.java"/>
     </javac>
   </target>
 

Added: db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/OptionalTool.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/OptionalTool.java?rev=1427859&view=auto
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/OptionalTool.java
(added)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/OptionalTool.java
Wed Jan  2 16:55:38 2013
@@ -0,0 +1,44 @@
+/*
+
+   Derby - Class org.apache.derby.iapi.sql.dictionary.OptionalTool
+
+   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.iapi.sql.dictionary;
+
+import java.sql.SQLException;
+
+/**
+ * <p>
+ * Interface implemented by optional tools which can be loaded and unloaded.
+ * In addition to the methods listed here, an OptionalTool must have a public no-arg
+ * constructor so that it can be instantiated by the DataDictionary.
+ * </p>
+ */
+public  interface   OptionalTool
+{
+    /** Load the tool, giving it optional configuration parameters */
+    public  void    loadTool( String... configurationParameters )
+        throws SQLException;
+    
+    /** Unload the tool, giving it optional configuration parameters */
+    public  void    unloadTool( String... configurationParameters )
+        throws SQLException;
+    
+}
+

Propchange: db/derby/code/trunk/java/engine/org/apache/derby/iapi/sql/dictionary/OptionalTool.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/DataDictionaryImpl.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/DataDictionaryImpl.java?rev=1427859&r1=1427858&r2=1427859&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/DataDictionaryImpl.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/catalog/DataDictionaryImpl.java
Wed Jan  2 16:55:38 2013
@@ -13392,6 +13392,7 @@ public final class	DataDictionaryImpl
         throws StandardException
     {
         UUID  sysUtilUUID = getSystemUtilSchemaDescriptor().getUUID();
+        TypeDescriptor varchar32672Type = DataTypeDescriptor.getCatalogType( Types.VARCHAR,
32672 );
 
         // void SYSCS_UTIL.SYSCS_INVALIDATE_STORED_STATEMENTS()
         {               
@@ -13410,6 +13411,37 @@ public final class	DataDictionaryImpl
                 tc);
         }
         
+        // void SYSCS_UTIL.SYSCS_REGISTER_TOOL
+        {               
+            // procedure argument names
+            String[] arg_names = { "toolName", "register", "optionalArgs" };
+
+            // procedure argument types
+            TypeDescriptor[] arg_types =
+                {
+                    varchar32672Type,
+                    DataTypeDescriptor.getCatalogType( Types.BOOLEAN ),
+                    varchar32672Type,
+                };
+
+            createSystemProcedureOrFunction
+                (
+                 "SYSCS_REGISTER_TOOL",
+                 sysUtilUUID,
+                 arg_names,
+                 arg_types,
+                 0,
+                 0,
+                 RoutineAliasInfo.MODIFIES_SQL_DATA,
+                 false,
+                 true,
+                 (TypeDescriptor) null,
+                 newlyCreatedRoutines,
+                 tc,
+                 "org.apache.derby.catalog.Java5SystemProcedures"
+                 );
+        }
+        
     }
 
 

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=1427859&r1=1427858&r2=1427859&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 Wed Jan  2 16:55:38
2013
@@ -3607,6 +3607,12 @@ Guide.
                 <arg>aggregateOrFunctionName</arg>
             </msg>
 
+            <msg>
+                <name>X0Y88.S</name>
+                <text>Unknown optional tool: '{0}'</text>
+                <arg>toolName</arg>
+            </msg>
+
         </family>
 
 

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=1427859&r1=1427858&r2=1427859&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
Wed Jan  2 16:55:38 2013
@@ -1378,6 +1378,7 @@ public interface SQLState {
 	String LANG_UNKNOWN_SEQUENCE_PREALLOCATOR                                = "X0Y85.S";
 	String LANG_CANT_FLUSH_PREALLOCATOR                                = "X0Y86.S";
 	String LANG_BAD_UDA_OR_FUNCTION_NAME                                = "X0Y87.S";
+	String LANG_UNKNOWN_TOOL_NAME                                = "X0Y88.S";
 
 
 	// TEMPORARY EXECUTION RESTRICTIONS

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/Changes10_10.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/Changes10_10.java?rev=1427859&r1=1427858&r2=1427859&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/Changes10_10.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/upgradeTests/Changes10_10.java
Wed Jan  2 16:55:38 2013
@@ -120,31 +120,30 @@ public class Changes10_10 extends Upgrad
     public  void    testProcsNewTo10_10()  throws Exception
     {
         Statement s = createStatement();
+        String  iss = "call syscs_util.SYSCS_INVALIDATE_STORED_STATEMENTS()";
+        String  rt = "call syscs_util.syscs_register_tool( 'foo', true )";
+        String  rtGoodSQLState = "X0Y88";
+        String  syntaxError = "42X01";
+        boolean atLeastJava5 = JDBC.vmSupportsJDBC3();
+        boolean oldSupportsBoolean = oldAtLeast( 10, 7 );
 
         switch ( getPhase() )
         {
         case PH_CREATE: // create with old version
-            vetProcs(s, "call syscs_util.SYSCS_INVALIDATE_STORED_STATEMENTS()", 
-            		false, 
-            		"syscs_util.SYSCS_INVALIDATE_STORED_STATEMENTS should not exist.");
-            break;
-            
         case PH_SOFT_UPGRADE: // boot with new version and soft-upgrade
-            vetProcs(s, "call syscs_util.SYSCS_INVALIDATE_STORED_STATEMENTS()", 
-            		false, 
-            		"syscs_util.SYSCS_INVALIDATE_STORED_STATEMENTS should not exist.");
-            break;
-            
         case PH_POST_SOFT_UPGRADE: // soft-downgrade: boot with old version after soft-upgrade
-            vetProcs(s, "call syscs_util.SYSCS_INVALIDATE_STORED_STATEMENTS()", 
-            		false, 
-            		"syscs_util.SYSCS_INVALIDATE_STORED_STATEMENTS should not exist.");
+            vetProcs( s, iss, false, null );
+            if ( atLeastJava5 )
+            {
+                vetProcs
+                    ( s, rt, false,
+                      oldSupportsBoolean || (getPhase() == PH_SOFT_UPGRADE ) ? null : syntaxError
);
+            }
             break;
-
+            
         case PH_HARD_UPGRADE: // boot with new version and hard-upgrade
-            vetProcs(s, "call syscs_util.SYSCS_INVALIDATE_STORED_STATEMENTS()", 
-            		true, 
-            		null);
+            vetProcs( s, iss, true, null );
+            if ( atLeastJava5 ) { vetProcs( s, rt, true, rtGoodSQLState ); }
             break;
         }
         
@@ -152,27 +151,29 @@ public class Changes10_10 extends Upgrad
     	
     }
     
-    private void    vetProcs( Statement s, String procCall, 
-    		boolean shouldExist,
-    		String errorMessage) throws Exception
+    private void    vetProcs
+        (
+         Statement s,
+         String procCall, 
+         boolean shouldExist,
+         String sqlState
+         ) throws Exception
     {
         try {
             s.execute( procCall );
             
             if ( !shouldExist )
             {
-                fail( errorMessage );
+                fail( "Procedure should not exist!"  );
             }
-        } catch (SQLException se )
-        {
-            if ( shouldExist )
+            if ( sqlState != null )
             {
-                assertSQLState( "4251K", se );
-            }
-            else
-            {
-                assertSQLState( "42Y03", se );
+                fail( "Expected to fail with SQLState " + sqlState );
             }
+        } catch (SQLException se )
+        {
+            if ( sqlState == null ) { sqlState = "42Y03"; }
+            assertSQLState( sqlState, se );
         }
     }
 

Modified: db/derby/code/trunk/tools/jar/extraDBMSclasses.properties
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/tools/jar/extraDBMSclasses.properties?rev=1427859&r1=1427858&r2=1427859&view=diff
==============================================================================
--- db/derby/code/trunk/tools/jar/extraDBMSclasses.properties (original)
+++ db/derby/code/trunk/tools/jar/extraDBMSclasses.properties Wed Jan  2 16:55:38 2013
@@ -58,6 +58,8 @@ derby.module.core.ad.jdk16=org.apache.de
 derby.module.database.consistency.checker=org.apache.derby.iapi.db.ConsistencyChecker
 derby.module.database.optimizer.trace=org.apache.derby.iapi.db.OptimizerTrace
 
+derby.module.sql.dictictionary.java5.procs=org.apache.derby.catalog.Java5SystemProcedures
+
 derby.module.diag.diagnosticable.generic=org.apache.derby.iapi.services.diag.DiagnosticableGeneric
 derby.module.diag.diagnostic.util=org.apache.derby.iapi.services.diag.DiagnosticUtil
 



Mime
View raw message