Apama 10.15.0 | Developing Apama Applications | Developing Apama Applications in EPL | Using EPL Plug-ins | Using the MemoryStore | Steps for using the MemoryStore | Creating and removing rows
 
Creating and removing rows
To create a row in a table, call the get() or add() action on the table to which you want to add the row. The action declaration for the get() action is as follows:
action get(string key) returns Row
The Table.get() action returns a Row event that represents the row in the table that has the specified key. If there is no row with the specified key, this action returns a Row event that represents a row that contains default values. A call to the Row.inTable() action returns false. For example:
boolean done := false;
integer n := -1;
while not done {
   Row row := tbl.get("example-row");
   n := row.getInteger("times_run");
   row.setInteger("times_run", n+1);
   done := row.tryCommit();
}
send Result(
"This example has been run " +n.toString() +" time(s) before")
to "output";
The add() action does the same as the get() action, except that it does not check if the row that is to be added already exists in the table until commit() is called and it therefore never throws an exception. If you are sure that the row does not yet exist, you can use add() as this is faster than get().
To remove a row from a table, call the Table.remove() action on the table that contains the row. The action declaration is as follows:
action remove(string key)
The Table.remove() action removes the row with the specified key from the table. If the row does not exist, this action does nothing.
It is also possible to remove a row transactionally, by calling Table.get() and then Row.remove() and Row.commit(). This strategy lets you check the row's state before removal. The Row.commit() action fails if the shared, in-memory row has been updated since the Table.get() action.
In some circumstances, using Row.remove() is essential to guarantee correctness. For example, when decrementing a usage counter in the row and removing the row when the count reaches zero. Otherwise, another correlator context might re-increment the count between it reaching zero and the row being removed.