Source Code Cross Referenced for TimeType.java in  » Database-ORM » hibernate » org » hibernate » type » 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 » hibernate » org.hibernate.type 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        //$Id: TimeType.java 8891 2005-12-21 05:13:29Z oneovthafew $
002:        package org.hibernate.type;
003:
004:        import java.sql.PreparedStatement;
005:        import java.sql.ResultSet;
006:        import java.sql.SQLException;
007:        import java.sql.Time;
008:        import java.sql.Types;
009:        import java.text.ParseException;
010:        import java.text.SimpleDateFormat;
011:        import java.util.Calendar;
012:        import java.util.Date;
013:
014:        import org.hibernate.EntityMode;
015:        import org.hibernate.HibernateException;
016:        import org.hibernate.dialect.Dialect;
017:
018:        /**
019:         * <tt>time</tt>: A type that maps an SQL TIME to a Java
020:         * java.util.Date or java.sql.Time.
021:         * @author Gavin King
022:         */
023:        public class TimeType extends MutableType implements  LiteralType {
024:
025:            private static final String TIME_FORMAT = "HH:mm:ss";
026:
027:            public Object get(ResultSet rs, String name) throws SQLException {
028:                return rs.getTime(name);
029:            }
030:
031:            public Class getReturnedClass() {
032:                return java.util.Date.class;
033:            }
034:
035:            public void set(PreparedStatement st, Object value, int index)
036:                    throws SQLException {
037:
038:                Time time;
039:                if (value instanceof  Time) {
040:                    time = (Time) value;
041:                } else {
042:                    time = new Time(((java.util.Date) value).getTime());
043:                }
044:                st.setTime(index, time);
045:            }
046:
047:            public int sqlType() {
048:                return Types.TIME;
049:            }
050:
051:            public String getName() {
052:                return "time";
053:            }
054:
055:            public String toString(Object val) {
056:                return new SimpleDateFormat(TIME_FORMAT)
057:                        .format((java.util.Date) val);
058:            }
059:
060:            public boolean isEqual(Object x, Object y) {
061:
062:                if (x == y)
063:                    return true;
064:                if (x == null || y == null)
065:                    return false;
066:
067:                Date xdate = (Date) x;
068:                Date ydate = (Date) y;
069:
070:                if (xdate.getTime() == ydate.getTime())
071:                    return true;
072:
073:                Calendar calendar1 = java.util.Calendar.getInstance();
074:                Calendar calendar2 = java.util.Calendar.getInstance();
075:                calendar1.setTime(xdate);
076:                calendar2.setTime(ydate);
077:
078:                return calendar1.get(Calendar.HOUR_OF_DAY) == calendar2
079:                        .get(Calendar.HOUR_OF_DAY)
080:                        && calendar1.get(Calendar.MINUTE) == calendar2
081:                                .get(Calendar.MINUTE)
082:                        && calendar1.get(Calendar.SECOND) == calendar2
083:                                .get(Calendar.SECOND)
084:                        && calendar1.get(Calendar.MILLISECOND) == calendar2
085:                                .get(Calendar.MILLISECOND);
086:            }
087:
088:            public int getHashCode(Object x, EntityMode entityMode) {
089:                Calendar calendar = java.util.Calendar.getInstance();
090:                calendar.setTime((java.util.Date) x);
091:                int hashCode = 1;
092:                hashCode = 31 * hashCode + calendar.get(Calendar.HOUR_OF_DAY);
093:                hashCode = 31 * hashCode + calendar.get(Calendar.MINUTE);
094:                hashCode = 31 * hashCode + calendar.get(Calendar.SECOND);
095:                hashCode = 31 * hashCode + calendar.get(Calendar.MILLISECOND);
096:                return hashCode;
097:            }
098:
099:            public Object deepCopyNotNull(Object value) {
100:                return new Time(((java.util.Date) value).getTime());
101:            }
102:
103:            public String objectToSQLString(Object value, Dialect dialect)
104:                    throws Exception {
105:                return '\'' + new Time(((java.util.Date) value).getTime())
106:                        .toString() + '\'';
107:            }
108:
109:            public Object fromStringValue(String xml) throws HibernateException {
110:                try {
111:                    return new SimpleDateFormat(TIME_FORMAT).parse(xml);
112:                } catch (ParseException pe) {
113:                    throw new HibernateException("could not parse XML", pe);
114:                }
115:            }
116:
117:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.