Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions src/Catnap/Mapping/Impl/BasePropertyMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,16 @@ public abstract class BasePropertyMap<TEntity, TProperty, TConcrete> : IProperty
protected BasePropertyMap(string propertyName)
{
PropertyName = propertyName;
// -- Added by RD for Monotouch AOT compiler limitations
accessStrategy = new PropertyAccessStrategy<TEntity, TProperty>(propertyName);
}

protected BasePropertyMap(Expression<Func<TEntity, TProperty>> property)
{
this.property = property;
PropertyName = property.GetMemberExpression().Member.Name;
// -- Added by RD for Monotouch AOT compiler limitations
accessStrategy = new PropertyAccessStrategy<TEntity, TProperty>(property);
}

public string PropertyName { get; private set; }
Expand Down Expand Up @@ -69,10 +73,11 @@ public PropertyInfo PropertyInfo

public virtual void Done(IDomainMap domainMap)
{
access = access ?? DefaultAccess;
accessStrategy = property == null
? access.CreateFor<TEntity, TProperty>(PropertyName)
: access.CreateFor(property);
// -- Removed by RD due to Monotouch AOT compiler limitations, moved to constructor where type information is known.
//access = access ?? DefaultAccess;
//accessStrategy = property == null
// ? access.CreateFor<TEntity, TProperty>(PropertyName)
// : access.CreateFor(property);
}

protected virtual IAccessStrategyFactory DefaultAccess
Expand Down
31 changes: 21 additions & 10 deletions src/Catnap/Mapping/Impl/DomainMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Copy link
Owner

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.

// -- 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)
{
Expand All @@ -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;
}

Expand Down Expand Up @@ -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);
}
Copy link
Owner

Choose a reason for hiding this comment

The 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.


}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Catnap/Mapping/Impl/PropertyWithColumnMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public TConcrete Column(string value)

public override void Done(IDomainMap domainMap)
{
base.Done(domainMap);
//base.Done(domainMap); RD removed call.
Copy link
Owner

Choose a reason for hiding this comment

The 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);
}

Expand Down
17 changes: 15 additions & 2 deletions src/Catnap/Session.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will prefer like this (in all cases):

using (var command = commandFactory.Create(commandSpec.Parameters, commandSpec.CommandText))
{
    return Try(() => ExecuteQuery(command));
}

}

public IList<T> List<T>(IDbCommandSpec commandSpec) where T : class, new()
Expand All @@ -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;
}

Expand All @@ -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;
}

Expand All @@ -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;
}

Expand All @@ -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()
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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/
Copy link
Owner

Choose a reason for hiding this comment

The 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;
}
}
Expand All @@ -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)
Expand All @@ -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;
}

Expand Down