Revision 9307
Added by Jing Tao over 9 years ago
src/edu/ucsb/nceas/metacat/IdentifierManager.java | ||
---|---|---|
1697 | 1697 |
ObjectList ol = new ObjectList(); |
1698 | 1698 |
DBConnection dbConn = null; |
1699 | 1699 |
int serialNumber = -1; |
1700 |
PreparedStatement countStmt=null; |
|
1701 |
ResultSet totalResult=null; |
|
1702 |
PreparedStatement fieldStmt = null; |
|
1703 |
ResultSet rs= null; |
|
1700 | 1704 |
|
1701 | 1705 |
try { |
1702 | 1706 |
String fieldSql = "select guid, date_uploaded, rights_holder, checksum, " |
... | ... | |
1708 | 1712 |
|
1709 | 1713 |
// the clause |
1710 | 1714 |
String whereClauseSql = ""; |
1715 |
|
|
1711 | 1716 |
|
1712 | 1717 |
boolean f1 = false; |
1713 | 1718 |
boolean f2 = false; |
... | ... | |
1786 | 1791 |
String orderBySql = " order by guid "; |
1787 | 1792 |
String fieldQuery = fieldSql + whereClauseSql + orderBySql; |
1788 | 1793 |
String finalQuery = DatabaseService.getInstance().getDBAdapter().getPagedQuery(fieldQuery, start, count); |
1789 |
PreparedStatement fieldStmt = dbConn.prepareStatement(finalQuery);
|
|
1794 |
fieldStmt = dbConn.prepareStatement(finalQuery); |
|
1790 | 1795 |
|
1791 | 1796 |
// construct the count query and statment |
1792 | 1797 |
String countQuery = countSql + whereClauseSql; |
1793 |
PreparedStatement countStmt = dbConn.prepareStatement(countQuery);
|
|
1798 |
countStmt = dbConn.prepareStatement(countQuery); |
|
1794 | 1799 |
|
1795 | 1800 |
if (f1 && f2 && f3 && f4) { |
1796 | 1801 |
fieldStmt.setTimestamp(1, new Timestamp(startTime.getTime())); |
... | ... | |
1896 | 1901 |
|
1897 | 1902 |
// get the total object count no matter what |
1898 | 1903 |
int total = 0; |
1899 |
ResultSet totalResult = countStmt.executeQuery();
|
|
1904 |
totalResult = countStmt.executeQuery(); |
|
1900 | 1905 |
if (totalResult.next()) { |
1901 | 1906 |
total = totalResult.getInt(1); |
1902 | 1907 |
} |
... | ... | |
1906 | 1911 |
// set the totals |
1907 | 1912 |
ol.setStart(start); |
1908 | 1913 |
ol.setCount(count); |
1909 |
ol.setTotal(total); |
|
1910 | 1914 |
|
1911 | 1915 |
// retrieve the actual records if requested |
1912 | 1916 |
if (count != 0) { |
1913 | 1917 |
|
1914 |
ResultSet rs = fieldStmt.executeQuery();
|
|
1918 |
rs = fieldStmt.executeQuery(); |
|
1915 | 1919 |
while (rs.next()) { |
1916 | 1920 |
|
1917 | 1921 |
String guid = rs.getString(1); |
... | ... | |
1959 | 1963 |
oi.setFormatId(fmtid); |
1960 | 1964 |
|
1961 | 1965 |
oi.setSize(size); |
1962 |
|
|
1966 |
|
|
1963 | 1967 |
ol.addObjectInfo(oi); |
1964 | 1968 |
|
1965 | 1969 |
} |
1966 | 1970 |
|
1967 | 1971 |
logMetacat.debug("list objects count: " + ol.sizeObjectInfoList()); |
1968 |
|
|
1969 | 1972 |
// set the actual count retrieved |
1970 | 1973 |
ol.setCount(ol.sizeObjectInfoList()); |
1974 |
ol.setTotal(total); |
|
1971 | 1975 |
|
1972 | 1976 |
} |
1973 | 1977 |
|
1974 |
} |
|
1975 |
|
|
1976 |
finally { |
|
1978 |
} finally { |
|
1977 | 1979 |
// Return database connection to the pool |
1980 |
try { |
|
1981 |
if(totalResult !=null ){ |
|
1982 |
totalResult.close(); |
|
1983 |
} |
|
1984 |
if(countStmt!=null ) { |
|
1985 |
countStmt.close(); |
|
1986 |
} |
|
1987 |
if(rs != null) { |
|
1988 |
rs.close(); |
|
1989 |
} |
|
1990 |
if(fieldStmt != null) { |
|
1991 |
fieldStmt.close(); |
|
1992 |
} |
|
1993 |
|
|
1994 |
} catch (SQLException sql) { |
|
1995 |
|
|
1996 |
} |
|
1978 | 1997 |
DBConnectionPool.returnDBConnection(dbConn, serialNumber); |
1998 |
|
|
1979 | 1999 |
} |
1980 |
|
|
2000 |
if(ol != null) { |
|
2001 |
logMetacat.debug("list objects start(before returning): " + ol.getStart()); |
|
2002 |
logMetacat.debug("list objects count: " + ol.getCount()); |
|
2003 |
logMetacat.debug("list objects total: " + ol.getTotal()); |
|
2004 |
} |
|
1981 | 2005 |
return ol; |
1982 | 2006 |
} |
1983 | 2007 |
|
Also available in: Unified diff
Fixed a bug the total was not correct in the querySystemMetadata method.