
de.zalando.sprocwrapper.dsprovider.ArrayDataSourceProvider 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.dsprovider;
import java.util.List;
import javax.sql.DataSource;
import com.google.common.collect.Lists;
/**
* @author jmussler
*/
public class ArrayDataSourceProvider implements DataSourceProvider {
private final DataSource[] dss;
public ArrayDataSourceProvider(final DataSource[] ds) {
dss = ds;
}
@Override
public int getDataSourceId(final int virtualShardId) {
return virtualShardId % dss.length;
}
@Override
public DataSource getDataSource(final int virtualShardId) {
return dss[virtualShardId % dss.length];
}
@Override
public List getDistinctShardIds() {
final List shardIds = Lists.newArrayListWithExpectedSize(dss.length);
for (int i = 0; i < dss.length; i++) {
shardIds.add(i);
}
return shardIds;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy