Search in sources :

Example 1 with DConfiguration

use of org.openntf.domino.graph2.impl.DConfiguration 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 DConfiguration

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

the class DFramedTransactionalGraph method frame.

public <F> F frame(final Vertex vertex, Class<F> kind, final boolean temporary) {
    if (vertex == null) {
        return null;
    }
    if (vertex instanceof DCategoryVertex) {
        kind = (Class<F>) CategoryVertex.class;
    } else {
        Map map = ((DVertex) vertex).getDelegate();
        if (map instanceof Document) {
            if (DesignFactory.isView((Document) map)) {
                kind = (Class<F>) ViewVertex.class;
            }
            if (DesignFactory.isIcon((Document) map) || DesignFactory.isACL((Document) map)) {
                // System.out.println("TEMP DEBUG framing an icon note");
                kind = (Class<F>) DbInfoVertex.class;
            }
        }
    }
    DConfiguration config = (DConfiguration) this.getConfig();
    Class<F> klazz = (Class<F>) (kind == null ? config.getDefaultVertexFrameType() : kind);
    if (config.getReplacementType(klazz) != null) {
        klazz = (Class<F>) config.getReplacementType(klazz);
    }
    DTypeManager manager = config.getTypeManager();
    klazz = (Class<F>) manager.initElement(klazz, this, vertex, temporary);
    for (FrameInitializer initializer : getConfig().getFrameInitializers()) {
        if (!(initializer instanceof JavaFrameInitializer)) {
            initializer.initElement(klazz, this, vertex);
        }
    }
    F result = null;
    try {
        result = super.frame(vertex, klazz);
    } catch (Throwable t) {
        System.out.println("Exception while attempting to frame a vertex " + vertex.getId() + " with class " + klazz.getName());
        t.printStackTrace();
        // DominoUtils.handleException(e);
        try {
            result = (F) super.frame(vertex, config.getDefaultVertexFrameType());
        } catch (Exception e) {
            System.out.println("Exception while attempting to frame a vertex " + vertex.getId() + " with class " + klazz.getName());
            e.printStackTrace();
            DominoUtils.handleException(e);
        }
    }
    for (FrameInitializer initializer : getConfig().getFrameInitializers()) {
        if (initializer instanceof JavaFrameInitializer) {
            ((JavaFrameInitializer) initializer).initElement(klazz, this, result);
        }
    }
    if (vertex instanceof DProxyVertex) {
        List<CaseInsensitiveString> proxied = config.getTypeRegistry().getProxied(klazz);
        if (proxied != null) {
            ((DProxyVertex) vertex).setProxied(proxied);
        }
    }
    if (result instanceof Eventable) {
        if (((Eventable) result).isNew()) {
            try {
                // $NON-NLS-1$
                Method crystal = result.getClass().getMethod("create");
                if (crystal != null) {
                    ((Eventable) result).create();
                }
            } catch (Throwable t) {
            // nothing
            }
        } else {
        // try {
        // Method crystal = result.getClass().getMethod("read", null);
        // if (crystal != null) {
        // ((Eventable) result).read();
        // }
        // } catch (Throwable t) {
        // //nothing
        // }
        }
    }
    return result;
}
Also used : CategoryVertex(org.openntf.domino.graph2.builtin.CategoryVertex) Eventable(org.openntf.domino.graph2.builtin.Eventable) Method(java.lang.reflect.Method) Document(org.openntf.domino.Document) JavaFrameInitializer(com.tinkerpop.frames.modules.javahandler.JavaFrameInitializer) FrameInitializer(com.tinkerpop.frames.FrameInitializer) InvalidCacheLoadException(com.google.common.cache.CacheLoader.InvalidCacheLoadException) UserAccessException(org.openntf.domino.exceptions.UserAccessException) UncheckedExecutionException(com.google.common.util.concurrent.UncheckedExecutionException) CaseInsensitiveString(org.openntf.domino.types.CaseInsensitiveString) ViewVertex(org.openntf.domino.graph2.builtin.ViewVertex) DbInfoVertex(org.openntf.domino.graph2.builtin.DbInfoVertex) DTypeManager(org.openntf.domino.graph2.impl.DConfiguration.DTypeManager) JavaFrameInitializer(com.tinkerpop.frames.modules.javahandler.JavaFrameInitializer) Map(java.util.Map)

Example 3 with DConfiguration

use of org.openntf.domino.graph2.impl.DConfiguration 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 DConfiguration

use of org.openntf.domino.graph2.impl.DConfiguration 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 DConfiguration

use of org.openntf.domino.graph2.impl.DConfiguration 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

DConfiguration (org.openntf.domino.graph2.impl.DConfiguration)9 DGraph (org.openntf.domino.graph2.impl.DGraph)9 DElementStore (org.openntf.domino.graph2.impl.DElementStore)7 DFramedGraphFactory (org.openntf.domino.graph2.impl.DFramedGraphFactory)7 DElementStore (org.openntf.domino.graph2.DElementStore)4 InvalidCacheLoadException (com.google.common.cache.CacheLoader.InvalidCacheLoadException)2 UncheckedExecutionException (com.google.common.util.concurrent.UncheckedExecutionException)2 FrameInitializer (com.tinkerpop.frames.FrameInitializer)2 Module (com.tinkerpop.frames.modules.Module)2 JavaFrameInitializer (com.tinkerpop.frames.modules.javahandler.JavaFrameInitializer)2 JavaHandlerModule (com.tinkerpop.frames.modules.javahandler.JavaHandlerModule)2 TypedGraphModuleBuilder (com.tinkerpop.frames.modules.typedgraph.TypedGraphModuleBuilder)2 NoteCoordinate (org.openntf.domino.big.NoteCoordinate)2 UserAccessException (org.openntf.domino.exceptions.UserAccessException)2 CategoryVertex (org.openntf.domino.graph2.builtin.CategoryVertex)2 DbInfoVertex (org.openntf.domino.graph2.builtin.DbInfoVertex)2 Eventable (org.openntf.domino.graph2.builtin.Eventable)2 ViewVertex (org.openntf.domino.graph2.builtin.ViewVertex)2 Person (org.openntf.domino.graph2.builtin.identity.Person)2 DTypeManager (org.openntf.domino.graph2.impl.DConfiguration.DTypeManager)2