public boolean createOrUpdate(StreamViewId viewId, ViewSpecification spec) throws Exception {
try {
ViewSpecification previousSpec = store.get(viewId);
if (spec.getTableName() == null) {
spec = new ViewSpecification(spec.getFormat(), previousSpec.getTableName());
} else if (!spec.getTableName().equals(previousSpec.getTableName())) {
throw new IllegalArgumentException(String.format("Cannot change table name for view %s", viewId));
}
explore.disableExploreStream(viewId.getParent(), previousSpec.getTableName());
} catch (NotFoundException e) {
}
if (spec.getTableName() == null) {
spec = new ViewSpecification(spec.getFormat(), naming.getTableName(viewId));
}
explore.enableExploreStream(viewId.getParent(), spec.getTableName(), spec.getFormat());
boolean result = store.createOrUpdate(viewId, spec);
ViewSystemMetadataWriter systemMetadataWriter = new ViewSystemMetadataWriter(metadataStore, viewId, spec, !result);
systemMetadataWriter.write();
return result;
}