Package org.springframework.core.io.support

Examples of org.springframework.core.io.support.EncodedResource


  private EncodedResource applyEncodingIfNecessary(Resource script) {
    if (script instanceof EncodedResource) {
      return (EncodedResource) script;
    }
    else {
      return new EncodedResource(script, this.sqlScriptEncoding);
    }
  }
View Full Code Here


  @SuppressWarnings("deprecation")
  public void executeSqlScriptsAndcountRowsInTableWhere() throws Exception {

    for (String script : Arrays.asList("schema.sql", "data.sql")) {
      Resource resource = new ClassPathResource(script, getClass());
      JdbcTestUtils.executeSqlScript(this.jdbcTemplate, new EncodedResource(resource), false);
    }

    assertEquals(1, JdbcTestUtils.countRowsInTableWhere(jdbcTemplate, "person", "name = 'bob'"));
  }
View Full Code Here

  private Resource substitutePlaceholdersForResource(Resource resource) {

    StringBuilder script = new StringBuilder();

    try {
      EncodedResource er = new EncodedResource(resource);
      LineNumberReader lnr = new LineNumberReader(er.getReader());
      String line = lnr.readLine();
      while (line != null) {
        if (tableName != null && line.contains(TABLE_PLACEHOLDER)) {
          logger.debug("Substituting '" + TABLE_PLACEHOLDER + "' with '" + tableName + "' in '" + line + "'");
          line = line.replace(TABLE_PLACEHOLDER, tableName);
View Full Code Here

  public static void executeScript(DataSource dataSource, String... sqlResourcePaths) throws DataAccessException {
    JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
    for (String sqlResourcePath : sqlResourcePaths) {
      Resource resource = resourceLoader.getResource(sqlResourcePath);
      JdbcTestUtils.executeSqlScript(jdbcTemplate, new EncodedResource(resource, DEFAULT_ENCODING), true);
    }
  }
View Full Code Here

     * @see #DEFAULT_STATEMENT_SEPARATOR
     * @see #DEFAULT_BLOCK_COMMENT_START_DELIMITER
     * @see #DEFAULT_BLOCK_COMMENT_END_DELIMITER
     */
    public static void executeSqlScript(DataSource dataSource, Resource resource) {
        executeSqlScript(dataSource, new EncodedResource(resource));
    }
View Full Code Here

            throw new DataAccessResourceFailureException("Failed to open SQL script '" + sqlResource + "'", ex);
        }
    }

    private void executeSqlScript(String sqlResourcePath) throws DataAccessException {
        EncodedResource resource =
                new EncodedResource(applicationContext.getResource(sqlResourcePath), "UTF-8");
        List<String> statements = new LinkedList<String>();
        try {
            LineNumberReader lnr = new LineNumberReader(resource.getReader());
            String script = JdbcTestUtils.readScript(lnr);
            char delimiter = ';';
            if (!JdbcTestUtils.containsSqlScriptDelimiters(script, delimiter)) {
                delimiter = '\n';
            }
View Full Code Here

TOP

Related Classes of org.springframework.core.io.support.EncodedResource

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.