forked from pgjdbc/pgjdbc
-
Notifications
You must be signed in to change notification settings - Fork 5
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
1b4413e
commit 62f3a49
Showing
6 changed files
with
119 additions
and
26 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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.yugabyte.ysql; | ||
|
||
import java.sql.Connection; | ||
import java.sql.SQLException; | ||
import java.util.Properties; | ||
|
||
import org.postgresql.CustomDriver; | ||
import org.postgresql.jdbc.PgConnection; | ||
import static org.postgresql.Driver.*; | ||
|
||
public class YBDriver implements CustomDriver{ | ||
|
||
/** | ||
* Create a connection from URL and properties. Always does the connection work in the current | ||
* thread without enforcing a timeout, regardless of any timeout specified in the properties. | ||
* | ||
* @param url the original URL | ||
* @param properties the parsed/defaulted connection properties | ||
* @return a new connection | ||
* @throws SQLException if the connection could not be made | ||
*/ | ||
@Override | ||
public Connection makeConnection(String url, Properties properties) throws SQLException { | ||
Connection connection = LoadBalanceManager.getConnection(url, properties, user(properties), | ||
database(properties)); | ||
if (connection != null) { | ||
return connection; | ||
} | ||
return new PgConnection(hostSpecs(properties), user(properties), database(properties), | ||
properties, url); | ||
} | ||
|
||
} |
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,24 @@ | ||
package org.postgresql; | ||
|
||
import java.sql.Connection; | ||
import java.sql.SQLException; | ||
import java.util.Properties; | ||
|
||
/** | ||
* An interface for any custom driver to implement. connect() invokes the | ||
* implemented method while processing a new connection request. | ||
*/ | ||
public interface CustomDriver { | ||
|
||
/** | ||
* Create a connection from URL and properties. Always does the connection work in the current | ||
* thread without enforcing a timeout, regardless of any timeout specified in the properties. | ||
* | ||
* @param url the original URL | ||
* @param properties the parsed/defaulted connection properties | ||
* @return a new connection | ||
* @throws SQLException if the connection could not be made | ||
*/ | ||
Connection makeConnection(String url, Properties properties) throws SQLException; | ||
|
||
} |
26 changes: 26 additions & 0 deletions
26
pgjdbc/src/main/java/org/postgresql/DefaultCustomDriver.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,26 @@ | ||
package org.postgresql; | ||
|
||
import java.sql.Connection; | ||
import java.sql.SQLException; | ||
import java.util.Properties; | ||
import org.postgresql.jdbc.PgConnection; | ||
import static org.postgresql.Driver.*; | ||
|
||
public class DefaultCustomDriver implements CustomDriver{ | ||
|
||
/** | ||
* Create a connection from URL and properties. Always does the connection work in the current | ||
* thread without enforcing a timeout, regardless of any timeout specified in the properties. | ||
* | ||
* @param url the original URL | ||
* @param properties the parsed/defaulted connection properties | ||
* @return a new connection | ||
* @throws SQLException if the connection could not be made | ||
*/ | ||
@Override | ||
public Connection makeConnection(String url, Properties properties) throws SQLException { | ||
return new PgConnection(hostSpecs(properties), user(properties), database(properties), | ||
properties, url); | ||
} | ||
|
||
} |
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