Dies ist ein Spickzettel für diverse jQAssistant / Cypher Codeschnipsel

jQAssistant Demos

Beispiel-Queries

Infos über Verbindungen eines Knoten

MATCH
  (c:Class {name:"Pet"})-[outgoing]->(out)
RETURN c.name as Klasse,  labels(c) as KlassenLabels, "-[:" + type(outgoing) + "]->" as Verbindungstyp, count(outgoing) as Anzahl, labels(out) as KnotenLabels
ORDER BY Anzahl DESC, Verbindungstyp
UNION
MATCH 
  (in)-[incoming]->(c:Class {name:"Pet"})
RETURN c.name as Klasse, labels(c) as KlassenLabels,  "<-[:" + type(incoming) + "]-" as Verbindungstyp, count(incoming) as Anzahl, labels(in) as KnotenLabels
ORDER BY Anzahl DESC, Verbindungstyp

Klasse mit den meisten Methoden

MATCH 
  (c:Class)-[:DECLARES]->(m:Method)
RETURN c.fqn as Klasse, COUNT(m.signature) as Methoden
ORDER BY Methoden DESC

Rekursive Aufrufe

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

Rekursive Aufrufe zur Datenbank

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

Statische, geschriebene Variablen

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

Aggregation von Messergebnissen über fachliche Bereiche

MATCH 
  (t:Type)-[:BELONGS_TO]->(s:Subdomain),
  (t)-[:HAS_CHANGE]->(ch:Change),
  (t)-[:HAS_MEASURE]->(co:Coverage)
OPTIONAL MATCH
  (t)-[:HAS_BUG]->(b:BugInstance)   
RETURN 
  s.name as ASubdomain,
  COUNT(DISTINCT t) as Types,
  COUNT(DISTINCT ch) as Changes,
  AVG(co.ratio) as Coverage,
  COUNT(DISTINCT b) as Bugs
ORDER BY Coverage ASC, Bugs DESC