You are viewing a plain text version of this content. The canonical link for it is here.
Posted to torque-dev@db.apache.org by "Löthe, Mathis" <Ma...@T-Systems.com> on 2002/11/29 13:11:44 UTC
Bugfix Serialization Diffs
Dear Torque-Developers
Here are the diffs between the rc1 and the fix
Mathis
SqlEnum.diff
---- begin -------------------------------------------------------------
--- rc1/SqlEnum.java 2002-11-05 15:55:12.000000000 +0100
+++ fix/SqlEnum.java 2002-11-05 15:56:08.000000000 +0100
@@ -78,6 +78,20 @@
return s;
}
+ /** use equals on internal string to allow for serialization <br>
+ * it is probably not a performance problem. <br>
+ * if you believe, there is one, you can return to the String ==
semantics
+ * but you have to implement a readObject-Deserialization method, which
+ * interns the string, i.e. it compares with all known SqlEnum-Strings
and
+ * inserts exactly this object. */
+
+ public boolean equals(Object obj) {
+ if (!(obj instanceof SqlEnum))
+ return false;
+ SqlEnum enum = (SqlEnum) obj;
+ return s.equals(enum.s);
+}
+
public static final SqlEnum EQUAL =
---- end -----------------------------------------------------------------
BasePeer.diff
---- begin ----------------------------------------------------------------
--- rc1/BasePeer.java 2002-10-26 15:10:16.000000000 +0200
+++ fix/BasePeer.java 2002-11-12 13:21:15.000000000 +0100
@@ -66,6 +66,7 @@
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Collections;
+import java.util.Map;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;
@@ -137,10 +138,10 @@
* @return A byte[] with the converted Hashtable.
* @exception TorqueException
*/
- public static byte[] hashtableToByteArray(Hashtable hash)
+ public static byte[] hashtableToByteArray(Map hash)
throws TorqueException
{
- Hashtable saveData = new Hashtable(hash.size());
+ Map saveData = new Hashtable(hash.size());
String key = null;
Object value = null;
byte[] byteArray = null;
@@ -865,11 +866,11 @@
colMap.getColumnName(),
((Short) obj).shortValue());
}
- else if (obj instanceof Hashtable)
+ else if (obj instanceof Map)
{
rec.setValue(
colMap.getColumnName(),
- hashtableToByteArray((Hashtable) obj));
+ hashtableToByteArray((Map) obj));
}
else if (obj instanceof byte[])
{
@@ -910,6 +911,7 @@
public static String createQueryString(Criteria criteria)
throws TorqueException
{
+
Query query = new Query();
DB db = Torque.getDB(criteria.getDbName());
DatabaseMap dbMap = Torque.getDatabaseMap(criteria.getDbName());
@@ -1117,7 +1119,7 @@
//String groupByString = null;
query.setHaving(having.toString());
}
-
+
if (orderBy != null && orderBy.size() > 0)
{
// Check for each String/Character column and apply
@@ -1155,6 +1157,7 @@
orderByColumn.indexOf('.') + 1,
spacePos);
}
+
ColumnMap column =
dbMap.getTable(table).getColumn(columnName);
if (column.getType() instanceof String)
{
@@ -1179,7 +1182,7 @@
}
}
}
-
+
// Limit the number of rows returned.
int limit = criteria.getLimit();
int offset = criteria.getOffset();
---- end ------------------------------------------------------------------
Criteria.diff
---- begin ---------------------------------------------------------------
--- rc1/Criteria.java 2002-10-26 15:10:16.000000000 +0200
+++ fix/Criteria.java 2002-11-12 13:21:40.000000000 +0100
@@ -1,7 +1,7 @@
package org.apache.torque.util;
-
+
/* ====================================================================
- * The Apache Software License, Version 1.1
+ * The Apache Software License, Version 1.1
*
* Copyright (c) 2001-2002 The Apache Software Foundation. All rights
* reserved.
@@ -54,25 +54,29 @@
* <http://www.apache.org/>.
*/
+import java.io.Serializable;
import java.lang.reflect.Array;
import java.math.BigDecimal;
-import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Collection;
+import java.util.Enumeration;
import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import java.util.Set;
+
+import org.apache.commons.collections.StringStack;
+import org.apache.log4j.Category;
import org.apache.torque.Torque;
import org.apache.torque.TorqueException;
import org.apache.torque.adapter.DB;
import org.apache.torque.map.DatabaseMap;
import org.apache.torque.om.DateKey;
import org.apache.torque.om.ObjectKey;
-import org.apache.commons.collections.StringStack;
-import org.apache.log4j.Category;
/**
* This is a utility class that is used for retrieving different types
@@ -90,7 +94,7 @@
* @author <a href="mailto:sam@neurogrid.com">Sam Joseph</a>
* @version $Id: Criteria.java,v 1.32 2002/10/14 01:44:08 stephenh Exp $
*/
-public class Criteria extends Hashtable
+public class Criteria implements Map, Serializable
{
/** Comparison type. */
@@ -169,6 +173,8 @@
private Hashtable asColumns = new Hashtable(8);
private ArrayList joinL = null;
private ArrayList joinR = null;
+ private Hashtable content;
+
/** The name of the database. */
private String dbName;
@@ -234,9 +240,9 @@
*/
public Criteria(String dbName, int initialCapacity)
{
- super(initialCapacity);
- this.dbName = dbName;
- this.originalDbName = dbName;
+ content = new Hashtable(initialCapacity);
+ this.dbName = dbName;
+ this.originalDbName = dbName;
}
/**
@@ -246,7 +252,7 @@
*/
public void clear()
{
- super.clear();
+ content.clear();
ignoreCase = false;
singleRecord = false;
cascade = false;
@@ -406,7 +412,7 @@
DatabaseMap map = Torque.getDatabaseMap(databaseMapName);
StringStack tables = new StringStack();
- for (Iterator it = super.values().iterator(); it.hasNext(); )
+ for (Iterator it = content.values().iterator(); it.hasNext(); )
{
Criterion co = (Criterion) it.next();
String tableName = co.getTable();
@@ -458,7 +464,7 @@
*/
public Criterion getCriterion(String column)
{
- return (Criterion) super.get(column);
+ return (Criterion) content.get(column);
}
/**
@@ -530,7 +536,7 @@
sb.append(c.getTable());
sb.append('.');
sb.append(c.getColumn());
- super.put(sb.toString(), c);
+ content.put(sb.toString(), c);
return this;
}
@@ -605,6 +611,7 @@
*/
public String getDbName()
{
+
return dbName;
}
@@ -972,7 +979,7 @@
Object val = e.getValue();
if (val instanceof Criteria.Criterion)
{
- super.put(e.getKey(), val);
+ content.put(e.getKey(), val);
}
else
{
@@ -1058,7 +1065,7 @@
*/
public Criteria add(String column, Object value, SqlEnum comparison)
{
- super.put(column, new Criterion(column, value, comparison));
+ content.put(column, new Criterion(column, value, comparison));
return this;
}
@@ -1119,7 +1126,7 @@
sb.append(table);
sb.append('.');
sb.append(column);
- super.put(sb.toString(),new Criterion(table, column, value,
comparison));
+ content.put(sb.toString(),new Criterion(table, column, value,
comparison));
return this;
}
@@ -1837,10 +1844,13 @@
*
* @param key A String with the key to be removed.
* @return The removed object.
+ * @throws ClassCastException if key is not a String
*/
- public Object remove(String key)
+ // mloethe: key of type Object, to get a clear Map interface
+
+ public Object remove(Object key)
{
- Object foo = super.remove(key);
+ Object foo = content.remove((String) key);
if (foo instanceof Criterion)
{
return ((Criterion) foo).getValue();
@@ -1861,7 +1871,7 @@
{
String key = (String) it.next();
sb.append(key).append("<=>")
- .append(super.get(key).toString()).append(": ");
+ .append(content.get(key).toString()).append(": ");
}
try
@@ -2050,7 +2060,7 @@
if (oc == null)
{
- super.put(column, nc);
+ content.put(column, nc);
}
else
{
@@ -2120,7 +2130,7 @@
if (oc == null)
{
- super.put(sb.toString(),nc);
+ content.put(sb.toString(),nc);
}
else
{
@@ -2626,7 +2636,7 @@
if (oc == null)
{
- super.put(column, nc);
+ content.put(column, nc);
}
else
{
@@ -2695,7 +2705,7 @@
Criterion nc = new Criterion(table, column, value, comparison);
if (oc == null)
{
- super.put(sb.toString(), nc);
+ content.put(sb.toString(), nc);
}
else
{
@@ -3296,14 +3306,14 @@
*/
public DB getDb()
{
- DB db = null;
+ DB db = null;
if (this.db == null)
{
// db may not be set if generating preliminary sql for
// debugging.
try
- {
- db = Torque.getDB(getDbName());
+ {
+ db = Torque.getDB(getDbName());
}
catch (Exception e)
{
@@ -3720,4 +3730,47 @@
}
}
}
+
+ // delegate map methods
+
+ /** see Map */
+ public boolean containsKey(Object obj){
+ return content.containsKey(obj);
+ }
+
+ /** see Map */
+ public boolean containsValue(Object obj){
+ return content.containsValue(obj);
+ }
+
+ /** */
+ public Set entrySet(){
+ return content.entrySet();
+ }
+
+ /** */
+ public boolean isEmpty(){
+ return content.isEmpty();
+ }
+
+ public Set keySet(){
+ return content.keySet();
+ }
+
+ public int size(){
+ return content.size();
+ }
+
+ public Collection values(){
+ return content.values();
+ }
+
+
+ /** see Hashtable */
+ // mloethe this is not in Map but in Hashtable and it is used
+ // please change use in BasePeer to something existing in Map
+ public Enumeration keys(){
+ return content.keys();
+ }
+
}
---- end -----------------------------------------------------------------
Re: Bugfix Serialization Diffs
Posted by Martin Poeschl <mp...@marmot.at>.
Löthe, Mathis wrote:
>Dear Torque-Developers
>
>Here are the diffs between the rc1 and the fix
>
>Mathis
>
>
could you please describe the problem you want to fix with the patch???
martin
>
>