Skip to Main Content

Integration

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

readDate problem for fields of POF enabled objects

700466Mar 31 2010 — edited Apr 22 2010
Hi,

We are facing this resetting of date variables of a POF enabled object to System Date any time when object is looked up from cache.

Here is the driver program that I use. Please help!!!

package com;

import java.util.ArrayList;
import java.util.Date;

import com.tangosol.net.CacheFactory;
import com.tangosol.net.NamedCache;

public class POFDates {
public static void main(String[] args) {
// create cache
try {
NamedCache testEntryCache = CacheFactory.getCache("TESTCACHE");
Date myDate = new Date(System.currentTimeMillis());
Date myDate1 = new Date(System.currentTimeMillis()+24*3600*1000);
Date date1 =new Date(System.currentTimeMillis()+2*24*3600*1000);
ArrayList potentialDates = new ArrayList();
potentialDates.add(date1);
Other other = new Other("FirstOther",myDate);
Dates dates = new Dates("FirstMe",myDate,potentialDates,other);
System.out.println("****Dates initialy set in cache***"+dates);
testEntryCache.put("dates",dates);
Dates retrivedDates = null;
retrivedDates = (Dates) testEntryCache.get("dates");
System.out.println("-----Dates retrieved first Time from Cache------"
+ retrivedDates);
for (int i = 0; i < 3; i++) {
Thread.sleep(3000);
retrivedDates = (Dates) testEntryCache.get("dates");
System.out.println("####Dates retrieved "+i+"th Time from Cache"
+ retrivedDates);
}

} catch (Exception e) {
e.printStackTrace();
}
}
}

Output of the program is


****Dates initialy set in cache*** Dates.myDate = Wed Mar 31 22:40:58 CDT 2010<<< Dates.potentialDates = [Fri Apr 02 22:40:58 CDT 2010]<<< Dates.Other = Others' myDate:Wed Mar 31 22:40:58 CDT 2010<<<
-----Dates retrieved first Time from Cache------ Dates.myDate = Wed Mar 31 22:40:58 CDT 2010<<< Dates.potentialDates = [2010-04-02 22:40:58.473]<<< Dates.Other = Others' myDate:Wed Mar 31 22:40:58 CDT 2010<<<
2010-03-31 22:40:59.083/2.407 Oracle Coherence GE 3.5.2/463 <D5> (thread=TcpRingListener, member=2): TcpRing: connecting to member 1 using TcpSocket{State=STATE_OPEN, Socket=Socket[addr=/105.106.192.124,port=4347,localport=8089]}
####Dates retrieved 0th Time from Cache Dates.myDate = Wed Mar 31 22:41:01 CDT 2010<<< Dates.potentialDates = [2010-04-02 22:40:58.473]<<< Dates.Other = Others' myDate:Wed Mar 31 22:41:01 CDT 2010<<<
####Dates retrieved 1th Time from Cache Dates.myDate = Wed Mar 31 22:41:04 CDT 2010<<< Dates.potentialDates = [2010-04-02 22:40:58.473]<<< Dates.Other = Others' myDate:Wed Mar 31 22:41:04 CDT 2010<<<
####Dates retrieved 2th Time from Cache Dates.myDate = Wed Mar 31 22:41:07 CDT 2010<<< Dates.potentialDates = [2010-04-02 22:40:58.473]<<< Dates.Other = Others' myDate:Wed Mar 31 22:41:07 CDT 2010<<<



******************Dates Class is******************* Start

package com;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.Vector;
import com.tangosol.io.pof.PofReader;
import com.tangosol.io.pof.PofWriter;
import com.tangosol.io.pof.PortableObject;

