Java 类com.datastax.driver.core.TypeCodec 实例源码

项目:cassandra-client    文件:ConnectionManager.java   
private TableColumn<ConnectionData, String> buildColumn(String name, int columnWidth, Function<ConnectionData,
        String> extractor) {
    TableColumn<ConnectionData, String> column = new TableColumn<>();
    Label columnLabel = new Label(name);
    column.setCellFactory(cellFactory(TypeCodec.varchar()));

    column.setCellValueFactory(param -> {
        String field = extractor.apply(param.getValue());
        return new SimpleObjectProperty<>(field);
    });

    column.setOnEditCommit(event -> log.info("edit"));
    column.setGraphic(columnLabel);
    column.setMinWidth(columnWidth);
    return column;
}
项目:zipkin    文件:DefaultSessionFactory.java   
private static void initializeUDTs(Session session) {
  Schema.ensureExists(DEFAULT_KEYSPACE + "_udts", session);
  MappingManager mapping = new MappingManager(session);

  // The UDTs are hardcoded against the zipkin keyspace.
  // If a different keyspace is being used the codecs must be re-applied to this different keyspace
  TypeCodec<TraceIdUDT> traceIdCodec = mapping.udtCodec(TraceIdUDT.class);
  TypeCodec<EndpointUDT> endpointCodec = mapping.udtCodec(EndpointUDT.class);
  TypeCodec<AnnotationUDT> annoCodec = mapping.udtCodec(AnnotationUDT.class);
  TypeCodec<BinaryAnnotationUDT> bAnnoCodec = mapping.udtCodec(BinaryAnnotationUDT.class);

  KeyspaceMetadata keyspace =
      session.getCluster().getMetadata().getKeyspace(session.getLoggedKeyspace());

  session.getCluster().getConfiguration().getCodecRegistry()
      .register(
          new TypeCodecImpl(keyspace.getUserType("trace_id"), TraceIdUDT.class, traceIdCodec))
      .register(
          new TypeCodecImpl(keyspace.getUserType("endpoint"), EndpointUDT.class, endpointCodec))
      .register(
          new TypeCodecImpl(keyspace.getUserType("annotation"), AnnotationUDT.class, annoCodec))
      .register(
          new TypeCodecImpl(keyspace.getUserType("binary_annotation"), BinaryAnnotationUDT.class,
              bAnnoCodec));
}
项目:emodb    文件:AdaptiveResultSetTest.java   
private String verifyNextRow(ResultSet rs) {
    String rowid = null;
    for (int col=0; col < 137; col++) {
        Row row = rs.one();
        assertNotNull(row);

        if (rowid == null) {
            rowid = row.get("rowid", TypeCodec.varchar());
        } else {
            assertEquals(row.get("rowid", TypeCodec.varchar()), rowid);
        }

        assertEquals((long) row.get("col", TypeCodec.bigint()), col);
        assertEquals( row.get("data", TypeCodec.blob()).asIntBuffer().get(), col);
    }

    return rowid;
}
项目:apex-malhar    文件:AbstractUpsertOutputOperator.java   
private void registerCodecs()
{
  complexTypeCodecs = getCodecsForUserDefinedTypes();
  if (complexTypeCodecs != null) {
    CodecRegistry registry = cluster.getConfiguration().getCodecRegistry();
    if (cluster.getConfiguration().getProtocolOptions().getProtocolVersion().toInt() < 4) {
      LOG.error("Custom codecs are not supported for protocol version < 4");
      throw new RuntimeException("Custom codecs are not supported for protocol version < 4");
    }
    for (String typeCodecStr : complexTypeCodecs.keySet()) {
      TypeCodec codec = complexTypeCodecs.get(typeCodecStr);
      registry.register(codec);
      userDefinedTypesClass.put(typeCodecStr, codec.getJavaType().getRawType());
    }
  } else {
    complexTypeCodecs = new HashMap<>();
  }
}
项目:apex-malhar    文件:UserUpsertOperator.java   
@Override
public Map<String, TypeCodec> getCodecsForUserDefinedTypes()
{
  Map<String, TypeCodec> allCodecs = new HashMap<>();
  CodecRegistry codecRegistry = cluster.getConfiguration().getCodecRegistry();

  UserType addressType = cluster.getMetadata().getKeyspace(getConnectionStateManager().getKeyspaceName())
      .getUserType("address");
  TypeCodec<UDTValue> addressTypeCodec = codecRegistry.codecFor(addressType);
  AddressCodec addressCodec = new AddressCodec(addressTypeCodec, Address.class);
  allCodecs.put("currentaddress", addressCodec);

  UserType userFullNameType = cluster.getMetadata().getKeyspace(getConnectionStateManager().getKeyspaceName())
      .getUserType("fullname");
  TypeCodec<UDTValue> userFullNameTypeCodec = codecRegistry.codecFor(userFullNameType);
  FullNameCodec fullNameCodec = new FullNameCodec(userFullNameTypeCodec, FullName.class);
  allCodecs.put("username", fullNameCodec);

  return allCodecs;
}
项目:cassandra-client    文件:UIUtil.java   
public static <S, T> Callback<TableColumn<S, T>, TableCell<S, T>> cellFactory(
        TypeCodec<T> codec) {
    return TextFieldTableCell.forTableColumn(new StringConverter<T>() {
        @Override
        public String toString(T object) {
            return codec.format(object);
        }

        @Override
        public T fromString(String string) {
            return codec.parse(string);
        }
    });
}
项目:cassandra-client    文件:NePredicate.java   
@Override
public boolean test(DataObject data) {
    TypeCodec<?> typeCodec = getColumnCodec(data.get(getField()));

    Object expected = typeCodec.parse(getValue());
    Object actual = data.get(getField());
    if (expected instanceof Comparable && actual instanceof Comparable) {
        //noinspection unchecked
        return Comparable.class.cast(actual).compareTo(expected) != 0;
    } else {
        return expected != actual;
    }
}
项目:cassandra-client    文件:LtPredicate.java   
@Override
public boolean test(DataObject data) {
    TypeCodec<?> typeCodec = getColumnCodec(data.get(getField()));

    Object expected = typeCodec.parse(getValue());
    Object actual = data.get(getField());
    if (expected instanceof Comparable && actual instanceof Comparable) {
        //noinspection unchecked
        return Comparable.class.cast(actual).compareTo(expected) < 0;
    } else {
        return false;
    }
}
项目:cassandra-client    文件:LePredicate.java   
@Override
public boolean test(DataObject data) {
    TypeCodec<?> typeCodec = getColumnCodec(data.get(getField()));

    Object expected = typeCodec.parse(getValue());
    Object actual = data.get(getField());
    if (expected instanceof Comparable && actual instanceof Comparable) {
        //noinspection unchecked
        return Comparable.class.cast(actual).compareTo(expected) <= 0;
    } else {
        return false;
    }
}
项目:cassandra-client    文件:GePredicate.java   
@Override
public boolean test(DataObject data) {
    TypeCodec<?> typeCodec = getColumnCodec(data.get(getField()));

    Object expected = typeCodec.parse(getValue());
    Object actual = data.get(getField());
    if (expected instanceof Comparable && actual instanceof Comparable) {
        //noinspection unchecked
        return Comparable.class.cast(actual).compareTo(expected) >= 0;
    } else {
        return false;
    }
}
项目:cassandra-client    文件:GtPredicate.java   
@Override
public boolean test(DataObject data) {
    TypeCodec<?> typeCodec = getColumnCodec(data.get(getField()));

    Object expected = typeCodec.parse(getValue());
    Object actual = data.get(getField());
    if (expected instanceof Comparable && actual instanceof Comparable) {
        //noinspection unchecked
        return Comparable.class.cast(actual).compareTo(expected) > 0;
    } else {
        return false;
    }
}
项目:iotplatform    文件:CassandraAbstractDao.java   
private void registerCodecIfNotFound(CodecRegistry registry, TypeCodec<?> codec) {
    try {
        registry.codecFor(codec.getCqlType(), codec.getJavaType());
    } catch (CodecNotFoundException e) {
        registry.register(codec);
    }
}
项目:scylla-tools-java    文件:UDHelper.java   
static TypeCodec<Object>[] codecsFor(DataType[] dataType)
{
    TypeCodec<Object>[] codecs = new TypeCodec[dataType.length];
    for (int i = 0; i < dataType.length; i++)
        codecs[i] = codecFor(dataType[i]);
    return codecs;
}
项目:scylla-tools-java    文件:UDHelper.java   
/**
 * Construct an array containing the Java classes for the given Java Driver {@link com.datastax.driver.core.DataType}s.
 *
 * @param dataTypes  array with UDF argument types
 * @param calledOnNullInput whether to allow {@code null} as an argument value
 * @return array of same size with UDF arguments
 */
