コード例 #1
1
ファイル: DdlUtils.java プロジェクト: SonarSource/sonarqube
 private static ScriptRunner newScriptRunner(Connection connection) {
   ScriptRunner scriptRunner = new ScriptRunner(connection);
   scriptRunner.setDelimiter(";");
   scriptRunner.setStopOnError(true);
   scriptRunner.setLogWriter(new PrintWriter(new NullWriter()));
   return scriptRunner;
 }
コード例 #2
1
ファイル: ForEachTest.java プロジェクト: kanishin/mybatis-3
  @BeforeClass
  public static void setUp() throws Exception {
    // create a SqlSessionFactory
    Reader reader =
        Resources.getResourceAsReader("org/apache/ibatis/submitted/foreach/mybatis-config.xml");
    sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);
    reader.close();

    // populate in-memory database
    SqlSession session = sqlSessionFactory.openSession();
    Connection conn = session.getConnection();
    reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/foreach/CreateDB.sql");
    ScriptRunner runner = new ScriptRunner(conn);
    runner.setLogWriter(null);
    runner.runScript(reader);
    reader.close();
    session.close();
  }
コード例 #3
0
ファイル: DdlUtils.java プロジェクト: SonarSource/sonarqube
  public static void executeScript(Connection connection, String path) {
    ScriptRunner scriptRunner = newScriptRunner(connection);
    try {
      scriptRunner.runScript(Resources.getResourceAsReader(path));
      connection.commit();

    } catch (Exception e) {
      throw new IllegalStateException("Fail to restore: " + path, e);
    }
  }
コード例 #4
0
 @BeforeClass
 public static void setup() throws Exception {
   SqlSession session = IbatisConfig.getSession();
   Connection conn = session.getConnection();
   ScriptRunner runner = new ScriptRunner(conn);
   runner.setLogWriter(null);
   runner.setErrorLogWriter(null);
   Reader reader =
       Resources.getResourceAsReader(
           "org/apache/ibatis/submitted/primitive_result_type/create.sql");
   runner.runScript(reader);
 }
コード例 #5
0
ファイル: BaseDataTest.java プロジェクト: jxcypress/mybatis
 public static void runScript(DataSource ds, String resource) throws IOException, SQLException {
   Connection connection = ds.getConnection();
   try {
     ScriptRunner runner = new ScriptRunner(connection);
     runner.setAutoCommit(true);
     runner.setStopOnError(false);
     runner.setLogWriter(null);
     runner.setErrorLogWriter(null);
     runScript(runner, resource);
   } finally {
     connection.close();
   }
 }
コード例 #6
0
  /** @throws java.lang.Exception */
  @Before
  public void setUpBefore() throws Exception {
    mockedRequest = Mockito.mock(HttpServletRequest.class);
    mockedResponse = Mockito.mock(HttpServletResponse.class);

    URL testfile = NewModelHandlerTest.class.getResource("/data/newmodelhandler/test1_svg.xml");
    File file = new File(testfile.toURI());
    svg = FileUtils.readFileToString(file, "UTF-8");

    testfile =
        NewModelHandlerTest.class.getResource("/data/newmodelhandler/test1_content_json.txt");
    file = new File(testfile.toURI());
    data = FileUtils.readFileToString(file, "UTF-8");

    // --
    // DataDefaults.all();
    Reader reader = Resources.getResourceAsReader("org/b3mn/poem/tests/myibitis-config.xml");
    sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);
    reader.close();

    SqlSession session = sqlSessionFactory.openSession();
    Connection conn = session.getConnection();
    reader = Resources.getResourceAsReader("org/b3mn/poem/tests/test_reset_mysql_db_schema.sql");
    ScriptRunner runner = new ScriptRunner(conn);
    runner.setErrorLogWriter(null);
    runner.runScript(reader);
    reader.close();

    reader = Resources.getResourceAsReader("org/b3mn/poem/tests/test_data.sql");
    runner = new ScriptRunner(conn);
    runner.setErrorLogWriter(null);
    runner.runScript(reader);
    reader.close();

    session.close();

    title = "Job #1";
    type = "http://b3mn.org/stencilset/reporting#";
    summary = "";
    newModelIdentity = null;
    user = new User("public");

    handler = new NewModelHandler();
    assertNotNull(handler);

    handler.init();
  }
コード例 #7
0
ファイル: BaseDataTest.java プロジェクト: jxcypress/mybatis
 public static void runScript(ScriptRunner runner, String resource)
     throws IOException, SQLException {
   Reader reader = Resources.getResourceAsReader(resource);
   try {
     runner.runScript(reader);
   } finally {
     reader.close();
   }
 }
コード例 #8
0
  @Before
  public void setUp() throws Exception {
    Class.forName("org.hsqldb.jdbcDriver");
    Connection conn = DriverManager.getConnection("jdbc:hsqldb:mem:attest", "sa", "");

    Reader reader =
        Resources.getResourceAsReader("org/apache/ibatis/submitted/awful_table/CreateDB.sql");

    ScriptRunner runner = new ScriptRunner(conn);
    runner.setLogWriter(null);
    runner.setErrorLogWriter(null);
    runner.runScript(reader);
    conn.commit();
    reader.close();

    reader =
        Resources.getResourceAsReader("org/apache/ibatis/submitted/awful_table/MapperConfig.xml");
    sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);
    reader.close();
  }
コード例 #9
0
  @Test(
      groups = {"tidb"},
      expectedExceptions = PersistenceException.class)
  public void shouldFailBecauseThereIsAPropertyWithoutTypeHandler() throws Exception {
    // create a SqlSessionFactory
    Reader reader =
        Resources.getResourceAsReader(
            "org/apache/ibatis/submitted/unknownobject/mybatis-config.xml");
    sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);
    reader.close();

    // populate in-memory database
    SqlSession session = sqlSessionFactory.openSession();
    Connection conn = session.getConnection();
    reader =
        Resources.getResourceAsReader("org/apache/ibatis/submitted/unknownobject/CreateDB.sql");
    ScriptRunner runner = new ScriptRunner(conn);
    runner.setLogWriter(null);
    runner.runScript(reader);
    reader.close();
    session.close();
  }
コード例 #10
0
 public static void initDatabase() {
   Connection connection = null;
   Reader reader = null;
   try {
     connection = MyBatisSqlSessionFactory.getConnection();
     ScriptRunner scriptRunner = new ScriptRunner(connection);
     reader = Resources.getResourceAsReader("sql/drop_tables.sql");
     scriptRunner.runScript(reader);
     logger.info("drop_tables.sql executed successfully");
     reader = Resources.getResourceAsReader("sql/create_tables.sql");
     scriptRunner.runScript(reader);
     logger.info("create_tables.sql executed successfully");
     reader = Resources.getResourceAsReader("sql/sample_data.sql");
     scriptRunner.runScript(reader);
     logger.info("sample_data.sql executed successfully");
     connection.commit();
     reader.close();
     scriptRunner.closeConnection();
   } catch (Exception e) {
     throw new RuntimeException(e);
   }
 }
コード例 #11
0
 private static void runReaderScript(Connection conn, SqlSession session, Reader reader)
     throws Exception {
   ScriptRunner runner = new ScriptRunner(conn);
   runner.setLogWriter(null);
   runner.setSendFullScript(true);
   runner.setAutoCommit(true);
   runner.setStopOnError(false);
   runner.runScript(reader);
 }