public void executeScripts(List<File> scriptDirs) throws MojoExecutionException { Map<DirectoryType, List<File>> masterFiles = Maps.newHashMap(); for (File scriptDir : scriptDirs) { if (scriptDir.exists()) { Map<DirectoryType, List<File>> files = FileUtils.getFilesByType(scriptDir); for (DirectoryType directoryType : files.keySet()) { if (!masterFiles.containsKey(directoryType)) { masterFiles.put(directoryType, new ArrayList<File>()); } if (!files.get(directoryType).isEmpty()) { masterFiles.get(directoryType).addAll(files.get(directoryType)); } } } } Connection connection = null; try { connection = getConnection(); executeType(connection, masterFiles, DirectoryType.SEQUENCE); executeType(connection, masterFiles, DirectoryType.TABLE); executeType(connection, masterFiles, DirectoryType.VIEW); executeType(connection, masterFiles, DirectoryType.TRIGGER); executeType(connection, masterFiles, DirectoryType.DEFAULT_REF_DATA); executeType(connection, masterFiles, DirectoryType.FOREIGN_KEY); executeType(connection, masterFiles, DirectoryType.FUNCTION); } catch (Throwable e) { throw new MojoExecutionException("Failed to release scripts", e); } finally { JdbcUtils.closeConnection(connection); } }
public void executeScripts(List<File> scriptDirs) throws MojoExecutionException { for (File scriptDir : scriptDirs) { Connection connection = null; if (scriptDir.exists()) { printTitle(" RELEASING DIRECTORY: " + scriptDir); try { // Check for folder structure Map<DirectoryType, List<File>> files = FileUtils.getFilesByType(scriptDir); // Create connection connection = getConnection(); // Loop through files and execute List<File> sequences = files.get(DirectoryType.SEQUENCE); if (sequences != null && !sequences.isEmpty()) { getLog().info("Releasing Sequences"); executeFiles(connection, DirectoryType.SEQUENCE, sequences); } List<File> tables = files.get(DirectoryType.TABLE); if (tables != null && !tables.isEmpty()) { getLog().info("Releasing Tables"); executeFiles(connection, DirectoryType.TABLE, tables); } List<File> functions = files.get(DirectoryType.FUNCTION); if (functions != null && !functions.isEmpty()) { getLog().info("Releasing Functions"); executeFiles(connection, DirectoryType.FUNCTION, functions); } List<File> views = files.get(DirectoryType.VIEW); if (views != null && !views.isEmpty()) { getLog().info("Releasing Views"); executeFiles(connection, DirectoryType.VIEW, views); } List<File> triggers = files.get(DirectoryType.TRIGGER); if (triggers != null && !triggers.isEmpty()) { getLog().info("Releasing Triggers"); executeFiles(connection, DirectoryType.TRIGGER, triggers); } List<File> refData = files.get(DirectoryType.DEFAULT_REF_DATA); if (refData != null && !refData.isEmpty()) { getLog().info("Releasing Default Reference Data"); executeFiles(connection, DirectoryType.DEFAULT_REF_DATA, refData); } List<File> fks = files.get(DirectoryType.FOREIGN_KEY); if (fks != null && !fks.isEmpty()) { getLog().info("Releasing Foreign Keys"); executeFiles(connection, DirectoryType.FOREIGN_KEY, fks); } } catch (Throwable e) { throw new MojoExecutionException("Failed to release scripts", e); } finally { JdbcUtils.closeConnection(connection); } } else { getLog().error("Directory " + scriptDir + " does not exist."); } } }