(Quick Reference)

Plugin Datastore Service

The datastore service service is provided to allow a plugin to persist data to the database that is isolated from all other persistent data. In other words, this service provides access to a plugin's Individual Datastore.

The pluginDatastoreService property will be injected with a class of type IPluginDatastoreService in all plugin types.

Examples

Adding a Single Custom Entry
package example

public class ExamplePlugin { def pluginDatastoreService

public void poll() { def collectionName = "collection1" def data = [:] … // Add data here to the Map if (pluginDatastoreService.addData(collectionName, data)) log.info("Data successfully added") else log.warn("There was an error adding the data") } }

Adding Multiple Entries
package example

public class ExamplePlugin { def pluginDatastoreService

public void poll() { def collectionName = "collection1" def dataList = [] dataList.add( /* Custom Map of data here */) dataList << … // Custom Map of data here if (pluginDatastoreService.addData(collectionName, dataList)) log.info("Data entries successfully added") else log.warn("There was an error adding the data entries") } }

Updating A Single Entry
package example

public class ExamplePlugin { def pluginDatastoreService

public void poll() { def collectionName = "collection1" def data = [:] … // Add data here to the Map if (pluginDatastoreService.updateData(collectionName, "key", "value", data)) log.info("Data successfully updated") else log.warn("There was an error updating the data") } }

Querying if a Collection Exists
package example

public class ExamplePlugin { def pluginDatastoreService

public void poll() { def collectionName = "collection1" if (pluginDatastoreService.exists(collectionName)) log.info("Collection exists") else log.warn("The collection does not exist") } }

Querying Contents of a Collection
package example

public class ExamplePlugin { def pluginDatastoreService

public void poll() { def collectionName = "collection1" def dataList = pluginDatastoreService.getCollection(collectionName) if (dataList!=null) log.info("Collection successfully queried") else log.warn("The collection does not exist!") } }

Retrieving a Single Entry
package example

public class ExamplePlugin { def pluginDatastoreService

public void poll() { def collectionName = "collection1" def data = pluginDatastoreService.getData(collectionName, "key", "value") if (data!=null) log.info("Data successfully retrieved") else log.warn("The entry with key==value does not exist") } }

Removing a Collection
package example

public class ExamplePlugin { def pluginDatastoreService

public void poll() { def collectionName = "collection1" def data = pluginDatastoreService.clearCollection(collectionName) // Data now contains the collection that was cleared if (data!=null) log.info("Collection successfully cleared") else log.warn("The collection does not exist!") } }

Removing a Single Entry
package example

public class ExamplePlugin { def pluginDatastoreService

public void poll() { def collectionName = "collection1" if (pluginDatastoreService.removeData(collectionName, "key", "value")) log.info("Data entry successfully removed") else log.warn("The entry where key==value does not exist!") } }