Source Code Cross Referenced for Row.java in  » Testing » sqlunit » net » sourceforge » sqlunit » beans » 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 » Testing » sqlunit » net.sourceforge.sqlunit.beans 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * $Id: Row.java,v 1.5 2005/05/03 17:22:38 spal Exp $
003:         * $Source: /cvsroot/sqlunit/sqlunit/src/net/sourceforge/sqlunit/beans/Row.java,v $
004:         * SQLUnit - a test harness for unit testing database stored procedures.
005:         * Copyright (C) 2003  The SQLUnit Team
006:         * 
007:         * This program is free software; you can redistribute it and/or
008:         * modify it under the terms of the GNU General Public License
009:         * as published by the Free Software Foundation; either version 2
010:         * of the License, or (at your option) any later version.
011:         * 
012:         * This program is distributed in the hope that it will be useful,
013:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
014:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
015:         * GNU General Public License for more details.
016:         * 
017:         * You should have received a copy of the GNU General Public License
018:         * along with this program; if not, write to the Free Software
019:         * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
020:         */
021:        package net.sourceforge.sqlunit.beans;
022:
023:        import org.apache.log4j.Logger;
024:        import org.jdom.Element;
025:
026:        import java.util.HashMap;
027:        import java.util.Map;
028:
029:        /**
030:         * Models a row element, (wrapping multiple Col objects) in a database result.
031:         * @author Sujit Pal (spal@users.sourceforge.net)
032:         * @version $Revision: 1.5 $
033:         */
034:        public class Row implements  Comparable {
035:
036:            private static final Logger LOG = Logger.getLogger(Row.class);
037:
038:            private String id;
039:            private boolean partial = false;
040:            private Col[] cols;
041:            private Map colMap;
042:            private String[] sortColIds;
043:
044:            /**
045:             * Returns the Id for this row.
046:             * @return the id for this row.
047:             */
048:            public final String getId() {
049:                return id;
050:            }
051:
052:            /**
053:             * Set the id for this row.
054:             * @param rowId the id for this row.
055:             */
056:            public final void setId(final String rowId) {
057:                this .id = rowId;
058:            }
059:
060:            /**
061:             * Returns true if the row is partially specified.
062:             * @return true if the row is partially specified.
063:             */
064:            public final boolean isPartial() {
065:                return partial;
066:            }
067:
068:            /**
069:             * Sets whether the row is partially specified.
070:             * @param partial "true" or "false", default is "false".
071:             */
072:            public final void setPartial(String partial) {
073:                this .partial = (partial.equals("true"));
074:            }
075:
076:            /**
077:             * Return an array of Col objects for this row.
078:             * @return an array of Col objects for this row.
079:             */
080:            public final Col[] getCols() {
081:                return cols;
082:            }
083:
084:            /**
085:             * Set the Col object array for this row. Also sets an internal Map
086:             * of Col objects.
087:             * @param columns an array of Col objects.
088:             */
089:            public final void setCols(final Col[] columns) {
090:                this .cols = columns;
091:                this .colMap = new HashMap();
092:                for (int i = 0; i < cols.length; i++) {
093:                    this .colMap.put(cols[i].getId(), cols[i]);
094:                }
095:            }
096:
097:            /**
098:             * Convenience method to return a Col object by its id.
099:             * @param colId the id of the Col object.
100:             * @return a Col object for that id.
101:             */
102:            public final Col getColById(final String colId) {
103:                return (Col) colMap.get(colId);
104:            }
105:
106:            /**
107:             * Sets a string array of ids to sort this row by.
108:             * @param colIdsToSort a String array of column ids.
109:             */
110:            public final void setSortCols(final String[] colIdsToSort) {
111:                this .sortColIds = colIdsToSort;
112:            }
113:
114:            /**
115:             * Returns a negative, zero or positive value depending on whether
116:             * the contents of this column is less than, equal to or greater 
117:             * than the contents of the passed in Col object.
118:             * @param obj an instance of a Col object.
119:             * @return a negative, zero or positive number.
120:             */
121:            public final int compareTo(final Object obj) {
122:                if (!(obj instanceof  Row)) {
123:                    return 0;
124:                }
125:                Row that = (Row) obj;
126:                // the sort columns are set up from the resultset level
127:                // so we can use either one, we are going to use this object.
128:                int compareResult = 0; // they are equal, for now
129:                String[] sortCols = sortColIds;
130:                for (int i = 0; i < sortCols.length; i++) {
131:                    // check if prefixed by a negative sign
132:                    LOG.debug("cols[" + i + "] = " + sortCols[i]);
133:                    boolean sortAscending = (!(sortCols[i].startsWith("-")));
134:                    Col this Col = this .getColById((sortAscending ? sortCols[i]
135:                            : sortCols[i].substring(1)));
136:                    Col thatCol = that.getColById((sortAscending ? sortCols[i]
137:                            : sortCols[i].substring(1)));
138:                    if (sortAscending) {
139:                        compareResult = this Col.compareTo(thatCol);
140:                    } else {
141:                        compareResult = thatCol.compareTo(this Col);
142:                    }
143:                    if (compareResult == 0) {
144:                        continue; // look at the next column to decide
145:                    } else {
146:                        break; // we know which is larger, quit compare
147:                    }
148:                }
149:                return compareResult;
150:            }
151:
152:            /**
153:             * Returns a JDOM element that represents this Col object.
154:             * @return a JDOM element representing this object.
155:             */
156:            public final Element toElement() {
157:                Element elRow = new Element("row");
158:                elRow.setAttribute("id", getId());
159:                Col[] theCols = getCols();
160:                for (int i = 0; i < theCols.length; i++) {
161:                    Element elCol = theCols[i].toElement();
162:                    elRow.addContent(elCol);
163:                }
164:                return elRow;
165:            }
166:
167:            /**
168:             * Returns the string representation of the Row bean.
169:             * @return the String representation of this bean.
170:             */
171:            public final String toString() {
172:                StringBuffer buffer = new StringBuffer();
173:                Col[] theCols = getCols();
174:                for (int i = 0; i < theCols.length; i++) {
175:                    if (i > 0) {
176:                        buffer.append(",");
177:                    }
178:                    buffer.append(theCols[i].getValue());
179:                }
180:                return buffer.toString();
181:            }
182:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.