Spring Data JPA – Multiple EnableJpaRepositories

In order to let spring knows what DataSource is related to what Repository you should define it at the @EnableJpaRepositories annotation. Let’s assume that we have two entities, the Servers entity and the Domains entity and each one has its own Repo then each Repository has its own JpaDataSource configuration. 1. Group all the repositories … Read more

mySQL DataSource on Visual Studio 2012

I have just read from mySQL Forums that mySQL will ship Visual Studio 2012 integration with mySQL Connector v.6.5.5 We’ll be adding support for VS 2012 in Connector/NET 6.5.5 and later 6.6.x version http://forums.mysql.com/read.php?38,546265,564533#msg-564533 and give a link to test a trick http://social.technet.microsoft.com/wiki/pt-br/contents/articles/10476.instalando-mysql-connector-no-visual-studio-2011-beta.aspx and here is the vsix file if you follow the tutorial (In … Read more

Externalizing Grails Datasource configuration

You can use a properties file specified in the grails.config.locations as a way to externalize the datasource configuration. Below is how I typically set up a Grails project: In my DataSource.groovy I specify this for the production environment: …. …. production { dataSource { dbCreate = “update” driverClassName = “com.myorg.jdbcDriverNotExists” url = “” username = … Read more

C# dictionary – one key, many values

As of .NET 3.5+, instead of using a Dictionary<IKey, List<IValue>>, you can use a Lookup from the LINQ namespace: // Lookup Order by payment status (1:m) // would need something like Dictionary<Boolean, IEnumerable<Order>> orderIdByIsPayed ILookup<Boolean, Order> byPayment = orderList.ToLookup(o => o.IsPayed); IEnumerable<Order> payedOrders = byPayment[false]; From MSDN: A Lookup<TKey, TElement> resembles a Dictionary<TKey, TValue>. The … Read more

Spring Boot configure and use two data sources

Here you go. Add in your application.properties file: #first db spring.datasource.url = [url] spring.datasource.username = [username] spring.datasource.password = [password] spring.datasource.driverClassName = oracle.jdbc.OracleDriver #second db … spring.secondDatasource.url = [url] spring.secondDatasource.username = [username] spring.secondDatasource.password = [password] spring.secondDatasource.driverClassName = oracle.jdbc.OracleDriver Add in any class annotated with @Configuration the following methods: @Bean @Primary @ConfigurationProperties(prefix=”spring.datasource”) public DataSource primaryDataSource() { return … Read more

dynamically change Spring data source

You can use spring’s AbstractRoutingDataSource by extending it and overriding the method determineCurrentLookupKey() that should return the key referencing the datasource’s spring bean to be used. Take a look at this blog article on spring source’s blog which will show you an example of how to use that feature. Basically to answer your questions, what … Read more