Project

General

Profile

« Previous | Next » 

Revision 1217

Added by Jing Tao almost 22 years ago

Merge DBConnection branch to head.

View differences:

DBSAXHandler.java
58 58
   private boolean 	stackCreated = false;
59 59
   private Stack 	  nodeStack;
60 60
   private Vector   nodeIndex;
61
   private Connection	  conn = null;
61
   private DBConnection	  connection = null;
62 62
   private DocumentImpl currentDocument;
63 63
   private DBSAXNode    rootNode;
64 64
   private String   action = null;
......
80 80
    *
81 81
    * @param conn the JDBC connection to which information is written
82 82
    */
83
   public DBSAXHandler(Connection conn) {
84
     this.conn = conn;
83
   public DBSAXHandler(DBConnection conn) {
84
     this.connection = conn;
85 85
     this.atFirstElement = true;
86 86
     this.processingDTD = false;
87 87

  
......
106 106
    *        resides.
107 107
    *
108 108
    */
109
   public DBSAXHandler(Connection conn, String action, String docid, 
109
   public DBSAXHandler(DBConnection conn, String action, String docid, 
110 110
                      String user, String[] groups, String pub, int serverCode)
111 111
   {
112 112
     this(conn);
......
133 133
    *        resides.
134 134
    *
135 135
    */
136
   public DBSAXHandler(Connection conn, String action, String docid, 
136
   public DBSAXHandler(DBConnection conn, String action, String docid, 
137 137
     String revision, String user, String[] groups, String pub, int serverCode)
138 138
   {
139 139
     this(conn);
......
152 152
     MetaCatUtil.debugMessage("start Document", 50);
153 153

  
154 154
     // Create the document node representation as root
155
     rootNode = new DBSAXNode(conn, this.docid);
155
     rootNode = new DBSAXNode(connection, this.docid);
156 156
     // Add the node to the stack, so that any text data can be 
157 157
     // added as it is encountered
158 158
     nodeStack.push(rootNode);
......
214 214
       rootNode.writeNodename(docname);
215 215
       try {
216 216
         // for validated XML Documents store a reference to XML DB Catalog
217
         // Because this is select statement and it needn't to roll back if
218
         // insert document action fialed.
219
         // In order to decrease DBConnection usage count, we get a new 
220
         // dbconnection from pool
217 221
         String catalogid = null;
222
         DBConnection dbConn = null;
223
         int serialNumber = -1;
224
         
218 225
         if ( systemid != null ) {
219
           Statement stmt = conn.createStatement();
220
           ResultSet rs = stmt.executeQuery(
226
           try
227
           {
228
            // Get dbconnection
229
            dbConn=DBConnectionPool.getDBConnection
230
                                          ("DBSAXHandler.startElement");
231
            serialNumber=dbConn.getCheckOutSerialNumber();
232
            
233
            Statement stmt = dbConn.createStatement();
234
            ResultSet rs = stmt.executeQuery(
221 235
                          "SELECT catalog_id FROM xml_catalog " +
222 236
                          "WHERE entry_type = 'DTD' " + 
223 237
                          "AND public_id = '" + doctype + "'");
224
           boolean hasRow = rs.next();
225
           if ( hasRow ) {
226
            catalogid = rs.getString(1);
227
           }
228
           stmt.close();
238
            boolean hasRow = rs.next();
239
            if ( hasRow ) {
240
              catalogid = rs.getString(1);
241
            }
242
            stmt.close();
243
           }//try
244
           finally
245
           {
246
             // Return dbconnection
247
             DBConnectionPool.returnDBConnection(dbConn, serialNumber);
248
           }//finally
229 249
         }
230 250
         
231 251
         //create documentImpl object by the constructor which can specify
232 252
         //the revision
233
         currentDocument = new DocumentImpl(conn, rootNode.getNodeID(), 
253
         currentDocument = new DocumentImpl(connection, rootNode.getNodeID(), 
234 254
                               docname, doctype, docid, revision, action, user, 
235 255
                               this.pub, catalogid, this.serverCode);
236 256
         
......
242 262
     }      
243 263

  
244 264
     // Create the current node representation
245
     currentNode = new DBSAXNode(conn, qName, localName, parentNode,
265
     currentNode = new DBSAXNode(connection, qName, localName, parentNode,
246 266
                                 currentDocument.getRootNodeID(),docid,
247 267
                                 currentDocument.getDoctype());
248 268
                               
......
275 295
  public void run () {
276 296
    DBSAXNode currNode = null;
277 297
    DBSAXNode prevNode = null;
278
    Connection dbconn = null;
298
    DBConnection dbConn = null;
299
    int serialNumber = -1;
279 300
    String doctype = currentDocument.getDoctype();
280 301
    int step = 0;
281 302
    int counter = 0;
282 303

  
283 304
    try {
305
      
284 306
      // Opening separate db connection for writing XML Index
285
      MetaCatUtil util = new MetaCatUtil();
286
      dbconn = util.openDBConnection();
287
      dbconn.setAutoCommit(false);
307
      dbConn=DBConnectionPool.getDBConnection("DBSAXHandler.run");
308
      serialNumber=dbConn.getCheckOutSerialNumber();
309
      dbConn.setAutoCommit(false);
288 310
      
289 311
      //the following while loop construct checks to make sure that the docid
290 312
      //of the document that we are trying to index is already
......
296 318
      {
297 319
        String xmlDocumentsCheck = "select distinct docid from xml_documents";
298 320
        PreparedStatement xmlDocCheck = 
299
                                  dbconn.prepareStatement(xmlDocumentsCheck);
321
                                 dbConn.prepareStatement(xmlDocumentsCheck);
322
        // Increase usage count
323
        dbConn.increaseUsageCount(1);
300 324
        xmlDocCheck.execute();
301 325
        ResultSet doccheckRS = xmlDocCheck.getResultSet();
302 326
        boolean tableHasRows = doccheckRS.next();
......
322 346
      Enumeration nodes = nodeIndex.elements();
323 347
      while ( nodes.hasMoreElements() ) {
324 348
        currNode = (DBSAXNode)nodes.nextElement();
325
        currNode.updateNodeIndex(dbconn, docid, doctype);
349
        currNode.updateNodeIndex(dbConn, docid, doctype);
326 350
      }
351
      
327 352
    
328
      dbconn.commit();
353
      dbConn.commit();
329 354
         
330 355
      //if this is a package file
331
      String packagedoctype = util.getOption("packagedoctype");
356
      String packagedoctype = MetaCatUtil.getOption("packagedoctype");
332 357
      Vector packagedoctypes = new Vector();
333 358
      
334 359
      packagedoctypes = MetaCatUtil.getOptionList(packagedoctype);
......
336 361
      if ( packagedoctypes.contains(doctype) )
337 362
      {
338 363
        // write the package info to xml_relation table
339
        RelationHandler rth = new RelationHandler(docid, dbconn);
364
        RelationHandler rth = new RelationHandler(docid, dbConn);
340 365
        // from the relations get the access file id for that package
341 366
        String aclid = rth.getAccessFileID(docid);
342 367
        // if there are access file, write ACL for that package
343 368
        if ( aclid != null ) {
344
          runAccessControlList(dbconn, aclid);
369
          runAccessControlList(dbConn, aclid);
345 370
        }
371
        
346 372
      }
373
      
347 374
      // if it is an access file
348 375
      else if ( MetaCatUtil.getOptionList(
349
                            util.getOption("accessdoctype")).contains(doctype) )
376
                     MetaCatUtil.getOption("accessdoctype")).contains(doctype) )
350 377
      {
351 378
        // write ACL for the package
352
        runAccessControlList(dbconn, docid);
379
        runAccessControlList(dbConn, docid);
380
        
353 381
      }
382
     
354 383
      
355
      dbconn.close();
384
      //dbconn.close();
356 385

  
357 386
    } catch (Exception e) {
358 387
      try {
359
        dbconn.rollback();
360
        dbconn.close();
388
        dbConn.rollback();
389
        //dbconn.close();
361 390
      } catch (SQLException sqle) {}
362 391
      System.out.println("Error in DBSAXHandler.run " + e.getMessage());
363 392
      e.printStackTrace();
364
    }      
393
    }
394
    finally
395
    {
396
      DBConnectionPool.returnDBConnection(dbConn, serialNumber);
397
    }//finally      
365 398
  }
366 399
  
367 400
  // It runs in xmlIndex thread. It writes ACL for a package.
368
  private void runAccessControlList (Connection conn, String aclid)
401
  private void runAccessControlList (DBConnection conn, String aclid)
369 402
                                                throws Exception
370 403
  {
371 404
    // read the access file from xml_nodes

Also available in: Unified diff