⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 loadertestcase.java

📁 数据仓库工具
💻 JAVA
字号:
/*
  Loader - tool for transfering data from one JDBC source to another and
  doing transformations during copy.
    Copyright (C) 2002  Together
    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 2.1 of the License, or (at your option) any later version.
    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Lesser General Public License for more details.
    You should have received a copy of the GNU Lesser General Public
    License along with this library; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 /*
  * DatabaseTestCase.java   Aug 29, 2002
  *	Sinisa Milosevic  sinisami@eunet.yu
  *
  */

package org.webdocwf.util.loader.test;

import java.sql.Connection;
import org.webdocwf.util.loader.test.DatabaseOperation;
import org.webdocwf.util.loader.test.LoaderOperation;
import org.webdocwf.util.loader.Loader;

import junit.framework.TestCase;

/**
 * Basic class for using Loader as a test case (extends Junit Test class)
 *
 * @author Sinisa Milosevic
 * @version $Revision: 1.2 $
 */
public abstract class LoaderTestCase
    extends TestCase {

  public LoaderTestCase(String name) {
    super(name);
  }

  /**
   * Returns the test database connection.
   */
  protected abstract Connection getConnection() throws Exception;

  /**
   * Returns the name of test database.
   */

  protected String getDatabaseName() throws Exception {
    return "LoaderTest";
  }

  /**
   * Returns the test Loader class (loaderjob).
   */
  protected abstract Loader getLoader() throws Exception;

  /**
   * Close the specified connection. Override this method of you want to
   * keep your connection alive between tests.
   */
  protected void closeConnection(Connection connection) throws Exception {
    connection.close();
  }

  /**
   * Returns the database operations executed in test setup. First operation will be
   * executed dbOperation[0], then dbOperation[1]...
   * Override this method of you want to change database operations before the start test.
   */
  protected DatabaseOperation[] getSetUpOperation() throws Exception {
    DatabaseOperation[] dbOperation = new DatabaseOperation[2];
    dbOperation[0] = new CreateDatabaseOperation(getDatabaseName());
    dbOperation[1] = new LoaderOperation(getLoader());

    return dbOperation;
  }

  /**
   * Returns the database operation executed in test cleanup.
   *  First operation will be executed dbOperation[0], then dbOperation[1]...
   * Override this method of you want to change database operations after the test execution.
   */
  protected DatabaseOperation[] getTearDownOperation() throws Exception {
    DatabaseOperation[] dbOperation = new DatabaseOperation[1];
    dbOperation[0] = new DropDatabaseOperation(getDatabaseName());

    return dbOperation;
  }

  private void executeOperation(DatabaseOperation dbOperation) throws Exception {
    if (dbOperation != null) {
      if (!dbOperation.getDatabaseOperationType().equals(DatabaseOperation.NONE)) {
        if (!dbOperation.getDatabaseOperationType().equals(DatabaseOperation.LOADER)) {
        Connection conn = getConnection();
          try {
            if (conn != null)
              dbOperation.execute(conn);
          }
          finally {
            if (conn != null)
              closeConnection(conn);
          }
        } else
          ( (LoaderOperation)dbOperation).execute();
      }
    }
  }

  protected void setUp() throws Exception {
    super.setUp();

    for (int i = 0; i < getSetUpOperation().length; i++)
      executeOperation(getSetUpOperation()[i]);
  }

  protected void tearDown() throws Exception {
    super.tearDown();

    for (int i = 0; i < getTearDownOperation().length; i++)
      executeOperation(getTearDownOperation()[i]);
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -