public static OImmutableClass getImmutableSchemaClass(final ODatabaseDocumentInternal database, final ODocument oDocument) { if (oDocument == null) { return null; } return oDocument.getImmutableSchemaClass(database); }
public static OImmutableClass getImmutableSchemaClass(final ODocument oDocument) { if (oDocument == null) { return null; } return oDocument.getImmutableSchemaClass(); }
protected OImmutableClass getImmutableSchemaClass() { return getImmutableSchemaClass(null); }
private OType deriveFieldType(String iFieldName, ODocumentEntry entry, OType[] iFieldType) { OType fieldType; if (iFieldType != null && iFieldType.length == 1) { entry.type = iFieldType[0]; fieldType = iFieldType[0]; } else fieldType = null; OClass _clazz = getImmutableSchemaClass(); if (_clazz != null) { // SCHEMA-FULL? final OProperty prop = _clazz.getProperty(iFieldName); if (prop != null) { entry.property = prop; fieldType = prop.getType(); if (fieldType != OType.ANY) entry.type = fieldType; } } return fieldType; }
/** * 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); }
protected void autoConvertValues() { OClass clazz = getImmutableSchemaClass(); if (clazz != null) { for (OProperty prop : clazz.properties()) {
OClass _clazz = getImmutableSchemaClass(); if (_clazz != null) { final OProperty prop = _clazz.getProperty(fieldEntry.getKey());
if (doc.getImmutableSchemaClass() != null && !schemaClass.isSuperClassOf(doc.getImmutableSchemaClass())) throw new OValidationException( "The field '" + p.getFullName() + "' has been declared as " + p.getType() + " of type '" + schemaClass.getName() + "' but the value is the document " + linkedRecord.getIdentity() + " of class '" + doc .getImmutableSchemaClass() + "'");
if (doc.getImmutableSchemaClass() == null) throw new OValidationException( "The field '" + p.getFullName() + "' has been declared as " + p.getType() + " with linked class '" + embeddedClass + "' but the record has no class"); if (!(doc.getImmutableSchemaClass().isSubClassOf(embeddedClass))) throw new OValidationException( "The field '" + p.getFullName() + "' has been declared as " + p.getType() + " with linked class '" + embeddedClass + "' but the record is of class '" + doc.getImmutableSchemaClass().getName() + "' that is not a subclass of that");
/** * 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); } } }