提交 1d018117 authored 作者: Thomas Mueller's avatar Thomas Mueller

CREATE ALIAS ... AS: Compilation was incorrect if the source code contained…

CREATE ALIAS ... AS: Compilation was incorrect if the source code contained characters that are not supported by the default file encoding.
上级 ae805215
...@@ -111,18 +111,20 @@ public class FunctionAlias extends DbObjectBase { ...@@ -111,18 +111,20 @@ public class FunctionAlias extends DbObjectBase {
private void loadFromSource() { private void loadFromSource() {
SourceCompiler compiler = database.getCompiler(); SourceCompiler compiler = database.getCompiler();
String fullClassName = Constants.USER_PACKAGE + "." + getName(); synchronized (compiler) {
compiler.setSource(fullClassName, source); String fullClassName = Constants.USER_PACKAGE + "." + getName();
try { compiler.setSource(fullClassName, source);
Method m = compiler.getMethod(fullClassName); try {
JavaMethod method = new JavaMethod(m, 0); Method m = compiler.getMethod(fullClassName);
javaMethods = new JavaMethod[] { JavaMethod method = new JavaMethod(m, 0);
method javaMethods = new JavaMethod[] {
}; method
} catch (DbException e) { };
throw e; } catch (DbException e) {
} catch (Exception e) { throw e;
throw DbException.get(ErrorCode.SYNTAX_ERROR_1, e, source); } catch (Exception e) {
throw DbException.get(ErrorCode.SYNTAX_ERROR_1, e, source);
}
} }
} }
......
...@@ -10,7 +10,6 @@ import java.io.ByteArrayOutputStream; ...@@ -10,7 +10,6 @@ import java.io.ByteArrayOutputStream;
import java.io.DataInputStream; import java.io.DataInputStream;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
...@@ -148,7 +147,8 @@ public class SourceCompiler { ...@@ -148,7 +147,8 @@ public class SourceCompiler {
File javaFile = new File(dir, className + ".java"); File javaFile = new File(dir, className + ".java");
File classFile = new File(dir, className + ".class"); File classFile = new File(dir, className + ".class");
try { try {
PrintWriter out = new PrintWriter(new FileWriter(javaFile)); OutputStream f = IOUtils.openFileOutputStream(javaFile.getAbsolutePath(), false);
PrintWriter out = new PrintWriter(IOUtils.getWriter(f));
classFile.delete(); classFile.delete();
int endImport = source.indexOf("@CODE"); int endImport = source.indexOf("@CODE");
String importCode = "import java.util.*;\n" + String importCode = "import java.util.*;\n" +
...@@ -189,6 +189,7 @@ public class SourceCompiler { ...@@ -189,6 +189,7 @@ public class SourceCompiler {
exec("javac", exec("javac",
"-sourcepath", compileDir, "-sourcepath", compileDir,
"-d", compileDir, "-d", compileDir,
"-encoding", "UTF-8",
javaFile.getAbsolutePath()); javaFile.getAbsolutePath());
} }
...@@ -245,6 +246,7 @@ public class SourceCompiler { ...@@ -245,6 +246,7 @@ public class SourceCompiler {
compile.invoke(javac, (Object) new String[] { compile.invoke(javac, (Object) new String[] {
"-sourcepath", compileDir, "-sourcepath", compileDir,
"-d", compileDir, "-d", compileDir,
"-encoding", "UTF-8",
javaFile.getAbsolutePath() }); javaFile.getAbsolutePath() });
throwSyntaxError(buff); throwSyntaxError(buff);
} catch (Exception e) { } catch (Exception e) {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论