#1594 - Support loading of beans with invalid JSON content

Adjust to be per query via query.setAllowLoadErrors() rather than a
global config via ServerConfig.
This commit is contained in:
rob bygrave
2019-01-09 20:03:26 +13:00
parent 9fc10e8e04
commit 2b0669c2ae
10 changed files with 86 additions and 64 deletions
@@ -25,7 +25,6 @@ import io.ebean.Transaction;
import io.ebean.UpdateQuery;
import io.ebean.Version;
import io.ebean.bean.CallStack;
import io.ebean.bean.EntityBean;
import io.ebean.bean.ObjectGraphNode;
import io.ebean.bean.ObjectGraphOrigin;
import io.ebean.bean.PersistenceContext;
@@ -47,7 +46,6 @@ import io.ebeaninternal.api.SpiQuerySecondary;
import io.ebeaninternal.server.autotune.ProfilingListener;
import io.ebeaninternal.server.core.SpiOrmQueryRequest;
import io.ebeaninternal.server.deploy.BeanDescriptor;
import io.ebeaninternal.server.deploy.BeanProperty;
import io.ebeaninternal.server.deploy.BeanPropertyAssocMany;
import io.ebeaninternal.server.deploy.InheritInfo;
import io.ebeaninternal.server.deploy.TableJoin;
@@ -57,6 +55,7 @@ import io.ebeaninternal.server.query.CancelableQuery;
import io.ebeaninternal.server.query.NativeSqlQueryPlanKey;
import io.ebeaninternal.server.rawsql.SpiRawSql;
import javax.persistence.PersistenceException;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Collection;
@@ -141,6 +140,8 @@ public class DefaultOrmQuery<T> implements SpiQuery<T> {
private String lazyLoadManyPath;
private boolean allowLoadErrors;
/**
* Flag set for report/DTO beans when we may choose to explicitly include the Id property.
*/
@@ -329,8 +330,10 @@ public class DefaultOrmQuery<T> implements SpiQuery<T> {
@Override
public String profileEventId() {
switch (mode) {
case LAZYLOAD_BEAN: return FIND_ONE_LAZY;
case LAZYLOAD_MANY: return FIND_MANY_LAZY;
case LAZYLOAD_BEAN:
return FIND_ONE_LAZY;
case LAZYLOAD_MANY:
return FIND_MANY_LAZY;
default:
return type.profileEventId();
}
@@ -343,7 +346,7 @@ public class DefaultOrmQuery<T> implements SpiQuery<T> {
@Override
public Query<T> setProfileId(int profileId) {
this.profileId = (short)profileId;
this.profileId = (short) profileId;
return this;
}
@@ -409,6 +412,12 @@ public class DefaultOrmQuery<T> implements SpiQuery<T> {
this.asOfBaseTable = true;
}
@Override
public DefaultOrmQuery<T> setAllowLoadErrors() {
this.allowLoadErrors = true;
return this;
}
@Override
public void incrementAsOfTableCount() {
asOfTableCount++;
@@ -463,7 +472,7 @@ public class DefaultOrmQuery<T> implements SpiQuery<T> {
@Override
public DefaultOrmQuery<T> setRawSql(RawSql rawSql) {
this.rawSql = (SpiRawSql)rawSql;
this.rawSql = (SpiRawSql) rawSql;
return this;
}
@@ -775,6 +784,7 @@ public class DefaultOrmQuery<T> implements SpiQuery<T> {
copy.baseTable = baseTable;
copy.rootTableAlias = rootTableAlias;
copy.distinct = distinct;
copy.allowLoadErrors = allowLoadErrors;
copy.timeout = timeout;
copy.mapKey = mapKey;
copy.id = id;
@@ -1088,6 +1098,9 @@ public class DefaultOrmQuery<T> implements SpiQuery<T> {
if (distinct) {
sb.append(",dist:");
}
if (allowLoadErrors) {
sb.append(",allowLoadErrors:");
}
if (disableLazyLoading) {
sb.append(",disLazy:");
}
@@ -1194,6 +1207,7 @@ public class DefaultOrmQuery<T> implements SpiQuery<T> {
beanDescriptor.appendOrderById(this);
}
}
/**
* Calculate a hash based on the bind values used in the query.
* <p>
@@ -1278,7 +1292,7 @@ public class DefaultOrmQuery<T> implements SpiQuery<T> {
@Override
public boolean isBeanCacheGet() {
return useBeanCache.isGet() && beanDescriptor.isBeanCaching() ;
return useBeanCache.isGet() && beanDescriptor.isBeanCaching();
}
@Override
@@ -1337,7 +1351,7 @@ public class DefaultOrmQuery<T> implements SpiQuery<T> {
@Override
public DefaultOrmQuery<T> select(FetchGroup fetchGroup) {
this.detail = ((SpiFetchGroup)fetchGroup).detail();
this.detail = ((SpiFetchGroup) fetchGroup).detail();
return this;
}
@@ -1969,8 +1983,10 @@ public class DefaultOrmQuery<T> implements SpiQuery<T> {
}
@Override
public void handleLoadError(EntityBean bean, BeanProperty prop, String fullName, Exception e) {
server.getServerConfig().getLoadErrorHandler().handleLoadError(bean, prop, fullName, e);
public void handleLoadError(String fullName, Exception e) {
if (!allowLoadErrors) {
throw new PersistenceException("Error loading on " + fullName, e);
}
}
@Override