Skip to content
This repository has been archived by the owner on Feb 29, 2020. It is now read-only.

Commit

Permalink
[client][managed][offline] rename fromServer to ignoreMissingColumns
Browse files Browse the repository at this point in the history
  • Loading branch information
hasankhan committed Nov 10, 2014
1 parent 6b8397f commit 8b047eb
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,9 @@ public override Task<JToken> ReadAsync(MobileServiceTableQueryDescription query)
/// </summary>
/// <param name="tableName">Name of the local table.</param>
/// <param name="items">A list of items to be inserted.</param>
/// <param name="fromServer"><code>true</code> if the call is made based on data coming from the server e.g. in a pull operation; <code>false</code> if the call is made by the client, such as insert or update calls on an <see cref="IMobileServiceSyncTable"/>.</param>
/// <param name="ignoreMissingColumns"><code>true</code> if the extra properties on item can be ignored; <code>false</code> otherwise.</param>
/// <returns>A task that completes when item has been upserted in local table.</returns>
public override Task UpsertAsync(string tableName, IEnumerable<JObject> items, bool fromServer)
public override Task UpsertAsync(string tableName, IEnumerable<JObject> items, bool ignoreMissingColumns)
{
if (tableName == null)
{
Expand All @@ -145,10 +145,10 @@ public override Task UpsertAsync(string tableName, IEnumerable<JObject> items, b

this.EnsureInitialized();

return UpsertAsyncInternal(tableName, items, fromServer);
return UpsertAsyncInternal(tableName, items, ignoreMissingColumns);
}

private Task UpsertAsyncInternal(string tableName, IEnumerable<JObject> items, bool fromServer)
private Task UpsertAsyncInternal(string tableName, IEnumerable<JObject> items, bool ignoreMissingColumns)
{
TableDefinition table = GetTable(tableName);

Expand All @@ -166,7 +166,7 @@ private Task UpsertAsyncInternal(string tableName, IEnumerable<JObject> items, b

// If the column is coming from the server we can just ignore it,
// otherwise, throw to alert the caller that they have passed an invalid column
if (!table.TryGetValue(prop.Name, out column) && !fromServer)
if (!table.TryGetValue(prop.Name, out column) && !ignoreMissingColumns)
{
throw new InvalidOperationException(string.Format(Properties.Resources.SQLiteStore_ColumnNotDefined, prop.Name, tableName));
}
Expand Down Expand Up @@ -301,7 +301,7 @@ internal virtual async Task SaveSetting(string name, string value)
{ "id", name },
{ "value", value }
};
await this.UpsertAsyncInternal(MobileServiceLocalSystemTables.Config, new[] { setting }, fromServer: false);
await this.UpsertAsyncInternal(MobileServiceLocalSystemTables.Config, new[] { setting }, ignoreMissingColumns: false);
}

private async Task InitializeConfig()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.WindowsAzure.MobileServices.Query;
using Newtonsoft.Json.Linq;
Expand All @@ -15,13 +13,13 @@ namespace Microsoft.WindowsAzure.MobileServices.Sync
/// <summary>
/// Allows saving and reading data in the local tables.
/// </summary>
public interface IMobileServiceLocalStore: IDisposable
public interface IMobileServiceLocalStore : IDisposable
{
/// <summary>
/// Initializes the store for use.
/// </summary>
/// <returns>A task that completes when store has initialized.</returns>
Task InitializeAsync();
Task InitializeAsync();

/// <summary>
/// Reads data from local table by executing the query.
Expand All @@ -35,9 +33,9 @@ public interface IMobileServiceLocalStore: IDisposable
/// </summary>
/// <param name="tableName">Name of the local table.</param>
/// <param name="items">A list of items to be inserted.</param>
/// <param name="fromServer"><code>true</code> if the call is made based on data coming from the server e.g. in a pull operation; <code>false</code> if the call is made by the client, such as insert or update calls on an <see cref="IMobileServiceSyncTable"/>.</param>
/// <param name="ignoreMissingColumns"><code>true</code> if the extra properties on item can be ignored; <code>false</code> otherwise.</param>
/// <returns>A task that completes when item has been upserted in local table.</returns>
Task UpsertAsync(string tableName, IEnumerable<JObject> items, bool fromServer);
Task UpsertAsync(string tableName, IEnumerable<JObject> items, bool ignoreMissingColumns);

/// <summary>
/// Deletes all the items from local table that match the query.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ public virtual void DefineTable(string tableName, JObject item)
/// </summary>
/// <param name="tableName">Name of the local table.</param>
/// <param name="items">A list of items to be inserted.</param>
/// <param name="fromServer"><code>true</code> if the call is made based on data coming from the server e.g. in a pull operation; <code>false</code> if the call is made by the client, such as insert or update calls on an <see cref="IMobileServiceSyncTable"/>.</param>
/// <param name="ignoreMissingColumns"><code>true</code> if the extra properties on item can be ignored; <code>false</code> otherwise.</param>
/// <returns>A task that completes when item has been upserted in local table.</returns>
public abstract Task UpsertAsync(string tableName, IEnumerable<JObject> items, bool fromServer);
public abstract Task UpsertAsync(string tableName, IEnumerable<JObject> items, bool ignoreMissingColumns);

/// <summary>
/// Deletes all the items from local table that match the query.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ private async Task ProcessAll(JArray items)

if (upsertList.Any())
{
await this.Store.UpsertAsync(this.Table.TableName, upsertList, fromServer: true);
await this.Store.UpsertAsync(this.Table.TableName, upsertList, ignoreMissingColumns: true);
}

if (deletedIds.Any())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ await store.UpsertAsync("ITEMwithDATE", new[]{new JObject()
{
{ "ID", Guid.NewGuid() },
{"dATE", DateTime.UtcNow }
}}, fromServer: false);
}}, ignoreMissingColumns: false);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ private static async Task<MobileServiceSQLiteStore> SetupMathTestTable(JObject[]
item[MobileServiceSystemColumns.Id] = Guid.NewGuid().ToString();
}

