Search in sources :

Example 11 with JdbcConnectionPool

use of org.glassfish.jdbc.config.JdbcConnectionPool in project Payara by payara.

the class JdbcRuntimeExtension method getAllSystemRAResourcesAndPools.

@Override
public Collection<Resource> getAllSystemRAResourcesAndPools() {
    List<Resource> resources = new ArrayList<Resource>();
    Domain domain = domainProvider.get();
    if (domain != null) {
        Resources allResources = domain.getResources();
        for (Resource resource : allResources.getResources()) {
            if (resource instanceof JdbcConnectionPool) {
                resources.add(resource);
            } else if (resource instanceof JdbcResource) {
                resources.add(resource);
            }
        }
    }
    System.out.println("JdbcRuntimeExtension,  getAllSystemRAResourcesAndPools = " + resources);
    return resources;
}
Also used : JdbcResource(org.glassfish.jdbc.config.JdbcResource) JdbcConnectionPool(org.glassfish.jdbc.config.JdbcConnectionPool) Resource(com.sun.enterprise.config.serverbeans.Resource) JdbcResource(org.glassfish.jdbc.config.JdbcResource) ArrayList(java.util.ArrayList) Resources(com.sun.enterprise.config.serverbeans.Resources) Domain(com.sun.enterprise.config.serverbeans.Domain)

Example 12 with JdbcConnectionPool

use of org.glassfish.jdbc.config.JdbcConnectionPool in project Payara by payara.

the class JDBCConnectionPoolManager method createResource.

private JdbcConnectionPool createResource(Resources param, Properties properties) throws PropertyVetoException, TransactionFailure {
    JdbcConnectionPool newResource = createConfigBean(param, properties);
    param.getResources().add(newResource);
    return newResource;
}
Also used : JdbcConnectionPool(org.glassfish.jdbc.config.JdbcConnectionPool)

Example 13 with JdbcConnectionPool

use of org.glassfish.jdbc.config.JdbcConnectionPool in project Payara by payara.

the class JdbcConnectionPoolValidatorTest method customConnectionValidation.

@Test
public void customConnectionValidation() {
    this.validator.initialize(createAnnotation(CUSTOM_VALIDATION_CLASS_NAME_MANDATORY));
    final JdbcConnectionPool pool = createMock();
    assertTrue("everything OK", this.validator.isValid(pool, null));
    updateMock(pool, p -> {
        expect(p.getIsConnectionValidationRequired()).andStubReturn("true");
        expect(p.getConnectionValidationMethod()).andStubReturn("custom-validation");
        expect(p.getValidationClassname()).andStubReturn(String.class.getName());
    });
    assertTrue("validation by class enabled, everything is set", this.validator.isValid(pool, null));
    updateMock(pool, p -> {
        expect(p.getIsConnectionValidationRequired()).andStubReturn("true");
        // is this alright?
        expect(p.getConnectionValidationMethod()).andStubReturn("somethingelse");
        expect(p.getValidationClassname()).andStubReturn(null);
    });
    assertTrue("validation by class is not set", this.validator.isValid(pool, null));
    updateMock(pool, p -> {
        expect(p.getIsConnectionValidationRequired()).andStubReturn("true");
        expect(p.getConnectionValidationMethod()).andStubReturn("custom-validation");
        expect(p.getValidationClassname()).andStubReturn(null);
    });
    assertFalse("validation by class set, but no class name", this.validator.isValid(pool, null));
}
Also used : JdbcConnectionPool(org.glassfish.jdbc.config.JdbcConnectionPool) Test(org.junit.Test)

Example 14 with JdbcConnectionPool

use of org.glassfish.jdbc.config.JdbcConnectionPool in project Payara by payara.

the class JdbcConnectionPoolValidatorTest method poolSizeMax.

@Test
public void poolSizeMax() {
    this.validator.initialize(createAnnotation(POOL_SIZE_MAX));
    final JdbcConnectionPool pool = createMock();
    assertTrue("everything OK", this.validator.isValid(pool, null));
    updateMock(pool, p -> expect(p.getSteadyPoolSize()).andStubReturn(null));
    assertTrue("steady pool size null", this.validator.isValid(pool, null));
    updateMock(pool, p -> expect(p.getSteadyPoolSize()).andStubReturn("-1"));
    assertTrue("negative steady pool size is not thing checked by max checker", this.validator.isValid(pool, null));
    updateMock(pool, p -> {
        expect(p.getSteadyPoolSize()).andStubReturn("8");
        expect(p.getMaxPoolSize()).andStubReturn("5");
    });
    assertFalse("steady pool size is higher than max pool size", this.validator.isValid(pool, null));
    updateMock(pool, p -> {
        expect(p.getSteadyPoolSize()).andStubReturn("0");
        expect(p.getMaxPoolSize()).andStubReturn("0");
    });
    assertFalse("max pool size is 0", this.validator.isValid(pool, null));
    updateMock(pool, p -> expect(p.getMaxPoolSize()).andStubReturn("${ENV=maxpoolsizeproperty}"));
    assertFalse("undefined variable in max pool size", this.validator.isValid(pool, null));
}
Also used : JdbcConnectionPool(org.glassfish.jdbc.config.JdbcConnectionPool) Test(org.junit.Test)

Example 15 with JdbcConnectionPool

use of org.glassfish.jdbc.config.JdbcConnectionPool in project Payara by payara.

the class JdbcConnectionPoolValidatorTest method resourceType.

