1. /*
  2. * Copyright 2002-2004 the original author or authors.
  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.springframework.orm.hibernate;
  17. import net.sf.hibernate.FlushMode;
  18. /**
  19. * Hibernate transaction object, representing a SessionHolder.
  20. * Used as transaction object by HibernateTransactionManager.
  21. *
  22. * <p>Instances of this class are the transaction objects that
  23. * HibernateTransactionManager returns. They nest the thread-bound
  24. * SessionHolder internally.
  25. *
  26. * <p>Note: This is an SPI class, not intended to be used by applications.
  27. *
  28. * @author Juergen Hoeller
  29. * @since 02.05.2003
  30. * @see HibernateTransactionManager
  31. * @see SessionHolder
  32. */
  33. public class HibernateTransactionObject {
  34. private SessionHolder sessionHolder;
  35. private boolean newSessionHolder;
  36. private Integer previousIsolationLevel;
  37. private FlushMode previousFlushMode;
  38. /**
  39. * Create HibernateTransactionObject for new SessionHolder.
  40. */
  41. protected HibernateTransactionObject() {
  42. }
  43. /**
  44. * Create HibernateTransactionObject for existing SessionHolder.
  45. */
  46. protected HibernateTransactionObject(SessionHolder sessionHolder) {
  47. this.sessionHolder = sessionHolder;
  48. this.newSessionHolder = false;
  49. }
  50. /**
  51. * Set new SessionHolder.
  52. */
  53. protected void setSessionHolder(SessionHolder sessionHolder) {
  54. this.sessionHolder = sessionHolder;
  55. this.newSessionHolder = (sessionHolder != null);
  56. }
  57. public SessionHolder getSessionHolder() {
  58. return sessionHolder;
  59. }
  60. public boolean isNewSessionHolder() {
  61. return newSessionHolder;
  62. }
  63. public boolean hasTransaction() {
  64. return (sessionHolder != null && sessionHolder.getTransaction() != null);
  65. }
  66. protected void setPreviousIsolationLevel(Integer previousIsolationLevel) {
  67. this.previousIsolationLevel = previousIsolationLevel;
  68. }
  69. public Integer getPreviousIsolationLevel() {
  70. return previousIsolationLevel;
  71. }
  72. protected void setPreviousFlushMode(FlushMode previousFlushMode) {
  73. this.previousFlushMode = previousFlushMode;
  74. }
  75. public FlushMode getPreviousFlushMode() {
  76. return previousFlushMode;
  77. }
  78. }