await store.UpsertAsync(MathTestTable, mathTestData, fromServer: false);
await store.UpsertAsync(MathTestTable, mathTestData, ignoreMissingColumns: false);

return store;
}
Expand Down Expand Up @@ -314,7 +314,7 @@ private static async Task<MobileServiceSQLiteStore> SetupTestTable()

if (!queryTableInitialized)
{
await store.UpsertAsync(TestTable, testData, fromServer: false);
await store.UpsertAsync(TestTable, testData, ignoreMissingColumns: false);
}

queryTableInitialized = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ public async Task DeleteAsync_DeletesTheRow()
[TestMethod]
public void UpsertAsync_Throws_WhenStoreIsNotInitialized()
{
TestStoreThrowOnUninitialized(store => store.UpsertAsync("asdf", new[] { new JObject() }, fromServer: false));
TestStoreThrowOnUninitialized(store => store.UpsertAsync("asdf", new[] { new JObject() }, ignoreMissingColumns: false));
}

[AsyncTestMethod]
Expand All @@ -235,7 +235,7 @@ public async Task UpsertAsync_Throws_WhenColumnInItemIsNotDefinedAndItIsLocal()

await store.InitializeAsync();

var ex = await ThrowsAsync<InvalidOperationException>(() => store.UpsertAsync(TestTable, new[] { new JObject() { { "notDefined", "okok" } } }, fromServer: false));
var ex = await ThrowsAsync<InvalidOperationException>(() => store.UpsertAsync(TestTable, new[] { new JObject() { { "notDefined", "okok" } } }, ignoreMissingColumns: false));

Assert.AreEqual(ex.Message, "Column with name 'notDefined' is not defined on the local table 'todo'.");
}
Expand All @@ -261,7 +261,7 @@ public async Task UpsertAsync_DoesNotThrow_WhenColumnInItemIsNotDefinedAndItIsFr
{ "id", "abc" },
{ "notDefined", "okok" },
{ "dob", DateTime.UtcNow }
} }, fromServer: true);
} }, ignoreMissingColumns: true);
}
}

Expand All @@ -280,8 +280,8 @@ public async Task UpsertAsync_DoesNotThrow_WhenItemIsEmpty()

