WIP
parent
d60d097b56
commit
7a5a94dbef
|
@ -59,6 +59,14 @@ namespace ln.types.odb
|
|||
}
|
||||
}
|
||||
|
||||
public bool HasField(String name)
|
||||
{
|
||||
foreach (FieldInfo fieldInfo in mappedFields)
|
||||
if (fieldInfo.Name.Equals(name))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
public object UnmapValue(ODBMapper mapper,ODBValue oval)
|
||||
{
|
||||
ODBDocument document = oval as ODBDocument;
|
||||
|
@ -79,7 +87,7 @@ namespace ln.types.odb
|
|||
else
|
||||
{
|
||||
object fv = mapper.UnmapValue(fieldInfo.FieldType, document[fieldInfo.Name]);
|
||||
if (fv != null)
|
||||
if (!object.ReferenceEquals(fv,null))
|
||||
{
|
||||
Type st = fv.GetType();
|
||||
if (st != fieldInfo.FieldType)
|
||||
|
@ -90,7 +98,8 @@ namespace ln.types.odb
|
|||
if (st != fieldInfo.FieldType)
|
||||
fv = Convert.ChangeType(fv, fieldInfo.FieldType);
|
||||
}
|
||||
fieldInfo.SetValue(o, fv);
|
||||
if (!object.ReferenceEquals(null,fv))
|
||||
fieldInfo.SetValue(o, fv);
|
||||
}
|
||||
}
|
||||
return o;
|
||||
|
|
|
@ -125,7 +125,9 @@ namespace ln.types.odb
|
|||
if (!object.ReferenceEquals(doc,null))
|
||||
documentCache.Add(doc);
|
||||
|
||||
doc.Collection = this;
|
||||
if (!object.ReferenceEquals(null,doc))
|
||||
doc.Collection = this;
|
||||
|
||||
return doc;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -57,6 +57,13 @@ namespace ln.types.odb
|
|||
return IF(propertyName, (v) => values.Contains(v));
|
||||
}
|
||||
|
||||
public static Query Contains<T, A>(string propertyName, IEnumerable<A> values)
|
||||
{
|
||||
ODBValue[] oValues = values.Select(v => ODBMapper.Default.MapValue(v)).ToArray();
|
||||
return IF(IndexPath.TranslatePropertyPath(typeof(T), propertyName), v => oValues.Contains(v));
|
||||
}
|
||||
|
||||
|
||||
public static Query IF<T>(string propertyName, Predicate<ODBValue> predicate) => IF(IndexPath.TranslatePropertyPath(typeof(T),propertyName), predicate);
|
||||
public static Query IF(string propertyName,Predicate<ODBValue> predicate)
|
||||
{
|
||||
|
|
|
@ -63,7 +63,10 @@ namespace ln.types.odb.mapped
|
|||
|
||||
public IEnumerable Select(Query query)
|
||||
{
|
||||
return new MappedEnumeration(this, query.Execute(DocumentCollection).ToArray());
|
||||
lock (this)
|
||||
{
|
||||
return new MappedEnumeration(this, query.Execute(DocumentCollection).ToArray());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -76,7 +79,12 @@ namespace ln.types.odb.mapped
|
|||
throw new ArgumentException(String.Format("Object needs to be of type {0}",ElementType.FullName), nameof(o));
|
||||
|
||||
ODBDocument document = ODBMapper.Default.MapValue(o) as ODBDocument;
|
||||
return DocumentCollection.Insert(document);
|
||||
if (DocumentCollection.Insert(document))
|
||||
{
|
||||
TouchCache(document.ID, o);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public bool Update(object o)
|
||||
|
@ -89,7 +97,12 @@ namespace ln.types.odb.mapped
|
|||
throw new ArgumentException(String.Format("Object needs to be of type {0}", ElementType.FullName), nameof(o));
|
||||
|
||||
ODBDocument document = Mapper.MapValue(o) as ODBDocument;
|
||||
return DocumentCollection.Update(document);
|
||||
if (DocumentCollection.Update(document))
|
||||
{
|
||||
TouchCache(document.ID, o);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -122,6 +135,21 @@ namespace ln.types.odb.mapped
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
public bool HasProperty(string propName)
|
||||
{
|
||||
propName = IndexPath.TranslatePropertyPath(ElementType, propName);
|
||||
|
||||
ClassMapping classMapping = Mapper.GetMapping(ElementType) as ClassMapping;
|
||||
if (classMapping != null)
|
||||
{
|
||||
return classMapping.HasField(propName);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* Indeces */
|
||||
public void EnsureIndex(string propertyPath)
|
||||
{
|
||||
|
@ -129,8 +157,6 @@ namespace ln.types.odb.mapped
|
|||
DocumentCollection.EnsureIndex(translatedPath, translatedPath);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* Object Cache */
|
||||
public bool UseStrongCache { get; private set; }
|
||||
Dictionary<ODBValue, object> objectCache = new Dictionary<ODBValue, object>();
|
||||
|
|
Loading…
Reference in New Issue