use of org.eclipse.persistence.internal.sessions.IsolatedClientSession in project eclipselink by eclipse-ee4j.
the class DeepMergeCloneSerializedTest method test.
/*
* This test creates an object and registers it with a unit of work. It then serializes that
* object and deserializes it. Adds an object onto the origional then performs serialization
* sequence again. Then deepMergeClone is attempted and the results are compared to verify that
* the merge worked.
*/
@Override
public void test() {
try {
ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
ObjectOutputStream stream = new ObjectOutputStream(byteStream);
// create the phoneNumber object
Employee empClone;
Session session = getSession();
org.eclipse.persistence.sessions.UnitOfWork uow = session.acquireUnitOfWork();
this.empObject = (Employee) session.readObject(Employee.class, new org.eclipse.persistence.expressions.ExpressionBuilder().get("firstName").equal("Bob"));
ClassDescriptor descriptor = session.getDescriptor(this.empObject);
if (descriptor.isProtectedIsolation() && descriptor.shouldIsolateProtectedObjectsInUnitOfWork() && session instanceof IsolatedClientSession) {
// this will have read a version of the protected Entity into the Isolated Cache even though the test wants to isolated to UOW
// replace with actual shared cache version
this.empObject = (Employee) ((AbstractSession) session).getParentIdentityMapSession(descriptor, false, true).getIdentityMapAccessor().getFromIdentityMap(this.empObject);
}
// force instantiations of value holders before serialization
this.empObject.getPhoneNumbers();
if (this.empObject.getManager() != null) {
this.empObject.getManager().getManagedEmployees();
}
this.empObject.getResponsibilitiesList();
// serialize object by writing to a stream
stream.writeObject(this.empObject);
stream.flush();
byte[] arr = byteStream.toByteArray();
ByteArrayInputStream inByteStream = new ByteArrayInputStream(arr);
ObjectInputStream inObjStream = new ObjectInputStream(inByteStream);
Employee deserialEmp;
// deserialize the object
try {
deserialEmp = (Employee) inObjStream.readObject();
} catch (ClassNotFoundException e) {
throw new TestErrorException("Could not deserialize object " + e.toString());
}
// add a new manager, test 1-m's
Employee newManager = new org.eclipse.persistence.testing.models.employee.domain.Employee();
if (deserialEmp.getManager() != null) {
deserialEmp.getManager().removeManagedEmployee(deserialEmp);
this.removedPhone = (PhoneNumber) deserialEmp.getPhoneNumbers().firstElement();
deserialEmp.getPhoneNumbers().removeElement(deserialEmp.getPhoneNumbers().firstElement());
}
newManager.addManagedEmployee(deserialEmp);
// add the PhoneNumber object to the origional clone, test 1-1
PhoneNumber phone = new org.eclipse.persistence.testing.models.employee.domain.PhoneNumber();
phone.setNumber("5555897");
phone.setType("Fax");
phone.setOwner(deserialEmp);
deserialEmp.addPhoneNumber(phone);
this.addedPhone = phone;
deserialEmp.setLastName("Willford");
this.gender = deserialEmp.getGender();
if (deserialEmp.getGender().equals("Female")) {
deserialEmp.setMale();
} else {
deserialEmp.setFemale();
}
this.endDate = deserialEmp.getPeriod().getEndDate();
deserialEmp.getPeriod().setEndDate(new java.sql.Date(System.currentTimeMillis() + 300000L));
this.endTime = deserialEmp.getEndTime();
deserialEmp.setEndTime(Helper.timeFromHourMinuteSecond(15, 2, 3));
deserialEmp.addResponsibility("A Very New Respons");
byteStream = new ByteArrayOutputStream();
stream = new ObjectOutputStream(byteStream);
// send the ammended object back through the serialization process
stream.writeObject(deserialEmp);
stream.flush();
arr = byteStream.toByteArray();
inByteStream = new ByteArrayInputStream(arr);
inObjStream = new ObjectInputStream(inByteStream);
try {
deserialEmp = (Employee) inObjStream.readObject();
} catch (ClassNotFoundException e) {
throw new TestErrorException("Could not deserialize object " + e.toString());
}
// merge the ammended clone with the unit of work
empClone = (Employee) uow.deepMergeClone(deserialEmp);
uow.commit();
uow = session.acquireUnitOfWork();
// do the serialization for the second time
byteStream = new ByteArrayOutputStream();
stream = new ObjectOutputStream(byteStream);
stream.writeObject(this.empObject);
stream.flush();
arr = byteStream.toByteArray();
inByteStream = new ByteArrayInputStream(arr);
inObjStream = new ObjectInputStream(inByteStream);
// attempt to deserialize the object
try {
deserialEmp = (Employee) inObjStream.readObject();
} catch (ClassNotFoundException e) {
throw new TestErrorException("Could not deserialize object " + e.toString());
}
deserialEmp.setFirstName("Danny");
this.origional = deserialEmp;
byteStream = new ByteArrayOutputStream();
stream = new ObjectOutputStream(byteStream);
// send the ammended object back through the serialization process
stream.writeObject(deserialEmp);
stream.flush();
arr = byteStream.toByteArray();
inByteStream = new ByteArrayInputStream(arr);
inObjStream = new ObjectInputStream(inByteStream);
try {
deserialEmp = (Employee) inObjStream.readObject();
} catch (ClassNotFoundException e) {
throw new TestErrorException("Could not deserialize object " + e.toString());
}
deserialEmp = (Employee) uow.deepMergeClone(deserialEmp);
uow.commit();
this.mergedClone = deserialEmp;
} catch (IOException e) {
throw new TestErrorException("Error running Test " + e.toString());
}
}
use of org.eclipse.persistence.internal.sessions.IsolatedClientSession in project eclipselink by eclipse-ee4j.
the class CheckAccessorUsageForIsolatedClass method test.
@Override
public void test() {
Session session = (Session) this.clients.get(0);
if (!(session instanceof IsolatedClientSession)) {
throw new TestErrorException("The session created was not an Isolated Session");
}
Accessor accessor = ((AbstractSession) session).getAccessor();
// client session does not need an accessor
((AbstractSession) session).setAccessor(null);
String userName = session.getProject().getLogin().getUserName();
// ensure we can not connect the accessor
session.getProject().getLogin().setUserName("dumbname");
UnitOfWork uow = session.acquireUnitOfWork();
try {
uow.readObject(IsolatedEmployee.class);
} catch (RuntimeException ex) {
throw new TestErrorException("TopLink executed call down incorrect accessor");
} finally {
((AbstractSession) session).setAccessor(accessor);
session.getProject().getLogin().setUserName(userName);
}
}
use of org.eclipse.persistence.internal.sessions.IsolatedClientSession in project eclipselink by eclipse-ee4j.
the class UOWCommitAndResumeWithPreCalcChangeSet method setup.
@Override
protected void setup() {
super.setup();
// Acquire first unit of work
this.originalObject = (Employee) getSession().readObject(Employee.class);
ClassDescriptor descriptor = getSession().getDescriptor(this.originalObject);
if (descriptor.isProtectedIsolation() && descriptor.shouldIsolateProtectedObjectsInUnitOfWork() && getSession() instanceof IsolatedClientSession) {
// this will have read a version of the protected Entity into the Isolated Cache even though the test wants to isolated to UOW
// replace with actual shared cache version
this.originalObject = (Employee) ((AbstractSession) getSession()).getParentIdentityMapSession(descriptor, false, true).getIdentityMapAccessor().getFromIdentityMap(this.originalObject);
}
this.unitOfWork = getSession().acquireUnitOfWork();
this.unitOfWorkWorkingCopy = (Employee) this.unitOfWork.registerObject(this.originalObject);
}
use of org.eclipse.persistence.internal.sessions.IsolatedClientSession in project eclipselink by eclipse-ee4j.
the class VerifyIsolationTest method test.
@Override
public void test() {
Session session = (Session) this.clients.get(0);
if (!(session instanceof IsolatedClientSession)) {
throw new TestErrorException("The session created was not an Isolated Session");
}
readEmployee = (IsolatedEmployee) session.readObject(IsolatedEmployee.class);
// load a isolated related object into memory
readEmployee.getPhoneNumbers();
// load non isolated related object
readEmployee.getAddress();
}
use of org.eclipse.persistence.internal.sessions.IsolatedClientSession in project eclipselink by eclipse-ee4j.
the class CommitAfterExecuteModifyQueryDuringTransTest method setup.
/**
* Test makes modifications that is not wrapped in a transaction..
*/
@Override
public void setup() {
if (getSession() instanceof RemoteSession) {
throw new TestWarningException("test will not run on RemoteSession - it uses events");
}
// employee to be modified - needed for reset.
cachedEmployee = (Employee) getSession().readObject(Employee.class);
ClassDescriptor descriptor = getSession().getDescriptor(this.cachedEmployee);
if (descriptor.isProtectedIsolation() && descriptor.shouldIsolateProtectedObjectsInUnitOfWork() && getSession() instanceof IsolatedClientSession) {
// this will have read a version of the protected Entity into the Isolated Cache even though the test wants to isolated to UOW
// replace with actual shared cache version
this.cachedEmployee = (Employee) ((AbstractSession) getSession()).getParentIdentityMapSession(descriptor, false, true).getIdentityMapAccessor().getFromIdentityMap(this.cachedEmployee);
}
originalEmployee = (Employee) getSession().copy(cachedEmployee);
employeesNewFirstName = "formerlyKnownAs";
initialVersionField = getSession().getIdentityMapAccessor().getWriteLockValue(cachedEmployee);
// query to be executed more than once
dataModifyQuery = new DataModifyQuery("UPDATE EMPLOYEE SET F_NAME = #F_NAME, VERSION = #VERSION WHERE L_NAME = #L_NAME");
dataModifyQuery.addArgument("F_NAME");
dataModifyQuery.addArgument("VERSION");
dataModifyQuery.addArgument("L_NAME");
}
Aggregations