Project

General

Profile

« Previous | Next » 

Revision 1575

Added by Jing Tao about 21 years ago

Add relation handler and access handler here.

View differences:

DocumentImpl.java
1675 1675
          conn.setAutoCommit(true);
1676 1676
          throw e;
1677 1677
        }
1678
                
1678
        // run write into relational db and access db       
1679
        RunRelationHandlerAndAccessHandler(accnum, user, groups, serverCode);
1679 1680
        
1680
        
1681 1681
        // Force replication the docid
1682 1682
        ForceReplicationHandler frh = new ForceReplicationHandler
1683 1683
                                                          (accnum, true, null);
......
1737 1737
      throw e;
1738 1738
    }
1739 1739
    
1740
    // run write into relational db and access db       
1741
    RunRelationHandlerAndAccessHandler(accnum, user, groups, serverCode);
1742
    
1740 1743
    // Force replicate out the new document to each server in our server list.
1741 1744
    // Start the thread to replicate this new document out to the other servers
1742 1745
    // true mean it is xml document
......
1852 1855
      throw e;
1853 1856
    }
1854 1857
    
1858
    // run write into relational db and access db       
1859
    RunRelationHandlerAndAccessHandler(accnum, user, groups, serverCode);
1855 1860
    //Force replication to other server
1856 1861
    ForceReplicationHandler forceReplication = new ForceReplicationHandler
1857 1862
                                  (accnum, action, true, notifyServer);
......
1859 1864

  
1860 1865
    return(accnum);
1861 1866
  }
1862

  
1863 1867
  
1868
  /* Running write record to xml_relation and xml_access*/
1869
  private static void RunRelationHandlerAndAccessHandler(String accnumber, 
1870
                                                  String userName, 
1871
                                                  String[]group, int servercode) 
1872
                                                   throws Exception
1873
  {
1874
    DBConnection dbconn = null;
1875
    int serialNumber = -1;
1876
    PreparedStatement pstmt =null;
1877
    String documenttype = getDocTypeFromDBForCurrentDocument(accnumber);
1878
    try
1879
    {
1880
      String packagedoctype = MetaCatUtil.getOption("packagedoctype");
1881
      Vector packagedoctypes = new Vector();
1882
      packagedoctypes = MetaCatUtil.getOptionList(packagedoctype);
1883
      String docIdWithoutRev = MetaCatUtil.getDocIdFromString(accnumber);
1884
      if (documenttype != null && packagedoctypes.contains(documenttype) )
1885
      {
1886
        dbconn=DBConnectionPool.
1887
           getDBConnection("DocumentImpl.RunRelationHandelerAndAccessHandeler");
1888
        serialNumber=dbconn.getCheckOutSerialNumber();
1889
        dbconn.setAutoCommit(false);
1890
        // write the package info to xml_relation table
1891
        RelationHandler rth = new RelationHandler(docIdWithoutRev, dbconn);
1892
        dbconn.commit();
1893
        // from the relations get the access file id for that package
1894
        String aclid = rth.getAccessFileID(docIdWithoutRev);
1895
        // if there are access file, write ACL for that package
1896
        if ( aclid != null ) 
1897
        {
1898
          runAccessControlList(dbconn, aclid, userName, group, servercode);
1899
        }
1900
        dbconn.commit();
1901
        dbconn.setAutoCommit(true);
1902
      }
1903
        // if it is an access file
1904
      else if ( documenttype != null && MetaCatUtil.getOptionList(
1905
                 MetaCatUtil.getOption("accessdoctype")).contains(documenttype))
1906
      {
1907
        dbconn=DBConnectionPool.
1908
           getDBConnection("DocumentImpl.RunRelationHandelerAndAccessHandeler");
1909
        serialNumber=dbconn.getCheckOutSerialNumber();
1910
        dbconn.setAutoCommit(false);
1911
        // write ACL for the package
1912
        runAccessControlList(dbconn, docIdWithoutRev, 
1913
                             userName, group, servercode);
1914
        dbconn.commit();
1915
        dbconn.setAutoCommit(true);
1916
        
1917
      }
1918
      
1919
    } 
1920
    catch (Exception e) 
1921
    {
1922
      if( dbconn != null)
1923
      {
1924
        dbconn.rollback();
1925
        dbconn.setAutoCommit(true);
1926
      }
1927
      MetaCatUtil.debugMessage("Error in RunRelationHandlerAndAccessHandler " +
1928
                                e.getMessage(), 30);
1929
      throw e;
1930
    }
1931
    finally
1932
    {
1933
      if (dbconn != null)
1934
      {
1935
        DBConnectionPool.returnDBConnection(dbconn, serialNumber);
1936
      }
1937
    }//
1938
  }
1939
  
1940
  // It runs in xmlIndex thread. It writes ACL for a package.
1941
  private static void runAccessControlList (DBConnection conn, String aclid, 
1942
                                    String users, String[]group, int servercode)
1943
                                                throws Exception
1944
  {
1945
    // read the access file from xml_nodes
1946
    // parse the access file and store the access info into xml_access
1947
    AccessControlList aclobj =
1948
    new AccessControlList(conn, aclid, users, group, servercode);
1949
   
1950
  }
1951
  
1952
  /* Method get document type from db*/
1953
  private static String getDocTypeFromDBForCurrentDocument(String accnumber)
1954
                                                  throws SQLException
1955
  {
1956
    String docoumentType = null;
1957
    String docid = null;
1958
    PreparedStatement pstate = null;
1959
    ResultSet rs = null;
1960
    String sql = "SELECT doctype FROM xml_documents where docid = ?";
1961
    DBConnection dbConnection = null;
1962
    int serialNumber = -1;
1963
    try
1964
    {
1965
      //get rid of revision number
1966
      docid = MetaCatUtil.getDocIdFromString(accnumber);
1967
      dbConnection=DBConnectionPool.
1968
           getDBConnection("DocumentImpl.getDocTypeFromDBForCurrentDoc");
1969
      serialNumber=dbConnection.getCheckOutSerialNumber();
1970
      pstate = dbConnection.prepareStatement(sql);
1971
      //bind variable
1972
      pstate.setString(1, docid);
1973
      //excute query
1974
      pstate.execute();
1975
      //handle resultset
1976
      rs = pstate.getResultSet();
1977
      if (rs.next())
1978
      {
1979
        docoumentType = rs.getString(1);
1980
      }
1981
      rs.close();
1982
      pstate.close();
1983
    }//try
1984
    catch (SQLException e)
1985
    {
1986
      MetaCatUtil.debugMessage("error in DocumentImpl."+
1987
                      "getDocTypeFromDBForCurrentDocument "+e.getMessage(), 30);
1988
      throw e;
1989
    }//catch
1990
    finally
1991
    {
1992
      pstate.close();
1993
      DBConnectionPool.returnDBConnection(dbConnection, serialNumber);
1994
    }//
1995
    MetaCatUtil.debugMessage("The current doctype from db is: "+
1996
                              docoumentType, 35);
1997
    return docoumentType;
1998
  }
1864 1999
  /**
1865 2000
   * Delete an XML file from the database (actually, just make it a revision
1866 2001
   * in the xml_revisions table)

Also available in: Unified diff