Search in sources :

Example 61 with Statement

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);
    }
}
Also used : SQLException(java.sql.SQLException) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) InvalidEventException(com.linkedin.databus.core.InvalidEventException) SQLException(java.sql.SQLException) KeyTypeNotImplementedException(com.linkedin.databus.core.KeyTypeNotImplementedException)

Example 62 with Statement

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);
    }
}
Also used : SourceInfo(com.linkedin.databus.bootstrap.common.SourceInfo) SQLException(java.sql.SQLException) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) ResultSet(java.sql.ResultSet)

Example 63 with Statement

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;
}
Also used : SQLException(java.sql.SQLException) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) ResultSet(java.sql.ResultSet)

Example 64 with Statement

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);
}
Also used : Statement(java.sql.Statement)

Example 65 with Statement

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();
}
Also used : ColumnDraft(org.gephi.io.importer.api.ColumnDraft) Issue(org.gephi.io.importer.api.Issue) SQLException(java.sql.SQLException) ElementDraft(org.gephi.io.importer.api.ElementDraft) PropertiesAssociations(org.gephi.io.importer.api.PropertiesAssociations) Statement(java.sql.Statement) ResultSetMetaData(java.sql.ResultSetMetaData) EdgeDraft(org.gephi.io.importer.api.EdgeDraft) ResultSet(java.sql.ResultSet) EdgeProperties(org.gephi.io.importer.api.PropertiesAssociations.EdgeProperties)

Aggregations

Statement (java.sql.Statement)3054 Connection (java.sql.Connection)1634 ResultSet (java.sql.ResultSet)1631 SQLException (java.sql.SQLException)1529 PreparedStatement (java.sql.PreparedStatement)1329 Test (org.junit.Test)570 ArrayList (java.util.ArrayList)323 CallableStatement (java.sql.CallableStatement)135 ResultSetMetaData (java.sql.ResultSetMetaData)127 IOException (java.io.IOException)121 Properties (java.util.Properties)114 HashMap (java.util.HashMap)83 PhoenixConnection (org.apache.phoenix.jdbc.PhoenixConnection)81 DruidPooledStatement (com.alibaba.druid.pool.DruidPooledStatement)71 StringPlus (mom.trd.opentheso.bdd.tools.StringPlus)63 DataSource (javax.sql.DataSource)62 SQLFeatureNotSupportedException (java.sql.SQLFeatureNotSupportedException)61 Vector (java.util.Vector)61 DatabaseMetaData (java.sql.DatabaseMetaData)53 KeyValue (org.vcell.util.document.KeyValue)49