Search code examples
javasqlj

SQLJ produced invalid Java code


although I an an old time user of the Website, but managed to resolve problems myself before. This time I need your advice :)

The situation: I've inherited the old Java project code where SQLJ is used for database access. Neither Database nor SQLJ are needed in the project, but I cannot change the history so have to live with it. Another part of the story is that development was done in JDeveloper before, however new company standards require Eclipse (a better product in my preference).

But I've got a problem with migrating SQLJs to be automatically built with Ant using javac instead of Oracle compiler. So here comes the problem:

Java files generated by SQLJs are not valid for javac compiler due to differences in Package structure. However JDeveloper (11.1.1.0.2) accepts such java files as far as it uses old oracle compiler. The example of both sqlj and Java to explain the problem better:

SQLJ

package Sess;
public class UserDB extends Object implements SessConstants
{
    #sql public static iterator  UserIterator(
         String              m
<cut off>
      );
<cut off>

private static UserIterator   UserIter  = null;
}

public static boolean readNext(User theUser )
  throws SQLException
  {
    if (iteratorOpen == false)
    {
     #sql UserIter = {
        select
          m
          <cut off>
   from
          <cut off>
  };

  iteratorOpen = true;
  <cut off>

Generated JAVA:

package Sess;
public class UserDB extends Object implements SessConstants
{
public static class UserIterator
extends sqlj.runtime.ref.ResultSetIterImpl
implements sqlj.runtime.NamedIterator
<cut off>
public static boolean readNext(User theUser )
throws SQLException
{
if (iteratorOpen == false)
{
<cut off>

{
<cut off>

UserIter = new Sess.UserDB.UserIterator(new 
...
<cut off>

The problem is with tha last statement

UserIter = new Sess.UserDB.UserIterator(new     ...

It should actually be:

UserIter = new UserDB.UserIterator(new 

Then it is ok.

Note that newer versions of JDeveloper have the same problem as they use javac (I believe) as well.

As a workaround we store Java files along with SQLJ and after we regenerate java from an SQLJ changed we fix Java again. Not quite happy in doing that stuff manually as it invalidates automatic build procedure for the cases when SQLJ needs to be updated.

Anyone has any ideas? Your help is much appreciated :)

Cheers


Solution

  • Well, not much I can get in response, although that's reasonable - topic is a rare one. Not much that I've found myself too. It looks like there is an existing problem with ant and sqlj which needs to be overcome.

    In fact we had to keep up with original workaround. i.e. we do compile the sqlj's, then modify files manually (scrip does it) and then compile it. Ugly but works.