Пример #1
0
        public async Task <List <int> > GetOIDsAsync()
        {
            List <int> list = new List <int>();
            List <int> unu  = await criteria1.GetOIDsAsync().ConfigureAwait(false);

            List <int> doi = await criteria2.GetOIDsAsync().ConfigureAwait(false);

            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);
        }
Пример #2
0
        internal async Task <bool> UpdateObjectByAsync(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 = await wPrev.GetOIDsAsync().ConfigureAwait(false);

            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];

                if (transact == null)
                {
                    await this.SaveObjectAsync(obj, ti, objInfo).ConfigureAwait(false);
                }
                else
                {
                    await this.SaveObjectAsync(obj, ti, objInfo, transact).ConfigureAwait(false);
                }
                return(true);
            }
            else
            {
                return(false);
            }
        }
Пример #3
0
        internal async Task <List <int> > DeleteObjectByAsync(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 = await wPrev.GetOIDsAsync().ConfigureAwait(false);

            ObjectSerializer serializer = SerializerFactory.GetSerializer(this.path, GetFileByType(ti), useElevatedTrust);

            foreach (int oid in oids)
            {
                await this.MarkObjectAsDeleteAsync(serializer, oid, ti).ConfigureAwait(false);

                await this.indexManager.UpdateIndexesAfterDeleteAsync(oid, ti).ConfigureAwait(false);
            }


            return(oids);
        }
Пример #4
0
        internal async Task <int> DeleteObjectByAsync(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 = await wPrev.GetOIDsAsync().ConfigureAwait(false);


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

                if (transaction == null)
                {
                    await CheckForConcurencyAsync(obj, objInfo, ti, serializer, true).ConfigureAwait(false);

                    await this.MarkObjectAsDeleteAsync(serializer, objInfo.Oid, ti).ConfigureAwait(false);

                    await this.indexManager.UpdateIndexesAfterDeleteAsync(objInfo, ti).ConfigureAwait(false);
                }
                else
                {
                    await this.DeleteObjectAsync(obj, ti, transaction, objInfo).ConfigureAwait(false);
                }

                return(oids[0]);
            }
            else
            {
                return(-1);
            }
        }