private void fireUpdateQuery(long pmrId, long lastSeenPmrId) throws SQLException { updateStmt.setLong(1, lastSeenPmrId); updateStmt.setLong(2, pmrId); updateStmt.executeUpdate(); }
/** * Add an exception statement either as a batch or execute immediately if * batch updates are not supported. */ void updateExceptionStatement(PreparedStatement exceptionStatement, String txt, short i, long eventId) throws SQLException { exceptionStatement.setLong(1, eventId); exceptionStatement.setShort(2, i); exceptionStatement.setString(3, txt); if (cnxSupportsBatchUpdates) { exceptionStatement.addBatch(); } else { exceptionStatement.execute(); } }
/** * Delete undo log. * * @param xid the xid * @param branchId the branch id * @param conn the conn * @throws SQLException the sql exception */ public static void deleteUndoLog(String xid, long branchId, Connection conn) throws SQLException { PreparedStatement deletePST = conn.prepareStatement(DELETE_UNDO_LOG_SQL); deletePST.setLong(1, branchId); deletePST.setString(2, xid); deletePST.executeUpdate(); } }
private long getInsertedRowsCount(Connection connection, long rowId) throws SQLException, MissingBootstrapRowException { String sql = "select inserted_rows from `bootstrap` where id = ?"; PreparedStatement preparedStatement = connection.prepareStatement(sql); preparedStatement.setLong(1, rowId); ResultSet resultSet = preparedStatement.executeQuery(); if ( resultSet.next() ) { return resultSet.getLong(1); } else { throw new MissingBootstrapRowException(rowId); } }
private Long insertHeartbeat(Connection c, Long thisHeartbeat) throws SQLException, DuplicateProcessException { String heartbeatInsert = "insert into `heartbeats` set `heartbeat` = ?, `server_id` = ?, `client_id` = ?"; PreparedStatement s = c.prepareStatement(heartbeatInsert); s.setLong(1, thisHeartbeat); s.setLong(2, serverID); s.setString(3, clientID); try { s.execute(); return thisHeartbeat; } catch ( MySQLIntegrityConstraintViolationException e ) { throw new DuplicateProcessException("Found heartbeat row for client,position while trying to insert. Is another maxwell running?"); } }
private void setBootstrapRowToCompleted(int insertedRows, RowMap startBootstrapRow, Connection connection) throws SQLException, NoSuchElementException { String sql = "update `bootstrap` set is_complete=1, inserted_rows=?, completed_at=NOW() where id=?"; PreparedStatement preparedStatement = connection.prepareStatement(sql); preparedStatement.setInt(1, insertedRows); preparedStatement.setLong(2, ( Long ) startBootstrapRow.getData("id")); if ( preparedStatement.executeUpdate() == 0) { throw new NoSuchElementException(); } }
public Position getLatestFromAnyClient() throws SQLException { try ( Connection c = connectionPool.getConnection() ) { PreparedStatement s = c.prepareStatement("SELECT * from `positions` where server_id = ? ORDER BY last_heartbeat_read desc limit 1"); s.setLong(1, serverID); return positionFromResultSet(s.executeQuery()); } }
LOB_DATA + " WHERE BLOCK = ?"; PreparedStatement prep = prepare(sql); prep.setLong(1, block); ResultSet rs = prep.executeQuery(); if (!rs.next()) { throw DbException.get(ErrorCode.IO_EXCEPTION_1, "Missing lob entry, block: " + block)
public Iterator<DatabaseVersion> getDatabaseVersionsTo(String machineName, long maxLocalClientVersion) { try (PreparedStatement preparedStatement = getStatement("databaseversion.select.master.getDatabaseVersionsTo.sql")) { preparedStatement.setString(1, machineName); preparedStatement.setLong(2, maxLocalClientVersion); return new DatabaseVersionIterator(preparedStatement.executeQuery()); } catch (SQLException e) { throw new RuntimeException(e); } }
public void writeMultiChunks(Connection connection, long databaseVersionId, Collection<MultiChunkEntry> multiChunks) throws SQLException { for (MultiChunkEntry multiChunk : multiChunks) { PreparedStatement preparedStatement = getStatement(connection, "multichunk.insert.all.writeMultiChunks.sql"); preparedStatement.setString(1, multiChunk.getId().toString()); preparedStatement.setLong(2, databaseVersionId); preparedStatement.setLong(3, multiChunk.getSize()); preparedStatement.executeUpdate(); preparedStatement.close(); writeMultiChunkRefs(connection, multiChunk); } }
private void removeBootstrapRow(Connection connection, long rowId) throws SQLException { LOGGER.info("deleting bootstrap start row"); String sql = "delete from `bootstrap` where id = ?"; PreparedStatement preparedStatement = connection.prepareStatement(sql); preparedStatement.setLong(1, rowId); preparedStatement.execute(); }
private long insertBootstrapStartRow(Connection connection, String db, String table, String whereClause, String clientID,Long totalRows) throws SQLException { LOGGER.info("inserting bootstrap start row"); String sql = "insert into `bootstrap` (database_name, table_name, where_clause, total_rows, client_id) values(?, ?, ?, ?, ?)"; PreparedStatement preparedStatement = connection.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS); preparedStatement.setString(1, db); preparedStatement.setString(2, table); preparedStatement.setString(3, whereClause); preparedStatement.setLong(4, totalRows); preparedStatement.setString(5, clientID); preparedStatement.execute(); ResultSet generatedKeys = preparedStatement.getGeneratedKeys(); generatedKeys.next(); return generatedKeys.getLong(1); }
static void perform(Connection cxn, long id, String selections, boolean isBlacklist) throws SQLException { try (PreparedStatement ps = cxn.prepareStatement("UPDATE pipelineselections SET selections = NULL, version = ?, filters = ? WHERE id = ?")) { ps.setInt(1, SCHEMA); ps.setString(2, asJson(selections, isBlacklist)); ps.setLong(3, id); ps.executeUpdate(); } }
protected void insertProperties(Map<String, String> mergedMap, Connection connection, long eventId) throws SQLException { Set<String> propertiesKeys = mergedMap.keySet(); if (propertiesKeys.size() > 0) { PreparedStatement insertPropertiesStatement = null; try { insertPropertiesStatement = connection.prepareStatement(insertPropertiesSQL); for (String key : propertiesKeys) { String value = mergedMap.get(key); insertPropertiesStatement.setLong(1, eventId); insertPropertiesStatement.setString(2, key); insertPropertiesStatement.setString(3, value); if (cnxSupportsBatchUpdates) { insertPropertiesStatement.addBatch(); } else { insertPropertiesStatement.execute(); } } if (cnxSupportsBatchUpdates) { insertPropertiesStatement.executeBatch(); } } finally { closeStatement(insertPropertiesStatement); } } }
private void setBootstrapRowToStarted(RowMap startBootstrapRow, Connection connection) throws SQLException, NoSuchElementException { String sql = "update `bootstrap` set started_at=NOW() where id=?"; PreparedStatement preparedStatement = connection.prepareStatement(sql); preparedStatement.setLong(1, ( Long ) startBootstrapRow.getData("id")); if ( preparedStatement.executeUpdate() == 0) { throw new NoSuchElementException(); } }
@Ignore("require dev sandbox") @Test public void testPreparedStatementWithCubeData() throws SQLException { Driver driver = new Driver(); Properties info = new Properties(); info.put("user", "ADMIN"); info.put("password", "KYLIN"); Connection conn = driver.connect("jdbc:kylin://localhost:7070/default", info); PreparedStatement state = conn .prepareStatement("select cal_dt, count(*) from test_kylin_fact where seller_id=? group by cal_dt"); state.setLong(1, 10000001); ResultSet resultSet = state.executeQuery(); printResultSetMetaData(resultSet); printResultSet(resultSet); resultSet.close(); state.close(); conn.close(); }
private void writeVectorClock(Connection connection, long databaseVersionId, VectorClock vectorClock) throws SQLException { try (PreparedStatement preparedStatement = getStatement(connection, "databaseversion.insert.all.writeVectorClock.sql")) { for (Map.Entry<String, Long> vectorClockEntry : vectorClock.entrySet()) { preparedStatement.setLong(1, databaseVersionId); preparedStatement.setString(2, vectorClockEntry.getKey()); preparedStatement.setLong(3, vectorClockEntry.getValue()); preparedStatement.addBatch(); } preparedStatement.executeBatch(); } }
/** * no commit */ public void updateDirtyMultiChunksNewDatabaseId(long newDatabaseVersionId) { try (PreparedStatement preparedStatement = getStatement("multichunk.update.dirty.updateDirtyMultiChunksNewDatabaseId.sql")) { preparedStatement.setLong(1, newDatabaseVersionId); preparedStatement.executeUpdate(); } catch (SQLException e) { throw new RuntimeException(e); } }
@Override public void remove(List<Long> pks) { PreparedStatement statement = null; try { this.connection.setAutoCommit(false); statement = this.connection.prepareStatement("DELETE FROM t_transaction WHERE offset = ?"); for (long pk : pks) { statement.setLong(1, pk); statement.addBatch(); } int[] executeBatch = statement.executeBatch(); this.connection.commit(); } catch (Exception e) { log.warn("createDB Exception", e); } finally { if (null != statement) { try { statement.close(); } catch (SQLException e) { } } } }
private boolean getIsComplete(Connection connection, long rowId) throws SQLException, MissingBootstrapRowException { String sql = "select is_complete from `bootstrap` where id = ?"; PreparedStatement preparedStatement = connection.prepareStatement(sql); preparedStatement.setLong(1, rowId); ResultSet resultSet = preparedStatement.executeQuery(); if ( resultSet.next() ) { return resultSet.getInt(1) == 1; } else { throw new MissingBootstrapRowException(rowId); } }