@Test public void should_update_table_with_new_indexed_simple_field() throws Exception { // Given PropertyMeta idMeta = valueClass(Long.class).type(PARTITION_KEY).cqlColumnName("id").build(); PropertyMeta longColPM = valueClass(Long.class).type(SIMPLE).cqlColumnName("longcol").build(); longColPM.setIndexProperties(new IndexProperties("long_index", "longCol")); when(meta.getAllMetasExceptId()).thenReturn(asList(longColPM)); when(meta.getIdMeta()).thenReturn(idMeta); when(tableMeta.getColumns()).thenReturn(Arrays.<ColumnMetadata>asList()); // When updater.updateTableForEntity(session, meta, tableMeta); // Then verify(session, Mockito.times(2)).execute(stringCaptor.capture()); final List<String> updates = stringCaptor.getAllValues(); assertThat(updates.get(0)).isEqualTo("\n\tALTER TABLE tableName ADD longcol bigint"); assertThat(updates.get(1)).isEqualTo("\n\tCREATE INDEX long_index ON tableName(longcol)"); }
public PropertyMeta parse(PropertyParsingContext context) { log.debug( "Parsing property {} of entity class {}", context.getCurrentPropertyName(), context.getCurrentEntityClass().getCanonicalName()); Field field = context.getCurrentField(); inferPropertyName(context); context.setCustomConsistencyLevels(hasConsistencyAnnotation(context.getCurrentField())); validator.validateNoDuplicate(context); validator.validateIndexIfSet(context); Class<?> fieldType = field.getType(); PropertyMeta propertyMeta; if (List.class.isAssignableFrom(fieldType)) { propertyMeta = parseListProperty(context); } else if (Set.class.isAssignableFrom(fieldType)) { propertyMeta = parseSetProperty(context); } else if (Map.class.isAssignableFrom(fieldType)) { propertyMeta = parseMapProperty(context); } else if (Counter.class.isAssignableFrom(fieldType)) { propertyMeta = parseCounterProperty(context); } else if (context.isEmbeddedId()) { propertyMeta = parseEmbeddedId(context); } else if (context.isPrimaryKey()) { propertyMeta = parseId(context); } else { propertyMeta = parseSimpleProperty(context); String indexName = getIndexName(field); if (indexName != null) { propertyMeta.setIndexProperties(new IndexProperties(indexName)); } } context.getPropertyMetas().put(context.getCurrentPropertyName(), propertyMeta); return propertyMeta; }