Announcement Announcement Module
Collapse
No announcement yet.
neo4j: findAllByMultipleQueries / AbstractGraphRepository Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • neo4j: findAllByMultipleQueries / AbstractGraphRepository

    Hi all,

    I would like to search starter nodes by matching multiple keys using the NamedIndexRepository.

    I already found out that extending one of the two AbstractGraphRepository subclasses (NodeGraphRepository ins this case) and using/extending the method findAllByQuery as a starting point might be the right way:

    public class MySuperNodeGraphRepository<T extends NodeBacked> extends NodeGraphRepository<Node, T> implements GraphRepository<T>

    So far so good.

    So lets now say somewhere a defined public interface XYZRepository extends GraphRepository<XYZ> is @Autowired.

    How do I manage it that my own MySuperNodeGraphRepository gets autowired and not the NodeGraphRepository.


    In case my approach was completely wrong, how can I extend or use soem kind of repository to find nodes by matching multiple keys?

    Thanks

  • #2
    in general you can use for this findAllByMultipleQueries method just:

    repo.findAllByQuery("prop:value OR prop2:value2 OR ..);

    it is the lucene query syntax: http://lucene.apache.org/java/3_4_0/...sersyntax.html

    for your own implementations you would add a separate interface


    interface MyRepository {
    void myMethod(...);
    }
    and put a
    class MyRepositoryImpl implements MyRepository {
    public void myMethod(...) {}
    }

    besides it
    then in the graph-repository you would just do:

    interface XYZRepository extends GraphRepository<XYZ>, MyRepository<XYZ> {
    }

    That's it for custom methods. If I didn't misunderstand you

    See also here:
    http://static.springsource.org/sprin...mplementations

    Cheers

    Michael

    Comment


    • #3
      Interface stuff understood, thanks.

      But I cant find repo.findAllByQuery(singleParam method in any of the repos at:

      https://github.com/SpringSource/spri...o4j/repository


      All find methods finally result in Neo4jTemplate.getIndex(Class<?> indexedType, String propertyName /*it is always a single propertyName*/)

      I could call repo.findAllByQuery(null, myLuceneQuery) but that seems a bit hackish to me?

      Next question would be, what about named parameters for the lucene query? Or could I use native lucene Query Objects somehow?


      Sorry, but there are a lot of question marks flying around my head

      Comment


      • #4
        No worries

        I meant the: repo.findAllByQuery(null, "lucene query syntax string or query object in here")
        the find methods don't necessarily need the field name, you're right I should put the non-property method in there too.

        Can you add a JIRA issue for this? http://spring.neo4j.org/issues

        Let the questions keep coming.

        Thanks

        Michael

        Comment


        • #5
          Hi again

          Head spinning, more questions follow:

          So I created:

          public interface XYZRepositoryAddons {just @Query methods}

          public interface SimpleDao<T, PK extends Serializable> {/*i need this for smooth transition of worker classes that don't care how something is being stored as long as they can use this interface*/}

          public class DaoNodeGraphRepositoryImpl<T> implements SimpleDao<T, Long> {
          @Autowired private GraphRepository<T> graphRepository; /*graph based dao impl using graphRepository, no @Query addon support*/}

          public interface XYZRepository extends GraphRepository<XYZ>, NamedIndexRepository<XYZ>, SimpleDao<XYZ, Long>, XYZRepositoryAddons {/*all worker classes (old jpa transition and neo4j only ones) can use this interface*/}


          Now what happens: org.springframework.data.repository.core.support.D efaultRepositoryInformation.getQueryMethods() calls isCustomMethod() on methods defined in SimpleDao, customImplementationClass is null (no idea what that means), so it returns false, leading to all methods from SimpleDao being added as QueryMethods.

          I don't know if thats the root of the following evel, just what i think is.

          Anyway, later on i get a java.lang.IllegalArgumentException: No property find found for type class mypkg.model.nodes.XYZ.

          find is a method of SimpleDao and of course there is no property find in pkg.model.nodes.XYZ.

          Big question? What happened?

          Any help appreciated
          Last edited by Xnyle; Nov 8th, 2011, 02:42 AM.

          Comment


          • #6
            Can you post this as a minimal sample project, either as github repo, zipfile or dropbox download?

            So it would be easier to follow. Please create a JIRA issue for it too.

            Thanks

            Comment


            • #7
              @ https://jira.springsource.org/browse/DATAGRAPH-130

              Comment


              • #8
                Sorry, I messed it up. Talked with Oliver and he clarified that the custom implementation (currently) has to be named like the concrete repository interface.

                so:
                Code:
                public interface CustomMovieRepository {
                  @Transactional void doSomething(Movie movie);
                }
                public interface MovieRepository extends GraphRepository<Movie>, CustomMovieRepository {}
                public class MovieRepositoryImpl implements CustomMovieRepository {
                   @Override public void doSomething(Movie movie) {
                       // do stuff
                   }
                }
                I also added a separate test for it, and it works fine. Please try and report back.

                Sorry for the confusion.

                Comment


                • #9
                  Hi Michael,

                  don't know if I got it right, I changed the custom implementation name to DaoNodeGraphRepositoryImpl, the corresponding newly created interface is now called DaoNodeGraphRepository and extends SimpleDao.

                  Still no luck, same error.

                  Could you please take a look at

                  https://jira.springsource.org/secure...6/n4jtest4.zip


                  Thanks

                  Comment


                  • #10
                    I just added the repository section to your pom and all built fine:

                    Code:
                        <repositories>
                            <repository>
                                <id>repository.springframework.maven.milestone</id>
                                <name>Spring Framework Maven Milestone Repository</name>
                                <url>http://maven.springframework.org/milestone</url>
                            </repository>
                        </repositories>

                    Comment


                    • #11
                      Sorry , my local archiva resolved that for me.

                      Anyway, adding it to the pom.xml didn't change anything.

                      The problem is not the build, but running it, try mvn exec:java:


                      Error creating bean with name 'worldRepository': FactoryBean threw exception on object creation; nested exception is java.lang.IllegalArgumentException: No property flush found for type class test.World

                      Comment

                      Working...
                      X