Search in sources :

Example 1 with JdbcProperties

use of org.eclipse.hono.service.base.jdbc.config.JdbcProperties in project hono by eclipse.

the class ClasspathSchemaCreator method runScript.

private Future<Void> runScript(final JdbcProperties jdbcProperties, final String script, final SpanContext ctx) {
    final JDBCClient jdbcClient = JdbcProperties.dataSource(vertx, jdbcProperties);
    final Promise<Void> clientCloseTracker = Promise.promise();
    SQL.runTransactionally(jdbcClient, tracer, ctx, (connection, context) -> {
        final var expanded = Statement.statement(script).expand();
        log.debug("Creating database schema in [{}] with script: {}", jdbcProperties.getUrl(), expanded);
        return expanded.query(jdbcClient).recover(SQL::translateException);
    }).onComplete(ar -> jdbcClient.close(clientCloseTracker));
    return clientCloseTracker.future();
}
Also used : SQL(org.eclipse.hono.service.base.jdbc.store.SQL) JdbcProperties(org.eclipse.hono.service.base.jdbc.config.JdbcProperties) Logger(org.slf4j.Logger) Tracer(io.opentracing.Tracer) Promise(io.vertx.core.Promise) LoggerFactory(org.slf4j.LoggerFactory) Vertx(io.vertx.core.Vertx) Future(io.vertx.core.Future) Statement(org.eclipse.hono.service.base.jdbc.store.Statement) SpanContext(io.opentracing.SpanContext) Objects(java.util.Objects) JDBCClient(io.vertx.ext.jdbc.JDBCClient) Buffer(io.vertx.core.buffer.Buffer) SchemaCreator(org.eclipse.hono.deviceregistry.jdbc.SchemaCreator) Span(io.opentracing.Span) TracingHelper(org.eclipse.hono.tracing.TracingHelper) JDBCClient(io.vertx.ext.jdbc.JDBCClient)

Aggregations

Span (io.opentracing.Span)1 SpanContext (io.opentracing.SpanContext)1 Tracer (io.opentracing.Tracer)1 Future (io.vertx.core.Future)1 Promise (io.vertx.core.Promise)1 Vertx (io.vertx.core.Vertx)1 Buffer (io.vertx.core.buffer.Buffer)1 JDBCClient (io.vertx.ext.jdbc.JDBCClient)1 Objects (java.util.Objects)1 SchemaCreator (org.eclipse.hono.deviceregistry.jdbc.SchemaCreator)1 JdbcProperties (org.eclipse.hono.service.base.jdbc.config.JdbcProperties)1 SQL (org.eclipse.hono.service.base.jdbc.store.SQL)1 Statement (org.eclipse.hono.service.base.jdbc.store.Statement)1 TracingHelper (org.eclipse.hono.tracing.TracingHelper)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1