net.sf.hajdbc.sql.CommonDataSourceInvocationHandler Maven / Gradle / Ivy
/*
* HA-JDBC: High-Availability JDBC
* Copyright (C) 2012 Paul Ferraro
*
* This program 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 3 of the License, or
* (at your option) any later version.
*
* This program 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 program. If not, see .
*/
package net.sf.hajdbc.sql;
import java.lang.reflect.Method;
import java.sql.SQLException;
import java.util.Set;
import net.sf.hajdbc.Database;
import net.sf.hajdbc.invocation.InvocationStrategies;
import net.sf.hajdbc.invocation.InvocationStrategy;
import net.sf.hajdbc.invocation.Invoker;
import net.sf.hajdbc.util.reflect.Methods;
/**
* @author Paul Ferraro
* @param
*/
@SuppressWarnings("nls")
public class CommonDataSourceInvocationHandler, F extends RootProxyFactory> extends ConnectionSourceInvocationHandler
{
private static final Set getMethodSet = Methods.findMethods(CommonDataSource.class, "get\\w+");
private static final Set setMethodSet = Methods.findMethods(CommonDataSource.class, "set\\w+");
protected CommonDataSourceInvocationHandler(Class targetClass, F factory)
{
super(targetClass, factory);
}
@Override
protected InvocationStrategy getInvocationStrategy(Z dataSource, Method method, Object... parameters) throws SQLException
{
if (getMethodSet.contains(method))
{
return InvocationStrategies.INVOKE_ON_ANY;
}
if (setMethodSet.contains(method))
{
return InvocationStrategies.INVOKE_ON_EXISTING;
}
return super.getInvocationStrategy(dataSource, method, parameters);
}
@Override
protected void postInvoke(Invoker invoker, Z proxy, Method method, Object... parameters)
{
if (setMethodSet.contains(method))
{
this.getProxyFactory().record(invoker);
}
}
}