Skip to content

Commit

Permalink
Can't get a prepared timestamp object to work w/ purgeservice sql for…
Browse files Browse the repository at this point in the history
… H2. Try formatting as a jdbc timestamp.
  • Loading branch information
chenson42 committed Sep 29, 2009
1 parent e700df4 commit ebcc6aa
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
Expand Up @@ -55,6 +55,7 @@
import org.apache.commons.collections.map.ListOrderedMap;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.time.DateUtils;
import org.apache.commons.lang.time.FastDateFormat;
import org.apache.ddlutils.Platform;
import org.apache.ddlutils.io.DatabaseIO;
import org.apache.ddlutils.model.Column;
Expand Down Expand Up @@ -101,6 +102,8 @@ abstract public class AbstractDbDialect implements IDbDialect {

public static final String[] TIME_PATTERNS = { "HH:mm:ss.S", "HH:mm:ss", "yyyy-MM-dd HH:mm:ss.S",
"yyyy-MM-dd HH:mm:ss" };

public static final FastDateFormat JDBC_TIMESTAMP_FORMATTER = FastDateFormat.getInstance("yyyy-MM-dd hh:mm:ss.SSS");

protected final ILog log = LogFactory.getLog(getClass());

Expand Down Expand Up @@ -158,6 +161,13 @@ protected AbstractDbDialect() {
_defaultSizes.put(new Integer(3), "15,15");
_defaultSizes.put(new Integer(2), "15,15");
}

public String toFormattedTimestamp(java.util.Date time) {
StringBuilder ts = new StringBuilder("{ts '");
ts.append(JDBC_TIMESTAMP_FORMATTER.format(time));
ts.append("'}");
return ts.toString();
}

public IColumnFilter getDatabaseColumnFilter() {
return null;
Expand Down
Expand Up @@ -20,6 +20,7 @@

package org.jumpmind.symmetric.db;

import java.util.Date;
import java.util.Set;

import org.apache.ddlutils.Platform;
Expand Down Expand Up @@ -244,4 +245,6 @@ public String getTriggerName(DataEventType dml, String triggerPrefix, int maxTri
public String getInitialLoadTableAlias();

public String preProcessTriggerSqlClause(String sqlClause);

public String toFormattedTimestamp(Date time);
}
Expand Up @@ -28,7 +28,6 @@
import java.util.List;

import org.apache.commons.lang.time.DateUtils;
import org.hsqldb.Types;
import org.jumpmind.symmetric.common.ParameterConstants;
import org.jumpmind.symmetric.model.NodeStatus;
import org.jumpmind.symmetric.service.IClusterService;
Expand Down Expand Up @@ -134,10 +133,7 @@ private void purgeByMinMax(long[] minMax, String deleteSql, Date retentionTime,
log.info("DataPurgeTableStarting", tableName);

MapSqlParameterSource parameterSource = new MapSqlParameterSource();
parameterSource.registerSqlType("CUTOFF_TIME", Types.TIMESTAMP);
parameterSource.registerSqlType("MIN", Types.INTEGER);
parameterSource.registerSqlType("MAX", Types.INTEGER);
parameterSource.addValue("CUTOFF_TIME", retentionTime);
parameterSource.addValue("CUTOFF_TIME", dbDialect.toFormattedTimestamp(retentionTime));

while (minId <= purgeUpToId) {
long maxId = minId + maxNumtoPurgeinTx;
Expand Down

0 comments on commit ebcc6aa

Please sign in to comment.