Click here to Skip to main content
15,886,578 members
Articles / Database Development / SQL Server

GPS Tracer Extension: Storing the Path on SQL2005 via Web Services

Rate me:
Please Sign up or sign in to vote.
4.72/5 (7 votes)
21 Aug 20075 min read 28.9K   282   34  
This article extends Leonardo Salvatore's project using the Web Service Software Factory
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Text;
using Microsoft.Practices.EnterpriseLibrary.Data;
using GpsTracerServer.BusinessEntities;
using GpsTracerServer.DataAccess.Generic;
using System.Globalization;

namespace GpsTracerServer.DataAccess
{
    /// <summary>
    /// A factory object that is responsible for taking a Device
    /// and generating the corresponding SQL to insert that
    /// Device into the database. It also includes a method
    /// to grab the returned ID from the call and updating the
    /// Device object with it.
    /// </summary>
    internal class DeviceInsertFactory : IDbToBusinessEntityNameMapper, IInsertFactory<Device>
    {
        /// <summary>
        /// Creates the DeviceInsertFactory to build an insert statement for
        /// the given Device object.
        /// </summary>
        /// <param name="Device">New Device to insert into the database.</param>
        public DeviceInsertFactory()
        {
        }

        #region IInsertFactory<Device> Members

        public DbCommand ConstructInsertCommand(Database db, Device device)
        {
            DbCommand command = db.GetStoredProcCommand("dbo.InsertDevice");

            db.AddInParameter(command, "creationDate", DbType.DateTime, device.CreationDate);
            db.AddInParameter(command, "iD", DbType.Guid, device.ID);
            db.AddInParameter(command, "lastLoginDate", DbType.DateTime, device.LastLoginDate);
            return command;
        }

        public void SetNewID(Database db, DbCommand command, Device device)
        {
            //TODO: Provide set mapping
        }

        #endregion

        #region IDbToBusinessEntityNameMapper Members
        /// <summary>
        /// Maps a field name in the database (usually a parameter name for a stored proc)
        /// to the corresponding business entity property name.
        /// </summary>
        /// <remarks>This method is intended for error message handling, not for reflection.</remarks>
        /// <param name="dbParameter">Name of field/parameter that the database knows about.</param>
        /// <returns>Corresponding business entity field name.</returns>
        public string MapDbParameterToBusinessEntityProperty(string dbParameter)
        {
            switch (dbParameter)
            {
                case "creationDate":
                    return "CreationDate";
                case "iD":
                    return "ID";
                case "lastLoginDate":
                    return "LastLoginDate";
                default:
                    throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, GenericResources.InvalidParameterName), dbParameter);
            }
        }
        #endregion
    }

}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
Italy Italy
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions