net.sf.hajdbc.invocation.SimpleInvoker Maven / Gradle / Ivy
package net.sf.hajdbc.invocation;
import java.lang.reflect.Method;
import net.sf.hajdbc.Database;
import net.sf.hajdbc.ExceptionFactory;
import net.sf.hajdbc.logging.Level;
import net.sf.hajdbc.logging.Logger;
import net.sf.hajdbc.logging.LoggerFactory;
import net.sf.hajdbc.util.reflect.Methods;
public class SimpleInvoker, T, R, E extends Exception> implements Invoker
{
private static final Logger logger = LoggerFactory.getLogger(SimpleInvoker.class);
private final Method method;
private final Object[] parameters;
private final ExceptionFactory exceptionFactory;
/**
* @param method
* @param parameters
*/
public SimpleInvoker(Method method, Object[] parameters, ExceptionFactory exceptionFactory)
{
this.method = method;
this.parameters = parameters;
this.exceptionFactory = exceptionFactory;
}
public Method getMethod()
{
return this.method;
}
public Object[] getParameters()
{
return this.parameters;
}
public ExceptionFactory getExceptionFactory()
{
return this.exceptionFactory;
}
/**
* @see net.sf.hajdbc.invocation.Invoker#invoke(net.sf.hajdbc.Database, java.lang.Object)
*/
@Override
public R invoke(D database, T object) throws E
{
logger.log(Level.TRACE, "Invoking {0} against {1}", this.method, database);
return Methods.invoke(this.method, this.exceptionFactory, object, this.parameters);
}
@Override
public int hashCode()
{
return this.method.hashCode();
}
@Override
public boolean equals(Object object)
{
if ((object != null) && (object instanceof SimpleInvoker))
{
@SuppressWarnings("unchecked")
SimpleInvoker invoker = (SimpleInvoker) object;
return this.method.equals(invoker.method);
}
return false;
}
/**
* {@inheritDoc}
* @see java.lang.Object#toString()
*/
@Override
public String toString()
{
return this.method.toString();
}
}