@Override public boolean isSubClassOf(final String iClassName) { if (iClassName == null) return false; if (iClassName.equalsIgnoreCase(getName()) || iClassName.equalsIgnoreCase(getShortName())) return true; final int s = superClasses.size(); for (int i = 0; i < s; ++i) { if (superClasses.get(i).isSubClassOf(iClassName)) return true; } return false; }
public OImmutableSchema(OSchemaShared schemaShared, ODatabaseDocumentInternal database) { assert schemaShared.getDocument().getInternalStatus() == ORecordElement.STATUS.LOADED; assert database.getSharedContext().getIndexManager().getDocument().getInternalStatus() == ORecordElement.STATUS.LOADED; version = schemaShared.getVersion(); identity = schemaShared.getIdentity(); clusterSelectionFactory = schemaShared.getClusterSelectionFactory(); clustersToClasses = new HashMap<Integer, OClass>(schemaShared.getClasses(database).size() * 3); classes = new HashMap<String, OClass>(schemaShared.getClasses(database).size()); for (OClass oClass : schemaShared.getClasses(database)) { final OImmutableClass immutableClass = new OImmutableClass(oClass, this); classes.put(immutableClass.getName().toLowerCase(Locale.ENGLISH), immutableClass); if (immutableClass.getShortName() != null) classes.put(immutableClass.getShortName().toLowerCase(Locale.ENGLISH), immutableClass); for (int clusterId : immutableClass.getClusterIds()) clustersToClasses.put(clusterId, immutableClass); } properties = new ArrayList<OGlobalProperty>(); for (OGlobalProperty globalProperty : schemaShared.getGlobalProperties()) properties.add(globalProperty); for (OClass cl : classes.values()) { ((OImmutableClass) cl).init(); } this.blogClusters = Collections.unmodifiableSet(new HashSet<Integer>(schemaShared.getBlobClusters())); }
/** * 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); }
} else throw new OConfigurationException( "Wrong custom field '" + OSecurityShared.ONCREATE_IDENTITY_TYPE + "' in class '" + cls.getName() + "' with value '" + identityType + "'. Supported ones are: 'user', 'role'");
@Override public Object get(ATTRIBUTES iAttribute) { if (iAttribute == null) throw new IllegalArgumentException("attribute is null"); switch (iAttribute) { case NAME: return getName(); case SHORTNAME: return getShortName(); case SUPERCLASS: return getSuperClass(); case SUPERCLASSES: return getSuperClasses(); case OVERSIZE: return getOverSize(); case STRICTMODE: return isStrictMode(); case ABSTRACT: return isAbstract(); case CLUSTERSELECTION: return getClusterSelection(); case CUSTOM: return getCustomInternal(); case DESCRIPTION: return getDescription(); } throw new IllegalArgumentException("Cannot find attribute '" + iAttribute + "'"); }
return (T) ODocumentInternal.getImmutableSchemaClass(getRecord()).getName(); else if (key.equals("_version")) return (T) new Integer(getRecord().getVersion());
/** * 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); } } }
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");