├── .gitignore
├── LICENSE.txt
├── NOTICE.txt
├── README.txt
├── RELEASE-NOTES.txt
├── pom.xml
└── src
├── changes
└── changes.xml
├── conf
└── MANIFEST.MF
├── main
├── assembly
│ └── dist.xml
└── java
│ └── org
│ └── joda
│ └── time
│ └── contrib
│ └── hibernate
│ ├── AbstractStringBasedJodaType.java
│ ├── PersistentDateTime.java
│ ├── PersistentDateTimeAsBigInt.java
│ ├── PersistentDateTimeTZ.java
│ ├── PersistentDuration.java
│ ├── PersistentDurationAsMilliseconds.java
│ ├── PersistentInstant.java
│ ├── PersistentInstantAsBigInt.java
│ ├── PersistentInterval.java
│ ├── PersistentLocalDate.java
│ ├── PersistentLocalDateTime.java
│ ├── PersistentLocalTimeAsString.java
│ ├── PersistentLocalTimeAsTime.java
│ ├── PersistentLocalTimeAsTimestamp.java
│ ├── PersistentLocalTimeExact.java
│ ├── PersistentPeriod.java
│ ├── PersistentTimeOfDay.java
│ ├── PersistentTimeOfDayExact.java
│ └── PersistentYearMonthDay.java
├── site
├── resources
│ ├── css
│ │ └── site.css
│ └── download.html
├── site.xml
└── xdoc
│ ├── index.xml
│ ├── licensecover.xml
│ └── userguide.xml
└── test
└── java
└── org
└── joda
└── time
└── contrib
└── hibernate
├── Event.java
├── EventTZ.java
├── HibernateTestCase.java
├── Plan.java
├── Schedule.java
├── TestPersistentDateTime.java
├── TestPersistentDateTimeAsBigInt.java
├── TestPersistentDuration.java
├── TestPersistentDurationAsMilliseconds.java
├── TestPersistentInstant.java
├── TestPersistentInstantAsBigInt.java
├── TestPersistentInterval.java
├── TestPersistentIntervalNull.java
├── TestPersistentLocalDate.java
├── TestPersistentLocalDateTime.java
├── TestPersistentLocalTime.java
├── TestPersistentPeriod.java
├── TestPersistentTimeOfDay.java
├── TestPersistentTimeOfDayExact.java
├── TestPersistentYearMonthDay.java
├── ThingWithDateTime.java
├── ThingWithInstant.java
├── event.hbm.xml
├── eventTZ.hbm.xml
├── plan.hbm.xml
├── schedule.hbm.xml
├── testmodel
├── SomethingThatHappens.hbm.xml
├── SomethingThatHappens.java
├── SomethingThatLasts.hbm.xml
├── SomethingThatLasts.java
└── SomethingThatLastsInMilliseconds.hbm.xml
├── thingWithDateTime.hbm.xml
├── thingWithDateTimeAsBigInt.hbm.xml
├── thingWithInstant.hbm.xml
└── thingWithInstantAsBigInt.hbm.xml
/.gitignore:
--------------------------------------------------------------------------------
1 | /bin/
2 | /target/
3 | *.log
4 | /tests/
5 | .checkstyle
6 | .classpath
7 | .project
8 | /.settings/
9 | /nbproject/
10 | .idea
11 | *.iml
12 |
--------------------------------------------------------------------------------
/LICENSE.txt:
--------------------------------------------------------------------------------
1 |
2 | Apache License
3 | Version 2.0, January 2004
4 | http://www.apache.org/licenses/
5 |
6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7 |
8 | 1. Definitions.
9 |
10 | "License" shall mean the terms and conditions for use, reproduction,
11 | and distribution as defined by Sections 1 through 9 of this document.
12 |
13 | "Licensor" shall mean the copyright owner or entity authorized by
14 | the copyright owner that is granting the License.
15 |
16 | "Legal Entity" shall mean the union of the acting entity and all
17 | other entities that control, are controlled by, or are under common
18 | control with that entity. For the purposes of this definition,
19 | "control" means (i) the power, direct or indirect, to cause the
20 | direction or management of such entity, whether by contract or
21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
22 | outstanding shares, or (iii) beneficial ownership of such entity.
23 |
24 | "You" (or "Your") shall mean an individual or Legal Entity
25 | exercising permissions granted by this License.
26 |
27 | "Source" form shall mean the preferred form for making modifications,
28 | including but not limited to software source code, documentation
29 | source, and configuration files.
30 |
31 | "Object" form shall mean any form resulting from mechanical
32 | transformation or translation of a Source form, including but
33 | not limited to compiled object code, generated documentation,
34 | and conversions to other media types.
35 |
36 | "Work" shall mean the work of authorship, whether in Source or
37 | Object form, made available under the License, as indicated by a
38 | copyright notice that is included in or attached to the work
39 | (an example is provided in the Appendix below).
40 |
41 | "Derivative Works" shall mean any work, whether in Source or Object
42 | form, that is based on (or derived from) the Work and for which the
43 | editorial revisions, annotations, elaborations, or other modifications
44 | represent, as a whole, an original work of authorship. For the purposes
45 | of this License, Derivative Works shall not include works that remain
46 | separable from, or merely link (or bind by name) to the interfaces of,
47 | the Work and Derivative Works thereof.
48 |
49 | "Contribution" shall mean any work of authorship, including
50 | the original version of the Work and any modifications or additions
51 | to that Work or Derivative Works thereof, that is intentionally
52 | submitted to Licensor for inclusion in the Work by the copyright owner
53 | or by an individual or Legal Entity authorized to submit on behalf of
54 | the copyright owner. For the purposes of this definition, "submitted"
55 | means any form of electronic, verbal, or written communication sent
56 | to the Licensor or its representatives, including but not limited to
57 | communication on electronic mailing lists, source code control systems,
58 | and issue tracking systems that are managed by, or on behalf of, the
59 | Licensor for the purpose of discussing and improving the Work, but
60 | excluding communication that is conspicuously marked or otherwise
61 | designated in writing by the copyright owner as "Not a Contribution."
62 |
63 | "Contributor" shall mean Licensor and any individual or Legal Entity
64 | on behalf of whom a Contribution has been received by Licensor and
65 | subsequently incorporated within the Work.
66 |
67 | 2. Grant of Copyright License. Subject to the terms and conditions of
68 | this License, each Contributor hereby grants to You a perpetual,
69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70 | copyright license to reproduce, prepare Derivative Works of,
71 | publicly display, publicly perform, sublicense, and distribute the
72 | Work and such Derivative Works in Source or Object form.
73 |
74 | 3. Grant of Patent License. Subject to the terms and conditions of
75 | this License, each Contributor hereby grants to You a perpetual,
76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77 | (except as stated in this section) patent license to make, have made,
78 | use, offer to sell, sell, import, and otherwise transfer the Work,
79 | where such license applies only to those patent claims licensable
80 | by such Contributor that are necessarily infringed by their
81 | Contribution(s) alone or by combination of their Contribution(s)
82 | with the Work to which such Contribution(s) was submitted. If You
83 | institute patent litigation against any entity (including a
84 | cross-claim or counterclaim in a lawsuit) alleging that the Work
85 | or a Contribution incorporated within the Work constitutes direct
86 | or contributory patent infringement, then any patent licenses
87 | granted to You under this License for that Work shall terminate
88 | as of the date such litigation is filed.
89 |
90 | 4. Redistribution. You may reproduce and distribute copies of the
91 | Work or Derivative Works thereof in any medium, with or without
92 | modifications, and in Source or Object form, provided that You
93 | meet the following conditions:
94 |
95 | (a) You must give any other recipients of the Work or
96 | Derivative Works a copy of this License; and
97 |
98 | (b) You must cause any modified files to carry prominent notices
99 | stating that You changed the files; and
100 |
101 | (c) You must retain, in the Source form of any Derivative Works
102 | that You distribute, all copyright, patent, trademark, and
103 | attribution notices from the Source form of the Work,
104 | excluding those notices that do not pertain to any part of
105 | the Derivative Works; and
106 |
107 | (d) If the Work includes a "NOTICE" text file as part of its
108 | distribution, then any Derivative Works that You distribute must
109 | include a readable copy of the attribution notices contained
110 | within such NOTICE file, excluding those notices that do not
111 | pertain to any part of the Derivative Works, in at least one
112 | of the following places: within a NOTICE text file distributed
113 | as part of the Derivative Works; within the Source form or
114 | documentation, if provided along with the Derivative Works; or,
115 | within a display generated by the Derivative Works, if and
116 | wherever such third-party notices normally appear. The contents
117 | of the NOTICE file are for informational purposes only and
118 | do not modify the License. You may add Your own attribution
119 | notices within Derivative Works that You distribute, alongside
120 | or as an addendum to the NOTICE text from the Work, provided
121 | that such additional attribution notices cannot be construed
122 | as modifying the License.
123 |
124 | You may add Your own copyright statement to Your modifications and
125 | may provide additional or different license terms and conditions
126 | for use, reproduction, or distribution of Your modifications, or
127 | for any such Derivative Works as a whole, provided Your use,
128 | reproduction, and distribution of the Work otherwise complies with
129 | the conditions stated in this License.
130 |
131 | 5. Submission of Contributions. Unless You explicitly state otherwise,
132 | any Contribution intentionally submitted for inclusion in the Work
133 | by You to the Licensor shall be under the terms and conditions of
134 | this License, without any additional terms or conditions.
135 | Notwithstanding the above, nothing herein shall supersede or modify
136 | the terms of any separate license agreement you may have executed
137 | with Licensor regarding such Contributions.
138 |
139 | 6. Trademarks. This License does not grant permission to use the trade
140 | names, trademarks, service marks, or product names of the Licensor,
141 | except as required for reasonable and customary use in describing the
142 | origin of the Work and reproducing the content of the NOTICE file.
143 |
144 | 7. Disclaimer of Warranty. Unless required by applicable law or
145 | agreed to in writing, Licensor provides the Work (and each
146 | Contributor provides its Contributions) on an "AS IS" BASIS,
147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148 | implied, including, without limitation, any warranties or conditions
149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150 | PARTICULAR PURPOSE. You are solely responsible for determining the
151 | appropriateness of using or redistributing the Work and assume any
152 | risks associated with Your exercise of permissions under this License.
153 |
154 | 8. Limitation of Liability. In no event and under no legal theory,
155 | whether in tort (including negligence), contract, or otherwise,
156 | unless required by applicable law (such as deliberate and grossly
157 | negligent acts) or agreed to in writing, shall any Contributor be
158 | liable to You for damages, including any direct, indirect, special,
159 | incidental, or consequential damages of any character arising as a
160 | result of this License or out of the use or inability to use the
161 | Work (including but not limited to damages for loss of goodwill,
162 | work stoppage, computer failure or malfunction, or any and all
163 | other commercial damages or losses), even if such Contributor
164 | has been advised of the possibility of such damages.
165 |
166 | 9. Accepting Warranty or Additional Liability. While redistributing
167 | the Work or Derivative Works thereof, You may choose to offer,
168 | and charge a fee for, acceptance of support, warranty, indemnity,
169 | or other liability obligations and/or rights consistent with this
170 | License. However, in accepting such obligations, You may act only
171 | on Your own behalf and on Your sole responsibility, not on behalf
172 | of any other Contributor, and only if You agree to indemnify,
173 | defend, and hold each Contributor harmless for any liability
174 | incurred by, or claims asserted against, such Contributor by reason
175 | of your accepting any such warranty or additional liability.
176 |
177 | END OF TERMS AND CONDITIONS
178 |
179 | APPENDIX: How to apply the Apache License to your work.
180 |
181 | To apply the Apache License to your work, attach the following
182 | boilerplate notice, with the fields enclosed by brackets "[]"
183 | replaced with your own identifying information. (Don't include
184 | the brackets!) The text should be enclosed in the appropriate
185 | comment syntax for the file format. We also recommend that a
186 | file or class name and description of purpose be included on the
187 | same "printed page" as the copyright notice for easier
188 | identification within third-party archives.
189 |
190 | Copyright [yyyy] [name of copyright owner]
191 |
192 | Licensed under the Apache License, Version 2.0 (the "License");
193 | you may not use this file except in compliance with the License.
194 | You may obtain a copy of the License at
195 |
196 | http://www.apache.org/licenses/LICENSE-2.0
197 |
198 | Unless required by applicable law or agreed to in writing, software
199 | distributed under the License is distributed on an "AS IS" BASIS,
200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201 | See the License for the specific language governing permissions and
202 | limitations under the License.
203 |
--------------------------------------------------------------------------------
/NOTICE.txt:
--------------------------------------------------------------------------------
1 | =============================================================================
2 | = NOTICE file corresponding to section 4d of the Apache License Version 2.0 =
3 | =============================================================================
4 | This product includes software developed by
5 | Joda.org (http://www.joda.org/).
6 |
--------------------------------------------------------------------------------
/README.txt:
--------------------------------------------------------------------------------
1 |
2 | Joda-Time Contributions area - Hibernate support
3 | ================================================
4 | Joda-Time is a date and time library that vastly improves on the JDK.
5 | This separate project provides Hibernate database persistence support.
6 |
7 | See the home page for more details:
8 | http://www.joda.org/joda-time-hibernate/
9 |
10 | The source code is held primarily at GitHub:
11 | https://github.com/JodaOrg/joda-time-hibernate
12 |
13 | Additional setup
14 | ----------------
15 | Joda-Time supports the use of maven for the build process.
16 | Maven tries to download all dependencies from Maven Central.
17 | However, at the time of writing, the Hibernate dependencies are not present.
18 |
19 | Add the JBoss repository to you setup to load the dependencies:
20 | https://repository.jboss.org/nexus/content/groups/public-jboss/
21 |
22 | See http://www.hibernate.org/ for more details on Hibernate.
23 |
--------------------------------------------------------------------------------
/RELEASE-NOTES.txt:
--------------------------------------------------------------------------------
1 |
2 | Joda-Time Contributions area - Hibernate support
3 | ================================================
4 | Joda-Time is a date and time library that vastly improves on the JDK.
5 | This release provides additional support for Hibernate database persistence.
6 | See http://www.hibernate.org/ for more details on Hibernate.
7 |
8 | This library was an initial user contribution by Mario Ivankovits and Gregory Joseph, thank you.
9 | Various other developers have provided additional persistence classes.
10 |
11 | The Joda-Time contributions area hosts additional code that may be of
12 | use when working with the main Joda-Time library.
13 | Each of these contributions is licensed using the Apache License v2.0.
14 | However, Hibernate is LGPL licensed software.
15 | It is your responsibility to use the joda-time-hibernate jar correctly
16 | in your own application according to the terms of the LGPL license.
17 |
18 | Please note that this code is not supported in the same way as the main
19 | Joda-Time code. As such it is possible that methods and classes may come
20 | and go over time without warning - you have been warned!
21 |
22 | See the change notes online:
23 | http://www.joda.org/joda-time-hibernate/changes-report.html
24 |
25 |
26 | --------
27 | Home page: http://www.joda.org/joda-time-hibernate/
28 | GitHub: https://github.com/JodaOrg/joda-time-hibernate
29 |
30 | The Joda team
31 |
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
39 | * "from Foo where :date is between barInterval.start and barInterval.end" 40 | *41 | * 42 | * @author Christopher R. Gardner (chris_gardner76@yahoo.com) 43 | */ 44 | public class PersistentInterval implements CompositeUserType, Serializable { 45 | 46 | private static final String[] PROPERTY_NAMES = new String[] { "start", "end" }; 47 | 48 | private static final Type[] TYPES = new Type[] { StandardBasicTypes.TIMESTAMP, StandardBasicTypes.TIMESTAMP }; 49 | 50 | public Object assemble(Serializable cached, SessionImplementor session, Object owner) throws HibernateException { 51 | return cached; 52 | } 53 | 54 | public Object deepCopy(Object value) throws HibernateException { 55 | return value; 56 | } 57 | 58 | public Serializable disassemble(Object value, SessionImplementor session) throws HibernateException { 59 | return (Serializable) value; 60 | } 61 | 62 | public boolean equals(Object x, Object y) throws HibernateException { 63 | if (x == y) { 64 | return true; 65 | } 66 | if (x == null || y == null) { 67 | return false; 68 | } 69 | return x.equals(y); 70 | } 71 | 72 | public String[] getPropertyNames() { 73 | return PROPERTY_NAMES; 74 | } 75 | 76 | public Type[] getPropertyTypes() { 77 | return TYPES; 78 | } 79 | 80 | public Object getPropertyValue(Object component, int property) throws HibernateException { 81 | Interval interval = (Interval) component; 82 | return (property == 0) ? interval.getStart().toDate() : interval.getEnd().toDate(); 83 | } 84 | 85 | public int hashCode(Object x) throws HibernateException { 86 | return x.hashCode(); 87 | } 88 | 89 | public boolean isMutable() { 90 | return false; 91 | } 92 | 93 | public Object nullSafeGet(ResultSet resultSet, String[] names, SessionImplementor session, Object owner) 94 | throws HibernateException, SQLException { 95 | if (resultSet == null) { 96 | return null; 97 | } 98 | PersistentDateTime pst = new PersistentDateTime(); 99 | DateTime start = (DateTime) pst.nullSafeGet(resultSet, names[0]); 100 | DateTime end = (DateTime) pst.nullSafeGet(resultSet, names[1]); 101 | if (start == null || end == null) { 102 | return null; 103 | } 104 | return new Interval(start, end); 105 | } 106 | 107 | public void nullSafeSet(PreparedStatement statement, Object value, int index, SessionImplementor session) 108 | throws HibernateException, SQLException { 109 | if (value == null) { 110 | statement.setNull(index, StandardBasicTypes.TIMESTAMP.sqlType()); 111 | statement.setNull(index + 1, StandardBasicTypes.TIMESTAMP.sqlType()); 112 | return; 113 | } 114 | Interval interval = (Interval) value; 115 | statement.setTimestamp(index, asTimeStamp(interval.getStart())); 116 | statement.setTimestamp(index + 1, asTimeStamp(interval.getEnd())); 117 | } 118 | 119 | private Timestamp asTimeStamp(DateTime time) { 120 | return new Timestamp(time.getMillis()); 121 | } 122 | 123 | public Object replace(Object original, Object target, SessionImplementor session, Object owner) 124 | throws HibernateException { 125 | return original; 126 | } 127 | 128 | public Class returnedClass() { 129 | return Interval.class; 130 | } 131 | 132 | public void setPropertyValue(Object component, int property, Object value) throws HibernateException { 133 | throw new UnsupportedOperationException("Immutable Interval"); 134 | } 135 | 136 | } 137 | -------------------------------------------------------------------------------- /src/main/java/org/joda/time/contrib/hibernate/PersistentLocalDate.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2001-2012 Stephen Colebourne 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.joda.time.contrib.hibernate; 17 | 18 | import java.io.Serializable; 19 | import java.sql.PreparedStatement; 20 | import java.sql.ResultSet; 21 | import java.sql.SQLException; 22 | import java.sql.Types; 23 | import java.util.Calendar; 24 | import java.util.Date; 25 | 26 | import org.hibernate.HibernateException; 27 | import org.hibernate.type.StandardBasicTypes; 28 | import org.hibernate.usertype.EnhancedUserType; 29 | import org.joda.time.LocalDate; 30 | 31 | /** 32 | * Persist {@link org.joda.time.LocalDate} via hibernate. 33 | * 34 | * @author Mario Ivankovits (mario@ops.co.at) 35 | */ 36 | public class PersistentLocalDate implements EnhancedUserType, Serializable { 37 | 38 | public static final PersistentLocalDate INSTANCE = new PersistentLocalDate(); 39 | 40 | private static final int[] SQL_TYPES = new int[] { Types.DATE, }; 41 | 42 | public int[] sqlTypes() { 43 | return SQL_TYPES; 44 | } 45 | 46 | public Class returnedClass() { 47 | return LocalDate.class; 48 | } 49 | 50 | public boolean equals(Object x, Object y) throws HibernateException { 51 | if (x == y) { 52 | return true; 53 | } 54 | if (x == null || y == null) { 55 | return false; 56 | } 57 | LocalDate dtx = (LocalDate) x; 58 | LocalDate dty = (LocalDate) y; 59 | return dtx.equals(dty); 60 | } 61 | 62 | public int hashCode(Object object) throws HibernateException { 63 | return object.hashCode(); 64 | } 65 | 66 | public Object nullSafeGet(ResultSet resultSet, String[] strings, Object object) throws HibernateException, SQLException { 67 | return nullSafeGet(resultSet, strings[0]); 68 | 69 | } 70 | 71 | public Object nullSafeGet(ResultSet resultSet, String string) throws SQLException { 72 | Object timestamp = StandardBasicTypes.DATE.nullSafeGet(resultSet, string); 73 | if (timestamp == null) { 74 | return null; 75 | } 76 | if (timestamp instanceof Date) { 77 | return LocalDate.fromDateFields((Date) timestamp); 78 | } else if (timestamp instanceof Calendar) { 79 | return LocalDate.fromCalendarFields((Calendar) timestamp); 80 | } 81 | return new LocalDate(timestamp); 82 | } 83 | 84 | public void nullSafeSet(PreparedStatement preparedStatement, Object value, int index) throws HibernateException, SQLException { 85 | if (value == null) { 86 | StandardBasicTypes.DATE.nullSafeSet(preparedStatement, null, index); 87 | } else { 88 | StandardBasicTypes.DATE.nullSafeSet(preparedStatement, ((LocalDate) value).toDate(), index); 89 | } 90 | } 91 | 92 | public Object deepCopy(Object value) throws HibernateException { 93 | return value; 94 | } 95 | 96 | public boolean isMutable() { 97 | return false; 98 | } 99 | 100 | public Serializable disassemble(Object value) throws HibernateException { 101 | return (Serializable) value; 102 | } 103 | 104 | public Object assemble(Serializable cached, Object value) throws HibernateException { 105 | return cached; 106 | } 107 | 108 | public Object replace(Object original, Object target, Object owner) throws HibernateException { 109 | return original; 110 | } 111 | 112 | public String objectToSQLString(Object object) { 113 | throw new UnsupportedOperationException(); 114 | } 115 | 116 | public String toXMLString(Object object) { 117 | return object.toString(); 118 | } 119 | 120 | public Object fromXMLString(String string) { 121 | return new LocalDate(string); 122 | } 123 | 124 | } 125 | -------------------------------------------------------------------------------- /src/main/java/org/joda/time/contrib/hibernate/PersistentLocalDateTime.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2001-2012 Stephen Colebourne 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.joda.time.contrib.hibernate; 17 | 18 | import java.io.Serializable; 19 | import java.sql.PreparedStatement; 20 | import java.sql.ResultSet; 21 | import java.sql.SQLException; 22 | import java.sql.Types; 23 | import java.util.Calendar; 24 | import java.util.Date; 25 | 26 | import org.hibernate.HibernateException; 27 | import org.hibernate.type.StandardBasicTypes; 28 | import org.hibernate.usertype.EnhancedUserType; 29 | import org.joda.time.LocalDate; 30 | import org.joda.time.LocalDateTime; 31 | 32 | /** 33 | * Persist {@link org.joda.time.LocalDateTime} via hibernate. 34 | * 35 | * @author Mario Ivankovits (mario@ops.co.at) 36 | */ 37 | public class PersistentLocalDateTime implements EnhancedUserType, Serializable { 38 | 39 | public static final PersistentLocalDateTime INSTANCE = new PersistentLocalDateTime(); 40 | 41 | private static final int[] SQL_TYPES = new int[] { Types.TIMESTAMP, }; 42 | 43 | public int[] sqlTypes() { 44 | return SQL_TYPES; 45 | } 46 | 47 | public Class returnedClass() { 48 | return LocalDateTime.class; 49 | } 50 | 51 | public boolean equals(Object x, Object y) throws HibernateException { 52 | if (x == y) { 53 | return true; 54 | } 55 | if (x == null || y == null) { 56 | return false; 57 | } 58 | LocalDateTime dtx = (LocalDateTime) x; 59 | LocalDateTime dty = (LocalDateTime) y; 60 | return dtx.equals(dty); 61 | } 62 | 63 | public int hashCode(Object object) throws HibernateException { 64 | return object.hashCode(); 65 | } 66 | 67 | public Object nullSafeGet(ResultSet resultSet, String[] strings, Object object) throws HibernateException, SQLException { 68 | return nullSafeGet(resultSet, strings[0]); 69 | } 70 | 71 | public Object nullSafeGet(ResultSet resultSet, String string) throws SQLException { 72 | Object timestamp = StandardBasicTypes.TIMESTAMP.nullSafeGet(resultSet, string); 73 | if (timestamp == null) { 74 | return null; 75 | } 76 | if (timestamp instanceof Date) { 77 | return LocalDateTime.fromDateFields((Date) timestamp); 78 | } else if (timestamp instanceof Calendar) { 79 | return LocalDateTime.fromCalendarFields((Calendar) timestamp); 80 | } 81 | return new LocalDateTime(timestamp); 82 | } 83 | 84 | public void nullSafeSet(PreparedStatement preparedStatement, Object value, int index) throws HibernateException, SQLException { 85 | if (value == null) { 86 | StandardBasicTypes.TIMESTAMP.nullSafeSet(preparedStatement, null, index); 87 | } else { 88 | StandardBasicTypes.TIMESTAMP.nullSafeSet(preparedStatement, ((LocalDateTime) value).toDate(), index); 89 | } 90 | } 91 | 92 | public Object deepCopy(Object value) throws HibernateException { 93 | return value; 94 | } 95 | 96 | public boolean isMutable() { 97 | return false; 98 | } 99 | 100 | public Serializable disassemble(Object value) throws HibernateException { 101 | return (Serializable) value; 102 | } 103 | 104 | public Object assemble(Serializable cached, Object value) throws HibernateException { 105 | return cached; 106 | } 107 | 108 | public Object replace(Object original, Object target, Object owner) throws HibernateException { 109 | return original; 110 | } 111 | 112 | public String objectToSQLString(Object object) { 113 | throw new UnsupportedOperationException(); 114 | } 115 | 116 | public String toXMLString(Object object) { 117 | return object.toString(); 118 | } 119 | 120 | public Object fromXMLString(String string) { 121 | return new LocalDateTime(string); 122 | } 123 | 124 | } 125 | -------------------------------------------------------------------------------- /src/main/java/org/joda/time/contrib/hibernate/PersistentLocalTimeAsString.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2001-2012 Stephen Colebourne 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.joda.time.contrib.hibernate; 17 | 18 | import java.io.Serializable; 19 | import java.sql.PreparedStatement; 20 | import java.sql.ResultSet; 21 | import java.sql.SQLException; 22 | import java.sql.Types; 23 | 24 | import org.hibernate.HibernateException; 25 | import org.hibernate.type.StandardBasicTypes; 26 | import org.hibernate.usertype.EnhancedUserType; 27 | import org.joda.time.LocalTime; 28 | 29 | /** 30 | * Persist {@link org.joda.time.LocalDate} via hibernate. 31 | * 32 | * @author Mario Ivankovits (mario@ops.co.at) 33 | */ 34 | public class PersistentLocalTimeAsString implements EnhancedUserType, Serializable { 35 | 36 | public static final PersistentLocalTimeAsString INSTANCE = new PersistentLocalTimeAsString(); 37 | 38 | private static final int[] SQL_TYPES = new int[] { Types.VARCHAR, }; 39 | 40 | public int[] sqlTypes() { 41 | return SQL_TYPES; 42 | } 43 | 44 | public Class returnedClass() { 45 | return LocalTime.class; 46 | } 47 | 48 | public boolean equals(Object x, Object y) throws HibernateException { 49 | if (x == y) { 50 | return true; 51 | } 52 | if (x == null || y == null) { 53 | return false; 54 | } 55 | LocalTime dtx = (LocalTime) x; 56 | LocalTime dty = (LocalTime) y; 57 | return dtx.equals(dty); 58 | } 59 | 60 | public int hashCode(Object object) throws HibernateException { 61 | return object.hashCode(); 62 | } 63 | 64 | public Object nullSafeGet(ResultSet resultSet, String[] strings, Object object) throws HibernateException, SQLException { 65 | return nullSafeGet(resultSet, strings[0]); 66 | 67 | } 68 | 69 | public Object nullSafeGet(ResultSet resultSet, String string) throws SQLException { 70 | Object timestamp = StandardBasicTypes.STRING.nullSafeGet(resultSet, string); 71 | if (timestamp == null) { 72 | return null; 73 | } 74 | 75 | return new LocalTime(timestamp.toString()); 76 | } 77 | 78 | public void nullSafeSet(PreparedStatement preparedStatement, Object value, int index) throws HibernateException, SQLException { 79 | if (value == null) { 80 | StandardBasicTypes.STRING.nullSafeSet(preparedStatement, null, index); 81 | } else { 82 | LocalTime lt = ((LocalTime) value); 83 | StandardBasicTypes.STRING.nullSafeSet(preparedStatement, lt.toString(), index); 84 | } 85 | } 86 | 87 | public Object deepCopy(Object value) throws HibernateException { 88 | return value; 89 | } 90 | 91 | public boolean isMutable() { 92 | return false; 93 | } 94 | 95 | public Serializable disassemble(Object value) throws HibernateException { 96 | return (Serializable) value; 97 | } 98 | 99 | public Object assemble(Serializable cached, Object value) throws HibernateException { 100 | return cached; 101 | } 102 | 103 | public Object replace(Object original, Object target, Object owner) throws HibernateException { 104 | return original; 105 | } 106 | 107 | public String objectToSQLString(Object object) { 108 | throw new UnsupportedOperationException(); 109 | } 110 | 111 | public String toXMLString(Object object) { 112 | return object.toString(); 113 | } 114 | 115 | public Object fromXMLString(String string) { 116 | return new LocalTime(string); 117 | } 118 | 119 | } 120 | -------------------------------------------------------------------------------- /src/main/java/org/joda/time/contrib/hibernate/PersistentLocalTimeAsTime.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2001-2012 Stephen Colebourne 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.joda.time.contrib.hibernate; 17 | 18 | import java.io.Serializable; 19 | import java.sql.PreparedStatement; 20 | import java.sql.ResultSet; 21 | import java.sql.SQLException; 22 | import java.sql.Time; 23 | import java.sql.Types; 24 | 25 | import org.hibernate.HibernateException; 26 | import org.hibernate.type.StandardBasicTypes; 27 | import org.hibernate.usertype.EnhancedUserType; 28 | import org.joda.time.DateTimeZone; 29 | import org.joda.time.LocalTime; 30 | 31 | /** 32 | * Persist {@link org.joda.time.LocalDate} via hibernate. 33 | * This uses a simple integer to store the time as milliseconds since 1970-1-1. 34 | * The milliseconds will survive. 35 | * 36 | * @author Mario Ivankovits (mario@ops.co.at) 37 | */ 38 | public class PersistentLocalTimeAsTime implements EnhancedUserType, Serializable { 39 | 40 | public static final PersistentLocalTimeAsTime INSTANCE = new PersistentLocalTimeAsTime(); 41 | 42 | private static final int[] SQL_TYPES = new int[] { Types.TIME, }; 43 | 44 | public int[] sqlTypes() { 45 | return SQL_TYPES; 46 | } 47 | 48 | public Class returnedClass() { 49 | return LocalTime.class; 50 | } 51 | 52 | public boolean equals(Object x, Object y) throws HibernateException { 53 | if (x == y) { 54 | return true; 55 | } 56 | if (x == null || y == null) { 57 | return false; 58 | } 59 | LocalTime dtx = (LocalTime) x; 60 | LocalTime dty = (LocalTime) y; 61 | return dtx.equals(dty); 62 | } 63 | 64 | public int hashCode(Object object) throws HibernateException { 65 | return object.hashCode(); 66 | } 67 | 68 | public Object nullSafeGet(ResultSet resultSet, String[] strings, Object object) throws HibernateException, SQLException { 69 | return nullSafeGet(resultSet, strings[0]); 70 | 71 | } 72 | 73 | public Object nullSafeGet(ResultSet resultSet, String string) throws SQLException { 74 | Object timestamp = StandardBasicTypes.TIME.nullSafeGet(resultSet, string); 75 | if (timestamp == null) { 76 | return null; 77 | } 78 | 79 | return new LocalTime(timestamp, DateTimeZone.UTC); 80 | } 81 | 82 | public void nullSafeSet(PreparedStatement preparedStatement, Object value, int index) throws HibernateException, SQLException { 83 | if (value == null) { 84 | StandardBasicTypes.TIME.nullSafeSet(preparedStatement, null, index); 85 | } else { 86 | LocalTime lt = ((LocalTime) value); 87 | Time time = new Time(lt.getMillisOfDay()); 88 | StandardBasicTypes.TIME.nullSafeSet(preparedStatement, time, index); 89 | } 90 | } 91 | 92 | public Object deepCopy(Object value) throws HibernateException { 93 | return value; 94 | } 95 | 96 | public boolean isMutable() { 97 | return false; 98 | } 99 | 100 | public Serializable disassemble(Object value) throws HibernateException { 101 | return (Serializable) value; 102 | } 103 | 104 | public Object assemble(Serializable cached, Object value) throws HibernateException { 105 | return cached; 106 | } 107 | 108 | public Object replace(Object original, Object target, Object owner) throws HibernateException { 109 | return original; 110 | } 111 | 112 | public String objectToSQLString(Object object) { 113 | throw new UnsupportedOperationException(); 114 | } 115 | 116 | public String toXMLString(Object object) { 117 | return object.toString(); 118 | } 119 | 120 | public Object fromXMLString(String string) { 121 | return new LocalTime(string); 122 | } 123 | 124 | } 125 | -------------------------------------------------------------------------------- /src/main/java/org/joda/time/contrib/hibernate/PersistentLocalTimeAsTimestamp.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2001-2012 Stephen Colebourne 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.joda.time.contrib.hibernate; 17 | 18 | import java.io.Serializable; 19 | import java.sql.PreparedStatement; 20 | import java.sql.ResultSet; 21 | import java.sql.SQLException; 22 | import java.sql.Timestamp; 23 | import java.sql.Types; 24 | 25 | import org.hibernate.HibernateException; 26 | import org.hibernate.type.StandardBasicTypes; 27 | import org.hibernate.usertype.EnhancedUserType; 28 | import org.joda.time.DateTimeZone; 29 | import org.joda.time.LocalTime; 30 | 31 | /** 32 | * Persist {@link org.joda.time.LocalDate} via hibernate. This uses a standard 33 | * Timestamp (DateTime) field to store the partial. 34 | * 35 | * @author Daniel Jurado (jurado@gmail.com) 36 | */ 37 | public class PersistentLocalTimeAsTimestamp implements EnhancedUserType, Serializable { 38 | 39 | public static final PersistentLocalTimeAsTimestamp INSTANCE = new PersistentLocalTimeAsTimestamp(); 40 | 41 | private static final int[] SQL_TYPES = new int[] { Types.TIMESTAMP, }; 42 | 43 | public Object assemble(Serializable cached, Object value) throws HibernateException { 44 | return cached; 45 | } 46 | 47 | public Object deepCopy(Object value) throws HibernateException { 48 | return value; 49 | } 50 | 51 | public Serializable disassemble(Object value) throws HibernateException { 52 | return (Serializable) value; 53 | } 54 | 55 | public boolean equals(Object x, Object y) throws HibernateException { 56 | if (x == y) { 57 | return true; 58 | } 59 | if (x == null || y == null) { 60 | return false; 61 | } 62 | LocalTime dtx = (LocalTime) x; 63 | LocalTime dty = (LocalTime) y; 64 | return dtx.equals(dty); 65 | } 66 | 67 | public Object fromXMLString(String string) { 68 | return new LocalTime(string); 69 | } 70 | 71 | public int hashCode(Object object) throws HibernateException { 72 | return object.hashCode(); 73 | } 74 | 75 | public boolean isMutable() { 76 | return false; 77 | } 78 | 79 | public Object nullSafeGet(ResultSet resultSet, String string) throws SQLException { 80 | Object timestamp = StandardBasicTypes.TIMESTAMP.nullSafeGet(resultSet, string); 81 | if (timestamp == null) { 82 | return null; 83 | } 84 | 85 | return new LocalTime(timestamp, DateTimeZone.UTC); 86 | } 87 | 88 | public Object nullSafeGet(ResultSet resultSet, String[] strings, Object object) throws HibernateException, SQLException { 89 | return nullSafeGet(resultSet, strings[0]); 90 | 91 | } 92 | 93 | public void nullSafeSet(PreparedStatement preparedStatement, Object value, int index) throws HibernateException, SQLException { 94 | if (value == null) { 95 | StandardBasicTypes.TIMESTAMP.nullSafeSet(preparedStatement, null, 96 | index); 97 | } else { 98 | LocalTime lt = ((LocalTime) value); 99 | Timestamp timestamp = new Timestamp(lt.getMillisOfDay()); 100 | StandardBasicTypes.TIMESTAMP.nullSafeSet(preparedStatement, 101 | timestamp, index); 102 | } 103 | } 104 | 105 | public String objectToSQLString(Object object) { 106 | throw new UnsupportedOperationException(); 107 | } 108 | 109 | public Object replace(Object original, Object target, Object owner) throws HibernateException { 110 | return original; 111 | } 112 | 113 | public Class> returnedClass() { 114 | return LocalTime.class; 115 | } 116 | 117 | public int[] sqlTypes() { 118 | return SQL_TYPES; 119 | } 120 | 121 | public String toXMLString(Object object) { 122 | return object.toString(); 123 | } 124 | } 125 | -------------------------------------------------------------------------------- /src/main/java/org/joda/time/contrib/hibernate/PersistentLocalTimeExact.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2001-2012 Stephen Colebourne 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.joda.time.contrib.hibernate; 17 | 18 | import java.io.Serializable; 19 | import java.sql.PreparedStatement; 20 | import java.sql.ResultSet; 21 | import java.sql.SQLException; 22 | import java.sql.Types; 23 | 24 | import org.hibernate.HibernateException; 25 | import org.hibernate.type.StandardBasicTypes; 26 | import org.hibernate.usertype.EnhancedUserType; 27 | import org.joda.time.LocalTime; 28 | 29 | /** 30 | * Persist {@link org.joda.time.LocalDate} via hibernate. 31 | * 32 | * @author Mario Ivankovits (mario@ops.co.at) 33 | */ 34 | public class PersistentLocalTimeExact implements EnhancedUserType, Serializable { 35 | 36 | public static final PersistentLocalTimeExact INSTANCE = new PersistentLocalTimeExact(); 37 | 38 | private static final int[] SQL_TYPES = new int[] { Types.INTEGER, }; 39 | 40 | public int[] sqlTypes() { 41 | return SQL_TYPES; 42 | } 43 | 44 | public Class returnedClass() { 45 | return LocalTime.class; 46 | } 47 | 48 | public boolean equals(Object x, Object y) throws HibernateException { 49 | if (x == y) { 50 | return true; 51 | } 52 | if (x == null || y == null) { 53 | return false; 54 | } 55 | LocalTime dtx = (LocalTime) x; 56 | LocalTime dty = (LocalTime) y; 57 | return dtx.equals(dty); 58 | } 59 | 60 | public int hashCode(Object object) throws HibernateException { 61 | return object.hashCode(); 62 | } 63 | 64 | public Object nullSafeGet(ResultSet resultSet, String[] strings, Object object) throws HibernateException, SQLException { 65 | return nullSafeGet(resultSet, strings[0]); 66 | 67 | } 68 | 69 | public Object nullSafeGet(ResultSet resultSet, String string) throws SQLException { 70 | Object timestamp = StandardBasicTypes.INTEGER.nullSafeGet(resultSet, string); 71 | if (timestamp == null) { 72 | return null; 73 | } 74 | 75 | return LocalTime.fromMillisOfDay(((Number) timestamp).intValue()); 76 | } 77 | 78 | public void nullSafeSet(PreparedStatement preparedStatement, Object value, int index) throws HibernateException, SQLException { 79 | if (value == null) { 80 | StandardBasicTypes.INTEGER.nullSafeSet(preparedStatement, null, index); 81 | } else { 82 | LocalTime lt = ((LocalTime) value); 83 | StandardBasicTypes.INTEGER.nullSafeSet(preparedStatement, new Integer(lt.getMillisOfDay()), index); 84 | } 85 | } 86 | 87 | public Object deepCopy(Object value) throws HibernateException { 88 | return value; 89 | } 90 | 91 | public boolean isMutable() { 92 | return false; 93 | } 94 | 95 | public Serializable disassemble(Object value) throws HibernateException { 96 | return (Serializable) value; 97 | } 98 | 99 | public Object assemble(Serializable cached, Object value) throws HibernateException { 100 | return cached; 101 | } 102 | 103 | public Object replace(Object original, Object target, Object owner) throws HibernateException { 104 | return original; 105 | } 106 | 107 | public String objectToSQLString(Object object) { 108 | throw new UnsupportedOperationException(); 109 | } 110 | 111 | public String toXMLString(Object object) { 112 | return object.toString(); 113 | } 114 | 115 | public Object fromXMLString(String string) { 116 | return new LocalTime(string); 117 | } 118 | 119 | } 120 | -------------------------------------------------------------------------------- /src/main/java/org/joda/time/contrib/hibernate/PersistentPeriod.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2001-2012 Stephen Colebourne 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.joda.time.contrib.hibernate; 17 | 18 | import org.joda.time.Period; 19 | 20 | /** 21 | * Converts a org.joda.time.Period to and from Sql for Hibernate. 22 | * It simply stores and retrieves the value as a varchar using Period.toString. 23 | * 24 | * @author gjoseph 25 | */ 26 | public class PersistentPeriod extends AbstractStringBasedJodaType { 27 | 28 | public Class returnedClass() { 29 | return Period.class; 30 | } 31 | 32 | protected Object fromNonNullString(String s) { 33 | return new Period(s); 34 | } 35 | 36 | protected String toNonNullString(Object value) { 37 | return value.toString(); 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/org/joda/time/contrib/hibernate/PersistentTimeOfDay.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2001-2012 Stephen Colebourne 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.joda.time.contrib.hibernate; 17 | 18 | import java.io.Serializable; 19 | import java.sql.PreparedStatement; 20 | import java.sql.ResultSet; 21 | import java.sql.SQLException; 22 | import java.sql.Time; 23 | import java.sql.Types; 24 | 25 | import org.hibernate.HibernateException; 26 | import org.hibernate.type.StandardBasicTypes; 27 | import org.hibernate.usertype.EnhancedUserType; 28 | import org.joda.time.DateTime; 29 | import org.joda.time.TimeOfDay; 30 | 31 | /** 32 | * Persist {@link org.joda.time.TimeOfDay} via hibernate. 33 | * This uses java.sql.Time and the time datatype of your database. 34 | * Notice: You might loose the milliseconds part. 35 | * 36 | * @author Mario Ivankovits (mario@ops.co.at) 37 | */ 38 | public class PersistentTimeOfDay implements EnhancedUserType, Serializable { 39 | 40 | private final DateTime timeBase = new DateTime(1970, 1, 1, 0, 0, 0, 0); 41 | 42 | public static final PersistentTimeOfDay INSTANCE = new PersistentTimeOfDay(); 43 | 44 | private static final int[] SQL_TYPES = new int[] { Types.TIME, }; 45 | 46 | public int[] sqlTypes() { 47 | return SQL_TYPES; 48 | } 49 | 50 | public Class returnedClass() { 51 | return TimeOfDay.class; 52 | } 53 | 54 | public boolean equals(Object x, Object y) throws HibernateException { 55 | if (x == y) { 56 | return true; 57 | } 58 | if (x == null || y == null) { 59 | return false; 60 | } 61 | TimeOfDay dtx = (TimeOfDay) x; 62 | TimeOfDay dty = (TimeOfDay) y; 63 | return dtx.equals(dty); 64 | } 65 | 66 | public int hashCode(Object object) throws HibernateException { 67 | return object.hashCode(); 68 | } 69 | 70 | public Object nullSafeGet(ResultSet resultSet, String[] strings, Object object) throws HibernateException, SQLException { 71 | return nullSafeGet(resultSet, strings[0]); 72 | 73 | } 74 | 75 | public Object nullSafeGet(ResultSet resultSet, String string) throws SQLException { 76 | Object date = StandardBasicTypes.TIME.nullSafeGet(resultSet, string); 77 | if (date == null) { 78 | return null; 79 | } 80 | 81 | return new TimeOfDay(date); 82 | } 83 | 84 | public void nullSafeSet(PreparedStatement preparedStatement, Object value, int index) throws HibernateException, SQLException { 85 | if (value == null) { 86 | StandardBasicTypes.TIME.nullSafeSet(preparedStatement, null, index); 87 | } else { 88 | StandardBasicTypes.TIME.nullSafeSet(preparedStatement, 89 | new Time(((TimeOfDay) value).toDateTime(timeBase).getMillis()), index); 90 | } 91 | } 92 | 93 | public Object deepCopy(Object value) throws HibernateException { 94 | return value; 95 | } 96 | 97 | public boolean isMutable() { 98 | return false; 99 | } 100 | 101 | public Serializable disassemble(Object value) throws HibernateException { 102 | return (Serializable) value; 103 | } 104 | 105 | public Object assemble(Serializable cached, Object value) throws HibernateException { 106 | return cached; 107 | } 108 | 109 | public Object replace(Object original, Object target, Object owner) throws HibernateException { 110 | return original; 111 | } 112 | 113 | public String objectToSQLString(Object object) { 114 | throw new UnsupportedOperationException(); 115 | } 116 | 117 | public String toXMLString(Object object) { 118 | return object.toString(); 119 | } 120 | 121 | public Object fromXMLString(String string) { 122 | return new TimeOfDay(string); 123 | } 124 | 125 | } 126 | -------------------------------------------------------------------------------- /src/main/java/org/joda/time/contrib/hibernate/PersistentTimeOfDayExact.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2001-2012 Stephen Colebourne 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.joda.time.contrib.hibernate; 17 | 18 | import java.io.Serializable; 19 | import java.sql.PreparedStatement; 20 | import java.sql.ResultSet; 21 | import java.sql.SQLException; 22 | import java.sql.Types; 23 | 24 | import org.hibernate.HibernateException; 25 | import org.hibernate.usertype.EnhancedUserType; 26 | import org.joda.time.DateTime; 27 | import org.joda.time.TimeOfDay; 28 | 29 | /** 30 | * Persist {@link org.joda.time.TimeOfDay} via hibernate. 31 | * This uses a simple integer to store the time as milliseconds since 1970-1-1. 32 | * The milliseconds will survive. 33 | * 34 | * @author Mario Ivankovits (mario@ops.co.at) 35 | */ 36 | public class PersistentTimeOfDayExact implements EnhancedUserType, Serializable { 37 | 38 | private final DateTime timeBase = new DateTime(1970, 1, 1, 0, 0, 0, 0); 39 | 40 | public static final PersistentTimeOfDayExact INSTANCE = new PersistentTimeOfDayExact(); 41 | 42 | private static final int[] SQL_TYPES = new int[] { Types.INTEGER, }; 43 | 44 | public int[] sqlTypes() { 45 | return SQL_TYPES; 46 | } 47 | 48 | public Class returnedClass() { 49 | return TimeOfDay.class; 50 | } 51 | 52 | public boolean equals(Object x, Object y) throws HibernateException { 53 | if (x == y) { 54 | return true; 55 | } 56 | if (x == null || y == null) { 57 | return false; 58 | } 59 | TimeOfDay dtx = (TimeOfDay) x; 60 | TimeOfDay dty = (TimeOfDay) y; 61 | 62 | return dtx.equals(dty); 63 | } 64 | 65 | public int hashCode(Object object) throws HibernateException { 66 | return object.hashCode(); 67 | } 68 | 69 | public Object nullSafeGet(ResultSet resultSet, String[] strings, Object object) throws HibernateException, SQLException { 70 | return nullSafeGet(resultSet, strings[0]); 71 | 72 | } 73 | 74 | public Object nullSafeGet(ResultSet resultSet, String string) throws SQLException { 75 | int value = resultSet.getInt(string); 76 | if (resultSet.wasNull()) { 77 | return null; 78 | } 79 | return new TimeOfDay(value); 80 | } 81 | 82 | public void nullSafeSet(PreparedStatement preparedStatement, Object value, int index) throws HibernateException, SQLException { 83 | if (value == null) { 84 | preparedStatement.setNull(index, SQL_TYPES[0]); 85 | } else { 86 | preparedStatement.setInt(index, (int) ((TimeOfDay) value).toDateTime(timeBase).getMillis()); 87 | } 88 | } 89 | 90 | public Object deepCopy(Object value) throws HibernateException { 91 | return value; 92 | } 93 | 94 | public boolean isMutable() { 95 | return false; 96 | } 97 | 98 | public Serializable disassemble(Object value) throws HibernateException { 99 | return (Serializable) value; 100 | } 101 | 102 | public Object assemble(Serializable cached, Object value) throws HibernateException { 103 | return cached; 104 | } 105 | 106 | public Object replace(Object original, Object target, Object owner) throws HibernateException { 107 | return original; 108 | } 109 | 110 | public String objectToSQLString(Object object) { 111 | throw new UnsupportedOperationException(); 112 | } 113 | 114 | public String toXMLString(Object object) { 115 | return object.toString(); 116 | } 117 | 118 | public Object fromXMLString(String string) { 119 | return new TimeOfDay(string); 120 | } 121 | 122 | } 123 | -------------------------------------------------------------------------------- /src/main/java/org/joda/time/contrib/hibernate/PersistentYearMonthDay.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2001-2012 Stephen Colebourne 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.joda.time.contrib.hibernate; 17 | 18 | import java.io.Serializable; 19 | import java.sql.PreparedStatement; 20 | import java.sql.ResultSet; 21 | import java.sql.SQLException; 22 | import java.sql.Types; 23 | 24 | import org.hibernate.HibernateException; 25 | import org.hibernate.type.StandardBasicTypes; 26 | import org.hibernate.usertype.EnhancedUserType; 27 | import org.joda.time.YearMonthDay; 28 | 29 | /** 30 | * Persist {@link org.joda.time.YearMonthDay} via hibernate. 31 | * 32 | * @author Mario Ivankovits (mario@ops.co.at) 33 | */ 34 | public class PersistentYearMonthDay implements EnhancedUserType, Serializable { 35 | 36 | public static final PersistentYearMonthDay INSTANCE = new PersistentYearMonthDay(); 37 | 38 | private static final int[] SQL_TYPES = new int[] { Types.DATE, }; 39 | 40 | public int[] sqlTypes() { 41 | return SQL_TYPES; 42 | } 43 | 44 | public Class returnedClass() { 45 | return YearMonthDay.class; 46 | } 47 | 48 | public boolean equals(Object x, Object y) throws HibernateException { 49 | if (x == y) { 50 | return true; 51 | } 52 | if (x == null || y == null) { 53 | return false; 54 | } 55 | YearMonthDay dtx = (YearMonthDay) x; 56 | YearMonthDay dty = (YearMonthDay) y; 57 | return dtx.equals(dty); 58 | } 59 | 60 | public int hashCode(Object object) throws HibernateException { 61 | return object.hashCode(); 62 | } 63 | 64 | public Object nullSafeGet(ResultSet resultSet, String[] strings, Object object) throws HibernateException, SQLException { 65 | return nullSafeGet(resultSet, strings[0]); 66 | 67 | } 68 | 69 | public Object nullSafeGet(ResultSet resultSet, String string) throws SQLException { 70 | Object date = StandardBasicTypes.DATE.nullSafeGet(resultSet, string); 71 | if (date == null) { 72 | return null; 73 | } 74 | return new YearMonthDay(date); 75 | } 76 | 77 | public void nullSafeSet(PreparedStatement preparedStatement, Object value, int index) throws HibernateException, SQLException { 78 | if (value == null) { 79 | StandardBasicTypes.DATE.nullSafeSet(preparedStatement, null, index); 80 | } else { 81 | StandardBasicTypes.DATE.nullSafeSet(preparedStatement, ((YearMonthDay) value).toDateMidnight().toDate(), index); 82 | } 83 | } 84 | 85 | public Object deepCopy(Object value) throws HibernateException { 86 | return value; 87 | } 88 | 89 | public boolean isMutable() { 90 | return false; 91 | } 92 | 93 | public Serializable disassemble(Object value) throws HibernateException { 94 | return (Serializable) value; 95 | } 96 | 97 | public Object assemble(Serializable cached, Object value) throws HibernateException { 98 | return cached; 99 | } 100 | 101 | public Object replace(Object original, Object target, Object owner) throws HibernateException { 102 | return original; 103 | } 104 | 105 | public String objectToSQLString(Object object) { 106 | throw new UnsupportedOperationException(); 107 | } 108 | 109 | public String toXMLString(Object object) { 110 | return object.toString(); 111 | } 112 | 113 | public Object fromXMLString(String string) { 114 | return new YearMonthDay(string); 115 | } 116 | 117 | } 118 | -------------------------------------------------------------------------------- /src/site/resources/css/site.css: -------------------------------------------------------------------------------- 1 | body, td, select, input, li{ 2 | font-family: Helvetica, Arial, sans-serif; 3 | font-size: 13px; 4 | background-color: #fff; 5 | } 6 | a { 7 | text-decoration: none; 8 | } 9 | a:link { 10 | color:#009; 11 | } 12 | a:visited { 13 | color:#009; 14 | } 15 | a:active, a:hover { 16 | text-decoration: underline; 17 | } 18 | a.externalLink, a.externalLink:link, a.externalLink:visited, a.externalLink:active, a.externalLink:hover { 19 | background: url(../images/external.png) right center no-repeat; 20 | padding-right: 15px; 21 | } 22 | a.newWindow, a.newWindow:link, a.newWindow:visited, a.newWindow:active, a.newWindow:hover { 23 | background: url(../images/newwindow.png) right center no-repeat; 24 | padding-right: 18px; 25 | } 26 | h2 { 27 | font-family: Verdana, Helvetica, Arial, sans-serif; 28 | padding: 4px 4px 4px 6px; 29 | border: 1px solid #999; 30 | color: #006; 31 | background-color: #eef; 32 | font-weight:bold; 33 | font-size: 16px; 34 | margin-top: 4px; 35 | margin-bottom: 6px; 36 | } 37 | h3 { 38 | padding: 4px 4px 4px 6px; 39 | border: 1px solid #aaa; 40 | color: #006; 41 | background-color: #eee; 42 | font-weight: normal; 43 | font-size: 14px; 44 | margin-top: 4px; 45 | margin-bottom: 6px; 46 | } 47 | p, ul { 48 | font-size: 13px; 49 | margin-top: 4px; 50 | margin-bottom: 6px; 51 | } 52 | #banner { 53 | background-color: #eef; 54 | border-bottom: 1px solid #aaa; 55 | padding: 8px; 56 | } 57 | #bannerLeft, #bannerRight { 58 | font-size: 30px; 59 | color:black; 60 | padding: 0px 5px; 61 | } 62 | #banner a:hover { 63 | text-decoration:none; 64 | } 65 | #breadcrumbs { 66 | padding-top: 1px; 67 | padding-bottom: 2px; 68 | border-bottom: 1px solid #aaa; 69 | background-color: #ddf; 70 | } 71 | #leftColumn { 72 | margin: 8px 0 8px 4px; 73 | border: 1px solid #999; 74 | background-color: #eef; 75 | } 76 | #navcolumn { 77 | padding: 6px 4px 0 6px; 78 | } 79 | #navcolumn h5 { 80 | font-size: 12px; 81 | border-bottom: 1px solid #aaaaaa; 82 | padding-top: 2px; 83 | font-weight: normal; 84 | } 85 | #navcolumn li { 86 | font-size: 12px; 87 | padding-left: 12px; 88 | background-color: #eef; 89 | } 90 | #navcolumn a:active, #navcolumn a:hover { 91 | text-decoration: none; 92 | } 93 | #lastPublished { 94 | font-size: 10px; 95 | } 96 | table.bodyTable th { 97 | color: white; 98 | background-color: #bbb; 99 | text-align: left; 100 | font-weight: bold; 101 | font-size: 13px; 102 | } 103 | 104 | table.bodyTable th, table.bodyTable td { 105 | font-size: 13px; 106 | } 107 | 108 | table.bodyTable tr.a { 109 | background-color: #ddd; 110 | } 111 | 112 | table.bodyTable tr.b { 113 | background-color: #eee; 114 | } 115 | 116 | .source { 117 | border: 1px solid #999; 118 | padding: 8px; 119 | margin: 6px; 120 | } 121 | #footer { 122 | background-color: #eef; 123 | border-top: 1px solid #999; 124 | } 125 | body { 126 | padding-bottom: 0px; 127 | } 128 | -------------------------------------------------------------------------------- /src/site/resources/download.html: -------------------------------------------------------------------------------- 1 | 2 |