Hi guys,
I've been working with Jython in ODI 11g, more particularly ODI procedures written in Jython (like some of the steps in KM's are written in Jython). Basically i've made a filehandling procedure in Jython that sometimes has to write some meta-data to tables while handling the file. I've set up a basic jython script that opens a jdbc connection and closes it again. The script is something like this:
import java.sql
import java.lang
L_DB_SCHEMA = 'XXIVL'
L_COUNT_TGT = 'IVL_FH_COUNT_IN'
L_SESSION_ID = '<%=odiRef.getOption("V_SESSION_ID")%>'
L_INTERFACE_ID = '<%=odiRef.getOption("V_INTERFACE_ID")%>'
L_COUNT1 = 0
db = odiRef.getJDBCConnection("SRC")
c = db.createStatement()
L_UPDATE_COUNT = "INSERT INTO "+L_DB_SCHEMA+"."+L_COUNT_TGT+" VALUES ('"+L_SESSION_ID+"' , '"+L_INTERFACE_ID+"' , '"+L_FILEMASK+"' , "+str(L_COUNT1)+" , sysdate)"
rs = c.executeUpdate(L_UPDATE_COUNT)
db.close()
As you can see, this is really basic Jython...but it's enough to do what I want it to do. The only thing is...if I make use of this filehandling procedures in a loop created in an ODI package, it tends to fail on this particular step once in a while. It gives me the error: Closed Connection. I've solved this by tweaking the advanced settings of the filehandler step in the package: setting the Number of Attempts to 3, Time between attempts = 1 second. This pratically does the trick...because the next time it tries to open a jdbc connections it works perfectly. But surely there must be a better way of opening and closing jdbc connections in Jython to prevent this annoyance? Am I missing something, not closing properly? I've been scoping the web endlessly, but all in vein i'm afraid...
It would be bliss if someone could help me with this!
extract:
org.apache.bsf.BSFException: exception from Jython:
Traceback (most recent call last):
File "<string>", line 4, in <module>
at oracle.jdbc.driver.PhysicalConnection.createStatement(PhysicalConnection.java:4070)
at oracle.jdbc.driver.PhysicalConnection.createStatement(PhysicalConnection.java:4008)
at sun.reflect.GeneratedMethodAccessor79.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at oracle.odi.core.datasource.dwgobject.support.OnConnectOnDisconnectDataSourceAdapter$OnDisconnectCommandExecutionHandler.invoke(OnConnectOnDisconnectDataSourceAdapter.java:200)
at com.sun.proxy.$Proxy36.createStatement(Unknown Source)
at sun.reflect.GeneratedMethodAccessor116.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
java.sql.SQLRecoverableException: java.sql.SQLRecoverableException: Closed Connection
at org.apache.bsf.engines.jython.JythonEngine.exec(JythonEngine.java:146)
at com.sunopsis.dwg.codeinterpretor.SnpScriptingInterpretor.execInBSFEngine(SnpScriptingInterpretor.java:322)
at com.sunopsis.dwg.codeinterpretor.SnpScriptingInterpretor.exec(SnpScriptingInterpretor.java:170)
at com.sunopsis.dwg.dbobj.SnpSessTaskSql.scripting(SnpSessTaskSql.java:2472)
at oracle.odi.runtime.agent.execution.cmd.ScriptingExecutor.execute(ScriptingExecutor.java:47)
at oracle.odi.runtime.agent.execution.cmd.ScriptingExecutor.execute(ScriptingExecutor.java:1)
at oracle.odi.runtime.agent.execution.TaskExecutionHandler.handleTask(TaskExecutionHandler.java:50)
at com.sunopsis.dwg.dbobj.SnpSessTaskSql.processTask(SnpSessTaskSql.java:2913)
at com.sunopsis.dwg.dbobj.SnpSessTaskSql.treatTask(SnpSessTaskSql.java:2625)
at com.sunopsis.dwg.dbobj.SnpSessStep.treatAttachedTasks(SnpSessStep.java:577)
at com.sunopsis.dwg.dbobj.SnpSessStep.treatSessStep(SnpSessStep.java:468)
at com.sunopsis.dwg.dbobj.SnpSession.treatSession(SnpSession.java:2128)
at com.sunopsis.dwg.dbobj.SnpSession.treatSession(SnpSession.java:1930)
at oracle.odi.runtime.agent.processor.impl.StartScenRequestProcessor$2.doAction(StartScenRequestProcessor.java:580)
at oracle.odi.core.persistence.dwgobject.DwgObjectTemplate.execute(DwgObjectTemplate.java:216)
at oracle.odi.runtime.agent.processor.impl.StartScenRequestProcessor.doProcessStartScenTask(StartScenRequestProcessor.java:513)
at oracle.odi.runtime.agent.processor.impl.StartScenRequestProcessor$StartScenTask.doExecute(StartScenRequestProcessor.java:1073)
at oracle.odi.runtime.agent.processor.task.AgentTask.execute(AgentTask.java:126)
at oracle.odi.runtime.agent.support.DefaultAgentTaskExecutor$2.run(DefaultAgentTaskExecutor.java:82)
at java.lang.Thread.run(Thread.java:744)
Caused by: Traceback (most recent call last):
File "<string>", line 4, in <module>
at oracle.jdbc.driver.PhysicalConnection.createStatement(PhysicalConnection.java:4070)
at oracle.jdbc.driver.PhysicalConnection.createStatement(PhysicalConnection.java:4008)
at sun.reflect.GeneratedMethodAccessor79.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at oracle.odi.core.datasource.dwgobject.support.OnConnectOnDisconnectDataSourceAdapter$OnDisconnectCommandExecutionHandler.invoke(OnConnectOnDisconnectDataSourceAdapter.java:200)
at com.sun.proxy.$Proxy36.createStatement(Unknown Source)
at sun.reflect.GeneratedMethodAccessor116.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
java.sql.SQLRecoverableException: java.sql.SQLRecoverableException: Closed Connection
at org.python.core.Py.JavaError(Py.java:455)
at org.python.core.Py.JavaError(Py.java:448)
at org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java:177)
at org.python.core.PyObject.__call__(PyObject.java:355)
at org.python.core.PyMethod.__call__(PyMethod.java:215)
at org.python.core.PyMethod.instancemethod___call__(PyMethod.java:221)
at org.python.core.PyMethod.__call__(PyMethod.java:206)
at org.python.core.PyObject.__call__(PyObject.java:381)
at org.python.core.PyObject.__call__(PyObject.java:385)
at org.python.pycode._pyx2120.f$0(<string>:26)
at org.python.pycode._pyx2120.call_function(<string>)
at org.python.core.PyTableCode.call(PyTableCode.java:165)
at org.python.core.PyCode.call(PyCode.java:18)
at org.python.core.Py.runCode(Py.java:1204)
at org.python.core.Py.exec(Py.java:1248)
at org.python.util.PythonInterpreter.exec(PythonInterpreter.java:172)
at org.apache.bsf.engines.jython.JythonEngine.exec(JythonEngine.java:144)
... 19 more
Caused by: java.sql.SQLRecoverableException: Closed Connection
at oracle.jdbc.driver.PhysicalConnection.createStatement(PhysicalConnection.java:4070)
at oracle.jdbc.driver.PhysicalConnection.createStatement(PhysicalConnection.java:4008)
at sun.reflect.GeneratedMethodAccessor79.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at oracle.odi.core.datasource.dwgobject.support.OnConnectOnDisconnectDataSourceAdapter$OnDisconnectCommandExecutionHandler.invoke(OnConnectOnDisconnectDataSourceAdapter.java:200)
at com.sun.proxy.$Proxy36.createStatement(Unknown Source)
at sun.reflect.GeneratedMethodAccessor116.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java:175)
... 33 more