當前位置: 首頁>>代碼示例>>Java>>正文


Java CriteriaDelete類代碼示例

本文整理匯總了Java中javax.persistence.criteria.CriteriaDelete的典型用法代碼示例。如果您正苦於以下問題:Java CriteriaDelete類的具體用法?Java CriteriaDelete怎麽用?Java CriteriaDelete使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


CriteriaDelete類屬於javax.persistence.criteria包,在下文中一共展示了CriteriaDelete類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: deleteBooks

import javax.persistence.criteria.CriteriaDelete; //導入依賴的package包/類
@Test
public void deleteBooks() {
	log.info("... deleteBooks ...");

	EntityManager em = emf.createEntityManager();
	em.getTransaction().begin();

	logBooks(em);
	
	CriteriaBuilder cb = em.getCriteriaBuilder();
	CriteriaDelete<Book> delete = cb.createCriteriaDelete(Book.class);
	delete.from(Book.class);
	
	Query query = em.createQuery(delete);
	query.executeUpdate();

	logBooks(em);
	
	em.getTransaction().commit();
	em.close();
}
 
開發者ID:thjanssen,項目名稱:HibernateTips,代碼行數:22,代碼來源:TestCriteriaDelete.java

示例2: deleteById

import javax.persistence.criteria.CriteriaDelete; //導入依賴的package包/類
@Override
public Integer deleteById(String id) {
	CriteriaBuilder cb = entityManager.getCriteriaBuilder();
	CriteriaDelete<T> delete = cb.createCriteriaDelete(getDomainClass());
	Root<T> e = delete.from(getDomainClass());
	delete.where(cb.equal(e.get("id"), id));
	return entityManager.createQuery(delete).executeUpdate();
}
 
開發者ID:geeker-lait,項目名稱:tasfe-framework,代碼行數:9,代碼來源:BaseRepositoryImpl.java

示例3: deleteByCriteria

import javax.persistence.criteria.CriteriaDelete; //導入依賴的package包/類
/**
 * {@inheritDoc}
 */
@Override
public <T extends BaseEntity> int deleteByCriteria(DeleteCriteria<T> criteria) {
    EntityManager em = null;
    EntityTransaction txn = null;
    try {
        em = this.emf.createEntityManager();
        txn = JpaUtil.getTransaction(em);
        CriteriaBuilder cb = em.getCriteriaBuilder();
        CriteriaDelete<T> cd = cb.createCriteriaDelete(criteria.getEntity());
        Root<T> root = cd.from(criteria.getEntity());
        int rowsDeleted = em
                .createQuery(cd.where(cb.and(JpaUtil.getPredicates(criteria.getCriteriaAttributes(), cb, root))))
                .executeUpdate();
        txn.commit();
        LOGGER.debug("deleteByCriteria: No. of rows deleted: [{}]", rowsDeleted);
        return rowsDeleted;
    } catch (RuntimeException ex) {
        JpaUtil.setRollbackOnly(txn);
        LOGGER.error(ex.getMessage(), ex);
        throw new PersistenceException(ex.getMessage(), ex);
    } finally {
        JpaUtil.rollbackTransaction(txn);
        JpaUtil.closeEntityManager(em);
    }
}
 
開發者ID:AdeptJ,項目名稱:adeptj-modules,代碼行數:29,代碼來源:EclipseLinkCrudRepository.java

示例4: deleteByEventName

import javax.persistence.criteria.CriteriaDelete; //導入依賴的package包/類
/**
 * JAVADOC Method Level Comments
 *
 * @param eventName JAVADOC.
 *
 * @return JAVADOC.
 */
@Override
public boolean deleteByEventName(String eventName) {
    CriteriaBuilder cb = entityManager.getCriteriaBuilder();
    CriteriaDelete<ClusterControl> cq = cb.createCriteriaDelete(ClusterControl.class);
    Root<ClusterControl> root = cq.from(ClusterControl.class);
    Predicate ep = cb.equal(root.get("event"), eventName);
    Predicate cp = cb.equal(root.get("complete"), false);

    int rows = entityManager.createQuery(cq.where(cb.and(ep, cp))).executeUpdate();

    if (LOG.isDebugEnabled()) {
        LOG.debug("Deleted " + rows + " for event " + eventName);
    }

    return rows > 0;
}
 
開發者ID:cucina,項目名稱:opencucina,代碼行數:24,代碼來源:ClusterControlRepositoryImpl.java

示例5: delete

import javax.persistence.criteria.CriteriaDelete; //導入依賴的package包/類
/**
 * WARNING, order will not be honoured by this method
 * 
 * @return
 */
public int delete()
{
	Preconditions.checkArgument(orders.size() == 0, "Order is not supported for delete");
	CriteriaDelete<E> deleteCriteria = builder.createCriteriaDelete(entityClass);
	root = deleteCriteria.getRoot();
	if (predicate != null)
	{
		deleteCriteria.where(predicate);
	}
	Query query = getEntityManager().createQuery(deleteCriteria);

	if (limit != null)
	{
		query.setMaxResults(limit);
	}
	if (startPosition != null)
	{
		query.setFirstResult(startPosition);
	}
	int result = query.executeUpdate();
	getEntityManager().getEntityManagerFactory().getCache().evict(entityClass);

	return result;
}
 
