added replaceFeatureId() method to low level attachmentsStore module

This commit is contained in:
Javier Abadia 2014-04-14 17:34:41 +02:00
parent 20578f3bf3
commit 25d427faaf
2 changed files with 52 additions and 2 deletions

View File

@ -155,7 +155,36 @@ define([], function()
}
}
this.getUsage = function(callback){
this.replaceFeatureId = function(featureLayerUrl, oldId, newId, callback)
{
var featureId = featureLayerUrl + "/" + oldId;
var objectStore = this._db.transaction([OBJECT_STORE_NAME],"readwrite").objectStore(OBJECT_STORE_NAME);
var index = objectStore.index("featureId");
var keyRange = IDBKeyRange.only(featureId);
var replacedCount = 0;
index.openCursor(keyRange).onsuccess = function(evt)
{
var cursor = evt.target.result;
if(cursor)
{
var newFeatureId = featureLayerUrl + "/" + newId;
var updated = cursor.value;
updated.featureId = newFeatureId;
updated.objectId = newId;
objectStore.put(updated);
replacedCount++;
cursor.continue()
}
else
{
callback(replacedCount);
}
}
}
this.getUsage = function(callback)
{
if(this._db != null){
var usage = { sizeBytes: 0, attachmentCount: 0 };

View File

@ -101,6 +101,27 @@ describe("attachments store module", function()
});
});
async.it("replace feature id", function(done)
{
g_attachmentsStore.replaceFeatureId("layer1",1,100, function(success)
{
expect(success).toBe(2);
g_attachmentsStore.getAttachmentsByFeatureId("layer1", 1, function(attachments)
{
expect(attachments.length).toBe(0);
g_attachmentsStore.getAttachmentsByFeatureId("layer1", 100, function(attachments)
{
expect(attachments.length).toBe(2);
expect(attachments[0].objectId).toBe(100);
expect(attachments[1].objectId).toBe(100);
expect(attachments[0].content).toContain("feature 1");
expect(attachments[1].content).toContain("feature 1");
done();
});
});
});
});
async.it("delete attachments of a single feature", function(done)
{
g_attachmentsStore.deleteAttachmentsByFeatureId("layer1", 300, function(deletedCount)
@ -113,7 +134,7 @@ describe("attachments store module", function()
expect(usage).not.toBeNull();
expect(usage.attachmentCount).toBe(testData.length);
g_attachmentsStore.deleteAttachmentsByFeatureId("layer1", 1, function(deletedCount)
g_attachmentsStore.deleteAttachmentsByFeatureId("layer1", 100, function(deletedCount)
{
expect(deletedCount).toBe(2);
setTimeout(function()