use of com.alibaba.otter.shared.common.model.config.data.db.DbMediaSource in project otter by alibaba.
the class BaseDbTest method getOracleMedia.
public DbDataMedia getOracleMedia() {
DbMediaSource dbMediaSource = new DbMediaSource();
dbMediaSource.setId(11L);
dbMediaSource.setDriver("oracle.jdbc.OracleDriver");
dbMediaSource.setUsername("xxxxx");
dbMediaSource.setPassword("xxxxx");
dbMediaSource.setUrl("jdbc:oracle:thin:@127.0.0.1:1521:crmgsb");
dbMediaSource.setEncode("UTF-8");
dbMediaSource.setType(DataMediaType.ORACLE);
DbDataMedia dataMedia = new DbDataMedia();
dataMedia.setSource(dbMediaSource);
dataMedia.setId(2L);
dataMedia.setName("columns");
dataMedia.setNamespace("srf");
return dataMedia;
}
use of com.alibaba.otter.shared.common.model.config.data.db.DbMediaSource in project otter by alibaba.
the class JsonUtilsTest method test_filter.
@Test
public void test_filter() {
DbMediaSource media = new DbMediaSource();
media.setGmtCreate(new Date());
media.setGmtModified(new Date());
media.setId(1L);
media.setName("test");
// 这个是枚举值
media.setType(DataMediaType.MYSQL);
media.setUsername("ljh");
media.setPassword("ljh");
String str = JsonUtils.marshalToString(media, "gmtCreate", "gmtModified", "id", "name", "type");
want.string(str).notContain("id");
DbMediaSource target = JsonUtils.unmarshalFromString(str, DbMediaSource.class);
want.object(target.getUsername()).notNull();
want.object(target.getPassword()).notNull();
}
use of com.alibaba.otter.shared.common.model.config.data.db.DbMediaSource in project otter by alibaba.
the class DataSourceCreator method createDataSource.
/**
* 直接创建数据源,不做cache
*/
public DataSource createDataSource(DataMediaSource dataMediaSource) {
Assert.notNull(dataMediaSource);
DbMediaSource dbMediaSource = (DbMediaSource) dataMediaSource;
// 扩展功能,可以自定义一些自己实现的 dataSource
DataSource customDataSource = preCreate(0L, dbMediaSource);
if (customDataSource != null) {
return customDataSource;
}
return createDataSource(dbMediaSource.getUrl(), dbMediaSource.getUsername(), dbMediaSource.getPassword(), dbMediaSource.getDriver(), dbMediaSource.getType(), dbMediaSource.getEncode());
}
use of com.alibaba.otter.shared.common.model.config.data.db.DbMediaSource in project otter by alibaba.
the class DataSourceChecker method checkMap.
public String checkMap(String namespace, String name, Long dataSourceId) {
Connection conn = null;
Statement stmt = null;
DataMediaSource source = dataMediaSourceService.findById(dataSourceId);
DataSource dataSource = null;
try {
DbMediaSource dbMediaSource = (DbMediaSource) source;
dataSource = dataSourceCreator.createDataSource(dbMediaSource);
// conn = dataSource.getConnection();
// if (null == conn) {
// return DATABASE_FAIL;
// }
ModeValue namespaceValue = ConfigHelper.parseMode(namespace);
ModeValue nameValue = ConfigHelper.parseMode(name);
String tempNamespace = namespaceValue.getSingleValue();
String tempName = nameValue.getSingleValue();
try {
Table table = DdlUtils.findTable(new JdbcTemplate(dataSource), tempNamespace, tempNamespace, tempName);
if (table == null) {
return SELECT_FAIL;
}
} catch (SQLException se) {
logger.error("check error!", se);
return SELECT_FAIL;
} catch (Exception e) {
logger.error("check error!", e);
return SELECT_FAIL;
}
// String selectSql = "SELECT * from " + tempNamespace + "." +
// tempName + " where 1 = 0";
// String insertSql = "INSERT INTO " + tempNamespace + "." +
// tempName + " select * from ";
// insertSql += "( SELECT * from " + tempNamespace + "." + tempName
// + ") table2 where 1 = 0";
// String deleteSql = "DELETE from " + tempNamespace + "." +
// tempName + " where 1 = 0";
//
// stmt = conn.createStatement();
//
// try {
// stmt.executeQuery(selectSql);
// } catch (SQLException se) {
// return SELECT_FAIL;
// }
//
// try {
// stmt.execute(insertSql);
// } catch (SQLException se) {
// return INSERT_FAIL;
// }
//
// try {
// stmt.execute(deleteSql);
// } catch (SQLException se) {
// return DELETE_FAIL;
// }
} finally {
closeConnection(conn, stmt);
dataSourceCreator.destroyDataSource(dataSource);
}
return TABLE_SUCCESS;
}
use of com.alibaba.otter.shared.common.model.config.data.db.DbMediaSource in project otter by alibaba.
the class DataMediaSourceServiceImpl method doToModel.
/**
* 类型:数据库类型 Mysql和Oracle 用于DO对象转化为Model对象
*
* @param dataMediaSourceDo
* @return DataMediaSource
*/
private DataMediaSource doToModel(DataMediaSourceDO dataMediaSourceDo) {
DataMediaSource dataMediaSource = new DbMediaSource();
try {
if (dataMediaSourceDo.getType().isMysql() || dataMediaSourceDo.getType().isOracle()) {
dataMediaSource = JsonUtils.unmarshalFromString(dataMediaSourceDo.getProperties(), DbMediaSource.class);
} else if (dataMediaSourceDo.getType().isNapoli() || dataMediaSourceDo.getType().isMq()) {
dataMediaSource = JsonUtils.unmarshalFromString(dataMediaSourceDo.getProperties(), MqMediaSource.class);
}
dataMediaSource.setId(dataMediaSourceDo.getId());
dataMediaSource.setGmtCreate(dataMediaSourceDo.getGmtCreate());
dataMediaSource.setGmtModified(dataMediaSourceDo.getGmtModified());
} catch (Exception e) {
logger.error("ERROR ## change the dataMediaSource Do to Model has an exception");
throw new ManagerException(e);
}
return dataMediaSource;
}
Aggregations