Exemplo n.º 1
1
 private static ScriptRunner newScriptRunner(Connection connection) {
   ScriptRunner scriptRunner = new ScriptRunner(connection);
   scriptRunner.setDelimiter(";");
   scriptRunner.setStopOnError(true);
   scriptRunner.setLogWriter(new PrintWriter(new NullWriter()));
   return scriptRunner;
 }
Exemplo n.º 2
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();
  }
 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);
 }
 @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);
 }
Exemplo n.º 5
0
 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();
   }
 }
  @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.º 7
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();
  }