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;
}
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");
}
}
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);
}
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;
}
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();
}
}
Aggregations