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
Signed-off-by: Tomáš Kraus <[email protected]>
- Loading branch information
1 parent
66f14d7
commit 26eb069
Showing
68 changed files
with
5,910 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> |
32 changes: 32 additions & 0 deletions
32
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,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; | ||
} | ||
|
||
} |
148 changes: 148 additions & 0 deletions
148
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,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; | ||
} | ||
|
||
} |
Oops, something went wrong.