Java Code Examples for javax.persistence.TypedQuery#executeUpdate()

The following examples show how to use javax.persistence.TypedQuery#executeUpdate() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ImageCacheGarbageCollector.java    From zstack with Apache License 2.0 5 votes vote down vote up
@Transactional
private List<ImageCacheVO> getImageCacheToDelete() {
    String sql = "select i from ImageCacheVO i where i.imageUuid = NULL and i.state = :state";
    TypedQuery<ImageCacheVO> q = dbf.getEntityManager().createQuery(sql, ImageCacheVO.class);
    q.setLockMode(LockModeType.PESSIMISTIC_WRITE);
    q.setParameter("state", ImageCacheState.ready);
    List<ImageCacheVO> ret = q.getResultList();
    
    // if ImageCacheVO in deleting state and it has been stayed for 1 day
    // that means zstack that issued garbage collection exited before removing this entry from database
    // we garbage this entry again here
    sql = "select i from ImageCacheVO i where i.imageUuid = NULL and i.state = :state and CURRENT_TIMESTAMP > DATE_ADD(i.lastOpDate, INTERVAL 1 DAY)";
    Query q1 = dbf.getEntityManager().createNativeQuery(sql, ImageCacheVO.class);
    q1.setLockMode(LockModeType.PESSIMISTIC_WRITE);
    q1.setParameter("state", ImageCacheState.deleting);
    ret.addAll(q1.getResultList());
    if (ret.isEmpty()) {
        return ret;
    }
    
    List<Long> ids = new ArrayList<Long>(ret.size());
    for (ImageCacheVO i : ret) {
        ids.add(i.getId());
    }
    sql = "update ImageCacheVO i set i.state = :state where i.id in (:ids)";
    TypedQuery<ImageCacheVO> q2 = dbf.getEntityManager().createQuery(sql, ImageCacheVO.class);
    q2.setParameter("state", ImageCacheState.deleting);
    q2.setParameter("ids", ids);
    q2.executeUpdate();
    return ret;
}
 
Example 2
Source File: JpaWidgetRepository.java    From attic-rave with Apache License 2.0 5 votes vote down vote up
/**
 * Delete all Widget Comments for a userId
 *
 * @param userId
 * @return count of comments deleted
 */
@Override
public int deleteAllWidgetComments(String userId) {
    TypedQuery<JpaWidgetComment> query = manager.createNamedQuery(JpaWidgetComment.DELETE_ALL_BY_USER, JpaWidgetComment.class);
    query.setParameter("userId", userId);
    return query.executeUpdate();
}
 
Example 3
Source File: ConfigurationItemDAO.java    From eplmp with Eclipse Public License 1.0 4 votes vote down vote up
public void removeLayersFromConfigurationItem(ConfigurationItemKey pKey){
    TypedQuery<Layer> query = em.createNamedQuery("Layer.removeLayersFromConfigurationItem", Layer.class);
    query.setParameter(WORKSPACE_ID, pKey.getWorkspace());
    query.setParameter("configurationItemId", pKey.getId());
    query.executeUpdate();
}
 
Example 4
Source File: ConfigurationItemDAO.java    From eplmp with Eclipse Public License 1.0 4 votes vote down vote up
public void removeEffectivitiesFromConfigurationItem(ConfigurationItemKey pKey){
    TypedQuery<Effectivity> query = em.createNamedQuery("Effectivity.removeEffectivitiesFromConfigurationItem", Effectivity.class);
    query.setParameter(WORKSPACE_ID, pKey.getWorkspace());
    query.setParameter("configurationItemId", pKey.getId());
    query.executeUpdate();
}
 
Example 5
Source File: JpaPersonRepository.java    From attic-rave with Apache License 2.0 4 votes vote down vote up
@Override
public int removeAllFriendsAndRequests(String userid) {
    TypedQuery<JpaPersonAssociation> query = manager.createNamedQuery(JpaPersonAssociation.DELETE_ASSOCIATION_ITEMS_BY_USERID, JpaPersonAssociation.class);
    query.setParameter(JpaPersonAssociation.USERID, Long.parseLong(userid));
    return query.executeUpdate();
}
 
Example 6
Source File: JpaWidgetRepository.java    From attic-rave with Apache License 2.0 4 votes vote down vote up
@Override
public int deleteAllWidgetRatings(String userId) {
    TypedQuery<JpaWidgetRating> query = manager.createNamedQuery(JpaWidgetRating.DELETE_ALL_BY_USER, JpaWidgetRating.class);
    query.setParameter("userId", userId == null ? null : Long.parseLong(userId));
    return query.executeUpdate();
}