Examples of OIndex


Examples of com.orientechnologies.orient.core.index.OIndex

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

    if (indexName != null) {
      final OIndex index = database.getMetadata().getIndexManager().getIndex(indexName);
      if (index == null)
        throw new OCommandExecutionException("Target index '" + indexName + "' not found");

      // BIND VALUES
      index.put(fields.get(KEYWORD_KEY), (OIdentifiable) fields.get(KEYWORD_RID));
      return null;
    } else {
      // CREATE NEW DOCUMENT
      ODocument doc = className != null ? new ODocument(database, className) : new ODocument(database);
View Full Code Here

Examples of com.orientechnologies.orient.core.index.OIndex

    listener.onMessage("\nRebuilding " + propertyIndexes.size() + " automatic indexes...");

    database.getMetadata().getIndexManager().reload();

    for (Entry<OProperty, String> e : propertyIndexes.entrySet()) {
      final OIndex idx = database.getMetadata().getIndexManager().getIndex(e.getValue());
      if (idx != null) {
        idx.setCallback(e.getKey().getIndex());

        listener.onMessage("\n- Index '" + idx.getName() + "'...");

        // idx.rebuild(new OProgressListener() {
        // public boolean onProgress(Object iTask, long iCounter, float iPercent) {
        // if (iPercent % 10 == 0)
        // listener.onMessage(".");
        // return false;
        // }
        //
        // public void onCompletition(Object iTask, boolean iSucceed) {
        // }
        //
        // public void onBegin(Object iTask, long iTotal) {
        // }
        // });

        listener.onMessage("OK (" + idx.getSize() + " records)");
      }
    }
  }
View Full Code Here

Examples of com.orientechnologies.orient.core.index.OIndex

      if (indexName == null || indexName.length() == 0)
        return;

      listener.onMessage("\n- Index '" + indexName + "'...");

      final OIndex index = database.getMetadata().getIndexManager().getIndex(indexName);

      long tot = 0;

      jsonReader.readNext(OJSONReader.BEGIN_OBJECT);

      String n;
      do {
        jsonReader.readNext(new char[] { ':', '}' });

        if (jsonReader.lastChar() != '}') {
          key = jsonReader.checkContent("\"key\"").readString(OJSONReader.COMMA_SEPARATOR);
          value = jsonReader.readNext(OJSONReader.FIELD_ASSIGNMENT).checkContent("\"value\"")
              .readString(OJSONReader.NEXT_IN_OBJECT);

          if (index != null)
            if (value.length() >= 4) {
              if (value.charAt(0) == '[')
                // REMOVE []
                value = value.substring(1, value.length() - 1);

              final Collection<String> rids = OStringSerializerHelper.split(value, ',', new char[] { '#', '"' });

              for (String rid : rids) {
                doc.setIdentity(new ORecordId(rid));
                index.put(key, doc);
              }
            }

          tot++;
        }
View Full Code Here

Examples of com.orientechnologies.orient.core.index.OIndex

      return totalIndexed;

    } else {

      final OIndex idx = database.getMetadata().getIndexManager().getIndex(name);
      if (idx == null)
        throw new OCommandExecutionException("Index '" + name + "' not found");

      if (!idx.isAutomatic())
        throw new OCommandExecutionException("Can't rebuild index '" + name
            + "' because it's manual and there aren't indications of what to index");

      return idx.rebuild();
    }
  }
View Full Code Here

Examples of com.orientechnologies.orient.core.index.OIndex

      // COMMIT INDEX CHANGES
      final ODocument indexEntries = currentTx.getIndexChanges();
      if (indexEntries != null) {
        for (Entry<String, Object> indexEntry : indexEntries) {
          final OIndex index = getMetadata().getIndexManager().getIndexInternal(indexEntry.getKey());
          index.commit((ODocument) indexEntry.getValue());
        }
      }
    } finally {
      // RELEASE INDEX LOCKS IF ANY
      if (lockedIndexes != null)
        for (OIndexMVRBTreeAbstract index : lockedIndexes) {
          index.releaseExclusiveLock();
        }
    }
  }
View Full Code Here

