### Install YTDB Gremlin Console via Docker Source: https://github.com/jetbrains/youtrackdb/blob/develop/console/README.md This snippet shows the recommended method for installing the YTDB Gremlin Console using a Docker image. Running this command pulls the image and starts the console interactively, activating the same plugins as the zip archive installation. ```bash $ docker run -it youtrackdb/youtrackdb-console \,,,/ (o o) -----oOOo-(3)-oOOo----- plugin activated: tinkerpop.server plugin activated: tinkerpop.utilities plugin activated: jetbrains.youtrackdb gremlin> ``` -------------------------------- ### Install YTDB Gremlin Console via Zip Archive Source: https://github.com/jetbrains/youtrackdb/blob/develop/console/README.md This snippet demonstrates how to install the YTDB Gremlin Console by downloading and extracting a zip archive. It covers unzipping the archive, navigating to the directory, and launching the console script. The console initializes with several plugins activated. ```bash $ unzip youtrackdb-console-{ytdb-version}.zip $ cd youtrackdb-console-{ytdb-version} $ bin/ytdb.sh \,,,/ (o o) -----oOOo-(3)-oOOo----- plugin activated: tinkerpop.server plugin activated: tinkerpop.utilities plugin activated: jetbrains.youtrackdb gremlin> ``` -------------------------------- ### Initialize YouTrackDB and Perform Graph Operations in Java Source: https://github.com/jetbrains/youtrackdb/blob/develop/README.md This Java example demonstrates how to initialize YouTrackDB, set up a JSON mapper for output, and perform basic graph operations within a transaction. It shows how to find vertices, retrieve properties, and add new vertices. ```java package io.youtrackdb; import com.jetbrains.youtrackdb.api.DatabaseType; import com.jetbrains.youtrackdb.api.YourTracks; import com.jetbrains.youtrackdb.api.gremlin.YTDBDemoGraphFactory; import com.jetbrains.youtrackdb.internal.core.gremlin.io.YTDBIoRegistry; import org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONMapper; import org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONVersion; import java.util.List; import static org.apache.tinkerpop.gremlin.process.traversal.P.gt; /// Minimal example of usage of YouTrackDB. public class Example { public static void main(String[] args) throws Exception { //Create a YouTrackDB database manager instance and provide the root folder where all databases will be stored try (var ytdb = YourTracks.instance("./target/data")) { //Prepare GraphSONMapper to check our results var jsonMapper = GraphSONMapper.build() .version(GraphSONVersion.V1_0) // use the simplest version for brevity .addRegistry(YTDBIoRegistry.instance())//add serializer for custom types .create().createMapper(); //Create the database with demo data to play with it try (var graph = YTDBDemoGraphFactory.createModern(ytdb)) { //YTDB data manipulation is performed inside a transaction, so let us start one. //YTDBGraphTraversal will start transaction automatically if it is not started yet. //But in such a case you will need to commit it manually, and borders of transaction will be diluted, //we suggest using lambda-style API to automatically start/commit/rollback transactions. graph.executeInTx(g -> { //Find a vertex with class "person" and property "name" equals to "marko". var v = g.V().has("person", "name", "marko").next(); System.out.println("output:" + jsonMapper.writeValueAsString(v)); //output:{ // "id":{..}, // "label":"person", // "type":"vertex", // "properties":{ // "name":[{"id":{..},"value":"marko"}], // "age":[{"id":{..},"value":29}] // } // } // there is ongoing change to implement conversion of vertices from/to native JSON // by using additional metadata provided by DB schema. // //Get the names of the people the vertex knows who are over the age of 30. List friendNames = g.V(v.id()).out("knows").has("age", gt(30)).values("name").toList(); System.out.println("output:" + String.join(", ", friendNames)); //output: josh }); //Create an empty database with the name "tg", username "superuser", admin role and password "adminpwd". ytdb.create("tg", DatabaseType.MEMORY, "superuser", "adminpwd", "admin"); //and then open the YTDBGraph instance try (var newGraph = ytdb.openGraph("tg", "superuser", "adminpwd")) { newGraph.executeInTx(g -> { //create a vertex with class(label) "person" and properties' name and age. var v1 = g.addV("person").property("name", "marko").property("age", 29).next(); ``` -------------------------------- ### Run YouTrackDB Console with Docker Source: https://github.com/jetbrains/youtrackdb/blob/develop/README.md This command runs the YouTrackDB console image from Docker, allowing for quick experimentation with the database without installation. ```bash docker run -it youtrackdb/youtrackdb-console ``` -------------------------------- ### Load Grateful Dead Demo Graph and Query (Gremlin) Source: https://github.com/jetbrains/youtrackdb/blob/develop/console/README.md This snippet shows how to set up a YouTrackDB instance and load the 'grateful-dead' demo graph. It then creates a Gremlin traversal source and executes basic count queries to demonstrate the graph's size. ```gremlin gremlin> ytdb = YourTracks.instance("data") gremlin> graph = YTDBDemoGraphFactory.createGratefulDead(ytdb) ==>YTDBGraph[grateful-dead] gremlin> g = traversal().withEmbedded(graph) ==>graphtraversalsource[YTDBGraph[grateful-dead], standard] gremlin> g.V().count() ==>808 gremlin> g.E().count() ==>8049 ``` -------------------------------- ### Create and Open YouTrackDB Graph (Gremlin) Source: https://github.com/jetbrains/youtrackdb/blob/develop/console/README.md This snippet demonstrates how to initialize a YouTrackDB manager instance, create a new in-memory graph with admin credentials, open the graph, and create a Gremlin traversal source. It's essential for setting up a basic graph environment for experimentation. ```gremlin gremlin> ytdb = YourTracks.instance("data") gremlin> ytdb.create("tg", DatabaseType.MEMORY, "superuser", "adminpwd", "admin") gremlin> graph = ytdb.openGraph("tg", "superuser", "adminpwd") ==>YTDBGraph[tg] gremlin> g = traversal().withEmbedded(graph) ==>graphtraversalsource[YTDBGraph[tg], standard] ``` -------------------------------- ### Load Modern Demo Graph (Gremlin) Source: https://github.com/jetbrains/youtrackdb/blob/develop/console/README.md This code initializes a YouTrackDB instance and then loads the 'modern' demo graph provided by YTDBDemoGraphFactory. It concludes by creating a Gremlin traversal source, enabling immediate exploration of the pre-defined graph structure. ```gremlin gremlin> ytdb = YourTracks.instance("data") gremlin> graph = YTDBDemoGraphFactory.createModern(ytdb) ==>YTDBGraph[modern] gremlin> g = traversal().withEmbedded(graph) ==>graphtraversalsource[YTDBGraph[modern], standard] ``` -------------------------------- ### Add YTDB Snapshot Repository to Gradle Source: https://github.com/jetbrains/youtrackdb/blob/develop/README.md Configures Gradle to use the YTDB snapshot repository for resolving dependencies, ensuring that snapshot versions of YouTrackDB can be accessed. ```gradle repositories { maven { url = uri("https://central.sonatype.com/repository/maven-snapshots/") mavenContent { snapshotsOnly() } } } ``` -------------------------------- ### Add YTDB Snapshot Repository to Maven Source: https://github.com/jetbrains/youtrackdb/blob/develop/README.md Configures the Maven POM file to include the YTDB snapshot repository, which is necessary for resolving YouTrackDB snapshot dependencies. ```xml Central Portal Snapshots central-portal-snapshots https://central.sonatype.com/repository/maven-snapshots/ false true ``` -------------------------------- ### Add YouTrackDB Core Dependency to Maven Project Source: https://github.com/jetbrains/youtrackdb/blob/develop/README.md Adds the YouTrackDB core library as a dependency to a Maven project. This allows YouTrackDB to be used as an embedded database. Note that migration to Gremlin Server is in progress. ```xml io.youtrackdb youtrackdb-core 0.5.0-SNAPSHOT ``` -------------------------------- ### Add YouTrackDB Core Dependency to Gradle Source: https://github.com/jetbrains/youtrackdb/blob/develop/README.md Adds the YouTrackDB core library as an implementation dependency to a Gradle project, enabling its use as an embedded database. ```gradle dependencies { implementation 'io.youtrackdb:youtrackdb-core:0.5.0-SNAPSHOT' } ``` -------------------------------- ### Create Vertex and Edge in YouTrackDB (Java) Source: https://github.com/jetbrains/youtrackdb/blob/develop/README.md This snippet shows how to create a new vertex with a specific label and properties, and then create an edge connecting two vertices with properties. It utilizes the graph traversal language for these operations. ```java var v2 = g.addV("software").property("name", "lop").property("lang", "java").next(); g.addE("created").from(v1).to(v2).property("weight", 0.4).iterate(); ``` -------------------------------- ### Query Vertex Property in YouTrackDB (Java) Source: https://github.com/jetbrains/youtrackdb/blob/develop/README.md This snippet demonstrates how to query for vertices that have a specific property value and then retrieve another property from those vertices. The results are collected into a list and printed. ```java var createdSoftware = g.V().has("person", "name", "marko").out("created").values("name").toList(); System.out.println("output:" + String.join(", ", createdSoftware)); ``` -------------------------------- ### Gremlin Traversal Debugging in YTDB Console Source: https://github.com/jetbrains/youtrackdb/blob/develop/console/README.md This snippet demonstrates debugging a Gremlin traversal in the YTDB Console. It shows the initial traversal to find a person named 'marko', followed by a more complex traversal to group outgoing edges by label and retrieve the names of adjacent vertices. The output highlights a potential issue with `inV()`. ```gremlin gremlin> g.V().has("person", "name", "marko") ==>v[#23:1] gremlin> g.V(RID.of("#23:1")).outE().group().by(label).by(inV().values("name")).next() ==>created=lop ==>knows=vadas ``` -------------------------------- ### Java Gremlin Traversal for Grouping Vertices Source: https://github.com/jetbrains/youtrackdb/blob/develop/console/README.md This Java code defines a method to group adjacent vertices by their edge labels. It takes a YTDBGraphTraversalSource and a vertex ID as input, and returns a map where keys are edge labels and values are lists of vertices. It utilizes static imports for a more concise Gremlin syntax. ```java package com.my.company; import org.apache.tinkerpop.gremlin.structure.Vertex; import com.jetbrains.youtrackdb.api.record.RID; import com.jetbrains.youtrackdb.api.gremlin.YTDBGraphTraversalSource; import static org.apache.tinkerpop.gremlin.structure.T.*; import static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.*; import java.util.List; import java.util.Map; public final class Traversals { public static Map> groupAround(YTDBGraphTraversalSource g, RID vertexId) { return g.V(vertexId).outE(). group(). by(label). by(inV()).next(); } } ``` -------------------------------- ### Group Vertices by Label in YouTrackDB (Java) Source: https://github.com/jetbrains/youtrackdb/blob/develop/console/README.md Groups vertices by their outgoing edge labels and collects the connected vertices. This Java code uses Gremlin's DSL to achieve the grouping. It takes a traversal source and a vertex ID as input and returns a map where keys are labels and values are lists of vertices. ```java import static org.apache.tinkerpop.gremlin.structure.T.*; import static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.*; import java.util.List; import java.util.Map; public final class Traversals { public static Map> groupAround(YTDBGraphTraversalSource g, RID vertexId) { return g.V(vertexId).outE(). group(). by(label). by(inV().fold()).next(); } } ``` -------------------------------- ### Updated Java Gremlin Traversal with fold() Source: https://github.com/jetbrains/youtrackdb/blob/develop/console/README.md This Java code snippet is an update to the `groupAround` method, incorporating the `fold()` step within the traversal. This modification ensures that the `group()` step correctly handles multiple values for the `inV()` traversal, aligning the Java implementation with the corrected Gremlin logic. ```java package com.my.company; import org.apache.tinkerpop.gremlin.structure.Vertex; import com.jetbrains.youtrackdb.api.gremlin.YTDBGraphTraversalSource; import com.jetbrains.youtrackdb.api.record.RID; // ... other imports and class definition ... ``` -------------------------------- ### Remove Vertices by Name in YouTrackDB (Java - Corrected with autoExecuteInTx) Source: https://github.com/jetbrains/youtrackdb/blob/develop/console/README.md Corrected Java code for removing vertices by name using Gremlin within YouTrackDB. This version utilizes `autoExecuteInTx()` for automatic transaction management and traversal iteration, ensuring that the changes are persisted. It takes a traversal source and a name string as input. ```java package com.my.company; import com.jetbrains.youtrackdb.api.gremlin.YTDBGraphTraversalSource; public final class Traversals { public static void removeByName(YTDBGraphTraversalSource g, String name) { g.autoExecuteInTx(() -> it.V().has("name", name).drop()); } } ``` -------------------------------- ### Corrected Gremlin Traversal with fold() in YTDB Console Source: https://github.com/jetbrains/youtrackdb/blob/develop/console/README.md This Gremlin snippet shows the corrected traversal after identifying an issue with `inV()`. By adding `fold()` to `inV()`, the traversal now correctly collects all adjacent vertices into a list before grouping, resolving the previous issue and producing the expected output. ```gremlin gremlin> g.V(RID.of("#23:1")).outE().group().by(label).by(inV().values("name").fold()).next() ==>created=[lop] ==>knows=[josh, vadas] ``` -------------------------------- ### Remove Vertices by Name in YouTrackDB (Java - Initial) Source: https://github.com/jetbrains/youtrackdb/blob/develop/console/README.md An initial attempt to remove vertices by their 'name' property using Gremlin in Java. This code snippet demonstrates a common pitfall where the traversal is not explicitly iterated, leading to no changes being persisted outside the Gremlin console. It takes a traversal source and a name string as input. ```java package com.my.company; import com.jetbrains.youtrackdb.api.gremlin.YTDBGraphTraversalSource; public final class Traversals { public static void removeByName(YTDBGraphTraversalSource g, String name) { g.V().has("name", name).drop(); } } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.