forked from helidon-io/helidon
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue helidon-io#6991 - Blocking DB Client: API, JDBC and Health
Signed-off-by: Tomáš Kraus <[email protected]>
- Loading branch information
1 parent
a20a7d0
commit 66097fe
Showing
110 changed files
with
11,029 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
46 changes: 46 additions & 0 deletions
46
dbclient/common/src/main/java/io/helidon/dbclient/common/CommonClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* 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; | ||
|
||
/** | ||
* Helidon database client. | ||
* <p>Common {@link DbClient} implementations ancestor with {@link CommonClientContext}. | ||
*/ | ||
public abstract class CommonClient implements DbClient { | ||
|
||
private final CommonClientContext context; | ||
|
||
/** | ||
* Creates an instance of {@link CommonClient}. | ||
* | ||
* @param context database client context. | ||
*/ | ||
public CommonClient(CommonClientContext context) { | ||
this.context = context; | ||
} | ||
|
||
/** | ||
* Get database client context. | ||
* | ||
* @return database client context. | ||
*/ | ||
public CommonClientContext context() { | ||
return context; | ||
} | ||
|
||
} |
188 changes: 188 additions & 0 deletions
188
dbclient/common/src/main/java/io/helidon/dbclient/common/CommonClientBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,188 @@ | ||
/* | ||
* 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; | ||
|
||
/** | ||
* Provider specific {@link io.helidon.dbclient.DbClient} builder. | ||
* <p>Common {@link DbClientBuilder} implementations ancestor with {@link DbMapperManager.Builder} | ||
* and common attributes required to initialize target {@code DbClient} instance. | ||
* | ||
* @param <T> type of the builder extending or implementing this interface. | ||
*/ | ||
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; | ||
|
||
/** | ||
* Creates an instance of {@link CommonClientBuilder}. | ||
*/ | ||
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(); | ||
} | ||
|
||
/** | ||
* Get database URL. | ||
* | ||
* @return database URL | ||
*/ | ||
public String url() { | ||
return url; | ||
} | ||
|
||
/** | ||
* Get database user name. | ||
* | ||
* @return database user name | ||
*/ | ||
public String username() { | ||
return username; | ||
} | ||
|
||
/** | ||
* Get database user password. | ||
* | ||
* @return database user password. | ||
*/ | ||
public String password() { | ||
return password; | ||
} | ||
|
||
/** | ||
* Get configured statements to be used by database provider. | ||
* | ||
* @return statements to be used by database provider | ||
*/ | ||
public DbStatements statements() { | ||
return statements; | ||
} | ||
|
||
// List<DbClientService> clientServices() { | ||
// return List.copyOf(clientServices); | ||
// } | ||
|
||
/** | ||
* Get {@link io.helidon.common.mapper.Mapper} manager. | ||
* | ||
* @return {@code Mapper} manager. | ||
*/ | ||
public MapperManager mapperManager() { | ||
return mapperManager; | ||
} | ||
|
||
/** | ||
* Get manager of all configured {@link DbMapper mappers}. | ||
* | ||
* @return manager of all configured {@link DbMapper mappers} | ||
*/ | ||
public DbMapperManager dbMapperManager() { | ||
return dbMapperManager; | ||
} | ||
|
||
} |
Oops, something went wrong.