Package com.orientechnologies.orient.core.metadata.schema

Examples of com.orientechnologies.orient.core.metadata.schema.OClass


    final int[] clusterIds;

    compiledFilter.bindParameters(iArgs);

    if (compiledFilter.getTargetClasses() != null) {
      OClass cls = compiledFilter.getTargetClasses().keySet().iterator().next();

      database.checkSecurity(ODatabaseSecurityResources.CLASS, ORole.PERMISSION_READ, cls.getName());

      clusterIds = cls.getPolymorphicClusterIds();

      // CHECK PERMISSION TO ACCESS TO ALL THE CONFIGURED CLUSTERS
      for (int clusterId : clusterIds)
        database.checkSecurity(ODatabaseSecurityResources.CLUSTER, ORole.PERMISSION_READ, database.getClusterNameById(clusterId),
            clusterId);
View Full Code Here


    if (iClassName.equals(OGraphVertex.class.getSimpleName()))
      return new OGraphVertex(this);
    else if (iClassName.equals(OGraphEdge.class.getSimpleName()))
      return new OGraphEdge(this);

    OClass cls = getMetadata().getSchema().getClass(iClassName);
    if (cls != null) {
      cls = cls.getSuperClass();
      while (cls != null) {
        if (cls.getName().equals(OGraphVertex.class.getSimpleName()))
          return new OGraphVertex(this, iClassName);
        else if (cls.getName().equals(OGraphEdge.class.getSimpleName()))
          return new OGraphEdge(this, iClassName);

        cls = cls.getSuperClass();
      }
    }

    throw new OGraphException("Unrecognized class: " + iClassName);
  }
View Full Code Here

    registerPojo(iVertex, iVertex.getDocument());
    return iVertex;
  }

  private void checkForGraphSchema() {
    OClass vertex = underlying.getMetadata().getSchema().getClass(OGraphDatabase.VERTEX_CLASS_NAME);
    OClass edge = underlying.getMetadata().getSchema().getClass(OGraphDatabase.EDGE_CLASS_NAME);

    if (vertex == null) {
      // CREATE THE META MODEL USING THE ORIENT SCHEMA
      vertex = underlying.getMetadata().getSchema()
          .createClass(OGraphDatabase.VERTEX_CLASS_NAME, underlying.addPhysicalCluster(OGraphDatabase.VERTEX_CLASS_NAME));
      edge = underlying.getMetadata().getSchema()
          .createClass(OGraphDatabase.EDGE_CLASS_NAME, underlying.addPhysicalCluster(OGraphDatabase.EDGE_CLASS_NAME));

      edge.createProperty(OGraphDatabase.EDGE_FIELD_IN, OType.LINK, vertex);
      edge.createProperty(OGraphDatabase.EDGE_FIELD_OUT, OType.LINK, vertex);

      vertex.createProperty(OGraphDatabase.VERTEX_FIELD_IN_EDGES, OType.LINKSET, edge);
      vertex.createProperty(OGraphDatabase.VERTEX_FIELD_OUT_EDGES, OType.LINKSET, edge);

      underlying.getMetadata().getSchema().save();
View Full Code Here

      }
    }
  }

  private void browseClass(final String iClassName, final Set<ORID> ids) {
    final OClass clazz = database.getMetadata().getSchema().getClass(iClassName);

    if (clazz == null)
      throw new OCommandExecutionException("Class '" + iClassName + "' was not found");

    for (int i : clazz.getClusterIds()) {
      browseCluster(database.getClusterNameById(i), ids);
    }
  }
View Full Code Here

    else {
      // CLASS
      if (subjectName.startsWith(OCommandExecutorSQLAbstract.CLASS_PREFIX))
        subjectName = subjectName.substring(OCommandExecutorSQLAbstract.CLASS_PREFIX.length());

      final OClass cls = database.getMetadata().getSchema().getClass(subjectName);
      if (cls == null)
        throw new OCommandSQLParsingException("Class " + subjectName + " not found in database", text, pos);

      className = cls.getName();
    }

    final int beginFields = OStringParser.jumpWhiteSpaces(text, pos);
    if (beginFields == -1 || text.charAt(beginFields) != '(')
      throw new OCommandSQLParsingException("Set of fields is missed. Example: (name, surname)", text, pos);
