Created
April 24, 2021 09:03
-
-
Save hugithordarson/12cd9972ae3b515b5005ec1adebda15a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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