use of org.structr.core.GraphObject in project structr by structr.
the class PerformanceTest method testPerformanceOfNodeDeletion.
@Test
public void testPerformanceOfNodeDeletion() {
final App app = StructrApp.getInstance(setup());
final List<TestOne> nodes = new LinkedList<>();
final int number = 1000;
try {
try (final Tx tx = app.tx()) {
nodes.addAll(createNodes(app, TestOne.class, number));
tx.success();
}
} catch (FrameworkException ex) {
logger.error(ex.toString());
fail("Unexpected exception");
}
// start measuring
final long t0 = System.currentTimeMillis();
try {
final BulkDeleteCommand cmd = app.command(BulkDeleteCommand.class);
try (final Tx tx = app.tx()) {
final Iterator<GraphObject> iterator = (Iterator) nodes.iterator();
cmd.bulkDelete(iterator);
tx.success();
}
} catch (FrameworkException ex) {
logger.error(ex.toString());
fail("Unexpected exception");
}
final long t1 = System.currentTimeMillis();
DecimalFormat decimalFormat = new DecimalFormat("0.000000000", DecimalFormatSymbols.getInstance(Locale.ENGLISH));
Double time = (t1 - t0) / 1000.0;
Double rate = number / ((t1 - t0) / 1000.0);
logger.info("Deleted {} nodes in {} seconds ({} per s)", number, decimalFormat.format(time), decimalFormat.format(rate));
assertTrue("Deletion rate of nodes too low, expected > 100, was " + rate, rate > 50);
}
use of org.structr.core.GraphObject in project structr by structr.
the class DOMNodeChildrenCommand method processMessage.
@Override
public void processMessage(final WebSocketMessage webSocketData) {
final DOMNode node = getDOMNode(webSocketData.getId());
if (node == null) {
return;
}
final List<GraphObject> result = new LinkedList<>();
DOMNode currentNode = (DOMNode) node.getFirstChild();
while (currentNode != null) {
result.add(currentNode);
currentNode = (DOMNode) currentNode.getNextSibling();
}
webSocketData.setView(PropertyView.Ui);
webSocketData.setResult(result);
// send only over local connection
getWebSocket().send(webSocketData, true);
}
use of org.structr.core.GraphObject in project structr by structr.
the class SyncCommand method exportToFile.
// ----- static methods -----
/**
* Exports the whole structr database to a file with the given name.
*
* @param graphDb
* @param fileName
* @param includeFiles
* @throws FrameworkException
*/
public static void exportToFile(final DatabaseService graphDb, final String fileName, final String query, final boolean includeFiles) throws FrameworkException {
final App app = StructrApp.getInstance();
try (final Tx tx = app.tx()) {
final NodeFactory nodeFactory = new NodeFactory(SecurityContext.getSuperUserInstance());
final RelationshipFactory relFactory = new RelationshipFactory(SecurityContext.getSuperUserInstance());
final Set<AbstractNode> nodes = new HashSet<>();
final Set<AbstractRelationship> rels = new HashSet<>();
boolean conditionalIncludeFiles = includeFiles;
if (query != null) {
logger.info("Using Cypher query {} to determine export set, disabling export of files", query);
conditionalIncludeFiles = false;
final List<GraphObject> result = StructrApp.getInstance().cypher(query, null);
for (final GraphObject obj : result) {
if (obj.isNode()) {
nodes.add((AbstractNode) obj.getSyncNode());
} else {
rels.add((AbstractRelationship) obj.getSyncRelationship());
}
}
logger.info("Query returned {} nodes and {} relationships.", new Object[] { nodes.size(), rels.size() });
} else {
nodes.addAll(nodeFactory.bulkInstantiate(graphDb.getAllNodes()));
rels.addAll(relFactory.bulkInstantiate(graphDb.getAllRelationships()));
}
try (final FileOutputStream fos = new FileOutputStream(fileName)) {
exportToStream(fos, nodes, rels, null, conditionalIncludeFiles);
}
tx.success();
} catch (Throwable t) {
logger.warn("", t);
throw new FrameworkException(500, t.getMessage());
}
}
use of org.structr.core.GraphObject in project structr by structr.
the class CypherQueryCommand method handleObject.
final Object handleObject(final NodeFactory nodeFactory, final RelationshipFactory relFactory, final String key, final Object value, boolean includeHiddenAndDeleted, boolean publicOnly, int level) throws FrameworkException {
GraphObject graphObject = null;
if (value instanceof Node) {
graphObject = nodeFactory.instantiate((Node) value, includeHiddenAndDeleted, publicOnly);
} else if (value instanceof Relationship) {
graphObject = relFactory.instantiate((Relationship) value);
} else if (value instanceof Map) {
final Map<String, Object> valueMap = (Map<String, Object>) value;
graphObject = new GraphObjectMap();
for (final Entry<String, Object> valueEntry : valueMap.entrySet()) {
final String valueKey = valueEntry.getKey();
final Object valueValue = valueEntry.getValue();
graphObject.setProperty(new GenericProperty(valueKey), handleObject(nodeFactory, relFactory, valueKey, valueValue, includeHiddenAndDeleted, publicOnly, level + 1));
}
} else if (value instanceof Collection) {
final Collection<Object> valueCollection = (Collection<Object>) value;
final List<Object> collection = new LinkedList<>();
for (final Object valueEntry : valueCollection) {
collection.add(handleObject(nodeFactory, relFactory, null, valueEntry, includeHiddenAndDeleted, publicOnly, level + 1));
}
return collection;
} else if (level == 0) {
graphObject = new GraphObjectMap();
graphObject.setProperty(new GenericProperty(key), value);
} else {
return value;
}
return graphObject;
}
use of org.structr.core.GraphObject in project structr by structr.
the class ValuesFunction method apply.
@Override
public Object apply(final ActionContext ctx, final Object caller, final Object[] sources) throws FrameworkException {
// if (arrayHasMinLengthAndAllElementsNotNull(sources, 2) && sources[0] instanceof GraphObject) {
if (sources.length >= 2 && sources[0] instanceof GraphObject) {
final Set<Object> values = new LinkedHashSet<>();
final GraphObject source = (GraphObject) sources[0];
for (final PropertyKey key : source.getPropertyKeys(sources[1].toString())) {
values.add(source.getProperty(key));
}
return new LinkedList<>(values);
// } else if (arrayHasMinLengthAndAllElementsNotNull(sources, 1) && sources[0] instanceof GraphObjectMap) {
} else if (sources.length >= 1) {
if (sources[0] instanceof GraphObjectMap) {
return new LinkedList<>(((GraphObjectMap) sources[0]).values());
} else if (sources[0] instanceof Map) {
return new LinkedList<>(((Map) sources[0]).values());
}
}
logParameterError(caller, sources, ctx.isJavaScriptContext());
return "";
}
Aggregations