Package com.orientechnologies.orient.core.exception

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


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

    final OIndex idx;
    if (name.indexOf('.') > -1) {
      // PROPERTY INDEX
      final String[] parts = name.split("\\.");
      final String className = parts[0];
      if (className == null)
        throw new OCommandExecutionException("Class " + className + " not found");
      String fieldName = parts[1];

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

      final OPropertyImpl prop = (OPropertyImpl) cls.getProperty(fieldName);
      if (prop == null)
        throw new IllegalArgumentException("Property '" + fieldName + "' was not found in class '" + cls + "'");

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");

    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.removeProperty(linkName);

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

        } else {

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

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

      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

    return true;
  }

  public List<T> run(final Object... iArgs) {
    if (!(database.getStorage() instanceof OStorageEmbedded))
      throw new OCommandExecutionException("Native queries can run only in embedded-local version. Not in the remote one.");

    queryRecord.setSourceQuery(this);

    // CHECK IF A CLASS WAS CREATED
    OClass cls = database.getMetadata().getSchema().getClass(cluster);
    if (cls == null)
      throw new OCommandExecutionException("Cluster " + cluster + " was not found");

    ((OStorageEmbedded) database.getStorage()).browse(cls.getPolymorphicClusterIds(), null, null, this, record, false);
    return null;
  }
View Full Code Here

      return executor.execute(iCommand.getParameters());
    } catch (OCommandExecutionException e) {
      // PASS THROUGHT
      throw e;
    } catch (Exception e) {
      throw new OCommandExecutionException("Error on execution of command: " + iCommand, e);
    }
  }
View Full Code Here

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

    OClass sourceClass = database.getMetadata().getSchema().getClass(className);
    if (sourceClass != null)
      throw new OCommandExecutionException("Class " + className + " already exists");

    sourceClass = database.getMetadata().getSchema().createClass(className);

    database.getMetadata().getSchema().save();

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");

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

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

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

    final Class<? extends OSQLFunction> f = aggregationFunctions.get(iFunctionName.toUpperCase());
    if (f != null)
      try {
        return f.newInstance();
      } catch (Exception e) {
        throw new OCommandExecutionException("Error in creation of function " + iFunctionName
            + "(). Probably there is not an empty constructor or the constructor generates errors", e);
      }
    return null;
  }
View Full Code Here

    if (commandClass != null)
      try {
        return commandClass.newInstance();
      } catch (Exception e) {
        throw new OCommandExecutionException("Error in creation of command " + commandClass
            + "(). Probably there is not an empty constructor or the constructor generates errors", e);
      }

    return null;
  }
View Full Code Here

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

    database.getMetadata().getSchema().removeClass(className);

    database.getMetadata().getSchema().save();

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");

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

    OProperty prop = 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

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.