@Test @Ignore public void shouldFetchPatientFasterAfterCachingPatient() { patientDao.executeSQLQueryForSource("insert into tblPatient values(1, '123123', '')"); patientDao.executeSQLQueryForSource("insert into tblPatientNames values('michael', 'gregorski', 1)"); patientDao.executeSQLQueryForSource("insert into tblPatientNames values('micha', 'gregor', 1)"); patientDao.executeSQLQueryForSource("insert into tblPatientAddresses values('address1','cb4 2za', 1)"); patientDao.executeSQLQueryForSource("insert into tblPatientAddresses values('address2','cb4 2za', 1)"); patientDao.executeSQLQueryForSource("insert into tblPatientPhoneNumbers values('213123', 1)"); patientDao.executeSQLQueryForSource("insert into tblPatientPhoneNumbers values('0778', 1)"); long start1 = System.nanoTime(); Patient patient = patientDao.getPatient(1L); long end1 = System.nanoTime(); long diff1 = end1-start1; long start2 = System.nanoTime(); patient = patientDao.getPatient(1L); long end2 = System.nanoTime(); long diff2 = end2-start2; assertTrue(diff2 <= diff1); }
@Cacheable(value = "patients", key = "#id") public Patient getPatient(Long id) { SessionWrapper sessionWrapper = getCurrentSourceSession(); try { Query getPatient = sessionWrapper.getNamedQuery("getPatient"); getPatient.setParameter("patientId", id); logger.info("Loading patient " + id); Patient patient = (Patient) getPatient. setFirstResult(0).setMaxResults(1). setResultTransformer(Transformers.aliasToBean(Patient.class)).uniqueResult(); setNames(patient); setPhoneNumbers(patient); setAddresses(patient); setCarers(patient); setNhsNumbers(patient); setDateOfBirths(patient); return patient; } finally { sessionWrapper.closeSession(); } }
PatientDao extends BaseDao { @Cacheable(value = "patients", key = "#id") public Patient getPatient(Long id) { SessionWrapper sessionWrapper = getCurrentSourceSession(); try { Query getPatient = sessionWrapper.getNamedQuery("getPatient"); getPatient.setParameter("patientId", id); logger.info("Loading patient " + id); Patient patient = (Patient) getPatient. setFirstResult(0).setMaxResults(1). setResultTransformer(Transformers.aliasToBean(Patient.class)).uniqueResult(); setNames(patient); setPhoneNumbers(patient); setAddresses(patient); setCarers(patient); setNhsNumbers(patient); setDateOfBirths(patient); return patient; } finally { sessionWrapper.closeSession(); } } }
PatientDao extends BaseDao { @Cacheable(value = "patients", key = "#id") public Patient getPatient(Long id) { SessionWrapper sessionWrapper = getCurrentSourceSession(); try { Query getPatient = sessionWrapper.getNamedQuery("getPatient"); getPatient.setParameter("patientId", id); logger.info("Loading patient " + id); Patient patient = (Patient) getPatient. setFirstResult(0).setMaxResults(1). setResultTransformer(Transformers.aliasToBean(Patient.class)).uniqueResult(); setNames(patient); setPhoneNumbers(patient); setAddresses(patient); setCarers(patient); setNhsNumbers(patient); setDateOfBirths(patient); return patient; } finally { sessionWrapper.closeSession(); } }  }
PatientDao extends BaseDao { @Cacheable(value = "patients", key = "#id") public Patient getPatient(Long id) { SessionWrapper sessionWrapper = getCurrentSourceSession(); try { Query getPatient = sessionWrapper.getNamedQuery("getPatient"); getPatient.setParameter("patientId", id); logger.info("Loading patient " + id); Patient patient = (Patient) getPatient. setFirstResult(0).setMaxResults(1). setResultTransformer(Transformers.aliasToBean(Patient.class)).uniqueResult(); setNames(patient); setPhoneNumbers(patient); setAddresses(patient); setCarers(patient); setNhsNumbers(patient); setDateOfBirths(patient); return patient; } finally { sessionWrapper.closeSession(); } }  @Cacheable(value = "patients", key = "#id") Patient getPatient(Long id); }
PatientDao extends BaseDao { @Cacheable(value = "patients", key = "#id") public Patient getPatient(Long id) { SessionWrapper sessionWrapper = getCurrentSourceSession(); try { Query getPatient = sessionWrapper.getNamedQuery("getPatient"); getPatient.setParameter("patientId", id); logger.info("Loading patient " + id); Patient patient = (Patient) getPatient. setFirstResult(0).setMaxResults(1). setResultTransformer(Transformers.aliasToBean(Patient.class)).uniqueResult(); setNames(patient); setPhoneNumbers(patient); setAddresses(patient); setCarers(patient); setNhsNumbers(patient); setDateOfBirths(patient); return patient; } finally { sessionWrapper.closeSession(); } }  @Cacheable(value = "patients", key = "#id") Patient getPatient(Long id);  }