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