This is an automated email from the ASF dual-hosted git repository.

wuweijie pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git


The following commit(s) were added to refs/heads/master by this push:
     new d392eb5  Use direct call to instead of event post on 
CreateDatabaseBackendHandler (#11492)
d392eb5 is described below

commit d392eb5cc890e0ff73218357285b85657e176492
Author: Liang Zhang <[email protected]>
AuthorDate: Sun Jul 25 14:55:59 2021 +0800

    Use direct call to instead of event post on CreateDatabaseBackendHandler 
(#11492)
---
 .../event/DatabaseCreatedSQLNotificationEvent.java | 32 ----------------------
 .../SchemaMetaDataRegistrySubscriber.java          | 13 +--------
 .../SchemaMetaDataRegistrySubscriberTest.java      | 10 +------
 .../database/CreateDatabaseBackendHandler.java     |  9 +-----
 4 files changed, 3 insertions(+), 61 deletions(-)

diff --git 
a/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/registry/metadata/event/DatabaseCreatedSQLNotificationEvent.java
 
b/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/registry/metadata/event/DatabaseCreatedSQLNotificationEvent.java
deleted file mode 100644
index f40045f..0000000
--- 
a/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/registry/metadata/event/DatabaseCreatedSQLNotificationEvent.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shardingsphere.governance.core.registry.metadata.event;
-
-import lombok.Getter;
-import lombok.RequiredArgsConstructor;
-import org.apache.shardingsphere.governance.core.registry.SQLNotificationEvent;
-
-/**
- * Database created SQL notification event.
- */
-@RequiredArgsConstructor
-@Getter
-public final class DatabaseCreatedSQLNotificationEvent implements 
SQLNotificationEvent {
-    
-    private final String databaseName;
-}
diff --git 
a/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/registry/metadata/subscriber/SchemaMetaDataRegistrySubscriber.java
 
b/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/registry/metadata/subscriber/SchemaMetaDataRegistrySubscriber.java
index 78bfbf8..1e54fd8 100644
--- 
a/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/registry/metadata/subscriber/SchemaMetaDataRegistrySubscriber.java
+++ 
b/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/registry/metadata/subscriber/SchemaMetaDataRegistrySubscriber.java
@@ -18,10 +18,9 @@
 package org.apache.shardingsphere.governance.core.registry.metadata.subscriber;
 
 import com.google.common.eventbus.Subscribe;
-import 
org.apache.shardingsphere.governance.core.registry.metadata.event.DatabaseCreatedSQLNotificationEvent;
 import 
org.apache.shardingsphere.governance.core.registry.metadata.event.DatabaseDroppedSQLNotificationEvent;
-import 
org.apache.shardingsphere.infra.config.persist.service.SchemaMetaDataPersistService;
 import 
org.apache.shardingsphere.governance.repository.spi.RegistryCenterRepository;
+import 
org.apache.shardingsphere.infra.config.persist.service.SchemaMetaDataPersistService;
 import org.apache.shardingsphere.infra.eventbus.ShardingSphereEventBus;
 import 
org.apache.shardingsphere.infra.metadata.schema.refresher.event.SchemaAlteredEvent;
 
@@ -38,16 +37,6 @@ public final class SchemaMetaDataRegistrySubscriber {
     }
     
     /**
-     * Update when database created.
-     *
-     * @param event database created SQL notification event
-     */
-    @Subscribe
-    public void update(final DatabaseCreatedSQLNotificationEvent event) {
-        persistService.persist(event.getDatabaseName(), null);
-    }
-    
-    /**
      * Update when meta data altered.
      *
      * @param event schema altered event
diff --git 
a/shardingsphere-governance/shardingsphere-governance-core/src/test/java/org/apache/shardingsphere/governance/core/registry/metadata/subscriber/SchemaMetaDataRegistrySubscriberTest.java
 
b/shardingsphere-governance/shardingsphere-governance-core/src/test/java/org/apache/shardingsphere/governance/core/registry/metadata/subscriber/SchemaMetaDataRegistrySubscriberTest.java
index 3998e33..5da7fdf 100644
--- 
a/shardingsphere-governance/shardingsphere-governance-core/src/test/java/org/apache/shardingsphere/governance/core/registry/metadata/subscriber/SchemaMetaDataRegistrySubscriberTest.java
+++ 
b/shardingsphere-governance/shardingsphere-governance-core/src/test/java/org/apache/shardingsphere/governance/core/registry/metadata/subscriber/SchemaMetaDataRegistrySubscriberTest.java
@@ -17,10 +17,9 @@
 
 package org.apache.shardingsphere.governance.core.registry.metadata.subscriber;
 
-import 
org.apache.shardingsphere.governance.core.registry.metadata.event.DatabaseCreatedSQLNotificationEvent;
 import 
org.apache.shardingsphere.governance.core.registry.metadata.event.DatabaseDroppedSQLNotificationEvent;
-import 
org.apache.shardingsphere.infra.config.persist.service.SchemaMetaDataPersistService;
 import 
org.apache.shardingsphere.governance.repository.spi.RegistryCenterRepository;
+import 
org.apache.shardingsphere.infra.config.persist.service.SchemaMetaDataPersistService;
 import org.apache.shardingsphere.infra.metadata.schema.ShardingSphereSchema;
 import 
org.apache.shardingsphere.infra.metadata.schema.refresher.event.SchemaAlteredEvent;
 import org.junit.Before;
@@ -51,13 +50,6 @@ public final class SchemaMetaDataRegistrySubscriberTest {
     }
     
     @Test
-    public void assertUpdateWithDatabaseCreatedSQLNotificationEvent() {
-        DatabaseCreatedSQLNotificationEvent event = new 
DatabaseCreatedSQLNotificationEvent("bar_db");
-        schemaMetaDataRegistrySubscriber.update(event);
-        verify(persistService).persist("bar_db", null);
-    }
-    
-    @Test
     public void assertUpdateWithMetaDataAlteredEvent() {
         SchemaAlteredEvent event = new SchemaAlteredEvent("foo_db", 
mock(ShardingSphereSchema.class));
         schemaMetaDataRegistrySubscriber.update(event);
diff --git 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/database/CreateDatabaseBackendHandler.java
 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/database/CreateDatabaseBackendHandler.java
index e1cd5ef..6e246f5 100644
--- 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/database/CreateDatabaseBackendHandler.java
+++ 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/database/CreateDatabaseBackendHandler.java
@@ -18,8 +18,6 @@
 package org.apache.shardingsphere.proxy.backend.text.database;
 
 import lombok.RequiredArgsConstructor;
-import 
org.apache.shardingsphere.governance.core.registry.metadata.event.DatabaseCreatedSQLNotificationEvent;
-import org.apache.shardingsphere.infra.eventbus.ShardingSphereEventBus;
 import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
 import 
org.apache.shardingsphere.proxy.backend.exception.DBCreateExistsException;
 import org.apache.shardingsphere.proxy.backend.response.header.ResponseHeader;
@@ -38,7 +36,7 @@ public final class CreateDatabaseBackendHandler implements 
TextProtocolBackendHa
     @Override
     public ResponseHeader execute() {
         check(sqlStatement);
-        post(sqlStatement);
+        
ProxyContext.getInstance().getMetaDataContexts().getConfigCenter().getSchemaMetaDataService().persist(sqlStatement.getDatabaseName(),
 null);
         return new UpdateResponseHeader(sqlStatement);
     }
     
@@ -47,9 +45,4 @@ public final class CreateDatabaseBackendHandler implements 
TextProtocolBackendHa
             throw new DBCreateExistsException(sqlStatement.getDatabaseName());
         }
     }
-    
-    private void post(final CreateDatabaseStatement sqlStatement) {
-        // TODO Need to get the executed feedback from registry center for 
returning.
-        ShardingSphereEventBus.getInstance().post(new 
DatabaseCreatedSQLNotificationEvent(sqlStatement.getDatabaseName()));
-    }
 }

Reply via email to