diff --git a/com.cubrid.common.core/src/com/cubrid/common/core/common/model/Synonym.java b/com.cubrid.common.core/src/com/cubrid/common/core/common/model/Synonym.java new file mode 100644 index 00000000..66a40bba --- /dev/null +++ b/com.cubrid.common.core/src/com/cubrid/common/core/common/model/Synonym.java @@ -0,0 +1,130 @@ +/* + * Copyright (C) 2013 Search Solution Corporation. All rights reserved by Search + * Solution. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: - + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. - Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. - Neither the name of the nor the names + * of its contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + */ + +package com.cubrid.common.core.common.model; + +import java.util.Locale; + +public class Synonym implements + Comparable { + private String name; + private String owner; + private String targetName; + private String targetOwner; + private String comment; + + /** + * compare to the argument obj + * + * @param obj Synonym + * @return int + */ + public int compareTo(Synonym obj) { + return getUniqueName().compareTo(obj.getUniqueName()); + } + + /** + * compare to the argument obj + * + * @param obj Synonym + * @return int + */ + public int targetCompareTo(Synonym obj) { + return getTargetUniqueName().compareTo(obj.getTargetUniqueName()); + } + + /** + * @param obj the reference object with which to compare. + * @return true if this object is the same as the obj argument; false + * otherwise. + */ + @Override + public boolean equals(Object obj) { + return obj instanceof Synonym && getUniqueName().equals(((Synonym) obj).getUniqueName()); + } + + public boolean targetEquals(Object obj) { + return obj instanceof Synonym && getTargetUniqueName().equals(((Synonym) obj).getTargetUniqueName()); + } + + /** + * @return a hash code value for this object. + */ + @Override + public int hashCode() { + return name.hashCode(); + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getOwner() { + return owner; + } + + public void setOwner(String owner) { + this.owner = owner; + } + + public String getTargetName() { + return targetName; + } + + public void setTargetName(String name) { + this.targetName = name; + } + + public String getTargetOwner() { + return targetOwner; + } + + public void setTargetOwner(String owner) { + this.targetOwner = owner; + } + + public void setComment(String comment) { + this.comment = comment; + } + + public String getComment() { + return comment; + } + + public String getUniqueName() { + return owner + "." + name; + } + + public String getTargetUniqueName() { + return targetOwner + "." + targetName; + } +} diff --git a/com.cubrid.common.core/src/com/cubrid/common/core/util/QuerySyntax.java b/com.cubrid.common.core/src/com/cubrid/common/core/util/QuerySyntax.java index 4622d43c..9ab8b29c 100644 --- a/com.cubrid.common.core/src/com/cubrid/common/core/util/QuerySyntax.java +++ b/com.cubrid.common.core/src/com/cubrid/common/core/util/QuerySyntax.java @@ -749,6 +749,26 @@ public static String escapeKeyword(String text) { return "[" + text + "]"; } + public static String escapeKeywordFromUniqueName(String text, boolean isSupportUserSchema) { + if (text == null) { + return null; + } + + if (text.length() == 0) { + return ""; + } + + if (isSupportUserSchema) { + int idx = text.indexOf("."); + if (idx > 0) { + String ownerName = text.substring(0, idx); + String className = text.substring(idx + 1); + return escapeKeyword(ownerName) + "." + escapeKeyword(className); + } + } + return escapeKeyword(text); + } + /** * Get the Key words map. * diff --git a/com.cubrid.common.ui/META-INF/MANIFEST.MF b/com.cubrid.common.ui/META-INF/MANIFEST.MF index 2b639313..13fe9e3b 100644 --- a/com.cubrid.common.ui/META-INF/MANIFEST.MF +++ b/com.cubrid.common.ui/META-INF/MANIFEST.MF @@ -109,6 +109,10 @@ Export-Package: ., com.cubrid.common.ui.cubrid.trigger.action, com.cubrid.common.ui.cubrid.trigger.dialog, com.cubrid.common.ui.cubrid.trigger.editor, + com.cubrid.common.ui.cubrid.synonym, + com.cubrid.common.ui.cubrid.synonym.action, + com.cubrid.common.ui.cubrid.synonym.dialog, + com.cubrid.common.ui.cubrid.synonym.editor, com.cubrid.common.ui.cubrid.user, com.cubrid.common.ui.cubrid.user.action, com.cubrid.common.ui.cubrid.user.dialog, diff --git a/com.cubrid.common.ui/icons/navigator/synonym_group.png b/com.cubrid.common.ui/icons/navigator/synonym_group.png new file mode 100644 index 00000000..76b30de2 Binary files /dev/null and b/com.cubrid.common.ui/icons/navigator/synonym_group.png differ diff --git a/com.cubrid.common.ui/icons/navigator/synonym_item.png b/com.cubrid.common.ui/icons/navigator/synonym_item.png new file mode 100644 index 00000000..b559c265 Binary files /dev/null and b/com.cubrid.common.ui/icons/navigator/synonym_item.png differ diff --git a/com.cubrid.common.ui/plugin.properties b/com.cubrid.common.ui/plugin.properties index dc921ca1..3c24dc56 100644 --- a/com.cubrid.common.ui/plugin.properties +++ b/com.cubrid.common.ui/plugin.properties @@ -22,6 +22,7 @@ cubridBrokerConfEditorPartName=Broker Editor tableInfoEditorName=Edit Table viewsDetailInfoName=View Dashboard triggersDetailInfoName=Trigger Dashboard +synonymsDetailInfoName=Synonym Dashboard serialsDetailInfoName=Serial Dashboard schemaCompareName=Compare DB schema dataCompareName=Compare DB data diff --git a/com.cubrid.common.ui/plugin.xml b/com.cubrid.common.ui/plugin.xml index e5b76134..41b02ef8 100644 --- a/com.cubrid.common.ui/plugin.xml +++ b/com.cubrid.common.ui/plugin.xml @@ -135,6 +135,13 @@ id="com.cubrid.common.ui.cubrid.trigger.editor.TriggerDashboardEditorPart" name="%triggersDetailInfoName"> + + nor the names + * of its contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + */ +package com.cubrid.common.ui.cubrid.synonym; + +import org.eclipse.osgi.util.NLS; + +import com.cubrid.common.ui.CommonUIPlugin; + +public class Messages extends + NLS { + + static { + NLS.initializeMessages(CommonUIPlugin.PLUGIN_ID + + ".cubrid.synonym.Messages", Messages.class); + } + public static String dropSynonymWarnMSG1; + public static String dropSynonymWarnMSG2; + public static String infoSQLScriptTab; + public static String infoSynonymTab; + public static String msgWarning; + public static String okBTN; + public static String cancleBTN; + public static String invalidSynonymNameError; + public static String invalidTargetNameError; + public static String enterEventTargetMSG; + public static String synonymInfo; + public static String synonymGroupName; + public static String synonymName; + public static String synonymDesscription; + + public static String msgInformation; + public static String newSynonymSuccess; + public static String newSynonymMSGTitle; + public static String newSynonymMsg; + + public static String synonymActionGroupText; + public static String synonymStatusGroupText; + public static String synonymPriorityGroupText; + public static String synonymPriorityText; + public static String sqlStatementMSG; + public static String synonymAlterMSG; + public static String alterSynonymShellTitle; + public static String synonymAlterMSGTitle; + public static String alterSynonymSuccess; + public static String errFormatPriority; + public static String errRangePriority; + public static String errPriorityFormat; + + public static String dropSynonymTaskName; + public static String addSynonymTaskName; + public static String alterSynonymTaskName; + + public static String errNameNoExist; + + public static String synonymsDetailInfoPartTitle; + + public static String synonymsDetailInfoPartCreateSynonymBtn; + public static String synonymsDetailInfoPartEditSynonymBtn; + public static String synonymsDetailInfoPartDropSynonymBtn; + + public static String synonymsDetailInfoPartTableOwnerCol; + public static String synonymsDetailInfoPartTableNameCol; + public static String synonymsDetailInfoPartTableTargetOwnerCol; + public static String synonymsDetailInfoPartTableTargetNameCol; + public static String synonymsDetailInfoPartTableCommentCol; + public static String errSynonymNoSelection; + + public static String dropSynonymSuccessMsg; + + public static String ToolTipName; + public static String ToolTipOwner; + public static String ToolTipTargetName; + public static String ToolTipTargetOwner; + public static String ToolTipComment; + + public static String synonymInfoLabel; + public static String synonymTargetInfoLabel; + public static String synonymCommentLabel; + +} diff --git a/com.cubrid.common.ui/src/com/cubrid/common/ui/cubrid/synonym/Messages.properties b/com.cubrid.common.ui/src/com/cubrid/common/ui/cubrid/synonym/Messages.properties new file mode 100644 index 00000000..8cad0a2c --- /dev/null +++ b/com.cubrid.common.ui/src/com/cubrid/common/ui/cubrid/synonym/Messages.properties @@ -0,0 +1,69 @@ +msgWarning=Warning +msgInformation=Information +okBTN=&OK +cancleBTN=&Cancel + +newSynonymMSGTitle=Create Synonym +newSynonymMsg=Please input the synonym information below. + +invalidSynonymNameError=Invalid synonym name +invalidTargetNameError=Invalid target name +enterEventTargetMSG=Please enter an event target +synonymInfo=Cannot create synonym for synonym in dialog, Please Use the Tools for query. + +synonymGroupName=CREATE SYNONYM +synonymOptionalGroupName=Options +synonymName=Synonym &name: +synonymDesscription=Synonym &memo: + +synonymToolTipActivity=Synonym activity description +synonymToolTipActivityType=Synonym activity type +synonymToolTipDelayedTime=Action evaluate time +synonymToolTipDatabaseEventType=Synonym event type +synonymToolTipName=Name of synonym +synonymToolTipEventTarget=Database event target (table or column) +synonymToolTipCondition=Controls whether or not the synonym action is performed + +newSynonymSuccess=The synonym has been successfully created. + +sqlStatementMSG=SQL statements or print messages for action type + +synonymAlterMSG=The Target Name and Target Owner, Comment are the only parts of the synonym definition that can be altered.\nIf synonym info of the synonym needs to be changed,\nthe synonym must be dropped and recreated. +synonymAlterMSGTitle=Edit synonym's target info and comment. +alterSynonymShellTitle=Edit Synonym +alterSynonymSuccess=Synonym has been successfully altered. +errFormatPriority=Cannot parse priority to data type float. +errPriorityFormat=Synonym priority is allowed to have a scale of only 2 (# of digits after the decimal point). +dropSynonymWarnMSG1=Are you sure you want to drop the selected {0} synonyms "{1}"? +dropSynonymWarnMSG2=Are you sure you want to drop the following synonyms: {0}? +infoSQLScriptTab=&SQL Script +infoSynonymTab=Synonym + +dropSynonymTaskName=Dropping synonym "{0}"... +addSynonymTaskName=Add synonym "{0}"... +alterSynonymTaskName=Altering synonym "{0}"... + +errNameNoExist=This synonym does not exist. + +synonymsDetailInfoPartCreateSynonymBtn=Create Synonym +synonymsDetailInfoPartEditSynonymBtn=Edit Synonym +synonymsDetailInfoPartDropSynonymBtn=Drop Synonym + +synonymsDetailInfoPartTitle=Synonyms +synonymsDetailInfoPartTableOwnerCol=Owner +synonymsDetailInfoPartTableNameCol=Name +synonymsDetailInfoPartTableTargetNameCol=Target Name +synonymsDetailInfoPartTableTargetOwnerCol=Target Owner +synonymsDetailInfoPartTableCommentCol=Comment + +errSynonymNoSelection=Please select a synonym to modify or delete. +dropSynonymSuccessMsg=Synonym was dropped successfully! + +ToolTipName=Synonym Name +ToolTipOwner=Synonym Owner Name +ToolTipTargetName=Synonym Target Name +ToolTipTargetOwner=Synonym Target Owner Name +ToolTipComment=Synonym Description +synonymInfoLabel=Synonym Info +synonymTargetInfoLabel=Target Info +synonymCommentLabel=description \ No newline at end of file diff --git a/com.cubrid.common.ui/src/com/cubrid/common/ui/cubrid/synonym/Messages_ko_KR.properties b/com.cubrid.common.ui/src/com/cubrid/common/ui/cubrid/synonym/Messages_ko_KR.properties new file mode 100644 index 00000000..3e996857 --- /dev/null +++ b/com.cubrid.common.ui/src/com/cubrid/common/ui/cubrid/synonym/Messages_ko_KR.properties @@ -0,0 +1,65 @@ +msgWarning=\uacbd\uace0 +msgInformation=\uc815\ubcf4 +okBTN=\ud655\uc778 +cancleBTN=\ucde8\uc18c + +newSynonymMSGTitle=\ub3d9\uc758\uc5b4 \uc0dd\uc131 +newSynonymMsg=\uc544\ub798 \ub3d9\uc758\uc5b4 \uc815\ubcf4\ub97c \uc785\ub825 \ud558\uc2ed\uc2dc\uc624. + +invalidSynonymNameError=\ub3d9\uc758\uc5b4 \uc774\ub984\uc774 \uc720\ud6a8\ud558\uc9c0 \uc54a\uc2b5\ub2c8\ub2e4. +invalidTargetNameError=\ud0c0\ucf13 \uc774\ub984\uc774 \uc720\ud6a8\ud558\uc9c0 \uc54a\uc2b5\ub2c8\ub2e4. +enterEventTargetMSG=\uc774\ubca4\ud2b8 \ub300\uc0c1 \uc774\ub984\uc744 \uc785\ub825\ud558\uc2ed\uc2dc\uc624. +synonymInfo=\ud604\uc7ac \ucc3d\uc5d0\uc11c\ub294 \ub3d9\uc758\uc5b4\uc5d0 \ub300\ud55c \ub3d9\uc758\uc5b4\ub294 \uc0dd\uc131 \ud560 \uc218 \uc5c6\uc2b5\ub2c8\ub2e4. \ucffc\ub9ac\ub97c \uc704\ud55c \ub3c4\uad6c\ub97c \uc0ac\uc6a9\ud558\uc2ed\uc2dc\uc624. + +synonymGroupName=\ub3d9\uc758\uc5b4 \uc0dd\uc131 +synonymOptionalGroupName=\uc635\uc158 +synonymName=\ub3d9\uc758\uc5b4 \uc774\ub984 +synonymDesscription=\ub3d9\uc758\uc5b4 \uc124\uba85 + +synonymToolTipActivity=\ub3d9\uc758\uc5b4 \uc791\uc5c5 \uc124\uba85 +synonymToolTipActivityType=\ub3d9\uc758\uc5b4 \uc791\uc5c5 \uc720\ud615 +synonymToolTipDelayedTime=\uc791\uc5c5 \ud655\uc778 \uc2dc\uc810 +synonymToolTipDatabaseEventType=\ub370\uc774\ud130\ubca0\uc774\uc2a4 \uc774\ubca4\ud2b8 \uc720\ud615 +synonymToolTipName=\ub3d9\uc758\uc5b4 \uc774\ub984 +synonymToolTipEventTarget=\ub370\uc774\ud130\ubca0\uc774\uc2a4 \uc774\ubca4\uc2a4 \ub300\uc0c1(\ud14c\uc774\ube14/\uceec\ub7fc) +synonymToolTipCondition=\ub3d9\uc758\uc5b4 \uc218\ud589 \uc5ec\ubd80\ub97c \uacb0\uc815\ud558\ub294 \uc870\uac74 + +newSynonymSuccess=\ub3d9\uc758\uc5b4 \ucd94\uac00\ub97c \uc131\uacf5\uc801\uc73c\ub85c \uc644\ub8cc\ud558\uc600\uc2b5\ub2c8\ub2e4. + +synonymAlterMSG=\ub3d9\uc758\uc5b4 \uc815\ubcf4 \uc911 \ubcc0\uacbd\uc774 \uac00\ub2a5\ud55c \uc124\uc815\uc740 \ub300\uc0c1 \uc815\ubcf4\uc640 \uc124\uba85\uc785\ub2c8\ub2e4. \ub3d9\uc758\uc5b4 \uc815\ubcf4\ub294 \ubcc0\uacbd\ub420 \uc218 \uc5c6\uc73c\ubbc0\ub85c \ud544\uc694\ud558\uba74 \uc0ad\uc81c \ud6c4 \ub2e4\uc2dc \ub9cc\ub4e4\uc5b4\uc57c \ud569\ub2c8\ub2e4. +synonymAlterMSGTitle=\ub3d9\uc758\uc5b4 \uc0c1\ud0dc\uc640 \uc6b0\uc120\uc21c\uc704 \ud3b8\uc9d1 +alterSynonymShellTitle=\ub3d9\uc758\uc5b4 \ud3b8\uc9d1 +alterSynonymSuccess=\ub3d9\uc758\uc5b4 \ubcc0\uacbd\uc774 \uc131\uacf5\uc801\uc73c\ub85c \uc644\ub8cc\ub418\uc5c8\uc2b5\ub2c8\ub2e4. +dropSynonymWarnMSG1={0} \ub3d9\uc758\uc5b4\ub97c \uc0ad\uc81c\ud558\uc2dc\uaca0\uc2b5\ub2c8\uae4c? +dropSynonymWarnMSG2={0} \ub3d9\uc758\uc5b4\ub4e4\uc744 \uc0ad\uc81c\ud558\uc2dc\uaca0\uc2b5\ub2c8\uae4c? +infoSQLScriptTab=SQL\ubb38 +infoSynonymTab=\ub3d9\uc758\uc5b4 + +dropSynonymTaskName="{0}" \ub3d9\uc758\uc5b4 \uc0ad\uc81c... +addSynonymTaskName="{0}" \ub3d9\uc758\uc5b4 \ucd94\uac00... +alterSynonymTaskName="{0}" \ub3d9\uc758\uc5b4 \ubcc0\uacbd... + +errNameNoExist=\ud574\ub2f9 \ub3d9\uc758\uc5b4\uac00 \uc874\uc7ac\ud558\uc9c0 \uc54a\uc2b5\ub2c8\ub2e4. + +synonymsDetailInfoPartCreateSynonymBtn=\ub3d9\uc758\uc5b4 \ucd94\uac00 +synonymsDetailInfoPartEditSynonymBtn=\ub3d9\uc758\uc5b4 \ud3b8\uc9d1 +synonymsDetailInfoPartDropSynonymBtn=\ub3d9\uc758\uc5b4 \uc0ad\uc81c + +synonymsDetailInfoPartTitle=\ub3d9\uc758\uc5b4 +synonymsDetailInfoPartTableOwnerCol=\uc18c\uc720\uc790 +synonymsDetailInfoPartTableNameCol=\uc774\ub984 +synonymsDetailInfoPartTableTargetOwnerCol=\ub300\uc0c1 \uc18c\uc720\uc790 +synonymsDetailInfoPartTableTargetNameCol=\ub300\uc0c1 \uc774\ub984 +synonymsDetailInfoPartTableCommentCol=\uc124\uba85 + +errSynonymNoSelection=\ub3d9\uc758\uc5b4\ub97c \uc120\ud0dd\ud558\uc2e0\ud6c4 \ud3b8\uc9d1 \ub610\ub294 \uc0ad\uc81c\uac00 \uac00\ub2a5\ud569\ub2c8\ub2e4. +dropSynonymSuccessMsg=\ub3d9\uc758\uc5b4\ub97c \uc0ad\uc81c\ud588\uc2b5\ub2c8\ub2e4. + +ToolTipName=\uc774\ub984 +ToolTipOwner=\uc18c\uc720\uc790 +ToolTipTargetName=\ub300\uc0c1 \uc774\ub984 +ToolTipTargetOwner=\ub300\uc0c1 \uc18c\uc720\uc790 +ToolTipComment=\ub3d9\uc758\uc5b4 \uc124\uba85 +synonymInfoLabel=\ub3d9\uc758\uc5b4 \uc815\ubcf4 +synonymTargetInfoLabel=\ub300\uc0c1 \uc815\ubcf4 +synonymCommentLabel=\uc124\uba85 \ No newline at end of file diff --git a/com.cubrid.common.ui/src/com/cubrid/common/ui/cubrid/synonym/action/AlterSynonymAction.java b/com.cubrid.common.ui/src/com/cubrid/common/ui/cubrid/synonym/action/AlterSynonymAction.java new file mode 100644 index 00000000..980a1c93 --- /dev/null +++ b/com.cubrid.common.ui/src/com/cubrid/common/ui/cubrid/synonym/action/AlterSynonymAction.java @@ -0,0 +1,193 @@ +/* + * Copyright (C) 2009 Search Solution Corporation. All rights reserved by Search + * Solution. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: - + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. - Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. - Neither the name of the nor the names + * of its contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + */ +package com.cubrid.common.ui.cubrid.synonym.action; + +import java.util.List; + +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.jface.dialogs.IDialogConstants; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.jface.viewers.ISelectionProvider; +import org.eclipse.swt.widgets.Shell; + +import com.cubrid.common.core.common.model.Synonym; +import com.cubrid.common.core.task.ITask; +import com.cubrid.common.ui.cubrid.synonym.Messages; +import com.cubrid.common.ui.cubrid.synonym.dialog.CreateSynonymDialog; +import com.cubrid.common.ui.spi.CubridNodeManager; +import com.cubrid.common.ui.spi.action.ActionManager; +import com.cubrid.common.ui.spi.action.SelectionAction; +import com.cubrid.common.ui.spi.event.CubridNodeChangedEvent; +import com.cubrid.common.ui.spi.event.CubridNodeChangedEventType; +import com.cubrid.common.ui.spi.model.CubridDatabase; +import com.cubrid.common.ui.spi.model.ISchemaNode; +import com.cubrid.common.ui.spi.model.NodeType; +import com.cubrid.common.ui.spi.progress.CommonTaskExec; +import com.cubrid.common.ui.spi.progress.ExecTaskWithProgress; +import com.cubrid.common.ui.spi.progress.TaskExecutor; +import com.cubrid.common.ui.spi.util.ActionSupportUtil; +import com.cubrid.cubridmanager.core.cubrid.synonym.JDBCGetSynonymInfoTask; +import com.cubrid.cubridmanager.core.cubrid.user.task.JDBCGetAllDbUserTask; + +public class AlterSynonymAction extends + SelectionAction { + + public static final String ID = AlterSynonymAction.class.getName(); + + /** + * The constructor + * + * @param shell + * @param text + * @param icon + */ + public AlterSynonymAction(Shell shell, String text, ImageDescriptor icon) { + this(shell, null, text, icon); + } + + /** + * The constructor + * + * @param shell + * @param provider + * @param text + * @param icon + */ + public AlterSynonymAction(Shell shell, ISelectionProvider provider, + String text, ImageDescriptor icon) { + super(shell, provider, text, icon); + this.setId(ID); + } + + /** + * + * @see com.cubrid.common.ui.spi.action.ISelectionAction#allowMultiSelections + * () + * @return false + */ + public boolean allowMultiSelections() { + return false; + } + + /** + * + * @see com.cubrid.common.ui.spi.action.ISelectionAction#isSupported(java + * .lang.Object) + * @param obj the Object + * @return true if support this obj;false + * otherwise + */ + public boolean isSupported(Object obj) { + return ActionSupportUtil.isSupportSinSelCheckDbUser(obj, + NodeType.SYNONYM); + } + + /** + * Open alter synonym dialog + */ + public void run() { + Object[] objArr = this.getSelectedObj(); + if (!isSupported(objArr)) { + this.setEnabled(false); + return; + } + final ISchemaNode synonymNode = (ISchemaNode) objArr[0]; + CubridDatabase database = synonymNode.getDatabase(); + run (database, synonymNode); + } + + /** + * edit synonym + * @param database + * @param node + * @return + */ + public int run (final CubridDatabase database, final ISchemaNode node) { // FIXME move this logic to core module + TaskExecutor taskExcutor = new TaskExecutor() { + public boolean exec(final IProgressMonitor monitor) { + if (monitor.isCanceled()) { + return false; + } + for (ITask task : taskList) { + task.execute(); + final String msg = task.getErrorMsg(); + if (openErrorBox(shell, msg, monitor)) { + return false; + } + if (monitor.isCanceled()) { + return false; + } + Synonym synonym = null; + JDBCGetSynonymInfoTask getSynonymInfoTask = (JDBCGetSynonymInfoTask) task; + synonym = getSynonymInfoTask.getSynonymInfo(node.getName()); + + if (synonym == null) { + openErrorBox(shell, Messages.errNameNoExist, monitor); + return false; + } + + node.setModelObj(synonym); + } + return true; + } + }; + ITask task = null; + + task = new JDBCGetSynonymInfoTask(database.getDatabaseInfo()); + taskExcutor.addTask(task); + new ExecTaskWithProgress(taskExcutor).busyCursorWhile(); + if (!taskExcutor.isSuccess()) { + return IDialogConstants.CANCEL_ID; + } + + TaskExecutor userTaskExcutor = new CommonTaskExec(null); + + JDBCGetAllDbUserTask userTask = new JDBCGetAllDbUserTask(database.getDatabaseInfo()); + userTaskExcutor.addTask(userTask); + new ExecTaskWithProgress(userTaskExcutor).busyCursorWhile(); + if (!taskExcutor.isSuccess()) { + return IDialogConstants.CANCEL_ID; + } + + List dbUserList = userTask.getDbUserList(); + + CreateSynonymDialog dialog = new CreateSynonymDialog(getShell(), + node.getDatabase(), + (Synonym) node.getAdapter(Synonym.class), + dbUserList); + + if (dialog.open() != IDialogConstants.CANCEL_ID) { + CubridNodeManager.getInstance().fireCubridNodeChanged( + new CubridNodeChangedEvent(node, + CubridNodeChangedEventType.NODE_REFRESH)); + ActionManager.getInstance().fireSelectionChanged(getSelection()); + return IDialogConstants.OK_ID; + } + return IDialogConstants.CANCEL_ID; + } +} diff --git a/com.cubrid.common.ui/src/com/cubrid/common/ui/cubrid/synonym/action/DropSynonymAction.java b/com.cubrid.common.ui/src/com/cubrid/common/ui/cubrid/synonym/action/DropSynonymAction.java new file mode 100644 index 00000000..8250cd13 --- /dev/null +++ b/com.cubrid.common.ui/src/com/cubrid/common/ui/cubrid/synonym/action/DropSynonymAction.java @@ -0,0 +1,148 @@ +/* + * Copyright (C) 2013 Search Solution Corporation. All rights reserved by Search + * Solution. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: - + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. - Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. - Neither the name of the nor the names + * of its contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + */ +package com.cubrid.common.ui.cubrid.synonym.action; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.jface.viewers.ISelectionProvider; +import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.jface.viewers.TreeViewer; +import org.eclipse.swt.widgets.Shell; +import org.slf4j.Logger; + +import com.cubrid.common.core.util.LogUtil; +import com.cubrid.common.core.util.QuerySyntax; +import com.cubrid.common.ui.cubrid.synonym.Messages; +import com.cubrid.common.ui.spi.action.SelectionAction; +import com.cubrid.common.ui.spi.model.DefaultSchemaNode; +import com.cubrid.common.ui.spi.model.ICubridNode; +import com.cubrid.common.ui.spi.model.ISchemaNode; +import com.cubrid.common.ui.spi.model.NodeType; +import com.cubrid.common.ui.spi.progress.CommonTaskExec; +import com.cubrid.common.ui.spi.progress.ExecTaskWithProgress; +import com.cubrid.common.ui.spi.progress.TaskExecutor; +import com.cubrid.common.ui.spi.util.ActionSupportUtil; +import com.cubrid.common.ui.spi.util.CommonUITool; +import com.cubrid.cubridmanager.core.common.task.CommonSQLExcuterTask; + +public class DropSynonymAction extends SelectionAction { + public static final String ID = DropSynonymAction.class.getName(); + private static final Logger LOGGER = LogUtil.getLogger(DropSynonymAction.class); + + public DropSynonymAction(Shell shell, String text, ImageDescriptor icon) { + this(shell, null, text, icon); + } + + public DropSynonymAction(Shell shell, ISelectionProvider provider, String text, ImageDescriptor icon) { + super(shell, provider, text, icon); + this.setId(ID); + } + + public boolean allowMultiSelections() { + return true; + } + + public boolean isSupported(Object obj) { + return ActionSupportUtil.isSupportMultiSelection(obj, + new String[]{NodeType.SYNONYM }, true); + } + + public void run() { + Object[] objArr = this.getSelectedObj(); + if (objArr == null || !isSupported(objArr)) { + this.setEnabled(false); + return; + } + ISchemaNode nodeArray[] = new ISchemaNode[objArr.length]; + for (int i = 0 ; i < objArr.length; i ++) { + nodeArray[i] = (ISchemaNode)objArr[i]; + } + run(nodeArray); + } + + public void run(ISchemaNode[] nodeArray) { // FIXME move this logic to core module + if (nodeArray == null) { + LOGGER.error("The nodeArray is a null."); + return; + } + + List synonymNameList = new ArrayList(); + StringBuffer bf = new StringBuffer(); + for (int i = 0; nodeArray != null && i < nodeArray.length; i++) { + DefaultSchemaNode synonym = (DefaultSchemaNode) nodeArray[i]; + synonymNameList.add(synonym.getName()); + if (i == 0) { + bf.append(synonym.getName()); + } + } + if (nodeArray.length > 1) { + bf.append(", ..."); + } + + String cfmMsg = Messages.bind(Messages.dropSynonymWarnMSG1, nodeArray.length, bf.toString()); + boolean ret = CommonUITool.openConfirmBox(cfmMsg); + if (!ret) { + return; + } + + ISchemaNode synonymNode = (ISchemaNode) nodeArray[0]; + CommonSQLExcuterTask task = new CommonSQLExcuterTask( + synonymNode.getDatabase().getDatabaseInfo()); + for (String synonymName : synonymNameList) { + String sql = "DROP SYNONYM " + QuerySyntax.escapeKeyword(synonymName); + task.addSqls(sql); + } + + String taskName = Messages.bind(Messages.dropSynonymTaskName, bf.toString()); + TaskExecutor taskExecutor = new CommonTaskExec(taskName); + taskExecutor.addTask(task); + + new ExecTaskWithProgress(taskExecutor).busyCursorWhile(); + if (!taskExecutor.isSuccess()) { + return; + } + + String title = com.cubrid.common.ui.common.Messages.titleSuccess; + String msg = Messages.dropSynonymSuccessMsg; + CommonUITool.openInformationBox(title, msg); + + ISelectionProvider provider = this.getSelectionProvider(); + ICubridNode parent = synonymNode.getParent(); + if (provider instanceof TreeViewer) { + TreeViewer viewer = (TreeViewer) provider; + for (int i = 0; nodeArray != null && i < nodeArray.length; i++) { + parent.removeChild((ISchemaNode) nodeArray[i]); + } + viewer.remove(parent, nodeArray); + viewer.setSelection(new StructuredSelection(parent), true); + CommonUITool.updateFolderNodeLabelIncludingChildrenCount(viewer, parent); + } + } +} diff --git a/com.cubrid.common.ui/src/com/cubrid/common/ui/cubrid/synonym/action/NewSynonymAction.java b/com.cubrid.common.ui/src/com/cubrid/common/ui/cubrid/synonym/action/NewSynonymAction.java new file mode 100644 index 00000000..c48099f8 --- /dev/null +++ b/com.cubrid.common.ui/src/com/cubrid/common/ui/cubrid/synonym/action/NewSynonymAction.java @@ -0,0 +1,193 @@ +/* + * Copyright (C) 2009 Search Solution Corporation. All rights reserved by Search + * Solution. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: - + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. - Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. - Neither the name of the nor the names + * of its contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + */ +package com.cubrid.common.ui.cubrid.synonym.action; + +import java.util.List; +import java.util.Locale; + +import org.eclipse.jface.dialogs.IDialogConstants; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.jface.viewers.ISelectionProvider; +import org.eclipse.jface.viewers.TreeViewer; +import org.eclipse.swt.widgets.Shell; + +import com.cubrid.common.core.common.model.Synonym; +import com.cubrid.common.core.util.ApplicationType; +import com.cubrid.common.ui.cubrid.synonym.dialog.CreateSynonymDialog; +import com.cubrid.common.ui.perspective.PerspectiveManager; +import com.cubrid.common.ui.spi.CubridNodeManager; +import com.cubrid.common.ui.spi.action.SelectionAction; +import com.cubrid.common.ui.spi.event.CubridNodeChangedEvent; +import com.cubrid.common.ui.spi.event.CubridNodeChangedEventType; +import com.cubrid.common.ui.spi.model.CubridDatabase; +import com.cubrid.common.ui.spi.model.ICubridNode; +import com.cubrid.common.ui.spi.model.ICubridNodeLoader; +import com.cubrid.common.ui.spi.model.ISchemaNode; +import com.cubrid.common.ui.spi.model.loader.CubridSynonymFolderLoader; +import com.cubrid.common.ui.spi.progress.CommonTaskExec; +import com.cubrid.common.ui.spi.progress.ExecTaskWithProgress; +import com.cubrid.common.ui.spi.progress.TaskExecutor; +import com.cubrid.common.ui.spi.util.ActionSupportUtil; +import com.cubrid.common.ui.spi.util.CommonUITool; +import com.cubrid.cubridmanager.core.cubrid.user.task.JDBCGetAllDbUserTask; + +public class NewSynonymAction extends + SelectionAction { + + public static final String ID = NewSynonymAction.class.getName(); + + /** + * The constructor + * + * @param shell + * @param text + * @param enabledIcon + * @param disabledIcon + */ + public NewSynonymAction(Shell shell, String text, + ImageDescriptor enabledIcon, ImageDescriptor disabledIcon) { + this(shell, null, text, enabledIcon, disabledIcon); + } + + /** + * The constructor + * + * @param shell + * @param provider + * @param text + * @param enabledIcon + * @param disabledIcon + */ + public NewSynonymAction(Shell shell, ISelectionProvider provider, + String text, ImageDescriptor enabledIcon, + ImageDescriptor disabledIcon) { + super(shell, provider, text, enabledIcon); + this.setId(ID); + this.setToolTipText(text); + this.setDisabledImageDescriptor(disabledIcon); + } + + /** + * + * @see com.cubrid.common.ui.spi.action.ISelectionAction#allowMultiSelections + * () + * @return false + */ + public boolean allowMultiSelections() { + return true; + } + + /** + * Sets this action support this object + * + * @see org.eclipse.jface.action.IAction.ISelectionAction + * @param obj Object + * @return boolean + */ + public boolean isSupported(Object obj) { + if (!ActionSupportUtil.isSupportMultiSelection(obj, null, false)) { + return false; + } + + if (ApplicationType.CUBRID_MANAGER.equals(PerspectiveManager.getInstance().getCurrentMode())) { + return true; + } + + CubridDatabase database = null; + if (obj instanceof ISchemaNode) { + ISchemaNode node = (ISchemaNode) obj; + database = node.getDatabase(); + } else if (obj instanceof Object[]) { + Object[] objArr = (Object[]) obj; + ISchemaNode node = (ISchemaNode) objArr[0]; + database = node.getDatabase(); + } + if (database != null + && database.getDatabaseInfo().getAuthLoginedDbUserInfo().isDbaAuthority()) { + return true; + } + return false; + } + + /** + * Create Synonym + */ + public void run() { + Object[] obj = this.getSelectedObj(); + if (!isSupported(obj)) { + setEnabled(false); + return; + } + ISchemaNode Node = (ISchemaNode) obj[0]; + CubridDatabase database = Node.getDatabase(); + run(database); + } + + /** + * Create Synonym + * @param database CubridDatabase + */ + public void run (CubridDatabase database) { + TaskExecutor taskExcutor = new CommonTaskExec(null); + + JDBCGetAllDbUserTask task = new JDBCGetAllDbUserTask(database.getDatabaseInfo()); + taskExcutor.addTask(task); + new ExecTaskWithProgress(taskExcutor).busyCursorWhile(); + if (!taskExcutor.isSuccess()) { + return; + } + + List dbUserList = task.getDbUserList(); + + CreateSynonymDialog dlg = new CreateSynonymDialog(getShell(), database, dbUserList); + ISelectionProvider provider = getSelectionProvider(); + if (dlg.open() == IDialogConstants.OK_ID + && (provider instanceof TreeViewer)) { + TreeViewer treeViewer = (TreeViewer) provider; + ICubridNode folderNode = database.getChild(database.getId() + + ICubridNodeLoader.NODE_SEPARATOR + + CubridSynonymFolderLoader.SYNONYM_FOLDER_ID); + if (folderNode == null || !folderNode.getLoader().isLoaded()) { + return; + } + String synonymName = dlg.getSynonym().getName().toLowerCase(Locale.getDefault()); + String ownerName = dlg.getSynonym().getOwner(); + String id = folderNode.getId() + ICubridNodeLoader.NODE_SEPARATOR + + ownerName + "." + synonymName; + + Synonym synonym = dlg.getSynonym(); + ICubridNode newNode = CubridSynonymFolderLoader.createSynonymNode( + database.getDatabaseInfo(), id, synonym); + CommonUITool.addNodeToTree(treeViewer, folderNode, newNode); + CommonUITool.updateFolderNodeLabelIncludingChildrenCount(treeViewer, folderNode); + CubridNodeManager.getInstance().fireCubridNodeChanged( + new CubridNodeChangedEvent(newNode, + CubridNodeChangedEventType.NODE_ADD)); + } + } +} \ No newline at end of file diff --git a/com.cubrid.common.ui/src/com/cubrid/common/ui/cubrid/synonym/dialog/CreateSynonymDialog.java b/com.cubrid.common.ui/src/com/cubrid/common/ui/cubrid/synonym/dialog/CreateSynonymDialog.java new file mode 100644 index 00000000..bfcaf83e --- /dev/null +++ b/com.cubrid.common.ui/src/com/cubrid/common/ui/cubrid/synonym/dialog/CreateSynonymDialog.java @@ -0,0 +1,554 @@ +/* + * Copyright (C) 2009 Search Solution Corporation. All rights reserved by Search + * Solution. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: - + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. - Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. - Neither the name of the nor the names + * of its contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + */ +package com.cubrid.common.ui.cubrid.synonym.dialog; + +import java.util.List; + +import org.eclipse.jface.dialogs.IDialogConstants; +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.StyledText; +import org.eclipse.swt.events.ModifyEvent; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Combo; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.TabFolder; +import org.eclipse.swt.widgets.TabItem; +import org.eclipse.swt.widgets.Text; + +import com.cubrid.common.core.common.model.Synonym; +import com.cubrid.common.core.util.StringUtil; +import com.cubrid.common.ui.cubrid.synonym.Messages; +import com.cubrid.common.ui.spi.ResourceManager; +import com.cubrid.common.ui.spi.dialog.CMTitleAreaDialog; +import com.cubrid.common.ui.spi.model.CubridDatabase; +import com.cubrid.common.ui.spi.progress.CommonTaskExec; +import com.cubrid.common.ui.spi.progress.ExecTaskWithProgress; +import com.cubrid.common.ui.spi.progress.TaskExecutor; +import com.cubrid.common.ui.spi.util.CommonUITool; +import com.cubrid.common.ui.spi.util.ValidateUtil; +import com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo; +import com.cubrid.cubridmanager.core.cubrid.synonym.SynonymDDL; +import com.cubrid.cubridmanager.core.cubrid.trigger.task.JDBCSqlExecuteTask; + +public class CreateSynonymDialog extends + CMTitleAreaDialog { + private StyledText sqlText; + private final Color white = ResourceManager.getColor(SWT.COLOR_WHITE); + private Text nameText = null; + private Combo ownerCombo = null; + private Text targetNameText= null; + private Combo targetOwnerCombo = null; + private Text commentText = null; + + private final CubridDatabase database; + private final DatabaseInfo dbInfo; + private List dbUserList = null; + + private Synonym synonym = null; + private TabFolder tabFolder; + public final static int ALTER_SYNONYM_OK_ID = 100; + + public CreateSynonymDialog(Shell parentShell, CubridDatabase database, List dbUserList) { + super(parentShell); + this.database = database; + this.dbInfo = database.getDatabaseInfo(); + this.dbUserList = dbUserList; + } + + public CreateSynonymDialog(Shell parentShell, CubridDatabase database, + Synonym synonym, List dbUserList) { + super(parentShell); + this.database = database; + this.synonym = synonym; + this.dbInfo = database.getDatabaseInfo(); + this.dbUserList = dbUserList; + } + + /** + * Create dialog area content + * + * @param parent the parent composite + * + * @return the composite + */ + protected Control createDialogArea(Composite parent) { + Composite parentComp = (Composite) super.createDialogArea(parent); + + parentComp.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + + Composite tabComposite = new Composite(parentComp, SWT.NONE); + { + final GridData gdComposite = new GridData(SWT.FILL, SWT.FILL, true, + true); + tabComposite.setLayoutData(gdComposite); + GridLayout tabCompositeLayout = new GridLayout(); + tabCompositeLayout.numColumns = 1; + tabCompositeLayout.marginHeight = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN); + tabCompositeLayout.marginWidth = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN); + tabCompositeLayout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING); + tabCompositeLayout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING); + tabCompositeLayout.numColumns = 1; + tabComposite.setLayout(tabCompositeLayout); + } + + tabFolder = new TabFolder(tabComposite, SWT.NONE); + tabFolder.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + + //create synonym tab + final TabItem synonymTabItem = new TabItem(tabFolder, SWT.NONE); + synonymTabItem.setText(Messages.infoSynonymTab); + synonymTabItem.setControl(createSynonymComposite(tabFolder)); + + //create the SQL tab + final Composite sqlScriptComposite = new Composite(tabFolder, SWT.NONE); + sqlScriptComposite.setLayout(new GridLayout()); + final TabItem sqlScriptTabItem = new TabItem(tabFolder, SWT.NONE); + sqlScriptTabItem.setText(Messages.infoSQLScriptTab); + sqlScriptTabItem.setControl(sqlScriptComposite); + + sqlText = new StyledText(sqlScriptComposite, SWT.WRAP | SWT.V_SCROLL + | SWT.READ_ONLY | SWT.H_SCROLL | SWT.BORDER); + CommonUITool.registerContextMenu(sqlText, false); + sqlText.setBackground(white); + sqlText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + + setTitle(Messages.newSynonymMSGTitle); + setMessage(Messages.newSynonymMsg); + + createInit(); + alterInit(); + addListener(); + return parentComp; + + } + + /** + * + * Create the synonym tab composite + * + * @param parent Composite + * @return Composite + */ + private Composite createSynonymComposite(Composite parent) { + Composite composite = new Composite(parent, SWT.NONE); + { + composite.setLayoutData(new GridData(GridData.FILL_BOTH)); + GridLayout layout = new GridLayout(); + layout.numColumns = 5; + layout.marginHeight = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN); + layout.marginWidth = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN); + layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING); + layout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING); + composite.setLayout(layout); + } + + Label SynonymInfoLabel = new Label(composite, SWT.LEFT | SWT.WRAP); + SynonymInfoLabel.setText(Messages.synonymInfoLabel); + SynonymInfoLabel.setLayoutData(CommonUITool.createGridData(1, 1, -1, -1)); + + ownerCombo = new Combo(composite, SWT.LEFT | SWT.BORDER | SWT.READ_ONLY); + ownerCombo.setLayoutData(CommonUITool.createGridData( + GridData.FILL_HORIZONTAL, 1, 1, 30, -1)); + nameText = new Text(composite, SWT.LEFT | SWT.BORDER); + nameText.setLayoutData(CommonUITool.createGridData( + GridData.FILL_HORIZONTAL, 3, 1, 30, -1)); + + Label targetInfoLabel = new Label(composite, SWT.LEFT | SWT.WRAP); + targetInfoLabel.setText(Messages.synonymTargetInfoLabel); + targetInfoLabel.setLayoutData(CommonUITool.createGridData(1, 1, -1, -1)); + + targetOwnerCombo = new Combo(composite, SWT.LEFT | SWT.BORDER | SWT.READ_ONLY); + targetOwnerCombo.setLayoutData(CommonUITool.createGridData( + GridData.FILL_HORIZONTAL, 1, 1, 30, -1)); + targetNameText = new Text(composite, SWT.LEFT | SWT.BORDER); + targetNameText.setLayoutData(CommonUITool.createGridData( + GridData.FILL_HORIZONTAL, 3, 1, 30, -1)); + + Label commentInfoLabel = new Label(composite, SWT.LEFT | SWT.WRAP); + commentInfoLabel.setText(Messages.synonymCommentLabel); + commentInfoLabel.setLayoutData(CommonUITool.createGridData(1, 1, -1, -1)); + + commentText = new Text(composite, SWT.LEFT | SWT.BORDER); + commentText.setLayoutData(CommonUITool.createGridData( + GridData.FILL_HORIZONTAL, 5, 1, 30, -1)); + commentText.setTextLimit(ValidateUtil.MAX_DB_OBJECT_COMMENT); + return composite; + } + + /** + * Create buttons for button bar + * + * @param parent the parent composite + */ + protected void createButtonsForButtonBar(Composite parent) { + if (null == synonym) { + createButton(parent, IDialogConstants.OK_ID, Messages.okBTN, false); + getButton(IDialogConstants.OK_ID).setEnabled(false); + } else { + createButton(parent, ALTER_SYNONYM_OK_ID, Messages.okBTN, false); + getButton(ALTER_SYNONYM_OK_ID).setEnabled(false); + } + createButton(parent, IDialogConstants.CANCEL_ID, Messages.cancleBTN, + false); + } + + /** + * When press button,call it + * + * @param buttonId the button id + */ + protected void buttonPressed(int buttonId) { + if (buttonId != IDialogConstants.OK_ID + && buttonId != ALTER_SYNONYM_OK_ID) { + super.buttonPressed(buttonId); + return; + } + + if (!validateAll()) { + return; + } + executeByJDBC(buttonId); + } + + /** + * + * Execute to add or alter synonym by JDBC + * + * @param buttonId int + */ + private void executeByJDBC(int buttonId) { // FIXME move this logic to core module + String createSQL = generateSqlText().toString(); + if (StringUtil.isEmpty(createSQL)) { + return; + } + + String SynonyUniqueName = ownerCombo.getText() + "." + nameText.getText(); + String taskName = null; + String message = null; + if (buttonId == IDialogConstants.OK_ID) { + taskName = Messages.bind(Messages.addSynonymTaskName, SynonyUniqueName); + message = Messages.newSynonymSuccess; + } else if (buttonId == ALTER_SYNONYM_OK_ID) { + createSQL = createSQL.substring(createSQL.indexOf("ALTER SYNONYM ")); + message = Messages.alterSynonymSuccess; + taskName = Messages.bind(Messages.alterSynonymTaskName, SynonyUniqueName); + } + // add or alter synonyms by JDBC + JDBCSqlExecuteTask jdbcTask = new JDBCSqlExecuteTask(taskName, + database.getDatabaseInfo(), createSQL); + TaskExecutor taskExecutor = new CommonTaskExec(taskName); + taskExecutor.addTask(jdbcTask); + new ExecTaskWithProgress(taskExecutor).busyCursorWhile(); + if (taskExecutor.isSuccess()) { + setReturnCode(buttonId); + close(); + CommonUITool.openInformationBox(Messages.msgInformation, message); + } + } + + /** + * + * Init data when create synonym + * + */ + private void createInit() { + + nameText.setToolTipText(Messages.ToolTipName); + ownerCombo.setToolTipText(Messages.ToolTipOwner); + targetNameText.setToolTipText(Messages.ToolTipTargetName); + targetOwnerCombo.setToolTipText(Messages.ToolTipTargetOwner); + commentText.setToolTipText(Messages.ToolTipComment); + + ownerCombo.setVisibleItemCount(20); + targetOwnerCombo.setVisibleItemCount(20); + + if (dbInfo != null) { + String ownerName; + for (int i = 0 ; i < dbUserList.size() ; i++ ) { + ownerName = dbUserList.get(i); + ownerCombo.add(ownerName); + targetOwnerCombo.add(ownerName); + boolean isSameOwner = false; + boolean isSameTargetOwner = false; + if (synonym == null) { + isSameOwner = StringUtil.isEqualIgnoreCase(ownerName, database.getDatabaseInfo().getAuthLoginedDbUserInfo().getName()); + } else { + isSameOwner = StringUtil.isEqualIgnoreCase(ownerName, synonym.getOwner()); + isSameTargetOwner = StringUtil.isEqualIgnoreCase(ownerName, synonym.getTargetOwner()); + } + if (isSameOwner) { + ownerCombo.select(i); + targetOwnerCombo.select(i); + } + + if (isSameTargetOwner) { + targetOwnerCombo.select(i); + } + } + } + + nameText.setFocus(); + } + + /** + * + * Init the data when alter synonym + * + */ + private void alterInit() { + if (synonym == null) { + return; + } + setMessage(Messages.synonymAlterMSG); + setTitle(Messages.synonymAlterMSGTitle); + + nameText.setText(synonym.getName()); + nameText.setEnabled(false); + ownerCombo.setEnabled(false); + + targetNameText.setText(synonym.getTargetName()); + if (synonym.getComment() != null) { + commentText.setText(synonym.getComment()); + } + + } + + /** + * + * Add listener + * + */ + private void addListener() { + if (synonym == null) { + nameText.addModifyListener(new ModifyListener() { + public void modifyText(ModifyEvent event) { + boolean valid = validateSynonymName(); + if (valid) { + validateAll(); + } else { + changeOKButtonStatus(false); + } + nameText.setFocus(); + } + }); + } + + targetNameText.addModifyListener(new ModifyListener() { + public void modifyText(ModifyEvent event) { + boolean valid = validateTargetName(); + if (valid) { + validateAll(); + } else { + changeOKButtonStatus(false); + } + targetNameText.setFocus(); + } + }); + + targetOwnerCombo.addSelectionListener(new SelectionListener() { + + @Override + public void widgetSelected(SelectionEvent e) { + validateAll(); + } + + @Override + public void widgetDefaultSelected(SelectionEvent e) { + } + }); + + commentText.addModifyListener(new ModifyListener() { + public void modifyText(ModifyEvent event) { + boolean valid = validateTargetName(); + if (valid) { + validateAll(); + } else { + changeOKButtonStatus(false); + } + } + }); + + tabFolder.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(final SelectionEvent event) { + if (tabFolder.getSelectionIndex() == 0) { + nameText.setFocus(); + } else if (tabFolder.getSelectionIndex() == tabFolder.getItemCount() - 1) { + sqlText.setText(generateSqlText().toString()); + } + } + }); + } + + Synonym newSynonym = null; + + /** + * + * Get new synonym + * + * @return the synonym object + */ + private Synonym getNewSynonym() { // FIXME move this logic to core module + newSynonym = new Synonym(); + String synoymName = nameText.getText(); + String ownerName = ownerCombo.getText(); + String targetName = targetNameText.getText(); + String targetOwner = targetOwnerCombo.getText(); + String comment = commentText.getText(); + + newSynonym.setName(synoymName); + newSynonym.setOwner(ownerName); + newSynonym.setTargetName(targetName); + newSynonym.setTargetOwner(targetOwner); + newSynonym.setComment(comment); + return newSynonym; + } + + /** + * Validate synonym information + * + * @return true if it is valid;falseotherwise + */ + private boolean validateAll() { + setErrorMessage(null); + changeOKButtonStatus(false); + if (!validateSynonymName()) { + return false; + } + if (!validateTargetName()) { + return false; + } + if (null != synonym && !isChanged(synonym, getNewSynonym())) { + return false; + } + changeOKButtonStatus(true); + return true; + } + + /** + * Change ok button status: enabled, or disabled + * + * @param valid whether it is enabled + * + */ + private void changeOKButtonStatus(boolean valid) { + if (null == synonym) { + getButton(IDialogConstants.OK_ID).setEnabled(valid); + } else { + getButton(ALTER_SYNONYM_OK_ID).setEnabled(valid); + } + } + + /** + * Validate synonym name + * + * @return true if it is valid;falseotherwise + */ + private boolean validateSynonymName() { + String synonymName = nameText.getText(); + if (!ValidateUtil.isValidIdentifier(synonymName)) { + setErrorMessage(Messages.invalidSynonymNameError); + nameText.setFocus(); + return false; + } + return true; + } + + /** + * Validate synonym name + * + * @return true if it is valid;falseotherwise + */ + private boolean validateTargetName() { + String targetName = targetNameText.getText(); + if (!ValidateUtil.isValidIdentifier(targetName)) { + setErrorMessage(Messages.invalidTargetNameError); + targetNameText.setFocus(); + return false; + } + return true; + } + + /** + * Return true if synonym is changed. + * + * @param oldSynonym the old synonym + * @param newSynonym the new synonym + * @return true if it is changed;falseotherwise + */ + public boolean isChanged(Synonym oldSynonym, Synonym newSynonym) { + if (null != oldSynonym && null != newSynonym) { + String oldDescription = oldSynonym.getComment(); + String newDescription = newSynonym.getComment(); + if (!newDescription.equals(oldDescription)) { + return true; + } + + if(!oldSynonym.equals(newSynonym)) { + return true; + } + + if(!oldSynonym.targetEquals(newSynonym)) { + return true; + } + } + return false; + } + + /** + * + * @return Sql string buffer + */ + private StringBuffer generateSqlText() { // FIXME move this logic to core module + StringBuffer sql = new StringBuffer(); + Synonym newSynonym = getNewSynonym(); + if (null == synonym) { + sql.append(SynonymDDL.getDDL(newSynonym)); + } else { + sql.append(SynonymDDL.getDDL(newSynonym)); + sql.append(StringUtil.NEWLINE); + sql.append(StringUtil.NEWLINE); + sql.append(StringUtil.NEWLINE); + sql.append(SynonymDDL.getAlterDDL(synonym, newSynonym)); + } + return sql; + } + + public Synonym getSynonym() { + return newSynonym; + } + +} diff --git a/com.cubrid.common.ui/src/com/cubrid/common/ui/cubrid/synonym/editor/SynonymDashboardEditorPart.java b/com.cubrid.common.ui/src/com/cubrid/common/ui/cubrid/synonym/editor/SynonymDashboardEditorPart.java new file mode 100644 index 00000000..a5b5ae27 --- /dev/null +++ b/com.cubrid.common.ui/src/com/cubrid/common/ui/cubrid/synonym/editor/SynonymDashboardEditorPart.java @@ -0,0 +1,485 @@ +/* + * Copyright (C) 2009 Search Solution Corporation. All rights reserved by Search + * Solution. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: - + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. - Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. - Neither the name of the nor the names + * of its contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + */ +package com.cubrid.common.ui.cubrid.synonym.editor; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.jface.action.MenuManager; +import org.eclipse.jface.dialogs.IDialogConstants; +import org.eclipse.jface.viewers.IStructuredContentProvider; +import org.eclipse.jface.viewers.ITableLabelProvider; +import org.eclipse.jface.viewers.LabelProvider; +import org.eclipse.jface.viewers.TableViewer; +import org.eclipse.jface.viewers.TableViewerColumn; +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.jface.viewers.ViewerSorter; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.FocusAdapter; +import org.eclipse.swt.events.FocusEvent; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.layout.FillLayout; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Menu; +import org.eclipse.swt.widgets.MenuItem; +import org.eclipse.swt.widgets.TableColumn; +import org.eclipse.swt.widgets.TableItem; +import org.eclipse.swt.widgets.ToolBar; +import org.eclipse.swt.widgets.ToolItem; +import org.eclipse.ui.IEditorInput; +import org.eclipse.ui.IEditorSite; +import org.eclipse.ui.PartInitException; +import org.eclipse.ui.PlatformUI; + +import com.cubrid.common.core.common.model.Synonym; +import com.cubrid.common.ui.CommonUIPlugin; +import com.cubrid.common.ui.cubrid.synonym.Messages; +import com.cubrid.common.ui.cubrid.synonym.action.AlterSynonymAction; +import com.cubrid.common.ui.cubrid.synonym.action.DropSynonymAction; +import com.cubrid.common.ui.cubrid.synonym.action.NewSynonymAction; +import com.cubrid.common.ui.spi.action.ActionManager; +import com.cubrid.common.ui.spi.event.CubridNodeChangedEvent; +import com.cubrid.common.ui.spi.event.CubridNodeChangedEventType; +import com.cubrid.common.ui.spi.model.CubridDatabase; +import com.cubrid.common.ui.spi.model.DefaultSchemaNode; +import com.cubrid.common.ui.spi.model.ICubridNode; +import com.cubrid.common.ui.spi.model.ISchemaNode; +import com.cubrid.common.ui.spi.model.NodeType; +import com.cubrid.common.ui.spi.part.CubridEditorPart; +import com.cubrid.common.ui.spi.progress.OpenSynonymDetailInfoPartProgress; +import com.cubrid.common.ui.spi.util.CommonUITool; + +public class SynonymDashboardEditorPart extends CubridEditorPart { + + public static final String ID = SynonymDashboardEditorPart.class.getName(); + private boolean synonymChangeFlag; + private CubridDatabase database; + private List synonymList = null; + private TableViewer synonymsDetailInfoTable; + + public void createPartControl(Composite parent) { + parent.setLayout(new GridLayout(1, false)); + + ToolBar toolBar = new ToolBar(parent, SWT.LEFT_TO_RIGHT | SWT.FLAT); + toolBar.setLayoutData(CommonUITool.createGridData(1, 1, -1, -1)); + + ToolItem refreshItem = new ToolItem(toolBar,SWT.PUSH); + refreshItem.setText(com.cubrid.common.ui.cubrid.table.Messages.tablesDetailInfoPartRefreshBtn); + refreshItem.setToolTipText(com.cubrid.common.ui.cubrid.table.Messages.tablesDetailInfoPartRefreshBtn); + refreshItem.setImage(CommonUIPlugin.getImage("icons/action/refresh.png")); + refreshItem.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(final SelectionEvent event) { + refresh(); + } + }); + + new ToolItem(toolBar, SWT.SEPARATOR); + ToolItem addItem = new ToolItem(toolBar, SWT.NONE); + addItem.setText(Messages.synonymsDetailInfoPartCreateSynonymBtn); + addItem.setImage(CommonUIPlugin.getImage("icons/action/trigger_add.png")); + addItem.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(final SelectionEvent event) { + addSynonym(); + } + }); + + ToolItem editlItem = new ToolItem(toolBar, SWT.NONE); + editlItem.setText(Messages.synonymsDetailInfoPartEditSynonymBtn); + editlItem.setImage(CommonUIPlugin.getImage("icons/action/trigger_edit.png")); + editlItem.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(final SelectionEvent event) { + editSynonym(); + } + }); + + ToolItem dropItem = new ToolItem(toolBar, SWT.NONE); + dropItem.setText(Messages.synonymsDetailInfoPartDropSynonymBtn); + dropItem.setImage(CommonUIPlugin.getImage("icons/action/trigger_delete.png")); + dropItem.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(final SelectionEvent event) { + dropSynonym(); + } + });; + + createSynonymsDetailInfoTable(parent); + this.setInputs(); + + } + + /** + * create table + * @param parent + */ + public void createSynonymsDetailInfoTable(Composite parent) { + final Composite tableComposite = new Composite(parent, SWT.NONE); + tableComposite.setLayout(new FillLayout()); + tableComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, + true)); + + synonymsDetailInfoTable = new TableViewer(tableComposite, SWT.H_SCROLL + | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.MULTI | SWT.BORDER); + synonymsDetailInfoTable.getTable().setHeaderVisible(true); + synonymsDetailInfoTable.getTable().setLinesVisible(true); + + final TableViewerColumn ownerColumn = new TableViewerColumn( + synonymsDetailInfoTable, SWT.LEFT); + ownerColumn.getColumn().setWidth(150); + ownerColumn.getColumn().setText(Messages.synonymsDetailInfoPartTableOwnerCol); + + final TableViewerColumn nameColumn = new TableViewerColumn( + synonymsDetailInfoTable, SWT.LEFT); + nameColumn.getColumn().setWidth(200); + nameColumn.getColumn().setText(Messages.synonymsDetailInfoPartTableNameCol); + + final TableViewerColumn targetOwnerColumn = new TableViewerColumn( + synonymsDetailInfoTable, SWT.LEFT); + targetOwnerColumn.getColumn().setWidth(150); + targetOwnerColumn.getColumn().setText(Messages.synonymsDetailInfoPartTableTargetOwnerCol); + + final TableViewerColumn targetNameColumn = new TableViewerColumn( + synonymsDetailInfoTable, SWT.LEFT); + targetNameColumn.getColumn().setWidth(200); + targetNameColumn.getColumn().setText(Messages.synonymsDetailInfoPartTableTargetNameCol); + + final TableViewerColumn CommentColumn = new TableViewerColumn( + synonymsDetailInfoTable, SWT.LEFT); + CommentColumn.getColumn().setWidth(250); + CommentColumn.getColumn().setText(Messages.synonymsDetailInfoPartTableCommentCol); + + synonymsDetailInfoTable.setComparator(new ColumnViewerSorter()); + + synonymsDetailInfoTable.setContentProvider(new SynonymsDetailTableViewerContentProvider()); + synonymsDetailInfoTable.setLabelProvider(new SynonymsTableViewerLabelProvider()); + + registerContextMenu(); + } + + /** + * register context menu + */ + private void registerContextMenu() { + synonymsDetailInfoTable.getTable().addFocusListener(new FocusAdapter() { + public void focusGained(FocusEvent event) { + ActionManager.getInstance().changeFocusProvider(synonymsDetailInfoTable.getTable()); + } + }); + + MenuManager menuManager = new MenuManager(); + menuManager.setRemoveAllWhenShown(true); + + Menu contextMenu = menuManager.createContextMenu(synonymsDetailInfoTable.getTable()); + synonymsDetailInfoTable.getTable().setMenu(contextMenu); + + Menu menu = new Menu(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), SWT.POP_UP); + + final MenuItem addSerialItem = new MenuItem(menu, SWT.PUSH); + addSerialItem.setText(Messages.synonymsDetailInfoPartCreateSynonymBtn); + addSerialItem.setImage(CommonUIPlugin.getImage("icons/action/trigger_add.png")); + addSerialItem.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent event) { + addSynonym(); + } + }); + + final MenuItem editSerialItem = new MenuItem(menu, SWT.PUSH); + editSerialItem.setText(Messages.synonymsDetailInfoPartEditSynonymBtn); + editSerialItem.setImage(CommonUIPlugin.getImage("icons/action/trigger_edit.png")); + editSerialItem.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent event) { + editSynonym(); + } + }); + + final MenuItem dropSerialItem = new MenuItem(menu, SWT.PUSH); + dropSerialItem.setText(Messages.synonymsDetailInfoPartDropSynonymBtn); + dropSerialItem.setImage(CommonUIPlugin.getImage("icons/action/trigger_delete.png")); + dropSerialItem.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent event) { + dropSynonym(); + } + }); + + synonymsDetailInfoTable.getTable().setMenu(menu); + } + + /** + * addTrigger + */ + public void addSynonym () { + NewSynonymAction action = (NewSynonymAction) ActionManager.getInstance().getAction( + NewSynonymAction.ID); + action.run(database); + refresh(); + } + + /** + * editTrigger + */ + public void editSynonym () { + TableItem[] items = synonymsDetailInfoTable.getTable().getSelection(); + if (items.length != 0) { + TableItem item = items[0]; + Synonym synonym = (Synonym) item.getData(); + Set typeSet = new HashSet(); + typeSet.add(NodeType.SYNONYM); + + ICubridNode Node = CommonUITool.findNode(database, typeSet, + synonym.getUniqueName()); + if (Node != null) { + AlterSynonymAction action = (AlterSynonymAction) ActionManager.getInstance().getAction( + AlterSynonymAction.ID); + if (action.run(database, (ISchemaNode) Node) == IDialogConstants.OK_ID) { + refresh(); + } + } + } else { + CommonUITool.openWarningBox(Messages.errSynonymNoSelection); + } + } + + /** + * dropTrigger + */ + public void dropSynonym () { + TableItem[] items = synonymsDetailInfoTable.getTable().getSelection(); + if (items.length > 0) { + List selectNodeList = new ArrayList(); + for (TableItem item : items) { + Synonym synonym = (Synonym) item.getData(); + Set typeSet = new HashSet(); + typeSet.add(NodeType.SYNONYM); + + ICubridNode Node = CommonUITool.findNode(database, typeSet, + synonym.getUniqueName()); + selectNodeList.add((ISchemaNode)Node); + } + + if (selectNodeList.size() > 0) { + DropSynonymAction action = (DropSynonymAction) ActionManager.getInstance().getAction( + DropSynonymAction.ID); + + ISchemaNode[] nodeArr = new ISchemaNode[selectNodeList.size()]; + action.run(selectNodeList.toArray(nodeArr)); + refresh(); + } + } else { + CommonUITool.openWarningBox(Messages.errSynonymNoSelection); + } + } + + /** + * refresh data + */ + public void refresh () { + OpenSynonymDetailInfoPartProgress progress = new OpenSynonymDetailInfoPartProgress(database); + progress.loadSynonymInfoList(); + if (progress.isSuccess()) { + synonymList = progress.getSynonymList(); + setInputs(); + } + synonymChangeFlag = false; + } + + /* (non-Javadoc) + * @see org.eclipse.ui.part.EditorPart#init(org.eclipse.ui.IEditorSite, org.eclipse.ui.IEditorInput) + */ + @SuppressWarnings("unchecked") + public void init(IEditorSite site, IEditorInput input) + throws PartInitException { + super.init(site, input); + this.database = (CubridDatabase)input.getAdapter(CubridDatabase.class); + this.synonymList = (List)input.getAdapter(List.class); + + StringBuilder partName = new StringBuilder( + Messages.synonymsDetailInfoPartTitle); + partName.append(" [").append(database.getUserName()).append("@") + .append(database.getName()).append(":") + .append(database.getDatabaseInfo().getBrokerIP()).append("]"); + setPartName(partName.toString()); + } + + public void setInputs() { + synonymsDetailInfoTable.setInput(synonymList); + synonymsDetailInfoTable.refresh(); + pack(); + } + + public void pack () { + for (int i = 0; i < synonymsDetailInfoTable.getTable().getColumnCount(); i++) { + TableColumn column = synonymsDetailInfoTable.getTable().getColumn(i); + if (column.getWidth() > 600) { + column.setWidth(600); + } + if (column.getWidth() < 100) { + column.setWidth(100); + } + } + } + + public void nodeChanged(CubridNodeChangedEvent event) { + if (event.getSource() instanceof DefaultSchemaNode) { + DefaultSchemaNode node = (DefaultSchemaNode)event.getSource(); + if ((node.getType().equals(NodeType.SYNONYM_FOLDER) + ||node.getType().equals(NodeType.SYNONYM) + && node.getDatabase().equals(database) )) { + synonymChangeFlag = true; + } + } + if (CubridNodeChangedEventType.SERVER_DISCONNECTED.equals(event.getType())) { + close(event, database.getServer()); + } + + if (CubridNodeChangedEventType.DATABASE_LOGOUT.equals(event.getType()) + || CubridNodeChangedEventType.DATABASE_STOP.equals(event.getType())) { + close(event, database); + } + } + + public void setFocus() { + //if view info chaned, ask whether refresh + if (synonymChangeFlag) { + if (CommonUITool.openConfirmBox(com.cubrid.common.ui.common.Messages.dashboardConfirmRefreshDataMsg)) { + refresh(); + } + synonymChangeFlag = false; + } + } + + /** + * synonym table label provider + * @author Administrator + * + */ + public class SynonymsTableViewerLabelProvider extends LabelProvider implements + ITableLabelProvider { + + public Image getColumnImage(Object element, int columnIndex) { + return null; + } + + public String getColumnText(Object element, int columnIndex) { + if (element instanceof Synonym) { + Synonym synonym = (Synonym) element; + if (synonym != null) { + switch (columnIndex) { + case 0 : return synonym.getOwner(); + case 1 : return synonym.getName(); + case 2 : return synonym.getTargetOwner(); + case 3 : return synonym.getTargetName(); + case 4 : return synonym.getComment(); + } + } + } + return null; + } + } + + /** + * trigger table content provider + * @author fulei + * + */ + public class SynonymsDetailTableViewerContentProvider implements IStructuredContentProvider { + /** + * getElements + * + * @param inputElement Object + * @return Object[] + */ + @SuppressWarnings("unchecked") + public Object[] getElements(Object inputElement) { + if (inputElement instanceof List) { + List list = (List) inputElement; + Synonym[] nodeArr = new Synonym[list.size()]; + return list.toArray(nodeArr); + } + + return new Object[]{}; + } + + /** + * dispose + */ + public void dispose() { + } + + /** + * inputChanged + * + * @param viewer Viewer + * @param oldInput Object + * @param newInput Object + */ + public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { + // do nothing + } + } + + /** + * Column Viewer Sorter + * + * @author fulei + * @version 1.0 - 2013-1-9 fulei + */ + class ColumnViewerSorter extends + ViewerSorter { + + public int compare(Viewer viewer, Object e1, Object e2) { + Synonym t1 = (Synonym)e1; + Synonym t2 = (Synonym)e2; + return t1.getOwner().compareTo(t2.getOwner()); + } + } + + public void doSave(IProgressMonitor monitor) { + + } + + public void doSaveAs() { + + } + + public boolean isDirty() { + return false; + } + + public boolean isSaveAsAllowed() { + return false; + } + + public CubridDatabase getDatabase() { + return database; + } +} diff --git a/com.cubrid.common.ui/src/com/cubrid/common/ui/cubrid/synonym/editor/SynonymDashboardInput.java b/com.cubrid.common.ui/src/com/cubrid/common/ui/cubrid/synonym/editor/SynonymDashboardInput.java new file mode 100644 index 00000000..aec83c4d --- /dev/null +++ b/com.cubrid.common.ui/src/com/cubrid/common/ui/cubrid/synonym/editor/SynonymDashboardInput.java @@ -0,0 +1,96 @@ +/* + * Copyright (C) 2009 Search Solution Corporation. All rights reserved by Search + * Solution. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: - + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. - Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. - Neither the name of the nor the names + * of its contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + */ +package com.cubrid.common.ui.cubrid.synonym.editor; + +import java.util.List; + +import org.eclipse.core.runtime.Platform; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.ui.IEditorInput; +import org.eclipse.ui.IPersistableElement; + +import com.cubrid.common.core.common.model.Synonym; +import com.cubrid.common.ui.cubrid.synonym.Messages; +import com.cubrid.common.ui.spi.model.CubridDatabase; + +public class SynonymDashboardInput implements IEditorInput { + private final CubridDatabase database; + private final List synonymList; + + public SynonymDashboardInput(CubridDatabase database, List synonymList) { + this.database = database; + this.synonymList = synonymList; + } + + /* (non-Javadoc) + * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class) + */ + public Object getAdapter(Class adapter) { + if (adapter.equals(CubridDatabase.class)) { + return database; + } else if(adapter.equals(List.class)) { + return synonymList; + } + return Platform.getAdapterManager().getAdapter(this, adapter); + } + + /* (non-Javadoc) + * @see org.eclipse.ui.IEditorInput#exists() + */ + public boolean exists() { + return false; + } + + /* (non-Javadoc) + * @see org.eclipse.ui.IEditorInput#getImageDescriptor() + */ + public ImageDescriptor getImageDescriptor() { + return null; + } + + /* (non-Javadoc) + * @see org.eclipse.ui.IEditorInput#getName() + */ + public String getName() { + return Messages.synonymsDetailInfoPartTitle; + } + + /* (non-Javadoc) + * @see org.eclipse.ui.IEditorInput#getPersistable() + */ + public IPersistableElement getPersistable() { + return null; + } + + /* (non-Javadoc) + * @see org.eclipse.ui.IEditorInput#getToolTipText() + */ + public String getToolTipText() { + return this.getName(); + } +} diff --git a/com.cubrid.common.ui/src/com/cubrid/common/ui/cubrid/table/action/CreateLikeTableAction.java b/com.cubrid.common.ui/src/com/cubrid/common/ui/cubrid/table/action/CreateLikeTableAction.java index a0178b98..6817298c 100644 --- a/com.cubrid.common.ui/src/com/cubrid/common/ui/cubrid/table/action/CreateLikeTableAction.java +++ b/com.cubrid.common.ui/src/com/cubrid/common/ui/cubrid/table/action/CreateLikeTableAction.java @@ -27,15 +27,19 @@ */ package com.cubrid.common.ui.cubrid.table.action; +import java.util.List; + import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.jface.viewers.ISelectionProvider; import org.eclipse.jface.viewers.TreeViewer; import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.PlatformUI; import com.cubrid.common.ui.common.navigator.CubridNavigatorView; import com.cubrid.common.ui.cubrid.table.dialog.CreateLikeTableDialog; +import com.cubrid.common.ui.cubrid.table.dialog.CreateViewDialog; import com.cubrid.common.ui.spi.CubridNodeManager; import com.cubrid.common.ui.spi.action.SelectionAction; import com.cubrid.common.ui.spi.event.CubridNodeChangedEvent; @@ -45,9 +49,14 @@ import com.cubrid.common.ui.spi.model.ISchemaNode; import com.cubrid.common.ui.spi.model.NodeType; import com.cubrid.common.ui.spi.model.loader.schema.CubridTablesFolderLoader; +import com.cubrid.common.ui.spi.progress.CommonTaskExec; +import com.cubrid.common.ui.spi.progress.ExecTaskWithProgress; +import com.cubrid.common.ui.spi.progress.TaskExecutor; import com.cubrid.common.ui.spi.util.ActionSupportUtil; import com.cubrid.common.ui.spi.util.CommonUITool; +import com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo; import com.cubrid.cubridmanager.core.cubrid.table.model.ClassInfo; +import com.cubrid.cubridmanager.core.cubrid.user.task.JDBCGetAllDbUserTask; import com.cubrid.cubridmanager.core.utils.ModelUtil.ClassType; /** @@ -146,31 +155,39 @@ public void run(ISchemaNode node) { */ private void doRun(ISchemaNode node) { - CreateLikeTableDialog dialog = new CreateLikeTableDialog(getShell()); - dialog.setDatabase(node.getDatabase()); + TaskExecutor taskExcutor = new CommonTaskExec(null); + + JDBCGetAllDbUserTask task = new JDBCGetAllDbUserTask(node.getDatabase().getDatabaseInfo()); + taskExcutor.addTask(task); + new ExecTaskWithProgress(taskExcutor).busyCursorWhile(); + if (!taskExcutor.isSuccess()) { + return; + } + + List dbUserList = task.getDbUserList(); + + CreateLikeTableDialog dialog = new CreateLikeTableDialog(getShell(), node.getDatabase(), dbUserList); isSupportUserSchema = node.getDatabase().getDatabaseInfo().isSupportUserSchema(); if (NodeType.USER_TABLE.equals(node.getType())) { - String tableName = node.getName(); - dialog.setLikeTableName(tableName); + ClassInfo classInfo = (ClassInfo) node.getAdapter(ClassInfo.class); + if (classInfo != null) { + dialog.setLikeTableName(classInfo.getClassName()); + dialog.setLikeTableOwnerName(classInfo.getOwnerName()); + } } if (IDialogConstants.OK_ID == dialog.open()) { // FIXME TreeViewer treeViewer = CubridNavigatorView.findNavigationView().getViewer(); - String tableName = dialog.getNewTableName(); + String className = dialog.getNewTableName(); + String ownerName = dialog.getNewOwnerName(); + String uniqueName = dialog.getNewUniqueTable(); ICubridNode newNode = null; if (NodeType.USER_TABLE.equals(node.getType())) { ClassInfo classInfo = (ClassInfo) node.getAdapter(ClassInfo.class); String id = node.getParent().getId() - + ICubridNodeLoader.NODE_SEPARATOR + tableName; - ClassInfo newClassInfo = null; - if (isSupportUserSchema) { - newClassInfo = new ClassInfo(getClassName(tableName), getOwnerName(tableName), + + ICubridNodeLoader.NODE_SEPARATOR + uniqueName; + ClassInfo newClassInfo = new ClassInfo(className, ownerName, ClassType.NORMAL, classInfo.isSystemClass(), classInfo.isPartitionedClass(), classInfo.isSupportUserSchema()); - } else { - newClassInfo = new ClassInfo(tableName, null, - ClassType.NORMAL, classInfo.isSystemClass(), - classInfo.isPartitionedClass(), classInfo.isSupportUserSchema()); - } newNode = CubridTablesFolderLoader.createUserTableNode( node.getParent(), id, newClassInfo, node.getParent().getLoader().getLevel(), @@ -181,13 +198,16 @@ private void doRun(ISchemaNode node) { } CommonUITool.addNodeToTree(treeViewer, node.getParent(), newNode); + CommonUITool.updateFolderNodeLabelIncludingChildrenCount(treeViewer, node.getParent()); + CubridNodeManager.getInstance().fireCubridNodeChanged( + new CubridNodeChangedEvent(newNode, CubridNodeChangedEventType.NODE_ADD)); } else { if (node == null || !node.getLoader().isLoaded()) { return; } String id = node.getId() + ICubridNodeLoader.NODE_SEPARATOR - + tableName; - ClassInfo newClassInfo = new ClassInfo(tableName, null, + + className; + ClassInfo newClassInfo = new ClassInfo(className, null, ClassType.NORMAL, false, false, false); newNode = CubridTablesFolderLoader.createUserTableNode( node, id, newClassInfo, node.getLoader().getLevel(), @@ -202,15 +222,22 @@ private void doRun(ISchemaNode node) { private String getClassName(String tableName) { if (isSupportUserSchema) { - return tableName.substring(tableName.indexOf(".")+1); + int idx = tableName.indexOf("."); + if (idx > 0) { + return tableName.substring(idx + 1); + } } return tableName; } private String getOwnerName(String tableName) { if (isSupportUserSchema) { - return tableName.substring(0, tableName.indexOf(".")); + int idx = tableName.indexOf("."); + if (idx > 0) { + return tableName.substring(0, idx); + } } return tableName; } + } diff --git a/com.cubrid.common.ui/src/com/cubrid/common/ui/cubrid/table/dialog/CreateLikeTableDialog.java b/com.cubrid.common.ui/src/com/cubrid/common/ui/cubrid/table/dialog/CreateLikeTableDialog.java index a4b4556e..4bebf5d3 100644 --- a/com.cubrid.common.ui/src/com/cubrid/common/ui/cubrid/table/dialog/CreateLikeTableDialog.java +++ b/com.cubrid.common.ui/src/com/cubrid/common/ui/cubrid/table/dialog/CreateLikeTableDialog.java @@ -27,18 +27,24 @@ */ package com.cubrid.common.ui.cubrid.table.dialog; +import java.util.List; + import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.swt.SWT; import org.eclipse.swt.events.ModifyEvent; import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Combo; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Text; +import com.cubrid.common.core.util.StringUtil; import com.cubrid.common.ui.cubrid.table.Messages; import com.cubrid.common.ui.spi.dialog.CMTitleAreaDialog; import com.cubrid.common.ui.spi.model.CubridDatabase; @@ -47,7 +53,9 @@ import com.cubrid.common.ui.spi.progress.TaskExecutor; import com.cubrid.common.ui.spi.util.CommonUITool; import com.cubrid.common.ui.spi.util.ValidateUtil; +import com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo; import com.cubrid.cubridmanager.core.cubrid.table.task.CreateLikeTableTask; +import com.cubrid.cubridmanager.core.utils.SchemaUtil; /** * @@ -59,19 +67,26 @@ public class CreateLikeTableDialog extends CMTitleAreaDialog implements ModifyListener { + private Text likeTableOwnerText = null; + private Combo newTableOwnerCombo = null; private Text likeTableNameText = null; private Text newTableNameText = null; private CubridDatabase database = null; + private String likeTableOwnerName = null; private String likeTableName = null; private String newTableName = null; + private String newOwnerName = null; + private List dbUserList = null; /** * The constructor * * @param parentShell */ - public CreateLikeTableDialog(Shell parentShell) { + public CreateLikeTableDialog(Shell parentShell, CubridDatabase database, List dbUserList) { super(parentShell); + this.database = database; + this.dbUserList = dbUserList; } /** @@ -86,7 +101,8 @@ protected Control createDialogArea(Composite parent) { Composite composite = new Composite(parentComp, SWT.NONE); composite.setLayoutData(new GridData(GridData.FILL_BOTH)); GridLayout layout = new GridLayout(); - layout.numColumns = 3; + DatabaseInfo dbInfo = database.getDatabaseInfo(); + layout.numColumns = 5; layout.marginHeight = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN); layout.marginWidth = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN); layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING); @@ -96,17 +112,40 @@ protected Control createDialogArea(Composite parent) { Label tableNameLabel = new Label(composite, SWT.LEFT); tableNameLabel.setText(Messages.lblLikeTableName); tableNameLabel.setLayoutData(CommonUITool.createGridData(1, 1, -1, -1)); + + likeTableOwnerText = new Text(composite, SWT.LEFT | SWT.BORDER | SWT.READ_ONLY); + likeTableOwnerText.setLayoutData(CommonUITool.createGridData( + GridData.FILL_HORIZONTAL, 1, 1, 30, -1)); + likeTableNameText = new Text(composite, SWT.LEFT | SWT.BORDER); + int horSpan = 3; likeTableNameText.setLayoutData(CommonUITool.createGridData( - GridData.FILL_HORIZONTAL, 2, 1, 100, -1)); + GridData.FILL_HORIZONTAL, horSpan, 1, 100, -1)); Label newTableNameLabel = new Label(composite, SWT.LEFT); newTableNameLabel.setText(Messages.lblNewTableName); newTableNameLabel.setLayoutData(CommonUITool.createGridData(1, 1, -1, -1)); + + newTableOwnerCombo = new Combo(composite, SWT.LEFT | SWT.BORDER | SWT.READ_ONLY); + newTableOwnerCombo.setLayoutData(CommonUITool.createGridData( + GridData.FILL_HORIZONTAL, 1, 1, 30, -1)); + newTableOwnerCombo.addSelectionListener(new SelectionListener() { + + @Override + public void widgetSelected(SelectionEvent e) { + modifyText(null); + } + + @Override + public void widgetDefaultSelected(SelectionEvent e) { + + } + }); + newTableNameText = new Text(composite, SWT.LEFT | SWT.BORDER); newTableNameText.setTextLimit(ValidateUtil.MAX_SCHEMA_NAME_LENGTH); newTableNameText.setLayoutData(CommonUITool.createGridData( - GridData.FILL_HORIZONTAL, 2, 1, 100, -1)); + GridData.FILL_HORIZONTAL, horSpan, 1, 100, -1)); newTableNameText.addModifyListener(this); if (likeTableName == null) { @@ -117,6 +156,26 @@ protected Control createDialogArea(Composite parent) { likeTableNameText.setEnabled(false); newTableNameText.setFocus(); } + + if (likeTableOwnerName != null) { + likeTableOwnerText.setText(likeTableOwnerName); + likeTableOwnerText.setEnabled(false); + } + + if (dbInfo != null) { + String ownerName; + for (int i = 0 ; i < dbUserList.size() ; i++ ) { + ownerName = dbUserList.get(i); + newTableOwnerCombo.add(ownerName); + boolean isSame = StringUtil.isEqualIgnoreCase(ownerName, database.getDatabaseInfo().getAuthLoginedDbUserInfo().getName()); + if (isSame) { + newTableOwnerCombo.select(i); + } + } + if (!database.getDatabaseInfo().isSupportUserSchema()) { + newTableOwnerCombo.setEnabled(false); + } + } setTitle(Messages.titleCreateLikeTableDialog); setMessage(Messages.msgCreateLikeTableDialog); @@ -165,15 +224,17 @@ protected void buttonPressed(int buttonId) { * */ private void createTable() { + newOwnerName = newTableOwnerCombo.getText(); newTableName = newTableNameText.getText(); String taskName = Messages.bind(Messages.createLikeTableTaskName, - newTableName); + getNewTableName()); TaskExecutor executor = new CommonTaskExec(taskName); CreateLikeTableTask task = new CreateLikeTableTask( getDatabase().getDatabaseInfo()); - likeTableName = likeTableNameText.getText(); task.setTableName(newTableName); - task.setLikeTableName(likeTableName); + task.setOwnerName(newOwnerName); + task.setLikeTableName(getLikeTableName()); + task.setLikeOwnerName(getLikeTableOwnerName()); executor.addTask(task); new ExecTaskWithProgress(executor).exec(); if (task.isSuccess()) { @@ -188,6 +249,7 @@ private void createTable() { */ public void modifyText(ModifyEvent event) { String newTableName = newTableNameText.getText(); + String newOwnerName = newTableOwnerCombo.getText(); String likeTableName = likeTableNameText.getText(); boolean isValid = true; if ("".equals(newTableName) || "".equals(likeTableName)) { @@ -201,9 +263,17 @@ public void modifyText(ModifyEvent event) { isValid = false; newTableNameText.selectAll(); newTableNameText.setFocus(); - } else if (newTableName.equalsIgnoreCase(likeTableName)) { + } else if (database.getDatabaseInfo().isSupportUserSchema() + && newTableName.equalsIgnoreCase(getLikeTableName()) + && newOwnerName.equalsIgnoreCase(getLikeTableOwnerName())) { setErrorMessage(Messages.bind(Messages.errExistTable, - newTableName)); + newOwnerName + "." + newTableName)); + isValid = false; + newTableNameText.setFocus(); + } else if (!database.getDatabaseInfo().isSupportUserSchema() + && newTableName.equalsIgnoreCase(getLikeTableName())) { + setErrorMessage(Messages.bind(Messages.errExistTable, + likeTableOwnerName + "." + newTableName)); isValid = false; newTableNameText.setFocus(); } else if (!ValidateUtil.isASCII(newTableName) @@ -248,6 +318,14 @@ public void setLikeTableName(String likeTableName) { this.likeTableName = likeTableName; } + public String getLikeTableOwnerName() { + return likeTableOwnerName; + } + + public void setLikeTableOwnerName(String ownerName) { + likeTableOwnerName = ownerName; + } + /** * * Return the new table name @@ -257,4 +335,21 @@ public void setLikeTableName(String likeTableName) { public String getNewTableName() { return newTableName; } + + public String getNewOwnerName() { + return newOwnerName; + } + + public String getNewUniqueTable() { + return newOwnerName + "." + newTableName; + } + + public String getLikeUniqueTable() { + return likeTableOwnerName + "." + likeTableName; + } + + public void setDbUserList(List dbUserList) { + this.dbUserList = dbUserList; + } + } diff --git a/com.cubrid.common.ui/src/com/cubrid/common/ui/cubrid/table/dialog/CreateViewDialog.java b/com.cubrid.common.ui/src/com/cubrid/common/ui/cubrid/table/dialog/CreateViewDialog.java index fdd08144..6ae5fa45 100644 --- a/com.cubrid.common.ui/src/com/cubrid/common/ui/cubrid/table/dialog/CreateViewDialog.java +++ b/com.cubrid.common.ui/src/com/cubrid/common/ui/cubrid/table/dialog/CreateViewDialog.java @@ -552,9 +552,7 @@ protected void buttonPressed(int buttonId) { DatabaseInfo dbInfo = database.getDatabaseInfo(); String ownerOld = ""; - if (isNewTableFlag) { - ownerOld = ownerCombo.getText(); - } else { + if (!isNewTableFlag) { ownerOld = classInfo.getOwnerName(); } String ownerNew = ownerCombo.getText(); diff --git a/com.cubrid.common.ui/src/com/cubrid/common/ui/cubrid/table/export/handler/AbsExportDataHandler.java b/com.cubrid.common.ui/src/com/cubrid/common/ui/cubrid/table/export/handler/AbsExportDataHandler.java index 5f2bc569..1a042870 100644 --- a/com.cubrid.common.ui/src/com/cubrid/common/ui/cubrid/table/export/handler/AbsExportDataHandler.java +++ b/com.cubrid.common.ui/src/com/cubrid/common/ui/cubrid/table/export/handler/AbsExportDataHandler.java @@ -58,6 +58,7 @@ import com.cubrid.common.core.common.model.SchemaInfo; import com.cubrid.common.core.common.model.SerialInfo; import com.cubrid.common.core.common.model.Trigger; +import com.cubrid.common.core.util.ApplicationType; import com.cubrid.common.core.util.Closer; import com.cubrid.common.core.util.CompatibleUtil; import com.cubrid.common.core.util.FileUtil; @@ -68,6 +69,7 @@ import com.cubrid.common.ui.cubrid.table.dialog.PstmtParameter; import com.cubrid.common.ui.cubrid.table.event.handler.IExportDataEventHandler; import com.cubrid.common.ui.cubrid.table.progress.ExportConfig; +import com.cubrid.common.ui.perspective.PerspectiveManager; import com.cubrid.common.ui.query.control.QueryExecuter; import com.cubrid.common.ui.spi.util.FieldHandlerUtils; import com.cubrid.cubridmanager.core.common.jdbc.JDBCConnectionManager; @@ -78,6 +80,7 @@ import com.cubrid.cubridmanager.core.cubrid.trigger.model.TriggerDDL; import com.cubrid.cubridmanager.core.cubrid.trigger.task.GetTriggerListTask; import com.cubrid.cubridmanager.core.cubrid.trigger.task.JDBCGetTriggerInfoTask; +import com.cubrid.cubridmanager.core.cubrid.trigger.task.JDBCGetTriggerListTask; import com.cubrid.jdbc.proxy.driver.CUBRIDBlobProxy; import com.cubrid.jdbc.proxy.driver.CUBRIDClobProxy; import com.cubrid.jdbc.proxy.driver.CUBRIDPreparedStatementProxy; @@ -566,10 +569,17 @@ public static void exportSchemaToOBSFile(DatabaseInfo databaseInfo, // TOOLS-4299 export the triggers if (triggerList != null) { - GetTriggerListTask triggerNameTask = new GetTriggerListTask(databaseInfo.getServerInfo()); - triggerNameTask.setDbName(databaseInfo.getDbName()); - triggerNameTask.execute(); - triggerList = triggerNameTask.getTriggerInfoList(); + if (ApplicationType.CUBRID_MANAGER.equals(PerspectiveManager.getInstance().getCurrentMode())) { + GetTriggerListTask triggerNameTask = new GetTriggerListTask(databaseInfo.getServerInfo()); + triggerNameTask.setDbName(databaseInfo.getDbName()); + triggerNameTask.execute(); + triggerList = triggerNameTask.getTriggerInfoList(); + } else { + JDBCGetTriggerListTask jdbcGetTriggerListTask = new JDBCGetTriggerListTask(databaseInfo); + jdbcGetTriggerListTask.execute(); + triggerList = jdbcGetTriggerListTask.getTriggerInfoList(); + } + for (Trigger t: triggerList) { triggerWriter.write(TriggerDDL.getDDL(t, databaseInfo.isSupportUserSchema())); triggerWriter.write(StringUtil.NEWLINE); diff --git a/com.cubrid.common.ui/src/com/cubrid/common/ui/cubrid/trigger/dialog/CreateTriggerDialog.java b/com.cubrid.common.ui/src/com/cubrid/common/ui/cubrid/trigger/dialog/CreateTriggerDialog.java index 9f75ce80..e3b73ed0 100644 --- a/com.cubrid.common.ui/src/com/cubrid/common/ui/cubrid/trigger/dialog/CreateTriggerDialog.java +++ b/com.cubrid.common.ui/src/com/cubrid/common/ui/cubrid/trigger/dialog/CreateTriggerDialog.java @@ -1417,7 +1417,7 @@ private StringBuffer generateSqlText() { // FIXME move this logic to core module sql.append(StringUtil.NEWLINE); sql.append(StringUtil.NEWLINE); sql.append(StringUtil.NEWLINE); - sql.append(TriggerDDL.getAlterDDL(trigger, newTrigger)); + sql.append(TriggerDDL.getAlterDDL(trigger, newTrigger, database.getDatabaseInfo().isSupportUserSchema())); } return sql; } diff --git a/com.cubrid.common.ui/src/com/cubrid/common/ui/cubrid/trigger/editor/TriggerDashboardEditorPart.java b/com.cubrid.common.ui/src/com/cubrid/common/ui/cubrid/trigger/editor/TriggerDashboardEditorPart.java index 0525259e..5c5357ac 100644 --- a/com.cubrid.common.ui/src/com/cubrid/common/ui/cubrid/trigger/editor/TriggerDashboardEditorPart.java +++ b/com.cubrid.common.ui/src/com/cubrid/common/ui/cubrid/trigger/editor/TriggerDashboardEditorPart.java @@ -421,18 +421,19 @@ public String getColumnText(Object element, int columnIndex) { if (element instanceof Trigger) { Trigger trigger = (Trigger)element; if (trigger != null) { - String owner; + String owner = ""; + if (trigger.getOwner() != null) { + owner = trigger.getOwner().toUpperCase(Locale.getDefault()); + } String name = trigger.getName(); if (database.getDatabaseInfo().isSupportUserSchema()) { int idx = name.indexOf("."); if (idx > 0) { - owner = name.substring(0, idx).toUpperCase(Locale.getDefault()); + if (owner == null || owner.isEmpty()) { + owner = name.substring(0, idx).toUpperCase(Locale.getDefault()); + } name = name.substring(idx + 1); - } else { - owner = ""; } - } else { - owner = ""; } switch (columnIndex) { case 0 : return owner; diff --git a/com.cubrid.common.ui/src/com/cubrid/common/ui/spi/Messages.java b/com.cubrid.common.ui/src/com/cubrid/common/ui/spi/Messages.java index 26b0c0bc..38a53cdd 100644 --- a/com.cubrid.common.ui/src/com/cubrid/common/ui/spi/Messages.java +++ b/com.cubrid.common.ui/src/com/cubrid/common/ui/spi/Messages.java @@ -71,6 +71,7 @@ public class Messages extends public static String msgSystemViewFolderName; public static String msgSpFolderName; public static String msgTriggerFolderName; + public static String msgSynonymFolderName; public static String msgSerialFolderName; public static String msgFunctionFolderName; public static String msgProcedureFolderName; @@ -144,6 +145,11 @@ public class Messages extends public static String dropTriggerActionName; public static String newTriggerActionName; public static String alterTriggerActionName; + + public static String dropSynonymActionName; + public static String newSynonymActionName; + public static String alterSynonymActionName; + // serial public static String deleteSerialActionName; public static String createSerialActionName; diff --git a/com.cubrid.common.ui/src/com/cubrid/common/ui/spi/Messages.properties b/com.cubrid.common.ui/src/com/cubrid/common/ui/spi/Messages.properties index 9f21c9c5..d79d7b1e 100644 --- a/com.cubrid.common.ui/src/com/cubrid/common/ui/spi/Messages.properties +++ b/com.cubrid.common.ui/src/com/cubrid/common/ui/spi/Messages.properties @@ -23,6 +23,7 @@ msgSystemTableFolderName=System tables msgSystemViewFolderName=System views msgSpFolderName=Stored procedure msgTriggerFolderName=Triggers +msgSynonymFolderName=Synonyms msgSerialFolderName=Serials msgFunctionFolderName=Function msgProcedureFolderName=Procedure @@ -98,6 +99,10 @@ tableToPhpCodeAction=Create PHP files... newTriggerActionName=&Create Trigger... alterTriggerActionName=&Edit Trigger... dropTriggerActionName=&Drop Trigger +#synonym action message +newSynonymActionName=&Create Synonym... +alterSynonymActionName=&Edit Synonym... +dropSynonymActionName=&Drop Synonym #serial action message deleteSerialActionName=&Drop Serial createSerialActionName=&Create Serial... diff --git a/com.cubrid.common.ui/src/com/cubrid/common/ui/spi/Messages_ko_KR.properties b/com.cubrid.common.ui/src/com/cubrid/common/ui/spi/Messages_ko_KR.properties index 9a0fadc8..153eb1d3 100644 --- a/com.cubrid.common.ui/src/com/cubrid/common/ui/spi/Messages_ko_KR.properties +++ b/com.cubrid.common.ui/src/com/cubrid/common/ui/spi/Messages_ko_KR.properties @@ -23,6 +23,7 @@ msgSystemTableFolderName=\uC2DC\uC2A4\uD15C \uD14C\uC774\uBE14 msgSystemViewFolderName=\uC2DC\uC2A4\uD15C \uBDF0 msgSpFolderName=\uC800\uC7A5 \uD504\uB85C\uC2DC\uC800 msgTriggerFolderName=\uD2B8\uB9AC\uAC70 +msgSynonymFolderName=\ub3d9\uc758\uc5b4 msgSerialFolderName=\uC2DC\uB9AC\uC5BC msgFunctionFolderName=\uD568\uC218 msgProcedureFolderName=\uD504\uB85C\uC2DC\uC800 @@ -98,6 +99,10 @@ tableToPhpCodeAction=PHP \uD30C\uC77C \uC0DD\uC131... newTriggerActionName=\uD2B8\uB9AC\uAC70 \uCD94\uAC00(&C)... alterTriggerActionName=\uD2B8\uB9AC\uAC70 \uD3B8\uC9D1(&E)... dropTriggerActionName=\uD2B8\uB9AC\uAC70 \uC0AD\uC81C(&D) +#synonym action message +newSynonymActionName=\ub3d9\uc758\uc5b4 \ucd94\uac00(&C)... +alterSynonymActionName=\ub3d9\uc758\uc5b4 \ud3b8\uc9d1(&E)... +dropSynonymActionName=\ub3d9\uc758\uc5b4 \uc0ad\uc81c(&D)... #serial action message deleteSerialActionName=\uC2DC\uB9AC\uC5BC \uC0AD\uC81C(&D) createSerialActionName=\uC2DC\uB9AC\uC5BC \uCD94\uAC00(&C)... diff --git a/com.cubrid.common.ui/src/com/cubrid/common/ui/spi/action/ActionBuilder.java b/com.cubrid.common.ui/src/com/cubrid/common/ui/spi/action/ActionBuilder.java index 18fc65a0..76190e02 100644 --- a/com.cubrid.common.ui/src/com/cubrid/common/ui/spi/action/ActionBuilder.java +++ b/com.cubrid.common.ui/src/com/cubrid/common/ui/spi/action/ActionBuilder.java @@ -63,6 +63,9 @@ import com.cubrid.common.ui.cubrid.serial.action.CreateSerialAction; import com.cubrid.common.ui.cubrid.serial.action.DeleteSerialAction; import com.cubrid.common.ui.cubrid.serial.action.EditSerialAction; +import com.cubrid.common.ui.cubrid.synonym.action.AlterSynonymAction; +import com.cubrid.common.ui.cubrid.synonym.action.DropSynonymAction; +import com.cubrid.common.ui.cubrid.synonym.action.NewSynonymAction; import com.cubrid.common.ui.cubrid.table.action.ColumnSelectCountAction; import com.cubrid.common.ui.cubrid.table.action.ColumnSelectSqlAction; import com.cubrid.common.ui.cubrid.table.action.CreateLikeTableAction; @@ -401,7 +404,25 @@ protected void makeActions(Shell shell) { Messages.dropTriggerActionName, loadImage("icons/action/trigger_delete.png")); registerAction(dropTriggerAction); + // synonym related action + IAction newSynonymAction = new NewSynonymAction( + shell, + Messages.newSynonymActionName, + loadImage("icons/action/trigger_add.png"), + loadImage("icons/action/trigger_add_disabled.png")); + registerAction(newSynonymAction); + + IAction alterSynonymAction = new AlterSynonymAction( + shell, + Messages.alterSynonymActionName, + loadImage("icons/action/trigger_edit.png")); + registerAction(alterSynonymAction); + IAction dropSynonymAction = new DropSynonymAction( + shell, + Messages.dropSynonymActionName, + loadImage("icons/action/trigger_delete.png")); + registerAction(dropSynonymAction); // serial related action IAction deleteSerialAction = new DeleteSerialAction( shell, diff --git a/com.cubrid.common.ui/src/com/cubrid/common/ui/spi/action/MenuProvider.java b/com.cubrid.common.ui/src/com/cubrid/common/ui/spi/action/MenuProvider.java index fbb976d4..9d4977af 100644 --- a/com.cubrid.common.ui/src/com/cubrid/common/ui/spi/action/MenuProvider.java +++ b/com.cubrid.common.ui/src/com/cubrid/common/ui/spi/action/MenuProvider.java @@ -47,6 +47,9 @@ import com.cubrid.common.ui.cubrid.serial.action.CreateSerialAction; import com.cubrid.common.ui.cubrid.serial.action.DeleteSerialAction; import com.cubrid.common.ui.cubrid.serial.action.EditSerialAction; +import com.cubrid.common.ui.cubrid.synonym.action.AlterSynonymAction; +import com.cubrid.common.ui.cubrid.synonym.action.DropSynonymAction; +import com.cubrid.common.ui.cubrid.synonym.action.NewSynonymAction; import com.cubrid.common.ui.cubrid.table.action.ColumnSelectCountAction; import com.cubrid.common.ui.cubrid.table.action.ColumnSelectSqlAction; import com.cubrid.common.ui.cubrid.table.action.CreateLikeTableAction; @@ -134,6 +137,11 @@ public void buildMenu(IMenuManager manager, ICubridNode node) { } else if (NodeType.TRIGGER.equals(type)) { // trigger instance addActionToManager(manager, getAction(AlterTriggerAction.ID)); addActionToManager(manager, getAction(DropTriggerAction.ID)); + } else if (NodeType.SYNONYM_FOLDER.equals(type)) { + addActionToManager(manager, getAction(NewSynonymAction.ID)); + } else if (NodeType.SYNONYM.equals(type)) { + addActionToManager(manager, getAction(AlterSynonymAction.ID)); + addActionToManager(manager, getAction(DropSynonymAction.ID)); } else if (NodeType.SERIAL_FOLDER.equals(type)) { addActionToManager(manager, getAction(CreateSerialAction.ID)); } else if (NodeType.SERIAL.equals(type)) { diff --git a/com.cubrid.common.ui/src/com/cubrid/common/ui/spi/contribution/StatusLineContrItem.java b/com.cubrid.common.ui/src/com/cubrid/common/ui/spi/contribution/StatusLineContrItem.java index 6b96d7f5..29bbe78d 100644 --- a/com.cubrid.common.ui/src/com/cubrid/common/ui/spi/contribution/StatusLineContrItem.java +++ b/com.cubrid.common.ui/src/com/cubrid/common/ui/spi/contribution/StatusLineContrItem.java @@ -153,6 +153,8 @@ protected String getChilderenNumStr(ICubridNode cubridNode) { return Messages.bind(Messages.msgSysViewNum, size); } else if (NodeType.TRIGGER_FOLDER.equals(nodeType)) { return Messages.bind(Messages.msgTriggerNum, size); + } else if (NodeType.SYNONYM_FOLDER.equals(nodeType)) { + return Messages.bind(Messages.msgSynonymNum, size); } else if (NodeType.SERIAL_FOLDER.equals(nodeType)) { return Messages.bind(Messages.msgSerialNum, size); } else if (NodeType.STORED_PROCEDURE_FUNCTION_FOLDER.equals(nodeType)) { diff --git a/com.cubrid.common.ui/src/com/cubrid/common/ui/spi/model/NodeType.java b/com.cubrid.common.ui/src/com/cubrid/common/ui/spi/model/NodeType.java index 6517f887..cf473268 100644 --- a/com.cubrid.common.ui/src/com/cubrid/common/ui/spi/model/NodeType.java +++ b/com.cubrid.common.ui/src/com/cubrid/common/ui/spi/model/NodeType.java @@ -58,6 +58,8 @@ public class NodeType { public static final String STORED_PROCEDURE_PROCEDURE = "STORED_PROCEDURE_PROCEDURE"; public static final String TRIGGER_FOLDER = "TRIGGER_FOLDER"; public static final String TRIGGER = "TRIGGER"; + public static final String SYNONYM_FOLDER = "SYNONYM_FOLDER"; + public static final String SYNONYM = "SYNONYM"; public static final String SERIAL_FOLDER = "SERIAL_FOLDER"; public static final String SERIAL = "SERIAL"; public static final String TABLE_COLUMN_FOLDER = "TABLE_COLUMN_FOLDER"; diff --git a/com.cubrid.common.ui/src/com/cubrid/common/ui/spi/model/loader/CubridSynonymFolderLoader.java b/com.cubrid.common.ui/src/com/cubrid/common/ui/spi/model/loader/CubridSynonymFolderLoader.java new file mode 100644 index 00000000..f77e100a --- /dev/null +++ b/com.cubrid.common.ui/src/com/cubrid/common/ui/spi/model/loader/CubridSynonymFolderLoader.java @@ -0,0 +1,136 @@ +/* + * Copyright (C) 2009 Search Solution Corporation. All rights reserved by Search + * Solution. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: - + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. - Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. - Neither the name of the nor the names + * of its contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + */ +package com.cubrid.common.ui.spi.model.loader; + +import java.util.Collections; +import java.util.List; + +import org.eclipse.core.runtime.IProgressMonitor; + +import com.cubrid.common.core.common.model.Synonym; +import com.cubrid.common.core.task.ITask; +import com.cubrid.common.ui.spi.CubridNodeManager; +import com.cubrid.common.ui.spi.event.CubridNodeChangedEvent; +import com.cubrid.common.ui.spi.event.CubridNodeChangedEventType; +import com.cubrid.common.ui.spi.model.CubridDatabase; +import com.cubrid.common.ui.spi.model.CubridNodeLoader; +import com.cubrid.common.ui.spi.model.DefaultSchemaNode; +import com.cubrid.common.ui.spi.model.ICubridNode; +import com.cubrid.common.ui.spi.model.ISchemaNode; +import com.cubrid.common.ui.spi.model.NodeType; +import com.cubrid.cubridmanager.core.common.model.DbRunningType; +import com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo; +import com.cubrid.cubridmanager.core.cubrid.synonym.JDBCGetSynonymListTask; + +public class CubridSynonymFolderLoader extends + CubridNodeLoader { + + public static final String SYNONYM_FOLDER_ID = "Synonym"; + + /** + * + * Load children object for parent + * + * @param parent the parent node + * @param monitor the IProgressMonitor object + */ + public void load(ICubridNode parent, final IProgressMonitor monitor) { + synchronized (this) { + if (isLoaded()) { + return; + } + CubridDatabase database = ((ISchemaNode) parent).getDatabase(); + if (!database.isLogined() + || database.getRunningType() == DbRunningType.STANDALONE) { + database.getDatabaseInfo().setSynonymList(null); + parent.removeAllChild(); + CubridNodeManager.getInstance().fireCubridNodeChanged( + new CubridNodeChangedEvent( + (ICubridNode) parent, + CubridNodeChangedEventType.CONTAINER_NODE_REFRESH)); + return; + } + DatabaseInfo databaseInfo = database.getDatabaseInfo(); + ITask task = null; + task = new JDBCGetSynonymListTask(databaseInfo); + + monitorCancel(monitor, new ITask[]{task }); + task.execute(); + final String errorMsg = task.getErrorMsg(); + if (!monitor.isCanceled() && errorMsg != null + && errorMsg.trim().length() > 0) { + parent.removeAllChild(); + openErrorBox(errorMsg); + setLoaded(true); + return; + } + if (monitor.isCanceled()) { + setLoaded(true); + return; + } + + parent.removeAllChild(); + List synonymList = null; + synonymList = ((JDBCGetSynonymListTask) task).getSynonymInfoList(); + if (synonymList != null && !synonymList.isEmpty()) { + for (Synonym synonym : synonymList) { + String id = parent.getId() + NODE_SEPARATOR + + synonym.getUniqueName(); + ICubridNode Node = createSynonymNode(databaseInfo, id, synonym); + parent.addChild(Node); + } + } + databaseInfo.setSynonymList(synonymList); + Collections.sort(parent.getChildren()); + setLoaded(true); + CubridNodeManager.getInstance().fireCubridNodeChanged( + new CubridNodeChangedEvent((ICubridNode) parent, + CubridNodeChangedEventType.CONTAINER_NODE_REFRESH)); + } + } + + /** + * + * Create synonym node + * + * @param id The node id + * @param synonym The model object + * @return ICubridNode + */ + public static ICubridNode createSynonymNode(DatabaseInfo databaseInfo, String id, Synonym synonym) { + ICubridNode Node; + Node = new DefaultSchemaNode(id, + "[" + synonym.getOwner() + "] " + synonym.getName(), + synonym.getUniqueName(), + "icons/navigator/synonym_item.png"); + Node.setType(NodeType.SYNONYM); + Node.setModelObj(synonym); + Node.setContainer(false); + return Node; + } +} diff --git a/com.cubrid.common.ui/src/com/cubrid/common/ui/spi/progress/OpenSynonymDetailInfoPartProgress.java b/com.cubrid.common.ui/src/com/cubrid/common/ui/spi/progress/OpenSynonymDetailInfoPartProgress.java new file mode 100644 index 00000000..f35bb45f --- /dev/null +++ b/com.cubrid.common.ui/src/com/cubrid/common/ui/spi/progress/OpenSynonymDetailInfoPartProgress.java @@ -0,0 +1,103 @@ +/* + * Copyright (C) 2009 Search Solution Corporation. All rights reserved by Search + * Solution. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: - + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. - Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. - Neither the name of the nor the names + * of its contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + */ +package com.cubrid.common.ui.spi.progress; + +import java.lang.reflect.InvocationTargetException; +import java.util.List; + +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.jface.dialogs.ProgressMonitorDialog; +import org.eclipse.jface.operation.IRunnableWithProgress; +import org.eclipse.swt.widgets.Display; +import org.slf4j.Logger; + +import com.cubrid.common.core.common.model.Synonym; +import com.cubrid.common.core.task.ITask; +import com.cubrid.common.core.util.LogUtil; +import com.cubrid.common.ui.spi.model.CubridDatabase; +import com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo; +import com.cubrid.cubridmanager.core.cubrid.synonym.JDBCGetSynonymListTask; + +/** + * @author fulei + * + * @version 1.0 - 2013-1-9 created by fulei + */ +public class OpenSynonymDetailInfoPartProgress implements IRunnableWithProgress { + + private static final Logger LOGGER = LogUtil.getLogger(OpenViewsDetailInfoPartProgress.class); + private final CubridDatabase database; + private List synonymList = null; + private boolean success = false; + + public OpenSynonymDetailInfoPartProgress (CubridDatabase database) { + this.database = database; + } + + public void run(IProgressMonitor monitor) throws InvocationTargetException, + InterruptedException { + DatabaseInfo databaseInfo = database.getDatabaseInfo(); + ITask task = null; + task = new JDBCGetSynonymListTask(databaseInfo); + + task.execute(); + if (!task.isSuccess()) { + LOGGER.error(task.getErrorMsg()); + return; + } + synonymList = ((JDBCGetSynonymListTask) task).getSynonymInfoList(); + success = true; + } + + /** + * load trigger info list + * + * @return Catalog + */ + public void loadSynonymInfoList() { + Display display = Display.getDefault(); + display.syncExec(new Runnable() { + public void run() { + try { + new ProgressMonitorDialog(null).run(true, false, + OpenSynonymDetailInfoPartProgress.this); + } catch (Exception e) { + LOGGER.error(e.getMessage(), e); + } + } + }); + } + + public List getSynonymList() { + return synonymList; + } + + public boolean isSuccess() { + return success; + } +} diff --git a/com.cubrid.common.ui/src/com/cubrid/common/ui/spi/util/ActionSupportUtil.java b/com.cubrid.common.ui/src/com/cubrid/common/ui/spi/util/ActionSupportUtil.java index 8a7c6502..bec364c0 100644 --- a/com.cubrid.common.ui/src/com/cubrid/common/ui/spi/util/ActionSupportUtil.java +++ b/com.cubrid.common.ui/src/com/cubrid/common/ui/spi/util/ActionSupportUtil.java @@ -30,6 +30,8 @@ import org.slf4j.Logger; import com.cubrid.common.core.common.model.SerialInfo; +import com.cubrid.common.core.common.model.Synonym; +import com.cubrid.common.core.common.model.Trigger; import com.cubrid.common.core.util.LogUtil; import com.cubrid.common.core.util.StringUtil; import com.cubrid.common.ui.spi.model.CubridDatabase; @@ -216,15 +218,6 @@ public static boolean isSupportSinSelCheckDbUser(Object obj, String type) { } boolean isSameUser = StringUtil.isEqualIgnoreCase(userInfo.getName(), getOwner(schemaNode)); - if (!isSameUser && type == NodeType.TRIGGER) { - if (dbInfo.isSupportUserSchema()) { - int idx = schemaNode.getName().indexOf("."); - if (idx > 0) { - String ownerName = schemaNode.getName().substring(0, idx); - isSameUser = StringUtil.isEqualIgnoreCase(userInfo.getName(), ownerName); - } - } - } if (isSameUser) { return true; @@ -250,6 +243,12 @@ private static String getOwner(ISchemaNode node) { || NodeType.STORED_PROCEDURE_PROCEDURE.equals(type)) { SPInfo spInfo = (SPInfo) node.getAdapter(SPInfo.class); return spInfo == null ? null : spInfo.getOwner(); + } else if (NodeType.SYNONYM.equals(type)) { + Synonym syInfo = (Synonym) node.getAdapter(Synonym.class); + return syInfo == null ? null : syInfo.getOwner(); + } else if (NodeType.TRIGGER.equals(type)) { + Trigger triInfo = (Trigger) node.getAdapter(Trigger.class); + return triInfo == null ? null : triInfo.getOwner(); } return null; } diff --git a/com.cubrid.common.ui/src/com/cubrid/common/ui/spi/util/CommonUITool.java b/com.cubrid.common.ui/src/com/cubrid/common/ui/spi/util/CommonUITool.java index 594d0c20..d65966e0 100644 --- a/com.cubrid.common.ui/src/com/cubrid/common/ui/spi/util/CommonUITool.java +++ b/com.cubrid.common.ui/src/com/cubrid/common/ui/spi/util/CommonUITool.java @@ -1446,7 +1446,8 @@ public static void updateFolderNodeLabelIncludingChildrenCount(AbstractTreeViewe && !node.getType().equals(NodeType.USER_FOLDER) && !node.getType().equals(NodeType.VIEW_FOLDER) && !node.getType().equals(NodeType.SERIAL_FOLDER) - && !node.getType().equals(NodeType.TRIGGER_FOLDER)) { + && !node.getType().equals(NodeType.TRIGGER_FOLDER) + && !node.getType().equals(NodeType.SYNONYM_FOLDER)) { return; } int count = 0; diff --git a/com.cubrid.common.ui/src/com/cubrid/common/ui/spi/util/NodeUtil.java b/com.cubrid.common.ui/src/com/cubrid/common/ui/spi/util/NodeUtil.java index 79ff63b9..f04bbdd4 100644 --- a/com.cubrid.common.ui/src/com/cubrid/common/ui/spi/util/NodeUtil.java +++ b/com.cubrid.common.ui/src/com/cubrid/common/ui/spi/util/NodeUtil.java @@ -70,6 +70,10 @@ public static boolean isTriggerFolderNode(ICubridNode node) { return NodeType.TRIGGER_FOLDER.equals(node.getType()); } + public static boolean isSynonymFolderNode(ICubridNode node) { + return NodeType.SYNONYM_FOLDER.equals(node.getType()); + } + public static boolean isUserFolderNode(ICubridNode node) { return NodeType.USER_FOLDER.equals(node.getType()); } diff --git a/com.cubrid.cubridmanager.core.testfragment/src/com/cubrid/cubridmanager/core/cubrid/trigger/model/TriggerDDLTest.java b/com.cubrid.cubridmanager.core.testfragment/src/com/cubrid/cubridmanager/core/cubrid/trigger/model/TriggerDDLTest.java index da599e1b..41a0955a 100644 --- a/com.cubrid.cubridmanager.core.testfragment/src/com/cubrid/cubridmanager/core/cubrid/trigger/model/TriggerDDLTest.java +++ b/com.cubrid.cubridmanager.core.testfragment/src/com/cubrid/cubridmanager/core/cubrid/trigger/model/TriggerDDLTest.java @@ -187,7 +187,7 @@ public void testGetAlterDDL() { newTrigger.setAction(action); newTrigger.setStatus(status); newTrigger.setPriority(priority); - TriggerDDL.getAlterDDL(trigger, newTrigger); + TriggerDDL.getAlterDDL(trigger, newTrigger, false); trigger.setName(name); trigger.setConditionTime(conditionTime); trigger.setEventType(eventType); @@ -210,7 +210,7 @@ public void testGetAlterDDL() { newTrigger.setAction(action); newTrigger.setStatus("no"); newTrigger.setPriority("99"); - TriggerDDL.getAlterDDL(trigger, newTrigger); + TriggerDDL.getAlterDDL(trigger, newTrigger, false); } } diff --git a/com.cubrid.cubridmanager.core/META-INF/MANIFEST.MF b/com.cubrid.cubridmanager.core/META-INF/MANIFEST.MF index 2315a9cb..a174485c 100644 --- a/com.cubrid.cubridmanager.core/META-INF/MANIFEST.MF +++ b/com.cubrid.cubridmanager.core/META-INF/MANIFEST.MF @@ -45,6 +45,7 @@ Export-Package: com.cubrid.cubridmanager.core, com.cubrid.cubridmanager.core.cubrid.service.task, com.cubrid.cubridmanager.core.cubrid.sp.model, com.cubrid.cubridmanager.core.cubrid.sp.task, + com.cubrid.cubridmanager.core.cubrid.synonym, com.cubrid.cubridmanager.core.cubrid.table, com.cubrid.cubridmanager.core.cubrid.table.model, com.cubrid.cubridmanager.core.cubrid.table.task, diff --git a/com.cubrid.cubridmanager.core/src/com/cubrid/cubridmanager/core/common/task/GetCMUserListTask.java b/com.cubrid.cubridmanager.core/src/com/cubrid/cubridmanager/core/common/task/GetCMUserListTask.java index 99516990..0f1aeb35 100644 --- a/com.cubrid.cubridmanager.core/src/com/cubrid/cubridmanager/core/common/task/GetCMUserListTask.java +++ b/com.cubrid.cubridmanager.core/src/com/cubrid/cubridmanager/core/common/task/GetCMUserListTask.java @@ -30,6 +30,7 @@ import java.util.ArrayList; import java.util.List; +import com.cubrid.common.core.util.CompatibleUtil; import com.cubrid.cubridmanager.core.common.model.CasAuthType; import com.cubrid.cubridmanager.core.common.model.ServerInfo; import com.cubrid.cubridmanager.core.common.model.ServerUserInfo; @@ -310,6 +311,7 @@ private void buildDatabaseInfo(String[] dbNameArr, String[] dbUserIdArr, databaseInfo.setBrokerPort(brokerPort); } databaseInfo.setAuthLoginedDbUserInfo(databaseUserInfo); + databaseInfo.setSupportUserSchema(CompatibleUtil.isAfter112(databaseInfo)); userInfo.addDatabaseInfo(databaseInfo); } } diff --git a/com.cubrid.cubridmanager.core/src/com/cubrid/cubridmanager/core/cubrid/database/model/DatabaseInfo.java b/com.cubrid.cubridmanager.core/src/com/cubrid/cubridmanager/core/cubrid/database/model/DatabaseInfo.java index 002465d2..bdc016e7 100644 --- a/com.cubrid.cubridmanager.core/src/com/cubrid/cubridmanager/core/cubrid/database/model/DatabaseInfo.java +++ b/com.cubrid.cubridmanager.core/src/com/cubrid/cubridmanager/core/cubrid/database/model/DatabaseInfo.java @@ -37,6 +37,7 @@ import com.cubrid.common.core.common.model.IDatabaseSpec; import com.cubrid.common.core.common.model.SchemaInfo; import com.cubrid.common.core.common.model.SerialInfo; +import com.cubrid.common.core.common.model.Synonym; import com.cubrid.common.core.common.model.Trigger; import com.cubrid.common.core.util.FileUtil; import com.cubrid.common.core.util.QueryUtil; @@ -77,6 +78,8 @@ public class DatabaseInfo implements IDatabaseSpec { private String jdbcAttrs = null; // all trigger private List triggerList = null; + // all synonym + private List synonymList = null; // all classes private List userTableInfoList = null; private List userViewInfoList = null; @@ -194,6 +197,7 @@ public void clear() { partitionedTableMap = null; dbSpaceInfoList = null; triggerList = null; + synonymList = null; backupPlanInfoList = null; queryPlanInfoList = null; spProcedureInfoList = null; @@ -389,6 +393,31 @@ public void setTriggerList(List triggerList) { } } + /** + * + * Get all synonyms list + * + * @return List + */ + public List getSynonymList() { + synchronized (this) { + return synonymList; + } + } + + /** + * + * Set synonyms list + * + * @param synonymList List The given list that includes the + * Synonym of Synonyms + */ + public void setSynonymList(List synonymList) { + synchronized (this) { + this.synonymList = synonymList; + } + } + /** * * Get class info list diff --git a/com.cubrid.cubridmanager.core/src/com/cubrid/cubridmanager/core/cubrid/synonym/JDBCGetSynonymInfoTask.java b/com.cubrid.cubridmanager.core/src/com/cubrid/cubridmanager/core/cubrid/synonym/JDBCGetSynonymInfoTask.java new file mode 100644 index 00000000..af0eb7fe --- /dev/null +++ b/com.cubrid.cubridmanager.core/src/com/cubrid/cubridmanager/core/cubrid/synonym/JDBCGetSynonymInfoTask.java @@ -0,0 +1,98 @@ +/* + * Copyright (C) 2013 Search Solution Corporation. All rights reserved by Search + * Solution. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: - + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. - Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. - Neither the name of the nor the names + * of its contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + */ +package com.cubrid.cubridmanager.core.cubrid.synonym; + +import java.sql.PreparedStatement; +import java.sql.SQLException; + +import org.slf4j.Logger; + +import com.cubrid.common.core.common.model.Synonym; +import com.cubrid.common.core.util.LogUtil; +import com.cubrid.cubridmanager.core.Messages; +import com.cubrid.cubridmanager.core.common.jdbc.JDBCTask; +import com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo; + +public class JDBCGetSynonymInfoTask extends JDBCTask { + private static final Logger LOGGER = LogUtil.getLogger(JDBCGetSynonymInfoTask.class); + + /** + * The constructor + * + * @param dbInfo + */ + public JDBCGetSynonymInfoTask(DatabaseInfo dbInfo) { + super("GetSynonymInfo", dbInfo); + } + + /** + * Get Synonym information by Synonym Unique name + * + * @param synonymUniqueName String The given synonym Unique name + * @return Synonym The instance of Synonym + */ + public Synonym getSynonymInfo(String synonymUniqueName) { + Synonym synonym = null; + try { + if (errorMsg != null && errorMsg.trim().length() > 0) { + return null; + } + + if (connection == null || connection.isClosed()) { + errorMsg = Messages.error_getConnection; + return null; + } + + String sql = "SELECT *" + + " FROM db_synonym" + + " WHERE CONCAT(synonym_owner_name , '.' , synonym_name)=?"; + + // [TOOLS-2425]Support shard broker + sql = DatabaseInfo.wrapShardQuery(databaseInfo, sql); + + stmt = connection.prepareStatement(sql); + ((PreparedStatement) stmt).setString(1, synonymUniqueName); + rs = ((PreparedStatement) stmt).executeQuery(); + while (rs.next()) { + synonym = new Synonym(); + synonym.setName(rs.getString("synonym_name")); + synonym.setOwner(rs.getString("synonym_owner_name")); + synonym.setTargetName(rs.getString("target_name")); + synonym.setTargetOwner(rs.getString("target_owner_name")); + synonym.setComment(rs.getString("comment")); + } + } catch (SQLException e) { + errorMsg = e.getMessage(); + LOGGER.error(e.getMessage(), e); + } finally { + finish(); + } + + return synonym; + } +} diff --git a/com.cubrid.cubridmanager.core/src/com/cubrid/cubridmanager/core/cubrid/synonym/JDBCGetSynonymListTask.java b/com.cubrid.cubridmanager.core/src/com/cubrid/cubridmanager/core/cubrid/synonym/JDBCGetSynonymListTask.java new file mode 100644 index 00000000..0e69190c --- /dev/null +++ b/com.cubrid.cubridmanager.core/src/com/cubrid/cubridmanager/core/cubrid/synonym/JDBCGetSynonymListTask.java @@ -0,0 +1,99 @@ +/* + * Copyright (C) 2013 Search Solution Corporation. All rights reserved by Search + * Solution. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: - + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. - Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. - Neither the name of the nor the names + * of its contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + */ + +package com.cubrid.cubridmanager.core.cubrid.synonym; + +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; + +import org.slf4j.Logger; + +import com.cubrid.common.core.common.model.Synonym; +import com.cubrid.common.core.util.LogUtil; +import com.cubrid.cubridmanager.core.Messages; +import com.cubrid.cubridmanager.core.common.jdbc.JDBCTask; +import com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo; + +public class JDBCGetSynonymListTask extends JDBCTask { + private static final Logger LOGGER = LogUtil.getLogger(JDBCGetSynonymListTask.class); + private final List synonyms = new ArrayList(); + + public JDBCGetSynonymListTask(DatabaseInfo dbInfo) { + super("GetSynonymList", dbInfo); + } + + /** + * Execute select sql. + */ + public void execute() { + try { + if (errorMsg != null && errorMsg.trim().length() > 0) { + return; + } + if (connection == null || connection.isClosed()) { + errorMsg = Messages.error_getConnection; + return; + } + stmt = connection.createStatement(); + String sql = "select * from db_synonym"; + + // [TOOLS-2425]Support shard broker + sql = DatabaseInfo.wrapShardQuery(databaseInfo, sql); + + rs = stmt.executeQuery(sql); + while (rs.next()) { + Synonym synonym = new Synonym(); + synonym.setName(rs.getString("synonym_name")); + synonym.setOwner(rs.getString("synonym_owner_name")); + synonym.setTargetName(rs.getString("target_name")); + synonym.setTargetOwner(rs.getString("target_owner_name")); + synonym.setComment(rs.getString("comment")); + synonyms.add(synonym); + } + } catch (SQLException e) { + errorMsg = e.getMessage(); + if (errorMsg.indexOf("Select is not authorized on db_trigger") >= 0) { + errorMsg = ""; + } + + LOGGER.error(e.getMessage(), e); + } finally { + finish(); + } + } + + /** + * Return whether adding synonym task is executed well + * + * @return List + */ + public List getSynonymInfoList() { + return synonyms; + } +} diff --git a/com.cubrid.cubridmanager.core/src/com/cubrid/cubridmanager/core/cubrid/synonym/SynonymDDL.java b/com.cubrid.cubridmanager.core/src/com/cubrid/cubridmanager/core/cubrid/synonym/SynonymDDL.java new file mode 100644 index 00000000..656c458a --- /dev/null +++ b/com.cubrid.cubridmanager.core/src/com/cubrid/cubridmanager/core/cubrid/synonym/SynonymDDL.java @@ -0,0 +1,132 @@ +/* + * Copyright (C) 2013 Search Solution Corporation. All rights reserved by Search + * Solution. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: - + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. - Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions and + * the following disclaimer in the documentation and/or other materials provided + * with the distribution. - Neither the name of the nor the names + * of its contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + */ +package com.cubrid.cubridmanager.core.cubrid.synonym; + +import com.cubrid.common.core.common.model.Synonym; +import com.cubrid.common.core.util.QuerySyntax; +import com.cubrid.common.core.util.StringUtil; + +/** + * + * This class indicates the trigger ddl + * + * @author sq + * @version 1.0 - 2009-12-29 created by sq + */ +public final class SynonymDDL { + //Constructor + private SynonymDDL() { + //empty + } + + static String newLine = StringUtil.NEWLINE; + static String endLineChar = ";"; + + /** + * Get the ddl + * + * @param trigger Trigger + * @return String + */ + public static String getDDL(Synonym synonym) { + StringBuffer bf = new StringBuffer(); + appendHead(synonym, bf); + appendComment(synonym, bf); + return bf.toString(); + } + + /** + * COMMENT 'user defined comment' [ ; ] + * + * @param trigger Trigger + * @param bf StringBuffer + */ + public static void appendComment(Synonym synonym, StringBuffer bf) { + String commnet = synonym.getComment(); + if (StringUtil.isNotEmpty(commnet)) { + commnet = String.format("'%s'", commnet); + bf.append(String.format(" COMMENT %s", StringUtil.escapeQuotes(commnet))); + } + bf.append(endLineChar); + } + + /** + * Generate head of trigger clause. + * + * @param trigger Trigger + * @param bf StringBuffer + */ + private static void appendHead(Synonym synonym, StringBuffer bf) { + //CREATE TRIGGER trigger_name + bf.append("CREATE SYNONYM "); + String synonymName = synonym.getName(); + String ownerName = synonym.getOwner(); + String targetName = synonym.getTargetName(); + String targetOwner = synonym.getTargetOwner(); + bf.append(QuerySyntax.escapeKeyword(ownerName) + "." + QuerySyntax.escapeKeyword(synonymName)); + bf.append(" FOR "); + bf.append(QuerySyntax.escapeKeyword(targetOwner) + "." + QuerySyntax.escapeKeyword(targetName)); + bf.append(newLine); + } + + /** + * Get after ddl + * + * @param oldTrigger Trigger + * @param newTrigger Trigger + * @return String + */ + public static String getAlterDDL(Synonym oldSynonym, Synonym newSynonym) { + String oldName = newSynonym.getName(); + String oldOwnerName = newSynonym.getOwner(); + String targetName = newSynonym.getTargetName(); + String targetOwner = newSynonym.getTargetOwner(); + StringBuffer bf = new StringBuffer(); + bf.append("ALTER SYNONYM "); + bf.append(QuerySyntax.escapeKeyword(oldOwnerName) + "." + QuerySyntax.escapeKeyword(oldName)); + bf.append(" FOR "); + bf.append(QuerySyntax.escapeKeyword(targetOwner) + "." + QuerySyntax.escapeKeyword(targetName)); + + String oldComment = oldSynonym.getComment(); + String newCommnet = newSynonym.getComment(); + boolean commentChanged = false; + if (newCommnet != null && !newCommnet.equals(oldComment)) { + commentChanged = true; + } + + if (commentChanged) { + newCommnet = String.format("'%s'", newCommnet); + bf.append(String.format(" COMMENT %s", StringUtil.escapeQuotes(newCommnet))); + bf.append(endLineChar); + bf.append(newLine); + } + bf.append(endLineChar); + + return bf.toString(); + } +} diff --git a/com.cubrid.cubridmanager.core/src/com/cubrid/cubridmanager/core/cubrid/table/model/SchemaDDL.java b/com.cubrid.cubridmanager.core/src/com/cubrid/cubridmanager/core/cubrid/table/model/SchemaDDL.java index 586b7f0b..f11975f7 100644 --- a/com.cubrid.cubridmanager.core/src/com/cubrid/cubridmanager/core/cubrid/table/model/SchemaDDL.java +++ b/com.cubrid.cubridmanager.core/src/com/cubrid/cubridmanager/core/cubrid/table/model/SchemaDDL.java @@ -97,8 +97,12 @@ public String getSchemaDDL(SchemaInfo schemaInfo) { return getSchemaDDL(schemaInfo, true); } + public String getSchemaDDLforErwin(SchemaInfo schemaInfo) { + return getSchemaDDL(schemaInfo, true, false, false, true); + } + public String getSchemaDDLForExport(SchemaInfo schemaInfo, boolean isContainIndex) { - return getSchemaDDL(schemaInfo, isContainIndex, false, true); + return getSchemaDDL(schemaInfo, isContainIndex, false, true, false); } /** @@ -113,7 +117,7 @@ public String getSchemaDDL(SchemaInfo schemaInfo, boolean isContainIndex) { } public String getSchemaDDL(SchemaInfo schemaInfo, boolean isContainIndex, boolean isVirtual) { - return getSchemaDDL(schemaInfo, isContainIndex, isVirtual, false); + return getSchemaDDL(schemaInfo, isContainIndex, isVirtual, false, false); } /** @@ -124,7 +128,7 @@ public String getSchemaDDL(SchemaInfo schemaInfo, boolean isContainIndex, boolea * @param isVirtual boolean whether be a virtual table * @return String a string indicates a instance of SchemaInfo */ - public String getSchemaDDL(SchemaInfo schemaInfo, boolean isContainIndex, boolean isVirtual, boolean isExport) { + public String getSchemaDDL(SchemaInfo schemaInfo, boolean isContainIndex, boolean isVirtual, boolean isExport, boolean isERwin) { StringBuffer ddlBuffer = new StringBuffer(); ddlBuffer.append("CREATE TABLE "); if (databaseInfo.isSupportUserSchema()) { @@ -141,7 +145,29 @@ public String getSchemaDDL(SchemaInfo schemaInfo, boolean isContainIndex, boolea } } else { final String className = schemaInfo.getClassname(); - if (null == className || className.equals("")) { + if (isERwin) { + final String uniqueName = schemaInfo.getUniqueName(); + if (null == uniqueName || uniqueName.isEmpty()) { + ddlBuffer.append(""); + } else { + int idx = uniqueName.indexOf("."); + boolean isSupportUserSchema = false; + for (int i = 0; i < idx; i++) { + char ch = uniqueName.charAt(i); + if (Character.isUpperCase(ch)){ + isSupportUserSchema = true; + break; + } + } + if (isSupportUserSchema) { + ddlBuffer.append(QuerySyntax.escapeKeyword(uniqueName.substring(0, idx)) + + "." + QuerySyntax.escapeKeyword(uniqueName.substring(idx + 1))); + } else { + ddlBuffer.append(QuerySyntax.escapeKeyword(uniqueName)); + } + } + } + else if (null == className || className.equals("")) { ddlBuffer.append(""); } else { ddlBuffer.append(QuerySyntax.escapeKeyword(className)); diff --git a/com.cubrid.cubridmanager.core/src/com/cubrid/cubridmanager/core/cubrid/table/task/CreateLikeTableTask.java b/com.cubrid.cubridmanager.core/src/com/cubrid/cubridmanager/core/cubrid/table/task/CreateLikeTableTask.java index 28a110b5..bf3171bc 100644 --- a/com.cubrid.cubridmanager.core/src/com/cubrid/cubridmanager/core/cubrid/table/task/CreateLikeTableTask.java +++ b/com.cubrid.cubridmanager.core/src/com/cubrid/cubridmanager/core/cubrid/table/task/CreateLikeTableTask.java @@ -46,10 +46,14 @@ public class CreateLikeTableTask extends JDBCTask { private static final Logger LOGGER = LogUtil.getLogger(CreateLikeTableTask.class); private String newTableName; + private String newOwnerName; private String likeTableName; + private String likeOwnerName; + private DatabaseInfo databaseInfo; public CreateLikeTableTask(DatabaseInfo dbInfo) { super("CreateLikeTable", dbInfo); + databaseInfo = dbInfo; } public void execute() { @@ -61,8 +65,16 @@ public void execute() { errorMsg = Messages.error_getConnection; return; } - String sql = "CREATE TABLE " + QuerySyntax.escapeKeyword(newTableName) + " LIKE " - + QuerySyntax.escapeKeyword(likeTableName); + + String sql; + if (isSupportUserSchema()) { + sql = "CREATE TABLE " + QuerySyntax.escapeKeyword(newOwnerName) + "." + QuerySyntax.escapeKeyword(newTableName) + " LIKE " + + QuerySyntax.escapeKeyword(likeOwnerName) + "." + QuerySyntax.escapeKeyword(likeTableName); + } else { + sql = "CREATE TABLE " + QuerySyntax.escapeKeyword(newTableName) + " LIKE " + + QuerySyntax.escapeKeyword(likeTableName); + } + stmt = connection.createStatement(); stmt.execute(sql); connection.commit(); @@ -83,6 +95,10 @@ public void setTableName(String tableName) { newTableName = tableName; } + public void setOwnerName(String ownerName) { + newOwnerName = ownerName; + } + /** * Set like table name * @@ -91,4 +107,15 @@ public void setTableName(String tableName) { public void setLikeTableName(String tableName) { likeTableName = tableName; } + + public void setLikeOwnerName(String ownerName) { + likeOwnerName = ownerName; + } + + private boolean isSupportUserSchema() { + if (databaseInfo != null) { + return databaseInfo.isSupportUserSchema(); + } + return false; + } } diff --git a/com.cubrid.cubridmanager.core/src/com/cubrid/cubridmanager/core/cubrid/table/task/GetAllSchemaTask.java b/com.cubrid.cubridmanager.core/src/com/cubrid/cubridmanager/core/cubrid/table/task/GetAllSchemaTask.java index e199a58e..25a1b6be 100644 --- a/com.cubrid.cubridmanager.core/src/com/cubrid/cubridmanager/core/cubrid/table/task/GetAllSchemaTask.java +++ b/com.cubrid.cubridmanager.core/src/com/cubrid/cubridmanager/core/cubrid/table/task/GetAllSchemaTask.java @@ -37,6 +37,7 @@ import java.util.Comparator; import java.util.HashMap; import java.util.List; +import java.util.Locale; import java.util.Map; import java.util.Map.Entry; @@ -611,11 +612,17 @@ private Map> getForeignKeyInfo() throws SQLException Map fkInfo = new HashMap(); fkInfo.put("PKTABLE_CAT", metaRs.getString("PKTABLE_CAT")); fkInfo.put("PKTABLE_SCHEM", metaRs.getString("PKTABLE_SCHEM")); - fkInfo.put("PKTABLE_NAME", metaRs.getString("PKTABLE_NAME")); + String pkTableName = metaRs.getString("PKTABLE_NAME");; + String fkTableName = metaRs.getString("FKTABLE_NAME"); + if (databaseInfo.isSupportUserSchema()) { + pkTableName = schemaNameToUpperCase(pkTableName); + fkTableName = schemaNameToUpperCase(fkTableName); + } + fkInfo.put("PKTABLE_NAME", pkTableName); fkInfo.put("PKCOLUMN_NAME", metaRs.getString("PKCOLUMN_NAME")); fkInfo.put("FKTABLE_CAT", metaRs.getString("FKTABLE_CAT")); fkInfo.put("FKTABLE_SCHEM", metaRs.getString("FKTABLE_SCHEM")); - fkInfo.put("FKTABLE_NAME", metaRs.getString("FKTABLE_NAME")); + fkInfo.put("FKTABLE_NAME", fkTableName); fkInfo.put("FKCOLUMN_NAME", fkColName); fkInfo.put("KEY_SEQ", metaRs.getString("KEY_SEQ")); fkInfo.put("UPDATE_RULE", FOREIGN_KEY_ACTION_MAP.get(metaRs.getInt("UPDATE_RULE"))); @@ -1079,4 +1086,13 @@ private boolean isSupportUserSchema() { return databaseInfo.isSupportUserSchema(); } + private String schemaNameToUpperCase(String uniqueName) { + int dotIdx = uniqueName.indexOf("."); + if (dotIdx > 0) { + uniqueName = uniqueName.substring(0, dotIdx).toUpperCase(Locale.getDefault()) + + uniqueName.substring(dotIdx); + } + return uniqueName; + } + } diff --git a/com.cubrid.cubridmanager.core/src/com/cubrid/cubridmanager/core/cubrid/table/task/GetSchemaTask.java b/com.cubrid.cubridmanager.core/src/com/cubrid/cubridmanager/core/cubrid/table/task/GetSchemaTask.java index 64ac4c6a..f5c7bb9b 100644 --- a/com.cubrid.cubridmanager.core/src/com/cubrid/cubridmanager/core/cubrid/table/task/GetSchemaTask.java +++ b/com.cubrid.cubridmanager.core/src/com/cubrid/cubridmanager/core/cubrid/table/task/GetSchemaTask.java @@ -449,22 +449,17 @@ private Map> getForeignKeyInfo() throws SQLException Map fkInfo = new HashMap(); fkInfo.put("PKTABLE_CAT", rs.getString("PKTABLE_CAT")); fkInfo.put("PKTABLE_SCHEM", rs.getString("PKTABLE_SCHEM")); - String pkTableName; + String pkTableName = rs.getString("PKTABLE_NAME");; + String fkTableName = rs.getString("FKTABLE_NAME"); if (databaseInfo.isSupportUserSchema()) { - pkTableName = rs.getString("PKTABLE_NAME"); - int dotIdx = pkTableName.indexOf("."); - if (dotIdx > 0) { - pkTableName = pkTableName.substring(0, dotIdx).toUpperCase(Locale.getDefault()) - + pkTableName.substring(dotIdx); - } - } else { - pkTableName = rs.getString("PKTABLE_NAME"); + pkTableName = schemaNameToUpperCase(pkTableName); + fkTableName = schemaNameToUpperCase(fkTableName); } fkInfo.put("PKTABLE_NAME", pkTableName); fkInfo.put("PKCOLUMN_NAME", rs.getString("PKCOLUMN_NAME")); fkInfo.put("FKTABLE_CAT", rs.getString("FKTABLE_CAT")); fkInfo.put("FKTABLE_SCHEM", rs.getString("FKTABLE_SCHEM")); - fkInfo.put("FKTABLE_NAME", rs.getString("FKTABLE_NAME")); + fkInfo.put("FKTABLE_NAME", fkTableName); String fkColName = rs.getString("FKCOLUMN_NAME"); fkInfo.put("FKCOLUMN_NAME", fkColName); fkInfo.put("KEY_SEQ", rs.getString("KEY_SEQ")); @@ -1044,6 +1039,15 @@ public void setNeedCollationInfo(boolean isNeedCollationInfo) { this.isNeedCollationInfo = isNeedCollationInfo; } + private String schemaNameToUpperCase(String uniqueName) { + int dotIdx = uniqueName.indexOf("."); + if (dotIdx > 0) { + uniqueName = uniqueName.substring(0, dotIdx).toUpperCase(Locale.getDefault()) + + uniqueName.substring(dotIdx); + } + return uniqueName; + } + } class SubAttribute{ @@ -1071,5 +1075,4 @@ public String getsubDataType() { return subDataType; } - } diff --git a/com.cubrid.cubridmanager.core/src/com/cubrid/cubridmanager/core/cubrid/table/task/GetTablesTask.java b/com.cubrid.cubridmanager.core/src/com/cubrid/cubridmanager/core/cubrid/table/task/GetTablesTask.java index c54377f8..bd43b9f9 100644 --- a/com.cubrid.cubridmanager.core/src/com/cubrid/cubridmanager/core/cubrid/table/task/GetTablesTask.java +++ b/com.cubrid.cubridmanager.core/src/com/cubrid/cubridmanager/core/cubrid/table/task/GetTablesTask.java @@ -99,8 +99,14 @@ public List getSystemTables() { * @return List */ public List getUserTables() { - String sql = "SELECT class_name FROM db_class WHERE is_system_class='NO'" + String sql; + if(databaseInfo.isSupportUserSchema()) { + sql = "SELECT owner_name, class_name FROM db_class WHERE is_system_class='NO'" + " AND class_type='CLASS' ORDER BY class_name ASC"; + } else { + sql = "SELECT class_name FROM db_class WHERE is_system_class='NO'" + + " AND class_type='CLASS' ORDER BY class_name ASC"; + } // [TOOLS-2425]Support shard broker sql = databaseInfo.wrapShardQuery(sql); diff --git a/com.cubrid.cubridmanager.core/src/com/cubrid/cubridmanager/core/cubrid/trigger/model/TriggerDDL.java b/com.cubrid.cubridmanager.core/src/com/cubrid/cubridmanager/core/cubrid/trigger/model/TriggerDDL.java index 33e719c2..206acbe1 100644 --- a/com.cubrid.cubridmanager.core/src/com/cubrid/cubridmanager/core/cubrid/trigger/model/TriggerDDL.java +++ b/com.cubrid.cubridmanager.core/src/com/cubrid/cubridmanager/core/cubrid/trigger/model/TriggerDDL.java @@ -32,7 +32,6 @@ import com.cubrid.common.core.common.model.Trigger; import com.cubrid.common.core.util.QuerySyntax; import com.cubrid.common.core.util.StringUtil; -import com.cubrid.cubridmanager.core.cubrid.database.model.DatabaseInfo; /** * @@ -226,7 +225,11 @@ private static void appendHead(Trigger trigger, StringBuffer bf, boolean isSuppo bf.append(QuerySyntax.escapeKeyword(triggerName)); } } else { - bf.append(QuerySyntax.escapeKeyword(ownerName) + "." + QuerySyntax.escapeKeyword(triggerName)); + if (isSupportUserSchema) { + bf.append(QuerySyntax.escapeKeyword(ownerName) + "." + QuerySyntax.escapeKeyword(triggerName)); + } else { + bf.append(QuerySyntax.escapeKeyword(triggerName)); + } } } bf.append(newLine); @@ -239,7 +242,7 @@ private static void appendHead(Trigger trigger, StringBuffer bf, boolean isSuppo * @param newTrigger Trigger * @return String */ - public static String getAlterDDL(Trigger oldTrigger, Trigger newTrigger) { + public static String getAlterDDL(Trigger oldTrigger, Trigger newTrigger, boolean isSupportUserSchema) { String triggerName = oldTrigger.getName(); String ownerName = oldTrigger.getOwner(); String oldPriority = oldTrigger.getPriority(); @@ -258,7 +261,11 @@ public static String getAlterDDL(Trigger oldTrigger, Trigger newTrigger) { if (ownerName == null || ownerName.isEmpty()) { bf.append(QuerySyntax.escapeKeyword(triggerName)); } else { - bf.append(QuerySyntax.escapeKeyword(ownerName) + "." + QuerySyntax.escapeKeyword(triggerName)); + if (isSupportUserSchema) { + bf.append(QuerySyntax.escapeKeyword(ownerName) + "." + QuerySyntax.escapeKeyword(triggerName)); + } else { + bf.append(QuerySyntax.escapeKeyword(triggerName)); + } } bf.append(" STATUS ").append(newStatus); bf.append(endLineChar); @@ -274,7 +281,11 @@ public static String getAlterDDL(Trigger oldTrigger, Trigger newTrigger) { if (ownerName == null || ownerName.isEmpty()) { bf.append(QuerySyntax.escapeKeyword(triggerName)); } else { - bf.append(QuerySyntax.escapeKeyword(ownerName) + "." + QuerySyntax.escapeKeyword(triggerName)); + if (isSupportUserSchema) { + bf.append(QuerySyntax.escapeKeyword(ownerName) + "." + QuerySyntax.escapeKeyword(triggerName)); + } else { + bf.append(QuerySyntax.escapeKeyword(triggerName)); + } } bf.append(" PRIORITY ").append(newPriority); bf.append(endLineChar); @@ -291,7 +302,11 @@ public static String getAlterDDL(Trigger oldTrigger, Trigger newTrigger) { if (ownerName == null || ownerName.isEmpty()) { bf.append(QuerySyntax.escapeKeyword(triggerName)); } else { - bf.append(QuerySyntax.escapeKeyword(ownerName) + "." + QuerySyntax.escapeKeyword(triggerName)); + if (isSupportUserSchema) { + bf.append(QuerySyntax.escapeKeyword(ownerName) + "." + QuerySyntax.escapeKeyword(triggerName)); + } else { + bf.append(QuerySyntax.escapeKeyword(triggerName)); + } } newDescription = String.format("'%s'", newDescription); bf.append(String.format(" COMMENT %s", StringUtil.escapeQuotes(newDescription))); diff --git a/com.cubrid.cubridmanager.core/src/com/cubrid/cubridmanager/core/cubrid/trigger/task/JDBCGetTriggerInfoTask.java b/com.cubrid.cubridmanager.core/src/com/cubrid/cubridmanager/core/cubrid/trigger/task/JDBCGetTriggerInfoTask.java index 94c35fcf..4a7ee73a 100644 --- a/com.cubrid.cubridmanager.core/src/com/cubrid/cubridmanager/core/cubrid/trigger/task/JDBCGetTriggerInfoTask.java +++ b/com.cubrid.cubridmanager.core/src/com/cubrid/cubridmanager/core/cubrid/trigger/task/JDBCGetTriggerInfoTask.java @@ -29,6 +29,7 @@ import java.sql.PreparedStatement; import java.sql.SQLException; +import java.util.Locale; import org.slf4j.Logger; @@ -76,7 +77,7 @@ public Trigger getTriggerInfo(String triggerName) { String sql; if (databaseInfo.isSupportUserSchema()) { - sql = "SELECT t.*, c.target_class_name, t.owner.name as trigger_owner" + sql = "SELECT t.*, c.target_class_name, c.target_owner_name, t.owner.name as trigger_owner" + " FROM db_trigger t, db_trig c" + " WHERE t.name=c.trigger_name" + " AND t.owner.name=c.owner_name" @@ -103,7 +104,11 @@ public Trigger getTriggerInfo(String triggerName) { trigger.setOwner(rs.getString("trigger_owner")); trigger.setConditionTime(JDBCGetTriggerListTask.getConditionTime(rs.getInt("condition_time"))); trigger.setEventType(JDBCGetTriggerListTask.getEventType(rs.getInt("event"))); - trigger.setTarget_class(rs.getString("target_class_name")); + if (databaseInfo.isSupportUserSchema()) { + trigger.setTarget_class(rs.getString("target_owner_name").toLowerCase(Locale.getDefault()) + "." + rs.getString("target_class_name")); + } else { + trigger.setTarget_class(rs.getString("target_class_name")); + } trigger.setTarget_att(rs.getString("target_attribute")); trigger.setCondition(rs.getString("condition")); trigger.setActionTime(JDBCGetTriggerListTask.getActionTime(rs.getInt("action_time"))); diff --git a/com.cubrid.cubridmanager.core/src/com/cubrid/cubridmanager/core/cubrid/trigger/task/JDBCGetTriggerListTask.java b/com.cubrid.cubridmanager.core/src/com/cubrid/cubridmanager/core/cubrid/trigger/task/JDBCGetTriggerListTask.java index 6b95569b..4af99c3c 100644 --- a/com.cubrid.cubridmanager.core/src/com/cubrid/cubridmanager/core/cubrid/trigger/task/JDBCGetTriggerListTask.java +++ b/com.cubrid.cubridmanager.core/src/com/cubrid/cubridmanager/core/cubrid/trigger/task/JDBCGetTriggerListTask.java @@ -95,10 +95,12 @@ public void execute() { rs = stmt.executeQuery(sql); while (rs.next()) { Trigger trigger = new Trigger(); - trigger.setName(rs.getString("name")); if (databaseInfo.isSupportUserSchema()) { + trigger.setName(rs.getString("unique_name")); //Data is LowerCase from CMS trigger.setOwner(rs.getString("owner_name").toLowerCase(Locale.getDefault())); + } else { + trigger.setName(rs.getString("name")); } trigger.setConditionTime(getConditionTime(rs.getInt("condition_time"))); trigger.setEventType(getEventType(rs.getInt("event"))); diff --git a/com.cubrid.cubridmanager.core/src/com/cubrid/cubridmanager/core/utils/SchemaUtil.java b/com.cubrid.cubridmanager.core/src/com/cubrid/cubridmanager/core/utils/SchemaUtil.java index 88ba2a72..28109032 100644 --- a/com.cubrid.cubridmanager.core/src/com/cubrid/cubridmanager/core/utils/SchemaUtil.java +++ b/com.cubrid.cubridmanager.core/src/com/cubrid/cubridmanager/core/utils/SchemaUtil.java @@ -115,4 +115,20 @@ public static List getTableColumn(DatabaseInfo databaseInfo, return columns; } + + public static String getOwnerNameForUserSchema(String uniqueName) { + int idx = uniqueName.indexOf("."); + if (idx > 0) { + return uniqueName.substring(0, idx); + } + return ""; + } + + public static String getClassNameForUserSchema(String uniqueName) { + int idx = uniqueName.indexOf("."); + if (idx > 0) { + return uniqueName.substring(idx + 1); + } + return ""; + } } diff --git a/com.cubrid.cubridmanager.ui/src/com/cubrid/cubridmanager/ui/common/navigator/CMNavigatorViewSorter.java b/com.cubrid.cubridmanager.ui/src/com/cubrid/cubridmanager/ui/common/navigator/CMNavigatorViewSorter.java index ba87ad0e..22960e7b 100644 --- a/com.cubrid.cubridmanager.ui/src/com/cubrid/cubridmanager/ui/common/navigator/CMNavigatorViewSorter.java +++ b/com.cubrid.cubridmanager.ui/src/com/cubrid/cubridmanager/ui/common/navigator/CMNavigatorViewSorter.java @@ -62,6 +62,7 @@ protected int category(ICubridNode node) { || NodeType.VIEW_FOLDER.equals(type) || NodeType.SERIAL_FOLDER.equals(type) || NodeType.TRIGGER_FOLDER.equals(type) + || NodeType.SYNONYM_FOLDER.equals(type) || NodeType.STORED_PROCEDURE_FOLDER.equals(type) || CubridNodeType.USER_FOLDER.equals(type) || CubridNodeType.JOB_FOLDER.equals(type) diff --git a/com.cubrid.cubridmanager.ui/src/com/cubrid/cubridmanager/ui/spi/Messages.java b/com.cubrid.cubridmanager.ui/src/com/cubrid/cubridmanager/ui/spi/Messages.java index 7534d5b8..7ea486d1 100644 --- a/com.cubrid.cubridmanager.ui/src/com/cubrid/cubridmanager/ui/spi/Messages.java +++ b/com.cubrid.cubridmanager.ui/src/com/cubrid/cubridmanager/ui/spi/Messages.java @@ -67,6 +67,7 @@ public class Messages extends NLS { public static String msgSystemViewFolderName; public static String msgSpFolderName; public static String msgTriggerFolderName; + public static String msgSynonymFolderName; public static String msgSerialFolderName; public static String msgGenerialVolumeFolderName; public static String msgDataVolumeFolderName; diff --git a/com.cubrid.cubridmanager.ui/src/com/cubrid/cubridmanager/ui/spi/Messages.properties b/com.cubrid.cubridmanager.ui/src/com/cubrid/cubridmanager/ui/spi/Messages.properties index e469430d..a96df90d 100644 --- a/com.cubrid.cubridmanager.ui/src/com/cubrid/cubridmanager/ui/spi/Messages.properties +++ b/com.cubrid.cubridmanager.ui/src/com/cubrid/cubridmanager/ui/spi/Messages.properties @@ -12,6 +12,7 @@ msgSystemTableFolderName=System tables msgSystemViewFolderName=System views msgSpFolderName=Stored procedure msgTriggerFolderName=Triggers +msgSynonymFolderName=Synonyms msgSerialFolderName=Serials msgGenerialVolumeFolderName=Generic msgDataVolumeFolderName=Data diff --git a/com.cubrid.cubridmanager.ui/src/com/cubrid/cubridmanager/ui/spi/Messages_ko_KR.properties b/com.cubrid.cubridmanager.ui/src/com/cubrid/cubridmanager/ui/spi/Messages_ko_KR.properties index 5f635592..f8e4a09a 100644 --- a/com.cubrid.cubridmanager.ui/src/com/cubrid/cubridmanager/ui/spi/Messages_ko_KR.properties +++ b/com.cubrid.cubridmanager.ui/src/com/cubrid/cubridmanager/ui/spi/Messages_ko_KR.properties @@ -12,6 +12,7 @@ msgSystemTableFolderName=\uC2DC\uC2A4\uD15C \uD14C\uC774\uBE14 msgSystemViewFolderName=\uC2DC\uC2A4\uD15C \uBDF0 msgSpFolderName=\uC800\uC7A5 \uD504\uB85C\uC2DC\uC800 msgTriggerFolderName=\uD2B8\uB9AC\uAC70 +msgSynonymFolderName=\ub3d9\uc758\uc5b4 msgSerialFolderName=\uC2DC\uB9AC\uC5BC msgGenerialVolumeFolderName=\uC77C\uBC18 \uBCFC\uB968 msgDataVolumeFolderName=\uB370\uC774\uD130 \uBCFC\uB968 diff --git a/com.cubrid.cubridmanager.ui/src/com/cubrid/cubridmanager/ui/spi/contribution/CubridWorkbenchContrItem.java b/com.cubrid.cubridmanager.ui/src/com/cubrid/cubridmanager/ui/spi/contribution/CubridWorkbenchContrItem.java index 66ed76d3..48dbe474 100644 --- a/com.cubrid.cubridmanager.ui/src/com/cubrid/cubridmanager/ui/spi/contribution/CubridWorkbenchContrItem.java +++ b/com.cubrid.cubridmanager.ui/src/com/cubrid/cubridmanager/ui/spi/contribution/CubridWorkbenchContrItem.java @@ -280,6 +280,7 @@ public void processDoubleClickNavigatorEvent(DoubleClickEvent event) { NodeType.TABLE_FOLDER, NodeType.VIEW_FOLDER, NodeType.TRIGGER_FOLDER, + NodeType.SYNONYM_FOLDER, NodeType.SERIAL_FOLDER, NodeType.USER_FOLDER, CubridNodeType.JOB_FOLDER }); @@ -316,6 +317,8 @@ public void processDoubleClickNavigatorEvent(DoubleClickEvent event) { openViewsDetailInfoPart(database); } else if (StringUtil.isEqual(cubridNode.getType(), NodeType.TRIGGER_FOLDER)) { openTriggersDetailInfoPart(database); + } else if (StringUtil.isEqual(cubridNode.getType(), NodeType.SYNONYM_FOLDER)) { + openSynonymsDetailInfoPart(database); } else if (StringUtil.isEqual(cubridNode.getType(), NodeType.SERIAL_FOLDER)) { openSerialsDetailInfoPart(database); } else if (StringUtil.isEqual(cubridNode.getType(), CubridNodeType.JOB_FOLDER)) { @@ -393,6 +396,16 @@ public void openTriggersDetailInfoPart(CubridDatabase database) { action.openTriggersDetailInfoEditor(database); } + /** + * openTriggersDetailInfoPart + * + * @param CubridDatabase database + */ + public void openSynonymsDetailInfoPart(CubridDatabase database) { + OpenTargetAction action = new OpenTargetAction(); + action.openSynonymsDetailInfoEditor(database); + } + /** * openJobDetailInfoPart * diff --git a/com.cubrid.cubridmanager.ui/src/com/cubrid/cubridmanager/ui/spi/model/CubridNodeTypeManager.java b/com.cubrid.cubridmanager.ui/src/com/cubrid/cubridmanager/ui/spi/model/CubridNodeTypeManager.java index 8b204094..5e0e7443 100644 --- a/com.cubrid.cubridmanager.ui/src/com/cubrid/cubridmanager/ui/spi/model/CubridNodeTypeManager.java +++ b/com.cubrid.cubridmanager.ui/src/com/cubrid/cubridmanager/ui/spi/model/CubridNodeTypeManager.java @@ -61,7 +61,9 @@ private CubridNodeTypeManager() { CubridNodeType.STORED_PROCEDURE_FOLDER, CubridNodeType.STORED_PROCEDURE_FUNCTION_FOLDER, CubridNodeType.STORED_PROCEDURE_PROCEDURE_FOLDER, - CubridNodeType.TRIGGER_FOLDER, CubridNodeType.SERIAL_FOLDER, + CubridNodeType.TRIGGER_FOLDER, + CubridNodeType.SYNONYM_FOLDER, + CubridNodeType.SERIAL_FOLDER, CubridNodeType.BROKER_FOLDER, CubridNodeType.BROKER, CubridNodeType.SHARD_FOLDER, CubridNodeType.SHARD, CubridNodeType.SHARD_SQL_LOG, CubridNodeType.SHARD_SQL_LOG_FOLDER, diff --git a/com.cubrid.cubridmanager.ui/src/com/cubrid/cubridmanager/ui/spi/model/loader/CQBDbConnectionLoader.java b/com.cubrid.cubridmanager.ui/src/com/cubrid/cubridmanager/ui/spi/model/loader/CQBDbConnectionLoader.java index ab220b62..2cfb8c5e 100644 --- a/com.cubrid.cubridmanager.ui/src/com/cubrid/cubridmanager/ui/spi/model/loader/CQBDbConnectionLoader.java +++ b/com.cubrid.cubridmanager.ui/src/com/cubrid/cubridmanager/ui/spi/model/loader/CQBDbConnectionLoader.java @@ -40,6 +40,7 @@ import com.cubrid.common.ui.spi.model.ICubridNodeLoader; import com.cubrid.common.ui.spi.model.NodeType; import com.cubrid.common.ui.spi.model.loader.CubridSerialFolderLoader; +import com.cubrid.common.ui.spi.model.loader.CubridSynonymFolderLoader; import com.cubrid.common.ui.spi.model.loader.CubridTriggerFolderLoader; import com.cubrid.common.ui.spi.model.loader.schema.CubridTablesFolderLoader; import com.cubrid.common.ui.spi.model.loader.schema.CubridViewsFolderLoader; @@ -62,6 +63,7 @@ public class CQBDbConnectionLoader extends private static final String VIEWS_FOLDER_NAME = Messages.msgViewsFolderName; private static final String SP_FOLDER_NAME = Messages.msgSpFolderName; private static final String TRIGGER_FOLDER_NAME = Messages.msgTriggerFolderName; + private static final String SYNONYM_FOLDER_NAME = Messages.msgSynonymFolderName; private static final String SERIAL_FOLDER_NAME = Messages.msgSerialFolderName; private static final String USERS_FOLDER_NAME = Messages.msgUserFolderName; @@ -69,6 +71,7 @@ public class CQBDbConnectionLoader extends public static final String VIEWS_FOLDER_ID = "Views"; public static final String SP_FOLDER_ID = "Stored procedure"; public static final String TRIGGER_FOLDER_ID = "Triggers"; + public static final String SYNONYM_FOLDER_ID = "Synonym"; public static final String SERIAL_FOLDER_ID = "Serials"; /** @@ -103,6 +106,10 @@ public void load(final ICubridNode parent, final IProgressMonitor monitor) { addUserFolder(monitor, database); // add triggers folder addTriggerFolder(monitor, database); + // add synonyms folder + if (database.getDatabaseInfo().isSupportSynonym()) { + addSynonymFolder(monitor, database); + } // add stored procedure folder addProcedureFolder(monitor, database); @@ -210,6 +217,41 @@ private void addTriggerFolder(final IProgressMonitor monitor, } } + /** + * Add synonym folder + * + * @param monitor the IProgressMonitor + * @param database the CubridDatabase + */ + private void addSynonymFolder(final IProgressMonitor monitor, + CubridDatabase database) { + if (!database.getDatabaseInfo().getAuthLoginedDbUserInfo().isDbaAuthority()) { + return; + } + String synoymFolderId = database.getId() + NODE_SEPARATOR + + SYNONYM_FOLDER_ID; + ICubridNode synonymFolder = database.getChild(synoymFolderId); + if (synonymFolder == null) { + synonymFolder = new DefaultSchemaNode(synoymFolderId, + SYNONYM_FOLDER_NAME, SYNONYM_FOLDER_NAME, "icons/navigator/synonym_group.png"); + synonymFolder.setType(NodeType.SYNONYM_FOLDER); + synonymFolder.setContainer(true); + ICubridNodeLoader loader = new CubridSynonymFolderLoader(); + loader.setLevel(getLevel()); + synonymFolder.setLoader(loader); + database.addChild(synonymFolder); + if (getLevel() == DEFINITE_LEVEL) { + synonymFolder.getChildren(monitor); + } + } else { + if (synonymFolder.getLoader() != null + && synonymFolder.getLoader().isLoaded()) { + synonymFolder.getLoader().setLoaded(false); + synonymFolder.getChildren(monitor); + } + } + } + /** * Add view folder * diff --git a/com.cubrid.cubridmanager.ui/src/com/cubrid/cubridmanager/ui/spi/model/loader/CubridDatabaseLoader.java b/com.cubrid.cubridmanager.ui/src/com/cubrid/cubridmanager/ui/spi/model/loader/CubridDatabaseLoader.java index 33882972..f21d42ad 100644 --- a/com.cubrid.cubridmanager.ui/src/com/cubrid/cubridmanager/ui/spi/model/loader/CubridDatabaseLoader.java +++ b/com.cubrid.cubridmanager.ui/src/com/cubrid/cubridmanager/ui/spi/model/loader/CubridDatabaseLoader.java @@ -47,6 +47,7 @@ import com.cubrid.common.ui.spi.model.ICubridNodeLoader; import com.cubrid.common.ui.spi.model.NodeType; import com.cubrid.common.ui.spi.model.loader.CubridSerialFolderLoader; +import com.cubrid.common.ui.spi.model.loader.CubridSynonymFolderLoader; import com.cubrid.common.ui.spi.model.loader.CubridTriggerFolderLoader; import com.cubrid.common.ui.spi.model.loader.schema.CubridTablesFolderLoader; import com.cubrid.common.ui.spi.model.loader.schema.CubridViewsFolderLoader; @@ -97,6 +98,7 @@ public class CubridDatabaseLoader extends private static final String VIEWS_FOLDER_NAME = Messages.msgViewsFolderName; private static final String SP_FOLDER_NAME = Messages.msgSpFolderName; private static final String TRIGGER_FOLDER_NAME = Messages.msgTriggerFolderName; + private static final String SYNONYM_FOLDER_NAME = Messages.msgSynonymFolderName; private static final String SERIAL_FOLDER_NAME = Messages.msgSerialFolderName; public static final String JOB_AUTO_FOLDER_ID = "Job automation"; @@ -193,6 +195,10 @@ public void run() { addUserFolder(monitor, database); // add triggers folder addTriggerFolder(monitor, database); + // add synonyms folder + if (database.getDatabaseInfo().isSupportSynonym()) { + addSynonymFolder(monitor, database); + } // add stored procedure folder addProcedureFolder(monitor, database); // add job automation folder @@ -371,6 +377,38 @@ private void addTriggerFolder(final IProgressMonitor monitor, } } + /** + * Add Synonym folder + * + * @param monitor the IProgressMonitor + * @param database the CubridDatabase + */ + private void addSynonymFolder(final IProgressMonitor monitor, + CubridDatabase database) { + String synonymFolderId = database.getId() + NODE_SEPARATOR + + CubridSynonymFolderLoader.SYNONYM_FOLDER_ID; + ICubridNode synonymFolder = database.getChild(synonymFolderId); + if (synonymFolder == null) { + synonymFolder = new DefaultSchemaNode(synonymFolderId, + SYNONYM_FOLDER_NAME, "icons/navigator/synonym_group.png"); + synonymFolder.setType(NodeType.SYNONYM_FOLDER); + synonymFolder.setContainer(true); + ICubridNodeLoader loader = new CubridSynonymFolderLoader(); + loader.setLevel(getLevel()); + synonymFolder.setLoader(loader); + database.addChild(synonymFolder); + if (getLevel() == DEFINITE_LEVEL) { + synonymFolder.getChildren(monitor); + } + } else { + if (synonymFolder.getLoader() != null + && synonymFolder.getLoader().isLoaded()) { + synonymFolder.getLoader().setLoaded(false); + synonymFolder.getChildren(monitor); + } + } + } + /** * Add view folder * diff --git a/com.cubrid.cubridmanager.ui/version.properties b/com.cubrid.cubridmanager.ui/version.properties index 09847786..16c925d1 100644 --- a/com.cubrid.cubridmanager.ui/version.properties +++ b/com.cubrid.cubridmanager.ui/version.properties @@ -1,4 +1,4 @@ productName=CUBRID Admin -releaseStr=11.1.0 -releaseVersion=11.1.0 -buildVersionId=11.1.0.0001 +releaseStr=11.1.1 +releaseVersion=11.1.1 +buildVersionId=11.1.1.0002 diff --git a/com.cubrid.cubridquery.ui/src/com/cubrid/cubridquery/ui/common/navigator/CQBNavigatorViewSorter.java b/com.cubrid.cubridquery.ui/src/com/cubrid/cubridquery/ui/common/navigator/CQBNavigatorViewSorter.java index c6d04039..92bedd7e 100644 --- a/com.cubrid.cubridquery.ui/src/com/cubrid/cubridquery/ui/common/navigator/CQBNavigatorViewSorter.java +++ b/com.cubrid.cubridquery.ui/src/com/cubrid/cubridquery/ui/common/navigator/CQBNavigatorViewSorter.java @@ -47,6 +47,7 @@ protected int category(ICubridNode node) { || NodeType.VIEW_FOLDER.equals(type) || NodeType.SERIAL_FOLDER.equals(type) || NodeType.TRIGGER_FOLDER.equals(type) + || NodeType.SYNONYM_FOLDER.equals(type) || NodeType.STORED_PROCEDURE_FOLDER.equals(type)) { return 1; } diff --git a/com.cubrid.cubridquery.ui/src/com/cubrid/cubridquery/ui/connection/dialog/QueryConnDialog.java b/com.cubrid.cubridquery.ui/src/com/cubrid/cubridquery/ui/connection/dialog/QueryConnDialog.java index bfb038bb..b4f08bd3 100644 --- a/com.cubrid.cubridquery.ui/src/com/cubrid/cubridquery/ui/connection/dialog/QueryConnDialog.java +++ b/com.cubrid.cubridquery.ui/src/com/cubrid/cubridquery/ui/connection/dialog/QueryConnDialog.java @@ -42,6 +42,7 @@ import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Text; +import com.cubrid.common.core.util.CompatibleUtil; import com.cubrid.common.ui.common.control.ConnectionComposite; import com.cubrid.common.ui.common.control.SelectColorCombo; import com.cubrid.common.ui.common.persist.ConnectionInfo; @@ -350,6 +351,7 @@ protected void buttonPressed(int buttonId) { userInfo.setName(userName); userInfo.setNoEncryptPassword(password); dbInfo.setAuthLoginedDbUserInfo(userInfo); + dbInfo.setSupportUserSchema(CompatibleUtil.isAfter112(dbInfo)); if (buttonId == TEST_CONNECT_ID || buttonId == CONNECT_ID) { TaskExecutor taskExcutor = new ConnectDatabaseExecutor(dbInfo); diff --git a/com.cubrid.cubridquery.ui/src/com/cubrid/cubridquery/ui/spi/CubridNodeTypeManager.java b/com.cubrid.cubridquery.ui/src/com/cubrid/cubridquery/ui/spi/CubridNodeTypeManager.java index 89757fa3..7f34ebe8 100644 --- a/com.cubrid.cubridquery.ui/src/com/cubrid/cubridquery/ui/spi/CubridNodeTypeManager.java +++ b/com.cubrid.cubridquery.ui/src/com/cubrid/cubridquery/ui/spi/CubridNodeTypeManager.java @@ -52,7 +52,9 @@ private CubridNodeTypeManager() { NodeType.STORED_PROCEDURE_FOLDER, NodeType.STORED_PROCEDURE_FUNCTION_FOLDER, NodeType.STORED_PROCEDURE_PROCEDURE_FOLDER, - NodeType.TRIGGER_FOLDER, NodeType.SERIAL_FOLDER, + NodeType.TRIGGER_FOLDER, + NodeType.SYNONYM_FOLDER, + NodeType.SERIAL_FOLDER, NodeType.USER_FOLDER}; /** diff --git a/com.cubrid.cubridquery.ui/src/com/cubrid/cubridquery/ui/spi/contribution/CubridWorkbenchContrItem.java b/com.cubrid.cubridquery.ui/src/com/cubrid/cubridquery/ui/spi/contribution/CubridWorkbenchContrItem.java index 92d2362f..8d2f7eb4 100644 --- a/com.cubrid.cubridquery.ui/src/com/cubrid/cubridquery/ui/spi/contribution/CubridWorkbenchContrItem.java +++ b/com.cubrid.cubridquery.ui/src/com/cubrid/cubridquery/ui/spi/contribution/CubridWorkbenchContrItem.java @@ -41,6 +41,7 @@ import org.eclipse.ui.PlatformUI; import org.slf4j.Logger; +import com.cubrid.common.core.util.CompatibleUtil; import com.cubrid.common.core.util.LogUtil; import com.cubrid.common.core.util.StringUtil; import com.cubrid.common.ui.common.Messages; @@ -146,6 +147,7 @@ && connectDatabase(database.getDatabaseInfo())) { || cubridNode.getType() == NodeType.TABLE_FOLDER || cubridNode.getType() == NodeType.VIEW_FOLDER || cubridNode.getType() == NodeType.TRIGGER_FOLDER + || cubridNode.getType() == NodeType.SYNONYM_FOLDER || cubridNode.getType() == NodeType.SERIAL_FOLDER || cubridNode.getType() == NodeType.USER_FOLDER) { @@ -185,6 +187,11 @@ && connectDatabase(database.getDatabaseInfo())) { treeViewer.expandToLevel(cubridNode, 1); } openTriggersDetailInfoPart(database); + } else if (cubridNode.getType() == NodeType.SYNONYM_FOLDER) { + if (!treeViewer.getExpandedState(cubridNode)) { + treeViewer.expandToLevel(cubridNode, 1); + } + openSynonymsDetailInfoPart(database); } else if (cubridNode.getType() == NodeType.SERIAL_FOLDER) { //if not expand ,expand the node //if not open child node ,edit trigger from dashboard can not open edit dialog @@ -262,6 +269,15 @@ public void openTriggersDetailInfoPart(CubridDatabase database) { action.openTriggersDetailInfoEditor(database); } + /** + * openSynonymsDetailInfoPart + * @param CubridDatabase database + */ + public void openSynonymsDetailInfoPart(CubridDatabase database) { + OpenTargetAction action = new OpenTargetAction(); + action.openSynonymsDetailInfoEditor(database); + } + /** * open user InfoPart * @@ -346,6 +362,7 @@ public static boolean connectDatabase(DatabaseInfo dbInfo) { // FIXME extract dbInfo.setRunningType(DbRunningType.CS); dbInfo.getServerInfo().setConnected(true); dbInfo.setLogined(true); + dbInfo.setSupportUserSchema(CompatibleUtil.isAfter112(dbInfo)); return true; } catch (SQLException e) { CommonUITool.openErrorBox(Messages.bind(Messages.errCommonTip, diff --git a/org.cubrid.cubridmanager.plugin.manager/src/org/cubrid/cubridmanager/plugin/manager/ActionAdvisor.java b/org.cubrid.cubridmanager.plugin.manager/src/org/cubrid/cubridmanager/plugin/manager/ActionAdvisor.java index b1dfccc4..7ef873ca 100644 --- a/org.cubrid.cubridmanager.plugin.manager/src/org/cubrid/cubridmanager/plugin/manager/ActionAdvisor.java +++ b/org.cubrid.cubridmanager.plugin.manager/src/org/cubrid/cubridmanager/plugin/manager/ActionAdvisor.java @@ -57,6 +57,7 @@ import com.cubrid.common.ui.cubrid.database.erwin.action.ExportERwinAction; import com.cubrid.common.ui.cubrid.database.erwin.action.ImportERwinAction; import com.cubrid.common.ui.cubrid.serial.action.CreateSerialAction; +import com.cubrid.common.ui.cubrid.synonym.action.NewSynonymAction; import com.cubrid.common.ui.cubrid.table.action.CreateViewAction; import com.cubrid.common.ui.cubrid.table.action.ExportWizardAction; import com.cubrid.common.ui.cubrid.table.action.ImportWizardAction; @@ -274,6 +275,7 @@ public void showToolbar(ICoolBarManager coolBarManager) { schemaActionManager.add(manager.getAction(CreateViewAction.ID)); schemaActionManager.add(manager.getAction(CreateSerialAction.ID)); schemaActionManager.add(manager.getAction(NewTriggerAction.ID)); + schemaActionManager.add(manager.getAction(NewSynonymAction.ID)); ActionContributionItem schemaItems = new ActionContributionItem( schemaDropAction); schemaItems.setMode(ActionContributionItem.MODE_FORCE_TEXT); diff --git a/org.cubrid.cubridquery.plugin.querybrowser/src/org/cubrid/cubridquery/plugin/querybrowser/ActionAdvisor.java b/org.cubrid.cubridquery.plugin.querybrowser/src/org/cubrid/cubridquery/plugin/querybrowser/ActionAdvisor.java index 265a76f8..f8b0a915 100644 --- a/org.cubrid.cubridquery.plugin.querybrowser/src/org/cubrid/cubridquery/plugin/querybrowser/ActionAdvisor.java +++ b/org.cubrid.cubridquery.plugin.querybrowser/src/org/cubrid/cubridquery/plugin/querybrowser/ActionAdvisor.java @@ -64,6 +64,7 @@ import com.cubrid.common.ui.cubrid.procedure.action.AddFunctionAction; import com.cubrid.common.ui.cubrid.procedure.action.AddProcedureAction; import com.cubrid.common.ui.cubrid.serial.action.CreateSerialAction; +import com.cubrid.common.ui.cubrid.synonym.action.NewSynonymAction; import com.cubrid.common.ui.cubrid.table.action.CreateViewAction; import com.cubrid.common.ui.cubrid.table.action.ExportWizardAction; import com.cubrid.common.ui.cubrid.table.action.ImportWizardAction; @@ -282,6 +283,16 @@ private void init() { .getImageDescriptor("icons/toolbar/qb_new_trigger_off.png")); ActionManager.getInstance().registerAction(newTriggerAction); + ProxyAction newSynonymAction = new ProxyAction( + NewSynonymAction.ID, + com.cubrid.common.ui.spi.Messages.newSynonymActionName + .replaceAll("\\.", ""), + Activator + .getImageDescriptor("icons/toolbar/qb_new_trigger_on.png"), + Activator + .getImageDescriptor("icons/toolbar/qb_new_trigger_off.png")); + ActionManager.getInstance().registerAction(newSynonymAction); + ProxyAction importAction = new ProxyAction( ImportWizardAction.ID, com.cubrid.common.ui.spi.Messages.tableImportActionName @@ -462,6 +473,8 @@ public void showMenu(IMenuManager menuManager) { toolsMenu.add(new Separator()); toolsMenu.add(manager.getAction(NewTriggerAction.ID)); toolsMenu.add(new Separator()); + toolsMenu.add(manager.getAction(NewSynonymAction.ID)); + toolsMenu.add(new Separator()); toolsMenu.add(manager.getAction(AddFunctionAction.ID)); toolsMenu.add(manager.getAction(AddProcedureAction.ID)); toolsMenu.add(new Separator());