com.datastax.driver.core.UDTValue Java Examples

The following examples show how to use com.datastax.driver.core.UDTValue. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: UserUpsertOperator.java    From attic-apex-malhar with Apache License 2.0 7 votes vote down vote up
@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;
}
 
Example #2
Source File: JobsService.java    From hawkular-metrics with Apache License 2.0 6 votes vote down vote up
static UDTValue getRepeatingTriggerValue(RxSession session, RepeatingTrigger trigger) {
    UserType triggerType = getKeyspace(session).getUserType("trigger_def");
    UDTValue triggerUDT = triggerType.newValue();
    triggerUDT.setInt("type", 1);
    triggerUDT.setLong("interval", trigger.getInterval());
    triggerUDT.setLong("trigger_time", trigger.getTriggerTime());
    if (trigger.getDelay() > 0) {
        triggerUDT.setLong("delay", trigger.getDelay());
    }
    if (trigger.getRepeatCount() != null) {
        triggerUDT.setInt("repeat_count", trigger.getRepeatCount());
        triggerUDT.setInt("execution_count", trigger.getExecutionCount());
    }

    return triggerUDT;
}
 
Example #3
Source File: JobsService.java    From hawkular-metrics with Apache License 2.0 6 votes vote down vote up
static Trigger getTrigger(UDTValue value) {
    int type = value.getInt("type");

    switch (type) {
        case 0:
            return new SingleExecutionTrigger(value.getLong("trigger_time"));
        case 1:
            return new RepeatingTrigger(
                    value.getLong("interval"),
                    value.getLong("delay"),
                    value.getLong("trigger_time"),
                    value.getInt("repeat_count"),
                    value.getInt("execution_count")
            );
        default:
            throw new IllegalArgumentException("Trigger type [" + type + "] is not supported");
    }
}
 
Example #4
Source File: ConverterToUDTValueMapper.java    From SimpleFlatMapper with MIT License 5 votes vote down vote up
@Override
public UDTValue convert(I in, Context context) throws Exception {
    if (in == null) return null;
    UDTValue udtValue = userType.newValue();
    mapper.mapTo(in, udtValue, null);
    return udtValue;
}
 
Example #5
Source File: CassandraMessageDAO.java    From james-project with Apache License 2.0 5 votes vote down vote up
private PropertyBuilder getPropertyBuilder(Row row) {
    PropertyBuilder property = new PropertyBuilder(
        row.getList(PROPERTIES, UDTValue.class).stream()
            .map(this::toProperty)
            .collect(Collectors.toList()));
    property.setTextualLineCount(row.getLong(TEXTUAL_LINE_COUNT));
    return property;
}
 
Example #6
Source File: CassandraMessageDAO.java    From james-project with Apache License 2.0 5 votes vote down vote up
private List<UDTValue> buildPropertiesUdt(MailboxMessage message) {
    return message.getProperties().stream()
        .map(property -> typesProvider.getDefinedUserType(PROPERTIES)
            .newValue()
            .setString(Properties.NAMESPACE, property.getNamespace())
            .setString(Properties.NAME, property.getLocalName())
            .setString(Properties.VALUE, property.getValue()))
        .collect(Guavate.toImmutableList());
}
 
Example #7
Source File: CassandraMessageDAO.java    From james-project with Apache License 2.0 5 votes vote down vote up
private UDTValue toUDT(MessageAttachmentMetadata messageAttachment) {
    UDTValue result = typesProvider.getDefinedUserType(ATTACHMENTS)
        .newValue()
        .setString(Attachments.ID, messageAttachment.getAttachmentId().getId())
        .setBool(Attachments.IS_INLINE, messageAttachment.isInline());
    messageAttachment.getName()
        .ifPresent(name -> result.setString(Attachments.NAME, name));
    messageAttachment.getCid()
        .ifPresent(cid -> result.setString(Attachments.CID, cid.getValue()));
    return result;
}
 
Example #8
Source File: CassandraMessageDAO.java    From james-project with Apache License 2.0 5 votes vote down vote up
private MessageAttachmentRepresentation messageAttachmentByIdFrom(UDTValue udtValue) {
    return MessageAttachmentRepresentation.builder()
        .attachmentId(AttachmentId.from(udtValue.getString(Attachments.ID)))
        .name(udtValue.getString(Attachments.NAME))
        .cid(cidParser.parse(udtValue.getString(CassandraMessageV2Table.Attachments.CID)))
        .isInline(udtValue.getBool(Attachments.IS_INLINE))
        .build();
}
 
