001: /*
002:
003: Derby - Class org.apache.derby.impl.sql.execute.JarDDL
004:
005: Licensed to the Apache Software Foundation (ASF) under one or more
006: contributor license agreements. See the NOTICE file distributed with
007: this work for additional information regarding copyright ownership.
008: The ASF licenses this file to you under the Apache License, Version 2.0
009: (the "License"); you may not use this file except in compliance with
010: the License. You may obtain a copy of the License at
011:
012: http://www.apache.org/licenses/LICENSE-2.0
013:
014: Unless required by applicable law or agreed to in writing, software
015: distributed under the License is distributed on an "AS IS" BASIS,
016: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: See the License for the specific language governing permissions and
018: limitations under the License.
019:
020: */
021:
022: package org.apache.derby.impl.sql.execute;
023:
024: import org.apache.derby.iapi.services.context.ContextService;
025: import org.apache.derby.iapi.error.StandardException;
026: import org.apache.derby.iapi.sql.conn.LanguageConnectionContext;
027: import org.apache.derby.iapi.sql.execute.ConstantAction;
028: import org.apache.derby.iapi.sql.execute.ExecutionContext;
029: import org.apache.derby.iapi.store.access.FileResource;
030:
031: public class JarDDL {
032: /**
033: Add a jar file to the current connection's database.
034:
035: @exception StandardException Opps
036: */
037: static public void add(String schemaName, String sqlName,
038: String externalPath) throws StandardException {
039: schemaName = JarDDL.getSchemaName(schemaName);
040:
041: GenericConstantActionFactory caf = getConstantActionFactory();
042: ConstantAction ca = caf.getAddJarConstantAction(null,
043: schemaName, sqlName, externalPath);
044: ca.executeConstantAction(null);
045: }
046:
047: /**
048: Drop a jar file from the current connection's database.
049:
050: @exception StandardException Opps
051: */
052: static public void drop(String schemaName, String sqlName)
053: throws StandardException {
054: schemaName = JarDDL.getSchemaName(schemaName);
055:
056: GenericConstantActionFactory caf = getConstantActionFactory();
057: ConstantAction ca = caf.getDropJarConstantAction(null,
058: schemaName, sqlName);
059: ca.executeConstantAction(null);
060: }
061:
062: /**
063: Replace a jar file from the current connection's database with the content of an
064: external file.
065:
066: @exception StandardException Opps
067: */
068: static public void replace(String schemaName, String sqlName,
069: String externalPath) throws StandardException {
070: schemaName = JarDDL.getSchemaName(schemaName);
071:
072: GenericConstantActionFactory caf = getConstantActionFactory();
073: ConstantAction ca = caf.getReplaceJarConstantAction(null,
074: schemaName, sqlName, externalPath);
075: ca.executeConstantAction(null);
076: }
077:
078: private static GenericConstantActionFactory getConstantActionFactory() {
079: ExecutionContext ec = (ExecutionContext) ContextService
080: .getContext(ExecutionContext.CONTEXT_ID);
081: GenericExecutionFactory gef = (GenericExecutionFactory) ec
082: .getExecutionFactory();
083: GenericConstantActionFactory caf = gef
084: .getConstantActionFactory();
085: return caf;
086: }
087:
088: private static String getSchemaName(String schemaName) {
089:
090: if (schemaName != null)
091: return schemaName;
092:
093: // find the language context.
094: LanguageConnectionContext lcc = (LanguageConnectionContext) ContextService
095: .getContext(LanguageConnectionContext.CONTEXT_ID);
096:
097: schemaName = lcc.getCurrentSchemaName();
098:
099: return schemaName;
100: }
101:
102: /**
103: Make an external name for a file stored in the database.
104: */
105: public static String mkExternalName(String schemaName,
106: String sqlName, char separatorChar) {
107: StringBuffer sb = new StringBuffer(30);
108:
109: sb.append(FileResource.JAR_DIRECTORY_NAME);
110: sb.append(separatorChar);
111: sb.append(schemaName);
112: sb.append(separatorChar);
113: sb.append(sqlName);
114: sb.append(".jar");
115: return sb.toString();
116: }
117: }
|