IDEMPIERE-96 Implement DB.getIDsEx

http://jira.idempiere.com/browse/IDEMPIERE-96
This commit is contained in:
Carlos Ruiz 2011-11-10 15:45:44 -05:00
parent 33f5898aab
commit 7792142bc3
1 changed files with 41 additions and 1 deletions

View File

@ -1768,6 +1768,47 @@ public final class DB
return retValue; return retValue;
} // getKeyNamePairs } // getKeyNamePairs
/**
* Get Array of IDs
* @param trxName
* @param sql select with id as first column
* @param params query parameters
* @throws DBException if there is any SQLException
*/
public static int[] getIDsEx(String trxName, String sql, Object ... params) throws DBException
{
PreparedStatement pstmt = null;
ResultSet rs = null;
ArrayList<Integer> list = new ArrayList<Integer>();
try
{
pstmt = DB.prepareStatement(sql, trxName);
setParameters(pstmt, params);
rs = pstmt.executeQuery();
while (rs.next())
{
list.add(rs.getInt(1));
}
}
catch (SQLException e)
{
throw new DBException(e, sql);
}
finally
{
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] = list.get(i);
}
return retValue;
} // getIDsEx
/** /**
* Is Sales Order Trx. * Is Sales Order Trx.
* Assumes Sales Order. Queries IsSOTrx of table with where clause * Assumes Sales Order. Queries IsSOTrx of table with where clause
@ -2395,4 +2436,3 @@ public final class DB
} }
} // DB } // DB