Persistent Object Management in less than 300 Lines of Code(codeproject.com)

submitted by rcerffrcerff(160) 4 years, 10 months ago

There's a lot of repetitive work associated with the writing of data classes within the data access layer of an N-tiered architecture. Apart from adding a column to the relevant database table, adding a field to the class involves adding a private variable to hold the field value, a property to expose it to other classes, and several lines to make sure the field is included in insert, fetch, and update operations. If you're using stored procedures (very silly for CRUD queries) that several more modifications to make. This is dull work I'm sure you'll agree. Presented here is a lightweight method for taking away all this tedium, such that you only have to add a getter/setter property in order to add a field to a data class. The technique involves abstracting SQL query writing and execution, and variable storage in data access classes to a base class. In the implementation presented here I've named this base class "PersistentDataObject". The "less then 300 lines of code" referred to in the title of this post are the lines of code in this base class, the database access class it uses, and a couple of exception classes used as markers to add clarity to exception origins. The complete code is included at the end of the post.

2 comments |category: |Views: 7

tags: another

new Add a live kick counter to your blog >> liveImage

You can even customize the image by choosing your own colors, and then clicking the button below to update the preview and the html code:

  • "Kick It" text
  • "Kick It" background
  • kick count text
  • kick count background
  • border

Simply copy and paste this HTML into your blog post.


Users who kicked this story:
Comments:

posted by mikethomasmikethomas(85) 4 years, 10 months ago 0

The code looks interesting, but a warning - the bases class makes extensive use of non-parameterized SQL leaving these classes wide open to SQL injection attacks.

Reply

posted by JudahGabrielJudahGabriel(783) 4 years, 9 months ago 0

Mike, read the comments to the article: the author claims there is no such security hole, because he's using parameters.

Reply

information Login or create an account to comment on this story