/** * Creates a new instance in memory of the specified schema class. New instances are not persistent until {@link #save()} is * called. The database reference is taken from the thread local. * * @param iClass OClass instance */ public ODocument(final OClass iClass) { this(iClass != null ? iClass.getName() : null); }
@Override public OEdge addEdge(OVertex to, OClass type) { String className = "E"; if (type != null) { className = type.getName(); } return addEdge(to, className); }
public static OClass addClusters(final OClass cls, final int iClusters) { final String clusterBase = cls.getName().toLowerCase(Locale.ENGLISH) + "_"; for (int i = 0; i < iClusters; ++i) { cls.addCluster(clusterBase + i); } return cls; }
@Override public Iterable<OEdge> getEdges(ODirection direction, OClass... type) { List<String> types = new ArrayList<>(); if (type != null) { for (OClass t : type) { types.add(t.getName()); } } return getEdges(direction, types.toArray(new String[] {})); }
/** * @param oClass subject {@link OClass} for security check * @param action action to be secured for * @param permissions required permissions for access {@link OClass} * @return array of {@link RequiredOrientResource} for rights setup emulation */ public static RequiredOrientResource[] requireOClass(final OClass oClass, final Action action, final OrientPermission... permissions) { return oClass!=null?requireOClass(oClass.getName(), action, permissions):new RequiredOrientResource[0]; } /**
/** * Check that all required permissions present for specified {@link OClass} * @param oClass {@link OClass} to check security rights for * @param permissions {@link OrientPermission}s to check * @return true of all permissions are allowable */ public static boolean isAllowed(OClass oClass, OrientPermission... permissions) { return isAllowed(ORule.ResourceGeneric.CLASS, oClass.getName(), permissions); }
private void checkNotIndexed(OClass oClass) { Set<OIndex<?>> indexes = oClass.getIndexes(); if (indexes != null && indexes.size() > 0) { throw new OCommandExecutionException("Cannot rename class '" + oClass.getName() + "' because it has indexes defined on it. Drop indexes before or use UNSAFE (at your won risk)"); } }
public int compareTo(final OClass o) { acquireSchemaReadLock(); try { return name.compareTo(o.getName()); } finally { releaseSchemaReadLock(); } }
public Object evaluate(OResult iCurrentRecord, OCommandContext ctx) { if (name.equalsIgnoreCase("@rid")) { return iCurrentRecord.getIdentity().orElse(null); } else if (name.equalsIgnoreCase("@class")) { return iCurrentRecord.getElement().flatMap(r -> r.getSchemaType()).map(clazz -> clazz.getName()).orElse(null); } else if (name.equalsIgnoreCase("@version")) { return iCurrentRecord.getRecord().map(r -> r.getVersion()).orElse(null); } return null; }
@Override public OEdge newEdge(OVertex from, OVertex to, OClass type) { if (type == null) { return newEdge(from, to, "E"); } return newEdge(from, to, type.getName()); }
protected void createProperty(final OClass cls, final String f, final Object fValue) { if (fValue != null) { final OType fType = OType.getTypeByClass(fValue.getClass()); try { cls.createProperty(f, fType); } catch (OSchemaException e) { } log(Level.FINE, "created property [%s.%s] of type [%s]", cls.getName(), f, fType); } }
public <T> T getProperty(final String key) { if (key == null) return null; if (key.equals("_class")) return (T) getRecord().getSchemaClass().getName(); else if (key.equals("_version")) return (T) new Integer(getRecord().getVersion()); else if (key.equals("_rid")) return (T) rawElement.getIdentity().toString(); return getRecord().field(key); }
private ODocument createDocumentFromMap(OClass embeddedType, Map<String, Object> o) { final ODocument doc = new ODocument(); if (embeddedType != null) doc.setClassName(embeddedType.getName()); doc.fromMap(o); return doc; }
protected OClass serializeClass(final ODocument document, final BytesContainer bytes) { final OClass clazz = ODocumentInternal.getImmutableSchemaClass(document); if (clazz != null) writeString(bytes, clazz.getName()); else writeEmptyString(bytes); return clazz; }
@Override public OProperty createProperty(final String iPropertyName, final OType iType, final OClass iLinkedClass) { return graph.executeOutsideTx(new OCallable<OProperty, OrientBaseGraph>() { @Override public OProperty call(final OrientBaseGraph g) { return OrientElementType.super.createProperty(iPropertyName, iType, iLinkedClass); } }, "create ", getTypeName(), " property '", iPropertyName, "' as type '", iType.toString(), "' linked class '", iLinkedClass.getName(), "'"); }
public ODocumentLinksQueryDataProvider(IModel<ODocument> docModel, OProperty property) { super("select expand("+property.getName()+") from "+property.getOwnerClass().getName()+" where @rid = :doc"); setParameter("doc", docModel); } }
@Override public String toJSON() { if (element != null) { return element.toJSON(); } else { return "{\"out\":\"" + vOut.getIdentity() + "\", \"in\":\"" + vIn.getIdentity() + "\", \"@class\":\"" + OStringSerializerHelper.encode(lightweightEdgeType.getName()) + "\"}"; } }
@Override protected OIndex<?> loadInstance() { OClass oClass = classModel!=null?classModel.getObject():null; OIndexManager indexManager = OrientDbWebSession.get().getDatabase().getMetadata().getIndexManager(); return oClass!=null? indexManager.getClassIndex(oClass.getName(), indexName):indexManager.getIndex(indexName); }
private void dropClassIndexes(ODatabaseDocumentInternal database, final OClass cls) { final OIndexManager indexManager = database.getMetadata().getIndexManager(); for (final OIndex<?> index : indexManager.getClassIndexes(cls.getName())) indexManager.dropIndex(index.getName()); }
protected void checkParametersConflict(final OClass baseClass) { final Collection<OProperty> baseClassProperties = baseClass.properties(); for (OProperty property : baseClassProperties) { OProperty thisProperty = getProperty(property.getName()); if (thisProperty != null && !thisProperty.getType().equals(property.getType())) { throw new OSchemaException( "Cannot add base class '" + baseClass.getName() + "', because of property conflict: '" + thisProperty + "' vs '" + property + "'"); } } }