//获取对应的SQL 语句
        private SqlString[] getSqlString(Type entityType, OperationType operationType)
        {
            ModelMappingInfo mappingInfo = AttMappingManager.Instance.GetModelMappingInfo(entityType);
            string           xmlFileName = mappingInfo.XmlConfigFileName;
            string           sqlName     = getSqlName(operationType);

            MB.Orm.Mapping.Xml.SqlConfigHelper xmlConfig = MB.Orm.Mapping.Xml.SqlConfigHelper.Instance;

            SqlString[] sqlStrs  = xmlConfig.GetSqlString(xmlFileName, sqlName);
            string      cacheKey = GenerateCacheKey(entityType, operationType);

            CacheProxy.CacheSql(cacheKey, sqlStrs);
            return(sqlStrs);
        }
Esempio n. 2
0
        /// <summary>
        /// 根据配置的属性信息生成选择的Select 语句。
        /// </summary>
        /// <param name="entityType"></param>
        /// <param name="properties"></param>
        /// <returns></returns>
        public override SqlString[] GenerateSimpleSelectSql(Type entityType, string[] properties)
        {
            ModelMappingInfo mappingInfo = AttMappingManager.Instance.GetModelMappingInfo(entityType);
            string           tableName   = mappingInfo.MapTable;
            List <string>    columns     = prepareSelectSql(mappingInfo, properties);

            string sql = new StringBuilder("SELECT ").Append(string.Join(",", columns.ToArray())).Append(" FROM ").Append(tableName).ToString();

            SqlString ss       = new SqlString(sql, null);
            string    cacheKey = GenerateCacheKey(entityType, OperationType.Select, properties);

            SqlString[] asql = new SqlString[] { ss };
            CacheProxy.CacheSql(cacheKey, asql);
            return(asql);
        }
Esempio n. 3
0
        /// <summary>
        /// 通过键值自动获取某一条记录的SQL 语句。
        /// </summary>
        /// <param name="entityType"></param>
        /// <param name="properties"></param>
        /// <returns></returns>
        public override SqlString[] GenerateFindByKeySql(Type entityType, string[] properties)
        {
            ModelMappingInfo    mappingInfo  = AttMappingManager.Instance.GetModelMappingInfo(entityType);
            string              tableName    = mappingInfo.MapTable;
            List <string>       whereString  = new List <string>();
            List <SqlParamInfo> sqlParams    = new List <SqlParamInfo>();
            List <string>       selectString = prepareUpdateSql(mappingInfo, properties, ref whereString, ref sqlParams);
            SqlString           ss           = new SqlString(new StringBuilder("SELECT ").Append(string.Join(",", selectString.ToArray()))
                                                             .Append(" FROM ").Append(tableName).Append(" WHERE ").Append(string.Join(" AND ", whereString.ToArray())).ToString(), sqlParams);

            string cacheKey = GenerateCacheKey(entityType, OperationType.SelectByKey, properties);

            SqlString[] asql = new SqlString[] { ss };
            CacheProxy.CacheSql(cacheKey, asql);
            return(asql);
        }
Esempio n. 4
0
        /// <summary>
        /// 根据对象配置信息获取自动生成的Delete SQL 语句。
        /// </summary>
        /// <param name="entityType"></param>
        /// <returns></returns>
        public override SqlString[] GenerateDeleteSql(Type entityType)
        {
            SqlString        sqlStr      = null;
            ModelMappingInfo mappingInfo = AttMappingManager.Instance.GetModelMappingInfo(entityType);

            string tableName = mappingInfo.MapTable;
            List <SqlParamInfo> sqlParams   = new List <SqlParamInfo>();
            List <string>       whereString = prepareDeleteSql(mappingInfo, ref sqlParams);

            StringBuilder strSqlBuilder = new StringBuilder();

            strSqlBuilder.Append(" DELETE FROM ").Append(tableName).Append(" WHERE ").Append(string.Join(" AND ", whereString.ToArray()));

            sqlStr = new SqlString(strSqlBuilder.ToString(), sqlParams);

            string cacheKey = GenerateCacheKey(entityType, OperationType.Delete);

            SqlString[] asql = new SqlString[] { sqlStr };
            CacheProxy.CacheSql(cacheKey, asql);
            return(asql);
        }
Esempio n. 5
0
        /// <summary>
        /// 根据配置的信息自动产生Insert 的SQL 语句。
        /// </summary>
        /// <param name="entityType"></param>
        /// <param name="properties"></param>
        /// <returns></returns>
        public override SqlString[] GenerateInsertSql(Type entityType, string[] properties)
        {
            SqlString        sqlStr      = null;
            ModelMappingInfo mappingInfo = AttMappingManager.Instance.GetModelMappingInfo(entityType);

            string tableName = mappingInfo.MapTable;

            List <string>       parameters = new List <string>();
            List <SqlParamInfo> sqlParams  = new List <SqlParamInfo>();
            List <string>       fields     = prepareInsertSql(mappingInfo, properties, ref parameters, ref sqlParams);

            StringBuilder strSqlBuilder = new StringBuilder("INSERT INTO ").
                                          Append(tableName).Append("(").Append(string.Join(",", fields.ToArray())).
                                          Append(") VALUES(").Append(string.Join(",", parameters.ToArray())).Append(") ");

            sqlStr = new SqlString(strSqlBuilder.ToString(), sqlParams);

            string cacheKey = GenerateCacheKey(entityType, OperationType.Insert);

            SqlString[] asql = new SqlString[] { sqlStr };
            CacheProxy.CacheSql(cacheKey, asql);
            return(asql);
        }