Ejemplo n.º 1
0
 public static Object getOriginalValueFromColumnValue(
     ByteBuffer byteBuffer, AttributeType attributeType) throws IOException {
   switch (attributeType) {
     case BOOL:
       {
         return booleanSerializer.fromByteBuffer(byteBuffer);
       }
     case INT:
       {
         return integerSerializer.fromByteBuffer(byteBuffer);
       }
     case DOUBLE:
       {
         return doubleSerializer.fromByteBuffer(byteBuffer);
       }
     case FLOAT:
       {
         return floatSerializer.fromByteBuffer(byteBuffer);
       }
     case LONG:
       {
         return longSerializer.fromByteBuffer(byteBuffer);
       }
     case STRING:
       {
         return stringSerializer.fromByteBuffer(byteBuffer);
       }
   }
   return null;
 }
Ejemplo n.º 2
0
 public void setBoolean(N columnName, Boolean value, int ttl) {
   addInsertion(columnName, value, BooleanSerializer.get(), ttl);
 }
Ejemplo n.º 3
0
 public void setBoolean(N columnName, Boolean value) {
   addInsertion(columnName, value, BooleanSerializer.get(), globalTtl);
 }
Ejemplo n.º 4
0
/**
 * Copyright (c) WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
 *
 * <p>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
 *
 * <p>http://www.apache.org/licenses/LICENSE-2.0
 *
 * <p>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.
 */
public class CassandraSDSUtils {
  public static String convertStreamNameToCFName(String streamName) {
    if (streamName == null) {
      return null;
    }
    int keySpaceLength = KeySpaceUtils.getKeySpaceName().length();
    if ((streamName.length() + keySpaceLength) > 48) {
      throw new RuntimeException(
          "The stream name you provided is too long. This has caused the"
              + " generated key (\""
              + streamName
              + "\") to go "
              + "beyond the allowed characters. of "
              + (48 - keySpaceLength));
    }
    return streamName.replace(":", "_").replace(".", "_");
  }

  public static long getLong(ByteBuffer byteBuffer) throws IOException {
    return longSerializer.fromByteBuffer(byteBuffer);
  }

  public static String getString(ByteBuffer byteBuffer) throws IOException {
    return stringSerializer.fromByteBuffer(byteBuffer);
  }

  private static final StringSerializer stringSerializer = StringSerializer.get();
  private static final IntegerSerializer integerSerializer = IntegerSerializer.get();
  private static final LongSerializer longSerializer = LongSerializer.get();
  private static final BooleanSerializer booleanSerializer = BooleanSerializer.get();
  private static final FloatSerializer floatSerializer = FloatSerializer.get();
  private static final DoubleSerializer doubleSerializer = DoubleSerializer.get();

  public static Object getOriginalValueFromColumnValue(
      ByteBuffer byteBuffer, AttributeType attributeType) throws IOException {
    switch (attributeType) {
      case BOOL:
        {
          return booleanSerializer.fromByteBuffer(byteBuffer);
        }
      case INT:
        {
          return integerSerializer.fromByteBuffer(byteBuffer);
        }
      case DOUBLE:
        {
          return doubleSerializer.fromByteBuffer(byteBuffer);
        }
      case FLOAT:
        {
          return floatSerializer.fromByteBuffer(byteBuffer);
        }
      case LONG:
        {
          return longSerializer.fromByteBuffer(byteBuffer);
        }
      case STRING:
        {
          return stringSerializer.fromByteBuffer(byteBuffer);
        }
    }
    return null;
  }

  public static String getColumnName(DataType dataType, Attribute attribute) {
    return dataType.name() + "_" + attribute.getName();
  }

  public static String createRowKey(long timestamp, String ip, int port, int count) {
    return timestamp + "::" + ip + "::" + port + "::" + count;
  }
}