Example #1
0
        // --- commit, rollback ---
        public void Commit()
        {
            _store.Begin();
            var gcedId = new List <string>();

            foreach (var pair in _idToObjMap)
            {
                var obj = pair.Value.Target;
                if (obj == null)
                {
                    gcedId.Add(pair.Key);
                }
                else
                {
                    var entity = AsEntity(obj);
                    if (entity != null && IsPersistTarget(entity.Type))
                    {
                        try {
                            entity.Reflect();
                        } catch (Exception e) {
                            Logger.Warn("Can't reflect entity. type=" + entity.Type + ",id=" + entity.Id, e);
                        }

                        /// Reflect()後でないとStateがNewのときに保存場所が作られていない
                        if (entity.IsExtendedDataDirty)
                        {
                            var data = entity.ExtendedData;
                            foreach (var datapair in data)
                            {
                                var value = datapair.Value;
                                if (value != null)
                                {
                                    _store.SaveExtendedTextData(entity.Type, entity.Id, datapair.Key, value);
                                }
                            }
                            entity.IsExtendedDataDirty = false;
                        }

                        if (entity.IsExtendedObjectDataDirty)
                        {
                            var data = entity.ExtendedObjectData;
                            foreach (var datapair in data)
                            {
                                var bytes = datapair.Value;
                                if (bytes != null)
                                {
                                    _store.SaveExtendedBinaryData(entity.Type, entity.Id, datapair.Key, bytes);
                                }
                            }
                            data.Clear();
                            entity.IsExtendedObjectDataDirty = false;
                        }

                        MaintainStrongReference(entity);
                    }
                }
            }
            gcedId.ForEach(id => _idToObjMap.Remove(id));
            _store.Commit();
        }