Ejemplo n.º 1
0
        public virtual IParameter ReadParameterAttribute(MemberInfo memberInfo)
        {
            P parameter = Activator.CreateInstance<P>();

            ParameterAttribute statementParameterAttribute = (ParameterAttribute)Attribute.GetCustomAttribute(memberInfo, typeof(ParameterAttribute), true);
            PA sqlServerParameterAttribute = (PA)Attribute.GetCustomAttribute(memberInfo, typeof(PA), true);

            if (statementParameterAttribute == null)
            {
                if (sqlServerParameterAttribute != null)
                {
                    throw AttributeException.ColumnAttributeNotFoundException(memberInfo, typeof(PA));
                }
                else
                {
                    return null;
                }
            }

            
            SetParameterValue(parameter, memberInfo, statementParameterAttribute, sqlServerParameterAttribute);

 

            return parameter;
        }
Ejemplo n.º 2
0
        public virtual IStatement ReadStatementAttribute(Type commandType)
        { 
            S statement = Activator.CreateInstance<S>();
            StatementAttribute statementAttribute = (StatementAttribute)Attribute.GetCustomAttribute(commandType, typeof(StatementAttribute), true);
            SA oracleStatementAttribute = (SA)Attribute.GetCustomAttribute(commandType, typeof(SA), true);
            if (statementAttribute == null)
            {
                if (oracleStatementAttribute != null)
                {
                    throw AttributeException.StatementAttributeNotFoundException(commandType, typeof(SA));
                }
                else
                {
                    return null;
                }
            }

            SetStatementValue(statement,commandType, statementAttribute, oracleStatementAttribute);
            return statement;
        }
Ejemplo n.º 3
0
        public virtual ITable ReadTableAttribute(Type entityType)
        {
            T table = Activator.CreateInstance<T>();

            TableAttribute tableAttribute = (TableAttribute)Attribute.GetCustomAttribute(entityType, typeof(TableAttribute), true);
            TA attr = (TA)Attribute.GetCustomAttribute(entityType, typeof(TA), true);
            if (tableAttribute == null)
            {
                if (attr != null)
                {
                    throw AttributeException.TableAttributeNotFoundException(entityType, typeof(TA));
                }
                else
                {
                    //throw ExceptionFactory.AttributeNotFoundException(entityType.Type, typeof(TableAttribute));
                    return null;
                }
            }

            SetTableValue(table, entityType, tableAttribute, attr);
            return table;
        }
Ejemplo n.º 4
0
        public IStatement GetStatement(object commandType)
        {
            Type type = (Type)commandType;

            if (!statements.ContainsKey(type))
            {
                lock (statements)
                {
                    if (!statements.ContainsKey(type))
                    {
                        IStatement command = attributeReader.ReadStatementAttribute(type);
                        if (command == null)
                        {
                            throw AttributeException.AttributeNotFoundException(type, typeof(StatementAttribute));
                        }
                        command.CreateCache();
                        statements.Add(type, command);
                    }
                }
            }
            return(statements[type]);
        }
Ejemplo n.º 5
0
        public ITable GetTable(object entityType)
        {
            Type type = (Type)entityType;

            if (!tables.ContainsKey(type))
            {
                lock (tables)
                {
                    if (!tables.ContainsKey(type))
                    {
                        ITable table = attributeReader.ReadTableAttribute(type);
                        if (table == null)
                        {
                            throw AttributeException.AttributeNotFoundException(type, typeof(TableAttribute));
                        }
                        //必须要查找出RelationColumn的ColumnName
                        foreach (IRelation relation in table.Relations.Values)
                        {
                            foreach (IRelationColumn relationColumn in relation.RelationColumns)
                            {
                                string columnName        = table.Columns[relationColumn.PropertyName].ColumnName;
                                Type   foreignEntityType = (Type)(relation.ForeignEntityType);
                                ITable t = attributeReader.ReadTableAttribute(foreignEntityType);
                                if (t == null)
                                {
                                    throw AttributeException.AttributeNotFoundException(foreignEntityType, typeof(TableAttribute));
                                }
                                string foreignColumnName = t.Columns[relationColumn.ForeignPropertyName].ColumnName;
                                relationColumn.ColumnName        = columnName;
                                relationColumn.ForeignColumnName = foreignColumnName;
                            }
                        }
                        table.CreateCache();
                        tables.Add(type, table);
                    }
                }
            }
            return(tables[type]);
        }
Ejemplo n.º 6
0
        public virtual IColumn ReadColumnAttribute(MemberInfo memberInfo)
        {
            C column = Activator.CreateInstance<C>();
            ColumnAttribute columnAttribute = (ColumnAttribute)Attribute.GetCustomAttribute(memberInfo, typeof(ColumnAttribute), true);
            CA sqlColumnAttribute = (CA)Attribute.GetCustomAttribute( memberInfo, typeof(CA), true);

            if (columnAttribute == null)
            {
                if (sqlColumnAttribute != null)
                {
                    throw AttributeException.ColumnAttributeNotFoundException(memberInfo, typeof(CA));
                }
                else
                {
                    return null;
                }
            }

            
            SetColumnValue(column, memberInfo, columnAttribute, sqlColumnAttribute);

             
            return column;
        }