Source Code Cross Referenced for MockResultSetMetaData.java in  » Open-Source-Library-Database » Database-Utilities » org » apache » commons » dbutils » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. JDK Core
2. JDK Modules
3. JDK Modules com.sun
4. JDK Modules com.sun.java
5. JDK Modules Platform
6. JDK Modules sun
7. Open Source Build
8. Open Source Graphic Library
9. Open Source IDE Eclipse
10. Open Source J2EE
11. Open Source JDBC Driver
12. Open Source Library
13. Open Source Library Database
14. Open Source Net
15. Open Source Script
16. Science
17. Security
18. Sevlet Container
19. SUN GlassFish
20. Swing Library
21. Web Services apache cxf 2.0.1
22. Web Services AXIS2
23. XML
Microsoft Office Word 2007 Tutorial
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
C# / C Sharp
C# / CSharp Tutorial
ASP.Net
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
PHP
Python
SQL Server / T-SQL
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Java Source Code / Java Documentation » Open Source Library Database » Database Utilities » org.apache.commons.dbutils 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


01:        /*
02:         * Licensed to the Apache Software Foundation (ASF) under one or more
03:         * contributor license agreements.  See the NOTICE file distributed with
04:         * this work for additional information regarding copyright ownership.
05:         * The ASF licenses this file to You under the Apache License, Version 2.0
06:         * (the "License"); you may not use this file except in compliance with
07:         * the License.  You may obtain a copy of the License at
08:         *
09:         *      http://www.apache.org/licenses/LICENSE-2.0
10:         *
11:         * Unless required by applicable law or agreed to in writing, software
12:         * distributed under the License is distributed on an "AS IS" BASIS,
13:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14:         * See the License for the specific language governing permissions and
15:         * limitations under the License.
16:         */
17:        package org.apache.commons.dbutils;
18:
19:        import java.lang.reflect.InvocationHandler;
20:        import java.lang.reflect.Method;
21:        import java.sql.ResultSetMetaData;
22:
23:        /**
24:         * MockResultSetMetaData dynamically implements the ResultSetMetaData 
25:         * interface.
26:         */
27:        public class MockResultSetMetaData implements  InvocationHandler {
28:
29:            private String[] columnNames = null;
30:
31:            /**
32:             * Create a <code>MockResultSetMetaData</code> proxy object.  This is 
33:             * equivalent to:
34:             * <pre>
35:             * ProxyFactory.instance().createResultSetMetaData(new MockResultSetMetaData(columnNames));
36:             * </pre>
37:             * 
38:             * @param columnNames
39:             * @return
40:             */
41:            public static ResultSetMetaData create(String[] columnNames) {
42:                return ProxyFactory.instance().createResultSetMetaData(
43:                        new MockResultSetMetaData(columnNames));
44:            }
45:
46:            public MockResultSetMetaData(String[] columnNames) {
47:                super ();
48:                this .columnNames = columnNames;
49:
50:            }
51:
52:            public Object invoke(Object proxy, Method method, Object[] args)
53:                    throws Throwable {
54:
55:                String methodName = method.getName();
56:
57:                if (methodName.equals("getColumnCount")) {
58:                    return new Integer(this .columnNames.length);
59:
60:                } else if (methodName.equals("getColumnName")
61:                        || methodName.equals("getColumnLabel")) {
62:
63:                    int col = ((Integer) args[0]).intValue() - 1;
64:                    return this .columnNames[col];
65:
66:                } else if (methodName.equals("hashCode")) {
67:                    return new Integer(System.identityHashCode(proxy));
68:
69:                } else if (methodName.equals("toString")) {
70:                    return "MockResultSetMetaData "
71:                            + System.identityHashCode(proxy);
72:
73:                } else if (methodName.equals("equals")) {
74:                    return new Boolean(proxy == args[0]);
75:
76:                } else {
77:                    throw new UnsupportedOperationException(
78:                            "Unsupported method: " + methodName);
79:                }
80:            }
81:        }
w___w__w_._ja___v___a__2__s___.___c_o___m__ | Contact Us
Copyright 2003 - 08 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.