Adding getIDs new method in Query

http://sourceforge.net/tracker2/?func=detail&aid=2493023&group_id=176962&atid=879335
This commit is contained in:
vpj-cd 2009-01-08 00:50:24 +00:00
parent 98ec121b73
commit a278c88d62
1 changed files with 38 additions and 0 deletions

View File

@ -501,5 +501,43 @@ public class Query
}
return pstmt.executeQuery();
}
/**
* Get a Array with the IDs for this Query
* @return Get a Array with the IDs
*/
public int[] getIDs ()
{
ArrayList<Integer> list = new ArrayList<Integer>();
StringBuffer sql = new StringBuffer("SELECT ");
sql.append(table.getTableName()).append("_ID FROM ").append(table.getTableName());
if (whereClause != null && whereClause.length() > 0)
sql.append(" WHERE ").append(whereClause);
PreparedStatement pstmt = null;
ResultSet rs = null;
try
{
pstmt = DB.prepareStatement(sql.toString(), trxName);
rs = createResultSet(pstmt);
while (rs.next())
list.add(new Integer(rs.getInt(1)));
}
catch (SQLException e)
{
log.log(Level.SEVERE, sql.toString(), e);
return null;
}
finally {
DB.close(rs, pstmt);
rs = null; pstmt = null;
}
// Convert to array
int[] retValue = new int[list.size()];
for (int i = 0; i < retValue.length; i++)
retValue[i] = ((Integer)list.get(i)).intValue();
return retValue;
} // get_IDs
}