Sorry I hit the send button too early:

AbstractClass - contains the db open in the constructor:
--------------
constructor:
    protected Implementation odmg = OJB.getInstance();
    protected Database db = odmg.newDatabase();
    //open database
    try   {
        db.open("repository.xml", Database.OPEN_READ_WRITE);
    }  catch (ODMGException ex)   {
        ex.printStackTrace();
    }
abstract public Iterator listAll();
abstract public boolean edit();
abstract public boolean delete();
...

ConcreteClass - extends AbstractClass
----------------------------------------
- calls super() from this class' constructor that performs the db connection.
- uses the odmg to create Transactions, etc in the listAll(), edit(), delete()
methods.

Is there any problem to this setup? Is it correct to connect everytime (by way
of the super() in the concreteclass constructor) listAll(), edit() or delete()
methods
are called (in separate instances - 1 web page displays all, then another web
page edits, etc.)

Thanks in advance.

>
>
> Ethel Emmons wrote:
>
> > In the ODMG tutorial 2 below, an application class
> >
> > performs db connect/open and passes
> > the odmg instance to the delete, edit, insert etc
> > classes.
> > In a web app where I have several tables to
> > update, insert, etc. where can I put the
> > connection?
> > Do I need to close the connection? Is the
> > connection always on?
> > Can I check if odmg and db are null before I
> > obtain the instance or open the db?
> >
> > Thanks,
> > Ethel
> >
> > public Application()
> > {
> >     // get odmg facade instance
> >     Implementation odmg = OJB.getInstance();
> >     Database db = odmg.newDatabase();
> >     //open database
> >     try
> >     {
> >         db.open("repository.xml",
> > Database.OPEN_READ_WRITE);
> >     }
> >     catch (ODMGException ex)
> >     {
> >         ex.printStackTrace();
> >     }
> >
> >     useCases = new Vector();
> >     useCases.add(new UCListAllProducts(odmg));
> >     useCases.add(new UCEnterNewProduct(odmg));
> >     useCases.add(new UCDeleteProduct(odmg));
> >     useCases.add(new UCQuitApplication(odmg));
> > }
> >
> >   --------------------------------------------------
> > --
> > To unsubscribe, e-mail:   <mailto:ojb-user-unsubscribe@;jakarta.apache.org>
> > For additional commands, e-mail: <mailto:ojb-user-help@;jakarta.apache.org>

--
To unsubscribe, e-mail:   <mailto:ojb-user-unsubscribe@;jakarta.apache.org>
For additional commands, e-mail: <mailto:ojb-user-help@;jakarta.apache.org>

Reply via email to