@Override public OClass getClass(Class<?> iClass) { if (iClass == null) return null; return getClass(iClass.getSimpleName()); }
public OImmutableSchema makeSnapshot(ODatabaseDocumentInternal database) { if (snapshot == null) { // Is null only in the case that is asked while the schema is created // all the other cases are already protected by a write lock acquireSchemaReadLock(); try { if (snapshot == null) snapshot = new OImmutableSchema(this, database); } finally { releaseSchemaReadLock(); } } return snapshot; }
public synchronized void load(final ODatabaseDocumentInternal db) { sequences.clear(); if (db.getMetadata().getImmutableSchemaSnapshot().existsClass(OSequence.CLASS_NAME)) { try (final OResultSet result = db.query("SELECT FROM " + OSequence.CLASS_NAME)) { while (result.hasNext()) { OResult res = result.next(); final OSequence sequence = OSequenceHelper.createSequence((ODocument) res.getElement().get()); sequences.put(sequence.getName().toUpperCase(Locale.ENGLISH), sequence); } } } }
protected OGlobalProperty getGlobalPropertyById(int id) { if (_schema == null) { OMetadataInternal metadata = getDatabase().getMetadata(); _schema = metadata.getImmutableSchemaSnapshot(); } OGlobalProperty prop = _schema.getGlobalPropertyById(id); if (prop == null) { ODatabaseDocument db = getDatabase(); if (db == null || db.isClosed()) throw new ODatabaseException( "Cannot unmarshall the document because no database is active, use detach for use the document outside the database session scope"); OMetadataInternal metadata = (OMetadataInternal) db.getMetadata(); if (metadata.getImmutableSchemaSnapshot() != null) metadata.clearThreadLocalSchemaSnapshot(); metadata.reload(); metadata.makeThreadLocalSchemaSnapshot(); _schema = metadata.getImmutableSchemaSnapshot(); prop = _schema.getGlobalPropertyById(id); } return prop; }
protected void checkRecordClass(final OClass recordClass, final String iClusterName, final ORecordId rid) { final OClass clusterIdClass = metadata.getImmutableSchemaSnapshot().getClassByClusterId(rid.getClusterId()); if (recordClass == null && clusterIdClass != null || clusterIdClass == null && recordClass != null || (recordClass != null && !recordClass.equals(clusterIdClass))) throw new IllegalArgumentException( "Record saved into cluster '" + iClusterName + "' should be saved with class '" + clusterIdClass + "' but has been created with class '" + recordClass + "'"); }
@Override public Collection<OClass> getClasses() { getDatabase().checkSecurity(ORule.ResourceGeneric.SCHEMA, ORole.PERMISSION_READ); return new HashSet<OClass>(classes.values()); }
public void checkForClusterPermissions(final String iClusterName) { // CHECK FOR ORESTRICTED final Set<OClass> classes = getMetadata().getImmutableSchemaSnapshot().getClassesRelyOnCluster(iClusterName); for (OClass c : classes) { if (c.isSubClassOf(OSecurityShared.RESTRICTED_CLASSNAME)) throw new OSecurityException( "Class '" + c.getName() + "' cannot be truncated because has record level security enabled (extends '" + OSecurityShared.RESTRICTED_CLASSNAME + "')"); } }
final List<OClass> classes = new ArrayList<OClass>(currentDatabase.getMetadata().getImmutableSchemaSnapshot().getClasses()); Collections.sort(classes, new Comparator<OClass>() { public int compare(OClass o1, OClass o2) {
private Triple<Signal, OBinaryField, Integer> processPropertyDeserializeField(int len, final OImmutableSchema _schema, final String iFieldName, final OClass iClass, final BytesContainer bytes, int cumulativeLength, int headerStart, int headerLength) { final int id = (len * -1) - 1; final OGlobalProperty prop = _schema.getGlobalPropertyById(id); final int fieldLength = OVarIntSerializer.readAsInteger(bytes); final OType type; type = getPropertyTypeFromStream(prop, bytes); if (!iFieldName.equals(prop.getName())) { return new Triple<>(Signal.NO_ACTION, null, cumulativeLength + fieldLength); } int valuePos = headerStart + headerLength + cumulativeLength; if (fieldLength == 0 || valuePos == 0 || !getComparator().isBinaryComparable(type)) return new Triple<>(Signal.RETURN_VALUE, null, cumulativeLength + fieldLength); bytes.offset = valuePos; final OProperty classProp = iClass.getProperty(iFieldName); return new Triple<>(Signal.RETURN_VALUE, new OBinaryField(iFieldName, type, bytes, classProp != null ? classProp.getCollate() : null), cumulativeLength + fieldLength); }
@Override public boolean isClusterEdge(int cluster) { OClass clazz = getMetadata().getImmutableSchemaSnapshot().getClassByClusterId(cluster); if (clazz != null && clazz.isEdgeType()) return true; return false; }
@Override public Set<OClass> getClassesRelyOnCluster(String clusterName) { getDatabase().checkSecurity(ORule.ResourceGeneric.SCHEMA, ORole.PERMISSION_READ); final int clusterId = getDatabase().getClusterIdByName(clusterName); final Set<OClass> result = new HashSet<OClass>(); for (OClass c : classes.values()) { if (OArrays.contains(c.getPolymorphicClusterIds(), clusterId)) result.add(c); } return result; }
private void initBaseClasses() { if (subclasses == null) { final List<OImmutableClass> result = new ArrayList<OImmutableClass>(baseClassesNames.size()); for (String clsName : baseClassesNames) result.add((OImmutableClass) schema.getClass(clsName)); subclasses = result; } }
prop = schema.getGlobalPropertyById(id); fieldLength = OVarIntSerializer.readAsInteger(bytes); debugProperty.valuePos = headerPos + headerLength + cumulativeLength;
@Override public boolean isClusterVertex(int cluster) { OClass clazz = getMetadata().getImmutableSchemaSnapshot().getClassByClusterId(cluster); if (clazz != null && clazz.isVertexType()) return true; return false; } }
public void forceSnapshot(ODatabaseDocumentInternal database) { acquireSchemaReadLock(); try { if (document.getInternalStatus() == ORecordElement.STATUS.LOADED) { snapshot = new OImmutableSchema(this, database); } } finally { releaseSchemaReadLock(); } }
public void load(ODatabaseDocumentInternal db) { // COPY CALLBACK IN RAM final Map<String, OCallable<Object, Map<Object, Object>>> callbacks = new HashMap<String, OCallable<Object, Map<Object, Object>>>(); for (Map.Entry<String, OFunction> entry : functions.entrySet()) { if (entry.getValue().getCallback() != null) callbacks.put(entry.getKey(), entry.getValue().getCallback()); } functions.clear(); // LOAD ALL THE FUNCTIONS IN MEMORY if (db.getMetadata().getImmutableSchemaSnapshot().existsClass("OFunction")) { try(OResultSet result = db.query("select from OFunction order by name")) { while (result.hasNext()) { OResult res = result.next(); ODocument d = (ODocument) res.getElement().get(); //skip the function records which do not contain real data if (d.fields() == 0) continue; final OFunction f = new OFunction(d); // RESTORE CALLBACK IF ANY f.setCallback(callbacks.get(f.getName())); functions.put(d.field("name").toString().toUpperCase(Locale.ENGLISH), f); } } } }
private void initSuperClasses() { if (superClassesNames != null && superClassesNames.size() != superClasses.size()) { superClasses.clear(); for (String superClassName : superClassesNames) { OImmutableClass superClass = (OImmutableClass) schema.getClass(superClassName); superClass.init(); superClasses.add(superClass); } } }
prop = schema.getGlobalPropertyById(id); valuePos = readInteger(bytes); debugProperty.valuePos = valuePos;
private boolean canScanStorageCluster(final int[] clusterIds) { final ODatabaseDocumentInternal db = getDatabase(); if (clusterIds != null && request.isIdempotent() && !db.getTransaction().isActive()) { final OImmutableSchema schema = ((OMetadataInternal) db.getMetadata()).getImmutableSchemaSnapshot(); for (int clusterId : clusterIds) { final OImmutableClass cls = (OImmutableClass) schema.getClassByClusterId(clusterId); if (cls != null) { if (cls.isRestricted() || cls.isOuser() || cls.isOrole()) return false; } } return true; } return false; }
public void create(final ODatabaseDocumentInternal database) { rwSpinLock.acquireWriteLock(); try { super.save(OMetadataDefault.CLUSTER_INTERNAL_NAME); database.getStorage().setSchemaRecordId(document.getIdentity().toString()); snapshot = new OImmutableSchema(this, database); } finally { rwSpinLock.releaseWriteLock(); } }