提交 090e4cc3 编写于 作者: K Karl Grießer

Exasol Foreign Key Manager Implementation

上级 b710cbc7
......@@ -14,7 +14,8 @@ Require-Bundle: org.eclipse.ui,
org.jkiss.dbeaver.core,
org.eclipse.ui.workbench.texteditor,
org.eclipse.ui.editors,
org.jkiss.dbeaver.ext.ui.locks
org.jkiss.dbeaver.ext.ui.locks,
org.eclipse.core.resources
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
Bundle-Vendor: JKISS
......
......@@ -239,3 +239,7 @@ tree.virtualschema.node.name = Virtual Schema
tree.virtualschemaparameters.node.name = Virtual Schema Parameters
tree.virtualschemas.node.name = Virtual Schemas
tree.locks.node.name = Lock Manager
meta.org.jkiss.dbeaver.model.struct.rdb.DBSTableConstraintColumn.attribute.name=Column Name
meta.org.jkiss.dbeaver.model.struct.rdb.DBSTableConstraintColumn.ordinalPosition.name=Ordinal Position
......@@ -447,6 +447,10 @@
class="org.jkiss.dbeaver.ext.exasol.manager.ExasolConnectionManager"
objectType="org.jkiss.dbeaver.ext.exasol.model.ExasolConnection">
</manager>
<manager
class="org.jkiss.dbeaver.ext.exasol.manager.ExasolForeignKeyManager"
objectType="org.jkiss.dbeaver.ext.exasol.model.ExasolTableForeignKey">
</manager>
</extension>
<extension point="org.eclipse.ui.editors">
<editor
......
......@@ -207,4 +207,7 @@ tree.viewsauths.node.name = View Berechtigungen
tree.virtualschema.node.name = Virtuelles Schema
tree.virtualschemaparameters.node.name = Virtuelles Schema - Parameter
tree.virtualschemas.node.name = Virtuelle Schemata
tree.locks.node.name = Lock Manager
\ No newline at end of file
tree.locks.node.name = Lock Manager
meta.org.jkiss.dbeaver.model.struct.rdb.DBSTableConstraintColumn.attribute.name = Spaltenname
meta.org.jkiss.dbeaver.model.struct.rdb.DBSTableConstraintColumn.ordinalPosition.name = Spaltennr.
......@@ -62,6 +62,7 @@ public class ExasolMessages extends NLS {
public static String dialog_table_tools_row_sep;
public static String dialog_table_tools_encoding;
public static String dialog_table_tools_import_title;
public static String dialog_struct_edit_fk_label_fk_name;
}
......@@ -28,6 +28,7 @@ dialog_table_tools_file_template=File Template
dialog_table_tools_export_title=Export to CSV File
dialog_table_tools_import_title=Import from CSV File
dialog_struct_edit_fk_label_fk_name=Foreign Key Name
editors_exasol_session_editor_title_kill_session = Kill Session
......
......@@ -46,3 +46,6 @@ editors_exasol_session_editor_confirm_action = {0} "{1}". Sind Sie sicher?
editors_exasol_session_editor_title_kill_session = Verbindung terminieren
editors_exasol_session_editor_title_kill_session_statement = Befehl terminieren
dialog_struct_edit_fk_label_fk_name=Fremschl\u00FCsselname
\ No newline at end of file
......@@ -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.DBPNamedObject2;
import org.jkiss.dbeaver.model.DBPScriptObject;
import org.jkiss.dbeaver.model.DBUtils;
import org.jkiss.dbeaver.model.impl.jdbc.JDBCUtils;
......@@ -41,13 +42,14 @@ import java.util.List;
/**
* @author Karl
*/
public class ExasolTableForeignKey extends JDBCTableConstraint<ExasolTable> implements DBSTableForeignKey,DBPScriptObject {
public class ExasolTableForeignKey extends JDBCTableConstraint<ExasolTable> implements DBSTableForeignKey,DBPScriptObject, DBPNamedObject2 {
private ExasolTable refTable;
private String constName;
private Boolean enabled;
private List<ExasolTableKeyColumn> columns;
private ExasolTableUniqueKey referencedKey;
......@@ -60,18 +62,22 @@ public class ExasolTableForeignKey extends JDBCTableConstraint<ExasolTable> impl
String refSchemaName = JDBCUtils.safeGetString(dbResult, "REFERENCED_SCHEMA");
String refTableName = JDBCUtils.safeGetString(dbResult, "REFERENCED_TABLE");
String constName = JDBCUtils.safeGetString(dbResult, "REF_PK_NAME");
this.constName = JDBCUtils.safeGetString(dbResult, "CONSTRAINT_NAME");
String refConstName = JDBCUtils.safeGetString(dbResult, "REF_PK_NAME");
refTable = ExasolUtils.findTableBySchemaNameAndName(monitor, exasolTable.getDataSource(), refSchemaName, refTableName);
enabled = JDBCUtils.safeGetBoolean(dbResult, "CONSTRAINT_ENABLED");
referencedKey = refTable.getConstraint(monitor, constName);
referencedKey = refTable.getConstraint(monitor, refConstName);
}
public ExasolTableForeignKey(ExasolTable exasolTable, ExasolTableUniqueKey referencedKey, Boolean enabled) {
super(exasolTable, null, null, DBSEntityConstraintType.FOREIGN_KEY, true);
public ExasolTableForeignKey(ExasolTable exasolTable, ExasolTableUniqueKey referencedKey, Boolean enabled, String name) {
super(exasolTable, name, "", DBSEntityConstraintType.FOREIGN_KEY, true);
this.referencedKey = referencedKey;
this.enabled = enabled;
this.constName = name;
this.refTable = referencedKey.getTable();
}
......@@ -160,6 +166,19 @@ public class ExasolTableForeignKey extends JDBCTableConstraint<ExasolTable> impl
{
return ExasolUtils.getFKDdl(this, monitor);
}
@Override
@Property(viewable = true)
public String getName()
{
return this.constName;
}
@Override
public void setName(String name)
{
this.constName = name;
}
}
......@@ -21,6 +21,7 @@ import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.Log;
import org.jkiss.dbeaver.ext.exasol.model.*;
import org.jkiss.dbeaver.ext.exasol.model.app.ExasolServerSession;
import org.jkiss.dbeaver.model.DBPEvaluationContext;
import org.jkiss.dbeaver.model.DBUtils;
import org.jkiss.dbeaver.model.exec.jdbc.JDBCResultSet;
import org.jkiss.dbeaver.model.exec.jdbc.JDBCSession;
......@@ -131,7 +132,7 @@ public class ExasolUtils {
//get only first as there is only 1 primary key
ExasolTableUniqueKey pk = null;
pk = pks.iterator().next();
ddlOutput.append(getPKDdl(pk, monitor));
ddlOutput.append("\n" + getPKDdl(pk, monitor) + ";\n");
}
//foreign key
......@@ -140,7 +141,7 @@ public class ExasolUtils {
//look keys
for (ExasolTableForeignKey fk : fks) {
ddlOutput.append(getFKDdl(fk, monitor));
ddlOutput.append("\n" + getFKDdl(fk, monitor) + ";\n");
}
}
......@@ -158,15 +159,25 @@ public class ExasolUtils {
{
ExasolTable exasolTable = fk.getTable();
ArrayList<String> columns = new ArrayList<String>();
ArrayList<String> refColumns = new ArrayList<String>();
for (DBSEntityAttributeRef c : fk.getAttributeReferences(monitor)) {
columns.add("\"" + c.getAttribute().getName() + "\"");
columns.add(DBUtils.getQuotedIdentifier(c.getAttribute()));
}
for (DBSEntityAttributeRef c : fk.getReferencedConstraint().getAttributeReferences(monitor))
{
refColumns.add(DBUtils.getQuotedIdentifier(c.getAttribute()));
}
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";
return "ALTER TABLE " + DBUtils.getObjectFullName(exasolTable, DBPEvaluationContext.DDL) +
" ADD CONSTRAINT " + DBUtils.getQuotedIdentifier(fk) +
" FOREIGN KEY (" + CommonUtils.joinStrings(",", columns) +
") REFERENCES " + DBUtils.getObjectFullName(fk.getAssociatedEntity(), DBPEvaluationContext.DDL) + " (" +
CommonUtils.joinStrings(",", refColumns) + ")" + fk_enabled;
}
......@@ -177,7 +188,7 @@ public class ExasolUtils {
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";
return "ALTER TABLE " + DBUtils.getObjectFullName(exasolTable, DBPEvaluationContext.DDL) + " ADD CONSTRAINT " + DBUtils.getQuotedIdentifier(pk) + " PRIMARY KEY (" + CommonUtils.joinStrings(",", columns) + ") " + (pk.getEnabled() ? " ENABLE " : " DISABLE ");
}
public static String getConnectionDdl(ExasolConnection con, DBRProgressMonitor monitor) throws DBException
......
......@@ -59,12 +59,10 @@ public class ExasolConnectionDialog extends BaseDialog {
final Composite group = new Composite(composite, SWT.NONE);
group.setLayout(new GridLayout(2, false));
final Text nameText = UIUtils.createLabelText(group, "Schema Name", "");
final Text nameText = UIUtils.createLabelText(group, "Connection Name", "");
final Text urlText = UIUtils.createLabelText(group,"Connection URL", "");
final Group configGroup = UIUtils.createControlGroup(group, "Credentials", 1, GridData.FILL_HORIZONTAL, 0);
Button saveCred = UIUtils.createCheckbox(configGroup, "Provide Credentials", false);
......@@ -80,6 +78,7 @@ public class ExasolConnectionDialog extends BaseDialog {
public void modifyText(ModifyEvent e) {
name = nameText.getText();
user = userText.getText();
url = urlText.getText();
password = passwordText.getText();
comment = commentText.getText();
getButton(IDialogConstants.OK_ID).setEnabled(!name.isEmpty());
......
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2016-2017 Karl Griesser (fullref@gmail.com)
* Copyright (C) 2010-2017 Serge Rider (serge@jkiss.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jkiss.dbeaver.ext.exasol.ui;
import java.util.ArrayList;
......@@ -40,7 +58,6 @@ public class ExasolCreateSchemaDialog extends BaseDialog {
this.datasource = datasource;
}
@SuppressWarnings("unchecked")
@Override
protected Composite createDialogArea(Composite parent)
{
......@@ -71,7 +88,6 @@ public class ExasolCreateSchemaDialog extends BaseDialog {
@Override
protected IStatus run(DBRProgressMonitor monitor) {
try {
final List<String> granteeNames = new ArrayList<>();
grantees = new ArrayList<>(datasource.getAllGrantees(monitor));
DBeaverUI.syncExec(new Runnable() {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册