473,386 Members | 1,766 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

SQLJ Connection Context and SP interportability

With DB2 7.2 we used to call methods from other SQLJ Stored
Procedures, as it was not possible to call SPs via the SQL
Call-statement from within SPs. So we always had a method like this:

protected static void execute(Connection con, (...))

Where we passed a Connection object for dynamic SQL (which we got
using the getConnection() method of the DefaultContext). Static SQL
was always executed on the DefaultContext.

Now with DB2 8.1 we are forced to create a dedicated Context for each
SP, and therefore changed our execute-method to something like this:

protected static void execute(ConnectionContext context, Connection
con, (...))

The problem now is that the SQLJ Precompiler doesn't like the "simple"
ConnectionContext. So if you would try something like this in the
"execute" method

#sql [context] { SELECT imbreqd FROM sysibm.sysdummy1 }

the precompiler says that you have to declare ConnectionContextes
using #sql context declaration. So I changed the execute-method to the
following:

protected static void execute(SPName_ConnectionContext context,
Connection con, (...))

This works fine for the current procedure, but I cannot call the
method from another SP anymore.

There are two solutions which come to mind:
1. Call one SP from another using the SQL-Call-command (now supported
with 8.1)
2. Define one global ConnectionContext used by all SPs

The first solution I don't like as it is much slower than calling a
Java method directly. I'm not sure if the second solution is a
"proper" solution, as you always operate on the same context-class and
this may therefore not be threadsafe (I don't know how those
context-classes are implemented).

Maybe somebody can think of another (better) solution or tell me
whether the second solution would be threadsafe or not.

Regards,
- Janick Bernet, SwissASP
Nov 12 '05 #1
9 2909
The reason you need a seperate context in 8.1 is that we're
multithreading on the JVM. Without a context per thread, threads would
run wild over each others objects (cursors etc) closing them, and other
bad things.

If you don't want to use CALL, you can catalog your sqlj stored
procedures as 'not threadsafe' and share the context like you used to
(use the old way of defining the null connection). (I haven't acutally
tried this, but it should work) :-).

You have to choose the tradeoff of multiple JVMs per instance (1 per
concurrently active non threadsafe Java routine) vs. changing your
routines. The change to threadedness was done for scalability.

Janick wrote:
With DB2 7.2 we used to call methods from other SQLJ Stored
Procedures, as it was not possible to call SPs via the SQL
Call-statement from within SPs. So we always had a method like this:

protected static void execute(Connection con, (...))

Where we passed a Connection object for dynamic SQL (which we got
using the getConnection() method of the DefaultContext). Static SQL
was always executed on the DefaultContext.

Now with DB2 8.1 we are forced to create a dedicated Context for each
SP, and therefore changed our execute-method to something like this:

protected static void execute(ConnectionContext context, Connection
con, (...))

The problem now is that the SQLJ Precompiler doesn't like the "simple"
ConnectionContext. So if you would try something like this in the
"execute" method

#sql [context] { SELECT imbreqd FROM sysibm.sysdummy1 }

the precompiler says that you have to declare ConnectionContextes
using #sql context declaration. So I changed the execute-method to the
following:

protected static void execute(SPName_ConnectionContext context,
Connection con, (...))

This works fine for the current procedure, but I cannot call the
method from another SP anymore.

There are two solutions which come to mind:
1. Call one SP from another using the SQL-Call-command (now supported
with 8.1)
2. Define one global ConnectionContext used by all SPs

The first solution I don't like as it is much slower than calling a
Java method directly. I'm not sure if the second solution is a
"proper" solution, as you always operate on the same context-class and
this may therefore not be threadsafe (I don't know how those
context-classes are implemented).

Maybe somebody can think of another (better) solution or tell me
whether the second solution would be threadsafe or not.

Regards,
- Janick Bernet, SwissASP

Nov 12 '05 #2
The reason you need a seperate context in 8.1 is that we're
multithreading on the JVM. Without a context per thread, threads would
run wild over each others objects (cursors etc) closing them, and other
bad things.

If you don't want to use CALL, you can catalog your sqlj stored
procedures as 'not threadsafe' and share the context like you used to
(use the old way of defining the null connection). (I haven't acutally
tried this, but it should work) :-).

You have to choose the tradeoff of multiple JVMs per instance (1 per
concurrently active non threadsafe Java routine) vs. changing your
routines. The change to threadedness was done for scalability.

Janick wrote:
With DB2 7.2 we used to call methods from other SQLJ Stored
Procedures, as it was not possible to call SPs via the SQL
Call-statement from within SPs. So we always had a method like this:

