Re: Indices

From: Andrus Adamchik (andru..bjectstyle.org)
Date: Thu Jan 06 2005 - 11:50:44 EST

  • Next message: Mike Kienenberger: "Re: PK generation with rich clients ..."

    Hi Borut,

    > I am trying to reverse-engineer a ver very simple database (actualy it
    > contains only one table). I succeded, but wondering how to create
    > indices on some of the attributes.
    ....
    > How do I create the last three "rows" in the above example in Cayenne
    > and what would be the best approach to create such db table at my
    > application startup period?

    Cayenne itself doesn't care about indices, so it doesn't store them in the
    mapping. Every now and then we receive a request to support this or that
    DB feature even though it may not be relevant to ORM as such, so this
    could be added at some point in the future... For now you can use Cayenne
    schema generation API to create basic tables, and store all extras (such
    as indices, defaults, etc.) as raw SQL (aka SQLTemplate queries) in the
    Modeler. Something like ALTER TABLE ...

    > Another question is more philosophical. I did not use stored procedures
    > yet. What are the pros and cons of using them and how Cayenne fits in
    > this story?

    Cayenne supports stored procedures as individual objects in the mapping.
    It does not support stored procedures as means of DataObject lifecycle
    management. Though you can probably create a custom DataContext to do
    that.

    As for implementing applications with business logic as stored procedures,
    some people do that. You won't find too many of them in this forum. So you
    may want to look for an alternative opinion elsewhere.

    Anyway... There is a number of reasons not to do it. You will be killing
    all the benefits of structured and object oriented programming, such as
    maintainability and reuse. You will tie yourself to a DB vendor (try
    rewriting "advanced" PL/SQL in any other SQL flavor). And finally
    languages like PL/SQL or Transact SQL are not suited for application
    programming.

    I know of a very few pros. The biggest one is that SQL is very good at
    data manipulation - sometimes a few lines of SQL can replace thousands of
    lines of Java code. Also there are various legacy considerations.

    So my philosophy is to be pragmatic - do an OO design in Java whenever
    possible and use stored procedures or views for "hardcode" data
    manipulation.

    > Can I use the same stored procedures on Oracle and say MySQL
    > v5 with Cayenne help?

    I haven't tested stored procedures with MySQL, though it should work as
    long as JDBC driver supports them. And yes, Cayenne (and JDBC) provide a
    pretty good cross-db abstraction of stored procedures.

    Andrus



    This archive was generated by hypermail 2.0.0 : Thu Jan 06 2005 - 11:50:46 EST