Skip to content

Commit

Permalink
Merge pull request #827 from mulesoft/fix/W-16615688
Browse files Browse the repository at this point in the history
[W-16615688] add oracle ssl docker image files and fix no able to resolve time with a clob in a UDT as SP parameter
  • Loading branch information
cristianchan-mulesoft authored Oct 28, 2024
2 parents cfe587d + 72850c4 commit b550f46
Show file tree
Hide file tree
Showing 12 changed files with 172 additions and 47 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ objectstore/
temp/
muleEmbeddedDB/
activemq-data/
directory/
testdir/
hostkey.ser
*.h2.db
Expand All @@ -34,3 +35,4 @@ myDB/
previousDB/
derbyLeakTriggererDB/
J17_validation.sh
db-derby-10.16.1.1-bin.tar.gz
31 changes: 29 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@
<awaitility.version>3.1.6</awaitility.version>
<!-- JDK 17 Compatibility Props -->
<mule.sdk.api.version>0.8.0</mule.sdk.api.version>
<munit.version>3.2.1</munit.version>
<munit.version>3.3.1</munit.version>
<mtf.tools.version>1.2.0</mtf.tools.version>
<munit.extensions.maven.plugin.version>1.3.0</munit.extensions.maven.plugin.version>
<munit.extensions.maven.plugin.version>1.4.0</munit.extensions.maven.plugin.version>
<jacoco.version>0.8.10</jacoco.version>
<mtf.javaopts></mtf.javaopts>
</properties>
Expand Down Expand Up @@ -1123,6 +1123,33 @@
<id>derby</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy</id>
<phase>test-compile</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>org.apache</groupId>
<artifactId>db-derby</artifactId>
<version>10.16.1.1</version>
<type>tar.gz</type>
<classifier>bin</classifier>
<overWrite>true</overWrite>
<outputDirectory>${project.basedir}/src/docker/derby</outputDirectory>
</artifactItem>
</artifactItems>

</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>io.fabric8</groupId>
<artifactId>docker-maven-plugin</artifactId>
Expand Down
6 changes: 4 additions & 2 deletions src/docker/derby/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
FROM openjdk:17-slim

ENV DERBY_VERSION=10.16.1.1

ENV DERBY_HOME=/derby
ENV DERBY_LIB=${DERBY_HOME}/lib
ENV CLASSPATH=${DERBY_LIB}/derby.jar:${DERBY_LIB}/derbynet.jar:${DERBY_LIB}/derbytools.jar:${DERBY_LIB}/derbyoptionaltools.jar:${DERBY_LIB}/derbyclient.jar
ENV FILENAME db-derby-${DERBY_VERSION}-bin.tar.gz

COPY $FILENAME $FILENAME