public static Class<?>[] javaTypes(TypeCodec<Object>[] dataTypes, boolean calledOnNullInput)
{
    Class<?>[] paramTypes = new Class[dataTypes.length];
    for (int i = 0; i < paramTypes.length; i++)
    {
        Class<?> clazz = asJavaClass(dataTypes[i]);
        if (!calledOnNullInput)
        {
            // only care about classes that can be used in a data type
            if (clazz == Integer.class)
                clazz = int.class;
            else if (clazz == Long.class)
                clazz = long.class;
            else if (clazz == Byte.class)
                clazz = byte.class;
            else if (clazz == Short.class)
                clazz = short.class;
            else if (clazz == Float.class)
                clazz = float.class;
            else if (clazz == Double.class)
                clazz = double.class;
            else if (clazz == Boolean.class)
                clazz = boolean.class;
        }
        paramTypes[i] = clazz;
    }
    return paramTypes;
}
项目:scylla-tools-java    文件:UDHelper.java   
public static ByteBuffer serialize(TypeCodec<?> codec, int protocolVersion, Object value)
{
    if (!codec.getJavaType().getRawType().isAssignableFrom(value.getClass()))
        throw new InvalidTypeException("Invalid value for CQL type " + codec.getCqlType().getName().toString());

    return ((TypeCodec)codec).serialize(value, ProtocolVersion.fromInt(protocolVersion));
}
项目:scylla-tools-java    文件:UDFunction.java   
static void initializeThread()
{
    // Get the TypeCodec stuff in Java Driver initialized.
    // This is to get the classes loaded outside of the restricted sandbox's security context of a UDF.
    TypeCodec.inet().format(InetAddress.getLoopbackAddress());
    TypeCodec.ascii().format("");
}
项目:Troilus    文件:UDTValueMapper.java   
/**
    * Serialize a field using the data type passed.
    * @param dataType
    * @param value
    * @return
    */
   @SuppressWarnings("unchecked")
