com.datastax.driver.core.UserType Java Examples

The following examples show how to use com.datastax.driver.core.UserType. 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: DatastaxUDTGetter.java    From SimpleFlatMapper with MIT License 5 votes vote down vote up
public static <P> ContextualSourceMapper<GettableByIndexData, P> newUDTMapper(Type target, UserType tt, DatastaxMapperFactory factory) {
    ConstantSourceMapperBuilder<GettableByIndexData, P, DatastaxColumnKey> builder = newFieldMapperBuilder(factory, target);

    Iterator<UserType.Field> iterator = tt.iterator();
    int i = 0;
    while(iterator.hasNext()) {
        UserType.Field f = iterator.next();
        FieldMapperColumnDefinition<DatastaxColumnKey> identity = FieldMapperColumnDefinition.identity();
        builder.addMapping(new DatastaxColumnKey(f.getName(), i, f.getType()), identity);
        i ++;
    }

    return builder.mapper();
}
 
Example #4
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 #5
Source File: CassandraTypeTest.java    From james-project with Apache License 2.0 5 votes vote down vote up
@Test
void initializeShouldReturnAlreadyDoneWhenTypeExists() {
    KeyspaceMetadata keyspace = mock(KeyspaceMetadata.class);
    when(keyspace.getUserType(NAME)).thenReturn(mock(UserType.class));
    Session session = mock(Session.class);

    assertThat(TYPE.initialize(keyspace, session))
            .isEqualByComparingTo(ALREADY_DONE);

    verify(keyspace).getUserType(NAME);
    verify(session, never()).execute(STATEMENT);
}
 
Example #6
Source File: CassandraConnection.java    From cassandra-jdbc-wrapper with Apache License 2.0 5 votes vote down vote up
public Map<String, Class<?>> getTypeMap() throws SQLException
{
	HashMap<String, Class<?>> typeMap = new HashMap<String, Class<?>>();
	logger.info("current KS : " + currentKeyspace);
	Collection<UserType> types = this.metadata.getKeyspace(currentKeyspace).getUserTypes();
	for(UserType type:types){    		    		
		typeMap.put(type.getTypeName(), type.getClass());
	}

	return typeMap;
}
 
Example #7
Source File: CassandraZonedDateTimeModule.java    From james-project with Apache License 2.0 4 votes vote down vote up
static UDTValue toUDT(UserType zonedDateTimeUserType, ZonedDateTime zonedDateTime) {
    ZonedDateTimeRepresentation representation = ZonedDateTimeRepresentation.fromZonedDateTime(zonedDateTime);
    return zonedDateTimeUserType.newValue()
        .setTimestamp(CassandraZonedDateTimeModule.DATE, representation.getDate())
        .setString(CassandraZonedDateTimeModule.TIME_ZONE, representation.getSerializedZoneId());
}
 
Example #8
Source File: CassandraZonedDateTimeModule.java    From james-project with Apache License 2.0 4 votes vote down vote up
static Optional<UDTValue> toUDT(UserType zonedDateTimeUserType, Optional<ZonedDateTime> zonedDateTimeOptional) {
    return zonedDateTimeOptional.map(zonedDateTime -> toUDT(zonedDateTimeUserType, zonedDateTime));
}
 
Example #9
Source File: CassandraTypesProvider.java    From james-project with Apache License 2.0 4 votes vote down vote up
public UserType getDefinedUserType(String typeName) {
    return Optional.ofNullable(userTypes.get(typeName))
        .orElseThrow(() -> new RuntimeException("Cassandra UDT " + typeName + " can not be retrieved"));
}
 
Example #10
Source File: DatastaxUDTGetter.java    From SimpleFlatMapper with MIT License 4 votes vote down vote up
@SuppressWarnings("unchecked")
public static <P> Getter<GettableByIndexData, P> newInstance(DatastaxMapperFactory factory, Type target,  UserType tt, int index) {
    ContextualSourceMapper<GettableByIndexData, P> mapper = newUDTMapper(target, tt, factory);
    return new DatastaxUDTGetter<P>(mapper, index);
}
 
