Search in sources :

Example 1 with ReadConnectionPool

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

the class EntityManagerJUnitTestSuite method testPersistenceProperties.

// The test removed because we moved back to binding literals
// on platforms other than DB2 and Derby
/*    public void testDontBindLiteral() {
        EntityManager em = createEntityManager();

        Query controlQuery = em.createQuery("SELECT OBJECT(p) FROM SmallProject p WHERE p.name = CONCAT(:param1, :param2)");
        controlQuery.setParameter("param1", "A").setParameter("param2", "B");
        List controlResults = controlQuery.getResultList();
        int nControlParams = ((ExpressionQueryMechanism)((EJBQueryImpl)controlQuery).getDatabaseQuery().getQueryMechanism()).getCall().getParameters().size();
        if(nControlParams != 2) {
            fail("controlQuery has wrong number of parameters = "+nControlParams+"; 2 is expected");
        }

        Query query = em.createQuery("SELECT OBJECT(p) FROM SmallProject p WHERE p.name = CONCAT('A', 'B')");
        List results = query.getResultList();
        int nParams = ((ExpressionQueryMechanism)((EJBQueryImpl)query).getDatabaseQuery().getQueryMechanism()).getCall().getParameters().size();
        if(nParams > 0) {
            fail("Query processed literals as parameters");
        }

        closeEntityManager(em);
    }*/
