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();
}
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();
}
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();
}
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();
}
}
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);
}
}
Aggregations