-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SNOW-1571459 parse jbdc properties (#909)
- Loading branch information
1 parent
05c1148
commit 3dabfc0
Showing
10 changed files
with
226 additions
and
47 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
86 changes: 86 additions & 0 deletions
86
src/main/java/com/snowflake/kafka/connector/internal/JdbcProperties.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,86 @@ | ||
package com.snowflake.kafka.connector.internal; | ||
|
||
import java.util.Properties; | ||
|
||
/** Wrapper class for all snowflake jdbc properties */ | ||
public class JdbcProperties { | ||
|
||
/** All jdbc properties including proxyProperties */ | ||
private final Properties properties; | ||
/** Proxy related properties */ | ||
private final Properties proxyProperties; | ||
|
||
private JdbcProperties(Properties combinedProperties, Properties proxyProperties) { | ||
this.properties = combinedProperties; | ||
this.proxyProperties = proxyProperties; | ||
} | ||
|
||
public Properties getProperties() { | ||
return properties; | ||
} | ||
|
||
public String getProperty(String key) { | ||
return properties.getProperty(key); | ||
} | ||
|
||
public Object get(String key) { | ||
return properties.get(key); | ||
} | ||
|
||
public Properties getProxyProperties() { | ||
return proxyProperties; | ||
} | ||
|
||
/** | ||
* Combine all jdbc related properties. Throws error if jdbcPropertiesMap overrides any property | ||
* defined in connectionProperties or proxyProperties. | ||
* | ||
* @param connectionProperties snowflake.database.name, snowflake.schema,name, | ||
* snowflake.private.key etc. | ||
* @param proxyProperties jvm.proxy.xxx | ||
* @param jdbcPropertiesMap snowflake.jdbc.map | ||
*/ | ||
static JdbcProperties create( | ||
Properties connectionProperties, Properties proxyProperties, Properties jdbcPropertiesMap) { | ||
InternalUtils.assertNotEmpty("connectionProperties", connectionProperties); | ||
proxyProperties = setEmptyIfNull(proxyProperties); | ||
jdbcPropertiesMap = setEmptyIfNull(jdbcPropertiesMap); | ||
|
||
Properties proxyAndConnection = mergeProperties(connectionProperties, proxyProperties); | ||
detectOverrides(proxyAndConnection, jdbcPropertiesMap); | ||
|
||
Properties combinedProperties = mergeProperties(proxyAndConnection, jdbcPropertiesMap); | ||
|
||
return new JdbcProperties(combinedProperties, proxyProperties); | ||
} | ||
|
||
/** Test method */ | ||
static JdbcProperties create(Properties connectionProperties) { | ||
return create(connectionProperties, new Properties(), new Properties()); | ||
} | ||
|
||
private static void detectOverrides(Properties proxyAndConnection, Properties jdbcPropertiesMap) { | ||
jdbcPropertiesMap.forEach( | ||
(k, v) -> { | ||
if (proxyAndConnection.containsKey(k)) { | ||
throw SnowflakeErrors.ERROR_0031.getException("Duplicated property: " + k); | ||
} | ||
}); | ||
} | ||
|
||
private static Properties mergeProperties( | ||
Properties connectionProperties, Properties proxyProperties) { | ||
Properties mergedProperties = new Properties(); | ||
mergedProperties.putAll(connectionProperties); | ||
mergedProperties.putAll(proxyProperties); | ||
return mergedProperties; | ||
} | ||
|
||
/** Parsing methods does not return null. However, It's better to be perfectly sure. */ | ||
private static Properties setEmptyIfNull(Properties properties) { | ||
if (properties != null) { | ||
return properties; | ||
} | ||
return new Properties(); | ||
} | ||
} |
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
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
Oops, something went wrong.