asereda-gs commented on a change in pull request #1036: [CALCITE-2815] 
GeodeSchemaFactory change to pass in clientCache using jndi
URL: https://github.com/apache/calcite/pull/1036#discussion_r256064720
 
 

 ##########
 File path: 
geode/src/main/java/org/apache/calcite/adapter/geode/rel/GeodeSchemaFactory.java
 ##########
 @@ -39,18 +46,58 @@
   public static final String PDX_SERIALIZABLE_PACKAGE_PATH = 
"pdxSerializablePackagePath";
   public static final String ALLOW_SPATIAL_FUNCTIONS = "spatialFunction";
   public static final String COMMA_DELIMITER = ",";
+  public static final String JNDI_INITIAL_CONTEXT_FACTORY = 
"jndiInitialContextFactory";
+  public static final String JNDI_CLIENT_CACHE_OBJECT_KEY = 
"jndiClientCacheObjectKey";
 
   public GeodeSchemaFactory() {
     // Do Nothing
   }
 
+  private static Context getContext(Map map) {
+    Context context = null;
+
+    try {
+      String jndiInitialContextFactory = (String) 
map.get(JNDI_INITIAL_CONTEXT_FACTORY);
+      Hashtable env = new Hashtable();
+      env.put(Context.INITIAL_CONTEXT_FACTORY, jndiInitialContextFactory);
+      context = new InitialContext(env);
+    } catch (NamingException ignored) {
+
+    }
+
+    return context;
+  }
+
+  private static GemFireCache getGemFireCache(Map map) {
+    GemFireCache gemFireCache = null;
+
+    try {
+      String clientCacheObjectKey = (String) 
map.get(JNDI_CLIENT_CACHE_OBJECT_KEY);
+
+      if (clientCacheObjectKey == null) {
+        String locatorHost = (String) map.get(LOCATOR_HOST);
+        int locatorPort = Integer.valueOf((String) map.get(LOCATOR_PORT));
+        String[] regionNames = ((String) 
map.get(REGIONS)).split(COMMA_DELIMITER);
+        String pbxSerializablePackagePath = (String) 
map.get(PDX_SERIALIZABLE_PACKAGE_PATH);
+
+        gemFireCache = GeodeUtils.createClientCache(locatorHost, locatorPort,
+            pbxSerializablePackagePath, true);
+      } else {
+        Context context = getContext(map);
+        gemFireCache = (GemFireCache) context.lookup(clientCacheObjectKey);
 
 Review comment:
   Perhaps extract jndi lookup into a separate class ? 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to