Source Code Cross Referenced for DateWidget.java in  » Database-ORM » TJDO » com » triactive » jdo » test » 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 ORM » TJDO » com.triactive.jdo.test 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2004 (C) TJDO.
003:         * All rights reserved.
004:         *
005:         * This software is distributed under the terms of the TJDO License version 1.0.
006:         * See the terms of the TJDO License in the documentation provided with this software.
007:         *
008:         * $Id: DateWidget.java,v 1.5 2004/01/18 03:01:07 jackknifebarber Exp $
009:         */
010:
011:        package com.triactive.jdo.test;
012:
013:        public class DateWidget extends Widget implements  HasSCOFields {
014:            private java.util.Date dateField;
015:            private java.sql.Date sqlDateField;
016:            private java.sql.Timestamp sqlTimestampField;
017:
018:            public DateWidget() {
019:                super ();
020:            }
021:
022:            public java.util.Date getDateField() {
023:                return dateField;
024:            }
025:
026:            public java.sql.Date getSQLDateField() {
027:                return sqlDateField;
028:            }
029:
030:            public java.sql.Timestamp getSQLTimestampField() {
031:                return sqlTimestampField;
032:            }
033:
034:            public Object[] getSCOFieldValues() {
035:                return new Object[] { dateField, sqlDateField,
036:                        sqlTimestampField };
037:            }
038:
039:            /**
040:             * Fills all of the object's fields with random data values.  Any non-
041:             * primitive fields will also be assigned <code>null</code> on a random
042:             * basis.
043:             */
044:
045:            public void fillRandom() {
046:                super .fillRandom();
047:
048:                /*
049:                 * When updating a field (rather than nulling it), roughly half the time
050:                 * we mutate the existing object if possible.  In the remaining cases we
051:                 * assign a new object.
052:                 *
053:                 * All dates below are made to be relative to an even second value
054:                 * because we don't insist that the database manage fractional seconds
055:                 * correctly.
056:                 */
057:                if (nextNull())
058:                    dateField = null;
059:                else {
060:                    long t = r.nextInt() * 1000L;
061:
062:                    if (dateField != null && r.nextBoolean())
063:                        dateField.setTime(t);
064:                    else
065:                        dateField = new java.util.Date(t);
066:                }
067:
068:                if (nextNull())
069:                    sqlDateField = null;
070:                else {
071:                    /*
072:                     * We have to convert the random date value to String and back in order
073:                     * to discard the time-of-day portion of the data, otherwise the field
074:                     * won't compare exactly after it's been transferred to the database and
075:                     * back.
076:                     */
077:                    java.sql.Date rndDate = new java.sql.Date(
078:                            r.nextInt() * 1000L);
079:                    long t = java.sql.Date.valueOf(rndDate.toString())
080:                            .getTime();
081:
082:                    if (sqlDateField != null && r.nextBoolean())
083:                        sqlDateField.setTime(t);
084:                    else
085:                        sqlDateField = new java.sql.Date(t);
086:                }
087:
088:                if (nextNull())
089:                    sqlTimestampField = null;
090:                else {
091:                    long t = r.nextInt() * 1000L;
092:
093:                    if (sqlTimestampField != null && r.nextBoolean())
094:                        sqlTimestampField.setTime(t);
095:                    else
096:                        sqlTimestampField = new java.sql.Timestamp(t);
097:                }
098:            }
099:
100:            /**
101:             * Indicates whether some other object is "equal to" this one.  By comparing
102:             * against an original copy of the object, <code>compareTo()</code> can be
103:             * used to verify that the object has been written to a database and read
104:             * back correctly.
105:             *
106:             * @param   obj     the reference object with which to compare
107:             *
108:             * @return  <code>true</code> if this object is equal to the obj argument;
109:             *          <code>false</code> otherwise.
110:             */
111:
112:            public boolean compareTo(Object obj) {
113:                if (this  == obj)
114:                    return true;
115:
116:                if (!(obj instanceof  DateWidget) || !super .compareTo(obj))
117:                    return false;
118:
119:                DateWidget w = (DateWidget) obj;
120:
121:                if (dateField == null) {
122:                    if (w.dateField != null)
123:                        return false;
124:                } else if (!dateField.equals(w.dateField))
125:                    return false;
126:
127:                if (sqlDateField == null) {
128:                    if (w.sqlDateField != null)
129:                        return false;
130:                } else if (!sqlDateField.equals(w.sqlDateField))
131:                    return false;
132:
133:                if (sqlTimestampField == null) {
134:                    if (w.sqlTimestampField != null)
135:                        return false;
136:                } else if (!sqlTimestampField.equals(w.sqlTimestampField))
137:                    return false;
138:
139:                return true;
140:            }
141:
142:            /**
143:             * Returns a string representation for this object.  All of the field
144:             * values are included in the string for debugging purposes.
145:             *
146:             * @return  a string representation for this object.
147:             */
148:
149:            public String toString() {
150:                StringBuffer s = new StringBuffer(super .toString());
151:
152:                s.append("  dateField = ").append(dateField);
153:                if (dateField != null)
154:                    s.append(" (").append(dateField.getTime()).append(')');
155:                s.append('\n');
156:
157:                s.append("  sqlDateField = ").append(sqlDateField);
158:                if (sqlDateField != null)
159:                    s.append(" (").append(sqlDateField.getTime()).append(')');
160:                s.append('\n');
161:
162:                s.append("  sqlTimestampField = ").append(sqlTimestampField);
163:                if (sqlTimestampField != null)
164:                    s.append(" (").append(sqlTimestampField.getTime()).append(
165:                            ')');
166:                s.append('\n');
167:
168:                return s.toString();
169:            }
170:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.