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

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

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

import com.mchange.v2.c3p0.ComboPooledDataSource;
import com.vladmihalcea.flexypool.common.ConfigurationProperties;
import com.vladmihalcea.flexypool.metric.Metrics;

/**
 * C3P0PoolAdapter extends {@link AbstractPoolAdapter} and it adapts the required API to
 * communicate with the c3p0 {@link ComboPooledDataSource}
 *
 * @author Vlad Mihalcea
 * @since 1.0
 */
public class C3P0PoolAdapter extends AbstractPoolAdapter {

    public static final String ACQUIRE_TIMEOUT_MESSAGE = "An attempt by a client to checkout a Connection has timed out.";

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

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

    /**
     * Init constructor
     * @param configurationProperties configuration properties
     */
    public C3P0PoolAdapter(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) {
        return e.getMessage() != null && ACQUIRE_TIMEOUT_MESSAGE.equals(e.getMessage());
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy