Project

General

Profile

« Previous | Next » 

Revision 2646

Added by Jing Tao about 19 years ago

Fixed bug couldn't delete xml_nodes when moving to xml_nodes_revision in replication.

View differences:

src/edu/ucsb/nceas/metacat/DocumentImpl.java
1950 1950
                // Save the old document publicaccessentry in a backup table
1951 1951
                String accNumber = docid+MetaCatUtil.getOption("accNumSeparator")+thisrev;
1952 1952
                thisdoc = new DocumentImpl(accNumber, false);
1953
                DocumentImpl.archiveDocRevision(connection, docid, user, thisdoc);
1953
                DocumentImpl.archiveDocAndNodesRevision(connection, docid, user, thisdoc);
1954 1954
                MetaCatUtil.debugMessage("after archiveDoc", 30);
1955 1955
                //if the updated vesion is not greater than current one,
1956 1956
                //throw it into a exception
......
2019 2019
            
2020 2020
            pstmt.close();
2021 2021
            if(action.equals("UPDATE")){
2022
                // Delete the old nodes in xml_nodes table...
2022
                /*// Delete the old nodes in xml_nodes table...
2023 2023
                pstmt = connection.prepareStatement("DELETE FROM xml_nodes "
2024 2024
                                                + "WHERE rootnodeid = ?");
2025 2025
                // Increase dbconnection usage count
......
2027 2027
                // Bind the values to the query and execute it
2028 2028
                pstmt.setLong(1, thisdoc.getRootNodeID());
2029 2029
                pstmt.execute();
2030
                pstmt.close();
2030
                pstmt.close();*/
2031
                deleteXMLNodes(connection, thisdoc.getRootNodeID());
2031 2032
            }
