-
Notifications
You must be signed in to change notification settings - Fork 2
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
1 parent
5766e4b
commit d515990
Showing
42 changed files
with
603 additions
and
216 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
5 changes: 1 addition & 4 deletions
5
src/main/java/com/github/collinalpert/java2db/annotations/ColumnName.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
5 changes: 1 addition & 4 deletions
5
src/main/java/com/github/collinalpert/java2db/annotations/Default.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
5 changes: 1 addition & 4 deletions
5
src/main/java/com/github/collinalpert/java2db/annotations/DefaultIfNull.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
9 changes: 3 additions & 6 deletions
9
src/main/java/com/github/collinalpert/java2db/annotations/ForeignKeyEntity.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
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
5 changes: 1 addition & 4 deletions
5
src/main/java/com/github/collinalpert/java2db/annotations/Ignore.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
5 changes: 1 addition & 4 deletions
5
src/main/java/com/github/collinalpert/java2db/annotations/TableName.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
37 changes: 37 additions & 0 deletions
37
src/main/java/com/github/collinalpert/java2db/database/ConnectionPool.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,37 @@ | ||
package com.github.collinalpert.java2db.database; | ||
|
||
import com.github.collinalpert.java2db.transactions.Transaction; | ||
|
||
import java.util.*; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
|
||
/** | ||
* @author Collin Alpert | ||
*/ | ||
public class ConnectionPool { | ||
|
||
private static final Map<String, Transaction> transactions; | ||
private static final DBConnection connection; | ||
|
||
static { | ||
connection = new DBConnection(); | ||
transactions = new ConcurrentHashMap<>(); | ||
} | ||
|
||
public static DBConnection getConnection() { | ||
var transactionOptional = StackWalker.getInstance().walk(s -> s.limit(10).map(x -> transactions.get(String.format("%s$%s", x.getClassName(), x.getMethodName()))).filter(Objects::nonNull).findFirst()); | ||
if (transactionOptional.isEmpty()) { | ||
return connection; | ||
} | ||
|
||
return transactionOptional.get().getConnection(); | ||
} | ||
|
||
public static void enlistTransaction(String transactionId, Transaction transaction) { | ||
transactions.put(transactionId, transaction); | ||
} | ||
|
||
public static void removeTransaction(String transactionId) { | ||
transactions.remove(transactionId); | ||
} | ||
} |
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
Oops, something went wrong.