Child pages
  • NewObject and GetObject (Location class)
Skip to end of metadata
Go to start of metadata

The base class DomainObject (or BindableDomainObject, in this case) have generic protected static methods for creating and retrieving domain object instances for a given class.

  • DomainObject.GetObject<T> fetches an object from the database
  • DomainObject.NewObject<T> creates a new object

Since these methods are protected, you can't use them from application code. If you want to use static GetObject and NewObject you must override public specializations for your objects.

This is what we do here. Each class gets its static NewObject and GetObject (not generic). The Location class, for example:

    
    // In class 'Location'
    public static Location NewObject ()
    {
      return DomainObject.NewObject<Location> ();
    }

    public static Location GetObject (ObjectID objid)
    {
      return DomainObject.GetObject<Location> (objid);
    }

Note that

  • both methods, like all work with domain objects, requires the context of transaction
  • even read-only operations require a transaction
  • NewObject does NOT store a (hollow, uninitialized) domain object in the database
  • all changes to domain objects are persisted with Commit() for the transaction providing the context

We will take a closer look at transactions in section FIXME.

  • No labels