Search in sources :

Example 16 with JdbcConnectionPool

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

the class JdbcConnectionPoolValidatorTest method wrappers.

@Test
public void wrappers() {
    this.validator.initialize(createAnnotation(STMT_WRAPPING_DISABLED));
    final JdbcConnectionPool pool = createMock();
    assertTrue("everything OK", this.validator.isValid(pool, null));
    updateMock(pool, p -> expect(p.getWrapJdbcObjects()).andStubReturn("false"));
    assertTrue("wrapping disabled, all related settings ok", this.validator.isValid(pool, null));
    updateMock(pool, p -> {
        expect(p.getWrapJdbcObjects()).andStubReturn("false");
        expect(p.getSqlTraceListeners()).andStubReturn(null);
        expect(p.getStatementCacheSize()).andStubReturn("200");
    });
    assertFalse("wrapping disabled, but statement cache size set", this.validator.isValid(pool, null));
    updateMock(pool, p -> {
        expect(p.getWrapJdbcObjects()).andStubReturn(null);
        expect(p.getStatementCacheSize()).andStubReturn("13");
        expect(p.getStatementLeakTimeoutInSeconds()).andStubReturn("30");
    });
    assertFalse("wrapping disabled, but statement leak timeout set", this.validator.isValid(pool, null));
    updateMock(pool, p -> {
        expect(p.getWrapJdbcObjects()).andStubReturn(null);
        expect(p.getStatementLeakTimeoutInSeconds()).andStubReturn(null);
        expect(p.getStatementLeakReclaim()).andStubReturn("true");
    });
    assertFalse("wrapping disabled, but statement leak reclaim set", this.validator.isValid(pool, null));
    updateMock(pool, p -> {
        expect(p.getWrapJdbcObjects()).andStubReturn(null);
        expect(p.getStatementLeakTimeoutInSeconds()).andStubReturn(null);
        expect(p.getStatementLeakReclaim()).andStubReturn("false");
    });
    assertTrue("wrapping disabled, no conflicts", this.validator.isValid(pool, null));
}
Also used : JdbcConnectionPool(org.glassfish.jdbc.config.JdbcConnectionPool) Test(org.junit.Test)

Example 17 with JdbcConnectionPool

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

the class JdbcConnectionPoolValidatorTest method poolSizeSteady.

@Test
public void poolSizeSteady() {
    this.validator.initialize(createAnnotation(POOL_SIZE_STEADY));
    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"));
    assertFalse("steady pool size negative", this.validator.isValid(pool, null));
    updateMock(pool, p -> expect(p.getSteadyPoolSize()).andStubReturn("${env.steadypoolsizeproperty}"));
    assertFalse("undefined variable in steady pool size", this.validator.isValid(pool, null));
    updateMock(pool, p -> expect(p.getSteadyPoolSize()).andStubReturn("${ENV=steadypoolsizeproperty}"));
    assertFalse("undefined variable in steady pool size", this.validator.isValid(pool, null));
    updateMock(pool, p -> expect(p.getSteadyPoolSize()).andStubReturn("${ENV=USER}"));
    assertFalse("env.USER variable in steady pool size is not a number", this.validator.isValid(pool, null));
    updateMock(pool, p -> expect(p.getSteadyPoolSize()).andStubReturn("${MPCONFIG=USER}"));
    try {
        this.validator.isValid(pool, null);
        fail("Expected exception, because we don't have any microprofile impl here.");
    } catch (final Exception e) {
        assertEquals("root cause.message", "No ConfigProviderResolver implementation found!", ExceptionUtil.getRootCause(e).getMessage());
    }
    updateMock(pool, p -> {
        expect(p.getSteadyPoolSize()).andStubReturn("8");
        expect(p.getMaxPoolSize()).andStubReturn("5");
    });
    assertTrue("this should not check the max pool size", this.validator.isValid(pool, null));
}
Also used : JdbcConnectionPool(org.glassfish.jdbc.config.JdbcConnectionPool) Test(org.junit.Test)

Example 18 with JdbcConnectionPool

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

the class FlushConnectionPool method execute.

