public Object call(ODatabaseDocumentInternal database) { iCurrent.checkForFields(); return null; } });
public Object call(ODatabaseDocumentInternal database) { iOther.checkForFields(); return null; } });
protected Set<Entry<String, ODocumentEntry>> getRawEntries() { checkForFields(); return _fields == null ? new HashSet<>() : _fields.entrySet(); }
public void setLazyLoad(final boolean iLazyLoad) { this._lazyLoad = iLazyLoad; checkForFields(); if (_fields != null) { // PROPAGATE LAZINESS TO THE FIELDS for (Entry<String, ODocumentEntry> field : _fields.entrySet()) { if (field.getValue().value instanceof ORecordLazyMultiValue) ((ORecordLazyMultiValue) field.getValue().value).setAutoConvertToRecord(false); } } }
/** * Returns the number of fields in memory. */ public int fields() { checkForLoading(); checkForFields(); return _fieldSize; }
/** * Returns the array of field values. */ public Object[] fieldValues() { checkForLoading(); checkForFields(); Object[] res = new Object[_fields.size()]; int i = 0; for (ODocumentEntry entry : _fields.values()) { res[i++] = entry.value; } return res; }
public boolean isEmpty() { checkForLoading(); checkForFields(); return _fields == null || _fields.isEmpty(); }
/** * Returns the forced field type if any. * * @param iFieldName name of field to check */ public OType fieldType(final String iFieldName) { checkForLoading(); checkForFields(iFieldName); ODocumentEntry entry = _fields.get(iFieldName); if (entry != null) return entry.type; return null; }
/** * Checks if a field exists. * * @return True if exists, otherwise false. */ public boolean containsField(final String iFieldName) { if (iFieldName == null) return false; checkForLoading(); checkForFields(iFieldName); ODocumentEntry entry = _fields.get(iFieldName); return entry != null && entry.exist(); }
@Override public ODocument reload(final String fetchPlan, final boolean ignoreCache) { super.reload(fetchPlan, ignoreCache); if (!_lazyLoad) { checkForLoading(); checkForFields(); } return this; }
@Override public Set<String> getPropertyNames() { checkForLoading(); if (_status == ORecordElement.STATUS.LOADED && _source != null && ODatabaseRecordThreadLocal.instance().isDefined() && !ODatabaseRecordThreadLocal.instance().get().isClosed()) { // DESERIALIZE FIELD NAMES ONLY (SUPPORTED ONLY BY BINARY SERIALIZER) final String[] fieldNames = _recordFormat.getFieldNamesRoot(this, _source); if (fieldNames != null) { Set<String> result = new HashSet<>(); Collections.addAll(result, fieldNames); return result; } } checkForFields(); if (_fields == null || _fields.size() == 0) return Collections.EMPTY_SET; return _fields.entrySet().stream().filter(s -> s.getValue().exist()).map(Entry::getKey).collect(Collectors.toSet()); }
public <RET> RET rawField(final String iFieldName) { if (iFieldName == null || iFieldName.length() == 0) return null; checkForLoading(); if (!checkForFields(iFieldName)) // NO FIELDS return null; // OPTIMIZATION if (!_allowChainedAccess || (iFieldName.charAt(0) != '@' && OStringSerializerHelper.indexOf(iFieldName, 0, '.', '[') == -1)) { ODocumentEntry entry = _fields.get(iFieldName); if (entry != null && entry.exist()) return (RET) entry.value; else return null; } // NOT FOUND, PARSE THE FIELD NAME return (RET) ODocumentHelper.getFieldValue(this, iFieldName); }
/** * Returns the set of field names. */ public String[] fieldNames() { checkForLoading(); if (_status == ORecordElement.STATUS.LOADED && _source != null && ODatabaseRecordThreadLocal.instance().isDefined() && !ODatabaseRecordThreadLocal.instance().get().isClosed()) { // DESERIALIZE FIELD NAMES ONLY (SUPPORTED ONLY BY BINARY SERIALIZER) final String[] fieldNames = _recordFormat.getFieldNamesRoot(this, _source); if (fieldNames != null) return fieldNames; } checkForFields(); if (_fields == null || _fields.size() == 0) return EMPTY_STRINGS; final List<String> names = new ArrayList<>(_fields.size()); for (Entry<String, ODocumentEntry> entry : _fields.entrySet()) { if (entry.getValue().exist()) names.add(entry.getKey()); } return names.toArray(new String[names.size()]); }
@Override public void setDirtyNoChanged() { if (_owners != null) { // PROPAGATES TO THE OWNER ORecordElement e; for (WeakReference<ORecordElement> o : _owners) { e = o.get(); if (e != null) e.setDirtyNoChanged(); } } getDirtyManager().setDirty(this); // THIS IS IMPORTANT TO BE SURE THAT FIELDS ARE LOADED BEFORE IT'S TOO LATE AND THE RECORD _SOURCE IS NULL checkForFields(); super.setDirtyNoChanged(); }
/** * Sets the field type. This overrides the schema property settings if any. * * @param iFieldName Field name * @param iFieldType Type to set between OType enumeration values */ public ODocument setFieldType(final String iFieldName, final OType iFieldType) { checkForLoading(); checkForFields(iFieldName); if (iFieldType != null) { if (_fields == null) _fields = _ordered ? new LinkedHashMap<>() : new HashMap<>(); // SET THE FORCED TYPE ODocumentEntry entry = getOrCreate(iFieldName); if (entry.type != iFieldType) field(iFieldName, field(iFieldName), iFieldType); } else if (_fields != null) { // REMOVE THE FIELD TYPE ODocumentEntry entry = _fields.get(iFieldName); if (entry != null) // EMPTY: OPTIMIZE IT BY REMOVING THE ENTIRE MAP entry.type = null; } return this; }
@Override public ODocument fromStream(final byte[] iRecordBuffer) { removeAllCollectionChangeListeners(); _fields = null; _fieldSize = 0; _contentChanged = false; _schema = null; fetchSchemaIfCan(); super.fromStream(iRecordBuffer); if (!_lazyLoad) { checkForLoading(); checkForFields(); } return this; }
/** * Merge current document with the document passed as parameter. If the field already exists then the conflicts are managed based * on the value of the parameter 'iUpdateOnlyMode'. * * @param iOther Other ODocument instance to merge * @param iUpdateOnlyMode if true, the other document properties will always be added or overwritten. If * false, the missed properties in the "other" document will be removed by original * document * @param iMergeSingleItemsOfMultiValueFields If true, merges single items of multi field fields (collections, maps, arrays, etc) * * @return */ public ODocument merge(final ODocument iOther, boolean iUpdateOnlyMode, boolean iMergeSingleItemsOfMultiValueFields) { iOther.checkForLoading(); iOther.checkForFields(); if (_className == null && iOther.getImmutableSchemaClass() != null) _className = iOther.getImmutableSchemaClass().getName(); return mergeMap(iOther._fields, iUpdateOnlyMode, iMergeSingleItemsOfMultiValueFields); }
private void fetchClassName() { final ODatabaseDocumentInternal database = getDatabaseIfDefinedInternal(); if (database != null && database.getStorageVersions() != null) { if (_recordId.getClusterId() < 0) { checkForLoading(); checkForFields(ODocumentHelper.ATTRIBUTE_CLASS); } else { final OSchema schema = database.getMetadata().getImmutableSchemaSnapshot(); if (schema != null) { OClass _clazz = schema.getClassByClusterId(_recordId.getClusterId()); if (_clazz != null) _className = _clazz.getName(); } } } else { // CLASS NOT FOUND: CHECK IF NEED LOADING AND UNMARSHALLING checkForLoading(); checkForFields(ODocumentHelper.ATTRIBUTE_CLASS); } }
public <RET> RET removeProperty(final String iFieldName) { checkForLoading(); checkForFields();
/** * Validates the record following the declared constraints defined in schema such as mandatory, notNull, min, max, regexp, etc. If * the schema is not defined for the current class or there are not constraints then the validation is ignored. * * @throws OValidationException if the document breaks some validation constraints defined in the schema * @see OProperty */ public void validate() throws OValidationException { checkForLoading(); checkForFields(); autoConvertValues(); if (ODatabaseRecordThreadLocal.instance().isDefined() && !getDatabase().isValidationEnabled()) return; final OImmutableClass immutableSchemaClass = getImmutableSchemaClass(); if (immutableSchemaClass != null) { if (immutableSchemaClass.isStrictMode()) { // CHECK IF ALL FIELDS ARE DEFINED for (String f : fieldNames()) { if (immutableSchemaClass.getProperty(f) == null) throw new OValidationException( "Found additional field '" + f + "'. It cannot be added because the schema class '" + immutableSchemaClass.getName() + "' is defined as STRICT"); } } for (OProperty p : immutableSchemaClass.properties()) { validateField(this, (OImmutableProperty) p); } } }