KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derby > impl > sql > execute > JarDDL


1 /*
2
3    Derby - Class org.apache.derby.impl.sql.execute.JarDDL
4
5    Licensed to the Apache Software Foundation (ASF) under one or more
6    contributor license agreements. See the NOTICE file distributed with
7    this work for additional information regarding copyright ownership.
8    The ASF licenses this file to you under the Apache License, Version 2.0
9    (the "License"); you may not use this file except in compliance with
10    the License. You may obtain a copy of the License at
11
12       http://www.apache.org/licenses/LICENSE-2.0
13
14    Unless required by applicable law or agreed to in writing, software
15    distributed under the License is distributed on an "AS IS" BASIS,
16    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17    See the License for the specific language governing permissions and
18    limitations under the License.
19
20  */

21
22 package org.apache.derby.impl.sql.execute;
23
24 import org.apache.derby.iapi.services.context.ContextService;
25 import org.apache.derby.iapi.error.StandardException;
26 import org.apache.derby.iapi.sql.conn.LanguageConnectionContext;
27 import org.apache.derby.iapi.sql.execute.ConstantAction;
28 import org.apache.derby.iapi.sql.execute.ExecutionContext;
29 import org.apache.derby.iapi.store.access.FileResource;
30
31 public class JarDDL
32 {
33     /**
34       Add a jar file to the current connection's database.
35
36       @exception StandardException Opps
37       */

38     static public void
39     add(String JavaDoc schemaName, String JavaDoc sqlName, String JavaDoc externalPath)
40          throws StandardException
41     {
42         schemaName = JarDDL.getSchemaName(schemaName);
43
44         GenericConstantActionFactory caf = getConstantActionFactory();
45         ConstantAction ca =
46             caf.getAddJarConstantAction(null,schemaName,sqlName,externalPath);
47         ca.executeConstantAction(null);
48     }
49
50
51     /**
52       Drop a jar file from the current connection's database.
53
54       @exception StandardException Opps
55       */

56     static public void
57     drop(String JavaDoc schemaName, String JavaDoc sqlName)
58          throws StandardException
59     {
60         schemaName = JarDDL.getSchemaName(schemaName);
61
62         GenericConstantActionFactory caf = getConstantActionFactory();
63         ConstantAction ca =
64             caf.getDropJarConstantAction(null,schemaName,sqlName);
65         ca.executeConstantAction(null);
66     }
67
68     /**
69       Replace a jar file from the current connection's database with the content of an
70       external file.
71
72       @exception StandardException Opps
73       */

74     static public void
75     replace(String JavaDoc schemaName, String JavaDoc sqlName,String JavaDoc externalPath)
76          throws StandardException
77     {
78         schemaName = JarDDL.getSchemaName(schemaName);
79
80         GenericConstantActionFactory caf = getConstantActionFactory();
81         ConstantAction ca =
82             caf.getReplaceJarConstantAction(null,schemaName,sqlName,externalPath);
83         ca.executeConstantAction(null);
84     }
85
86     private static GenericConstantActionFactory getConstantActionFactory()
87     {
88         ExecutionContext ec =
89             (ExecutionContext)ContextService.getContext(ExecutionContext.CONTEXT_ID);
90         GenericExecutionFactory gef =
91             (GenericExecutionFactory)ec.getExecutionFactory();
92         GenericConstantActionFactory caf = gef.getConstantActionFactory();
93         return caf;
94     }
95
96     private static String JavaDoc getSchemaName(String JavaDoc schemaName) {
97
98         if (schemaName != null)
99             return schemaName;
100
101         // find the language context.
102
LanguageConnectionContext lcc = (LanguageConnectionContext) ContextService.getContext(LanguageConnectionContext.CONTEXT_ID);
103
104         schemaName = lcc.getCurrentSchemaName();
105
106         return schemaName;
107     }
108     
109     /**
110       Make an external name for a file stored in the database.
111       */

112     public static String JavaDoc mkExternalName(String JavaDoc schemaName, String JavaDoc sqlName, char separatorChar)
113     {
114         StringBuffer JavaDoc sb = new StringBuffer JavaDoc(30);
115
116         sb.append(FileResource.JAR_DIRECTORY_NAME);
117         sb.append(separatorChar);
118         sb.append(schemaName);
119         sb.append(separatorChar);
120         sb.append(sqlName);
121         sb.append(".jar");
122         return sb.toString();
123     }
124 }
125
Popular Tags