Search in sources :

Example 56 with ScriptRunner

use of org.apache.ibatis.jdbc.ScriptRunner in project mybatis-3 by mybatis.

the class NamedConstructorArgsTest method setUp.

@BeforeClass
public static void setUp() throws Exception {
    // create an SqlSessionFactory
    Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/named_constructor_args/mybatis-config.xml");
    sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);
    reader.close();
    Configuration configuration = sqlSessionFactory.getConfiguration();
    configuration.setUseActualParamName(false);
    configuration.addMapper(Mapper.class);
    // populate in-memory database
    SqlSession session = sqlSessionFactory.openSession();
    Connection conn = session.getConnection();
    reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/named_constructor_args/CreateDB.sql");
    ScriptRunner runner = new ScriptRunner(conn);
    runner.setLogWriter(null);
    runner.runScript(reader);
    reader.close();
    session.close();
}
Also used : Configuration(org.apache.ibatis.session.Configuration) SqlSession(org.apache.ibatis.session.SqlSession) Connection(java.sql.Connection) Reader(java.io.Reader) SqlSessionFactoryBuilder(org.apache.ibatis.session.SqlSessionFactoryBuilder) ScriptRunner(org.apache.ibatis.jdbc.ScriptRunner) BeforeClass(org.junit.BeforeClass)

Example 57 with ScriptRunner

use of org.apache.ibatis.jdbc.ScriptRunner in project mybatis-3 by mybatis.

the class PermissionsTest method setUp.

@BeforeClass
public static void setUp() throws Exception {
    // create a SqlSessionFactory
    Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/permissions/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/permissions/CreateDB.sql");
    ScriptRunner runner = new ScriptRunner(conn);
    runner.setLogWriter(null);
    runner.setErrorLogWriter(null);
    runner.runScript(reader);
    conn.commit();
    conn.close();
    reader.close();
}
Also used : SqlSession(org.apache.ibatis.session.SqlSession) Connection(java.sql.Connection) Reader(java.io.Reader) SqlSessionFactoryBuilder(org.apache.ibatis.session.SqlSessionFactoryBuilder) ScriptRunner(org.apache.ibatis.jdbc.ScriptRunner) BeforeClass(org.junit.BeforeClass)

Example 58 with ScriptRunner

use of org.apache.ibatis.jdbc.ScriptRunner in project mybatis-3 by mybatis.

the class OgnlStaticTest method setUp.

@BeforeClass
public static void setUp() throws Exception {
    // create a SqlSessionFactory
    Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/ognlstatic/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/ognlstatic/CreateDB.sql");
    ScriptRunner runner = new ScriptRunner(conn);
    runner.setLogWriter(null);
    runner.runScript(reader);
    reader.close();
    session.close();
}
Also used : SqlSession(org.apache.ibatis.session.SqlSession) Connection(java.sql.Connection) Reader(java.io.Reader) SqlSessionFactoryBuilder(org.apache.ibatis.session.SqlSessionFactoryBuilder) ScriptRunner(org.apache.ibatis.jdbc.ScriptRunner) BeforeClass(org.junit.BeforeClass)

Example 59 with ScriptRunner

use of org.apache.ibatis.jdbc.ScriptRunner in project mybatis-3 by mybatis.

the class BaseDataTest method runScript.

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();
    }
}
Also used : Connection(java.sql.Connection) ScriptRunner(org.apache.ibatis.jdbc.ScriptRunner)

Example 60 with ScriptRunner

use of org.apache.ibatis.jdbc.ScriptRunner in project sonarqube by SonarSource.

the class DdlUtils method executeScript.

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);
    }
}
Also used : ScriptRunner(org.apache.ibatis.jdbc.ScriptRunner)

Aggregations

ScriptRunner (org.apache.ibatis.jdbc.ScriptRunner)130 Reader (java.io.Reader)126 Connection (java.sql.Connection)114 SqlSessionFactoryBuilder (org.apache.ibatis.session.SqlSessionFactoryBuilder)109 BeforeClass (org.junit.BeforeClass)91 SqlSession (org.apache.ibatis.session.SqlSession)69 Before (org.junit.Before)17 PrintWriter (java.io.PrintWriter)8 SqlSessionFactory (org.apache.ibatis.session.SqlSessionFactory)4 Configuration (org.apache.ibatis.session.Configuration)2 StringReader (java.io.StringReader)1 Charset (java.nio.charset.Charset)1 Properties (java.util.Properties)1 NullWriter (org.apache.commons.io.output.NullWriter)1 UnpooledDataSource (org.apache.ibatis.datasource.unpooled.UnpooledDataSource)1 Environment (org.apache.ibatis.mapping.Environment)1 JdbcTransactionFactory (org.apache.ibatis.transaction.jdbc.JdbcTransactionFactory)1 Test (org.junit.Test)1