Improved store-description and primary key usage in mongodb-store sample
/*
Purpose:
- This application demonstrates how to perform CRUD operations using Siddhi queries in mongo stores. The sample depicts a scenario in a sweet production factory. The sweet production details such as name of the raw material, amount used for production can be stored using insertSweetProductionStream. The existing data can be searched, deleted, updated, update or insert can be performed using following streams.
+This application demonstrates how to perform CRUD operations using Siddhi queries in mongo stores. The sample depicts a scenario in a sweet production factory. The sweet production details such as name of the raw material, amount used for production can be stored using insertSweetProductionStream. The following streams can be used to search, delete, update or upsert(update or insert) the existing data in the store.
Search - searchSweetProductionStream
delete - deleteSweetProductionStream
update - updateSweetProductionStream
@@ -31,6 +31,8 @@ Testing the Sample:
2) Send at-least one event with the single event simulator, where the name matches a name value in the data we previously inserted to the SweetProductionTable. This would satisfy the 'on' condition of our join query.
3) Likewise the events can be sent to the other corresponding streams to add, delete, update, insert, search events.
4) After a change in the store, using the search stream the developer can see whether the operation is successful.
+ 5) Primary Key constraint SweetProductionTable is disabled, since name cannot be used as a PrimaryKey in ProductionTable.
+ Siddhi functions can be used to create a unique id for the received events which can then be used to apply Primary Key constraint on the data store records. (http://wso2.github.io/siddhi/documentation/siddhi-4.0/#function)
Viewing the Results:
See the output for raw materials on the console. Inserted, deleted, updated events can be checked by searchSweetProductionStream.
@@ -42,7 +44,6 @@ Viewing the Results:
@App:description('Receive events via simulator and received data are persisted in store.')
define stream insertSweetProductionStream (name string, amount double);
-
define stream deleteSweetProductionStream (name string);
define stream searchSweetProductionStream (name string);
define stream updateSweetProductionStream (name string, amount double);
@@ -53,7 +54,7 @@ define stream containsSweetProductionStream (name string, amount double);
define stream logStream(name string, amount double);
@Store(type="mongodb",mongodb.uri='mongodb://localhost/production')
-@PrimaryKey("name")
+/* @PrimaryKey("name") */
@IndexBy("amount {background:true,unique:true}")
define table SweetProductionTable (name string, amount double);
