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

org.mybatis.guice.datasource.dbcp.PerUserPoolDataSourceModule Maven / Gradle / Ivy

/*
 *    Copyright 2010 The myBatis Team
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */
package org.mybatis.guice.datasource.dbcp;

import java.lang.annotation.Annotation;
import java.util.Map;

import com.google.inject.AbstractModule;
import com.google.inject.Binder;
import com.google.inject.Provider;
import com.google.inject.Scopes;
import com.google.inject.TypeLiteral;

/**
 * @version $Id: PerUserPoolDataSourceModule.java 2242 2010-08-05 16:15:42Z simone.tripodi $
 */
public final class PerUserPoolDataSourceModule extends AbstractModule {

    private static final TypeLiteral> STRING_BOOLEAN_MAP = new TypeLiteral>(){};

    private static final TypeLiteral> STRING_INTEGER_MAP = new TypeLiteral>(){};

    private Class>> perUserDefaultAutoCommitProviderClass;

    private Class>> perUserDefaultReadOnlyProviderClass;

    private Class>> perUserDefaultTransactionIsolationProviderClass;

    private Class>> perUserMaxActiveProviderClass;

    private Class>> perUserMaxIdleProviderClass;

    private Class>> perUserMaxWaitProviderClass;

    @Override
    protected void configure() {
        doBind(this.binder(), this.perUserDefaultAutoCommitProviderClass, STRING_BOOLEAN_MAP, PerUserDefaultAutoCommit.class);
        doBind(this.binder(), this.perUserDefaultReadOnlyProviderClass, STRING_BOOLEAN_MAP, PerUserDefaultReadOnly.class);
        doBind(this.binder(), this.perUserDefaultTransactionIsolationProviderClass, STRING_INTEGER_MAP, PerUserDefaultTransactionIsolation.class);
        doBind(this.binder(), this.perUserMaxActiveProviderClass, STRING_INTEGER_MAP, PerUserMaxActive.class);
        doBind(this.binder(), this.perUserMaxIdleProviderClass, STRING_INTEGER_MAP, PerUserMaxIdle.class);
        doBind(this.binder(), this.perUserMaxWaitProviderClass, STRING_INTEGER_MAP, PerUserMaxWait.class);
    }

    private static  void doBind(Binder binder, Class> providerClass, TypeLiteral typeLiteral, Class annotation) {
        if (providerClass != null) {
            binder.bind(typeLiteral)
                  .annotatedWith(annotation)
                  .toProvider(providerClass)
                  .in(Scopes.SINGLETON);
        }
    }

    /**
     * @param perUserDefaultAutoCommitProviderClass the perUserDefaultAutoCommitProviderClass to set
     */
    public PerUserPoolDataSourceModule setPerUserDefaultAutoCommitProviderClass(
            Class>> perUserDefaultAutoCommitProviderClass) {
        this.perUserDefaultAutoCommitProviderClass = perUserDefaultAutoCommitProviderClass;
        return this;
    }

    /**
     * @param perUserDefaultReadOnlyProviderClass the perUserDefaultReadOnlyProviderClass to set
     */
    public PerUserPoolDataSourceModule setPerUserDefaultReadOnlyProviderClass(
            Class>> perUserDefaultReadOnlyProviderClass) {
        this.perUserDefaultReadOnlyProviderClass = perUserDefaultReadOnlyProviderClass;
        return this;
    }

    /**
     * @param perUserDefaultTransactionIsolationProviderClass the perUserDefaultTransactionIsolationProviderClass to set
     */
    public PerUserPoolDataSourceModule setPerUserDefaultTransactionIsolationProviderClass(
            Class>> perUserDefaultTransactionIsolationProviderClass) {
        this.perUserDefaultTransactionIsolationProviderClass = perUserDefaultTransactionIsolationProviderClass;
        return this;
    }

    /**
     * @param perUserMaxActiveProviderClass the perUserMaxActiveProviderClass to set
     */
    public PerUserPoolDataSourceModule setPerUserMaxActiveProviderClass(
            Class>> perUserMaxActiveProviderClass) {
        this.perUserMaxActiveProviderClass = perUserMaxActiveProviderClass;
        return this;
    }

    /**
     * @param perUserMaxIdleProviderClass the perUserMaxIdleProviderClass to set
     */
    public PerUserPoolDataSourceModule setPerUserMaxIdleProviderClass(
            Class>> perUserMaxIdleProviderClass) {
        this.perUserMaxIdleProviderClass = perUserMaxIdleProviderClass;
        return this;
    }

    /**
     * @param perUserMaxWaitProviderClass the perUserMaxWaitProviderClass to set
     */
    public PerUserPoolDataSourceModule setPerUserMaxWaitProviderClass(
            Class>> perUserMaxWaitProviderClass) {
        this.perUserMaxWaitProviderClass = perUserMaxWaitProviderClass;
        return this;
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy