de.zalando.sprocwrapper.sharding.ShardedDataAccessException Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of zalando-sprocwrapper Show documentation
Show all versions of zalando-sprocwrapper Show documentation
Library to make PostgreSQL stored procedures available through simple Java "*SProcService" interfaces
including automatic object serialization and deserialization (using typemapper and
convention-over-configuration). Supports sharding, advisory locking, statement timeouts and PostgreSQL types
such as enums and hstore.
package de.zalando.sprocwrapper.sharding;
import java.util.Map;
import org.springframework.dao.DataAccessException;
import com.google.common.collect.ImmutableMap;
/**
* Signals that at an exception has occurred while executing the sproc on the shards.
*
* @author pribeiro
*/
public class ShardedDataAccessException extends DataAccessException {
private final Map causes;
/**
* Creates a {@code ShardedDataAccessException} with specified detail message and causes.
*
* @param msg the detail message
* @param causes the causes
*/
public ShardedDataAccessException(final String msg, final Map causes) {
super(msg);
// create an immutable map, no one should be able to change the causes.
// Performance hint. Pass an immutable map into the constructor, so no copy is performed at all
this.causes = (causes == null ? ImmutableMap.of() : ImmutableMap.copyOf(causes));
// add causes to new java 7 suppressed exceptions feature so we can see all nested exceptions in stacktrace
for (final Throwable cause : this.causes.values()) {
addSuppressed(cause);
}
}
/**
* Returns an immutable map with the shard id and respective cause.
*
* @return an immutable map with the shard id and respective cause
*/
public Map getCauses() {
return causes;
}
}