Developing Apama Applications > Developing Apama Applications in EPL > Using Correlator Plug-ins in EPL > Using the MemoryStore > Creating and removing rows
Creating and removing rows
To create a row in a table, call the get() action on the table you want to add the row to. The action declaration 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();
}
emit "This example has been run " +n.toString() +" time(s) before";
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.
Copyright © 2013 Software AG, Darmstadt, Germany and/or Software AG USA Inc., Reston, VA, USA, and/or Terracotta Inc., San Francisco, CA, USA, and/or Software AG (Canada) Inc., Cambridge, Ontario, Canada, and/or, Software AG (UK) Ltd., Derby, United Kingdom, and/or Software A.G. (Israel) Ltd., Or-Yehuda, Israel and/or their licensors.