Пример #1
0
 private Map<String, Object> extractOptions(final Indexed indexed) {
   Map<String, Object> map = toMap(indexed);
   if (indexed.options().collation().locale().equals("")) {
     map.remove("options");
   }
   map.remove("value");
   return map;
 }
Пример #2
0
  @Test
  public void indexedPartialFilters() {
    MongoCollection<Document> collection = getDatabase().getCollection("indexes");
    MappedClass mappedClass = getMorphia().getMapper().getMappedClass(IndexedClass.class);

    Indexed indexed =
        new IndexedBuilder()
            .options(new IndexOptionsBuilder().partialFilter("{ name : { $gt : 13 } }"));

    indexHelper.createIndex(collection, mappedClass, indexHelper.convert(indexed, "text"), false);
    findPartialIndex(BasicDBObject.parse(indexed.options().partialFilter()));
  }
Пример #3
0
  @SuppressWarnings("deprecation")
  Index convert(final Indexed indexed, final String nameToStore) {
    if (indexed.dropDups() || indexed.options().dropDups()) {
      LOG.warning(
          "dropDups value is no longer supported by the server.  Please set this value to false and "
              + "validate your system behaves as expected.");
    }
    final Map<String, Object> newOptions = extractOptions(indexed.options());
    if (!extractOptions(indexed).isEmpty() && !newOptions.isEmpty()) {
      throw new MappingException(
          "Mixed usage of deprecated @Indexed values with the new @IndexOption values is not "
              + "allowed.  Please migrate all settings to @IndexOptions");
    }

    List<Field> fields =
        Collections.<Field>singletonList(
            new FieldBuilder().value(nameToStore).type(fromValue(indexed.value().toIndexValue())));
    return newOptions.isEmpty()
        ? new IndexBuilder().options(new IndexOptionsBuilder().migrate(indexed)).fields(fields)
        : new IndexBuilder().options(indexed.options()).fields(fields);
  }
Пример #4
0
  @Test
  @SuppressWarnings("deprecation")
  public void oldIndexedForm() {
    Indexed indexed =
        new IndexedBuilder()
            .name("index_name")
            .background(true)
            .dropDups(true)
            .expireAfterSeconds(42)
            .sparse(true)
            .unique(true)
            .value(IndexDirection.DESC);
    assertEquals(indexed.options().name(), "");

    Index converted = indexHelper.convert(indexed, "oldstyle");
    assertEquals(converted.options().name(), "index_name");
    assertTrue(converted.options().background());
    assertTrue(converted.options().dropDups());
    assertTrue(converted.options().sparse());
    assertTrue(converted.options().unique());
    assertEquals(new FieldBuilder().value("oldstyle").type(IndexType.DESC), converted.fields()[0]);
  }