Example #11
Source File: CassandraTypeConverterTest.java    From debezium-incubator with Apache License 2.0 4 votes vote down vote up
@Test
public void testUdt() {
    // we can't create a UserType directly, and there isn't really a good way to make one some other way, so...
    // mock it!
    UserType userType = Mockito.mock(UserType.class);
    Mockito.when(userType.getName()).thenReturn(DataType.Name.UDT);
    Mockito.when(userType.getTypeName()).thenReturn("FooType");
    Mockito.when(userType.getKeyspace()).thenReturn("barspace");
    List<String> fieldNames = new ArrayList<>();
    fieldNames.add("asciiField");
    fieldNames.add("doubleField");
    Mockito.when(userType.getFieldNames()).thenReturn(fieldNames);
    Mockito.when(userType.getFieldType("asciiField")).thenReturn(DataType.ascii());
    Mockito.when(userType.getFieldType("doubleField")).thenReturn(DataType.cdouble());
    Mockito.when(userType.isFrozen()).thenReturn(false, true); // cheaty way to test non-frozen and then frozen path.

    ByteBuffer expectedTypeName = ByteBuffer.wrap("FooType".getBytes(Charset.defaultCharset()));
    List<FieldIdentifier> expectedFieldIdentifiers = new ArrayList<>();
    expectedFieldIdentifiers.add(new FieldIdentifier(ByteBuffer.wrap("asciiField".getBytes(Charset.defaultCharset()))));
    expectedFieldIdentifiers.add(new FieldIdentifier(ByteBuffer.wrap("doubleField".getBytes(Charset.defaultCharset()))));
    List<AbstractType<?>> expectedFieldTypes = new ArrayList<>();
    expectedFieldTypes.add(AsciiType.instance);
    expectedFieldTypes.add(DoubleType.instance);

    // non-frozen
    org.apache.cassandra.db.marshal.UserType expectedAbstractType = new org.apache.cassandra.db.marshal.UserType("barspace",
            expectedTypeName,
            expectedFieldIdentifiers,
            expectedFieldTypes,
            true);
    AbstractType<?> convertedType = CassandraTypeConverter.convert(userType);
    Assert.assertEquals(expectedAbstractType, convertedType);

    // frozen
    expectedAbstractType = new org.apache.cassandra.db.marshal.UserType("barspace",
            expectedTypeName,
            expectedFieldIdentifiers,
            expectedFieldTypes,
            false);
    convertedType = CassandraTypeConverter.convert(userType);
    Assert.assertEquals(expectedAbstractType, convertedType);
}
 
Example #12
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 #13
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 #14
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 #15
Source File: GCGraceSecondsManager.java    From hawkular-metrics with Apache License 2.0 2 votes vote down vote up
@Override
public void onUserTypeAdded(UserType type) {

}
 
Example #16
Source File: GCGraceSecondsManager.java    From hawkular-metrics with Apache License 2.0 2 votes vote down vote up
@Override
public void onUserTypeRemoved(UserType type) {

}
 
Example #17
Source File: GCGraceSecondsManager.java    From hawkular-metrics with Apache License 2.0 2 votes vote down vote up
@Override
public void onUserTypeChanged(UserType current, UserType previous) {

}
 
Example #18
Source File: DataAccessImpl.java    From hawkular-metrics with Apache License 2.0 votes vote down vote up
@Override public void onUserTypeAdded(UserType userType) {} 
Example #19
Source File: DataAccessImpl.java    From hawkular-metrics with Apache License 2.0 votes vote down vote up
@Override public void onUserTypeRemoved(UserType userType) {} 
Example #20
Source File: DataAccessImpl.java    From hawkular-metrics with Apache License 2.0 votes vote down vote up
@Override public void onUserTypeChanged(UserType userType, UserType userType1) {}