blob: 268b9444b4770742c61e92590b4ecb3e5eef957e [file] [log] [blame]
dyang4b8476e2005-12-02 09:39:18 +00001/*******************************************************************************
2 * Copyright (c) 2005 Sybase, Inc.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors:
9 * Sybase, Inc. - initial API and implementation
10 *******************************************************************************/
11package org.eclipse.datatools.sqltools.result;
12
dyangf39fb7c2005-12-12 03:22:42 +000013import org.eclipse.datatools.sqltools.result.internal.utils.Images;
dyang4b8476e2005-12-02 09:39:18 +000014import org.eclipse.datatools.sqltools.result.internal.utils.Messages;
dyangf39fb7c2005-12-12 03:22:42 +000015import org.eclipse.swt.graphics.Image;
dyang4b8476e2005-12-02 09:39:18 +000016
17/**
18 * The <code>OperationCommand</code> is used to uniquely identify an execution result in SQL Results View, it is the
19 * starting point to use SQL Results View.
20 * <p>
21 * The consumer needs to initiate an instance of <code>OperationCommand</code> first, and then uses
22 * <code>ResultsViewAPI</code> to append message or result set, or set parameters to SQL Results View. When using the
23 * <code>ResultsViewAPI</code> to append result item to SQL Results View, this instance should always be given.
24 *
25 * @see org.eclipse.datatools.sqltools.result.ResultsViewAPI
26 * @author Dafan Yang
27 */
28public class OperationCommand
29{
30 /* type of the operation */
31 private int _actionType;
32 /* script of this operation, for example, SQL statement */
33 private String _sqlScript;
34 /* name of the consumer */
35 private String _consumerName;
36 /* connection profile name */
37 private String _profileName;
38 /* database name */
39 private String _databaseName;
40
41 /* 7 statuses defined */
42 public static final int STATUS_CRITICAL_ERROR = 7;
43 public static final int STATUS_WARNING = 6;
44 public static final int STATUS_TERMINATED = 5;
45 public static final int STATUS_FAILED = 4;
46 public static final int STATUS_SUCCEEDED = 3;
47 public static final int STATUS_RUNNING = 2;
48 public static final int STATUS_STARTED = 1;
49
50 /* 1 action type(s) defined */
51 public static final int ACTION_EXECUTE = 1;
52
53 /**
54 * Constructs an instance of OperationCommand.
55 *
56 * @param type the action type, should be one of the types defined in this class(for now, we have only 1 type)
57 * @see #ACTION_EXECUTE
58 * @param script for example SQL statement, should not be null
59 * @param consumerName name of the caller
60 * @param profileName connection profile name, should not be null
61 * @param databaseName database name, should not be null
62 */
63 public OperationCommand(int type, String script, String consumerName, String profileName, String databaseName)
64 {
65 // will append the condition when action types are increased
66 if(type != ACTION_EXECUTE)
67 {
68 _actionType = ACTION_EXECUTE;
69 }
70 else
71 {
72 _actionType = type;
73 }
74 _sqlScript = script == null ? "" : script;
75 _consumerName = consumerName == null ? "" : consumerName;
76 _profileName = profileName == null ? "" : profileName;
77 _databaseName = databaseName == null ? "" : databaseName;
78 }
79
80 /**
81 * Returns the script of this operation
82 * @return the script of this operation
83 */
84 public String getScript()
85 {
86 return _sqlScript;
87 }
88
89 /**
90 * Returns the action type
91 *
92 * @see #ACTION_EXECUTE
93 * @return the action type
94 */
95 public int getActionType()
96 {
97 return _actionType;
98 }
99
100 /**
101 * Returns the consumer's name
102 *
103 * @return the consumer's name
104 */
105 public String getConsumerName()
106 {
107 return _consumerName;
108 }
109
110 /**
111 * Returns the connection profile name
112 *
113 * @return the connection profile name
114 */
115 public String getProfileName()
116 {
117 return _profileName;
118 }
119
120 /**
121 * Returns the database name
122 *
123 * @return the database name
124 */
125 public String getDatabaseName()
126 {
127 return _databaseName;
128 }
129
130 /**
131 * Converts the action id to action string.
dyangf39fb7c2005-12-12 03:22:42 +0000132 *
dyang4b8476e2005-12-02 09:39:18 +0000133 * @param actionId the action type
134 * @return the action string
135 */
136 public String getActionString(int actionId)
137 {
138 switch (actionId)
139 {
140 case ACTION_EXECUTE:
141 return Messages.getString("OperationCommand.action.execute");
142 default:
143 return Messages.getString("OperationCommand.unknown.action");
144 }
145 }
dyangf39fb7c2005-12-12 03:22:42 +0000146
147 /**
148 * Returns the image of given status
149 *
150 * @param statusId the status id
151 * @return the image of this status
152 */
153 public static Image getStatusImage(int statusId)
154 {
155 switch (statusId)
156 {
157 case STATUS_STARTED:
158 return Images.get(Images.IMG_STARTED);
159 case STATUS_RUNNING:
160 return Images.get(Images.IMG_RUNNING);
161 case STATUS_SUCCEEDED:
162 return Images.get(Images.IMG_SUCCESS);
163 case STATUS_FAILED:
164 return Images.get(Images.IMG_FAIL);
165 case STATUS_TERMINATED:
166 return Images.get(Images.IMG_TERMINATE);
167 case STATUS_WARNING:
168 return Images.get(Images.IMG_WARNING);
169 case STATUS_CRITICAL_ERROR:
170 return Images.get(Images.IMG_CRITICAL);
171 default:
172 return Images.get(Images.IMG_FAIL);
173 }
174 }
175
176 /**
177 * Converts the status id to status string
178 * @param statusId the id of the status
179 * @return the string that describes this status
180 */
181 public static String getStatusString(int statusId)
182 {
183 switch (statusId)
184 {
185 case STATUS_STARTED:
186 return Messages.getString("OperationCommand.status.started");
187 case STATUS_RUNNING:
188 return Messages.getString("OperationCommand.status.running");
189 case STATUS_SUCCEEDED:
190 return Messages.getString("OperationCommand.status.succeeded");
191 case STATUS_FAILED:
192 return Messages.getString("OperationCommand.status.failed");
193 case STATUS_TERMINATED:
194 return Messages.getString("OperationCommand.status.terminated");
195 case STATUS_WARNING:
196 return Messages.getString("OperationCommand.status.warning");
197 case STATUS_CRITICAL_ERROR:
198 return Messages.getString("OperationCommand.status.critical");
199 default:
200 return Messages.getString("OperationCommand.status.unknown");
201 }
202 }
dyang4b8476e2005-12-02 09:39:18 +0000203}