RUN \
apt-get update && apt-get install -y wget netcat && \
wget https://dist.apache.org/repos/dist/release/db/derby/db-derby-${DERBY_VERSION}/db-derby-${DERBY_VERSION}-bin.tar.gz && \
tar xzf /db-derby-${DERBY_VERSION}-bin.tar.gz && \
mv /db-derby-${DERBY_VERSION}-bin /derby && \
rm -Rf /*.tar.gz ${DERBY_HOME}/demo ${DERBY_HOME}/javadoc ${DERBY_HOME}/docs ${DERBY_HOME}/test ${DERBY_HOME}/*.html ${DERBY_HOME}/KEYS \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ public class OracleDbConnection extends DefaultDbConnection {
public static final String QUERY_TYPE_ATTRS =
"SELECT ATTR_NO, ATTR_TYPE_NAME FROM ALL_TYPE_ATTRS WHERE TYPE_NAME = ? AND ATTR_TYPE_NAME IN ('CLOB', 'BLOB')";


public static final String QUERY_PKG_ATTRS =
"SELECT ATTR_NO, ATTR_TYPE_NAME FROM ALL_PLSQL_TYPE_ATTRS WHERE PACKAGE_NAME = ? AND ATTR_TYPE_NAME IN ('CLOB', 'BLOB')";

private static final String QUERY_OWNER_CONDITION = " AND OWNER = ?";

private static final int PROCEDURE_SCHEM_COLUMN_INDEX = 2;
Expand Down Expand Up @@ -210,12 +214,18 @@ protected Map<Integer, ResolvedDbType> getLobFieldsDataTypeInfo(String typeName)
Optional<String> owner = getOwnerFrom(typeName);
String type = getTypeSimpleName(typeName);

String query = QUERY_TYPE_ATTRS + (owner.isPresent() ? QUERY_OWNER_CONDITION : "");
String query;
if (owner.isPresent()) {
query = QUERY_TYPE_ATTRS + QUERY_OWNER_CONDITION + " UNION ALL " + QUERY_PKG_ATTRS;
} else {
query = QUERY_TYPE_ATTRS;
}

try (PreparedStatement ps = this.prepareStatement(query)) {
ps.setString(1, type);
if (owner.isPresent()) {
ps.setString(2, owner.get());
ps.setString(3, owner.get());
}

try (ResultSet resultSet = ps.executeQuery()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import static org.mule.db.commons.api.param.JdbcType.CLOB;
import static org.mule.extension.db.internal.domain.connection.oracle.OracleConnectionUtils.getOwnerFrom;
import static org.mule.extension.db.internal.domain.connection.oracle.OracleConnectionUtils.getTypeSimpleName;
import static org.mule.extension.db.internal.domain.connection.oracle.OracleDbConnection.QUERY_PKG_ATTRS;

import static com.github.benmanes.caffeine.cache.Caffeine.newBuilder;
import static org.hamcrest.MatcherAssert.assertThat;
Expand Down Expand Up @@ -118,7 +119,8 @@ private void testThroughOracleQuery(Connection delegate, Object[] values, String

when(preparedStatement.executeQuery()).thenReturn(resultSet);
if (owner.isPresent()) {
when(delegate.prepareStatement(QUERY_TYPE_ATTRS + QUERY_OWNER_CONDITION)).thenReturn(preparedStatement);
when(delegate.prepareStatement(QUERY_TYPE_ATTRS + QUERY_OWNER_CONDITION + " UNION ALL " + QUERY_PKG_ATTRS))
.thenReturn(preparedStatement);
when(delegate.prepareStatement(QUERY_ALL_COLL_TYPES + QUERY_OWNER_CONDITION)).thenReturn(preparedStatement);
} else {
when(delegate.prepareStatement(QUERY_TYPE_ATTRS)).thenReturn(preparedStatement);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import static org.mule.db.commons.api.param.JdbcType.CLOB;
import static org.mule.extension.db.internal.domain.connection.oracle.OracleConnectionUtils.getOwnerFrom;
import static org.mule.extension.db.internal.domain.connection.oracle.OracleConnectionUtils.getTypeSimpleName;
import static org.mule.extension.db.internal.domain.connection.oracle.OracleDbConnection.QUERY_PKG_ATTRS;

import static com.github.benmanes.caffeine.cache.Caffeine.newBuilder;
import static org.hamcrest.MatcherAssert.assertThat;
Expand Down Expand Up @@ -84,7 +85,8 @@ private void testThroughOracleQuery(Connection delegate, Object[] structValues,

when(preparedStatement.executeQuery()).thenReturn(resultSet);
if (owner.isPresent()) {
when(delegate.prepareStatement(QUERY_TYPE_ATTRS + QUERY_OWNER_CONDITION)).thenReturn(preparedStatement);
when(delegate.prepareStatement(QUERY_TYPE_ATTRS + QUERY_OWNER_CONDITION + " UNION ALL " + QUERY_PKG_ATTRS))
.thenReturn(preparedStatement);
} else {
when(delegate.prepareStatement(QUERY_TYPE_ATTRS)).thenReturn(preparedStatement);
}
Expand Down
21 changes: 16 additions & 5 deletions src/test/munit/oracle/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
</db:config>

<db:config name="oracleGenericConfig">
<db:generic-connection url="#[java!org::mule::extension::db::DbMunitUtils::getOracleConnectionString('localhost', 'XEPDB1')]" user="system"
<db:generic-connection url="#[java!org::mule::extension::db::DbMunitUtils::getOracleConnectionString('0.0.0.0', 'XEPDB1')]" user="system"
password="oracle" driverClassName="oracle.jdbc.driver.OracleDriver"/>
</db:config>

Expand All @@ -40,7 +40,7 @@
</db:config>

<db:config name="oracleMTLSDbConfig">
<db:oracle-connection host="localhost" port="#[java!org::mule::extension::db::DbMunitUtils::getSecureDbPort('oracle')]" serviceName="XEPDB1" user="system" password="oracle">
<db:oracle-connection host="0.0.0.0" port="#[java!org::mule::extension::db::DbMunitUtils::getSecureDbPort('oracle')]" serviceName="XEPDB1" user="system" password="oracle">
<tls:context >
<tls:trust-store path="${project.build.directory}/docker/oracle-db-mtls/store/client-truststore.jks" password="WalletPasswd123" type="jks" />
<tls:key-store type="jks" path="${project.build.directory}/docker/oracle-db-mtls/store/client-keystore.jks" keyPassword="WalletPasswd123" password="WalletPasswd123" />
Expand All @@ -49,7 +49,7 @@
</db:config>

<db:config name="oracleInsecureTLSDbConfig">
<db:oracle-connection host="localhost" port="#[java!org::mule::extension::db::DbMunitUtils::getSecureDbPort('oracle')]" serviceName="XEPDB1" user="system" password="oracle">
<db:oracle-connection host="0.0.0.0" port="#[java!org::mule::extension::db::DbMunitUtils::getSecureDbPort('oracle')]" serviceName="XEPDB1" user="system" password="oracle">
<tls:context >
<tls:trust-store path="${project.build.directory}/docker/oracle-db-mtls/store/client-truststore.jks" password="WalletPasswd123" type="jks" insecure="true"/>
<tls:key-store type="jks" path="${project.build.directory}/docker/oracle-db-mtls/store/client-keystore.jks" keyPassword="WalletPasswd123" password="WalletPasswd123" />
Expand All @@ -58,7 +58,7 @@
</db:config>

<db:config name="oracleMTLSNoUserPassDbConfig">
<db:oracle-connection host="localhost" port="#[java!org::mule::extension::db::DbMunitUtils::getSecureDbPort('oracle')]" serviceName="XE" >
<db:oracle-connection host="0.0.0.0" port="#[java!org::mule::extension::db::DbMunitUtils::getSecureDbPort('oracle')]" serviceName="XE" >
<tls:context >
<tls:trust-store path="${project.build.directory}/docker/oracle-db-mtls/store/client-truststore.jks" password="WalletPasswd123" type="jks" />
<tls:key-store type="jks" path="${project.build.directory}/docker/oracle-db-mtls/store/client-keystore.jks" keyPassword="WalletPasswd123" password="WalletPasswd123" />
Expand All @@ -67,7 +67,7 @@
</db:config>

<db:config name="dbConfigWithPooling">
<db:oracle-connection host="localhost" port="#[java!org::mule::extension::db::DbMunitUtils::getSecureDbPort('oracle')]" user="system" password="oracle" serviceName="XEPDB1">
<db:oracle-connection host="0.0.0.0" port="#[java!org::mule::extension::db::DbMunitUtils::getSecureDbPort('oracle')]" user="system" password="oracle" serviceName="XEPDB1">
<tls:context>
<tls:trust-store path="${basedir}/target/docker/oracle-db-mtls/store/client-truststore.jks" password="WalletPasswd123" type="jks" />
<tls:key-store type="jks" path="${basedir}/target/docker/oracle-db-mtls/store/client-keystore.jks" keyPassword="WalletPasswd123" password="WalletPasswd123" />
Expand All @@ -86,6 +86,17 @@
</db:oracle-connection>
</db:config>

<db:config name="oracleDbClobUDTPoolingConfig">
<db:oracle-connection host="0.0.0.0" port="#[java!org::mule::extension::db::DbMunitUtils::getDbPort('oracle')]" serviceName="XEPDB1" user="system" password="oracle">
<db:pooling-profile maxPoolSize="1" minPoolSize="1" />
<db:column-types >
<db:column-type id="2002" typeName="PKG_DGTL_CLM_TASK.NOTEPAD_REC" />
<db:column-type id="2005" typeName="CLOB" />
<db:column-type id="2002" typeName="PKG_DGTL_CLM_TASK.INTF_ERR_REC" />
</db:column-types>
</db:oracle-connection>
</db:config>

<db:config name="oracleDbPoolingListenerExternalConfig">
<db:oracle-connection host="0.0.0.0" port="#[java!org::mule::extension::db::DbMunitUtils::getDbPort('oracle')]" serviceName="XEPDB1" user="system" password="oracle">
<db:pooling-profile maxPoolSize="4" minPoolSize="1"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns="http://www.mulesoft.org/schema/mule/core"
xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core"
xmlns:db="http://www.mulesoft.org/schema/mule/db"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:munit="http://www.mulesoft.org/schema/mule/munit"
xsi:schemaLocation="http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/munit http://www.mulesoft.org/schema/mule/munit/current/mule-munit.xsd
http://www.mulesoft.org/schema/mule/db http://www.mulesoft.org/schema/mule/db/current/mule-db.xsd
http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd">

<munit:config name="stored-procedure-clob-parameter-UDT-oracle-test-case" minMuleVersion="4.3.0"/>
<munit:before-suite name="createStoreProcedureUDT">
<db:execute-ddl config-ref="oracleDbClobUDTPoolingConfig">
<db:sql><![CDATA[CREATE TABLE my_table(id NUMBER PRIMARY KEY,large_text CLOB)]]></db:sql>
</db:execute-ddl>
<db:execute-ddl config-ref="oracleDbClobUDTPoolingConfig" >
<db:sql ><![CDATA[CREATE OR REPLACE PACKAGE BODY pkg_dgtl_clm_task AS
PROCEDURE prc_mytable(arec_notepad_rec IN notepad_rec) IS
BEGIN
INSERT INTO my_table (id, large_text)
VALUES (arec_notepad_rec.id, arec_notepad_rec.large_text);
END prc_mytable;
END pkg_dgtl_clm_task;]]></db:sql>
</db:execute-ddl>
<db:execute-ddl config-ref="oracleDbClobUDTPoolingConfig" >
<db:sql ><![CDATA[create or replace PACKAGE pkg_dgtl_clm_task IS
TYPE notepad_rec IS RECORD
(
id my_table.id%TYPE,
large_text CLOB
);
PROCEDURE prc_mytable(arec_notepad_rec IN notepad_rec);
END pkg_dgtl_clm_task;]]></db:sql>
</db:execute-ddl>
</munit:before-suite>
<munit:test name="storeProcedureExecutionWithClobInUDT" ignore="#[java!org::mule::extension::db::DbMunitUtils::isTestIgnored('oracle')]">
<munit:execution>
<ee:transform>
<ee:message />
<ee:variables >
<ee:set-variable variableName="in_notepad_rec" ><![CDATA[import * from dw::core::Strings
output application/java
---
Db::prepareStruct("PKG_DGTL_CLM_TASK.NOTEPAD_REC", [
1,
"adsfasdfadsfasdfasdfasdfasdfasdfsdfsadf"
])]]></ee:set-variable>
</ee:variables>
</ee:transform>
<db:stored-procedure config-ref="oracleDbClobUDTPoolingConfig">
<db:sql ><![CDATA[{call pkg_dgtl_clm_task.prc_mytable(:arec_notepad_rec)}]]></db:sql>
<db:input-parameters ><![CDATA[#[{arec_notepad_rec: vars.in_notepad_rec}]]]></db:input-parameters>
<db:output-parameters >
</db:output-parameters>
</db:stored-procedure>
</munit:execution>
</munit:test>

<munit:after-suite name="deleteStoreProcedureUDT">
<db:execute-script config-ref="oracleDbClobUDTPoolingConfig">
<db:sql><![CDATA[drop package pkg_dgtl_clm_task;
drop table my_table]]></db:sql>
</db:execute-script>
</munit:after-suite>
</mule>
2 changes: 1 addition & 1 deletion src/test/resources/_spring-config-oracle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd">
<bean id="oracleDataSourceXA" class="oracle.jdbc.xa.client.OracleXADataSource">
<property name="URL"
value="jdbc:oracle:thin:@//localhost:${oracle.port}/XEPDB1"/>
value="jdbc:oracle:thin:@//0.0.0.0:${oracle.port}/XEPDB1"/>
<property name="user" value="system"/>
<property name="password" value="oracle"/>
</bean>
Expand Down
7 changes: 5 additions & 2 deletions src/test/resources/docker/oracle-mtls/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
FROM kyleaure/oracle-18.4.0-expanded:1.0.full.ssl
FROM gvenzl/oracle-xe:21.3.0-full-faststart

COPY setup/ /tmp/setup/
COPY startup/ /opt/oracle/scripts/startup

ENV ORACLE_ADMIN=/opt/oracle/homes/OraDBHome21cXE/network/admin

USER root
RUN chmod 777 /tmp/setup/enable_ssl.sh
RUN /tmp/setup/enable_ssl.sh
Expand All @@ -13,4 +15,5 @@ EXPOSE 1521 1522
USER oracle
CMD ["/bin/sh","-c", "exec $ORACLE_BASE/$RUN_FILE"]

# Currently tagged in DockerHub as: kyleaure/oracle-ssl-18.4.0-xe-prebuilt:2.0


Loading

0 comments on commit b550f46

Please sign in to comment.