Search in sources :

Example 16 with Transactional

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();
}
Also used : JobBean(com.linkedin.thirdeye.datalayer.pojo.JobBean) Timestamp(java.sql.Timestamp) DateTime(org.joda.time.DateTime) Predicate(com.linkedin.thirdeye.datalayer.util.Predicate) Transactional(com.google.inject.persist.Transactional)

Example 17 with Transactional

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();
    }
}
Also used : EntityManager(javax.persistence.EntityManager) User(models.User) Query(javax.persistence.Query) Article(models.Article) List(java.util.List) Transactional(com.google.inject.persist.Transactional)

Example 18 with Transactional

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;
}
Also used : EntityTransaction(javax.persistence.EntityTransaction) EntityManager(javax.persistence.EntityManager) Transactional(com.google.inject.persist.Transactional)

Example 19 with Transactional

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;
}
Also used : Method(java.lang.reflect.Method) Transactional(com.google.inject.persist.Transactional)

Example 20 with 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;
}
Also used : Method(java.lang.reflect.Method) Transactional(com.google.inject.persist.Transactional)

Aggregations

Transactional (com.google.inject.persist.Transactional)51 EntityManager (javax.persistence.EntityManager)37 NotFoundException (org.eclipse.che.api.core.NotFoundException)16 ServerException (org.eclipse.che.api.core.ServerException)12 ProjectConfigImpl (org.eclipse.che.api.workspace.server.model.impl.ProjectConfigImpl)6 UserImpl (org.eclipse.che.api.user.server.model.impl.UserImpl)5 Predicate (com.linkedin.thirdeye.datalayer.util.Predicate)4 NoResultException (javax.persistence.NoResultException)4 RecipeImpl (org.eclipse.che.api.machine.server.recipe.RecipeImpl)4 WorkspaceImpl (org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl)4 Timestamp (java.sql.Timestamp)3 AccountImpl (org.eclipse.che.account.spi.AccountImpl)3 FactoryImpl (org.eclipse.che.api.factory.server.model.impl.FactoryImpl)3 DateTime (org.joda.time.DateTime)3 TaskBean (com.linkedin.thirdeye.datalayer.pojo.TaskBean)2 Method (java.lang.reflect.Method)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 EntityTransaction (javax.persistence.EntityTransaction)2 Query (javax.persistence.Query)2