protected static void execute(Connection con, (...))

Where we passed a Connection object for dynamic SQL (which we got
using the getConnection() method of the DefaultContext). Static SQL
was always executed on the DefaultContext.

Now with DB2 8.1 we are forced to create a dedicated Context for each
SP, and therefore changed our execute-method to something like this:

protected static void execute(ConnectionContext context, Connection
con, (...))

The problem now is that the SQLJ Precompiler doesn't like the "simple"
ConnectionContext. So if you would try something like this in the
"execute" method

#sql [context] { SELECT imbreqd FROM sysibm.sysdummy1 }

the precompiler says that you have to declare ConnectionContextes
using #sql context declaration. So I changed the execute-method to the
following:

protected static void execute(SPName_ConnectionContext context,
Connection con, (...))

This works fine for the current procedure, but I cannot call the
method from another SP anymore.

There are two solutions which come to mind:
1. Call one SP from another using the SQL-Call-command (now supported
with 8.1)
2. Define one global ConnectionContext used by all SPs

The first solution I don't like as it is much slower than calling a
Java method directly. I'm not sure if the second solution is a
"proper" solution, as you always operate on the same context-class and
this may therefore not be threadsafe (I don't know how those
context-classes are implemented).

Maybe somebody can think of another (better) solution or tell me
whether the second solution would be threadsafe or not.

Regards,
- Janick Bernet, SwissASP

Nov 12 '05 #3
> The reason you need a seperate context in 8.1 is that we're
multithreading on the JVM. Without a context per thread, threads would
run wild over each others objects (cursors etc) closing them, and other
bad things.


My main question regarding this is (which is not answered in then docu
and not apperant in the examples): do you need a seperate context
*class* per procedure or is it enough to have a seperate context
*instances*. I'm afraid its the first one, but I just can't really
imagine why, because thread-safety can easily be achieved on different
instance of the same class.
Anyone has more insight on the db2-sqlj-internals?

Regards
- Janick Bernet, SwissASP
Nov 12 '05 #4
> The reason you need a seperate context in 8.1 is that we're
multithreading on the JVM. Without a context per thread, threads would
run wild over each others objects (cursors etc) closing them, and other
bad things.


My main question regarding this is (which is not answered in then docu
and not apperant in the examples): do you need a seperate context
*class* per procedure or is it enough to have a seperate context
*instances*. I'm afraid its the first one, but I just can't really
imagine why, because thread-safety can easily be achieved on different
instance of the same class.
Anyone has more insight on the db2-sqlj-internals?

Regards
- Janick Bernet, SwissASP
Nov 12 '05 #5
The context as it was created/attained by the SP pre v8 was an SQLJ
static entry (everyone got the same context). If you're running non
threadsafe you can get away with a single instance of this connection
object.

Janick wrote:
The reason you need a seperate context in 8.1 is that we're
multithreading on the JVM. Without a context per thread, threads would
run wild over each others objects (cursors etc) closing them, and other
bad things.

My main question regarding this is (which is not answered in then docu
and not apperant in the examples): do you need a seperate context
*class* per procedure or is it enough to have a seperate context
*instances*. I'm afraid its the first one, but I just can't really
imagine why, because thread-safety can easily be achieved on different
instance of the same class.
Anyone has more insight on the db2-sqlj-internals?

Regards
- Janick Bernet, SwissASP

Nov 12 '05 #6
The context as it was created/attained by the SP pre v8 was an SQLJ
static entry (everyone got the same context). If you're running non
threadsafe you can get away with a single instance of this connection
object.

Janick wrote:
The reason you need a seperate context in 8.1 is that we're
multithreading on the JVM. Without a context per thread, threads would
run wild over each others objects (cursors etc) closing them, and other
bad things.

My main question regarding this is (which is not answered in then docu
and not apperant in the examples): do you need a seperate context
*class* per procedure or is it enough to have a seperate context
*instances*. I'm afraid its the first one, but I just can't really
imagine why, because thread-safety can easily be achieved on different
instance of the same class.
Anyone has more insight on the db2-sqlj-internals?

Regards
- Janick Bernet, SwissASP

Nov 12 '05 #7
Hmm, Ok. My last chance then to get the thing working threadsafe would
be if the following compiled. Why exactly is that code rejected by the
sqlj-precompiler with the message below?

protected static void execute(ConnectionContext context, Connection
con, (...))
{
#sql [context] { som query };
}

Error: Connection context must have been declared with #sql context
....
It can not be declared as a ConnectionContext.

