Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Datasource Factory
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