use of javax.jdo.identity.IntIdentity in project hive by apache.
the class ObjectStore method addMasterKey.
@Override
public int addMasterKey(String key) throws MetaException {
LOG.debug("Begin executing addMasterKey");
boolean committed = false;
MMasterKey masterKey = new MMasterKey(key);
try {
openTransaction();
pm.makePersistent(masterKey);
committed = commitTransaction();
} finally {
if (!committed) {
rollbackTransaction();
}
}
LOG.debug("Done executing addMasterKey with status : {}", committed);
if (committed) {
return ((IntIdentity) pm.getObjectId(masterKey)).getKey();
} else {
throw new MetaException("Failed to add master key.");
}
}
use of javax.jdo.identity.IntIdentity in project hive by apache.
the class ObjectStore method scheduledQueryPoll.
@Override
public ScheduledQueryPollResponse scheduledQueryPoll(ScheduledQueryPollRequest request) throws MetaException {
ensureScheduledQueriesEnabled();
boolean commited = false;
ScheduledQueryPollResponse ret = new ScheduledQueryPollResponse();
Query q = null;
try {
openTransaction();
q = pm.newQuery(MScheduledQuery.class, "nextExecution <= now && enabled && clusterNamespace == ns && activeExecution == null");
q.setSerializeRead(true);
q.declareParameters("java.lang.Integer now, java.lang.String ns");
q.setOrdering("nextExecution");
int now = (int) (System.currentTimeMillis() / 1000);
List<MScheduledQuery> results = (List<MScheduledQuery>) q.execute(now, request.getClusterNamespace());
if (results == null || results.isEmpty()) {
return new ScheduledQueryPollResponse();
}
MScheduledQuery schq = results.get(0);
schq.setNextExecution(computeNextExecutionTime(schq.getSchedule()));
MScheduledExecution execution = new MScheduledExecution();
execution.setScheduledQuery(schq);
execution.setState(QueryState.INITED);
execution.setStartTime(now);
execution.setLastUpdateTime(now);
schq.setActiveExecution(execution);
pm.makePersistent(execution);
pm.makePersistent(schq);
ObjectStoreTestHook.onScheduledQueryPoll();
commited = commitTransaction();
ret.setScheduleKey(schq.getScheduleKey());
ret.setQuery("/* schedule: " + schq.getScheduleName() + " */" + schq.getQuery());
ret.setUser(schq.getUser());
int executionId = ((IntIdentity) pm.getObjectId(execution)).getKey();
ret.setExecutionId(executionId);
} catch (JDOException e) {
LOG.debug("Caught jdo exception; exclusive", e);
commited = false;
} finally {
rollbackAndCleanup(commited, q);
return commited ? ret : new ScheduledQueryPollResponse();
}
}
Aggregations