Project

General

Profile

« Previous | Next » 

Revision 2702

Added by Jing Tao over 18 years ago

Add code to handle write record into xml_documents when catalog id is null.

View differences:

src/edu/ucsb/nceas/metacat/DocumentImpl.java
1911 1911
            if (action.equals("INSERT")) {
1912 1912
                //AccessionNumber ac = new AccessionNumber();
1913 1913
                //this.docid = ac.generate(docid, "INSERT");
1914
                
1915
                pstmt = connection
1914
                String sql = null;
1915
                if (catalogid != null )
1916
                {
1917
                	sql = "INSERT INTO xml_documents "
1918
                        + "(docid, rootnodeid, docname, doctype, user_owner, "
1919
                        + "user_updated, date_created, date_updated, "
1920
                        + "public_access, server_location, rev, catalog_id) "
1921
                        + "VALUES (?, ?, ?, ?, ?, ?, " + createDate + ", "
1922
                        + updateDate + ", ?, ?, ?, ?)";
1923
                }
1924
                else
1925
                {
1926
                	sql = "INSERT INTO xml_documents "
1927
                        + "(docid, rootnodeid, docname, doctype, user_owner, "
1928
                        + "user_updated, date_created, date_updated, "
1929
                        + "public_access, server_location, rev) "
1930
                        + "VALUES (?, ?, ?, ?, ?, ?, " + createDate + ", "
1931
                        + updateDate + ", ?, ?, ?)";
1932
                }
1933
                /*pstmt = connection
1916 1934
                        .prepareStatement("INSERT INTO xml_documents "
1917 1935
                        + "(docid, rootnodeid, docname, doctype, user_owner, "
1918 1936
                        + "user_updated, date_created, date_updated, "
1919 1937
                        + "public_access, catalog_id, server_location, rev) "
1920 1938
                        + "VALUES (?, ?, ?, ?, ?, ?, " + createDate + ", "
1921
                        + updateDate + ", ?, ?, ?, ?)");
1939
                        + updateDate + ", ?, ?, ?, ?)");*/
1940
                pstmt = connection.prepareStatement(sql);
1922 1941
                // Increase dbconnection usage count
1923 1942
                connection.increaseUsageCount(1);
1924 1943
                
......
1942 1961
                 * pub.toUpperCase().equals("NO") || pub.equals("0") ) {
1943 1962
                 * pstmt.setInt(7, 0); }
1944 1963
                 */
1945
                pstmt.setInt(8, (new Integer(catalogid)).intValue());
1946
                pstmt.setInt(9, serverCode);
1947
                pstmt.setInt(10, rev);
1964
                pstmt.setInt(8, serverCode);
1965
                pstmt.setInt(9, rev);
1966
               
1967
                if (catalogid != null)
1968
                {
1969
                  pstmt.setInt(10, (new Integer(catalogid)).intValue());
1970
                }
1948 1971
                
1972
                
1949 1973
            } else if (action.equals("UPDATE")) {
1950 1974
                int thisrev = DBUtil.getLatestRevisionInDocumentTable(docid);
1951 1975
                logMetacat.info("this revsion is: " + thisrev);
......
1983 2007
                }
1984 2008

  
1985 2009
                // Update the new document to reflect the new node tree
1986
                pstmt = connection
2010
                String updateSql = null;
2011
                if (catalogid != null)
2012
                {
2013
                	updateSql = "UPDATE xml_documents "
2014
                        + "SET rootnodeid = ?, docname = ?, doctype = ?, "
2015
                        + "user_updated = ?, date_updated = "
2016
                        + updateDate
2017
                        + ", "
2018
                        + "server_location = ?, rev = ?, public_access = ?, "
2019
                        + "catalog_id = ? "
2020
                        + "WHERE docid = ?";
2021
                }
2022
                else
2023
                {
2024
                	updateSql = "UPDATE xml_documents "
2025
                        + "SET rootnodeid = ?, docname = ?, doctype = ?, "
2026
                        + "user_updated = ?, date_updated = "
2027
                        + updateDate
2028
                        + ", "
2029
                        + "server_location = ?, rev = ?, public_access = ? "
2030
                        + "WHERE docid = ?";
2031
                }
2032
                /*pstmt = connection
1987 2033
                        .prepareStatement("UPDATE xml_documents "
1988 2034
                        + "SET rootnodeid = ?, docname = ?, doctype = ?, "
1989 2035
                        + "user_updated = ?, date_updated = "
......
1991 2037
                        + ", "
1992 2038
                        + "server_location = ?, rev = ?, public_access = ?, "
1993 2039
                        + "catalog_id = ? "
1994
                        + "WHERE docid = ?");
2040
                        + "WHERE docid = ?");*/
1995 2041
                // Increase dbconnection usage count
2042
                pstmt = connection.prepareStatement(updateSql);
1996 2043
                connection.increaseUsageCount(1);
1997 2044
                // Bind the values to the query
1998 2045
                pstmt.setLong(1, rootnodeid);
......
2008 2055
                 * .setInt(7, 1); } else if ( pub.toUpperCase().equals("NO") ||
2009 2056
                 * pub.equals("0") ) { pstmt.setInt(7, 0); }
2010 2057
                 */
2011
                pstmt.setInt(8, (new Integer(catalogid)).intValue());
2012
                pstmt.setString(9, this.docid);
2058
                if (catalogid != null)
2059
                {
2060
                  pstmt.setInt(8, (new Integer(catalogid)).intValue());
2061
                  pstmt.setString(9, this.docid);
2062
                }
2063
                else
2064
                {
2065
                  pstmt.setString(8, this.docid);
2066
                }
2013 2067

  
2014 2068
            } else {
2015 2069
                System.err.println("Action not supported: " + action);

Also available in: Unified diff