/// <summary>
        /// With a discriminator on the specified column.
        /// </summary>
        /// <param name="column">The column.</param>
        /// <returns></returns>
        public DiscriminatorExpression WithDiscriminator <TType, TTypeHandler>(string column)
        {
            Contract.Require.That(column, Is.Not.Null & Is.Not.Empty).When("retrieving column argument in WithDiscriminator method");

            Type type        = typeof(TType);
            Type typeHandler = typeof(TTypeHandler);
            MutableConfiguration configuration = new MutableConfiguration(ConfigConstants.ELEMENT_DISCRIMINATOR, column);

            configuration.CreateAttribute(ConfigConstants.ATTRIBUTE_COLUMN, column);
            configuration.CreateAttribute(ConfigConstants.ATTRIBUTE_TYPE, type.AssemblyQualifiedName);
            configuration.CreateAttribute(ConfigConstants.ATTRIBUTE_TYPEHANDLER, typeHandler.AssemblyQualifiedName);

            if (parentConfiguration == null)
            {
                discriminatorExpression = new DiscriminatorExpression(builder);
                parentConfiguration     = builder.RegisterConfiguration();
                discriminatorExpression.parentConfiguration = parentConfiguration;
            }
            if (discriminatorExpression == null)
            {
                discriminatorExpression = new DiscriminatorExpression(builder);
                discriminatorExpression.parentConfiguration = parentConfiguration;
            }

            builder.CurrentConfiguration = configuration;

            parentConfiguration.Children.Add(builder.CurrentConfiguration);

            return(discriminatorExpression);
        }
Example #2
0
        /// <summary>
        /// To the Column name.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <returns></returns>
        public ArgumentExpression ToColumnName(string name)
        {
            Contract.Require.That(name, Is.Not.Null & Is.Not.Empty).When("retrieving name argument in ToColumnName method");

            currentArgument.CreateAttribute(ConfigConstants.ATTRIBUTE_COLUMN, name);

            return(this);
        }
        /// <summary>
        /// Registers a TypeHandler.
        /// </summary>
        /// <returns>The TypeHandler identifiant</returns>
        public string RegisterTypeHandler <THandler, TCallBack>()
        {
            RegisterConfiguration();

            Type typeHandler = typeof(THandler);
            Type callBack    = typeof(TCallBack);

            currentConfiguration = new MutableConfiguration(
                ConfigConstants.ELEMENT_TYPEHANDLER,
                typeHandler.Name
                );
            currentConfiguration.CreateAttribute(ConfigConstants.ATTRIBUTE_CALLBACK, callBack.AssemblyQualifiedName);
            currentConfiguration.CreateAttribute(ConfigConstants.ATTRIBUTE_TYPE, typeHandler.Name);

            return(currentConfiguration.Id);
        }
        /// <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>
        /// For the value.
        /// </summary>
        /// <param name="value">The value.</param>
        /// <returns></returns>
        public DiscriminatorExpression ForValue(string value)
        {
            Contract.Require.That(value, Is.Not.Null & Is.Not.Empty).When("retrieving value argument in ForValue method");

            currentSubMap.CreateAttribute(ConfigConstants.ATTRIBUTE_VALUE, value);

            return(this);
        }
Example #6
0
        /// <summary>
        /// Registers a ParameterMap.
        /// </summary>
        /// <param name="id">The id.</param>
        public ParameterMapExpression RegisterParameterMap <TParameterClass>(string id)
        {
            Contract.Require.That(id, Is.Not.Null & Is.Not.Empty).When("retrieving id argument in RegisterParameterMap method");

            RegisterConfiguration();
            parameterMapExpression = new ParameterMapExpression(this);

            Type parameterType = typeof(TParameterClass);

            currentConfiguration = new MutableConfiguration(
                ConfigConstants.ELEMENT_PARAMETERMAP,
                ApplyNamespace(id),
                parameterType.AssemblyQualifiedName);
            currentConfiguration.CreateAttribute(ConfigConstants.ATTRIBUTE_CLASS, parameterType.AssemblyQualifiedName);
            currentConfiguration.CreateAttribute(ConfigConstants.ATTRIBUTE_NAMESPACE, nameSpace);

            return(parameterMapExpression);
        }
        /// <summary>
        /// Adds a database configuration item to the store.
        /// </summary>
        /// <example>
        /// <code>
        /// &lt;database&gt;
        ///  &lt;provider name="SQLite3"/&gt;
        ///  &lt;dataSource name="ibatisnet.sqlmap" connectionString="Data Source=ibatisnet.sqlite;Version=3;"/&gt;
        /// &lt;/database&gt;
        /// </code>
        /// </example>
        public void AddDatabase(IDbProvider dbProvider, string dataSourceConnectionString)
        {
            // hack: serialize the object to IConfiguration so it can eventually be converted back to IDbProvider
            configurationStore.AddProviderConfiguration(ProviderSerializer.Serialize(dbProvider));

            MutableConfiguration database = new MutableConfiguration(ConfigConstants.ELEMENT_DATABASE);

            MutableConfiguration provider = database.CreateChild("provider");

            provider.CreateAttribute(ConfigConstants.ATTRIBUTE_NAME, dbProvider.Id);

            MutableConfiguration dataSource = database.CreateChild("dataSource");

            dataSource.CreateAttribute(ConfigConstants.ATTRIBUTE_NAME, "defaultDataSource");
            dataSource.CreateAttribute("connectionString", dataSourceConnectionString);

            configurationStore.AddDatabaseConfiguration(database);
        }
        /// <summary>
        /// Registers a TypeHandler.
        /// </summary>
        /// <param name="dbType">Type of the db.</param>
        /// <returns>The TypeHandler identifiant</returns>
        public string RegisterTypeHandler <THandler, TCallBack>(string dbType)
        {
            Contract.Require.That(dbType, Is.Not.Null & Is.Not.Empty).When("retrieving dbType argument in RegisterTypeHandler method");

            RegisterConfiguration();

            Type typeHandler = typeof(THandler);
            Type callBack    = typeof(TCallBack);

            currentConfiguration = new MutableConfiguration(
                ConfigConstants.ELEMENT_TYPEHANDLER,
                typeHandler.Name
                );
            currentConfiguration.CreateAttribute(ConfigConstants.ATTRIBUTE_DBTYPE, dbType);
            currentConfiguration.CreateAttribute(ConfigConstants.ATTRIBUTE_CALLBACK, callBack.AssemblyQualifiedName);
            currentConfiguration.CreateAttribute(ConfigConstants.ATTRIBUTE_TYPE, typeHandler.Name);

            return(currentConfiguration.Id);
        }
        /// <summary>
        /// Using as subMap the ResulMap with the specified id.
        /// </summary>
        /// <param name="id">The id.</param>
        /// <returns></returns>
        public DiscriminatorExpression UsingResultMap(string id)
        {
            Contract.Require.That(id, Is.Not.Null & Is.Not.Empty).When("retrieving id argument in UsingResultMap method");

            id            = builder.ApplyNamespace(id);
            currentSubMap = new MutableConfiguration(ConfigConstants.ELEMENT_CASE, id);
            currentSubMap.CreateAttribute(ConfigConstants.ATTRIBUTE_RESULTMAP, id);
            parentConfiguration.Children.Add(currentSubMap);

            return(this);
        }
Example #10
0
        /// <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 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;
        }
Example #12
0
        /// <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;
        }
Example #13
0
        /// <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 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);
        }