@Override public void deleteSegments(final Set<DataSegment> segments) { connector.getDBI().inTransaction( new TransactionCallback<Void>() { @Override public Void inTransaction(Handle handle, TransactionStatus transactionStatus) { for (final DataSegment segment : segments) { deleteSegment(handle, segment); } return null; } } ); }
@Override public void updateSegmentMetadata(final Set<DataSegment> segments) { connector.getDBI().inTransaction( new TransactionCallback<Void>() { @Override public Void inTransaction(Handle handle, TransactionStatus transactionStatus) throws Exception { for (final DataSegment segment : segments) { updatePayload(handle, segment); } return null; } } ); }
public <T> T retryTransaction(final TransactionCallback<T> callback, final int quietTries, final int maxTries) { try { return RetryUtils.retry(() -> getDBI().inTransaction(TransactionIsolationLevel.READ_COMMITTED, callback), shouldRetry, quietTries, maxTries); } catch (Exception e) { throw Throwables.propagate(e); } }
return getDBI().inTransaction( new TransactionCallback<Void>()
return getDBI().inTransaction( new TransactionCallback<Boolean>()
@Override public boolean insertDataSourceMetadata(String dataSource, DataSourceMetadata metadata) { return 1 == connector.getDBI().inTransaction( (handle, status) -> handle .createStatement( StringUtils.format( "INSERT INTO %s (dataSource, created_date, commit_metadata_payload, commit_metadata_sha1) VALUES" + " (:dataSource, :created_date, :commit_metadata_payload, :commit_metadata_sha1)", dbTables.getDataSourceTable() ) ) .bind("dataSource", dataSource) .bind("created_date", DateTimes.nowUtc().toString()) .bind("commit_metadata_payload", jsonMapper.writeValueAsBytes(metadata)) .bind("commit_metadata_sha1", BaseEncoding.base16().encode( Hashing.sha1().hashBytes(jsonMapper.writeValueAsBytes(metadata)).asBytes())) .execute() ); } }
@Override public int deletePendingSegments(String dataSource, Interval deleteInterval) { return connector.getDBI().inTransaction( (handle, status) -> handle .createStatement( StringUtils.format( "delete from %s where datasource = :dataSource and created_date >= :start and created_date < :end", dbTables.getPendingSegmentsTable() ) ) .bind("dataSource", dataSource) .bind("start", deleteInterval.getStart().toString()) .bind("end", deleteInterval.getEnd().toString()) .execute() ); }
Configuration conf, DataSegmentPusher dataSegmentPusher) throws CallbackFailedException { return connector.getDBI().inTransaction((handle, transactionStatus) -> {
@PostConstruct public void setup() { dbi.inTransaction((Handle handle, TransactionStatus transactionStatus) -> { handle.createStatement("CREATE TABLE IF NOT EXISTS project (" + " name TEXT NOT NULL,\n" + " PRIMARY KEY (name))") .execute(); return null; }); }
private void setupTables() { dbi.inTransaction((Handle handle, TransactionStatus transactionStatus) -> { handle.createStatement("CREATE TABLE IF NOT EXISTS project (" + " name VARCHAR(255) NOT NULL, \n" + " PRIMARY KEY (name))") .execute(); return null; }); }
private void setup() { dbi.inTransaction((handle, transactionStatus) -> { handle.createStatement("CREATE TABLE IF NOT EXISTS automation_rules (" + " id SERIAL," + " is_active BOOLEAN NOT NULL," + " project TEXT NOT NULL," + " event_filters TEXT NOT NULL," + " actions TEXT NOT NULL," + " custom_data TEXT," + " PRIMARY KEY (id)" + " )") .execute(); return null; }); }
@JsonRequest @ApiOperation(value = "Update dashboard items") @Path("/update_dashboard_items") @ProtectEndpoint(writeOperation = true) public SuccessMessage updateDashboard( @Named("user_id") Project project, @ApiParam("dashboard") int dashboard, @ApiParam("items") List<DashboardItem> items) { dbi.inTransaction((handle, transactionStatus) -> { Long execute = handle.createQuery("SELECT id FROM dashboard WHERE id = :id AND project_id = :project") .bind("id", dashboard) .bind("project", project.project) .map(LongMapper.FIRST).first(); if (execute == null) { throw new RakamException(HttpResponseStatus.NOT_FOUND); } for (DashboardItem item : items) { // TODO: verify dashboard is in project handle.createStatement("UPDATE dashboard_items SET name = :name, directive = :directive, options = :options WHERE id = :id") .bind("id", item.id) .bind("name", item.name) .bind("directive", item.directive) .bind("options", JsonHelper.encode(item.options)) .execute(); } return null; }); return SuccessMessage.success(); }
@ApiParam(value = "refresh_interval", required = false) Duration refreshDuration, @ApiParam("options") Map<String, Object> options) { dbi.inTransaction((handle, transactionStatus) -> { if (sharedEveryone != null && !sharedEveryone) { handle.createStatement("DELETE FROM dashboard_permission WHERE dashboard = :dashboard")
dbi.inTransaction((Handle handle, TransactionStatus transactionStatus) -> { Integer apiKeyId = saveApiKeys(handle, userId, projectId, keys.readKey(), keys.writeKey(), keys.masterKey());
@Override public T call() throws Exception { return getDBI().inTransaction(callback); } };
@Override public void truncateTable(final String tableName) throws InsufficientConsistencyException { getDbi().inTransaction(new TransactionCallback<Void>() { @Override public Void inTransaction(Handle handle, TransactionStatus status) throws Exception { handle.execute("TRUNCATE TABLE " + USR_TABLE(tableName)); return null; } }); }
public SqlIconFileStore(DBI dbi) { this.dbi = dbi; this.databaseKind = dbi.inTransaction((h, s) -> { String dbName = h.getConnection().getMetaData().getDatabaseProductName(); return DatabaseKind.valueOf(dbName.replace(" ", "_")); }); }
public void write(String path, InputStream file) { FileStoreSupport.checkValidPath(path); Objects.requireNonNull(file, "file cannot be null"); try { dbi.inTransaction((h, status) -> { doWrite(h, path, file); return true; }); } catch (CallbackFailedException ex) { throw new DaoException("Unable to write on path " + path, ex); } }
public String writeTemporaryFile(InputStream file) { Objects.requireNonNull(file, "file cannot be null"); try { return dbi.inTransaction((h, status) -> { String path = newRandomTempFilePath(); doWrite(h, path, file); return path; }); } catch (CallbackFailedException ex) { throw new DaoException("Unable to write on temporary path", ex); } }
public boolean delete(String path) { FileStoreSupport.checkValidPath(path); try { return dbi.inTransaction((h, status) -> doDelete(h, path)); } catch (CallbackFailedException ex) { throw new DaoException("Unable to delete path " + path, ex); } }