Skip to content

Instantly share code, notes, and snippets.

@hugithordarson
Created April 24, 2021 09:03
Show Gist options
  • Save hugithordarson/12cd9972ae3b515b5005ec1adebda15a to your computer and use it in GitHub Desktop.
Save hugithordarson/12cd9972ae3b515b5005ec1adebda15a to your computer and use it in GitHub Desktop.
public static ServerRuntime createServerRuntime() {
return ServerRuntime
.builder()
.addConfig( "cayenne-project.xml" )
.addModule( b -> b.bind( DataSourceFactory.class ).to( AppDataSourceFactory.class ) )
.build();
}
private static class AppDataSourceFactory implements DataSourceFactory {
@Override
public DataSource getDataSource( DataNodeDescriptor nodeDescriptor ) throws Exception {
final String dataNoteName = nodeDescriptor.getName();
final HikariConfig config = new HikariConfig();
if( dataNoteName.equals( "somenode" ) ) {
config.setUsername( "someuser" );
config.setPassword( "somepass" );
config.setJdbcUrl( "someurl" );
config.setMaximumPoolSize( 4 );
}
else if( dataNoteName.equals( "othernode" ) ) {
config.setUsername( "otheruser" );
config.setPassword( "otherpass" );
config.setJdbcUrl( "otherurl" );
config.setOtherStuff( ... );
}
else {
throw new IllegalArgumentException( "Unknown dataNode: " + dataNoteName );
}
return new HikariDataSource( config );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment