Package com.orientechnologies.orient.core.exception

Examples of com.orientechnologies.orient.core.exception.OCommandExecutionException


  /**
   * Execute the ALTER CLASS.
   */
  public Object execute(final Map<Object, Object> iArgs) {
    if (attribute == null)
      throw new OCommandExecutionException("Can't execute the command because it hasn't been parsed yet");

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

    cls.setInternal(attribute, value);
    return null;
  }
View Full Code Here


  /**
   * Execute the CREATE LINK.
   */
  public Object execute(final Map<Object, Object> iArgs) {
    if (destField == null)
      throw new OCommandExecutionException("Can't execute the command because it hasn't been parsed yet");
    if (!(database instanceof ODatabaseDocumentTx))
      throw new OCommandSQLParsingException("This command supports only the database type ODatabaseDocumentTx and type '"
          + database.getClass() + "' was found");

    final ODatabaseDocumentTx db = (ODatabaseDocumentTx) database;

    OClass sourceClass = database.getMetadata().getSchema().getClass(sourceClassName);
    if (sourceClass == null)
      throw new OCommandExecutionException("Source class '" + sourceClassName + "' not found");

    OClass destClass = database.getMetadata().getSchema().getClass(destClassName);
    if (destClass == null)
      throw new OCommandExecutionException("Destination class '" + destClassName + "' not found");

    Object value;
    String cmd = "select from " + destClassName + " where " + destField + " = ";
    List<ODocument> result;
    ODocument target;
    Object oldValue;
    long total = 0;

    if (linkName == null)
      // NO LINK NAME EXPRESSED: OVERWRITE THE SOURCE FIELD
      linkName = sourceField;

    boolean inverse = linkType != null && linkType.equalsIgnoreCase("inverse");
    boolean multipleRelationship = false;

    long totRecords = db.countClass(sourceClass.getName());
    long currRecord = 0;

    if (progressListener != null)
      progressListener.onBegin(this, totRecords);

    try {
      // BROWSE ALL THE RECORDS OF THE SOURCE CLASS
      for (ODocument doc : db.browseClass(sourceClass.getName())) {
        value = doc.field(sourceField);

        if (value != null) {
          if (value instanceof ODocument || value instanceof ORID) {
            // ALREADY CONVERTED
          } else if (value instanceof Collection<?>) {
            // TODO
          } else {
            // SEARCH THE DESTINATION RECORD
            if (value instanceof String) {
              target = null;

              if (((String) value).length() == 0)
                value = null;
              else {
                value = "'" + value + "'";
                result = database.<OCommandRequest> command(new OSQLSynchQuery<ODocument>(cmd + value)).execute();

                if (result == null || result.size() == 0)
                  // throw new
                  // OCommandExecutionException("Can't create link because the destination record was not found in class '"
                  // + destClass.getName() + "' and with the field '" + destField + "' equals to " + value);
                  value = null;
                else if (result.size() > 1)
                  throw new OCommandExecutionException("Can't create link because multiple records was found in class '"
                      + destClass.getName() + "' with value " + value + " in field '" + destField + "'");
                else {
                  target = result.get(0);
                  value = target;
                }
              }

              if (target != null && inverse) {
                // INVERSE RELATIONSHIP
                oldValue = target.field(linkName);

                if (oldValue != null) {
                  if (!multipleRelationship)
                    multipleRelationship = true;

                  Collection<ODocument> coll;
                  if (oldValue instanceof Collection) {
                    // ADD IT IN THE EXISTENT COLLECTION
                    coll = (Collection<ODocument>) oldValue;
                    target.setDirty();
                  } else {
                    // CREATE A NEW COLLECTION FOR BOTH
                    coll = new ArrayList<ODocument>(2);
                    target.field(linkName, coll);
                    coll.add((ODocument) oldValue);
                  }
                  coll.add(doc);
                } else {
                  target.field(linkName, doc);
                }
                target.save();

              } else {
                // SET THE REFERENCE
                doc.field(linkName, value);
                doc.save();
              }

              total++;
            }
          }
        }

        if (progressListener != null)
          progressListener.onProgress(this, currRecord, currRecord * 100f / totRecords);
      }

      if (total > 0) {
        if (inverse) {
          // REMOVE THE OLD PROPERTY IF ANY
          OProperty prop = destClass.getProperty(linkName);
          if (prop != null)
            destClass.dropProperty(linkName);

          // CREATE THE PROPERTY
          destClass.createProperty(linkName, multipleRelationship ? OType.LINKLIST : OType.LINK, sourceClass);

        } else {

          // REMOVE THE OLD PROPERTY IF ANY
          OProperty prop = sourceClass.getProperty(linkName);
          if (prop != null)
            sourceClass.dropProperty(linkName);

          // CREATE THE PROPERTY
          sourceClass.createProperty(linkName, OType.LINK, destClass);
        }
      }

      if (progressListener != null)
        progressListener.onCompletition(this, true);

    } catch (Exception e) {
      if (progressListener != null)
        progressListener.onCompletition(this, false);

      throw new OCommandExecutionException("Error on creation of links", e);
    }

    return total;
  }
