Hi everybody,
Ok, here is the latest testing I have done. Recall once again that
my issue was that I have 3 databases (and thus 3 CSpDataSource's).
They are identically structured (tables, columns) databases except
that one is for development, one is for testing, and one is for
production. I created my CSpDataObject's in Studio (design time)
to be bound to the development one. (We don't want to have
3 identical CSpDataObject's; very tough maintenance) At runtime,
our users can choose any one of the 3 databases and work against
that one. To do this, I have successfully implemented the below to
switch the CSpDataSource that a CSpDataObject is bound
to at runtime. This works fine. I have verified on the database
side that this is not creating un-needed database connections
and that it is working as I hoped. Since we are a Java client,
every user is getting a copy of the CSpDataObject's in the
"mini-CP" in the browser JVM which are bound to the
original design time CSpDataSource. This is exactly what we
had hoped for since we didn't want one person changing
the bound CSpDataSource (for a particular CSpDataObject)
to affect anyone else.
The method we wrote is:
/**
Sets the current data source for a data object. Should be
called before any method is executed by a CSpDataObject
in Web ERM. Ensures that the right database is bound.
This is in place of having multiple data objects (eg,
LoginDataObjectDEVL61, LoginDataObjectPROD61,
LoginDataObjectTEST61).
@param currentDO The DataObject to set the DataSource for
@param database The name of the database (not the DataSource)
*/
public final static void setDataSource(CSpDataObject currentDO,
String database)
{
Trace.println("\nbegin: ERM.setDataSource()");
String dataSourceClassName = ERM.getDataSourceClassName(database);
// Set the DataSource based on database name
CSpDataSourcesList target = new CSpDataSourcesList(1);
CSpNamedListElement element = new CSpNamedListElement(
dataSourceClassName,
CSpider.getDataSource(dataSourceClassName));
target.addElement(element);
synchronized(currentDO)
{
currentDO.setDataSources(target);
}
Trace.println("end: ERM.setDataSource()");
}
The last question I have (Eugene - before you can close this case)
is concerning the login. This is an offshoot of this "switching
CSpDataSource" issue. Our method of logging into a database
is to use the CSpUserProfile, CSpLogin, and
profileInstance.setSecurityObjectActivated(true) approach.
This works fine. But how can I close the connection for a
particular user on the database side (via the API - not restarting
the server). The above works fine and I can recall it for
login A, B, C, etc. But each time, the old login stays connected
on the database side (this has been verified by checking on
the database server). How do I log that one out before logging
in with the other connection? That is my final question on this
issue.
The method I am using to "authenticate" a login to the database is:
/**
Internally called to reset the runtime login/password
for the authentication data source.
@param login The login
@param password The decrypted password
@param dataSourceClassName The name of the CSpDataSource
class
*/
private void configureUserCSpLogin(String login,
String password, String dataSourceClassName)
{
Trace.println("\nbegin: LoginBusinessObject.configureUserCSpLogin()");
// should be a valid data source if got to here from login
CSpDataSource targetSource =
CSpider.getDataSource(dataSourceClassName);
CSpLogin targetLogin = targetSource.getCurrentLogin();
// Store the user login parameters in CSpLogin targetLogin
targetLogin.setUserId(login);
targetLogin.setPassword(password);
// Store the user profile in CSpUserProfile profile
CSpUserProfile profile = CSpider.getUserProfile();
profile.addDBUserLogin(dataSourceClassName, targetLogin);
profile.setSecurityObjectActivated(true);
Trace.println("end: LoginBusinessObject.configureUserCSpLogin()");
}
Eugene - call me when you get this.
Thanks for everyone's time.
-Greg Bohmer, HHMI
Gregory Bohmer wrote:
> Eugene (NetD Tech support),
>
> I have read the below suggestion and this is the way I currently
> have it implemented (before I even contacted you). To refresh
> every one on this email distro, here is our issue. We have n
> DataObjects created from within Studio (design time) bound to
> DataSourceA (DSA). We also have DataSourceB (DSB) created
> within Studio but nothing is bound to it during design time. These
> two data sources are identical in table and column names. DSA
> represents our development database and DSB represents our
> production database. Whenever a user logs into our system,
> they enter in a database name (which maps to DSA or DSB).
> Depending on which one they enter, the subsequent data obects
> used by that ONE person need to be bound to the desired data
> source (but at the same time others logged in users may need the
> other data source). So here are the questions I'm still unsure about:
>
> 1) If user 1 needs DSA and user 2 needs DSB at the same time,
> what will happen to a data object that now needs to be bound to
> two different data sources. If we ensure that the data object is
> always bound correctly before executing any time, would that
> buy us what we want? What overhead is that incurring? Lots
> of setting of the DataSource calls.
>
> 2) What about database connections on the Oracle database?
> Are we creating new database connections every time we
> call setDataSource()? I am looking into this as we speak.
>
> 3) We are looking into this since we'd rather not have two data
> objects (each bound to a different data source at design time);
> both identical in logic code and data fields. This would make
> for tough maintenance.
>
> I really need some input on the above so if you could offer some
> thoughts, I would really appreciate it. Eugene, it's your job to
> help me here (the others on the distro I thought might have
> something to share).
>
> Regards,
> Greg Bohmer, HHMI
>
> Eugene Yuga wrote:
>
> > Hello Greg,
> >
> > Please read the thread below. I have posted your question to our internal
> > newsgroup and one of the object framework engineers has found a solution.
> >
> > Regards,
> > Eugene Yuga
> >
> > -----Original Message-----
> > From: Bob McQueer
> > Newsgroups: netdynamics.private.groups.support.objectframework.talk
> > Date: Wednesday, July 07, 1999 3:01 PM
> > Subject: Re: changing the data source for a data object at runtime
> >
> > >
> > >
> > >Eugene Yuga wrote:
> > >
> > >> Hi,
> > >>
> > >> Suppose I have data sources dsA and dsB. The data object I am using is
> > >> setup at design time to use data source dsA.
> > >> At runtime I need my data object to change to data source dsB. This
> > assumes
> > >> that dsA and dsB point to the same table and same columns.
> > >> I do not want to chance data source dsA to behave like dsB and have the
> > data
> > >> object still pointing to dsA as in technote 275.
> > >> I need the data object to point to a different data source, in this case
> > >> dsB. Is this possible and if so, then how?
> > >>
> > >> Thanks,
> > >> Eugene Yuga
> > >
> > >CSpDataObject has a method called "setDataSources()" which takes
> > >a CSpDataSourcesList. I'm not exactly sure why we have multiple data
> > >sources - getDataSource() just returns the first element of the list.
> > Anyway,
> > >you can change the attached data sources and get away with it. I tried
> > >the following, and it seemed to work:
> > >
> > >public int Href1_onWebEvent(CSpWebEvent event)
> > >{
> > >int command = PROCEED;
> > >CSpDataObject dob = CSpider.getDataObject("Dob");
> > >CSpDataSourcesList dl = new CSpDataSourcesList();
> > dl.addElement("WH2",CSpider.getDataSource("WH2"));
> > >dob.setDataSources(dl);
> > >command = doAction(event);
> > >return(command);
> > >}
> > >
> > >WH2 was another data source possessing the same tables as my
> > >original, with different data. When I exercised the link (to the same
> > page),
> > >I indeed started going through the records in the second DB. WARNING -
> > >since the original data sources are set in the init() code for the
> > dataobject,
> > >subsequent uses of the data object in this project graph are going to get
> > >the new DB, and you will have to handle setting the appropriate source
> > >in all of your web events.
> > >
> > >
_________________________________________________________________________
For help in using, subscribing, and unsubscribing to the discussion
forums, please go to: http://www.netdynamics.com/support/visitdevfor.html
For dire need help, email: [EMAIL PROTECTED]