|
1 | 1 | package ai.chat2db.plugin.mariadb; |
2 | 2 |
|
3 | | -import java.sql.Connection; |
4 | | -import java.util.ArrayList; |
5 | | -import java.util.List; |
6 | 3 |
|
7 | 4 | import ai.chat2db.plugin.mysql.MysqlMetaData; |
8 | 5 | import ai.chat2db.spi.MetaData; |
9 | | -import ai.chat2db.spi.jdbc.DefaultMetaService; |
10 | | -import ai.chat2db.spi.model.Function; |
11 | | -import ai.chat2db.spi.model.Procedure; |
12 | | -import ai.chat2db.spi.model.Table; |
13 | | -import ai.chat2db.spi.model.Trigger; |
14 | | -import ai.chat2db.spi.sql.SQLExecutor; |
15 | | -import jakarta.validation.constraints.NotEmpty; |
16 | 6 |
|
17 | 7 | public class MariaDBMetaData extends MysqlMetaData implements MetaData { |
18 | 8 |
|
19 | | - |
20 | | -// private static String ROUTINES_SQL |
21 | | -// = |
22 | | -// "SELECT SPECIFIC_NAME, ROUTINE_COMMENT, ROUTINE_DEFINITION FROM information_schema.routines WHERE " |
23 | | -// + "routine_type = '%s' AND ROUTINE_SCHEMA ='%s' AND " |
24 | | -// + "routine_name = '%s';"; |
25 | | -// |
26 | | -// @Override |
27 | | -// public Function function(Connection connection, @NotEmpty String databaseName, String schemaName, |
28 | | -// String functionName) { |
29 | | -// |
30 | | -// String sql = String.format(ROUTINES_SQL, "FUNCTION", databaseName, functionName); |
31 | | -// return SQLExecutor.getInstance().execute(connection, sql, resultSet -> { |
32 | | -// Function function = new Function(); |
33 | | -// function.setDatabaseName(databaseName); |
34 | | -// function.setSchemaName(schemaName); |
35 | | -// function.setFunctionName(functionName); |
36 | | -// if (resultSet.next()) { |
37 | | -// function.setSpecificName(resultSet.getString("SPECIFIC_NAME")); |
38 | | -// function.setRemarks(resultSet.getString("ROUTINE_COMMENT")); |
39 | | -// function.setFunctionBody(resultSet.getString("ROUTINE_DEFINITION")); |
40 | | -// } |
41 | | -// return function; |
42 | | -// }); |
43 | | -// |
44 | | -// } |
45 | | -// |
46 | | -// private static String TRIGGER_SQL |
47 | | -// = "SELECT TRIGGER_NAME,EVENT_MANIPULATION, ACTION_STATEMENT FROM INFORMATION_SCHEMA.TRIGGERS where " |
48 | | -// + "TRIGGER_SCHEMA = '%s' AND TRIGGER_NAME = '%s';"; |
49 | | -// |
50 | | -// private static String TRIGGER_SQL_LIST |
51 | | -// = "SELECT TRIGGER_NAME FROM INFORMATION_SCHEMA.TRIGGERS where TRIGGER_SCHEMA = '%s';"; |
52 | | -// |
53 | | -// @Override |
54 | | -// public List<Trigger> triggers(Connection connection, String databaseName, String schemaName) { |
55 | | -// List<Trigger> triggers = new ArrayList<>(); |
56 | | -// String sql = String.format(TRIGGER_SQL_LIST, databaseName); |
57 | | -// return SQLExecutor.getInstance().execute(connection, sql, resultSet -> { |
58 | | -// while (resultSet.next()) { |
59 | | -// Trigger trigger = new Trigger(); |
60 | | -// trigger.setTriggerName(resultSet.getString("TRIGGER_NAME")); |
61 | | -// trigger.setSchemaName(schemaName); |
62 | | -// trigger.setDatabaseName(databaseName); |
63 | | -// triggers.add(trigger); |
64 | | -// } |
65 | | -// return triggers; |
66 | | -// }); |
67 | | -// } |
68 | | -// |
69 | | -// @Override |
70 | | -// public Trigger trigger(Connection connection, @NotEmpty String databaseName, String schemaName, |
71 | | -// String triggerName) { |
72 | | -// |
73 | | -// String sql = String.format(TRIGGER_SQL, databaseName, triggerName); |
74 | | -// return SQLExecutor.getInstance().execute(connection, sql, resultSet -> { |
75 | | -// Trigger trigger = new Trigger(); |
76 | | -// trigger.setDatabaseName(databaseName); |
77 | | -// trigger.setSchemaName(schemaName); |
78 | | -// trigger.setTriggerName(triggerName); |
79 | | -// if (resultSet.next()) { |
80 | | -// trigger.setTriggerBody(resultSet.getString("ACTION_STATEMENT")); |
81 | | -// } |
82 | | -// return trigger; |
83 | | -// }); |
84 | | -// } |
85 | | -// |
86 | | -// @Override |
87 | | -// public Procedure procedure(Connection connection, @NotEmpty String databaseName, String schemaName, |
88 | | -// String procedureName) { |
89 | | -// String sql = String.format(ROUTINES_SQL, "PROCEDURE", databaseName, procedureName); |
90 | | -// return SQLExecutor.getInstance().execute(connection, sql, resultSet -> { |
91 | | -// Procedure procedure = new Procedure(); |
92 | | -// procedure.setDatabaseName(databaseName); |
93 | | -// procedure.setSchemaName(schemaName); |
94 | | -// procedure.setProcedureName(procedureName); |
95 | | -// if (resultSet.next()) { |
96 | | -// procedure.setSpecificName(resultSet.getString("SPECIFIC_NAME")); |
97 | | -// procedure.setRemarks(resultSet.getString("ROUTINE_COMMENT")); |
98 | | -// procedure.setProcedureBody(resultSet.getString("ROUTINE_DEFINITION")); |
99 | | -// } |
100 | | -// return procedure; |
101 | | -// }); |
102 | | -// } |
103 | | -// |
104 | | -// private static String VIEW_SQL |
105 | | -// = "SELECT TABLE_SCHEMA AS DatabaseName, TABLE_NAME AS ViewName, VIEW_DEFINITION AS definition, CHECK_OPTION, " |
106 | | -// + "IS_UPDATABLE FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_SCHEMA = '%s' AND TABLE_NAME = '%s';"; |
107 | | -// |
108 | | -// @Override |
109 | | -// public Table view(Connection connection, String databaseName, String schemaName, String viewName) { |
110 | | -// String sql = String.format(VIEW_SQL, databaseName, viewName); |
111 | | -// return SQLExecutor.getInstance().execute(connection, sql, resultSet -> { |
112 | | -// Table table = new Table(); |
113 | | -// table.setDatabaseName(databaseName); |
114 | | -// table.setSchemaName(schemaName); |
115 | | -// table.setName(viewName); |
116 | | -// if (resultSet.next()) { |
117 | | -// table.setDdl(resultSet.getString("definition")); |
118 | | -// } |
119 | | -// return table; |
120 | | -// }); |
121 | | -// } |
122 | 9 | } |
0 commit comments