Created
June 16, 2015 15:34
-
-
Save iocanel/678a440e343225be71df to your computer and use it in GitHub Desktop.
Datasource Factory
This file contains 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
import com.mysql.jdbc.jdbc2.optional.MysqlDataSource; | |
import io.fabric8.annotations.Configuration; | |
import io.fabric8.annotations.Factory; | |
import io.fabric8.annotations.ServiceName; | |
import javax.sql.DataSource; | |
public class DatasourceFactory { | |
private static final String TCP_PROTO = "tcp"; | |
private static final String JDBC_PROTO = "jdbc:mysql"; | |
@Factory | |
@ServiceName | |
public DataSource create(@ServiceName String url, @Configuration MysqlConfiguration conf) { | |
MysqlDataSource ds = new MysqlDataSource(); | |
ds.setURL(url.replaceFirst(TCP_PROTO, JDBC_PROTO) + "/" + conf.getDatabaseName()); | |
ds.setUser(conf.getUsername()); | |
ds.setPassword(conf.getPassword()); | |
return ds; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment