Пример #1
0
        private void _ValidateArguments(string nameSpace, PersistentObject obj)
        {
            if (string.IsNullOrEmpty(nameSpace))
            {
                throw new ArgumentException("A valid namespace must be supplied.", "nameSpace");
            }
            else
            {
                if (null == obj)
                {
                    throw new ArgumentNullException("obj");
                }
                else
                {
                    if (!_objectNaming.NameSpaceExists(nameSpace))
                    {
                        throw new ArgumentException("Unknown namespace: " + nameSpace);
                    }

                    if (!_objectNaming.ObjectNameExists(nameSpace, obj.Name))
                    {
                        throw new ArgumentException("Object name does not exist: " + ObjectNaming.CreateFullObjectName(nameSpace, obj.Name));
                    }

                    if (obj.SecondaryKey != null && obj.SecondaryKey.Length == 0)
                    {
                        throw new ArgumentException("Zero length Secondary Key is not supported.");
                    }
                }
            }
        }
Пример #2
0
        public void Set(string nameSpace, PersistentObject obj)
        {
            var objectFullName = ObjectNaming.CreateFullObjectName(nameSpace, obj.Name);
            var store = _EnsureStore(objectFullName);
            var storeValue = _CreateValueForStorage(obj.Value, obj.SecondaryKey);

            store.Set(SerializerHelper.Serialize(obj.ID), storeValue);

            if (obj.HasSecondaryKey())
            {
                var secondaryStore = _EnsureSecondaryStore(objectFullName);
                secondaryStore.Set(obj.SecondaryKey, SerializerHelper.Serialize(obj.ID));
            }
        }
Пример #3
0
        /// <summary>
        /// Stores an object value and its indexes in the Object Store.
        /// If an ID has not be specified, then one will be auto-generated from a 
        /// sequential ID list that belongs to the Object Store.
        /// Specify a SecondaryKey to enable the object to be looked up using that value.
        /// </summary>
        /// <param name="nameSpace"></param>
        /// <param name="obj"></param>
        /// <returns></returns>
        public ObjectID Store(string nameSpace, PersistentObject obj)
        {
            ObjectID returnValue = null;

            _ValidateArguments(nameSpace, obj);

            var objectFullName = ObjectNaming.CreateFullObjectName(nameSpace, obj.Name);
            var startingObjId = obj.ID;
            var objNameKey = ObjectNaming.CreateFullObjectKey(objectFullName);
            var objId = obj.ID;

            if (!obj.HasID())
            {
                objId = _objectIDStore.GetNextID(objNameKey);
                obj.ID = objId;
            }

            returnValue = new ObjectID()
            {
                ID = objId,
                SecondaryKey = obj.SecondaryKey
            };

            try
            {
                using (var trans = new TransactionScope(TransactionScopeOption.Required, _DefaultTransactionOptions))
                {
                    if (null != obj.Indexes && 0 < obj.Indexes.Length)
                    {
                        _objectIndexer.IndexObject(objectFullName, obj.ID,
                            obj.Indexes);
                    }

                    _objectStore.Set(nameSpace, obj);
                    _objectVersions.Update(objectFullName);

                    trans.Complete();
                }
            }
            catch (Exception)
            {
                // rollback in memory changes
                obj.ID = startingObjId;
                throw;
            }

            return returnValue;
        }