예제 #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();
            }
        }
예제 #2
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;
        }
예제 #3
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();
            }
        }
예제 #4
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();
            }
        }