Object Graph Programming (OGO) enables reading and modifying an object graph (i.e., the entire state of the JVM heap) via declarative Cypher queries.
-
Searching an
ArrayList
for a given element.ArrayList<Long> lst = new ArrayList<Long>(); lst.add(10L); lst.add(20L); lst.add(30L); query("MATCH ({$1})-[:elementData]->()-[]->({value : 20}) RETURN TRUE");
In this example, we use imperative code to instantiate and add elements to an
ArrayList
and then useCypher
query throughOGO
to querylst
to check if it contains element 20. -
Implementing the
containsKey
method ofjava.util.HashMap
class.public boolean containsKeyOgoImpl(HashMap map, object key){ queryBool("MATCH ({$1})-[:table]->()-[]->()-[:key]->(n)" +"MATCH (m {$2})" +"WHERE n.`equals`(m)" +"RETURN COUNT(n) <> 0", map, key); }
In this example, the first
MATCH
clause matches a pattern that collects all the objects corresponding to thekey
field ofHashMap's
inner classNode
into the variablen
. The secondMATCH
clause collects the given key object into the variablem
. TheWHERE
clause filters the elements ofn
based on the output of thejava.lang.Object
class'sequals
method evaluating to true for pairwise inputs fromn
andm
. This predicate is expected to filter number of elements ofn
to 1 if the given key is present in themap
and to 0 if absent. Finally, we use theRETURN
clause to return the value of the expression that compares equality of number of elements ofn
to 0. The query is hence expected to return true iff the number of elements inn
is non-zero which is true only if the given key is contained inmap
.
- OGO Code base
- ICSE 2024 OGO evaluation datasets
If you use OGO in your research, please cite our ICSE'24 paper. The paper can be found here.
@inproceedings{ThimmaiahETAL24OGO,
author = {Thimmaiah, Aditya and Lampropoulos, Leonidas and Rossbach, Christopher and Gligoric, Milos},
title = {Object Graph Programming},
year = {2024},
doi = {10.1145/3597503.3623319},
booktitle = {Proceedings of the IEEE/ACM 46th International Conference on Software Engineering},
pages = {1--13},
}