net.java.ao.builder.dbpool.DbPoolDataSourceFactory Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of activeobjects Show documentation
Show all versions of activeobjects Show documentation
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 extends Driver> 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;
}
}