├── .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 | 6 | 7 | 4.0.0 8 | joda-time 9 | joda-time-hibernate 10 | jar 11 | Joda-Time-Hibernate 12 | 1.5-SNAPSHOT 13 | Contribution to Joda-Time that adds Hibernate support 14 | http://www.joda.org/joda-time-hibernate/ 15 | 16 | 17 | 18 | GitHub 19 | https://github.com/JodaOrg/joda-time-hibernate/issues 20 | 21 | 2005 22 | 23 | 24 | 25 | 26 | imario 27 | Mario Ivankovits 28 | 29 | 30 | Lead developer 31 | 32 | 33 | 34 | gjoseph 35 | Gregory Joseph 36 | 37 | 38 | Developer 39 | 40 | 41 | 42 | jodastephen 43 | Stephen Colebourne 44 | 45 | Website and Release manager 46 | 47 | 0 48 | https://github.com/jodastephen 49 | 50 | 51 | 52 | 53 | 54 | 55 | Apache License, Version 2.0 56 | http://www.apache.org/licenses/LICENSE-2.0.txt 57 | repo 58 | 59 | 60 | 61 | scm:git:https://github.com/JodaOrg/joda-time-hibernate.git 62 | scm:git:git@github.com:JodaOrg/joda-time-hibernate.git 63 | https://github.com/JodaOrg/joda-time-hibernate 64 | 65 | 66 | Joda.org 67 | http://www.joda.org 68 | 69 | 70 | 71 | 72 | 73 | 74 | META-INF 75 | ${project.basedir} 76 | 77 | LICENSE.txt 78 | NOTICE.txt 79 | 80 | 81 | 82 | 83 | 84 | 85 | org.apache.maven.plugins 86 | maven-jar-plugin 87 | 88 | 89 | src/conf/MANIFEST.MF 90 | 91 | true 92 | true 93 | 94 | 95 | 96 | 97 | 98 | org.apache.maven.plugins 99 | maven-surefire-plugin 100 | 101 | 102 | **/Test* 103 | 104 | 105 | 106 | 107 | org.apache.maven.plugins 108 | maven-javadoc-plugin 109 | 110 | 111 | http://www.joda.org/joda-time/apidocs/ 112 | 113 | 114 | 115 | 116 | attach-javadocs 117 | package 118 | 119 | jar 120 | 121 | 122 | 123 | 124 | 125 | org.apache.maven.plugins 126 | maven-source-plugin 127 | 128 | 129 | attach-sources 130 | package 131 | 132 | jar-no-fork 133 | 134 | 135 | 136 | 137 | 138 | org.apache.maven.plugins 139 | maven-assembly-plugin 140 | 141 | false 142 | 143 | src/main/assembly/dist.xml 144 | 145 | gnu 146 | 147 | 148 | 149 | make-assembly 150 | deploy 151 | 152 | single 153 | 154 | 155 | 156 | 157 | 158 | org.apache.maven.plugins 159 | maven-site-plugin 160 | 161 | true 162 | 163 | 164 | 165 | com.github.github 166 | site-maven-plugin 167 | 0.11 168 | 169 | 170 | github-site 171 | 172 | site 173 | 174 | site-deploy 175 | 176 | 177 | 178 | Create website for ${project.artifactId} v${project.version} 179 | ${project.artifactId} 180 | true 181 | github 182 | JodaOrg 183 | jodaorg.github.io 184 | refs/heads/master 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | org.apache.maven.plugins 194 | maven-assembly-plugin 195 | ${maven-assembly-plugin.version} 196 | 197 | 198 | org.apache.maven.plugins 199 | maven-checkstyle-plugin 200 | ${maven-checkstyle-plugin.version} 201 | 202 | 203 | org.apache.maven.plugins 204 | maven-changes-plugin 205 | ${maven-changes-plugin.version} 206 | 207 | 208 | org.apache.maven.plugins 209 | maven-clean-plugin 210 | ${maven-clean-plugin.version} 211 | 212 | 213 | org.apache.maven.plugins 214 | maven-compiler-plugin 215 | ${maven-compiler-plugin.version} 216 | 217 | 218 | org.apache.maven.plugins 219 | maven-deploy-plugin 220 | ${maven-deploy-plugin.version} 221 | 222 | 223 | org.apache.maven.plugins 224 | maven-dependency-plugin 225 | ${maven-dependency-plugin.version} 226 | 227 | 228 | org.apache.maven.plugins 229 | maven-gpg-plugin 230 | ${maven-gpg-plugin.version} 231 | 232 | 233 | org.apache.maven.plugins 234 | maven-install-plugin 235 | ${maven-install-plugin.version} 236 | 237 | 238 | org.apache.maven.plugins 239 | maven-jar-plugin 240 | ${maven-jar-plugin.version} 241 | 242 | 243 | org.apache.maven.plugins 244 | maven-javadoc-plugin 245 | ${maven-javadoc-plugin.version} 246 | 247 | 248 | org.apache.maven.plugins 249 | maven-jxr-plugin 250 | ${maven-jxr-plugin.version} 251 | 252 | 253 | org.apache.maven.plugins 254 | maven-plugin-plugin 255 | ${maven-plugin-plugin.version} 256 | 257 | 258 | org.apache.maven.plugins 259 | maven-pmd-plugin 260 | ${maven-pmd-plugin.version} 261 | 262 | 263 | org.apache.maven.plugins 264 | maven-project-info-reports-plugin 265 | ${maven-project-info-reports-plugin.version} 266 | 267 | 268 | org.apache.maven.plugins 269 | maven-repository-plugin 270 | ${maven-repository-plugin.version} 271 | 272 | 273 | org.apache.maven.plugins 274 | maven-resources-plugin 275 | ${maven-resources-plugin.version} 276 | 277 | 278 | org.apache.maven.plugins 279 | maven-site-plugin 280 | ${maven-site-plugin.version} 281 | 282 | 283 | org.apache.maven.plugins 284 | maven-source-plugin 285 | ${maven-source-plugin.version} 286 | 287 | 288 | org.apache.maven.plugins 289 | maven-surefire-plugin 290 | ${maven-surefire-plugin.version} 291 | 292 | 293 | org.apache.maven.plugins 294 | maven-surefire-report-plugin 295 | ${maven-surefire-report-plugin.version} 296 | 297 | 298 | org.apache.maven.plugins 299 | maven-toolchains-plugin 300 | ${maven-toolchains-plugin.version} 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 | 3.0.4 309 | 310 | 311 | 312 | joda-time 313 | joda-time 314 | 2.0 315 | provided 316 | 317 | 318 | org.hibernate 319 | hibernate-core 320 | 3.6.0.Final 321 | provided 322 | 323 | 324 | org.hibernate 325 | hibernate-entitymanager 326 | 3.6.0.Final 327 | provided 328 | 329 | 330 | junit 331 | junit 332 | 4.13.1 333 | test 334 | 335 | 336 | hsqldb 337 | hsqldb 338 | 1.7.3.3 339 | test 340 | 341 | 342 | 343 | 344 | 345 | 346 | 347 | org.apache.maven.plugins 348 | maven-project-info-reports-plugin 349 | ${maven-project-info-plugin.version} 350 | 351 | 352 | 353 | dependencies 354 | dependency-info 355 | issue-tracking 356 | license 357 | project-team 358 | scm 359 | summary 360 | 361 | 362 | 363 | 364 | 365 | org.apache.maven.plugins 366 | maven-javadoc-plugin 367 | ${maven-javadoc-plugin.version} 368 | 369 | 370 | 371 | javadoc 372 | 373 | 374 | 375 | 376 | 377 | http://www.joda.org/joda-time/apidocs/ 378 | 379 | 380 | 381 | 382 | org.apache.maven.plugins 383 | maven-surefire-report-plugin 384 | ${maven-surefire-report-plugin.version} 385 | 386 | true 387 | 388 | 389 | 390 | org.apache.maven.plugins 391 | maven-changes-plugin 392 | ${maven-changes-plugin.version} 393 | 394 | 395 | 396 | changes-report 397 | 398 | 399 | 400 | 401 | 402 | org.apache.maven.plugins 403 | maven-jxr-plugin 404 | ${maven-jxr-plugin.version} 405 | 406 | 407 | 408 | jxr 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 419 | sonatype-joda-staging 420 | Sonatype OSS staging repository 421 | https://oss.sonatype.org/service/local/staging/deploy/maven2/ 422 | default 423 | 424 | 425 | false 426 | sonatype-joda-snapshot 427 | Sonatype OSS snapshot repository 428 | https://oss.sonatype.org/content/repositories/joda-snapshots 429 | default 430 | 431 | http://oss.sonatype.org/content/repositories/joda-releases 432 | 433 | 434 | 435 | 436 | 437 | repo-sign-artifacts 438 | 439 | 440 | oss.repo 441 | true 442 | 443 | 444 | 445 | 446 | 447 | org.apache.maven.plugins 448 | maven-toolchains-plugin 449 | 450 | 451 | validate 452 | 453 | toolchain 454 | 455 | 456 | 457 | 458 | 459 | 460 | 1.5 461 | sun 462 | 463 | 464 | 465 | 466 | 467 | org.apache.maven.plugins 468 | maven-gpg-plugin 469 | 470 | 471 | sign-artifacts 472 | verify 473 | 474 | sign 475 | 476 | 477 | 478 | 479 | 480 | 481 | 482 | 483 | jboss-public-repository-group 484 | JBoss Public Maven Repository Group 485 | https://repository.jboss.org/nexus/content/groups/public-jboss/ 486 | default 487 | 488 | true 489 | never 490 | 491 | 492 | true 493 | never 494 | 495 | 496 | 497 | 498 | 499 | 500 | 501 | 502 | 503 | 2.5.3 504 | 2.11 505 | 2.13 506 | 2.6.1 507 | 3.2 508 | 2.8.2 509 | 2.9 510 | 1.6 511 | 2.5.2 512 | 2.5 513 | 2.10.1 514 | 2.5 515 | 3.4 516 | 3.3 517 | 2.8 518 | 2.3.1 519 | 2.7 520 | 3.4 521 | 2.4 522 | 2.18.1 523 | 2.18.1 524 | 1.1 525 | 526 | 1.5 527 | 1.5 528 | 1.5 529 | true 530 | true 531 | true 532 | true 533 | lines,source 534 | 535 | false 536 | true 537 | 538 | ${project.basedir}/src/main/checkstyle/checkstyle.xml 539 | 540 | UTF-8 541 | UTF-8 542 | 543 | 544 | -------------------------------------------------------------------------------- /src/changes/changes.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Java date and time API - Hibernate - Changes 6 | 7 | 8 | 9 | 10 | 11 | 12 | Support older dates by round-tripping LocalDate/LocalDateTime via matching Date/Calendar fields. 13 | Fixes #8. 14 | 15 | 16 | Change minimum Joda-Time version to 2.0. 17 | 18 | 19 | Home page at GitHub. 20 | 21 | 22 | Change to use m2e Maven Eclipse 23 | 24 | 25 | Add PersistentDurationAsMilliseconds 26 | 27 | 28 | Add PersistentLocalTimeAsTimestamp 29 | 30 | 31 | Add PersistentDateTimeAsBigInt 32 | 33 | 34 | 35 | 36 | 37 | Move to Hibernate 3.6 and optional dependencies 38 | 39 | 40 | 41 | 42 | 43 | Use LocalDate.toDateTimeAtStartOfDay() [2461322] 44 | 45 | 46 | Require Joda-Time 1.5 47 | 48 | 49 | Method deepCopy() should just return the input value [2038742] 50 | 51 | 52 | Change to maven 2 53 | 54 | 55 | Add persistence for Instant 56 | 57 | 58 | Add Serializable interface [2819834] 59 | 60 | 61 | 62 | 63 | 64 | Handle null intervals stored in database [2111763] 65 | 66 | 67 | Add persistence for LocalDateTime 68 | 69 | 70 | 71 | 72 | 73 | Add persistence for Period and Duration 74 | 75 | 76 | Add persistence for LocalDate and LocalTime 77 | 78 | 79 | 80 | 81 | 82 | Initial version 83 | 84 | 85 | 86 | 87 | -------------------------------------------------------------------------------- /src/conf/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Package: org.joda.time 2 | Extension-Name: joda-time-hibernate 3 | Specification-Title: Joda-Time Hibernate support 4 | Specification-Vendor: Joda.org 5 | Specification-Version: 1.4 6 | Implementation-Vendor: Joda.org 7 | Implementation-Title: org.joda.time.contrib.hibernate 8 | Implementation-Version: 1.4 9 | Implementation-Vendor-Id: org.joda 10 | Bundle-ManifestVersion: 2 11 | Bundle-Vendor: Joda.org 12 | Bundle-Name: Joda-Time-Hibernate 13 | Bundle-SymbolicName: joda-time-hibernate 14 | Bundle-Version: 1.4 15 | Import-Package: org.joda.time;version="2.0" 16 | Export-Package: org.joda.time.contrib.hibernate;version=1.4 17 | Bundle-License: Apache 2.0 18 | Bundle-DocURL: http://www.joda.org/joda-time-hibernate/ 19 | -------------------------------------------------------------------------------- /src/main/assembly/dist.xml: -------------------------------------------------------------------------------- 1 | 2 | dist 3 | 4 | tar.gz 5 | zip 6 | 7 | ${artifactId}-${version} 8 | 9 | 10 | 11 | checkstyle.xml 12 | LICENSE.txt 13 | NOTICE.txt 14 | pom.xml 15 | README.txt 16 | RELEASE-NOTES.txt 17 | 18 | 19 | 20 | src 21 | 22 | 23 | target 24 | 25 | 26 | *.jar 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /src/main/java/org/joda/time/contrib/hibernate/AbstractStringBasedJodaType.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.UserType; 27 | 28 | /** 29 | * @author gjoseph 30 | */ 31 | public abstract class AbstractStringBasedJodaType implements UserType, Serializable { 32 | 33 | private static final int[] SQL_TYPES = new int[] { Types.VARCHAR }; 34 | 35 | public int[] sqlTypes() { 36 | return SQL_TYPES; 37 | } 38 | 39 | public Object nullSafeGet(ResultSet resultSet, String[] strings, Object object) throws HibernateException, SQLException { 40 | String s = (String) StandardBasicTypes.STRING.nullSafeGet(resultSet, strings[0]); 41 | if (s == null) { 42 | return null; 43 | } 44 | 45 | return fromNonNullString(s); 46 | } 47 | 48 | protected abstract Object fromNonNullString(String s); 49 | 50 | public void nullSafeSet(PreparedStatement preparedStatement, Object value, int index) throws HibernateException, SQLException { 51 | if (value == null) { 52 | StandardBasicTypes.STRING.nullSafeSet(preparedStatement, null, index); 53 | } else { 54 | StandardBasicTypes.STRING.nullSafeSet(preparedStatement, toNonNullString(value), index); 55 | } 56 | } 57 | 58 | protected abstract String toNonNullString(Object value); 59 | 60 | public boolean equals(Object x, Object y) throws HibernateException { 61 | if (x == y) { 62 | return true; 63 | } 64 | if (x == null || y == null) { 65 | return false; 66 | } 67 | return x.equals(y); 68 | } 69 | 70 | public int hashCode(Object object) throws HibernateException { 71 | return object.hashCode(); 72 | } 73 | 74 | public Object deepCopy(Object value) throws HibernateException { 75 | return value; 76 | } 77 | 78 | public boolean isMutable() { 79 | return false; 80 | } 81 | 82 | public Serializable disassemble(Object value) throws HibernateException { 83 | return (Serializable) value; 84 | } 85 | 86 | public Object assemble(Serializable cached, Object value) throws HibernateException { 87 | return cached; 88 | } 89 | 90 | public Object replace(Object original, Object target, Object owner) throws HibernateException { 91 | return original; 92 | } 93 | 94 | } 95 | -------------------------------------------------------------------------------- /src/main/java/org/joda/time/contrib/hibernate/PersistentDateTime.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.DateTime; 28 | 29 | /** 30 | * Persist {@link org.joda.time.DateTime} via hibernate. 31 | * 32 | * @author Mario Ivankovits (mario@ops.co.at) 33 | */ 34 | public class PersistentDateTime implements EnhancedUserType, Serializable { 35 | 36 | public static final PersistentDateTime INSTANCE = new PersistentDateTime(); 37 | 38 | private static final int[] SQL_TYPES = new int[] { Types.TIMESTAMP, }; 39 | 40 | public int[] sqlTypes() { 41 | return SQL_TYPES; 42 | } 43 | 44 | public Class returnedClass() { 45 | return DateTime.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 | DateTime dtx = (DateTime) x; 56 | DateTime dty = (DateTime) y; 57 | 58 | return dtx.equals(dty); 59 | } 60 | 61 | public int hashCode(Object object) throws HibernateException { 62 | return object.hashCode(); 63 | } 64 | 65 | public Object nullSafeGet(ResultSet resultSet, String[] strings, Object object) throws HibernateException, SQLException { 66 | return nullSafeGet(resultSet, strings[0]); 67 | 68 | } 69 | 70 | public Object nullSafeGet(ResultSet resultSet, String string) throws SQLException { 71 | Object timestamp = StandardBasicTypes.TIMESTAMP.nullSafeGet(resultSet, string); 72 | if (timestamp == null) { 73 | return null; 74 | } 75 | 76 | return new DateTime(timestamp); 77 | } 78 | 79 | public void nullSafeSet(PreparedStatement preparedStatement, Object value, int index) throws HibernateException, SQLException { 80 | if (value == null) { 81 | StandardBasicTypes.TIMESTAMP.nullSafeSet(preparedStatement, null, index); 82 | } else { 83 | StandardBasicTypes.TIMESTAMP.nullSafeSet(preparedStatement, ((DateTime) value).toDate(), 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 DateTime(string); 117 | } 118 | 119 | } 120 | -------------------------------------------------------------------------------- /src/main/java/org/joda/time/contrib/hibernate/PersistentDateTimeAsBigInt.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 org.hibernate.HibernateException; 24 | import org.hibernate.type.StandardBasicTypes; 25 | import org.hibernate.usertype.EnhancedUserType; 26 | import org.joda.time.DateTime; 27 | 28 | /** 29 | * Persist {@link org.joda.time.DateTime} via hibernate as a BIGINT. 30 | * 31 | * @author Martin Grove (marting@optrak.co.uk)) 32 | */ 33 | public class PersistentDateTimeAsBigInt implements EnhancedUserType, Serializable { 34 | 35 | public static final PersistentDateTimeAsBigInt INSTANCE = new PersistentDateTimeAsBigInt(); 36 | 37 | private static final int[] SQL_TYPES = new int[] { Types.BIGINT }; 38 | 39 | public int[] sqlTypes() { 40 | return SQL_TYPES; 41 | } 42 | 43 | public Class returnedClass() { 44 | return DateTime.class; 45 | } 46 | 47 | public boolean equals(Object x, Object y) throws HibernateException { 48 | if (x == y) { 49 | return true; 50 | } 51 | if (x == null || y == null) { 52 | return false; 53 | } 54 | DateTime ix = (DateTime) x; 55 | DateTime iy = (DateTime) y; 56 | return ix.equals(iy); 57 | } 58 | 59 | public int hashCode(Object object) throws HibernateException { 60 | return object.hashCode(); 61 | } 62 | 63 | public Object nullSafeGet(ResultSet resultSet, String[] names, Object object) throws HibernateException, SQLException { 64 | return nullSafeGet(resultSet, names[0]); 65 | } 66 | 67 | public Object nullSafeGet(ResultSet resultSet, String name) throws HibernateException, SQLException { 68 | Object value = StandardBasicTypes.LONG.nullSafeGet(resultSet, name); 69 | if (value == null) { 70 | return null; 71 | } 72 | return new DateTime(value); 73 | } 74 | 75 | public void nullSafeSet(PreparedStatement preparedStatement, Object value, int index) throws HibernateException, SQLException { 76 | if (value == null) { 77 | StandardBasicTypes.LONG.nullSafeSet(preparedStatement, null, index); 78 | } else { 79 | StandardBasicTypes.LONG.nullSafeSet(preparedStatement, new Long(((DateTime) value).getMillis()), index); 80 | } 81 | } 82 | 83 | public Object deepCopy(Object value) throws HibernateException { 84 | return value; 85 | } 86 | 87 | public boolean isMutable() { 88 | return false; 89 | } 90 | 91 | public Serializable disassemble(Object value) throws HibernateException { 92 | return (Serializable) value; 93 | } 94 | 95 | public Object assemble(Serializable serializable, Object value) throws HibernateException { 96 | return serializable; 97 | } 98 | 99 | public Object replace(Object original, Object target, Object owner) throws HibernateException { 100 | return original; 101 | } 102 | 103 | // __________ EnhancedUserType ____________________ 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 DateTime(string); 115 | } 116 | 117 | } 118 | -------------------------------------------------------------------------------- /src/main/java/org/joda/time/contrib/hibernate/PersistentDateTimeTZ.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.UserType; 27 | import org.joda.time.DateTime; 28 | import org.joda.time.DateTimeZone; 29 | 30 | /** 31 | * Persist {@link org.joda.time.DateTime} via hibernate. The timezone will be 32 | * stored in an extra column. 33 | * 34 | * @author Mario Ivankovits (mario@ops.co.at) 35 | */ 36 | public class PersistentDateTimeTZ implements UserType, Serializable { 37 | 38 | public static final PersistentDateTimeTZ INSTANCE = new PersistentDateTimeTZ(); 39 | 40 | private static final int[] SQL_TYPES = new int[] { Types.TIMESTAMP, Types.VARCHAR, }; 41 | 42 | public int[] sqlTypes() { 43 | return SQL_TYPES; 44 | } 45 | 46 | public Class returnedClass() { 47 | return DateTime.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 | DateTime dtx = (DateTime) x; 58 | DateTime dty = (DateTime) 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 | Object timestamp = StandardBasicTypes.TIMESTAMP.nullSafeGet(resultSet, strings[0]); 68 | Object timezone = StandardBasicTypes.STRING.nullSafeGet(resultSet, strings[1]); 69 | if (timestamp == null || timezone == null) { 70 | return null; 71 | } 72 | return new DateTime(timestamp, DateTimeZone.forID(timezone.toString())); 73 | } 74 | 75 | public void nullSafeSet(PreparedStatement preparedStatement, Object value, int index) throws HibernateException, SQLException { 76 | if (value == null) { 77 | StandardBasicTypes.TIMESTAMP.nullSafeSet(preparedStatement, null, index); 78 | StandardBasicTypes.STRING.nullSafeSet(preparedStatement, null, index + 1); 79 | } else { 80 | DateTime dt = (DateTime) value; 81 | StandardBasicTypes.TIMESTAMP.nullSafeSet(preparedStatement, dt.toDate(), index); 82 | StandardBasicTypes.STRING.nullSafeSet(preparedStatement, dt.getZone().getID(), index + 1); 83 | } 84 | } 85 | 86 | public Object deepCopy(Object value) throws HibernateException { 87 | return value; 88 | } 89 | 90 | public boolean isMutable() { 91 | return false; 92 | } 93 | 94 | public Serializable disassemble(Object value) throws HibernateException { 95 | return (Serializable) value; 96 | } 97 | 98 | public Object assemble(Serializable cached, Object value) throws HibernateException { 99 | return cached; 100 | } 101 | 102 | public Object replace(Object original, Object target, Object owner) throws HibernateException { 103 | return original; 104 | } 105 | 106 | } 107 | -------------------------------------------------------------------------------- /src/main/java/org/joda/time/contrib/hibernate/PersistentDuration.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.Duration; 19 | 20 | /** 21 | * Converts a org.joda.time.Duration to and from Sql for Hibernate. 22 | * It simply stores the value as a varchar using Duration.toString. 23 | * 24 | * @author gjoseph 25 | */ 26 | public class PersistentDuration extends AbstractStringBasedJodaType { 27 | 28 | public Class returnedClass() { 29 | return Duration.class; 30 | } 31 | 32 | protected Object fromNonNullString(String s) { 33 | return new Duration(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/PersistentDurationAsMilliseconds.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.math.BigInteger; 20 | import java.sql.PreparedStatement; 21 | import java.sql.ResultSet; 22 | import java.sql.SQLException; 23 | import java.sql.Types; 24 | 25 | import org.hibernate.HibernateException; 26 | import org.hibernate.type.StandardBasicTypes; 27 | import org.hibernate.usertype.UserType; 28 | import org.joda.time.Duration; 29 | 30 | /** 31 | * Converts a org.joda.time.Duration to and from Sql for Hibernate. It simply 32 | * stores the milliseconds as a bigint. 33 | * 34 | * @author Daniel Jurado (jurado@gmail.com) 35 | */ 36 | public class PersistentDurationAsMilliseconds implements UserType, Serializable { 37 | 38 | private static final int[] SQL_TYPES = new int[] { Types.BIGINT }; 39 | 40 | public Class returnedClass() { 41 | return Duration.class; 42 | } 43 | 44 | public int[] sqlTypes() { 45 | return SQL_TYPES; 46 | } 47 | 48 | public Object nullSafeGet(ResultSet resultSet, String[] strings, 49 | Object object) throws HibernateException, SQLException { 50 | BigInteger b = (BigInteger) StandardBasicTypes.BIG_INTEGER.nullSafeGet( 51 | resultSet, strings[0]); 52 | if (b == null) { 53 | return null; 54 | } 55 | 56 | return new Duration(b.longValue()); 57 | } 58 | 59 | public void nullSafeSet(PreparedStatement preparedStatement, Object value, 60 | int index) throws HibernateException, SQLException { 61 | if (value == null) { 62 | StandardBasicTypes.BIG_INTEGER.nullSafeSet(preparedStatement, null, 63 | index); 64 | } else { 65 | StandardBasicTypes.BIG_INTEGER.nullSafeSet(preparedStatement, 66 | BigInteger.valueOf((Long) value), index); 67 | } 68 | } 69 | 70 | public boolean equals(Object x, Object y) throws HibernateException { 71 | if (x == y) { 72 | return true; 73 | } 74 | if (x == null || y == null) { 75 | return false; 76 | } 77 | return x.equals(y); 78 | } 79 | 80 | public int hashCode(Object object) throws HibernateException { 81 | return object.hashCode(); 82 | } 83 | 84 | public Object deepCopy(Object value) throws HibernateException { 85 | return value; 86 | } 87 | 88 | public boolean isMutable() { 89 | return false; 90 | } 91 | 92 | public Serializable disassemble(Object value) throws HibernateException { 93 | return (Serializable) value; 94 | } 95 | 96 | public Object assemble(Serializable cached, Object value) 97 | throws HibernateException { 98 | return cached; 99 | } 100 | 101 | public Object replace(Object original, Object target, Object owner) 102 | throws HibernateException { 103 | return original; 104 | } 105 | 106 | } 107 | -------------------------------------------------------------------------------- /src/main/java/org/joda/time/contrib/hibernate/PersistentInstant.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.Instant; 28 | 29 | /** 30 | * Persist {@link org.joda.time.Instant} via hibernate as a TIMESTAMP. 31 | * 32 | * @author Olav Reinert (oreinert@sourceforge.net) 33 | */ 34 | public class PersistentInstant implements EnhancedUserType { 35 | 36 | public static final PersistentInstant INSTANCE = new PersistentInstant(); 37 | 38 | private static final int[] SQL_TYPES = new int[] { Types.TIMESTAMP }; 39 | 40 | public int[] sqlTypes() { 41 | return SQL_TYPES; 42 | } 43 | 44 | public Class returnedClass() { 45 | return Instant.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 | Instant ix = (Instant) x; 56 | Instant iy = (Instant) y; 57 | return ix.equals(iy); 58 | } 59 | 60 | public int hashCode(Object object) throws HibernateException { 61 | return object.hashCode(); 62 | } 63 | 64 | public Object nullSafeGet(ResultSet resultSet, String[] names, Object object) throws HibernateException, SQLException { 65 | return nullSafeGet(resultSet, names[0]); 66 | } 67 | 68 | public Object nullSafeGet(ResultSet resultSet, String name) throws SQLException { 69 | Object value = StandardBasicTypes.TIMESTAMP.nullSafeGet(resultSet, name); 70 | if (value == null) { 71 | return null; 72 | } 73 | return new Instant(value); 74 | } 75 | 76 | public void nullSafeSet(PreparedStatement preparedStatement, Object value, int index) throws HibernateException, SQLException { 77 | if (value == null) { 78 | StandardBasicTypes.TIMESTAMP.nullSafeSet(preparedStatement, null, index); 79 | } else { 80 | StandardBasicTypes.TIMESTAMP.nullSafeSet(preparedStatement, ((Instant) value).toDate(), index); 81 | } 82 | } 83 | 84 | public Object deepCopy(Object value) throws HibernateException { 85 | return value; 86 | } 87 | 88 | public boolean isMutable() { 89 | return false; 90 | } 91 | 92 | public Serializable disassemble(Object value) throws HibernateException { 93 | return (Serializable) value; 94 | } 95 | 96 | public Object assemble(Serializable serializable, Object value) throws HibernateException { 97 | return serializable; 98 | } 99 | 100 | public Object replace(Object original, Object target, Object owner) throws HibernateException { 101 | return original; 102 | } 103 | 104 | // __________ EnhancedUserType ____________________ 105 | 106 | public String objectToSQLString(Object object) { 107 | throw new UnsupportedOperationException(); 108 | } 109 | 110 | public String toXMLString(Object object) { 111 | return object.toString(); 112 | } 113 | 114 | public Object fromXMLString(String string) { 115 | return new Instant(string); 116 | } 117 | 118 | } 119 | -------------------------------------------------------------------------------- /src/main/java/org/joda/time/contrib/hibernate/PersistentInstantAsBigInt.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.Instant; 28 | 29 | /** 30 | * Persist {@link org.joda.time.Instant} via hibernate as a BIGINT. 31 | * 32 | * @author Martin Grove (marting@optrak.co.uk)) 33 | */ 34 | public class PersistentInstantAsBigInt implements EnhancedUserType, Serializable { 35 | 36 | public static final PersistentInstantAsBigInt INSTANCE = new PersistentInstantAsBigInt(); 37 | 38 | private static final int[] SQL_TYPES = new int[] { Types.BIGINT }; 39 | 40 | public int[] sqlTypes() { 41 | return SQL_TYPES; 42 | } 43 | 44 | public Class returnedClass() { 45 | return Instant.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 | Instant ix = (Instant) x; 56 | Instant iy = (Instant) y; 57 | return ix.equals(iy); 58 | } 59 | 60 | public int hashCode(Object object) throws HibernateException { 61 | return object.hashCode(); 62 | } 63 | 64 | public Object nullSafeGet(ResultSet resultSet, String[] names, Object object) throws HibernateException, SQLException { 65 | return nullSafeGet(resultSet, names[0]); 66 | } 67 | 68 | public Object nullSafeGet(ResultSet resultSet, String name) throws HibernateException, SQLException { 69 | Object value = StandardBasicTypes.LONG.nullSafeGet(resultSet, name); 70 | if (value == null) { 71 | return null; 72 | } 73 | return new Instant(value); 74 | } 75 | 76 | public void nullSafeSet(PreparedStatement preparedStatement, Object value, int index) throws HibernateException, SQLException { 77 | if (value == null) { 78 | StandardBasicTypes.LONG.nullSafeSet(preparedStatement, null, index); 79 | } else { 80 | StandardBasicTypes.LONG.nullSafeSet(preparedStatement, new Long(((Instant) value).getMillis()), index); 81 | } 82 | } 83 | 84 | public Object deepCopy(Object value) throws HibernateException { 85 | return value; 86 | } 87 | 88 | public boolean isMutable() { 89 | return false; 90 | } 91 | 92 | public Serializable disassemble(Object value) throws HibernateException { 93 | return (Serializable) value; 94 | } 95 | 96 | public Object assemble(Serializable serializable, Object value) throws HibernateException { 97 | return serializable; 98 | } 99 | 100 | public Object replace(Object original, Object target, Object owner) throws HibernateException { 101 | return original; 102 | } 103 | 104 | // __________ EnhancedUserType ____________________ 105 | 106 | public String objectToSQLString(Object object) { 107 | throw new UnsupportedOperationException(); 108 | } 109 | 110 | public String toXMLString(Object object) { 111 | return object.toString(); 112 | } 113 | 114 | public Object fromXMLString(String string) { 115 | return new Instant(string); 116 | } 117 | 118 | } 119 | -------------------------------------------------------------------------------- /src/main/java/org/joda/time/contrib/hibernate/PersistentInterval.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 | 24 | import org.hibernate.HibernateException; 25 | import org.hibernate.engine.SessionImplementor; 26 | import org.hibernate.type.StandardBasicTypes; 27 | import org.hibernate.type.Type; 28 | import org.hibernate.usertype.CompositeUserType; 29 | import org.joda.time.DateTime; 30 | import org.joda.time.Interval; 31 | 32 | /** 33 | * Persist {@link org.joda.time.Interval} via hibernate. Internally, this class 34 | * collaborates with {@link org.joda.time.contrib.hibernate.PersistentDateTime} 35 | * to convert the start and end components of an Interval to and from the 36 | * database correspondents. This class allows clients to execute hibernate or 37 | * JPA queries using the attribute names "start" and "end." For example, 38 | *
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 | OpenGamma 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /src/site/site.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Joda.org 6 | http://www.joda.org/ 7 | 8 | 9 | Joda-Time-Hibernate 10 | http://www.joda.org/joda-time-jsptags/ 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 52 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /src/site/xdoc/index.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Java date and time API - Hibernate - Home 7 | Stephen Colebourne 8 | 9 | 10 | 11 | 12 |
13 |

14 | Joda-Time provides a complete quality alternative 15 | to the JDK date and time classes. 16 | At some point however, many projects need to persist these classes to a database. 17 | One popular tool for achieving this is Hibernate. 18 |

19 |

20 | To ease the integration of Joda-Time and Hibernate, this sub-project was setup. 21 | It aims to provide the classes necessary to persist Joda-Time objects. 22 |

23 |

24 | Version 1.4 was released on 2015-04-17 - 25 | Download now 26 |

27 |

28 | Please note that version 1.4 is for Hibernate 3.6 and not Hibernate 4.0 (as the Hibernate team have 29 | made another incompatible change). 30 | The usertype project handles Hibernate 4.0. 31 | It is also more up to date and more complete than this project in general. 32 |

33 |
34 | 35 | 36 |
37 |

38 | Various documentation is available: 39 |

44 |

45 |
46 | 47 | 48 |
49 |

50 | Release 1.4 51 | is the current latest release. 52 | Please bear in mind that this project is separate from Joda-Time itself. 53 |

54 |

55 | The dependencies are Joda-Time 2.0 or later and Hibernate 3.6 (plus associated dependencies). 56 | The Maven POM defines the dependencies as "provided", so you must specify them independently of this project. 57 | We recommend JDK 1.5 or later, and have performed no testing on earlier JDKs. 58 |

59 |

60 | Available in Maven Central. 61 |

62 |
63 | 64 | 65 |
66 |

67 | The Joda-Time-Hibernate library was contributed to Joda-Time by Mario Ivankovits and Gregory Joseph. 68 |

69 |

70 | Support on bugs, library usage or enhancement requests is available on a best efforts basis. 71 |

72 |

73 | To suggest enhancements or contribute, please fork the source code on GitHub. 74 | Alternatively, use GitHub issues. 75 |

76 |

77 |
78 |

79 |

80 |
81 |

82 |

83 |
84 |

85 |
86 | 87 |
88 | -------------------------------------------------------------------------------- /src/site/xdoc/licensecover.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Java date and time API - Hibernate support - License 6 | Stephen Colebourne 7 | 8 | 9 | 10 | 11 |
12 |

13 | Joda-Time source code is released under the business-friendly 14 | Apache 2.0 license. 15 | This is the same license as Ant, 16 | Spring, 17 | Tomcat and 18 | Jakarta. 19 |

20 |

21 | The Hibernate support contributed library depends on 22 | Hibernate. 23 | Hibernate is LGPL v2.1 licensed. 24 | As a user of this library you must decide how the LGPL applies to you. 25 |

26 |

27 | As is normal with the Apache 2.0 license, a 28 | NOTICE file exists for Joda-Time-Hibernate: 29 | 30 | ============================================================================= 31 | = NOTICE file corresponding to section 4d of the Apache License Version 2.0 = 32 | ============================================================================= 33 | This product includes software developed by 34 | Joda.org (http://www.joda.org/). 35 | 36 |

37 |
38 | 39 | 40 |
41 | -------------------------------------------------------------------------------- /src/site/xdoc/userguide.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Java date and time API - Hibernate support - User Guide 6 | Stephen Colebourne 7 | 8 | 9 | 10 | 11 | 12 |
13 |

14 | Joda-Time-Hibernate support provides classes to 15 | persist Joda-Time based date and time objects to a database using Hibernate. 16 |

17 | 18 | 19 | 20 | 21 |

22 | It is fairly easy to use this package in your Hibernate environment. 23 | There are two main options for the configuration - the hibernate mapping file or annotations. 24 |

25 | 26 | 27 |

28 | Add the type attribute to your property configuration. e.g.: 29 |

30 |

 32 |         ]]>
33 |
34 | 35 | 36 |

37 | Set the type using the @org.hibernate.annotations.Type annotation. e.g.: 38 |

39 |
44 |

45 | Sometimes there are multiple columns to be specified, as with PersistentDateTimeTZ: 46 |

47 |
52 |
53 | 54 | 55 |

56 | The main types which can be persisted: 57 |

58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 |
ClassSQL Column Type(s)Description
org.joda.time.contrib.hibernate.PersistentDateTimeTIMESTAMP
org.joda.time.contrib.hibernate.PersistentDateTimeTZTIMESTAMP, VARCHARThis persister uses two columns, to separately store the time value and its timezone
org.joda.time.contrib.hibernate.PersistentInstantTIMESTAMPThis persister uses one column to store the timestamp
org.joda.time.contrib.hibernate.PersistentInstantAsBigIntBIGINTThis persister uses one column to store the millisconds
org.joda.time.contrib.hibernate.PersistentIntervalTIMESTAMP, TIMESTAMPThis persister uses two columns, to store the start and end of the interval
org.joda.time.contrib.hibernate.PersistentLocalDateTIMESTAMP
org.joda.time.contrib.hibernate.PersistentLocalTimeAsTimeTIMEDepending on your Database you might loose the millisecond part
org.joda.time.contrib.hibernate.PersistentLocalTimeAsTimestampTIMESTAMP
org.joda.time.contrib.hibernate.PersistentLocalTimeExactINTEGERThe milliseconds are stored as simple integer value, no information loss
org.joda.time.contrib.hibernate.PersistentLocalTimeAsStringVARCHARSame as above, just uses a human readable representation. ISO8601 format - HH:mm:ss.SSSZ
org.joda.time.contrib.hibernate.PersistentLocalDateTimeTIMESTAMP
org.joda.time.contrib.hibernate.PersistentDurationVARCHARThe format is PTnS where n is the value
org.joda.time.contrib.hibernate.PersistentDurationAsMillisecondsBIGINTInteger milliseconds
org.joda.time.contrib.hibernate.PersistentPeriodVARCHARThe format is PnYnMnDTnHnMnS where n is the value
135 | 136 |
137 | 138 | 139 |

