Merge OrientDB:将什么合并到什么?
我对OrientDB的API文档有点困惑。 气味记录法说: 将当前文档与作为参数传递的文档合并。如果该字段已存在,则将根据参数“iUpdateOnlyMode”的值管理冲突 参数: iOther-要合并的其他OdoDocument实例 iUpdateOnlyMode-如果为true,则将始终添加或覆盖其他文档属性。如果为false,则原始文档将删除其他文档中缺少的属性 iMergeSingleItemsOfMultiValueFields-如果为true,则合并多字段集合、映射、数组等的单个项 从这一点上,我不知道什么在什么时候融入了什么。这就是改进的状态,因为有两种方法的描述更不清楚Merge OrientDB:将什么合并到什么?,merge,orientdb,Merge,Orientdb,我对OrientDB的API文档有点困惑。 气味记录法说: 将当前文档与作为参数传递的文档合并。如果该字段已存在,则将根据参数“iUpdateOnlyMode”的值管理冲突 参数: iOther-要合并的其他OdoDocument实例 iUpdateOnlyMode-如果为true,则将始终添加或覆盖其他文档属性。如果为false,则原始文档将删除其他文档中缺少的属性 iMergeSingleItemsOfMultiValueFields-如果为true,则合并多字段集合、映射、数组等的单个项
有人对什么合并成什么有正常的解释吗?也许Ron Kittle可能知道?我做了一些测试,似乎API的名称有点奇怪或记录错误 我希望doc1.mergedoc2将doc2合并到doc1中。因为您通常正在编辑doc1,并且可以连续合并多个内容,如下所示:
doc1.merge(partialDocA);
doc1.merge(partialDocB);
doc1.merge(partialDocC);
partialDocA.merge(doc1, true, false);
partialDocB.merge(doc1, true, false);
partialDocC.merge(doc1, true, false);
public ODocument mergeDocument(Map<String, 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 RuntimeException("No document with sourceUri '"+sourceUri+"'.");
// Update it from the given map.
ODocument incomingDoc = new ODocument(docType);
incomingDoc.fromMap(incomingDocMap);
//ODocument merged = incomingDoc.merge(results.get(0), true, false);
ODocument merged = results.get(0).merge(incomingDoc, true, false);
//merged.save(); /// Duplicated key
return merged;
}
从merge的文档中可以看出,OrientDB的功能如下:
doc1.merge(partialDocA);
doc1.merge(partialDocB);
doc1.merge(partialDocC);
partialDocA.merge(doc1, true, false);
partialDocB.merge(doc1, true, false);
partialDocC.merge(doc1, true, false);
public ODocument mergeDocument(Map<String, 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 RuntimeException("No document with sourceUri '"+sourceUri+"'.");
// Update it from the given map.
ODocument incomingDoc = new ODocument(docType);
incomingDoc.fromMap(incomingDocMap);
//ODocument merged = incomingDoc.merge(results.get(0), true, false);
ODocument merged = results.get(0).merge(incomingDoc, true, false);
//merged.save(); /// Duplicated key
return merged;
}
其中true使merge不能删除doc1的其余部分。如果是false,它最终将成为partialdoc。那是什么样的合并?这叫做替换,不是合并
但在我进行了一些测试之后,第一个案例似乎是正确的
如果这是真的,它应该被命名为mergeFromtargetDoc,而不是merge,一些带有多字段的东西
因此,除非我忽略了什么,否则从地图保存文档如下所示:
doc1.merge(partialDocA);
doc1.merge(partialDocB);
doc1.merge(partialDocC);
partialDocA.merge(doc1, true, false);
partialDocB.merge(doc1, true, false);
partialDocC.merge(doc1, true, false);
public ODocument mergeDocument(Map<String, 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 RuntimeException("No document with sourceUri '"+sourceUri+"'.");
// Update it from the given map.
ODocument incomingDoc = new ODocument(docType);
incomingDoc.fromMap(incomingDocMap);
//ODocument merged = incomingDoc.merge(results.get(0), true, false);
ODocument merged = results.get(0).merge(incomingDoc, true, false);
//merged.save(); /// Duplicated key
return merged;
}
该方法甚至没有填充@return,因此我不知道是否可以继续使用原始的OdoDocument
很好,OrientDB。这在OrientDB 2.2.0中有效吗?