開發者ID:rlsutton1,項目名稱:VaadinUtils,代碼行數:30,代碼來源:JpaDslAbstract.java

示例6: shouldExecuteCriteriaDelete

import javax.persistence.criteria.CriteriaDelete; //導入依賴的package包/類
@Test
public void shouldExecuteCriteriaDelete() throws Exception {
    assertNotNull(em);
    CriteriaBuilder builder = em.getCriteriaBuilder();
    CriteriaDelete<Employee> c =
        builder.createCriteriaDelete(Employee.class);
    Root<Employee> p = c.from(Employee.class);
    Predicate condition1 = builder.ge(
        p.get(Employee_.salary),
            new BigDecimal("50000"));
    Predicate condition2 = builder.equal(
        p.get(Employee_.taxCode),
            new TaxCode(504, "Director"));
    c.where(condition1, condition2);
    utx.begin();
    Query query = em.createQuery(c);
    int rowsAffected = query.executeUpdate();
    assertTrue( rowsAffected > 0);
    utx.commit();
}
 
開發者ID:peterpilgrim,項目名稱:javaee7-developer-handbook,代碼行數:21,代碼來源:EmployeeCriteriaDeleteTest.java

示例7: deleteByFieldEq

import javax.persistence.criteria.CriteriaDelete; //導入依賴的package包/類
@Override
public Integer deleteByFieldEq(String Field, Object value) {
	CriteriaBuilder cb = entityManager.getCriteriaBuilder();
	CriteriaDelete<T> delete = cb.createCriteriaDelete(getDomainClass());
	Root<T> e = delete.from(getDomainClass());
	delete.where(cb.equal(e.get(Field), value));
	return entityManager.createQuery(delete).executeUpdate();
}
 
開發者ID:geeker-lait,項目名稱:tasfe-framework,代碼行數:9,代碼來源:BaseRepositoryImpl.java

示例8: deleteByFieldLike

import javax.persistence.criteria.CriteriaDelete; //導入依賴的package包/類
@Override
public Integer deleteByFieldLike(String Field, String value) {
	CriteriaBuilder cb = entityManager.getCriteriaBuilder();
	CriteriaDelete<T> delete = cb.createCriteriaDelete(getDomainClass());
	Root<T> e = delete.from(getDomainClass());
	delete.where(cb.like(e.get(Field).as(String.class), value));
	return entityManager.createQuery(delete).executeUpdate();
}
 
開發者ID:geeker-lait,項目名稱:tasfe-framework,代碼行數:9,代碼來源:BaseRepositoryImpl.java

示例9: deleteByFieldIn

import javax.persistence.criteria.CriteriaDelete; //導入依賴的package包/類
@Override
public Integer deleteByFieldIn(String Field, Iterable<?> values) {
	CriteriaBuilder cb = entityManager.getCriteriaBuilder();
	CriteriaDelete<T> delete = cb.createCriteriaDelete(getDomainClass());
	Root<T> e = delete.from(getDomainClass());
	delete.where(cb.in(e.get(Field)).value(values));
	return entityManager.createQuery(delete).executeUpdate();
}
 
開發者ID:geeker-lait,項目名稱:tasfe-framework,代碼行數:9,代碼來源:BaseRepositoryImpl.java

示例10: delete

import javax.persistence.criteria.CriteriaDelete; //導入依賴的package包/類
public void delete() {
    CriteriaDelete<T> criteriaDelete = criteriaBuilder.createCriteriaDelete(entityClass);

    Root<T> root = criteriaDelete.from(entityClass);

    if (!wheres.isEmpty()) {
        criteriaDelete.where( getPredicates(root, wheres) );
    }

    em.createQuery(criteriaDelete).executeUpdate();
}
 
開發者ID:jhonystein,項目名稱:Pedidex,代碼行數:12,代碼來源:JpaCriteriaHelper.java

示例11: deleteAll

import javax.persistence.criteria.CriteriaDelete; //導入依賴的package包/類
@Override
public int deleteAll() {
    return execute(session -> {
        CriteriaBuilder builder = session.getCriteriaBuilder();
        CriteriaDelete<T> delete = builder.createCriteriaDelete(getEntityClass());
        delete.from(getEntityClass());
        return session.createQuery(delete).executeUpdate();
    });
}
 
開發者ID:FlowCI,項目名稱:flow-platform,代碼行數:10,代碼來源:AbstractBaseDao.java

示例12: deleteBy

import javax.persistence.criteria.CriteriaDelete; //導入依賴的package包/類
/**
 * Deletes all entities which match the predicates provided.<p/>
 * 
 * <b>Performance note:</b> This implementation is not optimized as it is built from a dynamic query.
 * For production environments, implement this method explicitly by using named queries.
 */