public void testPersistenceProperties() {
    // Different properties are used on the server.
    if (isOnServer()) {
        return;
    }
    EntityManager em = createEntityManager();
    ServerSession ss = ((org.eclipse.persistence.internal.jpa.EntityManagerImpl) em).getServerSession();
    // these properties were set in persistence unit
    // and overridden in CMP3TestModel.setup - the values should be overridden.
    boolean isReadShared = (ss.getReadConnectionPool() instanceof ReadConnectionPool);
    if (isReadShared != Boolean.parseBoolean((String) JUnitTestCaseHelper.propertiesMap.get(PersistenceUnitProperties.JDBC_READ_CONNECTIONS_SHARED))) {
        fail("isReadShared is wrong");
    }
    int writeMin = ss.getDefaultConnectionPool().getMinNumberOfConnections();
    if (writeMin != Integer.parseInt((String) JUnitTestCaseHelper.propertiesMap.get(PersistenceUnitProperties.JDBC_WRITE_CONNECTIONS_MIN))) {
        fail("writeMin is wrong");
    }
    int writeInitial = ss.getDefaultConnectionPool().getInitialNumberOfConnections();
    if (writeInitial != Integer.parseInt((String) JUnitTestCaseHelper.propertiesMap.get(PersistenceUnitProperties.JDBC_WRITE_CONNECTIONS_INITIAL))) {
        fail("writeInitial is wrong");
    }
    int writeMax = ss.getDefaultConnectionPool().getMaxNumberOfConnections();
    if (writeMax != Integer.parseInt((String) JUnitTestCaseHelper.propertiesMap.get(PersistenceUnitProperties.JDBC_WRITE_CONNECTIONS_MAX))) {
        fail("writeMax is wrong");
    }
    int readMin = ss.getReadConnectionPool().getMinNumberOfConnections();
    if (readMin != Integer.parseInt((String) JUnitTestCaseHelper.propertiesMap.get(PersistenceUnitProperties.JDBC_READ_CONNECTIONS_MIN))) {
        fail("readMin is wrong");
    }
    int readMax = ss.getReadConnectionPool().getMaxNumberOfConnections();
    if (readMax != Integer.parseInt((String) JUnitTestCaseHelper.propertiesMap.get(PersistenceUnitProperties.JDBC_READ_CONNECTIONS_MAX))) {
        fail("readMax is wrong");
    }
    int batchSize = ss.getPlatform().getMaxBatchWritingSize();
    if (batchSize != Integer.parseInt((String) JUnitTestCaseHelper.propertiesMap.get(PersistenceUnitProperties.BATCH_WRITING_SIZE))) {
        fail("batchSize is wrong");
    }
    // these properties were set in persistence unit - the values should be the same as in persistence.xml
    /*
            <property name="eclipselink.session-name" value="default-session"/>
            <property name="eclipselink.cache.size.default" value="500"/>
            <property name="eclipselink.cache.size.Employee" value="550"/>
            <property name="eclipselink.cache.size.org.eclipse.persistence.testing.models.jpa.advanced.Address" value="555"/>
            <property name="eclipselink.cache.type.default" value="Full"/>
            <property name="eclipselink.cache.type.Employee" value="Weak"/>
            <property name="eclipselink.cache.type.org.eclipse.persistence.testing.models.jpa.advanced.Address" value="HardWeak"/>
            <property name="eclipselink.session.customizer" value="org.eclipse.persistence.testing.models.jpa.advanced.Customizer"/>
            <property name="eclipselink.descriptor.customizer.Employee" value="org.eclipse.persistence.testing.models.jpa.advanced.Customizer"/>
            <property name="eclipselink.descriptor.customizer.org.eclipse.persistence.testing.models.jpa.advanced.Address" value="org.eclipse.persistence.testing.models.jpa.advanced.Customizer"/>
            <property name="eclipselink.descriptor.customizer.Project" value="org.eclipse.persistence.testing.models.jpa.advanced.Customizer"/>
        */
    String sessionName = ss.getName();
    if (!sessionName.equals("default-session")) {
        fail("sessionName is wrong: " + sessionName);
    }
    int defaultCacheSize = ss.getDescriptor(Project.class).getIdentityMapSize();
    if (defaultCacheSize != 500) {
        fail("defaultCacheSize is wrong: " + defaultCacheSize);
    }
    int employeeCacheSize = ss.getDescriptor(Employee.class).getIdentityMapSize();
    if (employeeCacheSize != 550) {
        fail("employeeCacheSize is wrong: " + employeeCacheSize);
    }
    int addressCacheSize = ss.getDescriptor(Address.class).getIdentityMapSize();
    if (addressCacheSize != 555) {
        fail("addressCacheSize is wrong: " + addressCacheSize);
    }
    // Department cache size specified in @Cache annotation - that should override default property
    int departmentCacheSize = ss.getDescriptor(Department.class).getIdentityMapSize();
    if (departmentCacheSize != 777) {
        fail("departmentCacheSize is wrong: " + departmentCacheSize);
    }
    Class<?> defaultCacheType = ss.getDescriptor(Project.class).getIdentityMapClass();
    if (!Helper.getShortClassName(defaultCacheType).equals("FullIdentityMap")) {
        fail("defaultCacheType is wrong: " + Helper.getShortClassName(defaultCacheType));
    }
    Class<?> employeeCacheType = ss.getDescriptor(Employee.class).getIdentityMapClass();
    if (!Helper.getShortClassName(employeeCacheType).equals("WeakIdentityMap")) {
        fail("employeeCacheType is wrong: " + Helper.getShortClassName(employeeCacheType));
    }
    Class<?> addressCacheType = ss.getDescriptor(Address.class).getIdentityMapClass();
    if (!Helper.getShortClassName(addressCacheType).equals("HardCacheWeakIdentityMap")) {
        fail("addressCacheType is wrong: " + Helper.getShortClassName(addressCacheType));
    }
    // Department cache type specified in @Cache annotation - that should override default property
    Class<?> departmentCacheType = ss.getDescriptor(Department.class).getIdentityMapClass();
    if (!Helper.getShortClassName(departmentCacheType).equals("SoftCacheWeakIdentityMap")) {
        fail("departmentCacheType is wrong: " + Helper.getShortClassName(departmentCacheType));
    }
    int numSessionCalls = Customizer.getNumberOfCallsForSession(ss.getName());
    if (numSessionCalls == 0) {
        fail("session customizer hasn't been called");
    }
    int numProjectCalls = Customizer.getNumberOfCallsForClass(Project.class.getName());
    if (numProjectCalls == 0) {
        fail("Project customizer hasn't been called");
    }
    int numEmployeeCalls = Customizer.getNumberOfCallsForClass(Employee.class.getName());
    if (numEmployeeCalls == 0) {
        fail("Employee customizer hasn't been called");
    }
    int numAddressCalls = Customizer.getNumberOfCallsForClass(Address.class.getName());
    if (numAddressCalls == 0) {
        fail("Address customizer hasn't been called");
    }
    IdValidation employeeIdValidation = ss.getDescriptor(Employee.class).getIdValidation();
    if (employeeIdValidation != IdValidation.ZERO) {
        fail("employeeIdValidation is wrong, IdValidation.ZERO assigned through PrimaryKey annotation was expected");
    }
    IdValidation addressIdValidation = ss.getDescriptor(Address.class).getIdValidation();
    if (addressIdValidation != IdValidation.NEGATIVE) {
        fail("addressIdValidation is wrong, IdValidation.NEGATIVE set as a default value in persistence.xml was expected");
    }
    closeEntityManager(em);
}
Also used : ServerSession(org.eclipse.persistence.sessions.server.ServerSession) IdValidation(org.eclipse.persistence.annotations.IdValidation) ReadConnectionPool(org.eclipse.persistence.sessions.server.ReadConnectionPool) Address(org.eclipse.persistence.testing.models.jpa.advanced.Address) EntityManagerImpl(org.eclipse.persistence.internal.jpa.EntityManagerImpl) Project(org.eclipse.persistence.testing.models.jpa.advanced.Project) HugeProject(org.eclipse.persistence.testing.models.jpa.advanced.HugeProject) SmallProject(org.eclipse.persistence.testing.models.jpa.advanced.SmallProject) SuperLargeProject(org.eclipse.persistence.testing.models.jpa.advanced.SuperLargeProject) SpecialHugeProject(org.eclipse.persistence.testing.models.jpa.advanced.SpecialHugeProject) LargeProject(org.eclipse.persistence.testing.models.jpa.advanced.LargeProject) EntityManager(jakarta.persistence.EntityManager) JpaEntityManager(org.eclipse.persistence.jpa.JpaEntityManager) Department(org.eclipse.persistence.testing.models.jpa.advanced.Department) Employee(org.eclipse.persistence.testing.models.jpa.advanced.Employee)

