KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ofbiz > entity > jdbc > AbstractCursorHandler


1 /*
2  * $Id: AbstractCursorHandler.java 5462 2005-08-05 18:35:48Z jonesde $
3  *
4  * Copyright (c) 2001-2005 The Open For Business Project - www.ofbiz.org
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a
7  * copy of this software and associated documentation files (the "Software"),
8  * to deal in the Software without restriction, including without limitation
9  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  * and/or sell copies of the Software, and to permit persons to whom the
11  * Software is furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included
14  * in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
21  * OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
22  * THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23  */

24 package org.ofbiz.entity.jdbc;
25
26 import java.lang.reflect.Constructor JavaDoc;
27 import java.lang.reflect.InvocationHandler JavaDoc;
28 import java.lang.reflect.InvocationTargetException JavaDoc;
29 import java.lang.reflect.Method JavaDoc;
30 import java.lang.reflect.Proxy JavaDoc;
31
32 /**
33  *
34  * @version $Rev: 5462 $
35  * @since 3.1
36  */

37 public abstract class AbstractCursorHandler implements InvocationHandler JavaDoc {
38     
39     protected String JavaDoc cursorName;
40     protected int fetchSize;
41
42     protected AbstractCursorHandler(String JavaDoc cursorName, int fetchSize) {
43         this.cursorName = cursorName;
44         this.fetchSize = fetchSize;
45     }
46
47     public void setCursorName(String JavaDoc cursorName) {
48         this.cursorName = cursorName;
49     }
50
51     public String JavaDoc 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 JavaDoc invoke(Object JavaDoc obj, Object JavaDoc proxy, Method JavaDoc method, Object JavaDoc[] args) throws Throwable JavaDoc {
64         if ("toString".equals(method.getName())) {
65             String JavaDoc str = obj.toString();
66             return getClass().getName() + "{" + str + "}";
67         }
68         return method.invoke(obj, args);
69     }
70
71     protected static Object JavaDoc newHandler(InvocationHandler JavaDoc handler, Class JavaDoc implClass) throws IllegalAccessException JavaDoc, IllegalArgumentException JavaDoc, InstantiationException JavaDoc, InvocationTargetException JavaDoc, NoSuchMethodException JavaDoc, SecurityException JavaDoc {
72         ClassLoader JavaDoc loader = implClass.getClassLoader();
73         if (loader == null) loader = ClassLoader.getSystemClassLoader();
74         Class JavaDoc proxyClass = Proxy.getProxyClass(loader, new Class JavaDoc[]{implClass});
75         Constructor JavaDoc constructor = proxyClass.getConstructor(new Class JavaDoc[]{InvocationHandler JavaDoc.class});
76         return constructor.newInstance(new Object JavaDoc[]{handler});
77     }
78 }
79
Popular Tags