Re: how to set username/password ?

From: Andrus Adamchik (andru..bjectstyle.org)
Date: Tue Mar 04 2003 - 11:17:54 EST

  • Next message: Andrus Adamchik: "Re: how to set username/password ?"

    Hi Jean,

    Are you working on a Client-Server GUI application? Since it is quiet
    unusual for a multiuser *web* app to have database connection
    login/password be the same as user's. Anyway, just checking...

    For your case (one connection per user), you will need to instantiate the
    whole Cayenne stack for every session, instead of just getting a new
    DataContext from a shared DataDomain. But this is still doable.

    The idea is to instantaite a full Cayenne access stack on startup, but do
    not connect it to the database. On user session startup, use the main
    stack as a prototype. By stack I mean "DataContext -> DataDomain ->
    DataNode".

    The sequence of steps is something like this:

    1. Create a Cayenne project in the modeler, like you normally would.
    Important: create a DataNode without user name and passoword and with min
    connections set to zero (so that it does not connect on startup), max
    connections to

    2. When a user starts the session, you will create a new DataDomain
    instance, copy all DataMaps from the default "prototype" domain.

    3. Create a new instance of DataNode for each prototype DataNode (probably
    there is just a one - you have a single database?). Set node's DbAdaper,
    data maps, and add it to the new DataDomain.

    4. Now you need to do some casting to create a new DataSource, e.g.:

    DataNode protoNode;...
    DataNode newNode;

    PoolManager pool = (PoolManager)protoNode.getDataSource();
    PoolManager newDataSource = new PoolManager(pool.getJdbcDriver(),
    pool.getDataSourceUrl(), 1, 5, userName, password);

    newNode.setDataSorce(newDataSource);

    5. Create data context based on new domain.

    I guess in the future we should make it easier, by addressing such
    scenario directly in Cayenne.

    Andrus

    >
    > I can't figure out how to set the username and the password
    > before opening a connection to a database. In the examples
    > coming with cayenne these data are read from an xml file
    > then a context is made available automagically.
    > But in a real application authentication is carried out by
    > asking the user a name and a password on a command line
    > or in input fields and then set programmaticaly before
    > accessing the database.
    >
    > Looking at the API I couldn't find the correct sequence
    > of statements leading to a context for a particular user
    > and allowing to catch an exception is the connection is
    > denied.
    >



    This archive was generated by hypermail 2.0.0 : Tue Mar 04 2003 - 11:17:55 EST