Package com.taobao.datasource

Examples of com.taobao.datasource.LocalTxDataSourceDO


        }
        System.out.println();
    }

    public void test_jobss() throws Exception {
        LocalTxDataSourceDO dataSourceDO = new LocalTxDataSourceDO();
        dataSourceDO.setBlockingTimeoutMillis(1000 * 60);
        dataSourceDO.setMaxPoolSize(maxPoolSize);
        dataSourceDO.setMinPoolSize(minPoolSize);

        dataSourceDO.setDriverClass(driverClass);
        dataSourceDO.setConnectionURL(jdbcUrl);
        dataSourceDO.setUserName(user);
        dataSourceDO.setPassword(password);

        LocalTxDataSource tx = TaobaoDataSourceFactory.createLocalTxDataSource(dataSourceDO);
        DataSource dataSource = tx.getDatasource();

        for (int i = 0; i < loopCount; ++i) {
View Full Code Here


        }
        System.out.println();
    }

    public void test_jobss() throws Exception {
        LocalTxDataSourceDO dataSourceDO = new LocalTxDataSourceDO();
        dataSourceDO.setBlockingTimeoutMillis(1000 * 60);
        dataSourceDO.setMaxPoolSize(maxPoolSize);
        dataSourceDO.setMinPoolSize(minPoolSize);

        dataSourceDO.setDriverClass(driverClass);
        dataSourceDO.setConnectionURL(jdbcUrl);
        dataSourceDO.setUserName(user);
        dataSourceDO.setPassword(password);

        LocalTxDataSource tx = TaobaoDataSourceFactory.createLocalTxDataSource(dataSourceDO);
        DataSource dataSource = tx.getDatasource();

        for (int i = 0; i < loopCount; ++i) {
View Full Code Here

  public void init() throws Exception {
    if (init) {
      throw new AtomAlreadyInitException("[AlreadyInit] double call Init !");
    }
    LocalTxDataSourceDO localTxDataSourceDO = TAtomDsConfHandle.convertTAtomDsConf2JbossConf(confDO, confDO
        .getDbName());
    boolean checkPram = TAtomDsConfHandle.checkLocalTxDataSourceDO(localTxDataSourceDO);
    if (checkPram) {
      jbossDataSource = TaobaoDataSourceFactory.createLocalTxDataSource(localTxDataSourceDO);
      init = true;
View Full Code Here

          throw new AtomInitialException(errorMsg);
        }
        runTimeConf.setPasswd(passwd);
      }
      // 8.ת��tAtomDsConfDO
      LocalTxDataSourceDO localTxDataSourceDO = convertTAtomDsConf2JbossConf(
          this.runTimeConf,
          TAtomConstants.getDbNameStr(this.appName, this.dbKey));
      // 9.������������������ȷֱ���׳��쳣
      if (!checkLocalTxDataSourceDO(localTxDataSourceDO)) {
        String errorMsg = "[ConfigError]init dataSource Prams Error! config is : "
            + localTxDataSourceDO.toString();
        logger.error(errorMsg);
        throw new AtomInitialException(errorMsg);
      }
      // 10.��������Դ
      // �ر�TB-DATASOURCE��JMXע��
      localTxDataSourceDO.setUseJmx(false);
      LocalTxDataSource localTxDataSource = TaobaoDataSourceFactory
          .createLocalTxDataSource(localTxDataSourceDO);
      // 11.�������õ�����Դ��ָ��TAtomDatasource��
      this.jbossDataSource = localTxDataSource;
      clearDataSourceWrapper();
View Full Code Here

                  "[NA STATUS PUSH] destroy DataSource  Error!",
                  e);
            }
          } else {
            // ת��tAtomDsConfDO
            LocalTxDataSourceDO localTxDataSourceDO = convertTAtomDsConf2JbossConf(
                newConf, TAtomConstants.getDbNameStr(
                    TAtomDsConfHandle.this.appName,
                    TAtomDsConfHandle.this.dbKey));
            // ���ת�������Ƿ���ȷ
            if (!checkLocalTxDataSourceDO(localTxDataSourceDO)) {
              logger.error("[GlobaConfError] dataSource Prams Error! dataId : "
                  + dataId + " config : " + data);
              return;
            }
            // ������͵�״̬ʱ NA->RW/R ʱ��Ҫ���´�������Դ��������ˢ��
            if (TAtomDsConfHandle.this.runTimeConf
                .getDbStautsEnum() == AtomDbStatusEnum.NA_STATUS
                && (newConf.getDbStautsEnum() == AtomDbStatusEnum.RW_STATUS || newConf
                    .getDbStautsEnum() == AtomDbStatusEnum.R_STAUTS)) {
              // ��������Դ
              try {
                // �ر�TB-DATASOURCE��JMXע��
                localTxDataSourceDO.setUseJmx(false);
                LocalTxDataSource localTxDataSource = TaobaoDataSourceFactory
                    .createLocalTxDataSource(localTxDataSourceDO);
                TAtomDsConfHandle.this.jbossDataSource = localTxDataSource;
                logger.warn("[NA->RW/R STATUS PUSH] ReCreate DataSource !");
              } catch (Exception e) {
                logger.error(
                    "[NA->RW/R STATUS PUSH] ReCreate DataSource Error!",
                    e);
              }
            } else {
              boolean needFlush = checkGlobaConfChange(
                  TAtomDsConfHandle.this.runTimeConf, newConf);
              // ������������ñ仯�Ƿ���Ҫ�ؽ�����Դ
              if (needFlush) {
                TAtomDsConfHandle.this.jbossDataSource
                    .setConnectionURL(localTxDataSourceDO
                        .getConnectionURL());
                TAtomDsConfHandle.this.jbossDataSource
                    .setDriverClass(localTxDataSourceDO
                        .getDriverClass());
                TAtomDsConfHandle.this.jbossDataSource
                    .setExceptionSorterClassName(localTxDataSourceDO
                        .getExceptionSorterClassName());
                try {
                  // ��������Դ
                  TAtomDsConfHandle.this.flushDataSource();
                } catch (Exception e) {
View Full Code Here

              .getThreadCountRestrict());
          newConf.setTimeSliceInMillis(tmpConf.getTimeSliceInMillis());
          // ��������������
          overConfByLocal(TAtomDsConfHandle.this.localConf, newConf);
          // ת��tAtomDsConfDO
          LocalTxDataSourceDO localTxDataSourceDO = convertTAtomDsConf2JbossConf(
              newConf, TAtomConstants.getDbNameStr(
                  TAtomDsConfHandle.this.appName,
                  TAtomDsConfHandle.this.dbKey));
          // ���ת�������Ƿ���ȷ
          if (!checkLocalTxDataSourceDO(localTxDataSourceDO)) {
            logger.error("[GlobaConfError] dataSource Prams Error! dataId : "
                + dataId + " config : " + data);
            return;
          }
          boolean isNeedReCreate = isNeedReCreate(
              TAtomDsConfHandle.this.runTimeConf, newConf);
          if (isNeedReCreate) {
            try {
              TAtomDsConfHandle.this.jbossDataSource.destroy();
              logger.warn("[destroy OldDataSource] dataId : "
                  + dataId);
              LocalTxDataSource localTxDataSource = TaobaoDataSourceFactory
                  .createLocalTxDataSource(localTxDataSourceDO);
              logger.warn("[create newDataSource] dataId : "
                  + dataId);
              TAtomDsConfHandle.this.jbossDataSource = localTxDataSource;
              clearDataSourceWrapper();
              TAtomDsConfHandle.this.runTimeConf = newConf;
            } catch (Exception e) {
              logger.error(
                  "[Flsh AppConf Error] reCreate dataSource Error ! dataId: "
                      + dataId, e);
            }
          } else {
            boolean isNeedFlush = isNeedFlush(
                TAtomDsConfHandle.this.runTimeConf, newConf);
            /**
             * ��ֵ�仯����ˢ�³��е�����Դ��ֻҪ����runTimeConf���������wrapDataSource
             */
            boolean isRestrictChange = isRestrictChange(
                TAtomDsConfHandle.this.runTimeConf, newConf);
            if (isNeedFlush) {
              TAtomDsConfHandle.this.jbossDataSource
                  .setConnectionURL(localTxDataSourceDO
                      .getConnectionURL());
              TAtomDsConfHandle.this.jbossDataSource
                  .setUserName(localTxDataSourceDO
                      .getUserName());
              try {
                // ��������Դ
                TAtomDsConfHandle.this.flushDataSource();
                // �����µ����ø�������ʱ������
View Full Code Here

   * @param tAtomDsConfDO
   * @return
   */
  @SuppressWarnings("rawtypes")
  protected static LocalTxDataSourceDO convertTAtomDsConf2JbossConf(TAtomDsConfDO tAtomDsConfDO, String dbName) {
    LocalTxDataSourceDO localTxDataSourceDO = new LocalTxDataSourceDO();
    if (TStringUtil.isNotBlank(dbName)) {
      localTxDataSourceDO.setJndiName(dbName);
    }
    localTxDataSourceDO.setUserName(tAtomDsConfDO.getUserName());
    localTxDataSourceDO.setPassword(tAtomDsConfDO.getPasswd());
    localTxDataSourceDO.setDriverClass(tAtomDsConfDO.getDriverClass());
    localTxDataSourceDO.setExceptionSorterClassName(tAtomDsConfDO.getSorterClass());
    //�������ݿ���������conURL��setConnectionProperties
    if (AtomDbTypeEnum.ORACLE == tAtomDsConfDO.getDbTypeEnum()) {
      String conUlr = TAtomConURLTools.getOracleConURL(tAtomDsConfDO.getIp(), tAtomDsConfDO.getPort(),
          tAtomDsConfDO.getDbName(), tAtomDsConfDO.getOracleConType());
      localTxDataSourceDO.setConnectionURL(conUlr);
      //�����oracleû������ConnectionProperties����Ը�Ĭ�ϵ�
      if (!tAtomDsConfDO.getConnectionProperties().isEmpty()) {
        localTxDataSourceDO.setConnectionProperties(tAtomDsConfDO.getConnectionProperties());
      } else {
        localTxDataSourceDO.setConnectionProperties(TAtomConstants.DEFAULT_ORACLE_CONNECTION_PROPERTIES);
      }
    } else if (AtomDbTypeEnum.MYSQL == tAtomDsConfDO.getDbTypeEnum()) {
      String conUlr = TAtomConURLTools.getMySqlConURL(tAtomDsConfDO.getIp(), tAtomDsConfDO.getPort(),
          tAtomDsConfDO.getDbName(), tAtomDsConfDO.getConnectionProperties());
      localTxDataSourceDO.setConnectionURL(conUlr);
      //��������ҵ�mysqlDriver�е�Valid��ʹ�ã���������valid
      try {
        Class validClass = Class.forName(TAtomConstants.DEFAULT_MYSQL_VALID_CONNECTION_CHECKERCLASS);
        if (null != validClass) {
          localTxDataSourceDO
              .setValidConnectionCheckerClassName(TAtomConstants.DEFAULT_MYSQL_VALID_CONNECTION_CHECKERCLASS);
        } else {
          logger.warn("MYSQL Driver is Not Suport "
              + TAtomConstants.DEFAULT_MYSQL_VALID_CONNECTION_CHECKERCLASS);
        }
      } catch (ClassNotFoundException e) {
        logger.warn("MYSQL Driver is Not Suport " + TAtomConstants.DEFAULT_MYSQL_VALID_CONNECTION_CHECKERCLASS);
      } catch (NoClassDefFoundError e) {
        logger.warn("MYSQL Driver is Not Suport " + TAtomConstants.DEFAULT_MYSQL_VALID_CONNECTION_CHECKERCLASS);
      }
     
      //��������ҵ�mysqlDriver�е�integrationSorter��ʹ�÷���ʹ��Ĭ�ϵ�
      try {
        Class integrationSorterCalss = Class.forName(TAtomConstants.MYSQL_INTEGRATION_SORTER_CLASS);
        if (null != integrationSorterCalss) {
          localTxDataSourceDO.setExceptionSorterClassName(TAtomConstants.MYSQL_INTEGRATION_SORTER_CLASS);
        } else {
          localTxDataSourceDO.setExceptionSorterClassName(TAtomConstants.DEFAULT_MYSQL_SORTER_CLASS);
          logger.warn("MYSQL Driver is Not Suport " + TAtomConstants.MYSQL_INTEGRATION_SORTER_CLASS
              + " use default sorter " + TAtomConstants.DEFAULT_MYSQL_SORTER_CLASS);
        }
      } catch (ClassNotFoundException e) {
        logger.warn("MYSQL Driver is Not Suport " + TAtomConstants.MYSQL_INTEGRATION_SORTER_CLASS
            + " use default sorter " + TAtomConstants.DEFAULT_MYSQL_SORTER_CLASS);
      } catch (NoClassDefFoundError e){
        logger.warn("MYSQL Driver is Not Suport " + TAtomConstants.MYSQL_INTEGRATION_SORTER_CLASS
            + " use default sorter " + TAtomConstants.DEFAULT_MYSQL_SORTER_CLASS);
      }
    }
    localTxDataSourceDO.setMinPoolSize(tAtomDsConfDO.getMinPoolSize());
    localTxDataSourceDO.setMaxPoolSize(tAtomDsConfDO.getMaxPoolSize());
    localTxDataSourceDO.setPreparedStatementCacheSize(tAtomDsConfDO.getPreparedStatementCacheSize());
    if (tAtomDsConfDO.getIdleTimeout() > 0) {
      localTxDataSourceDO.setIdleTimeoutMinutes(tAtomDsConfDO.getIdleTimeout());
    }
    if (tAtomDsConfDO.getBlockingTimeout() > 0) {
      localTxDataSourceDO.setBlockingTimeoutMillis(tAtomDsConfDO.getBlockingTimeout());
    }
    return localTxDataSourceDO;
  }
View Full Code Here

    this.alive = alive;
  }

  public DataSourceConfig clone() {
    DataSourceConfig  dsConfig=new DataSourceConfig();
    LocalTxDataSourceDO config=null;
    if(null!=this.getDsConfig()){
      config = this.getDsConfig().clone();
      dsConfig.setDsConfig(config);
    }
    dsConfig.setAlive(this.alive);
View Full Code Here

TOP

Related Classes of com.taobao.datasource.LocalTxDataSourceDO

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.