[prev in list] [next in list] [prev in thread] [next in thread] 

List:       turbine-torque-user
Subject:    Re: Criteria/Torque Patch for Torque 3.0.0
From:       Daniel Rall <dlr () finemaltcoding ! com>
Date:       2003-02-27 17:37:44
[Download RAW message or body]

Jürgen Hoffmann <jh@byteaction.de> writes:

> We experienced a mysterious behaviour with Torque 3.0.0 which was a
> NullPointer Exception When not setting the DbName explicitly. It seemed
> that the Torque.getDefaultDb() Was returning the Database Name with a
> couple of Empty Chars ' ' at the end. This patch adds a trim to the
> related Method calls, which prevents such behaviour. 

> Index: src/java/org/apache/torque/Torque.java
> ===================================================================
> RCS file: /home/cvspublic/jakarta-turbine-torque/src/java/org/apache/torque/Torque.java,v
> retrieving revision 1.73
> diff -u -r1.73 Torque.java
> --- src/java/org/apache/torque/Torque.java	28 Nov 2002 18:52:02 -0000	1.73
> +++ src/java/org/apache/torque/Torque.java	18 Feb 2003 10:43:38 -0000
> @@ -971,13 +971,13 @@
>      {
>          if (configuration == null)
>          {
> -            return DEFAULT_NAME;
> +            return DEFAULT_NAME.trim();

This is a constant.  WTF would you need to trim it?

>          }
>          else if (defaultDBName == null)
>          {
>              // Determine default database name.
>              defaultDBName =
> -                configuration.getString(DATABASE_DEFAULT, DEFAULT_NAME);
> +                configuration.getString(DATABASE_DEFAULT, DEFAULT_NAME).trim();

Okay.

>          }
>  
>          return defaultDBName;
> Index: src/java/org/apache/torque/util/Criteria.java
> ===================================================================
> RCS file: /home/cvspublic/jakarta-turbine-torque/src/java/org/apache/torque/util/Criteria.java,v
> retrieving revision 1.35
> diff -u -r1.35 Criteria.java
> --- src/java/org/apache/torque/util/Criteria.java	28 Nov 2002 16:32:36 -0000	1.35
> +++ src/java/org/apache/torque/util/Criteria.java	18 Feb 2003 10:43:44 -0000
> @@ -605,7 +605,7 @@
>       */
>      public String getDbName()
>      {
> -        return dbName;
> +        return dbName.trim();
>      }

No, this should happen when you set dbName -- doing it every single
time is inefficient.

>      /**
> @@ -616,7 +616,7 @@
>       */
>      public void setDbName(String dbName)
>      {
> -        this.dbName = (dbName == null ? Torque.getDefaultDB() : dbName);
> +        this.dbName = (dbName == null ? Torque.getDefaultDB().trim() : dbName.trim());
>      }

Your change to Torque.java is already handling getDefaultDB() -- why
do it again?  Trimming dbName makes sense, though.

Committed.
-- 

Daniel Rall <dlr@finemaltcoding.com>

---------------------------------------------------------------------
To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic