Search in sources :

Example 6 with PooledDb

use of com.icodici.db.PooledDb in project universa by UniversaBlockchain.

the class PostgresLedger method addNode.

@Override
public void addNode(NodeInfo nodeInfo) {
    try (PooledDb db = dbPool.db()) {
        String sqlText = "insert into config(http_client_port,http_server_port,udp_server_port, node_number, node_name, public_host,host,public_key) values(?,?,?,?,?,?,?,?);";
        try (PreparedStatement statement = db.statementReturningKeys(sqlText)) {
            statement.setInt(1, nodeInfo.getClientAddress().getPort());
            statement.setInt(2, nodeInfo.getServerAddress().getPort());
            statement.setInt(3, nodeInfo.getNodeAddress().getPort());
            statement.setInt(4, nodeInfo.getNumber());
            statement.setString(5, nodeInfo.getName());
            statement.setString(6, nodeInfo.getPublicHost());
            statement.setString(7, nodeInfo.getClientAddress().getHostName());
            statement.setBytes(8, nodeInfo.getPublicKey().pack());
            db.updateWithStatement(statement);
        } catch (Exception e) {
            e.printStackTrace();
            throw e;
        }
    } catch (SQLException se) {
        se.printStackTrace();
        throw new Failure("add node failed:" + se);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : PooledDb(com.icodici.db.PooledDb) SQLException(java.sql.SQLException) PreparedStatement(java.sql.PreparedStatement) SQLException(java.sql.SQLException)

Aggregations

PooledDb (com.icodici.db.PooledDb)6 SQLException (java.sql.SQLException)6 PreparedStatement (java.sql.PreparedStatement)4 NodeInfo (com.icodici.universa.node2.NodeInfo)2 ResultSet (java.sql.ResultSet)2 PrivateKey (com.icodici.crypto.PrivateKey)1 Contract (com.icodici.universa.contract.Contract)1 NetConfig (com.icodici.universa.node2.NetConfig)1