use of com.google.inject.persist.Transactional in project pinot by linkedin.
the class JobManagerImpl method deleteRecordsOlderThanDaysWithStatus.
@Override
@Transactional
public int deleteRecordsOlderThanDaysWithStatus(int days, JobStatus status) {
DateTime expireDate = new DateTime().minusDays(days);
Timestamp expireTimestamp = new Timestamp(expireDate.getMillis());
Predicate statusPredicate = Predicate.EQ("status", status.toString());
Predicate timestampPredicate = Predicate.LT("updateTime", expireTimestamp);
List<JobBean> list = genericPojoDao.get(Predicate.AND(statusPredicate, timestampPredicate), JobBean.class);
for (JobBean jobBean : list) {
deleteById(jobBean.getId());
}
return list.size();
}
use of com.google.inject.persist.Transactional in project ninja by ninjaframework.
the class SetupDao method setup.
@Transactional
public void setup() {
EntityManager entityManager = entityManagerProvider.get();
Query q = entityManager.createQuery("SELECT x FROM User x");
List<User> users = (List<User>) q.getResultList();
if (users.size() == 0) {
// Create a new user and save it
User bob = new User("bob@gmail.com", "secret", "Bob");
entityManager.persist(bob);
// Create a new post
Article bobPost3 = new Article(bob, "My third post", lipsum);
entityManager.persist(bobPost3);
// Create a new post
Article bobPost2 = new Article(bob, "My second post", lipsum);
entityManager.persist(bobPost2);
// Create a new post
Article bobPost1 = new Article(bob, post1Title, post1Content);
entityManager.persist(bobPost1);
entityManager.setFlushMode(FlushModeType.COMMIT);
entityManager.flush();
}
}
use of com.google.inject.persist.Transactional in project roboguice by roboguice.
the class JpaLocalTxnInterceptor method invoke.
public Object invoke(MethodInvocation methodInvocation) throws Throwable {
// Should we start a unit of work?
if (!emProvider.isWorking()) {
emProvider.begin();
didWeStartWork.set(true);
}
Transactional transactional = readTransactionMetadata(methodInvocation);
EntityManager em = this.emProvider.get();
// Allow 'joining' of transactions if there is an enclosing @Transactional method.
if (em.getTransaction().isActive()) {
return methodInvocation.proceed();
}
final EntityTransaction txn = em.getTransaction();
txn.begin();
Object result;
try {
result = methodInvocation.proceed();
} catch (Exception e) {
//commit transaction only if rollback didnt occur
if (rollbackIfNecessary(transactional, e, txn)) {
txn.commit();
}
//propagate whatever exception is thrown anyway
throw e;
} finally {
// Close the em if necessary (guarded so this code doesn't run unless catch fired).
if (null != didWeStartWork.get() && !txn.isActive()) {
didWeStartWork.remove();
unitOfWork.end();
}
}
// interferes with the advised method's throwing semantics)
try {
txn.commit();
} finally {
//close the em if necessary
if (null != didWeStartWork.get()) {
didWeStartWork.remove();
unitOfWork.end();
}
}
//or return result
return result;
}
use of com.google.inject.persist.Transactional in project roboguice by roboguice.
the class JpaLocalTxnInterceptor method readTransactionMetadata.
// TODO(dhanji): Cache this method's results.
private Transactional readTransactionMetadata(MethodInvocation methodInvocation) {
Transactional transactional;
Method method = methodInvocation.getMethod();
Class<?> targetClass = methodInvocation.getThis().getClass();
transactional = method.getAnnotation(Transactional.class);
if (null == transactional) {
// If none on method, try the class.
transactional = targetClass.getAnnotation(Transactional.class);
}
if (null == transactional) {
// If there is no transactional annotation present, use the default
transactional = Internal.class.getAnnotation(Transactional.class);
}
return transactional;
}
use of com.google.inject.persist.Transactional in project guice by google.
the class JpaLocalTxnInterceptor method readTransactionMetadata.
// TODO(dhanji): Cache this method's results.
private Transactional readTransactionMetadata(MethodInvocation methodInvocation) {
Transactional transactional;
Method method = methodInvocation.getMethod();
Class<?> targetClass = methodInvocation.getThis().getClass();
transactional = method.getAnnotation(Transactional.class);
if (null == transactional) {
// If none on method, try the class.
transactional = targetClass.getAnnotation(Transactional.class);
}
if (null == transactional) {
// If there is no transactional annotation present, use the default
transactional = Internal.class.getAnnotation(Transactional.class);
}
return transactional;
}
Aggregations