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. import javax.jdo.JDOException;
  18. import javax.jdo.PersistenceManager;
  19. /**
  20. * Callback interface for JDO code. To be used with JdoTemplate's execute
  21. * method, assumably often as anonymous classes within a method implementation.
  22. * The typical implementation will call PersistenceManager CRUD to perform
  23. * some operations on persistent objects.
  24. *
  25. * <p>Note that JDO works on bytecode-modified Java objects, to be able to
  26. * perform dirty detection on each modification of a persistent instance field.
  27. * In contrast to Hibernate, using returned objects outside of an active
  28. * PersistenceManager poses a problem: To be able to read and modify fields
  29. * e.g. in a web GUI, one has to explicitly make the instances "transient".
  30. * Reassociation with a new PersistenceManager, e.g. for updates when coming
  31. * back from the GUI, isn't possible, as the JDO instances have lost their
  32. * identity when turned transient. This means that either value objects have
  33. * to be used as parameters, or the contents of the outside-modified instance
  34. * have to be copied to a freshly loaded active instance on reassociation.
  35. *
  36. * @author Juergen Hoeller
  37. * @since 03.06.2003
  38. * @see JdoTemplate
  39. * @see org.springframework.orm.hibernate.HibernateCallback
  40. */
  41. public interface JdoCallback {
  42. /**
  43. * Gets called by JdoTemplate.execute with an active PersistenceManager.
  44. * Does not need to care about activating or closing the PersistenceManager,
  45. * or handling transactions.
  46. *
  47. * <p>Note that JDO callback code will not flush any modifications to the
  48. * database if not executed within a transaction. Thus, you need to make
  49. * sure that JdoTransactionManager has initiated a JDO transaction when
  50. * the callback gets called, at least if you want to write to the database.
  51. *
  52. * <p>Allows for returning a result object created within the callback,
  53. * i.e. a domain object or a collection of domain objects.
  54. * A thrown RuntimeException is treated as application exception,
  55. * it gets propagated to the caller of the template.
  56. *
  57. * @param pm active PersistenceManager
  58. * @return a result object, or null if none
  59. * @throws javax.jdo.JDOException in case of JDO errors
  60. * @see JdoTemplate#execute
  61. * @see JdoTransactionManager
  62. */
  63. Object doInJdo(PersistenceManager pm) throws JDOException;
  64. }