Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   *      Copyright (C) 2012 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.driver.core;
 
 import java.util.Map;
Describes a keyspace defined in this cluster.
 
 public class KeyspaceMetadata {
 
     public static final String KS_NAME           = "keyspace_name";
     private static final String DURABLE_WRITES   = "durable_writes";
     private static final String STRATEGY_CLASS   = "strategy_class";
     private static final String STRATEGY_OPTIONS = "strategy_options";
 
     private final String name;
     private final boolean durableWrites;
     private final Map<StringStringreplication = new HashMap<StringString>();
     private final Map<StringTableMetadatatables = new ConcurrentHashMap<StringTableMetadata>();
 
     private KeyspaceMetadata(String nameboolean durableWrites) {
         this. = name;
         this. = durableWrites;
     }
 
     static KeyspaceMetadata build(Row row) {
 
         String name = row.getString();
         boolean durableWrites = row.getBool();
         KeyspaceMetadata ksm = new KeyspaceMetadata(namedurableWrites);
         ksm.replication.put("class"row.getString());
         ksm.replication.putAll(TableMetadata.fromJsonMap(row.getString()));
         return ksm;
     }

    
Returns the name of this keyspace.

Returns:
the name of this CQL keyspace.
 
     public String getName() {
         return ;
     }

    
Returns whether durable writes are set on this keyspace.

Returns:
true if durable writes are set on this keyspace (the default), false otherwise.
 
     public boolean isDurableWrites() {
         return ;
     }

    
Returns the replication options for this keyspace.

Returns:
a map containing the replication options for this keyspace.
 
     public Map<StringStringgetReplication() {
         return Collections.<StringString>unmodifiableMap();
     }

    
Returns the metadata for a table contained in this keyspace.

Parameters:
name the name of table to retrieve
Returns:
the metadata for table name in this keyspace if it exists, false otherwise.
 
     public TableMetadata getTable(String name) {
         return .get(name);
     }

    
Returns the tables defined in this keyspace.

Returns:
a collection of the metadata for the tables defined in this keyspace.
 
     public Collection<TableMetadatagetTables() {
        return Collections.<TableMetadata>unmodifiableCollection(.values());
    }

    
Returns a String containing CQL queries representing this keyspace and the table it contains. In other words, this method returns the queries that would allow to recreate the schema of this keyspace, along with all its table. Note that the returned String is formatted to be human readable (for some definition of human readable at least).

Returns:
the CQL queries representing this keyspace schema as a {code String}.
    public String exportAsString() {
        StringBuilder sb = new StringBuilder();
        sb.append(asCQLQuery()).append("\n");
        for (TableMetadata tm : .values())
            sb.append("\n").append(tm.exportAsString()).append("\n");
        return sb.toString();
    }

    
Returns a CQL query representing this keyspace. This method returns a single 'CREATE KEYSPACE' query with the options corresponding to this keyspace definition.

Returns:
the 'CREATE KEYSPACE' query corresponding to this keyspace.
See also:
exportAsString()
    public String asCQLQuery() {
        StringBuilder sb = new StringBuilder();
        sb.append("CREATE KEYSPACE ").append().append(" WITH ");
        sb.append("REPLICATION = { 'class' : '").append(.get("class")).append("'");
        for (Map.Entry<StringStringentry : .entrySet()) {
            if (entry.getKey().equals("class"))
                continue;
            sb.append(", '").append(entry.getKey()).append("': '").append(entry.getValue()).append("'");
        }
        sb.append(" } AND DURABLE_WRITES = ").append();
        sb.append(";");
        return sb.toString();
    }
    void add(TableMetadata tm) {
        .put(tm.getName(), tm);
    }
New to GrepCode? Check out our FAQ X