use of org.xbib.elasticsearch.jdbc.strategy.Sink in project elasticsearch-jdbc by jprante.
the class StandardContext method createSink.
protected Sink createSink() throws IOException {
Sink sink = StrategyLoader.newSink(strategy());
logger.info("found sink class {}", sink);
return sink;
}
use of org.xbib.elasticsearch.jdbc.strategy.Sink in project elasticsearch-jdbc by jprante.
the class StandardContext method beforeFetch.
@Override
@SuppressWarnings("unchecked")
public void beforeFetch() throws Exception {
logger.debug("before fetch");
Sink sink = createSink();
S source = createSource();
prepareContext(source, sink);
sink.setContext(this);
source.setContext(this);
getSink().beforeFetch();
getSource().beforeFetch();
}
use of org.xbib.elasticsearch.jdbc.strategy.Sink in project elasticsearch-jdbc by jprante.
the class MockTests method testMockTimePeriod.
@Test
@Parameters({ "sql4" })
public void testMockTimePeriod(String sql) throws Exception {
List<Object> params = new LinkedList<Object>();
params.add("2012-06-10 00:00:00");
Sink output = new MockSink() {
@Override
public void index(IndexableObject object, boolean create) throws IOException {
logger.debug("object={}", object);
}
};
PreparedStatement statement = source.prepareQuery(sql);
source.bind(statement, params);
ResultSet results = source.executeQuery(statement);
StringKeyValueStreamListener listener = new StringKeyValueStreamListener().output(output);
source.beforeRows(results, listener);
long rows = 0L;
while (source.nextRow(results, listener)) {
rows++;
}
source.afterRows(results, listener);
assertEquals(rows, 3);
source.close(results);
source.close(statement);
}
use of org.xbib.elasticsearch.jdbc.strategy.Sink in project elasticsearch-jdbc by jprante.
the class MockTests method testMockBill.
@Test
@Parameters({ "sql1" })
public void testMockBill(String sql) throws Exception {
List<Object> params = new LinkedList<Object>();
Sink output = new MockSink() {
@Override
public void index(IndexableObject object, boolean create) throws IOException {
logger.debug("sql1 object={}", object);
}
};
PreparedStatement statement = source.prepareQuery(sql);
source.bind(statement, params);
ResultSet results = source.executeQuery(statement);
StringKeyValueStreamListener listener = new StringKeyValueStreamListener().output(output);
long rows = 0L;
source.beforeRows(results, listener);
while (source.nextRow(results, listener)) {
rows++;
}
source.afterRows(results, listener);
assertEquals(rows, 5);
source.close(results);
source.close(statement);
}
use of org.xbib.elasticsearch.jdbc.strategy.Sink in project elasticsearch-jdbc by jprante.
the class StandardSourceTests method testSimpleNullInteger.
@Test
@Parameters({ "sql3" })
public void testSimpleNullInteger(String sql) throws Exception {
List<Object> params = new LinkedList<Object>();
Sink sink = new MockSink() {
@Override
public void index(IndexableObject object, boolean create) throws IOException {
if (object == null || object.source() == null) {
throw new IllegalArgumentException("object missing");
}
Values o = (Values) object.source().get("amount");
if (o == null) {
// hsqldb is uppercase
o = (Values) object.source().get("AMOUNT");
}
if (!o.isNull()) {
throw new IllegalArgumentException("amount not null??? " + o.getClass().getName());
}
}
};
PreparedStatement statement = source.prepareQuery(sql);
source.bind(statement, params);
ResultSet results = source.executeQuery(statement);
StringKeyValueStreamListener listener = new StringKeyValueStreamListener().output(sink);
long rows = 0L;
source.beforeRows(results, listener);
if (source.nextRow(results, listener)) {
// only one row
rows++;
}
source.afterRows(results, listener);
assertEquals(rows, 1);
source.close(results);
source.close(statement);
}
Aggregations