@Test public void testFindByAppAndPersonId() { AppData testAppData = jpaAppDataMapper.findOrCreateByPersonAndGadgetDefinitionIds(testGadgetDefinitionId, testOpenSocialPersonId); assertEquals("Person is not correct for retrieved AppData", testOpenSocialPersonId, testAppData.getPerson() .getOpenSocialId()); assertEquals("GadgetDefinition is not correct for retrieved AppData", testGadgetDefinitionUrl, testAppData .getGadgetDefinition().getUrl()); }
@SuppressWarnings("unchecked") public AppData findOrCreateByPersonAndGadgetDefinitionIds(final long gadgetDefinitionId, final String personId) { String logMsg = "GadgetDefId#" + gadgetDefinitionId + ", open social id: " + personId; log.info("Looking for the AppData in the database for " + logMsg); AppData outputAppData = null; Query query = getEntityManager().createQuery( "from AppData a where a.person.openSocialId = " + ":openSocialId and a.gadgetDefinition.id = :gadgetDefinitionId").setParameter("openSocialId", personId).setParameter("gadgetDefinitionId", gadgetDefinitionId); List<AppData> appDataList = query.getResultList(); if (appDataList.size() > 0) { log.info("Found the AppData in the database for " + logMsg); outputAppData = appDataList.get(0); } else { log.info("Didn't find the AppData in the database for " + logMsg + " - building it"); Query getPersonQuery = getEntityManager().createQuery("from Person p where p.openSocialId = :openSocialId") .setParameter("openSocialId", personId); Query getGadgetDefQuery = getEntityManager().createQuery( "from GadgetDefinition gd where gd.id = :gadgetDefinitionId").setParameter("gadgetDefinitionId", gadgetDefinitionId); Person currentPerson = null; GadgetDefinition currentGadgetDefinition = null; List<Person> peopleList = getPersonQuery.getResultList(); if (peopleList.size() > 0) { List<GadgetDefinition> gadgetDefList = getGadgetDefQuery.getResultList(); if (gadgetDefList.size() > 0) { log.info("Persisting AppData for " + logMsg); currentPerson = peopleList.get(0); currentGadgetDefinition = gadgetDefList.get(0); outputAppData = new AppData(currentPerson, currentGadgetDefinition); getEntityManager().persist(outputAppData); } } } return outputAppData; }
AppDataMapper extends DomainEntityMapper<AppData> { @SuppressWarnings("unchecked") public AppData findOrCreateByPersonAndGadgetDefinitionIds(final long gadgetDefinitionId, final String personId) { String logMsg = "GadgetDefId#" + gadgetDefinitionId + ", open social id: " + personId; log.info("Looking for the AppData in the database for " + logMsg); AppData outputAppData = null; Query query = getEntityManager().createQuery( "from AppData a where a.person.openSocialId = " + ":openSocialId and a.gadgetDefinition.id = :gadgetDefinitionId").setParameter("openSocialId", personId).setParameter("gadgetDefinitionId", gadgetDefinitionId); List<AppData> appDataList = query.getResultList(); if (appDataList.size() > 0) { log.info("Found the AppData in the database for " + logMsg); outputAppData = appDataList.get(0); } else { log.info("Didn't find the AppData in the database for " + logMsg + " - building it"); Query getPersonQuery = getEntityManager().createQuery("from Person p where p.openSocialId = :openSocialId") .setParameter("openSocialId", personId); Query getGadgetDefQuery = getEntityManager().createQuery( "from GadgetDefinition gd where gd.id = :gadgetDefinitionId").setParameter("gadgetDefinitionId", gadgetDefinitionId); Person currentPerson = null; GadgetDefinition currentGadgetDefinition = null; List<Person> peopleList = getPersonQuery.getResultList(); if (peopleList.size() > 0) { List<GadgetDefinition> gadgetDefList = getGadgetDefQuery.getResultList(); if (gadgetDefList.size() > 0) { log.info("Persisting AppData for " + logMsg); currentPerson = peopleList.get(0); currentGadgetDefinition = gadgetDefList.get(0); outputAppData = new AppData(currentPerson, currentGadgetDefinition); getEntityManager().persist(outputAppData); } } } return outputAppData; } }
AppDataMapper extends DomainEntityMapper<AppData> { @SuppressWarnings("unchecked") public AppData findOrCreateByPersonAndGadgetDefinitionIds(final long gadgetDefinitionId, final String personId) { String logMsg = "GadgetDefId#" + gadgetDefinitionId + ", open social id: " + personId; log.info("Looking for the AppData in the database for " + logMsg); AppData outputAppData = null; Query query = getEntityManager().createQuery( "from AppData a where a.person.openSocialId = " + ":openSocialId and a.gadgetDefinition.id = :gadgetDefinitionId").setParameter("openSocialId", personId).setParameter("gadgetDefinitionId", gadgetDefinitionId); List<AppData> appDataList = query.getResultList(); if (appDataList.size() > 0) { log.info("Found the AppData in the database for " + logMsg); outputAppData = appDataList.get(0); } else { log.info("Didn't find the AppData in the database for " + logMsg + " - building it"); Query getPersonQuery = getEntityManager().createQuery("from Person p where p.openSocialId = :openSocialId") .setParameter("openSocialId", personId); Query getGadgetDefQuery = getEntityManager().createQuery( "from GadgetDefinition gd where gd.id = :gadgetDefinitionId").setParameter("gadgetDefinitionId", gadgetDefinitionId); Person currentPerson = null; GadgetDefinition currentGadgetDefinition = null; List<Person> peopleList = getPersonQuery.getResultList(); if (peopleList.size() > 0) { List<GadgetDefinition> gadgetDefList = getGadgetDefQuery.getResultList(); if (gadgetDefList.size() > 0) { log.info("Persisting AppData for " + logMsg); currentPerson = peopleList.get(0); currentGadgetDefinition = gadgetDefList.get(0); outputAppData = new AppData(currentPerson, currentGadgetDefinition); getEntityManager().persist(outputAppData); } } } return outputAppData; } AppDataMapper(final QueryOptimizer inQueryOptimizer); }
AppDataMapper extends DomainEntityMapper<AppData> { @SuppressWarnings("unchecked") public AppData findOrCreateByPersonAndGadgetDefinitionIds(final long gadgetDefinitionId, final String personId) { String logMsg = "GadgetDefId#" + gadgetDefinitionId + ", open social id: " + personId; log.info("Looking for the AppData in the database for " + logMsg); AppData outputAppData = null; Query query = getEntityManager().createQuery( "from AppData a where a.person.openSocialId = " + ":openSocialId and a.gadgetDefinition.id = :gadgetDefinitionId").setParameter("openSocialId", personId).setParameter("gadgetDefinitionId", gadgetDefinitionId); List<AppData> appDataList = query.getResultList(); if (appDataList.size() > 0) { log.info("Found the AppData in the database for " + logMsg); outputAppData = appDataList.get(0); } else { log.info("Didn't find the AppData in the database for " + logMsg + " - building it"); Query getPersonQuery = getEntityManager().createQuery("from Person p where p.openSocialId = :openSocialId") .setParameter("openSocialId", personId); Query getGadgetDefQuery = getEntityManager().createQuery( "from GadgetDefinition gd where gd.id = :gadgetDefinitionId").setParameter("gadgetDefinitionId", gadgetDefinitionId); Person currentPerson = null; GadgetDefinition currentGadgetDefinition = null; List<Person> peopleList = getPersonQuery.getResultList(); if (peopleList.size() > 0) { List<GadgetDefinition> gadgetDefList = getGadgetDefQuery.getResultList(); if (gadgetDefList.size() > 0) { log.info("Persisting AppData for " + logMsg); currentPerson = peopleList.get(0); currentGadgetDefinition = gadgetDefList.get(0); outputAppData = new AppData(currentPerson, currentGadgetDefinition); getEntityManager().persist(outputAppData); } } } return outputAppData; } AppDataMapper(final QueryOptimizer inQueryOptimizer); @SuppressWarnings("unchecked") AppData findOrCreateByPersonAndGadgetDefinitionIds(final long gadgetDefinitionId, final String personId); void deleteAppDataValueByKey(final long appDataId, final String appDataValueKey); }
AppDataMapper extends DomainEntityMapper<AppData> { @SuppressWarnings("unchecked") public AppData findOrCreateByPersonAndGadgetDefinitionIds(final long gadgetDefinitionId, final String personId) { String logMsg = "GadgetDefId#" + gadgetDefinitionId + ", open social id: " + personId; log.info("Looking for the AppData in the database for " + logMsg); AppData outputAppData = null; Query query = getEntityManager().createQuery( "from AppData a where a.person.openSocialId = " + ":openSocialId and a.gadgetDefinition.id = :gadgetDefinitionId").setParameter("openSocialId", personId).setParameter("gadgetDefinitionId", gadgetDefinitionId); List<AppData> appDataList = query.getResultList(); if (appDataList.size() > 0) { log.info("Found the AppData in the database for " + logMsg); outputAppData = appDataList.get(0); } else { log.info("Didn't find the AppData in the database for " + logMsg + " - building it"); Query getPersonQuery = getEntityManager().createQuery("from Person p where p.openSocialId = :openSocialId") .setParameter("openSocialId", personId); Query getGadgetDefQuery = getEntityManager().createQuery( "from GadgetDefinition gd where gd.id = :gadgetDefinitionId").setParameter("gadgetDefinitionId", gadgetDefinitionId); Person currentPerson = null; GadgetDefinition currentGadgetDefinition = null; List<Person> peopleList = getPersonQuery.getResultList(); if (peopleList.size() > 0) { List<GadgetDefinition> gadgetDefList = getGadgetDefQuery.getResultList(); if (gadgetDefList.size() > 0) { log.info("Persisting AppData for " + logMsg); currentPerson = peopleList.get(0); currentGadgetDefinition = gadgetDefList.get(0); outputAppData = new AppData(currentPerson, currentGadgetDefinition); getEntityManager().persist(outputAppData); } } } return outputAppData; } AppDataMapper(final QueryOptimizer inQueryOptimizer); @SuppressWarnings("unchecked") AppData findOrCreateByPersonAndGadgetDefinitionIds(final long gadgetDefinitionId, final String personId); void deleteAppDataValueByKey(final long appDataId, final String appDataValueKey);  }