Exemplo n.º 1
1
  @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();
  }
Exemplo n.º 2
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();
  }
Exemplo n.º 3
0
 public static void runScript(ScriptRunner runner, String resource)
     throws IOException, SQLException {
   Reader reader = Resources.getResourceAsReader(resource);
   try {
     runner.runScript(reader);
   } finally {
     reader.close();
   }
 }
 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);
 }
Exemplo n.º 5
0
  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);
    }
  }
 @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);
 }
 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);
   }
 }
  @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();
  }
Exemplo n.º 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();
  }