Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #115 from rchodava/database-types-and-h2
Support multiple database types, add H2 database support
- Loading branch information
Showing
14 changed files
with
493 additions
and
58 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
45 changes: 45 additions & 0 deletions
45
core/src/main/java/foundation/stack/datamill/db/DatabaseType.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,45 @@ | ||
package foundation.stack.datamill.db; | ||
|
||
import java.net.URI; | ||
|
||
/** | ||
* @author Ravi Chodavarapu (rchodava@gmail.com) | ||
*/ | ||
public enum DatabaseType { | ||
MYSQL, | ||
H2; | ||
|
||
private static boolean isH2Url(URI uri) { | ||
String scheme = uri.getScheme(); | ||
if (scheme != null) { | ||
if (scheme.contains("h2")) { | ||
return true; | ||
} else if (scheme.contains("jdbc")) { | ||
String schemeSpecificPart = uri.getSchemeSpecificPart(); | ||
return schemeSpecificPart != null && schemeSpecificPart.startsWith("h2"); | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
|
||
private static boolean isH2Url(String uri) { | ||
if (uri != null) { | ||
try { | ||
URI parsed = URI.create(uri); | ||
return isH2Url(parsed); | ||
} catch (IllegalArgumentException e) { | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
|
||
public static DatabaseType guess(String uri) { | ||
if (isH2Url(uri)) { | ||
return H2; | ||
} | ||
|
||
return MYSQL; | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
core/src/main/java/foundation/stack/datamill/db/impl/DatabaseTypeAdapter.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,20 @@ | ||
package foundation.stack.datamill.db.impl; | ||
|
||
import java.sql.Connection; | ||
import java.sql.SQLException; | ||
|
||
/** | ||
* @author Ravi Chodavarapu (rchodava@gmail.com) | ||
*/ | ||
public interface DatabaseTypeAdapter { | ||
interface ConnectionPreparer { | ||
void prepare(Connection connection) throws SQLException; | ||
} | ||
|
||
interface UrlTransformer { | ||
String transform(String url); | ||
} | ||
|
||
ConnectionPreparer createConnectionPreparer(); | ||
UrlTransformer createUrlTransformer(); | ||
} |
Oops, something went wrong.