All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.datastax.stargate.sdk.rest.domain.CreateIndex Maven / Gradle / Ivy

There is a newer version: 2.3.7
Show newest version
/*
 * Copyright DataStax, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.datastax.stargate.sdk.rest.domain;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

/**
 * Creation request for an INDEX.
 *
 * @author Cedrick LUNVEN (@clunven)
 */
public class CreateIndex implements Serializable {

    /** Serial Number. */
    private static final long serialVersionUID = -5374080080154230782L;
    
    /** Limited values for the kind. */
    private static enum IndexKind { KEYS, VALUES, ENTRIES, FULL }
    
    /** Constant for a SASI index. */
    public static final String TYPE_SASI = "org.apache.cassandra.index.sasi.SASIIndex";
    
    /** Constant for a SAI index. */
    public static final String TYPE_SAI  = "org.apache.cassandra.index.sai.StorageAttachedIndex";
    
    /** Identifer of the index. */
    private String name;
    
    /** Name of the column. */
    private final String column;
  
    /** CREATE IF NOT EXIST. */
    private final boolean ifNotExists;
    
    /** Custom type. */
    private final String type;
    
    /** Default value for index. */
    private final IndexKind kind;
    
    /** Index options. */
    private final Map options;

    /**
     * Constructor.
     * @param builder
     */
    private CreateIndex(CreateIndexBuilder builder) {
        this.name         = builder.name;
        this.column       = builder.column;
        this.ifNotExists  = builder.ifNotExists;
        this.type         = builder.type;
        this.kind         = builder.kind;
        this.options      = builder.options;
    }
    
    public static CreateIndexBuilder builder() {
        return new CreateIndexBuilder();
    }
    
    public static class CreateIndexBuilder {
        boolean ifNotExists = false;
        String name;
        String column;
        String type = null;
        IndexKind kind = null;
        Map options = null;
        
        public CreateIndex build() {
            return new CreateIndex(this);
        }
        public CreateIndexBuilder ifNotExist(boolean ine) {
            this.ifNotExists = ine;
            return this;
        }
        public CreateIndexBuilder name(String name) {
            this.name = name;
            return this;
        }
        public CreateIndexBuilder type(String t) {
            this.type = t;
            return this;
        }
        public CreateIndexBuilder sasi() {
            return type(TYPE_SASI);
        }
        public CreateIndexBuilder column(String name) {
            this.column = name;
            return this;
        }
        public CreateIndexBuilder kind(IndexKind k) {
            this.kind = k;
            return this;
        }
        public CreateIndexBuilder addOption(String key, String value) {
            if (options == null) {
                options = new HashMap<>();
            }
            this.options.put(key, value);
            return this;
        }
    }

    /**
     * Getter accessor for attribute 'name'.
     *
     * @return
     *       current value of 'name'
     */
    public String getName() {
        return name;
    }

    /**
     * Getter accessor for attribute 'column'.
     *
     * @return
     *       current value of 'column'
     */
    public String getColumn() {
        return column;
    }

    /**
     * Getter accessor for attribute 'ifNotExists'.
     *
     * @return
     *       current value of 'ifNotExists'
     */
    public boolean isIfNotExists() {
        return ifNotExists;
    }

    /**
     * Getter accessor for attribute 'type'.
     *
     * @return
     *       current value of 'type'
     */
    public String getType() {
        return type;
    }

    /**
     * Getter accessor for attribute 'kind'.
     *
     * @return
     *       current value of 'kind'
     */
    public IndexKind getKind() {
        return kind;
    }

    /**
     * Getter accessor for attribute 'options'.
     *
     * @return
     *       current value of 'options'
     */
    public Map getOptions() {
        return options;
    }

    /**
     * Setter accessor for attribute 'name'.
     * @param name
     * 		new value for 'name '
     */
    public void setName(String name) {
        this.name = name;
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy