All Downloads are FREE. Search and download functionalities are using the official Maven repository.

src-main-ce.org.awakefw.sql.servlet.AwakeSqlConfiguratorCall Maven / Gradle / Ivy

Go to download

Awake SQL is an open source framework that allows remote and secure JDBC access through HTTP.

There is a newer version: 2.0.2
Show newest version
/*
 * Awake File: Easy file upload & download through HTTP with Java
 * Awake SQL: Remote JDBC access through HTTP.                                    
 * Copyright (C) 2012, Kawan Softwares S.A.S.
 * (http://www.awakeframework.org). All rights reserved.                                
 *                                                                               
 * Awake File/SQL 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.            
 *                                                                               
 * Awake File/SQL 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.awakefw.sql.servlet;

import java.io.IOException;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;

import org.awakefw.sql.api.server.AwakeSqlConfigurator;
import org.awakefw.sql.util.reflection.Invoker;

/**
 * 
 * Calls AwakeSqlConfigurator methods using reflection
 * 
 * @author Nicolas de Pomereu
 * 
 */

public class AwakeSqlConfiguratorCall {

    /**
     * Returns the result of AwakeSqlConfigurator.allowExecute
     * 
     * @param awakeSqlConfigurator
     *            the AwakeSqlConfigurator instance
     * @param username
     *            the client username
     * @param connection
     *            The JDBC Connection
     * @return the result of AwakeSqlConfigurator.allowExecute
     * @throws IOException
     * @throws SQLException
     */
    public static boolean allowExecute(AwakeSqlConfigurator awakeSqlConfigurator,
	    String username, Connection connection) throws IOException,
	    SQLException {
	return true;
    }

    /**
     * Returns the result of AwakeSqlConfigurator.allowExecuteUpdate
     * 
     * @param awakeSqlConfigurator
     *            the AwakeSqlConfigurator instance
     * @param username
     *            the client username
     * @param connection
     *            The JDBC Connection
     * @return the result of AwakeSqlConfigurator.allowExecuteUpdate
     * @throws IOException
     * @throws SQLException
     */
    public static boolean allowExecuteUpdate(
	    AwakeSqlConfigurator awakeSqlConfigurator, String username,
	    Connection connection) throws IOException, SQLException {
	return true;
    }

    /**
     * Returns the result of AwakeSqlConfigurator.allowStatementClass
     * 
     * @param awakeSqlConfigurator
     *            the AwakeSqlConfigurator instance
     * @param username
     *            the client username
     * @param connection
     *            The JDBC Connection
     * @return the result of AwakeSqlConfigurator.allowStatementClass
     * @throws IOException
     * @throws SQLException
     */
    public static boolean allowStatementClass(
	    AwakeSqlConfigurator awakeSqlConfigurator, String username,
	    Connection connection) throws IOException, SQLException {
	return true;
    }

    /**
     * Returns the result of AwakeSqlConfigurator.allowGetMetaData
     * 
     * @param awakeSqlConfigurator
     *            the AwakeSqlConfigurator instance
     * @param username
     *            the client username
     * @param connection
     *            The JDBC Connection
     * @return the result of AwakeSqlConfigurator.allowGetMetaData
     * @throws IOException
     * @throws SQLException
     */
    public static boolean allowGetMetaData(AwakeSqlConfigurator awakeSqlConfigurator,
	    String username, Connection connection) throws IOException,
	    SQLException {
	return awakeSqlConfigurator.allowGetMetaData(username, connection);
    }

    /**
     * Returns the result of AwakeSqlConfigurator.allowResultSetGetMetaData
     * 
     * @param awakeSqlConfigurator
     *            the AwakeSqlConfigurator instance
     * @param username
     *            the client username
     * @param connection
     *            The JDBC Connection
     * @return the result of AwakeSqlConfigurator.allowResultSetGetMetaData
     * @throws IOException
     * @throws SQLException
     */
    public static boolean allowResultSetGetMetaData(AwakeSqlConfigurator awakeSqlConfigurator,
	    String username, Connection connection) throws IOException,
	    SQLException {
	return true;
    }

    /**
     * RunsAwakeSqlConfigurator.runIfStatementRefused
     * 
     * @param awakeSqlConfigurator
     *            the AwakeSqlConfigurator instance
     * @param username
     *            the client username
     * @param connection
     *            The JDBC Connection
     * @throws IOException
     * @throws SQLException
     */
    public static void runIfStatementRefused(AwakeSqlConfigurator awakeSqlConfigurator,
	    String username, Connection connection, String ipAddress, String sql, List parameterValues) throws IOException,
	    SQLException {

    }
    
    
    /**
     * Return the result of getMaxRowsToReturn method of AwakeSqlConfigurator,
     * if it's implemented, else 0.
     * 
     * @param awakeSqlConfigurator
     *            the AwakeSqlConfigurator instance
     * @return the result of getMaxRowsToReturn of AwakeSqlConfigurator, if it's
     *         implemented, else 0;
     * 
     * @throws SQLException
     */
    public static int getMaxRowsToReturn(
	    AwakeSqlConfigurator awakeSqlConfigurator) throws SQLException {
	String methodName = new Object() {
	}.getClass().getEnclosingMethod().getName();

	if (!Invoker
		.existsMethod(
			org.awakefw.sql.api.server.AwakeSqlConfigurator.class
				.getName(), methodName)) {
	    return 0;
	}

	Object result = null;

	try {
	    result = Invoker.getMethodResult(awakeSqlConfigurator, methodName);
	} catch (Exception e) {
	    throw new SQLException(e);
	}

	if (result == null) {
	    return 0;
	} else {
	    return (Integer) result;
	}
    }

    /**
     * Return the result of encryptResultSet method of AwakeSqlConfigurator, if
     * it's implemented, else false. (Invocation using reflection)
     * 
     * @param awakeSqlConfigurator
     *            the AwakeSqlConfigurator instance
     * @return the result of getMaxRowsToReturn of AwakeSqlConfigurator, if it's
     *         implemented, else fase;
     * 
     * @throws SQLException
     */
    public static boolean encryptResultSet(
	    AwakeSqlConfigurator awakeSqlConfigurator) throws SQLException {
	String methodName = new Object() {
	}.getClass().getEnclosingMethod().getName();

	if (!Invoker
		.existsMethod(
			org.awakefw.sql.api.server.AwakeSqlConfigurator.class
				.getName(), methodName)) {
	    return false;
	}

	Object result = null;

	try {
	    result = Invoker.getMethodResult(awakeSqlConfigurator, methodName);
	} catch (Exception e) {
	    throw new SQLException(e);
	}

	if (result == null) {
	    return false;
	} else {
	    return (Boolean) result;
	}
    }

}