#390 - ENH: Add Change log mechanism for easy fine grained logging of insert, update, delete activity

This commit is contained in:
Robin Bygrave committed 2015-08-20 20:46:28 +12:00
1 parent 46b158a0a0
commit 84190f3c2a
34 files changed
+1642 -84

No files matched your search

@@ -6,6 +6,7 @@ import com.avaje.ebean.text.json.*;
import com.avaje.ebean.text.PathProperties;
import com.avaje.ebeaninternal.api.SpiEbeanServer;
import com.avaje.ebeaninternal.server.deploy.BeanDescriptor;
import com.avaje.ebeaninternal.server.type.TypeManager;
import com.avaje.ebeaninternal.util.ParamTypeHelper;
import com.avaje.ebeaninternal.util.ParamTypeHelper.ManyType;
import com.avaje.ebeaninternal.util.ParamTypeHelper.TypeInfo;
@@ -25,17 +26,24 @@ public class DJsonContext implements JsonContext {
private final JsonFactory jsonFactory;
private final TypeManager typeManager;
private final Object defaultObjectMapper;
private final JsonConfig.Include defaultInclude;
public DJsonContext(SpiEbeanServer server, JsonFactory jsonFactory) {
public DJsonContext(SpiEbeanServer server, JsonFactory jsonFactory, TypeManager typeManager) {
this.server = server;
this.typeManager = typeManager;
this.jsonFactory = (jsonFactory != null) ? jsonFactory : new JsonFactory();
this.defaultObjectMapper = this.server.getServerConfig().getObjectMapper();
this.defaultInclude = this.server.getServerConfig().getJsonInclude();
}
public JsonScalar getScalar(JsonGenerator generator) {
return new DefaultJsonScalar(typeManager, new WriteJson(generator, defaultInclude));
}
public boolean isSupportedType(Type genericType) {
return server.isSupportedType(genericType);
}
@@ -0,0 +1,38 @@
package com.avaje.ebeaninternal.server.text.json;
import com.avaje.ebean.text.json.JsonScalar;
import com.avaje.ebeaninternal.server.type.ScalarType;
import com.avaje.ebeaninternal.server.type.TypeManager;
import java.io.IOException;
/**
* Default implementation of JsonScalar.
*/
public class DefaultJsonScalar implements JsonScalar {
private final TypeManager typeManager;
private final WriteJson writeJson;
public DefaultJsonScalar(TypeManager typeManager, WriteJson writeJson) {
this.typeManager = typeManager;
this.writeJson = writeJson;
}
@Override
public void write(String name, Object value) throws IOException {
if (value instanceof String) {
writeJson.writeStringField(name, (String)value);
} else {
ScalarType scalarType = (ScalarType)typeManager.getScalarType(value.getClass());
if (scalarType == null) {
throw new IllegalArgumentException("unhandled type " + value.getClass());
}
scalarType.jsonWrite(writeJson, name, value);
}
}
}
@@ -26,27 +26,38 @@ public class WriteJson implements JsonWriter {
private final PathProperties pathProperties;
private final PathStack pathStack = new PathStack();
private final PathStack pathStack;
private final ArrayStack<Object> parentBeans = new ArrayStack<Object>();
private final ArrayStack<Object> parentBeans;
private final Object objectMapper;
private final JsonConfig.Include include;
/**
* Construct for full bean use (normal).
*/
public WriteJson(SpiEbeanServer server, JsonGenerator generator, PathProperties pathProperties, Object objectMapper, JsonConfig.Include include){
this.server = server;
this.generator = generator;
this.pathProperties = pathProperties;
this.objectMapper = objectMapper;
this.include = include;
this.parentBeans = new ArrayStack<Object>();
this.pathStack = new PathStack();
}
/**
* Construct for testing purposes only.
* Construct for Json scalar use.
*/
public WriteJson(JsonGenerator generator, JsonConfig.Include include) {
this(null, generator, null, null, include);
public WriteJson(JsonGenerator generator, JsonConfig.Include include){
this.generator = generator;
this.include = include;
this.server = null;
this.pathProperties = null;
this.objectMapper = null;
this.parentBeans = null;
this.pathStack = null;
}
/**