EMMA Coverage Report (generated Wed Jun 28 22:15:27 PDT 2006)
[all classes][org.apache.derby.catalog]

COVERAGE SUMMARY FOR SOURCE FILE [SystemProcedures.java]

nameclass, %method, %block, %line, %
SystemProcedures.java100% (1/1)91%  (39/43)65%  (693/1069)70%  (164.8/234)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class SystemProcedures100% (1/1)91%  (39/43)65%  (693/1069)70%  (164.8/234)
<static initializer> 100% (1/1)100% (19/19)100% (1/1)
INSTALL_JAR (String, String, int): void 100% (1/1)90%  (35/39)87%  (13/15)
METADATA (ResultSet []): void 0%   (0/1)0%   (0/14)0%   (0/5)
REMOVE_JAR (String, int): void 100% (1/1)82%  (31/38)80%  (12/15)
REPLACE_JAR (String, String): void 100% (1/1)72%  (28/39)67%  (10/15)
SQLCAMESSAGE (int, short, String, String, int, int, int, int, int, int, Strin... 100% (1/1)22%  (33/153)25%  (6.3/25)
SQLCOLPRIVILEGES (String, String, String, String, String, ResultSet []): void 100% (1/1)100% (10/10)100% (2/2)
SQLCOLUMNS (String, String, String, String, String, ResultSet []): void 100% (1/1)71%  (15/21)86%  (1.7/2)
SQLFOREIGNKEYS (String, String, String, String, String, String, String, Resul... 100% (1/1)100% (52/52)100% (8/8)
SQLGETTYPEINFO (short, String, ResultSet []): void 100% (1/1)85%  (11/13)92%  (1.8/2)
SQLPRIMARYKEYS (String, String, String, String, ResultSet []): void 100% (1/1)74%  (14/19)86%  (1.7/2)
SQLPROCEDURECOLS (String, String, String, String, String, ResultSet []): void 100% (1/1)71%  (15/21)86%  (1.7/2)
SQLPROCEDURES (String, String, String, String, ResultSet []): void 100% (1/1)74%  (14/19)86%  (1.7/2)
SQLSPECIALCOLUMNS (short, String, String, String, short, short, String, Resul... 100% (1/1)75%  (39/52)86%  (4.3/5)
SQLSTATISTICS (String, String, String, short, short, String, ResultSet []): void 100% (1/1)75%  (27/36)88%  (3.5/4)
SQLTABLEPRIVILEGES (String, String, String, String, ResultSet []): void 100% (1/1)100% (9/9)100% (2/2)
SQLTABLES (String, String, String, String, String, ResultSet []): void 100% (1/1)75%  (65/87)78%  (17.1/22)
SQLUDTS (String, String, String, String, String, ResultSet []): void 0%   (0/1)0%   (0/68)0%   (0/16)
SYSCS_BACKUP_DATABASE (String): void 100% (1/1)100% (4/4)100% (2/2)
SYSCS_BACKUP_DATABASE_AND_ENABLE_LOG_ARCHIVE_MODE (String, int): void 100% (1/1)100% (9/9)100% (2/2)
SYSCS_BULK_INSERT (String, String, String, String): void 0%   (0/1)0%   (0/70)0%   (0/7)
SYSCS_CHECKPOINT_DATABASE (): void 100% (1/1)100% (3/3)100% (2/2)
SYSCS_CHECK_TABLE (String, String): int 100% (1/1)90%  (9/10)95%  (1.9/2)
SYSCS_COMPRESS_TABLE (String, String, int): void 100% (1/1)100% (37/37)100% (5/5)
SYSCS_DISABLE_LOG_ARCHIVE_MODE (int): void 100% (1/1)100% (8/8)100% (2/2)
SYSCS_EXPORT_QUERY (String, String, String, String, String): void 100% (1/1)100% (12/12)100% (4/4)
SYSCS_EXPORT_TABLE (String, String, String, String, String, String): void 100% (1/1)100% (13/13)100% (4/4)
SYSCS_FREEZE_DATABASE (): void 100% (1/1)100% (3/3)100% (2/2)
SYSCS_GET_DATABASE_PROPERTY (String): String 100% (1/1)100% (3/3)100% (1/1)
SYSCS_GET_RUNTIMESTATISTICS (): String 100% (1/1)100% (10/10)100% (4/4)
SYSCS_IMPORT_DATA (String, String, String, String, String, String, String, St... 100% (1/1)100% (22/22)100% (8/8)
SYSCS_IMPORT_TABLE (String, String, String, String, String, String, short): void 100% (1/1)100% (20/20)100% (8/8)
SYSCS_INPLACE_COMPRESS_TABLE (String, String, int, int, int): void 100% (1/1)100% (22/22)100% (2/2)
SYSCS_SET_DATABASE_PROPERTY (String, String): void 100% (1/1)100% (4/4)100% (2/2)
SYSCS_SET_RUNTIMESTATISTICS (int): void 100% (1/1)100% (8/8)100% (2/2)
SYSCS_SET_STATISTICS_TIMING (int): void 100% (1/1)100% (8/8)100% (2/2)
SYSCS_UNFREEZE_DATABASE (): void 100% (1/1)100% (3/3)100% (2/2)
SystemProcedures (): void 0%   (0/1)0%   (0/3)0%   (0/1)
checkJarSQLName (String): void 100% (1/1)75%  (9/12)67%  (2/3)
getDMD (): DatabaseMetaData 100% (1/1)100% (5/5)100% (2/2)
getDefaultConn (): Connection 100% (1/1)87%  (13/15)83%  (5/6)
getOption (String, String): String 100% (1/1)90%  (37/41)83%  (10/12)
isForODBC (String): boolean 100% (1/1)93%  (14/15)96%  (1.9/2)

1/*
2 
3   Derby - Class org.apache.derby.catalog.SystemProcedures
4 
5   Copyright 2003, 2004 The Apache Software Foundation or its licensors, as applicable.
6 
7   Licensed under the Apache License, Version 2.0 (the "License");
8   you may not use this file except in compliance with the License.
9   You may obtain a copy of the License at
10 
11      http://www.apache.org/licenses/LICENSE-2.0
12 
13   Unless required by applicable law or agreed to in writing, software
14   distributed under the License is distributed on an "AS IS" BASIS,
15   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   See the License for the specific language governing permissions and
17   limitations under the License.
18 
19 */
20 
21package org.apache.derby.catalog;
22 
23import org.apache.derby.iapi.services.sanity.SanityManager;
24 
25import org.apache.derby.iapi.services.i18n.MessageService;
26import org.apache.derby.iapi.error.PublicAPI;
27import org.apache.derby.iapi.error.StandardException;
28import org.apache.derby.iapi.reference.SQLState;
29import java.sql.ResultSet;
30import java.sql.Connection;
31import java.sql.PreparedStatement;
32import java.sql.SQLException;
33import java.sql.DatabaseMetaData;
34import java.util.StringTokenizer;
35import java.util.NoSuchElementException;
36 
37import org.apache.derby.jdbc.InternalDriver;
38import org.apache.derby.iapi.db.Factory;
39import org.apache.derby.iapi.db.PropertyInfo;
40import org.apache.derby.impl.jdbc.Util;
41import org.apache.derby.impl.load.Export;
42import org.apache.derby.impl.load.Import;
43import org.apache.derby.impl.jdbc.EmbedDatabaseMetaData;
44 
45import org.apache.derby.impl.sql.execute.JarDDL;
46import org.apache.derby.iapi.util.IdUtil;
47import org.apache.derby.iapi.error.PublicAPI;
48import org.apache.derby.iapi.error.StandardException;
49import org.apache.derby.iapi.sql.conn.ConnectionUtil;
50 
51 
52/**
53        Some system built-in procedures, and help routines.  Now used for network server.
54        These procedures are built-in to the SYSIBM schema which match the DB2 SYSIBM procedures.
55        Currently information on those can be found at url: 
56        ftp://ftp.software.ibm.com/ps/products/db2/info/vr8/pdf/letter/db2l2e80.pdf
57        
58        <P>
59        Also used for builtin-routines, such as SYSFUN functions, when direct calls
60        into Java libraries cannot be made.
61*/
62public class SystemProcedures  {
63 
64 
65        private final static int SQL_BEST_ROWID = 1;
66        private final static int SQL_ROWVER = 2;
67        private final static String DRIVER_TYPE_OPTION = "DATATYPE";
68        private final static String ODBC_DRIVER_OPTION = "'ODBC'";
69 
70    // This token delimiter value is used to separate the tokens for multiple 
71    // error messages.  This is used in DRDAConnThread
72    /**
73     * <code>SQLERRMC_MESSAGE_DELIMITER</code> When message argument tokes are sent,
74     * this value separates the tokens for mulitiple error messages 
75     */
76    public  static String SQLERRMC_MESSAGE_DELIMITER = new String(new char[] {(char)20,(char)20,(char)20});
77 
78        /**
79          Method used by Cloudscape Network Server to get localized message (original call
80          from jcc.
81 
82          @param sqlcode        sqlcode, not used.
83          @param errmcLen        sqlerrmc length
84          @param sqlerrmc        sql error message tokens, variable part of error message (ie.,
85                                                arguments) plus messageId, separated by separator.
86          @param sqlerrp        not used
87          @param errd0          not used
88          @param errd1          not used
89          @param errd2          not used
90          @param errd3          not used
91          @param errd4          not used
92          @param errd5          not used
93          @param warn                not used
94          @param sqlState        5-char sql state
95          @param file                not used
96          @param localeStr        client locale in string
97          @param msg                OUTPUT parameter, localized error message
98          @param rc                        OUTPUT parameter, return code -- 0 for success
99         */
100        public static void SQLCAMESSAGE(int sqlcode, short errmcLen, String sqlerrmc,
101                                                                                String sqlerrp, int errd0, int errd1, int errd2,
102                                                                                int errd3, int errd4, int errd5, String warn,
103                                                                                String sqlState, String file, String localeStr,
104                                                                                String[] msg, int[] rc)
105        {
106                int numMessages = 1;
107        
108 
109                // Figure out if there are multiple exceptions in sqlerrmc. If so get each one
110                // translated and append to make the final result.
111                for (int index=0; ; numMessages++)
112                {
113                        if (sqlerrmc.indexOf(SQLERRMC_MESSAGE_DELIMITER, index) == -1)
114                                break;
115                        index = sqlerrmc.indexOf(SQLERRMC_MESSAGE_DELIMITER, index) + 
116                        SQLERRMC_MESSAGE_DELIMITER.length();
117                }
118 
119                // Putting it here instead of prepareCall it directly is because inter-jar reference tool
120                // cannot detect/resolve this otherwise
121                if (numMessages == 1)
122                        MessageService.getLocalizedMessage(sqlcode, errmcLen, sqlerrmc, sqlerrp, errd0, errd1,
123                                                                                        errd2, errd3, errd4, errd5, warn, sqlState, file,
124                                                                                        localeStr, msg, rc);
125                else
126                {
127                        int startIdx=0, endIdx;
128                        String sqlError;
129                        String[] errMsg = new String[2];
130                        for (int i=0; i<numMessages; i++)
131                        {
132                                endIdx = sqlerrmc.indexOf(SQLERRMC_MESSAGE_DELIMITER, startIdx);
133                                if (i == numMessages-1)                                // last error message
134                                        sqlError = sqlerrmc.substring(startIdx);
135                                else sqlError = sqlerrmc.substring(startIdx, endIdx);
136 
137                                if (i > 0)
138                                {
139                                        /* Strip out the SQLState */
140                                        sqlState = sqlError.substring(0, 5);
141                                        sqlError = sqlError.substring(6);
142                                        msg[0] += " SQLSTATE: " + sqlState + ": ";
143                                }
144 
145                                MessageService.getLocalizedMessage(sqlcode, (short)sqlError.length(), sqlError,
146                                                                                        sqlerrp, errd0, errd1, errd2, errd3, errd4, errd5,
147                                                                                        warn, sqlState, file, localeStr, errMsg, rc);
148 
149                                if (rc[0] == 0)                        // success
150                                {
151                                        if (i == 0)
152                                                msg[0] = errMsg[0];
153                                        else msg[0] += errMsg[0];        // append the new message
154                                }
155                                startIdx = endIdx + SQLERRMC_MESSAGE_DELIMITER.length();
156                        }
157                }
158        }
159        
160        /**
161         * Get the default or nested connection corresponding to the URL
162         * jdbc:default:connection. We do not use DriverManager here
163         * as it is not supported in JSR 169. IN addition we need to perform
164         * more checks for null drivers or the driver returing null from connect
165         * as that logic is in DriverManager.
166         * @return The nested connection
167         * @throws SQLException Not running in a SQL statement
168         */
169        private static Connection getDefaultConn()throws SQLException
170        {
171                InternalDriver id = InternalDriver.activeDriver();
172                if (id != null) { 
173                        Connection conn = id.connect("jdbc:default:connection", null);
174                        if (conn != null)
175                                return conn;
176                }
177                throw Util.noCurrentConnection();
178        }
179 
180        /**
181         *  Get the DatabaseMetaData for the current connection for use in
182         *  mapping the jcc SYSIBM.* calls to the Cloudscape DatabaseMetaData methods 
183         *
184         *  @return The DatabaseMetaData object of the current connection
185         */
186        private static DatabaseMetaData getDMD() throws SQLException {
187                Connection conn = getDefaultConn();
188                return conn.getMetaData();
189        }
190 
191        /**
192         *  Map SQLProcedures to EmbedDatabaseMetaData.getProcedures
193         *
194         *  @param catalogName SYSIBM.SQLProcedures CatalogName varchar(128),
195         *  @param schemaName  SYSIBM.SQLProcedures SchemaName  varchar(128),
196         *  @param procName    SYSIBM.SQLProcedures ProcName    varchar(128),
197         *  @param options     SYSIBM.SQLProcedures Options     varchar(4000))
198         *  @param rs          output parameter, the resultset object containing 
199     *                     the result of getProcedures
200         *          If options contains the string 'DATATYPE='ODBC'', call the ODBC
201         *          version of this procedure.
202         */
203        public static void SQLPROCEDURES (String catalogName, String schemaName, String procName,
204                                                                                String options, ResultSet[] rs) throws SQLException
205        {
206                rs[0] = isForODBC(options)
207                        ? ((EmbedDatabaseMetaData)getDMD()).getProceduresForODBC(
208                                catalogName, schemaName, procName)
209                        : getDMD().getProcedures(catalogName, schemaName, procName);
210        }
211 
212        /**
213         *  Map SQLFunctions to EmbedDatabaseMetaData.getFunctions
214         *
215         *  @param catalogName SYSIBM.SQLFunctions CatalogName varchar(128),
216         *  @param schemaName  SYSIBM.SQLFunctions SchemaName  varchar(128),
217         *  @param funcName    SYSIBM.SQLFunctions ProcName    varchar(128),
218         *  @param options     SYSIBM.SQLFunctions Options     varchar(4000)) 
219         *                     (not used)
220         *  @param rs          output parameter, the resultset object containing 
221         *                     the result of getFunctions
222         */
223        public static void SQLFUNCTIONS(String catalogName, 
224                                                                        String schemaName, 
225                                                                        String funcName,
226                                                                        String options, 
227                                                                        ResultSet[] rs) throws SQLException
228        {
229                rs[0] = ((EmbedDatabaseMetaData)getDMD()).
230                        getFunctions(catalogName, schemaName, funcName);
231        }
232 
233        /**
234         * Map SQLTables to EmbedDatabaseMetaData.getSchemas, getCatalogs,
235         * getTableTypes and getTables, and return the result of the
236         * DatabaseMetaData calls.
237         *
238         * <p>JCC and DNC overload this method:
239         * <ul>
240         * <li>If options contains the string 'GETSCHEMAS=1',
241         *     call getSchemas()</li>
242         * <li>If options contains the string 'GETSCHEMAS=2',
243         *     call getSchemas(String, String)</li>
244         * <li>If options contains the string 'GETCATALOGS=1',
245         *     call getCatalogs()</li>
246         * <li>If options contains the string 'GETTABLETYPES=1',
247         *     call getTableTypes()</li>
248         * <li>otherwise, call getTables()</li>
249         * </ul>
250         *
251         *  @param catalogName SYSIBM.SQLTables CatalogName varchar(128),
252         *  @param schemaName  SYSIBM.SQLTables SchemaName  varchar(128),
253         *  @param tableName   SYSIBM.SQLTables TableName   varchar(128),
254         *  @param tableType   SYSIBM.SQLTables TableType   varchar(4000))
255         *  @param options     SYSIBM.SQLTables Options     varchar(4000))
256         *  @param rs          output parameter, the resultset object 
257         */
258        public static void SQLTABLES (String catalogName, String schemaName, String tableName,
259                                                                                String tableType, String options, ResultSet[] rs)
260                throws SQLException
261        {
262 
263                String optionValue = getOption("GETCATALOGS", options);
264                if (optionValue != null && optionValue.trim().equals("1"))
265                {
266                        rs[0] = getDMD().getCatalogs();
267                        return;
268                }
269                optionValue = getOption("GETTABLETYPES", options);
270                if (optionValue != null && optionValue.trim().equals("1"))
271                {
272                        rs[0] = getDMD().getTableTypes();
273                        return;
274                }
275                optionValue = getOption("GETSCHEMAS", options);
276                if (optionValue != null) {
277                        optionValue = optionValue.trim();
278                        if (optionValue.equals("1")) {
279                                rs[0] = getDMD().getSchemas();
280                                return;
281                        }
282                        if (optionValue.equals("2")) {
283                                EmbedDatabaseMetaData edmd = (EmbedDatabaseMetaData) getDMD();
284                                rs[0] = edmd.getSchemas(catalogName, schemaName);
285                                return;
286                        }
287                }
288                                 
289 
290                String[] typeArray = null;
291                if (tableType != null)
292                {
293                        StringTokenizer st = new StringTokenizer(tableType,"',");
294                        typeArray = new String[st.countTokens()];
295                        int i = 0;
296 
297                        while (st.hasMoreTokens()) 
298                        {
299                                typeArray[i] = st.nextToken();
300                                i++;
301                        }
302                }
303                rs[0] = getDMD().getTables(catalogName, schemaName, tableName, typeArray);
304        }
305 
306        /**
307         *  Map SQLForeignKeys to EmbedDatabaseMetaData.getImportedKeys, getExportedKeys, and getCrossReference
308         *
309         *  @param pkCatalogName SYSIBM.SQLForeignKeys PKCatalogName varchar(128),
310         *  @param pkSchemaName  SYSIBM.SQLForeignKeys PKSchemaName  varchar(128),
311         *  @param pkTableName   SYSIBM.SQLForeignKeys PKTableName   varchar(128),
312         *  @param fkCatalogName SYSIBM.SQLForeignKeys FKCatalogName varchar(128),
313         *  @param fkSchemaName  SYSIBM.SQLForeignKeys FKSchemaName  varchar(128),
314         *  @param fkTableName   SYSIBM.SQLForeignKeys FKTableName   varchar(128),
315         *  @param options       SYSIBM.SQLForeignKeys Options       varchar(4000))
316         *  @param rs            output parameter, the resultset object 
317         *                              containing the result of the DatabaseMetaData calls
318         *                           JCC overloads this method:
319         *                           If options contains the string 'EXPORTEDKEY=1', call getImportedKeys
320         *                           If options contains the string 'IMPORTEDKEY=1', call getExportedKeys
321         *                           otherwise, call getCrossReference
322         */
323        public static void SQLFOREIGNKEYS (String pkCatalogName, String pkSchemaName, String pkTableName,
324                                                                                String fkCatalogName, String fkSchemaName, String fkTableName,
325                                                                                String options, ResultSet[] rs)
326                throws SQLException
327        {
328 
329                String exportedKeyProp = getOption("EXPORTEDKEY", options);
330                String importedKeyProp = getOption("IMPORTEDKEY", options);
331 
332                if (importedKeyProp != null && importedKeyProp.trim().equals("1"))
333                        rs[0] = getDMD().getImportedKeys(fkCatalogName,
334                                                                                fkSchemaName,fkTableName);
335                else if (exportedKeyProp != null && exportedKeyProp.trim().equals("1"))
336                        rs[0] = getDMD().getExportedKeys(pkCatalogName,
337                                                                                pkSchemaName,pkTableName);
338                else
339                        rs[0] = getDMD().getCrossReference (pkCatalogName,
340                                                                                   pkSchemaName,
341                                                                                   pkTableName,
342                                                                                   fkCatalogName,
343                                                                                   fkSchemaName,
344                                                                                   fkTableName);
345        }
346 
347        /**
348         *  Helper for SQLForeignKeys and SQLTables 
349         *
350         *  @return option        String containing the value for a given option 
351         *  @param  pattern         String containing the option to search for
352         *  @param  options         String containing the options to search through
353         */
354        private static String getOption(String pattern, String options)
355        {
356                if (options == null)
357                        return null;
358                int start = options.lastIndexOf(pattern);
359                if (start < 0)  // not there
360                        return null;
361                int valueStart = options.indexOf('=', start);
362                if (valueStart < 0)  // invalid options string
363                        return null;
364                int valueEnd = options.indexOf(';', valueStart);
365                if (valueEnd < 0)  // last option
366                        return options.substring(valueStart + 1);
367                else
368                        return options.substring(valueStart + 1, valueEnd);
369        }
370        
371        /**
372         *  Map SQLProcedureCols to EmbedDatabaseMetaData.getProcedureColumns
373         *
374         *  @param catalogName SYSIBM.SQLProcedureCols CatalogName varchar(128),
375         *  @param schemaName  SYSIBM.SQLProcedureCols SchemaName  varchar(128),
376         *  @param procName    SYSIBM.SQLProcedureCols ProcName    varchar(128),
377         *  @param paramName   SYSIBM.SQLProcedureCols ParamName   varchar(128),
378         *  @param options     SYSIBM.SQLProcedureCols Options     varchar(4000))
379         *  @param rs          output parameter, the resultset object containing 
380         *                                   the result of getProcedureColumns
381         *          If options contains the string 'DATATYPE='ODBC'', call the ODBC
382         *          version of this procedure.
383         */
384        public static void SQLPROCEDURECOLS (String catalogName, String schemaName, String procName,
385                                                                                String paramName, String options, ResultSet[] rs)
386                throws SQLException
387        {
388                rs[0] = isForODBC(options)
389                        ? ((EmbedDatabaseMetaData)getDMD()).getProcedureColumnsForODBC(
390                                catalogName, schemaName, procName, paramName)
391                        : getDMD().getProcedureColumns(catalogName, schemaName, procName, paramName);
392        }
393        
394        /**
395         *  Map SQLFunctionParameters to
396         *  EmbedDatabaseMetaData.getFunctionParameters()
397         *
398         * @param catalogName SYSIBM.SQLFunctionParameters CatalogName
399         * varchar(128),
400         * @param schemaName SYSIBM.SQLFunctionParameters SchemaName
401         * varchar(128),
402         * @param funcName SYSIBM.SQLFunctionParameters FuncName
403         * varchar(128),
404         * @param paramName SYSIBM.SQLFunctionParameters ParamName
405         * varchar(128),
406         * @param options SYSIBM.SQLFunctionParameters Options
407         * varchar(4000))
408         * @param rs output parameter, the resultset object containing the
409         * result of getFunctionParameters(). 
410         */
411        public static void SQLFUNCTIONPARAMS(String catalogName,
412                                                                                 String schemaName,
413                                                                                 String funcName,
414                                                                                 String paramName,
415                                                                                 String options,
416                                                                                 ResultSet[] rs) throws SQLException
417        {
418                        rs[0] = ((EmbedDatabaseMetaData)getDMD()).
419                                getFunctionParameters(catalogName, schemaName, funcName, 
420                                                                          paramName);
421        }
422        
423 
424        /**
425         *  Map SQLColumns to EmbedDatabaseMetaData.getColumns
426         *
427         *  @param catalogName SYSIBM.SQLColumns CatalogName varchar(128),
428         *  @param schemaName  SYSIBM.SQLColumns SchemaName  varchar(128),
429         *  @param tableName   SYSIBM.SQLColumns TableName   varchar(128),
430         *  @param columnName  SYSIBM.SQLColumns ColumnName  varchar(128),
431         *  @param options     SYSIBM.SQLColumns Options     varchar(4000))
432         *          If options contains the string 'DATATYPE='ODBC'', call the ODBC
433         *          version of this procedure.
434         *  @param rs          output parameter, the resultset object containing 
435     *                     the result of getProcedures
436         */
437        public static void SQLCOLUMNS (String catalogName, String schemaName, String tableName,
438                                                                                String columnName, String options, ResultSet[] rs)
439                throws SQLException
440        {
441                rs[0] = isForODBC(options)
442                        ? ((EmbedDatabaseMetaData)getDMD()).getColumnsForODBC(
443                                catalogName, schemaName, tableName, columnName)
444                        : getDMD().getColumns(catalogName, schemaName, tableName, columnName);
445        }
446 
447        /**
448         *  Map SQLColPrivileges to EmbedDatabaseMetaData.getColumnPrivileges
449         *
450         *  @param catalogName SYSIBM.SQLColPrivileges CatalogName varchar(128),
451         *  @param schemaName  SYSIBM.SQLColPrivileges SchemaName  varchar(128),
452         *  @param tableName   SYSIBM.SQLColPrivileges ProcName    varchar(128),
453         *  @param columnName  SYSIBM.SQLColPrivileges ColumnName  varchar(128),
454         *  @param options     SYSIBM.SQLColPrivileges Options     varchar(4000))
455         *  @param rs          output parameter, the resultset object containing 
456     *                     the result of getColumnPrivileges
457         */
458        public static void SQLCOLPRIVILEGES (String catalogName, String schemaName, String tableName,
459                                                                                String columnName, String options, ResultSet[] rs)
460                throws SQLException
461        {
462                rs[0] = getDMD().getColumnPrivileges(catalogName, schemaName, tableName, columnName);
463        }
464 
465        /**
466         *  Map SQLTablePrivileges to EmbedDatabaseMetaData.getTablePrivileges
467         *
468         *  @param catalogName SYSIBM.SQLTablePrivileges CatalogName varchar(128),
469         *  @param schemaName  SYSIBM.SQLTablePrivileges SchemaName  varchar(128),
470         *  @param tableName   SYSIBM.SQLTablePrivileges ProcName    varchar(128),
471         *  @param options     SYSIBM.SQLTablePrivileges Options     varchar(4000))
472         *  @param rs          output parameter, the resultset object containing 
473     *                     the result of getTablePrivileges
474         */
475        public static void SQLTABLEPRIVILEGES (String catalogName, String schemaName, String tableName,
476                                                                                String options, ResultSet[] rs)
477                throws SQLException
478        {
479                rs[0] = getDMD().getTablePrivileges(catalogName, schemaName, tableName);
480        }
481 
482        /**
483         *  Map SQLPrimaryKeys to EmbedDatabaseMetaData.getPrimaryKeys
484         *
485         *  @param catalogName SYSIBM.SQLPrimaryKeys CatalogName varchar(128),
486         *  @param schemaName  SYSIBM.SQLPrimaryKeys SchemaName  varchar(128),
487         *  @param tableName   SYSIBM.SQLPrimaryKeys TableName   varchar(128),
488         *  @param options     SYSIBM.SQLPrimaryKeys Options     varchar(4000))
489         *          If options contains the string 'DATATYPE='ODBC'', call the ODBC
490         *          version of this procedure.
491         *  @param rs          output parameter, the resultset object containing 
492     *                     the result of getPrimaryKeys
493         */
494        public static void SQLPRIMARYKEYS (String catalogName, String schemaName, String tableName, String options, ResultSet[] rs)
495                throws SQLException
496        {
497                rs[0] = isForODBC(options)
498                        ? ((EmbedDatabaseMetaData)getDMD()).getPrimaryKeysForODBC(
499                                catalogName, schemaName, tableName)
500                        : getDMD().getPrimaryKeys(catalogName, schemaName, tableName);
501        }
502 
503        /**
504         *  Map SQLGetTypeInfo to EmbedDatabaseMetaData.getTypeInfo
505         *
506         *  @param dataType  SYSIBM.SQLGetTypeInfo DataType smallint,
507         *  @param options   SYSIBM.SQLGetTypeInfo Options  varchar(4000))
508         *          If options contains the string 'DATATYPE='ODBC'', call the ODBC
509         *          version of this procedure.
510         *  @param rs        output parameter, the resultset object containing the
511     *                   result of getTypeInfo
512         */
513        public static void SQLGETTYPEINFO (short dataType, String options, ResultSet[] rs)
514                throws SQLException
515        {
516                rs[0] = isForODBC(options)
517                        ? ((EmbedDatabaseMetaData)getDMD()).getTypeInfoForODBC()
518                        : getDMD().getTypeInfo();
519        }
520 
521        /**
522         *  Map SQLStatistics to EmbedDatabaseMetaData.getIndexInfo
523         *
524         *  @param catalogName SYSIBM.SQLStatistics CatalogName varchar(128),
525         *  @param schemaName  SYSIBM.SQLStatistics SchemaName  varchar(128),
526         *  @param tableName   SYSIBM.SQLStatistics TableName   varchar(128),
527         *  @param unique      SYSIBM.SQLStatistics Unique      smallint; 0=SQL_INDEX_UNIQUE(0); 1=SQL_INDEX_ALL(1),
528         *  @param approximate SYSIBM.SQLStatistics Approximate smallint; 1=true; 0=false,
529         *  @param options     SYSIBM.SQLStatistics Options     varchar(4000))
530         *          If options contains the string 'DATATYPE='ODBC'', call the ODBC
531         *          version of this procedure.
532         *  @param rs          output parameter, the resultset object containing 
533     *                     the result of getIndexInfo
534         */
535        public static void SQLSTATISTICS (String catalogName, String schemaName, String tableName,
536                                                                                short unique, short approximate, String options, ResultSet[] rs)
537                throws SQLException
538        {
539                boolean boolUnique = (unique == 0) ? true: false;
540                boolean boolApproximate = (approximate == 1) ? true: false;
541                        
542                rs[0] = isForODBC(options)
543                        ? ((EmbedDatabaseMetaData)getDMD()).getIndexInfoForODBC(
544                                catalogName, schemaName, tableName, boolUnique, boolApproximate)
545                        : getDMD().getIndexInfo(catalogName, schemaName, tableName, boolUnique, boolApproximate);
546        }
547 
548        /**
549         *  Map SQLSpecialColumns to EmbedDatabaseMetaData.getBestRowIdentifier and getVersionColumns
550         *
551         *  @param colType     SYSIBM.SQLSpecialColumns ColType     smallint,
552         *                        where 1 means getBestRowIdentifier and 2 getVersionColumns was called.
553         *  @param catalogName SYSIBM.SQLSpecialColumns CatalogName varchar(128),
554         *  @param schemaName  SYSIBM.SQLSpecialColumns SchemaName  varchar(128),
555         *  @param tableName   SYSIBM.SQLSpecialColumns TableName   varchar(128),
556         *  @param scope       SYSIBM.SQLSpecialColumns Scope       smallint,
557         *  @param nullable    SYSIBM.SQLSpecialColumns Nullable    smallint; 0=false, 1=true,
558         *  @param options     SYSIBM.SQLSpecialColumns Options     varchar(4000))
559         *          If options contains the string 'DATATYPE='ODBC'', call the ODBC
560         *          version of this procedure.
561         *  @param rs          output parameter, the resultset object containing 
562     *                     the result of the DatabaseMetaData call
563         */
564        public static void SQLSPECIALCOLUMNS (short colType, String catalogName, String schemaName, String tableName,
565                                                                                short scope, short nullable, String options, ResultSet[] rs)
566                throws SQLException
567        {
568 
569                boolean boolNullable = (nullable == 1) ? true: false;
570                if (colType == SQL_BEST_ROWID)
571                {
572                        rs[0] = isForODBC(options)
573                                ? ((EmbedDatabaseMetaData)getDMD()).getBestRowIdentifierForODBC(
574                                        catalogName, schemaName, tableName, scope, boolNullable)
575                                : getDMD().getBestRowIdentifier(catalogName, schemaName, tableName, scope, boolNullable);
576                }
577                else // colType must be SQL_ROWVER
578                {
579                        rs[0] = isForODBC(options)
580                                ? ((EmbedDatabaseMetaData)getDMD()).getVersionColumnsForODBC(
581                                        catalogName, schemaName, tableName)
582                                : getDMD().getVersionColumns(catalogName, schemaName, tableName);
583                }
584        }
585 
586        /**
587         *  Map SQLUDTS to EmbedDatabaseMetaData.getUDTs
588         *
589         *  @param catalogName     SYSIBM.SQLUDTS CatalogName          varchar(128),
590         *  @param schemaPattern   SYSIBM.SQLUDTS Schema_Name_Pattern  varchar(128),
591         *  @param typeNamePattern SYSIBM.SQLUDTS Type_Name_Pattern    varchar(128),
592         *  @param udtTypes        SYSIBM.SQLUDTS UDTTypes             varchar(128),
593         *  @param options         SYSIBM.SQLUDTS Options              varchar(4000))
594         *  @param rs              output parameter, the resultset object containing
595     *                         the result of getUDTs, which will be empty
596         */
597        public static void SQLUDTS (String catalogName, String schemaPattern, String typeNamePattern,
598                                                                                String udtTypes, String options, ResultSet[] rs)
599                throws SQLException
600        {
601 
602                int[] types = null;
603                
604                if( udtTypes != null && udtTypes.length() > 0)
605                {
606                        StringTokenizer tokenizer = new StringTokenizer( udtTypes, " \t\n\t,");
607                        int udtTypeCount = tokenizer.countTokens();
608                        types = new int[ udtTypeCount];
609                        String udtType = "";
610                        try
611                        {
612                                for( int i = 0; i < udtTypeCount; i++)
613                                {
614                                        udtType = tokenizer.nextToken();
615                                        types[i] = Integer.parseInt( udtType);
616                                }
617                        }
618                        catch( NumberFormatException nfe)
619                        {
620                                throw new SQLException( "Invalid type, " + udtType + ", passed to getUDTs.");
621                        }
622                        catch( NoSuchElementException nsee)
623                        {
624                                throw new SQLException( "Internal failure: NoSuchElementException in getUDTs.");
625                        }
626                }
627                rs[0] = getDMD().getUDTs(catalogName, schemaPattern, typeNamePattern, types);
628        }
629 
630        /*
631         *  Map SYSIBM.METADATA to appropriate EmbedDatabaseMetaData methods 
632         *  for now, using the sps in org.apache.derby.iapi.db.jdbc.datadictionary.metadata_net.properties
633         *
634         */
635        public static void METADATA (ResultSet[] rs)
636                throws SQLException
637        {
638                rs[0] = ((EmbedDatabaseMetaData) getDMD()).getClientCachedMetaData();
639        }
640 
641        /**
642         * Helper for ODBC metadata calls.
643         * @param options        String containig the options to search through.
644         * @return True if options contain ODBC indicator; false otherwise.
645         */
646        private static boolean isForODBC(String options) {
647 
648                String optionValue = getOption(DRIVER_TYPE_OPTION, options);
649                return ((optionValue != null) && optionValue.toUpperCase().equals(ODBC_DRIVER_OPTION));
650 
651        }
652 
653    /**
654     * Set/delete the value of a property of the database in current connection.
655     * <p>
656     * Will be called as SYSCS_UTIL.SYSCS_SET_DATABASE_PROPERTY.
657     *
658     * @param key       The property key.
659     * @param value     The new value, if null the property is deleted.
660     *
661         * @exception  StandardException  Standard exception policy.
662     **/
663    public static void SYSCS_SET_DATABASE_PROPERTY(
664    String  key,
665    String  value)
666        throws SQLException
667    {
668        PropertyInfo.setDatabaseProperty(key, value);
669    }
670 
671    /**
672     * Get the value of a property of the database in current connection.
673     * <p>
674     * Will be called as SYSCS_UTIL.SYSCS_GET_DATABASE_PROPERTY.
675     *
676     * @param key       The property key.
677     *
678         * @exception  StandardException  Standard exception policy.
679     **/
680    public static String SYSCS_GET_DATABASE_PROPERTY(
681    String  key)
682        throws SQLException
683    {
684        return(PropertyInfo.getDatabaseProperty(key));
685    }
686 
687    /**
688     * Compress the table.
689     * <p>
690     * Calls the "alter table compress {sequential}" sql.  This syntax
691     * is not db2 compatible so it mapped by a system routine.  This
692     * routine will be called when an application calls:
693     *
694     *     SYSCS_UTIL.SYSCS_COMPRESS_TABLE
695     * <p>
696     *
697     * @param schema        schema name of the table to compress.  Must be
698     *                      non-null, no default is used.
699     * @param tablename     table name of the table to compress.  Must be
700     *                      non-null.
701     * @param sequential    if non-zero then rebuild indexes sequentially,
702     *                      if 0 then rebuild all indexes in parallel.
703     *
704         * @exception  StandardException  Standard exception policy.
705     **/
706    public static void SYSCS_COMPRESS_TABLE(
707    String  schema,
708    String  tablename,
709    int     sequential)
710        throws SQLException
711    {
712 
713        String query = 
714            "alter table " + "\"" + schema + "\"" + "." + "\"" +  tablename + "\"" + 
715                        " compress" +  (sequential != 0 ? " sequential" : "");
716 
717                Connection conn = getDefaultConn();
718 
719                conn.prepareStatement(query).executeUpdate();
720 
721                conn.close();
722    }
723 
724    /**
725     * Freeze the database.
726     * <p>
727     * Call internal routine to freeze the database so that a backup
728     * can be made.
729     *
730         * @exception  StandardException  Standard exception policy.
731     **/
732    public static void SYSCS_FREEZE_DATABASE()
733                throws SQLException
734    {
735        Factory.getDatabaseOfConnection().freeze();
736    }
737 
738    /**
739     * Unfreeze the database.
740     * <p>
741     * Call internal routine to unfreeze the database, which was "freezed"
742     * by calling SYSCS_FREEZE_DATABASE().
743     * can be made.
744     *
745         * @exception  StandardException  Standard exception policy.
746     **/
747    public static void SYSCS_UNFREEZE_DATABASE()
748                throws SQLException
749    {
750        Factory.getDatabaseOfConnection().unfreeze();
751    }
752 
753    public static void SYSCS_CHECKPOINT_DATABASE()
754                throws SQLException
755    {
756        Factory.getDatabaseOfConnection().checkpoint();
757    }
758 
759    /**
760     * Backup the database to a backup directory. 
761     *
762     * This procedure will throw error, if there are any unlogged 
763     * operation executed in the same transaction backup is started.
764     * If there any unlogged operations in progess in other transaction, it
765     * will wait until those transactions are completed before starting the backup.
766     *
767     * Examples of unlogged operations include: create index and bulk insert.
768     * Note that once the backup begins these operations will not block, 
769     * instead they are automatically converted into logged operations.
770     * 
771     * @param backupDir the name of the directory where the backup should be
772     *                  stored. This directory will be created if it 
773     *                  does not exist.
774     * @exception StandardException thrown on error
775     */
776    public static void SYSCS_BACKUP_DATABASE(String  backupDir)
777                throws SQLException
778    {
779        Factory.getDatabaseOfConnection().backup(backupDir, true);
780    }
781 
782    /**
783     * Backup the database to a backup directory.
784     *
785     * This procedure will throw error, if there are any uncommitted unlogged 
786     * operation before stating the backup. It will not wait for the unlogged
787     * operations to complete.
788     * 
789     * Examples of unlogged operations include: create index and bulk insert.
790     * Note that once the backup begins these operations will not block, 
791     * instead they are automatically converted into logged operations.
792     * 
793     * @param backupDir the name of the directory where the backup should be
794     *                  stored. This directory will be created if it 
795     *                  does not exist.
796     * @exception StandardException thrown on error
797     */
798    public static void SYSCS_BACKUP_DATABASE_NOWAIT(String  backupDir)
799        throws SQLException
800    {
801        Factory.getDatabaseOfConnection().backup(backupDir, false);
802    }
803 
804 
805    /**
806     * Backup the database to a backup directory and enable the log archive
807     * mode that will keep the archived log files required for roll-forward
808     * from this version of the backup.
809     *
810     * This procedure will throw error if there are any unlogged 
811     * operation executed in the same transaction backup is started.
812     * If there any unlogged operations in progess in other transaction, it
813     * will wait until those transactions are completed before starting the backup.
814     *
815     * Examples of unlogged operations include: create index and bulk insert.
816     * Note that once the backup begins these operations will not block, 
817     * instead they are automatically converted into logged operations.
818     *
819     * @param backupDir the name of the directory where the backup should be
820     *                  stored. This directory will be created if not it 
821     *                  does not exist.   
822     * @param deleteOnlineArchivedLogFiles  If <tt>non-zero</tt> deletes online 
823     *                 archived log files that exist before this backup, delete 
824     *                 will occur  only after the backup is  complete.
825     * @exception StandardException thrown on error.
826     */
827    public static void SYSCS_BACKUP_DATABASE_AND_ENABLE_LOG_ARCHIVE_MODE(
828    String  backupDir,
829    int     deleteOnlineArchivedLogFiles)
830                throws SQLException
831    {
832 
833        Factory.getDatabaseOfConnection().backupAndEnableLogArchiveMode(
834                backupDir, 
835                (deleteOnlineArchivedLogFiles != 0),
836                true);
837        }
838 
839    /**
840     * Backup the database to a backup directory and enable the log archive
841         * mode that will keep the archived log files required for roll-forward
842         * from this version backup.
843     *
844     * This procedure will throw error, if there are any uncommitted unlogged 
845     * operation before stating the backup. It will not wait for the unlogged
846     * operations to complete.
847     * 
848 
849     * Examples of unlogged operations include: create index and bulk insert.
850     * Note that once the backup begins these operations will not block, 
851     * instead they are automatically converted into logged operations.
852     *
853     * @param backupDir the name of the directory where the backup should be
854     *                  stored. This directory will be created if not it 
855     *                  does not exist.   
856     *
857     * @param deleteOnlineArchivedLogFiles  If <tt>non-zero</tt> deletes online 
858     *                  archived log files that exist before this backup, delete     
859     *                  will occur  only after the backup is  complete.
860     *
861     * @exception StandardException thrown on error.
862     */
863    public static void SYSCS_BACKUP_DATABASE_AND_ENABLE_LOG_ARCHIVE_MODE_NOWAIT(
864    String  backupDir,
865    int     deleteOnlineArchivedLogFiles)
866                throws SQLException
867    {
868 
869        Factory.getDatabaseOfConnection().backupAndEnableLogArchiveMode(
870                backupDir,
871                (deleteOnlineArchivedLogFiles != 0),
872                false);
873        }
874 
875 
876    /**
877         * Disables the log archival process, i.e No old log files
878         * will be kept around for a roll-forward recovery.
879     *
880         * @param deleteOnlineArchivedLogFiles  If <tt>non-zero</tt> deletes all the
881         *        online archived log files that exist before this call immediately.
882     *
883         * @exception StandardException Thrown on error
884         */
885 
886    public static void SYSCS_DISABLE_LOG_ARCHIVE_MODE(
887    int     deleteOnlineArchivedLogFiles)
888                throws SQLException
889    {
890        Factory.getDatabaseOfConnection().disableLogArchiveMode(
891                (deleteOnlineArchivedLogFiles != 0));
892    }
893 
894 
895    public static void SYSCS_SET_RUNTIMESTATISTICS(
896    int     enable)
897                throws SQLException
898    {
899                ConnectionUtil.getCurrentLCC().setRunTimeStatisticsMode(enable != 0 ? true : false);
900    }
901 
902    public static void SYSCS_SET_STATISTICS_TIMING(
903    int     enable)
904                throws SQLException
905    {
906                ConnectionUtil.getCurrentLCC().setStatisticsTiming(enable != 0 ? true : false);
907    }
908 
909    public static int SYSCS_CHECK_TABLE(
910    String  schema,
911    String  tablename)
912                throws SQLException
913    {
914        boolean ret_val = 
915            org.apache.derby.iapi.db.ConsistencyChecker.checkTable(
916                schema, tablename);
917 
918        return(ret_val ? 1 : 0);
919    }
920 
921    public static void SYSCS_INPLACE_COMPRESS_TABLE(
922    String  schema,
923    String  tablename,
924    int     purgeRows,
925    int     defragementRows,
926    int     truncateEnd)
927                throws SQLException
928    {
929        org.apache.derby.iapi.db.OnlineCompress.compressTable(
930            schema, 
931            tablename, 
932            (purgeRows == 1),
933            (defragementRows == 1),
934            (truncateEnd == 1));
935 
936        return;
937    }
938 
939    public static String SYSCS_GET_RUNTIMESTATISTICS()
940                throws SQLException
941    {
942 
943                Object rts = ConnectionUtil.getCurrentLCC().getRunTimeStatisticsObject();
944 
945                if (rts == null)
946                        return null;
947 
948                return rts.toString();
949 
950    }
951 
952 
953        /*
954        ** SQLJ Procedures.
955        */
956 
957        /**
958                Install a jar file in the database.
959 
960                SQLJ.INSTALL_JAR
961 
962                @param url URL of the jar file to be installed in the database.
963                @param jar SQL name jar will be installed as.
964                @param deploy Ignored.
965 
966                @exception SQLException Error installing jar file.
967        */
968        public static void INSTALL_JAR(String url, String jar, int deploy)
969                throws SQLException {
970 
971                try {
972 
973                        String[] st = IdUtil.parseQualifiedName(jar.trim(), true);
974 
975                        String schemaName = null;
976                        String sqlName = null;
977 
978                        switch (st.length) {
979                        case 1:
980                                schemaName = null;
981                                sqlName = st[0];
982                                break;
983                        case 2:
984                                schemaName = st[0];
985                                sqlName = st[1];
986                        default:
987                                ; // RESOLVE
988                        }
989 
990                        checkJarSQLName(sqlName);
991                        JarDDL.add(schemaName, sqlName, url);
992                } 
993                catch (StandardException se) {
994                        throw PublicAPI.wrapStandardException(se);
995                }
996        }
997 
998        /**
999                Replace a jar file in the database.
1000 
1001                SQLJ.REPLACE_JAR
1002 
1003                @param url URL of the jar file to be installed in the database.
1004                @param jar SQL name of jar to be replaced.
1005 
1006                @exception SQLException Error replacing jar file.
1007        */
1008        public static void REPLACE_JAR(String url, String jar)
1009                throws SQLException {
1010 
1011                try {
1012 
1013                        String[] st = IdUtil.parseQualifiedName(jar.trim(), true);
1014 
1015                        String schemaName = null;
1016                        String sqlName = null;
1017 
1018                        switch (st.length) {
1019                        case 1:
1020                                schemaName = null;
1021                                sqlName = st[0];
1022                                break;
1023                        case 2:
1024                                schemaName = st[0];
1025                                sqlName = st[1];
1026                        default:
1027                                ; // RESOLVE
1028                        }
1029 
1030                        checkJarSQLName(sqlName);
1031                        JarDDL.replace(schemaName, sqlName, url);
1032                } 
1033                catch (StandardException se) {
1034                        throw PublicAPI.wrapStandardException(se);
1035                }
1036        }
1037        /**
1038                Remove a jar file from the database.
1039 
1040                @param jar      SQL name of jar to be replaced.
1041                @param undeploy Ignored.
1042 
1043                @exception SQLException Error removing jar file.
1044        */
1045        public static void REMOVE_JAR(String jar, int undeploy)
1046                throws SQLException {
1047 
1048                try {
1049 
1050                        String[] st = IdUtil.parseQualifiedName(jar.trim(), true);
1051 
1052                        String schemaName = null;
1053                        String sqlName = null;
1054 
1055                        switch (st.length) {
1056                        case 1:
1057                                schemaName = null;
1058                                sqlName = st[0];
1059                                break;
1060                        case 2:
1061                                schemaName = st[0];
1062                                sqlName = st[1];
1063                        default:
1064                                ; // RESOLVE
1065                        }
1066 
1067                        checkJarSQLName(sqlName);
1068 
1069                        JarDDL.drop(schemaName, sqlName);
1070                } 
1071                catch (StandardException se) {
1072                        throw PublicAPI.wrapStandardException(se);
1073                }
1074        }
1075 
1076        private static void checkJarSQLName(String sqlName)
1077                throws StandardException {
1078 
1079                // weed out a few special cases that cause problems.
1080                if (   (sqlName.length() == 0)
1081                        || (sqlName.indexOf(':') != -1)
1082                        ) {
1083 
1084                        throw StandardException.newException(SQLState.ID_PARSE_ERROR);
1085                }
1086        }
1087 
1088        /**
1089     * Export data from a table to given file.
1090     * <p>
1091     * Will be called by system procedure:
1092         * SYSCS_EXPORT_TABLE(IN SCHEMANAME  VARCHAR(128), 
1093         * IN TABLENAME    VARCHAR(128),  IN FILENAME VARCHAR(32672) , 
1094         * IN COLUMNDELIMITER CHAR(1),  IN CHARACTERDELIMITER CHAR(1) ,  
1095         * IN CODESET VARCHAR(128))
1096         * @exception  StandardException  Standard exception policy.
1097     **/
1098        public static void SYSCS_EXPORT_TABLE(
1099        String  schemaName,
1100    String  tableName,
1101        String  fileName,
1102        String  columnDelimiter,
1103        String  characterDelimiter,
1104        String  codeset)
1105        throws SQLException
1106    {
1107                Connection conn = getDefaultConn();
1108                Export.exportTable(conn, schemaName , tableName , fileName ,
1109                                                          columnDelimiter , characterDelimiter, codeset);
1110                //export finished successfully, issue a commit 
1111                conn.commit();
1112        }
1113 
1114        
1115        /**
1116     * Export data from a  select statement to given file.
1117     * <p>
1118     * Will be called as 
1119         * SYSCS_EXPORT_QUERY(IN SELECTSTATEMENT  VARCHAR(32672), 
1120         * IN FILENAME VARCHAR(32672) , 
1121         * IN COLUMNDELIMITER CHAR(1),  IN CHARACTERDELIMITER CHAR(1) ,  
1122         * IN CODESET VARCHAR(128))
1123         *
1124         * @exception  StandardException  Standard exception policy.
1125     **/
1126        public static void SYSCS_EXPORT_QUERY(
1127    String  selectStatement,
1128        String  fileName,
1129        String  columnDelimiter,
1130        String  characterDelimiter,
1131        String  codeset)
1132        throws SQLException
1133    {
1134                Connection conn = getDefaultConn();
1135                Export.exportQuery(conn, selectStatement, fileName ,
1136                                                           columnDelimiter , characterDelimiter, codeset);
1137                
1138                //export finished successfully, issue a commit 
1139                conn.commit();
1140        }
1141 
1142        /**
1143     * Import  data from a given file to a table.
1144     * <p>
1145     * Will be called by system procedure as
1146         * SYSCS_IMPORT_TABLE(IN SCHEMANAME  VARCHAR(128), 
1147         * IN TABLENAME    VARCHAR(128),  IN FILENAME VARCHAR(32672) , 
1148         * IN COLUMNDELIMITER CHAR(1),  IN CHARACTERDELIMITER CHAR(1) ,  
1149         * IN CODESET VARCHAR(128), IN  REPLACE SMALLINT)
1150         * @exception  StandardException  Standard exception policy.
1151     **/
1152        public static void SYSCS_IMPORT_TABLE(
1153        String  schemaName,
1154    String  tableName,
1155        String  fileName,
1156        String  columnDelimiter,
1157        String  characterDelimiter,
1158        String  codeset,
1159        short   replace)
1160        throws SQLException
1161    {
1162                Connection conn = getDefaultConn();
1163                try{
1164                        Import.importTable(conn, schemaName , tableName , fileName ,
1165                                                                   columnDelimiter , characterDelimiter, codeset, replace);
1166                }catch(SQLException se)
1167                {
1168                        //issue a rollback on any errors
1169                        conn.rollback();
1170                        throw  se;
1171                }
1172                //import finished successfull, commit it.
1173                conn.commit();
1174        }
1175 
1176 
1177        /**
1178     * Import data from a given file into the specified table columns from the 
1179         * specified columns in the file.
1180     * <p>
1181     * Will be called as 
1182         * SYSCS_IMPORT_DATA (IN SCHEMANAME  VARCHAR(128), IN TABLENAME    VARCHAR(128),  
1183         *                    IN INSERTCOLUMNLIST VARCHAR(32762), IN COLUMNINDEXES VARCHAR(32762),
1184         *                    IN FILENAME VARCHAR(32762), IN COLUMNDELIMITER CHAR(1),  
1185         *                    IN CHARACTERDELIMITER  CHAR(1) ,  IN CODESET VARCHAR(128) , 
1186     *                    IN  REPLACE SMALLINT)
1187         *
1188         * @exception  StandardException  Standard exception policy.
1189     **/
1190        public static void SYSCS_IMPORT_DATA(
1191    String  schemaName,
1192    String  tableName,
1193        String  insertColumnList,
1194        String  columnIndexes,
1195        String  fileName,
1196        String  columnDelimiter,
1197        String  characterDelimiter,
1198        String  codeset,
1199        short   replace)
1200        throws SQLException
1201    {
1202                Connection conn = getDefaultConn();
1203                try{
1204                        Import.importData(conn, schemaName , tableName ,
1205                                                                  insertColumnList, columnIndexes, fileName,
1206                                                                  columnDelimiter, characterDelimiter, 
1207                                                                  codeset, replace);
1208                }catch(SQLException se)
1209                {
1210                        //issue a rollback on any errors
1211                        conn.rollback();
1212                        throw  se;
1213                }
1214 
1215                //import finished successfull, commit it.
1216                conn.commit();
1217        }
1218 
1219        /**
1220     * Perform bulk insert using the specificed vti .
1221     * <p>
1222     * Will be called as 
1223         * SYSCS_BULK_INSERT (IN SCHEMANAME VARCHAR(128), IN TABLENAME    VARCHAR(128),  
1224         *                    IN VTINAME VARCHAR(32762), IN VTIARG VARCHAR(32762))
1225         *
1226         * @exception  StandardException  Standard exception policy.
1227     **/
1228        public static void SYSCS_BULK_INSERT(
1229    String  schemaName,
1230    String  tableName,
1231        String  vtiName,
1232        String  vtiArg
1233        )
1234        throws SQLException
1235    {
1236                Connection conn = getDefaultConn();
1237                
1238                String entityName = (schemaName == null ? tableName : schemaName + "." + tableName); 
1239                String binsertSql = 
1240                        "insert into " + entityName +
1241                        " PROPERTIES insertMode=bulkInsert " +
1242                        "select * from new " + vtiName + 
1243                        "(" + 
1244                        "'" + schemaName + "'" + ", " + 
1245                        "'" + tableName + "'" +  ", " + 
1246                        "'" + vtiArg + "'" +  ")" + 
1247                        " as t"; 
1248 
1249                PreparedStatement ps = conn.prepareStatement(binsertSql);
1250                ps.executeUpdate();
1251                ps.close();
1252        }
1253        
1254        /**
1255         * Method to return the constant PI.
1256         * SYSFUN.PI().
1257         * @return PI
1258         */
1259        public static double PI()
1260        {
1261                return StrictMath.PI;
1262        }
1263        
1264        /**
1265         * Constant for natural log(10).
1266         */
1267        private static final double LOG10 = StrictMath.log(10.0d);
1268        
1269        /**
1270         * Base 10 log function. SYSFUN.LOG10
1271         * Calculated by
1272         * <code>
1273         * log(value) / log(10)
1274         * </code>
1275         * where log is the natural log.
1276         */
1277        public static double LOG10(double value)
1278        {
1279                return StrictMath.log(value) / LOG10;
1280        }
1281}

[all classes][org.apache.derby.catalog]
EMMA 2.0.5312 (C) Vladimir Roubtsov