View Full Code Here

      throw new ODatabaseException("Database is closed");
  }

  private void createRolesAndUsers() {
    // CREATE ROLE AND USER SCHEMA CLASSES
    final OClass roleClass = metadata.getSchema().createClass("ORole");
    roleClass.createProperty("mode", OType.BYTE);
    roleClass.createProperty("rules", OType.EMBEDDEDMAP, OType.BYTE);

    final OClass userClass = metadata.getSchema().createClass("OUser");
    userClass.createProperty("roles", OType.LINKSET, roleClass);

    metadata.getSchema().save();

    // CREATE ROLES AND USERS
    final ORole adminRole = metadata.getSecurity().createRole(ORole.ADMIN, ORole.ALLOW_MODES.ALLOW_ALL_BUT);
View Full Code Here

  public OClass createVertexType(final String iClassName) {
    return createVertexType(iClassName, vertexBaseClass);
  }

  public OClass createVertexType(final String iClassName, OClass iSuperClass) {
    OClass cls = getMetadata().getSchema().createClass(iClassName).setSuperClass(iSuperClass);
    getMetadata().getSchema().save();
    return cls;
  }
View Full Code Here

  public OClass getVertexType(final String iClassName) {
    return getMetadata().getSchema().getClass(iClassName);
  }

  public OClass createEdgeType(final String iClassName) {
    OClass cls = getMetadata().getSchema().createClass(iClassName)
        .setSuperClass(getMetadata().getSchema().getClass(EDGE_CLASS_NAME));
    getMetadata().getSchema().save();
    return cls;
  }
View Full Code Here

  }

  private void executeClassProperties(final OHttpRequest iRequest, final ODatabaseDocumentTx db, final String operation,
      final String rid, final String className, final Map<String, String> fields) throws IOException {
    // GET THE TARGET CLASS
    final OClass cls = db.getMetadata().getSchema().getClass(rid);
    if (cls == null) {
      sendTextContent(iRequest, OHttpUtils.STATUS_INTERNALERROR, "Error", null, OHttpUtils.CONTENT_TEXT_PLAIN, "Error: Class '"
          + rid + "' not found.");
      return;
    }

    if ("add".equals(operation)) {
      iRequest.data.commandInfo = "Studio add property";

      try {
        OType type = OType.valueOf(fields.get("type"));

        OProperty prop;
        if (type == OType.LINK || type == OType.LINKLIST || type == OType.LINKSET || type == OType.LINKMAP)
          prop = cls.createProperty(fields.get("name"), type, db.getMetadata().getSchema().getClass(fields.get("linkedClass")));
        else
          prop = cls.createProperty(fields.get("name"), type);

        if (fields.get("linkedType") != null)
          prop.setLinkedType(OType.valueOf(fields.get("linkedType")));
        if (fields.get("mandatory") != null)
          prop.setMandatory("on".equals(fields.get("mandatory")));
        if (fields.get("notNull") != null)
          prop.setNotNull("on".equals(fields.get("notNull")));
        if (fields.get("min") != null)
          prop.setMin(fields.get("min"));
        if (fields.get("max") != null)
          prop.setMax(fields.get("max"));
        if (fields.get("indexed") != null)
          prop.createIndex(fields.get("indexed").equals("Unique") ? OProperty.INDEX_TYPE.UNIQUE : OProperty.INDEX_TYPE.NOTUNIQUE);

        db.getMetadata().getSchema().save();

        sendTextContent(iRequest, OHttpUtils.STATUS_OK_CODE, "OK", null, OHttpUtils.CONTENT_TEXT_PLAIN,
            "Property " + fields.get("name") + " created successfully with id=" + prop.getId());

      } catch (Exception e) {
        sendTextContent(iRequest, OHttpUtils.STATUS_INTERNALERROR, "Error on creating a new property in class " + rid + ": " + e,
            null, OHttpUtils.CONTENT_TEXT_PLAIN, "Error on creating a new property in class " + rid + ": " + e);
      }
    } else if ("del".equals(operation)) {
      iRequest.data.commandInfo = "Studio delete property";

      cls.removeProperty(className);

      db.getMetadata().getSchema().save();

      sendTextContent(iRequest, OHttpUtils.STATUS_OK_CODE, "OK", null, OHttpUtils.CONTENT_TEXT_PLAIN,
          "Property " + fields.get("name") + " deleted successfully.");
View Full Code Here

    int classId;
    int classDefClusterId;
    String classClusterIds;
    String classSuper = null;

    OClass cls;

    try {
      do {
        jsonReader.readNext(OJSONReader.BEGIN_OBJECT);

        className = jsonReader.readNext(OJSONReader.FIELD_ASSIGNMENT).checkContent("\"name\"")
            .readString(OJSONReader.COMMA_SEPARATOR);

        classId = jsonReader.readNext(OJSONReader.FIELD_ASSIGNMENT).checkContent("\"id\"").readInteger(OJSONReader.COMMA_SEPARATOR);

        classDefClusterId = jsonReader.readNext(OJSONReader.FIELD_ASSIGNMENT).checkContent("\"default-cluster-id\"")
            .readInteger(OJSONReader.COMMA_SEPARATOR);

        classClusterIds = jsonReader.readNext(OJSONReader.FIELD_ASSIGNMENT).checkContent("\"cluster-ids\"")
            .readString(OJSONReader.NEXT_IN_OBJECT).trim();

        cls = database.getMetadata().getSchema().getClass(className);

        if (cls != null) {
          if (cls.getDefaultClusterId() != classDefClusterId)
            cls.setDefaultClusterId(classDefClusterId);
        } else
          cls = database.getMetadata().getSchema().createClass(className, classDefClusterId);

        if (classId != cls.getId())
          throw new OSchemaException("Imported class '" + className + "' has id=" + cls.getId() + " different from the original: "
              + classId);

        if (classClusterIds != null) {
          // REMOVE BRACES
          classClusterIds = classClusterIds.substring(1, classClusterIds.length() - 1);

          // ASSIGN OTHER CLUSTER IDS
          for (int i : OStringSerializerHelper.splitIntArray(classClusterIds)) {
            cls.addClusterIds(i);
          }
        }

        String value;
        while (jsonReader.lastChar() == ',') {
View Full Code Here

TOP

Related Classes of com.orientechnologies.orient.core.metadata.schema.OClass

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.