(Click to open topic with navigation)
The datastore 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 (see Individual Datastore).
The pluginDatastoreService property will be injected with a class of type IPluginDatastoreService in all plugin types. Note that it is not available for injection in translators or custom components.
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!") } }
Related Topics