mirror of
https://github.com/dbeaver/cloudbeaver.git
synced 2026-09-24 16:04:36 +08:00
CB-1214 add ap for SQL script parser
This commit is contained in:
@@ -174,6 +174,17 @@ type SQLQueryGenerator {
|
||||
multiObject: Boolean!
|
||||
}
|
||||
|
||||
####################################################
|
||||
# SQL Query info
|
||||
####################################################
|
||||
type SQLScriptInfo {
|
||||
queries: [ SQLScriptQuery ]
|
||||
}
|
||||
|
||||
type SQLScriptQuery {
|
||||
start: Int!
|
||||
end: Int!
|
||||
}
|
||||
####################################################
|
||||
# Query and Mutation
|
||||
####################################################
|
||||
@@ -224,6 +235,11 @@ extend type Query {
|
||||
options: Object!,
|
||||
nodePathList: [String!]!
|
||||
): String!
|
||||
|
||||
sqlParseScript(
|
||||
connectionId: ID!,
|
||||
script: String
|
||||
): SQLScriptInfo
|
||||
}
|
||||
|
||||
extend type Mutation {
|
||||
|
||||
@@ -127,4 +127,6 @@ public interface DBWServiceSQL extends DBWService {
|
||||
@WebAction
|
||||
WebSQLExecutionPlan asyncSqlExplainExecutionPlanResult(@NotNull WebSession webSession, @NotNull String taskId) throws DBWebException;
|
||||
|
||||
@WebAction
|
||||
WebSQLScriptInfo parseSqlScript(@NotNull WebSQLProcessor processor, @NotNull String sqlScript) throws DBWebException;
|
||||
}
|
||||
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
package io.cloudbeaver.service.sql;
|
||||
|
||||
import org.jkiss.dbeaver.model.meta.Property;
|
||||
|
||||
public class WebSQLQueryInfo {
|
||||
private final int start;
|
||||
private final int end;
|
||||
|
||||
public WebSQLQueryInfo(int start, int end) {
|
||||
this.start = start;
|
||||
this.end = end;
|
||||
}
|
||||
|
||||
@Property
|
||||
public int getEnd() {
|
||||
return end;
|
||||
}
|
||||
|
||||
@Property
|
||||
public int getStart() {
|
||||
return start;
|
||||
}
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
package io.cloudbeaver.service.sql;
|
||||
|
||||
import org.jkiss.dbeaver.model.meta.Property;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class WebSQLScriptInfo {
|
||||
private final List<WebSQLQueryInfo> queries;
|
||||
|
||||
public WebSQLScriptInfo(List<WebSQLQueryInfo> queries) {
|
||||
this.queries = queries;
|
||||
}
|
||||
|
||||
@Property
|
||||
public List<WebSQLQueryInfo> getQueries() {
|
||||
return queries;
|
||||
}
|
||||
}
|
||||
+2
@@ -89,6 +89,8 @@ public class WebServiceBindingSQL extends WebServiceBindingBase<DBWServiceSQL> i
|
||||
env.getArgument("generatorId"),
|
||||
env.getArgument("options"),
|
||||
env.getArgument("nodePathList"))
|
||||
).dataFetcher("sqlParseScript", env ->
|
||||
getService(env).parseSqlScript(getSQLProcessor(env), env.getArgument("script"))
|
||||
)
|
||||
;
|
||||
|
||||
|
||||
+14
@@ -55,6 +55,7 @@ import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Web service implementation
|
||||
@@ -397,4 +398,17 @@ public class WebServiceSQL implements DBWServiceSQL {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WebSQLScriptInfo parseSqlScript(@NotNull WebSQLProcessor processor, @NotNull String sqlScript) throws DBWebException {
|
||||
DBPDataSource dataSource = processor.getConnection().getDataSourceContainer().getDataSource();
|
||||
if (dataSource == null) {
|
||||
throw new DBWebException("Data source was not found");
|
||||
}
|
||||
List<SQLScriptElement> queries = SQLScriptParser.parseScript(dataSource, sqlScript);
|
||||
List<WebSQLQueryInfo> queriesInfo = queries.stream()
|
||||
.map(query -> new WebSQLQueryInfo(query.getOffset(), query.getLength() + query.getOffset()))
|
||||
.collect(Collectors.toList());
|
||||
return new WebSQLScriptInfo(queriesInfo);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user