/** * Creates the data source based on a `Config` instance. * * @param config * the config * @return the data source instance */ public static DataSource<PreparedStatement, Row> fromConfig(final Config config) { return create(io.trane.ndbc.DataSource.fromConfig(config)); }
@Override public <T> Future<T> transactional(final Supplier<Future<T>> supplier) { return underlying.transactional(supplier); }
@Test public void transactionDBFailure() throws CheckedFutureException { final PreparedStatement ps = PreparedStatement.create("DELETE FROM INVALID_TABLE WHERE s = ?").setString("s"); ds.transactional(() -> ds.execute(ps)).join(timeout); final Iterator<Row> rows = ds.query("SELECT * FROM " + table).get(timeout).iterator(); assertTrue(rows.hasNext()); }
@Override public Config config() { return underlying.config(); } }
@Override public Future<Void> close() { return underlying.close(); }
@Test public void simpleQueryInvalid() throws CheckedFutureException { try { ds.query("SLCT * FROM " + table).get(timeout); assertTrue(false); } catch (final NdbcException ex) { } }
/** * Creates the data source based on a JDBC url. See `Config.fromJdbcUrl` for * more details. * * @param url * the JDBC url * @return the data source instance */ public static MysqlDataSource fromJdbcUrl(final String url) { return create(io.trane.ndbc.DataSource.fromJdbcUrl(url)); }
/** * Creates the data source based on system properties. See * `Config.fromSystemProperties` for more details. * * @param prefix * the configuration prefix * @return the data source instance */ public static DataSource<PreparedStatement, Row> fromSystemProperties(final String prefix) { return create(io.trane.ndbc.DataSource.fromSystemProperties(prefix)); }
/** * Creates the data source based on a `Properties` object. See * `Config.fromProperties` for more details. * * @param prefix * the configuration prefix * @param properties * the properties object * @return the data source instance */ public static DataSource<PreparedStatement, Row> fromProperties(final String prefix, final Properties properties) { return create(io.trane.ndbc.DataSource.fromProperties(prefix, properties)); }
/** * Creates the data source based on a properties file. See * `Config.fromPropertiesFile` for more details. * * @param prefix * the configuration prefix * @param fileName * the properties file path * @return the data source instance * @throws IOException * if the file can't read */ public static DataSource<PreparedStatement, Row> fromPropertiesFile(final String prefix, final String fileName) throws IOException { return create(io.trane.ndbc.DataSource.fromPropertiesFile(prefix, fileName)); }
@Test public void extendedExecuteDeleteNoParam() throws CheckedFutureException { final PreparedStatement ps = PreparedStatement.create("DELETE FROM " + table + " WHERE s = 's'"); assertEquals(ds.execute(ps).get(timeout).longValue(), 1L); final Iterator<Row> rows = ds.query("SELECT * FROM " + table).get(timeout).iterator(); assertFalse(rows.hasNext()); }
@Test public void transactionSuccess() throws CheckedFutureException { final PreparedStatement ps = PreparedStatement.create("DELETE FROM " + table + " WHERE s = ?").setString("s"); final long affectedRows = ds.transactional(() -> ds.execute(ps)).get(timeout); assertEquals(affectedRows, 1L); final Iterator<Row> rows = ds.query("SELECT * FROM " + table).get(timeout).iterator(); assertFalse(rows.hasNext()); }
public final Config config() { return underlying.config(); } }
@Override public Future<Void> close() { return underlying.close(); }
@Test public void extendedQueryNoParams() throws CheckedFutureException { final PreparedStatement ps = PreparedStatement.create("SELECT * FROM " + table); final Iterator<Row> rows = ds.query(ps).get(timeout).iterator(); assertEquals(rows.next().column(0).getString(), "s"); assertFalse(rows.hasNext()); }
@Test public void simpleExecuteInsertFailure() throws CheckedFutureException { try { ds.execute("INSERT INTO invalid_table VALUES ('u')").get(timeout); assertTrue(false); } catch (final NdbcException ex) { assertTrue(ex.getMessage().contains("invalid_table")); } }
/** * Creates the data source based on a JDBC url. See `Config.fromJdbcUrl` for * more details. * * @param url * the JDBC url * @return the data source instance */ public static DataSource<PreparedStatement, Row> fromJdbcUrl(final String url) { return create(io.trane.ndbc.DataSource.fromJdbcUrl(url)); }