@Test public void testCrud() { final JpaMedia media = new JpaMedia(); media.setName("jdk 1.8"); media.setType(MediaType.JDK); media.setLocalPath(Paths.get("c:/java/jdk.zip")); media.setRemoteDir(Paths.get("c:/ctp")); media.setRootDir(Paths.get("jdk-1.8")); mediaDao.create(media); final JpaMedia foundMedia = mediaDao.find("jdk 1.8"); assertEquals(media, foundMedia); assertEquals(mediaDao.findAll().size(), 1); mediaDao.remove(media); assertEquals(mediaDao.findAll().size(), 0); }
@Override public JpaMedia find(final String name) { final Query q = entityManager.createNamedQuery(JpaMedia.QUERY_FIND_BY_NAME, JpaMedia.class); q.setParameter(JpaMedia.PARAM_NAME, name); return (JpaMedia) q.getSingleResult(); }
MediaDaoImpl extends AbstractCrudServiceImpl<JpaMedia> implements MediaDao { @Override public JpaMedia find(final String name) { final Query q = entityManager.createNamedQuery(JpaMedia.QUERY_FIND_BY_NAME, JpaMedia.class); q.setParameter(JpaMedia.PARAM_NAME, name); return (JpaMedia) q.getSingleResult(); } }
MediaDaoImpl extends AbstractCrudServiceImpl<JpaMedia> implements MediaDao { @Override public JpaMedia find(final String name) { final Query q = entityManager.createNamedQuery(JpaMedia.QUERY_FIND_BY_NAME, JpaMedia.class); q.setParameter(JpaMedia.PARAM_NAME, name); return (JpaMedia) q.getSingleResult(); }  }
MediaDaoImpl extends AbstractCrudServiceImpl<JpaMedia> implements MediaDao { @Override public JpaMedia find(final String name) { final Query q = entityManager.createNamedQuery(JpaMedia.QUERY_FIND_BY_NAME, JpaMedia.class); q.setParameter(JpaMedia.PARAM_NAME, name); return (JpaMedia) q.getSingleResult(); }  @Override JpaMedia find(final String name); @Override JpaMedia findByNameAndType(String name, MediaType type); }
MediaDaoImpl extends AbstractCrudServiceImpl<JpaMedia> implements MediaDao { @Override public JpaMedia find(final String name) { final Query q = entityManager.createNamedQuery(JpaMedia.QUERY_FIND_BY_NAME, JpaMedia.class); q.setParameter(JpaMedia.PARAM_NAME, name); return (JpaMedia) q.getSingleResult(); }  @Override JpaMedia find(final String name); @Override JpaMedia findByNameAndType(String name, MediaType type);  }