Daniel Flower Dot Com Banner

Introducing DBObject

The DBObject class, in the Shunde.Framework namespace, is the most important class in Shunde.  As the name suggests, a DBObject is an object which is stored in a database and every class which you want to save to the database is a subclass of DBObject.

Therefore, all your object files include the following properties:

  • Id - a unique (to the whole database) integer ID to identify your object.  Shunde automatically generates a new ID for your object when you save a new object
  • IsDeleted - a boolean indicating whether this object is deleted or not.  Shunde does not support the physical deletion of objects, rather they are marked as deleted (the reason? People accidently delete stuff sometimes, and it's useful for historical purposes to never throw away data. Besides, space is cheap.)
  • DisplayOrder - an integer which can be used to order objects in your database.  The use of this is optional, but if you want to order some objects in a specific way, then you can give different objects different display orders, and then when retrieving objects use "ORDER BY DBObject.displayOrder ASC" in your SQL.
  • LastUpdate - the date that the object was last updated
  • LastUpdatedBy - the name of the person or program that last updated this object. This is optional to use, but it can be useful for admin purposes sometimes to see who last updated an object.
  • FriendlyName - this returns a string to represent the object that is "friendly" for humans to read. For example, a car's FriendlyName may be its model appended to its make.  This is optionally overridden by subclasses; if not overridden, then the ToString method is called, which is not actually very friendly at all (DBObject.ToString() returns the class name with the object ID, such as: "[TestSpace.Car:101]"

The following instance methods are also defined in DBObject:

  •  Equals(object another) - checks if this object equals another.  Two DBObjects are considered equal if they share the same ID.
  • Exists() - returns true if this object exists in the database
  • Populate() - populates the fields of this object with data from the database, assuming that this object has its ID set.  If the object does not exist in the database, a Shunde.ObjectDoesNotExistException exception is thrown.
  • Save() - saves the data in the fields of the object to the database.  If its a new object, then it gets inserted into the database, and after calling, the Id field will contain the newly created ID of the object.  If it already exists, then the data is updated.
 
 
 
 
 
Comments for this page
Attributes
posted by Herman Lindner on 27/03/2011 3:28:27 a.m. (NZ time)
Dear Daniel,

I was looking at the shunde fraework and wondered wether it was possible to use attributes in order to map columns to properties and define wich property is ID etc. Also i would like to now how your frameworks deals with db trigers and computed columns.

Kind regards,
Herman
Add your comment below
Your Name:
Comment Title:
Comment: