1 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 38 static public void 39 add(String schemaName, String sqlName, String 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 56 static public void 57 drop(String schemaName, String 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 74 static public void 75 replace(String schemaName, String sqlName,String 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 getSchemaName(String schemaName) { 97 98 if (schemaName != null) 99 return schemaName; 100 101 LanguageConnectionContext lcc = (LanguageConnectionContext) ContextService.getContext(LanguageConnectionContext.CONTEXT_ID); 103 104 schemaName = lcc.getCurrentSchemaName(); 105 106 return schemaName; 107 } 108 109 112 public static String mkExternalName(String schemaName, String sqlName, char separatorChar) 113 { 114 StringBuffer sb = new StringBuffer (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 |