Skip to content

Commit ab3a804

Browse files
Update apxexp.js
New feature to export files in a folder. ex: >var a = new ApexExport(); >var myoptions = ["-workspace","MY_WORKSPACE","-expTranslations","-replace","-exportFolder","appsExport"]; >a.run(myoptions);
1 parent 06eebcb commit ab3a804

File tree

1 file changed

+30
-11
lines changed

1 file changed

+30
-11
lines changed

sqlcl/examples/apxexp.js

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@ var OracleCallableStatement = Java.type("oracle.jdbc.OracleCallableStatement");
44
var OracleTypes = Java.type("oracle.jdbc.OracleTypes");
55
var BigDecimal = Java.type("java.math.BigDecimal");
66
var CopyOption = Java.type("java.nio.file.StandardCopyOption");
7-
var Charset = Java.type("java.nio.charset.Charset")
8-
var BufferedReader = Java.type("java.io.BufferedReader")
7+
var Charset = Java.type("java.nio.charset.Charset");
8+
var BufferedReader = Java.type("java.io.BufferedReader");
9+
var FileSystems = Java.type("java.nio.file.FileSystems");
10+
var Files = Java.type("java.nio.file.Files");
11+
912
function ApexExport() {
1013
this.CmdName = "apxexp";
1114

@@ -41,10 +44,12 @@ function ApexExport() {
4144
this.debug('Param:' + args[i])
4245
if ( args[i].equalsIgnoreCase(this.CmdName)) {
4346
// just skip it.
47+
} else if (args[i].equalsIgnoreCase("-exportFolder")) {
48+
this.options.exportFolder = args[++i];
4449
} else if (args[i].equalsIgnoreCase("-workspaceid")) {
4550
this.options.workspaceID = args[++i];
4651
} else if (args[i].equalsIgnoreCase("-workspace")) {
47-
this.options.workspaceName = args[++i];
52+
this.options.workspaceName = args[++i];
4853
} else if (args[i].equalsIgnoreCase("-applicationid")) {
4954
this.options.appID = args[++i];
5055
} else if (args[i].equalsIgnoreCase("-debug")) {
@@ -100,6 +105,7 @@ function ApexExport() {
100105

101106
this.usage = function(){
102107
ctx.write("\nUsage "+this.CmdName+" [options] \n");
108+
ctx.write(" -exportFolder: Name of the folder where the files will be exported to\n");
103109
ctx.write(" -applicationid: ID for application to be exported\n");
104110
ctx.write(" -workspaceid: Workspace ID for which all applications to be exported or the workspace to be exported\n");
105111
ctx.write(" -workspace: Case Sensative workspace name to export\n");
@@ -264,15 +270,28 @@ function ApexExport() {
264270
}
265271
this.clob2file=function (clob,fName){
266272
var stream = new BufferedReader(clob.getCharacterStream());
267-
268-
// get the path/file handle to write to
269-
var path = java.nio.file.FileSystems.getDefault().getPath(fName);
270-
271-
// dump the file stream to the file
272-
var bytes=0;
273-
if ( ! path.toFile().exists() ||
273+
var path;
274+
275+
// get the path/file handle to write to
276+
if (this.options.exportFolder){
277+
var folderPath = FileSystems.getDefault().getPath(this.options.exportFolder);
278+
279+
// check if the export folder exists. If not create it.
280+
if (!folderPath.toFile().isDirectory()){
281+
Files.createDirectory(folderPath);
282+
}
283+
284+
path = FileSystems.getDefault().getPath(this.options.exportFolder, fName);
285+
}
286+
else{
287+
path = FileSystems.getDefault().getPath(fName);
288+
}
289+
290+
// dump the file stream to the file
291+
var bytes=0;
292+
if ( ! path.toFile().exists() ||
274293
( this.options.replace && path.toFile().exists() )) {
275-
var bw = java.nio.file.Files.newBufferedWriter(path,Charset.forName("UTF-8"))
294+
var bw = Files.newBufferedWriter(path,Charset.forName("UTF-8"))
276295
var line = null;
277296
while((line = stream.readLine())!=null){
278297
if ( ! ( this.options.skipDate && line.indexOf("-- Date and Time:") != 0 ) ) {

0 commit comments

Comments
 (0)