use of org.apache.hadoop.hive.metastore.model.MNotificationNextId in project hive by apache.
the class ObjectStore method getCurrentNotificationEventId.
@Override
public CurrentNotificationEventId getCurrentNotificationEventId() {
boolean commited = false;
Query query = null;
try {
openTransaction();
query = pm.newQuery(MNotificationNextId.class);
Collection<MNotificationNextId> ids = (Collection) query.execute();
long id = 0;
if (CollectionUtils.isNotEmpty(ids)) {
id = ids.iterator().next().getNextEventId() - 1;
}
commited = commitTransaction();
return new CurrentNotificationEventId(id);
} finally {
rollbackAndCleanup(commited, query);
}
}
use of org.apache.hadoop.hive.metastore.model.MNotificationNextId in project hive by apache.
the class ObjectStore method addNotificationEvent.
@Override
public void addNotificationEvent(NotificationEvent entry) throws MetaException {
boolean commited = false;
Query query = null;
try {
pm.flush();
openTransaction();
lockNotificationSequenceForUpdate();
query = pm.newQuery(MNotificationNextId.class);
Collection<MNotificationNextId> ids = (Collection) query.execute();
MNotificationNextId mNotificationNextId = null;
boolean needToPersistId;
if (CollectionUtils.isEmpty(ids)) {
mNotificationNextId = new MNotificationNextId(1L);
needToPersistId = true;
} else {
mNotificationNextId = ids.iterator().next();
needToPersistId = false;
}
entry.setEventId(mNotificationNextId.getNextEventId());
mNotificationNextId.incrementEventId();
if (needToPersistId) {
pm.makePersistent(mNotificationNextId);
}
pm.makePersistent(translateThriftToDb(entry));
commited = commitTransaction();
} catch (MetaException e) {
LOG.error("Couldn't get lock for update", e);
throw e;
} finally {
rollbackAndCleanup(commited, query);
}
}
Aggregations