Source Code Cross Referenced for MetaRow.java in  » Database-ORM » jaxor-3.5 » net » sourceforge » jaxor » 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 ORM » jaxor 3.5 » net.sourceforge.jaxor 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * User: mrettig
003:         * Date: Jun 25, 2002
004:         * Time: 11:38:42 AM
005:         */
006:        package net.sourceforge.jaxor;
007:
008:        import net.sourceforge.jaxor.util.SystemException;
009:        import net.sourceforge.jaxor.util.Validation;
010:
011:        import java.io.Serializable;
012:        import java.sql.Connection;
013:        import java.sql.DatabaseMetaData;
014:        import java.sql.ResultSet;
015:        import java.sql.SQLException;
016:        import java.util.*;
017:
018:        public class MetaRow implements  Serializable {
019:            private final List _list = new ArrayList();
020:            private final String _table;
021:            private MetaParser _parser;
022:            private Class _implClass;
023:            private Class _listImpl;
024:
025:            public MetaRow(String table, Class impl, Class listImpl) {
026:                _table = table;
027:                _implClass = impl;
028:                _listImpl = listImpl;
029:            }
030:
031:            public Class getImplClass() {
032:                return _implClass;
033:            }
034:
035:            public Class getListImplClass() {
036:                return _listImpl;
037:            }
038:
039:            public void setImplClass(Class implClass) {
040:                _implClass = implClass;
041:            }
042:
043:            public void add(MetaField field) {
044:                _list.add(field);
045:                _parser = null;
046:            }
047:
048:            public String getTableName() {
049:                return _table;
050:            }
051:
052:            public Validation validateColumns(Connection conn,
053:                    boolean capitalizeTable) {
054:                return findInvalidColumns(conn, capitalizeTable);
055:            }
056:
057:            private Validation findInvalidColumns(Connection conn,
058:                    boolean capitalizeTable) {
059:                try {
060:                    Validation val = new Validation();
061:                    DatabaseMetaData meta = conn.getMetaData();
062:                    Set allColumns = getColumnNamesInUpperCase();
063:
064:                    String tableName = capitalizeTable ? getTableName()
065:                            .toUpperCase() : getTableName();
066:
067:                    ResultSet set = meta.getColumns(null, null, tableName, "%");
068:                    while (set.next()) {
069:                        String columnName = set.getString("COLUMN_NAME");
070:                        if (!allColumns.remove(columnName.toUpperCase())) {
071:                            val.addInfo("Table " + tableName
072:                                    + " Contains Column: " + columnName
073:                                    + " not found in SQLGEN");
074:                        } else {
075:                            boolean nullable = "YES".equals(set
076:                                    .getString("IS_NULLABLE"));
077:                            MetaField field = findMetaByColumn(columnName);
078:                            if (!nullable && field.canBeNull()) {
079:                                String msg = " Jaxor nullable="
080:                                        + field.canBeNull()
081:                                        + " database nullable=" + nullable;
082:                                val.addError("Table: " + tableName
083:                                        + " Column: " + columnName + msg);
084:                            } else if (!nullable) {
085:                                //fine we insert first time to initialize but then we never update it
086:                            } else if (nullable != field.canBeNull()) {
087:                                String msg = " Jaxor nullable="
088:                                        + field.canBeNull()
089:                                        + " database nullable=" + nullable;
090:                                val.addInfo("Table: " + tableName + " Column: "
091:                                        + columnName + msg);
092:                            }
093:                        }
094:                    }
095:                    set.close();
096:                    for (Iterator iterator = allColumns.iterator(); iterator
097:                            .hasNext();) {
098:                        String s = (String) iterator.next();
099:                        val.addError(s + " column defined in " + tableName
100:                                + "Entity not found in database");
101:                    }
102:                    return val;
103:                } catch (SQLException e) {
104:                    throw new SystemException(
105:                            "Failed to find Columns for table: "
106:                                    + getTableName(), e);
107:                }
108:            }
109:
110:            public MetaField findMetaByColumn(String columnName) {
111:                for (Iterator iterator = _list.iterator(); iterator.hasNext();) {
112:                    MetaField metaField = (MetaField) iterator.next();
113:                    if (metaField.getColumn().equalsIgnoreCase(columnName))
114:                        return metaField;
115:                }
116:                return null;
117:            }
118:
119:            private Set getColumnNamesInUpperCase() {
120:                Set set = new HashSet();
121:                for (Iterator iterator = _list.iterator(); iterator.hasNext();) {
122:                    MetaField metaField = (MetaField) iterator.next();
123:                    set.add(metaField.getColumn().toUpperCase());
124:                }
125:                return set;
126:            }
127:
128:            public List getColumns() {
129:                return Collections.unmodifiableList(_list);
130:            }
131:
132:            public List getPrimaryKey() {
133:                List key = new ArrayList();
134:                for (int i = 0; i < _list.size(); i++) {
135:                    MetaField field = (MetaField) _list.get(i);
136:                    if (field.isPrimaryKey())
137:                        key.add(field);
138:                }
139:                return key;
140:            }
141:
142:            public List getInsertColumns() {
143:                List insert = new ArrayList();
144:                for (Iterator iter = _list.iterator(); iter.hasNext();) {
145:                    MetaField element = (MetaField) iter.next();
146:                    if (!element.isAutoAssign())
147:                        insert.add(element);
148:                }
149:                return insert;
150:            }
151:
152:            public List getUpdateColumns() {
153:                List all = new ArrayList();
154:                for (Iterator iterator = _list.iterator(); iterator.hasNext();) {
155:                    MetaField attribute = (MetaField) iterator.next();
156:                    if (!attribute.isPrimaryKey())
157:                        all.add(attribute);
158:                }
159:                return all;
160:            }
161:
162:            public List getUpdateMatchColumns() {
163:                List all = new ArrayList();
164:                for (Iterator iterator = _list.iterator(); iterator.hasNext();) {
165:                    MetaField attribute = (MetaField) iterator.next();
166:                    if (attribute.isMatchOnUpdate())
167:                        all.add(attribute);
168:                }
169:                return all;
170:            }
171:
172:            public MetaParser getParser() {
173:                if (_parser == null)
174:                    _parser = new MetaParser(this );
175:                return _parser;
176:            }
177:
178:            public List getNonPrimaryKeyColumns() {
179:                List results = new ArrayList();
180:                for (Iterator iterator = _list.iterator(); iterator.hasNext();) {
181:                    MetaField metaField = (MetaField) iterator.next();
182:                    if (!metaField.isPrimaryKey())
183:                        results.add(metaField);
184:                }
185:                return results;
186:            }
187:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.