Example #9
Source File: CassandraMailRepositoryMailDAO.java    From james-project with Apache License 2.0 5 votes vote down vote up
private MailDTO toMail(Row row) {
    MaybeSender sender = Optional.ofNullable(row.getString(SENDER))
        .map(MaybeSender::getMailSender)
        .orElse(MaybeSender.nullSender());
    List<MailAddress> recipients = row.getList(RECIPIENTS, String.class)
        .stream()
        .map(Throwing.function(MailAddress::new))
        .collect(Guavate.toImmutableList());
    String state = row.getString(STATE);
    String remoteAddr = row.getString(REMOTE_ADDR);
    String remoteHost = row.getString(REMOTE_HOST);
    String errorMessage = row.getString(ERROR_MESSAGE);
    String name = row.getString(MAIL_KEY);
    Date lastUpdated = row.getTimestamp(LAST_UPDATED);
    Map<String, ByteBuffer> rawAttributes = row.getMap(ATTRIBUTES, String.class, ByteBuffer.class);
    PerRecipientHeaders perRecipientHeaders = fromHeaderMap(row.getMap(PER_RECIPIENT_SPECIFIC_HEADERS, String.class, UDTValue.class));

    MailImpl.Builder mailBuilder = MailImpl.builder()
        .name(name)
        .sender(sender)
        .addRecipients(recipients)
        .lastUpdated(lastUpdated)
        .errorMessage(errorMessage)
        .remoteHost(remoteHost)
        .remoteAddr(remoteAddr)
        .state(state)
        .addAllHeadersForRecipients(perRecipientHeaders)
        .addAttributes(toAttributes(rawAttributes));

    return new MailDTO(mailBuilder,
        blobIdFactory.from(row.getString(HEADER_BLOB_ID)),
        blobIdFactory.from(row.getString(BODY_BLOB_ID)));
}
 
Example #10
Source File: CassandraMailRepositoryMailDAO.java    From james-project with Apache License 2.0 5 votes vote down vote up
private ImmutableMap<String, UDTValue> toHeaderMap(PerRecipientHeaders perRecipientHeaders) {
    return perRecipientHeaders.getHeadersByRecipient()
        .asMap()
        .entrySet()
        .stream()
        .flatMap(entry -> entry.getValue().stream().map(value -> Pair.of(entry.getKey(), value)))
        .map(entry -> Pair.of(entry.getKey().asString(),
            cassandraTypesProvider.getDefinedUserType(HEADER_TYPE)
                .newValue()
                .setString(HEADER_NAME, entry.getRight().getName())
                .setString(HEADER_VALUE, entry.getRight().getValue())))
        .collect(Guavate.toImmutableMap(Pair::getLeft, Pair::getRight));
}
 
Example #11
Source File: CassandraMailRepositoryMailDAO.java    From james-project with Apache License 2.0 5 votes vote down vote up
private PerRecipientHeaders fromHeaderMap(Map<String, UDTValue> rawMap) {
    PerRecipientHeaders result = new PerRecipientHeaders();

    rawMap.forEach((key, value) -> result.addHeaderForRecipient(PerRecipientHeaders.Header.builder()
            .name(value.getString(HEADER_NAME))
            .value(value.getString(HEADER_VALUE))
            .build(),
        toMailAddress(key)));
    return result;
}
 
Example #12
Source File: UDTValueSettableDataSetter.java    From SimpleFlatMapper with MIT License 5 votes vote down vote up
@Override
public void set(SettableByIndexData target, UDTValue value) throws Exception {
    if (value == null) {
        target.setToNull(index);
    } else {
        target.setUDTValue(index, value);
    }
}
 
Example #13
Source File: JobsService.java    From hawkular-metrics with Apache License 2.0 5 votes vote down vote up
static UDTValue getTriggerValue(RxSession session, Trigger trigger) {
    if (trigger instanceof RepeatingTrigger) {
        return getRepeatingTriggerValue(session, (RepeatingTrigger) trigger);
    }
    if (trigger instanceof SingleExecutionTrigger) {
        return getSingleExecutionTriggerValue(session, (SingleExecutionTrigger) trigger);
    }
    throw new IllegalArgumentException(trigger.getClass() + " is not a supported trigger type");
}
 
Example #14
Source File: JobsService.java    From hawkular-metrics with Apache License 2.0 5 votes vote down vote up
static UDTValue getSingleExecutionTriggerValue(RxSession session, SingleExecutionTrigger trigger) {
    UserType triggerType = getKeyspace(session).getUserType("trigger_def");
    UDTValue triggerUDT = triggerType.newValue();
    triggerUDT.setInt("type", 0);
    triggerUDT.setLong("trigger_time", trigger.getTriggerTime());

    return triggerUDT;
}
 
Example #15
Source File: AddressCodec.java    From attic-apex-malhar with Apache License 2.0 5 votes vote down vote up
protected UDTValue toUDTValue(Address value)
{
  return value == null ? null : userType.newValue()
    .setString("street", value.getStreet())
    .setInt("zip_code", value.getZip_code())
    .setString("city", value.getCity())
    .setSet("phones", value.getPhones());
}
 
Example #16
Source File: AddressCodec.java    From attic-apex-malhar with Apache License 2.0 5 votes vote down vote up
protected Address toAddress(UDTValue value)
{
  return value == null ? null : new Address(
    value.getString("city"),
    value.getString("street"),
    value.getInt("zip_code"),
    value.getSet("phones", String.class)
  );
}
 
