示例#1
0
 /** Remove the index on property */
 public void removeIndex() {
   if (index != null) {
     index.clear();
     index.getRecord().delete();
     index = null;
     setDirty();
   }
 }
示例#2
0
  public void fromStream() {
    name = document.field("name");
    if (document.field("type") != null)
      type = OType.getById(((Long) document.field("type")).byteValue());
    offset = ((Long) document.field("offset")).intValue();

    mandatory = (Boolean) document.field("mandatory");
    notNull = (Boolean) document.field("notNull");
    min = document.field("min");
    max = document.field("max");

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

    if (document.field("index") != null) {
      setIndex(
          INDEX_TYPE.valueOf((String) document.field("index-type")),
          ((ODocument) document.field("index")).getIdentity());
      try {
        index.load();
      } catch (IOException e) {
        OLogManager.instance()
            .error(
                this, "Can't load index for property %s", e, ODatabaseException.class, toString());
      }
    }
  }
示例#3
0
  /**
   * Creates an index on this property. Indexes speed up queries but slow down insert and update
   * operations. For massive inserts we suggest to remove the index, make the massive insert and
   * recreate it.
   *
   * @param iType One of types supported.
   *     <ul>
   *       <li>UNIQUE: Doesn't allow duplicates
   *       <li>NOT_UNIQUE: Allow duplicates
   *       <li>FULL_TEXT: Indexes single word for full text search
   *     </ul>
   *
   * @return
   */
  public OPropertyIndex createIndex(final INDEX_TYPE iType) {
    if (index != null) throw new IllegalStateException("Index already created");

    try {
      switch (iType) {
        case UNIQUE:
          index =
              new OPropertyIndexUnique(document.getDatabase(), this, OStorage.CLUSTER_INDEX_NAME);
          break;
        case NOT_UNIQUE:
          index =
              new OPropertyIndexNotUnique(
                  document.getDatabase(), this, OStorage.CLUSTER_INDEX_NAME);
          break;
        case FULLTEXT:
          index = new OFullTextIndex(document.getDatabase(), this, OStorage.CLUSTER_INDEX_NAME);
          break;
      }

      index.rebuild();

      setDirty();

      if (document.getDatabase() != null) {
        // / SAVE ONLY IF THE PROPERTY IS ALREADY PERSISTENT
        index.lazySave();
        document.getDatabase().getMetadata().getSchema().save();
      }

    } catch (OIndexException e) {
      throw e;

    } catch (Exception e) {
      OLogManager.instance()
          .exception(
              "Unable to create '%s' index for property: %s",
              e, ODatabaseException.class, iType, toString());
    }

    return index;
  }
示例#4
0
  @OBeforeSerialization
  public ODocument toStream() {
    document.field("name", name);
    document.field("type", type.id);
    document.field("offset", offset);
    document.field("mandatory", mandatory);
    document.field("notNull", notNull);
    document.field("min", min);
    document.field("max", max);

    document.field("linkedClass", linkedClass != null ? linkedClass.getName() : null);
    document.field("linkedType", linkedType != null ? linkedType.id : null);

    // SAVE THE INDEX
    if (index != null) {
      index.lazySave();
      document.field("index", index.getRID());
      document.field("index-type", index.getType());
    } else {
      document.field("index", ORecordId.EMPTY_RECORD_ID);
    }
    return document;
  }