Java Code Examples for org.skife.jdbi.v2.Handle#insert()
The following examples show how to use
org.skife.jdbi.v2.Handle#insert() .
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: SqlFileStore.java From syndesis with Apache License 2.0 | 5 votes |
private static void doWritePostgres(Handle h, String path, InputStream file) { doDelete(h, path); try { LargeObjectManager lobj = getPostgresConnection(h.getConnection()).getLargeObjectAPI(); long oid = lobj.createLO(); LargeObject obj = lobj.open(oid, LargeObjectManager.WRITE); try (OutputStream lob = obj.getOutputStream()) { IOUtils.copy(file, lob); } h.insert("INSERT INTO filestore(path, data) values (?,?)", path, oid); } catch (IOException | SQLException ex) { throw DaoException.launderThrowable(ex); } }
Example 2
Source File: SqlFileStore.java From syndesis with Apache License 2.0 | 5 votes |
private static void doWriteDerby(Handle h, String path, InputStream file) { doDelete(h, path); try { Blob blob = h.getConnection().createBlob(); try (OutputStream out = blob.setBinaryStream(1)) { IOUtils.copy(file, out); } h.insert("INSERT INTO filestore(path, data) values (?,?)", path, blob); } catch (IOException | SQLException ex) { throw DaoException.launderThrowable(ex); } }
Example 3
Source File: AlarmDAOImpl.java From monasca-thresh with Apache License 2.0 | 5 votes |
private void createAlarmedMetric(Handle h, MetricDefinitionAndTenantId metricDefinition, String alarmId) { final Sha1HashId metricDefinitionDimensionId = insertMetricDefinitionDimension(h, metricDefinition); h.insert("insert into alarm_metric (alarm_id, metric_definition_dimensions_id) values (?, ?)", alarmId, metricDefinitionDimensionId.getSha1Hash()); }
Example 4
Source File: AlarmDAOImpl.java From monasca-thresh with Apache License 2.0 | 5 votes |
private Sha1HashId insertMetricDefinitionDimension(Handle h, MetricDefinitionAndTenantId mdtid) { final Sha1HashId metricDefinitionId = insertMetricDefinition(h, mdtid); final Sha1HashId metricDimensionSetId = insertMetricDimensionSet(h, mdtid.metricDefinition.dimensions); final byte[] definitionDimensionsIdSha1Hash = DigestUtils.sha(metricDefinitionId.toHexString() + metricDimensionSetId.toHexString()); h.insert( "insert into metric_definition_dimensions (id, metric_definition_id, metric_dimension_set_id) values (?, ?, ?)" + "on duplicate key update id=id", definitionDimensionsIdSha1Hash, metricDefinitionId.getSha1Hash(), metricDimensionSetId.getSha1Hash()); return new Sha1HashId(definitionDimensionsIdSha1Hash); }
Example 5
Source File: AlarmDAOImpl.java From monasca-thresh with Apache License 2.0 | 5 votes |
private Sha1HashId insertMetricDimensionSet(Handle h, Map<String, String> dimensions) { final byte[] dimensionSetId = calculateDimensionSHA1(dimensions); for (final Map.Entry<String, String> entry : dimensions.entrySet()) { h.insert("insert into metric_dimension(dimension_set_id, name, value) values (?, ?, ?) " + "on duplicate key update dimension_set_id=dimension_set_id", dimensionSetId, entry.getKey(), entry.getValue()); } return new Sha1HashId(dimensionSetId); }
Example 6
Source File: AlarmDAOImpl.java From monasca-thresh with Apache License 2.0 | 5 votes |
private Sha1HashId insertMetricDefinition(Handle h, MetricDefinitionAndTenantId mdtid) { final String region = ""; // TODO We currently don't have region final String definitionIdStringToHash = trunc(mdtid.metricDefinition.name, MAX_COLUMN_LENGTH) + trunc(mdtid.tenantId, MAX_COLUMN_LENGTH) + trunc(region, MAX_COLUMN_LENGTH); final byte[] id = DigestUtils.sha(definitionIdStringToHash); h.insert("insert into metric_definition(id, name, tenant_id) values (?, ?, ?) " + "on duplicate key update id=id", id, mdtid.metricDefinition.name, mdtid.tenantId); return new Sha1HashId(id); }
Example 7
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 8
Source File: SqlFileStore.java From syndesis with Apache License 2.0 | 4 votes |
private static void doWriteStandard(Handle h, String path, InputStream file) { doDelete(h, path); h.insert("INSERT INTO filestore(path, data) values (?,?)", path, file); }
Example 9
Source File: DatabaseMigrator.java From digdag with Apache License 2.0 | 4 votes |
@VisibleForTesting public void applyMigration(Migration m, Handle handle, MigrationContext context) { m.migrate(handle, context); handle.insert("insert into schema_migrations (name, created_at) values (?, now())", m.getVersion()); }
Example 10
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; } }