Example usage for com.mongodb.client.model IndexOptions storageEngine

List of usage examples for com.mongodb.client.model IndexOptions storageEngine

Introduction

In this page you can find the example usage for com.mongodb.client.model IndexOptions storageEngine.

Prototype

Bson storageEngine

To view the source code for com.mongodb.client.model IndexOptions storageEngine.

Click Source Link

Usage

From source file:org.restheart.db.IndexDAO.java

License:Open Source License

IndexOptions getIndexOptions(BsonDocument options) {
    IndexOptions ret = new IndexOptions();

    //***Options for All Index Types
    //name  string
    if (options.containsKey("name") && options.get("name").isString()) {
        ret.name(options.get("name").asString().getValue());
    }/*from  w  ww  .  j a  v a2s  . c om*/

    //background    boolean
    if (options.containsKey("background") && options.get("background").isBoolean()) {
        ret.background(options.get("background").asBoolean().getValue());
    }

    //expireAfterSeconds    integer
    if (options.containsKey("expireAfterSeconds") && options.get("expireAfterSeconds").isInt32()) {
        ret.expireAfter(0l + options.get("expireAfterSeconds").asInt32().getValue(), TimeUnit.SECONDS);
    }

    //partialFilterExpression   document
    if (options.containsKey("partialFilterExpression") && options.get("partialFilterExpression").isDocument()) {
        ret.partialFilterExpression(options.get("partialFilterExpression").asDocument());
    }

    //storageEngine document
    if (options.containsKey("storageEngine") && options.get("storageEngine").isDocument()) {
        ret.storageEngine(options.get("storageEngine").asDocument());
    }

    //unique   boolean
    if (options.containsKey("unique") && options.get("unique").isBoolean()) {
        ret.unique(options.get("unique").asBoolean().getValue());
    }

    //sparse    boolean
    if (options.containsKey("sparse") && options.get("sparse").isBoolean()) {
        ret.sparse(options.get("sparse").asBoolean().getValue());
    }

    //***Options for text Indexes
    //weights   document
    if (options.containsKey("weights") && options.get("weights").isDocument()) {
        ret.weights(options.get("weights").asDocument());
    }
    //default_language   string
    if (options.containsKey("default_language") && options.get("default_language").isString()) {
        ret.defaultLanguage(options.get("default_language").asString().getValue());
    }

    //language_override   string
    if (options.containsKey("language_override") && options.get("language_override").isString()) {
        ret.languageOverride(options.get("language_override").asString().getValue());
    }

    //textIndexVersion   integer
    if (options.containsKey("textIndexVersion") && options.get("textIndexVersion").isInt32()) {
        ret.textVersion(options.get("textIndexVersion").asInt32().getValue());
    }

    //***Options for 2dsphere Indexes
    //2dsphereIndexVersion   integer
    if (options.containsKey("2dsphereIndexVersion") && options.get("2dsphereIndexVersion").isInt32()) {
        ret.sphereVersion(options.get("2dsphereIndexVersion").asInt32().getValue());
    }

    //***Options for 2d Indexes
    //bits   integer
    if (options.containsKey("bits") && options.get("bits").isInt32()) {
        ret.bits(options.get("bits").asInt32().getValue());
    }

    //min   number
    if (options.containsKey("min") && options.get("min").isDouble()) {
        ret.min(options.get("min").asDouble().getValue());
    }

    //max   number
    if (options.containsKey("max") && options.get("max").isDouble()) {
        ret.max(options.get("max").asDouble().getValue());
    }

    //***Options for geoHaystack Indexes
    //bucketSize   number
    if (options.containsKey("bucketSize") && options.get("bucketSize").isDouble()) {
        ret.bucketSize(options.get("bucketSize").asDouble().getValue());
    }

    return ret;
}

From source file:org.wso2.extension.siddhi.store.mongodb.util.MongoTableUtils.java

License:Open Source License

/**
 * Utility method which can be used to create an IndexModel.
 *
 * @param fieldName   the attribute on which the index is to be created.
 * @param sortOrder   the sort order of the index to be created.
 * @param indexOption json string of the options of the index to be created.
 * @return IndexModel.//from www .  j ava 2  s  . co m
 */
