Java Code Examples for org.apache.ibatis.jdbc.ScriptRunner#setDelimiter()

The following examples show how to use org.apache.ibatis.jdbc.ScriptRunner#setDelimiter() . 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: DataSourceInitializerImpl.java    From studio with GNU General Public License v3.0 6 votes vote down vote up
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 2
Source File: DataSourceInitializerImpl.java    From studio with GNU General Public License v3.0 6 votes vote down vote up
private void createSchema(Connection conn) throws IOException {
    String createSchemaScriptPath = getCreateSchemaScriptPath();
    // Database does not exist
    logger.info("Database schema does not exists.");
    logger.info("Creating database schema from script " + createSchemaScriptPath);
    ScriptRunner sr = new ScriptRunner(conn);

    sr.setDelimiter(delimiter);
    sr.setStopOnError(true);
    sr.setLogWriter(null);
    InputStream is = getClass().getClassLoader().getResourceAsStream(createSchemaScriptPath);
    String scriptContent = IOUtils.toString(is);
    Reader reader = new StringReader(
            scriptContent.replaceAll(CRAFTER_SCHEMA_NAME, studioConfiguration.getProperty(DB_SCHEMA)));
    try {
        sr.runScript(reader);
    } catch (RuntimeSqlException e) {
        logger.error("Error while running create DB script", e);
    }
}
 
Example 3
Source File: SPTest.java    From mybaties with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void initDatabase() throws Exception {
  Connection conn = null;

  try {
    Class.forName("org.hsqldb.jdbcDriver");
    conn = DriverManager.getConnection("jdbc:hsqldb:mem:sptest", "sa", "");

    Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/sptests/CreateDB.sql");

    ScriptRunner runner = new ScriptRunner(conn);
    runner.setDelimiter("go");
    runner.setLogWriter(null);
    runner.setErrorLogWriter(null);
    runner.runScript(reader);
    conn.commit();
    reader.close();

    reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/sptests/MapperConfig.xml");
    sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);
    reader.close();
  } finally {
    if (conn != null) {
      conn.close();
    }
  }
}
 
Example 4
Source File: SPTest.java    From mybatis with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void initDatabase() throws Exception {
  Connection conn = null;

  try {
    Class.forName("org.hsqldb.jdbcDriver");
    conn = DriverManager.getConnection("jdbc:hsqldb:mem:sptest", "sa", "");

    Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/sptests/CreateDB.sql");

    ScriptRunner runner = new ScriptRunner(conn);
    runner.setDelimiter("go");
    runner.setLogWriter(null);
    runner.setErrorLogWriter(null);
    runner.runScript(reader);
    conn.commit();
    reader.close();

    reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/sptests/MapperConfig.xml");
    sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);
    reader.close();
  } finally {
    if (conn != null) {
      conn.close();
    }
  }
}