org.umlg.runtime.adaptor.UmlgGraph Maven / Gradle / Ivy
package org.umlg.runtime.adaptor;
import org.apache.tinkerpop.gremlin.structure.Edge;
import org.apache.tinkerpop.gremlin.structure.Element;
import org.apache.tinkerpop.gremlin.structure.Graph;
import org.apache.tinkerpop.gremlin.structure.Vertex;
import org.umlg.runtime.collection.Filter;
import org.umlg.runtime.collection.UmlgRuntimeProperty;
import org.umlg.runtime.collection.UmlgSet;
import org.umlg.runtime.collection.persistent.PropertyTree;
import org.umlg.runtime.domain.PersistentObject;
import org.umlg.runtime.domain.UmlgApplicationNode;
import org.umlg.runtime.notification.NotificationListener;
import org.umlg.runtime.notification.UmlgNotificationManager;
import java.util.List;
import java.util.Map;
import java.util.Set;
public interface UmlgGraph extends Graph {
static final String ROOT_VERTEX = "UmlgRootVertex";
static final String DELETION_VERTEX = "deletionVertex";
static final String DELETED_VERTEX_EDGE = "deletedVertexEdgeToRoot";
static final String ROOT_CLASS_NAME = "org.umlg.root.Root";
void commit(boolean validate);
void commit();
void rollback();
UmlgSet allInstances(String className);
UmlgSet allInstances(String className, Filter filter);
/**
* returns the singleton Entity that represents the model.
* @return
*/
UmlgApplicationNode getUmlgApplicationNode();
void createKeyIndex(final String key, final Class elementClass, final UmlgParameter... indexUmlgParameters);
/**
* Instantiate any concrete classifier with its vertex id.
* @param id The id of the vertex that represents this object.
* @param The class of the object to instantiate.
* @return The entity that is represented by the vertex with id id.
*/
T getEntity(Object id);
/**
* Instantiate any concrete classifier with its vertex.
* @param vertex The vertex that represents this object.
* @param The class of the object to instantiate.
* @return The entity that is represented by the vertex with id id.
*/
public T getEntity(Vertex vertex);
/**
* uml models that have applied the Umlg::Profile and applied the <> stereotype to a property of the class
* will have instances of that class automatically indexed. The key of the index is the qualified name of the property.
* The value is the value of the property.
* UMLG <> stereotype supports UNIQUE and NON_UNIQUE indexes.
* getFromUniqueIndex returns the single object from the UNIQUE index.
*
* @param key The key to search the index on.
* @param value The value of the indexed property.
* @param The class of the indexed entity.
* @return The entity of class T with property with indexedKey that has a value of indexValue.
*/
T getFromUniqueIndex(String label, String key, Object value);
/**
* uml models that have applied the Umlg::Profile and applied the <> stereotype to a property of the class
* will have instances of that class automatically indexed. The key of the index is the qualified name of the property.
* The value is the value of the property.
* UMLG <> stereotype supports UNIQUE and NON_UNIQUE indexes.
* getFromIndex returns the all objects from the NON_UNIQUE index.
*
* @param key The key to search the index on.
* @param value The value of the indexed property.
* @param The class of the indexed entity.
* @return The entity of class T with property with indexedKey that has a value of indexValue.
*/
List getFromIndex(String label, String key, Object value);
List get(PropertyTree propertyTree);
/**
* Execute a query.
* @param umlgQueryEnum UMLG queries can be one of {@link org.umlg.runtime.adaptor.UmlgQueryEnum#OCL},
* {@link org.umlg.runtime.adaptor.UmlgQueryEnum#GROOVY} or {@link org.umlg.runtime.adaptor.UmlgQueryEnum#NATIVE}
* GROOVY includes gremlin queries.
* @param contextId The contextId of a query is the starting point of the query. If the query is an OCL query then it is the
* id of the Class that will be the context of the OCL query.
* If the query is a Gremlin query then the key word 'self' together with a context id translates into calling g.V(contextId)
* @param query The text of the query.
* @return return a String representation of the result of the query.
*/
String executeQueryToJson(UmlgQueryEnum umlgQueryEnum, Object contextId, String query);
/**
* Execute a query.
* @param umlgQueryEnum UMLG queries can be one of {@link org.umlg.runtime.adaptor.UmlgQueryEnum#OCL},
* {@link org.umlg.runtime.adaptor.UmlgQueryEnum#GROOVY} or {@link org.umlg.runtime.adaptor.UmlgQueryEnum#NATIVE}
* GROOVY includes gremlin queries.
* @param contextId The contextId of a query is the starting point of the query. If the query is an OCL query then it is the
* id of the Class that will be the context of the OCL query.
* If the query is a Gremlin query then the key word 'self' together with a context id translates into calling g.V(contextId)
* @param query The text of the query.
* @return The result of the query.
*/
T executeQuery(UmlgQueryEnum umlgQueryEnum, Object contextId, String query);
// /**
// * @return The singleton root node of the application/model
// */
// Vertex getRoot();
Vertex addVertex(String label, Map properties);
Set getEdgesBetween(Vertex v1, Vertex v2, String... labels);
boolean hasEdgeBeenDeleted(Edge edge);
boolean isTransactionActive();
/**
* To be called at the end of a threads interaction with the graph.
* This is useful for clearing thread locals.
* Blueprints implementation have different threading models.
* For OrientDb this is where the graph will be shutdown.
*/
void afterThreadContext();
T getUnderlyingGraph();
public default void registerListener(UmlgRuntimeProperty umlgRuntimeProperty, NotificationListener listener) {
UmlgNotificationManager.INSTANCE.registerListener(umlgRuntimeProperty, listener);
}
public default boolean supportsBatchMode() {
return false;
}
public default void batchModeOn() {
}
public default boolean isInBatchMode() {
return false;
}
public void bypassValidation();
public static class Exceptions {
public static IllegalArgumentException classForElementCannotBeNull() {
return new IllegalArgumentException("elementClass argument cannot be null.");
}
public static IllegalArgumentException classIsNotIndexable(final Class clazz) {
return new IllegalArgumentException("Class is not indexable: " + clazz);
}
}
}