public bool analyzeObjects()
        {
            if (object1.Rowguid != object2.Rowguid)
            {
                throw new Exception("Objects don´t correspond.");
            }
            bool inConflict = false;

            FieldInfo[] fields = AttributeWorker.RetrieveAllFields(ownerType);
            foreach (FieldInfo fi in fields)
            {
                Attribute   at = Attribute.GetCustomAttribute(fi, typeof(ColumnAttribute));
                IDAttribute id = (IDAttribute)Attribute.GetCustomAttribute(fi, typeof(IDAttribute));
                if (at != null)
                {
                    if (id != null && id.Autoinc == true)
                    {
                    }
                    else
                    {
                        Conflict cf = compareFields(fi, object1, object2);
                        if (cf != null)
                        {
                            inConflict = true;
                            this.conflicts.Add(cf);
                        }
                    }
                }
            }
            return(inConflict);
        }
Example #2
0
        /// <summary>
        /// Save the specified ID.
        /// </summary>
        /// <returns>The object UID.</returns>
        /// <param name="obj">Object.</param>
        public async override Task <int> SaveAsync(ID obj)
        {
            int baseReturn = await base.SaveAsync(obj);

            foreach (KeyValuePair <string, Attribute> entry in obj.Attributes)
            {
                await _attrMapper.SaveAsync(entry.Value);

                //Save the relationship between the ID and the attribute if it does not already exists
                IDAttribute idAttr;
                if ((idAttr = await GetIDAttributeMapping(obj.UID, entry.Value.UID)) == null)
                {
                    idAttr = new IDAttribute()
                    {
                        IDUID   = obj.UID,
                        AttrUID = entry.Value.UID
                    };

                    IMapper <IDAttribute> idAttrMapper = new Mapper <IDAttribute>(_dbFilePath);
                    await idAttrMapper.SaveAsync(idAttr);
                }
            }

            return(baseReturn);
        }
Example #3
0
        public override fsResult TryDeserialize(fsData data, ref object instance_, Type storageType)
        {
            var instance = (IDictionary)instance_;
            var result   = fsResult.Success;

            Type keyStorageType, valueStorageType;

            GetKeyValueTypes(instance.GetType(), out keyStorageType, out valueStorageType);
            string idFieldName = IDAttribute.TypeHasIDAttr(valueStorageType);

            if (data.IsList)
            {
                var list = data.AsList;
                for (int i = 0; i < list.Count; ++i)
                {
                    var item = list[i];

                    fsData keyData, valueData;
                    if ((result += CheckType(item, fsDataType.Object)).Failed)
                    {
                        return(result);
                    }
                    if ((result += CheckKey(item, "Key", out keyData)).Failed)
                    {
                        return(result);
                    }
                    if ((result += CheckKey(item, "Value", out valueData)).Failed)
                    {
                        return(result);
                    }
                    if (idFieldName != null)
                    {
                        valueData.AsDictionary.Add(idFieldName, keyData);
                    }

                    object keyInstance = null, valueInstance = null;
                    if ((result += Serializer.TryDeserialize(keyData, keyStorageType, ref keyInstance)).Failed)
                    {
                        return(result);
                    }
                    if ((result += Serializer.TryDeserialize(valueData, valueStorageType, ref valueInstance)).Failed)
                    {
                        return(result);
                    }

                    if ((result += AddItemToDictionary(instance, keyInstance, valueInstance)).Failed)
                    {
                        return(result);
                    }
                }
            }
            else
            {
                return(FailExpectedType(data, fsDataType.Array, fsDataType.Object));
            }

            return(result);
        }
Example #4
0
        public override fsResult TrySerialize(object instance_, out fsData serialized, Type storageType)
        {
            serialized = fsData.Null;

            var result = fsResult.Success;

            var instance = (IDictionary)instance_;

            Type keyStorageType, valueStorageType;

            GetKeyValueTypes(instance.GetType(), out keyStorageType, out valueStorageType);
            string idFieldName = IDAttribute.TypeHasIDAttr(valueStorageType);

            // No other way to iterate dictionaries and still have access to the
            // key/value info
            IDictionaryEnumerator enumerator = instance.GetEnumerator();

            var serializedKeys   = new List <fsData>(instance.Count);
            var serializedValues = new List <fsData>(instance.Count);

            while (enumerator.MoveNext())
            {
                fsData keyData, valueData;
                if ((result += Serializer.TrySerialize(keyStorageType, enumerator.Key, out keyData)).Failed)
                {
                    return(result);
                }
                if ((result += Serializer.TrySerialize(valueStorageType, enumerator.Value, out valueData)).Failed)
                {
                    return(result);
                }

                serializedKeys.Add(keyData);
                serializedValues.Add(valueData);
            }

            serialized = fsData.CreateList(serializedKeys.Count);
            var serializedList = serialized.AsList;

            for (int i = 0; i < serializedKeys.Count; ++i)
            {
                fsData key   = serializedKeys[i];
                fsData value = serializedValues[i];

                if (idFieldName != null)
                {
                    value.AsDictionary.Remove(idFieldName);
                }

                var container = new Dictionary <string, fsData>();
                container["Key"]   = key;
                container["Value"] = value;
                serializedList.Add(new fsData(container));
            }

            return(result);
        }
