Hello,
I notice that you decided to map the sql type "TIMESTAMP" into the java
type "java.util.Date".
In fact,in org.apache.turbine.torque.model.TypeMap:
* -------------------------------------------------------
* SQL Type | Java Type | Peer Type
* -------------------------------------------------------
* CHAR | String | String
* VARCHAR | String | String
* LONGVARCHAR | String | String
* NUMERIC | java.math.BigDecimal | java.math.BigDecimal
* DECIMAL | java.math.BigDecimal | java.math.BigDecimal
* BIT | boolean | Boolean
* TINYINT | byte | Byte
* SMALLINT | short | Short
* INTEGER | int | Integer
* BIGINT | long | Long
* REAL | float | Float
* FLOAT | double | Double
* DOUBLE | double | Double
* BINARY | byte[] | ?
* VARBINARY | byte[] | ?
* LONGVARBINARY | byte[] | ?
* DATE | java.sql.Date | java.util.Date
* TIME | java.sql.Time | java.util.Date
* TIMESTAMP | java.sql.Timestamp | java.util.Date
*
* -------------------------------------------------------
public static final String TIMESTAMP_OBJECT_TYPE = "new Date()";
public static final String TIMESTAMP_NATIVE_TYPE = "Date";
public static final String TIMESTAMP_VILLAGE_METHOD = "asDate()";
It seems to me that, throw this mapping, the information relating to
milliseconds is losen.
Is there any reason why you have decided to map TIMESTAMP into
java.util.Date and not into
java.sql.Timestamp?
In my project I need to use timestamps containing also the information
about milliseconds.
I decide to use java.sql.Timestamp instead of java.util.Date.
The changes that I did in the code are the following:
1) org.apache.turbine.torque.model.TypeMap:
public static final String TIMESTAMP_OBJECT_TYPE = "new
Timestamp(System.currentTimeMillis())";
public static final String TIMESTAMP_NATIVE_TYPE = "Timestamp";
public static final String TIMESTAMP_VILLAGE_METHOD = "asTimestamp()";
2) org.apache.turbine.om.peer.BasePeer:
private static void insertOrUpdateRecord(Record rec,
String tableName,
Criteria criteria)
throws Exception
{
DatabaseMap dbMap = TurbineDB.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 == 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(),
criteria.getBigDecimal(key) );
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 java.sql.Timestamp)
rec.setValue( colMap.getColumnName(),
(java.sql.Timestamp)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"
);
}
3) in torque-templates; I added
import java.sql.Timestamp;
My project now seems to work properly, but I wonder if there is something
else that I need to change.
I wonder moreover if there is a particular reason for which you use
java.util.Date.
Thank you very much,
Michela
------------------------------------------------------------
To subscribe: [EMAIL PROTECTED]
To unsubscribe: [EMAIL PROTECTED]
Search: <http://www.mail-archive.com/turbine%40list.working-dogs.com/>
Problems?: [EMAIL PROTECTED]