db-torque-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Thomas Fischer <fisc...@seitenbau.net>
Subject RE: doDelete problem, null dbMap
Date Thu, 17 Mar 2005 08:39:41 GMT





Jim,

are you sure you used setDbName() correctly ? The setDbName() is for ther
following scenario: In the schema.xml used by the generator, one can define
different <database>s  which have a different structure. The generated
classes know which <database> they belong to.  Then, in the runtime, you
can assign different connection-urls to the different <database>s. But as
the structure of the <database>s" may differ, this means that Torque has to
keep a dbMap for each <database>. So if you set the dbName in criterion, it
uses a different dbMap. If this map does not have the correct entries, the
doDelete fails.

This scenario is different from the case where you have different databases
(e.g. on different servers) with the same structure. For this, you have to
provide different runtime properties, but you must not change the name of
the database in the criteria.

In general, if you just have one <database> element in your schema.xml and
just one database to connect to, you need not worry about the database name
within the runtime.

   Thomas


Jim Caserta <smoothie_jc@yahoo.com> schrieb am 16.03.2005 13:44:44:

> Thomas,
>
> I did some further looking at what I changed and
> attempted to re-create the problem.
> It appears that setting the DbName with the actual
> HighLevel qualifier for the tables (was "default"
> previously) wreaked havoc with the "tables" hashtable
> in the dbMap (line commented out below) in the
> criteria.
>
> I cannot explain it, but it happens consistently.
>
> criteria.add(TableNamePeer.OFFRG_N, primaryKey);
> //criteria.setDbName(db2Schema);
> TableNamePeer.doDelete(criteria, dbConn);
>
>
> --- Thomas Fischer <fischer@seitenbau.net> wrote:
>
> >
> >
> >
> >
> >
> > Jim,
> >
> > I still not understand the cause of the problem and
> > your solution. What did
> > you do to make the error do away ?
> >
> > Looking at the generated code, I do not see how
> > accessing the static method
> > of one table could possibly initialize or
> > re-initialize the Map builder of
> > another table.
> >
> >        Thomas
> >
> >
> > Jim Caserta <smoothie_jc@yahoo.com> schrieb am
> > 15.03.2005 20:00:02:
> >
> > > Thomas,
> > >
> > > You are right. It appears that by executing the
> > > following:
> > > BaseTABLENAMEPeer.executeStatement("SET CURRENT
> > SQLID
> > > = '" +
> > > db2Schema...
> > > for each of the tables that would have been
> > deleted in
> > > a Cascade Delete, it somehow re-initialized Tables
> > in
> > > the dbMap.
> > >
> > > Now all I have to do is get the Updates and
> > Inserts
> > > working..
> > > Thanks for all your help!
> > >
> > > Jim
> > >
> > > --- Thomas Fischer <fischer@seitenbau.net> wrote:
> > >
> > > >
> > > >
> > > >
> > > >
> > > >
> > > > Jim,
> > > >
> > > > Sorry, I should have read your mail more
> > cautiously;
> > > > I was again
> > > > mistaken...
> > > > But nonetheless, I am still confused.
> > > >
> > > > There should be code in the generated
> > xxxBasePeer
> > > > class which looks like
> > > >
> > > >     public static MapBuilder
> > getMapBuilder(String
> > > > name)
> > > >     {
> > > >         try
> > > >         {
> > > >             MapBuilder mb = (MapBuilder)
> > > > mapBuilders.get(name);
> > > >             // Use the 'double-check pattern'
> > for
> > > > syncing
> > > >             //  caching of the MapBuilder.
> > > >             if (mb == null)
> > > >             {
> > > >                 synchronized (mapBuilders)
> > > >                 {
> > > >                     mb = (MapBuilder)
> > > > mapBuilders.get(name);
> > > >                     if (mb == null)
> > > >                     {
> > > >                         mb = (MapBuilder)
> > > > Class.forName(name).newInstance();
> > > >                         // Cache the MapBuilder
> > > > before it is built.
> > > >                         mapBuilders.put(name,
> > mb);
> > > >                     }
> > > >                 }
> > > >            }
> > > >       ....
> > > >
> > > > This should cache the map builder in the dbMap.
> > The
> > > > method is called from
> > > > the static initializer of the xxxBasePeer class,
> > > > which should be called at
> > > > the latest when you call xxxPeer.DoDelete(). If
> > you
> > > > have the possibility to
> > > > debug your code, you might want to put a
> > breakpoint
> > > > in there and see
> > > > whether and when it it called.
> > > >
> > > > There are two reasons I can think of why the
> > Table
> > > > does not appear in the
> > > > dbMap (there might be more)
> > > > 1) Torque is not initialized or it is
> > initialized
> > > > more than once
> > > > 2) For some obscure reason, the xxxBasePeer
> > class is
> > > > not loaded while you
> > > > execute the doDelete().
> > > >
> > > > To exclude 2), you can force the classLoader to
> > load
> > > > the xxxBasePeer class
> > > > by issuing
> > > >
> > >
> >
> class.ForName("fully.qualified.name.of.xxxBasePeer");
> > > > before the delete. But ") is very improbable, as
> > the
> > > > Java Language
> > > > specification explicitly states that a class is
> > > > loaded immediately before
> > > > you execute one of its static methods....
> > > >
> > > > JLS 2.0 §12.4.1--
> > > > "A class or interface type T will be initialized
> > > > immediately before the
> > > > first occurrence of any one of the following:
> > > > . T is a class and an instance of T is created.
> > > > . T is a class and a static method declared by T
> > is
> > > > invoked.
> > > > . A static field declared by T is assigned.
> > > > . A static field declared by T is used and the
> > > > reference to the field is
> > > > not a compile-time constant (§15.28). References
> > to
> > > > compile-time constants
> > > > must be resolved at compile time to a copy of
> > the
> > > > compile-time constant
> > > > value, so uses of such a field never cause
> > > > initialization."
> > > >
> > > > If you can solve this, I (and probably some more
> > > > people on the list) would
> > > > be very interested to know how this problem
> > could
> > > > originate.
> > > >
> > > >       Thomas
> > > >
> > > >
> > > >
> > > >
> > > > jcaserta@chubb.com schrieb am 14.03.2005
> > 19:49:22:
> > > >
> > > > >
> > > > > Tom,
> > > > >
> > > > > Yes it does. In the tables MapBulder class it
> > has
> > > > the following:
> > > > >
> > > > > dbMap = Torque.getDatabaseMap("default");
> > > > > dbMap.addTable("PMTEM021_POLOFFR");
> > > > > TableMap tMap =
> > > > dbMap.getTable("PMTEM021_POLOFFR");
> > > > > tMap.setPrimaryKeyMethod("none");
> > > > > tMap.addPrimaryKey("PMTEM021_POLOFFR.OFFRG_N",
> > new
> > > > String());
> > > > >
> > > > >
> > > >
> > > > >
> > > >
> > > > > >
> > > > >
> > > > >
> > > > >
> > > >
> > > > >              Thomas Fischer
> > > >
> > > > >              <fischer@seitenba
> > > >
> > > > >              u.net>
> > > > To
> > > > >                                        "Apache
> > > > Torque Users List"
> > > >
> >
> === message truncated ===
>
>
>
>
> __________________________________
> Do you Yahoo!?
> Yahoo! Mail - 250MB free storage. Do more. Manage less.
> http://info.mail.yahoo.com/mail_250
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
> For additional commands, e-mail: torque-user-help@db.apache.org
>


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


Mime
View raw message