Example usage for org.springframework.integration.jpa.support JpaUtils getEntityName

List of usage examples for org.springframework.integration.jpa.support JpaUtils getEntityName

Introduction

In this page you can find the example usage for org.springframework.integration.jpa.support JpaUtils getEntityName.

Prototype

public static String getEntityName(EntityManager em, Class<?> entityClass) 

Source Link

Usage

From source file:org.springframework.integration.jpa.core.DefaultJpaOperations.java

@Override
public void deleteInBatch(Iterable<?> entities) {

    Assert.notNull(entities, "entities must not be null.");

    Iterator<?> iterator = entities.iterator();

    if (!iterator.hasNext()) {
        return;//  w  w w  . ja v  a  2  s .c  o m
    }

    Class<?> entityClass = null;

    for (Object object : entities) {
        if (entityClass == null) {
            entityClass = object.getClass();
        } else {
            if (entityClass != object.getClass()) {
                throw new IllegalArgumentException("entities must be of the same type.");
            }
        }
    }

    final String entityName = JpaUtils.getEntityName(entityManager, entityClass);
    final String queryString = JpaUtils.getQueryString(JpaUtils.DELETE_ALL_QUERY_STRING, entityName);

    JpaUtils.applyAndBind(queryString, entities, entityManager).executeUpdate();

}

From source file:org.springframework.integration.jpa.core.DefaultJpaOperations.java

@Override
public List<?> getResultListForClass(Class<?> entityClass, int firstResult, int maxNumberOfResults) {

    final String entityName = JpaUtils.getEntityName(entityManager, entityClass);
    final Query query = entityManager.createQuery("select x from " + entityName + " x", entityClass);
    if (firstResult > 0) {
        query.setFirstResult(firstResult);
    }//from w ww .ja v a  2s  .  co  m
    if (maxNumberOfResults > 0) {
        query.setMaxResults(maxNumberOfResults);
    }

    return query.getResultList();

}