提交 1ffc095e 编写于 作者: J jurgen

Context init fixed.

Datasource composite icons fixed.

Former-commit-id: 14b12f94
上级 db0ed8a1
......@@ -92,7 +92,6 @@ public abstract class AbstractExecutionContext<DATASOURCE extends DBPDataSource>
if (bootstrap.isIgnoreErrors()) {
log.warn(message);
} else {
QMUtils.getDefaultHandler().handleContextClose(this);
throw new DBCException(message, e, dataSource);
}
}
......
......@@ -66,6 +66,7 @@ public class JDBCExecutionContext extends AbstractExecutionContext<JDBCDataSourc
log.error("Reopening not-closed connection");
close();
}
boolean connectionReadOnly = dataSource.getContainer().isConnectionReadOnly();
ACTIVE_CONTEXT.set(this);
try {
this.connection = dataSource.openConnection(monitor, purpose);
......@@ -107,10 +108,18 @@ public class JDBCExecutionContext extends AbstractExecutionContext<JDBCDataSourc
}
}
this.initContextBootstrap(monitor, autoCommit);
try {
this.initContextBootstrap(monitor, autoCommit);
} catch (DBCException e) {
log.error("Error while running context bootstrap", e);
}
// Copy context state
this.dataSource.initializeContextState(monitor, this, forceActiveObject);
try {
// Copy context state
this.dataSource.initializeContextState(monitor, this, forceActiveObject && !connectionReadOnly);
} catch (DBCException e) {
log.error("Error while initializing context state", e);
}
// Add self to context list
this.dataSource.allContexts.add(this);
......
......@@ -142,13 +142,18 @@ public class DBNDataSource extends DBNDatabaseNode implements IAdaptable
public DBPImage getNodeIcon() {
DBPImage image = super.getNodeIcon();
if (dataSource.isConnectionReadOnly() || dataSource.hasNetworkHandlers()) {
return new DBIconComposite(
image,
false,
null,
dataSource.hasNetworkHandlers() ? DBIcon.OVER_EXTERNAL : null,
dataSource.isConnectionReadOnly() ? DBIcon.OVER_LOCK : null,
null);
if (image instanceof DBIconComposite) {
((DBIconComposite) image).setTopRight(dataSource.hasNetworkHandlers() ? DBIcon.OVER_EXTERNAL : null);
((DBIconComposite) image).setBottomLeft(dataSource.isConnectionReadOnly() ? DBIcon.OVER_LOCK : null);
} else {
image = new DBIconComposite(
image,
false,
null,
dataSource.hasNetworkHandlers() ? DBIcon.OVER_EXTERNAL : null,
dataSource.isConnectionReadOnly() ? DBIcon.OVER_LOCK : null,
null);
}
}
return image;
}
......
......@@ -22,7 +22,12 @@ import net.sf.jsqlparser.parser.CCJSqlParserUtil;
import net.sf.jsqlparser.schema.Database;
import net.sf.jsqlparser.schema.Table;
import net.sf.jsqlparser.statement.Statement;
import net.sf.jsqlparser.statement.alter.Alter;
import net.sf.jsqlparser.statement.create.index.CreateIndex;
import net.sf.jsqlparser.statement.create.table.CreateTable;
import net.sf.jsqlparser.statement.create.view.CreateView;
import net.sf.jsqlparser.statement.delete.Delete;
import net.sf.jsqlparser.statement.drop.Drop;
import net.sf.jsqlparser.statement.insert.Insert;
import net.sf.jsqlparser.statement.select.PlainSelect;
import net.sf.jsqlparser.statement.select.Select;
......@@ -105,8 +110,15 @@ public class SQLQuery {
type = SQLQueryType.UPDATE;
} else if (statement instanceof Delete) {
type = SQLQueryType.DELETE;
} else {
} else if (statement instanceof Alter ||
statement instanceof CreateTable ||
statement instanceof CreateView ||
statement instanceof Drop ||
statement instanceof CreateIndex)
{
type = SQLQueryType.DDL;
} else {
type = SQLQueryType.UNKNOWN;
}
} catch (Throwable e) {
this.type = SQLQueryType.UNKNOWN;
......@@ -119,7 +131,7 @@ public class SQLQuery {
* @return true is this query is a plain select
*/
public boolean isPlainSelect() {
if (statement != null && ((Select) statement).getSelectBody() instanceof PlainSelect) {
if (statement instanceof Select && ((Select) statement).getSelectBody() instanceof PlainSelect) {
PlainSelect selectBody = (PlainSelect) ((Select) statement).getSelectBody();
return selectBody.getFromItem() != null && CommonUtils.isEmpty(selectBody.getIntoTables()) && selectBody.getLimit() == null && selectBody.getTop() == null;
}
......
......@@ -59,6 +59,7 @@ import org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress;
import org.jkiss.dbeaver.model.sql.SQLQuery;
import org.jkiss.dbeaver.model.sql.SQLQueryResult;
import org.jkiss.dbeaver.model.sql.SQLQueryTransformer;
import org.jkiss.dbeaver.model.sql.SQLQueryType;
import org.jkiss.dbeaver.model.struct.DBSDataContainer;
import org.jkiss.dbeaver.model.struct.DBSDataSourceContainer;
import org.jkiss.dbeaver.model.struct.DBSObject;
......@@ -613,6 +614,22 @@ public class SQLEditor extends SQLEditorBase implements
// Nothing to process
return;
}
DBSDataSourceContainer container = getDataSourceContainer();
if (container != null && container.isConnectionReadOnly()) {
/*
// Allow only selects
for (SQLQuery query : queries) {
if (query.getType() != SQLQueryType.SELECT && query.getType() != SQLQueryType.UNKNOWN) {
UIUtils.showErrorDialog(
getSite().getShell(),
CoreMessages.editors_sql_error_cant_execute_query_title,
"Read-only connection '" + container.getName() + "' restricts execution of non-select statements. " +
"Query [" + query.getQuery() + "] is " + query.getType() + " and can't be processed");
return;
}
}
*/
}
try {
checkSession();
} catch (DBException ex) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册