Last active
November 29, 2017 19:13
-
-
Save krisrice/8da5e6cbc07db5becde799742a3c72d2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
load('helpers.js'); | |
/* | |
CREATE TABLE K | |
( PATH VARCHAR2(2000), | |
BLOB_CONTENT BLOB, | |
mime varchar2(40), | |
WHEN TIMESTAMP (6) | |
) | |
*/ | |
/* File name */ | |
var File = Java.type("java.io.File") | |
var FilenameFilter = Java.type("java.io.FilenameFilter") | |
var dir = "." | |
var cwd = new File(dir); | |
var allFiles = cwd.listFiles(); | |
var files=[]; | |
for(f in allFiles ){ | |
if ( allFiles[f].isFile() ){ | |
files[realFileList.length++] = allFiles[f]; | |
} | |
} | |
for(var file in files){ | |
/* load binds */ | |
binds = helpers.getBindMap(); | |
/* add more binds */ | |
binds.put("path",files[file].toString().substring(2)); | |
var ext = files[file].toString().substring(files[file].toString().lastIndexOf(".")); | |
var mime="" | |
switch (ext){ | |
case '.js' : | |
mime = 'application/javascript' | |
break; | |
case '.sql' : | |
mime = 'application/sql' | |
break; | |
case '.log' : | |
mime = 'plain/text' | |
break; | |
default: | |
mime = 'application/octet' | |
} | |
binds.put("mime",mime) | |
ctx.write("Loading:"+ files[file] + "\n") | |
blob = helpers.getBlobFromFile(files[file]); | |
ctx.write("\t>"+ blob.length()+":" + files[file] + "\n") | |
binds.put("b",blob); | |
/* exec the insert and pass binds */ | |
var ret = util.execute("insert into k(path,blob_content,mime,when) values(:path , :b,:mime,systimestamp)",binds); | |
var ex = util.getLastException(); | |
if ( ex ){ | |
ctx.write(ex+ "\n") | |
} | |
} | |
/* print the results */ | |
sqlcl.setStmt("select path,dbms_lob.getlength(blob_content) from k order by when desc;"); | |
sqlcl.run(); |
Waiting on the nashorn team to tell me why this broke. I can't see any reason. It's in the extending the SimpleFileVisitor somehow.
It's a java9 bug that worked in java8 and now fixed in java10. I'll have to rewrite this to work in 9.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://gist.github.com/krisrice/8da5e6cbc07db5becde799742a3c72d2#file-blobs-helper-js-L25 this no longer works on Java 9. Any clue?