1 24 package org.ofbiz.entity.jdbc; 25 26 import java.lang.reflect.Constructor ; 27 import java.lang.reflect.InvocationHandler ; 28 import java.lang.reflect.InvocationTargetException ; 29 import java.lang.reflect.Method ; 30 import java.lang.reflect.Proxy ; 31 32 37 public abstract class AbstractCursorHandler implements InvocationHandler { 38 39 protected String cursorName; 40 protected int fetchSize; 41 42 protected AbstractCursorHandler(String cursorName, int fetchSize) { 43 this.cursorName = cursorName; 44 this.fetchSize = fetchSize; 45 } 46 47 public void setCursorName(String cursorName) { 48 this.cursorName = cursorName; 49 } 50 51 public String getCursorName() { 52 return cursorName; 53 } 54 55 public void setFetchSize(int fetchSize) { 56 this.fetchSize = fetchSize; 57 } 58 59 public int getFetchSize() { 60 return fetchSize; 61 } 62 63 protected Object invoke(Object obj, Object proxy, Method method, Object [] args) throws Throwable { 64 if ("toString".equals(method.getName())) { 65 String str = obj.toString(); 66 return getClass().getName() + "{" + str + "}"; 67 } 68 return method.invoke(obj, args); 69 } 70 71 protected static Object newHandler(InvocationHandler handler, Class implClass) throws IllegalAccessException , IllegalArgumentException , InstantiationException , InvocationTargetException , NoSuchMethodException , SecurityException { 72 ClassLoader loader = implClass.getClassLoader(); 73 if (loader == null) loader = ClassLoader.getSystemClassLoader(); 74 Class proxyClass = Proxy.getProxyClass(loader, new Class []{implClass}); 75 Constructor constructor = proxyClass.getConstructor(new Class []{InvocationHandler .class}); 76 return constructor.newInstance(new Object []{handler}); 77 } 78 } 79 | Popular Tags |