private TableContainer getTableContainer(String projectId, String datasetId, String tableId) throws InterruptedException, IOException { synchronized (tables) { Map<String, TableContainer> dataset = tables.get(projectId, datasetId); if (dataset == null) { throwNotFound( "Tried to get a dataset %s:%s, but no such dataset was set", projectId, datasetId); } TableContainer tableContainer = dataset.get(tableId); if (tableContainer == null) { throwNotFound( "Tried to get a table %s:%s.%s, but no such table was set", projectId, datasetId, tableId); } return tableContainer; } }
@Override public void deleteTable(TableReference tableRef) throws IOException, InterruptedException { validateWholeTableReference(tableRef); synchronized (tables) { Map<String, TableContainer> dataset = tables.get(tableRef.getProjectId(), tableRef.getDatasetId()); if (dataset == null) { throwNotFound( "Tried to get a dataset %s:%s, but no such table was set", tableRef.getProjectId(), tableRef.getDatasetId()); } dataset.remove(tableRef.getTableId()); } }
@Override public Dataset getDataset(String projectId, String datasetId) throws IOException, InterruptedException { synchronized (tables) { Map<String, TableContainer> dataset = tables.get(projectId, datasetId); if (dataset == null) { throwNotFound( "Tried to get a dataset %s:%s, but no such table was set", projectId, datasetId); } return new Dataset() .setDatasetReference( new DatasetReference().setDatasetId(datasetId).setProjectId(projectId)); } }
@Override public Table getTable(TableReference tableRef) throws InterruptedException, IOException { synchronized (tables) { Map<String, TableContainer> dataset = tables.get(tableRef.getProjectId(), tableRef.getDatasetId()); if (dataset == null) { throwNotFound( "Tried to get a dataset %s:%s, but no such dataset was set", tableRef.getProjectId(), tableRef.getDatasetId()); } TableContainer tableContainer = dataset.get(tableRef.getTableId()); return tableContainer == null ? null : tableContainer.getTable(); } }
@Override public void createTable(Table table) throws IOException { TableReference tableReference = table.getTableReference(); validateWholeTableReference(tableReference); synchronized (tables) { Map<String, TableContainer> dataset = tables.get(tableReference.getProjectId(), tableReference.getDatasetId()); if (dataset == null) { throwNotFound( "Tried to get a dataset %s:%s, but no such table was set", tableReference.getProjectId(), tableReference.getDatasetId()); } dataset.computeIfAbsent(tableReference.getTableId(), k -> new TableContainer(table)); } }