Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* This file is part of Awake SQL.
* Awake SQL: Remote JDBC access over HTTP.
* Copyright (C) 2013, KawanSoft SAS
* (http://www.kawansoft.com). All rights reserved.
*
* Awake SQL is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* Awake 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 General Public License
* along with this program; if not, see .
*
* If you develop commercial activities using Awake SQL, you must:
* a) disclose and distribute all source code of your own product,
* b) license your own product under the GNU General Public License.
*
* You can be released from the requirements of the license by
* purchasing a commercial license. Buying such a license will allow you
* to ship Awake SQL with your closed source products without disclosing
* the source code.
*
* For more information, please contact KawanSoft SAS at this
* address: [email protected]
*
* Any modifications to this file must keep this entire header
* intact.
*/
package org.awakefw.sql.api.server;
import java.util.List;
import org.apache.commons.lang3.StringUtils;
import org.awakefw.commons.server.util.AwakeServerLogger;
import org.awakefw.file.api.util.AwakeDebug;
import org.awakefw.file.util.Tag;
/**
*
* Class that allows the analysis of the string content of a SQL statement,
* mainly for security reasons.
*
* Analysis methods include:
*
*
Says if a statement contains SQL comments.
*
Extract the statement type:
* DELETE/INSERT/SELECT/UPDATE, CREATE/ALTER/DROP...
*
Says if the statement is a DML statement (exclusively:
* DELETE/INSERT/SELECT/UPDATE).
*
Says if the statement is a PreparedStatement with at least one '?'
* parameter.
*
Counts the number of parameters.
*
Methods to get the first, the last or any parameter.
*
Says if the statement is a DDL statement (exclusively:
* CREATE/ALTER/DROP/TRUNCATE/COMMENT/RENAME).
*
Says if the statement is a DCL statement (exclusively:
* GRANT/REVOKE).
*
Extract the table name in use for a DML statement;
*
*
* @author Nicolas de Pomereu
* @since 1.0
*/
public class StatementAnalyser {
/** Set to true to display/log debug info */
private static boolean DEBUG = AwakeDebug.isSet(StatementAnalyser.class);
// DML
private final static String DELETE = "DELETE";
private final static String INSERT = "INSERT";
private final static String SELECT = "SELECT";
private final static String UPDATE = "UPDATE";
// DDL
private final static String CREATE = "CREATE";
private final static String ALTER = "ALTER";
private final static String DROP = "DROP";
private final static String TRUNCATE = "TRUNCATE";
private final static String COMMENT = "COMMENT";
private final static String RENAME = "RENAME";
// DCL
private final static String GRANT = "GRANT";
private final static String REVOKE = "REVOKE";
// TCL
// public final static String COMMIT = "COMMIT ";
// public final static String ROLLBACK = "ROLLBACK";
// public final static String SET_TRANSACTION = "SAVEPOINT";
// public final static String savepoint = "savepoint";
private static final String BLANK = " ";
/** The statement type */
private final String statementType;
/** The Sql statement in string format */
private final String sql;
/** The parameter values */
private List