Returning multilple objects using SDN cypher annotated queries

20 views
Skip to first unread message

Craig Giordano

unread,
May 1, 2012, 2:25:38 PM5/1/12
to ne...@googlegroups.com
I find myself in the situation where I would like a cypher query to return a List of one of my domain objects and also a date.  I don't know if this is possible with the @Query annotation in SDN.  Originally my query looked like this:

    @Query("start pvac=node:__types__(className = \"com.ierin.paragon2.domain.variable.plant.PlantVariableActivityCode\") " +
            "match PV<-[:plantVariable]-pvac, activity-[:MODEL_SCHEDULE_ACTIVITY]->PV, activity-[:timeRange]->t " +
            "where PV.dataSetId = {modelDataSetId} " +
            "and activity.dataSetId={scheduleDataSetId} " +
            "and t.begin < {end} " +
            "and t.end > {begin} " +
            "return distinct pvac")      // TODO need t.begin in the results
    List<PlantVariableActivityCode> findAllPlantVariableActivityCodeByTimeRange(
            @Param("modelDataSetId") String modelDataSetId,
            @Param("scheduleDataSetId") String scheduleDataSetId,
            @Param("begin") Long begin,
            @Param("end") Long end);

But now I would like to change the return clause to the following:

    @Query("start pvac=node:__types__(className = \"com.ierin.paragon2.domain.variable.plant.PlantVariableActivityCode\") " +
            "match PV<-[:plantVariable]-pvac, activity-[:MODEL_SCHEDULE_ACTIVITY]->PV, activity-[:timeRange]->t " +
            "where PV.dataSetId = {modelDataSetId} " +
            "and activity.dataSetId={scheduleDataSetId} " +
            "and t.begin < {end} " +
            "and t.end > {begin} " +
            "return distinct pvac, MAX(t.begin)")      // TODO need t.begin in the results
    List<PlantVariableActivityCode> findAllPlantVariableActivityCodeByTimeRange(
            @Param("modelDataSetId") String modelDataSetId,
            @Param("scheduleDataSetId") String scheduleDataSetId,
            @Param("begin") Long begin,
            @Param("end") Long end);

What would the return type look like if this is possible?  If this is not possible, what are my other options?

Thanks,
Craig

Tero Paananen

unread,
May 1, 2012, 2:31:57 PM5/1/12
to ne...@googlegroups.com
>     List<PlantVariableActivityCode>
> findAllPlantVariableActivityCodeByTimeRange(
>             @Param("modelDataSetId") String modelDataSetId,
>             @Param("scheduleDataSetId") String scheduleDataSetId,
>             @Param("begin") Long begin,
>             @Param("end") Long end);
>
> What would the return type look like if this is possible?  If this is not
> possible, what are my other options?

Use MapResults:

@MapResult
public interface FooBarResult {
@ResultColumn("pvac")
PlantVariableActivityCode getPvac();

@ResultColumn("dt")
Date getDate();
}

List<FooBarResult> findAllPlantVariableActivityCodeByTimeRange(...)

Use column aliases in your Cypher query if you need to.

-TPP

Peter Neubauer

unread,
May 1, 2012, 2:35:37 PM5/1/12
to ne...@googlegroups.com
This looks nice I must say, Michael!

Cheers,

/peter neubauer

G:  neubauer.peter
S:  peter.neubauer
P:  +46 704 106975
L:   http://www.linkedin.com/in/neubauer
T:   @peterneubauer

If you can write, you can code - @coderdojomalmo
If you can sketch, you can use a graph database - @neo4j

Craig Giordano

unread,
May 1, 2012, 2:52:40 PM5/1/12
to ne...@googlegroups.com
Beautiful! 

Thanks,
Craig

Newbie

unread,
May 1, 2012, 4:19:33 PM5/1/12
to Neo4j
Does the FooBarResult interface need to stay in the same directory as
the scanned repository directory?

Tero Paananen

unread,
May 1, 2012, 4:25:31 PM5/1/12
to ne...@googlegroups.com
On Tue, May 1, 2012 at 4:19 PM, Newbie <xia.in...@gmail.com> wrote:
> Does the FooBarResult interface need to stay in the same directory as
> the scanned repository directory?

No. Just import it anywhere you need it.

-TPP
Reply all
Reply to author
Forward
0 new messages