/** * Returns a {@link Database} that obtains {@link Connection}s on demand * from the given {@link ConnectionProvider}. When {@link Database#close()} * is called, {@link ConnectionProvider#close()} is called. * * @param cp * @return */ public static Database from(ConnectionProvider cp) { return new Database(cp); }
/** * Returns a {@link Database} based on a jdbc connection string. * * @param url * jdbc connection url * @return */ public static Database from(String url) { return new Database(url, null, null); }
/** * Factory method. Uses the single connection provided and current thread * scheduler (trampoline) to run all queries. The connection will not be * closed in reality though the log may indicate it as having received a * close call. * * @param con * the connection */ public static Database from(Connection con) { return new Database(con); }
/** * Returns a Database based on the current Database except all * non-transactional queries run on the scheduler provided by the given * factory. * * @return new Database instance */ public Database asynchronous(final Func0<Scheduler> nonTransactionalSchedulerFactory) { return new Database(cp, nonTransactionalSchedulerFactory); }
/** * Returns a {@link Database} based on a jdbc connection string. * * @param url * jdbc url * @param username * username for connection * @param password * password for connection * @return the database object */ public static Database from(String url, String username, String password) { return new Database(url, username, password); }
/** * Returns a {@link Database} based on connections obtained from a * {@link DataSource} based on looking up the current {@link Context} * * @param jndiResource * @return */ public static Database fromContext(String jndiResource) { return new Database(new ConnectionProviderFromContext(jndiResource)); }
/** * Returns a {@link Database} based on connections obtained from a * {@link DataSource} * * @param jndiResource * @return */ public static Database fromDataSource(DataSource dataSource) { return new Database(new ConnectionProviderFromDataSource(dataSource)); }
/** * Returns a {@link Database}. * * @return the constructed Database */ public Database build() { if (url != null && pool != null) { cp = new ConnectionProviderPooled(url, username, password, pool.minSize, pool.maxSize, pool.connectionTimeoutMs, configureDataSource); } else if (url != null) { Preconditions.checkArgument(configureDataSource == null, "cannot configure data source unless pool specified"); cp = new ConnectionProviderFromUrl(url, username, password); } return new Database(cp, nonTransactionalSchedulerFactory, resultSetTransform); } }