use of org.apache.asterix.lang.common.statement.CreateFeedStatement in project asterixdb by apache.
the class QueryTranslator method handleCreateFeedStatement.
protected void handleCreateFeedStatement(MetadataProvider metadataProvider, Statement stmt) throws Exception {
CreateFeedStatement cfs = (CreateFeedStatement) stmt;
String dataverseName = getActiveDataverse(cfs.getDataverseName());
String feedName = cfs.getFeedName().getValue();
MetadataTransactionContext mdTxnCtx = MetadataManager.INSTANCE.beginTransaction();
metadataProvider.setMetadataTxnContext(mdTxnCtx);
MetadataLockManager.INSTANCE.createFeedBegin(metadataProvider.getLocks(), dataverseName, dataverseName + "." + feedName);
Feed feed = null;
try {
feed = MetadataManager.INSTANCE.getFeed(metadataProvider.getMetadataTxnContext(), dataverseName, feedName);
if (feed != null) {
if (cfs.getIfNotExists()) {
MetadataManager.INSTANCE.commitTransaction(mdTxnCtx);
return;
} else {
throw new AlgebricksException("A feed with this name " + feedName + " already exists.");
}
}
String adaptorName = cfs.getAdaptorName();
feed = new Feed(dataverseName, feedName, adaptorName, cfs.getAdaptorConfiguration());
FeedMetadataUtil.validateFeed(feed, mdTxnCtx, appCtx);
MetadataManager.INSTANCE.addFeed(metadataProvider.getMetadataTxnContext(), feed);
MetadataManager.INSTANCE.commitTransaction(mdTxnCtx);
} catch (Exception e) {
abort(e, e, mdTxnCtx);
throw e;
} finally {
metadataProvider.getLocks().unlock();
}
}
Aggregations