@Test
public void resourceType() {
    this.validator.initialize(createAnnotation(RES_TYPE_MANDATORY));
    final JdbcConnectionPool pool = createMock();
    assertTrue("everything OK", this.validator.isValid(pool, null));
    final Class<?>[] apiTypes = new Class[] { DataSource.class, XADataSource.class, ConnectionPoolDataSource.class };
    for (Class<?> api : apiTypes) {
        updateMock(pool, p -> {
            expect(pool.getResType()).andStubReturn(api.getName());
            expect(pool.getDatasourceClassname()).andStubReturn(null);
            expect(pool.getDriverClassname()).andStubReturn("ewdwedw");
        });
        assertFalse("Resource type " + api + ", but missing impl", this.validator.isValid(pool, null));
        updateMock(pool, p -> {
            expect(pool.getResType()).andStubReturn(api.getName());
            expect(pool.getDatasourceClassname()).andStubReturn(DataSource.class.getName());
            expect(pool.getDriverClassname()).andStubReturn(null);
        });
        assertTrue("Resource type " + api + "and Data source type set", this.validator.isValid(pool, null));
    }
    updateMock(pool, p -> {
        expect(pool.getResType()).andStubReturn(null);
        expect(pool.getDatasourceClassname()).andStubReturn(null);
        expect(pool.getDriverClassname()).andStubReturn(Driver.class.getName());
    });
    assertTrue("Resource type is null, driver is set", this.validator.isValid(pool, null));
    updateMock(pool, p -> {
        expect(pool.getResType()).andStubReturn(null);
        expect(pool.getDatasourceClassname()).andStubReturn(DataSource.class.getName());
        expect(pool.getDriverClassname()).andStubReturn(null);
    });
    assertTrue("Resource type is null, ds is set", this.validator.isValid(pool, null));
    updateMock(pool, p -> {
        expect(pool.getResType()).andStubReturn(null);
        expect(pool.getDatasourceClassname()).andStubReturn(DataSource.class.getName());
        expect(pool.getDriverClassname()).andStubReturn(Driver.class.getName());
    });
    assertFalse("Resource type is null, ds and driver are set", this.validator.isValid(pool, null));
    updateMock(pool, p -> {
        expect(pool.getResType()).andStubReturn(null);
        expect(pool.getDatasourceClassname()).andStubReturn(null);
        expect(pool.getDriverClassname()).andStubReturn(null);
    });
    assertFalse("Resource type, ds and driver are null", this.validator.isValid(pool, null));
    // questionable behavior of the old code
    updateMock(pool, p -> {
        expect(pool.getResType()).andStubReturn(String.class.getName());
        expect(pool.getDatasourceClassname()).andStubReturn(null);
        expect(pool.getDriverClassname()).andStubReturn(null);
    });
    assertTrue("Resource type is unknown", this.validator.isValid(pool, null));
    updateMock(pool, p -> {
        expect(pool.getResType()).andStubReturn(Driver.class.getName());
        expect(pool.getDatasourceClassname()).andStubReturn(null);
        expect(pool.getDriverClassname()).andStubReturn(null);
    });
    assertFalse("Resource type is " + pool.getResType() + ", but driver class is null", this.validator.isValid(pool, null));
    updateMock(pool, p -> {
        expect(pool.getResType()).andStubReturn(Driver.class.getName());
        expect(pool.getDatasourceClassname()).andStubReturn(null);
        expect(pool.getDriverClassname()).andStubReturn(Driver.class.getName());
    });
    assertTrue("Resource type is " + pool.getResType() + ", and driver class is set", this.validator.isValid(pool, null));
}
Also used : ConnectionPoolDataSource(javax.sql.ConnectionPoolDataSource) XADataSource(javax.sql.XADataSource) JdbcConnectionPool(org.glassfish.jdbc.config.JdbcConnectionPool) Driver(java.sql.Driver) XADataSource(javax.sql.XADataSource) DataSource(javax.sql.DataSource) ConnectionPoolDataSource(javax.sql.ConnectionPoolDataSource) Test(org.junit.Test)

Aggregations

JdbcConnectionPool (org.glassfish.jdbc.config.JdbcConnectionPool)32 PoolInfo (org.glassfish.resourcebase.resources.api.PoolInfo)10 JdbcResource (org.glassfish.jdbc.config.JdbcResource)7 Test (org.junit.Test)7 ConnectorRuntimeException (com.sun.appserv.connectors.internal.api.ConnectorRuntimeException)5 Resources (com.sun.enterprise.config.serverbeans.Resources)4 Resource (com.sun.enterprise.config.serverbeans.Resource)3 ActionReport (org.glassfish.api.ActionReport)3 ResourceInfo (org.glassfish.resourcebase.resources.api.ResourceInfo)3 Domain (com.sun.enterprise.config.serverbeans.Domain)2 ResourcePool (com.sun.enterprise.config.serverbeans.ResourcePool)2 ConnectorConnectionPool (com.sun.enterprise.connectors.ConnectorConnectionPool)2 DataSourceDefinitionDescriptor (com.sun.enterprise.deployment.DataSourceDefinitionDescriptor)2 ArrayList (java.util.ArrayList)2 ConnectionPoolDataSource (javax.sql.ConnectionPoolDataSource)2 DataSource (javax.sql.DataSource)2 XADataSource (javax.sql.XADataSource)2 ConnectorConnectionPool (org.glassfish.connectors.config.ConnectorConnectionPool)2 ResourceConflictException (org.glassfish.resourcebase.resources.api.ResourceConflictException)2 Property (org.jvnet.hk2.config.types.Property)2