예제 #1
0
파일: ORowSet.java 프로젝트: vancuvit/core
  /**
   * Initializes some class fields. Then creates DataSource, which serves as a single source for all
   * tables created in the test. This DataSource then registered in the global <code>DatabaseContext
   * </code> service. This data source's URL points to SOffice temp directory where tables are
   * copied from <code>TestDocuments</code> directory on every environment creation. To create
   * DataSource for MySQL database next parameters required in ini-file:
   *
   * <ul>
   *   <li><code>test.db.url</code> - URL to MySQL database. For example: <code>
   *       mysql://mercury:3306/api_current</code>
   *   <li><code>test.db.user</code> - user for MySQL database
   *   <li><code>test.db.password</code> - password for MySQL database
   * </ul>
   *
   * @throws StatusException if DataSource can not be created or registered.
   */
  protected void initialize(TestParameters Param, PrintWriter _log) throws StatusException {
    m_orb = (XMultiServiceFactory) Param.getMSF();

    String tmpDir = utils.getOfficeTemp(m_orb);

    origDB = util.utils.getFullTestDocName("TestDB/testDB.dbf");

    dbTools = new DBTools(m_orb, _log);

    // creating DataSource and registering it in DatabaseContext
    String dbURL = (String) Param.get("test.db.url");
    String dbUser = (String) Param.get("test.db.user");
    String dbPassword = (String) Param.get("test.db.password");

    log.println("Creating and registering DataSource ...");
    srcInf = new DataSourceDescriptor(m_orb);
    if (dbURL != null && dbUser != null && dbPassword != null) {
      isMySQLDB = true;
      log.println("dbURL = " + dbURL);
      log.println("dbUSER = "******"dbPASSWORD = "******"soffice_test_table";
      srcInf.URL = "jdbc:" + dbURL;
      srcInf.IsPasswordRequired = new Boolean(true);
      srcInf.Password = dbPassword;
      srcInf.User = dbUser;
      PropertyValue[] propInfo = new PropertyValue[1];
      propInfo[0] = new PropertyValue();
      propInfo[0].Name = "JavaDriverClass";
      propInfo[0].Value = "org.gjt.mm.mysql.Driver";
      srcInf.Info = propInfo;
    } else {
      srcInf.URL = "sdbc:dbase:" + DBTools.dirToUrl(tmpDir);
    }
    m_dataSource = srcInf.createDataSource();
    m_dataSource.registerAs(dbSourceName, true);
  }