Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CB-2700 sql editor delimiter support #2068

Merged
merged 2 commits into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,7 @@
import org.jkiss.dbeaver.model.navigator.DBNDatabaseItem;
import org.jkiss.dbeaver.model.navigator.DBNNode;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
import org.jkiss.dbeaver.model.sql.SQLQuery;
import org.jkiss.dbeaver.model.sql.SQLSyntaxManager;
import org.jkiss.dbeaver.model.sql.SQLUtils;
import org.jkiss.dbeaver.model.sql.*;
import org.jkiss.dbeaver.model.sql.parser.SQLParserContext;
import org.jkiss.dbeaver.model.sql.parser.SQLRuleManager;
import org.jkiss.dbeaver.model.sql.parser.SQLScriptParser;
Expand Down Expand Up @@ -173,7 +171,7 @@
long startTime = System.currentTimeMillis();
WebSQLExecuteInfo executeInfo = new WebSQLExecuteInfo();

DBSDataContainer dataContainer = new WebSQLQueryDataContainer(connection.getDataSource(), sql);
var dataContainer = new WebSQLQueryDataContainer(connection.getDataSource(), sql);

DBCExecutionContext context = getExecutionContext(dataContainer);

Expand All @@ -198,63 +196,69 @@
ruleManager,
document);

SQLQuery sqlQuery = (SQLQuery) SQLScriptParser.extractActiveQuery(parserContext, 0, sql.length());

DBExecUtils.tryExecuteRecover(monitor, connection.getDataSource(), param -> {
try (DBCSession session = context.openSession(monitor, resolveQueryPurpose(dataFilter), "Execute SQL")) {
AbstractExecutionSource source = new AbstractExecutionSource(
dataContainer,
session.getExecutionContext(),
WebSQLProcessor.this,
sqlQuery);

try (DBCStatement dbStat = DBUtils.makeStatement(
source,
session,
DBCStatementType.SCRIPT,
sqlQuery,
webDataFilter.getOffset(),
webDataFilter.getLimit()))
{
SqlOutputLogReaderJob sqlOutputLogReaderJob = null;
if (readLogs) {
DBPDataSource dataSource = context.getDataSource();
DBCServerOutputReader dbcServerOutputReader = DBUtils.getAdapter(DBCServerOutputReader.class, dataSource);
if (dbcServerOutputReader == null) {
dbcServerOutputReader = new DefaultServerOutputReader();
SQLScriptElement element = SQLScriptParser.extractActiveQuery(parserContext, 0, sql.length());

if (element instanceof SQLControlCommand command) {
dataContainer.getScriptContext().executeControlCommand(command);
WebSQLQueryResults stats = new WebSQLQueryResults(webSession, dataFormat);
executeInfo.setResults(new WebSQLQueryResults[]{stats});
} else if (element instanceof SQLQuery sqlQuery) {
DBExecUtils.tryExecuteRecover(monitor, connection.getDataSource(), param -> {
try (DBCSession session = context.openSession(monitor, resolveQueryPurpose(dataFilter), "Execute SQL")) {
AbstractExecutionSource source = new AbstractExecutionSource(
dataContainer,
session.getExecutionContext(),
WebSQLProcessor.this,
sqlQuery);

try (DBCStatement dbStat = DBUtils.makeStatement(
source,
session,
DBCStatementType.SCRIPT,
sqlQuery,
webDataFilter.getOffset(),
webDataFilter.getLimit()))
{

Check warning on line 221 in server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/service/sql/WebSQLProcessor.java

View check run for this annotation

Jenkins-CI-integration / CheckStyle Java Report

server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/service/sql/WebSQLProcessor.java#L221

[ at column 25 should be on the previous line.
SqlOutputLogReaderJob sqlOutputLogReaderJob = null;
if (readLogs) {
DBPDataSource dataSource = context.getDataSource();
DBCServerOutputReader dbcServerOutputReader = DBUtils.getAdapter(DBCServerOutputReader.class, dataSource);
if (dbcServerOutputReader == null) {
dbcServerOutputReader = new DefaultServerOutputReader();
}
sqlOutputLogReaderJob = new SqlOutputLogReaderJob(
webSession, context, dbStat, dbcServerOutputReader, contextInfo.getId());
sqlOutputLogReaderJob.schedule();
}
sqlOutputLogReaderJob = new SqlOutputLogReaderJob(
webSession, context, dbStat, dbcServerOutputReader, contextInfo.getId());
sqlOutputLogReaderJob.schedule();
}
// Set query timeout
int queryTimeout = (int) session.getDataSource().getContainer().getPreferenceStore()
.getDouble(WebSQLConstants.QUOTA_PROP_SQL_QUERY_TIMEOUT);
if (queryTimeout <= 0) {
queryTimeout = CommonUtils.toInt(
getWebSession().getApplication().getAppConfiguration()
.getResourceQuota(WebSQLConstants.QUOTA_PROP_SQL_QUERY_TIMEOUT));
}
if (queryTimeout > 0) {
try {
dbStat.setStatementTimeout(queryTimeout);
} catch (Throwable e) {
log.debug("Can't set statement timeout:" + e.getMessage());
// Set query timeout
int queryTimeout = (int) session.getDataSource().getContainer().getPreferenceStore()
.getDouble(WebSQLConstants.QUOTA_PROP_SQL_QUERY_TIMEOUT);
if (queryTimeout <= 0) {
queryTimeout = CommonUtils.toInt(
getWebSession().getApplication().getAppConfiguration()
.getResourceQuota(WebSQLConstants.QUOTA_PROP_SQL_QUERY_TIMEOUT));
}
if (queryTimeout > 0) {
try {
dbStat.setStatementTimeout(queryTimeout);
} catch (Throwable e) {
log.debug("Can't set statement timeout:" + e.getMessage());
}
}
}

boolean hasResultSet = dbStat.executeStatement();
boolean hasResultSet = dbStat.executeStatement();

// Wait SqlLogStateJob, if its starts
if (sqlOutputLogReaderJob != null) {
sqlOutputLogReaderJob.join();
// Wait SqlLogStateJob, if its starts
if (sqlOutputLogReaderJob != null) {
sqlOutputLogReaderJob.join();
}
fillQueryResults(contextInfo, dataContainer, dbStat, hasResultSet, executeInfo, webDataFilter, dataFilter, dataFormat);

Check warning on line 255 in server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/service/sql/WebSQLProcessor.java

View check run for this annotation

Jenkins-CI-integration / CheckStyle Java Report

server/bundles/io.cloudbeaver.server/src/io/cloudbeaver/service/sql/WebSQLProcessor.java#L255

Line is longer than 140 characters (found 147).
} catch (DBException e) {
throw new InvocationTargetException(e);
}
fillQueryResults(contextInfo, dataContainer, dbStat, hasResultSet, executeInfo, webDataFilter, dataFilter, dataFormat);
} catch (DBException e) {
throw new InvocationTargetException(e);
}
}
});
});
}
} catch (DBException e) {
throw new DBWebException("Error executing query", e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,9 @@ public DBCExecutionContext getExecutionContext() {
return DBUtils.getDefaultContext(dataSource, false);
}

@NotNull
public SQLScriptContext getScriptContext() {
return queryDataContainer.getScriptContext();
}

}
Loading