You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Jack <jb...@sympatico.ca> on 2002/12/12 18:35:20 UTC

RE: FW: struts with ojb, multiple repositories

Found /test/org/apache/ojb/odmg/MultiDBUsageTest.java in the ojb test
source. That and with the docs showing the inclusion of
repositoryFarAway.xml in repository.xml gives ideas on how your example in
your book could be modified to cater to multiple dbs.

What I'm doing is shown below.

public class MainService implements IMainService
{
	Implementation odmg = null;
	Implementation odmgB = null;
  	Database db = null;
  	Database dbB = null;

	public MainService() throws DatabaseException{
    		super();
    		init();
  	}
	...


	// opens the databases and prepares them for connections
	private void init() throws DatabaseException {
		odmg = OJB.getInstance();
    		odmgB = OJB.getInstance();
    		db = odmg.newDatabase();
    		dbB = odmgB.newDatabase();
	    try{
	      	db.open("repository.xml", Database.OPEN_READ_WRITE);
	      	dbB.open("repositoryB.xml", Database.OPEN_READ_WRITE);
	    } catch (ODMGException ex){
	      	ex.printStackTrace();
	      	throw new DatabaseException( ex );
	    }
  	}


  	private OQLQuery createQuery( String queryStr ) {
    	OQLQuery query = odmg.newOQLQuery();
    	try{
      		query.create( queryStr );
    	}catch( Exception ex ){
      		ex.printStackTrace();
    	}
    	return query;
  	}
	private OQLQuery createQueryB( String queryStr ) {
    	OQLQuery query = odmgB.newOQLQuery();
    	try{
      		query.create( queryStr );
    	}catch( Exception ex ){
      		ex.printStackTrace();
    	}
    	return query;
  	}

}

---
Transactions are then associated appropriately with:

tx = odmg.newTransaction();

OR

txB = odmgB.newTransaction();

---

Hope I'm doing this correctly...

  -- jack


> -----Original Message-----
> From: Chuck Cavaness [mailto:cava1801@bellsouth.net]
> Sent: Friday, November 29, 2002 11:22 AM
> To: Struts Users Mailing List
> Subject: Re: FW: struts with ojb, multiple repositories
>
>
> Jack,
>
>   I don't see why it can't be, although I should admit that I
> haven't tried it myself. I would indeed use a factory to return
> back an instance of whichever repository you needed to use. If
> you plan to use any type of caching and you need multiple caches
> to be synchronized, I think the latest release of OJB provides
> some type of mechanism for this. Sorry for the fuzzy details, I
> just remember reading something about it on the OJB site.
>
> Good luck,
> Chuck
>
> >
> > From: "Jack" <jb...@sympatico.ca>
> > Date: 2002/11/29 Fri AM 10:05:59 EST
> > To: <st...@jakarta.apache.org>
> > Subject: FW: struts with ojb, multiple repositories
> >
> >
> >  I'm using an application scoped 'service' which uses ojb's odmg
> >  implementation as done in Chuck Cavaness' Struts Model Components
> >  chapter. Works well with one repository. I now need to use two
> >  repositories. I've worked out the configuration for multiple
> >  repositories (one postgresql db, and one mysql) in ojb, which
> >  'works' but am concerned about threading issues given that
> >  OJB.java holds open one database at a time. I've also reviewed
> >  Chuck's Beer4All app and it seems to take a slightly different
> >  approach, getting an instance of the 'service' from a service
> >  factory from within a base action. Is this latter approach better
> >  for using multiple ojb repositories in a Struts framework ? Can
> >  the O'Reilly book example be modified to handle multiple
> >  databases in odmg...
> >
> >    - jack
> >
> > --
> > To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
> For additional commands, e-mail:
<ma...@jakarta.apache.org>
>
>


--
To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
For additional commands, e-mail:
<ma...@jakarta.apache.org>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>