List of usage examples for javax.persistence EntityManager createNamedQuery
public Query createNamedQuery(String name);
Query
for executing a named query (in the Java Persistence query language or in native SQL). From source file:de.zib.gndms.dspace.subspace.service.globus.resource.ExtSubspaceResourceHome.java
@NotNull public Query getListAllQuery(final @NotNull EntityManager em) { return em.createNamedQuery("listAllSubspaceIds"); }
From source file:eu.europa.ec.fisheries.uvms.spatial.service.dao.OracleUtilsDao.java
public OracleUtilsDao(EntityManager em) { this.em = em; mapDefaultSridToEpsg = em.createNativeQuery(MAP_DEFAULT_SRID_TO_EPSG); mapDefaultSridToEpsg.setMaxResults(1); mapEpsgToDefaultSrid = em.createNamedQuery(MAP_EPSG_TO_DEFAULT_SRID); mapEpsgToDefaultSrid.setMaxResults(1); }
From source file:fr.mby.opa.picsimpl.dao.DbAlbumDao.java
@Override public Album loadAlbumById(final Long id) { Assert.notNull(id, "Album Id should be supplied !"); final EmCallback<Album> emCallback = new EmCallback<Album>(this.getEmf()) { @Override//from w ww . ja va 2s . c o m @SuppressWarnings("unchecked") protected Album executeWithEntityManager(final EntityManager em) throws PersistenceException { final Query findByIdQuery = em.createNamedQuery(Album.LOAD_FULL_ALBUM_BY_ID); findByIdQuery.setParameter("id", id); final Album album = Iterables.getFirst(findByIdQuery.getResultList(), null); return album; } }; return emCallback.getReturnedValue(); }
From source file:com.sun.socialsite.business.impl.JPAPersistenceStrategy.java
/** * Get named update query with default flush mode * @param queryName the name of the query * @throws SocialSiteException on any error *///from w w w . java2 s .com public Query getNamedUpdate(String queryName) throws SocialSiteException { EntityManager em = getEntityManager(true); Query q = em.createNamedQuery(queryName); return q; }
From source file:com.sun.socialsite.business.impl.JPAPersistenceStrategy.java
/** * Get named query with FlushModeType.COMMIT * @param queryName the name of the query * @throws SocialSiteException on any error *//*from w w w .j av a 2 s. c om*/ public Query getNamedQuery(String queryName) throws SocialSiteException { EntityManager em = getEntityManager(false); Query q = em.createNamedQuery(queryName); // Never flush for queries. SocialSite code assumes this behavior q.setFlushMode(FlushModeType.COMMIT); return q; }
From source file:fr.mby.opa.picsimpl.dao.DbAlbumDao.java
@Override @SuppressWarnings("unchecked") public Collection<Album> findAllAlbums() { final EmCallback<Collection<Album>> emCallback = new EmCallback<Collection<Album>>(this.getEmf()) { @Override/*from www. j a va 2s . c o m*/ protected Collection<Album> executeWithEntityManager(final EntityManager em) throws PersistenceException { final Query findAllQuery = em.createNamedQuery(Album.FIND_ALL_ALBUMS_ORDER_BY_DATE); return findAllQuery.getResultList(); } }; Collection<Album> albums = emCallback.getReturnedValue(); if (albums == null) { albums = Collections.emptyList(); } return albums; }
From source file:fr.mby.portal.coreimpl.auth.DbPortalUserAuthenticationProvider.java
protected PortalUser findPortalUserByLogin(final EntityManager portalUserEm, final String login) { final Query query = portalUserEm.createNamedQuery(PortalUser.FIND_PORTAL_USER); query.setParameter("login", login); PortalUser found = null;//w w w.java 2s . co m final List<?> founds = query.getResultList(); if (founds != null && founds.size() == 1) { found = (PortalUser) founds.iterator().next(); } return found; }
From source file:org.apache.falcon.jdbc.MonitoringJdbcStateStore.java
public List<MonitoredFeedsBean> getAllMonitoredFeed() throws ResultNotFoundException { EntityManager entityManager = getEntityManager(); Query q = entityManager.createNamedQuery(PersistenceConstants.GET_ALL_MONITORING_FEEDS); List result = q.getResultList(); entityManager.close();/*from www.j a va 2s .c om*/ return result; }
From source file:org.apache.falcon.jdbc.MonitoringJdbcStateStore.java
public List<Date> getNominalInstances(String feedName, String clusterName) { EntityManager entityManager = getEntityManager(); Query q = entityManager.createNamedQuery(PersistenceConstants.GET_DATE_FOR_PENDING_INSTANCES); q.setParameter("feedName", feedName); q.setParameter("clusterName", clusterName); List result = q.getResultList(); entityManager.close();//from w ww . j a v a 2 s.c o m return result; }
From source file:org.apache.falcon.jdbc.MonitoringJdbcStateStore.java
public MonitoredFeedsBean getMonitoredFeed(String feedName) { EntityManager entityManager = getEntityManager(); Query q = entityManager.createNamedQuery(PersistenceConstants.GET_MONITERED_INSTANCE); q.setParameter("feedName", feedName); List result = q.getResultList(); try {//w ww . jav a 2 s . co m if (result.isEmpty()) { return null; } } finally { entityManager.close(); } return ((MonitoredFeedsBean) result.get(0)); }