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.Session;
  18. import net.sf.hibernate.Transaction;
  19. import org.springframework.transaction.support.ResourceHolderSupport;
  20. /**
  21. * Session holder, wrapping a Hibernate Session and a Hibernate Transaction.
  22. * HibernateTransactionManager binds instances of this class
  23. * to the thread, for a given SessionFactory.
  24. *
  25. * <p>Note: This is an SPI class, not intended to be used by applications.
  26. *
  27. * @author Juergen Hoeller
  28. * @since 06.05.2003
  29. * @see HibernateTransactionManager
  30. * @see HibernateTransactionObject
  31. * @see SessionFactoryUtils
  32. */
  33. public class SessionHolder extends ResourceHolderSupport {
  34. private final Session session;
  35. private Transaction transaction;
  36. private boolean synchronizedWithTransaction;
  37. public SessionHolder(Session session) {
  38. this.session = session;
  39. }
  40. public Session getSession() {
  41. return session;
  42. }
  43. public void setTransaction(Transaction transaction) {
  44. this.transaction = transaction;
  45. }
  46. public Transaction getTransaction() {
  47. return transaction;
  48. }
  49. public void setSynchronizedWithTransaction(boolean synchronizedWithTransaction) {
  50. this.synchronizedWithTransaction = synchronizedWithTransaction;
  51. }
  52. public boolean isSynchronizedWithTransaction() {
  53. return synchronizedWithTransaction;
  54. }
  55. }