Update of /var/cvs/src/org/mmbase/storage/search/implementation/database
In directory james.mmbase.org:/tmp/cvs-serv30652
Modified Files:
BasicSqlHandler.java
Log Message:
made it possible to override field-appending and use the type of the field.
SimpleDateFormat is not synchornized and its apidoc recommends to use one
instance per Thread
See also:
http://cvs.mmbase.org/viewcvs/src/org/mmbase/storage/search/implementation/database
Index: BasicSqlHandler.java
===================================================================
RCS file:
/var/cvs/src/org/mmbase/storage/search/implementation/database/BasicSqlHandler.java,v
retrieving revision 1.77
retrieving revision 1.78
diff -u -b -r1.77 -r1.78
--- BasicSqlHandler.java 25 Nov 2008 13:20:10 -0000 1.77
+++ BasicSqlHandler.java 1 Apr 2009 21:28:39 -0000 1.78
@@ -17,13 +17,12 @@
import java.util.*;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
-import java.text.FieldPosition;
/**
* Basic implementation.
*
* @author Rob van Maris
- * @version $Id: BasicSqlHandler.java,v 1.77 2008/11/25 13:20:10 michiel Exp $
+ * @version $Id: BasicSqlHandler.java,v 1.78 2009/04/01 21:28:39 michiel Exp $
* @since MMBase-1.7
*/
@@ -31,8 +30,13 @@
private static final Logger log =
Logging.getLoggerInstance(BasicSqlHandler.class);
- private static final SimpleDateFormat dateFormat = new
SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
- private static final FieldPosition dontcareFieldPosition = new
FieldPosition(DateFormat.YEAR_FIELD);
+ private static final ThreadLocal<SimpleDateFormat> DATE_FORMAT = new
ThreadLocal<SimpleDateFormat>() {
+ protected synchronized SimpleDateFormat initialValue() {
+ return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
+ }
+ };
+
+
/**
* Constructor.
@@ -122,12 +126,13 @@
Date date = new Date(value.getTime() - timeZoneOffset);
//Date date = new Date(value.getTime());
//log.debug("Using offset " + timeZoneOffset + " " + value + " -> " +
date);
- sb.append(dateFormat.format(date, new StringBuffer(),
dontcareFieldPosition));
+
+ sb.append(DATE_FORMAT.get().format(date));
}
/**
* Represents field value as a string, appending the result to a
- * stringbuffer.
+ * stringbuilder
* <p>
* Depending on the fieldType:
* <ul>
@@ -371,18 +376,15 @@
if (appended) {
sb.append(',');
}
+ String fieldAlias = field.getAlias();
appended = true;
// fieldname prefixed by table alias.
- Step step = field.getStep();
- String fieldName = field.getFieldName();
- String fieldAlias = field.getAlias();
-
if (field instanceof AggregatedField) {
int aggregationType = ((AggregatedField)
field).getAggregationType();
if (aggregationType ==
AggregatedField.AGGREGATION_TYPE_GROUP_BY) {
// Group by.
- appendField(sb, step, fieldName, multipleSteps);
+ appendField(sb, field, multipleSteps);
// Append to "GROUP BY"-buffer.
if (sbGroups.length() > 0) {
@@ -391,7 +393,7 @@
if (fieldAlias != null) {
sbGroups.append(getAllowedValue(fieldAlias));
} else {
- appendField(sbGroups, step, fieldName, multipleSteps);
+ appendField(sbGroups, field, multipleSteps);
}
} else {
@@ -416,14 +418,14 @@
default:
throw new IllegalStateException("Invalid
aggregationType value: " + aggregationType);
}
- appendField(sb, step, fieldName, multipleSteps);
+ appendField(sb, field, multipleSteps);
sb.append(')');
}
} else {
// Non-aggregate field.
- appendField(sb, step, fieldName, multipleSteps);
+ appendField(sb, field, multipleSteps);
}
// Field alias.
@@ -1067,6 +1069,14 @@
}
}
+
+ /**
+ * @since MMBase-1.9.1
+ */
+ protected void appendField(StringBuilder sb, StepField field, boolean
includeTablePrefix) {
+ appendField(sb, field.getStep(), field.getFieldName(),
includeTablePrefix);
+ }
+
/**
* Creates an identifier for a field, and appends it to a stringbuffer.
* The identifier is constructed from the fieldname, optionally prefixed
_______________________________________________
Cvs mailing list
[email protected]
http://lists.mmbase.org/mailman/listinfo/cvs