本文整理匯總了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();
}
示例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();
}
示例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);
}
}
示例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;
}
示例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;
}
示例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();
}
示例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();
}
示例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();
}
示例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();
}
示例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();
}
示例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();
});
}
示例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();
}
示例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);
}
示例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);
}
示例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);
}