Examples of com.orientechnologies.orient.core.index.OIndex

      // 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 (compiledFilter.getRootCondition() == null) {
        final long total = index.getSize();
        index.clear();
        return total;
      } else {
        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
          result = index.remove(key);
        return result ? 1 : 0;
      }
    }
  }
View Full Code Here

Examples of com.orientechnologies.orient.core.index.OIndex

   */
  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 + "'");

      idx = prop.createIndexInternal(indexType.toUpperCase(), progressListener).getUnderlying();
    } else {
      idx = database.getMetadata().getIndexManager().createIndex(name, indexType.toUpperCase(), keyType, null, null, null, false);
    }

    if (idx != null)
      return idx.getSize();

    return null;
  }
View Full Code Here

Examples of com.orientechnologies.orient.core.index.OIndex

    linkedClassName = (String) document.field("linkedClass");
    if (document.field("linkedType") != null)
      linkedType = OType.getById(((Integer) document.field("linkedType")).byteValue());

    final OIndex underlyingIndex = getDatabase().getMetadata().getIndexManager().getIndex(getFullName());

    if (underlyingIndex != null)
      index = new OPropertyIndex(getDatabase(), owner, new String[] { name });
  }
View Full Code Here

Examples of com.orientechnologies.orient.core.index.OIndex

    if (searchInIndexTriples.isEmpty())
      return false;

    for (OSearchInIndexTriple indexTriple : searchInIndexTriples) {
      final OIndex idx = indexTriple.index.getInternal();
      final OQueryOperator operator = indexTriple.indexOperator;
      final Object key = indexTriple.key;

      final boolean indexCanBeUsedInEqualityOperators = (idx instanceof OIndexUnique || idx instanceof OIndexNotUnique);

      if (indexCanBeUsedInEqualityOperators && operator instanceof OQueryOperatorBetween) {
        final Object[] betweenKeys = (Object[]) key;
        fillSearchIndexResultSet(iResultSet,
            indexTriple.index.getValuesBetween(OSQLHelper.getValue(betweenKeys[0]), OSQLHelper.getValue(betweenKeys[2])));
        return true;
      }

      if ((indexCanBeUsedInEqualityOperators && operator instanceof OQueryOperatorEquals) || idx instanceof OIndexFullText
          && operator instanceof OQueryOperatorContainsText) {
        fillSearchIndexResultSet(iResultSet, indexTriple.index.get(key));
        return true;
      }

      if (indexCanBeUsedInEqualityOperators && operator instanceof OQueryOperatorMajor) {
        fillSearchIndexResultSet(iResultSet, idx.getValuesMajor(key, false));
        return true;
      }

      if (indexCanBeUsedInEqualityOperators && operator instanceof OQueryOperatorMajorEquals) {
        fillSearchIndexResultSet(iResultSet, idx.getValuesMajor(key, true));
        return true;
      }

      if (indexCanBeUsedInEqualityOperators && operator instanceof OQueryOperatorMinor) {
        fillSearchIndexResultSet(iResultSet, idx.getValuesMinor(key, false));
        return true;
      }

      if (indexCanBeUsedInEqualityOperators && operator instanceof OQueryOperatorMinorEquals) {
        fillSearchIndexResultSet(iResultSet, idx.getValuesMinor(key, true));
        return true;
      }
    }
    return false;
  }
View Full Code Here

Examples of com.orientechnologies.orient.core.index.OIndex

      prop = iSchemaClass.getProperty(item.getRoot());
    }

    if (prop != null && prop.isIndexed()) {
      final Object origValue = iCondition.getLeft() == iItem ? iCondition.getRight() : iCondition.getLeft();
      final OIndex underlyingIndex = prop.getIndex().getUnderlying();

      if (iCondition.getOperator() instanceof OQueryOperatorBetween) {
        iSearchInIndexTriples.add(new OSearchInIndexTriple(iCondition.getOperator(), origValue, underlyingIndex));
        return true;
      }

      Object value = OSQLHelper.getValue(origValue);

      if (value == null)
        return false;

      value = OType.convert(value, underlyingIndex.getKeyType().getDefaultJavaType());

      if (value == null)
        return false;

      iSearchInIndexTriples.add(new OSearchInIndexTriple(iCondition.getOperator(), value, underlyingIndex));
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.