Search in sources :

Example 1 with DGraph

use of org.openntf.domino.graph2.impl.DGraph in project org.openntf.domino by OpenNTF.

the class DFramedTransactionalGraph method addVertex.

public <F> F addVertex(final Object id, final Class<F> kind, final boolean temporary) {
    if (id != null && id instanceof NoteCoordinate) {
        Object cacheChk = getElement(id, kind);
        if (cacheChk != null) {
            return (F) cacheChk;
        }
    }
    DGraph base = (DGraph) this.getBaseGraph();
    org.openntf.domino.graph2.DElementStore store = null;
    if (kind != null) {
        store = base.findElementStore(kind);
    }
    if (store == null) {
        // System.out.println("TEMP DEBUG store was null for type " + kind.getName());
        if (id instanceof NoteCoordinate) {
            store = base.findElementStore(id);
        } else {
            String typeid = getTypedId(id);
            if (typeid == null) {
                store = base.getDefaultElementStore();
            } else {
                store = base.findElementStore(typeid);
            }
        }
    } else {
    // System.out.println("TEMP DEBUG adding to store " + ((Database) store.getStoreDelegate()).getApiPath());
    }
    Vertex vertex = store.addVertex(id, temporary);
    String typeValue = ((DConfiguration) this.getConfig()).getTypeValue(kind);
    // System.out.println("TEMP DEBUG Creating new instance of " + kind.getName() + " with typeValue of " + typeValue);
    vertex.setProperty("form", typeValue);
    F result = frame(vertex, kind, temporary);
    if (result instanceof Eventable) {
    }
    if (!temporary) {
        getFramedElementCache().put(vertex.getId(), result);
    }
    return result;
}
Also used : NoteCoordinate(org.openntf.domino.big.NoteCoordinate) DbInfoVertex(org.openntf.domino.graph2.builtin.DbInfoVertex) ViewVertex(org.openntf.domino.graph2.builtin.ViewVertex) CategoryVertex(org.openntf.domino.graph2.builtin.CategoryVertex) Vertex(com.tinkerpop.blueprints.Vertex) Eventable(org.openntf.domino.graph2.builtin.Eventable) CaseInsensitiveString(org.openntf.domino.types.CaseInsensitiveString) DElementStore(org.openntf.domino.graph2.DElementStore)

Example 2 with DGraph

use of org.openntf.domino.graph2.impl.DGraph in project org.openntf.domino by OpenNTF.

the class DFramedTransactionalGraph method getFilteredElements.

public <F> Iterable<F> getFilteredElements(final String classname, final List<CharSequence> keys, final List<CaseInsensitiveString> values) {
    // System.out.println("Getting a filtered list of elements of type " + classname);
    org.openntf.domino.graph2.DElementStore store = null;
    DGraph base = (DGraph) this.getBaseGraph();
    Class<?> chkClass = getClassFromName(classname);
    if (chkClass != null) {
        store = base.findElementStore(chkClass);
        if (store != null) {
            List<String> keystrs = CaseInsensitiveString.toStrings(keys);
            List<Object> valobj = new ArrayList<Object>(values);
            String formulaFilter = org.openntf.domino.graph2.DGraph.Utils.getFramedElementFormula(keystrs, valobj, chkClass);
            long startTime = new Date().getTime();
            Iterable<Element> elements = (org.openntf.domino.graph2.impl.DElementIterable) store.getElements(formulaFilter);
            long endTime = new Date().getTime();
            System.out.println("TEMP DEBUG Retrieved elements for type " + classname + " in " + (endTime - startTime) + "ms. Framing...");
            return this.frameElements(elements, null);
        } else {
            return null;
        }
    } else {
        throw new IllegalArgumentException("Class " + classname + " not registered in graph");
    }
}
Also used : Element(com.tinkerpop.blueprints.Element) ArrayList(java.util.ArrayList) CaseInsensitiveString(org.openntf.domino.types.CaseInsensitiveString) Date(java.util.Date) DElementStore(org.openntf.domino.graph2.DElementStore)

Example 3 with DGraph

