Skip to content

Commit

Permalink
Apply formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
rainbowdashlabs committed Feb 9, 2024
1 parent cede1a9 commit 1a1ed82
Show file tree
Hide file tree
Showing 40 changed files with 101 additions and 131 deletions.
8 changes: 4 additions & 4 deletions .github/renovate.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
"extends": [
"github>rainbowdashlabs/rainbowdashlabs"
]
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
"extends": [
"github>rainbowdashlabs/rainbowdashlabs"
]
}
2 changes: 1 addition & 1 deletion .github/workflows/verify.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: Verify state

on: [push, pull_request]
on: [ push, pull_request ]

jobs:
build:
Expand Down
2 changes: 2 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
Hello and welcome new contributor.

# Issues

Please make sure to describe your issue as precisely as possible.

# Pull Requests

When you create a new pull request you have to take care of a few things.

- Create a feature branch based on the development branch
Expand Down
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ SADU offers support for four different databases at the moment. To use them simp
- `sadu-sqlite`

## Querybuilder

SADU offers a query builder to manage resources, error handling, result set reading and dispatching of queries.

to use it import: `sadu-queries`
Expand All @@ -44,12 +45,13 @@ Learn how to use the query builder [here](https://github.com/RainbowDashLabs/sad
Before I give you a long talk about how much nicer the syntax and code is let me simple show you a comparison.

Without the query builder your code would ideally look like this:

```java
class MyQueries {

DataSource dataSource;
MyQueries(DataSource dataSource){

MyQueries(DataSource dataSource) {
this.dataSource = dataSource;
}

Expand All @@ -71,6 +73,7 @@ class MyQueries {
```

But using the query builder your code becomes this:

```java
class MyQueries {
public Optional<Result> getResultNew(int id) {
Expand All @@ -88,6 +91,7 @@ read the result set and additionally handle the exceptions for you.
[How does it work?](https://github.com/RainbowDashLabs/sadu/wiki/SADU-Queries#how-does-it-work)

## Datasource Builder

SADU offsers a data source builder to create data sources for the databases listed above.

to use it import: `sadu-datasource`
Expand All @@ -106,4 +110,5 @@ Learn how to use it [here](https://sadu.docs.chojo.dev/queries/)


[nexus_releases]: https://search.maven.org/search?q=de.chojo.sadu

[nexus_snapshots]: https://s01.oss.sonatype.org/#nexus-search;quick~de.chojo.sadu
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ default boolean hasSchemas() {

/**
* Instantiates an implementation of {@link UpdaterBuilder}
*
* @return the instance
*/
@ApiStatus.Internal
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public String key() {
public String value() {
return URLEncoder.encode(String.valueOf(value), StandardCharsets.UTF_8);
}

public String valueRaw() {
return String.valueOf(value);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ public Credentials userCredentials() {
}

public static class Credentials {
public static final Credentials EMPTY = new Credentials(null,null);
public static final Credentials EMPTY = new Credentials(null, null);
private final JdbProperty<?> user;
private final JdbProperty<?> password;

Expand Down
30 changes: 15 additions & 15 deletions sadu-core/src/main/java/de/chojo/sadu/core/updater/SqlVersion.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,21 @@ public SqlVersion(int major, int patch) {
this.patch = patch;
}

public static SqlVersion load() throws IOException {
return load(SqlVersion.class.getClassLoader());
}

public static SqlVersion load(ClassLoader classLoader) throws IOException {
var version = "";
try (var versionFile = classLoader.getResourceAsStream("database/version")) {
version = new String(versionFile.readAllBytes(), StandardCharsets.UTF_8).trim();
}

var ver = version.split("\\.");
return new SqlVersion(Integer.parseInt(ver[0]), Integer.parseInt(ver[1]));

}

/**
* Major version
*
Expand Down Expand Up @@ -88,19 +103,4 @@ public int compareTo(@NotNull SqlVersion o) {
}
return Integer.compare(patch, o.patch);
}

public static SqlVersion load() throws IOException {
return load(SqlVersion.class.getClassLoader());
}

public static SqlVersion load(ClassLoader classLoader) throws IOException {
var version = "";
try (var versionFile = classLoader.getResourceAsStream("database/version")) {
version = new String(versionFile.readAllBytes(), StandardCharsets.UTF_8).trim();
}

var ver = version.split("\\.");
return new SqlVersion(Integer.parseInt(ver[0]), Integer.parseInt(ver[1]));

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,21 @@
public interface UpdaterBuilder<T extends JdbcConfig<?>, S extends UpdaterBuilder<T, ?>> {
/**
* Set the datasource that should be used
*
* @param source source
*/
S setSource(DataSource source);

/**
* Set the current db version that is expected
*
* @param version version
*/
S setVersion(SqlVersion version);

/**
* Set the Classloader that should be used to load resourced.
*
* @param classLoader classloader
*/
S withClassLoader(ClassLoader classLoader);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;
import de.chojo.sadu.core.databases.Database;
import de.chojo.sadu.datasource.stage.ConfigurationStage;
import de.chojo.sadu.datasource.stage.JdbcStage;
import de.chojo.sadu.core.jdbc.JdbcConfig;
import de.chojo.sadu.core.jdbc.RemoteJdbcConfig;
import de.chojo.sadu.datasource.stage.ConfigurationStage;
import de.chojo.sadu.datasource.stage.JdbcStage;
import org.jetbrains.annotations.CheckReturnValue;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -61,7 +61,7 @@ public ConfigurationStage create() {
loadDriverClass();
RemoteJdbcConfig.Credentials credentials = RemoteJdbcConfig.Credentials.EMPTY;
if (builder instanceof RemoteJdbcConfig) {
credentials = ((RemoteJdbcConfig)builder).userCredentials();
credentials = ((RemoteJdbcConfig) builder).userCredentials();
}
var jdbcUrl = builder.jdbcUrl();
log.info("Creating Hikari config using jdbc url: {}", jdbcUrl.replaceAll("password=.+?(&|$)", "password=******"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ public interface ConfigurationStage {

/**
* Allows the direct mutation of the HikariConfig, should be used for config options, that are not represented by a delegate.
*
* @param configConsumer the config consumer
* @return Configuration Stage with value set
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
package de.chojo.sadu.examples.datasource;

import com.zaxxer.hikari.HikariDataSource;
import de.chojo.sadu.postgresql.databases.PostgreSql;
import de.chojo.sadu.datasource.DataSourceCreator;
import de.chojo.sadu.postgresql.databases.PostgreSql;
import org.postgresql.Driver;

public class Create {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
package de.chojo.sadu.mapper;

import de.chojo.sadu.core.exceptions.ThrowingBiFunction;
import de.chojo.sadu.core.types.SqlType;
import de.chojo.sadu.mapper.rowmapper.RowMapper;
import de.chojo.sadu.mapper.util.Results;
import de.chojo.sadu.core.types.SqlType;
import de.chojo.sadu.wrapper.util.Row;

import java.math.BigDecimal;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public MapperConfig addAlias(String original, String alias) {

/**
* When true only mappers will be used, which have a mapping value for all columns or the wild card mapper if present and no matching mapper was found.
*
* @return true when strict
*/
public boolean isStrict() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public RowMapperRegistry register(RowMapper<?>... rowMapper) {
}
return this;
}

/**
* Registers new mapper.
* <p>
Expand Down Expand Up @@ -93,9 +94,9 @@ private List<RowMapper<?>> mapper(Class<?> clazz) {
@SuppressWarnings("unchecked")
public <T> Optional<RowMapper<T>> wildcard(Class<T> clazz) {
return mapper(clazz).stream()
.filter(RowMapper::isWildcard)
.findAny()
.map(rowMapper -> (RowMapper<T>) rowMapper);
.filter(RowMapper::isWildcard)
.findAny()
.map(rowMapper -> (RowMapper<T>) rowMapper);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

/**
* Represents a partially configured {@link RowMapper}
*
* @param <T> type of the mapper result.
*/
public interface PartialRowMapper<T> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

/**
* A builder to build a {@link RowMapper}.
*
* @param <T> type of the mapper result.
*/
public class RowMapperBuilder<T> implements PartialRowMapper<T> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
import java.sql.SQLException;

public interface RowMapping<T> {
T map(Row row) throws SQLException;

static <V> RowMapping<V> create(ThrowingFunction<V, Row, SQLException> mapper){
static <V> RowMapping<V> create(ThrowingFunction<V, Row, SQLException> mapper) {
return mapper::apply;
}

T map(Row row) throws SQLException;
}
Loading

0 comments on commit 1a1ed82

Please sign in to comment.