Joe White’s Blog

Life, .NET, and Cats


Object/Relational Mapping with InstantObjects

Okay, I’m finally getting a chance to catch up on my blogging. Here are my notes from the “Object/Relational Mapping with InstantObjects” Birds-of-a-Feather session this morning, led by Marco Cantù.

 

  • Object Persistence Framework
    • Software layer that persists the objects in the model into a storage medium (decouple model from storage)
    • Standard implementation of O/R mapping techniques
  • Advantages
    • Not locked into a specific vendor’s SQL dialect (database vendors are your enemies)
    • Ability to leverage the OO methodology
    • Reduction of redundancies in the application code
  • Disadvantages
    • Steeper learning curve
    • Inability to use some features of the DB server
      • Server-side programming, locking, transactions…
    • Possibly slower and memory-hungry applications

OPFs in Delphi

  • Bold (Win32) / ECO (.NET)
    • More than a simple OPF, Enterprise class, MDA and OCL support, ECO only available in .NET
  • InstantObjects
    • Open source; soft learning curve
    • Based on Scott Ambler’s approach (see www.ambysoft.com)
  • TechInsite OPF (tiOPF)
    • Open source; steeper learning curve; high rate of project activity
  • Roll-Out-Your-Own
    • Maybe not the best place to start – try something else first
    • See oodesign newsgroup
    • Joanna Carter’s Web site
      • She used to host a similar BOF at past conferences…

InstantObjects

  • Main advantages of InstantObjects
    • Nice integration with Delphi’s IDE
    • Very flexible at the Business Object Model level
    • Supports standard data-aware controls
      • through TInstantSelector and TInstantExposer
    • Solid base of users and developers
  • …and current drawbacks:
    • Constraints on the database structure
      • Structure and names of keys and relationship tables are currently fixed
      • V2 improves things through the “external storage” feature
      • Was originally designed for Paradox tables – some stuff was stored in BLOB fields. In v2 it’s a memo with XML.
    • Data access is not always very fast
      • Again, things get better in v2 thanks to new brokers and new optimizations

Model Explorer pane in IDE

  • Add new class – looks like it may need to descend from TInstantObject
  • Can put class in new unit or in existing unit
  • Add attributes via GUI dialogs. You need to have an ID in every table, but you can add other attributes.
  • Name of database field doesn’t have to be the same as the property name.
  • Generates code with magic comments.
  • For every field, you get an attribute object (TInstantString, TInstantInteger, etc., and you can add your own). It doesn’t try to rely on RTTI, partly because you need more info than RTTI can provide, partly because you may want to create rich types (like Address that contains street address, city, etc.)
  • Creates a class with properties (with getters and setters that read/write the embedded attribute object).
  • Some extra metadata (max length of string fields, etc.) is put into a comment inside the class declaration. Not actually used directly at design time, except that it’s used to generate the persistence code.
  • The new class doesn’t have a constructor – just published fields for the attribute objects. Presumably the base class constructor uses RTTI to instantiate those attribute objects.
  • It isn’t smart enough to automatically quote field names when they’re reserved words. You’ll have to manually specify the storage name for that attribute.
  • TInstantSelector is a TDataSet descendant. Lets you pick which object type it contains. You pick the object class, not the table name.
  • Got a Stack Overflow in the demo (oops). Well, it’s a beta version of InstantObjects running on a beta version of Delphi

Developing InstantObjects

  • Project organization
    • Ethea is a company backing it
    • Marco is hosting the support site
  • Roadmap
    • Finally getting v2.0 out (still beta 1 stage)
      • Arrays of objects
    • Restructuring and improving documentation
      • Both user and developer documentation
    • Recruiting new developers and contributors
    • Getting work done on new features

Q&A

  • Q: How do you handle inheritance? Base class and descendant classes?
    A: Single table can host multiple datatypes – class name is stored in each row.
  • If you’re coming from a relational background, read Fowler’s “Analysis Patterns”. (Read it several times – it’ll be pretty scary the first time or two.)

www.instantobjects.org

There are no responses to “Object/Relational Mapping with InstantObjects” yet.

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>


Joe White's Blog copyright © 2004-2008. Portions of the site layout use Yahoo! YUI Reset, Fonts, and Grids.
Proudly powered by WordPress. Entries (RSS) and Comments (RSS).