Example 2 with ReadConnectionPool

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

the class EntityManagerSetupImpl method updatePools.

/**
 * Configure the internal connection pooling parameters.
 * By default if nothing is configured a default shared (exclusive) read/write pool is used with 32 min/max connections and 1 initial.
 */
@SuppressWarnings("deprecation")
protected void updatePools(ServerSession serverSession, Map m) {
    String value = null;
    String property = null;
    try {
        // Sizes are irrelevant for external connection pool
        if (!serverSession.getDefaultConnectionPool().getLogin().shouldUseExternalConnectionPooling()) {
            // CONNECTION and WRITE_CONNECTION properties both configure the default pool (mean the same thing, but WRITE normally used with READ).
            property = PersistenceUnitProperties.JDBC_CONNECTIONS_MIN;
            value = getConfigPropertyAsStringLogDebug(property, m, serverSession);
            if (value != null) {
                serverSession.getDefaultConnectionPool().setMinNumberOfConnections(Integer.parseInt(value));
            }
            property = PersistenceUnitProperties.JDBC_CONNECTIONS_MAX;
            value = getConfigPropertyAsStringLogDebug(property, m, serverSession);
            if (value != null) {
                serverSession.getDefaultConnectionPool().setMaxNumberOfConnections(Integer.parseInt(value));
            }
            property = PersistenceUnitProperties.JDBC_CONNECTIONS_INITIAL;
            value = getConfigPropertyAsStringLogDebug(property, m, serverSession);
            if (value != null) {
                serverSession.getDefaultConnectionPool().setInitialNumberOfConnections(Integer.parseInt(value));
            }
            property = PersistenceUnitProperties.JDBC_WRITE_CONNECTIONS_MIN;
            value = getConfigPropertyAsStringLogDebug(property, m, serverSession);
            if (value != null) {
                serverSession.getDefaultConnectionPool().setMinNumberOfConnections(Integer.parseInt(value));
            }
            property = PersistenceUnitProperties.JDBC_WRITE_CONNECTIONS_MAX;
            value = getConfigPropertyAsStringLogDebug(property, m, serverSession);
            if (value != null) {
                serverSession.getDefaultConnectionPool().setMaxNumberOfConnections(Integer.parseInt(value));
            }
            property = PersistenceUnitProperties.JDBC_WRITE_CONNECTIONS_INITIAL;
            value = getConfigPropertyAsStringLogDebug(property, m, serverSession);
            if (value != null) {
                serverSession.getDefaultConnectionPool().setInitialNumberOfConnections(Integer.parseInt(value));
            }
        }
        // Sizes and shared option are irrelevant for external connection pool
        if (!serverSession.getReadConnectionPool().getLogin().shouldUseExternalConnectionPooling()) {
            String shared = getConfigPropertyAsStringLogDebug(PersistenceUnitProperties.JDBC_READ_CONNECTIONS_SHARED, m, serverSession);
            boolean isShared = false;
            if (shared != null) {
                isShared = Boolean.parseBoolean(shared);
            }
            ConnectionPool pool = null;
            if (isShared) {
                pool = new ReadConnectionPool("read", serverSession.getReadConnectionPool().getLogin(), serverSession);
            } else {
                pool = new ConnectionPool("read", serverSession.getReadConnectionPool().getLogin(), serverSession);
            }
            String min = getConfigPropertyAsStringLogDebug(PersistenceUnitProperties.JDBC_READ_CONNECTIONS_MIN, m, serverSession);
            if (min != null) {
                value = min;
                property = PersistenceUnitProperties.JDBC_READ_CONNECTIONS_MIN;
                pool.setMinNumberOfConnections(Integer.parseInt(min));
            }
            String max = getConfigPropertyAsStringLogDebug(PersistenceUnitProperties.JDBC_READ_CONNECTIONS_MAX, m, serverSession);
            if (max != null) {
                value = max;
                property = PersistenceUnitProperties.JDBC_READ_CONNECTIONS_MAX;
                pool.setMaxNumberOfConnections(Integer.parseInt(max));
            }
            String initial = getConfigPropertyAsStringLogDebug(PersistenceUnitProperties.JDBC_READ_CONNECTIONS_INITIAL, m, serverSession);
            if (initial != null) {
                value = initial;
                property = PersistenceUnitProperties.JDBC_READ_CONNECTIONS_INITIAL;
                pool.setInitialNumberOfConnections(Integer.parseInt(initial));
            }
            // Only set the read pool if they configured it, otherwise use default shared read/write.
            if (isShared || (min != null) || (max != null) || (initial != null)) {
                serverSession.setReadConnectionPool(pool);
            }
            String wait = getConfigPropertyAsStringLogDebug(PersistenceUnitProperties.JDBC_CONNECTIONS_WAIT, m, serverSession);
            if (wait != null) {
                value = wait;
                property = PersistenceUnitProperties.JDBC_CONNECTIONS_WAIT;
                serverSession.getDefaultConnectionPool().setWaitTimeout(Integer.parseInt(wait));
                pool.setWaitTimeout(Integer.parseInt(wait));
            }
        }
        // Configure sequence connection pool if set.
        String sequence = getConfigPropertyAsStringLogDebug(PersistenceUnitProperties.JDBC_SEQUENCE_CONNECTION_POOL, m, serverSession);
        if (sequence != null) {
            serverSession.getSequencingControl().setShouldUseSeparateConnection(Boolean.parseBoolean(sequence));
        }
        String sequenceDataSource = getConfigPropertyAsStringLogDebug(PersistenceUnitProperties.JDBC_SEQUENCE_CONNECTION_POOL_DATASOURCE, m, serverSession);
        if (sequenceDataSource != null) {
            DatasourceLogin login = this.session.getLogin().clone();
            login.dontUseExternalTransactionController();
            JNDIConnector jndiConnector = new JNDIConnector(sequenceDataSource);
            login.setConnector(jndiConnector);
            serverSession.getSequencingControl().setLogin(login);
        }
        // Sizes and shared option are irrelevant for external connection pool
        if (!serverSession.getReadConnectionPool().getLogin().shouldUseExternalConnectionPooling()) {
            value = getConfigPropertyAsStringLogDebug(PersistenceUnitProperties.JDBC_SEQUENCE_CONNECTION_POOL_MIN, m, serverSession);
            if (value != null) {
                property = PersistenceUnitProperties.JDBC_SEQUENCE_CONNECTION_POOL_MIN;
                serverSession.getSequencingControl().setMinPoolSize(Integer.parseInt(value));
            }
            value = getConfigPropertyAsStringLogDebug(PersistenceUnitProperties.JDBC_SEQUENCE_CONNECTION_POOL_MAX, m, serverSession);
            if (value != null) {
                property = PersistenceUnitProperties.JDBC_SEQUENCE_CONNECTION_POOL_MAX;
                serverSession.getSequencingControl().setMaxPoolSize(Integer.parseInt(value));
            }
            value = getConfigPropertyAsStringLogDebug(PersistenceUnitProperties.JDBC_SEQUENCE_CONNECTION_POOL_INITIAL, m, serverSession);
            if (value != null) {
                property = PersistenceUnitProperties.JDBC_SEQUENCE_CONNECTION_POOL_INITIAL;
                serverSession.getSequencingControl().setInitialPoolSize(Integer.parseInt(value));
            }
        }
    } catch (NumberFormatException exception) {
        serverSession.handleException(ValidationException.invalidValueForProperty(value, property, exception));
    }
}
Also used : ExternalConnectionPool(org.eclipse.persistence.sessions.server.ExternalConnectionPool) ReadConnectionPool(org.eclipse.persistence.sessions.server.ReadConnectionPool) ConnectionPool(org.eclipse.persistence.sessions.server.ConnectionPool) DatasourceLogin(org.eclipse.persistence.sessions.DatasourceLogin) ReadConnectionPool(org.eclipse.persistence.sessions.server.ReadConnectionPool) JNDIConnector(org.eclipse.persistence.sessions.JNDIConnector) EntityManagerFactoryProvider.getConfigPropertyAsString(org.eclipse.persistence.internal.jpa.EntityManagerFactoryProvider.getConfigPropertyAsString)

