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;
}
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;
}
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));
}
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));
}
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));
}
Aggregations