Simplified IN Operator Usage
Parameter for IN operator is a collection.
ArrayList<Integer> partNumbers = new ArrayList<Integer>();
partNumbers.add(999);
partNumbers.add(777);
partNumbers.add(1234);
System.out.println("selectIn partNumbers=" + partNumbers);
// set up
Database database = new Database(getConnection());
Table<Inventory> inventoryTable = database.getTable(Inventory.class);
// select operation for list "...WHERE PARTNUMBER IN (?, ?, ?)..."
for (Inventory inventory: inventoryTable.
selectAllWhere("partNumberIn", partNumbers))
{
System.out.println(inventory.getPartNumber());
}
Inventory.java
@Where(name="partNumberIn",
whereFields=@WhereField(name="partNumber", comparisonOperator="IN"))
public class Inventory
{
@Column(primaryKey=true)
int partNumber;
int quantity;
String manufacturerId;
getters/setters...
}
INVENTORY schema and Inventory.java used by this example.
See SimpleExample.java class in the Simple Example download.
|