javax.jdo.JDOException Java Examples

The following examples show how to use javax.jdo.JDOException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JdoTransactionManager.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Override
protected void doRollback(DefaultTransactionStatus status) {
	JdoTransactionObject txObject = (JdoTransactionObject) status.getTransaction();
	if (status.isDebug()) {
		logger.debug("Rolling back JDO transaction on PersistenceManager [" +
				txObject.getPersistenceManagerHolder().getPersistenceManager() + "]");
	}
	try {
		Transaction tx = txObject.getPersistenceManagerHolder().getPersistenceManager().currentTransaction();
		if (tx.isActive()) {
			tx.rollback();
		}
	}
	catch (JDOException ex) {
		throw new TransactionSystemException("Could not roll back JDO transaction", ex);
	}
}
 
Example #2
Source File: JdoTransactionManager.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Override
protected void doCommit(DefaultTransactionStatus status) {
	JdoTransactionObject txObject = (JdoTransactionObject) status.getTransaction();
	if (status.isDebug()) {
		logger.debug("Committing JDO transaction on PersistenceManager [" +
				txObject.getPersistenceManagerHolder().getPersistenceManager() + "]");
	}
	try {
		Transaction tx = txObject.getPersistenceManagerHolder().getPersistenceManager().currentTransaction();
		tx.commit();
	}
	catch (JDOException ex) {
		// Assumably failed to flush changes to database.
		throw convertJdoAccessException(ex);
	}
}
 
Example #3
Source File: PersistenceManagerFactoryUtils.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Convert the given JDOException to an appropriate exception from the
 * {@code org.springframework.dao} hierarchy.
 * <p>The most important cases like object not found or optimistic locking failure
 * are covered here. For more fine-granular conversion, JdoTransactionManager
 * supports sophisticated translation of exceptions via a JdoDialect.
 * @param ex JDOException that occured
 * @return the corresponding DataAccessException instance
 * @see JdoTransactionManager#convertJdoAccessException
 * @see JdoDialect#translateException
 */
public static DataAccessException convertJdoAccessException(JDOException ex) {
	if (ex instanceof JDOObjectNotFoundException) {
		throw new JdoObjectRetrievalFailureException((JDOObjectNotFoundException) ex);
	}
	if (ex instanceof JDOOptimisticVerificationException) {
		throw new JdoOptimisticLockingFailureException((JDOOptimisticVerificationException) ex);
	}
	if (ex instanceof JDODataStoreException) {
		return new JdoResourceFailureException((JDODataStoreException) ex);
	}
	if (ex instanceof JDOFatalDataStoreException) {
		return new JdoResourceFailureException((JDOFatalDataStoreException) ex);
	}
	if (ex instanceof JDOUserException) {
		return new JdoUsageException((JDOUserException) ex);
	}
	if (ex instanceof JDOFatalUserException) {
		return new JdoUsageException((JDOFatalUserException) ex);
	}
	// fallback
	return new JdoSystemException(ex);
}
 
Example #4
Source File: JdoTransactionManager.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@Override
protected void doCommit(DefaultTransactionStatus status) {
	JdoTransactionObject txObject = (JdoTransactionObject) status.getTransaction();
	if (status.isDebug()) {
		logger.debug("Committing JDO transaction on PersistenceManager [" +
				txObject.getPersistenceManagerHolder().getPersistenceManager() + "]");
	}
	try {
		Transaction tx = txObject.getPersistenceManagerHolder().getPersistenceManager().currentTransaction();
		tx.commit();
	}
	catch (JDOException ex) {
		// Assumably failed to flush changes to database.
		throw convertJdoAccessException(ex);
	}
}
 
Example #5
Source File: PersistenceManagerFactoryUtils.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
/**
 * Convert the given JDOException to an appropriate exception from the
 * {@code org.springframework.dao} hierarchy.
 * <p>The most important cases like object not found or optimistic locking failure
 * are covered here. For more fine-granular conversion, JdoTransactionManager
 * supports sophisticated translation of exceptions via a JdoDialect.
 * @param ex JDOException that occured
 * @return the corresponding DataAccessException instance
 * @see JdoTransactionManager#convertJdoAccessException
 * @see JdoDialect#translateException
 */
public static DataAccessException convertJdoAccessException(JDOException ex) {
	if (ex instanceof JDOObjectNotFoundException) {
		throw new JdoObjectRetrievalFailureException((JDOObjectNotFoundException) ex);
	}
	if (ex instanceof JDOOptimisticVerificationException) {
		throw new JdoOptimisticLockingFailureException((JDOOptimisticVerificationException) ex);
	}
	if (ex instanceof JDODataStoreException) {
		return new JdoResourceFailureException((JDODataStoreException) ex);
	}
	if (ex instanceof JDOFatalDataStoreException) {
		return new JdoResourceFailureException((JDOFatalDataStoreException) ex);
	}
	if (ex instanceof JDOUserException) {
		return new JdoUsageException((JDOUserException) ex);
	}
	if (ex instanceof JDOFatalUserException) {
		return new JdoUsageException((JDOFatalUserException) ex);
	}
	// fallback
	return new JdoSystemException(ex);
}
 
Example #6
Source File: JdoTransactionManager.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@Override
protected void doRollback(DefaultTransactionStatus status) {
	JdoTransactionObject txObject = (JdoTransactionObject) status.getTransaction();
	if (status.isDebug()) {
		logger.debug("Rolling back JDO transaction on PersistenceManager [" +
				txObject.getPersistenceManagerHolder().getPersistenceManager() + "]");
	}
	try {
		Transaction tx = txObject.getPersistenceManagerHolder().getPersistenceManager().currentTransaction();
		if (tx.isActive()) {
			tx.rollback();
		}
	}
	catch (JDOException ex) {
		throw new TransactionSystemException("Could not roll back JDO transaction", ex);
	}
}
 
Example #7
Source File: LocalPersistenceManagerFactoryBean.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * Implementation of the PersistenceExceptionTranslator interface,
 * as autodetected by Spring's PersistenceExceptionTranslationPostProcessor.
 * <p>Converts the exception if it is a JDOException, preferably using a specified
 * JdoDialect. Else returns {@code null} to indicate an unknown exception.
 * @see org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor
 * @see JdoDialect#translateException
 * @see PersistenceManagerFactoryUtils#convertJdoAccessException
 */
@Override
public DataAccessException translateExceptionIfPossible(RuntimeException ex) {
	if (ex instanceof JDOException) {
		if (this.jdoDialect != null) {
			return this.jdoDialect.translateException((JDOException) ex);
		}
		else {
			return PersistenceManagerFactoryUtils.convertJdoAccessException((JDOException) ex);
		}
	}
	return null;
}
 
Example #8
Source File: PersistenceManagerFactoryUtils.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void flushResource(PersistenceManagerHolder resourceHolder) {
	try {
		resourceHolder.getPersistenceManager().flush();
	}
	catch (JDOException ex) {
		throw convertJdoAccessException(ex);
	}
}
 
Example #9
Source File: JdoTransactionManager.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void flush() {
	try {
		this.persistenceManagerHolder.getPersistenceManager().flush();
	}
	catch (JDOException ex) {
		throw convertJdoAccessException(ex);
	}
}
 
Example #10
Source File: DefaultJdoDialect.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * This implementation invokes the standard JDO {@link Transaction#begin()}
 * method and also {@link Transaction#setIsolationLevel(String)} if necessary.
 * @see javax.jdo.Transaction#begin
 * @see org.springframework.transaction.InvalidIsolationLevelException
 */
@Override
public Object beginTransaction(Transaction transaction, TransactionDefinition definition)
		throws JDOException, SQLException, TransactionException {

	String jdoIsolationLevel = getJdoIsolationLevel(definition);
	if (jdoIsolationLevel != null) {
		transaction.setIsolationLevel(jdoIsolationLevel);
	}
	transaction.begin();
	return null;
}
 
Example #11
Source File: DefaultJdoDialect.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * This implementation delegates to PersistenceManagerFactoryUtils.
 * @see PersistenceManagerFactoryUtils#convertJdoAccessException
 */
@Override
public DataAccessException translateException(JDOException ex) {
	if (getJdbcExceptionTranslator() != null && ex.getCause() instanceof SQLException) {
		return getJdbcExceptionTranslator().translate("JDO operation: " + ex.getMessage(),
				extractSqlStringFromException(ex), (SQLException) ex.getCause());
	}
	return PersistenceManagerFactoryUtils.convertJdoAccessException(ex);
}
 
Example #12
Source File: LocalPersistenceManagerFactoryBean.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * Initialize the PersistenceManagerFactory for the given location.
 * @throws IllegalArgumentException in case of illegal property values
 * @throws IOException if the properties could not be loaded from the given location
 * @throws JDOException in case of JDO initialization errors
 */
@Override
public void afterPropertiesSet() throws IllegalArgumentException, IOException, JDOException {
	if (this.persistenceManagerFactoryName != null) {
		if (this.configLocation != null || !this.jdoPropertyMap.isEmpty()) {
			throw new IllegalStateException("'configLocation'/'jdoProperties' not supported in " +
					"combination with 'persistenceManagerFactoryName' - specify one or the other, not both");
		}
		if (logger.isInfoEnabled()) {
			logger.info("Building new JDO PersistenceManagerFactory for name '" +
					this.persistenceManagerFactoryName + "'");
		}
		this.persistenceManagerFactory = newPersistenceManagerFactory(this.persistenceManagerFactoryName);
	}

	else {
		Map<String, Object> mergedProps = new HashMap<String, Object>();
		if (this.configLocation != null) {
			if (logger.isInfoEnabled()) {
				logger.info("Loading JDO config from [" + this.configLocation + "]");
			}
			CollectionUtils.mergePropertiesIntoMap(
					PropertiesLoaderUtils.loadProperties(this.configLocation), mergedProps);
		}
		mergedProps.putAll(this.jdoPropertyMap);
		logger.info("Building new JDO PersistenceManagerFactory");
		this.persistenceManagerFactory = newPersistenceManagerFactory(mergedProps);
	}

	// Build default JdoDialect if none explicitly specified.
	if (this.jdoDialect == null) {
		this.jdoDialect = new DefaultJdoDialect(this.persistenceManagerFactory.getConnectionFactory());
	}
}
 
Example #13
Source File: DefaultJdoDialect.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * This implementation invokes the standard JDO {@link Transaction#begin()}
 * method and also {@link Transaction#setIsolationLevel(String)} if necessary.
 * @see javax.jdo.Transaction#begin
 * @see org.springframework.transaction.InvalidIsolationLevelException
 */
@Override
public Object beginTransaction(Transaction transaction, TransactionDefinition definition)
		throws JDOException, SQLException, TransactionException {

	String jdoIsolationLevel = getJdoIsolationLevel(definition);
	if (jdoIsolationLevel != null) {
		transaction.setIsolationLevel(jdoIsolationLevel);
	}
	transaction.begin();
	return null;
}
 
Example #14
Source File: PersistenceManagerFactoryUtils.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * Obtain a JDO PersistenceManager via the given factory. Is aware of a
 * corresponding PersistenceManager bound to the current thread,
 * for example when using JdoTransactionManager. Will create a new
 * PersistenceManager else, if "allowCreate" is {@code true}.
 * <p>Same as {@code getPersistenceManager}, but throwing the original JDOException.
 * @param pmf PersistenceManagerFactory to create the PersistenceManager with
 * @param allowCreate if a non-transactional PersistenceManager should be created
 * when no transactional PersistenceManager can be found for the current thread
 * @return the PersistenceManager
 * @throws JDOException if the PersistenceManager couldn't be created
 * @throws IllegalStateException if no thread-bound PersistenceManager found and
 * "allowCreate" is {@code false}
 * @see #getPersistenceManager(javax.jdo.PersistenceManagerFactory, boolean)
 * @see JdoTransactionManager
 */
public static PersistenceManager doGetPersistenceManager(PersistenceManagerFactory pmf, boolean allowCreate)
	throws JDOException, IllegalStateException {

	Assert.notNull(pmf, "No PersistenceManagerFactory specified");

	PersistenceManagerHolder pmHolder =
			(PersistenceManagerHolder) TransactionSynchronizationManager.getResource(pmf);
	if (pmHolder != null) {
		if (!pmHolder.isSynchronizedWithTransaction() &&
				TransactionSynchronizationManager.isSynchronizationActive()) {
			pmHolder.setSynchronizedWithTransaction(true);
			TransactionSynchronizationManager.registerSynchronization(
					new PersistenceManagerSynchronization(pmHolder, pmf, false));
		}
		return pmHolder.getPersistenceManager();
	}

	if (!allowCreate && !TransactionSynchronizationManager.isSynchronizationActive()) {
		throw new IllegalStateException("No JDO PersistenceManager bound to thread, " +
				"and configuration does not allow creation of non-transactional one here");
	}

	logger.debug("Opening JDO PersistenceManager");
	PersistenceManager pm = pmf.getPersistenceManager();

	if (TransactionSynchronizationManager.isSynchronizationActive()) {
		logger.debug("Registering transaction synchronization for JDO PersistenceManager");
		// Use same PersistenceManager for further JDO actions within the transaction.
		// Thread object will get removed by synchronization at transaction completion.
		pmHolder = new PersistenceManagerHolder(pm);
		pmHolder.setSynchronizedWithTransaction(true);
		TransactionSynchronizationManager.registerSynchronization(
				new PersistenceManagerSynchronization(pmHolder, pmf, true));
		TransactionSynchronizationManager.bindResource(pmf, pmHolder);
	}

	return pm;
}
 
Example #15
Source File: PersistenceManagerFactoryUtils.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * Apply the current transaction timeout, if any, to the given JDO Query object.
 * @param query the JDO Query object
 * @param pmf JDO PersistenceManagerFactory that the Query was created for
 * @throws JDOException if thrown by JDO methods
 */
public static void applyTransactionTimeout(Query query, PersistenceManagerFactory pmf) throws JDOException {
	Assert.notNull(query, "No Query object specified");
	PersistenceManagerHolder pmHolder =
			(PersistenceManagerHolder) TransactionSynchronizationManager.getResource(pmf);
	if (pmHolder != null && pmHolder.hasTimeout() &&
			pmf.supportedOptions().contains("javax.jdo.option.DatastoreTimeout")) {
		int timeout = (int) pmHolder.getTimeToLiveInMillis();
		query.setDatastoreReadTimeoutMillis(timeout);
		query.setDatastoreWriteTimeoutMillis(timeout);
	}
}
 
Example #16
Source File: PersistenceManagerFactoryUtils.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * Actually release a PersistenceManager for the given factory.
 * Same as {@code releasePersistenceManager}, but throwing the original JDOException.
 * @param pm PersistenceManager to close
 * @param pmf PersistenceManagerFactory that the PersistenceManager was created with
 * (can be {@code null})
 * @throws JDOException if thrown by JDO methods
 */
public static void doReleasePersistenceManager(PersistenceManager pm, PersistenceManagerFactory pmf)
		throws JDOException {

	if (pm == null) {
		return;
	}
	// Only release non-transactional PersistenceManagers.
	if (!isPersistenceManagerTransactional(pm, pmf)) {
		logger.debug("Closing JDO PersistenceManager");
		pm.close();
	}
}
 
Example #17
Source File: PersistenceManagerFactoryUtils.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
public void flushResource(PersistenceManagerHolder resourceHolder) {
	try {
		resourceHolder.getPersistenceManager().flush();
	}
	catch (JDOException ex) {
		throw convertJdoAccessException(ex);
	}
}
 
Example #18
Source File: JdoTransactionManager.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
public void flush() {
	try {
		this.persistenceManagerHolder.getPersistenceManager().flush();
	}
	catch (JDOException ex) {
		throw convertJdoAccessException(ex);
	}
}
 
Example #19
Source File: PersistenceManagerFactoryUtils.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Apply the current transaction timeout, if any, to the given JDO Query object.
 * @param query the JDO Query object
 * @param pmf JDO PersistenceManagerFactory that the Query was created for
 * @throws JDOException if thrown by JDO methods
 */
public static void applyTransactionTimeout(Query query, PersistenceManagerFactory pmf) throws JDOException {
	Assert.notNull(query, "No Query object specified");
	PersistenceManagerHolder pmHolder =
			(PersistenceManagerHolder) TransactionSynchronizationManager.getResource(pmf);
	if (pmHolder != null && pmHolder.hasTimeout() &&
			pmf.supportedOptions().contains("javax.jdo.option.DatastoreTimeout")) {
		int timeout = (int) pmHolder.getTimeToLiveInMillis();
		query.setDatastoreReadTimeoutMillis(timeout);
		query.setDatastoreWriteTimeoutMillis(timeout);
	}
}
 
Example #20
Source File: PersistenceManagerFactoryUtils.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Obtain a JDO PersistenceManager via the given factory. Is aware of a
 * corresponding PersistenceManager bound to the current thread,
 * for example when using JdoTransactionManager. Will create a new
 * PersistenceManager else, if "allowCreate" is {@code true}.
 * <p>Same as {@code getPersistenceManager}, but throwing the original JDOException.
 * @param pmf PersistenceManagerFactory to create the PersistenceManager with
 * @param allowCreate if a non-transactional PersistenceManager should be created
 * when no transactional PersistenceManager can be found for the current thread
 * @return the PersistenceManager
 * @throws JDOException if the PersistenceManager couldn't be created
 * @throws IllegalStateException if no thread-bound PersistenceManager found and
 * "allowCreate" is {@code false}
 * @see #getPersistenceManager(javax.jdo.PersistenceManagerFactory, boolean)
 * @see JdoTransactionManager
 */
public static PersistenceManager doGetPersistenceManager(PersistenceManagerFactory pmf, boolean allowCreate)
	throws JDOException, IllegalStateException {

	Assert.notNull(pmf, "No PersistenceManagerFactory specified");

	PersistenceManagerHolder pmHolder =
			(PersistenceManagerHolder) TransactionSynchronizationManager.getResource(pmf);
	if (pmHolder != null) {
		if (!pmHolder.isSynchronizedWithTransaction() &&
				TransactionSynchronizationManager.isSynchronizationActive()) {
			pmHolder.setSynchronizedWithTransaction(true);
			TransactionSynchronizationManager.registerSynchronization(
					new PersistenceManagerSynchronization(pmHolder, pmf, false));
		}
		return pmHolder.getPersistenceManager();
	}

	if (!allowCreate && !TransactionSynchronizationManager.isSynchronizationActive()) {
		throw new IllegalStateException("No JDO PersistenceManager bound to thread, " +
				"and configuration does not allow creation of non-transactional one here");
	}

	logger.debug("Opening JDO PersistenceManager");
	PersistenceManager pm = pmf.getPersistenceManager();

	if (TransactionSynchronizationManager.isSynchronizationActive()) {
		logger.debug("Registering transaction synchronization for JDO PersistenceManager");
		// Use same PersistenceManager for further JDO actions within the transaction.
		// Thread object will get removed by synchronization at transaction completion.
		pmHolder = new PersistenceManagerHolder(pm);
		pmHolder.setSynchronizedWithTransaction(true);
		TransactionSynchronizationManager.registerSynchronization(
				new PersistenceManagerSynchronization(pmHolder, pmf, true));
		TransactionSynchronizationManager.bindResource(pmf, pmHolder);
	}

	return pm;
}
 
Example #21
Source File: PersistenceManagerFactoryUtils.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Actually release a PersistenceManager for the given factory.
 * Same as {@code releasePersistenceManager}, but throwing the original JDOException.
 * @param pm PersistenceManager to close
 * @param pmf PersistenceManagerFactory that the PersistenceManager was created with
 * (can be {@code null})
 * @throws JDOException if thrown by JDO methods
 */
public static void doReleasePersistenceManager(PersistenceManager pm, PersistenceManagerFactory pmf)
		throws JDOException {

	if (pm == null) {
		return;
	}
	// Only release non-transactional PersistenceManagers.
	if (!isPersistenceManagerTransactional(pm, pmf)) {
		logger.debug("Closing JDO PersistenceManager");
		pm.close();
	}
}
 
Example #22
Source File: DefaultJdoDialect.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * This implementation delegates to PersistenceManagerFactoryUtils.
 * @see PersistenceManagerFactoryUtils#convertJdoAccessException
 */
@Override
public DataAccessException translateException(JDOException ex) {
	if (getJdbcExceptionTranslator() != null && ex.getCause() instanceof SQLException) {
		return getJdbcExceptionTranslator().translate("JDO operation: " + ex.getMessage(),
				extractSqlStringFromException(ex), (SQLException) ex.getCause());
	}
	return PersistenceManagerFactoryUtils.convertJdoAccessException(ex);
}
 
Example #23
Source File: LocalPersistenceManagerFactoryBean.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Initialize the PersistenceManagerFactory for the given location.
 * @throws IllegalArgumentException in case of illegal property values
 * @throws IOException if the properties could not be loaded from the given location
 * @throws JDOException in case of JDO initialization errors
 */
@Override
public void afterPropertiesSet() throws IllegalArgumentException, IOException, JDOException {
	if (this.persistenceManagerFactoryName != null) {
		if (this.configLocation != null || !this.jdoPropertyMap.isEmpty()) {
			throw new IllegalStateException("'configLocation'/'jdoProperties' not supported in " +
					"combination with 'persistenceManagerFactoryName' - specify one or the other, not both");
		}
		if (logger.isInfoEnabled()) {
			logger.info("Building new JDO PersistenceManagerFactory for name '" +
					this.persistenceManagerFactoryName + "'");
		}
		this.persistenceManagerFactory = newPersistenceManagerFactory(this.persistenceManagerFactoryName);
	}

	else {
		Map<String, Object> mergedProps = new HashMap<String, Object>();
		if (this.configLocation != null) {
			if (logger.isInfoEnabled()) {
				logger.info("Loading JDO config from [" + this.configLocation + "]");
			}
			CollectionUtils.mergePropertiesIntoMap(
					PropertiesLoaderUtils.loadProperties(this.configLocation), mergedProps);
		}
		mergedProps.putAll(this.jdoPropertyMap);
		logger.info("Building new JDO PersistenceManagerFactory");
		this.persistenceManagerFactory = newPersistenceManagerFactory(mergedProps);
	}

	// Build default JdoDialect if none explicitly specified.
	if (this.jdoDialect == null) {
		this.jdoDialect = new DefaultJdoDialect(this.persistenceManagerFactory.getConnectionFactory());
	}
}
 
Example #24
Source File: LocalPersistenceManagerFactoryBean.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Implementation of the PersistenceExceptionTranslator interface,
 * as autodetected by Spring's PersistenceExceptionTranslationPostProcessor.
 * <p>Converts the exception if it is a JDOException, preferably using a specified
 * JdoDialect. Else returns {@code null} to indicate an unknown exception.
 * @see org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor
 * @see JdoDialect#translateException
 * @see PersistenceManagerFactoryUtils#convertJdoAccessException
 */
@Override
public DataAccessException translateExceptionIfPossible(RuntimeException ex) {
	if (ex instanceof JDOException) {
		if (this.jdoDialect != null) {
			return this.jdoDialect.translateException((JDOException) ex);
		}
		else {
			return PersistenceManagerFactoryUtils.convertJdoAccessException((JDOException) ex);
		}
	}
	return null;
}
 
Example #25
Source File: JdoSystemException.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
public JdoSystemException(JDOException ex) {
	super(ex.getMessage(), ex);
}
 
Example #26
Source File: JdoSystemException.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
public JdoSystemException(JDOException ex) {
	super(ex.getMessage(), ex);
}
 
Example #27
Source File: DefaultJdoDialect.java    From lams with GNU General Public License v2.0 3 votes vote down vote up
/**
 * This implementation returns a DataStoreConnectionHandle for JDO.
 * <p><b>NOTE:</b> A JDO DataStoreConnection is always a wrapper,
 * never the native JDBC Connection. If you need access to the native JDBC
 * Connection (or the connection pool handle, to be unwrapped via a Spring
 * NativeJdbcExtractor), override this method to return the native
 * Connection through the corresponding vendor-specific mechanism.
 * <p>A JDO DataStoreConnection is only "borrowed" from the PersistenceManager:
 * it needs to be returned as early as possible. Effectively, JDO requires the
 * fetched Connection to be closed before continuing PersistenceManager work.
 * For this reason, the exposed ConnectionHandle eagerly releases its JDBC
 * Connection at the end of each JDBC data access operation (that is, on
 * {@code DataSourceUtils.releaseConnection}).
 * @see javax.jdo.PersistenceManager#getDataStoreConnection()
 * @see org.springframework.jdbc.support.nativejdbc.NativeJdbcExtractor
 * @see org.springframework.jdbc.datasource.DataSourceUtils#releaseConnection
 */
@Override
public ConnectionHandle getJdbcConnection(PersistenceManager pm, boolean readOnly)
		throws JDOException, SQLException {

	return new DataStoreConnectionHandle(pm);
}
 
Example #28
Source File: DefaultJdoDialect.java    From lams with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Implementation of the PersistenceExceptionTranslator interface,
 * as autodetected by Spring's PersistenceExceptionTranslationPostProcessor.
 * <p>Converts the exception if it is a JDOException, using this JdoDialect.
 * Else returns {@code null} to indicate an unknown exception.
 * @see org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor
 * @see #translateException
 */
@Override
public DataAccessException translateExceptionIfPossible(RuntimeException ex) {
	if (ex instanceof JDOException) {
		return translateException((JDOException) ex);
	}
	return null;
}
 
Example #29
Source File: PersistenceManagerFactoryUtils.java    From spring4-understanding with Apache License 2.0 3 votes vote down vote up
/**
 * Obtain a JDO PersistenceManager via the given factory. Is aware of a
 * corresponding PersistenceManager bound to the current thread,
 * for example when using JdoTransactionManager. Will create a new
 * PersistenceManager else, if "allowCreate" is {@code true}.
 * @param pmf PersistenceManagerFactory to create the PersistenceManager with
 * @param allowCreate if a non-transactional PersistenceManager should be created
 * when no transactional PersistenceManager can be found for the current thread
 * @return the PersistenceManager
 * @throws DataAccessResourceFailureException if the PersistenceManager couldn't be obtained
 * @throws IllegalStateException if no thread-bound PersistenceManager found and
 * "allowCreate" is {@code false}
 * @see JdoTransactionManager
 */
public static PersistenceManager getPersistenceManager(PersistenceManagerFactory pmf, boolean allowCreate)
	throws DataAccessResourceFailureException, IllegalStateException {

	try {
		return doGetPersistenceManager(pmf, allowCreate);
	}
	catch (JDOException ex) {
		throw new DataAccessResourceFailureException("Could not obtain JDO PersistenceManager", ex);
	}
}
 
Example #30
Source File: PersistenceManagerFactoryUtils.java    From lams with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Obtain a JDO PersistenceManager via the given factory. Is aware of a
 * corresponding PersistenceManager bound to the current thread,
 * for example when using JdoTransactionManager. Will create a new
 * PersistenceManager else, if "allowCreate" is {@code true}.
 * @param pmf PersistenceManagerFactory to create the PersistenceManager with
 * @param allowCreate if a non-transactional PersistenceManager should be created
 * when no transactional PersistenceManager can be found for the current thread
 * @return the PersistenceManager
 * @throws DataAccessResourceFailureException if the PersistenceManager couldn't be obtained
 * @throws IllegalStateException if no thread-bound PersistenceManager found and
 * "allowCreate" is {@code false}
 * @see JdoTransactionManager
 */
public static PersistenceManager getPersistenceManager(PersistenceManagerFactory pmf, boolean allowCreate)
	throws DataAccessResourceFailureException, IllegalStateException {

	try {
		return doGetPersistenceManager(pmf, allowCreate);
	}
	catch (JDOException ex) {
		throw new DataAccessResourceFailureException("Could not obtain JDO PersistenceManager", ex);
	}
}