Re: Problem concerning Prefetching

From: Jean-Paul Le Fèvre (jean-paul.lefevr..ea.fr)
Date: Mon Jan 28 2008 - 10:29:35 EST

  • Next message: Michael Gentry: "Re: Problem concerning Prefetching"

    On Monday 28 January 2008, Michael Gentry wrote:
    > Hi Jean-Paul,

    Hi Michael and Andrus,

    >
    > It looks like galaxy -> galaxy_component_properties is a to-one
    > relationship, which would cause Cayenne to issue multiple selects like
    > this since it tries to resolve each fault individually.

    It's a one to many : each galaxy has 3 different types of properties.

    Here is the code (simplified) implementing my method :

    public final List<Galaxy> selectGalaxies(int timestep)
    {
        StringBuffer buf = new StringBuffer("halo.simulation.name = '");
        buf.append(getCurrentSimulationName());
        buf.append("' and halo.properties.timestep = ");
        buf.append(timestep);

        Expression exp = Expression.fromString(buf.toString());
        SelectQuery query = new SelectQuery(Galaxy.class, exp);
        query.addOrdering("number", true);

        //query.addPrefetch("componentProperties");

        return (List<Galaxy>) performQuery(query);
    }

    And here is how I use it :
    galaxies = handler.selectGalaxies(ts);

    // Loop on galaxies, get the disc component and the mass of baryons.
    for (Galaxy g : galaxies) {

        GalaxyComponentProperties prop = g.getComponentProperties("disc");
        if (prop != null) {
            printer.println(g.getNumber() + ", " +
                            prop.getMassOfBaryons().toString());
        }
    }

    >
    > Given your manual SQL statement:
    >
    > select galaxies.number, galaxy_component_properties.mass_of_baryons
    > from galaxy_component_properties
    > join galaxies on galaxy_component_properties.galaxy_id = galaxies.id
    > where some_clause
    > order by galaxies.number;
    >
    > It looks like you don't actually care about having actual Cayenne
    > objects (it looks like you only care about having two of the
    > attributes)? If this is the case, you could use an SQLTemplate and
    > raw data rows to only fetch in those two properties. If this isn't
    > the case, let us know and we'll give you other ideas.

    In fact you asked the good question. I'm just at the beginning of the
    development and I don't really know how the application will be used and as a
    consequence it is hard to figure out what it the best strategy to implement
    the functionalities : I guess that some users are only interested in
    computing mean values, sums, min, max in big chunks of data but others want
    to retrieve all the attributes of a small amount of specific objects. The
    challenge is to make both types of users happy. I'm wondering whether it is
    possible or not.
    In my experience Cayenne has always been excellent at manipulating small
    numbers of complex objects but, on the other hand, difficult to use on huge
    dataset.

    -- 
    ___________________________________________________________________
    

    Jean-Paul Le Fèvre * Mail : LeFevr..onteny.org



    This archive was generated by hypermail 2.0.0 : Mon Jan 28 2008 - 10:30:12 EST