use of jnc.platform.win32.Handle in project providence by morimekta.
the class MessageInserter method execute.
public int execute(Handle handle, Collection<M> items) {
if (items.isEmpty()) {
throw new IllegalArgumentException("Nothing to insert");
}
String query = queryPrefix + items.stream().map(item -> valueMarkers).collect(Collectors.joining(", ")) + querySuffix;
Update update = handle.createStatement(query);
int offset = 0;
for (M item : items) {
for (String column : columnOrder) {
F field = columnToFieldMap.get(column);
int type = columnTypeMap.get(column);
update.bind(offset++, new MessageFieldArgument<>(item, field, type));
}
}
return update.execute();
}
use of jnc.platform.win32.Handle in project SpinalTap by airbnb.
the class LatestMysqlSchemaStore method getTableDDL.
String getTableDDL(@NotNull final String database, @NotNull final String table) {
// and handle.createQuery() needs to escape colon(:)
try (Handle handle = jdbi.open()) {
Statement statement = handle.getConnection().createStatement();
statement.execute(String.format(TABLE_DDL_QUERY, MysqlSchemaUtil.escapeBackQuote(database), MysqlSchemaUtil.escapeBackQuote(table)));
ResultSet resultSet = statement.getResultSet();
resultSet.first();
return resultSet.getString(2);
} catch (SQLException ex) {
log.error(String.format("Failed to get DDL for database: %s table: %s.", database, table), ex);
Throwables.throwIfUnchecked(ex);
throw new RuntimeException(ex);
}
}
use of jnc.platform.win32.Handle in project SpinalTap by airbnb.
the class MysqlSchemaDatabase method applyDDLStatement.
void applyDDLStatement(@NotNull final String database, @NotNull final String ddl) {
log.info(String.format("Applying DDL statement: %s (Database selected: %s)", ddl, database));
try (Handle handle = jdbi.open()) {
disableForeignKeyChecks(handle);
MysqlSchemaUtil.VOID_RETRYER.call(() -> {
MysqlSchemaUtil.executeSQL(handle, database.isEmpty() ? null : getSchemaDatabaseName(source, database), addSourcePrefix(ddl));
return null;
});
metrics.schemaDatabaseApplyDDLSuccess(database);
} catch (Exception ex) {
log.error(String.format("Failed to apply DDL Statement to source: %s database: %s. (SQL: %s. Exception: %s)", source, database, ddl, ex));
metrics.schemaDatabaseApplyDDLFailure(database, ex);
Throwables.throwIfUnchecked(ex);
throw new RuntimeException(ex);
}
}
use of jnc.platform.win32.Handle in project SpinalTap by airbnb.
the class MysqlSchemaDatabase method fetchTableSchema.
Map<String, MysqlTableSchema> fetchTableSchema(@NotNull final String database) {
List<ColumnInfo> allColumnInfo;
try (Handle handle = jdbi.open()) {
disableForeignKeyChecks(handle);
allColumnInfo = MysqlSchemaUtil.LIST_COLUMNINFO_RETRYER.call(() -> handle.createQuery(ALL_TABLE_SCHEMA_QUERY).bind("db", getSchemaDatabaseName(source, database)).map(MysqlSchemaUtil.COLUMN_MAPPER).list());
} catch (Exception ex) {
log.error(String.format("Failed to fetch schema for database: %s", database), ex);
Throwables.throwIfUnchecked(ex);
throw new RuntimeException(ex);
}
Map<String, MysqlTableSchema> allTableSchemaMap = Maps.newHashMap();
allColumnInfo.forEach(columnInfo -> {
String table = columnInfo.getTable();
allTableSchemaMap.computeIfAbsent(table, __ -> MysqlSchemaUtil.createTableSchema(source, database, table, "", Lists.newArrayList())).getColumnInfo().add(columnInfo);
});
return allTableSchemaMap;
}
use of jnc.platform.win32.Handle in project SpinalTap by airbnb.
the class MysqlSchemaStore method get.
@Override
public MysqlTableSchema get(@NotNull final String database, @NotNull final String table, final int version) {
try (Handle handle = jdbi.open()) {
String schemaInfo = MysqlSchemaUtil.STRING_RETRYER.call(() -> handle.createQuery(String.format(GET_SCHEMA_BY_VERSION_QUERY, source)).bind("database", database).bind("table", table).bind("version", version).map(StringColumnMapper.INSTANCE).first());
metrics.schemaStoreGetSuccess(database, table);
return deserializeSchemaInfo(schemaInfo);
} catch (Exception ex) {
log.error(String.format("Failed to get schema of database: %s table: %s version: %d. Does it exist?", database, table, version), ex);
metrics.schemaStoreGetFailure(database, table, ex);
Throwables.throwIfUnchecked(ex);
throw new RuntimeException(ex);
}
}
Aggregations