public List <int> GetOIDs() { List <int> list = new List <int>(); List <int> unu = criteria1.GetOIDs(); List <int> doi = criteria2.GetOIDs(); if (unu.Count < doi.Count) { doi.Sort(); foreach (int oid in unu) { int index = doi.BinarySearch(oid); if (index >= 0) { list.Add(doi[index]); } } } else { unu.Sort(); foreach (int oid in doi) { int index = unu.BinarySearch(oid); if (index >= 0) { list.Add(unu[index]); } } } return(list); }
public List <int> GetOIDs() { List <int> list = new List <int>(); List <int> unu = criteria1.GetOIDs(); List <int> doi = criteria2.GetOIDs(); #region old version /*foreach (int oid in unu) * { * * list.Add(oid); * * } * foreach (int oid in doi) * { * if (!list.Contains(oid)) * { * list.Add(oid); * } * * }*/ #endregion if (unu.Count < doi.Count) { foreach (int oid in doi) { list.Add(oid); } doi.Sort(); foreach (int oid in unu) { int index = doi.BinarySearch(oid); if (index < 0) { list.Add(oid); } } return(list); } else { foreach (int oid in unu) { list.Add(oid); } unu.Sort(); foreach (int oid in doi) { int index = unu.BinarySearch(oid); if (index < 0) { list.Add(oid); } } return(list); } }
internal List <int> DeleteObjectBy(SqoTypeInfo ti, Dictionary <string, object> criteria) { int i = 0; ICriteria wPrev = null; foreach (string fieldName in criteria.Keys) { FieldSqoInfo fi = MetaHelper.FindField(ti.Fields, fieldName); if (fi == null) { throw new SiaqodbException("Field:" + fieldName + " was not found as member of Type:" + ti.TypeName); } Where w = new Where(fieldName, OperationType.Equal, criteria[fieldName]); w.StorageEngine = this; w.ParentSqoTypeInfo = ti; w.ParentType.Add(w.ParentSqoTypeInfo.Type); if (i > 0) { And and = new And(); and.Add(w, wPrev); wPrev = and; } else { wPrev = w; } i++; } List <int> oids = wPrev.GetOIDs(); ObjectSerializer serializer = SerializerFactory.GetSerializer(this.path, GetFileByType(ti), useElevatedTrust); lock (_syncRoot) { foreach (int oid in oids) { this.MarkObjectAsDelete(serializer, oid, ti); this.indexManager.UpdateIndexesAfterDelete(oid, ti); } } return(oids); }
internal int DeleteObjectBy(string[] fieldNames, object obj, SqoTypeInfo ti, Transaction transaction) { ObjectInfo objInfo = MetaExtractor.GetObjectInfo(obj, ti, metaCache); int i = 0; ICriteria wPrev = null; foreach (string fieldName in fieldNames) { FieldSqoInfo fi = MetaHelper.FindField(ti.Fields, fieldName); if (fi == null) { throw new SiaqodbException("Field:" + fieldName + " was not found as member of Type:" + ti.TypeName); } Where w = new Where(fieldName, OperationType.Equal, objInfo.AtInfo[fi]); w.StorageEngine = this; w.ParentSqoTypeInfo = ti; w.ParentType.Add(w.ParentSqoTypeInfo.Type); if (i > 0) { And and = new And(); and.Add(w, wPrev); wPrev = and; } else { wPrev = w; } i++; } List <int> oids = wPrev.GetOIDs(); if (oids.Count > 1) { throw new SiaqodbException("In database exists more than one object with value of fields specified"); } else if (oids.Count == 1) { objInfo.Oid = oids[0]; //obj.OID = oids[0]; metaCache.SetOIDToObject(obj, oids[0], ti); ObjectSerializer serializer = SerializerFactory.GetSerializer(this.path, GetFileByType(ti), useElevatedTrust); lock (_syncRoot) { if (transaction == null) { CheckForConcurency(obj, objInfo, ti, serializer, true); this.MarkObjectAsDelete(serializer, objInfo.Oid, ti); this.indexManager.UpdateIndexesAfterDelete(objInfo, ti); } else { this.DeleteObject(obj, ti, transaction, objInfo); } } return(oids[0]); } else { return(-1); } }
internal bool UpdateObjectBy(string[] fieldNames, object obj, SqoTypeInfo ti, Transaction transact) { ObjectInfo objInfo = MetaExtractor.GetObjectInfo(obj, ti, metaCache); int i = 0; ICriteria wPrev = null; foreach (string fieldName in fieldNames) { FieldSqoInfo fi = MetaHelper.FindField(ti.Fields, fieldName); if (fi == null) { throw new SiaqodbException("Field:" + fieldName + " was not found as member of Type:" + ti.TypeName); } Where w = new Where(fieldName, OperationType.Equal, objInfo.AtInfo[fi]); w.StorageEngine = this; w.ParentSqoTypeInfo = ti; w.ParentType.Add(w.ParentSqoTypeInfo.Type); if (i > 0) { And and = new And(); and.Add(w, wPrev); wPrev = and; } else { wPrev = w; } i++; } List <int> oids = wPrev.GetOIDs(); if (oids.Count > 1) { throw new SiaqodbException("In database exists more than one object with value of fields specified"); } else if (oids.Count == 1) { objInfo.Oid = oids[0]; #region old code that was duplicated like on SaveObject /*//obj.OID = oids[0]; * MetaHelper.SetOIDToObject(obj, oids[0], ti.Type); * * lock (_syncRoot) * { * ObjectSerializer serializer = SerializerFactory.GetSerializer(this.path, GetFileByType(ti), useElevatedTrust); * * CheckForConcurency(obj, objInfo, ti, serializer,false); * * CheckConstraints(objInfo, ti); * * Dictionary<string, object> oldValuesOfIndexedFields = this.PrepareUpdateIndexes(objInfo, ti, serializer); * * serializer.SerializeObject(objInfo); * * this.UpdateIndexes(objInfo, ti, oldValuesOfIndexedFields); * }*/ #endregion if (transact == null) { this.SaveObject(obj, ti, objInfo); } else { this.SaveObject(obj, ti, objInfo, transact); } return(true); } else { return(false); } }