taojintianxia commented on a change in pull request #12820:
URL: https://github.com/apache/shardingsphere/pull/12820#discussion_r718321437



##########
File path: 
shardingsphere-mode/shardingsphere-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/ContextManager.java
##########
@@ -63,6 +79,74 @@ public synchronized void renewTransactionContexts(final 
TransactionContexts tran
         this.transactionContexts = transactionContexts;
     }
     
+    /**
+     * Add schema.
+     * 
+     * @param schemaName schema name
+     * @throws SQLException SQL exception                  
+     */
+    public void addSchema(final String schemaName) throws SQLException {
+        if (metaDataContexts.getMetaDataMap().containsKey(schemaName)) {
+            return;
+        }
+        MetaDataContexts newMetaDataContexts = 
buildNewMetaDataContext(schemaName);
+        
metaDataContexts.getOptimizerContext().getMetaData().getSchemas().put(schemaName,
+                
newMetaDataContexts.getOptimizerContext().getMetaData().getSchemas().get(schemaName));
+        metaDataContexts.getMetaDataMap().put(schemaName, 
newMetaDataContexts.getMetaData(schemaName));
+    }
+    
+    /**
+     * Delete schema.
+     * 
+     * @param schemaName schema name
+     */
+    public void deleteSchema(final String schemaName) {
+        if (metaDataContexts.getMetaDataMap().containsKey(schemaName)) {
+            
metaDataContexts.getOptimizerContext().getMetaData().getSchemas().remove(schemaName);
+            
metaDataContexts.getOptimizerContext().getParserContexts().remove(schemaName);
+            
metaDataContexts.getOptimizerContext().getPlannerContexts().remove(schemaName);
+            ShardingSphereMetaData removeMetaData = 
metaDataContexts.getMetaDataMap().remove(schemaName);
+            closeDataSources(removeMetaData);
+            closeTransactionEngine(schemaName);
+        }
+    }
+    
+    private MetaDataContexts buildNewMetaDataContext(final String schemaName) 
throws SQLException {
+        Map<String, Map<String, DataSource>> dataSourcesMap = 
Collections.singletonMap(schemaName, new HashMap<>());

Review comment:
       map inside a map ? I'm not sure if multimap is better here . not 
formaliar with that . 
   
   multimap ... from guava.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to