com.datastax.driver.core.TupleValue Java Examples

The following examples show how to use com.datastax.driver.core.TupleValue. 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: EnqueuedMailsDaoUtil.java    From james-project with Apache License 2.0 5 votes vote down vote up
private static PerRecipientHeaders fromList(List<TupleValue> list) {
    PerRecipientHeaders result = new PerRecipientHeaders();

    list.forEach(tuple ->
        result.addHeaderForRecipient(
            PerRecipientHeaders.Header.builder()
                .name(tuple.getString(HEADER_NAME_INDEX))
                .value(tuple.getString(HEADER_VALUE_INDEX))
                .build(),
            toMailAddress(tuple.getString(USER_INDEX))));
    return result;
}
 
Example #2
Source File: CassandraEnumerator.java    From calcite with Apache License 2.0 5 votes vote down vote up
/** Convert an object into the expected internal representation.
 *
 * @param obj Object to convert, if needed
 */
private Object convertToEnumeratorObject(Object obj) {
  if (obj instanceof ByteBuffer) {
    ByteBuffer buf = (ByteBuffer) obj;
    byte [] bytes = new byte[buf.remaining()];
    buf.get(bytes, 0, bytes.length);
    return new ByteString(bytes);
  } else if (obj instanceof LocalDate) {
    // converts dates to the expected numeric format
    return ((LocalDate) obj).getMillisSinceEpoch()
        / DateTimeUtils.MILLIS_PER_DAY;
  } else if (obj instanceof Date) {
    return ((Date) obj).toInstant().toEpochMilli();
  } else if (obj instanceof LinkedHashSet) {
    // MULTISET is handled as an array
    return ((LinkedHashSet) obj).toArray();
  } else if (obj instanceof TupleValue) {
    // STRUCT can be handled as an array
    final TupleValue tupleValue = (TupleValue) obj;
    int numComponents = tupleValue.getType().getComponentTypes().size();
    return IntStream.range(0, numComponents)
        .mapToObj(i ->
            tupleValue.get(i,
                CassandraSchema.CODEC_REGISTRY.codecFor(
                    tupleValue.getType().getComponentTypes().get(i)))
        ).map(this::convertToEnumeratorObject)
        .toArray();
  }

  return obj;
}
 
Example #3
Source File: ConverterToTupleValueMapper.java    From SimpleFlatMapper with MIT License 5 votes vote down vote up
@Override
public TupleValue convert(I in, Context context) throws Exception {
    if (in == null) return null;
    TupleValue tv = tupleType.newValue();
    mapper.mapTo(in, tv, null);
    return tv;
}
 
Example #4
Source File: TupleValueSettableDataSetter.java    From SimpleFlatMapper with MIT License 5 votes vote down vote up
@Override
public void set(SettableByIndexData target, TupleValue value) throws Exception {
    if (value == null) {
        target.setToNull(index);
    } else {
        target.setTupleValue(index, value);
    }
}
 
Example #5
Source File: EnqueuedMailsDaoUtil.java    From james-project with Apache License 2.0 5 votes vote down vote up
static ImmutableList<TupleValue> toTupleList(TupleType userHeaderNameHeaderValueTriple, PerRecipientHeaders perRecipientHeaders) {
    return perRecipientHeaders.getHeadersByRecipient()
        .entries()
        .stream()
        .map(entry -> userHeaderNameHeaderValueTriple.newValue(entry.getKey().asString(), entry.getValue().getName(), entry.getValue().getValue()))
        .collect(Guavate.toImmutableList());
}
 
Example #6
Source File: CassandraMailRepositoryMailDaoV2.java    From james-project with Apache License 2.0 5 votes vote down vote up
private PerRecipientHeaders fromList(List<TupleValue> list) {
    PerRecipientHeaders result = new PerRecipientHeaders();

    list.forEach(tuple ->
            result.addHeaderForRecipient(
                Header.builder()
                    .name(tuple.getString(HEADER_NAME_INDEX))
                    .value(tuple.getString(HEADER_VALUE_INDEX))
                    .build(),
                toMailAddress(tuple.getString(USER_INDEX))));
    return result;
}
 
Example #7
Source File: CassandraMailRepositoryMailDaoV2.java    From james-project with Apache License 2.0 5 votes vote down vote up
private ImmutableList<TupleValue> toTupleList(PerRecipientHeaders perRecipientHeaders) {
    return perRecipientHeaders.getHeadersByRecipient()
        .entries()
        .stream()
        .map(entry -> userHeaderNameHeaderValueTriple.newValue(entry.getKey().asString(), entry.getValue().getName(), entry.getValue().getValue()))
        .collect(Guavate.toImmutableList());
}
 
