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

net.java.ao.builder.dbpool.DbPoolDataSourceFactory Maven / Gradle / Ivy

Go to download

This is the full Active Objects library, if you don't know which one to use, you probably want this one.

The newest version!
package net.java.ao.builder.dbpool;

import net.java.ao.Disposable;
import net.java.ao.DisposableDataSource;
import net.java.ao.builder.ClassUtils;
import net.java.ao.builder.DataSourceFactory;
import net.java.ao.builder.DelegatingDisposableDataSourceHandler;
import snaq.db.DBPoolDataSource;

import java.sql.Driver;

public final class DbPoolDataSourceFactory implements DataSourceFactory {
    public DisposableDataSource getDataSource(Class driverClass, String url, String username, String password) {
        final DBPoolDataSource ds = new DBPoolDataSource();
        ds.setName("active-objects");
        ds.setDriverClassName(driverClass.getName());
        ds.setUrl(url);
        ds.setUsername(username);
        ds.setPassword(password);
        ds.setPoolSize(5);
        ds.setMaxSize(30);
        ds.setExpiryTime(3600);  // Specified in seconds.

        return DelegatingDisposableDataSourceHandler.newInstance(ds, new Disposable() {
            public void dispose() {
                ds.releaseConnectionPool();
            }
        });
    }

    public static boolean isAvailable() {
        return ClassUtils.loadClass("snaq.db.ConnectionPool") != null;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy