Search in sources :

Example 6 with DbMediaSource

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;
}
Also used : DbMediaSource(com.alibaba.otter.shared.common.model.config.data.db.DbMediaSource) DbDataMedia(com.alibaba.otter.shared.common.model.config.data.db.DbDataMedia)

Example 7 with DbMediaSource

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();
}
Also used : DbMediaSource(com.alibaba.otter.shared.common.model.config.data.db.DbMediaSource) Date(java.util.Date) Test(org.testng.annotations.Test)

Example 8 with DbMediaSource

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());
}
Also used : DbMediaSource(com.alibaba.otter.shared.common.model.config.data.db.DbMediaSource) BasicDataSource(org.apache.commons.dbcp.BasicDataSource) DataSource(javax.sql.DataSource)

Example 9 with DbMediaSource

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;
}
Also used : Table(org.apache.ddlutils.model.Table) ModeValue(com.alibaba.otter.shared.common.model.config.data.DataMedia.ModeValue) SQLException(java.sql.SQLException) Statement(java.sql.Statement) Connection(java.sql.Connection) DataMediaSource(com.alibaba.otter.shared.common.model.config.data.DataMediaSource) DbMediaSource(com.alibaba.otter.shared.common.model.config.data.db.DbMediaSource) JdbcTemplate(org.springframework.jdbc.core.JdbcTemplate) SQLException(java.sql.SQLException) DataSource(javax.sql.DataSource)

Example 10 with DbMediaSource

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;
}
Also used : DataMediaSource(com.alibaba.otter.shared.common.model.config.data.DataMediaSource) DbMediaSource(com.alibaba.otter.shared.common.model.config.data.db.DbMediaSource) ManagerException(com.alibaba.otter.manager.biz.common.exceptions.ManagerException) ManagerException(com.alibaba.otter.manager.biz.common.exceptions.ManagerException) RepeatConfigureException(com.alibaba.otter.manager.biz.common.exceptions.RepeatConfigureException)

Aggregations

DbMediaSource (com.alibaba.otter.shared.common.model.config.data.db.DbMediaSource)19 SQLException (java.sql.SQLException)6 DataSource (javax.sql.DataSource)6 JdbcTemplate (org.springframework.jdbc.core.JdbcTemplate)6 DbDialect (com.alibaba.otter.node.etl.common.db.dialect.DbDialect)5 DataMediaSource (com.alibaba.otter.shared.common.model.config.data.DataMediaSource)5 Table (org.apache.ddlutils.model.Table)5 Test (org.testng.annotations.Test)5 RepeatConfigureException (com.alibaba.otter.manager.biz.common.exceptions.RepeatConfigureException)4 BaseDbTest (com.alibaba.otter.node.etl.BaseDbTest)4 PreparedStatement (java.sql.PreparedStatement)4 TransactionStatus (org.springframework.transaction.TransactionStatus)4 TransactionCallback (org.springframework.transaction.support.TransactionCallback)4 TransactionTemplate (org.springframework.transaction.support.TransactionTemplate)4 SqlTemplate (com.alibaba.otter.node.etl.common.db.dialect.SqlTemplate)3 DbDataMedia (com.alibaba.otter.shared.common.model.config.data.db.DbDataMedia)3 MqMediaSource (com.alibaba.otter.shared.common.model.config.data.mq.MqMediaSource)3 PreparedStatementCallback (org.springframework.jdbc.core.PreparedStatementCallback)3 ManagerException (com.alibaba.otter.manager.biz.common.exceptions.ManagerException)2 ModeValue (com.alibaba.otter.shared.common.model.config.data.DataMedia.ModeValue)2