diff --git a/pl_engine/pl_server/src/main/java/com/cubrid/jsp/ExecuteThread.java b/pl_engine/pl_server/src/main/java/com/cubrid/jsp/ExecuteThread.java index 1b46aa7a55..1b44e7e925 100644 --- a/pl_engine/pl_server/src/main/java/com/cubrid/jsp/ExecuteThread.java +++ b/pl_engine/pl_server/src/main/java/com/cubrid/jsp/ExecuteThread.java @@ -65,6 +65,7 @@ import java.nio.ByteBuffer; import java.nio.file.Files; import java.nio.file.Path; +import java.nio.file.Paths; import java.sql.SQLException; import java.util.Base64; import java.util.List; @@ -308,9 +309,22 @@ public CUBRIDUnpacker getUnpacker() { return unpacker; } + private void readSessionParameter(CUBRIDUnpacker unpacker) { + int paramCnt = (int) unpacker.unpackBigint(); + if (paramCnt > 0) { + for (int i = 0; i < paramCnt; i++) { + SysParam sysParam = new SysParam(unpacker); + ctx.getSystemParameters().put(sysParam.getParamId(), sysParam); + } + } + } + private void processStoredProcedure() throws Exception { unpacker.setBuffer(ctx.getInboundQueue().take()); + // session parameters + readSessionParameter(unpacker); + // prepare if (prepareArgs == null) { prepareArgs = new PrepareArgs(unpacker); @@ -385,6 +399,9 @@ private void processBootstrap() throws Exception { private void processCompile() throws Exception { unpacker.setBuffer(ctx.getInboundQueue().take()); + // session parameters + readSessionParameter(unpacker); + CompileRequest request = new CompileRequest(unpacker); // TODO: Pass CompileRequest directly to compilePLCSQL () @@ -401,6 +418,18 @@ private void processCompile() throws Exception { if (info.errCode == 0) { MemoryJavaCompiler compiler = new MemoryJavaCompiler(); SourceCode sCode = new SourceCode(info.className, info.translated); + + // dump translated code into $CUBRID_TMP + if (Context.getSystemParameterBool(SysParam.STORED_PROCEDURE_DUMP_ICODE)) { + Path path = + Paths.get( + Server.getConfig().getTmpPath() + + "/" + + info.className + + ".java"); + Files.write(path, info.translated.getBytes(Context.getSessionCharset())); + } + CompiledCodeSet codeSet = compiler.compile(sCode); int mode = 1; // 0: temp file mode, 1: memory stream mode diff --git a/pl_engine/pl_server/src/main/java/com/cubrid/jsp/Server.java b/pl_engine/pl_server/src/main/java/com/cubrid/jsp/Server.java index 10418cd05e..8c3f4bacf9 100644 --- a/pl_engine/pl_server/src/main/java/com/cubrid/jsp/Server.java +++ b/pl_engine/pl_server/src/main/java/com/cubrid/jsp/Server.java @@ -32,7 +32,6 @@ package com.cubrid.jsp; import com.cubrid.jsp.classloader.ClassLoaderManager; -import com.cubrid.jsp.exception.TypeMismatchException; import com.cubrid.jsp.protocol.BootstrapRequest; import java.io.IOException; import java.io.PrintWriter; @@ -253,18 +252,6 @@ public static void bootstrap(BootstrapRequest request) { config.initializeCharset(); } - public static boolean getSystemParameterBool(int id) { - try { - SysParam param = config.getSystemParameters().get(id); - if (param != null) { - return param.getParamValue().toInt() != 0; - } - } catch (TypeMismatchException e) { - } - - return false; - } - public static void main(String[] args) throws Exception { Server.start(args); } diff --git a/pl_engine/pl_server/src/main/java/com/cubrid/jsp/ServerConfig.java b/pl_engine/pl_server/src/main/java/com/cubrid/jsp/ServerConfig.java index d4b0f6c02f..657c3ee6e5 100644 --- a/pl_engine/pl_server/src/main/java/com/cubrid/jsp/ServerConfig.java +++ b/pl_engine/pl_server/src/main/java/com/cubrid/jsp/ServerConfig.java @@ -144,9 +144,7 @@ public int getServerCodesetId() { return SysParam.getCodesetId(serverCharset); } - public void initializeCharset() { - SysParam sysParam = systemParameters.get(SysParam.INTL_COLLATION); - String collation = sysParam.getParamValue().toString(); + public static String parseCollationString(String collation) { String codeset = null; String[] codesetList = collation.split("_"); if (codesetList == null) { @@ -166,6 +164,14 @@ public void initializeCharset() { codeset = "UTF-8"; // ascii is a subset of UTF-8 } + return codeset; + } + + public void initializeCharset() { + SysParam sysParam = systemParameters.get(SysParam.INTL_COLLATION); + String collation = sysParam.getParamValue(); + String codeset = parseCollationString(collation); + try { serverCharset = Charset.forName(codeset); } catch (Exception e) { diff --git a/pl_engine/pl_server/src/main/java/com/cubrid/jsp/SysParam.java b/pl_engine/pl_server/src/main/java/com/cubrid/jsp/SysParam.java index eb3bff91b7..13b081642c 100644 --- a/pl_engine/pl_server/src/main/java/com/cubrid/jsp/SysParam.java +++ b/pl_engine/pl_server/src/main/java/com/cubrid/jsp/SysParam.java @@ -1,9 +1,7 @@ package com.cubrid.jsp; import com.cubrid.jsp.data.CUBRIDUnpacker; -import com.cubrid.jsp.exception.TypeMismatchException; import com.cubrid.jsp.protocol.UnPackableObject; -import com.cubrid.jsp.value.Value; import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; @@ -17,6 +15,16 @@ public class SysParam implements UnPackableObject { public static final int INTL_COLLATION = 206; public static final int TIMEZONE = 249; public static final int ORACLE_COMPAT_NUMBER_BEHAVIOR = 334; + public static final int STORED_PROCEDURE_DUMP_ICODE = 354; + + // paramType + public static final int PRM_TYPE_INTEGER = 0; + public static final int PRM_TYPE_FLOAT = 1; + public static final int PRM_TYPE_BOOLEAN = 2; + public static final int PRM_TYPE_KEYWORD = 3; + public static final int PRM_TYPE_BIGINT = 4; + public static final int PRM_TYPE_STRING = 5; + public static final int PRM_TYPE_INTEGER_LIST = 6; // codeset public static final int CODESET_ASCII = 0; @@ -63,7 +71,7 @@ public static int getCodesetId(Charset charset) { private int paramId; private int paramType; - private Value paramValue; + private String paramValue; public SysParam(CUBRIDUnpacker unpacker) { unpack(unpacker); @@ -73,7 +81,7 @@ public int getParamId() { return paramId; } - public Value getParamValue() { + public String getParamValue() { return paramValue; } @@ -93,11 +101,8 @@ public String toString() { @Override public void unpack(CUBRIDUnpacker unpacker) { - try { - this.paramId = unpacker.unpackInt(); // paramId - this.paramType = unpacker.unpackInt(); // paramType - this.paramValue = unpacker.unpackValue(paramType); - } catch (TypeMismatchException e) { - } + this.paramId = unpacker.unpackInt(); // paramId + this.paramType = unpacker.unpackInt(); // paramType + this.paramValue = new String(unpacker.unpackCStringByteArray()); } } diff --git a/pl_engine/pl_server/src/main/java/com/cubrid/jsp/code/CompiledCode.java b/pl_engine/pl_server/src/main/java/com/cubrid/jsp/code/CompiledCode.java index 5336d24707..3d3b05506d 100644 --- a/pl_engine/pl_server/src/main/java/com/cubrid/jsp/code/CompiledCode.java +++ b/pl_engine/pl_server/src/main/java/com/cubrid/jsp/code/CompiledCode.java @@ -31,7 +31,7 @@ package com.cubrid.jsp.code; -import com.cubrid.jsp.Server; +import com.cubrid.jsp.context.Context; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.OutputStream; @@ -79,7 +79,7 @@ public byte[] getByteCode() { @Override public CharSequence getCharContent(boolean ignoreEncodingErrors) { - return new String(getByteCode(), Server.getConfig().getServerCharset()); + return new String(getByteCode(), Context.getSessionCharset()); } @Override diff --git a/pl_engine/pl_server/src/main/java/com/cubrid/jsp/compiler/MemoryJavaCompiler.java b/pl_engine/pl_server/src/main/java/com/cubrid/jsp/compiler/MemoryJavaCompiler.java index 4285cb6256..85589f21a6 100644 --- a/pl_engine/pl_server/src/main/java/com/cubrid/jsp/compiler/MemoryJavaCompiler.java +++ b/pl_engine/pl_server/src/main/java/com/cubrid/jsp/compiler/MemoryJavaCompiler.java @@ -34,6 +34,7 @@ import com.cubrid.jsp.Server; import com.cubrid.jsp.code.CompiledCodeSet; import com.cubrid.jsp.code.SourceCode; +import com.cubrid.jsp.context.Context; import java.nio.file.Path; import java.util.ArrayList; import java.util.Arrays; @@ -57,7 +58,7 @@ public MemoryJavaCompiler() { } Path cubrid_env_root = Server.getServer().getRootPath(); - useOptions("-encoding", Server.getConfig().getServerCharset().toString()); + useOptions("-encoding", Context.getSessionCharset().toString()); useOptions("-classpath", cubrid_env_root + "/java/pl_server.jar"); } diff --git a/pl_engine/pl_server/src/main/java/com/cubrid/jsp/context/Context.java b/pl_engine/pl_server/src/main/java/com/cubrid/jsp/context/Context.java index 5082c747ac..3919796f5e 100644 --- a/pl_engine/pl_server/src/main/java/com/cubrid/jsp/context/Context.java +++ b/pl_engine/pl_server/src/main/java/com/cubrid/jsp/context/Context.java @@ -33,6 +33,8 @@ import com.cubrid.jsp.ExecuteThread; import com.cubrid.jsp.Server; +import com.cubrid.jsp.ServerConfig; +import com.cubrid.jsp.SysParam; import com.cubrid.jsp.TargetMethodCache; import com.cubrid.jsp.classloader.ClassLoaderManager; import com.cubrid.jsp.classloader.ContextClassLoader; @@ -44,6 +46,7 @@ import java.nio.charset.Charset; import java.sql.Connection; import java.sql.SQLException; +import java.util.HashMap; import java.util.Properties; import java.util.concurrent.LinkedBlockingQueue; @@ -85,6 +88,9 @@ public class Context { // message buffer for DBMS_OUTPUT private MessageBuffer messageBuffer; + // context system parameters + private HashMap systemParameters = null; + public Context(long id) { sessionId = id; } @@ -125,11 +131,11 @@ public LinkedBlockingQueue getInboundQueue() { return inBound; } - public Charset getSessionCharset() { - if (sessionCharset == null) { - sessionCharset = Server.getConfig().getServerCharset(); + public HashMap getSystemParameters() { + if (systemParameters == null) { + systemParameters = new HashMap(); } - return sessionCharset; + return systemParameters; } public void checkHeader(Header header) { @@ -226,6 +232,60 @@ public boolean canTransactionControl() { return false; } + public static int getCodesetId() { + return SysParam.getCodesetId(getSessionCharset()); + } + + public static Charset getSessionCharset() { + Context ctx = ContextManager.getContextofCurrentThread(); + SysParam sysParam = ctx.getSystemParameters().get(SysParam.INTL_COLLATION); + if (sysParam == null) { + return Server.getConfig().getServerCharset(); + } + + String collation = sysParam.getParamValue(); + String codeset = ServerConfig.parseCollationString(collation); + + Charset charset; + try { + charset = Charset.forName(codeset); + } catch (Exception e) { + // java.nio.charset.IllegalCharsetNameException + // invalid charset is specified + charset = Server.getConfig().getServerCharset(); + } + + return charset; + } + + public static SysParam getSystemParam(int id) { + Context ctx = ContextManager.getContextofCurrentThread(); + SysParam param = ctx.getSystemParameters().get(id); + if (param == null) { + // get server's parameter + param = Server.getConfig().getSystemParameters().get(id); + } + return param; + } + + public static String getSystemParameterString(int id) { + SysParam param = getSystemParam(id); + if (param != null) { + return param.getParamValue(); + } + + return null; + } + + public static Boolean getSystemParameterBool(int id) { + SysParam param = getSystemParam(id); + if (param != null) { + return Boolean.parseBoolean(param.getParamValue()); + } + + return null; + } + // TODO: move this function to proper place public static ExecuteThread getCurrentExecuteThread() { return (ExecuteThread) Thread.currentThread(); diff --git a/pl_engine/pl_server/src/main/java/com/cubrid/jsp/data/CUBRIDPacker.java b/pl_engine/pl_server/src/main/java/com/cubrid/jsp/data/CUBRIDPacker.java index 2077da81dd..b2c3b25f3a 100644 --- a/pl_engine/pl_server/src/main/java/com/cubrid/jsp/data/CUBRIDPacker.java +++ b/pl_engine/pl_server/src/main/java/com/cubrid/jsp/data/CUBRIDPacker.java @@ -31,8 +31,8 @@ package com.cubrid.jsp.data; -import com.cubrid.jsp.Server; import com.cubrid.jsp.SysParam; +import com.cubrid.jsp.context.Context; import com.cubrid.jsp.exception.TypeMismatchException; import com.cubrid.jsp.jdbc.CUBRIDServerSideResultSet; import com.cubrid.jsp.protocol.PackableObject; @@ -108,7 +108,7 @@ public void packDouble(double value) { } public void packString(String value) { - Charset charset = Server.getConfig().getServerCharset(); + Charset charset = Context.getSessionCharset(); packCString(value.getBytes(charset)); } diff --git a/pl_engine/pl_server/src/main/java/com/cubrid/jsp/data/CUBRIDUnpacker.java b/pl_engine/pl_server/src/main/java/com/cubrid/jsp/data/CUBRIDUnpacker.java index 54f5947906..e8ed2633dc 100644 --- a/pl_engine/pl_server/src/main/java/com/cubrid/jsp/data/CUBRIDUnpacker.java +++ b/pl_engine/pl_server/src/main/java/com/cubrid/jsp/data/CUBRIDUnpacker.java @@ -31,7 +31,7 @@ package com.cubrid.jsp.data; -import com.cubrid.jsp.Server; +import com.cubrid.jsp.context.Context; import com.cubrid.jsp.exception.TypeMismatchException; import com.cubrid.jsp.value.*; import java.nio.ByteBuffer; @@ -106,7 +106,7 @@ public String unpackCString() { byte[] str = new byte[len]; buffer.get(str); align(DataUtilities.INT_ALIGNMENT); - return new String(str, Server.getConfig().getServerCharset()); + return new String(str, Context.getSessionCharset()); } else { align(DataUtilities.INT_ALIGNMENT); return ""; diff --git a/pl_engine/pl_server/src/main/java/com/cubrid/jsp/impl/SUBindParameter.java b/pl_engine/pl_server/src/main/java/com/cubrid/jsp/impl/SUBindParameter.java index f911ac3f29..9298c760f6 100644 --- a/pl_engine/pl_server/src/main/java/com/cubrid/jsp/impl/SUBindParameter.java +++ b/pl_engine/pl_server/src/main/java/com/cubrid/jsp/impl/SUBindParameter.java @@ -30,7 +30,7 @@ */ package com.cubrid.jsp.impl; -import com.cubrid.jsp.Server; +import com.cubrid.jsp.context.Context; import com.cubrid.jsp.data.CUBRIDPacker; import com.cubrid.jsp.data.DBType; import com.cubrid.jsp.jdbc.CUBRIDServerSideJDBCErrorCode; @@ -108,7 +108,7 @@ synchronized void pack(CUBRIDPacker packer) throws UnsupportedEncodingException int cnt = paramMode.length; packer.packInt(cnt); for (int i = 0; i < cnt; i++) { - packer.packObject(values[i], types[i], Server.getConfig().getServerCodesetId()); + packer.packObject(values[i], types[i], Context.getCodesetId()); packer.packInt((int) paramMode[i]); } } diff --git a/pl_engine/pl_server/src/main/java/com/cubrid/jsp/impl/SUConnection.java b/pl_engine/pl_server/src/main/java/com/cubrid/jsp/impl/SUConnection.java index 6b5bc99d2f..97db7ef480 100644 --- a/pl_engine/pl_server/src/main/java/com/cubrid/jsp/impl/SUConnection.java +++ b/pl_engine/pl_server/src/main/java/com/cubrid/jsp/impl/SUConnection.java @@ -31,7 +31,6 @@ package com.cubrid.jsp.impl; -import com.cubrid.jsp.Server; import com.cubrid.jsp.context.Context; import com.cubrid.jsp.data.CUBRIDPacker; import com.cubrid.jsp.data.CUBRIDUnpacker; @@ -265,7 +264,7 @@ public void putByOID(CUBRIDOID oid, String[] attributeName, Object values[]) } int type = DBType.getObjectDBtype(values[i]); - packer.packObject(values[i], type, Server.getConfig().getServerCodesetId()); + packer.packObject(values[i], type, Context.getCodesetId()); } } else { packer.packInt(0); @@ -314,7 +313,7 @@ protected CUBRIDUnpacker collectionCmd( if (value != null) { packer.packInt(1); // has value int type = DBType.getObjectDBtype(value); - packer.packObject(value, type, Server.getConfig().getServerCodesetId()); + packer.packObject(value, type, Context.getCodesetId()); } else { packer.packInt(0); // has value } diff --git a/pl_engine/pl_server/src/main/java/com/cubrid/jsp/protocol/BootstrapRequest.java b/pl_engine/pl_server/src/main/java/com/cubrid/jsp/protocol/BootstrapRequest.java index 683fd3115e..f140acdde2 100644 --- a/pl_engine/pl_server/src/main/java/com/cubrid/jsp/protocol/BootstrapRequest.java +++ b/pl_engine/pl_server/src/main/java/com/cubrid/jsp/protocol/BootstrapRequest.java @@ -13,15 +13,10 @@ public BootstrapRequest(CUBRIDUnpacker unpacker) { @Override public void unpack(CUBRIDUnpacker unpacker) { - int size = unpacker.unpackInt(); + int size = (int) unpacker.unpackBigint(); sysParam = new SysParam[size]; - - try { - for (int i = 0; i < size; i++) { - sysParam[i] = new SysParam(unpacker); - } - } catch (Exception e) { - // do nothing + for (int i = 0; i < size; i++) { + sysParam[i] = new SysParam(unpacker); } } diff --git a/pl_engine/pl_server/src/main/java/com/cubrid/jsp/protocol/PrepareArgs.java b/pl_engine/pl_server/src/main/java/com/cubrid/jsp/protocol/PrepareArgs.java index cd723d5ce7..efe301f727 100644 --- a/pl_engine/pl_server/src/main/java/com/cubrid/jsp/protocol/PrepareArgs.java +++ b/pl_engine/pl_server/src/main/java/com/cubrid/jsp/protocol/PrepareArgs.java @@ -37,8 +37,8 @@ public int getTranId() { public void readArgs(CUBRIDUnpacker unpacker) throws TypeMismatchException { groupId = unpacker.unpackBigint(); tranId = unpacker.unpackInt(); - int argCount = unpacker.unpackInt(); + int argCount = unpacker.unpackInt(); if (argCount > 0) { arguments = new Value[argCount]; for (int i = 0; i < arguments.length; i++) { diff --git a/pl_engine/pl_server/src/main/java/com/cubrid/jsp/value/StringValue.java b/pl_engine/pl_server/src/main/java/com/cubrid/jsp/value/StringValue.java index 7e553de145..c3f744499d 100644 --- a/pl_engine/pl_server/src/main/java/com/cubrid/jsp/value/StringValue.java +++ b/pl_engine/pl_server/src/main/java/com/cubrid/jsp/value/StringValue.java @@ -33,6 +33,7 @@ import com.cubrid.jsp.Server; import com.cubrid.jsp.SysParam; +import com.cubrid.jsp.context.Context; import com.cubrid.jsp.data.DBType; import com.cubrid.jsp.exception.TypeMismatchException; import com.cubrid.plcsql.predefined.sp.SpLib; @@ -59,11 +60,11 @@ public StringValue(byte[] value, int codeset) { } public StringValue(byte[] value) { - this(value, Server.getConfig().getServerCodesetId()); + this(value, Context.getCodesetId()); } public StringValue(String value) { - this(value.getBytes(Server.getConfig().getServerCharset())); + this(value.getBytes(Context.getSessionCharset())); } @Override diff --git a/pl_engine/pl_server/src/main/java/com/cubrid/jsp/value/Value.java b/pl_engine/pl_server/src/main/java/com/cubrid/jsp/value/Value.java index 438ccbeb2c..13525b6c68 100644 --- a/pl_engine/pl_server/src/main/java/com/cubrid/jsp/value/Value.java +++ b/pl_engine/pl_server/src/main/java/com/cubrid/jsp/value/Value.java @@ -31,7 +31,7 @@ package com.cubrid.jsp.value; -import com.cubrid.jsp.Server; +import com.cubrid.jsp.context.Context; import com.cubrid.jsp.exception.TypeMismatchException; import com.cubrid.jsp.impl.SUConnection; import cubrid.sql.CUBRIDOID; @@ -53,7 +53,7 @@ public abstract class Value { public Value() { this.mode = IN; - this.codeset = Server.getConfig().getServerCodesetId(); + this.codeset = Context.getCodesetId(); } public void setMode(int mode) { diff --git a/pl_engine/pl_server/src/main/java/com/cubrid/plcsql/predefined/sp/SpLib.java b/pl_engine/pl_server/src/main/java/com/cubrid/plcsql/predefined/sp/SpLib.java index c33ea2ecb2..5e0353a048 100644 --- a/pl_engine/pl_server/src/main/java/com/cubrid/plcsql/predefined/sp/SpLib.java +++ b/pl_engine/pl_server/src/main/java/com/cubrid/plcsql/predefined/sp/SpLib.java @@ -32,6 +32,7 @@ import com.cubrid.jsp.Server; import com.cubrid.jsp.SysParam; +import com.cubrid.jsp.context.Context; import com.cubrid.jsp.value.DateTimeParser; import com.cubrid.plcsql.builtin.DBMS_OUTPUT; import com.cubrid.plcsql.compiler.CoercionScheme; @@ -702,7 +703,7 @@ public static Boolean opNot(Boolean l) { // is null @Operator(coercionScheme = CoercionScheme.ObjectOp) public static Boolean opIsNull(Object l) { - if (Server.getSystemParameterBool(SysParam.ORACLE_STYLE_EMPTY_STRING)) { + if (Context.getSystemParameterBool(SysParam.ORACLE_STYLE_EMPTY_STRING)) { if (EMPTY_STRING.equals(l)) { l = null; } @@ -779,7 +780,7 @@ public static Double opNeg(Double l) { @Operator(coercionScheme = CoercionScheme.ArithOp) public static Object opNeg(Object l) { - if (Server.getSystemParameterBool(SysParam.ORACLE_STYLE_EMPTY_STRING)) { + if (Context.getSystemParameterBool(SysParam.ORACLE_STYLE_EMPTY_STRING)) { if (EMPTY_STRING.equals(l)) { l = null; } @@ -854,7 +855,7 @@ public static Long opBitCompli(Long l) { @Operator(coercionScheme = CoercionScheme.IntArithOp) public static Object opBitCompli(Object l) { - if (Server.getSystemParameterBool(SysParam.ORACLE_STYLE_EMPTY_STRING)) { + if (Context.getSystemParameterBool(SysParam.ORACLE_STYLE_EMPTY_STRING)) { if (EMPTY_STRING.equals(l)) { l = null; } @@ -941,7 +942,7 @@ public static Boolean opEq(Boolean l, Boolean r) { @Operator(coercionScheme = CoercionScheme.CompOp) public static Boolean opEq(String l, String r) { - if (Server.getSystemParameterBool(SysParam.ORACLE_STYLE_EMPTY_STRING)) { + if (Context.getSystemParameterBool(SysParam.ORACLE_STYLE_EMPTY_STRING)) { if (EMPTY_STRING.equals(l)) { l = null; } @@ -954,7 +955,7 @@ public static Boolean opEq(String l, String r) { } public static Boolean opEqChar(String l, String r) { - if (Server.getSystemParameterBool(SysParam.ORACLE_STYLE_EMPTY_STRING)) { + if (Context.getSystemParameterBool(SysParam.ORACLE_STYLE_EMPTY_STRING)) { if (EMPTY_STRING.equals(l)) { l = null; } @@ -1037,7 +1038,7 @@ public static Boolean opEqTimestamp(Timestamp l, Timestamp r) { @Operator(coercionScheme = CoercionScheme.CompOp) public static Boolean opEq(Object l, Object r) { - if (Server.getSystemParameterBool(SysParam.ORACLE_STYLE_EMPTY_STRING)) { + if (Context.getSystemParameterBool(SysParam.ORACLE_STYLE_EMPTY_STRING)) { if (EMPTY_STRING.equals(l)) { l = null; } @@ -1062,7 +1063,7 @@ public static Boolean opNullSafeEq(Boolean l, Boolean r) { @Operator(coercionScheme = CoercionScheme.CompOp) public static Boolean opNullSafeEq(String l, String r) { - if (Server.getSystemParameterBool(SysParam.ORACLE_STYLE_EMPTY_STRING)) { + if (Context.getSystemParameterBool(SysParam.ORACLE_STYLE_EMPTY_STRING)) { if (EMPTY_STRING.equals(l)) { l = null; } @@ -1075,7 +1076,7 @@ public static Boolean opNullSafeEq(String l, String r) { } public static Boolean opNullSafeEqChar(String l, String r) { - if (Server.getSystemParameterBool(SysParam.ORACLE_STYLE_EMPTY_STRING)) { + if (Context.getSystemParameterBool(SysParam.ORACLE_STYLE_EMPTY_STRING)) { if (EMPTY_STRING.equals(l)) { l = null; } @@ -1170,7 +1171,7 @@ public static Boolean opNullSafeEqTimestamp(Timestamp l, Timestamp r) { @Operator(coercionScheme = CoercionScheme.CompOp) public static Boolean opNullSafeEq(Object l, Object r) { - if (Server.getSystemParameterBool(SysParam.ORACLE_STYLE_EMPTY_STRING)) { + if (Context.getSystemParameterBool(SysParam.ORACLE_STYLE_EMPTY_STRING)) { if (EMPTY_STRING.equals(l)) { l = null; } @@ -1198,7 +1199,7 @@ public static Boolean opNeq(Boolean l, Boolean r) { @Operator(coercionScheme = CoercionScheme.CompOp) public static Boolean opNeq(String l, String r) { - if (Server.getSystemParameterBool(SysParam.ORACLE_STYLE_EMPTY_STRING)) { + if (Context.getSystemParameterBool(SysParam.ORACLE_STYLE_EMPTY_STRING)) { if (EMPTY_STRING.equals(l)) { l = null; } @@ -1285,7 +1286,7 @@ public static Boolean opNeqTimestamp(Timestamp l, Timestamp r) { @Operator(coercionScheme = CoercionScheme.CompOp) public static Boolean opNeq(Object l, Object r) { - if (Server.getSystemParameterBool(SysParam.ORACLE_STYLE_EMPTY_STRING)) { + if (Context.getSystemParameterBool(SysParam.ORACLE_STYLE_EMPTY_STRING)) { if (EMPTY_STRING.equals(l)) { l = null; } @@ -1311,7 +1312,7 @@ public static Boolean opLe(Boolean l, Boolean r) { @Operator(coercionScheme = CoercionScheme.CompOp) public static Boolean opLe(String l, String r) { - if (Server.getSystemParameterBool(SysParam.ORACLE_STYLE_EMPTY_STRING)) { + if (Context.getSystemParameterBool(SysParam.ORACLE_STYLE_EMPTY_STRING)) { if (EMPTY_STRING.equals(l)) { l = null; } @@ -1324,7 +1325,7 @@ public static Boolean opLe(String l, String r) { } public static Boolean opLeChar(String l, String r) { - if (Server.getSystemParameterBool(SysParam.ORACLE_STYLE_EMPTY_STRING)) { + if (Context.getSystemParameterBool(SysParam.ORACLE_STYLE_EMPTY_STRING)) { if (EMPTY_STRING.equals(l)) { l = null; } @@ -1407,7 +1408,7 @@ public static Boolean opLeTimestamp(Timestamp l, Timestamp r) { @Operator(coercionScheme = CoercionScheme.CompOp) public static Boolean opLe(Object l, Object r) { - if (Server.getSystemParameterBool(SysParam.ORACLE_STYLE_EMPTY_STRING)) { + if (Context.getSystemParameterBool(SysParam.ORACLE_STYLE_EMPTY_STRING)) { if (EMPTY_STRING.equals(l)) { l = null; } @@ -1431,7 +1432,7 @@ public static Boolean opGe(Boolean l, Boolean r) { @Operator(coercionScheme = CoercionScheme.CompOp) public static Boolean opGe(String l, String r) { - if (Server.getSystemParameterBool(SysParam.ORACLE_STYLE_EMPTY_STRING)) { + if (Context.getSystemParameterBool(SysParam.ORACLE_STYLE_EMPTY_STRING)) { if (EMPTY_STRING.equals(l)) { l = null; } @@ -1444,7 +1445,7 @@ public static Boolean opGe(String l, String r) { } public static Boolean opGeChar(String l, String r) { - if (Server.getSystemParameterBool(SysParam.ORACLE_STYLE_EMPTY_STRING)) { + if (Context.getSystemParameterBool(SysParam.ORACLE_STYLE_EMPTY_STRING)) { if (EMPTY_STRING.equals(l)) { l = null; } @@ -1527,7 +1528,7 @@ public static Boolean opGeTimestamp(Timestamp l, Timestamp r) { @Operator(coercionScheme = CoercionScheme.CompOp) public static Boolean opGe(Object l, Object r) { - if (Server.getSystemParameterBool(SysParam.ORACLE_STYLE_EMPTY_STRING)) { + if (Context.getSystemParameterBool(SysParam.ORACLE_STYLE_EMPTY_STRING)) { if (EMPTY_STRING.equals(l)) { l = null; } @@ -1551,7 +1552,7 @@ public static Boolean opLt(Boolean l, Boolean r) { @Operator(coercionScheme = CoercionScheme.CompOp) public static Boolean opLt(String l, String r) { - if (Server.getSystemParameterBool(SysParam.ORACLE_STYLE_EMPTY_STRING)) { + if (Context.getSystemParameterBool(SysParam.ORACLE_STYLE_EMPTY_STRING)) { if (EMPTY_STRING.equals(l)) { l = null; } @@ -1564,7 +1565,7 @@ public static Boolean opLt(String l, String r) { } public static Boolean opLtChar(String l, String r) { - if (Server.getSystemParameterBool(SysParam.ORACLE_STYLE_EMPTY_STRING)) { + if (Context.getSystemParameterBool(SysParam.ORACLE_STYLE_EMPTY_STRING)) { if (EMPTY_STRING.equals(l)) { l = null; } @@ -1647,7 +1648,7 @@ public static Boolean opLtTimestamp(Timestamp l, Timestamp r) { @Operator(coercionScheme = CoercionScheme.CompOp) public static Boolean opLt(Object l, Object r) { - if (Server.getSystemParameterBool(SysParam.ORACLE_STYLE_EMPTY_STRING)) { + if (Context.getSystemParameterBool(SysParam.ORACLE_STYLE_EMPTY_STRING)) { if (EMPTY_STRING.equals(l)) { l = null; } @@ -1672,7 +1673,7 @@ public static Boolean opGt(Boolean l, Boolean r) { @Operator(coercionScheme = CoercionScheme.CompOp) public static Boolean opGt(String l, String r) { - if (Server.getSystemParameterBool(SysParam.ORACLE_STYLE_EMPTY_STRING)) { + if (Context.getSystemParameterBool(SysParam.ORACLE_STYLE_EMPTY_STRING)) { if (EMPTY_STRING.equals(l)) { l = null; } @@ -1685,7 +1686,7 @@ public static Boolean opGt(String l, String r) { } public static Boolean opGtChar(String l, String r) { - if (Server.getSystemParameterBool(SysParam.ORACLE_STYLE_EMPTY_STRING)) { + if (Context.getSystemParameterBool(SysParam.ORACLE_STYLE_EMPTY_STRING)) { if (EMPTY_STRING.equals(l)) { l = null; } @@ -1768,7 +1769,7 @@ public static Boolean opGtTimestamp(Timestamp l, Timestamp r) { @Operator(coercionScheme = CoercionScheme.CompOp) public static Boolean opGt(Object l, Object r) { - if (Server.getSystemParameterBool(SysParam.ORACLE_STYLE_EMPTY_STRING)) { + if (Context.getSystemParameterBool(SysParam.ORACLE_STYLE_EMPTY_STRING)) { if (EMPTY_STRING.equals(l)) { l = null; } @@ -1796,7 +1797,7 @@ public static Boolean opBetween(Boolean o, Boolean lower, Boolean upper) { @Operator(coercionScheme = CoercionScheme.NAryCompOp) public static Boolean opBetween(String o, String lower, String upper) { - if (Server.getSystemParameterBool(SysParam.ORACLE_STYLE_EMPTY_STRING)) { + if (Context.getSystemParameterBool(SysParam.ORACLE_STYLE_EMPTY_STRING)) { if (EMPTY_STRING.equals(o)) { o = null; } @@ -1815,7 +1816,7 @@ public static Boolean opBetween(String o, String lower, String upper) { } public static Boolean opBetweenChar(String o, String lower, String upper) { - if (Server.getSystemParameterBool(SysParam.ORACLE_STYLE_EMPTY_STRING)) { + if (Context.getSystemParameterBool(SysParam.ORACLE_STYLE_EMPTY_STRING)) { if (EMPTY_STRING.equals(o)) { o = null; } @@ -1930,7 +1931,7 @@ public static Boolean opBetweenTimestamp(Timestamp o, Timestamp lower, Timestamp @Operator(coercionScheme = CoercionScheme.NAryCompOp) public static Boolean opBetween(Object o, Object lower, Object upper) { - if (Server.getSystemParameterBool(SysParam.ORACLE_STYLE_EMPTY_STRING)) { + if (Context.getSystemParameterBool(SysParam.ORACLE_STYLE_EMPTY_STRING)) { if (EMPTY_STRING.equals(o)) { o = null; } @@ -1968,7 +1969,7 @@ public static Boolean opIn(String o, String... arr) { public static Boolean opInChar(String o, String... arr) { assert arr != null; - if (Server.getSystemParameterBool(SysParam.ORACLE_STYLE_EMPTY_STRING)) { + if (Context.getSystemParameterBool(SysParam.ORACLE_STYLE_EMPTY_STRING)) { if (EMPTY_STRING.equals(o)) { o = null; } @@ -1981,7 +1982,7 @@ public static Boolean opInChar(String o, String... arr) { boolean nullFound = false; for (String p : arr) { - if (Server.getSystemParameterBool(SysParam.ORACLE_STYLE_EMPTY_STRING)) { + if (Context.getSystemParameterBool(SysParam.ORACLE_STYLE_EMPTY_STRING)) { if (EMPTY_STRING.equals(p)) { p = null; } @@ -2086,7 +2087,7 @@ public static Boolean opInTimestamp(Timestamp o, Timestamp... arr) { public static Boolean opIn(Object o, Object... arr) { assert arr != null; - if (Server.getSystemParameterBool(SysParam.ORACLE_STYLE_EMPTY_STRING)) { + if (Context.getSystemParameterBool(SysParam.ORACLE_STYLE_EMPTY_STRING)) { if (EMPTY_STRING.equals(o)) { o = null; } @@ -2097,7 +2098,7 @@ public static Boolean opIn(Object o, Object... arr) { } boolean nullFound = false; for (Object p : arr) { - if (Server.getSystemParameterBool(SysParam.ORACLE_STYLE_EMPTY_STRING)) { + if (Context.getSystemParameterBool(SysParam.ORACLE_STYLE_EMPTY_STRING)) { if (EMPTY_STRING.equals(p)) { p = null; } @@ -2197,7 +2198,7 @@ public static Double opMult(Double l, Double r) { @Operator(coercionScheme = CoercionScheme.ArithOp) public static Object opMult(Object l, Object r) { - if (Server.getSystemParameterBool(SysParam.ORACLE_STYLE_EMPTY_STRING)) { + if (Context.getSystemParameterBool(SysParam.ORACLE_STYLE_EMPTY_STRING)) { if (EMPTY_STRING.equals(l)) { l = null; } @@ -2223,7 +2224,7 @@ public static Object opDiv(Short l, Short r) { if (r.equals((short) 0)) { throw new ZERO_DIVIDE(); } - if (Server.getSystemParameterBool(SysParam.ORACLE_COMPAT_NUMBER_BEHAVIOR)) { + if (Context.getSystemParameterBool(SysParam.ORACLE_COMPAT_NUMBER_BEHAVIOR)) { return opDiv(BigDecimal.valueOf(l.longValue()), BigDecimal.valueOf(r.longValue())); } else { return (short) (l / r); @@ -2238,7 +2239,7 @@ public static Object opDiv(Integer l, Integer r) { if (r.equals(0)) { throw new ZERO_DIVIDE(); } - if (Server.getSystemParameterBool(SysParam.ORACLE_COMPAT_NUMBER_BEHAVIOR)) { + if (Context.getSystemParameterBool(SysParam.ORACLE_COMPAT_NUMBER_BEHAVIOR)) { return opDiv(BigDecimal.valueOf(l.longValue()), BigDecimal.valueOf(r.longValue())); } else { return l / r; @@ -2254,7 +2255,7 @@ public static Object opDiv(Long l, Long r) { throw new ZERO_DIVIDE(); } - if (Server.getSystemParameterBool(SysParam.ORACLE_COMPAT_NUMBER_BEHAVIOR)) { + if (Context.getSystemParameterBool(SysParam.ORACLE_COMPAT_NUMBER_BEHAVIOR)) { return opDiv(BigDecimal.valueOf(l), BigDecimal.valueOf(r)); } else { return l / r; @@ -2276,7 +2277,7 @@ public static BigDecimal opDiv(BigDecimal l, BigDecimal r) { int s2 = r.scale(); int scale; - if (Server.getSystemParameterBool(SysParam.COMPAT_NUMERIC_DIVISION_SCALE)) { + if (Context.getSystemParameterBool(SysParam.COMPAT_NUMERIC_DIVISION_SCALE)) { scale = Math.max(s1, s2); } else { scale = Math.max(9, Math.max(s1, s2)); @@ -2325,7 +2326,7 @@ public static Double opDiv(Double l, Double r) { @Operator(coercionScheme = CoercionScheme.ArithOp) public static Object opDiv(Object l, Object r) { - if (Server.getSystemParameterBool(SysParam.ORACLE_STYLE_EMPTY_STRING)) { + if (Context.getSystemParameterBool(SysParam.ORACLE_STYLE_EMPTY_STRING)) { if (EMPTY_STRING.equals(l)) { l = null; } @@ -2378,7 +2379,7 @@ public static Long opDivInt(Long l, Long r) { @Operator(coercionScheme = CoercionScheme.IntArithOp) public static Object opDivInt(Object l, Object r) { - if (Server.getSystemParameterBool(SysParam.ORACLE_STYLE_EMPTY_STRING)) { + if (Context.getSystemParameterBool(SysParam.ORACLE_STYLE_EMPTY_STRING)) { if (EMPTY_STRING.equals(l)) { l = null; } @@ -2431,7 +2432,7 @@ public static Long opMod(Long l, Long r) { @Operator(coercionScheme = CoercionScheme.IntArithOp) public static Object opMod(Object l, Object r) { - if (Server.getSystemParameterBool(SysParam.ORACLE_STYLE_EMPTY_STRING)) { + if (Context.getSystemParameterBool(SysParam.ORACLE_STYLE_EMPTY_STRING)) { if (EMPTY_STRING.equals(l)) { l = null; } @@ -2451,7 +2452,7 @@ public static Object opMod(Object l, Object r) { // + @Operator(coercionScheme = CoercionScheme.ArithOp) public static String opAdd(String l, String r) { - if (Server.getSystemParameterBool(SysParam.ORACLE_STYLE_EMPTY_STRING)) { + if (Context.getSystemParameterBool(SysParam.ORACLE_STYLE_EMPTY_STRING)) { if (l == null) { l = EMPTY_STRING; } @@ -2645,7 +2646,7 @@ public static Timestamp opAddTimestamp(Long l, Timestamp r) { @Operator(coercionScheme = CoercionScheme.ArithOp) public static Object opAdd(Object l, Object r) { - if (Server.getSystemParameterBool(SysParam.ORACLE_STYLE_EMPTY_STRING)) { + if (Context.getSystemParameterBool(SysParam.ORACLE_STYLE_EMPTY_STRING)) { if (EMPTY_STRING.equals(l)) { l = null; } @@ -2879,7 +2880,7 @@ public static Timestamp opSubtractTimestamp(Timestamp l, Long r) { @Operator(coercionScheme = CoercionScheme.ArithOp) public static Object opSubtract(Object l, Object r) { - if (Server.getSystemParameterBool(SysParam.ORACLE_STYLE_EMPTY_STRING)) { + if (Context.getSystemParameterBool(SysParam.ORACLE_STYLE_EMPTY_STRING)) { if (EMPTY_STRING.equals(l)) { l = null; } @@ -2899,7 +2900,7 @@ public static Object opSubtract(Object l, Object r) { // || @Operator(coercionScheme = CoercionScheme.StringOp) public static String opConcat(String l, String r) { - if (Server.getSystemParameterBool(SysParam.ORACLE_STYLE_EMPTY_STRING)) { + if (Context.getSystemParameterBool(SysParam.ORACLE_STYLE_EMPTY_STRING)) { if (l == null) { l = EMPTY_STRING; } @@ -3203,7 +3204,7 @@ public static String convDoubleToString(Double e) { return null; } - if (Server.getSystemParameterBool(SysParam.ORACLE_COMPAT_NUMBER_BEHAVIOR)) { + if (Context.getSystemParameterBool(SysParam.ORACLE_COMPAT_NUMBER_BEHAVIOR)) { BigDecimal bd = new BigDecimal(e.doubleValue(), doubleToStringContext); return detachTrailingZeros(bd.toPlainString()); } else { @@ -3287,7 +3288,7 @@ public static String convFloatToString(Float e) { return null; } - if (Server.getSystemParameterBool(SysParam.ORACLE_COMPAT_NUMBER_BEHAVIOR)) { + if (Context.getSystemParameterBool(SysParam.ORACLE_COMPAT_NUMBER_BEHAVIOR)) { BigDecimal bd = new BigDecimal(e.doubleValue(), floatToStringContext); return detachTrailingZeros(bd.toPlainString()); } else { @@ -3362,7 +3363,7 @@ public static String convNumericToString(BigDecimal e) { return null; } - if (Server.getSystemParameterBool(SysParam.ORACLE_COMPAT_NUMBER_BEHAVIOR)) { + if (Context.getSystemParameterBool(SysParam.ORACLE_COMPAT_NUMBER_BEHAVIOR)) { return detachTrailingZeros(e.toPlainString()); } else { return e.toString(); @@ -4276,7 +4277,7 @@ private static Boolean commonOpGt(Comparable l, Comparable r) { private static Boolean commonOpIn(Object o, Object... arr) { assert arr != null; - if (Server.getSystemParameterBool(SysParam.ORACLE_STYLE_EMPTY_STRING)) { + if (Context.getSystemParameterBool(SysParam.ORACLE_STYLE_EMPTY_STRING)) { if (EMPTY_STRING.equals(o)) { o = null; } @@ -4287,7 +4288,7 @@ private static Boolean commonOpIn(Object o, Object... arr) { } boolean nullFound = false; for (Object p : arr) { - if (Server.getSystemParameterBool(SysParam.ORACLE_STYLE_EMPTY_STRING)) { + if (Context.getSystemParameterBool(SysParam.ORACLE_STYLE_EMPTY_STRING)) { if (EMPTY_STRING.equals(p)) { p = null; } diff --git a/src/base/system_parameter.c b/src/base/system_parameter.c index 76ffde8b29..1f60753484 100644 --- a/src/base/system_parameter.c +++ b/src/base/system_parameter.c @@ -763,6 +763,8 @@ static const char sysprm_ha_conf_file_name[] = "cubrid_ha.conf"; #define PRM_NAME_ENABLE_MEMORY_MONITORING "enable_memory_monitoring" +#define PRM_NAME_STORED_PROCEDURE_DUMP_ICODE "stored_procedure_dump_icode" + /* * Note about ERROR_LIST and INTEGER_LIST type * ERROR_LIST type is an array of bool type with the size of -(ER_LAST_ERROR) @@ -2339,6 +2341,10 @@ bool PRM_STORED_PROCEDURE_UDS = true; static bool prm_stored_procedure_uds_default = true; static unsigned int prm_stored_procedure_uds_flag = 0; +bool PRM_STORED_PROCEDURE_DUMP_ICODE = false; +static bool prm_stored_procedure_dump_icode_default = false; +static unsigned int prm_stored_procedure_dump_icode_flag = 0; + bool PRM_ALLOW_TRUNCATED_STRING = false; static bool prm_allow_truncated_string_default = false; static unsigned int prm_allow_truncated_string_flag = 0; @@ -6514,6 +6520,17 @@ SYSPRM_PARAM prm_Def[] = { (void *) NULL, (void *) NULL, (char *) NULL, (DUP_PRM_FUNC) NULL, + (DUP_PRM_FUNC) NULL}, + {PRM_ID_STORED_PROCEDURE_DUMP_ICODE, + PRM_NAME_STORED_PROCEDURE_DUMP_ICODE, + (PRM_FOR_CLIENT | PRM_FOR_SESSION | PRM_FOR_SERVER | PRM_USER_CHANGE | PRM_FOR_PL_CONTEXT), + PRM_BOOLEAN, + &prm_stored_procedure_dump_icode_flag, + (void *) &prm_stored_procedure_dump_icode_default, + (void *) &PRM_STORED_PROCEDURE_DUMP_ICODE, + (void *) NULL, (void *) NULL, + (char *) NULL, + (DUP_PRM_FUNC) NULL, (DUP_PRM_FUNC) NULL} }; @@ -9279,7 +9296,7 @@ xsysprm_dump_server_parameters (FILE * outfp) * */ SYSPRM_ASSIGN_VALUE * -xsysprm_get_pl_context_parameters (void) +xsysprm_get_pl_context_parameters (int flag) { SYSPRM_ASSIGN_VALUE *pl_ctx_values = NULL, *last_assign = NULL; SYSPRM_PARAM *prm = NULL; @@ -9288,7 +9305,7 @@ xsysprm_get_pl_context_parameters (void) for (i = 0; i < NUM_PRM; i++) { prm = GET_PRM (i); - if (PRM_IS_FOR_PL_CONTEXT (prm->static_flag)) + if (PRM_IS_FOR_PL_CONTEXT (prm->static_flag) && (prm->static_flag & flag)) { SYSPRM_ASSIGN_VALUE *change_val = (SYSPRM_ASSIGN_VALUE *) malloc (sizeof (SYSPRM_ASSIGN_VALUE)); if (change_val == NULL) @@ -10383,7 +10400,15 @@ sysprm_set_value (SYSPRM_PARAM * prm, SYSPRM_VALUE value, bool set_flag, bool du } } - return sysprm_set_session_parameter_value (param, id, value); + SYSPRM_ERR err = sysprm_set_session_parameter_value (param, id, value); + + // err always returns PRM_ERR_NO_ERROR + if (PRM_IS_FOR_PL_CONTEXT (GET_PRM_STATIC_FLAG (id))) + { + (void) session_set_pl_session_parameter (thread_p, id); + } + + return err; } /* if prm is not for session or if session_parameters have not been initialized just set the system parameter stored diff --git a/src/base/system_parameter.h b/src/base/system_parameter.h index 354e0d348d..cd4e59d02c 100644 --- a/src/base/system_parameter.h +++ b/src/base/system_parameter.h @@ -493,8 +493,9 @@ enum param_id PRM_ID_STORED_PROCEDURE_JVM_OPTIONS, PRM_ID_STORED_PROCEDURE_DEBUG, PRM_ID_STORED_PROCEDURE_UDS, + PRM_ID_STORED_PROCEDURE_DUMP_ICODE, /* change PRM_LAST_ID when adding new system parameters */ - PRM_LAST_ID = PRM_ID_STORED_PROCEDURE_UDS + PRM_LAST_ID = PRM_ID_STORED_PROCEDURE_DUMP_ICODE }; typedef enum param_id PARAM_ID; @@ -621,6 +622,8 @@ extern "C" #define PRM_DEPRECATED 0x40000000 /* is deprecated */ #define PRM_OBSOLETED 0x80000000 /* is obsoleted */ +#define PRM_ALL_FLAGS 0xFFFFFFFF /* all flags */ + /* * Dynamic flags */ @@ -739,7 +742,7 @@ extern "C" extern void xsysprm_obtain_server_parameters (SYSPRM_ASSIGN_VALUE * prm_values); extern SYSPRM_ASSIGN_VALUE *xsysprm_get_force_server_parameters (void); extern void xsysprm_dump_server_parameters (FILE * fp); - extern SYSPRM_ASSIGN_VALUE *xsysprm_get_pl_context_parameters (void); + extern SYSPRM_ASSIGN_VALUE *xsysprm_get_pl_context_parameters (int flag); #endif /* !CS_MODE */ extern int sysprm_set_force (const char *pname, const char *pvalue); diff --git a/src/session/session.c b/src/session/session.c index fab62a4997..30c5ae0375 100644 --- a/src/session/session.c +++ b/src/session/session.c @@ -3056,6 +3056,26 @@ session_state_verify_ref_count (THREAD_ENTRY * thread_p, SESSION_STATE * session * */ #if defined (SERVER_MODE) + +int +session_set_pl_session_parameter (THREAD_ENTRY * thread_p, PARAM_ID id) +{ + SESSION_STATE *state_p = NULL; + + state_p = session_get_session_state (thread_p); + if (state_p == NULL) + { + return ER_FAILED; + } + + if (state_p->pl_session_p != NULL) + { + state_p->pl_session_p->mark_session_param_changed (id); + } + + return NO_ERROR; +} + int session_state_increase_ref_count (THREAD_ENTRY * thread_p, SESSION_STATE * state_p) { diff --git a/src/session/session.h b/src/session/session.h index 6b55c12afe..1b1a7407d5 100644 --- a/src/session/session.h +++ b/src/session/session.h @@ -75,6 +75,7 @@ extern bool session_is_queryid_idle (THREAD_ENTRY * thread_p, const QUERY_ID que extern int session_get_exec_stats_and_clear (THREAD_ENTRY * thread_p, const DB_VALUE * name, DB_VALUE * result); extern SESSION_PARAM *session_get_session_parameter (THREAD_ENTRY * thread_p, PARAM_ID id); #if defined (SERVER_MODE) +extern int session_set_pl_session_parameter (THREAD_ENTRY * thread_p, PARAM_ID id); extern int session_state_increase_ref_count (THREAD_ENTRY * thread_p, struct session_state *state_p); extern int session_state_decrease_ref_count (THREAD_ENTRY * thread_p, struct session_state *state_p); #endif diff --git a/src/sp/jsp_cl.cpp b/src/sp/jsp_cl.cpp index 86c4d3b296..fa52a010e5 100644 --- a/src/sp/jsp_cl.cpp +++ b/src/sp/jsp_cl.cpp @@ -1876,7 +1876,7 @@ alter_stored_procedure_code (PARSER_CONTEXT *parser, MOP sp_mop, const char *nam goto error; } - db_make_string (&value, code_info.name.data ()); + db_make_string (&value, sp_info.target_class.data ()); err = dbt_put_internal (obt_p, SP_ATTR_TARGET_CLASS, &value); pr_clear_value (&value); if (err != NO_ERROR) @@ -1884,6 +1884,14 @@ alter_stored_procedure_code (PARSER_CONTEXT *parser, MOP sp_mop, const char *nam goto error; } + db_make_string (&value, sp_info.target_method.data ()); + err = dbt_put_internal (obt_p, SP_ATTR_TARGET_METHOD, &value); + pr_clear_value (&value); + if (err != NO_ERROR) + { + goto error; + } + object_p = dbt_finish_object (obt_p); if (!object_p) { diff --git a/src/sp/pl_compile_handler.cpp b/src/sp/pl_compile_handler.cpp index f250963b18..3dc4ee2179 100644 --- a/src/sp/pl_compile_handler.cpp +++ b/src/sp/pl_compile_handler.cpp @@ -86,8 +86,11 @@ namespace cubpl int error_code = NO_ERROR; SESSION_ID sid = get_session ()->get_id (); + // get changed session parameters + const std::vector &session_params = get_session ()->obtain_session_parameters (true); + m_stack->set_command (SP_CODE_COMPILE); - error_code = m_stack->send_data_to_java (req); + error_code = m_stack->send_data_to_java (session_params, req); if (error_code != NO_ERROR) { return error_code; diff --git a/src/sp/pl_executor.cpp b/src/sp/pl_executor.cpp index 86f113f6f6..340eabccf0 100644 --- a/src/sp/pl_executor.cpp +++ b/src/sp/pl_executor.cpp @@ -330,11 +330,14 @@ namespace cubpl TRANID tid = m_stack->get_tran_id (); m_stack->set_command (SP_CODE_INVOKE); + + // get changed session parameters + const std::vector &session_params = get_session ()->obtain_session_parameters (true); + prepare_args prepare_arg ((std::uint64_t) this, tid, METHOD_TYPE_PLCSQL, m_args); invoke_java invoke_arg ((std::uint64_t) this, tid, &m_sig, prm_get_bool_value (PRM_ID_PL_TRANSACTION_CONTROL)); - error = m_stack->send_data_to_java (prepare_arg, invoke_arg); - + error = m_stack->send_data_to_java (session_params, prepare_arg, invoke_arg); return error; } diff --git a/src/sp/pl_session.cpp b/src/sp/pl_session.cpp index 331c81a432..1f7025fbf2 100644 --- a/src/sp/pl_session.cpp +++ b/src/sp/pl_session.cpp @@ -468,4 +468,126 @@ namespace cubpl m_param_info = param_info; } + const std::vector + session::obtain_session_parameters (bool reset) + { + std::vector changed_sys_params; + SYSPRM_ASSIGN_VALUE *session_params = xsysprm_get_pl_context_parameters (PRM_USER_CHANGE | PRM_FOR_SESSION); + while (session_params != NULL) + { + if (m_session_param_changed_ids.find (session_params->prm_id) == m_session_param_changed_ids.end ()) + { + session_params = session_params->next; + continue; + } + + { + changed_sys_params.emplace_back (session_params); + } + + session_params = session_params->next; + } + + if (session_params) + { + sysprm_free_assign_values (&session_params); + } + + if (reset) + { + m_session_param_changed_ids.clear (); + } + + return changed_sys_params; + } + + void + session::mark_session_param_changed (PARAM_ID prm_id) + { + m_session_param_changed_ids.insert (prm_id); + } + +#define SYS_PARAM_PACKER_ARGS() \ + prm_id, prm_type, prm_value + + sys_param::sys_param (SYSPRM_ASSIGN_VALUE *db_param) + { + prm_id = (int) db_param->prm_id; + prm_type = GET_PRM_DATATYPE (db_param->prm_id); + + const SYSPRM_PARAM *prm = GET_PRM (db_param->prm_id); + set_prm_value (prm); + } + + void + sys_param::set_prm_value (const SYSPRM_PARAM *prm) + { + if (PRM_IS_BOOLEAN (prm)) + { + bool val = prm_get_bool_value (prm->id); + prm_value = val ? "true" : "false"; + } + else if (PRM_IS_STRING (prm)) + { + const char *val = prm_get_string_value (prm->id); + if (val == NULL) + { + switch (prm->id) + { + case PRM_ID_INTL_COLLATION: + val = lang_get_collation_name (LANG_GET_BINARY_COLLATION (LANG_SYS_CODESET)); + break; + case PRM_ID_INTL_DATE_LANG: + case PRM_ID_INTL_NUMBER_LANG: + val = lang_get_Lang_name (); + break; + case PRM_ID_TIMEZONE: + val = prm_get_string_value (PRM_ID_SERVER_TIMEZONE); + break; + default: + /* do nothing */ + break; + } + } + prm_value = val; + } + else if (PRM_IS_INTEGER (prm)) + { + int val = prm_get_integer_value (prm->id); + prm_value = std::to_string (val); + } + else if (PRM_IS_BIGINT (prm)) + { + UINT64 val = prm_get_bigint_value (prm->id); + prm_value = std::to_string (val); + } + else if (PRM_IS_FLOAT (prm)) + { + float val = prm_get_float_value (prm->id); + prm_value = std::to_string (val); + } + else + { + assert (false); + prm_value = "*unknown*"; + } + } + + void + sys_param::pack (cubpacking::packer &serializator) const + { + serializator.pack_all (SYS_PARAM_PACKER_ARGS()); + } + + size_t + sys_param::get_packed_size (cubpacking::packer &serializator, std::size_t start_offset) const + { + return serializator.get_all_packed_size_starting_offset (start_offset, SYS_PARAM_PACKER_ARGS ()); + } + + void + sys_param::unpack (cubpacking::unpacker &deserializator) + { + deserializator.unpack_all (SYS_PARAM_PACKER_ARGS ()); + } } // cubmethod diff --git a/src/sp/pl_session.hpp b/src/sp/pl_session.hpp index b8282958bf..b1ac6bfb0c 100644 --- a/src/sp/pl_session.hpp +++ b/src/sp/pl_session.hpp @@ -34,8 +34,10 @@ #include #include -#include "pl_connection.hpp" +#include "system_parameter.h" +#include "packable_object.hpp" +#include "pl_connection.hpp" #include "pl_execution_stack_context.hpp" #include "pl_signature.hpp" @@ -60,6 +62,21 @@ namespace cubpl using THREAD_ENTRY_IDX = int; using QUERY_ID = std::uint64_t; + struct EXPORT_IMPORT sys_param : public cubpacking::packable_object + { + int prm_id; + int prm_type; + std::string prm_value; + + sys_param (SYSPRM_ASSIGN_VALUE *db_param); + + void set_prm_value (const SYSPRM_PARAM *prm); + + void pack (cubpacking::packer &serializator) const override; + void unpack (cubpacking::unpacker &deserializator) override; + size_t get_packed_size (cubpacking::packer &serializator, std::size_t start_offset) const override; + }; + class session { public: @@ -115,6 +132,9 @@ namespace cubpl cubmethod::db_parameter_info *get_db_parameter_info () const; void set_db_parameter_info (cubmethod::db_parameter_info *param_info); + const std::vector obtain_session_parameters (bool reset); + void mark_session_param_changed (PARAM_ID prm_id); + private: execution_stack *top_stack_internal (); void destroy_all_cursors (); @@ -128,7 +148,6 @@ namespace cubpl exec_stack_id_type m_exec_stack; // runtime stack (implemented using vector) int m_stack_idx; - cursor_map_type m_cursor_map; // server-side cursor storage exec_stack_id_type m_deferred_free_stack; @@ -137,6 +156,10 @@ namespace cubpl cubmethod::db_parameter_info *m_param_info; + // session parameters + std::unordered_set m_session_param_changed_ids; + + // interrupt bool m_is_interrupted; int m_interrupt_id; std::string m_interrupt_msg; diff --git a/src/sp/pl_sr.cpp b/src/sp/pl_sr.cpp index b567cf5e7e..76860e1c82 100644 --- a/src/sp/pl_sr.cpp +++ b/src/sp/pl_sr.cpp @@ -53,6 +53,7 @@ #include "error_manager.h" #include "method_struct_invoke.hpp" #include "method_struct_value.hpp" +#include "pl_session.hpp" // XXX: SHOULD BE THE LAST INCLUDE HEADER #include "memory_wrapper.hpp" @@ -63,6 +64,7 @@ namespace cubpl ////////////////////////////////////////////////////////////////////////// class server_monitor_task; + struct bootstrap_request; /********************************************************************* * server_manager - declaration @@ -97,6 +99,11 @@ namespace cubpl */ connection_pool *get_connection_pool (); + /* + * get_pl_ctx_params() - get the PL context parameters + */ + SYSPRM_ASSIGN_VALUE *get_pl_ctx_params () const; + private: server_monitor_task *m_server_monitor_task; @@ -105,6 +112,8 @@ namespace cubpl #if defined (SERVER_MODE) cubthread::daemon *m_monitor_helper_daemon = nullptr; #endif + + SYSPRM_ASSIGN_VALUE *m_pl_ctx_params; }; /********************************************************************* @@ -170,23 +179,18 @@ namespace cubpl const char *m_argv[3]; connection_pool *m_sys_conn_pool; + bootstrap_request *m_bootstrap_request; std::mutex m_monitor_mutex; std::condition_variable m_monitor_cv; }; - struct pl_ctx_params - { - int param_id; - DB_VALUE param_value; - }; - struct bootstrap_request : public cubpacking::packable_object { - std::vector static_params; + std::vector server_params; bootstrap_request (SYSPRM_ASSIGN_VALUE *pl_ctx_values); - ~bootstrap_request (); + ~bootstrap_request () = default; void pack (cubpacking::packer &serializator) const override; void unpack (cubpacking::unpacker &deserializator) override; @@ -207,6 +211,9 @@ namespace cubpl m_monitor_helper_daemon = nullptr; #endif m_connection_pool = new connection_pool (server_manager::CONNECTION_POOL_SIZE, db_name); + + m_pl_ctx_params = xsysprm_get_pl_context_parameters (PRM_ALL_FLAGS); + assert (m_pl_ctx_params != nullptr); } server_manager::~server_manager () @@ -223,6 +230,11 @@ namespace cubpl m_connection_pool = nullptr; } #endif + + if (m_pl_ctx_params) + { + sysprm_free_assign_values (&m_pl_ctx_params); + } } void @@ -248,6 +260,12 @@ namespace cubpl return m_connection_pool; } + SYSPRM_ASSIGN_VALUE * + server_manager::get_pl_ctx_params () const + { + return m_pl_ctx_params; + } + /********************************************************************* * server_monitor_task - definition *********************************************************************/ @@ -259,6 +277,7 @@ namespace cubpl , m_binary_name ("cub_pl") , m_argv {m_binary_name.c_str (), m_db_name.c_str (), 0} , m_sys_conn_pool {nullptr} + , m_bootstrap_request {nullptr} , m_monitor_mutex {} , m_monitor_cv {} { @@ -269,7 +288,10 @@ namespace cubpl server_monitor_task::~server_monitor_task () { - // do nothing + if (m_bootstrap_request != nullptr) + { + delete m_bootstrap_request; + } } #if defined (SERVER_MODE) @@ -438,15 +460,17 @@ namespace cubpl int server_monitor_task::do_bootstrap_request () { + int error = ER_FAILED; + if (m_bootstrap_request == nullptr) + { + m_bootstrap_request = new bootstrap_request (m_manager->get_pl_ctx_params ()); + } + cubmem::block bootstrap_response; cubmethod::header header (DB_EMPTY_SESSION, SP_CODE_UTIL_BOOTSTRAP, 0); connection_view cv = m_sys_conn_pool->claim (); - int error = NO_ERROR; - - SYSPRM_ASSIGN_VALUE *pl_ctx_params_assignments = xsysprm_get_pl_context_parameters (); - bootstrap_request bootstrap_request (pl_ctx_params_assignments); - error = cv->send_buffer_args (header, bootstrap_request); + error = cv->send_buffer_args (header, *m_bootstrap_request); if (error == NO_ERROR) { error = cv->receive_buffer (bootstrap_response); @@ -458,8 +482,6 @@ namespace cubpl deserializator.unpack_int (error); } - sysprm_free_assign_values (&pl_ctx_params_assignments); - return error; } @@ -467,76 +489,19 @@ namespace cubpl * bootstrap_request - definition *********************************************************************/ bootstrap_request::bootstrap_request (SYSPRM_ASSIGN_VALUE *pl_ctx_values) - : static_params () + : server_params () { - int idx = 0; while (pl_ctx_values != nullptr) { - PARAM_ID param_id = pl_ctx_values->prm_id; - - pl_ctx_params param_obj; - param_obj.param_id = (int) param_id; - - if (PRM_IS_BOOLEAN (GET_PRM (param_id))) - { - int val = prm_get_bool_value (param_id) ? 1 : 0; - db_make_int (¶m_obj.param_value, val); - } - else if (PRM_IS_STRING (GET_PRM (param_id))) - { - const char *val = prm_get_string_value (param_id); - if (val == NULL) - { - switch (param_id) - { - case PRM_ID_INTL_COLLATION: - val = lang_get_collation_name (LANG_GET_BINARY_COLLATION (LANG_SYS_CODESET)); - break; - case PRM_ID_INTL_DATE_LANG: - case PRM_ID_INTL_NUMBER_LANG: - val = lang_get_Lang_name (); - break; - case PRM_ID_TIMEZONE: - val = prm_get_string_value (PRM_ID_SERVER_TIMEZONE); - break; - default: - /* do nothing */ - break; - } - } - db_make_string (¶m_obj.param_value, val); - } - else - { - // not implemented yet - assert (false); - } - static_params.push_back (param_obj); - - idx++; + server_params.emplace_back (pl_ctx_values); pl_ctx_values = pl_ctx_values->next; } } - bootstrap_request::~bootstrap_request () - { - for (pl_ctx_params ¶m : static_params) - { - db_value_clear (¶m.param_value); - } - } - void bootstrap_request::pack (cubpacking::packer &serializator) const { - serializator.pack_int (static_params.size ()); - cubmethod::dbvalue_java sp_val; - for (const pl_ctx_params ¶m : static_params) - { - serializator.pack_int (param.param_id); - sp_val.value = (DB_VALUE *) ¶m.param_value; - sp_val.pack (serializator); - } + serializator.pack_all (server_params); } void @@ -548,19 +513,8 @@ namespace cubpl size_t bootstrap_request::get_packed_size (cubpacking::packer &serializator, std::size_t start_offset) const { - size_t size = serializator.get_packed_int_size (start_offset); // static_params.size () - - cubmethod::dbvalue_java sp_val; - for (const pl_ctx_params ¶m : static_params) - { - size += serializator.get_packed_int_size (size); // param.param_id - sp_val.value = (DB_VALUE *) ¶m.param_value; - size += sp_val.get_packed_size (serializator, size); - } - - return size; + return serializator.get_all_packed_size_starting_offset (start_offset, server_params); } - } // namespace cubpl ////////////////////////////////////////////////////////////////////////// diff --git a/src/sp/sp_catalog.cpp b/src/sp/sp_catalog.cpp index 4caaad9537..3957a4f868 100644 --- a/src/sp/sp_catalog.cpp +++ b/src/sp/sp_catalog.cpp @@ -843,8 +843,8 @@ sp_add_stored_procedure_code (SP_CODE_INFO &info) goto error; } - db_make_varchar (&value, DB_DEFAULT_PRECISION, info.scode.data (), info.scode.length (), LANG_SYS_CODESET, - LANG_SYS_COLLATION); + db_make_varchar (&value, DB_DEFAULT_PRECISION, info.scode.data (), info.scode.length (), lang_get_client_charset (), + lang_get_client_collation ()); err = dbt_put_internal (obt_p, SP_ATTR_SOURCE_CODE, &value); pr_clear_value (&value); if (err != NO_ERROR) @@ -861,8 +861,8 @@ sp_add_stored_procedure_code (SP_CODE_INFO &info) goto error; } - db_make_varchar (&value, DB_DEFAULT_PRECISION, info.ocode.data (), info.ocode.length (), LANG_SYS_CODESET, - LANG_SYS_COLLATION); + db_make_varchar (&value, DB_DEFAULT_PRECISION, info.ocode.data (), info.ocode.length (), lang_get_client_charset (), + lang_get_client_collation ()); err = dbt_put_internal (obt_p, SP_ATTR_OBJECT_CODE, &value); pr_clear_value (&value); if (err != NO_ERROR)