#390 - ChangeLog - Change userContext to be Map<String,String>

This commit is contained in:
Robin Bygrave committed 2015-08-25 13:22:09 +12:00
1 parent b01df515bd
commit 16d5e04809
5 files changed
+49 -233

No files matched your search

@@ -1,7 +1,9 @@
package com.avaje.ebean.event.changelog;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
/**
* Holds a set of changes.
@@ -42,7 +44,7 @@ public class ChangeSet {
/**
* Arbitrary user context information expected to be optionally populated by ChangeLogPrepare.
*/
String userContext;
Map<String,String> userContext;
/**
* The bean changes.
@@ -178,7 +180,10 @@ public class ChangeSet {
/**
* Return a user context value - anything you set yourself in ChangeLogListener prepare().
*/
public String getUserContext() {
public Map<String,String> getUserContext() {
if (userContext == null) {
userContext = new LinkedHashMap<String, String>();
}
return userContext;
}
@@ -189,7 +194,7 @@ public class ChangeSet {
* in the foreground thread.
* </p>
*/
public void setUserContext(String userContext) {
public void setUserContext(Map<String,String> userContext) {
this.userContext = userContext;
}
@@ -67,14 +67,25 @@ public class ChangeJsonBuilder {
gen.writeStringField("txnState", changeSet.getTxnState().getCode());
gen.writeNumberField("txnBatch", changeSet.getTxnBatch());
gen.writeNumberField("txnPosition", position);
gen.writeStringField("userId", changeSet.getUserId());
String source = changeSet.getSource();
if (source != null) {
gen.writeStringField("source", source);
}
String userId = changeSet.getUserId();
if (userId != null) {
gen.writeStringField("userId", userId);
}
String userIpAddress = changeSet.getUserIpAddress();
if (userIpAddress != null) {
gen.writeStringField("userIpAddress", userIpAddress);
}
String userContext = changeSet.getUserContext();
if (userContext != null) {
gen.writeStringField("userContext", userContext);
Map<String, String> userContext = changeSet.getUserContext();
if (userContext != null && !userContext.isEmpty()) {
gen.writeObjectFieldStart("userContext");
for (Map.Entry<String, String> entry : userContext.entrySet()) {
gen.writeStringField(entry.getKey(), entry.getValue());
}
gen.writeEndObject();
}
}