Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/develop' into CBRD-25749
Browse files Browse the repository at this point in the history
  • Loading branch information
jongmin-won committed Dec 20, 2024
2 parents 71ee4cc + 07bdae3 commit 0fcb37d
Show file tree
Hide file tree
Showing 27 changed files with 451 additions and 205 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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 ()
Expand All @@ -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
Expand Down
13 changes: 0 additions & 13 deletions pl_engine/pl_server/src/main/java/com/cubrid/jsp/Server.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down
25 changes: 15 additions & 10 deletions pl_engine/pl_server/src/main/java/com/cubrid/jsp/SysParam.java
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -73,7 +81,7 @@ public int getParamId() {
return paramId;
}

public Value getParamValue() {
public String getParamValue() {
return paramValue;
}

Expand All @@ -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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -85,6 +88,9 @@ public class Context {
// message buffer for DBMS_OUTPUT
private MessageBuffer messageBuffer;

// context system parameters
private HashMap<Integer, SysParam> systemParameters = null;

public Context(long id) {
sessionId = id;
}
Expand Down Expand Up @@ -125,11 +131,11 @@ public LinkedBlockingQueue<ByteBuffer> getInboundQueue() {
return inBound;
}

public Charset getSessionCharset() {
if (sessionCharset == null) {
sessionCharset = Server.getConfig().getServerCharset();
public HashMap<Integer, SysParam> getSystemParameters() {
if (systemParameters == null) {
systemParameters = new HashMap<Integer, SysParam>();
}
return sessionCharset;
return systemParameters;
}

public void checkHeader(Header header) {
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 "";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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]);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
}
Expand Down
Loading

0 comments on commit 0fcb37d

Please sign in to comment.