org.kawanfw.test.util.SqlTestRunnerConsoleSpecial.java Source code

Java tutorial

Introduction

Here is the source code for org.kawanfw.test.util.SqlTestRunnerConsoleSpecial.java

Source

/*
 * This file is part of AceQL. 
 * AceQL: Remote JDBC access over HTTP.                                     
 * Copyright (C) 2015,  KawanSoft SAS
 * (http://www.kawansoft.com). All rights reserved.                                
 *                                                                               
 * AceQL is free software; you can redistribute it and/or                 
 * modify it under the terms of the GNU Lesser General Public                    
 * License as published by the Free Software Foundation; either                  
 * version 2.1 of the License, or (at your option) any later version.            
 *                                                                               
 * AceQL is distributed in the hope that it will be useful,               
 * but WITHOUT ANY WARRANTY; without even the implied warranty of                
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU             
 * Lesser General Public License for more details.                               
 *                                                                               
 * You should have received a copy of the GNU Lesser General Public              
 * License along with this library; if not, write to the Free Software           
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  
 * 02110-1301  USA
 *
 * Any modifications to this file must keep this entire header
 * intact.
 */
package org.kawanfw.test.util;

import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.SQLException;
import java.util.Date;

import org.apache.commons.lang3.SystemUtils;
import org.kawanfw.sql.api.util.SqlUtil;
import org.kawanfw.test.parms.ConnectionLoader;
import org.kawanfw.test.parms.SqlTestParms;

public class SqlTestRunnerConsoleSpecial {

    public static String CURRENT_SQL_ENGINE = null;

    /**
     * @param connection
     * @throws Exception
     * @throws SQLException
     */
    public static void testSqlEngine(Connection connection) throws Exception, SQLException {

        DatabaseMetaData databaseMetaData = connection.getMetaData();

        MessageDisplayer.display("");
        MessageDisplayer.display(
                "databaseMetaData.getDatabaseProductName()   : " + databaseMetaData.getDatabaseProductName());

        try {

            MessageDisplayer.display(
                    "databaseMetaData.supportsStoredProcedures(): " + databaseMetaData.supportsStoredProcedures());

            MessageDisplayer.display("databaseMetaData.supportsStoredFunctionsUsingCallSyntax(): "
                    + databaseMetaData.supportsStoredFunctionsUsingCallSyntax());

        } catch (Throwable e) {
            MessageDisplayer.display(e.toString());
        }

    }

    /** Start the test */
    public static void startIt() throws Exception {
        if (SystemUtils.IS_JAVA_1_7) {
            System.setProperty("java.net.preferIPv4Stack", "true");
        }

        Connection connection = null;

        while (true) {
            try {

                Date begin = new Date();

                for (int i = 0; i < SqlTestParms.SQL_ENGINES_TO_TEST.length; i++) {

                    UserPrefManager.setDatabaseToUse(SqlTestParms.SQL_ENGINES_TO_TEST[i]);

                    connection = ConnectionLoader.getAceqlConnection();

                    // Do not test AES in loop: it does release free space for
                    // blobs/clobs!

                    if (SqlTestParms.LOOP_MODE
                            && SqlTestParms.SQL_ENGINES_TO_TEST[i] == SqlUtil.ADAPTIVE_SERVER_ENTERPRISE) {
                        MessageDisplayer.display("SqlUtil.ADAPTIVE_SERVER_ENTERPRISE" + " skipped in Loop Mode.");
                    } else {
                        testSqlEngine(connection);
                    }

                }

                // Universal tests without connection
                // new StatementAnalyserTest().test();
                // new CallTest().test(connection);
                // new InvokerTest().test();

                Date end = new Date();

                MessageDisplayer.display("");
                MessageDisplayer.display("Begin: " + begin);
                MessageDisplayer.display("End  : " + end);

                if (connection != null)
                    connection.close();

                if (!SqlTestParms.LOOP_MODE) {
                    return;
                }

            } finally {
                if (connection != null)
                    connection.close();
            }
        }

    }

    public static void main(String[] args) throws Exception {
        startIt();
    }
}