Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Licensed to STRATIO (C) under one or more contributor license agreements.
   * See the NOTICE file distributed with this work for additional information
   * regarding copyright ownership.  The STRATIO (C) licenses this file
   * to you 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.stratio.connector.commons.metadata;
 
 import java.util.List;
 import java.util.Map;
 
Builder for TableMetadata.

Author(s):
darroyo
 
 public class TableMetadataBuilder {
 
     private TableName tableName;
     private Map<SelectorSelectoroptions;
     private Map<IndexNameIndexMetadataindexes;
     private LinkedList<ColumnNamepartitionKey;
     private LinkedList<ColumnNameclusterKey;
     private ClusterName clusterName;

    

Deprecated:
use TableMetadataBuilder(java.lang.String,java.lang.String,java.lang.String) instead.
Parameters:
catalogName the catalog name
tableName the table name
 
     @Deprecated
     public TableMetadataBuilder(String catalogNameString tableName) {
         this. = new TableName(catalogNametableName);
          = new LinkedHashMap<ColumnNameColumnMetadata>();
          = new LinkedHashMap<IndexNameIndexMetadata>();
          = new LinkedList<ColumnName>();
          = new LinkedList<ColumnName>();
          = null;
     }

    
Instantiates a new table metadata builder.

Parameters:
catalogName the catalog name
tableName the table name
clusName the cluster name
 
     public TableMetadataBuilder(String catalogNameString tableNameString clusName) {
         this. = new ClusterName(clusName);
         this. = new TableName(catalogNametableName);
          = new LinkedHashMap<ColumnNameColumnMetadata>();
          = new LinkedHashMap<IndexNameIndexMetadata>();
          = new LinkedList<ColumnName>();
          = new LinkedList<ColumnName>();
          = null;
     }

    
Set the options. Any options previously created are removed.

Parameters:
opts the opts
Returns:
the table metadata builder
 
     public TableMetadataBuilder withOptions(Map<SelectorSelectoropts) {
          = new HashMap<SelectorSelector>(opts);
         return this;
    }

    
Add new columns. The columns previously created are not removed.

Parameters:
columnsMetadata the columns metadata
Returns:
the table metadata builder
    public TableMetadataBuilder withColumns(List<ColumnMetadatacolumnsMetadata) {
        for (ColumnMetadata colMetadata : columnsMetadata) {
            .put(colMetadata.getName(), colMetadata);
        }
        return this;
    }

    
Add column. Parameters in columnMetadata will be null.

Parameters:
columnName the column name
colType the column type
Returns:
the table metadata builder
    public TableMetadataBuilder addColumn(String columnNameColumnType colType) {
        ColumnName colName = new ColumnName(columnName);
        ColumnMetadata colMetadata = new ColumnMetadata(colNamenullcolType);
        .put(colNamecolMetadata);
        return this;
    }

    
Add an index. Must be called after including columns because columnMetadata is recovered from the tableMetadata. Options in indexMetadata will be null.

Parameters:
indType the index type
indexName the index name
fields the columns which define the index
Returns:
the table metadata builder
    public TableMetadataBuilder addIndex(IndexType indTypeString indexNameString... fields) {
        IndexName indName = new IndexName(.getName(), .getName(), indexName);
        Map<ColumnNameColumnMetadatacolumnsMetadata = new HashMap<ColumnNameColumnMetadata>(fields.length);
        // recover the columns from the table metadata
        for (String field : fields) {
            ColumnMetadata cMetadata = .get(new ColumnName(field));
            if (cMetadata == null) {
                throw new RuntimeException("Trying to index a not existing column: " + field);
            }
            columnsMetadata.put(new ColumnName(field), cMetadata);
        }
        IndexMetadata indMetadata = new IndexMetadata(indNamecolumnsMetadataindTypenull);
        .put(indNameindMetadata);
        return this;
    }

    
Add an index.

Parameters:
indexMetadata the index metadata
Returns:
the table metadata builder
    public TableMetadataBuilder addIndex(IndexMetadata indexMetadata) {
        .put(indexMetadata.getName(), indexMetadata);
        return this;
    }

    
Set the partition key.

Parameters:
fields the fields
Returns:
the table metadata builder
    public TableMetadataBuilder withPartitionKey(String... fields) {
        for (String field : fields) {
            .add(new ColumnName(field));
        }
        return this;
    }

    
Set the cluster key.

Parameters:
fields the fields
Returns:
the table metadata builder
    public TableMetadataBuilder withClusterKey(String... fields) {
        for (String field : fields) {
            .add(new ColumnName(field));
        }
        return this;
    }

    
Set the cluster name.

Deprecated:
use TableMetadataBuilder(java.lang.String,java.lang.String,java.lang.String) instead.
Parameters:
clusterName the cluster name
Returns:
the table metadata builder
    @Deprecated
    public TableMetadataBuilder withClusterNameRef(ClusterName clusterName) {
        this. = clusterName;
        return this;
    }

    
Builds the table metadata.

Returns:
the table metadata
    public TableMetadata build() {
        return build(false);
    }

    
Builds the table metadata.

Parameters:
isPKRequired whether the pk is required or not
Returns:
the table metadata
    public TableMetadata build(boolean isPKRequired) {
        if (isPKRequired && .isEmpty()) {
            this.withPartitionKey(.keySet().iterator().next().getName());
        }
    }
New to GrepCode? Check out our FAQ X