List of usage examples for javax.persistence Query setParameter
Query setParameter(int position, Object value);
From source file:org.kuali.mobility.emergencyinfo.dao.EmergencyInfoDaoImpl.java
public void deleteEmergencyInfoById(Long id) { Query query = entityManager.createQuery("delete from MaintEmergencyInfo ei where ei.emergencyInfoId = :id"); query.setParameter("id", id); query.executeUpdate();/*from w w w. j a v a 2s . c om*/ }
From source file:ru.anr.base.dao.BaseRepositoryImpl.java
/** * {@inheritDoc}/*from ww w .ja v a 2s . c o m*/ */ @SuppressWarnings("unchecked") @Override public <S extends BaseEntity> List<S> query(String queryStr, Object... params) { Query q = entityManager.createQuery(queryStr); if (params != null) { for (int i = 0; i < params.length; i++) { q.setParameter(i + 1, params[i]); } } return q.getResultList(); }
From source file:com.tapas.evidence.repository.ResponsiblePersonRepositoryImpl.java
@Override @SuppressWarnings("unchecked") public List<ResponsiblePerson> findByKindergartenIdAndType(final Long kindergartenId, final ResponsibilityType type) { final Long tenantId = ((EvidenceUserDetails) SecurityContextHolder.getContext().getAuthentication() .getPrincipal()).getTenantId(); Query query = this.entityManager .createNamedQuery(ResponsiblePerson.QUERY_NAME_FIND_BY_KINDERGARTEN_ID_AND_TYPE_AND_DELETE_FLAG); query.setParameter("deleted", Boolean.FALSE); query.setParameter("kindergartenId", kindergartenId); query.setParameter("type", type); query.setParameter("tenantId", tenantId); return query.getResultList(); }
From source file:org.syncope.core.persistence.dao.impl.TaskDAOImpl.java
@Override public <T extends Task> List<T> findAll(final ExternalResource resource, final Class<T> reference) { StringBuilder queryString = buildfindAllQuery(reference); if (SchedTask.class.equals(reference)) { queryString.append("AND "); } else {/*from w w w .j av a 2s .c o m*/ queryString.append("WHERE "); } queryString.append("e.resource=:resource"); final Query query = entityManager.createQuery(queryString.toString()); query.setParameter("resource", resource); return query.getResultList(); }
From source file:org.venice.piazza.common.hibernate.dao.dataresource.DataResourceDaoImpl.java
public Page<DataResourceEntity> getDataResourceForUserAndKeyword(String keyword, String userName, Pagination pagination) {/* ww w. j a v a 2s .c om*/ // Query String queryString = String.format(USERNAME_AND_KEYWORD_DATARESOURCE_QUERY, Direction.fromString(pagination.getOrder())); Query query = entityManager.createNativeQuery(queryString, DataResourceEntity.class); query.setParameter(1, String.format(WILDCARD_STRING_QUERY, keyword)); query.setParameter(2, String.format(WILDCARD_STRING_QUERY, keyword)); query.setParameter(3, String.format(WILDCARD_STRING_QUERY, userName)); query.setParameter(4, pagination.getSortBy()); query.setParameter(5, pagination.getPerPage()); query.setParameter(6, pagination.getPage() * pagination.getPerPage()); List<DataResourceEntity> results = query.getResultList(); // Count query = entityManager.createNativeQuery(USERNAME_AND_KEYWORD_DATARESOURCE_QUERY_COUNT); query.setParameter(1, String.format(WILDCARD_STRING_QUERY, keyword)); query.setParameter(2, String.format(WILDCARD_STRING_QUERY, keyword)); query.setParameter(3, String.format(WILDCARD_STRING_QUERY, userName)); long count = ((BigInteger) query.getSingleResult()).longValue(); return new PageImpl<DataResourceEntity>(results, null, count); }
From source file:com.mothsoft.alexis.dao.DataSetPointDaoImpl.java
@SuppressWarnings("unchecked") @Override/* www. j a va 2s . c om*/ public DataSetPoint findLastPointBefore(final DataSet dataSet, final Timestamp timestamp) { final String queryString = "SELECT p FROM DataSetPoint p WHERE p.dataSet = :dataSet AND p.x <= :timestamp ORDER BY p.x DESC"; final Query query = this.em.createQuery(queryString); query.setParameter("dataSet", dataSet); query.setParameter("timestamp", timestamp); query.setMaxResults(1); final List<DataSetPoint> points = query.getResultList(); if (points.isEmpty()) { return null; } else { return points.get(0); } }
From source file:de.berlios.jhelpdesk.dao.jpa.TicketFilterDAOJpa.java
private void deleteFilterItems(EntityManager em, Long filterId) { for (String table : tables) { Query query = em .createNativeQuery("DELETE FROM ticket_filters_" + table + " WHERE ticket_filter_id=?1"); query.setParameter(1, filterId); query.executeUpdate();//from w ww. j av a 2 s.c om } }
From source file:org.apache.cxf.fediz.service.idp.service.jpa.EntitlementDAOJPAImpl.java
@Override public void deleteEntitlement(String name) { Query query = null; query = em.createQuery("select e from Entitlement e where e.name=:name"); query.setParameter("name", name); //@SuppressWarnings("rawtypes") Object entitlementObj = query.getSingleResult(); em.remove(entitlementObj);/* ww w .j a v a2 s .c o m*/ LOG.debug("Entitlement '{}' deleted", name); }
From source file:com.june.app.cmn.repository.jpa.FileRepositoryImpl.java
@Override public FileDetail fileSingle(FileDetail filedetail) { String atchFileId = filedetail.getAtchFileId(); int fileSn = filedetail.getFileSn(); Query query = this.em.createQuery( "SELECT fileDetail FROM FileDetail fileDetail WHERE fileDetail.atchFileId =:atchFileId and fileDetail.fileSn =:fileSn"); query.setParameter("atchFileId", atchFileId); query.setParameter("fileSn", fileSn); return (FileDetail) query.getSingleResult(); }
From source file:org.messic.server.datamodel.jpaimpl.DAOJPAPlaylist.java
@Override @Transactional//from ww w . j av a 2 s. c o m public MDOPlaylist getByName(String username, String name) { Query query = entityManager.createQuery( "from MDOPlaylist as a where (a.owner.login = :userName) and (a.name = :playlistName)"); query.setParameter("userName", username); query.setParameter("playlistName", name); @SuppressWarnings("unchecked") List<MDOPlaylist> results = query.getResultList(); if (results != null && results.size() > 0) { return results.get(0); } else { return null; } }