140 | The following types are now effectively deprecated, however persistence is still available: 141 |

142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 |
ClassSQL Column Type(s)Description
org.joda.time.contrib.hibernate.PersistentTimeOfDayTIMEDepending on your Database you might loose the millisecond part
org.joda.time.contrib.hibernate.PersistentTimeOfDayExactINTEGERThe milliseconds are stored as simple integer value, no information loss
org.joda.time.contrib.hibernate.PersistentYearMonthDayDATE
164 |
165 | 166 |
167 |
168 | 169 | 170 | 171 | 172 |
173 | -------------------------------------------------------------------------------- /src/test/java/org/joda/time/contrib/hibernate/Event.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 | 20 | import org.joda.time.DateTime; 21 | import org.joda.time.LocalDate; 22 | import org.joda.time.LocalDateTime; 23 | import org.joda.time.LocalTime; 24 | 25 | /** 26 | * PO to be stored using hibernate 27 | */ 28 | public class Event implements Serializable 29 | { 30 | private int id; 31 | private DateTime dateTime; 32 | private LocalDate localDate; 33 | private LocalTime localTime; 34 | private LocalTime localTime2; 35 | private LocalTime localTime3; 36 | private LocalTime localTime4; 37 | private LocalDateTime localDateTime; 38 | 39 | public Event() 40 | { 41 | } 42 | 43 | public int getId() 44 | { 45 | return id; 46 | } 47 | 48 | public void setId(int id) 49 | { 50 | this.id = id; 51 | } 52 | 53 | public DateTime getDateTime() 54 | { 55 | return dateTime; 56 | } 57 | 58 | public void setDateTime(DateTime dateTime) 59 | { 60 | this.dateTime = dateTime; 61 | } 62 | 63 | public LocalDate getLocalDate() 64 | { 65 | return localDate; 66 | } 67 | 68 | public void setLocalDate(LocalDate localDate) 69 | { 70 | this.localDate = localDate; 71 | } 72 | 73 | public LocalTime getLocalTime() 74 | { 75 | return localTime; 76 | } 77 | 78 | public void setLocalTime(LocalTime localTime) 79 | { 80 | this.localTime = localTime; 81 | } 82 | 83 | public LocalTime getLocalTime2() 84 | { 85 | return localTime2; 86 | } 87 | 88 | public void setLocalTime2(LocalTime localTime2) 89 | { 90 | this.localTime2 = localTime2; 91 | } 92 | 93 | public LocalTime getLocalTime3() 94 | { 95 | return localTime3; 96 | } 97 | 98 | public void setLocalTime3(LocalTime localTime3) 99 | { 100 | this.localTime3 = localTime3; 101 | } 102 | 103 | public LocalTime getLocalTime4() 104 | { 105 | return localTime4; 106 | } 107 | 108 | public void setLocalTime4(LocalTime localTime4) 109 | { 110 | this.localTime4 = localTime4; 111 | } 112 | 113 | public LocalDateTime getLocalDateTime() 114 | { 115 | return localDateTime; 116 | } 117 | 118 | public void setLocalDateTime(LocalDateTime localDateTime) 119 | { 120 | this.localDateTime = localDateTime; 121 | } 122 | } 123 | -------------------------------------------------------------------------------- /src/test/java/org/joda/time/contrib/hibernate/EventTZ.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 | 20 | import org.joda.time.DateTime; 21 | 22 | /** 23 | * PO to be stored using hibernate 24 | */ 25 | public class EventTZ implements Serializable 26 | { 27 | private int id; 28 | private DateTime dateTime; 29 | 30 | public EventTZ() 31 | { 32 | } 33 | 34 | public int getId() 35 | { 36 | return id; 37 | } 38 | 39 | public void setId(int id) 40 | { 41 | this.id = id; 42 | } 43 | 44 | public DateTime getDateTime() 45 | { 46 | return dateTime; 47 | } 48 | 49 | public void setDateTime(DateTime dateTime) 50 | { 51 | this.dateTime = dateTime; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/test/java/org/joda/time/contrib/hibernate/HibernateTestCase.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 junit.framework.TestCase; 19 | 20 | import org.hibernate.SessionFactory; 21 | import org.hibernate.cfg.Configuration; 22 | import org.hibernate.dialect.HSQLDialect; 23 | import org.hibernate.tool.hbm2ddl.SchemaUpdate; 24 | 25 | import java.sql.Connection; 26 | import java.sql.Statement; 27 | 28 | public abstract class HibernateTestCase extends TestCase 29 | { 30 | private SessionFactory factory; 31 | private Configuration cfg; 32 | 33 | protected SessionFactory getSessionFactory() 34 | { 35 | if (this.factory == null) 36 | { 37 | cfg = new Configuration(); 38 | 39 | setupConfiguration(cfg); 40 | 41 | cfg.setProperty("hibernate.connection.driver_class", "org.hsqldb.jdbcDriver"); 42 | cfg.setProperty("hibernate.connection.url", "jdbc:hsqldb:mem:hbmtest" + getClass().getName()); 43 | cfg.setProperty("hibernate.dialect", HSQLDialect.class.getName()); 44 | 45 | cfg.setProperty("hibernate.show_sql", "true"); 46 | SessionFactory factory = cfg.buildSessionFactory(); 47 | 48 | SchemaUpdate update = new SchemaUpdate(cfg); 49 | update.execute(true, true); 50 | 51 | this.factory = factory; 52 | } 53 | return factory; 54 | } 55 | 56 | protected void tearDown() throws Exception 57 | { 58 | final String[] dropSQLs = cfg.generateDropSchemaScript(new HSQLDialect()); 59 | final Connection connection = getSessionFactory().openSession().connection(); 60 | try { 61 | Statement stmt = connection.createStatement(); 62 | for (int i = 0; i < dropSQLs.length; i++) { 63 | //System.out.println("dropSQLs[i] = " + dropSQLs[i]); 64 | stmt.executeUpdate(dropSQLs[i]); 65 | } 66 | } finally { 67 | connection.close(); 68 | } 69 | 70 | if (this.factory != null) 71 | { 72 | this.factory.close(); 73 | this.factory = null; 74 | } 75 | } 76 | 77 | protected abstract void setupConfiguration(Configuration cfg); 78 | } 79 | -------------------------------------------------------------------------------- /src/test/java/org/joda/time/contrib/hibernate/Plan.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.Interval; 19 | 20 | public class Plan 21 | { 22 | private int id; 23 | private Interval period; 24 | 25 | public Plan() 26 | { 27 | } 28 | 29 | public Plan(int id) 30 | { 31 | setId(id); 32 | } 33 | 34 | private void setId(int id) 35 | { 36 | this.id = id; 37 | } 38 | 39 | public int getId() 40 | { 41 | return id; 42 | } 43 | 44 | public Interval getPeriod() 45 | { 46 | return period; 47 | } 48 | 49 | public void setPeriod(Interval period) 50 | { 51 | this.period = period; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/test/java/org/joda/time/contrib/hibernate/Schedule.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 | 20 | import org.joda.time.TimeOfDay; 21 | import org.joda.time.YearMonthDay; 22 | 23 | /** 24 | * PO to be stored using hibernate 25 | */ 26 | public class Schedule implements Serializable 27 | { 28 | private int id; 29 | private YearMonthDay startDate; 30 | private TimeOfDay nextTime; 31 | private TimeOfDay nextTimeMillis; 32 | 33 | public Schedule() 34 | { 35 | } 36 | 37 | public int getId() 38 | { 39 | return id; 40 | } 41 | 42 | public void setId(int id) 43 | { 44 | this.id = id; 45 | } 46 | 47 | public YearMonthDay getStartDate() 48 | { 49 | return startDate; 50 | } 51 | 52 | public void setStartDate(YearMonthDay startDate) 53 | { 54 | this.startDate = startDate; 55 | } 56 | 57 | public TimeOfDay getNextTime() 58 | { 59 | return nextTime; 60 | } 61 | 62 | public void setNextTime(TimeOfDay nextTime) 63 | { 64 | this.nextTime = nextTime; 65 | } 66 | 67 | public TimeOfDay getNextTimeMillis() 68 | { 69 | return nextTimeMillis; 70 | } 71 | 72 | public void setNextTimeMillis(TimeOfDay nextTimeMillis) 73 | { 74 | this.nextTimeMillis = nextTimeMillis; 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /src/test/java/org/joda/time/contrib/hibernate/TestPersistentDateTime.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.File; 19 | import java.sql.SQLException; 20 | 21 | import org.hibernate.Session; 22 | import org.hibernate.SessionFactory; 23 | import org.hibernate.cfg.Configuration; 24 | import org.joda.time.DateTime; 25 | import org.joda.time.DateTimeZone; 26 | 27 | public class TestPersistentDateTime extends HibernateTestCase 28 | { 29 | private DateTime[] writeReadTimes = new DateTime[] 30 | { 31 | new DateTime(2004, 2, 25, 17, 3, 45, 760), 32 | new DateTime(1980, 3, 11, 2, 3, 45, 0, DateTimeZone.forOffsetHours(2)) 33 | }; 34 | 35 | public void testSimpleStore() throws SQLException 36 | { 37 | SessionFactory factory = getSessionFactory(); 38 | 39 | Session session = factory.openSession(); 40 | 41 | for (int i = 0; i 2 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /src/test/java/org/joda/time/contrib/hibernate/eventTZ.hbm.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /src/test/java/org/joda/time/contrib/hibernate/plan.hbm.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /src/test/java/org/joda/time/contrib/hibernate/schedule.hbm.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /src/test/java/org/joda/time/contrib/hibernate/testmodel/SomethingThatHappens.hbm.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /src/test/java/org/joda/time/contrib/hibernate/testmodel/SomethingThatHappens.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.testmodel; 17 | 18 | import org.joda.time.Period; 19 | 20 | import java.io.Serializable; 21 | 22 | /** 23 | * 24 | * @author gjoseph 25 | * @author $Author: $ (last edit) 26 | * @version $Revision: $ 27 | */ 28 | public class SomethingThatHappens implements Serializable { 29 | private long id; 30 | private String name; 31 | private Period thePeriod; 32 | 33 | public long getId() { 34 | return id; 35 | } 36 | 37 | public void setId(long id) { 38 | this.id = id; 39 | } 40 | 41 | public String getName() { 42 | return name; 43 | } 44 | 45 | public void setName(String name) { 46 | this.name = name; 47 | } 48 | 49 | public Period getThePeriod() { 50 | return thePeriod; 51 | } 52 | 53 | public void setThePeriod(Period thePeriod) { 54 | this.thePeriod = thePeriod; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/test/java/org/joda/time/contrib/hibernate/testmodel/SomethingThatLasts.hbm.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /src/test/java/org/joda/time/contrib/hibernate/testmodel/SomethingThatLasts.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.testmodel; 17 | 18 | import org.joda.time.Duration; 19 | 20 | import java.io.Serializable; 21 | 22 | /** 23 | * 24 | * @author gjoseph 25 | * @author $Author: $ (last edit) 26 | * @version $Revision: $ 27 | */ 28 | public class SomethingThatLasts implements Serializable { 29 | private long id; 30 | private String name; 31 | private Duration theDuration; 32 | 33 | public long getId() { 34 | return id; 35 | } 36 | 37 | public void setId(long id) { 38 | this.id = id; 39 | } 40 | 41 | public String getName() { 42 | return name; 43 | } 44 | 45 | public void setName(String name) { 46 | this.name = name; 47 | } 48 | 49 | public Duration getTheDuration() { 50 | return theDuration; 51 | } 52 | 53 | public void setTheDuration(Duration theDuration) { 54 | this.theDuration = theDuration; 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /src/test/java/org/joda/time/contrib/hibernate/testmodel/SomethingThatLastsInMilliseconds.hbm.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /src/test/java/org/joda/time/contrib/hibernate/thingWithDateTime.hbm.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /src/test/java/org/joda/time/contrib/hibernate/thingWithDateTimeAsBigInt.hbm.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /src/test/java/org/joda/time/contrib/hibernate/thingWithInstant.hbm.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /src/test/java/org/joda/time/contrib/hibernate/thingWithInstantAsBigInt.hbm.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | --------------------------------------------------------------------------------