Build() публичный статический Метод

public static Build ( string tableName, PropertyInfo pi, IFieldHandlerFactory fieldHandlerFactory, FieldHandlerOptions handlerOptions ) : TableFieldInfo
tableName string
pi System.Reflection.PropertyInfo
fieldHandlerFactory IFieldHandlerFactory
handlerOptions FieldHandlerOptions
Результат TableFieldInfo
Пример #1
0
        internal void EnsureClientTypeVersion()
        {
            if (ClientTypeVersion != 0)
            {
                return;
            }
            EnsureKnownLastPersistedVersion();
            var props  = _clientType.GetProperties();
            var fields = new List <TableFieldInfo>(props.Length);

            foreach (var pi in props)
            {
                fields.Add(TableFieldInfo.Build(Name, pi, _tableInfoResolver.FieldHandlerFactory, ClientType));
            }
            var tvi = new TableVersionInfo(fields.ToArray());

            if (LastPersistedVersion == 0)
            {
                _tableVersions.TryAdd(1, tvi);
                ClientTypeVersion = 1;
            }
            else
            {
                var last = _tableVersions.GetOrAdd(LastPersistedVersion, v => _tableInfoResolver.LoadTableVersionInfo(_id, v, Name));
                if (TableVersionInfo.Equal(last, tvi))
                {
                    ClientTypeVersion = LastPersistedVersion;
                }
                else
                {
                    _tableVersions.TryAdd(LastPersistedVersion + 1, tvi);
                    ClientTypeVersion = LastPersistedVersion + 1;
                }
            }
        }
Пример #2
0
        internal void EnsureClientTypeVersion()
        {
            if (ClientTypeVersion != 0)
            {
                return;
            }
            EnsureKnownLastPersistedVersion();
            var props  = _clientType.GetProperties(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
            var fields = new StructList <TableFieldInfo>();

            fields.Reserve((uint)props.Length);
            foreach (var pi in props)
            {
                if (pi.GetCustomAttributes(typeof(NotStoredAttribute), true).Length != 0)
                {
                    continue;
                }
                if (pi.GetIndexParameters().Length != 0)
                {
                    continue;
                }
                fields.Add(TableFieldInfo.Build(Name, pi, _tableInfoResolver.FieldHandlerFactory, FieldHandlerOptions.None));
            }
            var tvi = new TableVersionInfo(fields.ToArray());

            if (LastPersistedVersion == 0)
            {
                _tableVersions.TryAdd(1, tvi);
                ClientTypeVersion = 1;
            }
            else
            {
                var last = _tableVersions.GetOrAdd(LastPersistedVersion, (ver, tableInfo) => tableInfo._tableInfoResolver.LoadTableVersionInfo(tableInfo._id, ver, tableInfo.Name), this);
                if (TableVersionInfo.Equal(last, tvi))
                {
                    _tableVersions[LastPersistedVersion] = tvi; // tvi was build from real types and not loaded so it is more exact
                    ClientTypeVersion = LastPersistedVersion;
                }
                else
                {
                    _tableVersions.TryAdd(LastPersistedVersion + 1, tvi);
                    ClientTypeVersion = LastPersistedVersion + 1;
                }
            }
        }
Пример #3
0
        RelationVersionInfo CreateVersionInfoByReflection()
        {
            var props              = _clientType.GetProperties(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
            var primaryKeys        = new Dictionary <uint, TableFieldInfo>(1);                  //PK order->fieldInfo
            var secondaryKeyFields = new List <TableFieldInfo>();
            var secondaryKeys      = new List <Tuple <int, IList <SecondaryKeyAttribute> > >(); //positive: sec key field idx, negative: pk order, attrs

            var fields = new List <TableFieldInfo>(props.Length);

            foreach (var pi in props)
            {
                if (pi.GetCustomAttributes(typeof(NotStoredAttribute), true).Length != 0)
                {
                    continue;
                }
                if (pi.GetIndexParameters().Length != 0)
                {
                    continue;
                }
                var pks = pi.GetCustomAttributes(typeof(PrimaryKeyAttribute), true);
                PrimaryKeyAttribute actualPKAttribute = null;
                if (pks.Length != 0)
                {
                    actualPKAttribute = (PrimaryKeyAttribute)pks[0];
                    var fieldInfo = TableFieldInfo.Build(Name, pi, _relationInfoResolver.FieldHandlerFactory,
                                                         FieldHandlerOptions.Orderable);
                    if (fieldInfo.Handler.NeedsCtx())
                    {
                        throw new BTDBException($"Unsupported key field {fieldInfo.Name} type.");
                    }
                    primaryKeys.Add(actualPKAttribute.Order, fieldInfo);
                }
                var sks = pi.GetCustomAttributes(typeof(SecondaryKeyAttribute), true);
                var id  = (int)(-actualPKAttribute?.Order ?? secondaryKeyFields.Count);
                List <SecondaryKeyAttribute> currentList = null;
                for (var i = 0; i < sks.Length; i++)
                {
                    if (i == 0)
                    {
                        currentList = new List <SecondaryKeyAttribute>(sks.Length);
                        secondaryKeys.Add(new Tuple <int, IList <SecondaryKeyAttribute> >(id, currentList));
                        if (actualPKAttribute == null)
                        {
                            secondaryKeyFields.Add(TableFieldInfo.Build(Name, pi, _relationInfoResolver.FieldHandlerFactory, FieldHandlerOptions.Orderable));
                        }
                    }
                    var key = (SecondaryKeyAttribute)sks[i];
                    if (key.Name == "Id")
                    {
                        throw new BTDBException("'Id' is invalid name for secondary key, it is reserved for primary key identification.");
                    }
                    currentList.Add(key);
                }
                if (actualPKAttribute == null)
                {
                    fields.Add(TableFieldInfo.Build(Name, pi, _relationInfoResolver.FieldHandlerFactory, FieldHandlerOptions.None));
                }
            }
            var prevVersion = LastPersistedVersion > 0 ? _relationVersions[LastPersistedVersion] : null;

            return(new RelationVersionInfo(primaryKeys, secondaryKeys, secondaryKeyFields.ToArray(), fields.ToArray(), prevVersion));
        }