use of org.openntf.domino.graph2.impl.DGraph in project org.openntf.domino by OpenNTF.

the class IndexFactory method initGraph.

public void initGraph() {
    DElementStore termsStore = new org.openntf.domino.graph2.builtin.search.IndexStore();
    termsStore.setStoreKey("ODADemo/terms.nsf");
    termsStore.addType(Term.class);
    DElementStore valuesStore = new org.openntf.domino.graph2.builtin.search.IndexStore();
    valuesStore.setStoreKey("ODADemo/values.nsf");
    valuesStore.addType(Value.class);
    DElementStore namesStore = new org.openntf.domino.graph2.builtin.search.IndexStore();
    namesStore.setStoreKey("ODADemo/names.nsf");
    namesStore.addType(Name.class);
    DConfiguration config = new DConfiguration();
    @SuppressWarnings("unused") DGraph graph = new DGraph(config);
    config.addElementStore(termsStore);
    config.addElementStore(valuesStore);
    config.addElementStore(namesStore);
}
Also used : DElementStore(org.openntf.domino.graph2.DElementStore) DGraph(org.openntf.domino.graph2.impl.DGraph) DConfiguration(org.openntf.domino.graph2.impl.DConfiguration)

Example 4 with DGraph

use of org.openntf.domino.graph2.impl.DGraph in project org.openntf.domino by OpenNTF.

the class BasicGraphFactory method getGraph.

protected static synchronized DGraph getGraph(final String apipath) {
    DConfiguration config = new DConfiguration();
    DGraph graph = new DGraph(config);
    DElementStore store = new org.openntf.domino.graph2.impl.DElementStore();
    store.setStoreKey(apipath);
    config.setDefaultElementStore(store);
    return graph;
}
Also used : DElementStore(org.openntf.domino.graph2.DElementStore) DGraph(org.openntf.domino.graph2.impl.DGraph) DConfiguration(org.openntf.domino.graph2.impl.DConfiguration)

Example 5 with DGraph

use of org.openntf.domino.graph2.impl.DGraph in project org.openntf.domino by OpenNTF.

the class Graph2Demo method run3.

