Search in sources :

Example 1 with DataSourceDriverVO

use of com.netsteadfast.greenstep.vo.DataSourceDriverVO in project bamboobsc by billchen198318.

the class DataSourceConfManagementAction method loadDataSourceConfData.

private void loadDataSourceConfData() throws ServiceException, Exception {
    this.transformFields2ValueObject(this.dataSourceConf, new String[] { "oid" });
    DefaultResult<DataSourceConfVO> result = this.dataSourceConfService.findObjectByOid(dataSourceConf);
    if (result.getValue() == null) {
        throw new ServiceException(result.getSystemMessage().getValue());
    }
    this.dataSourceConf = result.getValue();
    DataSourceDriverVO driver = new DataSourceDriverVO();
    driver.setId(dataSourceConf.getDriverId());
    DefaultResult<DataSourceDriverVO> dResult = this.dataSourceDriverService.findByUK(driver);
    if (dResult.getValue() != null) {
        this.getFields().put("driverOid", dResult.getValue().getOid());
    }
}
Also used : DataSourceConfVO(com.netsteadfast.greenstep.vo.DataSourceConfVO) ServiceException(com.netsteadfast.greenstep.base.exception.ServiceException) DataSourceDriverVO(com.netsteadfast.greenstep.vo.DataSourceDriverVO)

Example 2 with DataSourceDriverVO

use of com.netsteadfast.greenstep.vo.DataSourceDriverVO in project bamboobsc by billchen198318.

the class DataSourceLogicServiceImpl method updateConf.

@ServiceMethodAuthority(type = { ServiceMethodType.UPDATE })
@Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = { RuntimeException.class, IOException.class, Exception.class })
@Override
public DefaultResult<DataSourceConfVO> updateConf(String driverOid, DataSourceConfVO dataSourceConf) throws ServiceException, Exception {
    if (super.isBlank(driverOid) || null == dataSourceConf) {
        throw new ServiceException(SysMessageUtil.get(GreenStepSysMsgConstants.PARAMS_BLANK));
    }
    DefaultResult<DataSourceConfVO> oldResult = this.dataSourceConfService.findObjectByOid(dataSourceConf);
    if (oldResult.getValue() == null) {
        throw new ServiceException(oldResult.getSystemMessage().getValue());
    }
    // ID 是 UK, 不允許變動
    dataSourceConf.setId(oldResult.getValue().getId());
    DataSourceDriverVO driver = new DataSourceDriverVO();
    driver.setOid(driverOid);
    DefaultResult<DataSourceDriverVO> dResult = this.dataSourceDriverService.findObjectByOid(driver);
    if (dResult.getValue() == null) {
        throw new ServiceException(dResult.getSystemMessage().getValue());
    }
    driver = dResult.getValue();
    dataSourceConf.setDriverId(driver.getId());
    if (super.defaultString(dataSourceConf.getJdbcUrl()).length() > MAX_JDBC_URL_LENGTH) {
        throw new ServiceException("jdbc-url Only allows " + String.valueOf(MAX_JDBC_URL_LENGTH) + " characters!");
    }
    if (null == dataSourceConf.getDescription()) {
        dataSourceConf.setDescription("");
    }
    this.setStringValueMaxLength(dataSourceConf, "description", MAX_DESCRIPTION_LENGTH);
    return dataSourceConfService.updateObject(dataSourceConf);
}
Also used : DataSourceConfVO(com.netsteadfast.greenstep.vo.DataSourceConfVO) ServiceException(com.netsteadfast.greenstep.base.exception.ServiceException) DataSourceDriverVO(com.netsteadfast.greenstep.vo.DataSourceDriverVO) ServiceMethodAuthority(com.netsteadfast.greenstep.base.model.ServiceMethodAuthority) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with DataSourceDriverVO

use of com.netsteadfast.greenstep.vo.DataSourceDriverVO in project bamboobsc by billchen198318.

the class DataSourceLogicServiceImpl method createConf.

