Source Code Cross Referenced for ColumnGenerate.java in  » Database-ORM » SimpleORM » simpleorm » quickstart » 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 » SimpleORM » simpleorm.quickstart 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package simpleorm.quickstart;
002:
003:        import java.io.IOException;
004:        import java.io.Writer;
005:        import java.util.Vector;
006:
007:        import org.apache.commons.sql.model.Column;
008:        import org.apache.commons.sql.model.Table;
009:        import simpleorm.quickstart.AParam;
010:
011:        /**
012:         * @author <a href="mailto:richard.schmidt@inform6.com">Richard Schmidt</a>
013:         *
014:         */
015:        final class ColumnGenerate {
016:            Table table;
017:            Column column;
018:            INiceNameFormatter niceName;
019:            String sFieldName;
020:            String niceColumnName;
021:
022:            ColumnGenerate(Table table, Column column,
023:                    INiceNameFormatter niceName) {
024:                this .table = table;
025:                this .column = column;
026:                this .niceName = niceName;
027:
028:                sFieldName = jdbcTypeToSField(column);
029:                niceColumnName = niceName.niceNameForColumn(table.getName(),
030:                        column.getName());
031:            }
032:
033:            public boolean isPrimary() {
034:
035:                return column.isPrimaryKey();
036:            }
037:
038:            public void outputStaticFields(Writer out) throws IOException {
039:
040:                out.write("   public static final " + sFieldName + " "
041:                        + niceColumnName + " =\n");
042:
043:                out.write("      new " + sFieldName + "(meta, \""
044:                        + column.getName() + "\"");
045:
046:                if (sFieldName.equalsIgnoreCase("SFieldBigDecimal")) {
047:                    out.write(", " + column.getSize() + ", "
048:                            + column.getScale());
049:                } else if (sFieldName.equalsIgnoreCase("SFieldString")) {
050:                    out.write(", " + column.getSize());
051:                }
052:
053:                // required and/or primary key?
054:                String parameters = "";
055:                String comma = "";
056:
057:                if (column.isPrimaryKey()) {
058:                    parameters += (comma + "SFD_PRIMARY_KEY");
059:                    comma = ", ";
060:                }
061:
062:                if (column.isRequired()) {
063:                    parameters += (comma + "SFD_MANDATORY");
064:                    comma = ", ";
065:                }
066:                if (column.isAutoIncrement()) {
067:                    parameters += (comma + "SFD_GENERATED_KEY");
068:                    comma = ", ";
069:                }
070:
071:                if (parameters.length() != 0) {
072:                    out.write(",\n         new SPropertyValue[] { "
073:                            + parameters + " }");
074:                }
075:
076:                out.write(");\n\n");
077:            }
078:
079:            /**
080:             * Generate something like<br>
081:                    public long getfldIdBirdEvent(){
082:                            return this.getLong( fldIdBirdEvent);
083:                    }<br>
084:                    public void setfldIdBirdEvent( long value){
085:                            this.setLong( fldIdBirdEvent, value);
086:                    }
087:             */
088:            public void outputGettersAndSetters(Writer out) throws IOException {
089:                String type = sFieldToPrimative(jdbcTypeToSField(column));
090:                String typeUpper = type.substring(0, 1).toUpperCase()
091:                        + type.substring(1);
092:
093:                out.write("   public " + type + " get_" + niceColumnName
094:                        + "(){ return get" + typeUpper + "(" + niceColumnName
095:                        + ");}\n");
096:
097:                out.write("   public void set_" + niceColumnName + "( " + type
098:                        + " value){" + "set" + typeUpper + "( "
099:                        + niceColumnName + ",value);}\n\n");
100:            }
101:
102:            private static String sFieldToPrimative(String sField) {
103:                if (sField.equalsIgnoreCase("SFieldDouble")) {
104:                    return "BigDecimal";
105:                } else if (sField.equalsIgnoreCase("SFieldString")) {
106:                    return "String";
107:                } else if (sField.equalsIgnoreCase("SFieldBigDecimal")) {
108:                    return "BigDecimal";
109:                } else if (sField.equalsIgnoreCase("SFieldDate")) {
110:                    return "Date";
111:                } else if (sField.equalsIgnoreCase("SFieldTimestamp")) {
112:                    return "Date";
113:                } else if (sField.equalsIgnoreCase("SFieldInteger")) {
114:                    return "int";
115:                } else if (sField.equalsIgnoreCase("SFieldLong")) {
116:                    return "long";
117:                } else {
118:                    return " {Code not implemented " + sField + "}";
119:                }
120:            }
121:
122:            private static String sFieldToPrimativeObject(String sField) {
123:                if (sField.equalsIgnoreCase("SFieldInteger")) {
124:                    return "Integer";
125:                } else if (sField.equalsIgnoreCase("SFieldLong")) {
126:                    return "Long";
127:                } else {
128:                    return null;
129:                }
130:            }
131:
132:            /**
133:             * Mappings from Sybase to SimpleORM types.
134:             */
135:            private static String jdbcTypeToSField(Column _column) {
136:                String datatype = _column.getType();
137:
138:                if (datatype.equalsIgnoreCase("DOUBLE PRECIS")
139:                        || datatype.equalsIgnoreCase("DOUBLE")) {
140:                    return "SFieldDouble";
141:                }
142:
143:                if (datatype.equalsIgnoreCase("VARCHAR")
144:                        || datatype.equalsIgnoreCase("LONGVARCHAR")
145:                        || datatype.equalsIgnoreCase("LONGVARBINARY")) {
146:                    return "SFieldString";
147:                }
148:
149:                if (datatype.equalsIgnoreCase("NUMERIC")
150:                        || datatype.equalsIgnoreCase("DECIMAL")) {
151:                    if (_column.getScale() == 0) {
152:                        if (_column.getPrecisionRadix() <= 9) {
153:                            return "SFieldInteger";
154:                        } else if (_column.getPrecisionRadix() <= 20) {
155:                            return "SFieldLong";
156:                        }
157:                    }
158:
159:                    return "SFieldBigDecimal";
160:                }
161:
162:                if (datatype.equalsIgnoreCase("IMAGE")) {
163:                    return "SFieldString";
164:                }
165:
166:                if (datatype.equalsIgnoreCase("DATETIME")) {
167:                    return "SFieldDate";
168:                }
169:
170:                if (datatype.equalsIgnoreCase("CHAR")) {
171:                    return "SFieldString";
172:                }
173:
174:                if (datatype.equalsIgnoreCase("SMALLINT")) {
175:                    return "SFieldInteger";
176:                }
177:
178:                if (datatype.equalsIgnoreCase("BIT")) {
179:                    return "SFieldInteger"; //should be something else but ...
180:                }
181:
182:                if (datatype.equalsIgnoreCase("INT")
183:                        || datatype.equalsIgnoreCase("INTEGER")) {
184:                    if (_column.getSize() > 9) {
185:                        return "SFieldLong";
186:                    } else {
187:                        return "SFieldInteger";
188:                    }
189:                }
190:
191:                if (datatype.equalsIgnoreCase("TEXT")) {
192:                    return "SFieldString";
193:                }
194:
195:                if (datatype.equalsIgnoreCase("TINYINT")) {
196:                    return "SFieldInteger";
197:                }
198:
199:                if (datatype.equalsIgnoreCase("SMALLDATETIME")) {
200:                    return "SFieldDate";
201:                }
202:
203:                if (datatype.equalsIgnoreCase("TIMESTAMP")) {
204:                    return "SFieldTimestamp";
205:                }
206:
207:                //VARBINARY to Timestamp - are you sure          
208:                if (datatype.equalsIgnoreCase("VARBINARY")) {
209:                    return "SFieldTimestamp";
210:                }
211:
212:                //map a Float to double.          
213:                if (datatype.equalsIgnoreCase("FLOAT")) {
214:                    return "SFieldDouble";
215:                }
216:
217:                if (datatype.equalsIgnoreCase("DATE")) {
218:                    return "SFieldDate";
219:                } else {
220:                    return datatype.substring(0, 1).toUpperCase()
221:                            + datatype.substring(1).toLowerCase();
222:                }
223:            }
224:
225:            /**example: "int fldEmpleeID"*/
226:            public AParam getParameters() {
227:
228:                //not a foreign key
229:                String name = "_" + niceColumnName;
230:                String type = sFieldToPrimative(jdbcTypeToSField(column));
231:
232:                String methodParam = type + " " + name;
233:                String objectParam = name;
234:                if (sFieldToPrimativeObject(jdbcTypeToSField(column)) != null) {
235:                    objectParam = "new "
236:                            + sFieldToPrimativeObject(jdbcTypeToSField(column))
237:                            + "( " + name + ")";
238:                }
239:                ;
240:                return new AParam(name, type, methodParam, objectParam);
241:
242:            }
243:
244:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.