[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
[eclipselink-users] Caching
|
Here is snapshot of my jpa entity
aim: configure cache in way, select query pick up the data from the cache.
If there is an insert update delete the cache is also updated
Problem:- Is see multiple select query for the same entity "CodFlexCodesB"
In hibernate the query logging used to take place (but it was object query)
Is the same behavior eclipse link shows or I am making some mistake
Here is code snippet for your reference.
package com.oracle.healthinsurance.orm.entities;
import java.sql.Timestamp;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.QueryHint;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import org.eclipse.persistence.annotations.Cache;
import org.eclipse.persistence.annotations.CacheCoordinationType;
import org.eclipse.persistence.annotations.CacheType;
import org.eclipse.persistence.config.CacheUsage;
import org.eclipse.persistence.config.QueryHints;
import com.oracle.healthinsurance.model.entity.PersistableWithTimeValidity;
@Entity
@Cache (
type=CacheType.WEAK,
expiry=600000,
refreshOnlyIfNewer=true,
disableHits=false,
coordinationType=CacheCoordinationType.SEND_NEW_OBJECTS_WITH_CHANGES
)
@NamedQueries( {
@NamedQuery(name = "CodFlexCodesB.findAll",
query = "select o from CodFlexCodesB o"),
@NamedQuery(name = "CodFlexCodesB.timeValidity",
query = "SELECT em FROM CodFlexCodesB em " +
"WHERE em.codFlexCodeSystemsB.id = :id AND " +
"(em.startDate <= :endDate OR :endDate IS NULL ) AND (em.endDate
>= :startDate OR em.endDate IS NULL) ",
hints = @QueryHint(name=QueryHints.CACHE_USAGE,
value=CacheUsage.ConformResultsInUnitOfWork )
)
})
@Table(name = "COD_FLEX_CODES_B")
public class CodFlexCodesB implements PersistableWithTimeValidity {
--- ---- ---- ---
--- ---- ---- ---
Here is the snapshot of my Spring JPA test case
@Transactional
public void testInsertCodeValueWithMLS() {
CrudService<CodFlexCodesB> codeService = service;
CodFlexCodeSystemsB codeSystem = new CodFlexCodeSystemsB();
codeSystem.setId(new Long(10001));
Date today = new Date();
Long todayInLng = today.getTime();
Timestamp todayTS = new Timestamp(todayInLng);
codeSystem.setCreatedBy(todayInLng);
codeSystem.setLastUpdatedBy(todayInLng);
codeSystem.setCreationDate(todayTS);
codeSystem.setEndDate(todayTS);
codeSystem.setLastUpdatedDate(todayTS);
codeSystem.setObjectVersionNumber(new Long(1));
codeSystem.setLastUpdateLogin("test");
CodFlexCodesTl codeValueTl = new CodFlexCodesTl();
codeValueTl.setCreatedBy(todayInLng);
codeValueTl.setLastUpdatedBy(todayInLng);
codeValueTl.setCreationDate(todayTS);
codeValueTl.setLastUpdatedDate(todayTS);
codeValueTl.setObjectVersionNumber(new Long(1));
codeValueTl.setKeyValue("GMTEst");
codeValueTl.setSourceLang("NL");
codeValueTl.setLastUpdateLogin("test");
codeValueTl.setLanguage("US");
List<CodFlexCodesTl> listTl = new ArrayList();
listTl.add(codeValueTl);
CodFlexCodesB codesValue = new CodFlexCodesB();
codesValue.setStartDate(todayTS);
codesValue.setCodFlexCodeSystemsB(codeSystem);
codesValue.setCreatedBy(todayInLng);
codesValue.setLastUpdatedBy(todayInLng);
codesValue.setCreationDate(todayTS);
codesValue.setStartDate(todayTS);
codesValue.setLastUpdatedDate(todayTS);
codesValue.setObjectVersionNumber(new Long(1));
codesValue.setLastUpdateLogin("test");
codesValue.setCodFlexCodesTlList(listTl);
// endDate 10 days hence....
GregorianCalendar gc = new GregorianCalendar();
gc.setTimeInMillis(todayInLng);
gc.add(Calendar.DAY_OF_WEEK, 10);
codesValue.setEndDate(new Timestamp(gc.getTimeInMillis()));
codeValueTl.setCodFlexCodesB(codesValue);
// startDate = today and endDate = startDate + 10
codesValue = codeService.create(codesValue);
Assert.assertNotNull(codesValue.getId());
// Now check for the time validity
CodFlexCodesB cv = (CodFlexCodesB) ObjectCloner.deepCopy(codesValue);
// Test case 1. The same entity should fail
// startDate = today and endDate = startDate + 10
// for "CodFlexCodesB"
boolean testCase1 = service.isTimeValid(cv);
System.err.println(">>>>><<<<< " + testCase1);
Assert.assertEquals(false,testCase1);
//Test case2. Actually modify the "CodFlexCodesB"
// startDate=today + 11
// endDate = startDate + 10
Date tc2Today = new Date();
GregorianCalendar tc2GC = new GregorianCalendar();
tc2GC.setTime(tc2Today);
tc2GC.add(Calendar.DAY_OF_WEEK, 11);
cv.setStartDate(new Timestamp(tc2GC.getTimeInMillis()));
tc2GC.setTimeInMillis(tc2GC.getTimeInMillis());
tc2GC.add(Calendar.DAY_OF_WEEK, 10);
cv.setEndDate(new Timestamp(tc2GC.getTimeInMillis()));
boolean testCase2 = service.isTimeValid(cv);
Assert.assertEquals(true,testCase2);
//Test case3. Actually modify the "CodFlexCodesB"
// startDate=today - 10
// endDate = startDate - 1
Date tc3Today = new Date();
GregorianCalendar tc3GC = new GregorianCalendar();
tc3GC.setTime(tc3Today);
tc3GC.add(Calendar.DAY_OF_WEEK, -10);
cv.setStartDate(new Timestamp(tc3GC.getTimeInMillis()));
tc3GC.setTimeInMillis(tc3GC.getTimeInMillis());
tc3GC.add(Calendar.DAY_OF_WEEK, -1);
cv.setEndDate(new Timestamp(tc3GC.getTimeInMillis()));
boolean testCase3 = service.isTimeValid(cv);
Assert.assertEquals(true,testCase3);
codeService.remove(CodFlexCodesB.class, cv.getId());
setComplete();
endTransaction();
}
--
View this message in context: http://www.nabble.com/Caching-tp18829899p18829899.html
Sent from the EclipseLink - Users mailing list archive at Nabble.com.