Example 3 with ReadConnectionPool

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

the class SessionsFactory method buildReadConnectionPoolConfig.

/**
 * INTERNAL:
 * Build a read connection pool from the config to store on the server session.
 */
protected ConnectionPool buildReadConnectionPoolConfig(ReadConnectionPoolConfig poolConfig, ServerSession serverSession) {
    // Exclusive tag - XML Schema default is false
    ConnectionPool connectionPool = (poolConfig.getExclusive()) ? new ConnectionPool() : new ReadConnectionPool();
    // Process the common elements in ConnectionPool
    processConnectionPoolConfig(poolConfig, connectionPool, serverSession);
    return connectionPool;
}
Also used : ReadConnectionPool(org.eclipse.persistence.sessions.server.ReadConnectionPool) ConnectionPool(org.eclipse.persistence.sessions.server.ConnectionPool) ReadConnectionPool(org.eclipse.persistence.sessions.server.ReadConnectionPool)

Example 4 with ReadConnectionPool

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

the class EntityManagerTLRJUnitTestSuite method testPersistenceProperties.

// The test removed because we moved back to binding literals
// on platforms other than DB2 and Derby
/*    public void testDontBindLiteral() {
        EntityManager em = createEntityManager("fieldaccess");

        Query controlQuery = em.createQuery("SELECT OBJECT(p) FROM SmallProject p WHERE p.name = CONCAT(:param1, :param2)");
        controlQuery.setParameter("param1", "A").setParameter("param2", "B");
        List controlResults = controlQuery.getResultList();
        int nControlParams = ((ExpressionQueryMechanism)((EJBQueryImpl)controlQuery).getDatabaseQuery().getQueryMechanism()).getCall().getParameters().size();
        if(nControlParams != 2) {
            fail("controlQuery has wrong number of parameters = "+nControlParams+"; 2 is expected");
        }

        Query query = em.createQuery("SELECT OBJECT(p) FROM SmallProject p WHERE p.name = CONCAT('A', 'B')");
        List results = query.getResultList();
        int nParams = ((ExpressionQueryMechanism)((EJBQueryImpl)query).getDatabaseQuery().getQueryMechanism()).getCall().getParameters().size();
        if(nParams > 0) {
            fail("Query processed literals as parameters");
        }

        closeEntityManager(em);
    }*/
public void testPersistenceProperties() {
    // Different properties are used on the server.
    if (isOnServer()) {
        return;
    }
    EntityManager em = createEntityManager("fieldaccess");
    ServerSession ss = ((org.eclipse.persistence.internal.jpa.EntityManagerImpl) em.getDelegate()).getServerSession();
    // these properties were set in persistence unit
    // and overridden in CMP3TestModel.setup - the values should be overridden.
    boolean isReadShared = (ss.getReadConnectionPool() instanceof ReadConnectionPool);
    if (isReadShared != Boolean.parseBoolean((String) JUnitTestCaseHelper.propertiesMap.get(PersistenceUnitProperties.JDBC_READ_CONNECTIONS_SHARED))) {
        fail("isReadShared is wrong");
    }
    int writeMin = ss.getDefaultConnectionPool().getMinNumberOfConnections();
    if (writeMin != Integer.parseInt((String) JUnitTestCaseHelper.propertiesMap.get(PersistenceUnitProperties.JDBC_WRITE_CONNECTIONS_MIN))) {
        fail("writeMin is wrong");
    }
    int writeMax = ss.getDefaultConnectionPool().getMaxNumberOfConnections();
    if (writeMax != Integer.parseInt((String) JUnitTestCaseHelper.propertiesMap.get(PersistenceUnitProperties.JDBC_WRITE_CONNECTIONS_MAX))) {
        fail("writeMax is wrong");
    }
    int readMin = ss.getReadConnectionPool().getMinNumberOfConnections();
    if (readMin != Integer.parseInt((String) JUnitTestCaseHelper.propertiesMap.get(PersistenceUnitProperties.JDBC_READ_CONNECTIONS_MIN))) {
        fail("readMin is wrong");
    }
    int readMax = ss.getReadConnectionPool().getMaxNumberOfConnections();
    if (readMax != Integer.parseInt((String) JUnitTestCaseHelper.propertiesMap.get(PersistenceUnitProperties.JDBC_READ_CONNECTIONS_MAX))) {
        fail("readMax is wrong");
    }
    // these properties were set in persistence unit - the values should be the same as in persistence.xml
    /*
            <property name="eclipselink.session-name" value="default-session"/>
            <property name="eclipselink.cache.size.default" value="500"/>
            <property name="eclipselink.cache.size.Employee" value="550"/>
            <property name="eclipselink.cache.size.org.eclipse.persistence.testing.models.jpa.advanced.Address" value="555"/>
            <property name="eclipselink.cache.type.default" value="Full"/>
            <property name="eclipselink.cache.type.Employee" value="Weak"/>
            <property name="eclipselink.cache.type.org.eclipse.persistence.testing.models.jpa.advanced.Address" value="HardWeak"/>
            <property name="eclipselink.session.customizer" value="org.eclipse.persistence.testing.models.jpa.advanced.Customizer"/>
            <property name="eclipselink.descriptor.customizer.Employee" value="org.eclipse.persistence.testing.models.jpa.advanced.Customizer"/>
            <property name="eclipselink.descriptor.customizer.org.eclipse.persistence.testing.models.jpa.advanced.Address" value="org.eclipse.persistence.testing.models.jpa.advanced.Customizer"/>
        */
    int defaultCacheSize = ss.getDescriptor(Project.class).getIdentityMapSize();
    if (defaultCacheSize != 500) {
        fail("defaultCacheSize is wrong");
    }
    int employeeCacheSize = ss.getDescriptor(Employee.class).getIdentityMapSize();
    if (employeeCacheSize != 550) {
        fail("employeeCacheSize is wrong");
    }
    int addressCacheSize = ss.getDescriptor(Address.class).getIdentityMapSize();
    if (addressCacheSize != 555) {
        fail("addressCacheSize is wrong");
    }
    Class<?> defaultCacheType = ss.getDescriptor(Project.class).getIdentityMapClass();
    if (!Helper.getShortClassName(defaultCacheType).equals("FullIdentityMap")) {
        fail("defaultCacheType is wrong");
    }
    Class<?> employeeCacheType = ss.getDescriptor(Employee.class).getIdentityMapClass();
    if (!Helper.getShortClassName(employeeCacheType).equals("WeakIdentityMap")) {
        fail("employeeCacheType is wrong");
    }
    Class<?> addressCacheType = ss.getDescriptor(Address.class).getIdentityMapClass();
    if (!Helper.getShortClassName(addressCacheType).equals("HardCacheWeakIdentityMap")) {
        fail("addressCacheType is wrong");
    }
    int numSessionCalls = Customizer.getNumberOfCallsForSession(ss.getName());
    if (numSessionCalls == 0) {
        fail("session customizer hasn't been called");
    }
    int numProjectCalls = Customizer.getNumberOfCallsForClass(Project.class.getName());
    if (numProjectCalls > 0) {
        fail("Project customizer has been called");
    }
    int numEmployeeCalls = Customizer.getNumberOfCallsForClass(Employee.class.getName());
    if (numEmployeeCalls == 0) {
        fail("Employee customizer hasn't been called");
    }
    int numAddressCalls = Customizer.getNumberOfCallsForClass(Address.class.getName());
    if (numAddressCalls == 0) {
        fail("Address customizer hasn't been called");
    }
    closeEntityManager(em);
}
Also used : ServerSession(org.eclipse.persistence.sessions.server.ServerSession) ReadConnectionPool(org.eclipse.persistence.sessions.server.ReadConnectionPool) EntityManager(jakarta.persistence.EntityManager) JpaEntityManager(org.eclipse.persistence.jpa.JpaEntityManager)

Example 5 with ReadConnectionPool

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

the class EntityManagerJUnitTestSuite method testPersistenceProperties.

// The test removed because we moved back to binding literals
// on platforms other than DB2 and Derby
/*    public void testDontBindLiteral() {
        EntityManager em = createEntityManager();

        Query controlQuery = em.createQuery("SELECT OBJECT(p) FROM SmallProject p WHERE p.name = CONCAT(:param1, :param2)");
        controlQuery.setParameter("param1", "A").setParameter("param2", "B");
        List controlResults = controlQuery.getResultList();
        int nControlParams = ((ExpressionQueryMechanism)((EJBQueryImpl)controlQuery).getDatabaseQuery().getQueryMechanism()).getCall().getParameters().size();
        if(nControlParams != 2) {
            fail("controlQuery has wrong number of parameters = "+nControlParams+"; 2 is expected");
        }

        Query query = em.createQuery("SELECT OBJECT(p) FROM SmallProject p WHERE p.name = CONCAT('A', 'B')");
        List results = query.getResultList();
        int nParams = ((ExpressionQueryMechanism)((EJBQueryImpl)query).getDatabaseQuery().getQueryMechanism()).getCall().getParameters().size();
        if(nParams > 0) {
            fail("Query processed literals as parameters");
        }

        closeEntityManager(em);
    }*/
