/** * Get a document by sourceUri and update it from the given map. * @param incomingDocMap The document's db columns. * @return The saved document. * @throws IllegalArgumentException if sourceUri or docType are null, or if the document doesn't exist. */ public ODocument mergeDocument(Map<String, ? extends Object> incomingDocMap) { String sourceUri = (String) incomingDocMap.get(DocumentAttributes.SOURCE_URI.toString()); if (null == sourceUri) throw new IllegalArgumentException("Document sourceUri is null."); String docType = (String) incomingDocMap.get(Crawler.Attributes.TYPE); if (null == docType) throw new IllegalArgumentException("Document docType is null."); // Get a document by sourceUri String sql = "SELECT * FROM " + docType + " WHERE sourceuri=?"; activateOnCurrentThread(); List<ODocument> results = db.command(new OSQLSynchQuery<ODocument>(sql)).execute(sourceUri); if (results.size() == 0) throw new JBakeException("No document with sourceUri '"+sourceUri+"'."); // Update it from the given map. ODocument incomingDoc = new ODocument(docType); incomingDoc.fromMap(incomingDocMap); ODocument merged = results.get(0).merge(incomingDoc, true, false); return merged; }
private boolean handleMerge(ODocument record) { boolean updated = false; if (merge != null) { // MERGE THE CONTENT record.merge(merge, true, false); updated = true; } return updated; }
private void handleMerge(ODocument record, OCommandContext ctx) { record.merge(json.toDocument(record, ctx), true, false); }
@SuppressWarnings("unchecked") public Object execute(Object iThis, final OIdentifiable iCurrentRecord, Object iCurrentResult, final Object[] iParams, OCommandContext iContext) { if (iParams.length > 2) // IN LINE MODE context = new ODocument(); if (iParams.length == 1) { if (iParams[0] instanceof ODocument) // INSERT EVERY DOCUMENT FIELD context.merge((ODocument) iParams[0], true, false); else if (iParams[0] instanceof Map<?, ?>) // INSERT EVERY SINGLE COLLECTION ITEM context.fields((Map<String, Object>) iParams[0]); else throw new IllegalArgumentException("Map function: expected a map or pairs of parameters as key, value"); } else if (iParams.length % 2 != 0) throw new IllegalArgumentException("Map function: expected a map or pairs of parameters as key, value"); else for (int i = 0; i < iParams.length; i += 2) { final String key = iParams[i].toString(); final Object value = iParams[i + 1]; if (value != null) { if (iParams.length <= 2 && context == null) // AGGREGATION MODE (STATEFULL) context = new ODocument(); context.field(key, value); } } return prepareResult(context); }
/** * Get a document by sourceUri and update it from the given map. * @param incomingDocMap The document's db columns. * @return The saved document. * @throws IllegalArgumentException if sourceUri or docType are null, or if the document doesn't exist. */ public ODocument mergeDocument(Map<String, ? extends Object> incomingDocMap) { String sourceUri = (String) incomingDocMap.get(DocumentAttributes.SOURCE_URI.toString()); if (null == sourceUri) throw new IllegalArgumentException("Document sourceUri is null."); String docType = (String) incomingDocMap.get(Crawler.Attributes.TYPE); if (null == docType) throw new IllegalArgumentException("Document docType is null."); // Get a document by sourceUri String sql = "SELECT * FROM " + docType + " WHERE sourceuri=?"; activateOnCurrentThread(); List<ODocument> results = db.command(new OSQLSynchQuery<ODocument>(sql)).execute(sourceUri); if (results.size() == 0) throw new JBakeException("No document with sourceUri '"+sourceUri+"'."); // Update it from the given map. ODocument incomingDoc = new ODocument(docType); incomingDoc.fromMap(incomingDocMap); ODocument merged = results.get(0).merge(incomingDoc, true, false); return merged; }
@Override public byte[] onUpdate(OStorage storage, byte iRecordType, final ORecordId rid, final int iRecordVersion, final byte[] iRecordContent, final AtomicInteger iDatabaseVersion) { if (iRecordType == ODocument.RECORD_TYPE) { // No need lock, is already inside a lock. Use database to read temporary objects too OStorageOperationResult<ORawBuffer> res = storage.readRecord(rid, null, false, false, null); final ODocument storedRecord = new ODocument(rid).fromStream(res.getResult().getBuffer()); ODocument newRecord = (ODocument) ORecordSaveThreadLocal.getLast(); if (newRecord == null || !newRecord.getIdentity().equals(rid)) newRecord = new ODocument(rid).fromStream(iRecordContent); storedRecord.merge(newRecord, true, true); iDatabaseVersion.set(Math.max(iDatabaseVersion.get(), iRecordVersion) + 1); return storedRecord.toStream(); } else // NO DOCUMENT, CANNOT MERGE SO RELY TO THE VERSION CHECK checkVersions(rid, iRecordVersion, iDatabaseVersion.get()); return null; }
final String config = OIOUtils.readFileAsString(new File(arg)); configuration.merge(new ODocument().fromJSON(config, "noMap"), true, true);
protected static OETLProcessor parseConfigAndParameters(String[] args) { final OCommandContext context = createDefaultContext(); ODocument configuration = new ODocument().fromJSON("{}"); for (final String arg : args) { if (arg.charAt(0) != '-') { try { final String config = OIOUtils.readFileAsString(new File(arg)); configuration.merge(new ODocument().fromJSON(config, "noMap"), true, true); // configuration = ; ODocument cfgGlobal = configuration.field("config"); if (cfgGlobal != null) { for (String f : cfgGlobal.fieldNames()) { context.setVariable(f, cfgGlobal.field(f)); } } } catch (IOException e) { throw new OConfigurationException("Error on loading config file: " + arg, e); } } } // override with args passes by command line for (final String arg : args) { if (arg.charAt(0) == '-') { final String[] parts = arg.substring(1).split("="); context.setVariable(parts[0], parts[1]); } } return new OETLProcessor().parse(configuration, context); }
doc.merge(json.toDocument(record, ctx), false, false); } else if (inputParameter != null) { Object val = inputParameter.getValue(ctx.getInputParameters()); if (val instanceof OElement) { doc.merge((ODocument) ((OElement) val).getRecord(), false, false); } else if (val instanceof Map) { doc.merge(new ODocument().fromMap((Map) val), false, false); } else { throw new OCommandExecutionException("Invalid value for UPDATE CONTENT: " + val); doc.merge(fieldsToPreserve, true, false);
} else if (content != null) { final ODocument doc = className != null ? new ODocument(className) : new ODocument(); doc.merge(content, true, false); saveRecord(doc); return prepareReturnItem(doc);
public static OrienteerETLProcessor parseConfigRecord(OETLTaskSession taskSession,String config){ final OCommandContext context = createDefaultContext(); ODocument configuration = new ODocument().fromJSON("{}"); configuration.merge(new ODocument().fromJSON(config, "noMap"), true, true); // configuration = ; ODocument cfgGlobal = configuration.field("config"); if (cfgGlobal != null) { for (String f : cfgGlobal.fieldNames()) { context.setVariable(f, cfgGlobal.field(f)); } } return (OrienteerETLProcessor) new OrienteerETLProcessor(taskSession).parse(configuration, context); }
private Object getValueAsRecord(ODocument iRecord, String iFieldValue, OType iType, String iOptions, String[] fields) { ORID rid = new ORecordId(OIOUtils.getStringContent(getFieldValue("@rid", fields))); boolean shouldReload = rid.isTemporary(); final ODocument recordInternal = (ODocument) fromString(iFieldValue, new ODocument(), null, iOptions, shouldReload); if (shouldBeDeserializedAsEmbedded(recordInternal, iType)) ODocumentInternal.addOwner(recordInternal, iRecord); else { ODatabaseDocument database = ODatabaseRecordThreadLocal.instance().getIfDefined(); if (rid.isPersistent() && database != null) { ODocument documentToMerge = database.load(rid); documentToMerge.merge(recordInternal, false, false); return documentToMerge; } } return recordInternal; }
newVertexDoc.merge(merge, true, false);
newVertexDoc.merge(merge, true, false);
/** * Execute the command and return the ODocument object created. */ public Object execute(final Map<Object, Object> iArgs) { if (clazz == null) throw new OCommandExecutionException("Cannot execute the command because it has not been parsed yet"); // CREATE VERTEX DOES NOT HAVE TO BE IN TX final OVertex vertex = getDatabase().newVertex(clazz); if (fields != null) // EVALUATE FIELDS for (final OPair<String, Object> f : fields) { if (f.getValue() instanceof OSQLFunctionRuntime) f.setValue(((OSQLFunctionRuntime) f.getValue()).getValue(vertex.getRecord(), null, context)); } OSQLHelper.bindParameters(vertex.getRecord(), fields, new OCommandParameters(iArgs), context); if (content != null) ((ODocument)vertex.getRecord()).merge(content, true, false); if (clusterName != null) vertex.save(clusterName); else vertex.save(); return vertex.getRecord(); }
((ODocument) result).merge((ODocument) input, true, false); log(Level.FINE, "%s: merged record %s with found record=%s", getName(), result, input); return result; ((ODocument) firstValue).merge((ODocument) ((OIdentifiable) input).getRecord(), true, false); log(Level.FINE, "%s: merged record %s with found record=%s", getName(), firstValue, input); return firstValue;
else { final Object o = OMultiValue.getFirstValue(result); ((ODocument) o).merge((ODocument) ((OIdentifiable) input).getRecord(), true, false); log(OETLProcessor.LOG_LEVELS.DEBUG, "merged record %s with found record=%s", result, input); return o;