Search in sources :

Example 11 with Employee

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);
}
Also used : Employee(org.eclipse.persistence.testing.models.employee.domain.Employee) UpdateAllQuery(org.eclipse.persistence.queries.UpdateAllQuery)

Example 12 with Employee

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();
            }
        }
    };
}
Also used : UnitOfWork(org.eclipse.persistence.sessions.UnitOfWork) Employee(org.eclipse.persistence.testing.models.employee.domain.Employee) ReadAllQuery(org.eclipse.persistence.queries.ReadAllQuery) ExpressionBuilder(org.eclipse.persistence.expressions.ExpressionBuilder) Cursor(org.eclipse.persistence.queries.Cursor)

Example 13 with Employee

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());
    }
}
Also used : ClassDescriptor(org.eclipse.persistence.descriptors.ClassDescriptor) TestErrorException(org.eclipse.persistence.testing.framework.TestErrorException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) ObjectOutputStream(java.io.ObjectOutputStream) IsolatedClientSession(org.eclipse.persistence.internal.sessions.IsolatedClientSession) Employee(org.eclipse.persistence.testing.models.employee.domain.Employee) ByteArrayInputStream(java.io.ByteArrayInputStream) PhoneNumber(org.eclipse.persistence.testing.models.employee.domain.PhoneNumber) Session(org.eclipse.persistence.sessions.Session) AbstractSession(org.eclipse.persistence.internal.sessions.AbstractSession) IsolatedClientSession(org.eclipse.persistence.internal.sessions.IsolatedClientSession) AbstractSession(org.eclipse.persistence.internal.sessions.AbstractSession) ObjectInputStream(java.io.ObjectInputStream)

Example 14 with Employee

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())));
}
Also used : Employee(org.eclipse.persistence.testing.models.employee.domain.Employee) ExpressionBuilder(org.eclipse.persistence.expressions.ExpressionBuilder) Vector(java.util.Vector)

Example 15 with Employee

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));
}
Also used : Employee(org.eclipse.persistence.testing.models.employee.domain.Employee) Vector(java.util.Vector)

Aggregations

Employee (org.eclipse.persistence.testing.models.employee.domain.Employee)220 UnitOfWork (org.eclipse.persistence.sessions.UnitOfWork)79 TestErrorException (org.eclipse.persistence.testing.framework.TestErrorException)52 ExpressionBuilder (org.eclipse.persistence.expressions.ExpressionBuilder)40 Vector (java.util.Vector)34 ReadObjectQuery (org.eclipse.persistence.queries.ReadObjectQuery)32 SmallProject (org.eclipse.persistence.testing.models.employee.domain.SmallProject)29 Address (org.eclipse.persistence.testing.models.employee.domain.Address)24 PhoneNumber (org.eclipse.persistence.testing.models.employee.domain.PhoneNumber)22 Expression (org.eclipse.persistence.expressions.Expression)21 LargeProject (org.eclipse.persistence.testing.models.employee.domain.LargeProject)18 UnitOfWorkImpl (org.eclipse.persistence.internal.sessions.UnitOfWorkImpl)16 TestSuite (org.eclipse.persistence.testing.framework.TestSuite)15 PopulationManager (org.eclipse.persistence.tools.schemaframework.PopulationManager)15 ReadAllQuery (org.eclipse.persistence.queries.ReadAllQuery)14 Project (org.eclipse.persistence.testing.models.employee.domain.Project)14 EmployeePopulator (org.eclipse.persistence.testing.models.employee.domain.EmployeePopulator)11 ClassDescriptor (org.eclipse.persistence.descriptors.ClassDescriptor)9 ValidationException (org.eclipse.persistence.exceptions.ValidationException)9 EmploymentPeriod (org.eclipse.persistence.testing.models.employee.domain.EmploymentPeriod)9