public void testPersistenceProperties() {
    // Different properties are used on the server.
    if (isOnServer()) {
        return;
    }
    if (!getDatabaseSession().isServerSession()) {
        return;
    }
    EntityManager em = createEntityManager();
    ServerSession ss = ((org.eclipse.persistence.internal.jpa.EntityManagerImpl) em.getDelegate()).getServerSession();
    // these properties were set in persistence unit
    // and overridden in CMP3TestModel.setup - the values should be overridden.
    boolean isReadShared = (ss.getReadConnectionPool() instanceof ReadConnectionPool);
    if (isReadShared != Boolean.parseBoolean((String) JUnitTestCaseHelper.propertiesMap.get(PersistenceUnitProperties.JDBC_READ_CONNECTIONS_SHARED))) {
        fail("isReadShared is wrong");
    }
    int writeMin = ss.getDefaultConnectionPool().getMinNumberOfConnections();
    if (writeMin != Integer.parseInt((String) JUnitTestCaseHelper.propertiesMap.get(PersistenceUnitProperties.JDBC_WRITE_CONNECTIONS_MIN))) {
        fail("writeMin is wrong");
    }
    int writeMax = ss.getDefaultConnectionPool().getMaxNumberOfConnections();
    if (writeMax != Integer.parseInt((String) JUnitTestCaseHelper.propertiesMap.get(PersistenceUnitProperties.JDBC_WRITE_CONNECTIONS_MAX))) {
        fail("writeMax is wrong");
    }
    int readMin = ss.getReadConnectionPool().getMinNumberOfConnections();
    if (readMin != Integer.parseInt((String) JUnitTestCaseHelper.propertiesMap.get(PersistenceUnitProperties.JDBC_READ_CONNECTIONS_MIN))) {
        fail("readMin is wrong");
    }
    int readMax = ss.getReadConnectionPool().getMaxNumberOfConnections();
    if (readMax != Integer.parseInt((String) JUnitTestCaseHelper.propertiesMap.get(PersistenceUnitProperties.JDBC_READ_CONNECTIONS_MAX))) {
        fail("readMax is wrong");
    }
    // these properties were set in persistence unit - the values should be the same as in persistence.xml
    /*
            <property name="eclipselink.session-name" value="default-session"/>
            <property name="eclipselink.cache.size.default" value="500"/>
            <property name="eclipselink.cache.size.Employee" value="550"/>
            <property name="eclipselink.cache.size.org.eclipse.persistence.testing.models.jpa.advanced.Address" value="555"/>
            <property name="eclipselink.cache.type.default" value="Full"/>
            <property name="eclipselink.cache.type.Employee" value="Weak"/>
            <property name="eclipselink.cache.type.org.eclipse.persistence.testing.models.jpa.advanced.Address" value="HardWeak"/>
            <property name="eclipselink.session.customizer" value="org.eclipse.persistence.testing.models.jpa.advanced.Customizer"/>
            <property name="eclipselink.descriptor.customizer.Employee" value="org.eclipse.persistence.testing.models.jpa.advanced.Customizer"/>
            <property name="eclipselink.descriptor.customizer.org.eclipse.persistence.testing.models.jpa.advanced.Address" value="org.eclipse.persistence.testing.models.jpa.advanced.Customizer"/>
        */
    int defaultCacheSize = ss.getDescriptor(Project.class).getIdentityMapSize();
    if (defaultCacheSize != 500) {
        fail("defaultCacheSize is wrong");
    }
    int employeeCacheSize = ss.getDescriptor(Employee.class).getIdentityMapSize();
    if (employeeCacheSize != 550) {
        fail("employeeCacheSize is wrong");
    }
    int addressCacheSize = ss.getDescriptor(Address.class).getIdentityMapSize();
    if (addressCacheSize != 555) {
        fail("addressCacheSize is wrong");
    }
    Class<?> defaultCacheType = ss.getDescriptor(Project.class).getIdentityMapClass();
    if (!Helper.getShortClassName(defaultCacheType).equals("FullIdentityMap")) {
        fail("defaultCacheType is wrong");
    }
    Class<?> employeeCacheType = ss.getDescriptor(Employee.class).getIdentityMapClass();
    if (!Helper.getShortClassName(employeeCacheType).equals("WeakIdentityMap")) {
        fail("employeeCacheType is wrong");
    }
    Class<?> addressCacheType = ss.getDescriptor(Address.class).getIdentityMapClass();
    if (!Helper.getShortClassName(addressCacheType).equals("HardCacheWeakIdentityMap")) {
        fail("addressCacheType is wrong");
    }
    int numSessionCalls = Customizer.getNumberOfCallsForSession(ss.getName());
    if (numSessionCalls == 0) {
        fail("session customizer hasn't been called");
    }
    int numProjectCalls = Customizer.getNumberOfCallsForClass(Project.class.getName());
    if (numProjectCalls > 0) {
        fail("Project customizer has been called");
    }
    int numEmployeeCalls = Customizer.getNumberOfCallsForClass(Employee.class.getName());
    if (numEmployeeCalls == 0) {
        fail("Employee customizer hasn't been called");
    }
    int numAddressCalls = Customizer.getNumberOfCallsForClass(Address.class.getName());
    if (numAddressCalls == 0) {
        fail("Address customizer hasn't been called");
    }
    closeEntityManager(em);
}
Also used : ServerSession(org.eclipse.persistence.sessions.server.ServerSession) ReadConnectionPool(org.eclipse.persistence.sessions.server.ReadConnectionPool) Address(org.eclipse.persistence.testing.models.jpa.fieldaccess.advanced.Address) EntityManagerImpl(org.eclipse.persistence.internal.jpa.EntityManagerImpl) LargeProject(org.eclipse.persistence.testing.models.jpa.fieldaccess.advanced.LargeProject) SuperLargeProject(org.eclipse.persistence.testing.models.jpa.fieldaccess.advanced.SuperLargeProject) SmallProject(org.eclipse.persistence.testing.models.jpa.fieldaccess.advanced.SmallProject) Project(org.eclipse.persistence.testing.models.jpa.fieldaccess.advanced.Project) EntityManager(jakarta.persistence.EntityManager) JpaEntityManager(org.eclipse.persistence.jpa.JpaEntityManager) Employee(org.eclipse.persistence.testing.models.jpa.fieldaccess.advanced.Employee)

