Source Code Cross Referenced for tsRow.java in  » Database-DBMS » TinySQL » com » sqlmagic » tinysql » 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 DBMS » TinySQL » com.sqlmagic.tinysql 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *
003:         * tsRow.java - Row object for tinySQL.
004:         * 
005:         * Copyright 1996, Brian C. Jepson
006:         *                 (bjepson@ids.net)
007:         * $Author: davis $
008:         * $Date: 2004/12/18 21:25:20 $
009:         * $Revision: 1.1 $
010:         *
011:         * This library is free software; you can redistribute it and/or
012:         * modify it under the terms of the GNU Lesser General Public
013:         * License as published by the Free Software Foundation; either
014:         * version 2.1 of the License, or (at your option) any later version.
015:         *
016:         * This library is distributed in the hope that it will be useful,
017:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
018:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
019:         * Lesser General Public License for more details.
020:         *
021:         * You should have received a copy of the GNU Lesser General Public
022:         * License along with this library; if not, write to the Free Software
023:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
024:         *
025:         */
026:
027:        package com.sqlmagic.tinysql;
028:
029:        import java.util.*;
030:        import java.lang.*;
031:        import java.io.*;
032:
033:        /*
034:         *
035:         * tsRow - an extension to Hashtable to hold a given row.
036:         *
037:         */
038:        class tsRow extends Hashtable implements  Comparable {
039:            Vector orderByColumns = (Vector) null;
040:            boolean debug = false;
041:
042:            /**
043:             *
044:             * Given a column name, returns its value as a string.
045:             *
046:             * @param column the name of the column
047:             *
048:             */
049:            public void setOrderBy(Vector inputColumns) {
050:                orderByColumns = inputColumns;
051:            }
052:
053:            public String columnAsString(String column) {
054:                return (String) get(column);
055:            }
056:
057:            /**
058:             *
059:             * Given a tsColumn object, returns its value as a String.
060:             *
061:             * @param column the tsColumn object
062:             *
063:             */
064:            public String columnAsString(tsColumn column) {
065:                String outputString, valueString, functionName, argList, nextArg;
066:                StringBuffer functionBuffer;
067:                FieldTokenizer ft1, ft2;
068:                /*
069:                 *    Next try to retrieve as a group function, which will not have a
070:                 *    tablename prefix.
071:                 */
072:                outputString = (String) get(column.name);
073:                if (outputString != (String) null)
074:                    return outputString;
075:                ft1 = new FieldTokenizer(column.name, '(', false);
076:                if (ft1.countFields() == 2) {
077:                    /*
078:                     *       The column is a function.  If it is a group function, the value
079:                     *       will be stored in the record.  Otherwise, the function value
080:                     *       will be determined here by retrieving and processing all the
081:                     *       columns in the function arguments.
082:                     */
083:                    outputString = (String) get(column.name);
084:                    if (outputString != (String) null)
085:                        return outputString;
086:                    functionName = ft1.getField(0);
087:                    argList = ft1.getField(1);
088:                    ft2 = new FieldTokenizer(argList, ',', false);
089:                    functionBuffer = new StringBuffer();
090:                    /*
091:                     *       Function arguments must consist of table.column names or constants.
092:                     */
093:                    while (ft2.hasMoreFields()) {
094:                        nextArg = ft2.nextField();
095:                        valueString = (String) get(nextArg);
096:                        if (debug)
097:                            System.out.println("Function " + functionName
098:                                    + " argument " + nextArg + " has value "
099:                                    + valueString);
100:                        /*
101:                         *          If the valueString is null then it is a constant rather than
102:                         *          a database column.  Remove enclosing quotes.
103:                         */
104:                        if (valueString == (String) null)
105:                            valueString = UtilString.removeQuotes(nextArg);
106:                        else
107:                            valueString = valueString.trim();
108:                        if (functionName.equals("CONCAT"))
109:                            functionBuffer.append(valueString);
110:                    }
111:                    outputString = functionBuffer.toString();
112:                } else if (column.tableName == (String) null) {
113:                    /*
114:                     *       This is a constant.  Return the table name which will be equal to
115:                     *       the constant value.
116:                     */
117:                    outputString = UtilString.removeQuotes(column.name);
118:                } else {
119:                    /*
120:                     *       Retrieve as a simple database column.
121:                     */
122:                    outputString = (String) get(column.tableName + "."
123:                            + column.name);
124:                    if (Utils.isDateColumn(column.type)) {
125:                        /*
126:                         *          Format dates as DD-MON-YY for output.  Note that the value
127:                         *          stored in the database may already be in this format because
128:                         *          of incorrect storage of date strings prior to version 2.3.
129:                         */
130:                        try {
131:                            outputString = UtilString
132:                                    .toStandardDate(outputString);
133:                        } catch (Exception dateEx) {
134:                            System.out.println(dateEx.getMessage());
135:                        }
136:                    }
137:                }
138:                return outputString;
139:            }
140:
141:            public int compareTo(Object inputObj) {
142:                String tableColumnName, this String, inputString;
143:                tsColumn columnObject;
144:                tsRow inputRow;
145:                int i, columnType;
146:                double this Value, inputValue;
147:                if (orderByColumns == (Vector) null)
148:                    return 0;
149:                inputRow = (tsRow) inputObj;
150:                for (i = 0; i < orderByColumns.size(); i++) {
151:                    columnObject = (tsColumn) orderByColumns.elementAt(i);
152:                    tableColumnName = columnObject.name;
153:                    columnType = columnObject.type;
154:                    this String = (String) get(tableColumnName);
155:                    inputString = (String) inputRow.get(tableColumnName);
156:                    if (Utils.isCharColumn(columnType)
157:                            | Utils.isDateColumn(columnType)) {
158:                        if (this String == (String) null
159:                                | inputString == (String) null)
160:                            continue;
161:                        if (this String.compareTo(inputString) != 0)
162:                            return this String.compareTo(inputString);
163:                    } else if (Utils.isNumberColumn(columnType)) {
164:                        this Value = UtilString.doubleValue(this String);
165:                        inputValue = UtilString.doubleValue(inputString);
166:                        if (this Value > inputValue)
167:                            return 1;
168:                        else if (this Value < inputValue)
169:                            return -1;
170:                    } else {
171:                        System.out.println("Cannot sort unknown type");
172:                    }
173:                }
174:                return 0;
175:            }
176:
177:            public String toString() {
178:                StringBuffer outputBuffer = new StringBuffer();
179:                String columnName, columnValue;
180:                Enumeration e;
181:                for (e = this .keys(); e.hasMoreElements();) {
182:                    columnName = (String) e.nextElement();
183:                    columnValue = (String) this .get(columnName);
184:                    outputBuffer.append(columnName + "=" + columnValue + " ");
185:                }
186:                return outputBuffer.toString();
187:            }
188:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.