public void run3() {
    long testStartTime = System.nanoTime();
    marktime = System.nanoTime();
    try {
        timelog("Beginning graph2 test3...");
        DElementStore crewStore = new DElementStore();
        crewStore.setStoreKey(NoteCoordinate.Utils.getLongFromReplid(crewId));
        crewStore.addType(Crew.class);
        DElementStore movieStore = new DElementStore();
        movieStore.setStoreKey(NoteCoordinate.Utils.getLongFromReplid(movieId));
        movieStore.addType(Movie.class);
        DElementStore characterStore = new DElementStore();
        characterStore.setStoreKey(NoteCoordinate.Utils.getLongFromReplid(characterId));
        characterStore.addType(Character.class);
        DElementStore edgeStore = new DElementStore();
        edgeStore.setStoreKey(NoteCoordinate.Utils.getLongFromReplid(edgeId));
        DElementStore usersStore = new DElementStore();
        usersStore.setStoreKey(NoteCoordinate.Utils.getLongFromReplid(nabId));
        usersStore.setProxyStoreKey(NoteCoordinate.Utils.getLongFromReplid(usersId));
        usersStore.addType(Person.class);
        DConfiguration config = new DConfiguration();
        config.addElementStore(crewStore);
        config.addElementStore(movieStore);
        config.addElementStore(characterStore);
        config.addElementStore(edgeStore);
        config.addElementStore(usersStore);
        config.setDefaultElementStore(NoteCoordinate.Utils.getLongFromReplid(edgeId));
        graph = new DGraph(config);
        JavaHandlerModule jhm = new JavaHandlerModule();
        Module module = new TypedGraphModuleBuilder().withClass(Person.class).withClass(Movie.class).withClass(Character.class).withClass(Crew.class).build();
        DFramedGraphFactory factory = new DFramedGraphFactory(module, jhm);
        FramedTransactionalGraph<DGraph> framedGraph = factory.create(graph);
        Person ntfUser = framedGraph.getVertex(nabId + ntfUnid, Person.class);
        Movie newhopeMovie = framedGraph.getVertex("Star Wars", Movie.class);
        Movie empireMovie = framedGraph.getVertex("The Empire Strikes Back", Movie.class);
        Movie jediMovie = framedGraph.getVertex("Return of the Jedi", Movie.class);
        Movie phantomMovie = framedGraph.getVertex("The Phantom Menace", Movie.class);
        Movie clonesMovie = framedGraph.getVertex("Attack of the Clones", Movie.class);
        Movie revengeMovie = framedGraph.getVertex("Revenge of the Sith", Movie.class);
        System.out.println("***************************");
        System.out.println("Don't miss " + newhopeMovie.getTitle());
        Iterable<Starring> starrings = newhopeMovie.getStarring();
        for (Starring starring : starrings) {
            Crew crew = starring.getStar();
            Character character = crew.getPortraysCharacters().iterator().next();
            System.out.println(crew.getFirstName() + " " + crew.getLastName() + " as " + character.getName());
        }
        System.out.println("***************************");
        System.out.println("Don't miss " + empireMovie.getTitle());
        starrings = empireMovie.getStarring();
        for (Starring starring : starrings) {
            Crew crew = starring.getStar();
            Character character = crew.getPortraysCharacters().iterator().next();
            System.out.println(crew.getFirstName() + " " + crew.getLastName() + " as " + character.getName());
        }
        System.out.println("***************************");
        System.out.println("Don't miss " + jediMovie.getTitle());
        starrings = jediMovie.getStarring();
        for (Starring starring : starrings) {
            Crew crew = starring.getStar();
            Character character = crew.getPortraysCharacters().iterator().next();
            System.out.println(crew.getFirstName() + " " + crew.getLastName() + " as " + character.getName());
        }
    } catch (Throwable t) {
        t.printStackTrace();
    }
}
Also used : JavaHandlerModule(com.tinkerpop.frames.modules.javahandler.JavaHandlerModule) TypedGraphModuleBuilder(com.tinkerpop.frames.modules.typedgraph.TypedGraphModuleBuilder) DElementStore(org.openntf.domino.graph2.impl.DElementStore) DGraph(org.openntf.domino.graph2.impl.DGraph) DConfiguration(org.openntf.domino.graph2.impl.DConfiguration) JavaHandlerModule(com.tinkerpop.frames.modules.javahandler.JavaHandlerModule) Module(com.tinkerpop.frames.modules.Module) Person(org.openntf.domino.graph2.builtin.identity.Person) DFramedGraphFactory(org.openntf.domino.graph2.impl.DFramedGraphFactory)

Aggregations

DGraph (org.openntf.domino.graph2.impl.DGraph)17 DElementStore (org.openntf.domino.graph2.DElementStore)12 CaseInsensitiveString (org.openntf.domino.types.CaseInsensitiveString)12 DConfiguration (org.openntf.domino.graph2.impl.DConfiguration)9 DElementStore (org.openntf.domino.graph2.impl.DElementStore)7 DFramedGraphFactory (org.openntf.domino.graph2.impl.DFramedGraphFactory)7 Element (com.tinkerpop.blueprints.Element)5 ArrayList (java.util.ArrayList)5 Person (org.openntf.domino.graph2.builtin.identity.Person)4 Vertex (com.tinkerpop.blueprints.Vertex)3 List (java.util.List)3 Session (org.openntf.domino.Session)3 DFramedTransactionalGraph (org.openntf.domino.graph2.impl.DFramedTransactionalGraph)3 Edge (com.tinkerpop.blueprints.Edge)2 Module (com.tinkerpop.frames.modules.Module)2 JavaHandlerModule (com.tinkerpop.frames.modules.javahandler.JavaHandlerModule)2 TypedGraphModuleBuilder (com.tinkerpop.frames.modules.typedgraph.TypedGraphModuleBuilder)2 Database (org.openntf.domino.Database)2 NoteCoordinate (org.openntf.domino.big.NoteCoordinate)2 FramedVertexList (org.openntf.domino.graph2.annotations.FramedVertexList)2