View Full Code Here

          if (targetClasses == null)
            targetClasses = new HashMap<OClass, String>();

          OClass cls = database.getMetadata().getSchema().getClass(subjectName);
          if (cls == null)
            throw new OCommandExecutionException("Class '" + subjectName + "' was not found");

          targetClasses.put(cls, alias);
        }
      }
    }
View Full Code Here

  public void bindParameters(final Map<Object, Object> iArgs) {
    if (parameterItems == null || iArgs == null || iArgs.size() == 0)
      return;

    if (iArgs.size() < parameterItems.size())
      throw new OCommandExecutionException("Can't execute because " + (parameterItems.size() - iArgs.size())
          + " parameter(s) are unbounded");

    String paramName;
    for (Entry<Object, Object> entry : iArgs.entrySet()) {
      if (entry.getKey() instanceof Integer)
View Full Code Here

  /**
   * Execute the CREATE PROPERTY.
   */
  public Object execute(final Map<Object, Object> iArgs) {
    if (type == null)
      throw new OCommandExecutionException("Can't execute the command because it hasn't been parsed yet");

    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;
View Full Code Here

  /**
   * Execute the command.
   */
  public Object execute(final Map<Object, Object> iArgs) {
    if (role == null)
      throw new OCommandExecutionException("Can't execute the command because it hasn't been parsed yet");

    role.revoke(resource, privilege);
    role.save();

    return role;
View Full Code Here

    return this;
  }

  public Object execute(final Map<Object, Object> iArgs) {
    if (subjectName == null)
      throw new OCommandExecutionException("Can't execute the command because it hasn't been parsed yet");

    database.query(query, iArgs);
    return recordCount;
  }
View Full Code Here

        if (record.getSchemaClass() != null) {
          final OProperty property = record.getSchemaClass().getProperty(entry.getKey());
          if (property != null
              && (property.getType() != null && (!property.getType().equals(OType.EMBEDDEDMAP) && !property.getType().equals(
                  OType.LINKMAP)))) {
            throw new OCommandExecutionException("field " + entry.getKey() + " is not defined as a map");
          }
        }
        fieldValue = new HashMap();
        record.field(entry.getKey(), fieldValue);
      }
View Full Code Here

  /**
   * Execute the CREATE PROPERTY.
   */
  public Object execute(final Map<Object, Object> iArgs) {
    if (fieldName == null)
      throw new OCommandExecutionException("Can't execute the command because it hasn't been parsed yet");

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

    // REMOVE THE PROPERTY
    sourceClass.dropPropertyInternal(fieldName);

    return null;
View Full Code Here

    return this;
  }

  public Object execute(final Map<Object, Object> iArgs) {
    if (query == null && indexName == null)
      throw new OCommandExecutionException("Can't execute the command because it hasn't been parsed yet");

    if (query != null) {
      // AGAINST CLUSTERS AND CLASSES
      query.execute(iArgs);
      return recordCount;
    } else {
      // AGAINST INDEXES
      final OIndex index = database.getMetadata().getIndexManager().getIndex(indexName);
      if (index == null)
        throw new OCommandExecutionException("Target index '" + indexName + "' not found");

      Object key = null;
      Object value = VALUE_NOT_FOUND;

      if (KEYWORD_KEY.equalsIgnoreCase(compiledFilter.getRootCondition().getLeft().toString()))
        // FOUND KEY ONLY
        key = compiledFilter.getRootCondition().getRight();
      else if (compiledFilter.getRootCondition().getLeft() instanceof OSQLFilterCondition) {
        // KEY AND VALUE
        final OSQLFilterCondition leftCondition = (OSQLFilterCondition) compiledFilter.getRootCondition().getLeft();
        if (KEYWORD_KEY.equalsIgnoreCase(leftCondition.getLeft().toString()))
          key = leftCondition.getRight();

        final OSQLFilterCondition rightCondition = (OSQLFilterCondition) compiledFilter.getRootCondition().getRight();
        if (KEYWORD_RID.equalsIgnoreCase(rightCondition.getLeft().toString()))
          value = rightCondition.getRight();

      }

      if (key == null)
        throw new OCommandExecutionException("'Key' field is required for queries against indexes");

      final boolean result;
      if (value != VALUE_NOT_FOUND)
        result = index.remove(key, (OIdentifiable) value);
      else
View Full Code Here

TOP

Related Classes of com.orientechnologies.orient.core.exception.OCommandExecutionException

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.