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

org.cattleframework.db.datasource.reflect.invocation.PreparedStatementInvocationHandler Maven / Gradle / Ivy

The newest version!
/*
 * Copyright (C) 2018 the original author or authors.
 *
 * Licensed 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.
 */
package org.cattleframework.db.datasource.reflect.invocation;

import java.lang.reflect.Method;
import java.sql.PreparedStatement;

import org.apache.commons.lang3.ArrayUtils;
import org.checkerframework.checker.nullness.qual.Nullable;

/**
 * 数据库预处理语句调用处理
 * 
 * @author orange
 *
 */
public class PreparedStatementInvocationHandler extends StatementInvocationHandler {

    private final String sql;

    public PreparedStatementInvocationHandler(PreparedStatement target, String sql) {
	super(target);
	this.sql = sql;
    }

    @Override
    protected Object handleInvocation(Object proxy, Method method, @Nullable Object[] args) throws Throwable {
	String methodName = method.getName();
	if (METHOD_NAME_EXECUTE_QUERY.equals(methodName) && ArrayUtils.getLength(args) == 0) {
	    return executeQuery(method, sql, args);
	} else if (METHOD_NAME_EXECUTE_UPDATE.equals(methodName) && ArrayUtils.getLength(args) == 0) {
	    return executeUpdate(method, sql, args);
	} else if (METHOD_NAME_EXECUTE.equals(methodName) && ArrayUtils.getLength(args) == 0) {
	    return execute(method, sql, args);
	} else if (METHOD_NAME_ADD_BATCH.equals(methodName)) {
	    return addBatch(method, sql, args);
	}
	return super.handleInvocation(proxy, method, args);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy