KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > cofax > SqlDataStore


1 /*
2  * SqlDataStore is part of the Cofax content management system library.
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Please see http://www.cofax.org for contact information and other related informaion.
19  *
20  * $Header: /cvsroot/cofax/cofax/src/org/cofax/SqlDataStore.java,v 1.12.2.1 2006/12/11 16:28:44 fxrobin Exp $
21  */

22 package org.cofax;
23
24 import java.util.*;
25 import java.io.*;
26 import java.sql.*;
27 import org.cofax.connectionpool.*;
28
29 /**
30  * Provides SQL database connectivity for Cofax. A subclass of
31  * <code>DataStore</code> . SqlDataStore uses an SQL compatible database as
32  * the data store for Cofax. SqlDataStore itself is flexible since it is not
33  * tied to a given table or field naming structure other then it's packageTag
34  * lookup table. tblpackagetags must contain the fields tag_name and tag_value
35  * for packageTag lookups. To add a new packageTag to the system simply add a
36  * row to this table. There should be no mention of the
37  * <code>SqlDataStore</code> in any client code.
38  *
39  * @author Rajiv Pant
40  * @author Karl Martino
41  * @author Sam Cohen
42  * @created April 19, 2002
43  * @version 1.9.7
44  */

45 public class SqlDataStore extends DataStore {
46
47     private boolean writeAccess;
48
49     // flag for wether the database can be updated or not
50
private boolean connected;
51
52     // flag for wether the current session is activly connected
53
private ConnectionWrapper connection;
54
55     // global database connection to share
56
static CofaxCache cacheOfPackageTags;
57
58     static PoolManager poolMgr;
59
60     /**
61      * Hashmap into a determination of if stored procedures contain clobs is
62      * placed to speed transactions.
63      */

64     public static HashMap clobColumns = new HashMap();
65
66     /**
67      * Hashmap into which the cache results parameter (1,0) is thrown upon
68      * initialization.
69      */

70     public static HashMap dbPackageTagsCacheCommand = new HashMap();
71
72     /**
73      * Hashmap into which package tags may be placed into memory upon
74      * initialization.
75      */

76     public static HashMap dbPackageTags = new HashMap();
77
78     /**
79      * Hashmap into which package tag results are cached.
80      */

81     public static HashMap dbPackageTagsCache = new HashMap();
82
83     /**
84      * Initializes the connection pool.
85      *
86      * @param configFile
87      * Description of the Parameter
88      */

89
90     public void init(String JavaDoc configFile) {
91         // TODO: J2EE: javax.naming.Context ctx = new InitialContext();
92
// TODO: J2EE: javax.sql.DataSource poolMgr =
93
// (DataSource)ctx.lookup("jdbc/cofax");
94
poolMgr = PoolManager.getInstance(configFile);
95     }
96
97     /**
98      * To be ran once before using the data store. With a pre-loaded Properties
99      * object.
100      *
101      * @param dbProps
102      * Description of the Parameter
103      */

104     public void init(Properties dbProps) {
105         // TODO: J2EE: javax.naming.Context ctx = new InitialContext();
106
// TODO: J2EE: javax.sql.DataSource poolMgr =
107
// (DataSource)ctx.lookup("jdbc/cofax");
108

109         poolMgr = PoolManager.getInstance(dbProps);
110     }
111
112     /**
113      * Initializes variables.
114      */

115     public SqlDataStore() {
116
117         connected = false;
118         writeAccess = false;
119
120     }
121
122     /**
123      * Set's this data store's cache object and caches all package tags.
124      *
125      * @param cache
126      * The new cache value
127      * @param whichCache
128      * The new cache value
129      */

130     public void setCache(Object JavaDoc cache, int whichCache) {
131         switch (whichCache) {
132         case 1:
133             cacheOfPackageTags = (CofaxCache) cache;
134             // packageTags?
135
break;
136         case 2:
137             // processed packageTags
138
dbPackageTags = (HashMap) cache;
139             break;
140         case 3:
141             // packageTag results
142
dbPackageTagsCache = (HashMap) cache;
143             break;
144         case 4:
145             // clob columns
146
clobColumns.clear();
147             break;
148         case 5:
149             // packageTag cache command
150
dbPackageTagsCacheCommand = (HashMap) cache;
151             break;
152         default:
153             break;
154         }
155         // cacheOfPackageTags = cache;
156
return;
157     }
158
159     /**
160      * Description of the Method
161      *
162      * @param whichCache
163      * Description of the Parameter
164      */

165     public void clearCache(int whichCache) {
166
167         switch (whichCache) {
168         case 1:
169             break;
170         case 2:
171             // processed packageTags
172
dbPackageTags.clear();
173             break;
174         case 3:
175             // packageTag results
176
dbPackageTagsCache.clear();
177             break;
178         case 4:
179             // clob columns
180
clobColumns.clear();
181             break;
182         case 5:
183             // packageTag cache command
184
dbPackageTagsCacheCommand.clear();
185             break;
186         default:
187             break;
188         }
189         // log("SqlDataStore clearPackageCache clearing package cache.");
190
return;
191     }
192
193     /**
194      * Gets the cacheValue attribute of the SqlDataStore object
195      *
196      * @param key
197      * Description of the Parameter
198      * @param whichCache
199      * Description of the Parameter
200      * @return The cacheValue value
201      */

202     public Object JavaDoc getCacheValue(Object JavaDoc key, int whichCache) {
203         String JavaDoc tag = (String JavaDoc) key;
204         String JavaDoc value = null;
205         switch (whichCache) {
206         case 1:
207             // packageTags?
208
break;
209         case 2:
210             // processed packageTags
211
value = (String JavaDoc) dbPackageTags.get(tag);
212             break;
213         case 3:
214             // packageTag results
215
break;
216         case 4:
217             // clob columns
218
break;
219         case 5:
220             // packageTag cache command
221
break;
222         default:
223             break;
224         }
225
226         return value;
227     }
228
229     /**
230      * Connects to the database using a connection established in the database
231      * pool
232      *
233      * @param dbPool
234      * Description of the Parameter
235      * @return Description of the Return Value
236      */

237     public final boolean connect() {
238
239         setLastError("");
240
241         String JavaDoc dbPool = getDataStoreName();
242
243         // try to connect to data base
244
try {
245             connection = poolMgr.getConnection(dbPool);
246             connected = true;
247             setConnected(connected);
248             if (connection == null) {
249                 setLastError("Could not get connection from pool.");
250                 connected = false;
251             }
252         } catch (Exception JavaDoc e) {
253             try {
254                 if (connection != null) {
255                     connection.close();
256                 }
257             } catch (Exception JavaDoc e2) {
258             }
259             setLastError("Connection failed, url bad or user name and password not accepted" + e.getMessage());
260             connected = false;
261             setConnected(connected);
262         }
263         return connected;
264     }
265
266     /**
267      * Description of the Method
268      */

269     public void initPool() {
270
271         return;
272     }
273
274     /**
275      * Connects to the database using a connection established in the database
276      * poo
277      *
278      * @return Description of the Return Value
279      */

280     public final boolean connectFromPool() {
281
282         return false;
283     }
284
285     /**
286      * Makes a sting sql ready by surrounding it with singlequotes, replacing
287      * internal single quotes, or making a NULL value. TO DO: This should use
288      * the database driver's internal method.
289      *
290      * @param input
291      * Description of the Parameter
292      * @return Description of the Return Value
293      */

294     private final String JavaDoc prepSqlString(String JavaDoc input) {
295
296         if (input != null) {
297             return "'" + CofaxUtil.replace(input, "'", "''") + "'";
298         } else {
299             return "NULL";
300         }
301
302     }
303
304     /**
305      * Replaces internal single quotes, or making a NULL value.
306      *
307      * @param input
308      * Description of the Parameter
309      * @return Description of the Return Value
310      */

311     private final String JavaDoc sqlEscape(String JavaDoc input) {
312
313         if (input != null) {
314             return CofaxUtil.replace(input, "'", "''");
315         } else {
316             return "NULL";
317         }
318
319     }
320
321     /**
322      * Gets the sql string that is used for the packageTag request and parses it
323      * with it's parameters.
324      *
325      * @param tag
326      * Description of the Parameter
327      * @param params
328      * Description of the Parameter
329      * @param servPage
330      * Description of the Parameter
331      * @param servAddr
332      * Description of the Parameter
333      * @return The packageTag value
334      */

335     public final String JavaDoc getPackageTag(String JavaDoc tag, HashMap params, String JavaDoc servPage, String JavaDoc servAddr) {
336
337         String JavaDoc tagStatement = null;
338         setError(false);
339
340         if (cacheOfPackageTags != null && cacheOfPackageTags.isPageCached(tag)) {
341             cacheOfPackageTags.incrementHitCount(tag);
342             tagStatement = cacheOfPackageTags.getPage(tag).toString();
343         } else {
344             // Get tag meaning
345
String JavaDoc sqlString = "SELECT tag_value FROM tblpackagetags WHERE tag_name = '" + tag + "'";
346
347             Statement sql;
348             ResultSet result;
349             try {
350                 // Get the tag value
351
sql = connection.createStatement();
352                 connection.setCurrentActivity("Building: " + servPage + " For: " + servAddr + " Query: " + sqlString);
353                 sql.execute(sqlString);
354                 result = sql.getResultSet();
355                 if (result.next()) {
356                     tagStatement = result.getString(1);
357                 } else {
358                     tagStatement = "";
359                 }
360             } catch (SQLException e) {
361                 setLastError(e.toString());
362                 setError(true);
363             } finally {
364                 result = null;
365                 sql = null;
366             }
367
368             if (cacheOfPackageTags != null) {
369                 cacheOfPackageTags.incrementHitCount(tag);
370                 CofaxPage packageTagContainer = new CofaxPage();
371                 packageTagContainer.append(tagStatement);
372                 if (cacheOfPackageTags.shouldPageBeCached(tag)) {
373                     cacheOfPackageTags.addPageToCache(tag, packageTagContainer);
374                 }
375             }
376         }
377
378         // Replace values matched in glossary to complete the tag's meaning
379
String JavaDoc searchFor;
380
381         // Replace values matched in glossary to complete the tag's meaning
382
String JavaDoc replaceWith;
383         Iterator tagArgs = params.keySet().iterator();
384         while (tagArgs.hasNext()) {
385             searchFor = (String JavaDoc) tagArgs.next();
386             replaceWith = sqlEscape(params.get(searchFor).toString());
387             tagStatement = CofaxUtil.replace(tagStatement, searchFor, replaceWith);
388         }
389         return tagStatement;
390     }
391
392     /**
393      * Returns a set of content by tag. Prefixes returned names of values with
394      * the tag name.
395      *
396      * @param tag
397      * Description of the Parameter
398      * @param tagStatement
399      * Description of the Parameter
400      * @param servPage
401      * Description of the Parameter
402      * @param servAddr
403      * Description of the Parameter
404      * @return The packageData value
405      */

406     public final List getPackageData(String JavaDoc tag, String JavaDoc tagStatement, String JavaDoc servPage, String JavaDoc servAddr) {
407
408         ArrayList articles = new ArrayList();
409         if (tagStatement != null && !tagStatement.equals("")) {
410             Statement sql;
411             ResultSet result;
412             try {
413                 // load the articles
414
int help = 0;
415                 setError(false);
416                 int i;
417                 sql = connection.createStatement();
418                 connection.setCurrentActivity("Building: " + servPage + " For: " + servAddr + " Query: " + tagStatement);
419                 sql.execute(tagStatement);
420                 result = sql.getResultSet();
421                 ResultSetMetaData meta = result.getMetaData();
422                 int cols = meta.getColumnCount();
423                 while (result.next()) {
424                     HashMap article = new HashMap();
425                     for (i = 1; i <= cols; i++) {
426                         String JavaDoc val = result.getString(meta.getColumnLabel(i));
427                         if (val == null) {
428                             val = "";
429                         }
430                         if (!tag.equals("")) {
431                             article.put(tag + ":" + meta.getColumnLabel(i) + "", val + "");
432                         } else {
433                             article.put(meta.getColumnLabel(i) + "", val + "");
434                         }
435                     }
436                     articles.add(article);
437                 }
438             } catch (SQLException e) {
439                 setLastError(e.toString());
440                 setError(true);
441             } finally {
442                 result = null;
443                 sql = null;
444             }
445         }
446         return articles;
447     }
448
449     /**
450      * Returns a set of content by tag for stored procedures, inserts, updates,
451      * or selects. Handles clobs both on the way in and the way out.
452      *
453      * @param data
454      * Description of the Parameter
455      * @param tagName
456      * Description of the Parameter
457      * @param tagData
458      * Description of the Parameter
459      * @param init
460      * Description of the Parameter
461      * @return The packageData value
462      */

463     public final List getPackageData(HashMap data, String JavaDoc tagName, String JavaDoc tagData, boolean init) {
464
465         // variable to be set to true if tag needs to be cached and
466
// results have not yet been cached.
467
boolean cacheThisCall = false;
468
469         // determine whether the package tag results should be already cached
470
boolean cacheMe = false;
471         if (init == false) {
472             String JavaDoc ifCache = "0";
473             try {
474                 ifCache = (String JavaDoc) dbPackageTagsCacheCommand.get(tagData);
475             } catch (Exception JavaDoc e) {
476                 log("SQLDataStore getPackageData ERROR: dbPackageTagsCacheCommand is null: " + e);
477             }
478             if (ifCache != null && ifCache.equals("1")) {
479                 cacheMe = true;
480             } else {
481                 cacheMe = false;
482             }
483         }
484
485         // create a list to be populated with hashmaps of data
486
List articles = new ArrayList();
487
488         // append a colon to tag if tagname exists so it
489
// will be prepended to column names when resultset is delivered
490
String JavaDoc tag = "";
491         if (tagName == null && !tagName.equals("")) {
492             tag = tagName + ":";
493         }
494
495         try {
496             // fulfill package tag with HashMap data
497
tagData = fillToolsTag(data, tagData);
498
499             log("SQLDataStore getPackageData filled tag is : " + tagData);
500
501             // check to see if the results are already cached
502
// if they are, return them
503
// if not, make sure that they get cached at the end of this routine
504
if (init == false && cacheMe == true) {
505                 if (dbPackageTagsCache.get(tagData) != null) {
506                     // log("SQLDataStore getPackageData fulfilled tagData is " +
507
// tagData);
508
log("SQLDataStore getPackageData getting results of tag " + tagData + "\nfrom cache.");
509                     return ((ArrayList) dbPackageTagsCache.get(tagData));
510                 } else {
511                     cacheThisCall = true;
512                 }
513             }
514             int i;
515             Statement sql = connection.createStatement();
516             connection.setCurrentActivity(tagData);
517             sql.execute(tagData);
518             ResultSet result = sql.getResultSet();
519             ResultSetMetaData meta = result.getMetaData();
520             int cols = meta.getColumnCount();
521             String JavaDoc val;
522
523             while (result.next()) {
524                 HashMap article = new HashMap();
525                 for (i = 1; i <= cols; i++) {
526                     val = result.getString(meta.getColumnLabel(i));
527                     if (val == null) {
528                         val = "";
529                     }
530                     if (!tag.equals("")) {
531                         article.put(tag + ":" + meta.getColumnLabel(i).toUpperCase() + "", val + "");
532                     } else {
533                         article.put(meta.getColumnLabel(i).toUpperCase() + "", val + "");
534                     }
535                 }
536                 articles.add(article);
537             }
538             result.close();
539             sql.close();
540         } catch (Exception JavaDoc e) {
541             setError(true);
542             setLastError("SQLDataStore getPackageData ERROR: " + e);
543         }
544
545         if (cacheThisCall == true) {
546             dbPackageTagsCache.put(tagData, articles);
547             log("SQLDataStore getPackageData adding results of tag to cache");
548         }
549         return articles;
550     }
551
552     // getPackageData
553

554     /**
555      * Free's a connection from the database pool.
556      *
557      * @param dataStoreName
558      * Description of the Parameter
559      * @return Description of the Return Value
560      */

561
562     public final boolean disConnect() {
563
564         // try to disconnect from the data base
565
try {
566             if (connected) {
567                 connection.close();
568             }
569         } catch (Exception JavaDoc e) {
570             setLastError("Could not disconnect from the database: " + e.toString());
571             return false;
572         }
573         connected = false;
574         setConnected(connected);
575         return true;
576     }
577
578     /**
579      * Description of the Method
580      */

581     public void destroy() {
582
583         poolMgr.release();
584
585     }
586
587     /**
588      * Purpose: The main insertArticle routine.
589      *
590      * @param article
591      * Description of the Parameter
592      * @param approvedBy
593      * Description of the Parameter
594      * @param xmlFileType
595      * Description of the Parameter
596      * @param mappings
597      * Description of the Parameter
598      * @param relatedLinks
599      * Description of the Parameter
600      * @return Description of the Return Value
601      */

602     public final boolean insertArticle(HashMap article, String JavaDoc approvedBy, String JavaDoc xmlFileType, ArrayList mappings, ArrayList relatedLinks) {
603
604         setLastError("");
605         String JavaDoc sqlString = "";
606         Statement sql;
607
608         // check for active connection ;
609
if (!connected) {
610             setLastError("Tried to insert an article with no connection.\n");
611             return false;
612         }
613
614         if (xmlFileType.equals("article")) {
615
616             // Insert new article
617
sqlString = "s_insertArticle " + "'" + CofaxUtil.getString(article, "article:pubName") + "', "
618                     + prepSqlString(CofaxUtil.getString(article, "article:section")) + ", " + prepSqlString(CofaxUtil.getString(article, "article:pubDate"))
619                     + ", " + prepSqlString(CofaxUtil.getString(article, "article:fileName")) + ", " + "'" + approvedBy + "'," + "\n"
620                     + prepSqlString(CofaxUtil.getString(article, "article:headline")) + ", " + "\n"
621                     + prepSqlString(CofaxUtil.getString(article, "article:headline2")) + ", " + "\n"
622                     + prepSqlString(CofaxUtil.getString(article, "article:lead")) + ", " + "\n" + prepSqlString(CofaxUtil.getString(article, "article:byline"))
623                     + ", " + "\n" + prepSqlString(CofaxUtil.getString(article, "article:bycredit")) + ", " + "\n"
624                     + prepSqlString(CofaxUtil.getString(article, "article:dateline")) + ", " + "\n"
625                     + prepSqlString(CofaxUtil.getString(article, "article:body")) + ", " + "\n" + prepSqlString(CofaxUtil.getString(article, "article:memo"))
626                     + ", " + "\n" + prepSqlString(CofaxUtil.getString(article, "article:webHeadline")) + ", " + "\n"
627                     + prepSqlString(CofaxUtil.getString(article, "article:keywords")) + ", " + "\n" + "'', \n"
628                     + prepSqlString(CofaxUtil.getString(article, "article:pubRank")) + ", " + "\n"
629                     + prepSqlString(CofaxUtil.getString(article, "article:pubData")) + ", " + "\n"
630                     + CofaxUtil.getIntegerAsString(article, "article:disableIndex") + ", " + "0, " + "0, "
631                     + prepSqlString(CofaxUtil.getString(article, "article:articleType")) + ", \n"
632                     + CofaxUtil.getIntegerAsString(article, "article:noVersioning") + " \n";
633
634         } else if (xmlFileType.equals("multimediaInfo")) {
635             sqlString = "s_insertRelatedMultimedia " + "'" + CofaxUtil.getString(article, "pubName") + "', "
636                     + prepSqlString(CofaxUtil.getString(article, "section")) + ", " + prepSqlString(CofaxUtil.getString(article, "pubDate")) + ", "
637                     + prepSqlString(CofaxUtil.getString(article, "fileName")) + ", " + prepSqlString(CofaxUtil.getString(article, "type")) + ", " + "\n"
638                     + prepSqlString(CofaxUtil.getString(article, "itemName")) + ", " + "\n" + prepSqlString(CofaxUtil.getString(article, "caption")) + ", "
639                     + "\n" + prepSqlString(CofaxUtil.getString(article, "mimeType")) + ", " + "\n" + CofaxUtil.getString(article, "rank") + "\n";
640
641             return (false);
642         }
643
644         try {
645             sql = connection.createStatement();
646             connection.setCurrentActivity(sqlString);
647             sql.execute(sqlString);
648             ResultSet result = sql.getResultSet();
649             int itemID;
650             if (result.next()) {
651                 itemID = result.getInt(1);
652             } else {
653                 itemID = 0;
654             }
655             result.close();
656
657             sql.close();
658
659             // If we have mappings... insert them
660
if (mappings.size() > 0) {
661                 System.out.println("GOT MAPPINGS FOR ITEMID: " + itemID);
662                 Iterator it = mappings.iterator();
663                 while (it.hasNext()) {
664                     HashMap mapping = (HashMap) it.next();
665                     sqlString = "s_insertMapFromCode " + "'" + CofaxUtil.getString(article, "article:pubName") + "', " + itemID + ", " + "'"
666                             + CofaxUtil.getString(mapping, "map:section") + "', " + CofaxUtil.getString(mapping, "map:rank") + ", " + "'"
667                             + CofaxUtil.getString(mapping, "map:timeStart") + "'," + "'" + CofaxUtil.getString(mapping, "map:timeEnd") + "' \n ";
668
669                     sql = connection.createStatement();
670                     connection.setCurrentActivity(sqlString);
671                     sql.executeUpdate(sqlString);
672                     sql.close();
673                 }
674             }
675
676             // if we have links... insert them
677

678             if (relatedLinks.size() > 0) {
679
680                 System.out.println("GOT LINKS FOR ITEMID: " + itemID);
681
682                 Iterator it = relatedLinks.iterator();
683                 while (it.hasNext()) {
684
685                     HashMap link = (HashMap) it.next();
686                     // First call delete just in case it already exists
687
sqlString = "s_deleteRelatedLinkByItemID " + itemID + ", " + "'" + CofaxUtil.getString(link, "link:url") + "' \n";
688                     sql = connection.createStatement();
689                     connection.setCurrentActivity(sqlString);
690                     sql.executeUpdate(sqlString);
691                     sql.close();
692
693                     // Then insert the link
694
sqlString = "s_insertRelatedLinkByItemID " + itemID + ", " + "'" + CofaxUtil.getString(link, "link:url") + "', " + "'"
695                             + CofaxUtil.getString(link, "link:linkText") + "', " + CofaxUtil.getString(link, "link:rank") + "\n";
696                     sql = connection.createStatement();
697                     connection.setCurrentActivity(sqlString);
698                     sql.executeUpdate(sqlString);
699                     sql.close();
700
701                 }
702
703             }
704
705         } catch (SQLException e) {
706             setLastError("There was an SQL error inserting article: \n" + e.toString() + "\n");
707             return (false);
708         }
709
710         return (true);
711     }
712
713     /**
714      * Logs to a file or to System.out - basic function is to concentrate error
715      * checking.
716      *
717      * @param input
718      * Description of the Parameter
719      */

720     private static void log(String JavaDoc input) {
721         input = "SqlDataStore - " + new java.util.Date JavaDoc() + " - " + input;
722         if (DataStore.dataLog.equals("1")) {
723             if (!DataStore.dataLogLocation.equals("")) {
724                 try {
725                     if (DataStore.dataLogMaxSize > 0) {
726                         File file = new File(DataStore.dataLogLocation);
727                         long fileSize = file.length();
728                         if (fileSize > DataStore.dataLogMaxSize) {
729                             file.delete();
730                         }
731                     }
732                     PrintWriter fileOutputStream = new PrintWriter(new FileWriter(DataStore.dataLogLocation, true));
733                     fileOutputStream.println(input);
734                     fileOutputStream.close();
735                 } catch (IOException e) {
736                     log(e.toString());
737                 }
738             } else {
739                 System.out.println("ODS log: " + input);
740             }
741         }
742     }
743
744     /**
745      * Populates A SQL String with query values from a HashMap when String is
746      * formatted as: select req:value from etc. Duplex method exists for package
747      * tags that have fulfillable values.
748      *
749      * @param ht
750      * Description of the Parameter
751      * @param tag
752      * Description of the Parameter
753      * @return Description of the Return Value
754      */

755     public static String JavaDoc fillToolsTag(HashMap ht, String JavaDoc tag) {
756
757         Iterator keys = ht.keySet().iterator();
758         // First, replace all values that are provided in the hash
759
while (keys.hasNext()) {
760             String JavaDoc key = "";
761             String JavaDoc value = "";
762
763             try {
764                 key = (String JavaDoc) keys.next();
765                 value = ht.get(key).toString();
766                 if (value == null) {
767                     value = "";
768                 }
769             } catch (Exception JavaDoc e) {
770                 log("OracleDataStore fillToolsTag encountered an error in HashMap ht: " + e);
771             }
772
773             int firstPos = 0;
774             int lastPos = 0;
775
776             // check to see which index of space, ", or ' is closest to the tag
777
HashMap hti = checkInstance(tag, key);
778             firstPos = Integer.parseInt((String JavaDoc) hti.get("firstPos"));
779             lastPos = Integer.parseInt((String JavaDoc) hti.get("lastPos"));
780             while (firstPos > -1) {
781
782                 // we never found an ending character for particluar key,
783
// because it wasn't inluded in tag
784
if (firstPos == -1) {
785                     log("searching for key " + key);
786                 }
787
788                 String JavaDoc first = tag.substring(0, firstPos);
789                 String JavaDoc last = tag.substring(lastPos);
790                 value = CofaxUtil.replace(value, "'", "''");
791                 tag = first + value + last;
792
793                 HashMap hto = checkInstance(tag, key);
794                 firstPos = Integer.parseInt((String JavaDoc) hto.get("firstPos"));
795                 lastPos = Integer.parseInt((String JavaDoc) hto.get("lastPos"));
796             }
797         }
798
799         // Any remaining values in the tag? Kill them.
800
int firstPos = tag.indexOf("req:");
801         while (firstPos >= 0) {
802             int nextPos = 0;
803             // check to see which index of space, ", or ' is closest to the tag
804
int whichPos1 = tag.indexOf(" ", firstPos + 1);
805             int whichPos2 = tag.indexOf("\"", firstPos + 1);
806             int whichPos3 = tag.indexOf("\'", firstPos + 1);
807             int whichPos4 = tag.indexOf(",", firstPos + 1);
808             int whichPos5 = tag.indexOf(")", firstPos + 1);
809             int whichPos6 = tag.indexOf(";", firstPos + 1);
810             int whichPos7 = tag.indexOf("\r", firstPos + 1);
811             if (whichPos1 == -1) {
812                 whichPos1 = 1000000;
813             }
814             if (whichPos2 == -1) {
815                 whichPos2 = 1000000;
816             }
817             if (whichPos3 == -1) {
818                 whichPos3 = 1000000;
819             }
820             if (whichPos4 == -1) {
821                 whichPos4 = 1000000;
822             }
823             if (whichPos5 == -1) {
824                 whichPos5 = 1000000;
825             }
826             if (whichPos6 == -1) {
827                 whichPos6 = 1000000;
828             }
829             if (whichPos7 == -1) {
830                 whichPos7 = 1000000;
831             }
832
833             // set the next position to split on to that character
834
if ((whichPos1 < whichPos2) && (whichPos1 < whichPos3) && (whichPos1 < whichPos4) && (whichPos1 < whichPos5) && (whichPos1 < whichPos6)
835                     && (whichPos1 < whichPos7)) {
836                 nextPos = whichPos1;
837             } else if ((whichPos2 < whichPos1) && (whichPos2 < whichPos3) && (whichPos2 < whichPos4) && (whichPos2 < whichPos5) && (whichPos2 < whichPos6)
838                     && (whichPos2 < whichPos7)) {
839                 nextPos = whichPos2;
840             } else if ((whichPos3 < whichPos1) && (whichPos3 < whichPos2) && (whichPos3 < whichPos4) && (whichPos3 < whichPos5) && (whichPos3 < whichPos6)
841                     && (whichPos3 < whichPos7)) {
842                 nextPos = whichPos3;
843             } else if ((whichPos4 < whichPos1) && (whichPos4 < whichPos2) && (whichPos4 < whichPos3) && (whichPos4 < whichPos5) && (whichPos4 < whichPos6)
844                     && (whichPos4 < whichPos7)) {
845                 nextPos = whichPos4;
846             } else if ((whichPos5 < whichPos1) && (whichPos5 < whichPos2) && (whichPos5 < whichPos3) && (whichPos5 < whichPos4) && (whichPos5 < whichPos6)
847                     && (whichPos5 < whichPos7)) {
848                 nextPos = whichPos5;
849             } else if ((whichPos6 < whichPos1) && (whichPos6 < whichPos2) && (whichPos6 < whichPos3) && (whichPos6 < whichPos4) && (whichPos6 < whichPos5)
850                     && (whichPos6 < whichPos7)) {
851                 nextPos = whichPos6;
852             } else if ((whichPos7 < whichPos1) && (whichPos7 < whichPos2) && (whichPos7 < whichPos3) && (whichPos7 < whichPos4) && (whichPos7 < whichPos5)
853                     && (whichPos7 < whichPos6)) {
854                 nextPos = whichPos7;
855             } else {
856                 // malformed tag - we never found an ending character
857
log("ERROR at CofaxToolsDbUtils setTag route 2 = " + "indexEndBoundary: Tag malformed" + tag);
858             }
859             // end if()...
860
String JavaDoc first = tag.substring(0, firstPos);
861             String JavaDoc last = tag.substring(nextPos);
862             tag = first + last;
863             firstPos = tag.indexOf("req:");
864         }
865         return (tag);
866     }
867
868     /**
869      * Description of the Method
870      *
871      * @param tag
872      * Description of the Parameter
873      * @param key
874      * Description of the Parameter
875      * @return Description of the Return Value
876      */

877     public static HashMap checkInstance(String JavaDoc tag, String JavaDoc key) {
878         int firstPos = -1;
879         String JavaDoc temp = "";
880         int firstPos1 = tag.indexOf("req:" + key + " ");
881         int firstPos2 = tag.indexOf("req:" + key + "\"");
882         int firstPos3 = tag.indexOf("req:" + key + "\'");
883         int firstPos4 = tag.indexOf("req:" + key + ",");
884         int firstPos5 = tag.indexOf("req:" + key + ")");
885         int firstPos6 = tag.indexOf("req:" + key + ";");
886         int firstPos7 = tag.indexOf("req:" + key + "\r");
887
888         if (firstPos1 > -1) {
889             firstPos = firstPos1;
890             temp = "req:" + key + " ";
891         } else if (firstPos2 > -1) {
892             firstPos = firstPos2;
893             temp = "req:" + key + "\"";
894         } else if (firstPos3 > -1) {
895             firstPos = firstPos3;
896             temp = "req:" + key + "\'";
897         } else if (firstPos4 > -1) {
898             firstPos = firstPos4;
899             temp = "req:" + key + ",";
900         } else if (firstPos5 > -1) {
901             firstPos = firstPos5;
902             temp = "req:" + key + ")";
903         } else if (firstPos6 > -1) {
904             firstPos = firstPos6;
905             temp = "req:" + key + ";";
906         } else if (firstPos7 > -1) {
907             firstPos = firstPos7;
908             temp = "req:" + key + "\r";
909         }
910         HashMap ht = new HashMap();
911         int lastPos = firstPos + temp.length() - 1;
912         ht.put("lastPos", String.valueOf(lastPos));
913         ht.put("firstPos", String.valueOf(firstPos));
914         return ht;
915     }
916
917     /**
918      * Gets the poolConnectionStats attribute of the SqlDataStore object
919      *
920      * @param name
921      * Description of the Parameter
922      * @return The poolConnectionStats value
923      */

924     public String JavaDoc getPoolConnectionStats(String JavaDoc name) {
925
926         return poolMgr.getConnectionStats(name);
927     }
928
929     /**
930      * Gets the uRL attribute of the SqlDataStore object
931      *
932      * @return The uRL value
933      */

934     public String JavaDoc getURL() {
935         return poolMgr.getURL();
936     }
937
938     /**
939      * Gets the user attribute of the SqlDataStore object
940      *
941      * @return The user value
942      */

943     public String JavaDoc getUser() {
944         return poolMgr.getUser();
945     }
946
947     /**
948      * Gets the password attribute of the SqlDataStore object
949      *
950      * @return The password value
951      */

952     public String JavaDoc getPassword() {
953         return poolMgr.getPassword();
954     }
955
956     /**
957      * Gets the maxConns attribute of the SqlDataStore object
958      *
959      * @return The maxConns value
960      */

961     public int getMaxConns() {
962         return poolMgr.getMaxConns();
963     }
964
965     /**
966      * Gets the initConns attribute of the SqlDataStore object
967      *
968      * @return The initConns value
969      */

970     public int getInitConns() {
971         return poolMgr.getInitConns();
972     }
973
974     /**
975      * Gets the timeOut attribute of the SqlDataStore object
976      *
977      * @return The timeOut value
978      */

979     public int getTimeOut() {
980         return poolMgr.getTimeOut();
981     }
982
983     /**
984      * Gets the conUsageLimit attribute of the SqlDataStore object
985      *
986      * @return The conUsageLimit value
987      */

988     public int getConUsageLimit() {
989         return poolMgr.getConUsageLimit();
990     }
991
992     /**
993      * Gets the killTime attribute of the SqlDataStore object
994      *
995      * @return The killTime value
996      */

997     public long getKillTime() {
998         return poolMgr.getKillTime();
999     }
1000
1001    /**
1002     * Sets the uRL attribute of the SqlDataStore object
1003     *
1004     * @param in
1005     * The new uRL value
1006     */

1007    public void setURL(String JavaDoc in) {
1008        poolMgr.setURL(in);
1009    }
1010
1011    /**
1012     * Sets the user attribute of the SqlDataStore object
1013     *
1014     * @param in
1015     * The new user value
1016     */

1017    public void setUser(String JavaDoc in) {
1018        poolMgr.setUser(in);
1019    }
1020
1021    /**
1022     * Sets the password attribute of the SqlDataStore object
1023     *
1024     * @param in
1025     * The new password value
1026     */

1027    public void setPassword(String JavaDoc in) {
1028        poolMgr.setPassword(in);
1029    }
1030
1031    /**
1032     * Sets the maxConns attribute of the SqlDataStore object
1033     *
1034     * @param in
1035     * The new maxConns value
1036     */

1037    public void setMaxConns(int in) {
1038        poolMgr.setMaxConns(in);
1039    }
1040
1041    /**
1042     * Sets the initConns attribute of the SqlDataStore object
1043     *
1044     * @param in
1045     * The new initConns value
1046     */

1047    public void setInitConns(int in) {
1048        poolMgr.setInitConns(in);
1049    }
1050
1051    /**
1052     * Sets the timeOut attribute of the SqlDataStore object
1053     *
1054     * @param in
1055     * The new timeOut value
1056     */

1057    public void setTimeOut(int in) {
1058        poolMgr.setTimeOut(in);
1059    }
1060
1061    /**
1062     * Sets the conUsageLimit attribute of the SqlDataStore object
1063     *
1064     * @param in
1065     * The new conUsageLimit value
1066     */

1067    public void setConUsageLimit(int in) {
1068        poolMgr.setConUsageLimit(in);
1069    }
1070
1071    /**
1072     * Sets the killTime attribute of the SqlDataStore object
1073     *
1074     * @param in
1075     * The new killTime value
1076     */

1077    public void setKillTime(long in) {
1078        poolMgr.setKillTime(in);
1079    }
1080
1081    public HashMap searchArticles(HashMap htParams) {
1082        HashMap htReturn = new HashMap();
1083        htReturn.put("SQLState", "");
1084        htReturn.put("thisSearch", "");
1085        return htReturn;
1086    }
1087
1088    public String JavaDoc selectPackagetags() {
1089        return ("select TAG_NAME, TAG_VALUE from goon.dbo.tbltoolspackagetags");
1090    }
1091
1092    public String JavaDoc selectPackagetagsCache() {
1093        return ("select TAG_VALUE, CACHE from goon.dbo.tbltoolspackagetags");
1094    }
1095
1096}
1097
Popular Tags