[Adapdev-commits] Adapdev/src/Adapdev.Data.Tests/CategoriesExample CategoriesDAO.cs,1.4,1.5 Categori
Status: Beta
Brought to you by:
intesar66
From: Sean M. <int...@us...> - 2005-11-16 07:01:56
|
Update of /cvsroot/adapdev/Adapdev/src/Adapdev.Data.Tests/CategoriesExample In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv909/src/Adapdev.Data.Tests/CategoriesExample Added Files: CategoriesDAO.cs CategoriesDAOBase.cs CategoriesEntity.cs CategoriesEntityBase.cs CategoriesEntityCollection.cs CategoriesEntityDictionary.cs CategoriesEntityEnumerator.cs DbConstants.cs MockCategories.cs Log Message: --- NEW FILE: CategoriesDAO.cs --- /****************************************** * Auto-generated by Codus * 9/30/2005 5:18:20 PM ******************************************/ using System; using System.Data; using System.Data.Common; using Adapdev.Data; using Adapdev.Data.Sql; namespace Test { /// <summary> /// Data Access Object for the Categories table. /// </summary> /// <remarks> /// All generated functionality is part of the CategoriesDAOBase class. All /// custom implementations should be done in this class. /// </remarks> public class CategoriesDAO : Test.CategoriesDAOBase { } } --- NEW FILE: CategoriesDAOBase.cs --- /****************************************** * Auto-generated by Codus * 9/30/2005 5:18:20 PM ******************************************/ using System; using System.Collections; using System.Data; using System.Data.Common; using Adapdev.Data; using Adapdev.Data.Sql; namespace Test { /// <summary> /// Base Data Access Object for the Categories table. /// </summary> public abstract class CategoriesDAOBase : Adapdev.Data.AbstractDAO { /// <summary> /// A static representation of column CategoryID /// </summary> public static readonly string COLUMN_CATEGORYID = "CategoryID"; /// <summary> /// A static representation of column CategoryName /// </summary> public static readonly string COLUMN_CATEGORYNAME = "CategoryName"; /// <summary> /// A static representation of column Description /// </summary> public static readonly string COLUMN_DESCRIPTION = "Description"; /// <summary> /// A static representation of column Picture /// </summary> public static readonly string COLUMN_PICTURE = "Picture"; /// <summary> /// Provides access to the name of the primary key column (CategoryID) /// </summary> public static readonly string TABLE_PRIMARYKEY = "CategoryID"; /// <summary> /// Provides access to the name of the table /// </summary> public static readonly string TABLE_NAME = "Categories"; /// <summary> /// Provides access to the name of the database /// </summary> public static readonly string DATABASE_NAME = "Northwind"; /// <summary> /// Constructor /// </summary> public CategoriesDAOBase() : base(DbConstants.DatabaseProviderType, DbConstants.DatabaseType, "Categories", DbConstants.ConnectionString) { } /// <summary> /// Maps the IDataReader values to a CategoriesEntity object /// </summary> /// <param name="r">The IDataReader to map</param> /// <returns>CategoriesEntity</returns> protected override object MapObject(System.Data.IDataReader r) { CategoriesEntity entity = new CategoriesEntity(); try{ int ordinal = r.GetOrdinal("CategoryID"); if (!r.IsDBNull(ordinal)) entity.CategoryID = ((System.Int32)(r.GetValue(ordinal))); } catch(Exception){} try{ int ordinal = r.GetOrdinal("CategoryName"); if (!r.IsDBNull(ordinal)) entity.CategoryName = ((System.String)(r.GetValue(ordinal))); } catch(Exception){} try{ int ordinal = r.GetOrdinal("Description"); if (!r.IsDBNull(ordinal)) entity.Description = ((System.String)(r.GetValue(ordinal))); } catch(Exception){} try{ int ordinal = r.GetOrdinal("Picture"); if (!r.IsDBNull(ordinal)) entity.Picture = ((System.Byte[])(r.GetValue(ordinal))); } catch(Exception){} return entity; } /// <summary> /// Creates the sql insert command, using the values from the passed /// in CategoriesEntity object /// </summary> /// <param name="o">A CategoriesEntity object, from which the insert values are pulled</param> /// <returns>An IDbCommand</returns> protected override System.Data.IDbCommand CreateInsertCommand(object o) { CategoriesEntity entity = ((CategoriesEntity)(o)); System.Data.IDbCommand cmd = this.CreateCommand("INSERT INTO [Categories] ( [CategoryName], [Description], [Picture] ) VALUES ( @CategoryName, @Description, @Picture ) "); IDataParameterCollection cmdParams = cmd.Parameters; System.Data.IDbDataParameter parCategoryName = cmd.CreateParameter(); parCategoryName.ParameterName = "@CategoryName"; parCategoryName.Value = entity.CategoryName; cmdParams.Add(parCategoryName); System.Data.IDbDataParameter parDescription = cmd.CreateParameter(); parDescription.ParameterName = "@Description"; parDescription.Value = entity.Description; cmdParams.Add(parDescription); System.Data.IDbDataParameter parPicture = cmd.CreateParameter(); parPicture.ParameterName = "@Picture"; parPicture.Value = entity.Picture; cmdParams.Add(parPicture); return cmd; } /// <summary> /// Creates the sql update command, using the values from the passed /// in CategoriesEntity object /// </summary> /// <param name="o">A CategoriesEntity object, from which the update values are pulled</param> /// <returns>An IDbCommand</returns> protected override System.Data.IDbCommand CreateUpdateCommand(object o) { CategoriesEntity entity = ((CategoriesEntity)(o)); System.Data.IDbCommand cmd = this.CreateCommand("UPDATE [Categories] SET [CategoryName] = @CategoryName, [Description] = @Description, [Picture] = @Picture WHERE [CategoryID] = @CategoryID "); IDataParameterCollection cmdParams = cmd.Parameters; System.Data.IDbDataParameter parCategoryName = cmd.CreateParameter(); parCategoryName.ParameterName = "@CategoryName"; parCategoryName.Value = entity.CategoryName; cmdParams.Add(parCategoryName); System.Data.IDbDataParameter parDescription = cmd.CreateParameter(); parDescription.ParameterName = "@Description"; parDescription.Value = entity.Description; cmdParams.Add(parDescription); System.Data.IDbDataParameter parPicture = cmd.CreateParameter(); parPicture.ParameterName = "@Picture"; parPicture.Value = entity.Picture; cmdParams.Add(parPicture); System.Data.IDbDataParameter pkparCategoryID = cmd.CreateParameter(); pkparCategoryID.ParameterName = "@CategoryID"; pkparCategoryID.Value = entity.CategoryID; cmdParams.Add(pkparCategoryID); return cmd; } /// <summary> /// Creates the sql delete command, using the passed in primary key /// </summary> /// <param name="id">The primary key of the object to delete</param> /// <returns>An IDbCommand</returns> protected override System.Data.IDbCommand CreateDeleteOneCommand(object id) { System.Data.IDbCommand cmd = this.CreateCommand("DELETE FROM [Categories] WHERE [CategoryID] = @CategoryID "); IDataParameterCollection cmdParams = cmd.Parameters; System.Data.IDbDataParameter par = cmd.CreateParameter(); par.ParameterName = "@CategoryID"; par.Value = id; cmdParams.Add(par); return cmd; } /// <summary> /// Creates the sql select command, using the passed in primary key /// </summary> /// <param name="o">The primary key of the object to select</param> /// <returns>An IDbCommand</returns> protected override System.Data.IDbCommand CreateSelectOneCommand(object id) { System.Data.IDbCommand cmd = this.CreateCommand("SELECT [CategoryID], [CategoryName], [Description], [Picture] FROM [Categories] WHERE [CategoryID] = @CategoryID "); IDataParameterCollection cmdParams = cmd.Parameters; System.Data.IDbDataParameter par = cmd.CreateParameter(); par.ParameterName = "@CategoryID"; par.Value = id; cmdParams.Add(par); return cmd; } protected override void CustomSave(object o, IDbConnection connection){ string query = QueryHelper.GetSqlServerLastInsertedScopeCommand(); //string query = QueryHelper.GetSqlServerLastInsertedCommand(CategoriesDAO.TABLE_NAME); IDbCommand cmd = DbProviderFactory.CreateCommand(DbConstants.DatabaseProviderType); cmd.CommandText = query; cmd.Connection = connection; object id = cmd.ExecuteScalar(); this.MapIdentity(o as CategoriesEntity, id); } protected override void CustomSave(object o, IDbConnection connection, IDbTransaction transaction){ string query = QueryHelper.GetSqlServerLastInsertedScopeCommand(); //string query = QueryHelper.GetSqlServerLastInsertedCommand(CategoriesDAO.TABLE_NAME); IDbCommand cmd = DbProviderFactory.CreateCommand(DbConstants.DatabaseProviderType); cmd.CommandText = query; cmd.Transaction = transaction; cmd.Connection = connection; object id = cmd.ExecuteScalar(); this.MapIdentity(o as CategoriesEntity, id); } private void MapIdentity(CategoriesEntity entity, object id){ entity.CategoryID = Convert.ToInt32(id); } } } --- NEW FILE: CategoriesEntity.cs --- /****************************************** * Auto-generated by Codus * 9/30/2005 5:18:19 PM ******************************************/ using System; using Test.Collections; using Adapdev.Text; namespace Test { /// <summary> /// An object representation of the Northwind Categories table /// </summary> [Serializable] public class CategoriesEntity : CategoriesEntityBase{ } } --- NEW FILE: CategoriesEntityBase.cs --- /****************************************** * Auto-generated by Codus * 9/30/2005 5:18:19 PM ******************************************/ using System; using System.Xml.Serialization; using Test.Collections; using Adapdev.Text; namespace Test { /// <summary> /// An object representation of the Northwind Categories table /// </summary> [Serializable] public abstract class CategoriesEntityBase{ private System.Int32 _CategoryID = 0; private System.String _CategoryName = ""; private System.String _Description = ""; private System.Byte[] _Picture = null; [XmlElement(ElementName = "CategoryID")] public System.Int32 CategoryID { get { return this._CategoryID; } set { this._CategoryID = value; } } [XmlElement(ElementName = "CategoryName")] public System.String CategoryName { get { return this._CategoryName; } set { this._CategoryName = value; } } [XmlElement(ElementName = "Description")] public System.String Description { get { return this._Description; } set { this._Description = value; } } [XmlElement(ElementName = "Picture")] public System.Byte[] Picture { get { return this._Picture; } set { this._Picture = value; } } /// <summary> /// Returns a string representation of the object, displaying all property and field names and values. /// </summary> public override string ToString() { return StringUtil.ToString(this); } // public ProductsEntityCollection ProductsByCategoryID{ // get{return new ProductsEntityCollection(new ProductsDAO().SelectAllByCategoryID(this._CategoryID));} // } } } --- NEW FILE: CategoriesEntityCollection.cs --- /****************************************** * Auto-generated by Codus * 9/30/2005 5:18:19 PM ******************************************/ using System; using System.Collections; using Adapdev.Collections; using Test; namespace Test.Collections { [Serializable()] public class CategoriesEntityCollection : SortableCollectionBase { public CategoriesEntityCollection() { } public CategoriesEntityCollection(IList value) { this.AddRange(value); } public CategoriesEntityCollection(CategoriesEntity[] value) { this.AddRange(value); } public CategoriesEntity this[int index] { get { return ((CategoriesEntity)(List[index])); } set { List[index] = value; } } public int Add(CategoriesEntity value) { return List.Add(value); } public void AddRange(CategoriesEntity[] value) { for (int i = 0; (i < value.Length); i = (i + 1)) { this.Add(value[i]); } } public void AddRange(IList value) { for (int i = 0; (i < value.Count); i = (i + 1)) { this.Add((CategoriesEntity)value[i]); } } public bool Contains(CategoriesEntity value) { return List.Contains(value); } public void CopyTo(CategoriesEntity[] array, int index) { List.CopyTo(array, index); } public int IndexOf(CategoriesEntity value) { return List.IndexOf(value); } public void Insert(int index, CategoriesEntity value) { List.Insert(index, value); } public new CategoriesEntityEnumerator GetEnumerator() { return new CategoriesEntityEnumerator(this); } public void Remove(CategoriesEntity value) { List.Remove(value); } } } --- NEW FILE: DbConstants.cs --- /****************************************** * Auto-generated by Codus * 9/30/2005 5:18:21 PM ******************************************/ using System; using Adapdev.Data; namespace Test { public class DbConstants { public static readonly Adapdev.Data.DbProviderType DatabaseProviderType = Adapdev.Data.DbProviderType.SQLSERVER; public static readonly Adapdev.Data.DbType DatabaseType = Adapdev.Data.DbType.SQLSERVER; public static readonly string ConnectionString = @"Data Source=localhost; Initial Catalog=northwind; User ID=sa; Password=; Trusted_Connection=false;"; } } --- NEW FILE: MockCategories.cs --- /****************************************** * Auto-generated by Codus * 9/30/2005 5:18:20 PM ******************************************/ using System; using Adapdev.Text; namespace Test.Mock { /// <summary> /// Represents a test instance of a CategoriesEntity object /// </summary> [Serializable] public class MockCategoriesEntity : CategoriesEntity { public MockCategoriesEntity() : base(){ this.CategoryID = 2; this.CategoryName = "test"; this.Description = "test"; this.Picture = System.Text.Encoding.ASCII.GetBytes("Test String2"); } } } --- NEW FILE: CategoriesEntityEnumerator.cs --- /****************************************** * Auto-generated by Codus * 9/30/2005 5:18:20 PM ******************************************/ using System; using System.Collections; using Test; namespace Test.Collections { public class CategoriesEntityEnumerator : IEnumerator { private IEnumerator baseEnumerator; private IEnumerable temp; public CategoriesEntityEnumerator(CategoriesEntityCollection mappings) { this.temp = ((IEnumerable)(mappings)); this.baseEnumerator = temp.GetEnumerator(); } public CategoriesEntityEnumerator(CategoriesEntityDictionary mappings) { this.temp = ((IEnumerable)(mappings)); this.baseEnumerator = temp.GetEnumerator(); } public CategoriesEntity Current { get { return ((CategoriesEntity)(baseEnumerator.Current)); } } object IEnumerator.Current { get { return baseEnumerator.Current; } } public bool MoveNext() { return baseEnumerator.MoveNext(); } bool IEnumerator.MoveNext() { return baseEnumerator.MoveNext(); } public void Reset() { baseEnumerator.Reset(); } void IEnumerator.Reset() { baseEnumerator.Reset(); } } } --- NEW FILE: CategoriesEntityDictionary.cs --- /****************************************** * Auto-generated by Codus * 9/30/2005 5:18:19 PM ******************************************/ using System; using System.Collections; using Test; namespace Test.Collections { public class CategoriesEntityDictionary : DictionaryBase { public CategoriesEntity this[ object key ] { get { return( (CategoriesEntity) Dictionary[key] ); } set { Dictionary[key] = value; } } public ICollection Keys { get { return( Dictionary.Keys ); } } public ICollection Values { get { return( Dictionary.Values ); } } public void Add( String key, String value ) { Dictionary.Add( key, value ); } public bool Contains( String key ) { return( Dictionary.Contains( key ) ); } public void Remove( String key ) { Dictionary.Remove( key ); } } } |