Esempio n. 1
0
        public void Insert(RegisterInfo registerInfo)
        {
            Storage   storage = DaoHelper.Instance.DbStorage;
            ClothRoot root    = (ClothRoot)storage.Root;

            FieldIndex registerInfoOidIndex = root.RegisterInfoOidIndex;

            if (registerInfo == null || registerInfoOidIndex.Contains(registerInfo))
            {
                return;
            }

            storage.BeginThreadTransaction(TransactionMode.Exclusive);
            try
            {
                // this method called for generate the Oid, or the key of RegisterInfoOidIndex will always be 0.
                storage.MakePersistent(registerInfo);
                registerInfoOidIndex.Set(registerInfo);
                root.RegisterInfoNameIndex.Set(registerInfo);
                storage.EndThreadTransaction();
            }
            catch (Exception)
            {
                // do some log
                storage.RollbackThreadTransaction();
            }
        }
Esempio n. 2
0
        public void UpdateNoneIndex(RegisterInfo registerInfo)
        {
            Storage   storage = DaoHelper.Instance.DbStorage;
            ClothRoot root    = (ClothRoot)storage.Root;

            FieldIndex registerInfoOidIndex = root.RegisterInfoOidIndex;

            if (null == registerInfo || !registerInfoOidIndex.Contains(registerInfo))
            {
                return;
            }

            storage.BeginThreadTransaction(TransactionMode.Exclusive);
            try
            {
                registerInfo.Modify();

                storage.EndThreadTransaction();
            }
            catch (Exception)
            {
                // do some log
                storage.RollbackThreadTransaction();
            }
        }
Esempio n. 3
0
/*
 *      public List<Cloth> FindAllByColorsAndShapes(ColorEnum colors, ColorEnum notColors, ShapeEnum shapes, ShapeEnum notShapes)
 *      {
 *          Storage storage = DaoHelper.Instance.DbStorage;
 *          ClothRoot root = (ClothRoot)storage.Root;
 *
 *          BitIndex<Cloth> colorIndex = root.ColorIndex;
 *          BitIndex<Cloth> shapeIndex = root.ShapeIndex;
 *
 *          Query<Cloth> query = storage.CreateQuery<Cloth>();
 *          query.Prepare("(colors and ? = ?) and (colors and ?) = 0 and (shapes and ? = ?) and (shapes and ?) = 0");
 *          query.AddIndex(colorIndex);
 *          query.AddIndex(shapeIndex);
 *
 *      }*/

        private void insertWithoutCommit(Storage storage, ClothRoot root, Cloth cloth)
        {
            FieldIndex clothOidIndex = root.ClothOidIndex;

            if (cloth == null || clothOidIndex.Contains(cloth))
            {
                return;
            }

            // this method called for generate the Oid, or the key of ClothOidIndex will always be 0.
            storage.MakePersistent(cloth);
            clothOidIndex.Set(cloth);
            root.PathIndex.Set(cloth);
            root.ColorNumIndex.Put(cloth);
            if (cloth.Pattern != null)
            {
                root.PatternIndex.Put(cloth);
            }

            root.ColorIndex[cloth] = (int)cloth.Colors;
            root.ShapeIndex[cloth] = (int)cloth.Shapes;
        }
Esempio n. 4
0
        public void Update(RegisterInfo registerInfo, RegisterInfo newRegisterInfo)
        {
            Storage   storage = DaoHelper.Instance.DbStorage;
            ClothRoot root    = (ClothRoot)storage.Root;

            FieldIndex registerInfoOidIndex  = root.RegisterInfoOidIndex;
            FieldIndex registerInfoNameIndex = root.RegisterInfoNameIndex;

            if (null == registerInfo || !registerInfoOidIndex.Contains(registerInfo))
            {
                return;
            }

            storage.BeginThreadTransaction(TransactionMode.Exclusive);
            try
            {
                if (registerInfo.Name != newRegisterInfo.Name)
                {
                    registerInfoNameIndex.Remove(registerInfo);
                    registerInfo.Name = newRegisterInfo.Name;
                    registerInfoNameIndex.Set(registerInfo);
                }

                registerInfo.SearchTime = newRegisterInfo.SearchTime;
                registerInfo.UpdateTime = newRegisterInfo.UpdateTime;
                registerInfo.LoginTime  = newRegisterInfo.LoginTime;
                registerInfo.Md5Key     = newRegisterInfo.Md5Key;
                registerInfo.Modify();

                storage.EndThreadTransaction();
            }
            catch (Exception)
            {
                // do some log
                storage.RollbackThreadTransaction();
            }
        }
    static public void Main(string[] args)
    {
        int     i;
        Storage db = StorageFactory.Instance.CreateStorage();

        for (i = 0; i < args.Length; i++)
        {
            if ("altbtree" == args[i])
            {
                db.SetProperty("perst.alternative.btree", true);
            }
        }
        db.Open("testcidx.dbs", pagePoolSize);

#if USE_GENERICS
        MultiFieldIndex <Record> root = (MultiFieldIndex <Record>)db.Root;
        if (root == null)
        {
            root = db.CreateFieldIndex <Record>(new string[] { "intKey", "strKey" }, true);
#else
        FieldIndex root = (FieldIndex)db.Root;
        if (root == null)
        {
            root = db.CreateFieldIndex(typeof(Record), new string[] { "intKey", "strKey" }, true);
#endif
            db.Root = root;
        }
        DateTime start = DateTime.Now;
        long key       = 1999;
        for (i = 0; i < nRecords; i++)
        {
            Record rec = new Record();
            key        = (3141592621L * key + 2718281829L) % 1000000007L;
            rec.intKey = (int)((ulong)key >> 32);
            rec.strKey = Convert.ToString((int)key);
            root.Put(rec);
        }
        db.Commit();
        Console.WriteLine("Elapsed time for inserting " + nRecords + " records: " + (DateTime.Now - start));

        start = DateTime.Now;
        key   = 1999;
        int minKey = Int32.MaxValue;
        int maxKey = Int32.MinValue;
        for (i = 0; i < nRecords; i++)
        {
            key = (3141592621L * key + 2718281829L) % 1000000007L;
            int    intKey = (int)((ulong)key >> 32);
            String strKey = Convert.ToString((int)key);
#if USE_GENERICS
            Record rec = root.Get(new Key(new Object[] { intKey, strKey }));
#else
            Record rec = (Record)root.Get(new Key(new Object[] { intKey, strKey }));
#endif
            Debug.Assert(rec != null && rec.intKey == intKey && rec.strKey.Equals(strKey));
            if (intKey < minKey)
            {
                minKey = intKey;
            }
            if (intKey > maxKey)
            {
                maxKey = intKey;
            }
        }
        Console.WriteLine("Elapsed time for performing " + nRecords + " index searches: " + (DateTime.Now - start));

        start = DateTime.Now;
        int n          = 0;
        string prevStr = "";
        int prevInt    = minKey;
        foreach (Record rec in root.Range(new Key(minKey, ""),
                                          new Key(maxKey + 1, "???"),
                                          IterationOrder.AscentOrder))
        {
            Debug.Assert(rec.intKey > prevInt || rec.intKey == prevInt && rec.strKey.CompareTo(prevStr) > 0);
            prevStr = rec.strKey;
            prevInt = rec.intKey;
            n      += 1;
        }
        Debug.Assert(n == nRecords);

        n       = 0;
        prevInt = maxKey + 1;
        foreach (Record rec in root.Range(new Key(minKey, "", false),
                                          new Key(maxKey + 1, "???", false),
                                          IterationOrder.DescentOrder))
        {
            Debug.Assert(rec.intKey < prevInt || rec.intKey == prevInt && rec.strKey.CompareTo(prevStr) < 0);
            prevStr = rec.strKey;
            prevInt = rec.intKey;
            n      += 1;
        }
        Debug.Assert(n == nRecords);
        Console.WriteLine("Elapsed time for iterating through " + (nRecords * 2) + " records: " + (DateTime.Now - start));
        start = DateTime.Now;
        key   = 1999;
        for (i = 0; i < nRecords; i++)
        {
            key = (3141592621L * key + 2718281829L) % 1000000007L;
            int    intKey = (int)((ulong)key >> 32);
            String strKey = Convert.ToString((int)key);
#if USE_GENERICS
            Record rec = root.Get(new Key(new Object[] { intKey, strKey }));
#else
            Record rec = (Record)root.Get(new Key(new Object[] { intKey, strKey }));
#endif
            Debug.Assert(rec != null && rec.intKey == intKey && rec.strKey.Equals(strKey));
            Debug.Assert(root.Contains(rec));
            root.Remove(rec);
            rec.Deallocate();
        }
        Debug.Assert(!root.GetEnumerator().MoveNext());
        Debug.Assert(!root.Reverse().GetEnumerator().MoveNext());
        Console.WriteLine("Elapsed time for deleting " + nRecords + " records: " + (DateTime.Now - start));
        db.Close();
    }
}
Esempio n. 6
0
        public void Update(Cloth cloth, Cloth newCloth)
        {
            Storage   storage = DaoHelper.Instance.DbStorage;
            ClothRoot root    = (ClothRoot)storage.Root;

            FieldIndex clothOidIndex = root.ClothOidIndex;

            if (null == cloth || !clothOidIndex.Contains(cloth))
            {
                return;
            }

            FieldIndex patternIndex  = root.PatternIndex;
            BitIndex   colorIndex    = root.ColorIndex;
            BitIndex   shapeIndex    = root.ShapeIndex;
            FieldIndex pathIndex     = root.PathIndex;
            FieldIndex colorNumIndex = root.ColorNumIndex;

            storage.BeginThreadTransaction(TransactionMode.Exclusive);
            try
            {
                // Pattern
                if (cloth.Pattern != null)
                {
                    if (!cloth.Pattern.Equals(newCloth.Pattern))
                    {
                        patternIndex.Remove(cloth);
                        cloth.Pattern = newCloth.Pattern;
                        patternIndex.Put(cloth);
                    }
                }
                else if (newCloth.Pattern != null)
                {
                    cloth.Pattern = newCloth.Pattern;
                    patternIndex.Put(cloth);
                }

                // ColorNum
                if (cloth.ColorNum != newCloth.ColorNum)
                {
                    colorNumIndex.Remove(cloth);
                    cloth.ColorNum = newCloth.ColorNum;
                    colorNumIndex.Put(cloth);
                }

                // Path
                if (cloth.Path != null)
                {
                    if (!cloth.Path.Equals(newCloth.Path))
                    {
                        pathIndex.Remove(cloth);
                        cloth.Path = newCloth.Path;
                        pathIndex.Set(cloth);
                    }
                }
                else if (newCloth.Path != null)
                {
                    cloth.Path = newCloth.Path;
                    pathIndex.Set(cloth);
                }

                // Colors
                if (cloth.Colors != newCloth.Colors)
                {
                    colorIndex.Remove(cloth);
                    cloth.Colors      = newCloth.Colors;
                    colorIndex[cloth] = (int)cloth.Colors;
                }

                // Shapes
                if (cloth.Shapes != newCloth.Shapes)
                {
                    shapeIndex.Remove(cloth);
                    cloth.Shapes      = newCloth.Shapes;
                    shapeIndex[cloth] = (int)cloth.Shapes;
                }

                // Name
                if ((cloth.Name != null && !cloth.Name.Equals(newCloth.Name)) ||
                    (cloth.Name == null && newCloth.Name != null))
                {
                    cloth.Name = newCloth.Name;
                }

                // RGBSeparateColorVector
                if (newCloth.RGBSeparateColorVector != null && !newCloth.RGBSeparateColorVector.Equals(cloth.RGBSeparateColorVector))
                {
                    cloth.RGBSeparateColorVector = newCloth.RGBSeparateColorVector;
                }

                // RGBColorVector
                if (newCloth.RGBColorVector != null && !newCloth.RGBColorVector.Equals(cloth.RGBColorVector))
                {
                    cloth.RGBColorVector = newCloth.RGBColorVector;
                }

                // HSVColorVector
                if (newCloth.HSVColorVector != null && !newCloth.HSVColorVector.Equals(cloth.HSVColorVector))
                {
                    cloth.HSVColorVector = newCloth.HSVColorVector;
                }

                // HSVAynsColorVector
                if (newCloth.HSVAynsColorVector != null && !newCloth.HSVAynsColorVector.Equals(cloth.HSVAynsColorVector))
                {
                    cloth.HSVAynsColorVector = newCloth.HSVAynsColorVector;
                }

                // HLSColorVector
                if (newCloth.HLSColorVector != null && !newCloth.HLSColorVector.Equals(cloth.HLSColorVector))
                {
                    cloth.HLSColorVector = newCloth.HLSColorVector;
                }

                // DaubechiesWaveletVector
                if (newCloth.DaubechiesWaveletVector != null && !newCloth.DaubechiesWaveletVector.Equals(cloth.DaubechiesWaveletVector))
                {
                    cloth.DaubechiesWaveletVector = newCloth.DaubechiesWaveletVector;
                }

                // GaborVector
                if (newCloth.GaborVector != null && !newCloth.GaborVector.Equals(cloth.GaborVector))
                {
                    cloth.GaborVector = newCloth.GaborVector;
                }

                // CooccurrenceVector
                if (newCloth.CooccurrenceVector != null && !newCloth.CooccurrenceVector.Equals(cloth.CooccurrenceVector))
                {
                    cloth.CooccurrenceVector = newCloth.CooccurrenceVector;
                }

                cloth.UpdateTime = (0 == newCloth.UpdateTime.Ticks) ? DateTime.UtcNow : newCloth.UpdateTime;

                cloth.Modify();

                storage.EndThreadTransaction();
            }
            catch (Exception e)
            {
                // do some log
                storage.RollbackThreadTransaction();
            }
        }