kamagra how much to take

PersistenceManager

The PersistenceManager class is a static helper class that manages the commonly used objects like the connection string, the ADO.NET connection, and the current transaction.

  1. //*****************************************************************************
  2. // This file is part of the data access layer example to the ASP.NET 2.0 provider database
  3. // This file was written by Adam Buenz [WSS MVP] of ARB Security Solutions, LLC
  4. // http://www.sharepointsecurity.com
  5. //
  6. // This file and its parts is free for re-distribution, for use in both free
  7. // and commercial applications, however this header must remain intact for legal
  8. // use. The data access layer example is distributed in the hope that it will
  9. // be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. //*****************************************************************************
  12. using System;
  13. using System.Collections.Generic;
  14. using System.Data;
  15. using System.Data.SqlClient;
  16. using Aspnet.Provider.Datalayer.Commands;
  17. using Aspnet.Provider.Datalayer.DataTransferObjects;
  18.  
  19. namespace Aspnet.Provider.Datalayer
  20. {
  21. ///
  22. /// The AspnetApplications class.
  23. ///
  24. public partial class AspnetApplications : IPersistable
  25. {
  26. #region Members
  27.  
  28. private bool isNew;
  29. private bool _isNew;
  30. private string applicationname;
  31. private string loweredapplicationname;
  32. private Guid applicationid;
  33. private string description;
  34.  
  35. #endregion
  36.  
  37. #region Properties
  38.  
  39. ///
  40. /// The Applicationname.
  41. ///
  42. [StringInfo(256, true)]
  43. public virtual string Applicationname
  44. {
  45. get { return this.applicationname; }
  46. set { this.applicationname = value; }
  47. }
  48.  
  49. ///
  50. /// The Loweredapplicationname.
  51. ///
  52. [StringInfo(256, true)]
  53. public virtual string Loweredapplicationname
  54. {
  55. get { return this.loweredapplicationname; }
  56. set { this.loweredapplicationname = value; }
  57. }
  58.  
  59. ///
  60. /// The Applicationid.
  61. ///
  62. public virtual Guid Applicationid
  63. {
  64. get { return this.applicationid; }
  65. set { this.applicationid = value; }
  66. }
  67.  
  68. ///
  69. /// The Description.
  70. ///
  71. [StringInfo(256, false)]
  72. public virtual string Description
  73. {
  74. get { return this.description; }
  75. set { this.description = value; }
  76. }
  77.  
  78. #endregion
  79.  
  80. #region ColumnNames
  81.  
  82. ///
  83. /// The corresponding schema name.
  84. ///
  85. internal const string SchemaName = "dbo";
  86.  
  87. ///
  88. /// The corresponding table name.
  89. ///
  90. internal const string TableName = "aspnet_Applications";
  91.  
  92. ///
  93. /// The column names.
  94. ///
  95. internal class ColumnNames
  96. {
  97. ///
  98. /// The column name of the Applicationname property.
  99. ///
  100. public const string Applicationname="ApplicationName";
  101. ///
  102. /// The column name of the Loweredapplicationname property.
  103. ///
  104. public const string Loweredapplicationname="LoweredApplicationName";
  105. ///
  106. /// The column name of the Applicationid property.
  107. ///
  108. public const string Applicationid="ApplicationId";
  109. ///
  110. /// The column name of the Description property.
  111. ///
  112. public const string Description="Description";
  113. }
  114.  
  115. #endregion
  116.  
  117. ///
  118. /// The default constructor.
  119. ///
  120. public AspnetApplications()
  121. {
  122. this.isNew = true;
  123. PersistenceManager.InvokeInstanceMethod(this, "CreationComplete", null);
  124. }
  125.  
  126. ///
  127. /// The constructor of the required fields.
  128. ///
  129. ///
  130. The Applicationname. ///
  131. The Loweredapplicationname. ///
  132. The Applicationid. public AspnetApplications(string applicationname, string loweredapplicationname, Guid applicationid)
  133. {
  134. this.applicationname = applicationname;
  135. this.loweredapplicationname = loweredapplicationname;
  136. this.applicationid = applicationid;
  137.  
  138. this.isNew = true;
  139. PersistenceManager.InvokeInstanceMethod(this, "CreationComplete", null);
  140. }
  141.  
  142. ///
  143. /// The constructor from IDataReader.
  144. ///
  145. ///
  146. An initalized IDataReader. internal AspnetApplications(IDataReader reader)
  147. {
  148. if ((reader["ApplicationName"] != null) && (reader["ApplicationName"] != DBNull.Value))
  149. this.applicationname = (string)reader["ApplicationName"];
  150. if ((reader["LoweredApplicationName"] != null) && (reader["LoweredApplicationName"] != DBNull.Value))
  151. this.loweredapplicationname = (string)reader["LoweredApplicationName"];
  152. if ((reader["ApplicationId"] != null) && (reader["ApplicationId"] != DBNull.Value))
  153. this.applicationid = (Guid)reader["ApplicationId"];
  154. if ((reader["Description"] != null) && (reader["Description"] != DBNull.Value))
  155. this.description = (string)reader["Description"];
  156.  
  157. this.isNew = false;
  158. }
  159.  
  160. ///
  161. /// Creates an IDbCommand to insert an object into the database.
  162. ///
  163. /// An initialized IDbCommand object.
  164. internal virtual IDbCommand CreateInsertCommand()
  165. {
  166. SqlCommand cmd = new SqlCommand();
  167. cmd.CommandText = "insert into [dbo].[aspnet_Applications] ([ApplicationName], [LoweredApplicationName], [ApplicationId], [Description]) values (@applicationname, @loweredapplicationname, @applicationid, @description)";
  168. cmd.Parameters.AddWithValue("@applicationname", this.applicationname);
  169. cmd.Parameters.AddWithValue("@loweredapplicationname", this.loweredapplicationname);
  170. cmd.Parameters.AddWithValue("@applicationid", this.applicationid);
  171. if (String.IsNullOrEmpty(this.description))
  172. cmd.Parameters.AddWithValue("@description", DBNull.Value);
  173. else
  174. cmd.Parameters.AddWithValue("@description", this.description);
  175.  
  176. cmd.Connection = PersistenceManager.Connection;
  177. return cmd;
  178. }
  179.  
  180. ///
  181. /// Creates an IDbCommand to update an object in the database.
  182. ///
  183. /// An initialized IDbCommand object.
  184. internal virtual IDbCommand CreateUpdateCommand()
  185. {
  186. SqlCommand cmd = new SqlCommand();
  187. cmd.CommandText = "update [dbo].[aspnet_Applications] set [ApplicationName]=@applicationname, [LoweredApplicationName]=@loweredapplicationname, [Description]=@description where ([ApplicationId]=@applicationid)";
  188. cmd.Parameters.AddWithValue("@applicationname", this.applicationname);
  189. cmd.Parameters.AddWithValue("@loweredapplicationname", this.loweredapplicationname);
  190. if (String.IsNullOrEmpty(this.description))
  191. cmd.Parameters.AddWithValue("@description", DBNull.Value);
  192. else
  193. cmd.Parameters.AddWithValue("@description", this.description);
  194. cmd.Parameters.AddWithValue("@applicationid", this.applicationid);
  195.  
  196. cmd.Connection = PersistenceManager.Connection;
  197. return cmd;
  198. }
  199.  
  200. ///
  201. /// Creates an IDbCommand to delete an object in the database.
  202. ///
  203. /// An initialized IDbCommand object.
  204. internal virtual IDbCommand CreateDeleteCommand()
  205. {
  206. SqlCommand cmd = new SqlCommand();
  207. cmd.CommandText = "delete from [dbo].[aspnet_Applications] where ([ApplicationId]=@applicationid)";
  208. cmd.Parameters.AddWithValue("@applicationid", this.applicationid);
  209.  
  210. cmd.Connection = PersistenceManager.Connection;
  211. return cmd;
  212. }
  213.  
  214. ///
  215. /// Persists the object.
  216. ///
  217. public virtual void Persist()
  218. {
  219. PersistenceManager.InvokeInstanceMethod(this, "PrePersist", null);
  220.  
  221. IDbCommand cmd;
  222.  
  223. if (this.isNew)
  224. cmd = this.CreateInsertCommand();
  225. else
  226. cmd = this.CreateUpdateCommand();
  227.  
  228. cmd.Transaction = PersistenceManager.Transaction;
  229. PersistenceManager.RegisterInTransaction(this);
  230.  
  231. bool connWasClosed =
  232. PersistenceManager.Connection.State.Equals(ConnectionState.Closed) ||
  233. PersistenceManager.Connection.State.Equals(ConnectionState.Broken);
  234.  
  235. try
  236. {
  237.  
  238. if (connWasClosed)
  239. PersistenceManager.Connection.Open();
  240.  
  241. cmd.ExecuteNonQuery();
  242.  
  243. this.isNew = false;
  244.  
  245. if (connWasClosed)
  246. PersistenceManager.Connection.Close();
  247. }
  248. catch (Exception ex)
  249. {
  250. if (connWasClosed)
  251. PersistenceManager.Connection.Close();
  252. throw ex;
  253. }
  254. }
  255.  
  256. ///
  257. /// Deletes the object.
  258. ///
  259. public virtual void Delete()
  260. {
  261. PersistenceManager.InvokeInstanceMethod(this, "PreDelete", null);
  262.  
  263. IDbCommand cmd = this.CreateDeleteCommand();
  264. cmd.Transaction = PersistenceManager.Transaction;
  265.  
  266. bool connWasClosed =
  267. PersistenceManager.Connection.State.Equals(ConnectionState.Closed) ||
  268. PersistenceManager.Connection.State.Equals(ConnectionState.Broken);
  269.  
  270. try
  271. {
  272. if (connWasClosed)
  273. PersistenceManager.Connection.Open();
  274.  
  275. cmd.ExecuteNonQuery();
  276.  
  277. if (connWasClosed)
  278. PersistenceManager.Connection.Close();
  279. }
  280. catch (Exception ex)
  281. {
  282. if (connWasClosed)
  283. PersistenceManager.Connection.Close();
  284. throw ex;
  285. }
  286. }
  287.  
  288. ///
  289. /// Retrieves a AspnetApplications object by its primary key (Throws System.DataException).
  290. ///
  291. ///
  292. The Applicationid. /// The AspnetApplications object.
  293. public static AspnetApplications Get(Guid applicationid)
  294. {
  295. AspnetApplications aspnetapplications;
  296. if (AspnetApplications.TryGet(applicationid, out aspnetapplications))
  297. return aspnetapplications;
  298. else
  299. throw new DataException("'AspnetApplications' object not found.");
  300. }
  301.  
  302. ///
  303. /// Tries to retrieve a AspnetApplications object by its primary key.
  304. ///
  305. ///
  306. The Applicationid. ///
  307. The found AspnetApplications or null if the primary key value does not exist. /// True if the AspnetApplications exists, else false.
  308. public static bool TryGet(Guid applicationid, out AspnetApplications aspnetapplications)
  309. {
  310. SqlCommand cmd = new SqlCommand("select * from [dbo].[aspnet_Applications] where ([ApplicationId]=@applicationid)");
  311. cmd.Parameters.AddWithValue("@applicationid", applicationid);
  312.  
  313. IList list = AspnetApplications.Query(cmd);
  314.  
  315. if (list.Count == 0)
  316. {
  317. aspnetapplications = null;
  318. return false;
  319. }
  320. else
  321. {
  322. aspnetapplications = list[0];
  323. return true;
  324. }
  325. }
  326.  
  327. ///
  328. /// For internal use only.
  329. ///
  330. public virtual void SaveState()
  331. {
  332. this._isNew = this.isNew;
  333. }
  334.  
  335. ///
  336. /// For internal use only.
  337. ///
  338. public virtual void RestoreState()
  339. {
  340. this.isNew = this._isNew;
  341. }
  342.  
  343. ///
  344. /// Refreshes the internal state of the object.
  345. ///
  346. /// This method should be called after xml deserialization to refresh internal flags.
  347. public virtual void RefreshState()
  348. {
  349. AspnetApplications aspnetapplications;
  350.  
  351. if (AspnetApplications.TryGet(this.applicationid, out aspnetapplications))
  352. {
  353. this.isNew = false;
  354. }
  355. else
  356. {
  357. this.isNew = true;
  358. }
  359. }
  360.  
  361. ///
  362. /// Returns a Data Transfer Object of this AspnetApplications.
  363. ///
  364. /// A Data Transfer Object of this AspnetApplications.
  365. public virtual AspnetApplicationsDTO GetDTO()
  366. {
  367. AspnetApplicationsDTO dto = new AspnetApplicationsDTO();
  368.  
  369. dto.Applicationname = this.Applicationname;
  370. dto.Loweredapplicationname = this.Loweredapplicationname;
  371. dto.Applicationid = this.Applicationid;
  372. dto.Description = this.Description;
  373.  
  374. return dto;
  375. }
  376.  
  377. ///
  378. /// Applies a Data Transfer Object data to this AspnetApplications.
  379. ///
  380. ///
  381. The Data Transfer Object. public virtual void SetDTO(AspnetApplicationsDTO dto)
  382. {
  383. this.Applicationname = dto.Applicationname;
  384. this.Loweredapplicationname = dto.Loweredapplicationname;
  385. this.Applicationid = dto.Applicationid;
  386. this.Description = dto.Description;
  387. }
  388.  
  389. ///
  390. /// Perfoms a query on AspnetApplications objects.
  391. ///
  392. ///
  393. An IDbCommand containing the select statement. /// A result list of AspnetApplications objects.
  394. internal static IList Query(IDbCommand command)
  395. {
  396. command.Connection = PersistenceManager.Connection;
  397. command.Transaction = PersistenceManager.Transaction;
  398.  
  399. bool connWasClosed =
  400. PersistenceManager.Connection.State.Equals(ConnectionState.Closed) ||
  401. PersistenceManager.Connection.State.Equals(ConnectionState.Broken);
  402.  
  403. try
  404. {
  405. if (connWasClosed)
  406. PersistenceManager.Connection.Open();
  407.  
  408. List list = new List();
  409. IDataReader reader = command.ExecuteReader();
  410.  
  411. using (reader)
  412. {
  413. while (reader.Read())
  414. list.Add(new AspnetApplications(reader));
  415. }
  416.  
  417. if (connWasClosed)
  418. PersistenceManager.Connection.Close();
  419.  
  420. return list;
  421. }
  422. catch (Exception ex)
  423. {
  424. if (connWasClosed)
  425. PersistenceManager.Connection.Close();
  426. throw ex;
  427. }
  428. }
  429.  
  430. ///
  431. /// Finds all AspnetApplications objects with a certain Applicationname value.
  432. ///
  433. ///
  434. The Applicationname value ('*' can be used as a wildcard). /// All AspnetApplications objects with a certain Applicationname value.
  435. public static IList FindByApplicationname(string applicationname)
  436. {
  437. return AspnetApplications.Query(AspnetApplicationsCommands.FindByApplicationname(applicationname));
  438. }
  439.  
  440. ///
  441. /// Finds all AspnetApplications objects with a certain Loweredapplicationname value.
  442. ///
  443. ///
  444. The Loweredapplicationname value ('*' can be used as a wildcard). /// All AspnetApplications objects with a certain Loweredapplicationname value.
  445. public static IList FindByLoweredapplicationname(string loweredapplicationname)
  446. {
  447. return AspnetApplications.Query(AspnetApplicationsCommands.FindByLoweredapplicationname(loweredapplicationname));
  448. }
  449.  
  450. ///
  451. /// Finds all AspnetApplications objects with a certain Description value.
  452. ///
  453. ///
  454. The Description value ('*' can be used as a wildcard). /// All AspnetApplications objects with a certain Description value.
  455. public static IList FindByDescription(string description)
  456. {
  457. return AspnetApplications.Query(AspnetApplicationsCommands.FindByDescription(description));
  458. }
  459.  
  460. }
  461. }
Share

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>