Examples of ODatabaseRecord


Examples of com.orientechnologies.orient.core.db.record.ODatabaseRecord

        throw new OSchemaException("Cluster with id " + clusterId + " already belongs to class " + clustersToClasses.get(clusterId));
    }
  }

  private void dropClassIndexes(final OClass cls) {
    final ODatabaseRecord database = getDatabase();
    final OIndexManager indexManager = database.getMetadata().getIndexManager();

    for (final OIndex<?> index : indexManager.getClassIndexes(cls.getName()))
      indexManager.dropIndex(index.getName());
  }
View Full Code Here

Examples of com.orientechnologies.orient.core.db.record.ODatabaseRecord

  public static final String KEYWORD_CLASS    = "CLASS";
  private OClass             schemaClass;

  @SuppressWarnings("unchecked")
  public OCommandExecutorSQLTruncateClass parse(final OCommandRequest iRequest) {
    final ODatabaseRecord database = getDatabase();

    init((OCommandRequestText) iRequest);

    StringBuilder word = new StringBuilder();

    int oldPos = 0;
    int pos = nextWord(parserText, parserTextUpperCase, oldPos, word, true);
    if (pos == -1 || !word.toString().equals(KEYWORD_TRUNCATE))
      throw new OCommandSQLParsingException("Keyword " + KEYWORD_TRUNCATE + " not found. Use " + getSyntax(), parserText, oldPos);

    oldPos = pos;
    pos = nextWord(parserText, parserTextUpperCase, oldPos, word, true);
    if (pos == -1 || !word.toString().equals(KEYWORD_CLASS))
      throw new OCommandSQLParsingException("Keyword " + KEYWORD_CLASS + " not found. Use " + getSyntax(), parserText, oldPos);

    oldPos = pos;
    pos = nextWord(parserText, parserText, oldPos, word, true);
    if (pos == -1)
      throw new OCommandSQLParsingException("Expected class name. Use " + getSyntax(), parserText, oldPos);

    final String className = word.toString();

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

    if (schemaClass == null)
      throw new OCommandSQLParsingException("Class '" + className + "' not found", parserText, oldPos);
    return this;
  }
View Full Code Here

Examples of com.orientechnologies.orient.core.db.record.ODatabaseRecord

*
*/
public class OFindReferenceHelper {