Example #8
Source File: CassandraMailRepositoryMailDaoV2.java    From james-project with Apache License 2.0 5 votes vote down vote up
private MailDTO toMail(Row row) {
    MaybeSender sender = MaybeSender.getMailSender(row.getString(SENDER));
    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, String> rawAttributes = row.getMap(ATTRIBUTES, String.class, String.class);
    PerRecipientHeaders perRecipientHeaders = fromList(row.getList(PER_RECIPIENT_SPECIFIC_HEADERS, TupleValue.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 #9
Source File: MetadataRow.java    From cassandra-jdbc-wrapper with Apache License 2.0 4 votes vote down vote up
public TupleValue getTupleValue(String name) {
	return null;
}
 
Example #10
Source File: MetadataRow.java    From cassandra-jdbc-wrapper with Apache License 2.0 4 votes vote down vote up
public TupleValue getTupleValue(int i) {
	return null;
}
 
Example #11
Source File: JdbcTuple.java    From cassandra-jdbc-wrapper with Apache License 2.0 4 votes vote down vote up
@Override
public String toString(TupleValue obj) {
	// TODO Auto-generated method stub
	return obj.toString();
}
 
Example #12
Source File: EnqueuedMailsDaoUtil.java    From james-project with Apache License 2.0 4 votes vote down vote up
static EnqueuedItemWithSlicingContext toEnqueuedMail(Row row, BlobId.Factory blobFactory) {
    MailQueueName queueName = MailQueueName.fromString(row.getString(QUEUE_NAME));
    EnqueueId enqueueId = EnqueueId.of(row.getUUID(ENQUEUE_ID));
    Instant timeRangeStart = row.getTimestamp(TIME_RANGE_START).toInstant();
    BucketedSlices.BucketId bucketId = BucketedSlices.BucketId.of(row.getInt(BUCKET_ID));
    Instant enqueuedTime = row.getTimestamp(ENQUEUED_TIME).toInstant();
    BlobId headerBlobId = blobFactory.from(row.getString(HEADER_BLOB_ID));
    BlobId bodyBlobId = blobFactory.from(row.getString(BODY_BLOB_ID));
    MimeMessagePartsId mimeMessagePartsId = MimeMessagePartsId
        .builder()
        .headerBlobId(headerBlobId)
        .bodyBlobId(bodyBlobId)
        .build();

    MailAddress sender = Optional.ofNullable(row.getString(SENDER))
        .map(Throwing.function(MailAddress::new))
        .orElse(null);
    List<MailAddress> recipients = row.getList(RECIPIENTS, String.class)
        .stream()
        .map(Throwing.function(MailAddress::new))
        .collect(ImmutableList.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(NAME);
    Date lastUpdated = row.getTimestamp(LAST_UPDATED);
    Map<String, ByteBuffer> rawAttributes = row.getMap(ATTRIBUTES, String.class, ByteBuffer.class);
    PerRecipientHeaders perRecipientHeaders = fromList(row.getList(PER_RECIPIENT_SPECIFIC_HEADERS, TupleValue.class));

    MailImpl mail = MailImpl.builder()
        .name(name)
        .sender(sender)
        .addRecipients(recipients)
        .lastUpdated(lastUpdated)
        .errorMessage(errorMessage)
        .remoteHost(remoteHost)
        .remoteAddr(remoteAddr)
        .state(state)
        .addAllHeadersForRecipients(perRecipientHeaders)
        .addAttributes(toAttributes(rawAttributes))
        .build();
    EnqueuedItem enqueuedItem = EnqueuedItem.builder()
        .enqueueId(enqueueId)
        .mailQueueName(queueName)
        .mail(mail)
        .enqueuedTime(enqueuedTime)
        .mimeMessagePartsId(mimeMessagePartsId)
        .build();


    return EnqueuedItemWithSlicingContext.builder()
        .enqueuedItem(enqueuedItem)
        .slicingContext(EnqueuedItemWithSlicingContext.SlicingContext.of(bucketId, timeRangeStart))
        .build();
}
 
Example #13
Source File: JdbcTuple.java    From cassandra-jdbc-wrapper with Apache License 2.0 4 votes vote down vote up
public Class<TupleValue> getType()
{
    return TupleValue.class;
}
 
Example #14
Source File: JdbcTuple.java    From cassandra-jdbc-wrapper with Apache License 2.0 4 votes vote down vote up
@Override
public int getPrecision(TupleValue obj) {
	// TODO Auto-generated method stub
	return -1;
}
 
Example #15
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 #16
Source File: DatastaxTupleValueGetter.java    From SimpleFlatMapper with MIT License 4 votes vote down vote up
@Override
public TupleValue get(GettableByIndexData target) throws Exception {
    return target.getTupleValue(index);
}
 
Example #17
Source File: JdbcTuple.java    From cassandra-jdbc-wrapper with Apache License 2.0 4 votes vote down vote up
@Override
public int getScale(TupleValue obj) {
	// TODO Auto-generated method stub
	return -1;
}
 
Example #18
Source File: ConverterToTupleValueMapper.java    From SimpleFlatMapper with MIT License 4 votes vote down vote up
public ConverterToTupleValueMapper(FieldMapper<I, TupleValue> mapper, TupleType tupleType) {
    this.mapper = mapper;
    this.tupleType = tupleType;
}
 
Example #19
Source File: JdbcTuple.java    From cassandra-jdbc-wrapper with Apache License 2.0 4 votes vote down vote up
public Object decompose(TupleValue value)
{
    return (Object) value;
}
 
Example #20
Source File: DbObjectsWithTupleValue.java    From SimpleFlatMapper with MIT License 4 votes vote down vote up
public TupleValue getT() {
    return t;
}
 
Example #21
Source File: DbObjectsWithTupleValue.java    From SimpleFlatMapper with MIT License 4 votes vote down vote up
public void setT(TupleValue t) {
    this.t = t;
}
 
Example #22
Source File: MockRow.java    From hawkular-metrics with Apache License 2.0 4 votes vote down vote up
@Override
public TupleValue getTupleValue(int i) {
    throw new UnsupportedOperationException();
}
 
Example #23
Source File: MockRow.java    From hawkular-metrics with Apache License 2.0 4 votes vote down vote up
@Override
public TupleValue getTupleValue(String name) {
    throw new UnsupportedOperationException();
}
 
Example #24
Source File: JdbcTuple.java    From cassandra-jdbc-wrapper with Apache License 2.0 4 votes vote down vote up
public TupleValue compose(Object obj)
{
    return (TupleValue)obj;
}