use of org.eclipse.persistence.testing.models.employee.domain.Employee in project eclipselink by eclipse-ee4j.
the class UpdateAllQueryTest method test.
@Override
public void test() {
Employee emp = (Employee) m_session.readObject(Employee.class);
// Store a first name (any first name will do)
m_firstName = emp.getFirstName();
ExpressionBuilder eb = new ExpressionBuilder();
UpdateAllQuery updateQuery = new UpdateAllQuery(Employee.class);
updateQuery.setSelectionCriteria(eb.get("firstName").equal(m_firstName));
updateQuery.addUpdate(eb.get("lastName"), "oneverynonelikelylastname");
m_session.executeQuery(updateQuery);
}
use of org.eclipse.persistence.testing.models.employee.domain.Employee in project eclipselink by eclipse-ee4j.
the class ConcurrentRefreshOnUpdateTest method runnable.
public Runnable runnable() {
return new Runnable() {
@Override
public void run() {
if (writer) {
UnitOfWork uow = session.acquireUnitOfWork();
Employee empClone = (Employee) uow.registerObject(ConcurrentRefreshOnUpdateTest.lock);
empClone.setFirstName("The New City Name" + System.currentTimeMillis());
synchronized (ConcurrentRefreshOnUpdateTest.lock) {
if (ConcurrentRefreshOnUpdateTest.readerWaiting) {
ConcurrentRefreshOnUpdateTest.lock.notifyAll();
} else {
ConcurrentRefreshOnUpdateTest.writerWaiting = true;
try {
ConcurrentRefreshOnUpdateTest.lock.wait(30000);
} catch (InterruptedException ex) {
// ignore
}
ConcurrentRefreshOnUpdateTest.writerWaiting = false;
}
}
uow.commit();
} else {
ReadAllQuery query = new ReadAllQuery(Employee.class);
query.setShouldRefreshIdentityMapResult(true);
query.useCursoredStream(0, 1);
query.setSelectionCriteria(new ExpressionBuilder().get("id").equal(ConcurrentRefreshOnUpdateTest.lock.getId()));
Cursor cursor = (Cursor) session.executeQuery(query);
// wait for both thread to set up
synchronized (ConcurrentRefreshOnUpdateTest.lock) {
if (ConcurrentRefreshOnUpdateTest.writerWaiting) {
ConcurrentRefreshOnUpdateTest.lock.notifyAll();
} else {
ConcurrentRefreshOnUpdateTest.readerWaiting = true;
try {
ConcurrentRefreshOnUpdateTest.lock.wait(30000);
} catch (InterruptedException ex) {
// ignore
}
ConcurrentRefreshOnUpdateTest.readerWaiting = false;
}
}
Thread.yield();
// writer is commiting, wait for postMerge event
synchronized (ConcurrentRefreshOnUpdateTest.lock) {
if (!ConcurrentRefreshOnUpdateTest.writerWaiting) {
ConcurrentRefreshOnUpdateTest.readerWaiting = true;
try {
ConcurrentRefreshOnUpdateTest.lock.wait(30000);
} catch (InterruptedException ex) {
}
// ignore
ConcurrentRefreshOnUpdateTest.readerWaiting = false;
}
}
if (cursor.hasMoreElements()) {
cursor.nextElement();
}
cursor.close();
}
}
};
}
use of org.eclipse.persistence.testing.models.employee.domain.Employee 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.testing.models.employee.domain.Employee in project eclipselink by eclipse-ee4j.
the class DeepNestedUnitOfWorkTest method changeThirdLevelUnitOfWorkWorkingCopy.
protected void changeThirdLevelUnitOfWorkWorkingCopy() {
Employee employee = (Employee) this.unitOfWorkWorkingCopy[2];
// Direct collection
employee.setResponsibilitiesList(new Vector());
employee.addResponsibility("make coffee");
employee.addResponsibility("buy donuts");
// One to one private/public
employee.setAddress(new org.eclipse.persistence.testing.models.employee.domain.EmployeePopulator().addressExample10());
// make sure that the employee is not his own manager
employee.setManager((Employee) this.unitOfWork[2].readObject(Employee.class, (new ExpressionBuilder()).get("id").notEqual(employee.getId())));
}
use of org.eclipse.persistence.testing.models.employee.domain.Employee in project eclipselink by eclipse-ee4j.
the class DeepNestedUnitOfWorkTest method changeSecondLevelUnitOfWorkWorkingCopy.
protected void changeSecondLevelUnitOfWorkWorkingCopy() {
Employee employee = (Employee) this.unitOfWorkWorkingCopy[1];
// One to many private
employee.setPhoneNumbers(new Vector());
employee.addPhoneNumber(new org.eclipse.persistence.testing.models.employee.domain.PhoneNumber("home", "613", "2263374"));
employee.addPhoneNumber(new org.eclipse.persistence.testing.models.employee.domain.PhoneNumber("office", "416", "8224599"));
// Many to many
employee.setProjects(new Vector());
employee.addProject((org.eclipse.persistence.testing.models.employee.domain.Project) this.unitOfWork[1].readObject(SmallProject.class));
employee.addProject((org.eclipse.persistence.testing.models.employee.domain.Project) this.unitOfWork[1].readObject(LargeProject.class));
}
Aggregations