Beispiel #1
0
        public bool IsNew(string kind, IDictionary <string, object> data)
        {
            var key                   = _keyAccess.GetKey(kind, data);
            var autoIncrement         = _keyAccess.IsAutoIncrement(kind);
            var autoIncrementReplaced = _keyAccess.IsAutoIncrementReplaced();

            if (!autoIncrement && key == null && !autoIncrementReplaced)
            {
                throw new InvalidOperationException("Missing key value");
            }

            return(!autoIncrement ? !IsKnownKey(kind, key) : key == null);
        }
Beispiel #2
0
        public object Store(string kind, IDictionary <string, object> data, ICollection <string> dirtyNames)
        {
            var key = _keyAccess.GetKey(kind, data);

            if (key == null)
            {
                key = _autoId++;
                _keyAccess.SetKey(kind, data, key);
            }
            else
            {
                Trash(kind, key);
            }

            _storage.Add(data);
            return(key);
        }
        public object Store(string kind, IDictionary <string, object> data, ICollection <string> dirtyNames)
        {
            var key           = _keyAccess.GetKey(kind, data);
            var autoIncrement = _keyAccess.IsAutoIncrement(kind);

            if (!autoIncrement && key == null)
            {
                throw new InvalidOperationException("Missing key value");
            }

            var isNew = !autoIncrement ? !IsKnownKey(kind, key) : key == null;

            if (!isNew && key != null)
            {
                data = new Dictionary <string, object>(data);
                _keyAccess.SetKey(kind, data, null);
            }

            data = data
                   .Where(e => dirtyNames == null || dirtyNames.Contains(e.Key))
                   .ToDictionary(e => e.Key, e => ConvertValue(e.Value));

            if (_isFluidMode)
            {
                data = DropNulls(kind, data);
                CheckSchema(kind, data);
            }

            if (isNew)
            {
                var insertResult = _details.ExecInsert(_db, kind, _keyAccess.GetAutoIncrementName(kind), data);
                if (autoIncrement)
                {
                    return(insertResult);
                }
            }
            else if (data.Count > 0)
            {
                ExecUpdate(kind, key, data);
            }

            return(key);
        }
Beispiel #4
0
 internal object GetKey(IKeyAccess access)
 {
     return(access.GetKey(_kind, _props));
 }
Beispiel #5
0
 public bool IsNew(string kind, IDictionary <string, object> data)
 {
     return(_keyAccess.GetKey(kind, data) == null);
 }