Feature f = persistenceContext.persist(tweet.getPlace());
if (null != placeHelper) {
try {
placeHelper.submit(tweet.getPlace(), f);
} catch (TwitterClientException e) {
throw new HandlerException(e);
}
}
Set<SpatialThing> s = currentMicroblogPost.getLocation();
s.add(f);
currentMicroblogPost.setLocation(s);
}
// end Elmo operations
try {
storeConnection.commit();
} catch (TweetStoreException e) {
throw new HandlerException(e);
}
// Note: we assume that Twitter and any other services which supply these posts will not allow a cycle
// of replies and/or retweets.
// Note: these tweets are persisted in their own transactions.
if (null != tweet.getInReplyToTweet()) {
this.handle(tweet.getInReplyToTweet());
}
if (null != tweet.getRetweetOf()) {
this.handle(tweet.getRetweetOf());
}
//System.out.println(" ...ending transaction");
// Note: these Sail operations are performed outside of the Elmo transaction. If they were to be
// carried out inside the transaction, apparently Sesame would kill the thread without throwing
// an exception or logging an error.
if (hasAnnotations) {
for (Triple triple : tweet.getAnnotations()) {
System.out.println("\t (" + triple.getWeight() + ")\t" + triple);
Statement st;
try {
st = toRDF(triple, uriOf(currentMicroblogPost.getEmbedsKnowledge()));
} catch (TwitterClientException e) {
throw new HandlerException(e);
}
if (null != st) {
// FIXME: creating a statement and then breaking it into parts is wasty
try {
//System.out.println("subject: " + st.getSubject());
//System.out.println("predicate: " + st.getPredicate());
//System.out.println("object: " + st.getObject());
//System.out.println("context: " + st.getContext());
storeConnection.getSailConnection()
.addStatement(st.getSubject(), st.getPredicate(), st.getObject(), st.getContext());
} catch (SailException e) {
throw new HandlerException(e);
}
}
}
try {
storeConnection.getSailConnection().commit();
} catch (SailException e) {
throw new HandlerException(e);
}
}
finished = true;
} catch (HandlerException e) {
throw e;
} catch (Throwable t) {
throw new HandlerException(t);
} finally {
if (!finished) {
try {
LOGGER.info("rolling back failed transaction");
storeConnection.rollback();
} catch (TweetStoreException e) {
throw new HandlerException(e);
}
}
}
}