/// <summary> /// Mappings to the specified Argument. /// </summary> /// <param name="name">The name.</param> /// <returns></returns> public ArgumentExpression MappingArgument(string name) { Contract.Require.That(name, Is.Not.Null & Is.Not.Empty).When("retrieving name argument in MappingArgument method"); //if (parentConfiguration == null) //{ // argumentExpression = new ArgumentExpression(builder); // parentConfiguration = builder.RegisterConfiguration(); // argumentExpression.parentConfiguration = parentConfiguration; //} //if (argumentExpression == null) //{ // argumentExpression = new ArgumentExpression(builder); // argumentExpression.parentConfiguration = parentConfiguration; //} //currentArgument = new MutableConfiguration(ConfigConstants.ELEMENT_ARGUMENT, name); //currentArgument.CreateAttribute(ConfigConstants.ATTRIBUTE_ARGUMENTNAME, name); //parentConfiguration.Children.Add(currentSubMap); MutableConfiguration configArgument = new MutableConfiguration(ConfigConstants.ELEMENT_ARGUMENT, name); configArgument.CreateAttribute(ConfigConstants.ATTRIBUTE_ARGUMENTNAME, name); builder.CurrentConfiguration.Children.Add(configArgument); ArgumentExpression argumentExpression = new ArgumentExpression(builder, parentConfiguration, configArgument); return argumentExpression; }
/// <summary> /// Processes a parameter map element. /// </summary> /// <param name="element">The element.</param> /// <param name="configurationStore">The configuration store.</param> private void ProcessParameterMapElement(Tag element, IConfigurationStore configurationStore) { MutableConfiguration config = null; if (element.Attributes.ContainsKey(ConfigConstants.ATTRIBUTE_CLASS)) { config = new MutableConfiguration( element.Name, ApplyNamespace(element.Attributes[ConfigConstants.ATTRIBUTE_ID]), element.Attributes[ConfigConstants.ATTRIBUTE_CLASS]); } else { config = new MutableConfiguration( element.Name, ApplyNamespace(element.Attributes[ConfigConstants.ATTRIBUTE_ID])); } config.CreateAttributes(element.Attributes); config.CreateAttribute(ConfigConstants.ATTRIBUTE_NAMESPACE, nameSpace); AddAttribute(config, ConfigConstants.ATTRIBUTE_EXTENDS, true); configurationStore.AddParameterMapConfiguration(config); element.Configuration = config; }
/// <summary> /// Creates the child on the <see cref="MutableConfiguration"/>. /// </summary> /// <param name="name">The name.</param> /// <param name="value">The value.</param> /// <returns>The <see cref="MutableConfiguration"/></returns> public MutableConfiguration CreateChild(string name, string value) { MutableConfiguration child = new MutableConfiguration(name, value); Children.Add(child); return(child); }
/// <summary> /// Serializes the specified <see cref="IDbProvider"/> into an <see cred="IConfiguration" /> node. /// </summary> public static IConfiguration Serialize(IDbProvider dbProvider) { IConfiguration providerConfig = new MutableConfiguration("provider", dbProvider.Id, dbProvider.Id); providerConfig.Attributes[DataConstants.ATTRIBUTE_NAME] = dbProvider.Id; providerConfig.Attributes[DataConstants.ATTRIBUTE_ASSEMBLYNAME] = dbProvider.AssemblyName; providerConfig.Attributes[DataConstants.ATTRIBUTE_COMMANDBUILDERCLASS] = dbProvider.CommandBuilderClass; providerConfig.Attributes[DataConstants.ATTRIBUTE_COMMANDCLASS] = dbProvider.DbCommandClass; providerConfig.Attributes[DataConstants.ATTRIBUTE_CONNECTIONCLASS] = dbProvider.DbConnectionClass; providerConfig.Attributes[DataConstants.ATTRIBUTE_DESCRIPTION] = dbProvider.Description; providerConfig.Attributes[DataConstants.ATTRIBUTE_DEFAULT] = dbProvider.IsDefault.ToString().ToLower(); providerConfig.Attributes[DataConstants.ATTRIBUTE_ENABLED] = dbProvider.IsEnabled.ToString().ToLower(); providerConfig.Attributes[DataConstants.ATTRIBUTE_PARAMETERDBTYPECLASS] = dbProvider.ParameterDbTypeClass; providerConfig.Attributes[DataConstants.ATTRIBUTE_PARAMETERDBTYPEPROPERTY] = dbProvider.ParameterDbTypeProperty; providerConfig.Attributes[DataConstants.ATTRIBUTE_PARAMETERPREFIX] = dbProvider.ParameterPrefix; providerConfig.Attributes[DataConstants.ATTRIBUTE_PARAMETERPREFIX] = dbProvider.ParameterPrefix; providerConfig.Attributes[DataConstants.ATTRIBUTE_SETDBPARAMETERPRECISION] = dbProvider.SetDbParameterPrecision.ToString().ToLower(); providerConfig.Attributes[DataConstants.ATTRIBUTE_SETDBPARAMETERSCALE] = dbProvider.SetDbParameterScale.ToString().ToLower(); providerConfig.Attributes[DataConstants.ATTRIBUTE_SETDBPARAMETERSIZE] = dbProvider.SetDbParameterSize.ToString().ToLower(); providerConfig.Attributes[DataConstants.ATTRIBUTE_USEDERIVEPARAMETERS] = dbProvider.UseDeriveParameters.ToString().ToLower(); providerConfig.Attributes[DataConstants.ATTRIBUTE_USEPARAMETERPREFIXINPARAMETER] = dbProvider.UseParameterPrefixInParameter.ToString().ToLower(); providerConfig.Attributes[DataConstants.ATTRIBUTE_USEPARAMETERPREFIXINSQL] = dbProvider.UseParameterPrefixInSql.ToString().ToLower(); providerConfig.Attributes[DataConstants.ATTRIBUTE_USEPOSITIONALPARAMETERS] = dbProvider.UsePositionalParameters.ToString().ToLower(); providerConfig.Attributes[DataConstants.ATTRIBUTE_ALLOWMARS] = dbProvider.AllowMARS.ToString().ToLower(); return providerConfig; }
/// <summary> /// Processes the database element in the SqlMap.config file. /// </summary> /// <param name="element">The element.</param> /// <param name="configurationStore">The configuration store.</param> private void ProcessDatabaseElement(Tag element, IConfigurationStore configurationStore) { MutableConfiguration config = new MutableConfiguration(element.Name); config.CreateAttributes(element.Attributes); configurationStore.AddDatabaseConfiguration(config); element.Configuration = config; }
/// <summary> /// Adds a Type alias to the store. /// </summary> /// <remarks> /// Uses ConfigConstants.ELEMENT_TYPEALIAS as the value for IConfiguration.Type. /// </remarks> /// <example> /// <code> /// <alias> /// <typeAlias alias="Account" type="MyBatis.DataMapper.Sqlite.Test.Domain.Account, MyBatis.DataMapper.Sqlite.Test"/> /// </alias> /// </code> /// </example> public void AddAlias(Type type, string name) { IConfiguration typeAlias = new MutableConfiguration( ConfigConstants.ELEMENT_TYPEALIAS, name, type.FullName + ", " + type.Assembly.GetName().Name); configurationStore.AddAliasConfiguration(typeAlias); }
/// <summary> /// Processes the type alias element. /// </summary> /// <param name="element">The element.</param> /// <param name="configurationStore">The configuration store.</param> private void ProcessTypeAliasElement(Tag element, IConfigurationStore configurationStore) { IConfiguration config = new MutableConfiguration( element.Name, element.Attributes[ConfigConstants.ATTRIBUTE_ALIAS], element.Attributes[ConfigConstants.ATTRIBUTE_TYPE]); configurationStore.AddAliasConfiguration(config); }
/// <summary> /// Processes the add element in external properties file /// </summary> /// <param name="element">The element.</param> /// <param name="configurationStore">The configuration store.</param> private void ProcessAddElement(Tag element, IConfigurationStore configurationStore) { IConfiguration config = new MutableConfiguration( element.Name, element.Attributes[ConfigConstants.ATTRIBUTE_KEY], element.Attributes[ConfigConstants.ATTRIBUTE_VALUE]); configurationStore.AddPropertyConfiguration(config); }
/// <summary> /// Processes the flush intervall element. /// </summary> /// <param name="element">The element.</param> /// <param name="configurationStore">The configuration store.</param> private void ProcessFlushIntervallElement(Tag element, IConfigurationStore configurationStore) { if (element.Parent != null && element.Parent.Name == ConfigConstants.ELEMENT_CACHEMODEL) { MutableConfiguration config = new MutableConfiguration(element.Name); config.CreateAttributes(element.Attributes); element.Parent.Configuration.Children.Add(config); } }
/// <summary> /// Processes the constructor element. /// </summary> /// <param name="element">The element.</param> /// <param name="configurationStore">The configuration store.</param> private void ProcessConstructorElement(Tag element, IConfigurationStore configurationStore) { if (element.Parent != null && element.Parent.Name == ConfigConstants.ELEMENT_RESULTMAP) { IConfiguration config = new MutableConfiguration(element.Name); element.Configuration = config; element.Parent.Configuration.Children.Add(config); } }
/// <summary> /// Processes the Sql element. /// </summary> /// <param name="element">The element.</param> /// <param name="configurationStore">The configuration store.</param> private void ProcessSqlElement(Tag element, IConfigurationStore configurationStore) { MutableConfiguration config = new MutableConfiguration( element.Name, element.Attributes[ConfigConstants.ATTRIBUTE_ID]); config.CreateAttribute(ConfigConstants.ATTRIBUTE_NAMESPACE, nameSpace); configurationStore.AddStatementConfiguration(config); element.Configuration = config; }
/// <summary> /// Processes the type handler element. /// </summary> /// <param name="element">The element.</param> /// <param name="configurationStore">The configuration store.</param> private void ProcessTypeHandlerElement(Tag element, IConfigurationStore configurationStore) { MutableConfiguration config = new MutableConfiguration( element.Name, element.Attributes[ConfigConstants.ATTRIBUTE_TYPE] ); config.CreateAttributes(element.Attributes); configurationStore.AddTypeHandlerConfiguration(config); }
/// <summary> /// Processes a cache model element. /// </summary> /// <param name="element">The element.</param> /// <param name="configurationStore">The configuration store.</param> private void ProcessCacheModelElement(Tag element, IConfigurationStore configurationStore) { MutableConfiguration config = new MutableConfiguration( element.Name, ApplyNamespace(element.Attributes[ConfigConstants.ATTRIBUTE_ID]), element.Attributes[ConfigConstants.ATTRIBUTE_TYPE]); config.CreateAttributes(element.Attributes); config.CreateAttribute(ConfigConstants.ATTRIBUTE_NAMESPACE, nameSpace); configurationStore.AddCacheConfiguration(config); element.Configuration = config; }
/// <summary> /// Processes the Include element. /// </summary> /// <param name="element">The element.</param> /// <param name="configurationStore">The configuration store.</param> private void ProcessIncludeElement(Tag element, IConfigurationStore configurationStore) { MutableConfiguration config = new MutableConfiguration( element.Name, element.Attributes[ConfigConstants.ATTRIBUTE_REFID]); config.CreateAttribute(ConfigConstants.ATTRIBUTE_NAMESPACE, nameSpace); config.CreateAttributes(element.Attributes); config.Parent = element.Parent.Configuration; element.Parent.Configuration.Children.Add(config); element.Configuration = config; }
/// <summary> /// Processes the parameter element. /// </summary> /// <param name="element">The element.</param> /// <param name="configurationStore">The configuration store.</param> private void ProcessParameterElement(Tag element, IConfigurationStore configurationStore) { if (element.Parent != null && element.Parent.Name == ConfigConstants.ELEMENT_PARAMETERMAP) { MutableConfiguration config = new MutableConfiguration( element.Name, element.Attributes[ConfigConstants.ATTRIBUTE_PROPERTY]); config.CreateAttributes(element.Attributes); element.Parent.Configuration.Children.Add(config); } }
/// <summary> /// Processes the flush on execute element. /// </summary> /// <param name="element">The element.</param> /// <param name="configurationStore">The configuration store.</param> private void ProcessFlushOnExecuteElement(Tag element, IConfigurationStore configurationStore) { if (element.Parent != null && element.Parent.Name == ConfigConstants.ELEMENT_CACHEMODEL) { MutableConfiguration config = new MutableConfiguration( element.Name, element.Attributes[ConfigConstants.ATTRIBUTE_STATEMENT]); config.CreateAttributes(element.Attributes); element.Parent.Configuration.Children.Add(config); } }
/// <summary> /// Processes the argument element. /// </summary> /// <param name="element">The element.</param> /// <param name="configurationStore">The configuration store.</param> private void ProcessArgumentElement(Tag element, IConfigurationStore configurationStore) { if (element.Parent != null && element.Parent.Name == ConfigConstants.ELEMENT_CONSTRUCTOR) { MutableConfiguration config = new MutableConfiguration( element.Name, element.Attributes[ConfigConstants.ATTRIBUTE_ARGUMENTNAME]); config.CreateAttributes(element.Attributes); element.Parent.Configuration.Children.Add(config); } }
/// <summary> /// Processes the dynamic elements. /// </summary> /// <param name="element">The element.</param> /// <param name="configurationStore">The configuration store.</param> private void ProcessDynamicElement(Tag element, IConfigurationStore configurationStore) { if (element.Parent != null) { MutableConfiguration config = new MutableConfiguration(element.Name); config.CreateAttributes(element.Attributes); config.Parent = element.Parent.Configuration; element.Parent.Configuration.Children.Add(config); element.Configuration = config; } }
/// <summary> /// Processes the DataSource element in the SqlMap.config file. /// </summary> /// <param name="element">The element.</param> /// <param name="configurationStore">The configuration store.</param> private void ProcessDataSourceElement(Tag element, IConfigurationStore configurationStore) { if (element.Parent != null && element.Parent.Name == ConfigConstants.ELEMENT_DATABASE) { MutableConfiguration config = new MutableConfiguration( element.Name, element.Attributes[DataConstants.ATTRIBUTE_NAME], element.Attributes[DataConstants.ATTRIBUTE_CONNECTIONSTRING]); config.CreateAttributes(element.Attributes); element.Parent.Configuration.Children.Add(config); } }
/// <summary> /// Processes the discriminator element. /// </summary> /// <param name="element">The element.</param> /// <param name="configurationStore">The configuration store.</param> private void ProcessDiscriminatorElement(Tag element, IConfigurationStore configurationStore) { if (element.Parent != null && element.Parent.Name == ConfigConstants.ELEMENT_RESULTMAP) { MutableConfiguration config = new MutableConfiguration( element.Name, element.Attributes[ConfigConstants.ATTRIBUTE_COLUMN]); config.CreateAttributes(element.Attributes); element.Configuration = config; element.Parent.Configuration.Children.Add(config); } }
/// <summary> /// Processes the setting element in the SqlMap.config file. /// </summary> /// <param name="element">The element.</param> /// <param name="configurationStore">The configuration store.</param> private void ProcessSettingElement(Tag element, IConfigurationStore configurationStore) { // <setting hello="world" /> string settingKey = element.GetAttributeName(0); string settingValue = element.GetAttributeValue(0); IConfiguration config = new MutableConfiguration( element.Name, settingKey, settingValue); configurationStore.AddSettingConfiguration(config); }
/// <summary> /// Processes the discriminator/case element. /// </summary> /// <param name="element">The element.</param> /// <param name="configurationStore">The configuration store.</param> private void ProcessCaseElement(Tag element, IConfigurationStore configurationStore) { if (element.Parent != null && element.Parent.Name == ConfigConstants.ELEMENT_DISCRIMINATOR) { MutableConfiguration config = new MutableConfiguration( element.Name, element.Attributes[ConfigConstants.ATTRIBUTE_VALUE]); config.CreateAttributes(element.Attributes); AddAttribute(config, ConfigConstants.ATTRIBUTE_RESULTMAP, true); element.Parent.Configuration.Children.Add(config); } }
/// <summary> /// Processes the result map element. /// </summary> /// <param name="element">The element.</param> /// <param name="configurationStore">The configuration store.</param> private void ProcessResultMapElement(Tag element, IConfigurationStore configurationStore) { MutableConfiguration config = new MutableConfiguration( element.Name, ApplyNamespace(element.Attributes[ConfigConstants.ATTRIBUTE_ID]), element.Attributes[ConfigConstants.ATTRIBUTE_CLASS]); config.CreateAttributes(element.Attributes); config.CreateAttribute(ConfigConstants.ATTRIBUTE_NAMESPACE, nameSpace); AddAttribute(config, ConfigConstants.ATTRIBUTE_EXTENDS, true); configurationStore.AddResultMapConfiguration(config); element.Configuration = config; }
/// <summary> /// Processes the discriminator/default element. /// </summary> /// <param name="element">The element.</param> /// <param name="configurationStore">The configuration store.</param> private void ProcessDefaultElement(Tag element, IConfigurationStore configurationStore) { if (element.Parent != null && element.Parent.Name == ConfigConstants.ELEMENT_DISCRIMINATOR) { MutableConfiguration config = new MutableConfiguration( ConfigConstants.ELEMENT_CASE, Discriminator.DEFAULT_KEY); config.CreateAttributes(element.Attributes); config.CreateAttribute(ConfigConstants.ATTRIBUTE_VALUE, Discriminator.DEFAULT_KEY); AddAttribute(config, ConfigConstants.ATTRIBUTE_RESULTMAP, true); element.Parent.Configuration.Children.Add(config); } }
/// <summary> /// Processes the text element. /// </summary> /// <param name="element">The element.</param> /// <param name="configurationStore">The configuration store.</param> protected override void ProcessTextElement(Tag element, IConfigurationStore configurationStore) { if (element.Parent != null) { string text = element.Value.Replace('\n', ' ').Replace('\r', ' ').Replace('\t', ' ').Trim(); MutableConfiguration config = new MutableConfiguration( element.Name, string.Empty, element.Value); // text); element.Parent.Configuration.Children.Add(config); element.Configuration = config; } }
/// <summary> /// Processes the statement element. /// </summary> /// <param name="element">The element.</param> /// <param name="configurationStore">The configuration store.</param> private void ProcessStatementElement(Tag element, IConfigurationStore configurationStore) { MutableConfiguration config = new MutableConfiguration( element.Name, element.Attributes[ConfigConstants.ATTRIBUTE_ID]); config.CreateAttributes(element.Attributes); config.CreateAttribute(ConfigConstants.ATTRIBUTE_NAMESPACE, nameSpace); AddAttribute(config, ConfigConstants.ATTRIBUTE_CACHEMODEL, true); AddAttribute(config, ConfigConstants.ELEMENT_PARAMETERMAP, true); AddAttribute(config, ConfigConstants.ELEMENT_RESULTMAP, true); AddAttribute(config, ConfigConstants.ELEMENT_PRESERVEWHITESPACE, false); configurationStore.AddStatementConfiguration(config); element.Configuration = config; }
/// <summary> /// Extendses the specified parameter map. /// </summary> /// <param name="extend">The extend id.</param> /// <returns></returns> public ParameterExpression Extends(string extend) { Contract.Require.That(extend, Is.Not.Null & Is.Not.Empty).When("retrieving extend argument in Extends method"); if (parentConfiguration == null) { parameterExpression = new ParameterExpression(builder); parentConfiguration = builder.RegisterConfiguration(); parameterExpression.parentConfiguration = parentConfiguration; } if (parameterExpression == null) { parameterExpression = new ParameterExpression(builder); parameterExpression.parentConfiguration = parentConfiguration; } parentConfiguration.CreateAttribute(ConfigConstants.ATTRIBUTE_EXTENDS, builder.ApplyNamespace(extend)); return parameterExpression; }
/// <summary> /// Processes the provider element in the providers.config file. /// </summary> /// <param name="element">The element.</param> /// <param name="configurationStore">The configuration store.</param> private void ProcessProviderElement(Tag element, IConfigurationStore configurationStore) { // provider child tag of Database tag if (element.Parent != null && element.Parent.Name == "database") { MutableConfiguration config = new MutableConfiguration( element.Name, element.Attributes[DataConstants.ATTRIBUTE_NAME], element.Attributes[DataConstants.ATTRIBUTE_NAME]); config.CreateAttributes(element.Attributes); element.Parent.Configuration.Children.Add(config); } else { MutableConfiguration config = new MutableConfiguration( element.Name, element.Attributes[DataConstants.ATTRIBUTE_NAME]); config.CreateAttributes(element.Attributes); configurationStore.AddProviderConfiguration(config); } }
/// <summary> /// Processes the property element in the SqlMap.config file. /// </summary> /// <param name="element">The element.</param> /// <param name="configurationStore">The configuration store.</param> private void ProcessPropertyElement(Tag element, IConfigurationStore configurationStore) { if (element.Parent.Name != ConfigConstants.ELEMENT_CACHEMODEL) { if (element.Attributes.ContainsKey(ConfigConstants.ATTRIBUTE_URI)) { string uri = element.Attributes[ConfigConstants.ATTRIBUTE_URI]; using (XmlTextReader reader = Resources.GetUriAsXmlReader(uri)) { this.Process(reader, configurationStore); } } else { IConfiguration config = new MutableConfiguration( element.Name, element.Attributes[ConfigConstants.ATTRIBUTE_KEY], element.Attributes[ConfigConstants.ATTRIBUTE_VALUE]); configurationStore.AddPropertyConfiguration(config); } } }
/// <summary> /// Registers the current configuration. /// </summary> /// <returns></returns> public MutableConfiguration RegisterConfiguration() { MutableConfiguration configuration = currentConfiguration; if (currentConfiguration!=null) { switch(currentConfiguration.Type) { case ConfigConstants.ELEMENT_TYPEALIAS: store.AddAliasConfiguration(currentConfiguration); break; case ConfigConstants.ELEMENT_TYPEHANDLER: store.AddTypeHandlerConfiguration(currentConfiguration); break; case ConfigConstants.ELEMENT_RESULTMAP: store.AddResultMapConfiguration(currentConfiguration); break; case ConfigConstants.ELEMENT_PARAMETERMAP: store.AddParameterMapConfiguration(currentConfiguration); break; case ConfigConstants.ELEMENT_RESULT: case ConfigConstants.ELEMENT_DISCRIMINATOR: case ConfigConstants.ELEMENT_CONSTRUCTOR: case ConfigConstants.ELEMENT_PARAMETER: break; default: throw new DataMapperException("Invalid configuration registration for configuration type:" + currentConfiguration.Type); } currentConfiguration = null; } return configuration; }
/// <summary> /// Creates the child on the <see cref="MutableConfiguration"/>. /// </summary> /// <param name="name">The name.</param> /// <param name="value">The value.</param> /// <returns>The <see cref="MutableConfiguration"/></returns> public MutableConfiguration CreateChild(string name, string value) { MutableConfiguration child = new MutableConfiguration(name, value); Children.Add(child); return child; }