RE: Second Step for Cayenne

From: Gentry, Michael (michael_gentr..anniemae.com)
Date: Thu Jul 29 2004 - 09:55:27 EDT

  • Next message: McDaniel, Joe R.: "RE: Second Step for Cayenne"

    How about something like this?

    Expression expression = Expression.fromString("roleName = $roleName");
    Map parameters = new HashMap();

    parameters.put("roleName", "Sarvesh1");

    SelectQuery query;
    List roles;

    query = new SelectQuery(Role.class,
    expression.expWithParameters(parameters));
    roles = context.performQuery(query);

    if (roles.size() == 1)
      return (Role) roles.get(0);
    else
      return null;

    Note that I've overly complicated it to show how to use expressions with
    parameter substitution, etc. Hopefully that'll give you some ideas,
    though.

    /dev/mrg

    -----Original Message-----
    From: sarvesh.naid..t.com [mailto:sarvesh.naidu@bt.com]
    Sent: Thursday, July 29, 2004 9:45 AM
    To: cayenne-use..bjectstyle.org
    Subject: Second Step for Cayenne

    Hi,
     Now that I have been able to insert values, next is retrieving them,
    how does this work? Firstly I have been working a lot with EJB, so
    remote and local references have always been a part of everything. But
    now that I am using cayenne, its different. To give you an example, I am
    trying to work on a project which I had successfully implemented using
    EJB CMR. I have a table called Role, and I have inserted values by
    creating a new instance of datacontext and registering the Role object
    to the context, and then comitting it. How do I get the values back?

    Role role1 = (Role) context.createAndRegisterNewObject("Role");
            role1.setRoleName("Sarvesh1");
                role1.setRoleDescription("Cayenne Test11");
            context.commitChanges();

    I understand that a getRole() should return me a role class, so that I
    can call the getXXX() on it. But how do I get the Role class is the
    question.Could anyone please explain.
    Thanks

    Regards,
    Sarvesh Naidu
    Wholesale Portal Team
    * (0)20 7322 4645
    *sarvesh.naid..t.com



    This archive was generated by hypermail 2.0.0 : Thu Jul 29 2004 - 09:55:32 EDT