Project

General

Profile

1
/**
2
 *  '$RCSfile$'
3
 *    Purpose: A class to asyncronously do delta-T replication checking
4
 *  Copyright: 2000 Regents of the University of California and the
5
 *             National Center for Ecological Analysis and Synthesis
6
 *    Authors: Chad Berkley
7
 *    Release: @release@
8
 *
9
 *   '$Author: tao $'
10
 *     '$Date: 2002-07-14 12:33:25 -0700 (Sun, 14 Jul 2002) $'
11
 * '$Revision: 1292 $'
12
 *
13
 * This program is free software; you can redistribute it and/or modify
14
 * it under the terms of the GNU General Public License as published by
15
 * the Free Software Foundation; either version 2 of the License, or
16
 * (at your option) any later version.
17
 *
18
 * This program is distributed in the hope that it will be useful,
19
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21
 * GNU General Public License for more details.
22
 *
23
 * You should have received a copy of the GNU General Public License
24
 * along with this program; if not, write to the Free Software
25
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
26
 */
27
 
28
package edu.ucsb.nceas.metacat;
29

    
30
import java.sql.*;
31
import java.util.*;
32
import java.lang.Thread; 
33
import java.io.*;
34
import java.net.*;
35
import java.text.*;
36
import org.xml.sax.AttributeList;
37
import org.xml.sax.ContentHandler;
38
import org.xml.sax.DTDHandler;
39
import org.xml.sax.EntityResolver;
40
import org.xml.sax.ErrorHandler;
41
import org.xml.sax.InputSource;
42
import org.xml.sax.XMLReader;
43
import org.xml.sax.SAXException;
44
import org.xml.sax.SAXParseException;
45
import org.xml.sax.helpers.XMLReaderFactory;
46
import org.xml.sax.helpers.DefaultHandler;
47

    
48

    
49

    
50
/**
51
 * This class handles deltaT replication checking.  Whenever this TimerTask
52
 * is fired it checks each server in xml_replication for updates and updates
53
 * the local db as needed.
54
 */
