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 java.sql.Connection;
  18. import javax.jdo.JDOException;
  19. import javax.jdo.PersistenceManager;
  20. import org.springframework.dao.DataAccessException;
  21. /**
  22. * Strategy that encapsulates certain functionality that standard JDO 1.0 does not offer
  23. * despite being relevant in the context of O/R mapping, like access to the underlying
  24. * JDBC connection and explicit flushing of changes to the database.
  25. *
  26. * <p>To be implemented for specific JDO implementations like Kodo, Lido, or JDO Genie.
  27. * Almost every O/R-based JDO implementation will offer proprietary means to access the
  28. * underlying JDBC Connection and to explicitly flush changes. JDO 2.0 respectively
  29. * JDO/R 2.0 are likely to define standard ways for these: If applicable, a JdoDialect
  30. * implementation for JDO 2.0 will be provided to leverage them with Spring's JDO support.
  31. *
  32. * @author Juergen Hoeller
  33. * @since 02.11.2003
  34. */
  35. public interface JdoDialect {
  36. /**
  37. * Retrieve the JDBC connection that the given JDO persistence manager uses underneath,
  38. * if accessing a relational database. This method will just get invoked if actually
  39. * needing access to the underlying JDBC connection.
  40. * <p>This strategy is necessary as JDO 1.0 does not provide a standard way to retrieve
  41. * the underlying JDBC Connection (due to the fact that a JDO implementation might not
  42. * work with a relational database at all).
  43. * @param pm the current JDO persistence manager
  44. * @return the underlying JDBC connection
  45. * @throws JDOException in case of retrieval errors
  46. * @see JdoTransactionManager#setDataSource
  47. */
  48. Connection getJdbcConnection(PersistenceManager pm) throws JDOException;
  49. /**
  50. * Flush the given persistence manager, i.e. flush all changes (that have been applied
  51. * to persistent objects) to the underlying database. This method will just get invoked
  52. * if eager flushing is actually necessary, for example if JDBC access code needs to
  53. * see changes within the same transaction.
  54. * @param pm the current JDO persistence manager
  55. * @throws JDOException in case of errors
  56. * @see JdoAccessor#setFlushEager
  57. */
  58. void flush(PersistenceManager pm) throws JDOException;
  59. /**
  60. * Translate the given JDOException to a corresponding exception from Spring's
  61. * generic DataAccessException hierarchy. An implementation should apply
  62. * PersistenceManagerFactoryUtils' standard exception translation if can't do
  63. * anything more specific.
  64. * <p>Of particular importance is the correct translation to
  65. * ObjectRetrievalFailureException, ObjectOptimisticLockingFailureException,
  66. * and DataIntegrityViolationException. Unfortunately, standard JDO does not
  67. * allow for portable detection of those.
  68. * @param ex the JDOException thrown
  69. * @return the corresponding DataAccessException (must not be null)
  70. * @see JdoAccessor#convertJdoAccessException
  71. * @see JdoTransactionManager#convertJdoAccessException
  72. * @see PersistenceManagerFactoryUtils#convertJdoAccessException
  73. * @see org.springframework.orm.ObjectRetrievalFailureException
  74. * @see org.springframework.orm.ObjectOptimisticLockingFailureException
  75. * @see org.springframework.dao.DataIntegrityViolationException
  76. */
  77. DataAccessException translateException(JDOException ex);
  78. }