MysqlKeyProvider implements KeyProvider<Mutation<?>, String> { @Override public String get(@NonNull final Mutation<?> mutation) { Preconditions.checkState(mutation instanceof MysqlMutation); final MysqlMutation mysqlMutation = (MysqlMutation) mutation; final Table table = mysqlMutation.getMetadata().getTable(); final Row row = mysqlMutation.getRow(); return String.format( "%s:%s:%s", table.getDatabase(), table.getName(), row.getPrimaryKeyValue()); }  @Override String get(@NonNull final Mutation<?> mutation); static final MysqlKeyProvider INSTANCE; }
@Test public void testGetKey() throws Exception { Row row = new Row( TABLE, ImmutableMap.of(ID_COLUMN, new Column(TABLE.getColumns().get(ID_COLUMN), 1234))); MysqlMutation mutation = new MysqlInsertMutation(MUTATION_METADATA, row); assertEquals("test:users:1234", MysqlKeyProvider.INSTANCE.get(mutation)); }
@Test public void testGetNullKey() throws Exception { Row row = new Row( TABLE, ImmutableMap.of(ID_COLUMN, new Column(TABLE.getColumns().get(ID_COLUMN), null))); MysqlMutation mutation = new MysqlInsertMutation(MUTATION_METADATA, row); assertEquals("test:users:null", MysqlKeyProvider.INSTANCE.get(mutation)); }