Link to Home page Main Banner


Local Links

  

SSF -Simple Storable Framework

The main goal of this project is to bring to the development community a simple, and at the time powerful, framework to map C++/java classes to tables in a RDBMS.

Along with the goal above, we are aiming for simplicity, i.e., the framework must be simple, easy to learn and small to atrack its use on embedded systems.

This project is hosted by:

SourceForge Logo

NOTE: Not quite yet. I *thought* sourceforge was going to be an easy thing. But, it turned out to be a very complex issue, and after a couple of weeks, I sill not have access to their secure shell and CVS access. All lists that I have created, still not ready.

I think it is time to start looking at e-Groups. :-)

Environment and Drivers Available

As of the initial release, the framework has been tested under Windows NT 4.0 SP6. It should run fine under any version of Windows.

The C++ code has been tested with Borland C++ 5.5 or higher. It is a free compiler for Win32 from Borland.
You can download it from here:
http://www.borland.com/bcppbuilder/freecompiler/

DB drivers available:

  • MySQL using the windows client( libmySQL.DLL )

Architecture

The architecture of SSF is composed of two main sub-components:
  • Database interface or DB driver ( java uses JDBC for this )
  • Storable Framework
Below we will describe how the components are associated, and what you have to do to use the framework.


Fig. 1 - Class Diagram

Database Driver

This component is the basic interface to talk to the database engine. It has been desgined to resembles the JDBC classes a little bit. Not much. :-)

Two classes compose the driver:

  • Connection - this class offers a basic interface to allow connections to the DB engine be established as well as the executation of SQL statements.
  • ResultSet - This class is created as the result of executing of a SQL query command through a Connection instance. This class has interface to access all fields in a row , and for all rows that match the query.

Storable Classes

This component provides the OO class framework that you use to customize your own classes from a C++ or java standpoint. It has a basic class called Storable, which has a set of pure virtual functions that must be provided by the specialized classes. A template based factory is provided to allow the creation of Storable instances matching a query executed against the DB engine. The factory is used to create a set of instances from a single query.
  • Storable - base class for any class that uses the SSF design.
  • StorableFactory< T > -- factory class used to create instances of a Storable class, where a query matching multiple instances is required.

How to Customize your Classes

This section describes in a nutshell what is required for you to write classes that maps to tables in a relational database. Let's use as an example a simple table called "Product" that has a schema as shown below:

    create table Product (
    ID      INTEGER DEFAULT 0 AUTO_INCREMENT PRIMARY KEY,
    NAME    VARCHAR( 80 ) NOT NULL,
    PRICE   FLOAT  DEFAULT 0,
    QTY     INTEGER  );

Where:

   ID:    Primary Key  ( PK ) as the ID of the product
   NAME:  Description of the product
   PRICE: Price of the product
   QTY:   Quantity available on the inventory

Steps to write the Product class:

  • 1. Subclass it from Storable
  • 2. Define the table name that the class should map to: --> TABLE_NAME = "Product"
  • 3. Add getColumnList() virtual function to returns a string with the list of column names used during query and updates.
  • 4. Add getColumnListForInsert() virtual function to returns a string with the list of column names used during one insert. Sometimes this differ from ( 3 ) in a way that the column for the PK is omitted because it is auto-generated by the DB engine.
  • 5. Add geInsertValues() virtual function to returns a string with the values of the fields for the row being inserted.
  • 6. Add getUpdateValues() virtual function to returns a string with the values for the fields of the row ( instance ) being updated.
  • 7. Add getWhereClause() virtual function to returns a string to an unique idenfier for a row matching to the instance.
  • 8. Add mapping() virtual function to map each column with the values passed in the ResultSet.
  • 9. Default Ctor - used by the factory. Should initialize each field with default values. No database access is performed here.

NOTE: The distribution has source code in C++/java mapping the Product table.

Download

ssf-20010121.zip
Archive with source code and examples of the SSF framework.

License

This framework is licensed under the GPL.

Visitors:



Last modified Jan 14, 2001
Copyright ©1999-2001 Rosimildo da Silva. All rights reserved.


   e-mail me