Java Code Examples for org.skife.jdbi.v2.Handle#commit()
The following examples show how to use
org.skife.jdbi.v2.Handle#commit() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PostgresStorage.java From cassandra-reaper with Apache License 2.0 | 5 votes |
@Override public Optional<RepairRun> deleteRepairRun(UUID id) { RepairRun result = null; Handle handle = null; try { handle = jdbi.open(); handle.begin(); IStoragePostgreSql pg = getPostgresStorage(handle); RepairRun runToDelete = pg.getRepairRun(UuidUtil.toSequenceId(id)); if (runToDelete != null) { int segmentsRunning = pg.getSegmentAmountForRepairRunWithState(UuidUtil.toSequenceId(id), RepairSegment.State.RUNNING); if (segmentsRunning == 0) { pg.deleteRepairSegmentsForRun(UuidUtil.toSequenceId(runToDelete.getId())); pg.deleteRepairRun(UuidUtil.toSequenceId(id)); result = runToDelete.with() .runState(RepairRun.RunState.DELETED) .endTime(DateTime.now()) .build(id); } else { LOG.warn("not deleting RepairRun \"{}\" as it has segments running: {}", id, segmentsRunning); } } handle.commit(); } catch (DBIException ex) { LOG.warn("DELETE failed", ex); if (handle != null) { handle.rollback(); } } finally { if (handle != null) { handle.close(); } } return Optional.ofNullable(result); }
Example 2
Source File: AlarmDAOImpl.java From monasca-thresh with Apache License 2.0 | 5 votes |
@Override public void addAlarmedMetric(String alarmId, MetricDefinitionAndTenantId metricDefinition) { Handle h = db.open(); try { h.begin(); createAlarmedMetric(h, metricDefinition, alarmId); h.commit(); } catch (RuntimeException e) { h.rollback(); throw e; } finally { h.close(); } }
Example 3
Source File: AlarmDAOImpl.java From monasca-thresh with Apache License 2.0 | 5 votes |
@Override public void createAlarm(Alarm alarm) { Handle h = db.open(); try { String timestamp = formatDateFromMillis(System.currentTimeMillis()); h.begin(); h.insert( "insert into alarm (id, alarm_definition_id, state, state_updated_at, created_at, updated_at) values (?, ?, ?, ?, ?, ?)", alarm.getId(), alarm.getAlarmDefinitionId(), alarm.getState().toString(), timestamp, timestamp, timestamp); for (final SubAlarm subAlarm : alarm.getSubAlarms()) { h.insert( "insert into sub_alarm (id, alarm_id, sub_expression_id, expression, state, created_at, updated_at) values (?, ?, ?, ?, ?, ?, ?)", subAlarm.getId(), subAlarm.getAlarmId(), subAlarm.getAlarmSubExpressionId(), subAlarm .getExpression().getExpression(), subAlarm.getState().toString(), timestamp, timestamp); } for (final MetricDefinitionAndTenantId md : alarm.getAlarmedMetrics()) { createAlarmedMetric(h, md, alarm.getId()); } h.commit(); } catch (RuntimeException e) { h.rollback(); throw e; } finally { h.close(); } }
Example 4
Source File: AlarmDefinitionDAOImplTest.java From monasca-thresh with Apache License 2.0 | 4 votes |
@Test(enabled=false) public static void insertAlarmDefinition(Handle handle, AlarmDefinition alarmDefinition) { try { handle.begin(); handle .insert( "insert into alarm_definition (id, tenant_id, name, description, severity, expression, match_by, actions_enabled, created_at, updated_at, deleted_at) values (?, ?, ?, ?, ?, ?, ?, ?, NOW(), NOW(), NULL)", alarmDefinition.getId(), alarmDefinition.getTenantId(), alarmDefinition.getName(), alarmDefinition.getDescription(), "LOW", alarmDefinition.getAlarmExpression().getExpression(), alarmDefinition.getMatchBy().isEmpty() ? null : COMMA_JOINER.join(alarmDefinition .getMatchBy()), alarmDefinition.isActionsEnabled()); for (final SubExpression subExpression : alarmDefinition.getSubExpressions()) { final AlarmSubExpression alarmSubExpr = subExpression.getAlarmSubExpression(); handle .insert( "insert into sub_alarm_definition (id, alarm_definition_id, function, metric_name, operator, " + "threshold, period, periods, is_deterministic, created_at, updated_at) " + "values (?, ?, ?, ?, ?, ?, ?, ?, ?, NOW(), NOW())", subExpression.getId(), alarmDefinition.getId(), alarmSubExpr.getFunction().name(), alarmSubExpr.getMetricDefinition().name, alarmSubExpr.getOperator().name(), alarmSubExpr.getThreshold(), alarmSubExpr.getPeriod(), alarmSubExpr.getPeriods(), alarmSubExpr.isDeterministic() ); for (final Map.Entry<String, String> entry : alarmSubExpr.getMetricDefinition().dimensions.entrySet()) { handle .insert( "insert into sub_alarm_definition_dimension (sub_alarm_definition_id, dimension_name, value) values (?, ?, ?)", subExpression.getId(), entry.getKey(), entry.getValue()); } } handle.commit(); } catch (RuntimeException e) { handle.rollback(); throw e; } }