Permalink
Browse files

added delete functionality

  • Loading branch information...
bthornton32 committed Jul 16, 2012
1 parent a62c832 commit 7133e43f23988cb847d59f8314318f6dbca97097
@@ -42,6 +42,9 @@ Whenever you use the below feature id in any of your WebWorks applications this
//Read from storage
var myResult = webworks.persistent.storage.read("mykey");
+
+ //Delete from storage
+ webworks.persistent.storage.delete("mykey");
## Code Example
@@ -58,12 +61,18 @@ Whenever you use the below feature id in any of your WebWorks applications this
var myResult = webworks.persistent.storage.read("mykey");
alert(myResult);
}
+
+ function doDelete(){
+ webworks.persistent.storage.delete("mykey");
+ alert('Persistent Data Destroyed');
+ }
</script>
</head>
- <body >
+ <body>
<h1>Hello World</h1>
<button onclick="doWrite();">Test Write</button>
<button onclick="doRead();">Test Read</button>
+ <button onclick="doDelete();">Test Delete</button>
</body>
</html>
@@ -26,6 +26,7 @@
{
public static final String FIELD_WRITE = "write";
public static final String FIELD_READ = "read";
+ public static final String FIELD_DELETE = "delete";
public Object getField(String name) throws Exception
{
if (name.equals(FIELD_WRITE))
@@ -36,9 +37,28 @@ public Object getField(String name) throws Exception
{
return new StorageRead();
}
+
+ if (name.equals(FIELD_DELETE))
+ {
+ return new StorageDelete();
+ }
return super.getField(name);
}
+ public class StorageDelete extends ScriptableFunction
+ {
+ private static final String NAME = "delete";
+ public Object invoke(Object obj, Object[] args) throws Exception
+ {
+ if (args.length == 1)
+ {
+ PersistentObject myPersistentData;
+ PersistentStore.destroyPersistentObject(StringUtilities.stringHashToLong(args[0].toString()));
+ }
+ return UNDEFINED;
+ }
+ }
+
public class StorageWrite extends ScriptableFunction
{
private static final String NAME = "write";

0 comments on commit 7133e43

Please sign in to comment.