List of usage examples for org.apache.ibatis.jdbc ScriptRunner ScriptRunner
public ScriptRunner(Connection connection)
From source file:org.mybatis.scripting.freemarker.FreeMarkerInXmlTest.java
License:Apache License
@BeforeAll public static void setUp() throws Exception { Connection conn = null;//from ww w. j a v a 2s . c om try { Class.forName("org.hsqldb.jdbcDriver"); conn = DriverManager.getConnection("jdbc:hsqldb:mem:db2", "sa", ""); Reader reader = Resources.getResourceAsReader("org/mybatis/scripting/freemarker/create-db.sql"); ScriptRunner runner = new ScriptRunner(conn); runner.setLogWriter(null); runner.setErrorLogWriter(null); runner.runScript(reader); conn.commit(); reader.close(); reader = Resources.getResourceAsReader("org/mybatis/scripting/freemarker/mapper-config.xml"); sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader); reader.close(); } finally { if (conn != null) { conn.close(); } } }
From source file:org.mybatis.scripting.freemarker.PreparedParamsTest.java
License:Apache License
@BeforeAll public static void setUp() throws Exception { Class.forName("org.hsqldb.jdbcDriver"); JDBCDataSource dataSource = new JDBCDataSource(); dataSource.setUrl("jdbc:hsqldb:mem:db3"); dataSource.setUser("sa"); dataSource.setPassword(""); try (Connection conn = dataSource.getConnection()) { try (Reader reader = Resources.getResourceAsReader("org/mybatis/scripting/freemarker/create-db.sql")) { ScriptRunner runner = new ScriptRunner(conn); runner.setLogWriter(null);/*www .j a v a 2 s . c o m*/ runner.setErrorLogWriter(null); runner.runScript(reader); conn.commit(); } } TransactionFactory transactionFactory = new JdbcTransactionFactory(); Environment environment = new Environment("development", transactionFactory, dataSource); // You can call configuration.setDefaultScriptingLanguage(FreeMarkerLanguageDriver.class) // after this to use FreeMarker driver by default. Configuration configuration = new Configuration(environment); configuration.addMapper(PreparedParamsMapper.class); sqlSessionFactory = new SqlSessionFactoryBuilder().build(configuration); }
From source file:org.mybatis.scripting.velocity.use.VelocityLanguageTest.java
License:Apache License
@BeforeClass public static void setUp() throws Exception { Connection conn = null;// ww w . ja va2s .c o m try { Class.forName("org.hsqldb.jdbcDriver"); conn = DriverManager.getConnection("jdbc:hsqldb:mem:bname", "sa", ""); Reader reader = Resources.getResourceAsReader("org/mybatis/scripting/velocity/use/CreateDB.sql"); ScriptRunner runner = new ScriptRunner(conn); runner.setLogWriter(null); runner.setErrorLogWriter(null); runner.runScript(reader); conn.commit(); reader.close(); reader = Resources.getResourceAsReader("org/mybatis/scripting/velocity/use/MapperConfig.xml"); sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader); reader.close(); } finally { if (conn != null) { conn.close(); } } }
From source file:org.openo.gso.activator.ActivatorTest.java
License:Apache License
/** * Before executing UT, start sql.<br/> * // w w w . j a va2s . c om * @since GSO 0.5 */ @Before public void start() throws IOException, SQLException { // Get database connect String resource = "mybatis-config.xml"; Reader reader = Resources.getResourceAsReader(resource); SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader); session = sqlSessionFactory.openSession(); Connection conn = session.getConnection(); ScriptRunner runner = new ScriptRunner(conn); // Run DB script reader = Resources.getResourceAsReader("ServiceModel.sql"); runner.runScript(reader); reader = Resources.getResourceAsReader("ServicePackage.sql"); runner.runScript(reader); reader = Resources.getResourceAsReader("ServiceSegment.sql"); runner.runScript(reader); reader = Resources.getResourceAsReader("ServiceParameter.sql"); runner.runScript(reader); reader = Resources.getResourceAsReader("inventory.sql"); runner.runScript(reader); reader = Resources.getResourceAsReader("Operation.sql"); runner.runScript(reader); reader.close(); svcModelDao = (IServiceModelDao) SpringContextUtil.getBeanById("serviceModelDao"); svcOperDao = (IServiceOperDao) SpringContextUtil.getBeanById("serviceOperDao"); segmentDao = (IServiceSegmentDao) SpringContextUtil.getBeanById("serviceSegmentDao"); mockSession(); }
From source file:org.openo.gso.dao.impl.ServiceModelDaoImplTest.java
License:Apache License
/** * Before starting to test UT, prepare database data.<br/> * //from w w w .j av a2 s . c o m * @throws IOException * @throws SQLException * @since GSO 0.5 */ @Before public void setup() throws IOException, SQLException { serviceModelDao.setDbSessionHandler(dbSessionHandler); packageDao.setDbSessionHandler(dbSessionHandler); String resource = "mybatis-config.xml"; Reader reader = Resources.getResourceAsReader(resource); SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader); session = sqlSessionFactory.openSession(); Connection conn = session.getConnection(); ScriptRunner runner = new ScriptRunner(conn); reader = Resources.getResourceAsReader("ServiceModel.sql"); runner.runScript(reader); reader = Resources.getResourceAsReader("ServicePackage.sql"); runner.runScript(reader); reader = Resources.getResourceAsReader("ServiceParameter.sql"); runner.runScript(reader); reader.close(); // mock session mockSession(); }
From source file:org.openo.gso.dao.impl.ServicePackageDaoImplTest.java
License:Apache License
@Before public void setup() throws IOException, SQLException { servicePackageDao.setDbSessionHandler(dbSessionHandler); String resource = "mybatis-config.xml"; Reader reader = Resources.getResourceAsReader(resource); SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader); session = sqlSessionFactory.openSession(); Connection conn = session.getConnection(); reader = Resources.getResourceAsReader("ServicePackage.sql"); ScriptRunner runner = new ScriptRunner(conn); runner.runScript(reader);//from w ww . j a va 2s . c o m reader.close(); // mock session mockSession(); }
From source file:org.openo.gso.dao.impl.ServiceSegmentDaoImplTest.java
License:Apache License
@Before public void setup() throws IOException, SQLException { serviceSegmentDao.setDbSessionHandler(dbSessionHandler); String resource = "mybatis-config.xml"; Reader reader = Resources.getResourceAsReader(resource); SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader); session = sqlSessionFactory.openSession(); Connection conn = session.getConnection(); reader = Resources.getResourceAsReader("ServiceSegment.sql"); ScriptRunner runner = new ScriptRunner(conn); runner.runScript(reader);/* w w w . j a v a 2s .c o m*/ reader = Resources.getResourceAsReader("Operation.sql"); runner.runScript(reader); reader.close(); // mock session mockSession(); }
From source file:org.openo.gso.roa.impl.ServicemgrRoaModuleImplTest.java
License:Apache License
/** * Prepare SQL environment<br/>//w w w.ja v a 2s.co m * * @throws IOException * @throws SQLException * @since GSO 0.5 */ private void prepareSQL() throws IOException, SQLException { String resource = "mybatis-config.xml"; Reader reader = Resources.getResourceAsReader(resource); SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader); session = sqlSessionFactory.openSession(); Connection conn = session.getConnection(); ScriptRunner runner = new ScriptRunner(conn); reader = Resources.getResourceAsReader("ServiceModel.sql"); runner.runScript(reader); reader = Resources.getResourceAsReader("ServicePackage.sql"); runner.runScript(reader); reader = Resources.getResourceAsReader("ServiceSegment.sql"); runner.runScript(reader); reader = Resources.getResourceAsReader("ServiceParameter.sql"); runner.runScript(reader); reader = Resources.getResourceAsReader("inventory.sql"); runner.runScript(reader); reader = Resources.getResourceAsReader("Operation.sql"); runner.runScript(reader); reader.close(); // mock session mockSession(); }
From source file:org.pau.assetmanager.test.GenericTest.java
License:Open Source License
private static void createDatabase(Properties properties) { try {/*w ww .j a v a 2 s .c om*/ Connection connection = getJDBCConnection(properties); ScriptRunner scriptRunner = new ScriptRunner(connection); InputStreamReader inputStreamReader = new InputStreamReader( getInputStreamFromFile("table_creation.sql")); scriptRunner.runScript(inputStreamReader); inputStreamReader.close(); InputStreamReader inputStreamReaderInit = new InputStreamReader(getInputStreamFromFile("init.sql")); scriptRunner.runScript(inputStreamReaderInit); inputStreamReaderInit.close(); scriptRunner.closeConnection(); } catch (IOException e) { throw new RuntimeException("Error initalizing database", e); } }
From source file:org.sonar.core.persistence.DdlUtils.java
License:Open Source License
private static ScriptRunner newScriptRunner(Connection connection) { ScriptRunner scriptRunner = new ScriptRunner(connection); scriptRunner.setDelimiter(";"); scriptRunner.setStopOnError(true);/* w ww . ja va2 s .c o m*/ scriptRunner.setLogWriter(new PrintWriter(new NullWriter())); return scriptRunner; }