public class Dates implements PortableObject {

private String fname =null;
private Date fmyDate=null;
private ArrayList fpotentialDates=null;
private Other otherWithDate=null;

public Dates(String fname, Date fmyDate, ArrayList fpotentialDates, Other fothersDate) {
super();
this.fname = fname;
this.fmyDate = fmyDate;
this.fpotentialDates = fpotentialDates;
this.otherWithDate = fothersDate;
}



public Dates()
{

}


public void readExternal(PofReader reader) throws IOException {
fname = reader.readString(0);
fmyDate = reader.readDate(1);
fpotentialDates = (ArrayList<Date>)(reader.readCollection(2, new ArrayList<Date>()));
otherWithDate = (Other)reader.readObject(3);

}
public void writeExternal(PofWriter writer) throws IOException {
writer.writeString(0, fname);
writer.writeDate(1, fmyDate);
writer.writeCollection(2, fpotentialDates);
writer.writeObject(3, otherWithDate);

}
/**
* @return the myDate
*/
public Date getMyDate() {
return fmyDate;
}
/**
* @param myDate the myDate to set
*/
public void setMyDate(Date myDate) {
this.fmyDate = myDate;

}
/**
* @return the othersDate
*/
public Other getOthersDate() {
return otherWithDate;
}
/**
* @param othersDate the othersDate to set
*/
public void setOthersDate(Other othersDate) {
this.otherWithDate = othersDate;
}
/**
* @return the potentialDates
*/
public ArrayList getPotentialDates() {
return fpotentialDates;
}
/**
* @param potentialDates the potentialDates to set
*/
public void setPotentialDates(ArrayList potentialDates) {
this.fpotentialDates = potentialDates;
}


public String toString()
{
StringBuffer lBuffer = new StringBuffer();
lBuffer.append(" Dates.myDate = "+fmyDate+"<<<");
lBuffer.append(" Dates.potentialDates = "+fpotentialDates+"<<<");
lBuffer.append(" Other = "+otherWithDate+"<<<");
return lBuffer.toString();
}
public int hashCode() {
final int PRIME = 31;
int result = 1;
result = PRIME * result + ((fmyDate == null) ? 0 : fmyDate.hashCode());
result = PRIME * result + ((fname == null) ? 0 : fname.hashCode());
result = PRIME * result + ((otherWithDate == null) ? 0 : otherWithDate.hashCode());
return result;
}

public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
final Dates other = (Dates) obj;
if (fmyDate == null) {
if (other.fmyDate != null)
return false;
} else if (!fmyDate.equals(other.fmyDate))
return false;
if (fname == null) {
if (other.fname != null)
return false;
} else if (!fname.equals(other.fname))
return false;
if (otherWithDate == null) {
if (other.otherWithDate != null)
return false;
} else if (!otherWithDate.equals(other.otherWithDate))
return false;
return true;
}



}
******************Dates Class is******************* End




******************Other Class is******************* Start


package com;

import java.io.IOException;
import java.util.Date;

import com.tangosol.io.pof.PofReader;
import com.tangosol.io.pof.PofWriter;
import com.tangosol.io.pof.PortableObject;

public class Other implements PortableObject {

private String fname =null;
private Date fmyDate=null;
public Other(String fname, Date fmyDate) {
super();
this.fname = fname;
this.fmyDate = fmyDate;
}

public Other()
{}

public Other(Date myDate) {
super();
this.fmyDate = myDate;
}

public void readExternal(PofReader reader) throws IOException {
fname = reader.readString(0);
fmyDate = reader.readDate(1);

}

public void writeExternal(PofWriter writer) throws IOException {
writer.writeString(0, fname);
writer.writeDate(1, fmyDate);

}
public Date getMyDate() {
return fmyDate;
}

public void setMyDate(Date myDate) {
this.fmyDate = myDate;
}

public String toString()
{
StringBuffer lBuffer = new StringBuffer();
lBuffer.append("Others' myDate:"+fmyDate);
return lBuffer.toString();
}
public int hashCode() {
final int PRIME = 31;
int result = 1;
result = PRIME * result + ((fmyDate == null) ? 0 : fmyDate.hashCode());
result = PRIME * result + ((fname == null) ? 0 : fname.hashCode());
return result;
}
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
final Other other = (Other) obj;
if (fmyDate == null) {
if (other.fmyDate != null)
return false;
} else if (!fmyDate.equals(other.fmyDate))
return false;
if (fname == null) {
if (other.fname != null)
return false;
} else if (!fname.equals(other.fname))
return false;
return true;
}

public String getFname() {
return fname;
}

public void setFname(String fname) {
this.fname = fname;
}

}


Thanks,
Tarun

Edited by: user1228154 on Mar 31, 2010 8:54 PM
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 20 2010
Added on Mar 31 2010
2 comments
1,578 views