@Test public void getIndexDBObjectFullTextTest() throws MongoValidationException { IndexMetadataBuilder indexMetaBuilder = new IndexMetadataBuilder(DB_NAME, TABLE_NAME, INDEX_NAME, IndexType.FULL_TEXT); indexMetaBuilder.addColumn(COLUMN_NAME, COLUMN_VARCHAR); IndexMetadata indexMetadata = indexMetaBuilder.build(); DBObject object = IndexUtils.getIndexDBObject(indexMetadata); assertEquals("The value of the full-text index column should be 'text'", "text", object.get(COLUMN_NAME)); }
public static DBObject getIndexDBObject(IndexMetadata indexMetadata) throws MongoValidationException { IndexType indexType = indexMetadata.getType(); DBObject indexDBObject = new BasicDBObject(); if (indexType == IndexType.DEFAULT) { for (ColumnMetadata columnMeta : indexMetadata.getColumns().values()) { indexDBObject.put(columnMeta.getName().getName(), 1); } } else if (indexType == IndexType.FULL_TEXT) { for (ColumnMetadata columnMeta : indexMetadata.getColumns().values()) { indexDBObject.put(columnMeta.getName().getName(), "text"); } } else if (indexMetadata.getType() == IndexType.CUSTOM) { indexDBObject = getCustomIndexDBObject(indexMetadata); } else { String msg = "Index type " + indexMetadata.getType().toString() + " is not supported"; LOGGER.error(msg); throw new MongoValidationException(msg); } return indexDBObject; }
IndexUtils { public static DBObject getIndexDBObject(IndexMetadata indexMetadata) throws MongoValidationException { IndexType indexType = indexMetadata.getType(); DBObject indexDBObject = new BasicDBObject(); if (indexType == IndexType.DEFAULT) { for (ColumnMetadata columnMeta : indexMetadata.getColumns().values()) { indexDBObject.put(columnMeta.getName().getName(), 1); } } else if (indexType == IndexType.FULL_TEXT) { for (ColumnMetadata columnMeta : indexMetadata.getColumns().values()) { indexDBObject.put(columnMeta.getName().getName(), "text"); } } else if (indexMetadata.getType() == IndexType.CUSTOM) { indexDBObject = getCustomIndexDBObject(indexMetadata); } else { String msg = "Index type " + indexMetadata.getType().toString() + " is not supported"; LOGGER.error(msg); throw new MongoValidationException(msg); } return indexDBObject; } }
IndexUtils { public static DBObject getIndexDBObject(IndexMetadata indexMetadata) throws MongoValidationException { IndexType indexType = indexMetadata.getType(); DBObject indexDBObject = new BasicDBObject(); if (indexType == IndexType.DEFAULT) { for (ColumnMetadata columnMeta : indexMetadata.getColumns().values()) { indexDBObject.put(columnMeta.getName().getName(), 1); } } else if (indexType == IndexType.FULL_TEXT) { for (ColumnMetadata columnMeta : indexMetadata.getColumns().values()) { indexDBObject.put(columnMeta.getName().getName(), "text"); } } else if (indexMetadata.getType() == IndexType.CUSTOM) { indexDBObject = getCustomIndexDBObject(indexMetadata); } else { String msg = "Index type " + indexMetadata.getType().toString() + " is not supported"; LOGGER.error(msg); throw new MongoValidationException(msg); } return indexDBObject; } private  IndexUtils(); }
IndexUtils { public static DBObject getIndexDBObject(IndexMetadata indexMetadata) throws MongoValidationException { IndexType indexType = indexMetadata.getType(); DBObject indexDBObject = new BasicDBObject(); if (indexType == IndexType.DEFAULT) { for (ColumnMetadata columnMeta : indexMetadata.getColumns().values()) { indexDBObject.put(columnMeta.getName().getName(), 1); } } else if (indexType == IndexType.FULL_TEXT) { for (ColumnMetadata columnMeta : indexMetadata.getColumns().values()) { indexDBObject.put(columnMeta.getName().getName(), "text"); } } else if (indexMetadata.getType() == IndexType.CUSTOM) { indexDBObject = getCustomIndexDBObject(indexMetadata); } else { String msg = "Index type " + indexMetadata.getType().toString() + " is not supported"; LOGGER.error(msg); throw new MongoValidationException(msg); } return indexDBObject; } private  IndexUtils(); static DBObject getCustomOptions(IndexMetadata indexMetadata); static DBObject getIndexDBObject(IndexMetadata indexMetadata); static void dropIndexWithDefaultName(IndexMetadata indexMetadata, DB db); }
IndexUtils { public static DBObject getIndexDBObject(IndexMetadata indexMetadata) throws MongoValidationException { IndexType indexType = indexMetadata.getType(); DBObject indexDBObject = new BasicDBObject(); if (indexType == IndexType.DEFAULT) { for (ColumnMetadata columnMeta : indexMetadata.getColumns().values()) { indexDBObject.put(columnMeta.getName().getName(), 1); } } else if (indexType == IndexType.FULL_TEXT) { for (ColumnMetadata columnMeta : indexMetadata.getColumns().values()) { indexDBObject.put(columnMeta.getName().getName(), "text"); } } else if (indexMetadata.getType() == IndexType.CUSTOM) { indexDBObject = getCustomIndexDBObject(indexMetadata); } else { String msg = "Index type " + indexMetadata.getType().toString() + " is not supported"; LOGGER.error(msg); throw new MongoValidationException(msg); } return indexDBObject; } private  IndexUtils(); static DBObject getCustomOptions(IndexMetadata indexMetadata); static DBObject getIndexDBObject(IndexMetadata indexMetadata); static void dropIndexWithDefaultName(IndexMetadata indexMetadata, DB db);  }