-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathJDBCPeopleCodeContainer.java
382 lines (338 loc) · 11.1 KB
/
JDBCPeopleCodeContainer.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
package decodepcode;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Logger;
/*
* Copyright (c) 2011 Erik H (erikh3@users.sourceforge.net)
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/**
* Extends the base PeopleCodeContainer with functionality to retrieve the bytecode from the PeopleTools tables
*/
public class JDBCPeopleCodeContainer extends PeopleCodeContainer implements PeopleCodeObject
{
public static class KeySet
{
private String[] values;
private int[] objIDs;
private int objType = -1;
private int nrOfValuesToCompare = 7;
public KeySet(ResultSet rs) throws SQLException
{
this( rs, true);
}
public KeySet( ResultSet rs, boolean limitType58) throws SQLException
{
values = new String[7];
objIDs = new int[7];
for (int i = 0; i < 7; i++)
{
values[i] = rs.getString("OBJECTVALUE" + (i+1));
objIDs[i] = rs.getInt("OBJECTID" + (i+1));
}
objType = getObjectType(objIDs);
if (objType == 58 && limitType58)
setNrOfValuesToCompare(3);
}
public KeySet( int _objType, ResultSet rs) throws SQLException
{
this(rs);
objType =_objType;
}
public static String getList()
{
String s = "";
for (int i = 0; i < 7; i++)
s = s + (i==0? "": ", ") + " pc.OBJECTID"+ (i+1) + ", pc.OBJECTVALUE"+ (i+1);
return s;
}
public String getWhere( String prefix)
{
String s = "";
for (int i = 0; i < nrOfValuesToCompare; i++)
s = s + (i==0? "": " and ") + prefix + "OBJECTVALUE"+ (i+1) + " = '" + values[i] + "'";
return s;
}
public String getWhere()
{
return getWhere(" ");
}
public String compositeKey()
{
String s;
if (objType <= 0)
{
s = "";
for (int i = 0; i < 7; i++)
if (values[i] != null && values[i].trim().length() > 0)
s = s + (i==0? "": "-") + values[i].trim();
}
else
{
s = PeopleCodeContainer.objectTypeStr(objType);
for (int i = 0; i < 7; i++)
if (values[i] != null && values[i].trim().length() > 0)
s = s + "-" + values[i].trim();
}
return s;
}
@Override
public boolean equals( Object o)
{
return compositeKey().equals( ((KeySet) o).compositeKey());
}
@Override
public String toString()
{
return compositeKey();
}
public int getNrOfValuesToCompare() {
return nrOfValuesToCompare;
}
public void setNrOfValuesToCompare(int nrOfValuesToCompare) {
this.nrOfValuesToCompare = nrOfValuesToCompare;
}
}
static Logger logger = Logger.getLogger(JDBCPeopleCodeContainer.class.getName());
static final String keywordArray[] = {"Component","Panel","RecName", "Scroll", "MenuName", "BarName", "ItemName", "CompIntfc",
"Image", "Interlink", "StyleSheet", "FileLayout", "Page", "PanelGroup", "Message", "BusProcess", "BusEvent", "BusActivity"
, "Field", "Record"
};
Map<Integer, String>references = new HashMap<Integer, String>();
KeySet keys;
static Map<String, String> keyWords = new HashMap<String, String>();
static
{
for (String s: keywordArray)
keyWords.put(s.toUpperCase(), s);
// keyWords.put("FIELD", "");
// keyWords.put("RECORD", "");
}
boolean foundPeopleCode = false;
Connection originatingConnection;
String originatingName;
/**
*
* @param dbconn Connection from which bytecode is to be read
* @param dbowner schema for this connection
* @param rs ResultSet containing key info for the PCMPROG row(s)to be read; this ResultSet may or may not come
* from the same database as the Connection parameter
* @param canAccessPROGTXT if true, get plain text from PSPROGTEXT
* @param sourceDB
*/
public JDBCPeopleCodeContainer( Connection dbconn,
String dbowner,
ResultSet rs ,
boolean canAccessPROGTXT,
String dbName) throws SQLException, ClassNotFoundException
{
originatingName = dbName;
String cat = dbconn.getCatalog();
if (cat != null && cat.trim().length() > 0)
source = cat.trim();
else
source = dbName;
if (!canAccessPROGTXT)
initJDBCPeopleCodeContainerViaDecode(dbconn, dbowner, rs);
else
{
keys = new KeySet(rs, false);
Statement st = dbconn.createStatement();
String q ="select LASTUPDDTTM, LASTUPDOPRID from " + dbowner + "PSPCMPROG pc where " + keys.getWhere() + " and PROGSEQ = 0";
logger.fine(q);
ResultSet rs0 = st.executeQuery(q);
foundPeopleCode = rs0.next();
if (!foundPeopleCode)
{
logger.fine("Nothing found - setting foundPeopleCode=false for this environment");
st.close();
return;
}
setLastChangedDtTm(rs0.getTimestamp("LASTUPDDTTM"));
setLastChangedBy(rs0.getString("LASTUPDOPRID").trim());
q = "select PCTEXT from " + dbowner + "PSPCMTXT pt where"
+ keys.getWhere(" pt.")
+ " order by pt.PROGSEQ";
logger.fine(q);
ResultSet rs2 = st.executeQuery(q);
StringBuffer sb = new StringBuffer();
while (rs2.next())
{
sb.append(rs2.getString("PCTEXT"));
foundPeopleCode = true;
}
st.close();
this.setPeopleCodeText(sb.toString());
}
if (foundPeopleCode)
originatingConnection = dbconn;
}
/**
*
* @param dbconn Connection from which bytecode is to be read
* @param dbowner schema for this connection
* @param rs ResultSet containing key info for the PCMPROG row(s)to be read; this ResultSet may or may not come
* from the same database as the Connection parameter.
*/
void initJDBCPeopleCodeContainerViaDecode( Connection dbconn, String dbowner, ResultSet rs ) throws SQLException, ClassNotFoundException
{
keys = new KeySet(rs, false);
Statement st = dbconn.createStatement();
String sqlWhere = keys.getWhere();
String q ="select LASTUPDDTTM, LASTUPDOPRID, PROGTXT from " + dbowner + "PSPCMPROG pc where " + sqlWhere + " order by PROGSEQ";
logger.fine(q);
ResultSet rs2 = st.executeQuery(q);
while (rs2.next())
{
setLastChangedDtTm(rs2.getTimestamp("LASTUPDDTTM"));
setLastChangedBy(rs2.getString("LASTUPDOPRID").trim());
byte[] b = rs2.getBytes("PROGTXT");
if (bytes == null)
bytes = b;
else
{
byte[] b1 = new byte[bytes.length + b.length];
for (int i = 0; i < bytes.length; i++)
b1[i] = bytes[i];
for (int i = bytes.length; i < bytes.length + b.length; i++)
b1[i] = b[i - bytes.length];
bytes = b1;
}
}
rs2.close();
if (bytes == null || bytes.length == 0)
{
//logger.severe("Nothing retrieved from PSPCMPRPG with "+ q);
st.close();
return;
}
foundPeopleCode = true;
logger.fine("PeopleCode byte length = " + bytes.length + " (0x" + Integer.toString(bytes.length, 16) + ")" );
q ="select RECNAME, REFNAME, NAMENUM from " + dbowner + "PSPCMNAME where " + sqlWhere;
logger.fine(q);
rs2 = st.executeQuery(q);
while (rs2.next())
{
if (references.get(rs2.getInt("NAMENUM")) != null)
logger.warning("Duplicate reference: " + rs2.getInt("NAMENUM") + " in " + sqlWhere);
String recname = rs2.getString("RECNAME").trim(),
special = keyWords.get(recname);
if (special != null)
recname = special;
String refName = rs2.getString("REFNAME").trim();
references.put(rs2.getInt("NAMENUM"),
(recname != null && recname.length()> 0? recname + "." : "")
+ refName);
}
rs2.close();
logger.fine("" + references.size() + " references found");
st.close();
}
@Override
String getReference(int nameNum) {
return references.get(nameNum);
}
@Override
public String getCompositeKey()
{
return keys.compositeKey();
}
void writeReferencesToFile( File ff) throws IOException
{
FileWriter w= new FileWriter(ff);
for (Integer ref: references.keySet())
w.write(ref + "=" + references.get(ref) + PeopleCodeParser.eol);
w.close();
}
@Override
void writeReferencesInDirectory(File f) throws IOException
{
File ff = new File( f, keys.compositeKey() + ".references");
writeReferencesToFile(ff);
}
static int getObjectType( int[] objIDs)
{
int objType = -1;
if (objIDs[1-1] == 1 && objIDs[2-1] == 2 && objIDs[3-1] == 12 && objIDs[4-1] == 0) objType= 8;
if (objIDs[1-1] == 3 && objIDs[2-1] == 4 && objIDs[3-1] == 5 && objIDs[4-1] == 12) objType= 9;
if (objIDs[1-1] == 60 && objIDs[2-1] == 12 && objIDs[3-1] == 0 && objIDs[4-1] == 0) objType= 39;
if (objIDs[1-1] == 60 && objIDs[2-1] == 87 && objIDs[3-1] == 12 && objIDs[4-1] == 0) objType= 40;
if (objIDs[1-1] == 66 && objIDs[2-1] == 77 && objIDs[3-1] == 78 && objIDs[4-1] == 12) objType= 43;
if (objIDs[1-1] == 66 && objIDs[2-1] == 77 && objIDs[3-1] == 39 && objIDs[4-1] == 20) objType= 43;
if (objIDs[1-1] == 74) objType = 42;
if (objIDs[1-1] == 9 && objIDs[2-1] == 12 && objIDs[3-1] == 0 && objIDs[4-1] == 0) objType= 44;
if (objIDs[1-1] == 10 && objIDs[2-1] == 39 && objIDs[3-1] == 12 && objIDs[4-1] == 0) objType= 46;
if (objIDs[1-1] == 10 && objIDs[2-1] == 39 && objIDs[3-1] == 1 && objIDs[4-1] == 12) objType= 47;
if (objIDs[1-1] == 10 && objIDs[2-1] == 39 && objIDs[3-1] == 1 && objIDs[4-1] == 2) objType= 48;
if (objIDs[1-1] == 104 ) objType= 58;
// File reference (added 11/2012)
if (objIDs[1-1] == 121 && objIDs[2-1] == 122 && objIDs[3-1] == 0 && objIDs[4-1] == 0) objType= 68;
if (objType < 0)
logger.warning("Could not determine the object type for "+ objIDs[1-1] + "/" + objIDs[2-1]+ "/" + objIDs[3-1] + "/" + objIDs[4-1]);
return objType;
}
static class StoreInList extends ContainerProcessor
{
List<PeopleCodeObject> list;
List<SQLobject> sqlList;
List<CONTobject> contList;
public StoreInList(List<PeopleCodeObject> _list, List<SQLobject> _sqlList, List<CONTobject> _contList)
{
list = _list;
sqlList = _sqlList;
contList = _contList;
}
public void process(PeopleCodeObject c)
{
list.add(c);
}
public void processSQL(SQLobject sql) throws IOException {
sqlList.add(sql);
}
public void processCONT(CONTobject cont) throws IOException {
contList.add(cont);
}
@Override
public void aboutToProcess() {
// TODO Auto-generated method stub
}
}
@Override
public String[] getKeys()
{
return keys.values;
}
@Override
public int getPeopleCodeType() {
return keys.objType;
}
public boolean hasFoundPeopleCode() {
return foundPeopleCode;
}
public int[] getKeyTypes() {
return keys.objIDs;
}
public Connection getOriginatingConnection() {
return originatingConnection;
}
public String getOriginatingName() {
return originatingName;
}
}