本文整理汇总了Java中org.springframework.orm.jpa.JpaCallback类的典型用法代码示例。如果您正苦于以下问题:Java JpaCallback类的具体用法?Java JpaCallback怎么用?Java JpaCallback使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
JpaCallback类属于org.springframework.orm.jpa包,在下文中一共展示了JpaCallback类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: executeNamedQuery
import org.springframework.orm.jpa.JpaCallback; //导入依赖的package包/类
public List executeNamedQuery(final String queryName,
final Object[] params, final int begin, final int max) {
List ret = (List) this.getJpaTemplate().execute(new JpaCallback() {
public Object doInJpa(EntityManager em) throws PersistenceException {
Query query = em.createNamedQuery(queryName);
int parameterIndex = 1;
if (params != null && params.length > 0) {
for (Object obj : params) {
query.setParameter(parameterIndex++, obj);
}
}
if (begin >= 0 && max > 0) {
query.setFirstResult(begin);
query.setMaxResults(max);
}
return query.getResultList();
}
});
if (ret != null && ret.size() >= 0) {
return ret;
} else {
return new ArrayList();
}
}
示例2: executeNativeNamedQuery
import org.springframework.orm.jpa.JpaCallback; //导入依赖的package包/类
public List executeNativeNamedQuery(final String nnq,final Object[] params) {
Object ret = this.getJpaTemplate().execute(new JpaCallback() {
public Object doInJpa(EntityManager em) throws PersistenceException {
Query query = em.createNamedQuery(nnq);
int parameterIndex = 1;
if (params != null && params.length > 0) {
for (Object obj : params) {
query.setParameter(parameterIndex++, obj);
}
}
return query.getResultList();
}
});
return (List) ret;
}
示例3: executeNativeQuery
import org.springframework.orm.jpa.JpaCallback; //导入依赖的package包/类
public List executeNativeQuery(final String nnq, final Object[] params,
final int begin, final int max) {
List ret = (List) this.getJpaTemplate().execute(new JpaCallback() {
public Object doInJpa(EntityManager em) throws PersistenceException {
Query query = em.createNativeQuery(nnq);
int parameterIndex = 1;
if (params != null && params.length > 0) {
for (Object obj : params) {
query.setParameter(parameterIndex++, obj);
}
}
if (begin >= 0 && max > 0) {
query.setFirstResult(begin);
query.setMaxResults(max);
}
return query.getResultList();
}
});
if (ret != null && ret.size() >= 0) {
return ret;
} else {
return new ArrayList();
}
}
示例4: find
import org.springframework.orm.jpa.JpaCallback; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public List<Client> find(final String scope, final Object[] params, final int begin,
final int max) {
return this.getJpaTemplate().executeFind(new JpaCallback() {
public Object doInJpa(EntityManager entitymanager) throws PersistenceException {
StringBuffer sql = new StringBuffer("select obj from Client obj ");
if (StringUtils.hasLength(scope)) {
sql.append(" where ").append(scope);
}
Query query = entitymanager.createQuery(sql.toString());
if (params != null) {
for (int i = 0; i < params.length; i++)
query.setParameter(i + 1, params[i]);
}
if (begin > 0) {
query.setFirstResult(begin);
query.setMaxResults(max);
}
return query.getResultList();
}
});
}
示例5: findAll
import org.springframework.orm.jpa.JpaCallback; //导入依赖的package包/类
public List<Note> findAll(final int offset, final int count,
final String sortProperty, final boolean sortAscending) {
return getJpaTemplate().execute(new JpaCallback<List<Note>>() {
public List<Note> doInJpa(EntityManager em)
throws PersistenceException {
/* breaks with user.name sorting.....*/
// CriteriaBuilder builder = em.getCriteriaBuilder();
// CriteriaQuery<Note> select = builder.createQuery(Note.class);
// Root<Note> note = select.from(Note.class);
// Path<Object> sort = note.get(sortProperty);
// Order order = null;
// if (sortAscending) {
// order = builder.asc(sort);
// } else {
// order = builder.desc(sort);
// }
// select.orderBy(order);
//
// TypedQuery<Note> query = em.createQuery(select);
/* workaround for user.name sorting... */
TypedQuery<Note> query = em.createQuery(
"from Note order by " + sortProperty + " "
+ (sortAscending ? "asc" : "desc"), Note.class);
query.setFirstResult(offset);
query.setMaxResults(count);
return query.getResultList();
}
});
}
示例6: findAll
import org.springframework.orm.jpa.JpaCallback; //导入依赖的package包/类
@TransactionAttribute(TransactionAttributeType.SUPPORTS)
public Set<T> findAll() {
return getJpaTemplate().execute(new JpaCallback<Set<T>>() {
public Set<T> doInJpa(EntityManager em) throws PersistenceException {
TypedQuery<T> query = em.createQuery(
"select x from " + type.getName() + " x", type);
return new HashSet<T>(query.getResultList());
}
});
}
示例7: countAll
import org.springframework.orm.jpa.JpaCallback; //导入依赖的package包/类
@TransactionAttribute(TransactionAttributeType.SUPPORTS)
public long countAll() {
return getJpaTemplate().execute(new JpaCallback<Integer>() {
public Integer doInJpa(EntityManager em)
throws PersistenceException {
TypedQuery<Long> query = em.createQuery("select count(x) from "
+ type.getName() + " x", Long.class);
return (query.getSingleResult()).intValue();
}
});
}
示例8: findByUsername
import org.springframework.orm.jpa.JpaCallback; //导入依赖的package包/类
@TransactionAttribute(TransactionAttributeType.SUPPORTS)
public User findByUsername(final String username) {
return getJpaTemplate().execute(new JpaCallback<User>() {
public User doInJpa(EntityManager em) throws PersistenceException {
TypedQuery<User> query = em.createNamedQuery(
"User.findByUsername", User.class);
query.setParameter("name", username);
try {
return query.getSingleResult();
} catch (NoResultException e) {
return null;
}
}
});
}
示例9: find
import org.springframework.orm.jpa.JpaCallback; //导入依赖的package包/类
public List<T> find(final String queryStr, final Object[] params,
final int begin, final int max) {
List<T> ret = (List<T>) this.getJpaTemplate().execute(
new JpaCallback() {
public Object doInJpa(EntityManager em)
throws PersistenceException {
String clazzName = clazz.getName();
StringBuffer sb = new StringBuffer("select obj from ");
sb.append(clazzName).append(" obj").append(" where ")
.append(queryStr);
Query query = em.createQuery(sb.toString());
int parameterIndex = 1;
if (params != null && params.length > 0) {
for (Object obj : params) {
query.setParameter(parameterIndex++, obj);
}
}
if (begin >= 0 && max > 0) {
query.setFirstResult(begin);
query.setMaxResults(max);
}
if (begin >= 0 && max > 0) {
query.setFirstResult(begin);
query.setMaxResults(max);
}
return query.getResultList();
}
});
if (ret != null && ret.size() >= 0) {
return ret;
} else {
return new ArrayList<T>();
}
}
示例10: getBy
import org.springframework.orm.jpa.JpaCallback; //导入依赖的package包/类
public T getBy(final String propertyName, final Object value) {
if (propertyName == null || "".equals(propertyName) || value == null)
throw new IllegalArgumentException(
I18n
.getLocaleMessage("ext.Call.parameter.is.not.correct.attribute.names.and.values.are.not.empty"));
List<T> ret = (List<T>) this.getJpaTemplate().execute(
new JpaCallback() {
public Object doInJpa(EntityManager em)
throws PersistenceException {
String clazzName = clazz.getName();
StringBuffer sb = new StringBuffer("select obj from ");
sb.append(clazzName).append(" obj");
Query query = null;
if (propertyName != null && value != null) {
sb.append(" where obj.").append(propertyName)
.append(" = :value");
query = em.createQuery(sb.toString()).setParameter(
"value", value);
} else {
query = em.createQuery(sb.toString());
}
return query.getResultList();
}
});
if (ret != null && ret.size() == 1) {
return ret.get(0);
} else if (ret != null && ret.size() > 1) {
throw new java.lang.IllegalStateException(
"worning --more than one object find!!");
} else {
return null;
}
}
示例11: executeNativeSQL
import org.springframework.orm.jpa.JpaCallback; //导入依赖的package包/类
public int executeNativeSQL(final String nnq) {
Object ret = this.getJpaTemplate().execute(new JpaCallback() {
public Object doInJpa(EntityManager em) throws PersistenceException {
Query query = em.createNativeQuery(nnq);
return query.executeUpdate();
}
});
return (Integer) ret;
}
示例12: batchUpdate
import org.springframework.orm.jpa.JpaCallback; //导入依赖的package包/类
public int batchUpdate(final String jpql, final Object[] params) {
Object ret = this.getJpaTemplate().execute(new JpaCallback() {
public Object doInJpa(EntityManager em) throws PersistenceException {
Query query = em.createQuery(jpql);
int parameterIndex = 1;
if (params != null && params.length > 0) {
for (Object obj : params) {
query.setParameter(parameterIndex++, obj);
}
}
return query.executeUpdate();
}
});
return (Integer) ret;
}
示例13: flush
import org.springframework.orm.jpa.JpaCallback; //导入依赖的package包/类
public void flush() {
this.getJpaTemplate().execute(new JpaCallback() {
public Object doInJpa(EntityManager em) throws PersistenceException {
Session session = (Session) em.getDelegate();
session.flush();
return null;
}
});
}
示例14: findAll
import org.springframework.orm.jpa.JpaCallback; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Transactional(readOnly = true)
public List<T> findAll() {
return (List<T>) getJpaTemplate().execute(new JpaCallback() {
public Object doInJpa(EntityManager entityManager) {
Query query = entityManager.createQuery("Select e from "
+ getPersistentClass().getSimpleName() + " e ");
return query.getResultList();
}
});
}