Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SQL client template example with JPMS #474

Open
wants to merge 1 commit into
base: 5.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions jpms-examples/README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,7 @@ Since it requires a database, you can run it from a link:src/test/java/io/vertx/
== Service Proxy

A simple link:src/main/java/io/vertx/example/jpms/serviceproxy/UserService.java[service proxy] example.

== Sql Client Template

An SQL client link:src/main/java/io/vertx/example/jpms/sqltemplate/UserDataObject.java[template].
10 changes: 10 additions & 0 deletions jpms-examples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@
<groupId>io.vertx</groupId>
<artifactId>vertx-codegen-api</artifactId>
</dependency>
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-sql-client-templates</artifactId>
<version>5.0.0-SNAPSHOT</version>
</dependency>

<dependency>
<groupId>com.aayushatharva.brotli4j</groupId>
Expand Down Expand Up @@ -248,6 +253,11 @@
<groupId>io.vertx</groupId>
<artifactId>vertx-service-proxy</artifactId>
</annotationProcessorPath>
<annotationProcessorPath>
<groupId>io.vertx</groupId>
<artifactId>vertx-sql-client-templates</artifactId>
<version>5.0.0-SNAPSHOT</version>
</annotationProcessorPath>
</annotationProcessorPaths>
</configuration>
</plugin>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package io.vertx.example.jpms.sqltemplate;

/**
* Mapper for {@link UserDataObject}.
* NOTE: This class has been automatically generated from the {@link UserDataObject} original class using Vert.x codegen.
*/
@io.vertx.codegen.annotations.VertxGen
public interface UserDataObjectRowMapper extends io.vertx.sqlclient.templates.RowMapper<UserDataObject> {

UserDataObjectRowMapper INSTANCE = new UserDataObjectRowMapper() { };

@io.vertx.codegen.annotations.GenIgnore
java.util.stream.Collector<io.vertx.sqlclient.Row, ?, java.util.List<UserDataObject>> COLLECTOR = java.util.stream.Collectors.mapping(INSTANCE::map, java.util.stream.Collectors.toList());

@io.vertx.codegen.annotations.GenIgnore
default UserDataObject map(io.vertx.sqlclient.Row row) {
UserDataObject obj = new UserDataObject();
Object val;
int idx;
if ((idx = row.getColumnIndex("id")) != -1 && (val = row.getLong(idx)) != null) {
obj.setId((long)val);
}
if ((idx = row.getColumnIndex("first_name")) != -1 && (val = row.getString(idx)) != null) {
obj.setFirstName((java.lang.String)val);
}
if ((idx = row.getColumnIndex("last_name")) != -1 && (val = row.getString(idx)) != null) {
obj.setLastName((java.lang.String)val);
}
return obj;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package io.vertx.example.jpms.sqltemplate;

import io.vertx.codegen.annotations.DataObject;
import io.vertx.codegen.format.SnakeCase;
import io.vertx.sqlclient.templates.annotations.Column;
import io.vertx.sqlclient.templates.annotations.RowMapped;
import io.vertx.sqlclient.templates.annotations.TemplateParameter;

@DataObject
@RowMapped(formatter = SnakeCase.class)
public class UserDataObject {

private long id;
private String firstName;
private String lastName;

public long getId() {
return id;
}

public void setId(long id) {
this.id = id;
}

public String getFirstName() {
return firstName;
}

@TemplateParameter(name = "first_name")
@Column(name = "first_name")
public void setFirstName(String firstName) {
this.firstName = firstName;
}

public String getLastName() {
return lastName;
}

@TemplateParameter(name = "last_name")
@Column(name = "last_name")
public void setLastName(String lastName) {
this.lastName = lastName;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@ModuleGen(groupPackage = "io.vertx.example.jpms.sqltemplate", name = "sql-template")
package io.vertx.example.jpms.sqltemplate;

import io.vertx.codegen.annotations.ModuleGen;
3 changes: 3 additions & 0 deletions jpms-examples/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
requires io.vertx.codegen.api;
requires io.vertx.codegen.json;

// SQL client template@
requires io.vertx.sql.client.templates;

exports io.vertx.example.jpms.sqlclient;
exports io.vertx.example.jpms.native_transport;
exports io.vertx.example.jpms.serviceproxy;
Expand Down
Loading