  public static List<ODocument> findReferences(final Set<ORID> iRecordIds, final String classList) {
    final ODatabaseRecord db = ODatabaseRecordThreadLocal.INSTANCE.get();

    final Map<ORID, Set<ORID>> map = new HashMap<ORID, Set<ORID>>();
    for (ORID rid : iRecordIds) {
      map.put(rid, new HashSet<ORID>());
    }

    if (classList == null || classList.isEmpty()) {
      for (String clusterName : db.getClusterNames()) {
        browseCluster(db, iRecordIds, map, clusterName);
      }
    } else {
      final List<String> classes = OStringSerializerHelper.smartSplit(classList, ',');
      for (String clazz : classes) {
View Full Code Here

Examples of com.orientechnologies.orient.core.db.record.ODatabaseRecord

  public Set<String> getInvolvedClusters() {

    final Set<String> clusters = new HashSet<String>();

    if (parsedTarget != null) {
      final ODatabaseRecord db = getDatabase();

      if (parsedTarget.getTargetQuery() != null) {
        // SUB QUERY, PROPAGATE THE CALL
        final Set<String> clIds = parsedTarget.getTargetQuery().getInvolvedClusters();
        for (String c : clIds)
          // FILTER THE CLUSTER WHERE THE USER HAS THE RIGHT ACCESS
          if (checkClusterAccess(db, c))
            clusters.add(c);

      } else if (parsedTarget.getTargetRecords() != null) {
        // SINGLE RECORDS: BROWSE ALL (COULD BE EXPENSIVE).
        for (OIdentifiable identifiable : parsedTarget.getTargetRecords()) {
          final String c = db.getClusterNameById(identifiable.getIdentity().getClusterId()).toLowerCase();
          // FILTER THE CLUSTER WHERE THE USER HAS THE RIGHT ACCESS
          if (checkClusterAccess(db, c))
            clusters.add(c);
        }
      }
View Full Code Here

Examples of com.orientechnologies.orient.core.db.record.ODatabaseRecord

      OLogManager.instance().warn(this, "Repair completed");
    }
  }

  public OUser createMetadata() {
    final ODatabaseRecord database = getDatabase();

    OClass identityClass = database.getMetadata().getSchema().getClass(IDENTITY_CLASSNAME); // SINCE 1.2.0
    if (identityClass == null)
      identityClass = database.getMetadata().getSchema().createAbstractClass(IDENTITY_CLASSNAME);

    OClass roleClass = database.getMetadata().getSchema().getClass("ORole");
    if (roleClass == null)
      roleClass = database.getMetadata().getSchema().createClass("ORole", identityClass);
    else if (roleClass.getSuperClass() == null)
      // MIGRATE AUTOMATICALLY TO 1.2.0
      roleClass.setSuperClass(identityClass);

    if (!roleClass.existsProperty("name")) {
      roleClass.createProperty("name", OType.STRING).setMandatory(true).setNotNull(true).setCollate("ci");
      roleClass.createIndex("ORole.name", INDEX_TYPE.UNIQUE, ONullOutputListener.INSTANCE, "name");
    } else {
      final Set<OIndex<?>> indexes = roleClass.getInvolvedIndexes("name");
      if (indexes.isEmpty())
        roleClass.createIndex("ORole.name", INDEX_TYPE.UNIQUE, ONullOutputListener.INSTANCE, "name");
    }

    if (!roleClass.existsProperty("mode"))
      roleClass.createProperty("mode", OType.BYTE);
    if (!roleClass.existsProperty("rules"))
      roleClass.createProperty("rules", OType.EMBEDDEDMAP, OType.BYTE);
    if (!roleClass.existsProperty("inheritedRole"))
      roleClass.createProperty("inheritedRole", OType.LINK, roleClass);

    OClass userClass = database.getMetadata().getSchema().getClass("OUser");
    if (userClass == null)
      userClass = database.getMetadata().getSchema().createClass("OUser", identityClass);
    else if (userClass.getSuperClass() == null)
      // MIGRATE AUTOMATICALLY TO 1.2.0
      userClass.setSuperClass(identityClass);

    if (!userClass.existsProperty("name")) {
      userClass.createProperty("name", OType.STRING).setMandatory(true).setNotNull(true).setCollate("ci");
      userClass.createIndex("OUser.name", INDEX_TYPE.UNIQUE, ONullOutputListener.INSTANCE, "name");
    }
    if (!userClass.existsProperty("password"))
      userClass.createProperty("password", OType.STRING).setMandatory(true).setNotNull(true);
    if (!userClass.existsProperty("roles"))
      userClass.createProperty("roles", OType.LINKSET, roleClass);
    if (!userClass.existsProperty("status"))
      userClass.createProperty("status", OType.STRING).setMandatory(true).setNotNull(true);

    // CREATE ROLES AND USERS
    ORole adminRole = getRole(ORole.ADMIN, false);
    if (adminRole == null) {
      adminRole = createRole(ORole.ADMIN, ORole.ALLOW_MODES.ALLOW_ALL_BUT);
      adminRole.addRule(ODatabaseSecurityResources.BYPASS_RESTRICTED, ORole.PERMISSION_ALL).save();
    }

    OUser adminUser = getUser(OUser.ADMIN, false);
    if (adminUser == null)
      adminUser = createUser(OUser.ADMIN, OUser.ADMIN, adminRole);

    // SINCE 1.2.0
    OClass restrictedClass = database.getMetadata().getSchema().getClass(RESTRICTED_CLASSNAME);
    if (restrictedClass == null)
      restrictedClass = database.getMetadata().getSchema().createAbstractClass(RESTRICTED_CLASSNAME);
    if (!restrictedClass.existsProperty(ALLOW_ALL_FIELD))
      restrictedClass.createProperty(ALLOW_ALL_FIELD, OType.LINKSET, database.getMetadata().getSchema()
          .getClass(IDENTITY_CLASSNAME));
    if (!restrictedClass.existsProperty(ALLOW_READ_FIELD))
      restrictedClass.createProperty(ALLOW_READ_FIELD, OType.LINKSET,
          database.getMetadata().getSchema().getClass(IDENTITY_CLASSNAME));
    if (!restrictedClass.existsProperty(ALLOW_UPDATE_FIELD))
      restrictedClass.createProperty(ALLOW_UPDATE_FIELD, OType.LINKSET,
          database.getMetadata().getSchema().getClass(IDENTITY_CLASSNAME));
    if (!restrictedClass.existsProperty(ALLOW_DELETE_FIELD))
      restrictedClass.createProperty(ALLOW_DELETE_FIELD, OType.LINKSET,
          database.getMetadata().getSchema().getClass(IDENTITY_CLASSNAME));

    return adminUser;
  }
View Full Code Here

Examples of com.orientechnologies.orient.core.db.record.ODatabaseRecord

    }

  }

  public void createClassTrigger() {
    final ODatabaseRecord db = ODatabaseRecordThreadLocal.INSTANCE.get();
    OClass classTrigger = db.getMetadata().getSchema().getClass(OClassTrigger.CLASSNAME);
    if (classTrigger == null)
      classTrigger = db.getMetadata().getSchema().createAbstractClass(OClassTrigger.CLASSNAME);
  }
View Full Code Here

Examples of com.orientechnologies.orient.core.db.record.ODatabaseRecord

   */
  public Object execute(final Map<Object, Object> iArgs) {
    if (type == null)
      throw new OCommandExecutionException("Cannot execute the command because it has not been parsed yet");

    final ODatabaseRecord database = getDatabase();
    final OClassImpl sourceClass = (OClassImpl) database.getMetadata().getSchema().getClass(className);
    if (sourceClass == null)
      throw new OCommandExecutionException("Source class '" + className + "' not found");

    OPropertyImpl prop = (OPropertyImpl) sourceClass.getProperty(fieldName);
    if (prop != null)
      throw new OCommandExecutionException("Property '" + className + "." + fieldName
          + "' already exists. Remove it before to retry.");

    // CREATE THE PROPERTY
    OClass linkedClass = null;
    OType linkedType = null;
    if (linked != null) {
      // FIRST SEARCH BETWEEN CLASSES
      linkedClass = database.getMetadata().getSchema().getClass(linked);

      if (linkedClass == null)
        // NOT FOUND: SEARCH BETWEEN TYPES
        linkedType = OType.valueOf(linked.toUpperCase(Locale.ENGLISH));
    }
View Full Code Here

Examples of com.orientechnologies.orient.core.db.record.ODatabaseRecord

  public static final String  KEYWORD_REVOKE = "REVOKE";
  private static final String KEYWORD_FROM   = "FROM";

  @SuppressWarnings("unchecked")
  public OCommandExecutorSQLRevoke parse(final OCommandRequest iRequest) {
    final ODatabaseRecord database = getDatabase();

    init((OCommandRequestText) iRequest);

    privilege = ORole.PERMISSION_NONE;
    resource = null;
    role = null;

    StringBuilder word = new StringBuilder();

    int oldPos = 0;
    int pos = nextWord(parserText, parserTextUpperCase, oldPos, word, true);
    if (pos == -1 || !word.toString().equals(KEYWORD_REVOKE))
      throw new OCommandSQLParsingException("Keyword " + KEYWORD_REVOKE + " not found. Use " + getSyntax(), parserText, oldPos);

    pos = nextWord(parserText, parserTextUpperCase, pos, word, true);
    if (pos == -1)
      throw new OCommandSQLParsingException("Invalid privilege", parserText, oldPos);

    parsePrivilege(word, oldPos);

    pos = nextWord(parserText, parserTextUpperCase, pos, word, true);
    if (pos == -1 || !word.toString().equals(KEYWORD_ON))
      throw new OCommandSQLParsingException("Keyword " + KEYWORD_ON + " not found. Use " + getSyntax(), parserText, oldPos);

    pos = nextWord(parserText, parserText, pos, word, true);
    if (pos == -1)
      throw new OCommandSQLParsingException("Invalid resource", parserText, oldPos);

    resource = word.toString();

    pos = nextWord(parserText, parserTextUpperCase, pos, word, true);
    if (pos == -1 || !word.toString().equals(KEYWORD_FROM))
      throw new OCommandSQLParsingException("Keyword " + KEYWORD_FROM + " not found. Use " + getSyntax(), parserText, oldPos);

    pos = nextWord(parserText, parserText, pos, word, true);
    if (pos == -1)
      throw new OCommandSQLParsingException("Invalid role", parserText, oldPos);

    final String roleName = word.toString();
    role = database.getMetadata().getSecurity().getRole(roleName);
    if (role == null)
      throw new OCommandSQLParsingException("Invalid role: " + roleName);
    return this;
  }
View Full Code Here

Examples of com.orientechnologies.orient.core.db.record.ODatabaseRecord

    try {
      if (recreateIndexesThread != null && recreateIndexesThread.isAlive())
        // BUILDING ALREADY IN PROGRESS
        return;

      final ODatabaseRecord db = getDatabase();
      document = db.load(new ORecordId(getDatabase().getStorage().getConfiguration().indexMgrRecordId));
      final ODocument doc = new ODocument();
      document.copyTo(doc);

      // USE A NEW DB INSTANCE
      final ODatabaseDocumentTx newDb = new ODatabaseDocumentTx(db.getURL());

      Runnable recreateIndexesTask = new RecreateIndexesTask(newDb, doc);

      recreateIndexesThread = new Thread(recreateIndexesTask, "OrientDB rebuild indexes");
      recreateIndexesThread.start();
View Full Code Here

Examples of com.orientechnologies.orient.core.db.record.ODatabaseRecord

  private boolean                            isUpsertAllowed   = false;
  private boolean                            updated           = false;

  @SuppressWarnings("unchecked")
  public OCommandExecutorSQLUpdate parse(final OCommandRequest iRequest) {
    final ODatabaseRecord database = getDatabase();

    init((OCommandRequestText) iRequest);

    setEntries.clear();
    addEntries.clear();
    putEntries.clear();
    removeEntries.clear();
    incrementEntries.clear();
    content = null;
    merge = null;

    query = null;

    parserRequiredKeyword(KEYWORD_UPDATE);

    subjectName = parserRequiredWord(false, "Invalid target", " =><,\r\n");
    if (subjectName == null)
      throwSyntaxErrorException("Invalid subject name. Expected cluster, class, index or sub-query");

    parserNextWord(true);
    String word = parserGetLastWord();

    if (parserIsEnded()
        || (!word.equals(KEYWORD_SET) && !word.equals(KEYWORD_ADD) && !word.equals(KEYWORD_PUT) && !word.equals(KEYWORD_REMOVE)
            && !word.equals(KEYWORD_INCREMENT) && !word.equals(KEYWORD_CONTENT) && !word.equals(KEYWORD_MERGE)
            && !word.equals(KEYWORD_LOCK) && !word.equals(KEYWORD_RETURN) && !word.equals(KEYWORD_UPSERT)))
      throwSyntaxErrorException("Expected keyword " + KEYWORD_SET + "," + KEYWORD_ADD + "," + KEYWORD_CONTENT + "," + KEYWORD_MERGE
          + "," + KEYWORD_PUT + "," + KEYWORD_REMOVE + "," + KEYWORD_INCREMENT + "," + KEYWORD_LOCK + " or " + KEYWORD_RETURN
          + " or " + KEYWORD_UPSERT);

    while ((!parserIsEnded() && !parserGetLastWord().equals(OCommandExecutorSQLAbstract.KEYWORD_WHERE))
        || parserGetLastWord().equals(KEYWORD_UPSERT)) {
      word = parserGetLastWord();

      if (word.equals(KEYWORD_CONTENT))
        parseContent();
      else if (word.equals(KEYWORD_MERGE))
        parseMerge();
      else if (word.equals(KEYWORD_SET))
        parseSetFields(setEntries);
      else if (word.equals(KEYWORD_ADD))
        parseAddFields();
      else if (word.equals(KEYWORD_PUT))
        parsePutFields();
      else if (word.equals(KEYWORD_REMOVE))
        parseRemoveFields();
      else if (word.equals(KEYWORD_INCREMENT))
        parseIncrementFields();
      else if (word.equals(KEYWORD_LOCK))
        lockStrategy = parseLock();
      else if (word.equals(KEYWORD_UPSERT))
        upsertMode = true;
      else if (word.equals(KEYWORD_RETURN))
        parseReturn();
      else if (word.equals(KEYWORD_RETRY))
        parseRetry();
      else
        break;

      parserNextWord(true);
    }

    final String additionalStatement = parserGetLastWord();

    if (subjectName.startsWith("(")) {
      subjectName = subjectName.trim();
      query = database.command(new OSQLAsynchQuery<ODocument>(subjectName.substring(1, subjectName.length() - 1), this)
          .setContext(context));

      if (additionalStatement.equals(OCommandExecutorSQLAbstract.KEYWORD_WHERE)
          || additionalStatement.equals(OCommandExecutorSQLAbstract.KEYWORD_LIMIT))
        compiledFilter = OSQLEngine.getInstance().parseCondition(parserText.substring(parserGetCurrentPosition()), getContext(),
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.