@ServiceMethodAuthority(type = { ServiceMethodType.INSERT })
@Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = { RuntimeException.class, IOException.class, Exception.class })
@Override
public DefaultResult<DataSourceConfVO> createConf(String driverOid, DataSourceConfVO dataSourceConf) throws ServiceException, Exception {
    if (super.isBlank(driverOid) || null == dataSourceConf) {
        throw new ServiceException(SysMessageUtil.get(GreenStepSysMsgConstants.PARAMS_BLANK));
    }
    DataSourceDriverVO driver = new DataSourceDriverVO();
    driver.setOid(driverOid);
    DefaultResult<DataSourceDriverVO> dResult = this.dataSourceDriverService.findObjectByOid(driver);
    if (dResult.getValue() == null) {
        throw new ServiceException(dResult.getSystemMessage().getValue());
    }
    driver = dResult.getValue();
    dataSourceConf.setDriverId(driver.getId());
    if (super.defaultString(dataSourceConf.getJdbcUrl()).length() > MAX_JDBC_URL_LENGTH) {
        throw new ServiceException("jdbc-url Only allows " + String.valueOf(MAX_JDBC_URL_LENGTH) + " characters!");
    }
    if (null == dataSourceConf.getDescription()) {
        dataSourceConf.setDescription("");
    }
    this.setStringValueMaxLength(dataSourceConf, "description", MAX_DESCRIPTION_LENGTH);
    return this.dataSourceConfService.saveObject(dataSourceConf);
}
Also used : ServiceException(com.netsteadfast.greenstep.base.exception.ServiceException) DataSourceDriverVO(com.netsteadfast.greenstep.vo.DataSourceDriverVO) ServiceMethodAuthority(com.netsteadfast.greenstep.base.model.ServiceMethodAuthority) Transactional(org.springframework.transaction.annotation.Transactional)

Example 4 with DataSourceDriverVO

use of com.netsteadfast.greenstep.vo.DataSourceDriverVO in project bamboobsc by billchen198318.

the class ManualJdbcTemplateFactory method getManualJdbcTemplate.

public static NamedParameterJdbcTemplate getManualJdbcTemplate(String confOid) throws ServiceException, Exception {
    if (jdbcTemplateTreadLocal.get() != null && jdbcTemplateTreadLocal.get().getDataSourceConf().getOid().equals(confOid)) {
        return jdbcTemplateTreadLocal.get().getJdbcTemplate();
    }
    DataSourceConfVO conf = new DataSourceConfVO();
    conf.setOid(confOid);
    DefaultResult<DataSourceConfVO> confResult = dataSourceConfService.findObjectByOid(conf);
    if (confResult.getValue() == null) {
        throw new ServiceException(confResult.getSystemMessage().getValue());
    }
    conf = confResult.getValue();
    DataSourceDriverVO driver = new DataSourceDriverVO();
    driver.setId(conf.getDriverId());
    DefaultResult<DataSourceDriverVO> driverResult = dataSourceDriverService.findByUK(driver);
    if (driverResult.getValue() == null) {
        throw new ServiceException(driverResult.getSystemMessage().getValue());
    }
    driver = driverResult.getValue();
    NamedParameterJdbcTemplate jdbcTemplate = DataUtils.getManualJdbcTemplate(Class.forName(driver.getClassName()), conf.getJdbcUrl(), conf.getDbAccount(), conf.getDbPassword());
    DataProperty dataProperty = new DataProperty();
    dataProperty.setDataSourceConf(conf);
    dataProperty.setJdbcTemplate(jdbcTemplate);
    jdbcTemplateTreadLocal.set(dataProperty);
    return jdbcTemplate;
}
Also used : DataSourceConfVO(com.netsteadfast.greenstep.vo.DataSourceConfVO) ServiceException(com.netsteadfast.greenstep.base.exception.ServiceException) NamedParameterJdbcTemplate(org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate) DataSourceDriverVO(com.netsteadfast.greenstep.vo.DataSourceDriverVO)

Aggregations

ServiceException (com.netsteadfast.greenstep.base.exception.ServiceException)4 DataSourceDriverVO (com.netsteadfast.greenstep.vo.DataSourceDriverVO)4 DataSourceConfVO (com.netsteadfast.greenstep.vo.DataSourceConfVO)3 ServiceMethodAuthority (com.netsteadfast.greenstep.base.model.ServiceMethodAuthority)2 Transactional (org.springframework.transaction.annotation.Transactional)2 NamedParameterJdbcTemplate (org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate)1