Example #17
Source File: MockRow.java    From hawkular-metrics with Apache License 2.0 4 votes vote down vote up
@Override
public UDTValue getUDTValue(String name) {
    throw new UnsupportedOperationException();
}
 
Example #18
Source File: ConverterToUDTValueMapper.java    From SimpleFlatMapper with MIT License 4 votes vote down vote up
public ConverterToUDTValueMapper(FieldMapper<I, UDTValue> mapper, UserType userType) {
    this.mapper = mapper;
    this.userType = userType;
}
 
Example #19
Source File: DataTypeHelper.java    From SimpleFlatMapper with MIT License 4 votes vote down vote up
public static Class<?> asJavaClass(DataType.Name name) {
    if (name == null) return null;
    switch (name) {
        case ASCII:
            return String.class;
        case BIGINT:
            return Long.class;
        case BLOB:
            return ByteBuffer.class;
        case BOOLEAN:
            return Boolean.class;
        case COUNTER:
            return Long.class;
        case DECIMAL:
            return BigDecimal.class;
        case DOUBLE:
            return Double.class;
        case FLOAT:
            return Float.class;
        case INET:
            return InetAddress.class;
        case INT:
            return Integer.class;
        case LIST:
            return List.class;
        case MAP:
            return Map.class;
        case SET:
            return Set.class;
        case TEXT:
            return String.class;
        case TIMESTAMP:
            return Date.class;
        case TIMEUUID:
            return UUID.class;
        case UUID:
            return UUID.class;
        case VARCHAR:
            return String.class;
        case VARINT:
            return BigInteger.class;
        case UDT:
            return UDTValue.class;
        case TUPLE:
            return TupleValue.class;
        case CUSTOM:
            return ByteBuffer.class;
        case DATE:
            return LocalDate.class;
        case TIME:
            return Long.class;
        case SMALLINT:
            return Short.class;
        case TINYINT:
            return Byte.class;
    }

    return null;
}
 
Example #20
Source File: DbObjectsWithUDTValue.java    From SimpleFlatMapper with MIT License 4 votes vote down vote up
public UDTValue getT() {
    return t;
}
 
Example #21
Source File: DbObjectsWithUDTValue.java    From SimpleFlatMapper with MIT License 4 votes vote down vote up
public void setT(UDTValue t) {
    this.t = t;
}
 
Example #22
Source File: CassandraMessageDAO.java    From james-project with Apache License 2.0 4 votes vote down vote up
private Stream<MessageAttachmentRepresentation> attachmentByIds(List<UDTValue> udtValues) {
    return udtValues.stream()
        .map(this::messageAttachmentByIdFrom);
}
 
Example #23
Source File: CassandraMessageDAO.java    From james-project with Apache License 2.0 4 votes vote down vote up
private boolean hasAttachment(Row row) {
    List<UDTValue> udtValues = row.getList(ATTACHMENTS, UDTValue.class);
    return !udtValues.isEmpty();
}
 
Example #24
Source File: MockRow.java    From hawkular-metrics with Apache License 2.0 4 votes vote down vote up
@Override
public UDTValue getUDTValue(int i) {
    throw new UnsupportedOperationException();
}
 
Example #25
Source File: CassandraMessageDAO.java    From james-project with Apache License 2.0 4 votes vote down vote up
private Stream<MessageAttachmentRepresentation> getAttachments(Row row) {
    List<UDTValue> udtValues = row.getList(ATTACHMENTS, UDTValue.class);
    return attachmentByIds(udtValues);
}
 
Example #26
Source File: JdbcUdt.java    From cassandra-jdbc-wrapper with Apache License 2.0 4 votes vote down vote up
@Override
public int getScale(UDTValue obj) {
	// TODO Auto-generated method stub
	return -1;
}
 
Example #27
Source File: AddressCodec.java    From attic-apex-malhar with Apache License 2.0 4 votes vote down vote up
public AddressCodec(TypeCodec<UDTValue> innerCodec, Class<Address> javaType)
{
  super(innerCodec.getCqlType(), javaType);
  this.innerCodec = innerCodec;
  this.userType = (UserType)innerCodec.getCqlType();
}
 
Example #28
Source File: FullNameCodec.java    From attic-apex-malhar with Apache License 2.0 4 votes vote down vote up
public FullNameCodec(TypeCodec<UDTValue> innerCodec, Class<FullName> javaType)
{
  super(innerCodec.getCqlType(), javaType);
  this.innerCodec = innerCodec;
  this.userType = (UserType)innerCodec.getCqlType();
}
 
Example #29
Source File: FullNameCodec.java    From attic-apex-malhar with Apache License 2.0 4 votes vote down vote up
protected FullName toFullName(UDTValue value)
{
  return value == null ? null : new FullName(
    value.getString("firstname"),
    value.getString("lastname"));
}
 
Example #30
Source File: FullNameCodec.java    From attic-apex-malhar with Apache License 2.0 4 votes vote down vote up
protected UDTValue toUDTValue(FullName value)
{
  return value == null ? null : userType.newValue()
    .setString("lastname", value.getLastname())
    .setString("firstname", value.getFirstname());
}