Package me.prettyprint.cassandra.model

Examples of me.prettyprint.cassandra.model.BasicColumnFamilyDefinition


    }
   
    // load column family definitions
    List<Element> elements = keyspace.getChildren();
    for (Element element: elements) {
      BasicColumnFamilyDefinition cfDef = new BasicColumnFamilyDefinition();
     
      String familyName = element.getAttributeValue(NAME_ATTRIBUTE);
      if (familyName == null) {
        LOG.error("Error locating column family name attribute!");
        continue;
      } else {
        if (LOG.isDebugEnabled()) {
          LOG.debug("Located column family: '" + familyName + "'" );
        }
      }
      String superAttribute = element.getAttributeValue(SUPER_ATTRIBUTE);
      if (superAttribute != null) {
        if (LOG.isDebugEnabled()) {
          LOG.debug("Located super column family");
        }
        this.superFamilies.add(familyName);
        if (LOG.isDebugEnabled()) {
          LOG.debug("Added super column family: '" + familyName + "'");
        }
        cfDef.setColumnType(ColumnType.SUPER);
        cfDef.setSubComparatorType(ComparatorType.BYTESTYPE);
      }
     
      cfDef.setKeyspaceName(this.keyspaceName);
      cfDef.setName(familyName);
      cfDef.setComparatorType(ComparatorType.BYTESTYPE);
      cfDef.setDefaultValidationClass(ComparatorType.BYTESTYPE.getClassName());
     
      this.columnFamilyDefinitions.put(familyName, cfDef);

    }
   
    // load column definitions   
    elements = mapping.getChildren();
    for (Element element: elements) {
      String fieldName = element.getAttributeValue(NAME_ATTRIBUTE);
      String familyName = element.getAttributeValue(FAMILY_ATTRIBUTE);
      String columnName = element.getAttributeValue(COLUMN_ATTRIBUTE);
      if (fieldName == null) {
       LOG.error("Field name is not declared.");
        continue;
      }
      if (familyName == null) {
        LOG.error("Family name is not declared for \"" + fieldName + "\" field.");
        continue;
      }
      if (columnName == null) {
        LOG.warn("Column name (qualifier) is not declared for \"" + fieldName + "\" field.");
        columnName = fieldName;
      }

      BasicColumnFamilyDefinition columnFamilyDefinition = this.columnFamilyDefinitions.get(familyName);
      if (columnFamilyDefinition == null) {
        LOG.warn("Family " + familyName + " was not declared in the keyspace.");
      }
     
      this.familyMap.put(fieldName, familyName);
View Full Code Here


  }
 
  @Test
  public void testEditKeyspace() throws Exception {
       
    BasicColumnFamilyDefinition columnFamilyDefinition = new BasicColumnFamilyDefinition();
    columnFamilyDefinition.setKeyspaceName("DynKeyspace2");
    columnFamilyDefinition.setName("DynamicCF");   
   
    ColumnFamilyDefinition cfDef = new ThriftCfDef(columnFamilyDefinition);
   
    KeyspaceDefinition keyspaceDefinition =
        HFactory.createKeyspaceDefinition("DynKeyspace2", "org.apache.cassandra.locator.SimpleStrategy", 1, Arrays.asList(cfDef));
View Full Code Here

  }
 
  @Test
  public void testEditColumnFamily() throws Exception {
       
    BasicColumnFamilyDefinition columnFamilyDefinition = new BasicColumnFamilyDefinition();
    columnFamilyDefinition.setKeyspaceName("DynKeyspace3");
    columnFamilyDefinition.setName("DynamicCF");   
   
    ColumnFamilyDefinition cfDef = new ThriftCfDef(columnFamilyDefinition);
   
    KeyspaceDefinition keyspaceDefinition =
        HFactory.createKeyspaceDefinition("DynKeyspace3", "org.apache.cassandra.locator.SimpleStrategy", 1, Arrays.asList(cfDef));
   
    cassandraCluster.addKeyspace(keyspaceDefinition);
   
   
    KeyspaceDefinition fromCluster = cassandraCluster.describeKeyspace("DynKeyspace3");
    cfDef = fromCluster.getCfDefs().get(0);
   
    columnFamilyDefinition = new BasicColumnFamilyDefinition(cfDef);
    BasicColumnDefinition columnDefinition = new BasicColumnDefinition();
    columnDefinition.setName(StringSerializer.get().toByteBuffer("birthdate"));
    columnDefinition.setIndexType(ColumnIndexType.KEYS);
    columnDefinition.setValidationClass(ComparatorType.LONGTYPE.getClassName());
    columnFamilyDefinition.addColumnDefinition(columnDefinition);
   
   
    cassandraCluster.updateColumnFamily(new ThriftCfDef(columnFamilyDefinition));
   
    fromCluster = cassandraCluster.describeKeyspace("DynKeyspace3");
View Full Code Here

    private Keyspace getKeyspace() {
        Cluster cassandraCluster = HFactory.createCluster(
                Constants.CLUSTER_NAME, new CassandraHostConfigurator(Constants.CLUSTER_HOST), credentials);

        if (cassandraCluster.describeKeyspace(Constants.KEYSPACE_NAME) == null) {
            BasicColumnFamilyDefinition columnFamilyDefinition = new BasicColumnFamilyDefinition();
            columnFamilyDefinition.setKeyspaceName(Constants.KEYSPACE_NAME);
            columnFamilyDefinition.setName(Constants.COL_FAMILY_NAME);
            columnFamilyDefinition.setComparatorType(ComparatorType.LONGTYPE);

            ColumnFamilyDefinition cfDef = new ThriftCfDef(columnFamilyDefinition);

            KeyspaceDefinition keyspaceDefinition =
                    HFactory.createKeyspaceDefinition(Constants.KEYSPACE_NAME,
View Full Code Here

        String type = columnFamilyInformation.getType();
        if (type != null && !"".equals(type.trim())) {
            columnType = ColumnType.getFromValue(type.trim());
        }

        BasicColumnFamilyDefinition familyDefinition = new BasicColumnFamilyDefinition();   //TODO remove with a thrift cfd
        familyDefinition.setColumnType(columnType);
        familyDefinition.setId(columnFamilyInformation.getId());
        familyDefinition.setName(columnFamilyName);
        familyDefinition.setKeyspaceName(keyspaceName);
        familyDefinition.setKeyCacheSize(columnFamilyInformation.getKeyCacheSize());
        familyDefinition.setComment(columnFamilyInformation.getComment());
        familyDefinition.setGcGraceSeconds(columnFamilyInformation.getGcGraceSeconds());
        familyDefinition.setRowCacheSize(columnFamilyInformation.getRowCacheSize());
        familyDefinition.setReadRepairChance(columnFamilyInformation.getReadRepairChance());
        familyDefinition.setComparatorType(ComparatorType.getByClassName(columnFamilyInformation.getComparatorType()));
        if (ColumnType.SUPER == columnType) {
            familyDefinition.setSubComparatorType(
                    ComparatorType.getByClassName(columnFamilyInformation.getSubComparatorType()));
        } else {
            familyDefinition.setSubComparatorType(null);
        }
        familyDefinition.setMaxCompactionThreshold(columnFamilyInformation.getMaxCompactionThreshold());
        familyDefinition.setMinCompactionThreshold(columnFamilyInformation.getMinCompactionThreshold());

        String defaultValidationClass = columnFamilyInformation.getDefaultValidationClass();
        if (defaultValidationClass != null && !"".equals(defaultValidationClass.trim())) {
            familyDefinition.setDefaultValidationClass(defaultValidationClass.trim());
        }

        ColumnInformation[] columns = columnFamilyInformation.getColumns();
        if (columns != null && columns.length > 0) {
            for (ColumnInformation column : columns) {
                validateColumnInformation(column);

                BasicColumnDefinition columnDefinition = new BasicColumnDefinition();
                columnDefinition.setName(StringSerializer.get().toByteBuffer(column.getName().trim()));

                String indexName = column.getIndexName();
                if (indexName != null && !"".equals(indexName.trim())) {
                    columnDefinition.setIndexName(indexName.trim());
                }

                String validationClass = column.getValidationClass();
                if (validationClass != null && !"".equals(validationClass.trim())) {
                    columnDefinition.setValidationClass(validationClass.trim());
                }

                String indexType = column.getIndexType();
                if (indexType != null && !"".equals(indexType.trim())) {
                    columnDefinition.setIndexType(ColumnIndexType.valueOf(indexType.trim().toUpperCase()));
                }
                familyDefinition.addColumnDefinition(columnDefinition);
            }
        }

        try {
            Cluster cluster = getCluster(null);
View Full Code Here

                cfd = c;
                break;
            }
        }

        BasicColumnFamilyDefinition columnFamilyDefinition = new BasicColumnFamilyDefinition(cfd);

        BasicColumnDefinition bcdf = new BasicColumnDefinition();
        bcdf.setName(StringSerializer.get().toByteBuffer(idxColumnName));
        bcdf.setIndexName(idxColumnName + "index");
        bcdf.setIndexType(ColumnIndexType.KEYS);
        bcdf.setValidationClass(ComparatorType.UTF8TYPE.getClassName());

        columnFamilyDefinition.addColumnDefinition(bcdf);
        cluster.updateColumnFamily(new ThriftCfDef(columnFamilyDefinition));

    }
View Full Code Here

   
    // load column family definitions
    List<Element> elements = keyspace.getChildren();
    for (Element element: elements) {
      BasicColumnFamilyDefinition cfDef = new BasicColumnFamilyDefinition();
     
      String familyName = element.getAttributeValue(NAME_ATTRIBUTE);
      if (familyName == null) {
        LOG.error("Error locating column family name attribute!");
        continue;
      } else {
        if (LOG.isDebugEnabled()) {
          LOG.debug("Located column family: '" + familyName + "'" );
        }
      }
      String gcgrace_scs = element.getAttributeValue(GCGRACE_SECONDS_ATTRIBUTE);
      if (gcgrace_scs == null) {
        LOG.warn("Error locating gc_grace_seconds attribute for '" + familyName + "' column family");
        LOG.warn("Using gc_grace_seconds default value which is: " + DEFAULT_GCGRACE_SECONDS
            + " and is viable ONLY FOR A SINGLE NODE CLUSTER");
        LOG.warn("please update the gora-cassandra-mapping.xml file to avoid seeing this warning");
      } else {
        if (LOG.isDebugEnabled()) {
        LOG.debug("Located gc_grace_seconds: '" + gcgrace_scs + "'" );
        }
      }

      String superAttribute = element.getAttributeValue(SUPER_ATTRIBUTE);
      if (superAttribute != null) {
        if (LOG.isDebugEnabled()) {
          LOG.debug("Located super column family");
        }
        this.superFamilies.add(familyName);
        if (LOG.isDebugEnabled()) {
          LOG.debug("Added super column family: '" + familyName + "'");
        }
        cfDef.setColumnType(ColumnType.SUPER);
        cfDef.setSubComparatorType(ComparatorType.BYTESTYPE);
      }

      cfDef.setKeyspaceName(this.keyspaceName);
      cfDef.setName(familyName);
      cfDef.setComparatorType(ComparatorType.BYTESTYPE);
      cfDef.setDefaultValidationClass(ComparatorType.BYTESTYPE.getClassName());

      cfDef.setGcGraceSeconds(Integer.parseInt( gcgrace_scs!=null?gcgrace_scs:DEFAULT_GCGRACE_SECONDS));
      this.columnFamilyDefinitions.put(familyName, cfDef);

    }
   
    // load column definitions   
    elements = mapping.getChildren();
    for (Element element: elements) {
      String fieldName = element.getAttributeValue(NAME_ATTRIBUTE);
      String familyName = element.getAttributeValue(FAMILY_ATTRIBUTE);
      String columnName = element.getAttributeValue(COLUMN_ATTRIBUTE);
      String ttlValue = element.getAttributeValue(COLUMNS_TTL_ATTRIBUTE);
      if (fieldName == null) {
       LOG.error("Field name is not declared.");
        continue;
      }
      if (familyName == null) {
        LOG.error("Family name is not declared for \"" + fieldName + "\" field.");
        continue;
      }
      if (columnName == null) {
        LOG.warn("Column name (qualifier) is not declared for \"" + fieldName + "\" field.");
        columnName = fieldName;
      }
      if (ttlValue == null) {
        LOG.warn("TTL value is not defined for \"" + fieldName + "\" field. \n Using default value: " + DEFAULT_COLUMNS_TTL);
      }

      BasicColumnFamilyDefinition columnFamilyDefinition = this.columnFamilyDefinitions.get(familyName);
      if (columnFamilyDefinition == null) {
        LOG.warn("Family " + familyName + " was not declared in the keyspace.");
      }

      this.familyMap.put(fieldName, familyName);
View Full Code Here

    }
   
    // load column family definitions
    List<Element> elements = keyspace.getChildren();
    for (Element element: elements) {
      BasicColumnFamilyDefinition cfDef = new BasicColumnFamilyDefinition();
     
      String familyName = element.getAttributeValue(NAME_ATTRIBUTE);
      if (familyName == null) {
        LOG.warn("Error locating column family name attribute!");
      } else {
        // LOG.info("Located column family name: '" + NAME_ATTRIBUTE + "'");
      }
      String superAttribute = element.getAttributeValue(SUPER_ATTRIBUTE);
      if (superAttribute != null) {
      // LOG.info("Located super column family");
        this.superFamilies.add(familyName);
        // LOG.info("Added super column family: '" + familyName + "'");
        cfDef.setColumnType(ColumnType.SUPER);
        cfDef.setSubComparatorType(ComparatorType.BYTESTYPE);
      }
     
      cfDef.setKeyspaceName(this.keyspaceName);
      cfDef.setName(familyName);
      cfDef.setComparatorType(ComparatorType.BYTESTYPE);
      cfDef.setDefaultValidationClass(ComparatorType.BYTESTYPE.getClassName());
     
      this.columnFamilyDefinitions.put(familyName, cfDef);

    }
   
    // load column definitions   
    elements = mapping.getChildren();
    for (Element element: elements) {
      String fieldName = element.getAttributeValue(NAME_ATTRIBUTE);
      String familyName = element.getAttributeValue(FAMILY_ATTRIBUTE);
      String columnName = element.getAttributeValue(COLUMN_ATTRIBUTE);
      BasicColumnFamilyDefinition columnFamilyDefinition = this.columnFamilyDefinitions.get(familyName);
      if (columnFamilyDefinition == null) {
        LOG.warn("Family " + familyName + " was not declared in the keyspace.");
      }
     
      this.familyMap.put(fieldName, familyName);
View Full Code Here

            columnDefinition.setName(stringSerializer.toByteBuffer("birthdate"));
            columnDefinition.setIndexName("birthdate_idx");
            columnDefinition.setIndexType(ColumnIndexType.KEYS);
            columnDefinition.setValidationClass(ComparatorType.LONGTYPE.getClassName());
           
            BasicColumnFamilyDefinition columnFamilyDefinition = new BasicColumnFamilyDefinition();
            columnFamilyDefinition.setKeyspaceName(DYN_KEYSPACE);
            columnFamilyDefinition.setName(DYN_CF);
            columnFamilyDefinition.addColumnDefinition(columnDefinition);
           
            BasicColumnFamilyDefinition superCfDefinition = new BasicColumnFamilyDefinition();
            superCfDefinition.setKeyspaceName(DYN_KEYSPACE);
            superCfDefinition.setName(CF_SUPER);
            superCfDefinition.setColumnType(ColumnType.SUPER);
           
           
           
            ColumnFamilyDefinition cfDefStandard = new ThriftCfDef(columnFamilyDefinition);
            ColumnFamilyDefinition cfDefSuper = new ThriftCfDef(superCfDefinition);
View Full Code Here

                cfd = c;
                break;
            }
        }

        BasicColumnFamilyDefinition columnFamilyDefinition = new BasicColumnFamilyDefinition(cfd);

        BasicColumnDefinition bcdf = new BasicColumnDefinition();
        bcdf.setName(StringSerializer.get().toByteBuffer(idxColumnName));
        bcdf.setIndexName(idxColumnName + "index");
        bcdf.setIndexType(ColumnIndexType.KEYS);
        bcdf.setValidationClass(ComparatorType.UTF8TYPE.getClassName());

        columnFamilyDefinition.addColumnDefinition(bcdf);
        cluster.updateColumnFamily(new ThriftCfDef(columnFamilyDefinition));

    }
View Full Code Here

TOP

Related Classes of me.prettyprint.cassandra.model.BasicColumnFamilyDefinition

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.