private static IndexModel createIndexModel(String fieldName, Integer sortOrder, String indexOption) {
    Document indexDocument = new Document(fieldName, sortOrder);
    if (indexOption == null) {
        return new IndexModel(indexDocument);
    } else {
        IndexOptions indexOptions = new IndexOptions();
        Document indexOptionDocument;
        try {
            indexOptionDocument = Document.parse(indexOption);
            for (Map.Entry<String, Object> indexEntry : indexOptionDocument.entrySet()) {
                Object value = indexEntry.getValue();
                switch (indexEntry.getKey()) {
                case "unique":
                    indexOptions.unique(Boolean.parseBoolean(value.toString()));
                    break;
                case "background":
                    indexOptions.background(Boolean.parseBoolean(value.toString()));
                    break;
                case "name":
                    indexOptions.name(value.toString());
                    break;
                case "sparse":
                    indexOptions.sparse(Boolean.parseBoolean(value.toString()));
                    break;
                case "expireAfterSeconds":
                    indexOptions.expireAfter(Long.parseLong(value.toString()), TimeUnit.SECONDS);
                    break;
                case "version":
                    indexOptions.version(Integer.parseInt(value.toString()));
                    break;
                case "weights":
                    indexOptions.weights((Bson) value);
                    break;
                case "languageOverride":
                    indexOptions.languageOverride(value.toString());
                    break;
                case "defaultLanguage":
                    indexOptions.defaultLanguage(value.toString());
                    break;
                case "textVersion":
                    indexOptions.textVersion(Integer.parseInt(value.toString()));
                    break;
                case "sphereVersion":
                    indexOptions.sphereVersion(Integer.parseInt(value.toString()));
                    break;
                case "bits":
                    indexOptions.bits(Integer.parseInt(value.toString()));
                    break;
                case "min":
                    indexOptions.min(Double.parseDouble(value.toString()));
                    break;
                case "max":
                    indexOptions.max(Double.parseDouble(value.toString()));
                    break;
                case "bucketSize":
                    indexOptions.bucketSize(Double.parseDouble(value.toString()));
                    break;
                case "partialFilterExpression":
                    indexOptions.partialFilterExpression((Bson) value);
                    break;
                case "collation":
                    DBObject collationOptions = (DBObject) value;
                    Collation.Builder builder = Collation.builder();
                    for (String collationKey : collationOptions.keySet()) {
                        String collationObj = value.toString();
                        switch (collationKey) {
                        case "locale":
                            builder.locale(collationObj);
                            break;
                        case "caseLevel":
                            builder.caseLevel(Boolean.parseBoolean(collationObj));
                            break;
                        case "caseFirst":
                            builder.collationCaseFirst(CollationCaseFirst.fromString(collationObj));
                            break;
                        case "strength":
                            builder.collationStrength(CollationStrength.valueOf(collationObj));
                            break;
                        case "numericOrdering":
                            builder.numericOrdering(Boolean.parseBoolean(collationObj));
                            break;
                        case "normalization":
                            builder.normalization(Boolean.parseBoolean(collationObj));
                            break;
                        case "backwards":
                            builder.backwards(Boolean.parseBoolean(collationObj));
                            break;
                        case "alternate":
                            builder.collationAlternate(CollationAlternate.fromString(collationObj));
                            break;
                        case "maxVariable":
                            builder.collationMaxVariable(CollationMaxVariable.fromString(collationObj));
                            break;
                        default:
                            log.warn("Annotation 'IndexBy' for the field '" + fieldName + "' contains "
                                    + "unknown 'Collation' Option key : '" + collationKey + "'. Please "
                                    + "check your query and try again.");
                            break;
                        }
                    }
                    if (builder.build().getLocale() != null) {
                        indexOptions.collation(builder.build());
                    } else {
                        throw new MongoTableException("Annotation 'IndexBy' for the field '" + fieldName + "'"
                                + " do not contain option for locale. Please check your query and try again.");
                    }
                    break;
                case "storageEngine":
                    indexOptions.storageEngine((Bson) value);
                    break;
                default:
                    log.warn("Annotation 'IndexBy' for the field '" + fieldName + "' contains unknown option "
                            + "key : '" + indexEntry.getKey() + "'. Please check your query and try again.");
                    break;
                }
            }
        } catch (JsonParseException | NumberFormatException e) {
            throw new MongoTableException("Annotation 'IndexBy' for the field '" + fieldName + "' contains "
                    + "illegal value(s) for index option. Please check your query and try again.", e);
        }
        return new IndexModel(indexDocument, indexOptions);
    }
}