/// <summary> /// Builds the data source model. /// </summary> /// <param name="store">The store.</param> private void BuildDataSource(IConfigurationStore store) { if (dataSource == null) { IConfiguration dataBaseConfig = store.Databases[0]; IConfiguration providerConfig = dataBaseConfig.Children.Find(DataConstants.ELEMENT_PROVIDER)[0]; string key = providerConfig.Value ?? providerConfig.GetAttributeValue(DataConstants.ATTRIBUTE_NAME); IDbProvider dbProvider = dbProviderFactory.GetDbProvider(key); dataSource = DataSourceDeSerializer.Deserialize(dbProvider, commandTimeOut, dataBaseConfig); } }
// /// <summary> // /// Build a provider // /// </summary> // /// <param name="node"></param> // /// <returns></returns> // /// <remarks> // /// Not use, I use it to test if it faster than serializer. // /// But the tests are not concluant... // /// </remarks> // private static Provider BuildProvider(XmlNode node) // { // XmlAttribute attribute = null; // Provider provider = new Provider(); // // attribute = node.Attributes["assemblyName"]; // provider.AssemblyName = attribute.Value; // attribute = node.Attributes["default"]; // if (attribute != null) // { // provider.IsDefault = Convert.ToBoolean( attribute.Value ); // } // attribute = node.Attributes["enabled"]; // if (attribute != null) // { // provider.IsEnabled = Convert.ToBoolean( attribute.Value ); // } // attribute = node.Attributes["connectionClass"]; // provider.ConnectionClass = attribute.Value; // attribute = node.Attributes["UseParameterPrefixInSql"]; // if (attribute != null) // { // provider.UseParameterPrefixInSql = Convert.ToBoolean( attribute.Value ); // } // attribute = node.Attributes["useParameterPrefixInParameter"]; // if (attribute != null) // { // provider.UseParameterPrefixInParameter = Convert.ToBoolean( attribute.Value ); // } // attribute = node.Attributes["usePositionalParameters"]; // if (attribute != null) // { // provider.UsePositionalParameters = Convert.ToBoolean( attribute.Value ); // } // attribute = node.Attributes["commandClass"]; // provider.CommandClass = attribute.Value; // attribute = node.Attributes["parameterClass"]; // provider.ParameterClass = attribute.Value; // attribute = node.Attributes["parameterDbTypeClass"]; // provider.ParameterDbTypeClass = attribute.Value; // attribute = node.Attributes["parameterDbTypeProperty"]; // provider.ParameterDbTypeProperty = attribute.Value; // attribute = node.Attributes["dataAdapterClass"]; // provider.DataAdapterClass = attribute.Value; // attribute = node.Attributes["commandBuilderClass"]; // provider.CommandBuilderClass = attribute.Value; // attribute = node.Attributes["commandBuilderClass"]; // provider.CommandBuilderClass = attribute.Value; // attribute = node.Attributes["name"]; // provider.Name = attribute.Value; // attribute = node.Attributes["parameterPrefix"]; // provider.ParameterPrefix = attribute.Value; // // return provider; // } /// <summary> /// Build the data source object /// </summary> /// <param name="configurationScope">The scope of the configuration</param> /// <returns>A DataSource</returns> private DataSource ParseDataSource(ConfigurationScope configurationScope) { DataSource dataSource = null; XmlNode node = configurationScope.NodeContext.SelectSingleNode(ApplyNamespacePrefix(XML_DATABASE_DATASOURCE), configurationScope.XmlNamespaceManager); configurationScope.ErrorContext.Resource = node.InnerXml.ToString(); configurationScope.ErrorContext.MoreInfo = "configure data source"; dataSource = DataSourceDeSerializer.Deserialize(node); // (DataSource)serializer.Deserialize(new XmlNodeReader(node)); dataSource.ConnectionString = NodeUtils.ParsePropertyTokens(dataSource.ConnectionString, configurationScope.Properties); configurationScope.ErrorContext.Resource = string.Empty; configurationScope.ErrorContext.MoreInfo = string.Empty; return(dataSource); }
/// <summary> /// Builds the data source model. /// </summary> /// <param name="store">The store.</param> private void BuildDataSource(IConfigurationStore store) { if (dataSource == null) { /* * <database> * <provider name="sqlServer2.0" /> * <dataSource name="iBatisNet" connectionString="data source=${datasource};database=${database};Integrated Security=SSPI;" /> * </database> */ //取第一个配置文件对应的数据连接节点database IConfiguration dataBaseConfig = store.Databases[0]; IConfiguration providerConfig = dataBaseConfig.Children.Find(DataConstants.ELEMENT_PROVIDER)[0]; string key = providerConfig.Value ?? providerConfig.GetAttributeValue(DataConstants.ATTRIBUTE_NAME); //去工厂类中获得对应的DbProvider IDbProvider dbProvider = dbProviderFactory.GetDbProvider(key); //初始化DataSource对象 dataSource = DataSourceDeSerializer.Deserialize(dbProvider, commandTimeOut, dataBaseConfig); } }