Search in sources :

Example 1 with Server

use of org.eclipse.persistence.sessions.server.Server in project eclipselink by eclipse-ee4j.

the class UnitOfWorkPartitionedIsolatedAlwaysTestModel method buildServerSession.

/**
 * Simulate a database cluster by having multiple pools to the same database.
 */
@Override
public Server buildServerSession() {
    Server server = getSession().getProject().clone().createServerSession(1, 3);
    server.addConnectionPool("node2", getSession().getLogin(), 1, 3);
    server.addConnectionPool("node3", getSession().getLogin(), 1, 3);
    server.setSessionLog(getSession().getSessionLog());
    server.setPartitioningPolicy(new RoundRobinPartitioningPolicy("default", "node2", "node3"));
    server.login();
    return server;
}
Also used : RoundRobinPartitioningPolicy(org.eclipse.persistence.descriptors.partitioning.RoundRobinPartitioningPolicy) Server(org.eclipse.persistence.sessions.server.Server)

Example 2 with Server

use of org.eclipse.persistence.sessions.server.Server in project eclipselink by eclipse-ee4j.

the class UnitOfWorkPartitionedTestModel method buildServerSession.

/**
 * Simulate a database cluster by having multiple pools to the same database.
 */
@Override
public Server buildServerSession() {
    Server server = getSession().getProject().clone().createServerSession(1, 3);
    server.addConnectionPool("node2", getSession().getLogin(), 1, 3);
    server.addConnectionPool("node3", getSession().getLogin(), 1, 3);
    server.setSessionLog(getSession().getSessionLog());
    server.setPartitioningPolicy(new RoundRobinPartitioningPolicy("default", "node2", "node3"));
    server.login();
    return server;
}
Also used : RoundRobinPartitioningPolicy(org.eclipse.persistence.descriptors.partitioning.RoundRobinPartitioningPolicy) Server(org.eclipse.persistence.sessions.server.Server)

Example 3 with Server

use of org.eclipse.persistence.sessions.server.Server in project eclipselink by eclipse-ee4j.

the class ConcurrentReadFetchJoinWithUOWLocksTest method test.

@Override
public void test() {
    Server server = this.getServerSession();
    UnitOfWork uow = server.acquireUnitOfWork();
    ConcurrentLargeProject clonedProject = (ConcurrentLargeProject) uow.registerObject(project);
    clonedProject.getLocation().setPostalCode("K1P 1A4");
    ConcurrentPerson clonedPerson = (ConcurrentPerson) uow.registerObject(person);
    clonedPerson.setHobby(clonedProject);
    uow.writeChanges();
    Thread thread1 = new Thread(new ProjectReader(server.acquireClientSession(), project.getId()));
    ConcurrentProject.RUNNING_TEST = ConcurrentProject.READ_WITH_UOW_LOCKS_TESTS;
    // start reading Project, and have the thread wait while building DTF mappings
    thread1.start();
    try {
        // wait a token amount to be sure that thread1 isn't starved before getting deferred lock on Project.
        thread1.join(1000);
    } catch (InterruptedException ex) {
    }
    // start uow commit, which will get locks on Person+Address, commit, then merge.
    // merge should get a deferred lock on Project.
    Thread thread2 = new Thread(new UOWCommit(uow));
    thread2.start();
    // releases.
    try {
        thread1.join(20000);
        if (thread1.isAlive()) {
            try {
                thread1.interrupt();
                thread2.interrupt();
            } catch (Exception e) {
            }
            deadlockDetected = true;
        }
    } catch (InterruptedException ex) {
    }
}
Also used : UnitOfWork(org.eclipse.persistence.sessions.UnitOfWork) ConcurrentLargeProject(org.eclipse.persistence.testing.tests.unitofwork.ConcurrentLargeProject) Server(org.eclipse.persistence.sessions.server.Server) ConcurrentPerson(org.eclipse.persistence.testing.tests.unitofwork.ConcurrentPerson) TestErrorException(org.eclipse.persistence.testing.framework.TestErrorException)

Example 4 with Server

use of org.eclipse.persistence.sessions.server.Server in project eclipselink by eclipse-ee4j.

the class NoSQLSessionTest method testServerSession.

/**
 * Test {@link Server} session creation and login.
 */
@Test
public void testServerSession() throws Exception {
    final Server session = SessionHelper.createServerSession(NoSQLTestSuite.project);
    session.logout();
}
Also used : Server(org.eclipse.persistence.sessions.server.Server) Test(org.junit.Test)

Example 5 with Server

use of org.eclipse.persistence.sessions.server.Server in project eclipselink by eclipse-ee4j.

the class JUnitJPQLSimpleTestSuite method conformResultsInUnitOfWorkTest.

public void conformResultsInUnitOfWorkTest() {
    ReadObjectQuery readObjectQuery = new ReadObjectQuery();
    readObjectQuery.setReferenceClass(Employee.class);
    readObjectQuery.setEJBQLString("SELECT OBJECT(emp) FROM Employee emp WHERE emp.id = ?1");
    readObjectQuery.conformResultsInUnitOfWork();
    readObjectQuery.addArgument("1", Integer.class);
    // ServerSession next
    Server serverSession = getServerSession().getProject().createServerSession();
    serverSession.setSessionLog(getServerSession().getSessionLog());
    serverSession.login();
    UnitOfWork unitOfWork = serverSession.acquireUnitOfWork();
    Employee newEmployee = new Employee();
    newEmployee.setId(9000);
    unitOfWork.registerObject(newEmployee);
    Vector testV = new Vector();
    testV.addElement(9000);
    Employee result = (Employee) unitOfWork.executeQuery(readObjectQuery, testV);
    Assert.assertTrue("Conform Results In Unit of Work using ServerSession failed", comparer.compareObjects(result, newEmployee));
    serverSession.logout();
}
Also used : UnitOfWork(org.eclipse.persistence.sessions.UnitOfWork) Employee(org.eclipse.persistence.testing.models.jpa.advanced.Employee) ReadObjectQuery(org.eclipse.persistence.queries.ReadObjectQuery) Server(org.eclipse.persistence.sessions.server.Server) Vector(java.util.Vector)

Aggregations

Server (org.eclipse.persistence.sessions.server.Server)34 EntityManager (jakarta.persistence.EntityManager)15 UnitOfWork (org.eclipse.persistence.sessions.UnitOfWork)15 AbstractSession (org.eclipse.persistence.internal.sessions.AbstractSession)12 JpaEntityManager (org.eclipse.persistence.jpa.JpaEntityManager)12 DatabaseSession (org.eclipse.persistence.sessions.DatabaseSession)12 Session (org.eclipse.persistence.sessions.Session)12 ArrayList (java.util.ArrayList)10 List (java.util.List)10 Employee (org.eclipse.persistence.testing.models.jpa.advanced.Employee)9 Vector (java.util.Vector)8 Test (org.junit.Test)8 CriteriaBuilder (jakarta.persistence.criteria.CriteriaBuilder)6 TestErrorException (org.eclipse.persistence.testing.framework.TestErrorException)6 Project (org.eclipse.persistence.sessions.Project)5 ClassDescriptor (org.eclipse.persistence.descriptors.ClassDescriptor)4 Expression (org.eclipse.persistence.expressions.Expression)4 ExpressionBuilder (org.eclipse.persistence.expressions.ExpressionBuilder)4 ReadAllQuery (org.eclipse.persistence.queries.ReadAllQuery)4 Address (org.eclipse.persistence.testing.models.jpa.advanced.Address)4