org.apache.ibatis.jdbc.ScriptRunner Java Examples
The following examples show how to use
org.apache.ibatis.jdbc.ScriptRunner.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ComplexTypeTest.java From mybaties with Apache License 2.0 | 10 votes |
@BeforeClass public static void setUp() throws Exception { // create a SqlSessionFactory Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/complex_type/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/complex_type/CreateDB.sql"); ScriptRunner runner = new ScriptRunner(conn); runner.setLogWriter(null); runner.runScript(reader); reader.close(); session.close(); }
Example #2
Source File: CacheOrderTest.java From mybaties with Apache License 2.0 | 6 votes |
@BeforeClass public static void setUp() throws Exception { // create a SqlSessionFactory Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/cacheorder/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/cacheorder/CreateDB.sql"); ScriptRunner runner = new ScriptRunner(conn); runner.setLogWriter(null); runner.runScript(reader); reader.close(); session.close(); }
Example #3
Source File: BaseTest.java From mybatis with Apache License 2.0 | 6 votes |
@BeforeClass public static void setUp() throws Exception { // create an SqlSessionFactory Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/global_variables/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/global_variables/CreateDB.sql"); ScriptRunner runner = new ScriptRunner(conn); runner.setLogWriter(null); runner.runScript(reader); reader.close(); session.close(); }
Example #4
Source File: DbSchemaCreator.java From taskana with Apache License 2.0 | 6 votes |
private boolean isSchemaPreexisting(Connection connection) { ScriptRunner runner = getScriptRunnerInstance(connection); StringWriter errorWriter = new StringWriter(); runner.setErrorLogWriter(new PrintWriter(errorWriter)); try { String scriptPath = selectDbSchemaDetectionScript(connection.getMetaData().getDatabaseProductName()); InputStream resourceAsStream = DbSchemaCreator.class.getResourceAsStream(scriptPath); BufferedReader reader = new BufferedReader(new InputStreamReader(resourceAsStream, StandardCharsets.UTF_8)); runner.runScript(getSqlSchemaNameParsed(reader)); } catch (RuntimeSqlException | SQLException e) { LOGGER.debug("Schema does not exist."); if (!errorWriter.toString().trim().isEmpty()) { LOGGER.debug(errorWriter.toString()); } return false; } LOGGER.debug("Schema does exist."); return true; }
Example #5
Source File: ColumnForwardingTest.java From mybatis with Apache License 2.0 | 6 votes |
@BeforeClass public static void setUp() throws Exception { // create a SqlSessionFactory Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/column_forwarding/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/column_forwarding/CreateDB.sql"); ScriptRunner runner = new ScriptRunner(conn); runner.setLogWriter(null); runner.runScript(reader); reader.close(); session.close(); }
Example #6
Source File: MapperExtendTest.java From mybaties with Apache License 2.0 | 6 votes |
@BeforeClass public static void setUp() throws Exception { // create an SqlSessionFactory Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/mapper_extend/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_extend/CreateDB.sql"); ScriptRunner runner = new ScriptRunner(conn); runner.setLogWriter(null); runner.runScript(reader); reader.close(); session.close(); }
Example #7
Source File: JavassistTest.java From mybaties with Apache License 2.0 | 6 votes |
@BeforeClass public static void setUp() throws Exception { // create a SqlSessionFactory Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/javassist/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/javassist/CreateDB.sql"); ScriptRunner runner = new ScriptRunner(conn); runner.setLogWriter(null); runner.runScript(reader); reader.close(); session.close(); }
Example #8
Source File: AutomappingTest.java From mybatis with Apache License 2.0 | 6 votes |
@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(); }
Example #9
Source File: AuthorDAOTest.java From mybatis with Apache License 2.0 | 6 votes |
@BeforeClass public static void testGetMessageForEmptyDatabase() throws Exception { final String resource = "org/apache/ibatis/submitted/initialized_collection_property/mybatis-config.xml"; Reader reader = Resources.getResourceAsReader(resource); factory = new SqlSessionFactoryBuilder().build(reader); SqlSession session = factory.openSession(); Connection conn = session.getConnection(); ScriptRunner runner = new ScriptRunner(conn); runner.setLogWriter(null); runner.setErrorLogWriter(null); reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/initialized_collection_property/create.sql"); runner.runScript(reader); session.close(); }
Example #10
Source File: NestedResultHandlerAssociationTest.java From mybatis with Apache License 2.0 | 6 votes |
@BeforeClass public static void setUp() throws Exception { // create an SqlSessionFactory Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/nestedresulthandler_association/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_association/CreateDB.sql"); ScriptRunner runner = new ScriptRunner(conn); runner.setLogWriter(null); runner.runScript(reader); reader.close(); session.close(); }
Example #11
Source File: BartDBMSUtility.java From BART with MIT License | 6 votes |
public static void createDB(AccessConfiguration accessConfiguration) { AccessConfiguration tempAccessConfiguration = getTempAccessConfiguration(accessConfiguration); Connection connection = null; try { if (logger.isDebugEnabled()) logger.debug("Creating db: " + accessConfiguration); // connection = new SimpleDbConnectionFactory().getConnection(tempAccessConfiguration); connection = simpleDataSourceDB.getConnection(tempAccessConfiguration); // connection = QueryManager.getConnection(tempAccessConfiguration); String createQuery = "create database " + accessConfiguration.getDatabaseName() + ";"; ScriptRunner scriptRunner = getScriptRunner(connection); scriptRunner.setAutoCommit(true); scriptRunner.setStopOnError(true); scriptRunner.runScript(new StringReader(createQuery)); } catch (Exception daoe) { throw new DBMSException("Unable to create new database " + accessConfiguration.getDatabaseName() + ".\n" + tempAccessConfiguration + "\n" + daoe.getLocalizedMessage()); } finally { QueryManager.closeConnection(connection); } }
Example #12
Source File: GenericTypesTest.java From mybatis with Apache License 2.0 | 6 votes |
@Before public void setUp() throws Exception { Connection conn = null; try { Class.forName("org.hsqldb.jdbcDriver"); conn = DriverManager.getConnection("jdbc:hsqldb:mem:generictypes", "sa", ""); Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/generictypes/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/generictypes/Config.xml"); sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader); reader.close(); } finally { if (conn != null) { conn.close(); } } }
Example #13
Source File: SqlProviderTest.java From mybatis with Apache License 2.0 | 6 votes |
@BeforeClass public static void setUp() throws Exception { // create a SqlSessionFactory Reader reader = Resources .getResourceAsReader("org/apache/ibatis/submitted/sqlprovider/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/sqlprovider/CreateDB.sql"); ScriptRunner runner = new ScriptRunner(conn); runner.setLogWriter(null); runner.runScript(reader); reader.close(); session.close(); }
Example #14
Source File: ColumnPrefixTest.java From mybaties with Apache License 2.0 | 6 votes |
@Before public void setUp() throws Exception { Connection conn = null; try { Class.forName("org.hsqldb.jdbcDriver"); conn = DriverManager.getConnection("jdbc:hsqldb:mem:clmpfx", "sa", ""); Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/column_prefix/CreateDB.sql"); ScriptRunner runner = new ScriptRunner(conn); runner.setLogWriter(null); runner.setErrorLogWriter(null); runner.runScript(reader); conn.commit(); reader.close(); reader = Resources.getResourceAsReader(getConfigPath()); sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader); reader.close(); } finally { if (conn != null) { conn.close(); } } }
Example #15
Source File: ForEachMapTest.java From mybatis with Apache License 2.0 | 6 votes |
@BeforeClass public static void setUpClass() throws Exception { // create a SqlSessionFactory Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/foreach_map/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_map/CreateDB.sql"); ScriptRunner runner = new ScriptRunner(conn); runner.setLogWriter(null); runner.runScript(reader); reader.close(); session.close(); }
Example #16
Source File: ValueInMapTest.java From mybaties with Apache License 2.0 | 6 votes |
@BeforeClass public static void setUp() throws Exception { // create a SqlSessionFactory Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/valueinmap/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/valueinmap/CreateDB.sql"); ScriptRunner runner = new ScriptRunner(conn); runner.setLogWriter(null); runner.runScript(reader); reader.close(); session.close(); }
Example #17
Source File: OrderPrefixRemoved.java From mybaties with Apache License 2.0 | 6 votes |
@BeforeClass public static void initDatabase() throws Exception { Connection conn = null; try { Class.forName("org.hsqldb.jdbcDriver"); conn = DriverManager.getConnection("jdbc:hsqldb:mem:order_prefix_removed", "sa", ""); Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/order_prefix_removed/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/order_prefix_removed/ibatisConfig.xml"); sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader); reader.close(); } finally { if (conn != null) { conn.close(); } } }
Example #18
Source File: DataSourceInitializerImpl.java From studio with GNU General Public License v3.0 | 6 votes |
private void createDatabaseTables(Connection conn, Statement statement) throws SQLException, IOException { String createDbScriptPath = getCreateDBScriptPath(); // Database does not exist logger.info("Database tables do not exist."); logger.info("Creating database tables from script " + createDbScriptPath); ScriptRunner sr = new ScriptRunner(conn); sr.setDelimiter(delimiter); sr.setStopOnError(true); sr.setLogWriter(null); InputStream is = getClass().getClassLoader().getResourceAsStream(createDbScriptPath); String scriptContent = IOUtils.toString(is); Reader reader = new StringReader( scriptContent.replaceAll(CRAFTER_SCHEMA_NAME, studioConfiguration.getProperty(DB_SCHEMA))); try { sr.runScript(reader); if (isRandomAdminPasswordEnabled()) { setRandomAdminPassword(conn, statement); } integrityValidator.store(conn); } catch (RuntimeSqlException e) { logger.error("Error while running create DB script", e); } }
Example #19
Source File: ResulthandlerTest.java From mybatis with Apache License 2.0 | 6 votes |
@BeforeClass public static void setUp() throws Exception { // create a SqlSessionFactory Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/result_handler/mybatis-config.xml"); sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader); reader.close(); sqlSessionFactory.getConfiguration().addMapper(Mapper.class); // populate in-memory database SqlSession session = sqlSessionFactory.openSession(); Connection conn = session.getConnection(); reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/result_handler/CreateDB.sql"); ScriptRunner runner = new ScriptRunner(conn); runner.setLogWriter(null); runner.runScript(reader); reader.close(); session.close(); }
Example #20
Source File: MultiDbTest.java From mybatis with Apache License 2.0 | 6 votes |
@BeforeClass public static void setUp() throws Exception { Connection conn = null; try { Class.forName("org.hsqldb.jdbcDriver"); conn = DriverManager.getConnection("jdbc:hsqldb:mem:multidb", "sa", ""); Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/multidb/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/multidb/MultiDbConfig.xml"); sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader); reader.close(); } finally { if (conn != null) { conn.close(); } } }
Example #21
Source File: DuplicateStatementsTest.java From mybatis with Apache License 2.0 | 6 votes |
@Before public void setupDb() throws Exception { // create a SqlSessionFactory Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/duplicate_statements/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/duplicate_statements/CreateDB.sql"); ScriptRunner runner = new ScriptRunner(conn); runner.setLogWriter(null); runner.runScript(reader); reader.close(); session.close(); }
Example #22
Source File: RawSqlSourceTest.java From mybaties with Apache License 2.0 | 6 votes |
@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(); }
Example #23
Source File: QuotedColumnNamesTest.java From mybaties with Apache License 2.0 | 6 votes |
@BeforeClass public static void setUp() throws Exception { Connection conn = null; try { Class.forName("org.hsqldb.jdbcDriver"); conn = DriverManager.getConnection("jdbc:hsqldb:mem:gname", "sa", ""); Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/quotedcolumnnames/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/quotedcolumnnames/MapperConfig.xml"); sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader); reader.close(); } finally { if (conn != null) { conn.close(); } } }
Example #24
Source File: RawSqlSourceTest.java From mybatis with Apache License 2.0 | 6 votes |
@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(); }
Example #25
Source File: BlockingCacheTest.java From mybatis with Apache License 2.0 | 6 votes |
@Before public void setUp() throws Exception { // create a SqlSessionFactory Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/blocking_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/blocking_cache/CreateDB.sql"); ScriptRunner runner = new ScriptRunner(conn); runner.setLogWriter(null); runner.runScript(reader); reader.close(); session.close(); }
Example #26
Source File: AwfulTableTest.java From mybatis with Apache License 2.0 | 6 votes |
@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(); }
Example #27
Source File: ComplexTypeTest.java From mybatis with Apache License 2.0 | 6 votes |
@BeforeClass public static void setUp() throws Exception { // create a SqlSessionFactory Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/complex_type/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/complex_type/CreateDB.sql"); ScriptRunner runner = new ScriptRunner(conn); runner.setLogWriter(null); runner.runScript(reader); reader.close(); session.close(); }
Example #28
Source File: GenericTypesTest.java From mybaties with Apache License 2.0 | 6 votes |
@Before public void setUp() throws Exception { Connection conn = null; try { Class.forName("org.hsqldb.jdbcDriver"); conn = DriverManager.getConnection("jdbc:hsqldb:mem:generictypes", "sa", ""); Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/generictypes/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/generictypes/Config.xml"); sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader); reader.close(); } finally { if (conn != null) { conn.close(); } } }
Example #29
Source File: SqlProviderTest.java From mybaties with Apache License 2.0 | 6 votes |
@BeforeClass public static void setUp() throws Exception { // create a SqlSessionFactory Reader reader = Resources .getResourceAsReader("org/apache/ibatis/submitted/sqlprovider/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/sqlprovider/CreateDB.sql"); ScriptRunner runner = new ScriptRunner(conn); runner.setLogWriter(null); runner.runScript(reader); reader.close(); session.close(); }
Example #30
Source File: MultipleIteratesTest.java From mybaties with Apache License 2.0 | 6 votes |
@BeforeClass public static void setUp() throws Exception { // create a SqlSessionFactory Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/multipleiterates/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/multipleiterates/CreateDB.sql"); ScriptRunner runner = new ScriptRunner(conn); runner.setLogWriter(null); runner.runScript(reader); reader.close(); session.close(); }