-
-
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.
- Loading branch information
suuft (valeriy)
committed
Mar 5, 2023
1 parent
03e1240
commit 12ce790
Showing
14 changed files
with
231 additions
and
80 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
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 |
---|---|---|
@@ -1,6 +1,12 @@ | ||
## | `Lithe DI - Learn project` | ||
## | `Wonsi - Learn project` | ||
Hi! This is a learn project, if you have idea or know how to refactor the code, be sure to send me pull requests, issues. Im not adequate criticism. | ||
### | `Road-Map`: | ||
1) Add Automatic-Generation adept. | ||
2) Add Auto-Injection Depends. | ||
3) Refactor all. | ||
1) Add Automatic Serialization | ||
2) Refactor all. | ||
### | `Used patterns`: | ||
1) Builder | ||
2) Factory | ||
3) Template Method | ||
4) Mediator | ||
5) Command | ||
6) Facade |
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 |
---|---|---|
@@ -1,7 +1,6 @@ | ||
## | `Wonsi Objest Mapping` | ||
A small & fast but convenient framework for working with dependencies. I'll add dependency injection soon. | ||
|
||
The best, free, fast ORM that will simplify working with SQL-like databases. WITHOUT USING REFLECTION (used only when initializing the table). In project contains protection about sql injections. | ||
### | `Links`: | ||
* [About this learn project](https://github.com/suuft/Lithe/blob/master/LEARN.md) | ||
* [Add as Depend](https://github.com/suuft/Lithe/blob/master/.github/DEPEND.md) | ||
* [Usage Example](https://github.com/suuft/Lithe/blob/master/.github/USAGE.md) | ||
* [About this learn project](https://github.com/suuft/wonsi/blob/master/LEARN.md) | ||
* [Add as Depend](https://github.com/suuft/wonsi/blob/master/.github/DEPEND.md) | ||
* [Usage Example](https://github.com/suuft/wonsi/blob/master/.github/USAGE.md) |
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 |
---|---|---|
@@ -1,4 +1,17 @@ | ||
package net.wonsi.api.request; | ||
|
||
import lombok.NonNull; | ||
import net.wonsi.util.Condition; | ||
|
||
import java.util.Map; | ||
import java.util.function.Consumer; | ||
|
||
public interface UpdateRequest extends Request { | ||
|
||
UpdateRequest where(Condition condition); | ||
|
||
UpdateRequest data(@NonNull Consumer<Map<String, Object>> insertData); | ||
|
||
UpdateRequest limit(int limit); | ||
|
||
} |
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
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
75 changes: 75 additions & 0 deletions
75
src/main/java/net/wonsi/proxy/request/RealUpdateRequest.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,75 @@ | ||
package net.wonsi.proxy.request; | ||
|
||
import com.google.common.base.Joiner; | ||
import net.wonsi.api.request.UpdateRequest; | ||
import net.wonsi.util.Condition; | ||
import net.wonsi.util.ExecutorUtil; | ||
|
||
import java.sql.Connection; | ||
import java.sql.PreparedStatement; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.concurrent.CompletableFuture; | ||
import java.util.function.Consumer; | ||
|
||
public class RealUpdateRequest implements UpdateRequest { | ||
|
||
private final Connection connection; | ||
private final String tableName; | ||
private String condition; | ||
private int limit; | ||
private Map<String, Object> data; | ||
|
||
public RealUpdateRequest(Connection connection, String tableName) { | ||
this.connection = connection; | ||
this.tableName = tableName; | ||
condition = "0"; | ||
limit = 10; | ||
} | ||
|
||
|
||
@Override | ||
public CompletableFuture<Void> async() { | ||
return CompletableFuture.runAsync(this::sync); | ||
} | ||
|
||
@Override | ||
public void sync() { | ||
try { | ||
PreparedStatement statement = connection.prepareStatement("UPDATE " + tableName + Joiner.on("= ?,").join(data.keySet()) + " = ? LIMIT = ?"); | ||
|
||
int currentArgument = 1; | ||
|
||
for (Object o : data.values()) { | ||
statement.setObject(currentArgument, o); | ||
currentArgument++; | ||
} | ||
|
||
statement.setObject(currentArgument, limit); | ||
|
||
ExecutorUtil.execute(statement, connection); | ||
} catch (Exception exception) { | ||
exception.printStackTrace(); | ||
} | ||
} | ||
|
||
@Override | ||
public UpdateRequest where(Condition condition) { | ||
this.condition = condition.toString(); | ||
return this; | ||
} | ||
|
||
@Override | ||
public UpdateRequest data(Consumer<Map<String, Object>> insertData) { | ||
data = new HashMap<>(); | ||
insertData.accept(data); | ||
|
||
return this; | ||
} | ||
|
||
@Override | ||
public UpdateRequest limit(int limit) { | ||
this.limit = limit; | ||
return this; | ||
} | ||
} |
Oops, something went wrong.