openjpa-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Amy Yang" <milo...@gmail.com>
Subject Re: about the initialization of DB2Dictionary
Date Thu, 03 Apr 2008 05:39:14 GMT
Hi Catalina,
Thank you for the quick response.
As you mentioned, one approach is adding some null check to avoid the NPE.
And  some  warnings should be output to inform user about creating index
manually. And corresponding document for reference.
Is there any possibility to automatically create the index without
connection to database?
By the way, I've opened a JIRA issue for this problem:
https://issues.apache.org/jira/browse/OPENJPA-549


Thanks,
Amy

2008/4/2, catalina wei <catalina.wei@gmail.com>:
>
> HI Amy,
> Several methods in DB2Dictionary precondition is that
> connectedConfiguration() is called so that databaseProductName and
> databaseProductVersion are initialized.
>
> A quick fix for you is to modify isDB2... method to check for not nulls,
> for
> example:
>
>
>     public boolean isDB2UDBV82OrLater() {
>         boolean match = false;
>         if (databaseProductName != null &&
>             (databaseProductVersion.indexOf("SQL") != -1
>             || databaseProductName.indexOf("DB2/") != -1)
>             && ((maj == 8 && min >= 2) || (maj >= 9)))
>             match = true;
>         return match;
>     }
>
>     public boolean isDB2ZOSV8xOrLater() {
>        boolean match = false;
>        if (databaseProductName != null &&
>            (databaseProductVersion.indexOf("DSN") != -1
>            || databaseProductName.indexOf("DB2/") == -1)
>            && maj >= 8)
>            match = true;
>         return match;
>     }
>
>     public boolean isDB2ISeriesV5R3OrEarlier() {
>        boolean match = false;
>        if (databaseProductName != null &&
>            databaseProductName.indexOf("AS") != -1
>            && ((maj == 5 && min <=3) || maj < 5))
>            match = true;
>        return match;
>     }
>
>     public boolean isDB2ISeriesV5R4OrLater() {
>        boolean match = false;
>        if (databaseProductName != null &&
>            databaseProductName.indexOf("AS") != -1
>            && (maj >=6 || (maj == 5 && min >=4)))
>            match = true;
>       return match;
>     }
>
>     public boolean isDB2UDBV81OrEarlier() {
>         boolean match = false;
>         if (databaseProductName != null &&
>             (databaseProductVersion.indexOf("SQL") != -1
>             || databaseProductName.indexOf("DB2/") != -1) &&
>             ((maj == 8 && min <= 1) || maj < 8))
>             match = true;
>         return match;
>     }
>
>
> This should resolve that  NullPointerExceiption, but requires user to
> manually create index if needed.
>
> If this fix works for you, I can commit the changes.
>
>
> Catalina
>
> On 4/2/08, milotty <milotty@gmail.com> wrote:
> >
> > Hi,
> > Now I'm encountered a problem of NullPointerException like this:
> > java.lang.NullPointerException
> >      at
> > org.apache.openjpa.jdbc.sql.DB2Dictionary.isDB2ZOSV8xOrLater(
> > DB2Dictionary.java:392)
> >
> >      at
> > org.apache.openjpa.jdbc.sql.DB2Dictionary.createIndexIfNecessary(
> > DB2Dictionary.java:784)
> >
> >      at
> > org.apache.openjpa.jdbc.kernel.TableJDBCSeq.addSchema(TableJDBCSeq.java
> > :244)
> >
> >      at
> > org.apache.openjpa.jdbc.meta.MappingTool.addSequenceComponents(
> > MappingTool.java:609)
> >
> >      at
> > org.apache.openjpa.jdbc.meta.MappingTool.addSequenceComponents(
> > MappingTool.java:591)
> >
> >      at
> > org.apache.openjpa.jdbc.meta.MappingTool.record(MappingTool.java:477)
> >      at org.apache.openjpa.jdbc.meta.MappingTool.run(MappingTool.java
> > :1075)
> >      at
> >
> org.apache.openjpa.jdbc.ant.MappingToolTask.executeOn(MappingToolTask.java
> > :197)
> >
> >      at
> > org.apache.openjpa.lib.ant.AbstractTask.execute(AbstractTask.java:172)
> >      at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java
> > :275)
> >
> >      at org.apache.tools.ant.Task.perform(Task.java:364)
> >      at org.apache.tools.ant.taskdefs.Sequential.execute(Sequential.java
> > :64)
> >
> >      at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java
> > :275)
> >
> >      at org.apache.tools.ant.Task.perform(Task.java:364)
> >
> > The scenario is I'm only using the ant task of MappingTool to build
> schema
> > for some JDO classes.
> > I looked into the source code a little. The problem is when
> > org.apache.openjpa.jdbc.kernel.TableJDBCSeq.addSchema() invokes
> > org.apache.openjpa.jdbc.sql.DB2Dictionary.createIndexIfNecessary() to
> > create
> > the index for the sequence table, the databaseProductVersion and/or
> > databaseProductName of DB2Dictionary are needed. But these 2 variables
> > will
> > not be initialized until DB2Dictionary.connectedConfiguration() is
> > invoked,
> > and it need a connection to the database. But in addSchema(), there
> isn't
> > any connection yet.
> > MappingTool doesn't always require a connection. So it should be wrong
> if
> > simply adding a connection before addSchema() invoked.
> >
> > Could anyone give me any suggestion of this problem? How to resolve this
> > problem in OpenJPA scope? Or, is there any method from DB2 side can be
> > used
> > to get databaseProductVersion and/or databaseProductName without a
> > connection to database?
> >
> >
> >
> > Thanks,
> > Amy
> >
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message