public class SingleTypeModule extends Object implements co.cask.cdap.api.dataset.module.DatasetModule
Dataset into a DatasetModule.
This allows for easier implementation of simple datasets without requiring to implement DatasetDefinition,
DatasetAdmin, etc. when the implementation uses existing dataset types.
NOTE: all admin ops of the dataset will be delegated to embedded datasets;
DatasetProperties will be propagated to embedded datasets as well
NOTE: must have exactly one constructor with parameter types of
(DatasetSpecification, [0..n] @EmbeddedDataset Dataset)
Example of usage:
// ...
datasetFramework.addModule("myModule", new SingleTypeModule(SimpleKVTable.class));
// ...
@DatasetType("KVTable")
public class SimpleKVTable extends AbstractDataset implements KeyValueTable {
private static final byte[] COL = new byte[0];
private final Table table;
public SimpleKVTable(DatasetSpecification spec,
@EmbeddedDataset("data") Table table) {
super(spec.getTransactionAwareName(), table);
this.table = table;
}
public void put(String key, String value) throws Exception {
table.put(Bytes.toBytes(key), COL, Bytes.toBytes(value));
}
public String get(String key) throws Exception {
byte[] value = table.get(Bytes.toBytes(key), COL);
return value == null ? null : Bytes.toString(value);
}
}
See DatasetType and EmbeddedDataset for more details on their usage.| Constructor and Description |
|---|
SingleTypeModule(Class<? extends co.cask.cdap.api.dataset.Dataset> dataSetClass) |
| Modifier and Type | Method and Description |
|---|---|
Class<? extends co.cask.cdap.api.dataset.Dataset> |
getDataSetClass() |
void |
register(co.cask.cdap.api.dataset.module.DatasetDefinitionRegistry registry) |
public SingleTypeModule(Class<? extends co.cask.cdap.api.dataset.Dataset> dataSetClass)
public Class<? extends co.cask.cdap.api.dataset.Dataset> getDataSetClass()
public void register(co.cask.cdap.api.dataset.module.DatasetDefinitionRegistry registry)
register in interface co.cask.cdap.api.dataset.module.DatasetModuleCopyright © 2016 Cask Data, Inc. Licensed under the Apache License, Version 2.0.