All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.vertx.sqlclient.spi.ConnectionFactory Maven / Gradle / Ivy

There is a newer version: 5.0.0.CR1
Show newest version
package io.vertx.sqlclient.spi;

import io.vertx.core.*;
import io.vertx.core.impl.ContextInternal;
import io.vertx.sqlclient.SqlConnectOptions;
import io.vertx.sqlclient.SqlConnection;

/**
 * A connection factory, can be obtained from {@link Driver#createConnectionFactory}
 */
public interface ConnectionFactory extends Closeable {

  default Future connect(Context context, Future fut) {
    // The future might be on any context or context-less
    // So we need to use a specific context promise
    Promise promise = ((ContextInternal) context).promise();
    fut.onComplete(ar -> {
      if (ar.succeeded()) {
        promise.complete(ar.result());
      } else {
        promise.fail(ar.cause());
      }
    });
    return promise
      .future()
      .compose(connectOptions -> connect(context, connectOptions));
  }

  /**
   * Create a connection using the given {@code context}.
   *
   * @param context the context
   * @return the future connection
   */
  Future connect(Context context);

  /**
   * Create a connection using the given {@code context}.
   *
   * @param context the context
   * @return the future connection
   */
  Future connect(Context context, SqlConnectOptions options);

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy