Revision 5186
Added by Jing Tao about 14 years ago
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.