Here are some queries that I use regulary at meetups and conferences for showing some features of jQAssistant and Neo4j. First, you can follow instructions here to get your started with a database full of software data. Then, you can execute some queries like the following:

 

List types with the most methods

MATCH 
  (t:Type)-[:DECLARES]->(m:Method)
RETURN t.fqn as Typ, COUNT(m) as Methods
ORDER BY Methods DESC

Find static, mutable fields

MATCH (c:Class)-[:DECLARES]->(f:Field)<-[w:WRITES]-(m:Method)
WHERE 
    EXISTS(f.static) AND NOT EXISTS(f.final)
RETURN 
    c.name as InClass, 
    m.name as theMethod, 
    w.lineNumber as writesInLine, 
    f.name as toStaticField

Find recursive calls

MATCH
  (c:Class)-[:DECLARES]->(m:Method)-[:INVOKES*1..5]->(m)
RETURN c, m

Find recursive calls to the database

MATCH 
  (m:Method)-[:INVOKES*]->(m)-[:INVOKES]->(dbMethod:Method),
  (dbMethod)<-[:DECLARES]-(dbClass:Class)
WHERE dbClass.name ENDS WITH "Database"
RETURN m, dbMethod, dbClass

Aggregate measures to business subdomains

MATCH 
  (t:Type)-[:BELONGS_TO]->(s:Subdomain),
  (t)-[:HAS_CHANGE]->(ch:Change)
RETURN 
  s.name as ASubdomain,
  COUNT(DISTINCT t) as Types,
  COUNT(DISTINCT ch) as Changes
ORDER BY Types DESC

I hope this cheat sheet will help you for getting stated with the amazing jQAssistant and the world of graphs with Neo4j! If you want to add jQAssistant to your own Java/Maven project, check out the 101 tutorial!

print

jQAssistant: Cypher Query Examples
Tagged on:

One thought on “jQAssistant: Cypher Query Examples

Leave a Reply

Your email address will not be published. Required fields are marked *

I accept that my given data and my IP address is sent to a server in the USA only for the purpose of spam prevention through the Akismet program.More information on Akismet and GDPR.