Document Type | Technical Information
Category | Administration
Applicable Product Version | Tibero 7.2.4
Document Number | TADTI175
Overview
Java External Procedure Operation Process
The JEPA process is created when the database server starts.
Users register their own Java classes as Java objects in the database.
Write a PSM program to link with the Java object registered in step 2.
When an execution request occurs in the PSM program written in step 3, it connects to the JEPA process.
The JEPA process finds and executes the function, then sends the result to the database server.
The database server analyzes the result received from the JEPA process and sends it to the user.
When the session ends, the connection with the JEPA process is disconnected. Subsequently, when the next session connects and the PSM program is called, it reconnects to the JEPA process.
The JEPA process automatically terminates when the database server shuts down.
[Java External Procedure Operation Process]
Method
Java External Procedure Configuration
TIP File Parameter Settings
Set the $TB_SID.tip file as follows.
_PSM_BOOT_JEPA=Y
JAVA_CLASS_PATH=/home/tibero/tibero7/instance/tibero/javaThe descriptions for each item are as follows.
| Item | Description |
| _PSM_BOOT_JEPA | Sets whether to start the JEPA process. - Y: To start the JEPA process, this initialization parameter must be set to 'Y'. - N: The database server starts, but the JEPA process does not start. |
| JAVA_CLASS_PATH | Used as the compile path when users create Java objects. If this item is not set, a java directory is created in the path set by the DB_CREATE_FILE_DEST initialization parameter, and class files are created in that directory. Do not specify locations that may be affected by patches or upgrades, such as where Tibero binaries are installed. |
JEPA Connection Information
Set the connection information for the JEPA process in the tbdsn.tbr file located in the $TB_HOME/client/config directory.
Below is an example of connection information set in the tbdsn.tbr file.
epa=(
(EXTPROC=(LANG=JAVA)
(LISTENER=(HOST=localhost)
(PORT=9390)
)
)
)JEPA Configuration
Modify the epa.cfg file located in the $TB_HOME/client/epa/java/config directory according to your system environment.
# listener port
LISTENER_PORT=9390
# initial thread pool size
INIT_POOL_SIZE=10
# max thread pool size
MAX_POOL_SIZE=1000
# tbjavaepa encoding "ASCII", "EUC-KR", "MSWIN949", "UTF-8", "UTF-16", "SHIFT-JIS"
ENCODING=UTF-8
#STATIC_LOADING_CLASSES=ex.StaticClass1, ex.st.Class2The descriptions for each item are as follows.
| Parameter | Description |
| LISTENER_PORT | Set to the same port number as in the tbdsn.tbr file. |
| INIT_POOL_SIZE | Number of threads initially created when the JEPA process starts. |
| MAX_POOL_SIZE | Maximum number of threads the JEPA process can create. |
| ENCODING | Encoding method used by the JEPA process. However, to synchronize with the database server, the same encoding must be used on both sides. |
| STATIC_LOADING_CLASSES | Parameter needed when using class libraries unsuitable for dynamic class loading, such as libraries using JNI. |
When referencing external libraries (no need to set if not using jar files)
For external Java compilation, add the jar file path to the psmjavac script located in the $TB_HOME/bin directory.
javac -classpath <jar_path>:${classpath} ${src}If the exptest.jar file is located at /tibero/tibero7/tbdata/lib, set it as follows.
javac -classpath /tibero/tibero7/tbdata/lib/exptest.jar:${classpath} ${src}Since JEPA is executed by the tbjavaepa script in the $TB_HOME/client/bin directory, also add the library path to the -classpath option of the exec java command line below.
exec java -verbose:gc -Xms128m -Xmx512m -Djavaepa="$TB_HOME"
-Dlog4j.configuration=$log4jfile
-classpath $pool:$collections:$log4j:
$:$:$config $mainclass CONFIG=$configfile
Creating Java External Procedure
The following is an example of creating a Java External Procedure.
1. Create a Java object.
SQL> CREATE OR REPLACE AND RESOLVE JAVA SOURCE NAMED "JavaExtproc" AS
public class SimpleMath {
public static int findMax(int x, int y) {
if (x >= y) return x;
else return y;
}
}
/
Java Source 'JavaExtproc' created.2. Check the created object in USER_OBJECTS.
SQL> col OBJECT_NAME format a15
SQL> SELECT OBJECT_NAME, OBJECT_TYPE, STATUS
FROM USER_OBJECTS
WHERE OBJECT_TYPE = 'JAVA';
OBJECT_NAME OBJECT_TYPE STATUS
--------------- -------------------- -------
JavaExtproc JAVA VALID
1 row selected.
3. Create a PSM function.
SQL> CREATE OR REPLACE FUNCTION find_max(x PLS_INTEGER, y PLS_INTEGER)
RETURN PLS_INTEGER IS
LANGUAGE JAVA NAME 'SimpleMath.findMax(int, int) return int';
/
Function 'FIND_MAX' created.4. Execute the PSM function.
SQL> select find_max(4,60) from dual;
FIND_MAX(4,60)
--------------
60
1 row selected.