Skip to content

Commit

Permalink
feat: specify tableName in runtime & new maven repo
Browse files Browse the repository at this point in the history
  • Loading branch information
dynomake committed Aug 15, 2024
1 parent e2f0e03 commit 4822c40
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 20 deletions.
13 changes: 6 additions & 7 deletions .github/DEPEND.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
## | `Wonsi - Add as depend:`

[![Clojars Project](https://img.shields.io/clojars/v/io.github.dynomake/wonsi.svg)](https://clojars.org/io.github.dynomake/wonsi)

Here is how to add this framework depending on your project.
### | `Gradle`:
Expand All @@ -9,14 +8,14 @@ If you use Gradle with Groovy, then here is an example of adding dependencies:
repositories {
// other repositories
maven {
name = "clojars.org"
url = uri("https://repo.clojars.org")
name = "dynomakeRepo"
url = uri("https://maven.dynomake.space/releases")
}
}
dependencies {
// other depends
implementation 'io.github.dynomake:wonsi:VERSION'
implementation 'io.github.dynomake:wonsi:1.0.7'
}
```

Expand All @@ -26,8 +25,8 @@ Repository:

```xml
<repository>
<id>clojars.org</id>
<url>https://repo.clojars.org</url>
<id>dynomake-repo</id>
<url>https://maven.dynomake.space/releases</url>
</repository>
```

Expand All @@ -38,6 +37,6 @@ Depend:
<dependency>
<groupId>io.github.dynomake</groupId>
<artifactId>wonsi</artifactId>
<version>VERSION</version>
<version>1.0.7</version>
</dependency>
```
4 changes: 2 additions & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
- name: Build and Publish
uses: gradle/gradle-build-action@67421db6bd0bf253fb4bd25b31ebb98943c375e1
env:
deployUser: ${{ secrets.CLOJARS_USER }}
deployToken: ${{ secrets.CLOJARS_TOKEN }}
deployUser: ${{ secrets.MAVEN_USER }}
deployToken: ${{ secrets.MAVEN_TOKEN }}
with:
arguments: publish
7 changes: 4 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ plugins {
}

group 'io.github.dynomake'
version '1.0.6'
version '1.0.7'
tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}
Expand All @@ -28,8 +28,9 @@ dependencies {
publishing {
repositories {
maven {
name = "clojars"
url = uri("https://clojars.org/repo")
name = "dynomakeRepoReleases"
url = uri("https://maven.dynomake.space/releases")

credentials {
username = "$System.env.deployUser"
password = "$System.env.deployToken"
Expand Down
20 changes: 20 additions & 0 deletions src/main/java/net/wonsi/api/Wonsi.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,24 @@ public interface Wonsi {
* @return - wonsi table handle
*/
<T> WonsiTable<T> getTable(@NonNull Class<T> tClass);


/**
* Get or create (if not exits) table by class and name
*
* @param tClass - class
* @return - wonsi table handle
*/
<T> WonsiTable<T> getTable(@NonNull Class<T> tClass, @NonNull Function<ResultSet, T> deserializer, @NonNull String tableName);


/**
* Get or create (if not exits) table by class
* if you are using this way with auto-serialisation & de, you can
* use only long number types. DO NOT USE Long, int, short, Integer.
*
* @param tClass - class
* @return - wonsi table handle
*/
<T> WonsiTable<T> getTable(@NonNull Class<T> tClass, @NonNull String tableName);
}
28 changes: 20 additions & 8 deletions src/main/java/net/wonsi/proxy/RealWonsi.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,31 @@ public class RealWonsi implements Wonsi {
public <T> WonsiTable<T> getTable(@NonNull Class<T> tClass, @NonNull Function<ResultSet, T> deserializer) {
Table tableAnnotation = tClass.getAnnotation(Table.class);

if (tableAnnotation == null) throw new IllegalArgumentException("Class don't has annotation @Table, please read documentation!");
if (tableAnnotation == null)
throw new IllegalArgumentException("Class don't has annotation @Table, please read documentation!");

return getTable(tClass, deserializer, tableAnnotation.value());
}

WonsiTable<T> table = new RealWonsiTable<>(connection, deserializer, tableAnnotation.value());
table.createIfNotExits(tClass);
@Override
public <T> WonsiTable<T> getTable(@NonNull Class<T> tClass) {
return getTable(tClass, createDeserializer(tClass));
}

@Override
public <T> WonsiTable<T> getTable(@NonNull Class<T> tClass, @NonNull Function<ResultSet, T> deserializer, @NonNull String tableName) {
WonsiTable<T> table = new RealWonsiTable<>(connection, deserializer, tableName);
table.createIfNotExits(tClass);
return table;
}

@Override
public <T> WonsiTable<T> getTable(@NonNull Class<T> tClass) {
return getTable(tClass, (resultSet) -> {
public <T> WonsiTable<T> getTable(@NonNull Class<T> tClass, @NonNull String tableName) {
return getTable(tClass, createDeserializer(tClass), tableName);
}

private <T> Function<ResultSet, T> createDeserializer(@NonNull Class<T> tClass) {
return (resultSet) -> {
try {
T object = tClass.newInstance();

Expand All @@ -47,15 +60,14 @@ public <T> WonsiTable<T> getTable(@NonNull Class<T> tClass) {
// field.getType().cast(
field.set(object, value.getClass().isAssignableFrom(field.getType()) ? value :
value.getClass().equals(Long.class) ? (((Long) value).longValue()) :
field.getType().cast(value));
field.getType().cast(value));
}

return object;
} catch (Exception exception) {
exception.printStackTrace();
return null;
}
});
};
}

}

0 comments on commit 4822c40

Please sign in to comment.