You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@eventmesh.apache.org by mi...@apache.org on 2022/10/18 10:00:32 UTC
[incubator-eventmesh] branch storage-api updated: [ISSUE #1646] connector-storage-jdbc StorageSQL interface
This is an automated email from the ASF dual-hosted git repository.
mikexue pushed a commit to branch storage-api
in repository https://gitbox.apache.org/repos/asf/incubator-eventmesh.git
The following commit(s) were added to refs/heads/storage-api by this push:
new 9a1ce9e9 [ISSUE #1646] connector-storage-jdbc StorageSQL interface
new e43a7105 Merge pull request #1647 from githublaohu/jdbc-connector-storage
9a1ce9e9 is described below
commit 9a1ce9e9ba1bca5e684a58fe109b21932304448a
Author: githublaohu <23...@qq.com>
AuthorDate: Tue Oct 18 17:57:44 2022 +0800
[ISSUE #1646] connector-storage-jdbc StorageSQL interface
---
.../connector/storage/jdbc/SQL/StorageSQL.java | 76 ++++++++++++++++++++++
.../storage/jdbc/SQL/StorageSQLService.java | 67 +++++++++++++++++++
2 files changed, 143 insertions(+)
diff --git a/eventmesh-connector-plugin/eventmesh-connector-storage-jdbc/src/main/java/org/apache/eventmesh/connector/storage/jdbc/SQL/StorageSQL.java b/eventmesh-connector-plugin/eventmesh-connector-storage-jdbc/src/main/java/org/apache/eventmesh/connector/storage/jdbc/SQL/StorageSQL.java
new file mode 100644
index 00000000..7d7ea7ec
--- /dev/null
+++ b/eventmesh-connector-plugin/eventmesh-connector-storage-jdbc/src/main/java/org/apache/eventmesh/connector/storage/jdbc/SQL/StorageSQL.java
@@ -0,0 +1,76 @@
+/*
+ * 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.eventmesh.connector.storage.jdbc.SQL;
+
+public interface StorageSQL {
+
+ public String insertSQL(String tableName);
+
+ public String selectSQL(String tableName);
+
+ public String selectConsumerGroup();
+
+ public String insertConsumerGroup();
+
+ public String createDatabaseSQL(String databaseName);
+
+ public String topicTableCreateSQL(String table);
+
+ public String consumerGroupTableCreateSQL();
+
+ public String locationEventSQL(String tableName);
+
+ public String queryLocationEventSQL(String tableName);
+
+ public String selectFastMessageSQL(String tableName);
+
+ public String selectLastMessageSQL(String tableName);
+
+ public String selectNoConsumptionMessageSQL(String tableName, Long consumerGroupId);
+
+ public String selectAppointTimeMessageSQL(String tableName, String time);
+
+ public String queryTables();
+
+ public default String replySelectSQL(String table, int num) {
+ StringBuffer sql = new StringBuffer();
+ sql.append("select * from ").append(table).append(" where cloud_event_info_id in(");
+ for (int i = 1; i <= num; i++) {
+ sql.append("?");
+ if (i != num) {
+ sql.append(",");
+ }
+ }
+ sql.append(")");
+ sql.append(" and cloud_event_reply_data is not null");
+ return sql.toString();
+ }
+
+ public default String replyResult(String table) {
+ StringBuffer sql = new StringBuffer();
+ sql.append(" update ").append(table)
+ .append(" set cloud_event_reply_data = ? , cloud_event_reply_state = 'NOTHING' where cloud_event_info_id = ?");
+ return sql.toString();
+ }
+
+ public default String updateOffsetSQL(String table) {
+ StringBuffer sql = new StringBuffer();
+ sql.append("update ").append(table).append(" set cloud_event_state = 'SUCCESS' where cloud_event_info_id = ?");
+ return sql.toString();
+ }
+}
diff --git a/eventmesh-connector-plugin/eventmesh-connector-storage-jdbc/src/main/java/org/apache/eventmesh/connector/storage/jdbc/SQL/StorageSQLService.java b/eventmesh-connector-plugin/eventmesh-connector-storage-jdbc/src/main/java/org/apache/eventmesh/connector/storage/jdbc/SQL/StorageSQLService.java
new file mode 100644
index 00000000..f3e846b2
--- /dev/null
+++ b/eventmesh-connector-plugin/eventmesh-connector-storage-jdbc/src/main/java/org/apache/eventmesh/connector/storage/jdbc/SQL/StorageSQLService.java
@@ -0,0 +1,67 @@
+/*
+ * 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.eventmesh.connector.storage.jdbc.SQL;
+
+import java.io.BufferedInputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.lang.reflect.Proxy;
+
+import org.yaml.snakeyaml.Yaml;
+
+public class StorageSQLService {
+
+ private Object object;
+
+ public StorageSQLService(String dbName) throws Exception {
+ String rootPath = StorageSQLService.class.getProtectionDomain().getCodeSource().getLocation().getPath();
+ if (rootPath.endsWith("/bin/main/")) {
+ rootPath = rootPath + "../../src/main/resource/";
+ }
+ CloudEventSQL cloudEventSQL = this.readYaml(rootPath + dbName + "-cloudevent.yaml", CloudEventSQL.class);
+ BaseSQL baseSQL = this.readYaml(rootPath + dbName + "-base.yaml", BaseSQL.class);
+ ConsumerGroupSQL consumerGroupSQL = this.readYaml(rootPath + dbName + "-consumer-group.yaml",
+ ConsumerGroupSQL.class);
+
+ SQLServiceInvocationHandler SQLServiceHandler = new SQLServiceInvocationHandler();
+ SQLServiceHandler.analysis(baseSQL);
+ SQLServiceHandler.analysis(cloudEventSQL);
+ SQLServiceHandler.analysis(consumerGroupSQL);
+ object = Proxy.newProxyInstance(this.getClass().getClassLoader(),
+ new Class[] {CloudEventSQLOperation.class, BaseSQLOperation.class, ConsumerGroupSQLOperation.class},
+ SQLServiceHandler);
+ }
+
+ @SuppressWarnings("unchecked")
+ public <T> T getObject() {
+ return (T) this.object;
+ }
+
+ @SuppressWarnings("unchecked")
+ private <T> T readYaml(String path, Class<?> clazz) throws FileNotFoundException {
+ File file = new File(path);
+ if (!file.exists()) {
+ String errer = String.format("file does not exist , paht %s", path);
+ throw new RuntimeException(errer);
+ }
+
+ Yaml yaml = new Yaml();
+ return (T) yaml.loadAs(new BufferedInputStream(new FileInputStream(file)), clazz);
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@eventmesh.apache.org
For additional commands, e-mail: commits-help@eventmesh.apache.org