Source Code Cross Referenced for ImportedKeyInfo.java in  » Database-Client » SQLMinus » db » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Database Client » SQLMinus » db 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * $Author$
003:         * $Id$
004:         * This is free software, as software should be; you can redistribute 
005:         * it and/or modify it under the terms of the GNU Lesser General Public
006:         * License as published by the Free Software Foundation; either
007:         * version 2.1 of the License, or (at your option) any later version.
008:
009:         * See LICENSE.txt for the full license covering this software/program/code.
010:         */
011:
012:        package db;
013:
014:        import java.util.*;
015:        import util.*;
016:        import java.sql.*;
017:
018:        /**
019:         * Creates an object containing a tables primay key info, in a more
020:         * usable manner.
021:         * @author rahul kumar <rahul_kumar@yahoo.com>
022:         * @see XXX
023:         */
024:
025:        public class ImportedKeyInfo {
026:
027:            /** ctor/constructor taking a connection object and a tablename.
028:             */
029:            public ImportedKeyInfo(Connection conn, String tableName) {
030:                try {
031:                    DatabaseMetaData dma = conn.getMetaData();
032:                    ResultSet rs = dma.getImportedKeys(null, "", tableName);
033:                    List l = ResultSetUtil.getMappedDataString(rs);
034:                    rs.close();
035:                    setInfo(l);
036:                } catch (Exception exc) {
037:                    System.err.println(P + " L EXC:" + exc.toString());
038:                    exc.printStackTrace();
039:                }
040:            }
041:
042:            /** takes a list containing a map object for each key.
043:             * 
044:             * It sorts the keys as per KEY_SEQ since the javadoc says its per
045:             * COLUMN_NAME which sucks. Also mysql driver returns each key_seq
046:             * as 0. mysql returns them as per defined order, so not a worry. 
047:             * To check how oracle works.
048:             */
049:            private void setInfo(List /*<Map>*/l) {
050:                _list = l;
051:            }
052:
053:            /** returns keys as a comma delimited string.
054:             */
055:            public String getKeysAsString() {
056:                if (_list == null)
057:                    return null;
058:                String a[] = getKeysAsArray();
059:                if (a.length == 1)
060:                    return a[0];
061:                return ArrayUtil.join(a, ',');
062:            }
063:
064:            /** returns keys as a string array.
065:             */
066:            public String[] getKeysAsArray() {
067:                if (_list == null)
068:                    return null;
069:
070:                String a[] = new String[_list.size()];
071:                for (int i = 0; i < _list.size(); i++) {
072:                    Map m = (Map) _list.get(i);
073:                    a[i] = (String) m.get(COLUMN_NAME);
074:                }
075:                return a;
076:            }
077:
078:            /** returns the number of columns that make this key.
079:             */
080:            public int getKeyCount() {
081:                if (_list == null)
082:                    return 0;
083:                return _list.size();
084:            }
085:
086:            /** returns a List of Map objects each containing a key.
087:             * Use the names given in the javadoc as keys in the Map.
088:             * COLUMN_NAME and KEY_SEQ are two of them.
089:             * @see java.sql.DatabaseMetaData#getPrimaryKeys()
090:             */
091:            public List getInfo() {
092:                return _list;
093:            }
094:
095:            ////// START INSTANCE VARIABLES //////
096:
097:            List _list;
098:            ////// START CONSTANTS AND CLASS LEVEL VARIABLES  //////
099:            static final String P = "ImportedKeyInfo"; // used in exception strings
100:            public final static String COLUMN_NAME = "COLUMN_NAME";
101:            public final static String KEY_SEQ = "KEY_SEQ";
102:
103:        } // end of class
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.