public void deleteBy(Map<String, String> predicates) {
    CriteriaDelete<T> query = em.getCriteriaBuilder().createCriteriaDelete(getModelClass());
    Root<T> from = query.from(getModelClass());
    if (predicates != null) {
        query.where(createPredicates(em.getCriteriaBuilder(), from, predicates));
    }
    em.createQuery(query).executeUpdate();
    em.flush();
}
 
開發者ID:codebulb,項目名稱:crudlet,代碼行數:16,代碼來源:CrudService.java

示例13: clearHistory

import javax.persistence.criteria.CriteriaDelete; //導入依賴的package包/類
@MCRCommand(syntax = "clear metadata history of base {0}",
    help = "clears metadata history of all objects with base id {0}")
public static void clearHistory(String baseId) {
    EntityManager em = MCREntityManagerProvider.getCurrentEntityManager();
    CriteriaBuilder cb = em.getCriteriaBuilder();
    CriteriaDelete<MCRMetaHistoryItem> delete = cb.createCriteriaDelete(MCRMetaHistoryItem.class);
    Root<MCRMetaHistoryItem> item = delete.from(MCRMetaHistoryItem.class);
    int rowsDeleted = em.createQuery(
        delete.where(
            cb.like(item.get(MCRMetaHistoryItem_.id).as(String.class), baseId + "_".replace("_", "$_") + '%', '$')))
        .executeUpdate();
    LogManager.getLogger().info("Deleted {} items in history of {}", rowsDeleted, baseId);
}
 
開發者ID:MyCoRe-Org,項目名稱:mycore,代碼行數:14,代碼來源:MCRMetadataHistoryCommands.java

示例14: clearSingleHistory

import javax.persistence.criteria.CriteriaDelete; //導入依賴的package包/類
@MCRCommand(syntax = "clear metadata history of id {0}",
    help = "clears metadata history of object/derivate with id {0}")
public static void clearSingleHistory(String mcrId) {
    EntityManager em = MCREntityManagerProvider.getCurrentEntityManager();
    CriteriaBuilder cb = em.getCriteriaBuilder();
    CriteriaDelete<MCRMetaHistoryItem> delete = cb.createCriteriaDelete(MCRMetaHistoryItem.class);
    Root<MCRMetaHistoryItem> item = delete.from(MCRMetaHistoryItem.class);
    int rowsDeleted = em.createQuery(
        delete.where(cb.equal(item.get(MCRMetaHistoryItem_.id).as(String.class), mcrId)))
        .executeUpdate();
    LogManager.getLogger().info("Deleted {} items in history of {}", rowsDeleted, mcrId);
}
 
開發者ID:MyCoRe-Org,項目名稱:mycore,代碼行數:13,代碼來源:MCRMetadataHistoryCommands.java

示例15: buildDeleteQuery

import javax.persistence.criteria.CriteriaDelete; //導入依賴的package包/類
/**
 * Builds the query to delete {@link com.box.l10n.mojito.entity.TMTextUnitCurrentVariant}s that will be rolled back
 *
 * @param tmId            ID of the TM the {@link TMTextUnitCurrentVariant}s to be rolled back should belong to
 * @param extraParameters Extra parameters to filter what to rollback
 * @return The delete query
 */
protected Query buildDeleteQuery(Long tmId, CurrentVariantRollbackParameters extraParameters) {

    logger.trace("Building the delete tmTextUnitCurrentVariants query");

    CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
    CriteriaDelete<TMTextUnitCurrentVariant> deleteCriteria = criteriaBuilder.createCriteriaDelete(TMTextUnitCurrentVariant.class);
    Root<TMTextUnitCurrentVariant> root = deleteCriteria.from(TMTextUnitCurrentVariant.class);

    Predicate whereClause = criteriaBuilder.conjunction();

    Predicate tmPredicate = criteriaBuilder.equal(root.get(TMTextUnitCurrentVariant_.tm), tmId);
    whereClause = criteriaBuilder.and(whereClause, tmPredicate);

    List<Long> localeIdsToRollback = extraParameters.getLocaleIds();
    if (localeIdsToRollback != null && !localeIdsToRollback.isEmpty()) {
        Predicate localesPredicate = criteriaBuilder.isTrue(root.get(TMTextUnitCurrentVariant_.locale).in(localeIdsToRollback));
        whereClause = criteriaBuilder.and(whereClause, localesPredicate);
    }

    List<Long> tmTextUnitIdsToRollback = extraParameters.getTmTextUnitIds();
    if (tmTextUnitIdsToRollback != null && !tmTextUnitIdsToRollback.isEmpty()) {
        Predicate tmTextUnitPredicate = criteriaBuilder.isTrue(root.get(TMTextUnitCurrentVariant_.tmTextUnit).in(tmTextUnitIdsToRollback));
        whereClause = criteriaBuilder.and(whereClause, tmTextUnitPredicate);
    }

    deleteCriteria.where(whereClause);

    return entityManager.createQuery(deleteCriteria);
}
 
開發者ID:box,項目名稱:mojito,代碼行數:37,代碼來源:CurrentVariantRollbackService.java


注:本文中的javax.persistence.criteria.CriteriaDelete類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。