-
Notifications
You must be signed in to change notification settings - Fork 7
Changes Needed for Monotouch Device Deployments #16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,8 +10,10 @@ namespace Catnap.Mapping.Impl | |
| { | ||
| public class DomainMap : IDomainMap, IDomainMappable | ||
| { | ||
| private readonly IDbAdapter dbAdapter; | ||
| private readonly IDictionary<Type, IEntityMap> entityMaps = new Dictionary<Type, IEntityMap>(); | ||
| private IDbAdapter dbAdapter; | ||
| // -- Changed by RD to overcome Monotouch limitations when Value types are used as Dictionary Keys | ||
| // -- see http://docs.xamarin.com/ios/guides/advanced_topics/limitations | ||
| private Dictionary<string, IEntityMap> entityMaps = new Dictionary<string, IEntityMap>(); // - RD | ||
|
|
||
| public DomainMap(IDbAdapter dbAdapter) | ||
| { | ||
|
|
@@ -25,12 +27,12 @@ public DomainMap(IDbAdapter dbAdapter) | |
|
|
||
| public IEntityMappable<T> Entity<T>(Action<IEntityMappable<T>> propertyMappings) where T : class, new() | ||
| { | ||
| if (entityMaps.ContainsKey(typeof(T))) | ||
| if (entityMaps.ContainsKey(typeof(T).Name)) // RD - change | ||
| { | ||
| throw new ApplicationException(string.Format("Cannot map type '{0}' because it is already mapped.", typeof(T))); | ||
| } | ||
| var map = new EntityMap<T>(propertyMappings); | ||
| entityMaps.Add(typeof(T), map); | ||
| entityMaps.Add(typeof(T).Name, map); | ||
| return map; | ||
| } | ||
|
|
||
|
|
@@ -58,23 +60,32 @@ public void ListParentIdColumnNameConvention(Func<IListPropertyMapDescriptor, st | |
|
|
||
| public IEntityMap<T> GetMapFor<T>() where T : class, new() | ||
| { | ||
| return (IEntityMap<T>)entityMaps.First(x => x.Key == typeof(T)).Value; | ||
| return (IEntityMap<T>)entityMaps.First(x => x.Key == typeof(T).Name).Value; // RD - change | ||
| } | ||
|
|
||
| public IEntityMap GetMapFor(Type type) | ||
| { | ||
| return entityMaps.First(x => x.Key == type).Value; | ||
| return entityMaps.First(x => x.Key == type.Name).Value; // RD - change | ||
| } | ||
|
|
||
| public void Done() | ||
| // -- RD wrapped done calls with exception handling - probably not needed. | ||
| public void Done () | ||
| { | ||
| if (IdMappingConvention == null) | ||
| if (IdMappingConvention == null) | ||
| { | ||
| IdMappingConvention = new IdMappingConvention(); | ||
| IdMappingConvention = new IdMappingConvention (); | ||
| } | ||
| foreach (var map in entityMaps.Values) | ||
| { | ||
| map.Done(this, dbAdapter); | ||
| try | ||
| { | ||
| map.Done(this, dbAdapter); | ||
| } | ||
| catch (Exception e) | ||
| { | ||
| Console.WriteLine("FAILED Done for " + map.TableName + " " + e); | ||
| } | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I assume this was for debugging inadvertently left in. We won't want to swallow this exception. |
||
|
|
||
| } | ||
| } | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -32,7 +32,7 @@ public TConcrete Column(string value) | |
|
|
||
| public override void Done(IDomainMap domainMap) | ||
| { | ||
| base.Done(domainMap); | ||
| //base.Done(domainMap); RD removed call. | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This needs to stay unless we get rid of the base Done, which per my prior comment, I think we need to set default access. |
||
| ColumnName = ColumnName ?? GetDeafultColumnName(domainMap); | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -42,7 +42,9 @@ public IList<IDictionary<string, object>> List(IDbCommandSpec commandSpec) | |
| { | ||
| commandSpec.GuardArgumentNull("commandSpec"); | ||
| var command = commandFactory.Create(commandSpec.Parameters, commandSpec.CommandText); | ||
| return Try(() => ExecuteQuery(command)); | ||
| var result = Try(() => ExecuteQuery(command)); | ||
| command.Dispose (); //RD see http://www.aaronheise.com/2012/12/monotouch-sqlite-sigsegv/ | ||
| return result; | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I will prefer like this (in all cases): |
||
| } | ||
|
|
||
| public IList<T> List<T>(IDbCommandSpec commandSpec) where T : class, new() | ||
|
|
@@ -60,6 +62,7 @@ public IList<IDictionary<string, object>> List(IDbCommandSpec commandSpec) | |
| var command = entityMap.GetListCommand(predicateSpec.Parameters, predicateSpec.CommandText, commandFactory); | ||
| var results = ExecuteQuery(command).Select(x => entityMap.BuildFrom(x, this)).ToList(); | ||
| StoreAll(entityMap, results); | ||
| command.Dispose (); //RD see http://www.aaronheise.com/2012/12/monotouch-sqlite-sigsegv/ | ||
| return results; | ||
| } | ||
|
|
||
|
|
@@ -75,6 +78,7 @@ public IList<IDictionary<string, object>> List(IDbCommandSpec commandSpec) | |
| var command = entityMap.GetListAllCommand(commandFactory); | ||
| var results = ExecuteQuery(command).Select(x => entityMap.BuildFrom(x, this)).ToList(); | ||
| StoreAll(entityMap, results); | ||
| command.Dispose(); //RD see http://www.aaronheise.com/2012/12/monotouch-sqlite-sigsegv/ | ||
| return results; | ||
| } | ||
|
|
||
|
|
@@ -90,6 +94,7 @@ public IList<IDictionary<string, object>> List(IDbCommandSpec commandSpec) | |
| var command = entityMap.GetGetCommand(id, commandFactory); | ||
| var result = ExecuteQuery(command).Select(x => entityMap.BuildFrom(x, this)).FirstOrDefault(); | ||
| sessionCache.Store(id, result); | ||
| command.Dispose (); //RD see http://www.aaronheise.com/2012/12/monotouch-sqlite-sigsegv/ | ||
| return result; | ||
| } | ||
|
|
||
|
|
@@ -113,6 +118,7 @@ public IList<IDictionary<string, object>> List(IDbCommandSpec commandSpec) | |
| } | ||
| sessionCache.Store(entityMap.GetId(entity), entity); | ||
| Cascade(entityMap, entity); | ||
| command.Dispose(); //RD see http://www.aaronheise.com/2012/12/monotouch-sqlite-sigsegv/ | ||
| } | ||
|
|
||
| private void Cascade<T>(IEntityMap<T> entityMap, T entity) where T : class, new() | ||
|
|
@@ -131,6 +137,7 @@ public IList<IDictionary<string, object>> List(IDbCommandSpec commandSpec) | |
| var deleteCommand = map.GetDeleteCommand(id, commandFactory); | ||
| Try(deleteCommand.ExecuteNonQuery); | ||
| sessionCache.Store<T>(id, null); | ||
| deleteCommand.Dispose (); //RD see http://www.aaronheise.com/2012/12/monotouch-sqlite-sigsegv/ | ||
| } | ||
|
|
||
| public void ExecuteNonQuery(IDbCommandSpec commandSpec) | ||
|
|
@@ -139,6 +146,7 @@ public void ExecuteNonQuery(IDbCommandSpec commandSpec) | |
| commandSpec.GuardArgumentNull("commandSpec"); | ||
| var command = commandFactory.Create(commandSpec); | ||
| Try(command.ExecuteNonQuery); | ||
| command.Dispose (); //RD | ||
| } | ||
|
|
||
| public IList<IDictionary<string, object>> ExecuteQuery(IDbCommand command) | ||
|
|
@@ -158,6 +166,7 @@ public IList<IDictionary<string, object>> ExecuteQuery(IDbCommand command) | |
| result.Add(row); | ||
| } | ||
| reader.Close(); | ||
| command.Dispose (); //RD see http://www.aaronheise.com/2012/12/monotouch-sqlite-sigsegv/ | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should not be disposed here. It's passed in. Also we can see that all callers of this method dispose it, which is the proper scope to do so. |
||
| return result; | ||
| } | ||
| } | ||
|
|
@@ -167,7 +176,9 @@ public object ExecuteScalar(IDbCommandSpec commandSpec) | |
| GuardNotDisposed(); | ||
| commandSpec.GuardArgumentNull("commandSpec"); | ||
| var command = commandFactory.Create(commandSpec); | ||
| return Try(command.ExecuteScalar); | ||
| object result = Try(command.ExecuteScalar); | ||
| command.Dispose(); //RD see http://www.aaronheise.com/2012/12/monotouch-sqlite-sigsegv/ | ||
| return result; | ||
| } | ||
|
|
||
| public T ExecuteScalar<T>(IDbCommandSpec commandSpec) | ||
|
|
@@ -176,13 +187,15 @@ public T ExecuteScalar<T>(IDbCommandSpec commandSpec) | |
| commandSpec.GuardArgumentNull("commandSpec"); | ||
| var command = commandFactory.Create(commandSpec); | ||
| var result = Try(command.ExecuteScalar); | ||
| command.Dispose (); //RD see http://www.aaronheise.com/2012/12/monotouch-sqlite-sigsegv/ | ||
| return (T)result; | ||
| } | ||
|
|
||
| public bool TableExists(string tableName) | ||
| { | ||
| var getTableMetadataCommand = DbAdapter.CreateGetTableMetadataCommand(tableName, commandFactory); | ||
| var result = ExecuteQuery(getTableMetadataCommand); | ||
| getTableMetadataCommand.Dispose (); //RD see http://www.aaronheise.com/2012/12/monotouch-sqlite-sigsegv/ | ||
| return result.Count > 0; | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason to make this not readonly? It's only assigned in the c-tor.