Maybe its possible to get sqlj to ignore this, as the
ConnectionContext passed would effectively be a "correct"
ConnectionContext declared using "#sql context ...".
Sean McKeough <mc******@nospam.ca.ibm.com> wrote in message news:<c7**********@hanover.torolab.ibm.com>...
The context as it was created/attained by the SP pre v8 was an SQLJ
static entry (everyone got the same context). If you're running non
threadsafe you can get away with a single instance of this connection
object.

Nov 12 '05 #8
Sadly I do not know the inner workings of sqlj well (I only know the
pieces that caused java routines to break once we moved to
threaded)...sorry. :-(

Janick wrote:
Hmm, Ok. My last chance then to get the thing working threadsafe would
be if the following compiled. Why exactly is that code rejected by the
sqlj-precompiler with the message below?

protected static void execute(ConnectionContext context, Connection
con, (...))
{
#sql [context] { som query };
}

Error: Connection context must have been declared with #sql context
...
It can not be declared as a ConnectionContext.

Maybe its possible to get sqlj to ignore this, as the
ConnectionContext passed would effectively be a "correct"
ConnectionContext declared using "#sql context ...".
Sean McKeough <mc******@nospam.ca.ibm.com> wrote in message news:<c7**********@hanover.torolab.ibm.com>...
The context as it was created/attained by the SP pre v8 was an SQLJ
static entry (everyone got the same context). If you're running non
threadsafe you can get away with a single instance of this connection
object.

Nov 12 '05 #9
Sean McKeough <mc******@nospam.ca.ibm.com> wrote in message news:<c7**********@hanover.torolab.ibm.com>...
Sadly I do not know the inner workings of sqlj well (I only know the
pieces that caused java routines to break once we moved to
threaded)...sorry. :-(


No Problem, thanks for your help so far.

I decided to do a workaround to achieve what I want. I defined the
method in sqlj as enforced by the precompiler using a dedicated
ConnectionContext like this:

#sql context MyProcContext;
...
public static void execute(MyProcContext context, ...);
{
#sql context { some query };
}

And then replace MyProcContext with a general ConnectionContext in the
java-file generated by the precompiler. This way I can call the
execute() method from other procedures with their corresponding
ConnectionContexts as parameter.

I still wonder why the sqlj-precompiler doesn't allow we to define a
general ConnectionContext to use for executing SQL, as this is
completly legal and doesn't raise an exception if done in the
java-source. In the generated source all contexts are even accessed as
a simple ConnectionContext:

sqlj.runtime.ConnectionContext __sJT_connCtx = context;

Anyway, it works now. Hope it will still work on next Fixpack,
though... ;)
Nov 12 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Almund Sebi | last post by:
Hello I have just found this advice on the net: http://www.share.org/proceedings/sh98/data/S1326.PDF I'm interested mainly in page 19: > Use explicit connection context objects > If...
0
by: Janick | last post by:
With DB2 7.2 we used to call methods from other SQLJ Stored Procedures, as it was not possible to call SPs via the SQL Call-statement from within SPs. So we always had a method like this: ...
5
by: Raquel | last post by:
This is a very simple DB2 SQLJ stored procedure. The problem is that it seems to run fine but returns NOTHING. I mean..as if nothing has happened..not resultset is returned. I am passing value...
2
by: Jean-Marc Blaise | last post by:
Hi, The Information Center (V8 FP4) states that "Each SQL statement must explicitly indicate the Connection Context object, and that context must be explicitly instantiated in the Java method"...
12
by: Rhino | last post by:
I am having an odd problem: the sqlj command on my system doesn't work. I am running DB2 (LUW) V8 (FP8) on WinXP. I haven't done an sqlj program since Version 6 of DB2 (LUW) so I checked the...
2
by: Jean-Marc Blaise | last post by:
Dear all, We try to isolate on Windows 8.2 FP8/FP9 a problem or a bug ? we have on call's on SQLJ procs. Call proc gives SQL0818 indicating a mismatch between the JAR and package (all was...
7
by: Jean-Marc Blaise | last post by:
Hi, The dev center calls sqlj.DB2_UPDATEJARINFO ('JMARC.JMB','JMB','file:JMB.sqlj') to update the sqlj routine source. I tried in CLP from the directory containing jar and sqlj files (Windows...
1
by: vasilip | last post by:
I'm trying to insert large polygon data via sql statement. since the data was over 32k I had to use sqlj to insert my data. I made a class that inserts the data. ran sqlj, generated the .java...
0
by: ajitkathar | last post by:
In my SQLJ procedure , there is call to another stored procedure using a callable statement. But during excecution when .excute() happens . . the DB2 V7 database shuts down. Plz help. Follwing...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.