use of java.sql.Statement in project databus by linkedin.
the class BootstrapDBSeeder method endSeeding.
/*
* Callback for processing end of Seeding
*/
public void endSeeding() {
//Copy seeder state to producer and applier state
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
long minScn = -1;
try {
String sql = getMinSCNSeederQuery();
conn = getConnection();
stmt = conn.createStatement();
LOG.info("Executing Min startSCN Query in Bootstrap DB:" + sql);
rs = stmt.executeQuery(sql);
rs.next();
minScn = rs.getLong(1);
LOG.info("Minimum startSCN of all the sources which were seeded was :" + minScn);
updateBootstrapStateTable(minScn, "bootstrap_applier_state");
updateBootstrapStateTable(minScn, "bootstrap_producer_state");
createLogTableRows();
// Go to the next bootstrap state for this Source
setBootstrapSourceStatus(BootstrapProducerStatus.SEEDING_CATCHUP);
conn.commit();
} catch (SQLException sqlEx) {
LOG.error("Got Exception while updating bootstrap state tables", sqlEx);
try {
conn.rollback();
} catch (Exception ex) {
LOG.error("Error while rolling back ...", ex);
}
throw new RuntimeException(sqlEx);
} catch (Exception e) {
throw new RuntimeException(e);
} finally {
DBHelper.close(rs, stmt, null);
}
}
use of java.sql.Statement in project databus by linkedin.
the class BootstrapProducerCallback method initWindowScn.
private void initWindowScn() throws SQLException {
ResultSet rs = null;
StringBuilder sql = new StringBuilder();
Statement stmt = null;
try {
sql.append("select max(p.windowscn), max(s.endscn) from bootstrap_producer_state p, bootstrap_seeder_state s ");
sql.append("where p.srcid = s.srcid and p.srcid in (");
int count = _trackedSources.size();
for (SourceInfo srcInfo : _trackedSources.values()) {
count--;
sql.append(srcInfo.getSrcId());
if (count > 0)
sql.append(",");
}
sql.append(")");
stmt = getConnection().createStatement();
LOG.info("sql query = " + sql.toString());
rs = stmt.executeQuery(sql.toString());
if (rs.next()) {
_producerStartScn = _oldWindowScn = _newWindowScn = rs.getLong(1);
_seedCatchupScn = rs.getLong(2);
}
} catch (SQLException e) {
if (null != _statsCollector)
_statsCollector.registerSQLException();
LOG.error("Unable to select producer's max windowscn. Setting windowscn to -1", e);
_oldWindowScn = -1;
_newWindowScn = -1;
_producerStartScn = -1;
throw e;
} finally {
DBHelper.close(rs, stmt, null);
}
}
use of java.sql.Statement in project databus by linkedin.
the class BootstrapProducerCallback method getLastLogEntry.
private int getLastLogEntry(String source) throws SQLException {
int rid = 0;
Statement stmt = null;
ResultSet rs = null;
int srcId = _trackedSources.get(source).getSrcId();
try {
stmt = getConnection().createStatement();
rs = stmt.executeQuery("select max(id) from " + getTableName(srcId));
if (rs.next()) {
rid = rs.getInt(1);
}
} catch (SQLException e) {
LOG.error("Unable to find max. rid. Setting current rid to -1", e);
rid = -1;
throw e;
} finally {
if (null != stmt) {
stmt.close();
stmt = null;
}
if (null != rs) {
rs.close();
rs = null;
}
}
return rid;
}
use of java.sql.Statement in project h2o-3 by h2oai.
the class TestCaseResult method saveToAccuracyTable.
public void saveToAccuracyTable(Connection conn) throws Exception {
String sql = makeSQLCmd();
Statement statement = conn.createStatement();
statement.executeUpdate(sql);
AccuracyTestingSuite.summaryLog.println("Successfully executed the following sql statement: " + sql);
}
use of java.sql.Statement in project gephi by gephi.
the class ImporterEdgeList method getEdges.
private void getEdges(Connection connection) throws SQLException {
//Factory
ElementDraft.Factory factory = container.factory();
//Properties
PropertiesAssociations properties = database.getPropertiesAssociations();
Statement s = connection.createStatement();
ResultSet rs = null;
try {
rs = s.executeQuery(database.getEdgeQuery());
} catch (SQLException ex) {
report.logIssue(new Issue("Failed to execute Edge query", Issue.Level.SEVERE, ex));
return;
}
findEdgeAttributesColumns(rs);
ResultSetMetaData metaData = rs.getMetaData();
int columnsCount = metaData.getColumnCount();
while (rs.next()) {
String id = null;
for (int i = 0; i < columnsCount; i++) {
String columnName = metaData.getColumnLabel(i + 1);
EdgeProperties p = properties.getEdgeProperty(columnName);
if (p != null && p.equals(EdgeProperties.ID)) {
String ide = rs.getString(i + 1);
if (ide != null) {
id = ide;
}
}
}
EdgeDraft edge;
if (id != null) {
edge = factory.newEdgeDraft(id);
} else {
edge = factory.newEdgeDraft();
}
for (int i = 0; i < columnsCount; i++) {
String columnName = metaData.getColumnLabel(i + 1);
EdgeProperties p = properties.getEdgeProperty(columnName);
if (p != null) {
injectEdgeProperty(p, rs, i + 1, edge);
} else {
//Inject edge attributes
ColumnDraft col = container.getEdgeColumn(columnName);
injectElementAttribute(rs, i + 1, col, edge);
}
}
injectTimeIntervalProperty(edge);
container.addEdge(edge);
}
rs.close();
s.close();
}
Aggregations