Revision 5186
Added by Jing Tao almost 15 years ago
src/edu/ucsb/nceas/metacat/DocumentImpl.java | ||
---|---|---|
1984 | 1984 |
// if we couldn't find it in xml_documents we |
1985 | 1985 |
// need to find it in xml_revision table |
1986 | 1986 |
Vector<Integer> revList = DBUtil.getRevListFromRevisionTable(docid); |
1987 |
for (int i=0; i<revList.size(); i++) |
|
1987 |
/*for (int i=0; i<revList.size(); i++)
|
|
1988 | 1988 |
{ |
1989 | 1989 |
// Integer k = (Integer) revList.elementAt(i); |
1990 | 1990 |
// System.out.println("The rev in xml_revision table "+ k.toString()); |
... | ... | |
1993 | 1993 |
if (revList.contains(new Integer(revision))) |
1994 | 1994 |
{ |
1995 | 1995 |
return true; |
1996 |
}*/ |
|
1997 |
if(revList != null && !revList.isEmpty()) |
|
1998 |
{ |
|
1999 |
return true; |
|
1996 | 2000 |
} |
1997 | 2001 |
} |
1998 | 2002 |
// Get miss docid and rev, throw to McdDocNotFoundException |
src/edu/ucsb/nceas/metacat/AccessionNumber.java | ||
---|---|---|
224 | 224 |
pstmt.execute(); |
225 | 225 |
ResultSet rs = pstmt.getResultSet(); |
226 | 226 |
hasCurrentAccNumber = rs.next(); |
227 |
if(!hasCurrentAccNumber) |
|
228 |
{ |
|
229 |
//need to look xml_revision table; |
|
230 |
pstmt = conn.prepareStatement( |
|
231 |
"SELECT 'x' FROM xml_revisions " + |
|
232 |
"WHERE docid = ?"); |
|
233 |
pstmt.setString(1, accNumber); |
|
234 |
pstmt.execute(); |
|
235 |
rs = pstmt.getResultSet(); |
|
236 |
hasCurrentAccNumber = rs.next(); |
|
237 |
} |
|
227 | 238 |
pstmt.close(); |
228 | 239 |
|
229 | 240 |
} catch (SQLException e) { |
... | ... | |
295 | 306 |
|
296 | 307 |
ResultSet rs = pStmt.getResultSet(); |
297 | 308 |
boolean hasRow = rs.next(); |
298 |
rev = rs.getInt(1); |
|
309 |
if(hasRow) |
|
310 |
{ |
|
311 |
rev = rs.getInt(1); |
|
312 |
} |
|
299 | 313 |
pStmt.close(); |
300 | 314 |
|
301 | 315 |
} catch (SQLException e) { |
src/edu/ucsb/nceas/metacat/DBUtil.java | ||
---|---|---|
58 | 58 |
|
59 | 59 |
//private Connection conn = null; |
60 | 60 |
private static Logger logMetacat = Logger.getLogger(DBUtil.class); |
61 |
private static int MAXMUM = -2; |
|
62 |
public static int NONEEXIST = -1; |
|
61 | 63 |
|
62 | 64 |
/** |
63 | 65 |
* main routine used for testing. |
... | ... | |
721 | 723 |
}//if |
722 | 724 |
else |
723 | 725 |
{ |
724 |
// No record, throw a exception |
|
725 |
throw new |
|
726 |
SQLException("DBUtil.getCurrentRevisionAndDocTypeForGivenDocument - " + |
|
727 |
"There is no record for given docid: " + givenDocId); |
|
726 |
//search xml_revision table |
|
727 |
Vector<Integer> revisionList = getRevListFromRevisionTable(docIdWithoutRevision); |
|
728 |
if(revisionList == null || revisionList.isEmpty()) |
|
729 |
{ |
|
730 |
// No record, throw a exception |
|
731 |
throw new |
|
732 |
SQLException("DBUtil.getCurrentRevisionAndDocTypeForGivenDocument - " + |
|
733 |
"There is no record for given docid: " + givenDocId); |
|
734 |
} |
|
735 |
else |
|
736 |
{ |
|
737 |
int maxRev = getMaxmumNumber(revisionList); |
|
738 |
if(maxRev == MAXMUM) |
|
739 |
{ |
|
740 |
throw new |
|
741 |
SQLException("DBUtil.getCurrentRevisionAndDocTypeForGivenDocument - " + |
|
742 |
"There is no record for given docid: " + givenDocId); |
|
743 |
} |
|
744 |
revision = (new Integer(maxRev)).toString(); |
|
745 |
sqlCommand = "select doctype from xml_revisions where docid like '"+docIdWithoutRevision+"' and rev="+maxRev; |
|
746 |
pstmt = dbConn.prepareStatement(sqlCommand); |
|
747 |
// Execute the prepared statement |
|
748 |
pstmt.execute(); |
|
749 |
// Get result set |
|
750 |
rs = pstmt.getResultSet(); |
|
751 |
// If there is some record |
|
752 |
if (rs.next()) |
|
753 |
{ |
|
754 |
docType = rs.getString(1); |
|
755 |
}//if |
|
756 |
} |
|
757 |
|
|
728 | 758 |
}//else |
729 | 759 |
|
730 | 760 |
} |
... | ... | |
753 | 783 |
return revision+";"+docType; |
754 | 784 |
}//getCurrentRevisionAndDocTypeForGivenDocument |
755 | 785 |
|
786 |
/* |
|
787 |
* Gets the maxium number in a given vector. |
|
788 |
*/ |
|
789 |
private static int getMaxmumNumber(Vector<Integer>list) |
|
790 |
{ |
|
791 |
Integer max = null; |
|
792 |
if(list != null) |
|
793 |
{ |
|
794 |
for(int i=0; i<list.size(); i++) |
|
795 |
{ |
|
796 |
if(i ==0) |
|
797 |
{ |
|
798 |
max = list.elementAt(i); |
|
799 |
} |
|
800 |
else |
|
801 |
{ |
|
802 |
if(max == null) |
|
803 |
{ |
|
804 |
max = list.elementAt(i); |
|
805 |
} |
|
806 |
else |
|
807 |
{ |
|
808 |
Integer current = list.elementAt(i); |
|
809 |
if(current != null && current.intValue() > max.intValue()) |
|
810 |
{ |
|
811 |
max = current; |
|
812 |
} |
|
813 |
} |
|
814 |
} |
|
815 |
} |
|
816 |
} |
|
817 |
if(max != null) |
|
818 |
{ |
|
819 |
return max.intValue(); |
|
820 |
} |
|
821 |
else |
|
822 |
{ |
|
823 |
return MAXMUM; |
|
824 |
} |
|
825 |
} |
|
826 |
|
|
756 | 827 |
/** |
757 | 828 |
* Method to return a rev list in xml_revision for given docid. |
758 | 829 |
* @param docId |
... | ... | |
836 | 907 |
rev = rs.getInt(1); |
837 | 908 |
pStmt.close(); |
838 | 909 |
} else { |
839 |
rev = -1;
|
|
910 |
rev = NONEEXIST;
|
|
840 | 911 |
pStmt.close(); |
841 | 912 |
} |
842 | 913 |
}//try |
... | ... | |
853 | 924 |
|
854 | 925 |
return rev; |
855 | 926 |
} |
856 |
|
|
927 |
|
|
928 |
|
|
857 | 929 |
} |
Also available in: Unified diff
Fix the bug of http://bugzilla.ecoinformatics.org/show_bug.cgi?id=4645. handleGetRevisionAndDocTypeAction will search both xml_documents and xml_revisions table.
It also changed some constrain in AccessionNumber when user update a document, of which all previous versions are in xml_revisions table.