Aggregations

ReadConnectionPool (org.eclipse.persistence.sessions.server.ReadConnectionPool)7 ConnectionPool (org.eclipse.persistence.sessions.server.ConnectionPool)4 ServerSession (org.eclipse.persistence.sessions.server.ServerSession)4 EntityManager (jakarta.persistence.EntityManager)3 EntityManagerFactoryProvider.getConfigPropertyAsString (org.eclipse.persistence.internal.jpa.EntityManagerFactoryProvider.getConfigPropertyAsString)3 JpaEntityManager (org.eclipse.persistence.jpa.JpaEntityManager)3 ExternalConnectionPool (org.eclipse.persistence.sessions.server.ExternalConnectionPool)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 ConcurrentMap (java.util.concurrent.ConcurrentMap)2 IdentityMap (org.eclipse.persistence.internal.identitymaps.IdentityMap)2 EntityManagerImpl (org.eclipse.persistence.internal.jpa.EntityManagerImpl)2 OptimisticLockException (jakarta.persistence.OptimisticLockException)1 PersistenceException (jakarta.persistence.PersistenceException)1 PersistenceUnitTransactionType (jakarta.persistence.spi.PersistenceUnitTransactionType)1 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 Constructor (java.lang.reflect.Constructor)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 MalformedURLException (java.net.MalformedURLException)1