2032 2033

  
2033 2034
        } catch (SQLException sqle) {
......
2389 2390

  
2390 2391
        // insert into xml_nodes table
2391 2392
        XMLReader parser = null;
2393
        boolean isRevision = false;
2392 2394
        try {
2393
            boolean isRevision = false;
2395
            
2394 2396
            if (tableName.equals(REVISIONTABLE))
2395 2397
            {
2396 2398
                isRevision = true;
......
2432 2434

  
2433 2435
        // run write into access db base on relation table and access rule
2434 2436
        try {
2435
        	conn.setAutoCommit(false);
2436
            if (!tableName.equals(REVISIONTABLE))
2437
            conn.setAutoCommit(false);
2438
            if (!isRevision)
2437 2439
            {
2438 2440
               runRelationAndAccessHandler(accnum, user, groups, serverCode);
2439 2441
            }
......
2443 2445
              // we need to move nodes from xml_nodes to xml_nodes_revision and register the record
2444 2446
            	// into xml_revision table
2445 2447
               moveNodesToNodesRevision(conn, rootId);
2448
               deleteXMLNodes(conn, rootId);
2446 2449
               writeDocumentToRevisionTable(conn, docid, rev, docType, docName, user, 
2447 2450
                       catalogId, serverCode, rootId, createDate, updateDate);
2451
              
2448 2452
            }
2453
            conn.commit();
2454
            conn.setAutoCommit(true);
2449 2455
            
2450 2456
        } catch (Exception ee) {
2451 2457
        	conn.rollback();
......
2454 2460
            {
2455 2461
                // because we couldn't register the table into xml_revsion
2456 2462
                // we need to delete the nodes in xml_ndoes.
2457
                deleteXMLNodes(rootId);
2463
                deleteXMLNodes(conn, rootId);
2458 2464
            }
2459 2465
            MetacatReplication.replErrorLog("Failed to " + "create access "
2460 2466
                    + "rule for package: " + accnum + " because "
......
2655 2661

  
2656 2662
            conn.setAutoCommit(false);
2657 2663
            // Copy the record to the xml_revisions table
2658
            DocumentImpl.archiveDocRevision(conn, docid, user, null);
2664
            DocumentImpl.archiveDocAndNodesRevision(conn, docid, user, null);
2659 2665

  
2660 2666
            // Now delete it from the xml_index table
2661 2667
            boolean useXMLIndex = (new Boolean(MetaCatUtil
......
2959 2965
    }
2960 2966

  
2961 2967
    /**
2962
     * Save a document entry in the xml_revisions table Connection use as a
2968
     * Save a document entry in the xml_revisions and xml_nodes_revision
2969
     *  table Connection use as a
2963 2970
     * paramter is in order to rollback feature
2964 2971
     */
2965
    private static void archiveDocRevision(DBConnection dbconn, String docid,
2972
    private static void archiveDocAndNodesRevision(DBConnection dbconn, String docid,
2966 2973
            String user, DocumentImpl doc)
2967 2974
    {
2968 2975
        
......
3055 3062
    private static void moveNodesToNodesRevision(DBConnection dbconn,
3056 3063
                                       long rootNodeId) throws Exception
3057 3064
    {
3065
        MetaCatUtil.debugMessage("the root node id is "+rootNodeId+
3066
                " will be moved from xml_nodes to xml_node_revision table", 20);
3058 3067
        PreparedStatement pstmt = null;
3059 3068
        // Move the nodes from xml_nodes to xml_revisions table...
3060 3069
        pstmt = dbconn.prepareStatement("INSERT INTO xml_nodes_revisions "
......
3069 3078
        pstmt.setLong(1, rootNodeId);
3070 3079
        pstmt.execute();
3071 3080
        pstmt.close();
3081
        
3072 3082

  
3073 3083
    }
3074 3084

  
......
3525 3535
        
3526 3536
        try 
3527 3537
        {
3538
            
3528 3539
            if (createDate == null)
3529 3540
            {
3530 3541
                createDate = dbAdapter.getDateTimeFunction();
......
3533 3544
            {
3534 3545
                createDate = dbAdapter.toDate(createDate, "YYYY-MM-DD HH24:MI:SS");
3535 3546
            }
3547
            MetaCatUtil.debugMessage("the create date is "+createDate, 30);
3536 3548
            if (updateDate == null)
3537 3549
            {
3538 3550
                updateDate = dbAdapter.getDateTimeFunction();
......
3541 3553
            {
3542 3554
                updateDate = dbAdapter.toDate(updateDate, "YYYY-MM-DD HH24:MI:SS");
3543 3555
            }
3556
            MetaCatUtil.debugMessage("the update date is "+updateDate, 30);
3544 3557
            PreparedStatement pstmt = null;
3545 3558
            String sql = null;
3559
            MetaCatUtil.debugMessage("the root node id is "+rootNodeId, 20);
3546 3560
            if (rootNodeId <= 0)
3547 3561
            {
3548 3562
            	// this is for data file, not rootnodeid need
......
3568 3582

  
3569 3583
            // Bind the values to the query
3570 3584
            pstmt.setString(1, docId);
3585
            MetaCatUtil.debugMessage("docid is "+docId, 50);
3571 3586
            pstmt.setString(2, docName);
3587
            MetaCatUtil.debugMessage("docname is "+docName, 50);
3572 3588
            pstmt.setString(3, docType);
3589
            MetaCatUtil.debugMessage("docType is "+docType, 50);
3573 3590
            pstmt.setString(4, user);
3591
            MetaCatUtil.debugMessage("onwer is "+user, 50);
3574 3592
            pstmt.setString(5, user);
3593
            MetaCatUtil.debugMessage("update user is "+user, 50);
3575 3594
            pstmt.setInt(6, 0);
3576 3595
            pstmt.setInt(7, (new Integer(catalogid)).intValue());
3596
            MetaCatUtil.debugMessage("catalogid is "+catalogid, 50);
3577 3597
            pstmt.setInt(8, serverCode);
3598
            MetaCatUtil.debugMessage("server code is "+serverCode, 50);
3578 3599
            pstmt.setInt(9, Integer.parseInt(rev));
3600
            MetaCatUtil.debugMessage("rev is "+rev, 50);
3579 3601
            
3580 3602
            if (rootNodeId >0 )
3581 3603
            {
3582 3604
              pstmt.setLong(10, rootNodeId);
3605
              MetaCatUtil.debugMessage("root id is "+rootNodeId, 50);
3583 3606
            }
3584 3607
            // Do the insertion
3585 3608
            pstmt.execute();
3586 3609
            pstmt.close();
3587

  
3610
            MetaCatUtil.debugMessage("end of write into revisons", 50);
3588 3611
           
3589 3612
        } 
3590 3613
        catch (SQLException sqle) 
......
3594 3617
        } 
3595 3618
        catch (Exception e) 
3596 3619
        {
3620
            e.printStackTrace();
3597 3621
            throw e;
3598 3622
        }
3599 3623
    }
......
3643 3667
     * if in the second step some error happend, we need to delete the
3644 3668
     * node in xml_nodes table as roll back
3645 3669
     */
3646
    static private void deleteXMLNodes(long rootId) throws Exception
3670
    static private void deleteXMLNodes(DBConnection dbconn, long rootId) throws Exception
3647 3671
    {
3648
        DBConnection dbconn = null;
3649
        int serialNumber = -1;
3650 3672
        //MetaCatUtil util = new MetaCatUtil();
3651 3673
        AccessionNumber ac;
3652 3674
        PreparedStatement pstmt = null;
3653
        String sql = "DELETE FROM xml_documents WHERE docid = "+ rootId;
3654
        try 
3655
        {
3656
            //dbconn = util.openDBConnection();
3657
            dbconn = DBConnectionPool.getDBConnection(
3658
                    "DeletedDocumentImpl.deletXMLNode");
3659
            serialNumber = dbconn.getCheckOutSerialNumber();
3660
            pstmt = dbconn.prepareStatement(sql);
3661
            // Increase dbconnection usage count
3662
            dbconn.increaseUsageCount(1);
3663
            pstmt.close();
3664
            dbconn.close();
3665
        } 
3666
        finally 
3667
        {
3668
            
3669
            DBConnectionPool.returnDBConnection(dbconn, serialNumber);
3670
        }
3675
        String sql = "DELETE FROM xml_nodes WHERE rootnodeid ="+ rootId;
3676
        pstmt = dbconn.prepareStatement(sql);
3677
        // Increase dbconnection usage count
3678
        dbconn.increaseUsageCount(1);
3679
        pstmt.execute();
3680
        pstmt.close(); 
3681
     
3671 3682
    }
3672 3683
}

Also available in: Unified diff