001package io.ebean.datasource; 002 003/** 004 * Factory that creates DataSourcePool's. 005 * 006 * <pre>{@code 007 * 008 * DataSourceFactory factory = DataSourceFactory.get(); 009 * 010 * DataSourceConfig config = new DataSourceConfig(); 011 * config.setDriver("org.h2.Driver"); 012 * config.setUrl("jdbc:h2:mem:tests2"); 013 * config.setUsername("sa"); 014 * config.setPassword(""); 015 * 016 * DataSourcePool pool = factory.createPool("test", config); 017 * 018 * Connection connection = pool.getConnection(); 019 * 020 * }</pre> 021 */ 022public interface DataSourceFactory { 023 024 /** 025 * Create the DataSourcePool given the name and configuration. 026 */ 027 static DataSourcePool create(String name, DataSourceConfig config) { 028 return get().createPool(name, config); 029 } 030 031 /** 032 * Return the DataSourceFactory. 033 * <p> 034 * The implementation is obtained via standard service loader mechanism requiring an 035 * implementation to be in the classpath. 036 * </p> 037 */ 038 static DataSourceFactory get() { 039 return DSManager.get(); 040 } 041 042 /** 043 * Create the DataSourcePool with the given configuration. 044 * 045 * @param name The name of the pool. 046 * @param config The configuration options. 047 * @return The created DataSourcePool 048 */ 049 DataSourcePool createPool(String name, DataSourceConfig config); 050}