Optimize import of ridbags (import database)
@@ -668,7 +668,7 @@ public class ORecordSerializerJSON extends ORecordSerializerStringAbstract {
if (iType == OType.LINKBAG) {
final ORidBag bag = new ORidBag();
- parseCollection(iRecord, iFieldValue, iType, OType.LINK, iFieldTypes, iNoMap, iOptions, new CollectionItemVisitor() {
+ parseRidbag(iRecord, iFieldValue, iType, OType.LINK, iFieldTypes, iNoMap, iOptions, new CollectionItemVisitor() {
@Override
public void visitItem(Object item) {
bag.add((OIdentifiable) item);
@@ -717,6 +717,31 @@ public class ORecordSerializerJSON extends ORecordSerializerStringAbstract {
return collection;
}
+ private void parseRidbag(ODocument iRecord, String iFieldValue, OType iType, OType iLinkedType,
+ Map<String, Character> iFieldTypes, boolean iNoMap, String iOptions, CollectionItemVisitor visitor) {
+ if (!iFieldValue.isEmpty()) {
+ int lastCommaPosition = -1;
+ for (int i = 1; i < iFieldValue.length(); i++) {
+ if (iFieldValue.charAt(i) == ',' || i == iFieldValue.length() - 1) {
+ String item = (i == iFieldValue.length() - 1) ? iFieldValue.substring(lastCommaPosition + 1) : iFieldValue.substring(lastCommaPosition + 1, i);
+ lastCommaPosition = i;
+ final String itemValue = item.trim();
+ if (itemValue.length() == 0)
+ continue;
+
+ final Object collectionItem = getValue(iRecord, null, itemValue, OIOUtils.getStringContent(itemValue), iLinkedType, null,
+ iFieldTypes, iNoMap, iOptions);
+
+ // TODO redundant in some cases, owner is already added by getValue in some cases
+ if (shouldBeDeserializedAsEmbedded(collectionItem, iType))
+ ODocumentInternal.addOwner((ODocument) collectionItem, iRecord);
+
+ visitor.visitItem(collectionItem);
+ }
+ }
+ }
+ }
+
private void parseCollection(ODocument iRecord, String iFieldValue, OType iType, OType iLinkedType,
Map<String, Character> iFieldTypes, boolean iNoMap, String iOptions, CollectionItemVisitor visitor) {
if (!iFieldValue.isEmpty()) {
