-
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.
2. added method logger prefix 3. added db config in the DatabaseException 4. added repeat method in Util 5. updated pom to have required dependency for testing purpose 6. updated the Readme.md with examples
- Loading branch information
1 parent
e670d80
commit 86080a1
Showing
9 changed files
with
287 additions
and
47 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,60 @@ | ||
# Database | ||
Simple Database wrapper written in Java to easily execute storedProcedure with flexible functions to meet requirements for all cases | ||
Simple Database wrapper written in Java to easily execute storedProcedure with flexible functions to meet requirements for all cases. | ||
|
||
In case one wants to enable logging then corresponding slf4j implementation for respective logger will have to be added as a dependency. | ||
|
||
Time taken for establishing DB connection as well as for executing the query is logged at **INFO** level. | ||
|
||
## How to use it !! | ||
|
||
#### Create DatabaseConfig | ||
* For Single Connection | ||
```java | ||
DatabaseConfig MSSQL_DATABASE_CONFIG = new DatabaseConfig("KEYWORD_MASTER", | ||
DatabaseTypeImpl.MSSQL, | ||
"skenzo_dev", | ||
"Skenzo_Dev", | ||
"net.sourceforge.jtds.jdbc.Driver", | ||
"jdbc:jtds:sqlserver://172.19.19.19;databaseName=KEYWORD_MASTER"); | ||
``` | ||
|
||
* For Pooled Connections | ||
*Create PoolProperties and Pass it to DatabaseConfig | ||
```java | ||
PoolProperties POOL_PROPERTIES = new PoolProperties() {{ | ||
setTestOnBorrow(true); | ||
setTestOnReturn(true); | ||
}}; | ||
DatabaseConfig MSSQL_POOLED_DATABASE_CONFIG = new DatabaseConfig("KEYWORD_MASTER", | ||
DatabaseTypeImpl.MSSQL, | ||
"skenzo_dev", | ||
"Skenzo_Dev", | ||
"net.sourceforge.jtds.jdbc.Driver", | ||
"jdbc:jtds:sqlserver://172.19.19.19;databaseName=KEYWORD_MASTER", | ||
POOL_PROPERTIES); | ||
``` | ||
|
||
#### Extend abstract class Database and match the constructor | ||
|
||
```java | ||
public class DatabaseTest extends Database { | ||
public DatabaseTest(DatabaseConfig databaseConfig) { | ||
super(databaseConfig); | ||
} | ||
} | ||
``` | ||
|
||
#### Initialize the Derived Class by passing DatabaseConfig to it | ||
|
||
```java | ||
DatabaseTest mssqlDB = new DatabaseTest(MSSQL_DATABASE_CONFIG); | ||
DatabaseTest mssqlPooledDB = new DatabaseTest(MSSQL_POOLED_DATABASE_CONFIG); | ||
``` | ||
|
||
#### Use the Derived Class object to executeQuery | ||
|
||
```java | ||
StoredProcedureCall<String> storedProcedureCall = new StoredProcedureCall<>("sp_server_info", resultSet -> (resultSet.getString("attribute_name"))); | ||
List<String> values = database.executeQuery(storedProcedureCall); | ||
System.out.println(values); | ||
``` |
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
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,10 @@ | ||
import java.util.List; | ||
|
||
/** | ||
* Created by sumeet | ||
* on 25/4/17. | ||
*/ | ||
@FunctionalInterface | ||
public interface DatabaseType { | ||
String getProcedureCallString(String storedProcedureName, List<Parameter> parameters); | ||
} |
Oops, something went wrong.