Skip to content

Commit

Permalink
Issue helidon-io#6991 - Blocking DB Client
Browse files Browse the repository at this point in the history
Signed-off-by: Tomáš Kraus <[email protected]>
  • Loading branch information
Tomas-Kraus committed Jun 23, 2023
1 parent 66f14d7 commit 26eb069
Show file tree
Hide file tree
Showing 68 changed files with 5,910 additions and 8 deletions.
17 changes: 17 additions & 0 deletions bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -713,6 +713,23 @@
</dependency>

<!-- db client -->
<dependency>
<groupId>io.helidon.dbclient</groupId>
<artifactId>helidon-dbclient</artifactId>
<version>${helidon.version}</version>
</dependency>
<dependency>
<groupId>io.helidon.dbclient</groupId>
<artifactId>helidon-dbclient-common</artifactId>
<version>${helidon.version}</version>
</dependency>
<dependency>
<groupId>io.helidon.dbclient</groupId>
<artifactId>helidon-dbclient-jdbc</artifactId>
<version>${helidon.version}</version>
</dependency>

<!-- reactive db client -->
<dependency>
<groupId>io.helidon.reactive.dbclient</groupId>
<artifactId>helidon-reactive-dbclient</artifactId>
Expand Down
52 changes: 52 additions & 0 deletions dbclient/common/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2023 Oracle and/or its affiliates.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->

<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>io.helidon.dbclient</groupId>
<artifactId>helidon-dbclient-project</artifactId>
<version>4.0.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

<artifactId>helidon-dbclient-common</artifactId>
<name>Helidon DB Client Common</name>
<description>Helidon Database Client Common Module</description>

<dependencies>
<dependency>
<groupId>io.helidon.dbclient</groupId>
<artifactId>helidon-dbclient</artifactId>
<version>${project.version}</version>
</dependency>
<!-- jUnit tests -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-all</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright (c) 2023 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.helidon.dbclient.common;

import io.helidon.dbclient.DbClient;

public abstract class CommonClient implements DbClient {

private final CommonClientContext context;

public CommonClient(CommonClientContext context) {
this.context = context;
}

public CommonClientContext context() {
return context;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
/*
* Copyright (c) 2023 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.helidon.dbclient.common;

import java.util.Optional;

import io.helidon.common.GenericType;
import io.helidon.common.mapper.MapperManager;
import io.helidon.config.Config;
import io.helidon.dbclient.DbMapper;
import io.helidon.dbclient.DbMapperManager;
import io.helidon.dbclient.DbStatements;
import io.helidon.dbclient.spi.DbClientBuilder;
import io.helidon.dbclient.spi.DbMapperProvider;

public abstract class CommonClientBuilder<T extends CommonClientBuilder<T>>
implements DbClientBuilder<T> {

private final DbMapperManager.Builder dbMapperBuilder = DbMapperManager.builder();
private String url;
private String username;
private String password;
private DbStatements statements;
private MapperManager mapperManager;
private DbMapperManager dbMapperManager;

protected CommonClientBuilder() {
}

@Override
public T config(Config config) {
config.get("statements").as(DbStatements::create).ifPresent(this::statements);
return identity();
}

@Override
public T url(String url) {
this.url = url;
return identity();
}

@Override
public T username(String username) {
this.username = username;
return identity();
}

@Override
public T password(String password) {
this.password = password;
return identity();
}

@Override
public T statements(DbStatements statements) {
this.statements = statements;
return identity();
}

@Override
public <TYPE> T addMapper(DbMapper<TYPE> dbMapper, Class<TYPE> mappedClass) {
this.dbMapperBuilder.addMapperProvider(new DbMapperProvider() {
@SuppressWarnings("unchecked")
@Override
public <T> Optional<DbMapper<T>> mapper(Class<T> type) {
if (type.equals(mappedClass)) {
return Optional.of((DbMapper<T>) dbMapper);
}
return Optional.empty();
}
});
return identity();
}

@Override
public <TYPE> T addMapper(DbMapper<TYPE> dbMapper, GenericType<TYPE> mappedType) {
this.dbMapperBuilder.addMapperProvider(new DbMapperProvider() {
@Override
public <T> Optional<DbMapper<T>> mapper(Class<T> type) {
return Optional.empty();
}

@SuppressWarnings("unchecked")
@Override
public <T> Optional<DbMapper<T>> mapper(GenericType<T> type) {
if (type.equals(mappedType)) {
return Optional.of((DbMapper<T>) dbMapper);
}
return Optional.empty();
}
});
return identity();
}

@Override
public T mapperManager(MapperManager manager) {
this.mapperManager = manager;
return identity();
}

@Override
public T addMapperProvider(DbMapperProvider provider) {
this.dbMapperBuilder.addMapperProvider(provider);
return identity();
}

public String url() {
return url;
}

public String username() {
return username;
}

public String password() {
return password;
}

public DbStatements statements() {
return statements;
}

// List<DbClientService> clientServices() {
// return List.copyOf(clientServices);
// }

public MapperManager mapperManager() {
return mapperManager;
}

public DbMapperManager dbMapperManager() {
return dbMapperManager;
}

}
Loading

0 comments on commit 26eb069

Please sign in to comment.