Search in sources :

Example 46 with Transactional

use of com.google.inject.persist.Transactional in project pinot by linkedin.

the class DetectionStatusManagerImpl method deleteRecordsOlderThanDays.

@Override
@Transactional
public int deleteRecordsOlderThanDays(int days) {
    DateTime expireDate = new DateTime().minusDays(days);
    Timestamp expireTimestamp = new Timestamp(expireDate.getMillis());
    Predicate timestampPredicate = Predicate.LT("createTime", expireTimestamp);
    List<DetectionStatusBean> list = genericPojoDao.get(timestampPredicate, DetectionStatusBean.class);
    for (DetectionStatusBean bean : list) {
        deleteById(bean.getId());
    }
    return list.size();
}
Also used : Timestamp(java.sql.Timestamp) DateTime(org.joda.time.DateTime) DetectionStatusBean(com.linkedin.thirdeye.datalayer.pojo.DetectionStatusBean) Predicate(com.linkedin.thirdeye.datalayer.util.Predicate) Transactional(com.google.inject.persist.Transactional)

Example 47 with Transactional

use of com.google.inject.persist.Transactional in project pinot by linkedin.

the class TaskManagerImpl method deleteRecordsOlderThanDaysWithStatus.

@Override
@Transactional
public int deleteRecordsOlderThanDaysWithStatus(int days, TaskStatus status) {
    DateTime expireDate = new DateTime().minusDays(days);
    Timestamp expireTimestamp = new Timestamp(expireDate.getMillis());
    Predicate timestampPredicate = Predicate.LT("createTime", expireTimestamp);
    Predicate statusPredicate = Predicate.EQ("status", status.toString());
    List<TaskBean> list = genericPojoDao.get(Predicate.AND(statusPredicate, timestampPredicate), TaskBean.class);
    for (TaskBean bean : list) {
        deleteById(bean.getId());
    }
    return list.size();
}
Also used : TaskBean(com.linkedin.thirdeye.datalayer.pojo.TaskBean) Timestamp(java.sql.Timestamp) DateTime(org.joda.time.DateTime) Predicate(com.linkedin.thirdeye.datalayer.util.Predicate) Transactional(com.google.inject.persist.Transactional)

Example 48 with Transactional

use of com.google.inject.persist.Transactional in project pinot by linkedin.

the class TaskManagerImpl method findByStatusNotIn.

@Override
@Transactional
public List<TaskDTO> findByStatusNotIn(TaskStatus status) {
    Predicate statusPredicate = Predicate.NEQ("status", status.toString());
    List<TaskBean> list = genericPojoDao.get(statusPredicate, TaskBean.class);
    List<TaskDTO> result = new ArrayList<>();
    for (TaskBean bean : list) {
        result.add((TaskDTO) MODEL_MAPPER.map(bean, TaskDTO.class));
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) TaskBean(com.linkedin.thirdeye.datalayer.pojo.TaskBean) TaskDTO(com.linkedin.thirdeye.datalayer.dto.TaskDTO) Predicate(com.linkedin.thirdeye.datalayer.util.Predicate) Transactional(com.google.inject.persist.Transactional)

Example 49 with Transactional

use of com.google.inject.persist.Transactional in project ninja by ninjaframework.

the class ArticleDao method postArticle.

/**
     * Returns false if user cannot be found in database.
     */
@Transactional
public boolean postArticle(String username, ArticleDto articleDto) {
    EntityManager entityManager = entitiyManagerProvider.get();
    Query query = entityManager.createQuery("SELECT x FROM User x WHERE username = :usernameParam");
    User user = (User) query.setParameter("usernameParam", username).getSingleResult();
    if (user == null) {
        return false;
    }
    Article article = new Article(user, articleDto.title, articleDto.content);
    entityManager.persist(article);
    return true;
}
Also used : EntityManager(javax.persistence.EntityManager) User(models.User) Query(javax.persistence.Query) TypedQuery(javax.persistence.TypedQuery) Article(models.Article) Transactional(com.google.inject.persist.Transactional)

Example 50 with Transactional

use of com.google.inject.persist.Transactional in project querydsl by querydsl.

the class AbstractPersistenceTest method before.

@Before
@Transactional
public void before() {
    EntityManager entityManager = em.get();
    entityManager.getEntityManagerFactory().getCache().evictAll();
    Session session = entityManager.unwrap(Session.class);
    session.doWork(new Work() {

        @Override
        public void execute(Connection connection) throws SQLException {
            List<String> tables = new ArrayList<String>();
            DatabaseMetaData md = connection.getMetaData();
            ResultSet rs = md.getTables(null, null, null, new String[] { "TABLE" });
            try {
                while (rs.next()) {
                    tables.add(rs.getString("TABLE_NAME"));
                }
            } finally {
                rs.close();
            }
            java.sql.Statement stmt = connection.createStatement();
            try {
                stmt.execute("SET REFERENTIAL_INTEGRITY FALSE");
                for (String table : tables) {
                    stmt.execute("TRUNCATE TABLE " + table);
                }
                stmt.execute("SET REFERENTIAL_INTEGRITY TRUE");
            } finally {
                stmt.close();
            }
        }
    });
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) DatabaseMetaData(java.sql.DatabaseMetaData) EntityManager(javax.persistence.EntityManager) Work(org.hibernate.jdbc.Work) ResultSet(java.sql.ResultSet) ArrayList(java.util.ArrayList) List(java.util.List) Session(org.hibernate.Session) Before(org.junit.Before) 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