You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-commits@db.apache.org by dj...@apache.org on 2006/11/12 01:08:08 UTC
svn commit: r473834 - in /db/derby/code/trunk/java:
engine/org/apache/derby/impl/sql/execute/JarUtil.java
testing/org/apache/derbyTesting/functionTests/tests/lang/DatabaseClassLoadingTest.java
Author: djd
Date: Sat Nov 11 16:08:07 2006
New Revision: 473834
URL: http://svn.apache.org/viewvc?view=rev&rev=473834
Log:
DERBY-537 (partial) Call FileResource.add in a privleged block when executing code to add a jar,
driven by sqlj.install_jar. Allows one test fixture in DatabaseClassLoadingTest to be executed
with a security manager.
Modified:
db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/JarUtil.java
db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/DatabaseClassLoadingTest.java
Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/JarUtil.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/JarUtil.java?view=diff&rev=473834&r1=473833&r2=473834
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/JarUtil.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/sql/execute/JarUtil.java Sat Nov 11 16:08:07 2006
@@ -39,7 +39,6 @@
import org.apache.derby.iapi.reference.SQLState;
import org.apache.derby.iapi.store.access.FileResource;
import org.apache.derby.catalog.UUID;
-import org.apache.derby.iapi.services.io.FileUtil;
import java.io.FileInputStream;
import java.io.IOException;
@@ -119,7 +118,7 @@
@param is A stream for reading the content of the file to add.
@exception StandardException Opps
*/
- private long add(InputStream is) throws StandardException
+ private long add(final InputStream is) throws StandardException
{
//
//Like create table we say we are writing before we read the dd
@@ -130,34 +129,40 @@
StandardException.newException(SQLState.LANG_OBJECT_ALREADY_EXISTS_IN_OBJECT,
fid.getDescriptorType(), sqlName, fid.getSchemaDescriptor().getDescriptorType(), schemaName);
- try {
- notifyLoader(false);
- dd.invalidateAllSPSPlans();
- long generationId = fr.add(JarDDL.mkExternalName(schemaName, sqlName, fr.getSeparatorChar()),is);
-
- SchemaDescriptor sd = dd.getSchemaDescriptor(schemaName, null, true);
-
- fid = ddg.newFileInfoDescriptor(id, sd,
- sqlName, generationId);
- dd.addDescriptor(fid, sd, DataDictionary.SYSFILES_CATALOG_NUM,
- false, lcc.getTransactionExecute());
- return generationId;
- } finally {
- notifyLoader(true);
- }
+ SchemaDescriptor sd = dd.getSchemaDescriptor(schemaName, null, true);
+ try {
+ notifyLoader(false);
+ dd.invalidateAllSPSPlans();
+ final String jarExternalName = JarDDL.mkExternalName(schemaName,
+ sqlName, fr.getSeparatorChar());
+
+ long generationId = setJar(jarExternalName, is);
+
+ fid = ddg.newFileInfoDescriptor(id, sd, sqlName, generationId);
+ dd.addDescriptor(fid, sd, DataDictionary.SYSFILES_CATALOG_NUM,
+ false, lcc.getTransactionExecute());
+ return generationId;
+ } finally {
+ notifyLoader(true);
+ }
}
/**
- Drop a jar file from the current connection's database.
-
- @param id The id for the jar file we drop. Ignored if null.
- @param schemaName the name for the schema that holds the jar file.
- @param sqlName the sql name for the jar file.
- @param purgeOnCommit True means purge the old jar file on commit. False
- means leave it around for use by replication.
-
- @exception StandardException Opps
- */
+ * Drop a jar file from the current connection's database.
+ *
+ * @param id
+ * The id for the jar file we drop. Ignored if null.
+ * @param schemaName
+ * the name for the schema that holds the jar file.
+ * @param sqlName
+ * the sql name for the jar file.
+ * @param purgeOnCommit
+ * True means purge the old jar file on commit. False means leave
+ * it around for use by replication.
+ *
+ * @exception StandardException
+ * Opps
+ */
static void
drop(UUID id, String schemaName, String sqlName,boolean purgeOnCommit)
throws StandardException
@@ -307,11 +312,13 @@
notifyLoader(false);
dd.invalidateAllSPSPlans();
dd.dropFileInfoDescriptor(fid);
+ final String jarExternalName =
+ JarDDL.mkExternalName(schemaName, sqlName, fr.getSeparatorChar());
//
//Replace the file.
long generationId =
- fr.replace(JarDDL.mkExternalName(schemaName, sqlName, fr.getSeparatorChar()),
+ fr.replace(jarExternalName,
fid.getGenerationId(), is, purgeOnCommit);
//
@@ -377,6 +384,28 @@
});
} catch (PrivilegedActionException e) {
throw (IOException) e.getException();
+ }
+ }
+
+ /**
+ * Copy the jar from the externally obtained
+ * input stream into the database
+ * @param jarExternalName Name of jar with database structure.
+ * @param contents Contents of jar file.
+ */
+ private long setJar(final String jarExternalName, final InputStream contents)
+ throws StandardException {
+ try {
+ return ((Long) AccessController
+ .doPrivileged(new java.security.PrivilegedExceptionAction() {
+
+ public Object run() throws StandardException {
+ long generatedId = fr.add(jarExternalName, contents);
+ return new Long(generatedId);
+ }
+ })).longValue();
+ } catch (PrivilegedActionException e) {
+ throw (StandardException) e.getException();
}
}
}
Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/DatabaseClassLoadingTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/DatabaseClassLoadingTest.java?view=diff&rev=473834&r1=473833&r2=473834
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/DatabaseClassLoadingTest.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/lang/DatabaseClassLoadingTest.java Sat Nov 11 16:08:07 2006
@@ -48,9 +48,7 @@
suite.addTest(new DatabaseClassLoadingTest("testWithNoInstalledJars"));
- suite.addTest(
- SecurityManagerSetup.noSecurityManager(
- new DatabaseClassLoadingTest("testWithNoClasspath")));
+ suite.addTest(new DatabaseClassLoadingTest("testWithNoClasspath"));
suite.addTest(
SecurityManagerSetup.noSecurityManager(
new DatabaseClassLoadingTest("testSetClasspath")));