Source Code Cross Referenced for DBColumn.java in  » Groupware » hipergate » com » knowgate » dataobjs » 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 » Groupware » hipergate » com.knowgate.dataobjs 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:          Copyright (C) 2003  Know Gate S.L. All rights reserved.
003:                              C/Oņa, 107 1š2 28050 Madrid (Spain)
004:
005:          Redistribution and use in source and binary forms, with or without
006:          modification, are permitted provided that the following conditions
007:          are met:
008:
009:          1. Redistributions of source code must retain the above copyright
010:             notice, this list of conditions and the following disclaimer.
011:
012:          2. The end-user documentation included with the redistribution,
013:             if any, must include the following acknowledgment:
014:             "This product includes software parts from hipergate
015:             (http://www.hipergate.org/)."
016:             Alternately, this acknowledgment may appear in the software itself,
017:             if and wherever such third-party acknowledgments normally appear.
018:
019:          3. The name hipergate must not be used to endorse or promote products
020:             derived from this software without prior written permission.
021:             Products derived from this software may not be called hipergate,
022:             nor may hipergate appear in their name, without prior written
023:             permission.
024:
025:          This library is distributed in the hope that it will be useful,
026:          but WITHOUT ANY WARRANTY; without even the implied warranty of
027:          MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
028:
029:          You should have received a copy of hipergate License with this code;
030:          if not, visit http://www.hipergate.org or mail to info@hipergate.org
031:         */
032:
033:        package com.knowgate.dataobjs;
034:
035:        import java.sql.DatabaseMetaData;
036:        import java.sql.Types;
037:        import java.sql.Timestamp;
038:
039:        import java.text.ParseException;
040:        import java.text.SimpleDateFormat;
041:        import java.math.BigDecimal;
042:
043:        /**
044:         * <p>Object representing metadata for a database table column.</p>
045:         * @author Sergio Montoro Ten
046:         * @version 3.0
047:         */
048:
049:        public final class DBColumn {
050:
051:            public DBColumn() {
052:            }
053:
054:            public DBColumn(String sTable, String sColName, short iColType,
055:                    String sColType, int iPrecision, int iDecDigits,
056:                    int iNullable, int iColPos)
057:
058:            {
059:                sName = sColName;
060:                iPosition = iColPos;
061:                sTableName = sTable;
062:                iSQLType = iColType;
063:                sSQLTypeName = sColType;
064:                iMaxSize = iPrecision;
065:                iDecimalDigits = iDecDigits;
066:                bNullable = (iNullable == DatabaseMetaData.columnNullable);
067:            }
068:
069:            //-----------------------------------------------------------
070:
071:            /**
072:             *
073:             * @return Column Name
074:             */
075:            public String getName() {
076:                return sName;
077:            }
078:
079:            /**
080:             * Set column name
081:             * @param sColName String
082:             */
083:            public void setName(String sColName) {
084:                sName = sColName;
085:            }
086:
087:            /**
088:             *
089:             * @return Column Position (starting at column 1)
090:             */
091:            public int getPosition() {
092:                return iPosition;
093:            }
094:
095:            /**
096:             * Set column position
097:             * @param iPos int
098:             */
099:            public void setPosition(int iPos) {
100:                iPosition = iPos;
101:            }
102:
103:            /**
104:             *
105:             * @return Name of table containing this column
106:             */
107:            public String getTableName() {
108:                return sTableName;
109:            }
110:
111:            /**
112:             *
113:             * @return Column SQL Type
114:             * @see java.sql.Types
115:             */
116:
117:            public short getSqlType() {
118:                return iSQLType;
119:            }
120:
121:            /**
122:             * Set SQL type for this column
123:             * @param iType short
124:             */
125:            public void setSqlType(short iType) {
126:                iSQLType = iType;
127:                sSQLTypeName = DBColumn.typeName(iSQLType);
128:            }
129:
130:            public void setSqlType(int iType) {
131:                iSQLType = (short) iType;
132:                sSQLTypeName = DBColumn.typeName(iSQLType);
133:            }
134:
135:            /**
136:             *
137:             * @return SQL Type Name
138:             */
139:            public String getSqlTypeName() {
140:                return sSQLTypeName;
141:            }
142:
143:            /**
144:             *
145:             * @return Column Precision
146:             */
147:
148:            public int getPrecision() {
149:                return iMaxSize;
150:            }
151:
152:            /**
153:             *
154:             * @return Decimal Digits
155:             */
156:
157:            public int getDecimalDigits() {
158:                return iDecimalDigits;
159:            }
160:
161:            /**
162:             *
163:             * @return Allows NULLs?
164:             */
165:
166:            public boolean isNullable() {
167:                return bNullable;
168:            }
169:
170:            //-----------------------------------------------------------
171:
172:            public void setDateFormat(String sFmt)
173:                    throws IllegalArgumentException {
174:                oDtFmt = new SimpleDateFormat(sFmt);
175:            }
176:
177:            //-----------------------------------------------------------
178:
179:            public SimpleDateFormat getDateFormat() {
180:                return oDtFmt;
181:            }
182:
183:            //-----------------------------------------------------------
184:
185:            /**
186:             * Get SQL type name from its integer identifier
187:             * @param iSQLtype int
188:             * @return String
189:             */
190:            public static String typeName(int iSQLtype) {
191:                switch (iSQLtype) {
192:                case Types.BIGINT:
193:                    return "BIGINT";
194:                case Types.BINARY:
195:                    return "BINARY";
196:                case Types.BIT:
197:                    return "BIT";
198:                case Types.BLOB:
199:                    return "BLOB";
200:                case Types.BOOLEAN:
201:                    return "BOOLEAN";
202:                case Types.CHAR:
203:                    return "CHAR";
204:                case Types.CLOB:
205:                    return "CLOB";
206:                case Types.DATE:
207:                    return "DATE";
208:                case Types.DECIMAL:
209:                    return "DECIMAL";
210:                case Types.DOUBLE:
211:                    return "DOUBLE";
212:                case Types.FLOAT:
213:                    return "FLOAT";
214:                case Types.INTEGER:
215:                    return "INTEGER";
216:                case Types.LONGVARBINARY:
217:                    return "LONGVARBINARY";
218:                case Types.LONGVARCHAR:
219:                    return "LONGVARCHAR";
220:                case Types.NULL:
221:                    return "NULL";
222:                case Types.NUMERIC:
223:                    return "NUMERIC";
224:                case Types.REAL:
225:                    return "REAL";
226:                case Types.SMALLINT:
227:                    return "SMALLINT";
228:                case Types.TIME:
229:                    return "TIME";
230:                case Types.TIMESTAMP:
231:                    return "TIMESTAMP";
232:                case Types.TINYINT:
233:                    return "TINYINT";
234:                case Types.VARBINARY:
235:                    return "VARBINARY";
236:                case Types.VARCHAR:
237:                    return "VARCHAR";
238:                default:
239:                    return "OTHER";
240:                }
241:            }
242:
243:            //-----------------------------------------------------------
244:
245:            /**
246:             * Get SQL type identifier from its name
247:             * @param sToken String
248:             * @return String
249:             */
250:
251:            public static int getSQLType(String sToken) {
252:                int iSQLType;
253:                if (sToken.equalsIgnoreCase("VARCHAR"))
254:                    iSQLType = Types.VARCHAR;
255:                else if (sToken.equalsIgnoreCase("CHAR"))
256:                    iSQLType = Types.CHAR;
257:                else if (sToken.equalsIgnoreCase("SMALLINT"))
258:                    iSQLType = Types.SMALLINT;
259:                else if (sToken.equalsIgnoreCase("INTEGER"))
260:                    iSQLType = Types.INTEGER;
261:                else if (sToken.equalsIgnoreCase("FLOAT"))
262:                    iSQLType = Types.FLOAT;
263:                else if (sToken.equalsIgnoreCase("DOUBLE"))
264:                    iSQLType = Types.DOUBLE;
265:                else if (sToken.equalsIgnoreCase("NUMERIC"))
266:                    iSQLType = Types.NUMERIC;
267:                else if (sToken.equalsIgnoreCase("DECIMAL"))
268:                    iSQLType = Types.DECIMAL;
269:                else if (sToken.equalsIgnoreCase("DATE"))
270:                    iSQLType = Types.DATE;
271:                else if (sToken.equalsIgnoreCase("TIMESTAMP"))
272:                    iSQLType = Types.TIMESTAMP;
273:                else if (sToken.equalsIgnoreCase("DATETIME"))
274:                    iSQLType = Types.TIMESTAMP;
275:                else if (sToken.equalsIgnoreCase("NVARCHAR"))
276:                    iSQLType = Types.VARCHAR;
277:                else if (sToken.equalsIgnoreCase("VARCHAR2"))
278:                    iSQLType = Types.VARCHAR;
279:                else if (sToken.equalsIgnoreCase("LONGVARCHAR"))
280:                    iSQLType = Types.LONGVARCHAR;
281:                else if (sToken.equalsIgnoreCase("LONG"))
282:                    iSQLType = Types.LONGVARCHAR;
283:                else if (sToken.equalsIgnoreCase("TEXT"))
284:                    iSQLType = Types.LONGVARCHAR;
285:                else if (sToken.equalsIgnoreCase("LONGVARBINARY"))
286:                    iSQLType = Types.LONGVARBINARY;
287:                else if (sToken.equalsIgnoreCase("LONG RAW"))
288:                    iSQLType = Types.LONGVARBINARY;
289:                else if (sToken.equalsIgnoreCase("BLOB"))
290:                    iSQLType = Types.BLOB;
291:                else if (sToken.equalsIgnoreCase("CLOB"))
292:                    iSQLType = Types.CLOB;
293:                else
294:                    iSQLType = Types.NULL;
295:                return iSQLType;
296:            }
297:
298:            // -------------------------------------------------
299:
300:            public Object convert(String sIn) throws NumberFormatException,
301:                    ParseException, NullPointerException {
302:                if (sIn == null)
303:                    return null;
304:                if (sIn.length() == 0)
305:                    return null;
306:                switch (iSQLType) {
307:                case Types.SMALLINT:
308:                    return new Short(sIn);
309:                case Types.INTEGER:
310:                    return new Integer(sIn);
311:                case Types.FLOAT:
312:                    return new Float(sIn);
313:                case Types.DOUBLE:
314:                    return new Double(sIn);
315:                case Types.DECIMAL:
316:                case Types.NUMERIC:
317:                    return new BigDecimal(sIn);
318:                case Types.DATE:
319:                    return oDtFmt.parse(sIn);
320:                case Types.TIMESTAMP:
321:                    return new Timestamp(oDtFmt.parse(sIn).getTime());
322:                default:
323:                    return sIn;
324:                }
325:            } // convert
326:
327:            //-----------------------------------------------------------
328:
329:            private String sName;
330:            private int iPosition;
331:            private String sTableName;
332:            private short iSQLType;
333:            private String sSQLTypeName;
334:            private int iMaxSize;
335:            private int iDecimalDigits;
336:            private boolean bNullable;
337:            private SimpleDateFormat oDtFmt;
338:        } // DBColumn
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.