Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
0001155: Audit router causes NPE on MySQL.
  • Loading branch information
chenson42 committed Apr 3, 2013
1 parent dd988fe commit 7d6d191
Showing 1 changed file with 15 additions and 17 deletions.
Expand Up @@ -19,6 +19,7 @@
import org.jumpmind.symmetric.model.Node;
import org.jumpmind.symmetric.model.TriggerHistory;
import org.jumpmind.symmetric.service.IParameterService;
import org.jumpmind.util.FormatUtils;

public class AuditTableDataRouter extends AbstractDataRouter {

Expand Down Expand Up @@ -60,26 +61,26 @@ public Set<String> routeToNodes(SimpleRouterContext context, DataMetaData dataMe
.getDatabaseInfo().getDelimiterToken());

ISqlTemplate template = platform.getSqlTemplate();

Map<String, Object> values = null;
if (eventType != DataEventType.DELETE) {
values = new HashMap<String, Object>(getNewDataAsObject(null,
dataMetaData, engine.getSymmetricDialect()));
dataMetaData, engine.getSymmetricDialect(), false));
} else {
values = new HashMap<String, Object>(getOldDataAsObject(null,
dataMetaData, engine.getSymmetricDialect()));
dataMetaData, engine.getSymmetricDialect(), false));
}
Long sequence = (Long) context.get(auditTableName);
if (sequence == null) {
sequence = 1l + template.queryForLong(String.format("select max(%s) from %s",
COLUMN_AUDIT_ID, auditTableName));
} else {
sequence = 1l + sequence;
}
context.put(auditTableName, sequence);
values.put(COLUMN_AUDIT_ID, sequence);
values.put(COLUMN_AUDIT_TIME, new Date());
values.put(COLUMN_AUDIT_EVENT, eventType.getCode());
}
context.put(auditTable.getName(), sequence);
values.put(auditTable.getColumnWithName(COLUMN_AUDIT_ID).getName(), sequence);
values.put(auditTable.getColumnWithName(COLUMN_AUDIT_TIME).getName(), new Date());
values.put(auditTable.getColumnWithName(COLUMN_AUDIT_EVENT).getName(), eventType.getCode());
DmlStatement statement = platform.createDmlStatement(DmlType.INSERT, auditTable);
int[] types = statement.getTypes();
Object[] args = statement.getValueArray(values);
Expand All @@ -92,18 +93,15 @@ public Set<String> routeToNodes(SimpleRouterContext context, DataMetaData dataMe
protected Table toAuditTable(Table table) {
Table auditTable = table.copy();
String tableName = table.getName();
if (!FormatUtils.isMixedCase(tableName)) {
tableName = tableName.toUpperCase();
}
auditTable.setName(String.format("%s_AUDIT", tableName));
Column[] columns = auditTable.getColumns();
auditTable.removeAllColumns();
Column idColumn = new Column(COLUMN_AUDIT_ID, true, Types.BIGINT, 0, 0);
idColumn.setJdbcTypeName("BIGINT");
auditTable.addColumn(idColumn);
Column timeColumn = new Column(COLUMN_AUDIT_TIME, false, Types.TIMESTAMP, 0, 0);
timeColumn.setJdbcTypeName("TIMESTAMP");
auditTable.addColumn(timeColumn);
Column eventColumn = new Column(COLUMN_AUDIT_EVENT, false, Types.CHAR, 1, 0);
eventColumn.setJdbcTypeName("CHAR");
auditTable.addColumn(eventColumn);
auditTable.addColumn(new Column(COLUMN_AUDIT_ID, true, Types.BIGINT, 0, 0));
auditTable.addColumn(new Column(COLUMN_AUDIT_TIME, false, Types.TIMESTAMP, 0, 0));
auditTable.addColumn(new Column(COLUMN_AUDIT_EVENT, false, Types.CHAR, 1, 0));
for (Column column : columns) {
column.setRequired(false);
column.setPrimaryKey(false);
Expand Down

0 comments on commit 7d6d191

Please sign in to comment.