55
public class ReplicationHandler extends TimerTask
56
{
57
  int serverCheckCode = 1;
58
  MetaCatUtil util = new MetaCatUtil();
59
  ReplicationServerList serverList = null; 
60
  PrintWriter out;
61
  
62
  public ReplicationHandler(PrintWriter o)
63
  {
64
    this.out = o;
65
    serverList = new ReplicationServerList();
66
  }
67
  
68
  public ReplicationHandler(PrintWriter o, int serverCheckCode)
69
  {
70
    this.out = o;
71
    this.serverCheckCode = serverCheckCode;
72
    serverList = new ReplicationServerList();
73
  }
74
  
75
  /**
76
   * Method that implements TimerTask.run().  It runs whenever the timer is 
77
   * fired.
78
   */
79
  public void run()
80
  {
81
    //find out the last_checked time of each server in the server list and
82
    //send a query to each server to see if there are any documents in 
83
    //xml_documents with an update_date > last_checked
84
    try
85
    {
86
      //if serverList is null, metacat don't need to replication
87
      if (serverList==null||serverList.isEmpty())
88
      {
89
        return;
90
      }
91
      updateCatalog();
92
      update();
93
      //conn.close();
94
    }//try
95
    catch (Exception e)
96
    {
97
      MetaCatUtil.debugMessage("Error in replicationHandler.run():"
98
                                                    +e.getMessage(), 30);
99
      e.printStackTrace();
100
    }//catch
101
  }
102
  
103
  /**
104
   * Method that uses revision taging for replication instead of update_date.
105
   */
106
  private void update()
107
  {
108
    /*
109
     Pseudo-algorithm
110
     - request a doc list from each server in xml_replication
111
     - check the rev number of each of those documents agains the 
112
       documents in the local database
113
     - pull any documents that have a lesser rev number on the local server
114
       from the remote server
115
     - delete any documents that still exist in the local xml_documents but
116
       are in the deletedDocuments tag of the remote host response.
117
     - update last_checked to keep track of the last time it was checked.
118
       (this info is theoretically not needed using this system but probably 
119
       should be kept anyway)
120
    */
121
    
122
    DBConnection dbConn = null;
123
    int serialNumber = -1;
124
   
125
    ReplicationServer replServer = null; // Variable to store the 
126
                                        // ReplicationServer got from 
127
                                        // Server list
128
    String server; // Variable to store server name
129
    String update;
130
    ReplMessageHandler message = new ReplMessageHandler();
131
    Vector responses = new Vector();
132
    PreparedStatement pstmt = null;
133
    ResultSet rs;
134
    boolean tablehasrows;
135
    boolean flag=false; // If a document need to update
136
    boolean dataFile=false;
137
    String action = new String();
138
    XMLReader parser;
139
    URL u;
140
    
141
    try
142
    {
143
      // Get DBConnection from pool
144
      dbConn=DBConnectionPool.
145
                  getDBConnection("ReplicationHandler.update");
146
      serialNumber=dbConn.getCheckOutSerialNumber();
147
      MetaCatUtil.debugMessage("init parser", 50);
148
      parser = initParser(message);
149
      //Check for every server in server list
150
      for (int i=0; i<serverList.size(); i++)
151
      {
152
        // Get ReplicationServer object from server list
153
        replServer = serverList.serverAt(i);
154
        // Get server name from ReplicationServer object
155
        server = replServer.getServerName();
156
        MetacatReplication.replLog("full update started to: " + server);
157
        // Send command to that server to get updated docid information
158
        u = new URL("https://" + server + "?server="
159
        +util.getLocalReplicationServerName()+"&action=update");
160
        MetaCatUtil.debugMessage("Sending infomation " +u.toString(), 50);
161
        // Get information from remote server
162
        String result = null;
163
        try
164
        {
165
          result = MetacatReplication.getURLContent(u);
166
        }//try
167
        catch (Exception e)
168
        {
169
          
170
          MetaCatUtil.debugMessage("Error in get docid information from "+
171
                                server+" :"+e.getMessage(), 30);
172
          continue;
173
        }//catch
174
        MetaCatUtil.debugMessage("docid: "+server+" "+result, 50);
175
        //check if result have error or not, if has skip it.
176
        if (result.indexOf("error")!=-1)
177
        {
178
          continue;
179
        }
180
        responses.add(result);
181
      }
182
      
183
      //make sure that there is updated file list
184
      //If response is null, metacat don't need do anything
185
       if (responses==null||responses.isEmpty())
186
      {
187
        return;
188
      }
189
     
190
      
191
      MetaCatUtil.debugMessage("Responses from remote metacat about updated "+
192
                   "document information: "+ responses.toString(), 30);
193
      
194
      for(int i=0; i<responses.size(); i++)
195
      { //check each server for updated files
196
        parser.parse(new InputSource(
197
                     new StringReader(
198
                     (String)(responses.elementAt(i)))));
199
        //v is the list of updated documents
200
        Vector v = new Vector(message.getUpdatesVect());
201
        //System.out.println("v: " + v.toString());
202
        //d is the list of deleted documents
203
        Vector d = new Vector(message.getDeletesVect());
204
        //System.out.println("d: " + d.toString());
205
        MetaCatUtil.debugMessage("Update vector size: "+ v.size(), 40);
206
        MetaCatUtil.debugMessage("Delete vector size: "+ d.size(),40);
207
        //check the revs in u to see if there are any newer ones than
208
        //in the local DB.
209
        for(int j=0; j<v.size(); j++)
210
        {
211
          //initial dataFile is false
212
          dataFile=false;
213
          //w is information for one document, information contain
214
          //docid, rev, server or datafile.
215
          Vector w = new Vector((Vector)(v.elementAt(j)));
216
          //Check if the vector w contain "datafile"
217
          //If it has, this document is data file
218
          if (w.contains((String)util.getOption("datafileflag")))
219
          {
220
            dataFile=true;
221
          }
222
          //System.out.println("w: " + w.toString());
223
          // Get docid
224
          String docid = (String)w.elementAt(0);
225
          MetaCatUtil.debugMessage("docid: " + docid, 40);
226
          // Get revision number
227
          int rev = Integer.parseInt((String)w.elementAt(1));
228
          MetaCatUtil.debugMessage("rev: " + rev, 40);
229
          // Get remote server name (it is may not be doc homeserver because
230
          // the new hub feature
231
          String remoteServer = (String)w.elementAt(2);
232
          
233
          // Choose revision number from local host
234
          pstmt = dbConn.prepareStatement("select rev from xml_documents where "
235
                                            + "docid like '" + docid + "'");
236
          pstmt.execute();
237
          rs = pstmt.getResultSet();
238
          tablehasrows = rs.next();
239
          if(tablehasrows)
240
          { //check the revs for an update because this document is in the
241
            //local DB, it might be out of date.
242
            int localrev = rs.getInt(1);
243
            if(localrev == rev)
244
            {
245
              // Local meatacat has the same rev to remote host, don't need 
246
              // update and flag set false
247
              flag = false;
248
            }
249
            else if(localrev < rev)
250
            {//this document needs to be updated so send an read request
251
              action = "UPDATE";
252
              flag = true;
253
            }
254
          }
255
          else
256
          { //insert this document as new because it is not in the local DB
257
            action = "INSERT";
258
            flag = true;
259
          }
260
          
261
          // Close result set
262
          rs.close();
263
          // Close preparedstatement
264
          pstmt.close();
265
          
266
          // this is non-data file
267
          if(flag && !dataFile)
268
          { //if the document needs to be updated or inserted, this is executed
269
            u = new URL("https://" + remoteServer + "?server="+
270
              util.getLocalReplicationServerName()+"&action=read&docid="+docid);
271
            //System.out.println("Sending message: " + u.toString());
272
            // Get docid content
273
            String newxmldoc = MetacatReplication.getURLContent(u);
274
            // If couldn't get skip it
275
            if ( newxmldoc.indexOf("error")!= -1)
276
            {
277
              continue;
278
            }
279
            MetaCatUtil.debugMessage("xml documnet:", 50);
280
            MetaCatUtil.debugMessage(newxmldoc, 50);
281
            
282
            // Try get the docid info from remote server
283
            DocInfoHandler dih = new DocInfoHandler();
284
            XMLReader docinfoParser = initParser(dih);
285
            URL docinfoUrl = new URL("https://" + remoteServer + 
286
                  "?server="+util.getLocalReplicationServerName()+
287
                  "&action=getdocumentinfo&docid="+docid);
288
            MetaCatUtil.debugMessage("Sending message: " + 
289
                                                  docinfoUrl.toString(), 50);
290
            String docInfoStr = MetacatReplication.getURLContent(docinfoUrl);
291
            docinfoParser.parse(new InputSource(new StringReader(docInfoStr)));
292
            Hashtable docinfoHash = dih.getDocInfo();
293
            // Get home server of the docid
294
            String docHomeServer = (String)docinfoHash.get("home_server");
295
                
296
            //docid should include rev number too
297
            String accnum=docid+util.getOption("accNumSeparator")+
298
                                              (String)docinfoHash.get("rev");
299
            try
300
            {
301
              // Write the document into local host
302
              String newDocid = DocumentImpl.writeReplication(dbConn, 
303
                              new StringReader(newxmldoc),
304
                              (String)docinfoHash.get("public_access"),
305
                              null,  /* the dtd text */
306
                              action, 
307
                              accnum, 
308
                              (String)docinfoHash.get("user_owner"),
309
                              null, /* null for groups[] */
310
                              docHomeServer, 
311
                              false /* validate */,
312
                              remoteServer);
313
              //increase usage
314
              dbConn.increaseUsageCount(1);
315
              MetacatReplication.replLog("wrote doc " + docid + " from " + 
316
                                         remoteServer);
317
              /*System.out.println("wrote doc " + docid + " from " + 
318
                                 docServer);*/
319
            }
320
            catch(Exception e)
321
            {
322
              System.out.println("error writing document in " + 
323
                                 "ReplicationHandler.update: " + docid +
324
                                 ": " + e.getMessage());
325
            }
326
          }//if for non-data file
327
          
328
           // this is for data file
329
          if(flag && dataFile)
330
          { 
331
            //if the document needs to be updated or inserted, this is executed
332
            
333
            // Try get docid info from remote server
334
            DocInfoHandler dih = new DocInfoHandler();
335
            XMLReader docinfoParser = initParser(dih);
336
            URL docinfoUrl = new URL("https://" + remoteServer + 
337
                  "?server="+util.getLocalReplicationServerName()+
338
                  "&action=getdocumentinfo&docid="+docid);
339
            
340
            String docInfoStr = MetacatReplication.getURLContent(docinfoUrl);
341
            docinfoParser.parse(new InputSource(new StringReader(docInfoStr)));
342
            Hashtable docinfoHash = dih.getDocInfo();
343
            // Get doicd owner
344
            String user = (String)docinfoHash.get("user_owner");
345
            // Get docid name (such as acl or dataset)
346
            String docName = (String)docinfoHash.get("docname");
347
            // Get doc type (eml public id) 
348
            String docType = (String)docinfoHash.get("doctype");
349
            // Get docid home sever. it might be different to remoteserver
350
            // becuause of hub feature
351
            String docHomeServer = (String)docinfoHash.get("home_server");
352
         
353
            //System.out.println("updating doc: " + docid +" action: "+ action);
354
            //docid should include rev number too
355
            String accnum=docid+util.getOption("accNumSeparator")+
356
                                              (String)docinfoHash.get("rev");
357
            String datafilePath = util.getOption("datafilepath");
358
            // Get data file content
359
            u = new URL("https://" + remoteServer + "?server="+
360
                                        util.getLocalReplicationServerName()+
361
                                            "&action=readdata&docid="+accnum);
362
           
363
            try
364
            {
365
              //register data file into xml_documents table and wite data file
366
              //into file system
367
              if (u.openStream() != null)
368
              {
369
                DocumentImpl.writeDataFileInReplication(u.openStream(), 
370
                                                        datafilePath, 
371
                                                        docName,docType, 
372
                                                        accnum, user,
373
                                                        docHomeServer,
374
                                                        remoteServer);
375
              
376
                MetacatReplication.replLog("wrote doc " + docid + " from " + 
377
                                         remoteServer);
378
              }//if
379
              else
380
              {
381
                // If get null, skip it
382
                continue;
383
              }//else
384
            
385
            }//try
386
            catch(Exception e)
387
            {
388
              System.out.println("error writing document in " + 
389
                                 "ReplicationHandler.update: " + docid +
390
                                 ": " + e.getMessage());
391
            }//catch
392
          }//for datafile
393
        }//for update docs
394
        
395
        //handle deleted docs
396
        for(int k=0; k<d.size(); k++)
397
        { //delete the deleted documents;
398
          Vector w = new Vector((Vector)d.elementAt(k));
399
          String docid = (String)w.elementAt(0);
400
          if(!alreadyDeleted(docid))
401
          {
402
          
403
            //because delete method docid should have rev number
404
            //so we just add one for it. This rev number is no sence.
405
            String accnum=docid+util.getOption("accNumSeparator")+"1";
406
            //System.out.println("accnum: "+accnum);
407
            DocumentImpl.delete(accnum, null, null);
408
            MetacatReplication.replLog("doc " + docid + " deleted");
409
          }
410
        }//for delete docs
411
      }//for
412
      
413
      //updated last_checked
414
      for (int i=0;i<serverList.size(); i++)
415
      {
416
          // Get ReplicationServer object from server list
417
          replServer = serverList.serverAt(i);
418
          // Get server name from ReplicationServer object
419
          server = replServer.getServerName();
420
          // Get time from remote server
421
          URL dateurl = new URL("https://" + server + "?server="+
422
          util.getLocalReplicationServerName()+"&action=gettime");
423
          String datexml = MetacatReplication.getURLContent(dateurl);
424
          MetaCatUtil.debugMessage("datexml: "+datexml, 40);
425
          if (datexml!=null && !datexml.equals(""))
426
          {
427
            String datestr = datexml.substring(11, datexml.indexOf('<', 11));
428
            StringBuffer sql = new StringBuffer();
429
            sql.append("update xml_replication set last_checked = to_date('");
430
            sql.append(datestr).append("', 'YY-MM-DD HH24:MI:SS') where ");
431
            sql.append("server like '").append(server).append("'");
432
            //System.out.println("sql: " + sql.toString());
433
            pstmt.close();
434
            pstmt = dbConn.prepareStatement(sql.toString());
435
            //increase usage count
436
            dbConn.increaseUsageCount(1);
437
            pstmt.executeUpdate();
438
            dbConn.commit();
439
            MetaCatUtil.debugMessage("last_checked updated to "+datestr+" on " 
440
                                      + server, 45);
441
          }//if
442
      }//for
443
    }//try
444
    catch(Exception e)
445
    {
446
      /*System.out.println("error in ReplicationHandler.update: " + 
447
                          e.getMessage());*/
448
      e.printStackTrace(System.out);
449
    }
450
    finally
451
    {
452
      try
453
      {
454
        
455
          pstmt.close();
456
       
457
      }//try
458
      catch(Exception ee) 
459
      {
460
        MetaCatUtil.debugMessage("Error in ReplicationHandler.update to close"+
461
                                " pstmt: "+ee.getMessage(), 30);
462
      }//catch
463
      finally
464
      {
465
        DBConnectionPool.returnDBConnection(dbConn, serialNumber);
466
      }//finally
467
    }//finally
468
  }//update
469
  
470
  /**
471
   * updates xml_catalog with entries from other servers.
472
   */
473
  private void updateCatalog()
474
  {
475
    // DConnection
476
    DBConnection dbConn = null;
477
    // DBConnection checkout serial number
478
    int serialNumber = -1;
479
    // ReplicationServer object in server list
480
    ReplicationServer replServer = null;
481
    PreparedStatement pstmt = null;
482
    try
483
    {
484

    
485
      dbConn=DBConnectionPool.
486
                  getDBConnection("ReplicationHandler.updateCatalog");
487
      serialNumber=dbConn.getCheckOutSerialNumber();
488
      String server;
489
      
490
      // Go through each ReplicationServer object in sererlist
491
      for (int j=0; j<serverList.size(); j++)
492
      { 
493
        // Get ReplicationServer object from server list
494
        replServer = serverList.serverAt(j);
495
        // Get server name from the ReplicationServer object
496
        server = replServer.getServerName();
497
        // Try to get catalog
498
        URL u = new URL("https://" + server + "?server="+
499
        util.getLocalReplicationServerName()+"&action=getcatalog");
500
        MetaCatUtil.debugMessage("sending message " + u.toString(), 50);
501
        String catxml = MetacatReplication.getURLContent(u);
502
        
503
        // Make sure there are not error, no empty string
504
        if (catxml.indexOf("error")!=-1 || catxml==null||catxml.equals(""))
505
        {
506
          continue;
507
        }
508
        MetaCatUtil.debugMessage("catxml: " + catxml, 50);
509
        CatalogMessageHandler cmh = new CatalogMessageHandler();
510
        XMLReader catparser = initParser(cmh);
511
        catparser.parse(new InputSource(new StringReader(catxml)));
512
        //parse the returned catalog xml and put it into a vector
513
        Vector remoteCatalog = cmh.getCatalogVect();
514
        
515
        // Makse sure remoteCatalog is not empty
516
        if (remoteCatalog.isEmpty())
517
        {
518
          continue;
519
        }
520
        
521
        String localcatxml = MetacatReplication.getCatalogXML();
522
        
523
        // Make sure local catalog is no empty
524
        if (localcatxml==null||localcatxml.equals(""))
525
        {
526
          continue;
527
        }
528
        
529
        cmh = new CatalogMessageHandler();
530
        catparser = initParser(cmh);
531
        catparser.parse(new InputSource(new StringReader(localcatxml)));
532
        Vector localCatalog = cmh.getCatalogVect();
533
        
534
        //now we have the catalog from the remote server and this local server
535
        //we now need to compare the two and merge the differences.
536
        //the comparison is base on the public_id fields which is the 4th
537
        //entry in each row vector.
538
        Vector publicId = new Vector();
539
        for(int i=0; i<localCatalog.size(); i++)
540
        {
541
          Vector v = new Vector((Vector)localCatalog.elementAt(i));
542
          MetaCatUtil.debugMessage("v1: " + v.toString(), 50);
543
          publicId.add(new String((String)v.elementAt(3)));
544
          //System.out.println("adding " + (String)v.elementAt(3));
545
        }
546
        
547
        for(int i=0; i<remoteCatalog.size(); i++)
548
        {
549
          Vector v = (Vector)remoteCatalog.elementAt(i);
550
          //System.out.println("v2: " + v.toString());
551
          //System.out.println("i: " + i);
552
          //System.out.println("remoteCatalog.size(): " + remoteCatalog.size());
553
          //System.out.println("publicID: " + publicId.toString());
554
          MetaCatUtil.debugMessage
555
                              ("v.elementAt(3): " + (String)v.elementAt(3), 50);
556
          if(!publicId.contains(v.elementAt(3)))
557
          { //so we don't have this public id in our local table so we need to
558
            //add it.
559
            //System.out.println("in if");
560
            StringBuffer sql = new StringBuffer();
561
            sql.append("insert into xml_catalog (entry_type, source_doctype, ");
562
            sql.append("target_doctype, public_id, system_id) values (?,?,?,");
563
            sql.append("?,?)");
564
            //System.out.println("sql: " + sql.toString());
565
            pstmt = dbConn.prepareStatement(sql.toString());
566
            //increase usage count 1
567
            dbConn.increaseUsageCount(1);
568
            pstmt.setString(1, (String)v.elementAt(0));
569
            pstmt.setString(2, (String)v.elementAt(1));
570
            pstmt.setString(3, (String)v.elementAt(2));
571
            pstmt.setString(4, (String)v.elementAt(3));
572
            pstmt.setString(5, (String)v.elementAt(4));
573
            pstmt.execute();
574
            pstmt.close();
575
          }
576
        }
577
      }
578
     
579
    }
580
    catch(Exception e)
581
    {
582
      System.out.println("error in ReplicationHandler.updateCatalog: " + 
583
                          e.getMessage());
584
      e.printStackTrace(System.out);
585
    }//catch
586
    finally
587
    {
588
      DBConnectionPool.returnDBConnection(dbConn, serialNumber);
589
    }//finall
590
  }
591
  
592
  /**
593
   * Method that returns true if docid has already been "deleted" from metacat.
594
   * This method really implements a truth table for deleted documents
595
   * The table is (a docid in one of the tables is represented by the X):
596
   * xml_docs      xml_revs      deleted?
597
   * ------------------------------------
598
   *   X             X             FALSE
599
   *   X             _             FALSE
600
   *   _             X             TRUE
601
   *   _             _             TRUE
602
   */
603
  private static boolean alreadyDeleted(String docid)
604
  {
605
    DBConnection dbConn = null;
606
    int serialNumber = -1;
607
    PreparedStatement pstmt = null;
608
    try
609
    {
610
      dbConn=DBConnectionPool.
611
                  getDBConnection("ReplicationHandler.alreadyDeleted");
612
      serialNumber=dbConn.getCheckOutSerialNumber();
613
      boolean xml_docs = false;
614
      boolean xml_revs = false;
615
      
616
      StringBuffer sb = new StringBuffer();
617
      sb.append("select docid from xml_revisions where docid like '");
618
      sb.append(docid).append("'");
619
      pstmt = dbConn.prepareStatement(sb.toString());
620
      pstmt.execute();
621
      ResultSet rs = pstmt.getResultSet();
622
      boolean tablehasrows = rs.next();
623
      if(tablehasrows)
624
      {
625
        xml_revs = true;
626
      }
627
      
628
      sb = new StringBuffer();
629
      sb.append("select docid from xml_documents where docid like '");
630
      sb.append(docid).append("'");
631
      pstmt.close();
632
      pstmt = dbConn.prepareStatement(sb.toString());
633
      //increase usage count
634
      dbConn.increaseUsageCount(1);
635
      pstmt.execute();
636
      rs = pstmt.getResultSet();
637
      tablehasrows = rs.next();
638
      pstmt.close();
639
      if(tablehasrows)
640
      {
641
        xml_docs = true;
642
      }
643
      
644
      if(xml_docs && xml_revs)
645
      {
646
        return false;
647
      }
648
      else if(xml_docs && !xml_revs)
649
      {
650
        return false;
651
      }
652
      else if(!xml_docs && xml_revs)
653
      {
654
        return true;
655
      }
656
      else if(!xml_docs && !xml_revs)
657
      {
658
        return true;
659
      }
660
    }
661
    catch(Exception e)
662
    {
663
      System.out.println("error in ReplicationHandler.alreadyDeleted: " + 
664
                          e.getMessage());
665
      e.printStackTrace(System.out);
666
    }
667
    finally
668
    {
669
      try
670
      {
671
        pstmt.close();
672
      }//try
673
      catch (SQLException ee)
674
      {
675
        MetaCatUtil.debugMessage("Error in replicationHandler.alreadyDeleted "+
676
                          "to close pstmt: "+ee.getMessage(), 30);
677
      }//catch
678
      finally
679
      {
680
        DBConnectionPool.returnDBConnection(dbConn, serialNumber);
681
      }//finally
682
    }//finally
683
    return false;
684
  }
685

    
686
  
687
  /**
688
   * Method to initialize the message parser
689
   */
690
  public static XMLReader initParser(DefaultHandler dh)
691
          throws Exception
692
  {
693
    XMLReader parser = null;
694

    
695
    try {
696
      ContentHandler chandler = dh;
697

    
698
      // Get an instance of the parser
699
      MetaCatUtil util = new MetaCatUtil();
700
      String parserName = util.getOption("saxparser");
701
      parser = XMLReaderFactory.createXMLReader(parserName);
702

    
703
      // Turn off validation
704
      parser.setFeature("http://xml.org/sax/features/validation", false);
705
      
706
      parser.setContentHandler((ContentHandler)chandler);
707
      parser.setErrorHandler((ErrorHandler)chandler);
708

    
709
    } catch (Exception e) {
710
      throw e;
711
    }
712

    
713
    return parser;
714
  }
715
  
716
 
717
}
718
   
(43-43/46)