objectbridge-developers Mailing List for ObJectRelationalBridge (Page 39)
Brought to you by:
thma
You can subscribe to this list here.
2000 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
(14) |
Dec
(20) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2001 |
Jan
(33) |
Feb
(8) |
Mar
(3) |
Apr
(1) |
May
(18) |
Jun
(6) |
Jul
(15) |
Aug
(71) |
Sep
(29) |
Oct
(43) |
Nov
(77) |
Dec
(54) |
2002 |
Jan
(54) |
Feb
(147) |
Mar
(144) |
Apr
(163) |
May
(307) |
Jun
(240) |
Jul
|
Aug
|
Sep
(1) |
Oct
|
Nov
|
Dec
|
From: Mahler T. <tho...@it...> - 2002-02-14 11:17:49
|
Hi all, I prefer the wasNull() solution as getObject() is Problematic with = several JDBC drivers... I will put this on my todo list ! thanks, Thomas > -----Urspr=FCngliche Nachricht----- > Von: Darren Syzling [mailto:Dar...@cw...] > Gesendet: Donnerstag, 14. Februar 2002 10:45 > An: obj...@li...; > tho...@ho... > Betreff: Re: [OJB-developers] Detecting and mapping null=20 > Integer values >=20 >=20 > It appears to me there are two choices: >=20 > - wasNull >=20 > - getObject using a cast, is there any reason this wouldn't=20 > work ? For example: >=20 > case Types.INTEGER : > { > result =3D (Integer)rs.getObject(columnId); > break; > } >=20 > getObject will return a null reference if the column value is null. >=20 >=20 >=20 > Darren >=20 >=20 >=20 > |--------+-----------------------> > | | "Jakob | > | | Braeuchi" | > | | <jbraeuchi@ho| > | | tmail.com> | > | | | > | | 02/13/02 | > | | 07:44 PM | > | | | > |--------+-----------------------> > =20 > >------------------------------------------------------------- > ---------------| > | =20 > | > | To: "Thomas Mahler"=20 > <tho...@ho...>, Darren | > | Syzling/London/CWB@CWB =20 > | > | cc: =20 > obj...@li... | > | Subject: Re: [OJB-developers] Detecting and=20 > mapping null Integer | > | values =20 > | > =20 > >------------------------------------------------------------- > ---------------| >=20 >=20 >=20 >=20 > hi thomas, >=20 > what about using wasNull of ResultSet ? >=20 > /** > * Reports whether > * the last column read had a value of SQL <code>NULL</code>. > * Note that you must first call one of the <code>getXXX</code> = methods > * on a column to try to read its value and then call > * the method <code>wasNull</code> to see if the value read was > * SQL <code>NULL</code>. > * > * @return <code>true</code> if the last column value read was SQL > * <code>NULL</code> and <code>false</code> otherwise > * @exception SQLException if a database access error occurs > */ > boolean wasNull() throws SQLException; >=20 > hth jakob >=20 > ----- Original Message ----- > From: "Thomas Mahler" <tho...@ho...> > To: "Darren Syzling" <Dar...@cw...> > Cc: <obj...@li...> > Sent: Wednesday, February 13, 2002 8:09 PM > Subject: Re: [OJB-developers] Detecting and mapping null=20 > Integer values >=20 >=20 > > Hi Darren, > > > > Darren Syzling wrote: > > > > > How can I detect null values for Integer, Long, Double=20 > etc Java class > attributes > > > ? Let's say we're mapping an object which has the=20 > following attributes: > > > > > > class Test > > > { > > > Integer id; > > > String name; > > > Integer sales; > > > } > > > > > > > > > Let's assume that both name and sales can be null. When=20 > retrieving this > object > > > from the database using the PersistenceBroker the String=20 > reference will > be null > > > but the sales reference will in fact refer to an Integer=20 > object with a > zero > > > value. If zero is within the valid range how can we=20 > detect that the > value is > > > actually null. > > > > > > This appears to boil down to:=20 > JdbcAccess.getObjectFromColumn. The code > to > > > convert a string looks like: > > > > > > case Types.VARCHAR: > > > result =3D rs.getString(columnId); > > > break; > > > > > > If the string value is null getString will return a null=20 > reference. But > for > > > Integer (and other classes) the following is used: > > > > > > case Types.INTEGER: > > > result =3D new Integer(rs.getInt(columnId)); > > > break; > > > > > > > > > > > I get your point. But: how should the above code look like to = handle > > your problem correctly? I have no idea. > > If you (or somebody else) tell me how this section should=20 > look like I > > will change it! > > > > > > java.sql.ResultSet does not tell you that a column is NULL. It just > > returns a 0. Of course this is wrong. But SUN specified it this = way. > > Or am I missing something? From the java.sql.ResultSet Source: > > > > /** > > * Gets the value of the designated column in the current row > > * of this <code>ResultSet</code> object as > > * an <code>int</code> in the Java programming language. > > * > > * @param columnIndex the first column is 1, the=20 > second is 2, ... > > * @return the column value; if the value is SQL=20 > <code>NULL</code>, > > * the value returned is <code>0</code> > > * @exception SQLException if a database access error occurs > > */ > > int getInt(int columnIndex) throws SQLException; > > > > > > > getInt will return 0 for null and the an integer will be=20 > created with a > zero > > > value. > > > > > > The Conversion Strategy stuff appears too late in the day=20 > to make the > > > conversion. > > > > > > You are right, things are already on the wrong track at=20 > this point.... > > > > How is everybody else handling this or have I missed something ? > > > > > > cu, > > > > Thomas > > > > > > > > > > > > > Thanks > > > Darren > > > > > > > > > > > > > ************************************************************** > ************** > ************************************************************** > ************ > > > This e-mail has been prepared using information believed by = the > author to be > > > reliable and accurate, but Thales Information Systems=20 > Finance makes no > > > warranty as to accuracy or completeness. In particular Thales > Information > > > Systems Finance does not accept responsibility for =20 > changes made to > this > > > e-mail after it was sent. Any opinions expressed in=20 > this document are > those of > > > the author and do not necessarily reflect the opinions=20 > of the company > or its > > > affiliates. They may be subject to change without notice. > > > This e-mail, its content and any files transmitted with it = are > intended > > > solely for the addressee(s) and may be legally = privileged > and/or > > > confidential. Access by any other party is unauthorised=20 > without the > express > > > written permission of the sender. If you have received=20 > this e-mail in > error you > > > may not copy or use the contents, attachments or=20 > information in any > way. > > > Please destroy it and contact the sender via the Thales=20 > Information > Systems > > > Finance switchboard in London at +44 (0) 20 7650 0100 or=20 > via e-mail > return. > > > This message and any attachments have been scanned > > > for viruses prior to leaving the originators network. The=20 > originator > does not > > > guarantee the security of this message and will not be=20 > responsible for > any > > > damages arising from any alteration of this message by a=20 > third party or > as a > > > result of any virus being passed on. > > > > ************************************************************** > ************** > ************************************************************** > ************* > > > > > > > > > > > > _______________________________________________ > > > Objectbridge-developers mailing list > > > Obj...@li... > > >=20 https://lists.sourceforge.net/lists/listinfo/objectbridge-developers > > > > > > > > > > > > > _______________________________________________ > Objectbridge-developers mailing list > Obj...@li... > https://lists.sourceforge.net/lists/listinfo/objectbridge-developers > _______________________________________________ Objectbridge-developers mailing list Obj...@li... https://lists.sourceforge.net/lists/listinfo/objectbridge-developers _______________________________________________ Objectbridge-developers mailing list Obj...@li... https://lists.sourceforge.net/lists/listinfo/objectbridge-developers |
From: Darren S. <Dar...@cw...> - 2002-02-14 09:51:29
|
It appears to me there are two choices: - wasNull - getObject using a cast, is there any reason this wouldn't work ? For example: case Types.INTEGER : { result = (Integer)rs.getObject(columnId); break; } getObject will return a null reference if the column value is null. Darren |--------+-----------------------> | | "Jakob | | | Braeuchi" | | | <jbraeuchi@ho| | | tmail.com> | | | | | | 02/13/02 | | | 07:44 PM | | | | |--------+-----------------------> >----------------------------------------------------------------------------| | | | To: "Thomas Mahler" <tho...@ho...>, Darren | | Syzling/London/CWB@CWB | | cc: obj...@li... | | Subject: Re: [OJB-developers] Detecting and mapping null Integer | | values | >----------------------------------------------------------------------------| hi thomas, what about using wasNull of ResultSet ? /** * Reports whether * the last column read had a value of SQL <code>NULL</code>. * Note that you must first call one of the <code>getXXX</code> methods * on a column to try to read its value and then call * the method <code>wasNull</code> to see if the value read was * SQL <code>NULL</code>. * * @return <code>true</code> if the last column value read was SQL * <code>NULL</code> and <code>false</code> otherwise * @exception SQLException if a database access error occurs */ boolean wasNull() throws SQLException; hth jakob ----- Original Message ----- From: "Thomas Mahler" <tho...@ho...> To: "Darren Syzling" <Dar...@cw...> Cc: <obj...@li...> Sent: Wednesday, February 13, 2002 8:09 PM Subject: Re: [OJB-developers] Detecting and mapping null Integer values > Hi Darren, > > Darren Syzling wrote: > > > How can I detect null values for Integer, Long, Double etc Java class attributes > > ? Let's say we're mapping an object which has the following attributes: > > > > class Test > > { > > Integer id; > > String name; > > Integer sales; > > } > > > > > > Let's assume that both name and sales can be null. When retrieving this object > > from the database using the PersistenceBroker the String reference will be null > > but the sales reference will in fact refer to an Integer object with a zero > > value. If zero is within the valid range how can we detect that the value is > > actually null. > > > > This appears to boil down to: JdbcAccess.getObjectFromColumn. The code to > > convert a string looks like: > > > > case Types.VARCHAR: > > result = rs.getString(columnId); > > break; > > > > If the string value is null getString will return a null reference. But for > > Integer (and other classes) the following is used: > > > > case Types.INTEGER: > > result = new Integer(rs.getInt(columnId)); > > break; > > > > > > I get your point. But: how should the above code look like to handle > your problem correctly? I have no idea. > If you (or somebody else) tell me how this section should look like I > will change it! > > > java.sql.ResultSet does not tell you that a column is NULL. It just > returns a 0. Of course this is wrong. But SUN specified it this way. > Or am I missing something? From the java.sql.ResultSet Source: > > /** > * Gets the value of the designated column in the current row > * of this <code>ResultSet</code> object as > * an <code>int</code> in the Java programming language. > * > * @param columnIndex the first column is 1, the second is 2, ... > * @return the column value; if the value is SQL <code>NULL</code>, > * the value returned is <code>0</code> > * @exception SQLException if a database access error occurs > */ > int getInt(int columnIndex) throws SQLException; > > > > getInt will return 0 for null and the an integer will be created with a zero > > value. > > > > The Conversion Strategy stuff appears too late in the day to make the > > conversion. > > > You are right, things are already on the wrong track at this point.... > > How is everybody else handling this or have I missed something ? > > > cu, > > Thomas > > > > > > > > Thanks > > Darren > > > > > > > > **************************************************************************** ************************************************************************** > > This e-mail has been prepared using information believed by the author to be > > reliable and accurate, but Thales Information Systems Finance makes no > > warranty as to accuracy or completeness. In particular Thales Information > > Systems Finance does not accept responsibility for changes made to this > > e-mail after it was sent. Any opinions expressed in this document are those of > > the author and do not necessarily reflect the opinions of the company or its > > affiliates. They may be subject to change without notice. > > This e-mail, its content and any files transmitted with it are intended > > solely for the addressee(s) and may be legally privileged and/or > > confidential. Access by any other party is unauthorised without the express > > written permission of the sender. If you have received this e-mail in error you > > may not copy or use the contents, attachments or information in any way. > > Please destroy it and contact the sender via the Thales Information Systems > > Finance switchboard in London at +44 (0) 20 7650 0100 or via e-mail return. > > This message and any attachments have been scanned > > for viruses prior to leaving the originators network. The originator does not > > guarantee the security of this message and will not be responsible for any > > damages arising from any alteration of this message by a third party or as a > > result of any virus being passed on. > > **************************************************************************** *************************************************************************** > > > > > > > > _______________________________________________ > > Objectbridge-developers mailing list > > Obj...@li... > > https://lists.sourceforge.net/lists/listinfo/objectbridge-developers > > > > > > > > > > > > > _______________________________________________ > Objectbridge-developers mailing list > Obj...@li... > https://lists.sourceforge.net/lists/listinfo/objectbridge-developers > _______________________________________________ Objectbridge-developers mailing list Obj...@li... https://lists.sourceforge.net/lists/listinfo/objectbridge-developers |
From: Jakob B. <jbr...@ho...> - 2002-02-14 07:50:32
|
hi thomas, i think the method set() of PersistentField could be streamlined a lot when using f.set(obj,value) instead of the if-else-cascade. public void set(Object obj, Object value) throws IllegalAccessException, IllegalArgumentException { boolean before = getField().isAccessible(); AccessController.doPrivileged(new SetAccessibleAction()); Field f = getField(); Class type = f.getType(); try { f.set(obj,value); } catch (IllegalArgumentException ex) { getField().setAccessible(before); LoggerFactory.getDefaultLogger().error(ex); LoggerFactory.getDefaultLogger().error("field: " + fieldname + ", type: " + type); LoggerFactory.getDefaultLogger().error("value: " + value + ", type: " + value.getClass()); throw ex; } getField().setAccessible(before); } jakob ----- Original Message ----- From: "Thomas Mahler" <tho...@ho...> To: "Darren Syzling" <Dar...@cw...> Cc: <obj...@li...> Sent: Wednesday, February 13, 2002 8:09 PM Subject: Re: [OJB-developers] Detecting and mapping null Integer values > Hi Darren, > > Darren Syzling wrote: > > > How can I detect null values for Integer, Long, Double etc Java class attributes > > ? Let's say we're mapping an object which has the following attributes: > > > > class Test > > { > > Integer id; > > String name; > > Integer sales; > > } > > > > > > Let's assume that both name and sales can be null. When retrieving this object > > from the database using the PersistenceBroker the String reference will be null > > but the sales reference will in fact refer to an Integer object with a zero > > value. If zero is within the valid range how can we detect that the value is > > actually null. > > > > This appears to boil down to: JdbcAccess.getObjectFromColumn. The code to > > convert a string looks like: > > > > case Types.VARCHAR: > > result = rs.getString(columnId); > > break; > > > > If the string value is null getString will return a null reference. But for > > Integer (and other classes) the following is used: > > > > case Types.INTEGER: > > result = new Integer(rs.getInt(columnId)); > > break; > > > > > > I get your point. But: how should the above code look like to handle > your problem correctly? I have no idea. > If you (or somebody else) tell me how this section should look like I > will change it! > > > java.sql.ResultSet does not tell you that a column is NULL. It just > returns a 0. Of course this is wrong. But SUN specified it this way. > Or am I missing something? From the java.sql.ResultSet Source: > > /** > * Gets the value of the designated column in the current row > * of this <code>ResultSet</code> object as > * an <code>int</code> in the Java programming language. > * > * @param columnIndex the first column is 1, the second is 2, ... > * @return the column value; if the value is SQL <code>NULL</code>, > * the value returned is <code>0</code> > * @exception SQLException if a database access error occurs > */ > int getInt(int columnIndex) throws SQLException; > > > > getInt will return 0 for null and the an integer will be created with a zero > > value. > > > > The Conversion Strategy stuff appears too late in the day to make the > > conversion. > > > You are right, things are already on the wrong track at this point.... > > How is everybody else handling this or have I missed something ? > > > cu, > > Thomas > > > > > > > > Thanks > > Darren > > > > > > > > **************************************************************************** ************************************************************************** > > This e-mail has been prepared using information believed by the author to be > > reliable and accurate, but Thales Information Systems Finance makes no > > warranty as to accuracy or completeness. In particular Thales Information > > Systems Finance does not accept responsibility for changes made to this > > e-mail after it was sent. Any opinions expressed in this document are those of > > the author and do not necessarily reflect the opinions of the company or its > > affiliates. They may be subject to change without notice. > > This e-mail, its content and any files transmitted with it are intended > > solely for the addressee(s) and may be legally privileged and/or > > confidential. Access by any other party is unauthorised without the express > > written permission of the sender. If you have received this e-mail in error you > > may not copy or use the contents, attachments or information in any way. > > Please destroy it and contact the sender via the Thales Information Systems > > Finance switchboard in London at +44 (0) 20 7650 0100 or via e-mail return. > > This message and any attachments have been scanned > > for viruses prior to leaving the originators network. The originator does not > > guarantee the security of this message and will not be responsible for any > > damages arising from any alteration of this message by a third party or as a > > result of any virus being passed on. > > **************************************************************************** *************************************************************************** > > > > > > > > _______________________________________________ > > Objectbridge-developers mailing list > > Obj...@li... > > https://lists.sourceforge.net/lists/listinfo/objectbridge-developers > > > > > > > > > > > > > _______________________________________________ > Objectbridge-developers mailing list > Obj...@li... > https://lists.sourceforge.net/lists/listinfo/objectbridge-developers > |
From: Jakob B. <jbr...@ho...> - 2002-02-14 07:35:12
|
hi, the attached zip contains JdbcAccess using wasNull: case Types.INTEGER : { int val = rs.getInt(columnId); if (!rs.wasNull()) result = new Integer(val); break; } hth jakob ----- Original Message ----- From: "Jakob Braeuchi" <jbr...@ho...> To: "Thomas Mahler" <tho...@ho...>; "Darren Syzling" <Dar...@cw...> Cc: <obj...@li...> Sent: Wednesday, February 13, 2002 8:44 PM Subject: Re: [OJB-developers] Detecting and mapping null Integer values > hi thomas, > > what about using wasNull of ResultSet ? > > /** > * Reports whether > * the last column read had a value of SQL <code>NULL</code>. > * Note that you must first call one of the <code>getXXX</code> methods > * on a column to try to read its value and then call > * the method <code>wasNull</code> to see if the value read was > * SQL <code>NULL</code>. > * > * @return <code>true</code> if the last column value read was SQL > * <code>NULL</code> and <code>false</code> otherwise > * @exception SQLException if a database access error occurs > */ > boolean wasNull() throws SQLException; > > hth jakob > > ----- Original Message ----- > From: "Thomas Mahler" <tho...@ho...> > To: "Darren Syzling" <Dar...@cw...> > Cc: <obj...@li...> > Sent: Wednesday, February 13, 2002 8:09 PM > Subject: Re: [OJB-developers] Detecting and mapping null Integer values > > > > Hi Darren, > > > > Darren Syzling wrote: > > > > > How can I detect null values for Integer, Long, Double etc Java class > attributes > > > ? Let's say we're mapping an object which has the following attributes: > > > > > > class Test > > > { > > > Integer id; > > > String name; > > > Integer sales; > > > } > > > > > > > > > Let's assume that both name and sales can be null. When retrieving this > object > > > from the database using the PersistenceBroker the String reference will > be null > > > but the sales reference will in fact refer to an Integer object with a > zero > > > value. If zero is within the valid range how can we detect that the > value is > > > actually null. > > > > > > This appears to boil down to: JdbcAccess.getObjectFromColumn. The code > to > > > convert a string looks like: > > > > > > case Types.VARCHAR: > > > result = rs.getString(columnId); > > > break; > > > > > > If the string value is null getString will return a null reference. But > for > > > Integer (and other classes) the following is used: > > > > > > case Types.INTEGER: > > > result = new Integer(rs.getInt(columnId)); > > > break; > > > > > > > > > > > I get your point. But: how should the above code look like to handle > > your problem correctly? I have no idea. > > If you (or somebody else) tell me how this section should look like I > > will change it! > > > > > > java.sql.ResultSet does not tell you that a column is NULL. It just > > returns a 0. Of course this is wrong. But SUN specified it this way. > > Or am I missing something? From the java.sql.ResultSet Source: > > > > /** > > * Gets the value of the designated column in the current row > > * of this <code>ResultSet</code> object as > > * an <code>int</code> in the Java programming language. > > * > > * @param columnIndex the first column is 1, the second is 2, ... > > * @return the column value; if the value is SQL <code>NULL</code>, > > * the value returned is <code>0</code> > > * @exception SQLException if a database access error occurs > > */ > > int getInt(int columnIndex) throws SQLException; > > > > > > > getInt will return 0 for null and the an integer will be created with a > zero > > > value. > > > > > > The Conversion Strategy stuff appears too late in the day to make the > > > conversion. > > > > > > You are right, things are already on the wrong track at this point.... > > > > How is everybody else handling this or have I missed something ? > > > > > > cu, > > > > Thomas > > > > > > > > > > > > > Thanks > > > Darren > > > > > > > > > > > > > **************************************************************************** > ************************************************************************** > > > This e-mail has been prepared using information believed by the > author to be > > > reliable and accurate, but Thales Information Systems Finance makes no > > > warranty as to accuracy or completeness. In particular Thales > Information > > > Systems Finance does not accept responsibility for changes made to > this > > > e-mail after it was sent. Any opinions expressed in this document are > those of > > > the author and do not necessarily reflect the opinions of the company > or its > > > affiliates. They may be subject to change without notice. > > > This e-mail, its content and any files transmitted with it are > intended > > > solely for the addressee(s) and may be legally privileged > and/or > > > confidential. Access by any other party is unauthorised without the > express > > > written permission of the sender. If you have received this e-mail in > error you > > > may not copy or use the contents, attachments or information in any > way. > > > Please destroy it and contact the sender via the Thales Information > Systems > > > Finance switchboard in London at +44 (0) 20 7650 0100 or via e-mail > return. > > > This message and any attachments have been scanned > > > for viruses prior to leaving the originators network. The originator > does not > > > guarantee the security of this message and will not be responsible for > any > > > damages arising from any alteration of this message by a third party or > as a > > > result of any virus being passed on. > > > > **************************************************************************** > *************************************************************************** > > > > > > > > > > > > _______________________________________________ > > > Objectbridge-developers mailing list > > > Obj...@li... > > > https://lists.sourceforge.net/lists/listinfo/objectbridge-developers > > > > > > > > > > > > > > > > > > > > > > _______________________________________________ > > Objectbridge-developers mailing list > > Obj...@li... > > https://lists.sourceforge.net/lists/listinfo/objectbridge-developers > > > > _______________________________________________ > Objectbridge-developers mailing list > Obj...@li... > https://lists.sourceforge.net/lists/listinfo/objectbridge-developers > |
From: Jakob B. <jbr...@ho...> - 2002-02-13 19:43:09
|
hi thomas, what about using wasNull of ResultSet ? /** * Reports whether * the last column read had a value of SQL <code>NULL</code>. * Note that you must first call one of the <code>getXXX</code> methods * on a column to try to read its value and then call * the method <code>wasNull</code> to see if the value read was * SQL <code>NULL</code>. * * @return <code>true</code> if the last column value read was SQL * <code>NULL</code> and <code>false</code> otherwise * @exception SQLException if a database access error occurs */ boolean wasNull() throws SQLException; hth jakob ----- Original Message ----- From: "Thomas Mahler" <tho...@ho...> To: "Darren Syzling" <Dar...@cw...> Cc: <obj...@li...> Sent: Wednesday, February 13, 2002 8:09 PM Subject: Re: [OJB-developers] Detecting and mapping null Integer values > Hi Darren, > > Darren Syzling wrote: > > > How can I detect null values for Integer, Long, Double etc Java class attributes > > ? Let's say we're mapping an object which has the following attributes: > > > > class Test > > { > > Integer id; > > String name; > > Integer sales; > > } > > > > > > Let's assume that both name and sales can be null. When retrieving this object > > from the database using the PersistenceBroker the String reference will be null > > but the sales reference will in fact refer to an Integer object with a zero > > value. If zero is within the valid range how can we detect that the value is > > actually null. > > > > This appears to boil down to: JdbcAccess.getObjectFromColumn. The code to > > convert a string looks like: > > > > case Types.VARCHAR: > > result = rs.getString(columnId); > > break; > > > > If the string value is null getString will return a null reference. But for > > Integer (and other classes) the following is used: > > > > case Types.INTEGER: > > result = new Integer(rs.getInt(columnId)); > > break; > > > > > > I get your point. But: how should the above code look like to handle > your problem correctly? I have no idea. > If you (or somebody else) tell me how this section should look like I > will change it! > > > java.sql.ResultSet does not tell you that a column is NULL. It just > returns a 0. Of course this is wrong. But SUN specified it this way. > Or am I missing something? From the java.sql.ResultSet Source: > > /** > * Gets the value of the designated column in the current row > * of this <code>ResultSet</code> object as > * an <code>int</code> in the Java programming language. > * > * @param columnIndex the first column is 1, the second is 2, ... > * @return the column value; if the value is SQL <code>NULL</code>, > * the value returned is <code>0</code> > * @exception SQLException if a database access error occurs > */ > int getInt(int columnIndex) throws SQLException; > > > > getInt will return 0 for null and the an integer will be created with a zero > > value. > > > > The Conversion Strategy stuff appears too late in the day to make the > > conversion. > > > You are right, things are already on the wrong track at this point.... > > How is everybody else handling this or have I missed something ? > > > cu, > > Thomas > > > > > > > > Thanks > > Darren > > > > > > > > **************************************************************************** ************************************************************************** > > This e-mail has been prepared using information believed by the author to be > > reliable and accurate, but Thales Information Systems Finance makes no > > warranty as to accuracy or completeness. In particular Thales Information > > Systems Finance does not accept responsibility for changes made to this > > e-mail after it was sent. Any opinions expressed in this document are those of > > the author and do not necessarily reflect the opinions of the company or its > > affiliates. They may be subject to change without notice. > > This e-mail, its content and any files transmitted with it are intended > > solely for the addressee(s) and may be legally privileged and/or > > confidential. Access by any other party is unauthorised without the express > > written permission of the sender. If you have received this e-mail in error you > > may not copy or use the contents, attachments or information in any way. > > Please destroy it and contact the sender via the Thales Information Systems > > Finance switchboard in London at +44 (0) 20 7650 0100 or via e-mail return. > > This message and any attachments have been scanned > > for viruses prior to leaving the originators network. The originator does not > > guarantee the security of this message and will not be responsible for any > > damages arising from any alteration of this message by a third party or as a > > result of any virus being passed on. > > **************************************************************************** *************************************************************************** > > > > > > > > _______________________________________________ > > Objectbridge-developers mailing list > > Obj...@li... > > https://lists.sourceforge.net/lists/listinfo/objectbridge-developers > > > > > > > > > > > > > _______________________________________________ > Objectbridge-developers mailing list > Obj...@li... > https://lists.sourceforge.net/lists/listinfo/objectbridge-developers > |
From: Florian B. <bf...@fl...> - 2002-02-13 19:37:33
|
Hi, > > If the string value is null getString will return a null > reference. But for > > Integer (and other classes) the following is used: > > > > case Types.INTEGER: > > result = new Integer(rs.getInt(columnId)); > > break; > > > > > > I get your point. But: how should the above code look like to handle > your problem correctly? I have no idea. > If you (or somebody else) tell me how this section should look like I > will change it! > the foolproof solution, although not the quickest one: Integer result = null; case Types.INTEGER: if (rs.getObject(columnId) == null) result = null; else result = new Integer(rs.getInt(columnId); break; the optimized but a lot more dangerous solution would be: case Types.INTEGER: result = rs.getObject(columnId); There is no guarantee the getObject will return an Integer object here, so typechecking and conversion would be deferred to the ConversionStragety object. MfG, Florian Bruckner |
From: Thomas M. <tho...@ho...> - 2002-02-13 19:10:07
|
Hi Darren, Darren Syzling wrote: > How can I detect null values for Integer, Long, Double etc Java class attributes > ? Let's say we're mapping an object which has the following attributes: > > class Test > { > Integer id; > String name; > Integer sales; > } > > > Let's assume that both name and sales can be null. When retrieving this object > from the database using the PersistenceBroker the String reference will be null > but the sales reference will in fact refer to an Integer object with a zero > value. If zero is within the valid range how can we detect that the value is > actually null. > > This appears to boil down to: JdbcAccess.getObjectFromColumn. The code to > convert a string looks like: > > case Types.VARCHAR: > result = rs.getString(columnId); > break; > > If the string value is null getString will return a null reference. But for > Integer (and other classes) the following is used: > > case Types.INTEGER: > result = new Integer(rs.getInt(columnId)); > break; > I get your point. But: how should the above code look like to handle your problem correctly? I have no idea. If you (or somebody else) tell me how this section should look like I will change it! java.sql.ResultSet does not tell you that a column is NULL. It just returns a 0. Of course this is wrong. But SUN specified it this way. Or am I missing something? From the java.sql.ResultSet Source: /** * Gets the value of the designated column in the current row * of this <code>ResultSet</code> object as * an <code>int</code> in the Java programming language. * * @param columnIndex the first column is 1, the second is 2, ... * @return the column value; if the value is SQL <code>NULL</code>, * the value returned is <code>0</code> * @exception SQLException if a database access error occurs */ int getInt(int columnIndex) throws SQLException; > getInt will return 0 for null and the an integer will be created with a zero > value. > > The Conversion Strategy stuff appears too late in the day to make the > conversion. You are right, things are already on the wrong track at this point.... How is everybody else handling this or have I missed something ? cu, Thomas > > > Thanks > Darren > > > > ****************************************************************************************************************************************************** > This e-mail has been prepared using information believed by the author to be > reliable and accurate, but Thales Information Systems Finance makes no > warranty as to accuracy or completeness. In particular Thales Information > Systems Finance does not accept responsibility for changes made to this > e-mail after it was sent. Any opinions expressed in this document are those of > the author and do not necessarily reflect the opinions of the company or its > affiliates. They may be subject to change without notice. > This e-mail, its content and any files transmitted with it are intended > solely for the addressee(s) and may be legally privileged and/or > confidential. Access by any other party is unauthorised without the express > written permission of the sender. If you have received this e-mail in error you > may not copy or use the contents, attachments or information in any way. > Please destroy it and contact the sender via the Thales Information Systems > Finance switchboard in London at +44 (0) 20 7650 0100 or via e-mail return. > This message and any attachments have been scanned > for viruses prior to leaving the originators network. The originator does not > guarantee the security of this message and will not be responsible for any > damages arising from any alteration of this message by a third party or as a > result of any virus being passed on. > ******************************************************************************************************************************************************* > > > > _______________________________________________ > Objectbridge-developers mailing list > Obj...@li... > https://lists.sourceforge.net/lists/listinfo/objectbridge-developers > > > > |
From: Darren S. <Dar...@cw...> - 2002-02-13 16:54:53
|
How can I detect null values for Integer, Long, Double etc Java class attributes ? Let's say we're mapping an object which has the following attributes: class Test { Integer id; String name; Integer sales; } Let's assume that both name and sales can be null. When retrieving this object from the database using the PersistenceBroker the String reference will be null but the sales reference will in fact refer to an Integer object with a zero value. If zero is within the valid range how can we detect that the value is actually null. This appears to boil down to: JdbcAccess.getObjectFromColumn. The code to convert a string looks like: case Types.VARCHAR: result = rs.getString(columnId); break; If the string value is null getString will return a null reference. But for Integer (and other classes) the following is used: case Types.INTEGER: result = new Integer(rs.getInt(columnId)); break; getInt will return 0 for null and the an integer will be created with a zero value. The Conversion Strategy stuff appears too late in the day to make the conversion. How is everybody else handling this or have I missed something ? Thanks Darren ****************************************************************************************************************************************************** This e-mail has been prepared using information believed by the author to be reliable and accurate, but Thales Information Systems Finance makes no warranty as to accuracy or completeness. In particular Thales Information Systems Finance does not accept responsibility for changes made to this e-mail after it was sent. Any opinions expressed in this document are those of the author and do not necessarily reflect the opinions of the company or its affiliates. They may be subject to change without notice. This e-mail, its content and any files transmitted with it are intended solely for the addressee(s) and may be legally privileged and/or confidential. Access by any other party is unauthorised without the express written permission of the sender. If you have received this e-mail in error you may not copy or use the contents, attachments or information in any way. Please destroy it and contact the sender via the Thales Information Systems Finance switchboard in London at +44 (0) 20 7650 0100 or via e-mail return. This message and any attachments have been scanned for viruses prior to leaving the originators network. The originator does not guarantee the security of this message and will not be responsible for any damages arising from any alteration of this message by a third party or as a result of any virus being passed on. ******************************************************************************************************************************************************* |
From: <Dal...@bd...> - 2002-02-13 03:25:37
|
I tried out my original code on OJB v0.7.343 and it appears single table inheritance is still be broken, or at least the bug I was encountering still exists. This specific bug shows up when you have descendent classes with *additional* fields. None of the OJB inheritance test cases have descendent classes with additional fields, so the bug never appears. This is strange, because having a bunch of classes with the exact number of fields is an unrealistic example of inheritance. Anyway, this bug has to do with having a descendent with additional fields, for example: class Foo { public int id; public String ojbConcreteClass; public String foo_value; .... } class Bar extends Foo { public Date bar_date; .... } TABLE FOOBAR (contents) ID CLASS_TYPE FOO_VALUE BAR_DATE ---- ---- ---- ---- 1 'Foo' 'A Foo' NULL 2 'Bar' 'A Bar' 02/03/2002 The repository.xml file maps Foo's fields to the first 3 columns, and Bar's fields to all 4 columns. If I try to map this type of class hierarchy with OJB and do a query for all instances of Foo, the first instance, which is *a Foo*, will get read in fine. However, when OJB goes to read in the Bar instance, I get this exception: [ojb.broker.accesslayer.RsIterator] ERROR: 3 3 at ojb.broker.accesslayer.RowReaderDefaultImpl.readObjectFrom(RowReaderDefaultImpl.java:72) at ojb.broker.accesslayer.RsIterator.getObjectFromResultSet(RsIterator.java:251) at ojb.broker.accesslayer.RsIterator.next(RsIterator.java:142) at plprototype2.tests.SingleTableInheritanceTest.testSingleTableInheritance(SingleTableInheritanceTest.java:81) at java.lang.reflect.Method.invoke(Native Method) at junit.framework.TestCase.runTest(TestCase.java:166) at junit.framework.TestCase.runBare(TestCase.java:140) at junit.framework.TestResult$1.protect(TestResult.java:106) at junit.framework.TestResult.runProtected(TestResult.java:124) at junit.framework.TestResult.run(TestResult.java:109) at junit.framework.TestCase.run(TestCase.java:131) at junit.framework.TestSuite.runTest(TestSuite.java:173) at junit.framework.TestSuite.run(TestSuite.java:168) at junit.textui.TestRunner.doRun(TestRunner.java:74) at junit.textui.TestRunner.start(TestRunner.java:234) at junit.textui.TestRunner.main(TestRunner.java:112) at plprototype2.tests.SingleTableInheritanceTest.main(SingleTableInheritanceTest.java:39) [plprototype2.tests.SingleTableInheritanceTest] INFO: Inheritance query failed! java.util.NoSuchElementException at ojb.broker.accesslayer.RsIterator.next(RsIterator.java:151) at plprototype2.tests.SingleTableInheritanceTest.testSingleTableInheritance(SingleTableInheritanceTest.java:81) at java.lang.reflect.Method.invoke(Native Method) at junit.framework.TestCase.runTest(TestCase.java:166) at junit.framework.TestCase.runBare(TestCase.java:140) at junit.framework.TestResult$1.protect(TestResult.java:106) at junit.framework.TestResult.runProtected(TestResult.java:124) at junit.framework.TestResult.run(TestResult.java:109) at junit.framework.TestCase.run(TestCase.java:131) at junit.framework.TestSuite.runTest(TestSuite.java:173) at junit.framework.TestSuite.run(TestSuite.java:168) at junit.textui.TestRunner.doRun(TestRunner.java:74) at junit.textui.TestRunner.start(TestRunner.java:234) at junit.textui.TestRunner.main(TestRunner.java:112) at plprototype2.tests.SingleTableInheritanceTest.main(SingleTableInheritanceTest.java:39) What's happening is that OJB is getting the definition for the number of fields to expect from Foo's mapping definition, but Foo has only been defined with 3 columns: ID, CLASS_TYPE, and FOO_VALUE. When it reads in the Bar instance, the RowReader returns an array of *4* columns: ID, CLASS_TYPE, FOO_VALUE, and BAR_DATE. When it tries to initialize the BAR_DATE value into the object, it goes past the 3 items in the Foo mapping definition and the system throws the java.util.NoSuchElementException. The only way inheritance works is if Foo and Bar had exactly the same fields, like this: class Foo { public int id; public String ojbConcreteClass; public String foo_value; public Date bar_date; .... } class Bar extends Foo { } But of course, this is not inheritance at all and contrary to how most real inheritance trees look. It is my suspicion that this may be a sticky bug to fix, but I hope I'm wrong. Anyway, let me know if this makes any sense or not. Dale Davis |
From: Mahler T. <tho...@it...> - 2002-02-12 09:59:20
|
Hi Dale, > Is it possible to query for all instances of a base class if > its descendents are > mapped to another table using the PersistenceBroker API? I'm > using inheritance > method #2 - two classes/two tables, each with all the fields > from the base class > duplicated and the extents statement in the mapping > definition for the base > class specifying its descendents. When I query for all > instances of the base, > however, I never get any of the descendents. If this > functionality is supposed > to work in OJB, what am I doing wrong? > This scenario is supported. There are several testcases in the package test.ojb.broker testing this behaviour. I the latest release (0.7.343) there have been some fixes to inheritance related stuff. Please check if you still have problems with this new release. HTH, Thomas > > Base.java > --------------- > package plprototype2.domain; > > public class Base { > > public int id; > public String aString; > > public Base() { > } > > public Base(int id, String aString) { > this.id = id; > this.aString = aString; > } > > } > > > Descendent.java > --------------- > package plprototype2.domain; > > public class Descendent extends Base { > public String bString; > > public Descendent() { > } > > public Descendent(int id, String aString, String bString) { > super(id, aString); > this.bString = bString; > } > } > > > schema.sql > --------------- > DROP TABLE BASE_TABLE; > CREATE TABLE BASE_TABLE > ( ID INT NOT NULL PRIMARY KEY, > A_STRING VARCHAR(60) > ); > > DROP TABLE DESCENDENT_TABLE; > CREATE TABLE DESCENDENT_TABLE > ( ID INT NOT NULL PRIMARY KEY, > A_STRING VARCHAR(60), > B_STRING VARCHAR(60) > ); > > INSERT INTO BASE_TABLE VALUES (1,'Base 1'); > INSERT INTO BASE_TABLE VALUES (2,'Base 2'); > > INSERT INTO DESCENDENT_TABLE VALUES (1,'Descendent 1','1'); > INSERT INTO DESCENDENT_TABLE VALUES (2,'Descendent 2','2'); > > > repositor.xml > --------------- > ...<stuff clipped>... > > <ClassDescriptor id="26"> > <class.name>plprototype2.domain.Base</class.name> > <class.extent>plprototype2.domain.Descendent</class.extent> > <table.name>BASE_TABLE</table.name> > <FieldDescriptor id="1"> > <field.name>id</field.name> > <column.name>ID</column.name> > <jdbc_type>INTEGER</jdbc_type> > <PrimaryKey>true</PrimaryKey> > <autoincrement>true</autoincrement> > </FieldDescriptor> > <FieldDescriptor id="2"> > <field.name>aString</field.name> > <column.name>A_STRING</column.name> > <jdbc_type>VARCHAR</jdbc_type> > </FieldDescriptor> > </ClassDescriptor> > > <ClassDescriptor id="25"> > <class.name>plprototype2.domain.Descendent</class.name> > <table.name>DESCENDENT_TABLE</table.name> > <FieldDescriptor id="1"> > <field.name>id</field.name> > <column.name>ID</column.name> > <jdbc_type>INTEGER</jdbc_type> > <PrimaryKey>true</PrimaryKey> > <autoincrement>true</autoincrement> > </FieldDescriptor> > <FieldDescriptor id="2"> > <field.name>aString</field.name> > <column.name>A_STRING</column.name> > <jdbc_type>VARCHAR</jdbc_type> > </FieldDescriptor> > <FieldDescriptor id="3"> > <field.name>bString</field.name> > <column.name>B_STRING</column.name> > <jdbc_type>VARCHAR</jdbc_type> > </FieldDescriptor> > </ClassDescriptor> > > ...<stuff clipped>... > > > PerClassTableInheritanceTest.java > --------------- > package plprototype2.tests; > > import ojb.broker.query.Criteria; > import ojb.broker.query.Query; > import ojb.broker.query.QueryByExample; > import ojb.broker.query.QueryByCriteria; > import plprototype2.domain.Base; > > import java.util.Collection; > > import junit.framework.Assert; > > public class PerClassTableInheritanceTest extends OJBTestCase { > > /** > * Static reference to .class. Java does not provide any > way to obtain the > * Class object from static method without naming it. > */ > private static Class CLASS = PerClassTableInheritanceTest.class; > > /** > * Runs the suite in a junit.textui.TestRunner. > */ > public static void main(String[] args) { > String[] arr = {CLASS.getName()}; > junit.textui.TestRunner.main(arr); > } > > public PerClassTableInheritanceTest(String name) { > super(name); > } > > /** > * Query all objects of Type "Base". You should get 2 from > BASE_TABLE and > * 2 from DESCENDENT_TABLE. > */ > public void testInheritance() { > Criteria selectAll = null; > Query q = new QueryByCriteria(Base.class, selectAll); > Collection c = broker.getCollectionByQuery(q); > logger.info("Base class query returned "+c.size()+" objects."); > Assert.assertEquals("Incorrect number of Base objects > returned!", 4, > c.size()); > } > } > > > > _______________________________________________ > Objectbridge-developers mailing list > Obj...@li... > https://lists.sourceforge.net/lists/listinfo/objectbridge-developers > |
From: <Dal...@bd...> - 2002-02-11 23:12:23
|
Is it possible to query for all instances of a base class if its descendents are mapped to another table using the PersistenceBroker API? I'm using inheritance method #2 - two classes/two tables, each with all the fields from the base class duplicated and the extents statement in the mapping definition for the base class specifying its descendents. When I query for all instances of the base, however, I never get any of the descendents. If this functionality is supposed to work in OJB, what am I doing wrong? Base.java --------------- package plprototype2.domain; public class Base { public int id; public String aString; public Base() { } public Base(int id, String aString) { this.id = id; this.aString = aString; } } Descendent.java --------------- package plprototype2.domain; public class Descendent extends Base { public String bString; public Descendent() { } public Descendent(int id, String aString, String bString) { super(id, aString); this.bString = bString; } } schema.sql --------------- DROP TABLE BASE_TABLE; CREATE TABLE BASE_TABLE ( ID INT NOT NULL PRIMARY KEY, A_STRING VARCHAR(60) ); DROP TABLE DESCENDENT_TABLE; CREATE TABLE DESCENDENT_TABLE ( ID INT NOT NULL PRIMARY KEY, A_STRING VARCHAR(60), B_STRING VARCHAR(60) ); INSERT INTO BASE_TABLE VALUES (1,'Base 1'); INSERT INTO BASE_TABLE VALUES (2,'Base 2'); INSERT INTO DESCENDENT_TABLE VALUES (1,'Descendent 1','1'); INSERT INTO DESCENDENT_TABLE VALUES (2,'Descendent 2','2'); repositor.xml --------------- ...<stuff clipped>... <ClassDescriptor id="26"> <class.name>plprototype2.domain.Base</class.name> <class.extent>plprototype2.domain.Descendent</class.extent> <table.name>BASE_TABLE</table.name> <FieldDescriptor id="1"> <field.name>id</field.name> <column.name>ID</column.name> <jdbc_type>INTEGER</jdbc_type> <PrimaryKey>true</PrimaryKey> <autoincrement>true</autoincrement> </FieldDescriptor> <FieldDescriptor id="2"> <field.name>aString</field.name> <column.name>A_STRING</column.name> <jdbc_type>VARCHAR</jdbc_type> </FieldDescriptor> </ClassDescriptor> <ClassDescriptor id="25"> <class.name>plprototype2.domain.Descendent</class.name> <table.name>DESCENDENT_TABLE</table.name> <FieldDescriptor id="1"> <field.name>id</field.name> <column.name>ID</column.name> <jdbc_type>INTEGER</jdbc_type> <PrimaryKey>true</PrimaryKey> <autoincrement>true</autoincrement> </FieldDescriptor> <FieldDescriptor id="2"> <field.name>aString</field.name> <column.name>A_STRING</column.name> <jdbc_type>VARCHAR</jdbc_type> </FieldDescriptor> <FieldDescriptor id="3"> <field.name>bString</field.name> <column.name>B_STRING</column.name> <jdbc_type>VARCHAR</jdbc_type> </FieldDescriptor> </ClassDescriptor> ...<stuff clipped>... PerClassTableInheritanceTest.java --------------- package plprototype2.tests; import ojb.broker.query.Criteria; import ojb.broker.query.Query; import ojb.broker.query.QueryByExample; import ojb.broker.query.QueryByCriteria; import plprototype2.domain.Base; import java.util.Collection; import junit.framework.Assert; public class PerClassTableInheritanceTest extends OJBTestCase { /** * Static reference to .class. Java does not provide any way to obtain the * Class object from static method without naming it. */ private static Class CLASS = PerClassTableInheritanceTest.class; /** * Runs the suite in a junit.textui.TestRunner. */ public static void main(String[] args) { String[] arr = {CLASS.getName()}; junit.textui.TestRunner.main(arr); } public PerClassTableInheritanceTest(String name) { super(name); } /** * Query all objects of Type "Base". You should get 2 from BASE_TABLE and * 2 from DESCENDENT_TABLE. */ public void testInheritance() { Criteria selectAll = null; Query q = new QueryByCriteria(Base.class, selectAll); Collection c = broker.getCollectionByQuery(q); logger.info("Base class query returned "+c.size()+" objects."); Assert.assertEquals("Incorrect number of Base objects returned!", 4, c.size()); } } |
From: Thomas M. <tho...@ho...> - 2002-02-11 18:21:13
|
Hi Jason, As mentioned on the OJB homepage we currently do not maintain a public CVS repository. (Of course I'm running a private one ;-)) The latest sources can be found in the source distribution at the SourceForge site. I'm planning to relaunch CVS soon. HTH, Thomas Jason van Zyl wrote: > Hi, > > What is the current state of CVS? Is this where the latest versions of the > source files can be found? > > > |
From: Jason v. Z. <jv...@ze...> - 2002-02-11 17:03:09
|
Hi, What is the current state of CVS? Is this where the latest versions of the source files can be found? -- jvz. Jason van Zyl http://tambora.zenplex.org http://jakarta.apache.org/turbine http://jakarta.apache.org/velocity http://jakarta.apache.org/alexandria http://jakarta.apache.org/commons |
From: Jakob B. <jbr...@ho...> - 2002-02-10 12:14:58
|
hi, the attached zip contains modifications to support individual refresh of relationships. <CollectionDescriptor id="1"> <refreshCollection>true</refreshCollection> <ReferenceDescriptor id="1"> <refreshReference>true</refreshReference> refreshRelationship on ClassDescriptor no longer exists. Relationships are refreshed in RsIterator::getObjectFromResultSet() and PersistenceBrokerImpl::getObjectByIdentity(), this leads to the situation that the same relationship gets refreshed several times. i do not yet have a solution to prevent multiple refresh. other fixes: - SqlManager::bindInsert() : default values for optimisticLocking fields. - JdbcAccess::getObjectFromColumn() : get column index from resultset. - SqlBasedRsIterator::getObjectFromColumn() : removed call to m_mif.getRowReader().readObjectArrayFrom(); this is done in super(); jakob |
From: Jakob B. <jbr...@fr...> - 2002-02-10 12:12:15
|
hi, the attached zip contains modifications to support individual refresh of relationships. <CollectionDescriptor id="1"> <refreshCollection>true</refreshCollection> <ReferenceDescriptor id="1"> <refreshReference>true</refreshReference> refreshRelationship on ClassDescriptor no longer exists. Relationships are refreshed in RsIterator::getObjectFromResultSet() and PersistenceBrokerImpl::getObjectByIdentity(), this leads to the situation that the same relationship gets refreshed several times. i do not yet have a solution to prevent multiple refresh. other fixes: - SqlManager::bindInsert() : default values for optimisticLocking fields. - JdbcAccess::getObjectFromColumn() : get column index from resultset. - SqlBasedRsIterator::getObjectFromColumn() : removed call to m_mif.getRowReader().readObjectArrayFrom(); this is done in super(); jakob |
From: <Dal...@bd...> - 2002-02-07 22:26:34
|
I'm trying to map two classes to a single table, but I can't seem to get the mapping file correct. I have a basic inheritance test where B inherits from A. When I run the test case, the A classes read in fine, but I get a java.util.NoSuchElementException when I start reading in the B's. I'm using 0.7.325. What am I doing wrong? Here's what I have: A.java ------ package plprototype2.domain; public class A { protected String ojbConcreteClass; public int id; public String aString; public A() { ojbConcreteClass = A.class.getName(); } public A(int id, String objConcreteClass, String aString) { this.id = id; ojbConcreteClass = A.class.getName(); this.aString = aString; } public String getConcreteClass() { return ojbConcreteClass; } } B.java ------ package plprototype2.domain; public class B extends A { public String bString; public B() { ojbConcreteClass = B.class.getName(); } public B(int id, String objConcreteClass, String aString, String bString) { super(id, objConcreteClass, aString); ojbConcreteClass = B.class.getName(); this.bString = bString; } } SingleTableInheritanceTest.java ------------------------------- package plprototype2.tests; import junit.framework.Assert; import junit.framework.TestCase; import ojb.broker.PersistenceBroker; import ojb.broker.PersistenceBrokerException; import ojb.broker.PersistenceBrokerFactory; import ojb.broker.TransactionNotInProgressException; import ojb.broker.query.Criteria; import ojb.broker.query.Query; import ojb.broker.query.QueryByCriteria; import ojb.broker.util.Logger; import ojb.broker.util.LoggerFactory; import plprototype2.domain.A; import java.util.Iterator; public class SingleTableInheritanceTest extends TestCase { /** * Static reference to .class. Java does not provide any way to obtain the * Class object from static method without naming it. */ private static Class CLASS = SingleTableInheritanceTest.class; /** * Runs the suite in a junit.textui.TestRunner. */ public static void main(String[] args) { String[] arr = {CLASS.getName()}; junit.textui.TestRunner.main(arr); } protected PersistenceBroker broker; protected Logger logger; public SingleTableInheritanceTest(String name) { super(name); } /** * Sets up the fixture, for example, open a network connection. * This method is called before a test is executed. */ protected void setUp() throws Exception { broker = PersistenceBrokerFactory.createPersistenceBroker(); logger = LoggerFactory.getLogger(this.getClass()); } /** * Tears down the fixture, for example, close a network connection. * This method is called after a test is executed. */ protected void tearDown() throws Exception { try { broker.clearCache(); } catch (PersistenceBrokerException e) { logger.error("Exception during tearDown(): " + e.getMessage()); } } public void testSingleTableInheritance() { try { logger.info("Querying all A objects..."); // These should already be in the database (set up by mapping.sql). Criteria selectAll = null; Query q = new QueryByCriteria(A.class, selectAll); Iterator iterator = broker.getIteratorByQuery(q); while (iterator.hasNext()) { Object o = iterator.next(); A a = (A) o; logger.info("Checking " + a.getConcreteClass() + " vs. " + o.getClass().getName() + "."); Assert.assertEquals(a.getConcreteClass(), o.getClass().getName()); } logger.info("Inheritance query succeeded!"); } catch (Throwable t) { // As of ojb-0.7.325, isInTransaction() is not part of the // PersistenceBroker interface, so we have to check the hard way. try { broker.abortTransaction(); } catch (TransactionNotInProgressException e) { } logger.info("Inheritance query failed!"); t.printStackTrace(); Assert.assertTrue(false); } } } mapping.xml ----------- ... <driver stuff deleted> ... <ClassDescriptor id="9"> <class.name>plprototype2.domain.B</class.name> <table.name>AB_TABLE</table.name> <FieldDescriptor id="1"> <field.name>id</field.name> <column.name>ID</column.name> <jdbc_type>INTEGER</jdbc_type> <PrimaryKey>true</PrimaryKey> <autoincrement>true</autoincrement> </FieldDescriptor> <FieldDescriptor id="2"> <field.name>ojbConcreteClass</field.name> <column.name>CLASS_NAME</column.name> <jdbc_type>VARCHAR</jdbc_type> </FieldDescriptor> <FieldDescriptor id="3"> <field.name>aString</field.name> <column.name>A_STRING</column.name> <jdbc_type>VARCHAR</jdbc_type> </FieldDescriptor> <FieldDescriptor id="4"> <field.name>bString</field.name> <column.name>B_STRING</column.name> <jdbc_type>VARCHAR</jdbc_type> </FieldDescriptor> </ClassDescriptor> <ClassDescriptor id="10"> <class.name>plprototype2.domain.A</class.name> <class.extent>plprototype2.domain.B</class.extent> <table.name>AB_TABLE</table.name> <FieldDescriptor id="1"> <field.name>id</field.name> <column.name>ID</column.name> <jdbc_type>INTEGER</jdbc_type> <PrimaryKey>true</PrimaryKey> <autoincrement>true</autoincrement> </FieldDescriptor> <FieldDescriptor id="2"> <field.name>ojbConcreteClass</field.name> <column.name>CLASS_NAME</column.name> <jdbc_type>VARCHAR</jdbc_type> </FieldDescriptor> <FieldDescriptor id="3"> <field.name>aString</field.name> <column.name>A_STRING</column.name> <jdbc_type>VARCHAR</jdbc_type> </FieldDescriptor> </ClassDescriptor> ... schema.sql ---------- DROP TABLE AB_TABLE; CREATE TABLE AB_TABLE ( ID INT NOT NULL PRIMARY KEY, CLASS_NAME VARCHAR(128), A_STRING VARCHAR(60), B_STRING VARCHAR(60) ); INSERT INTO AB_TABLE VALUES (1,'plprototype2.domain.A','A1',NULL); INSERT INTO AB_TABLE VALUES (2,'plprototype2.domain.A','A2',NULL); INSERT INTO AB_TABLE VALUES (3,'plprototype2.domain.A','A3',NULL); INSERT INTO AB_TABLE VALUES (4,'plprototype2.domain.B','B4','B4'); INSERT INTO AB_TABLE VALUES (5,'plprototype2.domain.B','B5','B5'); output ------ .[BOOT] INFO: OJB.properties: file:/C:/Personal/plprototype2/src/OJB.properties 0 INFO [main] tests.SingleTableInheritanceTest - Querying all A objects... 671 WARN [main] DEFAULT - Please define a public constructor for class plprototype2.domain.A with the following signature: (int, java.lang.String, java.lang.String). It must initialize the classes persistent attributes. This is recommended to increase performance but it's not mandatory! 681 INFO [main] tests.SingleTableInheritanceTest - Checking plprototype2.domain.A vs. plprototype2.domain.A. 681 INFO [main] tests.SingleTableInheritanceTest - Checking plprototype2.domain.A vs. plprototype2.domain.A. 691 INFO [main] tests.SingleTableInheritanceTest - Checking plprototype2.domain.A vs. plprototype2.domain.A. 691 WARN [main] DEFAULT - Please define a public constructor for class plprototype2.domain.B with the following signature: (int, java.lang.String, java.lang.String, java.lang.String). It must initialize the classes persistent attributes. This is recommended to increase performance but it's not mandatory! 691 ERROR [main] accesslayer.RsIterator - 3 701 INFO [main] tests.SingleTableInheritanceTest - Inheritance query failed! java.util.NoSuchElementException at ojb.broker.accesslayer.RsIterator.next(RsIterator.java:151) at plprototype2.tests.SingleTableInheritanceTest.testSingleTableInheritance(SingleTableInheritanceTest.java:81) at java.lang.reflect.Method.invoke(Native Method) at junit.framework.TestCase.runTest(TestCase.java:166) at junit.framework.TestCase.runBare(TestCase.java:140) at junit.framework.TestResult$1.protect(TestResult.java:106) at junit.framework.TestResult.runProtected(TestResult.java:124) at junit.framework.TestResult.run(TestResult.java:109) at junit.framework.TestCase.run(TestCase.java:131) at junit.framework.TestSuite.runTest(TestSuite.java:173) at junit.framework.TestSuite.run(TestSuite.java:168) at junit.textui.TestRunner.doRun(TestRunner.java:74) at junit.textui.TestRunner.start(TestRunner.java:234) at junit.textui.TestRunner.main(TestRunner.java:112) at plprototype2.tests.SingleTableInheritanceTest.main(SingleTableInheritanceTest.java:39) F Time: 1.953 There was 1 failure: 1) testSingleTableInheritance(plprototype2.tests.SingleTableInheritanceTest)junit.framework.AssertionFailedError at plprototype2.tests.SingleTableInheritanceTest.testSingleTableInheritance(SingleTableInheritanceTest.java:99) at plprototype2.tests.SingleTableInheritanceTest.main(SingleTableInheritanceTest.java:39) FAILURES!!! Tests run: 1, Failures: 1, Errors: 0 |
From: Florian B. <bf...@fl...> - 2002-02-07 18:33:31
|
Hi Thomas, >I think the best idea will be to have an Interface "RdbmsSpecifics" that > provides callback methods like initializeJdbcConnection(Connection conn). > Concrete Implementations like "InformixSpecifics" would provide their > specific implementations of these methods. > I believe that we will find several small spots where such things are > needed for certain databases. Sure, another spot where I think it could become database specific is when it comes to searching in CLOB fields. Oracle has the "context option", Informix the "Excalibur Datablade" for indexing content in CLOBs and searching for it in WHERE clauses. > If you send me you patches I will integrate as described above! > Apart from the BLOB/CLOB problem, what things were necessary to run OJB > against Informix. > Did you follow the steps in the rdbms-support.html document? Or did you > experiment on your own. Cool! There were no other modifications for Informix except modifications to the schema (e.g. Informix doesn't support varchar with more than 255 characters, so I had to change the column type to LVARCHAR). I didn't follow the guidelines because I found it a little bit too confusing, so I just copied the schema into a plain sql-File and did the modifications that were necessary. Attached is the Informix-specific sql-File I used for creating the database definitions. It is not in the format of the original file (i.e. without the commands preceding each statement), but nonetheless should give Informix users some hint what to change. MfG, Florian Bruckner |
From: Thomas M. <tho...@ho...> - 2002-02-07 18:15:00
|
Hi Florian, I think the best idea will be to have an Interface "RdbmsSpecifics" that provides callback methods like initializeJdbcConnection(Connection conn). Concrete Implementations like "InformixSpecifics" would provide their specific implementations of these methods. I believe that we will find several small spots where such things are needed for certain databases. If you send me you patches I will integrate as described above! Apart from the BLOB/CLOB problem, what things were necessary to run OJB against Informix. Did you follow the steps in the rdbms-support.html document? Or did you experiment on your own. Your experiences might be helpful for others ! Thanks, Thomas Florian Bruckner wrote: > Hi, > > I'm using OJB with Informix as RDBMS. So far most things work fine, there is > just a minor issue. When I run an application with multiple threads that do > inserts into a table, some inserts fail because the table is locked. This is > due to a Informix-specific setting in the connection that if a required lock > is not available, the statement fails without waiting for the lock. > > This behaviour can be changed per connection by issuing a command to the > RDBMS ("SET LOCK MODE TO WAIT"). To achieve this I modified > ConnectionFactoryDefaultImpl to issue this command when a connection is > obtained. Is it possible to do this in a somewhat cleaner way that will work > with future releases without having to modify the sourcecode again and > again? > > best regards, > Florian > > > _______________________________________________ > Objectbridge-developers mailing list > Obj...@li... > https://lists.sourceforge.net/lists/listinfo/objectbridge-developers > > > > |
From: Thomas M. <tho...@ho...> - 2002-02-07 18:15:00
|
Hi Florian, Thanks for your patch ! I will have a look at it and try to integrate it. thanks, Thomas Florian Bruckner wrote: > Hi, > > the following changes were necessary to support BLOB/CLOB type columns. I > tested it with Informix IIF 2000 with version 2.21JC2 of the JDBC driver. > Concerning a JUnit test for it - I'm looking into it, but HSQLDB doesn't > seem to support BLOB/CLOB, so I am quite unsure how I could provide a test. > > best regards, > Florian > > > Changes against 0.7.327 > > JdbcAccess.java, starting at line 571: > break; > } > case Types.CLOB: > { > java.sql.Clob aClob = rs.getClob(columnId); > result = aClob.getSubString(0L, (int)aClob.length()); > break; > } > case Types.BLOB: > { > java.sql.Blob aBlob = rs.getBlob(columnId); > result = aBlob.getBytes(0L, (int)aBlob.length()); > break; > } > default: > { > > JdbcAccess.java around line 637: > else if (type.equals("longvarbinary")) > result = Types.LONGVARBINARY; > else if (type.equals("clob")) > result = Types.CLOB; > else if (type.equals("blob")) > result = Types.BLOB; > else > > StatementManager.java line 266: > if (val != null) > stmt.setObject(i + 1, val, JdbcAccess.getSqlTypeAll(cld, i)); > else > stmt.setNull(i + 1, JdbcAccess.getSqlTypeAll(cld, i)); > > > > _______________________________________________ > Objectbridge-developers mailing list > Obj...@li... > https://lists.sourceforge.net/lists/listinfo/objectbridge-developers > > > > |
From: Florian B. <bf...@fl...> - 2002-02-07 11:35:28
|
Hi, the following changes were necessary to support BLOB/CLOB type columns. I tested it with Informix IIF 2000 with version 2.21JC2 of the JDBC driver. Concerning a JUnit test for it - I'm looking into it, but HSQLDB doesn't seem to support BLOB/CLOB, so I am quite unsure how I could provide a test. best regards, Florian Changes against 0.7.327 JdbcAccess.java, starting at line 571: break; } case Types.CLOB: { java.sql.Clob aClob = rs.getClob(columnId); result = aClob.getSubString(0L, (int)aClob.length()); break; } case Types.BLOB: { java.sql.Blob aBlob = rs.getBlob(columnId); result = aBlob.getBytes(0L, (int)aBlob.length()); break; } default: { JdbcAccess.java around line 637: else if (type.equals("longvarbinary")) result = Types.LONGVARBINARY; else if (type.equals("clob")) result = Types.CLOB; else if (type.equals("blob")) result = Types.BLOB; else StatementManager.java line 266: if (val != null) stmt.setObject(i + 1, val, JdbcAccess.getSqlTypeAll(cld, i)); else stmt.setNull(i + 1, JdbcAccess.getSqlTypeAll(cld, i)); |
From: Florian B. <bf...@fl...> - 2002-02-07 11:14:57
|
Hi, I'm using OJB with Informix as RDBMS. So far most things work fine, there is just a minor issue. When I run an application with multiple threads that do inserts into a table, some inserts fail because the table is locked. This is due to a Informix-specific setting in the connection that if a required lock is not available, the statement fails without waiting for the lock. This behaviour can be changed per connection by issuing a command to the RDBMS ("SET LOCK MODE TO WAIT"). To achieve this I modified ConnectionFactoryDefaultImpl to issue this command when a connection is obtained. Is it possible to do this in a somewhat cleaner way that will work with future releases without having to modify the sourcecode again and again? best regards, Florian |
From: Mahler T. <tho...@it...> - 2002-02-07 07:53:04
|
Hi Florian, thanks for your interest! <snip> > > One very important requirement is support for BLOB and CLOB types. > Fortunately not very much modification was necessary to > achieve this. Now, I > would like to contribute this small modification. Before I > send the patch to > this list I wanted to ask whether such patches are welcome > and in which > format you prefer patches. > Of course all contributions are welcome! You cand send patches either to the list or directly to me. .zip or .tgz as compression format is fine. Please include some information on what you did and why and against which ojb release you coded your changes. This will help in integrating your code into the distribution! Providing JUnit TestCases demonstrating and testing the is greatly appreciated! thanks, Thomas > best regards, > Florian > > > > best regards, > Florian > > > _______________________________________________ > Objectbridge-developers mailing list > Obj...@li... > https://lists.sourceforge.net/lists/listinfo/objectbridge-developers > |
From: Jakob B. <jbr...@ho...> - 2002-02-07 07:28:41
|
hi, the following patch to the method bindInsert() of class StatementManager provides default values for the locking fields. /** * binds the values of the object obj to the statements parameters */ public void bindInsert(PreparedStatement stmt, ClassDescriptor cld, Object obj) throws java.sql.SQLException { Object[] values; cld.updateLockingValues(obj); // BRJ : provide useful defaults for locking fields values = cld.getAllValues(obj); for (int i = 0; i < values.length; i++) { Object val = values[i]; if (val != null) stmt.setObject(i + 1, val); else stmt.setNull(i + 1, JdbcAccess.getSqlTypeAll(cld, i)); } } jakob |
From: Florian B. <bf...@fl...> - 2002-02-06 22:41:39
|
Hi, I started evaluating Objectbridge a few days ago and I must say I am impressed of the design. I hope this fine piece of software will meet the requirements for a web project that is going to start within the next few weeks. One very important requirement is support for BLOB and CLOB types. Fortunately not very much modification was necessary to achieve this. Now, I would like to contribute this small modification. Before I send the patch to this list I wanted to ask whether such patches are welcome and in which format you prefer patches. best regards, Florian best regards, Florian |
From: Mahler T. <tho...@it...> - 2002-02-06 08:41:07
|
Hi Ricardo, >=20 > Thomas, >=20 > Thanks, it worked!!! Great news ! =20 > In single VM mode I get this message: >=20 > [BOOT] INFO: OJB.properties:=20 > file:/C:/Java/Tomcat401/webapps/charlie-dev/WEB-INF > /classes/OJB.properties > [ojb.broker.metadata.RepositoryXmlHandler] WARN: unknown=20 > isolation-level: read-u > ncomitted using RW_UNCOMMITTED as default > [ojb.broker.metadata.RepositoryXmlHandler] WARN: unknown=20 > isolation-level: read-u > ncomitted using RW_UNCOMMITTED as default > [ojb.broker.metadata.RepositoryXmlHandler] WARN: unknown=20 > isolation-level: read-u > ncomitted using RW_UNCOMMITTED as default > [ojb.broker.metadata.RepositoryXmlHandler] WARN: unknown=20 > isolation-level: read-u > ncomitted using RW_UNCOMMITTED as default > [ojb.broker.metadata.RepositoryXmlHandler] WARN: unknown=20 > isolation-level: read-u > ncomitted using RW_UNCOMMITTED as default >=20 Maybe there is some typo in the repository file. Just send it to me = I'll try to find the problem. >=20 > But It works. I can make two threads read data from the same=20 > table concurrently. >=20 >=20 > When I tried to run OJB in C/S mode, I got this exception: >=20 <snip> Yes, I have not worked on the C/S related problems yet >=20 >=20 > I suppose I would not need to use the Client/Server mode=20 > anymore, since now OJB is working in single JVM mode,=20 > concurrently... I do not need the load balancing stuff yet...=20 > What do you think? Yes! In a servlet environment it should be absolutely OK to use = singlevm mode. >=20 > I'll try to get some sleep (it's 3am here, I downloaded your=20 > patch almost inmediatly), and tomorrow I'll finish testing=20 > with more cases of concurrency of web clients. >=20 >=20 > THANKS for your great work! >=20 Thanks for your patience! -- Thomas > Greetings, >=20 >=20 > Ricardo Arguello >=20 > ----- Original Message -----=20 > From: "Thomas Mahler" <tho...@ho...> > To: "Ricardo Arg=FCello" <ri...@ya...> > Cc: <obj...@li...> > Sent: Wednesday, February 06, 2002 1:20 AM > Subject: Re: [OJB-developers] Concurrent access not posible=20 > with 0.7.325 in C/S mode >=20 >=20 > > Hi Ricardo, > >=20 > > I just placed a new release (0.7.327) on the OJB download page. > > I modified the PersistenceBrokerFactory and the ODMG = implementation. > > Now in singlevm mode each transaction will obtain its own=20 > broker instance. > > During comit() or abort() the broker instances are released=20 > to a pool. > >=20 > > I hope this will solve at least some of your problems. > >=20 > > This is no release build. thus there are no TestCases yet=20 > that check the=20 > > implemented features. There may be bugs! > >=20 > > HTH, > >=20 > > Thomas > >=20 > >=20 > > _______________________________________________ > > Objectbridge-developers mailing list > > Obj...@li... > > = https://lists.sourceforge.net/lists/listinfo/objectbridge-developers > >=20 >=20 >=20 > _______________________________________________ > Objectbridge-developers mailing list > Obj...@li... > https://lists.sourceforge.net/lists/listinfo/objectbridge-developers >=20 |