await store.InitializeAsync();

await store.UpsertAsync(TestTable, new[] { new JObject() }, fromServer: true);
await store.UpsertAsync(TestTable, new[] { new JObject() }, fromServer: false);
await store.UpsertAsync(TestTable, new[] { new JObject() }, ignoreMissingColumns: true);
await store.UpsertAsync(TestTable, new[] { new JObject() }, ignoreMissingColumns: false);
}
}

Expand Down Expand Up @@ -318,7 +318,7 @@ public async Task UpsertAsync_InsertsTheRow_WhenItemHasNullValues()
{ "friends", null },
{ "__version", null }
};
await store.UpsertAsync(TestTable, new[] { inserted }, fromServer: false);
await store.UpsertAsync(TestTable, new[] { inserted }, ignoreMissingColumns: false);

JObject read = await store.LookupAsync(TestTable, "abc");

Expand All @@ -340,7 +340,7 @@ await store.UpsertAsync(TestTable, new[]{new JObject()
{
{ "id", "abc" },
{ "__createdAt", DateTime.Now }
}}, fromServer: false);
}}, ignoreMissingColumns: false);
}
long count = TestUtilities.CountRows(TestDbName, TestTable);
Assert.AreEqual(count, 1L);
Expand All @@ -362,13 +362,13 @@ await store.UpsertAsync(TestTable, new[]{new JObject()
{ "id", "abc" },
{ "text", "xyz" },
{ "__createdAt", DateTime.Now }
}}, fromServer: false);
}}, ignoreMissingColumns: false);

await store.UpsertAsync(TestTable, new[]{new JObject()
{
{ "id", "abc" },
{ "__createdAt", new DateTime(200,1,1) }
}}, fromServer: false);
}}, ignoreMissingColumns: false);

JObject result = await store.LookupAsync(TestTable, "abc");

Expand Down Expand Up @@ -410,7 +410,7 @@ public async Task UpsertAsync_Throws_WhenInsertingRecordsWhichAreTooLarge()
var item2 = new JObject(template);
item1["id"] = 2;

InvalidOperationException ex = await AssertEx.Throws<InvalidOperationException>(() => store.UpsertAsync(TestTable, new[] { item1, item2 }, fromServer: false));
InvalidOperationException ex = await AssertEx.Throws<InvalidOperationException>(() => store.UpsertAsync(TestTable, new[] { item1, item2 }, ignoreMissingColumns: false));

Assert.AreEqual("The number of fields per entity in an upsert operation is limited to 800.", ex.Message);
}
Expand Down Expand Up @@ -451,7 +451,7 @@ public async Task UpsertAsync_CanProcessManyRecordsAtOnce()
.ToArray();

//Insert the items
await store.UpsertAsync(TestTable, itemsToInsert, fromServer: false);
await store.UpsertAsync(TestTable, itemsToInsert, ignoreMissingColumns: false);

JArray records = (JArray)await store.ReadAsync(MobileServiceTableQueryDescription.Parse(TestTable, "$orderby=id"));

Expand Down Expand Up @@ -491,7 +491,7 @@ public async Task Upsert_ThenLookup_ThenUpsert_ThenDelete_ThenLookup()
await store.InitializeAsync();

// first add an item
await store.UpsertAsync(TestTable, new[] { originalItem }, fromServer: false);
await store.UpsertAsync(TestTable, new[] { originalItem }, ignoreMissingColumns: false);

// read the item back
JObject itemRead = await store.LookupAsync(TestTable, "abc");
Expand All @@ -503,7 +503,7 @@ public async Task Upsert_ThenLookup_ThenUpsert_ThenDelete_ThenLookup()
originalItem["double"] = 111.222d;

// upsert the item
await store.UpsertAsync(TestTable, new[] { originalItem }, fromServer: false);
await store.UpsertAsync(TestTable, new[] { originalItem }, ignoreMissingColumns: false);

// read the updated item
JObject updatedItem = await store.LookupAsync(TestTable, "abc");
Expand Down

0 comments on commit 8b047eb

Please sign in to comment.