@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 + "'"); }
protected static void checkType(final OClass iType) { if (iType == null) throw new IllegalArgumentException("Edge class is null"); if (((iType instanceof OImmutableClass) && !((OImmutableClass) iType).isEdgeType()) || !iType.isSubClassOf(CLASS_NAME)) throw new IllegalArgumentException("Type error. The class " + iType + " does not extend class '" + CLASS_NAME + "' and therefore cannot be considered an Edge"); }
protected static void checkType(final OClass iType) { if (iType == null) throw new IllegalArgumentException("Vertex class is null"); if (((iType instanceof OImmutableClass) && !((OImmutableClass) iType).isVertexType()) || !iType.isSubClassOf(CLASS_NAME)) throw new IllegalArgumentException("Type error. The class '" + iType + "' does not extend class '" + CLASS_NAME + "' and therefore cannot be considered a Vertex"); }
@Override public Collection<OClass> getAllSubclasses() { initBaseClasses(); final Set<OClass> set = new HashSet<OClass>(); set.addAll(getSubclasses()); for (OImmutableClass c : subclasses) set.addAll(c.getAllSubclasses()); return set; }
@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; }
@Override public boolean isSubClassOf(final OClass clazz) { if (clazz == null) return false; if (equals(clazz)) return true; final int s = superClasses.size(); for (int i = 0; i < s; ++i) { if (superClasses.get(i).isSubClassOf(clazz)) return true; } return false; }
@Override public OIdentifiable getGraphElementRecord(final Object iObject) { final ORecord rec = ((OIdentifiable) iObject).getRecord(); if (rec == null || !(rec instanceof ODocument)) return null; final ODocument value = (ODocument) rec; final OIdentifiable v; OImmutableClass immutableClass = ODocumentInternal.getImmutableSchemaClass(value); if (immutableClass.isVertexType()) { // DIRECT VERTEX v = value; } else if (immutableClass.isEdgeType()) { // EDGE if (vertex.settings.isUseVertexFieldsForEdgeLabels() || OrientEdge.isLabeled(OrientEdge.getRecordLabel(value), iLabels)) v = OrientEdge.getConnection(value, connection.getKey().opposite()); else v = null; } else throw new IllegalStateException("Invalid content found between connections: " + value); return v; }
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())); }
/** * 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); } } }
public static boolean onRecordBeforeCreate(final ODocument iDocument, ODatabaseDocumentInternal database) { final OImmutableClass cls = ODocumentInternal.getImmutableSchemaClass(database, iDocument); if (cls != null && cls.isRestricted()) { String fieldNames = cls.getCustom(OSecurityShared.ONCREATE_FIELD); if (fieldNames == null) fieldNames = ORestrictedOperation.ALLOW_ALL.getFieldName(); final String[] fields = fieldNames.split(","); String identityType = cls.getCustom(OSecurityShared.ONCREATE_IDENTITY_TYPE); if (identityType == null) identityType = "user"; } else throw new OConfigurationException( "Wrong custom field '" + OSecurityShared.ONCREATE_IDENTITY_TYPE + "' in class '" + cls.getName() + "' with value '" + identityType + "'. Supported ones are: 'user', 'role'");
public void getIndexedProperties(Collection<OProperty> indexedProperties) { for (OProperty p : properties.values()) if (areIndexed(p.getName())) indexedProperties.add(p); initSuperClasses(); for (OImmutableClass superClass : superClasses) { superClass.getIndexedProperties(indexedProperties); } }
@Override public boolean areIndexed(Collection<String> fields) { final OIndexManager indexManager = getDatabase().getMetadata().getIndexManager(); final boolean currentClassResult = indexManager.areIndexed(name, fields); initSuperClasses(); if (currentClassResult) return true; for (OImmutableClass superClass : superClasses) { if (superClass.areIndexed(fields)) return true; } return false; }
final OProperty prop = immutableClass.getProperty(fieldName); if (prop != null) { if (prop.getType() == OType.LINK) { } else if (immutableClass.isEdgeType() && ("out".equals(fieldName) || "in".equals(fieldName)) && (fieldValue instanceof List)) { List lst = (List) fieldValue;
+ "' 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");
/** * 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 getAllSuperClasses(Set<OClass> set) { set.addAll(superClasses); for (OImmutableClass superClass : superClasses) { superClass.getAllSuperClasses(set); } }
@Override public long count() { return count(true); }
@Override public boolean existsProperty(String propertyName) { boolean result = properties.containsKey(propertyName); if (result) return true; for (OImmutableClass superClass : superClasses) { result = superClass.existsProperty(propertyName); if (result) return true; } return false; }
@Override @Deprecated public Collection<OClass> getAllBaseClasses() { return getAllSubclasses(); }
@Override public boolean areIndexed(String... fields) { return areIndexed(Arrays.asList(fields)); }