-
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.
ledger-book: adding new source-connector for use pool-configured data…
…source.
- Loading branch information
Showing
2 changed files
with
91 additions
and
1 deletion.
There are no files selected for viewing
89 changes: 89 additions & 0 deletions
89
LedgerBook/src/main/java/com/itsoul/lab/ledgerbook/connector/SQLDataSourceConnector.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,89 @@ | ||
package com.itsoul.lab.ledgerbook.connector; | ||
|
||
import com.it.soul.lab.sql.QueryExecutor; | ||
import com.it.soul.lab.sql.SQLExecutor; | ||
|
||
import javax.sql.DataSource; | ||
import java.sql.Connection; | ||
import java.sql.SQLException; | ||
|
||
public final class SQLDataSourceConnector implements SourceConnector{ | ||
|
||
private DataSource dataSource; | ||
private String driverClassName; | ||
private String url; | ||
private String username; | ||
private String password; | ||
private String schema; | ||
private boolean shouldGenerateSchema; | ||
|
||
public SQLDataSourceConnector(DataSource dataSource) { | ||
this.dataSource = dataSource; | ||
} | ||
|
||
@Override | ||
public Connection getConnection() throws SQLException { | ||
if (dataSource == null) throw new SQLException("DataSource must not be null!"); | ||
return dataSource.getConnection(); | ||
} | ||
|
||
@Override | ||
public QueryExecutor getExecutor() throws SQLException { | ||
return new SQLExecutor(getConnection()); | ||
} | ||
|
||
public SQLDataSourceConnector url(String url) { | ||
this.url = url; | ||
return this; | ||
} | ||
|
||
public SQLDataSourceConnector username(String username) { | ||
this.username = username; | ||
return this; | ||
} | ||
|
||
public SQLDataSourceConnector password(String password) { | ||
this.password = password; | ||
return this; | ||
} | ||
|
||
public SQLDataSourceConnector schema(String schema) { | ||
this.schema = schema; | ||
return this; | ||
} | ||
|
||
public SQLDataSourceConnector skipSchemaGeneration(boolean skip){ | ||
this.shouldGenerateSchema = !skip; | ||
return this; | ||
} | ||
|
||
public SQLDataSourceConnector driverClassName(String driverClassName) { | ||
this.driverClassName = driverClassName; | ||
return this; | ||
} | ||
|
||
@Override | ||
public boolean generateSchema() { | ||
return shouldGenerateSchema; | ||
} | ||
|
||
public String driverClassName() { | ||
return this.driverClassName; | ||
} | ||
|
||
public String url() { | ||
return this.url; | ||
} | ||
|
||
public String username() { | ||
return this.username; | ||
} | ||
|
||
public String password() { | ||
return this.password; | ||
} | ||
|
||
public String schema() { | ||
return schema; | ||
} | ||
} |
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