Source Code Cross Referenced for Col.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: Col.java,v 1.11 2005/05/21 19:41:23 spal Exp $
003:         * $Source: /cvsroot/sqlunit/sqlunit/src/net/sourceforge/sqlunit/beans/Col.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 net.sourceforge.sqlunit.IType;
024:        import net.sourceforge.sqlunit.SQLUnitException;
025:        import net.sourceforge.sqlunit.TypeFactory;
026:        import net.sourceforge.sqlunit.TypeMapper;
027:        import net.sourceforge.sqlunit.types.BigDecimalType;
028:        import net.sourceforge.sqlunit.utils.TypeUtils;
029:
030:        import org.apache.log4j.Logger;
031:        import org.jdom.Element;
032:
033:        /**
034:         * Models a col element, representing a column in a database row.
035:         * @author Sujit Pal (spal@users.sourceforge.net)
036:         * @version $Revision: 1.11 $
037:         */
038:        public class Col implements  Comparable {
039:
040:            private String id;
041:            private String name;
042:            private String type;
043:            private String className;
044:            private String value;
045:
046:            private static final Logger LOG = Logger.getLogger(Col.class);
047:
048:            /**
049:             * Returns the Id for this column.
050:             * @return the id for this column.
051:             */
052:            public final String getId() {
053:                return id;
054:            }
055:
056:            /**
057:             * Set the id for this column.
058:             * @param id the id for this column.
059:             */
060:            public final void setId(final String id) {
061:                this .id = id;
062:            }
063:
064:            /**
065:             * Return the name for this column.
066:             * @return the name for this column.
067:             */
068:            public final String getName() {
069:                return name;
070:            }
071:
072:            /**
073:             * Set the name for this column,
074:             * @param name the name for this column.
075:             */
076:            public final void setName(final String name) {
077:                this .name = name;
078:            }
079:
080:            /**
081:             * Return the XML type for this column.
082:             * @return the XML type for this column,
083:             */
084:            public final String getType() {
085:                return type;
086:            }
087:
088:            /**
089:             * Set the XML type for this column,
090:             * @param type the XML type for this column.
091:             */
092:            public final void setType(final String type) {
093:                this .type = type;
094:            }
095:
096:            /**
097:             * Returns the class name (for IJavaObject objects) for this column,
098:             * @return the class name for this column.
099:             */
100:            public final String getClassName() {
101:                return className;
102:            }
103:
104:            /**
105:             * Set the class name (for IJavaObject objects) for this column,
106:             * @param className the class name for this column.
107:             */
108:            public final void setClassName(final String className) {
109:                this .className = className;
110:            }
111:
112:            /**
113:             * Returns the value of this column as a String.
114:             * @return the value of this column as a String.
115:             */
116:            public final String getValue() {
117:                return value;
118:            }
119:
120:            /**
121:             * Set the value of this column from a String.
122:             * @param value the value to set.
123:             */
124:            public final void setValue(final String value) {
125:                this .value = value;
126:            }
127:
128:            /**
129:             * Returns a negative, zero or positive value depending on whether
130:             * the contents of this column is less than, equal to or greater 
131:             * than the contents of the passed in Col object.
132:             * @param obj an instance of a Col object.
133:             * @return a negative, zero or positive number.
134:             */
135:            public final int compareTo(final Object obj) {
136:                LOG.debug("compareTo(" + obj.toString() + ")");
137:                if (!(obj instanceof  Col)) {
138:                    return 0;
139:                }
140:                Col that = (Col) obj;
141:                if (!(this .getType().equals(that.getType()))) {
142:                    return 0;
143:                }
144:                try {
145:                    IType this TypeObj = TypeFactory.getInstance(this .getType());
146:                    IType thatTypeObj = TypeFactory.getInstance(that.getType());
147:                    this TypeObj.toObject(this .getValue());
148:                    thatTypeObj.toObject(that.getValue());
149:                    return (this TypeObj.compareTo(thatTypeObj));
150:                } catch (SQLUnitException e) {
151:                    return 0;
152:                }
153:            }
154:
155:            /**
156:             * Returns a true or false based on whether the objects are equal.
157:             * @param obj the Object to compare against.
158:             * @return true or false.
159:             */
160:            public final boolean equals(final Object obj) {
161:                if (!(obj instanceof  Col)) {
162:                    return false;
163:                }
164:                Col that = (Col) obj;
165:                try {
166:                    boolean isTypeEqual = this .getType().equals(that.getType());
167:                    //(TypeUtils.getSqlTypeFromXmlType(this.getType())
168:                    //== TypeUtils.getSqlTypeFromXmlType(that.getType()));
169:                    if (isTypeEqual) {
170:                        String typeClassName = TypeMapper
171:                                .findClassById(TypeUtils
172:                                        .getSqlTypeFromXmlType(this .getType()));
173:                        // special treatment for BigDecimal, we need to normalize
174:                        // the scales.
175:                        if (BigDecimalType.class.getName()
176:                                .equals(typeClassName)) {
177:                            return isTypeEqual
178:                                    && TypeUtils.isValueOfBigDecimalEqual(this 
179:                                            .getValue(), that.getValue());
180:                        } else {
181:                            return isTypeEqual
182:                                    && this .getValue().equals(that.getValue());
183:                        }
184:                    } else {
185:                        return false;
186:                    }
187:                } catch (SQLUnitException e) {
188:                    return false;
189:                }
190:            }
191:
192:            /**
193:             * Returns a hashcode for the Col object. This is the sum of the
194:             * hashcodes for the type and the value.
195:             * @return a hash code for the Col object.
196:             */
197:            public final int hashCode() {
198:                return this .getType().hashCode() + this .getValue().hashCode();
199:            }
200:
201:            /**
202:             * Returns a JDOM element that represents this Col object.
203:             * @return a JDOM element representing this object.
204:             */
205:            public final Element toElement() {
206:                Element elCol = new Element("col");
207:                elCol.setAttribute("id", getId());
208:                elCol.setAttribute("name", (getName() == null ? "c" + getId()
209:                        : getName()));
210:                if (getClassName() != null) {
211:                    elCol.setAttribute("class", getClassName());
212:                }
213:                elCol.setAttribute("type", getType());
214:                elCol.setText(getValue());
215:                return elCol;
216:            }
217:
218:            /**
219:             * Returns a compact String representation of the Col object.
220:             * @return a String representation of the Col object.
221:             */
222:            public final String toString() {
223:                return getValue() + "(" + getType() + ")";
224:            }
225:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.