use of io.cdap.cdap.spi.data.common.StructuredTableRegistry in project cdap by caskdata.
the class SqlStructuredTableRegistry method createRegistryTable.
private void createRegistryTable() throws IOException {
// Use a no-op registry to create PostgresSqlStructuredTableAdmin.
// During a table creation, except for registerSpecification and getSpecification, no other methods on the
// registry will be called by PostgresSqlStructuredTableAdmin. Since we always check existence before we create
// the registry table, we can safely return null for the getSpecification method.
StructuredTableRegistry noOpRegistry = new StructuredTableRegistry() {
final UnsupportedOperationException exception = new UnsupportedOperationException("Not expected to be called during creation of registry!");
@Override
public void registerSpecification(StructuredTableSpecification specification) {
// Do nothing
}
@Nullable
@Override
public StructuredTableSpecification getSpecification(StructuredTableId tableId) {
return null;
}
@Override
public void removeSpecification(StructuredTableId tableId) {
throw exception;
}
@Override
public boolean isEmpty() {
throw exception;
}
};
try {
// Create the table if needed
PostgreSqlStructuredTableAdmin admin = new PostgreSqlStructuredTableAdmin(noOpRegistry, dataSource);
if (!admin.tableExists(REGISTRY)) {
LOG.info("Creating SQL table {}", REGISTRY);
admin.create(SPEC);
}
} catch (TableAlreadyExistsException e) {
// Looks like the table was created concurrently by some other process
LOG.debug(String.format("Got exception when trying to create table %s", REGISTRY), e);
}
}
Aggregations