Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
/*
    
 Derby - Class org.apache.derbyDemo.vtis.core.VTIHelper
    
 Licensed to the Apache Software Foundation (ASF) under one or more
 contributor license agreements.  See the NOTICE file distributed with
 this work for additional information regarding copyright ownership.
 The ASF licenses this file to You under the Apache License, Version 2.0
 (the "License"); you may not use this file except in compliance with
 the License.  You may obtain a copy of the License at
    
 http://www.apache.org/licenses/LICENSE-2.0
    
 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
    
 */

import java.lang.reflect.*;

import java.sql.*;

public class Main {
    private static final boolean DEBUG = true;

    /**
     * <p>
     * Unregister a VTI.
     * </p>
     */
    public static void unregisterVTI(Method method) throws SQLException {
        String methodName = method.getName();
        String sqlName = doubleQuote(methodName);

        dropObject("function", sqlName, false);
    }

    /**
     * <p>
     * Double-quote a name.
     * </p>
     *
     */
    public static String doubleQuote(String name) {
        return '\"' + name + '\"';
    }

    /**
     * <p>
     * Execute a DDL statement to drop an object if it exists. Swallow exceptions.
     * </p>
     */
    public static void dropObject(String objectType, String objectName, boolean objectIfMissing)
            throws SQLException {
        String dropDDL = "drop " + objectType + " " + objectName;
        Connection conn = getLocalConnection();

        // Drop the object if it does exist. Swallow exception if it doesn't.
        print(dropDDL);
        try {
            PreparedStatement dropStatement = conn.prepareStatement(dropDDL);

            dropStatement.execute();
            dropStatement.close();
        } catch (SQLException s) {
            if (objectIfMissing) {
                throw s;
            }
        }
    }

    /**
     * <p>
     * Get the connection to the local database.
     * </p>
     */
    public static Connection getLocalConnection() throws SQLException {
        return DriverManager.getConnection("jdbc:default:connection");
    }

    /**
     * <p>
     * Debug helper method to print a diagnostic.
     * </p>
     */
    public static void print(String text) {
        if (DEBUG) {
            System.out.println(text);
        }
    }
}