Package org.apache.cassandra.db

Examples of org.apache.cassandra.db.RowMutation


    public void insert(String tablename, String key, String columnFamily_column, byte[] cellData, long timestamp)
  {
    try
    {
      validateTable(tablename);
      RowMutation rm = new RowMutation(tablename, key.trim());
      rm.add(columnFamily_column, cellData, timestamp);
      StorageProxy.insert(rm);
    }
    catch (Exception e)
    {
      logger_.debug( LogUtil.throwableToString(e) );
View Full Code Here


  }
   
    public boolean batch_insert_blocking(batch_mutation_t batchMutation)
    {
        logger_.debug("batch_insert_blocking");
        RowMutation rm = RowMutation.getRowMutation(batchMutation);
        return StorageProxy.insertBlocking(rm);
    }
View Full Code Here

    }

  public void batch_insert(batch_mutation_t batchMutation)
  {
        logger_.debug("batch_insert");
        RowMutation rm = RowMutation.getRowMutation(batchMutation);
        StorageProxy.insert(rm);
  }
View Full Code Here

  }

    public boolean remove(String tablename, String key, String columnFamily_column, long timestamp, boolean block)
  {
        logger_.debug("remove");
        RowMutation rm = new RowMutation(tablename, key.trim());
        rm.delete(columnFamily_column, timestamp);
        if (block) {
            return StorageProxy.insertBlocking(rm);
        } else {
            StorageProxy.insert(rm);
            return true;
View Full Code Here

    }
   
    public boolean batch_insert_superColumn_blocking(batch_mutation_super_t batchMutationSuper)
    {
        logger_.debug("batch_insert_SuperColumn_blocking");
        RowMutation rm = RowMutation.getRowMutation(batchMutationSuper);
        return StorageProxy.insertBlocking(rm);
    }
View Full Code Here

    }

    public void batch_insert_superColumn(batch_mutation_super_t batchMutationSuper)
    {
        logger_.debug("batch_insert_SuperColumn");
        RowMutation rm = RowMutation.getRowMutation(batchMutationSuper);
        StorageProxy.insert(rm);
    }
View Full Code Here

                new FileInputStream(rootDirectory)), 16 * 1024 * 1024);
        String line = null;
        while ((line = bufReader.readLine()) != null)
        {
                String userId = line;
                RowMutation rm = new RowMutation(table, userId);
                rm.add(cfName, userId.getBytes(), 0);
                rm.apply();
        }
    }
View Full Code Here

            if ( file.isDirectory() )
                preParse(file, table, cfName);
            else
            {
                String fileName = file.getName();
                RowMutation rm = new RowMutation(table, fileName);
                rm.add(cfName, fileName.getBytes(), 0);
                rm.apply();
            }
        }
    }
View Full Code Here

    {
        BufferedReader bufReader = new BufferedReader(new InputStreamReader(
                new FileInputStream(filepath)), 16 * 1024 * 1024);
        String line = null;
        String delimiter_ = new String(",");
        RowMutation rm = null;
        Map<String, RowMutation> rms = new HashMap<String, RowMutation>();
        if(importer_.columnFamily.delimiter != null)
        {
          delimiter_ = importer_.columnFamily.delimiter;
        }
        while ((line = bufReader.readLine()) != null)
        {
            StringTokenizer st = new StringTokenizer(line, delimiter_);
            List<String> tokenList = new ArrayList<String>();
            String key = null;
            while (st.hasMoreElements())
            {
              tokenList.add((String)st.nextElement());
            }
            /* Construct the Key */
            List<String> keyFields = new ArrayList<String> ();
            for(int fieldId: importer_.key.fields.field)
            {
              keyFields.add(tokenList.get(fieldId));
            }
            key = merge(keyFields, importer_.key.combiner);
            if(importer_.key.optimizeIt != null && !importer_.key.optimizeIt)
            {
              if(!checkIfProcessKey(key))
              {
                continue;
              }
            }
            rm = rms.get(key);
            if( rm == null)
            {
              rm = new RowMutation(importer_.table, key);
              rms.put(key, rm);
            }
            if(importer_.columnFamily.superColumn != null)
            {
              List<String> superColumnList = new ArrayList<String>();
              for(int fieldId : importer_.columnFamily.superColumn.fields.field)
              {
                superColumnList.add(tokenList.get(fieldId));
              }
              String superColumnName = merge(superColumnList, " ");
              superColumnList.clear();
              if(importer_.columnFamily.superColumn.tokenize)
              {
                  Analyzer analyzer = new StandardAnalyzer();
                  TokenStream ts = analyzer.tokenStream("superColumn", new StringReader(superColumnName));
                  Token token = null;
                  token = ts.next();
                  while(token != null)
                  {
                    superColumnList.add(token.termText());
                      token = ts.next();
                  }
              }
              else
              {
                superColumnList.add(superColumnName);
              }
              for(String sName : superColumnList)
              {
                String cfName = importer_.columnFamily.name + ":" + sName;
                  if(importer_.columnFamily.column != null)
                  {
                    for(ColumnType column : importer_.columnFamily.column )
                    {
                      String cfColumn = cfName +":" + (column.name == null ? tokenList.get(column.field):column.name);
                      rm.add(cfColumn, tokenList.get(column.value.field).getBytes(), Integer.parseInt(tokenList.get(column.timestamp.field)));
                    }
                  }
               
              }
             
            }
            else
            {
              if(importer_.columnFamily.column != null)
              {
                for(ColumnType column : importer_.columnFamily.column )
                {
                  String cfColumn = importer_.columnFamily.name +":" + (column.name == null ? tokenList.get(column.field):column.name);
                  rm.add(cfColumn, tokenList.get(column.value.field).getBytes(), Integer.parseInt(tokenList.get(column.timestamp.field)));
                }
              }
            }
        }
        // Now apply the data for all keys 
        // TODO : Add checks for large data
        // size maybe we want to check the
        // data size and then apply.
        Set<String> keys = rms.keySet();
        for(String pKey : keys)
        {
          rm = rms.get(pKey);
          if( rm != null)
          {
            rm.apply();
          }
        }
    }
View Full Code Here

    public RowMutation mutationForKey(CFDefinition cfDef, ClientState clientState, ByteBuffer key, ColumnNameBuilder builder, List<ByteBuffer> variables)
    throws InvalidRequestException
    {
        QueryProcessor.validateKey(key);
        RowMutation rm = new RowMutation(cfDef.cfm.ksName, key);

        if (columns.isEmpty() && builder.componentCount() == 0)
        {
            // No columns, delete the row
            rm.delete(new QueryPath(columnFamily()), getTimestamp(clientState));
        }
        else
        {
            for (ColumnIdentifier column : columns)
            {
                CFDefinition.Name name = cfDef.get(column);
                if (name == null)
                    throw new InvalidRequestException(String.format("Unknown identifier %s", column));

                // For compact, we only have one value except the key, so the only form of DELETE that make sense is without a column
                // list. However, we support having the value name for coherence with the static/sparse case
                if (name.kind != CFDefinition.Name.Kind.COLUMN_METADATA && name.kind != CFDefinition.Name.Kind.VALUE_ALIAS)
                    throw new InvalidRequestException(String.format("Invalid identifier %s for deletion (should not be a PRIMARY KEY part)", column));
            }

            if (cfDef.isCompact)
            {
                    ByteBuffer columnName = builder.build();
                    QueryProcessor.validateColumnName(columnName);
                    rm.delete(new QueryPath(columnFamily(), null, columnName), getTimestamp(clientState));
            }
            else
            {
                // Delete specific columns
                Iterator<ColumnIdentifier> iter = columns.iterator();
                while (iter.hasNext())
                {
                    ColumnIdentifier column = iter.next();
                    ColumnNameBuilder b = iter.hasNext() ? builder.copy() : builder;
                    ByteBuffer columnName = b.add(column.key).build();
                    QueryProcessor.validateColumnName(columnName);
                    rm.delete(new QueryPath(columnFamily(), null, columnName), getTimestamp(clientState));
                }
            }
        }

        return rm;
View Full Code Here

TOP

Related Classes of org.apache.cassandra.db.RowMutation

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.