use of org.structr.core.entity.AbstractSchemaNode in project structr by structr.
the class SyncCommand method exportDatabase.
private static void exportDatabase(final ZipOutputStream zos, final OutputStream outputStream, final Iterable<? extends NodeInterface> nodes, final Iterable<? extends RelationshipInterface> relationships) throws IOException, FrameworkException {
// start database zip entry
final ZipEntry dbEntry = new ZipEntry(STRUCTR_ZIP_DB_NAME);
final DataOutputStream dos = new DataOutputStream(outputStream);
final String uuidPropertyName = GraphObject.id.dbName();
int nodeCount = 0;
int relCount = 0;
zos.putNextEntry(dbEntry);
for (NodeInterface nodeObject : nodes) {
// skip schema
if (nodeObject instanceof AbstractSchemaNode) {
continue;
}
final Node node = nodeObject.getNode();
// ignore non-structr nodes
if (node.hasProperty(GraphObject.id.dbName())) {
outputStream.write('N');
for (String key : node.getPropertyKeys()) {
serialize(dos, key);
serialize(dos, node.getProperty(key));
}
// do not use platform-specific line ending here!
dos.write('\n');
nodeCount++;
}
}
dos.flush();
for (RelationshipInterface relObject : relationships) {
final Relationship rel = relObject.getRelationship();
// ignore non-structr nodes
if (rel.hasProperty(GraphObject.id.dbName())) {
final Node startNode = rel.getStartNode();
final Node endNode = rel.getEndNode();
if (startNode.hasProperty(uuidPropertyName) && endNode.hasProperty(uuidPropertyName)) {
String startId = (String) startNode.getProperty(uuidPropertyName);
String endId = (String) endNode.getProperty(uuidPropertyName);
outputStream.write('R');
serialize(dos, startId);
serialize(dos, endId);
serialize(dos, rel.getType().name());
for (String key : rel.getPropertyKeys()) {
serialize(dos, key);
serialize(dos, rel.getProperty(key));
}
// do not use platform-specific line ending here!
dos.write('\n');
relCount++;
}
}
}
dos.flush();
// finish db entry
zos.closeEntry();
logger.info("Exported {} nodes and {} rels", new Object[] { nodeCount, relCount });
}
use of org.structr.core.entity.AbstractSchemaNode in project structr by structr.
the class StructrSchemaPropertyPath method getSchemaNode.
public AbstractSchemaNode getSchemaNode() {
if (schemaNode == null) {
final App app = StructrApp.getInstance(fs.getSecurityContext());
try (final Tx tx = app.tx()) {
// remove /files from path since it is a virtual directory
schemaNode = app.nodeQuery(AbstractSchemaNode.class).and(AbstractNode.name, name).getFirst();
tx.success();
} catch (FrameworkException fex) {
logger.warn("Unable to load actual file for path {}: {}", new Object[] { toString(), fex.getMessage() });
}
}
return schemaNode;
}
Aggregations