public void execute(AdminCommandContext context) {
    final ActionReport report = context.getActionReport();
    Resources resources = domain.getResources();
    String scope = "";
    if (moduleName != null) {
        if (!poolUtil.isValidModule(applicationName, moduleName, poolName, report)) {
            return;
        }
        Application application = applications.getApplication(applicationName);
        Module module = application.getModule(moduleName);
        resources = module.getResources();
        scope = ConnectorConstants.JAVA_MODULE_SCOPE_PREFIX;
    } else if (applicationName != null) {
        if (!poolUtil.isValidApplication(applicationName, poolName, report)) {
            return;
        }
        Application application = applications.getApplication(applicationName);
        resources = application.getResources();
        scope = ConnectorConstants.JAVA_APP_SCOPE_PREFIX;
    }
    if (!poolUtil.isValidPool(resources, poolName, scope, report)) {
        return;
    }
    boolean poolingEnabled = false;
    ResourcePool pool = (ResourcePool) ConnectorsUtil.getResourceByName(resources, ResourcePool.class, poolName);
    if (pool instanceof ConnectorConnectionPool) {
        ConnectorConnectionPool ccp = (ConnectorConnectionPool) pool;
        poolingEnabled = Boolean.valueOf(ccp.getPooling());
    } else {
        JdbcConnectionPool ccp = (JdbcConnectionPool) pool;
        poolingEnabled = Boolean.valueOf(ccp.getPooling());
    }
    if (!poolingEnabled) {
        String i18nMsg = localStrings.getLocalString("flush.connection.pool.pooling.disabled", "Attempt to Flush Connection Pool failed because Pooling is disabled for pool : {0}", poolName);
        report.setMessage(i18nMsg);
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    try {
        PoolInfo poolInfo = new PoolInfo(poolName, applicationName, moduleName);
        _runtime.flushConnectionPool(poolInfo);
        report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
    } catch (ConnectorRuntimeException e) {
        report.setMessage(localStrings.getLocalString("flush.connection.pool.fail", "Flush connection pool for {0} failed", poolName));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setFailureCause(e);
    }
}
Also used : ConnectorRuntimeException(com.sun.appserv.connectors.internal.api.ConnectorRuntimeException) ConnectorConnectionPool(org.glassfish.connectors.config.ConnectorConnectionPool) JdbcConnectionPool(org.glassfish.jdbc.config.JdbcConnectionPool) PoolInfo(org.glassfish.resourcebase.resources.api.PoolInfo) ActionReport(org.glassfish.api.ActionReport)

Example 19 with JdbcConnectionPool

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

the class FlushConnectionPoolLocal method execute.

@Override
public void execute(AdminCommandContext context) {
    final ActionReport report = context.getActionReport();
    Resources resources = domain.getResources();
    String scope = "";
    if (moduleName != null) {
        if (!poolUtil.isValidModule(applicationName, moduleName, poolName, report)) {
            return;
        }
        Application application = applications.getApplication(applicationName);
        Module module = application.getModule(moduleName);
        resources = module.getResources();
        scope = ConnectorConstants.JAVA_MODULE_SCOPE_PREFIX;
    } else if (applicationName != null) {
        if (!poolUtil.isValidApplication(applicationName, poolName, report)) {
            return;
        }
        Application application = applications.getApplication(applicationName);
        resources = application.getResources();
        scope = ConnectorConstants.JAVA_APP_SCOPE_PREFIX;
    }
    if (!poolUtil.isValidPool(resources, poolName, scope, report)) {
        return;
    }
    boolean poolingEnabled = false;
    ResourcePool pool = (ResourcePool) ConnectorsUtil.getResourceByName(resources, ResourcePool.class, poolName);
    if (pool instanceof ConnectorConnectionPool) {
        ConnectorConnectionPool ccp = (ConnectorConnectionPool) pool;
        poolingEnabled = Boolean.valueOf(ccp.getPooling());
    } else {
        JdbcConnectionPool ccp = (JdbcConnectionPool) pool;
        poolingEnabled = Boolean.valueOf(ccp.getPooling());
    }
    if (!poolingEnabled) {
        String i18nMsg = localStrings.getLocalString("flush.connection.pool.pooling.disabled", "Attempt to Flush Connection Pool failed because Pooling is disabled for pool : {0}", poolName);
        report.setMessage(i18nMsg);
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        return;
    }
    try {
        PoolInfo poolInfo = new PoolInfo(poolName, applicationName, moduleName);
        _runtime.flushConnectionPool(poolInfo);
        report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
        Logger.getLogger("org.glassfish.connectors.admin.cli").log(Level.FINE, "Flush connection pool for {0} succeeded", poolName);
    } catch (ConnectorRuntimeException e) {
        report.setMessage(localStrings.getLocalString("flush.connection.pool.fail", "Flush connection pool for {0} failed", poolName));
        report.setActionExitCode(ActionReport.ExitCode.FAILURE);
        report.setFailureCause(e);
    }
}
Also used : ConnectorRuntimeException(com.sun.appserv.connectors.internal.api.ConnectorRuntimeException) ConnectorConnectionPool(org.glassfish.connectors.config.ConnectorConnectionPool) JdbcConnectionPool(org.glassfish.jdbc.config.JdbcConnectionPool) PoolInfo(org.glassfish.resourcebase.resources.api.PoolInfo) ActionReport(org.glassfish.api.ActionReport) Module(com.sun.enterprise.config.serverbeans.Module)

Example 20 with JdbcConnectionPool

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

the class JdbcRuntimeExtension method getDeferredResourceConfig.

@Override
public DeferredResourceConfig getDeferredResourceConfig(Object resource, Object pool, String resType, String raName) throws ConnectorRuntimeException {
    String resourceAdapterName;
    DeferredResourceConfig resConfig = null;
    // TODO V3 (not to hold specific resource types)
    if (resource instanceof JdbcResource || pool instanceof JdbcConnectionPool) {
        JdbcConnectionPool jdbcPool = (JdbcConnectionPool) pool;
        JdbcResource jdbcResource = (JdbcResource) resource;
        resourceAdapterName = getRANameofJdbcConnectionPool((JdbcConnectionPool) pool);
        resConfig = new DeferredResourceConfig(resourceAdapterName, null, jdbcPool, jdbcResource, null);
        Resource[] resourcesToload = new Resource[] { jdbcPool, jdbcResource };
        resConfig.setResourcesToLoad(resourcesToload);
    } else {
        throw new ConnectorRuntimeException("unsupported resource type : " + resource);
    }
    return resConfig;
}
Also used : ConnectorRuntimeException(com.sun.appserv.connectors.internal.api.ConnectorRuntimeException) JdbcResource(org.glassfish.jdbc.config.JdbcResource) DeferredResourceConfig(com.sun.enterprise.connectors.DeferredResourceConfig) JdbcConnectionPool(org.glassfish.jdbc.config.JdbcConnectionPool) Resource(com.sun.enterprise.config.serverbeans.Resource) JdbcResource(org.glassfish.jdbc.config.JdbcResource)

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