|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| |
|
6 |
| |
|
7 |
| |
|
8 |
| |
|
9 |
| |
|
10 |
| |
|
11 |
| package org.globus.cas.impl.databaseAccess; |
|
12 |
| |
|
13 |
| import java.sql.Connection; |
|
14 |
| import java.sql.ResultSet; |
|
15 |
| import java.sql.Statement; |
|
16 |
| import java.sql.SQLException; |
|
17 |
| |
|
18 |
| import java.util.Vector; |
|
19 |
| |
|
20 |
| import org.apache.commons.logging.Log; |
|
21 |
| import org.apache.commons.logging.LogFactory; |
|
22 |
| |
|
23 |
| import org.globus.cas.impl.CasConstants; |
|
24 |
| |
|
25 |
| import org.globus.cas.types.CasObjectData; |
|
26 |
| import org.globus.cas.types.ArrayOfString; |
|
27 |
| import org.globus.cas.types.ServiceTypeData; |
|
28 |
| |
|
29 |
| import org.globus.util.I18n; |
|
30 |
| |
|
31 |
| |
|
32 |
| |
|
33 |
| |
|
34 |
| public class ServiceTypeDataHandler { |
|
35 |
| |
|
36 |
| static Log logger = |
|
37 |
| LogFactory.getLog(ServiceTypeDataHandler.class.getName() ); |
|
38 |
| |
|
39 |
| private static I18n i18n = |
|
40 |
| I18n.getI18n("org.globus.cas.impl.databaseAccess.errors", |
|
41 |
| ServiceTypeDataHandler.class.getClassLoader()); |
|
42 |
| |
|
43 |
| |
|
44 |
| |
|
45 |
| |
|
46 |
0
| public static String storeObject(ServiceTypeData serviceTypeData)
|
|
47 |
| throws CasDBException { |
|
48 |
| |
|
49 |
0
| logger.debug("Service type data storeObject called");
|
|
50 |
0
| Connection connection = CasDBStorage.getDBConnection();
|
|
51 |
0
| String serviceTypeName = serviceTypeData.getName();
|
|
52 |
| |
|
53 |
0
| String query = "insert into " + CasDBConstants.TABLE_SERVICETYPE + " ("
|
|
54 |
| + CasDBConstants.COL_SERVICETYPE_NAME + ") values ('" |
|
55 |
| + serviceTypeName + "')"; |
|
56 |
0
| Statement statement = null;
|
|
57 |
0
| try {
|
|
58 |
0
| statement = connection.createStatement();
|
|
59 |
0
| logger.debug("store query is " + query);
|
|
60 |
0
| statement.executeUpdate(query);
|
|
61 |
| } |
|
62 |
| catch (SQLException exp) { |
|
63 |
0
| logger.error(i18n.getMessage("storeErr", new Object[] {
|
|
64 |
| "service type", query }), exp); |
|
65 |
0
| throw new CasDBException(i18n.getMessage("storeErr", new Object[] {
|
|
66 |
| "service type", exp.getMessage() }), exp); |
|
67 |
| } |
|
68 |
| finally { |
|
69 |
| |
|
70 |
| |
|
71 |
0
| CasDBStorage.returnDBConnection(connection);
|
|
72 |
0
| try {
|
|
73 |
0
| if (statement != null)
|
|
74 |
0
| statement.close();
|
|
75 |
| } |
|
76 |
| catch (SQLException exp) { |
|
77 |
0
| logger.warn(i18n.getMessage("storeErrClose", "service type "),
|
|
78 |
| exp); |
|
79 |
| } |
|
80 |
| } |
|
81 |
0
| return serviceTypeName;
|
|
82 |
| } |
|
83 |
| |
|
84 |
| |
|
85 |
| |
|
86 |
| |
|
87 |
0
| public static String[] list() throws CasDBException {
|
|
88 |
| |
|
89 |
0
| String query = "select" + CasDBConstants.COL_SERVICETYPE_NAME + " from"
|
|
90 |
| + CasDBConstants.TABLE_SERVICETYPE; |
|
91 |
0
| return CasDBStorage.runListQuery(query,
|
|
92 |
| CasDBConstants.COL_SERVICETYPE_NAME); |
|
93 |
| } |
|
94 |
| |
|
95 |
| |
|
96 |
| |
|
97 |
| |
|
98 |
| |
|
99 |
0
| public static CasObjectData retrieveObject(String name)
|
|
100 |
| throws CasDBException { |
|
101 |
| |
|
102 |
0
| ServiceTypeData returnObject = null;
|
|
103 |
0
| Vector actionNames = null;
|
|
104 |
0
| Connection connection = CasDBStorage.getDBConnection();
|
|
105 |
| |
|
106 |
0
| String query = "select" + CasDBConstants.COL_ACTION_NAME + " from"
|
|
107 |
| + CasDBConstants.TABLE_SERVICETYPE_ACTION + " where" |
|
108 |
| + CasDBConstants.COL_SERVICETYPE_NAME + "='" + name.trim() + "'"; |
|
109 |
| |
|
110 |
0
| Statement statement = null;
|
|
111 |
0
| ResultSet resultSet = null;
|
|
112 |
0
| try {
|
|
113 |
0
| statement = connection.createStatement();
|
|
114 |
0
| resultSet = statement.executeQuery(query);
|
|
115 |
0
| if ((resultSet!=null) && (resultSet.next())) {
|
|
116 |
0
| actionNames = new Vector(resultSet.getFetchSize());
|
|
117 |
0
| do {
|
|
118 |
0
| actionNames.add(resultSet.getString(
|
|
119 |
| CasDBConstants.COL_ACTION_NAME.trim())); |
|
120 |
0
| } while (resultSet.next());
|
|
121 |
| } |
|
122 |
| } |
|
123 |
| catch (SQLException exp) { |
|
124 |
0
| CasDBStorage.returnDBConnection(connection);
|
|
125 |
0
| logger.error(i18n.getMessage("retrieveErr", new Object[] {
|
|
126 |
| "service type", query }), exp); |
|
127 |
0
| throw new CasDBException(i18n.getMessage("retrieveErr",
|
|
128 |
| new Object[] { "service type", exp.getMessage()}), exp); |
|
129 |
| } |
|
130 |
| finally { |
|
131 |
0
| try {
|
|
132 |
0
| if (resultSet != null)
|
|
133 |
0
| resultSet.close();
|
|
134 |
0
| if (statement != null)
|
|
135 |
0
| statement.close();
|
|
136 |
| } |
|
137 |
| catch (SQLException exp) { |
|
138 |
0
| logger.warn(i18n.getMessage("retrieveErrClose",
|
|
139 |
| "service type"), exp); |
|
140 |
| } |
|
141 |
| } |
|
142 |
| |
|
143 |
0
| ArrayOfString arrayOfActionNames = null;
|
|
144 |
0
| if (actionNames != null) {
|
|
145 |
0
| String stringActionNames[] = new String[actionNames.size()];
|
|
146 |
0
| actionNames.toArray(stringActionNames);
|
|
147 |
0
| arrayOfActionNames = new ArrayOfString(stringActionNames);
|
|
148 |
| } |
|
149 |
| |
|
150 |
0
| query = "select * from" + CasDBConstants.TABLE_SERVICETYPE + " where"
|
|
151 |
| + CasDBConstants.COL_SERVICETYPE_NAME + " = '" + name.trim() + "'"; |
|
152 |
| |
|
153 |
0
| try {
|
|
154 |
0
| statement = connection.createStatement();
|
|
155 |
0
| resultSet = statement.executeQuery(query);
|
|
156 |
0
| if (resultSet!=null) {
|
|
157 |
0
| if (resultSet.next()) {
|
|
158 |
0
| returnObject = new ServiceTypeData();
|
|
159 |
0
| returnObject.setName(resultSet.getString(
|
|
160 |
| CasDBConstants.COL_SERVICETYPE_NAME.trim())); |
|
161 |
0
| returnObject.setActionNames(arrayOfActionNames);
|
|
162 |
| } |
|
163 |
| } |
|
164 |
| } |
|
165 |
| catch (SQLException exp) { |
|
166 |
0
| logger.error("Error retrieving service type data\n" + query, exp);
|
|
167 |
0
| logger.error(i18n.getMessage("retrieveErr", new Object[] {
|
|
168 |
| "service type", query }), exp); |
|
169 |
0
| throw new CasDBException(i18n.getMessage("retrieveErr",
|
|
170 |
| new Object[] { "service type", exp.getMessage()}), exp); |
|
171 |
| } |
|
172 |
| finally { |
|
173 |
| |
|
174 |
| |
|
175 |
0
| CasDBStorage.returnDBConnection(connection);
|
|
176 |
0
| try {
|
|
177 |
0
| if (resultSet != null)
|
|
178 |
0
| resultSet.close();
|
|
179 |
0
| if (statement != null)
|
|
180 |
0
| statement.close();
|
|
181 |
| } |
|
182 |
| catch (SQLException exp) { |
|
183 |
0
| logger.warn(i18n.getMessage("retrieveErrClose",
|
|
184 |
| "service type"), exp); |
|
185 |
| } |
|
186 |
| } |
|
187 |
0
| return returnObject;
|
|
188 |
| } |
|
189 |
| |
|
190 |
| |
|
191 |
| |
|
192 |
| |
|
193 |
| |
|
194 |
0
| public static void deleteObject(String serviceName) throws CasDBException {
|
|
195 |
| |
|
196 |
| |
|
197 |
| |
|
198 |
0
| if (ObjectGroupDataHandler.isMember(serviceName.trim(),
|
|
199 |
| CasConstants.SERVICETYPE_SPEC)) { |
|
200 |
0
| String errMesg = i18n.getMessage("memberOfGpErr", new Object[] {
|
|
201 |
| "Service type", serviceName.trim(), "object"}); |
|
202 |
0
| logger.debug(errMesg);
|
|
203 |
0
| throw new CasDBException(errMesg);
|
|
204 |
| } |
|
205 |
| |
|
206 |
0
| Connection connection = CasDBStorage.getDBConnection();
|
|
207 |
0
| String query = "delete from" + CasDBConstants.TABLE_SERVICETYPE
|
|
208 |
| + " where" + CasDBConstants.COL_SERVICETYPE_NAME + " ='" |
|
209 |
| + serviceName.trim() + "'"; |
|
210 |
0
| Statement statement = null;
|
|
211 |
0
| int result = -1;
|
|
212 |
0
| try {
|
|
213 |
0
| statement = connection.createStatement();
|
|
214 |
0
| result = statement.executeUpdate(query);
|
|
215 |
| } |
|
216 |
| catch (SQLException exp) { |
|
217 |
0
| logger.error(i18n.getMessage("delObjErr", new Object[] {
|
|
218 |
| "servicetype", query }), exp); |
|
219 |
0
| throw new CasDBException(i18n.getMessage("delObjErr",
|
|
220 |
| new Object[] { "servicetype", exp.getMessage()}), exp); |
|
221 |
| } |
|
222 |
| finally { |
|
223 |
| |
|
224 |
| |
|
225 |
0
| CasDBStorage.returnDBConnection(connection);
|
|
226 |
0
| try {
|
|
227 |
0
| if (statement != null)
|
|
228 |
0
| statement.close();
|
|
229 |
| } |
|
230 |
| catch (SQLException exp) { |
|
231 |
0
| logger.warn(i18n.getMessage("delObjErrClose", "servicetype"),
|
|
232 |
| exp); |
|
233 |
| } |
|
234 |
| } |
|
235 |
0
| if (result <= 0) {
|
|
236 |
0
| String err = i18n.getMessage("serviceTypeDelError", serviceName);
|
|
237 |
0
| logger.error(err);
|
|
238 |
0
| throw new CasDBException(err);
|
|
239 |
| } |
|
240 |
| } |
|
241 |
| } |