Title: RE: TurbineUserPeer and Postgres column name case inconsistencies.

I've seen this problem in Informix and in thread
"Turbine security (TurbineUserPeer) - Cannot login causeof"empty" user objects"
someone (with postgres) has posted a solution beyond changing the case of column names all over the sourcecode.
He proposed the following change, which is obviously not in CVS until today and I don't know if the line number has changed in the actual code:

> An another solution is to change line number 330 in
> org.apache.turbine.om.security.peer.TurbineUserPeer to:
>
>   tempHash.put( columnNames[j].toUpperCase(), obj2 );
                                ^^^^^^^^^^^^^

Hope that helps
Stefan

> -----Original Message-----
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED]]On Behalf Of mango parts
> Sent: Tuesday, January 30, 2001 6:56 PM
> To: [EMAIL PROTECTED]
> Subject: TurbineUserPeer and Postgres column name case
> inconsistencies.
>
>
> I am running the lastest cvs version of turbine with postgres. I have
> encountered problems retrieving the field values from the TurbineUser
> class, calling getUserName(), getLastName(), or getFirstName() would
> always return null even though there was valid data. Doing further
> research, I've found that the problem was in the keys of the hashtable
> that was storing the data values. Postgres was using lower case column
> names and the TurbineUserPeer column names where in upper case. To fix
> the problem, I changed the keys to upper case when they are added and
> removed to the hash table.
>
> Anyway comments?
>
> ......
>     /**
>      * Builds a criteria object based upon an User object
>      */
>     public static Criteria buildCriteria(User user)
>     {
>         Hashtable permData = (Hashtable)
> user.getPermStorage().clone();
>         Criteria criteria = new Criteria();
>         criteria.add( TurbineUserPeer.USER_ID,
> ((BaseObject)user).getPrimaryKey() );
>
>         for (int i=1; i<TurbineUserPeer.columnNames.length; i++ )
>         {
> >>>>>>>>            if (
> permData.containsKey(TurbineUserPeer.columnNames[i].toUpperCase()) )
>             {
>                 criteria.add( TurbineUserPeer.criteriaKeys[i],
> >>>>>>>>                             
> permData.remove(TurbineUserPeer.columnNames[i].toUpperCase()) );
>             }
>         }
>         criteria.add( TurbineUserPeer.OBJECT_DATA, permData );
>         return criteria;
>     }
>
>
>     /**
>      * Issues a select based on a criteria.
>      *
>      * @param criteria Object containing data that is used to create
>      * the SELECT statement.
>      * @param current User object that is to be used as part of the
>      * results - if not passed, then a new one is created.
>      * @return Vector containing TurbineUser objects.
>      * @exception Exception, a generic exception.
>      */
>     public static Vector doSelect(Criteria criteria,
>                                   User current)
>         throws Exception
>     {
>         // Set values are where columns are expected.  They are not
>         // required to be in these positions, as we set the positions
>         // while populating the select columns.
>         int idPosition = 1;
>         int objectDataPosition = columnNames.length;
>
>         for( int i=0; i<columnNames.length; i++ )
>         {
>             criteria.addSelectColumn(new StringBuffer()
>                 .append(TABLE_NAME)
>                 .append(".")
>                 .append(columnNames[i]).toString() );
>             if (columnNames[i].equals(USER_ID_COLUMN))
>                 idPosition = i+1;
>             if (columnNames[i].equals(OBJECT_DATA_COLUMN))
>                 objectDataPosition = i+1;
>         }
>
>         if (criteria.getOrderByColumns() == null)
>         {
>             criteria.addOrderByColumn(LAST_NAME);
>         }
>
>         // Place any checks here to intercept criteria which require
>         // custom SQL.  For example:
>         // if ( criteria.containsKey("SomeTable.SomeColumn") )
>         // {
>         //     String whereSql = "SomeTable.SomeColumn IN
> (Select ...";
>         //     criteria.add("SomeTable.SomeColumn",
>         //                  whereSQL, criteria.CUSTOM);
>         // }
>
>         // BasePeer returns a Vector of Record (Village) objects.  The
>         // array order follows the order columns were placed in the
>         // Select clause.
>         Vector rows = BasePeer.doSelect(criteria);
>         Vector results = new Vector();
>
>         // Populate the object(s).
>         for ( int i=0; i<rows.size(); i++ )
>         {
>             User obj = TurbineSecurity.getUserInstance();
>             Record row = (Record)rows.elementAt(i);
>
>             ((BaseObject)obj).setPrimaryKey(
> row.getValue(idPosition).asBigDecimal() );
>
>             // Restore the Permanent Storage Hashtable.  First the
>             // Hashtable is restored, then any explicit table columns
>             // which should be included in the Hashtable are added.
>             byte[] objectData =
> (byte[])row.getValue(objectDataPosition).asBytes();
>             Hashtable tempHash =
> (Hashtable)ObjectUtils.deserialize(objectData);
>             if (tempHash == null)
>             {
>                 tempHash = new Hashtable(10);
>             }
>
>             for( int j=0; j<columnNames.length; j++ )
>             {
>                 if ( ! ( columnNames[j].equalsIgnoreCase(
> USER_ID_COLUMN
> )
>                          ||  columnNames[j].equalsIgnoreCase(
> OBJECT_DATA_COLUMN ) ))
>                 {
>                     Object obj2 = null;
>                     Value value = row.getValue(j+1);
>                     if (value.isByte()) obj2 = new
> Byte(value.asByte());
>                     if (value.isBigDecimal()) obj2 =
> value.asBigDecimal();
>                     if (value.isBytes()) obj2 = value.asBytes();
>                     if (value.isDate()) obj2 = value.asDate();
>                     if (value.isShort()) obj2 = new
> Short(value.asShort());
>                     if (value.isInt()) obj2 = new
> Integer(value.asInt());
>                     if (value.isLong()) obj2 = new
> Long(value.asLong());
>                     if (value.isDouble()) obj2 = new
> Double(value.asDouble());
>                     if (value.isFloat()) obj2 = new
> Float(value.asFloat());
>                     if (value.isBoolean()) obj2 = new
> Boolean(value.asBoolean());
>                     if (value.isString()) obj2 = value.asString();
>                     if (value.isTime()) obj2 = value.asTime();
>                     if (value.isTimestamp()) obj2 =
> value.asTimestamp();
>                     if (value.isUtilDate()) obj2 = value.asUtilDate();
>                     if ( obj2 != null )
> >>>>>>>>                        tempHash.put(
> columnNames[j].toUpperCase(), obj2 );
>                 }
>             }
>             obj.setPermStorage( tempHash );
>             // Add User to the return Vector.
>             results.addElement( obj );
>         }
>         return results;
>     }
>
>
> ------------------------------------
> eumir
> [EMAIL PROTECTED]
>
> _________________________________________________________
> Do You Yahoo!?
> Get your free @yahoo.com address at http://mail.yahoo.com
>
>
>
> ------------------------------------------------------------
> To subscribe:        [EMAIL PROTECTED]
> To unsubscribe:      [EMAIL PROTECTED]
> Search: <http://www.mail-archive.com/turbine%40list.working-dogs.com/>
> Problems?:           [EMAIL PROTECTED]
>

Reply via email to