1212import com .google .common .base .Strings ;
1313import org .slf4j .Logger ;
1414
15- import java .sql .*;
15+ import java .sql .Connection ;
16+ import java .sql .DriverManager ;
17+ import java .sql .ResultSet ;
18+ import java .sql .SQLException ;
19+ import java .sql .Statement ;
1620import java .util .Map ;
1721import java .util .Properties ;
22+ import java .util .logging .Level ;
1823
1924
2025public class JDBCConnectionAdapter {
@@ -23,6 +28,10 @@ public class JDBCConnectionAdapter {
2328 private final String connUrl ;
2429 private final Map <String , String > connectionProperties ;
2530
31+ private String winLibPath ;
32+
33+ private boolean enableWindowsAuthentication ;
34+
2635
2736 private JDBCConnectionAdapter (String connStr , Map <String , String > connectionProperties ) {
2837 this .connUrl = connStr ;
@@ -36,20 +45,26 @@ static JDBCConnectionAdapter create(String connUrl, Map<String, String> connecti
3645
3746 Connection open (String driver ) throws SQLException , ClassNotFoundException {
3847 Connection connection ;
48+ java .util .logging .Logger log = java .util .logging .Logger .getLogger ("com.microsoft.sqlserver.jdbc" );
49+ log .setLevel (Level .FINE );
3950 Class .forName (driver );
40-
41- Properties properties = new Properties ();
42-
43- if (connectionProperties != null ) {
44- for (String key : connectionProperties .keySet ()) {
45- if (!Strings .isNullOrEmpty (connectionProperties .get (key )))
46- properties .put (key , connectionProperties .get (key ));
51+ logger .info ("driver====>" +driver );
52+ logger .info ("Passed all checks for properties and attempting to connect to =====>" + connUrl );
53+ long timestamp1 = System .currentTimeMillis ();
54+ if (enableWindowsAuthentication ){
55+ System .setProperty ("java.library.path" , winLibPath );
56+ logger .info ("setting the libreary path :" + winLibPath );
57+ connection = DriverManager .getConnection (connUrl );
58+ } else {
59+ Properties properties = new Properties ();
60+ if (connectionProperties != null ) {
61+ for (String key : connectionProperties .keySet ()) {
62+ if (!Strings .isNullOrEmpty (connectionProperties .get (key )))
63+ properties .put (key , connectionProperties .get (key ));
64+ }
4765 }
66+ connection = DriverManager .getConnection (connUrl , properties );
4867 }
49-
50- logger .debug ("Passed all checks for properties and attempting to connect to: " + connUrl );
51- long timestamp1 = System .currentTimeMillis ();
52- connection = DriverManager .getConnection (connUrl , properties );
5368 long timestamp2 = System .currentTimeMillis ();
5469 logger .debug ("Connection received in JDBC ConnectionAdapter in :" + (timestamp2 -timestamp1 )+ " ms" );
5570
@@ -67,4 +82,12 @@ void closeStatement(Statement statement) throws SQLException {
6782 void closeConnection (Connection connection ) throws SQLException {
6883 connection .close ();
6984 }
85+
86+ public void setWinLibPath (String winLibPath ) {
87+ this .winLibPath = winLibPath ;
88+ }
89+
90+ public void setEnableWindowsAuthentication (boolean enableWindowsAuthentication ) {
91+ this .enableWindowsAuthentication = enableWindowsAuthentication ;
92+ }
7093}
0 commit comments