@Test public void testFindOrCreatePersonBackground() { String openSocialId = "2d359911-0977-418a-9490-57e8252b1a98"; Background background = jpaBackgroundMapper.findOrCreatePersonBackground(openSocialId); assertNotNull(background); Background confirmBg = jpaBackgroundMapper.findById(background.getId()); assertEquals(background, confirmBg); }
@SuppressWarnings("unchecked") public Background findOrCreatePersonBackground(final String inOpenSocialId) { Background background = findPersonBackground(inOpenSocialId); if (null == background) { logger.debug("background not found, so creating one"); Query q = getEntityManager().createQuery("from Person where openSocialId = :openSocialId").setParameter( "openSocialId", inOpenSocialId); List personList = q.getResultList(); if (personList.size() == 0) { return null; } background = new Background((Person) personList.get(0)); background.setBackgroundItems(new ArrayList<BackgroundItem>(), BackgroundItemType.AFFILIATION); background.setBackgroundItems(new ArrayList<BackgroundItem>(), BackgroundItemType.HONOR); background.setBackgroundItems(new ArrayList<BackgroundItem>(), BackgroundItemType.INTEREST); background.setBackgroundItems(new ArrayList<BackgroundItem>(), BackgroundItemType.SKILL); getEntityManager().persist(background); } return background; }
BackgroundMapper extends DomainEntityMapper<Background> { @SuppressWarnings("unchecked") public Background findOrCreatePersonBackground(final String inOpenSocialId) { Background background = findPersonBackground(inOpenSocialId); if (null == background) { logger.debug("background not found, so creating one"); Query q = getEntityManager().createQuery("from Person where openSocialId = :openSocialId").setParameter( "openSocialId", inOpenSocialId); List personList = q.getResultList(); if (personList.size() == 0) { return null; } background = new Background((Person) personList.get(0)); background.setBackgroundItems(new ArrayList<BackgroundItem>(), BackgroundItemType.AFFILIATION); background.setBackgroundItems(new ArrayList<BackgroundItem>(), BackgroundItemType.HONOR); background.setBackgroundItems(new ArrayList<BackgroundItem>(), BackgroundItemType.INTEREST); background.setBackgroundItems(new ArrayList<BackgroundItem>(), BackgroundItemType.SKILL); getEntityManager().persist(background); } return background; } }
BackgroundMapper extends DomainEntityMapper<Background> { @SuppressWarnings("unchecked") public Background findOrCreatePersonBackground(final String inOpenSocialId) { Background background = findPersonBackground(inOpenSocialId); if (null == background) { logger.debug("background not found, so creating one"); Query q = getEntityManager().createQuery("from Person where openSocialId = :openSocialId").setParameter( "openSocialId", inOpenSocialId); List personList = q.getResultList(); if (personList.size() == 0) { return null; } background = new Background((Person) personList.get(0)); background.setBackgroundItems(new ArrayList<BackgroundItem>(), BackgroundItemType.AFFILIATION); background.setBackgroundItems(new ArrayList<BackgroundItem>(), BackgroundItemType.HONOR); background.setBackgroundItems(new ArrayList<BackgroundItem>(), BackgroundItemType.INTEREST); background.setBackgroundItems(new ArrayList<BackgroundItem>(), BackgroundItemType.SKILL); getEntityManager().persist(background); } return background; } BackgroundMapper(final QueryOptimizer inQueryOptimizer, final PersonMapper inPersonMapper); }
BackgroundMapper extends DomainEntityMapper<Background> { @SuppressWarnings("unchecked") public Background findOrCreatePersonBackground(final String inOpenSocialId) { Background background = findPersonBackground(inOpenSocialId); if (null == background) { logger.debug("background not found, so creating one"); Query q = getEntityManager().createQuery("from Person where openSocialId = :openSocialId").setParameter( "openSocialId", inOpenSocialId); List personList = q.getResultList(); if (personList.size() == 0) { return null; } background = new Background((Person) personList.get(0)); background.setBackgroundItems(new ArrayList<BackgroundItem>(), BackgroundItemType.AFFILIATION); background.setBackgroundItems(new ArrayList<BackgroundItem>(), BackgroundItemType.HONOR); background.setBackgroundItems(new ArrayList<BackgroundItem>(), BackgroundItemType.INTEREST); background.setBackgroundItems(new ArrayList<BackgroundItem>(), BackgroundItemType.SKILL); getEntityManager().persist(background); } return background; } BackgroundMapper(final QueryOptimizer inQueryOptimizer, final PersonMapper inPersonMapper); @SuppressWarnings("unchecked") Background findPersonBackground(final String inOpenSocialId); void delete(final Background inBackground); void deleteItem(final BackgroundItem item); @SuppressWarnings("unchecked") Background findOrCreatePersonBackground(final String inOpenSocialId); @SuppressWarnings("unchecked") List<String> findBackgroundItemNamesByType(final BackgroundItemType backgroundType,
            final String searchString, final int maxResults); void flush(final String uuid); }
BackgroundMapper extends DomainEntityMapper<Background> { @SuppressWarnings("unchecked") public Background findOrCreatePersonBackground(final String inOpenSocialId) { Background background = findPersonBackground(inOpenSocialId); if (null == background) { logger.debug("background not found, so creating one"); Query q = getEntityManager().createQuery("from Person where openSocialId = :openSocialId").setParameter( "openSocialId", inOpenSocialId); List personList = q.getResultList(); if (personList.size() == 0) { return null; } background = new Background((Person) personList.get(0)); background.setBackgroundItems(new ArrayList<BackgroundItem>(), BackgroundItemType.AFFILIATION); background.setBackgroundItems(new ArrayList<BackgroundItem>(), BackgroundItemType.HONOR); background.setBackgroundItems(new ArrayList<BackgroundItem>(), BackgroundItemType.INTEREST); background.setBackgroundItems(new ArrayList<BackgroundItem>(), BackgroundItemType.SKILL); getEntityManager().persist(background); } return background; } BackgroundMapper(final QueryOptimizer inQueryOptimizer, final PersonMapper inPersonMapper); @SuppressWarnings("unchecked") Background findPersonBackground(final String inOpenSocialId); void delete(final Background inBackground); void deleteItem(final BackgroundItem item); @SuppressWarnings("unchecked") Background findOrCreatePersonBackground(final String inOpenSocialId); @SuppressWarnings("unchecked") List<String> findBackgroundItemNamesByType(final BackgroundItemType backgroundType,
            final String searchString, final int maxResults); void flush(final String uuid);  }