You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@turbine.apache.org by Patrick Tonidandel <pa...@wuerth.it> on 2001/11/29 18:49:21 UTC

Update columns of type Byte

Dear gentlemen,

i would like to insert a byte value into a column of my table.

After calling the doUpdate-method of MYOBJECTPeer.java i noticed that
nothing happens
to my column of type Byte.

I suppose that the reason is, in following source code.

The method insertOrUpdateRecord of BasePeer.java misses if-clause for
Byte-types.

Regards
Patrick Tonidandel





-------------------------------------------------------------------------->
CODE
    private static void insertOrUpdateRecord(Record rec,
                                             String tableName,
                                             Criteria criteria)
        throws Exception
    {
        DatabaseMap dbMap = Torque.getDatabaseMap( criteria.getDbName() );

        ColumnMap[] columnMaps = dbMap.getTable( tableName ).getColumns();
        boolean shouldSave = false;
        for (int j=0; j<columnMaps.length; j++)
        {
            ColumnMap colMap = columnMaps[j];
            String key = new StringBuffer(colMap.getTableName())
                .append('.').append(colMap.getColumnName()).toString();
            if ( criteria.containsKey(key) )
            {
                // A village Record.setValue( String, Object ) would
                // be nice here.
                Object obj = criteria.getValue(key);
                if ( obj instanceof SimpleKey )
                {
                    obj = ((SimpleKey)obj).getValue();
                }
                if (obj == null)
                {
                    rec.setValueNull(colMap.getColumnName());
                }
                else if ( obj instanceof String )
                {
                    rec.setValue( colMap.getColumnName(),
                                  (String)obj );
                }
                else if ( obj instanceof Integer)
                {
                    rec.setValue( colMap.getColumnName(),
                                  criteria.getInt(key) );
                }
                else if ( obj instanceof BigDecimal)
                {
                    rec.setValue( colMap.getColumnName(),
                                  (BigDecimal)obj );
                }
                else if ( obj instanceof Long)
                {
                    rec.setValue( colMap.getColumnName(),
                                  criteria.getLong(key) );
                }
                else if ( obj instanceof java.util.Date)
                {
                    rec.setValue( colMap.getColumnName(),
                                  (java.util.Date)obj );
                }
                else if ( obj instanceof Float)
                {
                    rec.setValue( colMap.getColumnName(),
                                  criteria.getFloat(key) );
                }
                else if ( obj instanceof Double)
                {
                    rec.setValue( colMap.getColumnName(),
                                  criteria.getDouble(key) );
                }
                else if ( obj instanceof Hashtable )
                {
                    rec.setValue( colMap.getColumnName(),
                                  hashtableToByteArray( (Hashtable)obj ) );
                }
                else if ( obj instanceof byte[])
                {
                    rec.setValue( colMap.getColumnName(),
                                  (byte[])obj);
                }
                else if ( obj instanceof Boolean)
                {
                    rec.setValue( colMap.getColumnName(),
                                   criteria.getBoolean(key) ? 1 : 0);
                }
                shouldSave = true;
             }
        }

        if ( shouldSave )
        {
            rec.save();
        }
        else
        {
           throw new Exception ( "BasePeer.doInsert() - Nothing to
insert" );
        }
    }
--------------------------------------------------------------------------<
CODE


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>