--- Begin Message ---
Hey gang--

I would like to outline a proposed change to Torque for some initial
feedback. Unless I get shouted down as a fool, I will submit a more
formal "diff"-based proposal.

My application requirement is as follows: I have what could loosely
be called a data collection application. Possibly many sources of data
will be written to identical (schema-wise) yet different databases.
The source of the data is not identified until run-time, specifically
HTTP request-time. I need run-time binding of OM tables to
a database.

Currently, the Peer classes have a hardcoded reference to the
database. This presents a problem. Although Criteria allows
for database name specification as does Peer.save(), it turns
out that is not enough. There are places futher down (up?) the
save(dbName) stack, e.g. BasePeer.doInsert that construst
a Criteria using hard-coded database name. Additionally, there
are occasions when the Peer code retrieves a database map
to get. Though there is a DatabaseMap entry for all runtime-defined
datasources (torque.dsfactory.*), there is no map information
associated with them.  The MapBuilder interface does not allow
specification of a database name when building a map so all
you are ever left with is a populated map entry for the hardcoded
database.

So, the proposed changes are:


1) Generate an instance variable in<table>MapBuilder to maintain
database name. Initialize it with build-time database name.
2) Add a method doBuild(dbName) to the MapBuilder interface that
sets this instance variable and calls doBuild()
3) Modify doBuild() method to use this instance variable.
4) Change the MapBuilder.vm to generate the appropriate changes
above.


These two changes allow you to properly construct a map for
an arbitrary database. As for ensuring the Peers use runtime
database...
5) Add BasePeer.setDatabaseName()
6) add protected databaseName instance variable in BasePeer set
by above.
7)   Where currently the hardcoded database name (ie DATABASE_NAME)
is referenced in the peers (eg. 449, 649), generate instead a ternary
test to use BasePeer.databaseName if defined, otherwise DATABASE_NAME.

By my count, this touches two templates (Peer.vm and MapBuilder.vm)
and one class BasePeer.

>From a usage standpoint, here is how I am using my changes:

 // First I ask, "does datasource named 'source' have TABLE_NAME
// mapped.
 DatabaseMap map = Torque.getDatabaseMap(source);
 if ( ! map.containsTable(tableMapClass)) {
       // ignore exception handling
         MapBuilder mb =
                (MapBuilder) Class.forName(tableMapClass).newInstance();

        mb.doBuild(source);
        BaseSightingTablePeer.setDatabaseName(source);
  }

Feedback would be appreciated.

Rob




--- End Message ---
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to