Java Code Examples for org.springframework.dao.support.DataAccessUtils#translateIfNecessary()

The following examples show how to use org.springframework.dao.support.DataAccessUtils#translateIfNecessary() . 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: ReactivePersistenceExceptionTranslationInterceptor.java    From sdn-rx with Apache License 2.0 6 votes vote down vote up
@Override
public Object invoke(MethodInvocation mi) throws Throwable {

	// Invoke the method potentially returning a reactive type
	Object m = mi.proceed();

	PersistenceExceptionTranslator translator = getPersistenceExceptionTranslator();
	if (translator == null) {
		return m;
	} else {
		// Add the translation. Nothing will happen if no-one subscribe the reactive result.
		Function<RuntimeException, Throwable> errorMappingFunction =
			t -> t instanceof DataAccessException ? t : DataAccessUtils.translateIfNecessary(t, translator);
		if (m instanceof Mono) {
			return ((Mono<?>) m).onErrorMap(RuntimeException.class, errorMappingFunction);
		} else if (m instanceof Flux) {
			return ((Flux<?>) m).onErrorMap(RuntimeException.class, errorMappingFunction);
		} else {
			return m;
		}
	}
}
 
Example 2
Source File: JpaTransactionManager.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Override
public void flush() {
	try {
		getEntityManagerHolder().getEntityManager().flush();
	}
	catch (RuntimeException ex) {
		throw DataAccessUtils.translateIfNecessary(ex, getJpaDialect());
	}
}
 
Example 3
Source File: JpaTransactionManager.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
public void flush() {
	try {
		getEntityManagerHolder().getEntityManager().flush();
	}
	catch (RuntimeException ex) {
		throw DataAccessUtils.translateIfNecessary(ex, getJpaDialect());
	}
}
 
Example 4
Source File: JpaTransactionManager.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void flush() {
	try {
		this.entityManagerHolder.getEntityManager().flush();
	}
	catch (RuntimeException ex) {
		throw DataAccessUtils.translateIfNecessary(ex, getJpaDialect());
	}
}
 
Example 5
Source File: JpaTransactionManager.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
public void flush() {
	try {
		this.entityManagerHolder.getEntityManager().flush();
	}
	catch (RuntimeException ex) {
		throw DataAccessUtils.translateIfNecessary(ex, getJpaDialect());
	}
}