提交 25344800 编写于 作者: C Charly 提交者: GitHub

Merge pull request #1812 from Sargul/devel

various fixes and enhancements for exasol
......@@ -157,8 +157,12 @@
</items>
</items>
</folder>
<folder type="" label="%tree.administer.node.name" icon="#folder_admin"
description="Maintenance/Settings">
<folder
description="Maintenance/Settings"
icon="#folder_admin"
label="%tree.administer.node.name"
type="org.jkiss.dbeaver.model.struct.DBSObject"
visibleIf="object.dataSource.UserAuthorizedForSessions">
<object type="org.jkiss.dbeaver.ext.exasol.model.app.ExasolServerSession"
label="%tree.sessions.node.name"
icon="#admin"
......@@ -177,8 +181,7 @@
description="Connections"
icon="#folder_connections"
label="%tree.connections.node.name"
type="org.jkiss.dbeaver.ext.exasol.model.ExasolConnection"
visibleIf="object.dataSource.authorizedForConnections">
type="org.jkiss.dbeaver.ext.exasol.model.ExasolConnection">
<items
icon="icons/remoteServer.gif"
label="%tree.connection.node.name"
......
......@@ -19,8 +19,10 @@ package org.jkiss.dbeaver.ext.exasol.model;
import org.jkiss.code.NotNull;
import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.ext.exasol.tools.ExasolUtils;
import org.jkiss.dbeaver.model.DBPRefreshableObject;
import org.jkiss.dbeaver.model.DBPSaveableObject;
import org.jkiss.dbeaver.model.DBPScriptObject;
import org.jkiss.dbeaver.model.impl.jdbc.JDBCUtils;
import org.jkiss.dbeaver.model.meta.Property;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
......@@ -30,7 +32,7 @@ import java.sql.Date;
import java.sql.ResultSet;
public class ExasolConnection
implements DBPRefreshableObject, DBPSaveableObject {
implements DBPRefreshableObject, DBPSaveableObject, DBPScriptObject{
private ExasolDataSource dataSource;
private String connectionName;
......@@ -121,4 +123,15 @@ public class ExasolConnection
return this;
}
@Override
public String getObjectDefinitionText(DBRProgressMonitor monitor)
throws DBException
{
if (getDataSource().isAuthorizedForConnections()) {
return ExasolUtils.getConnectionDdl(this, monitor);
} else {
return "User needs full access to dictionary or dba privilege to generate ddl for connections";
}
}
}
......@@ -43,6 +43,7 @@ public class ExasolCurrentUserPrivileges {
private final Boolean userIsAuthorizedForObjectPrivs;
private final Boolean userIsAuthorizedForConnectionPrivs;
private final Boolean userIsAuthorizedForSystemPrivs;
private final Boolean userIsAuthorizedForSessions;
private final int ExasolVersion;
......@@ -59,6 +60,7 @@ public class ExasolCurrentUserPrivileges {
userIsAuthorizedForObjectPrivs = ExasolCurrentUserPrivileges.verifyPriv(C_OBJECT_PRIV, session);
userIsAuthorizedForConnectionPrivs = ExasolCurrentUserPrivileges.verifyPriv(C_CONNECTION_PRIV, session);
userIsAuthorizedForSystemPrivs = ExasolCurrentUserPrivileges.verifyPriv("SELECT GRANTEE,PRIVILEGE,ADMIN_OPTION FROM SYS.EXA_DBA_SYS_PRIVS WHERE FALSE", session);
userIsAuthorizedForSessions = ExasolCurrentUserPrivileges.verifyPriv("SELECT * FROM SYS.EXA_DBA_SESSIONS", session);
JDBCPreparedStatement dbStat;
try {
......@@ -141,5 +143,10 @@ public class ExasolCurrentUserPrivileges {
return userIsAuthorizedForConnectionPrivs;
}
public Boolean isUserAuthorizedForSessions()
{
return userIsAuthorizedForSessions;
}
}
......@@ -181,7 +181,10 @@ public class ExasolDataSource extends JDBCDataSource
if (exasolCurrentUserPrivileges.getUserIsAuthorizedForConnections()) {
this.connectionCache = new JDBCObjectSimpleCache<>(
ExasolConnection.class, "SELECT * FROM EXA_DBA_CONNECTIONS ORDER BY CONNECTION_NAME");
ExasolConnection.class, "SELECT * FROM SYS.EXA_DBA_CONNECTIONS ORDER BY CONNECTION_NAME");
} else {
this.connectionCache = new JDBCObjectSimpleCache<>(
ExasolConnection.class, "SELECT * FROM SYS.EXA_SESSION_CONNECTIONS ORDER BY CONNECTION_NAME");
}
if (exasolCurrentUserPrivileges.getUserIsAuthorizedForConnectionPrivs())
......@@ -671,6 +674,11 @@ public class ExasolDataSource extends JDBCDataSource
return this.exasolCurrentUserPrivileges.getUserIsAuthorizedForRolePrivs();
}
public boolean isUserAuthorizedForSessions()
{
return this.exasolCurrentUserPrivileges.isUserAuthorizedForSessions();
}
public boolean isatLeastV6()
{
return this.exasolCurrentUserPrivileges.getatLeastV6();
......@@ -796,5 +804,10 @@ public class ExasolDataSource extends JDBCDataSource
{
return dataTypeCache;
}
public ExasolCurrentUserPrivileges getUserPriviliges()
{
return exasolCurrentUserPrivileges;
}
}
......@@ -224,7 +224,9 @@ public class ExasolStructureAssistant implements DBSStructureAssistant {
if (schema != null) {
sql = String.format(SQL_COLS_SCHEMA, ExasolUtils.quoteString(schema.getName()), ExasolUtils.quoteString(searchObjectNameMask));
} else {
sql = String.format(SQL_COLS_ALL, ExasolUtils.quoteString(searchObjectNameMask));
// sql = String.format(SQL_COLS_ALL, ExasolUtils.quoteString(searchObjectNameMask));
// search for columns is to slow in exasol
return;
}
......
......@@ -23,6 +23,7 @@ import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.ext.exasol.tools.ExasolUtils;
import org.jkiss.dbeaver.model.DBPDataSource;
import org.jkiss.dbeaver.model.DBPEvaluationContext;
import org.jkiss.dbeaver.model.DBPScriptObject;
import org.jkiss.dbeaver.model.DBUtils;
import org.jkiss.dbeaver.model.impl.jdbc.JDBCUtils;
import org.jkiss.dbeaver.model.impl.jdbc.struct.JDBCTableConstraint;
......@@ -40,7 +41,7 @@ import java.util.List;
/**
* @author Karl
*/
public class ExasolTableForeignKey extends JDBCTableConstraint<ExasolTable> implements DBSTableForeignKey {
public class ExasolTableForeignKey extends JDBCTableConstraint<ExasolTable> implements DBSTableForeignKey,DBPScriptObject {
private ExasolTable refTable;
......@@ -153,5 +154,12 @@ public class ExasolTableForeignKey extends JDBCTableConstraint<ExasolTable> impl
this.enabled = enabled;
}
@Override
public String getObjectDefinitionText(DBRProgressMonitor monitor)
throws DBException
{
return ExasolUtils.getFKDdl(this, monitor);
}
}
......@@ -21,8 +21,10 @@ import org.jkiss.code.NotNull;
import org.jkiss.code.Nullable;
import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.ext.exasol.ExasolConstants;
import org.jkiss.dbeaver.ext.exasol.tools.ExasolUtils;
import org.jkiss.dbeaver.model.DBPDataSource;
import org.jkiss.dbeaver.model.DBPEvaluationContext;
import org.jkiss.dbeaver.model.DBPScriptObject;
import org.jkiss.dbeaver.model.DBUtils;
import org.jkiss.dbeaver.model.impl.jdbc.JDBCUtils;
import org.jkiss.dbeaver.model.impl.jdbc.struct.JDBCTableConstraint;
......@@ -38,7 +40,7 @@ import java.util.List;
/**
* @author Karl Griesser
*/
public class ExasolTableUniqueKey extends JDBCTableConstraint<ExasolTable> implements DBSEntityReferrer {
public class ExasolTableUniqueKey extends JDBCTableConstraint<ExasolTable> implements DBSEntityReferrer,DBPScriptObject {
private String owner;
private Boolean enabled;
......@@ -134,5 +136,12 @@ public class ExasolTableUniqueKey extends JDBCTableConstraint<ExasolTable> imple
return false;
}
@Override
public String getObjectDefinitionText(DBRProgressMonitor monitor)
throws DBException
{
return ExasolUtils.getPKDdl(this, monitor);
}
}
......@@ -131,13 +131,7 @@ public class ExasolUtils {
//get only first as there is only 1 primary key
ExasolTableUniqueKey pk = null;
pk = pks.iterator().next();
ArrayList<String> columns = new ArrayList<String>();
for (DBSEntityAttributeRef c : pk.getAttributeReferences(monitor)) {
columns.add("\"" + c.getAttribute().getName() + "\"");
}
ddlOutput.append("\nALTER TABLE \"" + exasolTable.getSchema().getName() + "\".\"" + exasolTable.getName() + "\" ADD CONSTRAINT " + pk.getName() + " PRIMARY KEY (" + CommonUtils.joinStrings(",", columns) + ") " + (pk.getEnabled() ? "ENABLE" : "") + " ;\n");
ddlOutput.append(getPKDdl(pk, monitor));
}
//foreign key
......@@ -146,12 +140,7 @@ public class ExasolUtils {
//look keys
for (ExasolTableForeignKey fk : fks) {
ArrayList<String> columns = new ArrayList<String>();
for (DBSEntityAttributeRef c : fk.getAttributeReferences(monitor)) {
columns.add("\"" + c.getAttribute().getName() + "\"");
}
ddlOutput.append("\nALTER TABLE \"" + exasolTable.getSchema().getName() + "\".\"" + exasolTable.getName() + "\" ADD CONSTRAINT " + fk.getName() + " FOREIGN KEY (" + CommonUtils.joinStrings(",", columns) + ") REFERENCES \"" + fk.getReferencedTable().getSchema().getName() + "\".\"" + fk.getReferencedTable().getName() + "\" " + (fk.getEnabled() ? "ENABLE" : "") + " ;\n");
ddlOutput.append(getFKDdl(fk, monitor));
}
}
......@@ -164,6 +153,46 @@ public class ExasolUtils {
}
}
public static String getFKDdl(ExasolTableForeignKey fk, DBRProgressMonitor monitor) throws DBException
{
ExasolTable exasolTable = fk.getTable();
ArrayList<String> columns = new ArrayList<String>();
for (DBSEntityAttributeRef c : fk.getAttributeReferences(monitor)) {
columns.add("\"" + c.getAttribute().getName() + "\"");
}
String fk_enabled = " DISABLE ";
if (fk.getEnabled())
fk_enabled = " ENABLE ";
return "\nALTER TABLE \"" + exasolTable.getSchema().getName() + "\".\"" + exasolTable.getName() + "\" ADD CONSTRAINT " + fk.getName() + " FOREIGN KEY (" + CommonUtils.joinStrings(",", columns) + ") REFERENCES \"" + fk.getReferencedTable().getSchema().getName() + "\".\"" + fk.getReferencedTable().getName() + "\" " + fk_enabled + " ;\n";
}
public static String getPKDdl(ExasolTableUniqueKey pk, DBRProgressMonitor monitor) throws DBException
{
ExasolTable exasolTable = pk.getTable();
ArrayList<String> columns = new ArrayList<String>();
for (DBSEntityAttributeRef c : pk.getAttributeReferences(monitor)) {
columns.add("\"" + c.getAttribute().getName() + "\"");
}
return "\nALTER TABLE \"" + exasolTable.getSchema().getName() + "\".\"" + exasolTable.getName() + "\" ADD CONSTRAINT " + pk.getName() + " PRIMARY KEY (" + CommonUtils.joinStrings(",", columns) + ") " + (pk.getEnabled() ? " ENABLE " : " DISABLE ") + " ;\n";
}
public static String getConnectionDdl(ExasolConnection con, DBRProgressMonitor monitor) throws DBException
{
String userInfo = "";
if (con.getUserName() != null)
{
userInfo = " USER '" + con.getUserName() + "' IDENTIFIED BY '<password>' ";
}
return "CREATE CONNECTION \"" + con.getName() + "\" to '" + con.getConnectionString() + "'" + userInfo + ";";
}
private ExasolUtils() {
// Pure utility class, no instanciation allowed
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册