db-torque-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Thomas Fischer <Fisc...@seitenbau.net>
Subject initialisation process: registration of Map builders
Date Sun, 19 Dec 2004 13:29:27 GMT




Hi,

I would like to call for opinions how to proceed with the registration of
Map builders in the Torque initialisation process.
The problem is described in detail in scarab:

http://nagoya.apache.org/scarab/issues/id/TRQS228

In short, the problem is as follows:
To execute certain queries on a table (let's call it A), the class
BaseAPeer has to be loaded (to trigger some initialisation process in its
static initializer, namely the registration of its Map builder). The
Classloader only loads the class when it is needed (see JLS 2.0 ยง12.4.1 for
details). In "simple" casses (access of Table A via APeer), this is not a
problem because the APeer class and all its ancestors are loaded before its
method is executed. In more complicated cases, however, this can cause
problems, e.g, if the table A is accessed via a call to another Peer. Then,
the class BaseAPeer is not necessarily loaded before the execution, leading
to strage error messages which are difficult to interpret.
To get around this problem, in the current templates, an effort was made to
ensure loading of the peer class when a column name of A is accessed.
(by e.g reading APeer.A_ID). In BaseAPeer, this is done via the following
code:

public abstract class BaseAPeer
    extends BasePeer
{
  ...
  /** the column name for the A_ID field */
  public static final String A_ID;
  ...
  static
  {
    A_ID = "a.A_ID";
    ...
  }
  ...
}

So if A_ID is accessed, the static initializer has to be accessed because
APeer.A_ID has to be allocated before it can be accessed.
Note that in the following code, accessing APeer.A_ID would not trigger the
execution of the static initializer

public abstract class BaseAPeer
    extends BasePeer
{
  ...
  /** the column name for the A_ID field */
  public static final String A_ID =  "a.A_ID";
  ...
  static
  {
    ...
  }
  ...
}

So the question is, is this enough ? It would not be enough in the
following cases:
1) the query is executed without referring to any column names in APeer
2) an optimizer optimizes the initialisation process and generates compiled
code corresponding to the second example.

For example, 1) could occur if one generates column names dynamically. I
have never used optimizers, therefore I do not know anything whether 2) can
occur.

Now, I see 4 possibilities to proceed:
1) leave it as it is
2) add an extra initialisation procedure to load the Peer classes
3) initialize load the Peer classes on Torque startup
4) modify the Peer classes such that the static initializer of any Peer
class loads every other Peer class, e.g. by putting in class.forName(...)
calls in the static initializer.

1) has the problems mentioned above
2) this is Henning's mapbulder-init proposal (see proposals in CVS). It has
the disadvantage that 2 function calls are necessary to initialize Torque,
which is counterintuitive in my opinion, and additionally, it is not
compatible to existing code.
3) As the torque engine does not know anything about the Peer classes and
where they are located, the engine would have to be told e.g. by adding a
parameter to the Torque runtime properties. The initialisation of Torque is
already complicated enough, so this is also not the optimal solution.
4) this is better than 1) and does not have the disadvantages of 2) and 3).
It would fail e.g. if a call was made directly to BasePeer and no other
Peer would be loaded.

Personally, I would go for 4). I would really appreciate other opinions.

     Thomas


---------------------------------------------------------------------
To unsubscribe, e-mail: torque-dev-unsubscribe@db.apache.org
For additional commands, e-mail: torque-dev-help@db.apache.org


Mime
View raw message