From f253da1bdb512296940285617089ea4062e6929d Mon Sep 17 00:00:00 2001 From: Suraiya Hameed Date: Tue, 7 Mar 2017 17:19:14 -0800 Subject: [PATCH] datasource support --- .../sqlserver/jdbc/SQLServerDataSource.java | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerDataSource.java b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerDataSource.java index a8f0fbca1..01423753a 100644 --- a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerDataSource.java +++ b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerDataSource.java @@ -22,6 +22,8 @@ import javax.naming.StringRefAddr; import javax.sql.DataSource; +import org.ietf.jgss.GSSCredential; + /** * This datasource lists properties specific for the SQLServerConnection class. */ @@ -175,6 +177,25 @@ public String getAuthentication() { SQLServerDriverStringProperty.AUTHENTICATION.getDefaultValue()); } + /** + * sets GSSCredential + * + * @param userCredential + */ + public void setGSSCredentials(GSSCredential userCredential){ + setObjectProperty(connectionProps,SQLServerDriverObjectProperty.GSS_CREDENTIAL.toString(), userCredential); + } + + /** + * Retrieves the GSSCredential + * + * @return GSSCredential + */ + public GSSCredential getGSSCredentials(){ + return (GSSCredential) getObjectProperty(connectionProps, SQLServerDriverObjectProperty.GSS_CREDENTIAL.toString(), + SQLServerDriverObjectProperty.GSS_CREDENTIAL.getDefaultValue()); + } + /** * Sets the access token. * @@ -772,6 +793,30 @@ private boolean getBooleanProperty(Properties props, return value.booleanValue(); } + private void setObjectProperty(Properties props, + String propKey, + Object propValue) { + if (loggerExternal.isLoggable(java.util.logging.Level.FINER)) { + loggerExternal.entering(getClassNameLogging(), "set" + propKey); + } + if (null != propValue) { + props.put(propKey, propValue); + } + loggerExternal.exiting(getClassNameLogging(), "set" + propKey); + } + + private Object getObjectProperty(Properties props, + String propKey, + Object defaultValue) { + if (loggerExternal.isLoggable(java.util.logging.Level.FINER)) + loggerExternal.entering(getClassNameLogging(), "get" + propKey); + Object propValue = props.get(propKey); + if (null == propValue) + propValue = defaultValue; + loggerExternal.exiting(getClassNameLogging(), "get" + propKey); + return propValue; + } + // Returns a SQLServerConnection given username, password, and pooledConnection. // Note that the DataSource properties set to connectionProps are used when creating // the connection.