/** * Performs all metadata operations necessary to create a table index * * @param tableId The id of the table to create the index * @param indexSchema The {@link com.nearinfinity.honeycomb.mysql.schema.IndexSchema} representing the index details, not null */ public void createTableIndex(final long tableId, final IndexSchema indexSchema) { Verify.isValidId(tableId); checkNotNull(indexSchema, "The index schema is invalid"); final List<Put> puts = Lists.newArrayList(); final List<IndexSchema> indexDetailMap = ImmutableList.of(indexSchema); // Update the table schema to store the new index schema details final TableSchema existingSchema = getSchema(tableId); final TableSchema updatedSchema = existingSchema.schemaCopy(); updatedSchema.addIndices(indexDetailMap); // Write the updated table schema and created index puts.add(putTableSchema(tableId, updatedSchema)); puts.add(putIndices(tableId, indexDetailMap)); performMutations(ImmutableList.<Delete>of(), puts); }
@Test(expected = NullPointerException.class) public void testAddIndicesInvalidIndices() { tableSchema.addIndices(null); }
@Test public void testAddIndicesValidIndex() { final List<IndexSchema> indices = Lists.newArrayList(); final TableSchema schema = new TableSchema(COLUMNS, indices); assertEquals(0, schema.getIndices().size()); schema.addIndices(INDICES); assertEquals(INDICES.size(), schema.getIndices().size()); }