本文整理汇总了Java中org.apache.ibatis.jdbc.ScriptRunner类的典型用法代码示例。如果您正苦于以下问题:Java ScriptRunner类的具体用法?Java ScriptRunner怎么用?Java ScriptRunner使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ScriptRunner类属于org.apache.ibatis.jdbc包,在下文中一共展示了ScriptRunner类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: clearDb
import org.apache.ibatis.jdbc.ScriptRunner; //导入依赖的package包/类
/**
* Clears the db.
*
* @param dropTables
* if true drop tables, else clean tables
* @throws SQLException
*/
public void clearDb(DataSource dataSource, boolean dropTables) throws SQLException {
try (Connection connection = dataSource.getConnection()) {
ScriptRunner runner = new ScriptRunner(connection);
LOGGER.debug(connection.getMetaData().toString());
runner.setStopOnError(false);
runner.setLogWriter(logWriter);
runner.setErrorLogWriter(errorLogWriter);
if (dropTables) {
runner.runScript(new InputStreamReader(this.getClass().getResourceAsStream(DB_DROP_TABLES_SCRIPT)));
} else {
runner.runScript(new InputStreamReader(this.getClass().getResourceAsStream(DB_CLEAR_SCRIPT)));
}
} catch (Exception e) {
LOGGER.error("caught Exception " + e);
}
LOGGER.debug(outWriter.toString());
String errorMsg = errorWriter.toString().trim();
if (!errorMsg.isEmpty() && errorMsg.indexOf("SQLCODE=-204, SQLSTATE=42704") == -1) {
LOGGER.error(errorWriter.toString());
}
}
示例2: run
import org.apache.ibatis.jdbc.ScriptRunner; //导入依赖的package包/类
/**
* Run all db scripts.
* @throws SQLException TODO
*/
public void run() throws SQLException {
Connection connection = dataSource.getConnection();
ScriptRunner runner = new ScriptRunner(connection);
LOGGER.debug(connection.getMetaData().toString());
runner.setStopOnError(true);
runner.setLogWriter(logWriter);
runner.setErrorLogWriter(errorLogWriter);
if (!isSchemaPreexisting(runner)) {
runner.runScript(new InputStreamReader(this.getClass().getResourceAsStream(DB_SCHEMA)));
}
runner.closeConnection();
LOGGER.debug(outWriter.toString());
if (!errorWriter.toString().trim().isEmpty()) {
LOGGER.error(errorWriter.toString());
}
}
示例3: setupClass
import org.apache.ibatis.jdbc.ScriptRunner; //导入依赖的package包/类
@BeforeClass
public static void setupClass() throws Exception {
Connection conn = null;
try {
Class.forName("org.hsqldb.jdbcDriver");
conn = DriverManager.getConnection("jdbc:hsqldb:mem:immutable_constructor", "sa", "");
Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/immutable_constructor/CreateDB.sql");
ScriptRunner runner = new ScriptRunner(conn);
runner.setLogWriter(null);
runner.setErrorLogWriter(new PrintWriter(System.err));
runner.runScript(reader);
conn.commit();
reader.close();
reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/immutable_constructor/ibatisConfig.xml");
factory = new SqlSessionFactoryBuilder().build(reader);
reader.close();
} finally {
if (conn != null) {
conn.close();
}
}
}
示例4: setUp
import org.apache.ibatis.jdbc.ScriptRunner; //导入依赖的package包/类
@BeforeClass
public static void setUp() throws Exception {
// create an SqlSessionFactory
Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/collectionparameters/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/collectionparameters/CreateDB.sql");
ScriptRunner runner = new ScriptRunner(conn);
runner.setLogWriter(null);
runner.runScript(reader);
reader.close();
session.close();
}
示例5: setUp
import org.apache.ibatis.jdbc.ScriptRunner; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
// create a SqlSessionFactory
Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/typehandler/mybatis-config.xml");
sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);
reader.close();
sqlSessionFactory.getConfiguration().getTypeHandlerRegistry().register(StringTrimmingTypeHandler.class);
// populate in-memory database
SqlSession session = sqlSessionFactory.openSession();
Connection conn = session.getConnection();
reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/typehandler/CreateDB.sql");
ScriptRunner runner = new ScriptRunner(conn);
runner.setLogWriter(null);
runner.runScript(reader);
reader.close();
session.close();
}
示例6: setUp
import org.apache.ibatis.jdbc.ScriptRunner; //导入依赖的package包/类
@BeforeClass
public static void setUp() throws Exception {
// create an SqlSessionFactory
Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/raw_sql_source/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/raw_sql_source/CreateDB.sql");
ScriptRunner runner = new ScriptRunner(conn);
runner.setLogWriter(null);
runner.runScript(reader);
reader.close();
session.close();
}
示例7: setUp
import org.apache.ibatis.jdbc.ScriptRunner; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
// create a SqlSessionFactory
Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/cache/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/cache/CreateDB.sql");
ScriptRunner runner = new ScriptRunner(conn);
runner.setLogWriter(null);
runner.runScript(reader);
reader.close();
session.close();
}
示例8: setUp
import org.apache.ibatis.jdbc.ScriptRunner; //导入依赖的package包/类
@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();
}
示例9: setUp
import org.apache.ibatis.jdbc.ScriptRunner; //导入依赖的package包/类
@BeforeClass
public static void setUp() throws Exception {
// create a SqlSessionFactory
Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/resultmapwithassociationstest/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/resultmapwithassociationstest/CreateDB.sql");
ScriptRunner runner = new ScriptRunner(conn);
runner.setLogWriter(null);
runner.runScript(reader);
reader.close();
session.close();
}
示例10: setUp
import org.apache.ibatis.jdbc.ScriptRunner; //导入依赖的package包/类
@BeforeClass
public static void setUp() throws Exception {
// create a SqlSessionFactory
Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/nestedresulthandler/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/nestedresulthandler/CreateDB.sql");
ScriptRunner runner = new ScriptRunner(conn);
runner.setLogWriter(null);
runner.runScript(reader);
reader.close();
session.close();
}
示例11: setUp
import org.apache.ibatis.jdbc.ScriptRunner; //导入依赖的package包/类
@BeforeClass
public static void setUp() throws Exception {
// create a SqlSessionFactory
Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/automapping/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/automapping/CreateDB.sql");
ScriptRunner runner = new ScriptRunner(conn);
runner.setLogWriter(null);
runner.runScript(reader);
reader.close();
session.close();
}
示例12: openSession
import org.apache.ibatis.jdbc.ScriptRunner; //导入依赖的package包/类
public void openSession(String aConfig) throws Exception {
final String resource = "org/apache/ibatis/submitted/inline_association_with_dot/ibatis-" + aConfig + ".xml";
Reader batisConfigReader = Resources.getResourceAsReader(resource);
SqlSessionFactory sqlSessionFactory;
try {
sqlSessionFactory = new SqlSessionFactoryBuilder().build(batisConfigReader);
} catch(Exception anException) {
throw new RuntimeException("Mapper configuration failed, expected this to work: " + anException.getMessage(), anException);
}
SqlSession session = sqlSessionFactory.openSession();
Connection conn = session.getConnection();
ScriptRunner runner = new ScriptRunner(conn);
runner.setLogWriter(null);
runner.setErrorLogWriter(null);
Reader createScriptReader = Resources.getResourceAsReader("org/apache/ibatis/submitted/inline_association_with_dot/create.sql");
runner.runScript(createScriptReader);
sqlSession = sqlSessionFactory.openSession();
}
示例13: setUp
import org.apache.ibatis.jdbc.ScriptRunner; //导入依赖的package包/类
@BeforeClass
public static void setUp() throws Exception {
// create a SqlSessionFactory
Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/missing_id_property/MapperConfig.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/missing_id_property/CreateDB.sql");
ScriptRunner runner = new ScriptRunner(conn);
runner.setLogWriter(null);
runner.runScript(reader);
reader.close();
session.close();
}
示例14: setUp
import org.apache.ibatis.jdbc.ScriptRunner; //导入依赖的package包/类
@BeforeClass
public static void setUp() throws Exception {
// create an SqlSessionFactory
Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/mapper_type_parameter/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/mapper_type_parameter/CreateDB.sql");
ScriptRunner runner = new ScriptRunner(conn);
runner.setLogWriter(null);
runner.runScript(reader);
reader.close();
session.close();
}
示例15: setUp
import org.apache.ibatis.jdbc.ScriptRunner; //导入依赖的package包/类
@BeforeClass
public static void setUp() throws Exception {
// create an SqlSessionFactory
Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/keygen/MapperConfig.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/keygen/CreateDB.sql");
ScriptRunner runner = new ScriptRunner(conn);
runner.setLogWriter(null);
runner.runScript(reader);
reader.close();
session.close();
}