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


001:        /*
002:         * $Id: TimeType.java,v 1.10 2005/04/13 06:26:46 spal Exp $
003:         * $Source: /cvsroot/sqlunit/sqlunit/src/net/sourceforge/sqlunit/types/TimeType.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.types;
022:
023:        import net.sourceforge.sqlunit.IErrorCodes;
024:        import net.sourceforge.sqlunit.SQLUnitException;
025:        import net.sourceforge.sqlunit.SymbolTable;
026:        import net.sourceforge.sqlunit.utils.TypeUtils;
027:
028:        import java.sql.Time;
029:        import java.text.ParseException;
030:        import java.text.SimpleDateFormat;
031:        import java.util.Calendar;
032:        import java.util.Date;
033:        import java.util.GregorianCalendar;
034:
035:        /**
036:         * Models a TIME type.
037:         * @author Ralph Brendler (rbrendler@users.sourceforge.net)
038:         * @author Sujit Pal (spal@users.sourceforge.net)
039:         * @version $Revision: 1.10 $
040:         * @sqlunit.type name="TimeType" input="Yes" output="Yes" sortable="Yes"
041:         *  wraps="java.sql.Time"
042:         * @sqlunit.typename name="TIME" server="Any"
043:         */
044:        public class TimeType extends UnsupportedType {
045:
046:            private static final int NUM_SECS_PER_MIN = 60;
047:            private static final int NUM_SECS_PER_HR = 3600;
048:
049:            /** 
050:             * Specifies the pattern for the DATE object. This can be overriden 
051:             * to work with other database formats for time in subclasses.
052:             */
053:            protected static String PATTERN = "HH:mm:ss";
054:
055:            private SimpleDateFormat formatter = new SimpleDateFormat(PATTERN);
056:
057:            /**
058:             * Formats a TIME into its String representation.
059:             * @param obj an Object to be converted to the IType interface.
060:             * @return the String representation of the object.
061:             * @exception SQLUnitException if the formatting failed.
062:             */
063:            protected String format(final Object obj) throws SQLUnitException {
064:                if (!(obj instanceof  Time)) {
065:                    throw new SQLUnitException(
066:                            IErrorCodes.UNSUPPORTED_DATATYPE_FORMAT,
067:                            new String[] {
068:                                    SymbolTable.getCurrentResultKey(),
069:                                    (obj == null ? "NULL" : obj.getClass()
070:                                            .getName()), getName(),
071:                                    (new Integer(getId())).toString() });
072:                }
073:                Time time = (Time) obj;
074:                long millisSinceEpoch = time.getTime();
075:                Date d = new Date(millisSinceEpoch);
076:                return formatter.format(d);
077:            }
078:
079:            /**
080:             * Parses a String representing a TIME to a Time object.
081:             * @param str the String representation of the DATE.
082:             * @return a Time object.
083:             * @exception SQLUnitException if the parsing failed.
084:             */
085:            protected Object parse(final String str) throws SQLUnitException {
086:                try {
087:                    Date d = formatter.parse(str);
088:                    Time time = new Time(d.getTime());
089:                    return time;
090:                } catch (ParseException e) {
091:                    throw new SQLUnitException(
092:                            IErrorCodes.UNSUPPORTED_DATATYPE_PARSE,
093:                            new String[] { SymbolTable.getCurrentResultKey(),
094:                                    str, "java.sql.Time", getName(),
095:                                    (new Integer(getId())).toString() });
096:                }
097:            }
098:
099:            /**
100:             * Returns true if the two objects are equal, false otherwise.
101:             * @param obj the Object to compare against.
102:             * @return true or false.
103:             */
104:            public final boolean equals(final Object obj) {
105:                if (!(obj instanceof  TimeType)) {
106:                    return false;
107:                } else {
108:                    return (compareTo(obj) == 0);
109:                }
110:            }
111:
112:            /**
113:             * Returns the hashcode for the underlying wrapped datatype.
114:             * @return the hashcode for the underlying wrapped datatype.
115:             */
116:            public final int hashCode() {
117:                return super .hashCode();
118:            }
119:
120:            /**
121:             * Returns a negative, zero or positive number according to whether this
122:             * object is smaller, equal or larger than the passed in object.
123:             * @param obj an Object of type TimeType.
124:             * @return a negative, zero or positive number.
125:             */
126:            public final int compareTo(final Object obj) {
127:                if (!(obj instanceof  TimeType)) {
128:                    return 0;
129:                }
130:                TimeType that = (TimeType) obj;
131:                boolean isEitherNull = TypeUtils.checkIfNull(this , that);
132:                if (isEitherNull) {
133:                    return TypeUtils.compareNulls(this , that);
134:                } else {
135:                    // compare only the time portion
136:                    Calendar cal = new GregorianCalendar();
137:                    cal.setTime(new Date(((Time) this .getValue()).getTime()));
138:                    int this SecondsSinceToday = ((cal.get(Calendar.HOUR_OF_DAY) * NUM_SECS_PER_HR)
139:                            + (cal.get(Calendar.MINUTE) * NUM_SECS_PER_MIN) + (cal
140:                            .get(Calendar.SECOND)));
141:                    cal.setTime(new Date(((Time) that.getValue()).getTime()));
142:                    int thatSecondsSinceToday = ((cal.get(Calendar.HOUR_OF_DAY) * NUM_SECS_PER_HR)
143:                            + (cal.get(Calendar.MINUTE) * NUM_SECS_PER_MIN) + (cal
144:                            .get(Calendar.SECOND)));
145:                    return (thisSecondsSinceToday - thatSecondsSinceToday);
146:                }
147:            }
148:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.