Example #1
0
        private static void CheckIfAuditTableExists(Type auditRecordType, DatabaseType databaseType)
        {
            var classConfig = ClassConfigContainer.FindClassConfig(auditRecordType);

            var table = classConfig.TableName;

            var sql = string.Empty;

            if (databaseType != DatabaseType.Oracle)
            {
                sql = string.Format("SELECT COUNT(*) " +
                                    "FROM INFORMATION_SCHEMA.TABLES " +
                                    "WHERE TABLE_SCHEMA = '[Schema]'   AND  TABLE_NAME = '{0}'  OR   TABLE_NAME = '{1}' ",
                                    table.ToLower(), table);
            }
            else
            {
                sql = string.Format("SELECT COUNT(*) FROM  ALL_TABLES  WHERE OWNER ='[Schema]'  AND TABLE_NAME ='{0}'",
                                    table);
            }


            var database = DatabaseCreator.CreateDatabase();

            var result = database.ExecuteScalar(sql);

            if (result.ToString() == "0")
            {
                throw new EasylinkException("Audit table {0} does not exist in the database.", table);
            }
        }
Example #2
0
        internal List <PropertyConfig> GetDerivedPropertyConfigs()
        {
            if (_derivedPropertyConfigs == null)
            {
                if (_linkType == LinkType.Property)
                {
                    return(new List <PropertyConfig>());
                }

                _derivedPropertyConfigs = new List <PropertyConfig>();

                var rightClassConfig = ClassConfigContainer.FindClassConfig(RightType);

                foreach (var property in rightClassConfig.Properties)
                {
                    if (!property.IsDerived)
                    {
                        var derived = CreateDerivedProperty(property);

                        _derivedPropertyConfigs.Add(derived);
                    }
                }
            }

            return(_derivedPropertyConfigs);
        }
Example #3
0
        private string GetTableName()
        {
            if (IsDerived)
            {
                return(_link.Alias);
            }
            var myClassConfig = ClassConfigContainer.FindClassConfig(_type);

            return(myClassConfig.TableName);
        }
Example #4
0
        private object  GetOriginal(object obj)
        {
            var classConfig = ClassConfigContainer.FindClassConfig(obj.GetType());

            string idPropertyName = classConfig.IdPropertyName;

            var propertyInfo = obj.GetType().GetProperty(idPropertyName);

            object idPropertyValue = propertyInfo.GetValue(obj, null);

            return(RetrieveOriginal(obj, new Criteria(idPropertyName, "=", idPropertyValue)));
        }
Example #5
0
        private List <Criteria> UpdateCriteria <T>(List <Criteria> criterias)
        {
            var found = ClassConfigContainer.FindClassConfig1 <T>();

            foreach (var criteria in criterias)
            {
                PropertyConfig propertyConfig = found.GetPropertyConfig(criteria.PropertyName);

                if (propertyConfig == null)
                {
                    var temp = criteria.PropertyName.Split(new[] { '.' }).ToList();

                    var propertyName = temp[temp.Count - 1];

                    temp.RemoveAt(temp.Count - 1);

                    var linkName = string.Join(".", temp);

                    var link = found.FindMatchedLink(linkName);


                    if (link != null)
                    {
                        var classConfig = ClassConfigContainer.FindClassConfig(link.RightType);

                        var propertyConfig1 = classConfig.GetPropertyConfig(propertyName);

                        if (propertyConfig1 == null)
                        {
                            throw new EasylinkException(
                                      "Error occurred when updating criteria. property name {0}  is not defined in the {1} mapping.",
                                      criteria.PropertyName, link.RightType.Name);
                        }

                        criteria.SetColumnName(string.Format("{0}.{1}", link.Alias, propertyConfig1.ColumnName));
                    }
                    else
                    {
                        throw new EasylinkException(
                                  "Error occurred when updating criteria. link name {0} is not defined in the {1} mapping.",
                                  linkName, typeof(T).Name);
                    }
                }
                else
                {
                    criteria.SetColumnName(propertyConfig.SelectColumn.Trim());
                }
            }

            return(criterias);
        }
Example #6
0
        internal string GetRightColumnName()
        {
            var classConfig = ClassConfigContainer.FindClassConfig(RightType);

            var propertyConfig = classConfig.GetPropertyConfig(RightPropertyName);

            if (propertyConfig == null)
            {
                throw new EasylinkException("Property name {0} is not defined in {1} mapping class.",
                                            RightPropertyName, RightType.Name);
            }

            return(propertyConfig.ColumnName);
        }
Example #7
0
        private string GetColumnName()
        {
            var getFromClassConfig = ClassConfigContainer.FindClassConfig(_getFromType);

            var getFromPropertyConfig = getFromClassConfig.GetPropertyConfig(_getFromProperty);

            if (getFromPropertyConfig == null)
            {
                throw new EasylinkException("Property [{0}] in class [{1}] column mapping is not set.",
                                            _getFromProperty, _getFromType.Name);
            }
            var columnName = getFromPropertyConfig.ColumnName;


            return(columnName);
        }
Example #8
0
        private Criteria UpdateCriteria(Type objectType, Criteria criteria)
        {
            var found = ClassConfigContainer.FindClassConfig(objectType);


            PropertyConfig propertyConfig = found.GetPropertyConfig(criteria.PropertyName);

            if (propertyConfig == null)
            {
                var temp = criteria.PropertyName.Split(new[] { '.' }).ToList();

                var propertyName = temp[temp.Count - 1];

                temp.RemoveAt(temp.Count - 1);

                var linkName = string.Join(".", temp);

                var link = found.FindMatchedLink(linkName);


                if (link != null)
                {
                    var classConfig = ClassConfigContainer.FindClassConfig(link.RightType);

                    var propertyConfig1 = classConfig.GetPropertyConfig(propertyName);

                    criteria.SetColumnName(string.Format("{0}.{1}", link.Alias, propertyConfig1.ColumnName));
                }
                else
                {
                    throw new EasylinkException(
                              "Error occurred when updating criteria. property name {0} or link name{1} is not found in the {2} mapping.",
                              criteria.PropertyName, linkName, objectType.Name);
                }
            }
            else
            {
                criteria.SetColumnName(propertyConfig.SelectColumn.Trim());
            }

            return(criteria);
        }
Example #9
0
        internal static bool IsAuditable <T>( ) where T : new()
        {
            var classConfig = ClassConfigContainer.FindClassConfig(typeof(T));

            return(classConfig.Auditable);
        }
Example #10
0
        internal override string FindNextIdSql(Type objectType)
        {
            string sequenceName = ClassConfigContainer.FindClassConfig(objectType).SequenceName;

            return(string.Format("SELECT Next VALUE FOR [Schema].{0} as NextId", sequenceName));
        }
Example #11
0
        internal override string FindNextIdSql(Type objectType)
        {
            string sequenceName = ClassConfigContainer.FindClassConfig(objectType).SequenceName;

            return(string.Format("Select [Schema].{0}.NEXTVAL As NextId From DUAL", sequenceName));
        }
Example #12
0
        internal override string FindNextIdSql(Type objectType)
        {
            string sequenceName = ClassConfigContainer.FindClassConfig(objectType).SequenceName;

            return(string.Format("SELECT nextval('{0}') as NextId", sequenceName));
        }
Example #13
0
 internal string GetRightTableName()
 {
     return(ClassConfigContainer.FindClassConfig(RightType).TableName);
 }