use of org.structr.common.error.ErrorBuffer in project structr by structr.
the class SchemaProperty method getDoublePropertyParser.
public DoublePropertyParser getDoublePropertyParser() {
if (doublePropertyParser == null) {
try {
doublePropertyParser = new DoublePropertyParser(new ErrorBuffer(), getName(), this);
doublePropertyParser.getPropertySource(new StringBuilder(), getProperty(SchemaProperty.schemaNode));
} catch (FrameworkException fex) {
logger.warn("", fex);
}
}
return doublePropertyParser;
}
use of org.structr.common.error.ErrorBuffer in project structr by structr.
the class SchemaProperty method getIntArrayPropertyParser.
public IntegerArrayPropertyParser getIntArrayPropertyParser() {
if (intArrayPropertyParser == null) {
try {
intArrayPropertyParser = new IntegerArrayPropertyParser(new ErrorBuffer(), getName(), this);
intArrayPropertyParser.getPropertySource(new StringBuilder(), getProperty(SchemaProperty.schemaNode));
} catch (FrameworkException fex) {
logger.warn("", fex);
}
}
return intArrayPropertyParser;
}
use of org.structr.common.error.ErrorBuffer in project structr by structr.
the class SchemaProperty method getLongArrayPropertyParser.
public LongArrayPropertyParser getLongArrayPropertyParser() {
if (longArrayPropertyParser == null) {
try {
longArrayPropertyParser = new LongArrayPropertyParser(new ErrorBuffer(), getName(), this);
longArrayPropertyParser.getPropertySource(new StringBuilder(), getProperty(SchemaProperty.schemaNode));
} catch (FrameworkException fex) {
logger.warn("", fex);
}
}
return longArrayPropertyParser;
}
use of org.structr.common.error.ErrorBuffer in project structr by structr.
the class SchemaProperty method getDoubleArrayPropertyParser.
public DoubleArrayPropertyParser getDoubleArrayPropertyParser() {
if (doubleArrayPropertyParser == null) {
try {
doubleArrayPropertyParser = new DoubleArrayPropertyParser(new ErrorBuffer(), getName(), this);
doubleArrayPropertyParser.getPropertySource(new StringBuilder(), getProperty(SchemaProperty.schemaNode));
} catch (FrameworkException fex) {
logger.warn("", fex);
}
}
return doubleArrayPropertyParser;
}
use of org.structr.common.error.ErrorBuffer in project structr by structr.
the class SyncCommand method importDatabase.
private static void importDatabase(final DatabaseService graphDb, final SecurityContext securityContext, final ZipInputStream zis, boolean doValidation, final Long batchSize) throws FrameworkException, IOException {
final App app = StructrApp.getInstance();
final DataInputStream dis = new DataInputStream(new BufferedInputStream(zis));
final long internalBatchSize = batchSize != null ? batchSize : 200;
final String uuidPropertyName = GraphObject.id.dbName();
final Map<String, Node> uuidMap = new LinkedHashMap<>();
final Set<Long> deletedNodes = new HashSet<>();
double t0 = System.nanoTime();
PropertyContainer currentObject = null;
String currentKey = null;
boolean finished = false;
long totalNodeCount = 0;
long totalRelCount = 0;
do {
try (final Tx tx = app.tx(doValidation)) {
final List<Relationship> rels = new LinkedList<>();
final List<Node> nodes = new LinkedList<>();
long nodeCount = 0;
long relCount = 0;
do {
try {
// store current position
dis.mark(4);
// read one byte
byte objectType = dis.readByte();
// skip newlines
if (objectType == '\n') {
continue;
}
if (objectType == 'N') {
// break loop after 200 objects, commit and restart afterwards
if (nodeCount + relCount >= internalBatchSize) {
dis.reset();
break;
}
currentObject = graphDb.createNode(Collections.EMPTY_SET, Collections.EMPTY_MAP);
nodeCount++;
// store for later use
nodes.add((Node) currentObject);
} else if (objectType == 'R') {
// break look after 200 objects, commit and restart afterwards
if (nodeCount + relCount >= internalBatchSize) {
dis.reset();
break;
}
String startId = (String) deserialize(dis);
String endId = (String) deserialize(dis);
String relTypeName = (String) deserialize(dis);
Node endNode = uuidMap.get(endId);
Node startNode = uuidMap.get(startId);
if (startNode != null && endNode != null) {
if (deletedNodes.contains(startNode.getId()) || deletedNodes.contains(endNode.getId())) {
System.out.println("NOT creating relationship between deleted nodes..");
currentObject = null;
currentKey = null;
} else {
RelationshipType relType = RelationshipType.forName(relTypeName);
currentObject = startNode.createRelationshipTo(endNode, relType);
// store for later use
rels.add((Relationship) currentObject);
relCount++;
}
} else {
System.out.println("NOT creating relationship of type " + relTypeName + ", start: " + startId + ", end: " + endId);
currentObject = null;
currentKey = null;
}
} else {
// reset if not at the beginning of a line
dis.reset();
if (currentKey == null) {
try {
currentKey = (String) deserialize(dis);
} catch (Throwable t) {
logger.warn("", t);
}
} else {
final Object obj = deserialize(dis);
if (obj != null && currentObject != null) {
if (uuidPropertyName.equals(currentKey) && currentObject instanceof Node) {
final String uuid = (String) obj;
uuidMap.put(uuid, (Node) currentObject);
}
if (currentKey.length() != 0) {
// store object in DB
currentObject.setProperty(currentKey, obj);
// set type label
if (currentObject instanceof Node && NodeInterface.type.dbName().equals(currentKey)) {
((Node) currentObject).addLabel(graphDb.forName(Label.class, (String) obj));
}
} else {
logger.error("Invalid property key for value {}, ignoring", obj);
}
} else {
logger.warn("No current object to store property in.");
}
currentKey = null;
}
}
} catch (EOFException eofex) {
finished = true;
}
} while (!finished);
totalNodeCount += nodeCount;
totalRelCount += relCount;
logger.info("Imported {} nodes and {} rels, committing transaction..", new Object[] { totalNodeCount, totalRelCount });
tx.success();
}
} while (!finished);
// build schema
try (final Tx tx = app.tx()) {
SchemaHelper.reloadSchema(new ErrorBuffer(), securityContext.getSessionId());
tx.success();
} catch (FrameworkException fex) {
logger.warn("", fex);
}
final Map<String, Object> params = new HashMap<>();
params.put("removeUnused", false);
// set correct labels after schema has been compiled
app.command(BulkCreateLabelsCommand.class).execute(params);
double t1 = System.nanoTime();
double time = ((t1 - t0) / 1000000000.0);
DecimalFormat decimalFormat = new DecimalFormat("0.000000000", DecimalFormatSymbols.getInstance(Locale.ENGLISH));
logger.info("Import done in {} s", decimalFormat.format(time));
}
Aggregations