Class DataSourceConfig
applicationContext-dataSource.xml.
Ports four concerns from the XML, preserving bean ids exactly (the dataSource id is
referenced by name from applicationContext-hibernate.xml's sessionFactory,
from applicationContext-dataSourceInitializer.xml's test-profile
DataSourceInitializer beans, and from many @Autowired DataSource injections in
persistence code — breaking the name would break the world):
- Production / dev
dataSource— Hikari, pointed atgemma.db.*. - Test
dataSource— Hikari, pointed atgemma.testdb.*. groupAgentSecurityContext— lazy factory bean used by the scheduler to run scheduled jobs under the GROUP_AGENT identity; the test profile uses different credentials.mailSender— realJavaMailSenderImplin production, aDummyMailSenderelsewhere.
java.lang.Object beans named
createDatabaseInitializer and dataSourceInitializer under the
production/dev profile so that applicationContext-hibernate.xml's
depends-on="createDatabaseInitializer" would resolve. In the test profile,
applicationContext-dataSourceInitializer.xml provides real
DataSourceInitializer beans under the same ids. We preserve that arrangement by
declaring the stubs here under @Profile("!test & !testdb"); the test-profile XML's
beans then live alongside (different profile) without collision.
The MySQL-specific connection properties bean (dataSourceProps) is preserved as a
private helper rather than a Spring bean — it was only ever referenced by the two
dataSource bean definitions in the same XML, never by name from outside.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionDummycreateDatabaseInitializerstub.dataSource(String user, String password, String url, int maximumPoolSize, int minimumIdle) Production / dev datasource.DummydataSourceInitializerstub.org.springframework.mail.MailSendergroupAgentSecurityContext(ManualAuthenticationService manualAuthenticationService, String userName, String password) Lazy factory for theGROUP_AGENTSecurityContext.org.springframework.mail.MailSendermailSender(String host, String protocol, String username, String password) static LongmaxExecutionTimeOf(String sessionVariables) Read back the statement timeoutwithMaxExecutionTime(String, String)composed, in milliseconds, ornullwhen the list carries none.testDataSource(String user, String password, String url, int maximumPoolSize, int minimumIdle) Test datasource.testGroupAgentSecurityContext(ManualAuthenticationService manualAuthenticationService, String userName, String password) Test-profile variant ofgroupAgentSecurityContext(ManualAuthenticationService, String, String): same bean id, different credential keys (gemma.testdb.agent.*) so test runs don't authenticate against production credentials.
-
Constructor Details
-
DataSourceConfig
public DataSourceConfig()
-
-
Method Details
-
maxExecutionTimeOf
Read back the statement timeoutwithMaxExecutionTime(String, String)composed, in milliseconds, ornullwhen the list carries none.It lives beside the composer so the two cannot drift, and it exists because the setting is otherwise invisible from outside the JVM: the deployment sets an environment variable, the variable becomes a Connector/J property, and nothing between there and MySQL says whether it arrived.
GET /admin/db/poolreports what this returns, so "is the cap on?" is a question the running server answers about itself rather than one answered by reading env files and inferring.- Parameters:
sessionVariables- a Connector/J session-variable list, possibly null
-
dataSource
@Bean(name="dataSource", destroyMethod="close") @Profile({"production","dev"}) public DataSource dataSource(@Value("${gemma.db.user}") String user, @Value("${gemma.db.password}") String password, @Value("${gemma.db.url}") String url, @Value("${gemma.db.maximumPoolSize}") int maximumPoolSize, @Value("${gemma.db.minimumIdle}") int minimumIdle) Production / dev datasource. Active under theproductionanddevprofiles (Gemma uses the same physical database in both — dev points at the prod schema for local-against-prod debugging; only the connection pool sizes differ viagemma.db.*property overrides). -
testDataSource
@Bean(name="dataSource", destroyMethod="close") @Profile({"test","testdb"}) public DataSource testDataSource(@Value("${gemma.testdb.user}") String user, @Value("${gemma.testdb.password}") String password, @Value("${gemma.testdb.url}") String url, @Value("${gemma.testdb.maximumPoolSize}") int maximumPoolSize, @Value("${gemma.testdb.minimumIdle}") int minimumIdle) Test datasource. Active undertest(unit + integration tests) andtestdb(Flyway baseline / migration verification against a disposable schema). Bean id is the same as the prod datasource — only one of the two definitions is active at a time, so downstream@Autowired DataSourceinjections work uniformly. The test-profileDataSourceInitializerbeans inapplicationContext-dataSourceInitializer.xmlreferencedataSourceby name and so consume whichever of these two is active. -
groupAgentSecurityContext
@Bean(name="groupAgentSecurityContext") @Lazy @Profile({"production","dev"}) public ManualAuthenticationServiceBasedSecurityContextFactory groupAgentSecurityContext(ManualAuthenticationService manualAuthenticationService, @Value("${gemma.agent.userName}") String userName, @Value("${gemma.agent.password}") String password) Lazy factory for theGROUP_AGENTSecurityContext. Only built when the scheduler actually launches a job. Active under production / dev wheregemma.agent.*properties are populated.Returned as the
ManualAuthenticationServiceBasedSecurityContextFactory(a SpringFactoryBean); Spring unwraps it for@Autowired SecurityContextinjections and exposes it as the raw factory forBeanFactory#getBean("&...")callers. -
testGroupAgentSecurityContext
@Bean(name="groupAgentSecurityContext") @Lazy @Profile({"test","testdb"}) public ManualAuthenticationServiceBasedSecurityContextFactory testGroupAgentSecurityContext(ManualAuthenticationService manualAuthenticationService, @Value("${gemma.testdb.agent.userName}") String userName, @Value("${gemma.testdb.agent.password}") String password) Test-profile variant ofgroupAgentSecurityContext(ManualAuthenticationService, String, String): same bean id, different credential keys (gemma.testdb.agent.*) so test runs don't authenticate against production credentials. -
mailSender
-
dummyMailSender
@Bean(name="mailSender") @Profile("!production") public org.springframework.mail.MailSender dummyMailSender() -
createDatabaseInitializerStub
@Bean(name="createDatabaseInitializer") @Profile({"production","dev"}) public Object createDatabaseInitializerStub()DummycreateDatabaseInitializerstub.applicationContext-hibernate.xml'ssessionFactorydeclaresdepends-on="createDatabaseInitializer"so that in test runs the empty gemdtest DB exists before Hibernate's hbm2ddl=create fires; the realDataSourceInitializerbean by this id is provided byapplicationContext-dataSourceInitializer.xmlunder@Profile("test"). Outside the test profile that bean isn't loaded, sodepends-onwould fail resolution — hence the stub here under the complementary profile. -
dataSourceInitializerStub
@Bean(name="dataSourceInitializer") @Profile({"production","dev"}) public Object dataSourceInitializerStub()DummydataSourceInitializerstub. MirrorscreateDatabaseInitializerStub(); other beans (test-only) may declaredepends-on="dataSourceInitializer"and the legacy XML kept a stub for symmetry. Preserved here verbatim.
-