| 1 | |
package com.ctrip.apollo.biz.datasource; |
| 2 | |
|
| 3 | |
import java.lang.reflect.Method; |
| 4 | |
|
| 5 | |
import javax.sql.DataSource; |
| 6 | |
|
| 7 | |
import org.springframework.beans.factory.annotation.Autowired; |
| 8 | |
import org.springframework.context.annotation.Bean; |
| 9 | |
import org.springframework.context.annotation.Conditional; |
| 10 | |
import org.springframework.stereotype.Component; |
| 11 | |
|
| 12 | |
import com.dianping.cat.Cat; |
| 13 | |
|
| 14 | |
@Component |
| 15 | |
@Conditional(TitanCondition.class) |
| 16 | 0 | public class TitanEntityManager { |
| 17 | |
|
| 18 | |
@Autowired |
| 19 | |
private TitanSettings settings; |
| 20 | |
|
| 21 | |
@SuppressWarnings({"rawtypes", "unchecked"}) |
| 22 | |
@Bean |
| 23 | |
public DataSource datasource() throws Exception { |
| 24 | 0 | Class clazz = Class.forName("com.ctrip.datasource.configure.DalDataSourceFactory"); |
| 25 | 0 | Object obj = clazz.newInstance(); |
| 26 | 0 | Method method = clazz.getMethod("createDataSource", new Class[] {String.class, String.class}); |
| 27 | 0 | DataSource ds = ((DataSource) method.invoke(obj, |
| 28 | 0 | new Object[] {settings.getTitanDbname(), settings.getTitanUrl()})); |
| 29 | 0 | Cat.logEvent("Apollo.Datasource.Titan", settings.getTitanDbname()); |
| 30 | 0 | return ds; |
| 31 | |
} |
| 32 | |
|
| 33 | |
} |