JDBC

The javax.sql based implementation of YoSQL to access your database. It does not require any dependencies outside from standard JDK classes exposed by the JDBC API. The available configuration is listed split into multiple pages which are listed at the bottom of this page.

Tooling

In order to use the JDBC API in generated code, set the daoApi option to JDBC. Further configuration can be performed using the dedicated jdbc section.

Maven

In order to use YoSQL together with Maven, take a look at the tooling documentation for Maven.

<build>
    <plugins>
        ...
        <plugin>
            <groupId>wtf.metio.yosql</groupId>
            <artifactId>yosql-tooling-maven</artifactId>
            <version>2021.4.21</version>
            <configuration>
                <apis>
                    <daoApi>JDBC</daoApi>
                </apis>
                <jdbc>
                    ... JDBC configuration
                </jdbc>
            </configuration>
        </plugin>
        ...
    </plugins>
</build>

Gradle

In order to use YoSQL together with Gradle, take a look at the tooling documentation for Gradle.

plugins {
  id("wtf.metio.yosql")
}

yosql {
  apis {
    daoApi = JDBC
  }
  jdbc {
    ... jdbc configuration
  }
}

Bazel

In order to use YoSQL together with Bazel, take a look at the tooling documentation for Bazel.

CLI

In order to use YoSQL on the command line, take a look at the tooling documentation for CLI.

$ yosql --apis-dao-api=JDBC

The shorter form is available as well:

$ yosql --dao-api=JDBC

Manual Converters

The JDBC API offers no built-in object mapping mechanism. In order to use high level types of your domain, use a converter to map results to your types.

-- results:
--   converter: my.own.UserConverter
SELECT  *
FROM    users

You can either specify the fully-qualified name of the converter or use its alias. The result type is read from the converter configuration as well. This in turn changes the generated code into this:

// uses "User" as type argument for all return types
List<User> findUsers()
Stream<User> findUsersStreamEager()
Stream<User> findUsersStreamLazy()
Flowable<User> findUsersFlow()

my.own.UserConverter could look like this:

package my.own;

import java.sql.ResultSet;
import java.sql.SQLException;

import my.own.User;
import my.own.persistence.util.ResultState;

public class UserConverter {

    public final User asUserType(final ResultState result) throws SQLException {
        final ResultSet resultSet = result.getResultSet();
        final User pojo = new User();
        pojo.setId(resultSet.getInt("id"));
        pojo.setName(resultSet.getString("name"));
        return pojo;
    }

}

Pages