Example #5
0
        public void EventIDConstructor_Should_SetProperties()
        {
            // Arrange
            // Act
            var obj = new IDAttribute(id: 1337);

            // Assert
            obj.ID.Should().Be(1337);
        }
        protected override void SetupProperty(Type beanType, IDatabaseMetaData dbMetaData, IDbms dbms)
        {
            if (!IsEntity(beanType))
            {
                base.SetupProperty(beanType, dbMetaData, dbms);
                return;
            }
            Entity entity = (Entity)ClassUtil.NewInstance(beanType);
            DBMeta dbmeta = entity.DBMeta;

            foreach (PropertyInfo pi in beanType.GetProperties())
            {
                IPropertyType  pt        = null;
                RelnoAttribute relnoAttr = _beanAnnotationReader.GetRelnoAttribute(pi);
                if (relnoAttr != null)
                {
                    if (!_relation)
                    {
                        IRelationPropertyType rpt = CreateRelationPropertyType(beanType, pi, relnoAttr, dbMetaData, dbms);
                        AddRelationPropertyType(rpt);
                    }
                }
                else
                {
                    if (pi.CanWrite)
                    {
                        pt = CreatePropertyTypeExtension(pi, dbmeta);
                        if (pt != null)
                        {
                            AddPropertyType(pt);
                            if (pt.IsPrimaryKey)
                            {
                                _primaryKeyList.add(pt);
                            }
                        }
                    }
                }
                if (IdentifierGenerator == null)
                {
                    IDAttribute idAttr = _beanAnnotationReader.GetIdAttribute(pi, dbms);
                    if (idAttr != null)
                    {
                        _identifierGenerator = Seasar.Dao.Id.IdentifierGeneratorFactory.CreateIdentifierGenerator(pi.Name, dbms, idAttr);
                        if (pt != null)
                        {
                            _primaryKeys    = new string[] { pt.ColumnName };
                            pt.IsPrimaryKey = true;
                        }
                    }
                }
            }
        }
Example #7
0
        private async Task <IDAttribute> GetIDAttributeMapping(int IDUID, int attrUID)
        {
            SQLiteConnection conn = await ConnectToTableAsync <IDAttribute>();

            return(await Task.Run(() =>
            {
                IDAttribute idAttrMapping = conn
                                            .Table <IDAttribute>()
                                            .Where(mapping => mapping.IDUID == IDUID && mapping.AttrUID == attrUID).FirstOrDefault();

                conn.Close();
                return idAttrMapping;
            }));
        }
Example #8
0
        public PocoData(Type t)
        {
            type      = t;
            TableInfo = new TableInfo();

            // Get the table name
            var a = t.GetCustomAttributes(typeof(TableAttribute), true);

            TableInfo.TableName = a.Length == 0 ? t.Name : (a[0] as TableAttribute).Name;


            // Call column mapper
            if (Database.Mapper != null)
            {
                Database.Mapper.GetTableInfo(t, TableInfo);
            }

            // Work out bound properties
            bool ExplicitColumns = t.GetCustomAttributes(typeof(ExplicitColumnsAttribute), true).Length > 0;

            Columns       = new Dictionary <string, PocoColumn>(StringComparer.OrdinalIgnoreCase);
            IgnoreColumns = new Dictionary <string, PocoColumn>(StringComparer.OrdinalIgnoreCase);
            foreach (var pi in t.GetProperties())
            {
                a = pi.GetCustomAttributes(typeof(IDAttribute), true);
                if (a.Length > 0)
                {
                    IDAttribute idAttri = a[0] as IDAttribute;
                    TableInfo.PrimaryKey    = idAttri.Name ?? pi.Name;
                    TableInfo.SequenceName  = idAttri.Name ?? pi.Name;
                    TableInfo.AutoIncrement = idAttri.AutoIncrement;
                }


                // Work out if properties is to be included
                var ColAttrs = pi.GetCustomAttributes(typeof(ColumnAttribute), true);

                if (ExplicitColumns)
                {
                    if (ColAttrs.Length == 0)
                    {
                        continue;
                    }
                }
                else
                {
                }

                var pc = new PocoColumn();
                pc.PropertyInfo = pi;

                // Work out the DB column name
                if (ColAttrs.Length > 0)
                {
                    var colattr = (ColumnAttribute)ColAttrs[0];
                    pc.ColumnName = colattr.Name;
                    if ((colattr as ResultColumnAttribute) != null)
                    {
                        pc.ResultColumn = true;
                    }
                }
                if (pc.ColumnName == null)
                {
                    pc.ColumnName = pi.Name;
                    if (Database.Mapper != null && !Database.Mapper.MapPropertyToColumn(pi, ref pc.ColumnName, ref pc.ResultColumn))
                    {
                        continue;
                    }
                }
                if (pi.GetCustomAttributes(typeof(IgnoreAttribute), true).Length != 0)
                {
                    IgnoreColumns[pc.ColumnName] = pc;
                }
                // Store it
                Columns.Add(pc.ColumnName, pc);
            }
            TableInfo.PrimaryKey   = TableInfo.PrimaryKey ?? "ID";
            TableInfo.SequenceName = TableInfo.SequenceName ?? "ID";
            // Build column list for automatic select
            QueryColumns = (from c in Columns where !c.Value.ResultColumn select c.Key).ToArray();
        }