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.jdo;
  17. /**
  18. * JDO transaction object, representing a PersistenceManagerHolder.
  19. * Used as transaction object by JdoTransactionManager.
  20. *
  21. * <p>Instances of this class are the transaction objects that
  22. * JdoTransactionManager returns. They nest the thread-bound
  23. * PersistenceManagerHolder internally.
  24. *
  25. * <p>Note: This is an SPI class, not intended to be used by applications.
  26. *
  27. * @author Juergen Hoeller
  28. * @since 13.06.2003
  29. */
  30. public class JdoTransactionObject {
  31. private PersistenceManagerHolder persistenceManagerHolder;
  32. private boolean newPersistenceManagerHolder;
  33. /**
  34. * Create JdoTransactionObject for new PersistenceManagerHolder.
  35. */
  36. protected JdoTransactionObject() {
  37. }
  38. /**
  39. * Create JdoTransactionObject for existing PersistenceManagerHolder.
  40. */
  41. protected JdoTransactionObject(PersistenceManagerHolder persistenceManagerHolder) {
  42. this.persistenceManagerHolder = persistenceManagerHolder;
  43. this.newPersistenceManagerHolder = false;
  44. }
  45. /**
  46. * Set new PersistenceManagerHolder.
  47. */
  48. protected void setPersistenceManagerHolder(PersistenceManagerHolder persistenceManagerHolder) {
  49. this.persistenceManagerHolder = persistenceManagerHolder;
  50. this.newPersistenceManagerHolder = (persistenceManagerHolder != null);
  51. }
  52. public PersistenceManagerHolder getPersistenceManagerHolder() {
  53. return persistenceManagerHolder;
  54. }
  55. public boolean isNewPersistenceManagerHolder() {
  56. return newPersistenceManagerHolder;
  57. }
  58. public boolean hasTransaction() {
  59. return (persistenceManagerHolder != null && persistenceManagerHolder.getPersistenceManager() != null &&
  60. persistenceManagerHolder.getPersistenceManager().currentTransaction().isActive());
  61. }
  62. }