Red Hat build of Eclipse Vert.x 3.9 brings Fluent API Query

Red Hat build of Eclipse Vert.x 3.9 brings Fluent API Query

Red Hat Runtimes provides a set of comprehensive frameworks, runtimes, and programming languages for developers, architects, and IT leaders with cloud-native application development needs. The latest update to Red Hat Runtimes has arrived with Red Hat’s build of Eclipse Vert.x version 3.9. Red Hat Runtimes provides application developers with a variety of application runtimes and lets them run on the Red Hat OpenShift Container Platform.

A fluent API is a common pattern throughout Vert.x, it lets multiple methods calls be chained together. For example:

request.response().putHeader("Content-Type", "text/plain").write("some text").end();

Chaining calls like this also allows you to write code that’s a bit less verbose.

With 3.9, you can now create prepared statements and collector queries with the inclusion of Query in the Fluent API. If you are familiar with JDBC, PreparedStatement lets you create and execute statements. Moreover, you can run multiple interactions, such as cursor or stream operations.

Creating a prepared statement

To create a prepared statement:

connection.prepare(sql, ar1 -> {
  if (ar1.succeded()) {
    PreparedStatement ps = ar1.result();
    PreparedQuery<RowSet<Row>> pq = ps.query();
    pq.execute(tuple, ar2 -> ...);

// Or fluently
    ps.query().execute(tuple, ar2 -> ...);
  }
});

Everything you need to grow your career.

With your free Red Hat Developer program membership, unlock our library of cheat sheets and ebooks on next-generation application development.

SIGN UP

Creating a collector query

You can use the Java Collectors with Vert.x too. For example to create a collector query:

PreparedQuery<RowSet<Row>> query = client.preparedQuery(sql);
PreparedQuery<SqlResult<List<Row>> collectedQuery = query.collecting(Collectors.toList());
collectedQuery.execute(tuple, ar -> ...);

// Or fluently
client.preparedQuery(sql).collecting(Collectors.toList()).execute(tuple, ar -> ...);

See these Vert.x examples on GitHub.

Use Promise instead of Future

Another important change in this release is the deprecation of the following methods: start(Future<Void>) and stop(Future<Void>). The future() method returns the Future associated with a promise. The future can then be used for getting notified of the promise’s completion and retrieving its value.

Instead, use start(Promise<Void>) and stop(Promise<Void>). These methods represent the writable side of an action that may, or may not, have occurred yet. A promise extends Handler<AsyncResult<T>> so it can be used as a callback.

Documentation

For more details, take a look at the supported configurations and component details: Red Hat Runtimes Eclipse Vert.x Supported Configurations and Red Hat Runtimes Eclipse Vert.x 3.9 Component Details. If you are new to Eclipse Vert.x and would like to learn more, go to our live learning portal for a guided tutorial or to the documentation for details.

Developer interactive learning scenarios

These self-paced scenarios provide you with a preconfigured Red Hat OpenShift instance, accessible from your browser without any downloads or configuration. Use it to learn and experiment with Vert.x or learn about other technologies within Red Hat Runtimes and see how they help solve real-world problems.

Getting support for Eclipse Vert.x

Support for Eclipse Vert.x is available to Red Hat customers through a subscription to Red Hat Runtimes. Contact your local Red Hat representative or Red Hat Sales for details on how you can enjoy the world-class support offered by Red Hat and its worldwide partner network.

Moving forward, customers can expect support for Eclipse Vert.x and other runtimes according to the Red Hat Product Update and Support Lifecycle.

The people behind Eclipse Vert.x in Red Hat Runtimes

This offering was produced by Red Hat’s Runtimes product and engineering teams, along with the Eclipse Vert.x upstream community. It involved many hours of development, testing, documentation writing, testing some more, and working with the wider Red Hat community of customers, partners, and Vert.x developers to incorporate contributions, both big and small.

Share