public <T> ByteBuffer serialize(DataType dataType, Object value) {
       final CodecRegistry codecRegistry = getCodecRegistry();
       final TypeCodec<T> typeCodec = codecRegistry.codecFor(dataType);
    return typeCodec.serialize((T)value, protocolVersion);
   }
项目:act-platform    文件:CassandraEnumCodec.java   
public CassandraEnumCodec(Class<E> enumClass, Map<Integer, E> enumValueMap) {
  this(TypeCodec.cint(), enumClass, enumValueMap);
}
项目:act-platform    文件:CassandraEnumCodec.java   
public CassandraEnumCodec(TypeCodec<Integer> innerCodec, Class<E> enumClass, Map<Integer, E> enumValueMap) {
  super(innerCodec.getCqlType(), enumClass);
  this.enumValueMap = enumValueMap;
  this.innerCodec = innerCodec;
}
项目:cassandra-client    文件:RowPredicate.java   
TypeCodec<?> getColumnCodec(Object actual) {
    return getCodecRegistry().codecFor(actual);
}
项目:cassandra-client    文件:EqPredicate.java   
@Override
public boolean test(DataObject data) {
    TypeCodec<?> typeCodec = getColumnCodec(data.get(getField()));
    Object typedValue = typeCodec.parse(getValue());
    return Objects.equals(typedValue, data.get(getField()));
}
项目:zipkin    文件:Schema.java   
public TypeCodecImpl(DataType cqlType, Class<T> javaClass, TypeCodec<T> codec) {
  super(cqlType, javaClass);
  this.codec = codec;
}
项目:AbacusUtil    文件:CassandraExecutor.java   
public UDTCodec(TypeCodec<UDTValue> innerCodec, Class<T> javaType) {
    super(innerCodec.getCqlType(), javaType);
    this.innerCodec = innerCodec;
    this.userType = (UserType) innerCodec.getCqlType();
    this.javaType = javaType;
}
项目:AbacusUtil    文件:CassandraExecutor.java   
public UDTCodec(final Cluster cluster, final String keySpace, final String userType, Class<T> javaType) {
    this(TypeCodec.userType(cluster.getMetadata().getKeyspace(keySpace).getUserType(userType)), javaType);
}
项目:apex-malhar    文件:AddressCodec.java   
public AddressCodec(TypeCodec<UDTValue> innerCodec, Class<Address> javaType)
{
  super(innerCodec.getCqlType(), javaType);
  this.innerCodec = innerCodec;
  this.userType = (UserType)innerCodec.getCqlType();
}
项目:apex-malhar    文件:CounterColumnUpdatesOperator.java   
@Override
public Map<String, TypeCodec> getCodecsForUserDefinedTypes()
{
  return null;
}
项目:apex-malhar    文件:CompositePrimaryKeyUpdateOperator.java   
@Override
public Map<String, TypeCodec> getCodecsForUserDefinedTypes()
{
  return null;
}
项目:apex-malhar    文件:FullNameCodec.java   
public FullNameCodec(TypeCodec<UDTValue> innerCodec, Class<FullName> javaType)
{
  super(innerCodec.getCqlType(), javaType);
  this.innerCodec = innerCodec;
  this.userType = (UserType)innerCodec.getCqlType();
}
项目:datacollector    文件:UUIDAsStringCodec.java   
public UUIDAsStringCodec() {
  super(TypeCodec.uuid(), String.class);
}
项目:datacollector    文件:LocalDateAsDateCodec.java   
public LocalDateAsDateCodec() {
  super(TypeCodec.date(), Date.class);
}
项目:datacollector    文件:TimeUUIDAsStringCodec.java   
public TimeUUIDAsStringCodec() {
  super(TypeCodec.timeUUID(), String.class);
}
项目:scylla-tools-java    文件:UDHelper.java   
static TypeCodec<Object> codecFor(DataType dataType)
{
    return codecRegistry.codecFor(dataType);
}
项目:scylla-tools-java    文件:UDHelper.java   
public static Object deserialize(TypeCodec<?> codec, int protocolVersion, ByteBuffer value)
{
    return codec.deserialize(value, ProtocolVersion.fromInt(protocolVersion));
}
项目:scylla-tools-java    文件:UDHelper.java   
public static Class<?> asJavaClass(TypeCodec<?> codec)
{
    return codec.getJavaType().getRawType();
}
项目:scylla-tools-java    文件:JavaUDF.java   
protected JavaUDF(TypeCodec<Object> returnCodec, TypeCodec<Object>[] argCodecs)
{
    this.returnCodec = returnCodec;
    this.argCodecs = argCodecs;
}
项目:scylla-tools-java    文件:UDFunction.java   
protected static Object compose(TypeCodec<Object>[] codecs, int protocolVersion, int argIndex, ByteBuffer value)
{
    return value == null ? null : UDHelper.deserialize(codecs[argIndex], protocolVersion, value);
}
项目:scylla-tools-java    文件:UDFunction.java   
protected static ByteBuffer decompose(TypeCodec<Object> codec, int protocolVersion, Object value)
{
    return value == null ? null : UDHelper.serialize(codec, protocolVersion, value);
}
项目:scylla-tools-java    文件:CqlRecordReader.java   
@Override
public <T> T get(int i, TypeCodec<T> typeCodec)
{
    return row.get(i, typeCodec);
}
项目:scylla-tools-java    文件:CqlRecordReader.java   
@Override
public <T> T get(String s, TypeCodec<T> typeCodec)
{
    return row.get(s, typeCodec);
}
项目:scylla-tools-java    文件:ClassWithInitializer3.java   
public ClassWithInitializer3(TypeCodec<Object> returnDataType, TypeCodec<Object>[] argDataTypes)
{
    super(returnDataType, argDataTypes);
}