All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.vladmihalcea.flexypool.adaptor.AtomikosPoolAdapter Maven / Gradle / Ivy

There is a newer version: 2.2.3
Show newest version
package com.vladmihalcea.flexypool.adaptor;

import com.atomikos.jdbc.AbstractDataSourceBean;
import com.atomikos.jdbc.AtomikosSQLException;
import com.vladmihalcea.flexypool.common.ConfigurationProperties;
import com.vladmihalcea.flexypool.metric.Metrics;

/**
 * AtomikosPoolAdapter extends {@link AbstractPoolAdapter} and it adapts the required API to
 * communicate with the {@link AbstractDataSourceBean Atomikos DataSourceBean}
 *
 * @author Vlad Mihalcea
 * @since 1.2.1
 */
public class AtomikosPoolAdapter extends AbstractPoolAdapter {

    public static final String ACQUIRE_TIMEOUT_MESSAGE = "Connection pool exhausted - try increasing 'maxPoolSize' and/or 'borrowConnectionTimeout' on the DataSourceBean.";

    /**
     * Singleton factory object reference
     */
    public static final PoolAdapterFactory FACTORY = new PoolAdapterFactory() {

        @Override
        public PoolAdapter newInstance(
                ConfigurationProperties> configurationProperties) {
            return new AtomikosPoolAdapter(configurationProperties);
        }
    };

    /**
     * Init constructor
     */
    public AtomikosPoolAdapter(ConfigurationProperties> configurationProperties) {
        super(configurationProperties);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public int getMaxPoolSize() {
        return getTargetDataSource().getMaxPoolSize();
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public void setMaxPoolSize(int maxPoolSize) {
        getTargetDataSource().setMaxPoolSize(maxPoolSize);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    protected boolean isAcquireTimeoutException(Exception e) {
        if (e instanceof AtomikosSQLException) {
            AtomikosSQLException atomikosSQLException = (AtomikosSQLException) e;
            return atomikosSQLException.getMessage() != null &&
                ACQUIRE_TIMEOUT_MESSAGE.equals(atomikosSQLException.getMessage());
        }
        return false;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy