mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-11-17 22:56:28 +00:00
Supports loading of corrupt beans
This commit is contained in:
1 parent
0b299edf0d
commit
4d93b70bf9
26 files changed
+221
-24
No files matched your search
@@ -88,4 +88,10 @@ public class DefaultBeanState implements BeanState {
|
||||
public void resetForInsert() {
|
||||
intercept.setNew();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Exception> getLoadErrors() {
|
||||
return intercept.getLoadErrors();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -90,4 +90,10 @@ public interface DbReadContext {
|
||||
* Return true if this request disables lazy loading.
|
||||
*/
|
||||
boolean isDisableLazyLoading();
|
||||
|
||||
/**
|
||||
* Handles a load error on given property.
|
||||
*/
|
||||
void handleLoadError(EntityBean bean, BeanProperty prop, String fullName, Exception e);
|
||||
|
||||
}
|
||||
@@ -49,15 +49,16 @@ class DynamicPropertyAggregationFormula extends DynamicPropertyBase {
|
||||
|
||||
@Override
|
||||
public void load(SqlBeanLoad sqlBeanLoad) {
|
||||
|
||||
Object value;
|
||||
try {
|
||||
Object value = scalarType.read(sqlBeanLoad.ctx().getDataReader());
|
||||
if (asTarget != null) {
|
||||
sqlBeanLoad.load(asTarget, value);
|
||||
}
|
||||
value = scalarType.read(sqlBeanLoad.ctx().getDataReader());
|
||||
|
||||
} catch (Exception e) {
|
||||
throw new PersistenceException("Error loading on " + fullName, e);
|
||||
sqlBeanLoad.ctx().handleLoadError(null, asTarget, fullName, e);
|
||||
return;
|
||||
}
|
||||
if (asTarget != null) {
|
||||
sqlBeanLoad.load(asTarget, value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ import io.ebeaninternal.server.core.SpiOrmQueryRequest;
|
||||
import io.ebeaninternal.server.deploy.BeanCollectionHelp;
|
||||
import io.ebeaninternal.server.deploy.BeanCollectionHelpFactory;
|
||||
import io.ebeaninternal.server.deploy.BeanDescriptor;
|
||||
import io.ebeaninternal.server.deploy.BeanProperty;
|
||||
import io.ebeaninternal.server.deploy.BeanPropertyAssocMany;
|
||||
import io.ebeaninternal.server.deploy.DbReadContext;
|
||||
import io.ebeaninternal.server.type.DataBind;
|
||||
@@ -815,6 +816,11 @@ public class CQuery<T> implements DbReadContext, CancelableQuery, SpiProfileTran
|
||||
return pstmt;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleLoadError(EntityBean bean, BeanProperty prop, String fullName, Exception e) {
|
||||
query.handleLoadError(bean, prop, fullName, e);
|
||||
}
|
||||
|
||||
public Set<String> getDependentTables() {
|
||||
return queryPlan.getDependentTables();
|
||||
}
|
||||
|
||||
@@ -6,8 +6,6 @@ import io.ebeaninternal.api.SpiQuery.Mode;
|
||||
import io.ebeaninternal.server.deploy.BeanProperty;
|
||||
import io.ebeaninternal.server.deploy.DbReadContext;
|
||||
|
||||
import javax.persistence.PersistenceException;
|
||||
|
||||
/**
|
||||
* Controls the loading of property data into a bean.
|
||||
* <p>
|
||||
@@ -88,8 +86,9 @@ public class SqlBeanLoad {
|
||||
return dbVal;
|
||||
|
||||
} catch (Exception e) {
|
||||
String msg = "Error loading on " + prop.getFullBeanName();
|
||||
throw new PersistenceException(msg, e);
|
||||
bean._ebean_getIntercept().setLoadError(prop.getPropertyIndex(), e);
|
||||
ctx.handleLoadError(bean, prop, prop.getFullBeanName(), e);
|
||||
return prop.getValue(bean);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@ 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;
|
||||
@@ -46,6 +47,7 @@ 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.TableJoin;
|
||||
import io.ebeaninternal.server.expression.DefaultExpressionList;
|
||||
@@ -1921,6 +1923,11 @@ public class DefaultOrmQuery<T> implements SpiQuery<T> {
|
||||
return profileLocation;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleLoadError(EntityBean bean, BeanProperty prop, String fullName, Exception e) {
|
||||
server.getServerConfig().getLoadErrorHandler().handleLoadError(bean, prop, fullName, e);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Query<T> orderById(boolean orderById) {
|
||||
this.orderById = orderById;
|
||||
|
||||
@@ -351,7 +351,7 @@ public class TCsvReader<T> implements CsvReader<T> {
|
||||
return path.parseDateTime(dt.getTime());
|
||||
|
||||
} catch (ParseException e) {
|
||||
throw new TextException("Error parsing [" + value + "] using format[" + format + "]", e);
|
||||
throw new TextException("Error parsing [{}] using format[" + format + "]", value, e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ package io.ebeaninternal.server.type;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonGenerator;
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import io.ebean.text.TextException;
|
||||
import io.ebean.text.json.EJson;
|
||||
import io.ebeaninternal.json.ModifyAwareList;
|
||||
import io.ebeanservice.docstore.api.mapping.DocPropertyType;
|
||||
@@ -145,7 +146,7 @@ public class ScalarTypeArrayList extends ScalarTypeJsonCollection<List> implemen
|
||||
try {
|
||||
return EJson.parseList(value, false);
|
||||
} catch (IOException e) {
|
||||
throw new PersistenceException("Failed to parse JSON content as List: [" + value + "]", e);
|
||||
throw new TextException("Failed to parse JSON [{}] as List", value, e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ package io.ebeaninternal.server.type;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonGenerator;
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import io.ebean.text.TextException;
|
||||
import io.ebean.text.json.EJson;
|
||||
import io.ebeaninternal.json.ModifyAwareSet;
|
||||
import io.ebeanservice.docstore.api.mapping.DocPropertyType;
|
||||
@@ -144,7 +145,7 @@ public class ScalarTypeArraySet<T> extends ScalarTypeJsonCollection<Set<T>> impl
|
||||
try {
|
||||
return EJson.parseSet(value, false);
|
||||
} catch (IOException e) {
|
||||
throw new PersistenceException("Failed to parse JSON content as List: [" + value + "]", e);
|
||||
throw new TextException("Failed to parse JSON [{}] as Set", value, e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@ public class ScalarTypeInetAddress extends ScalarTypeBaseVarchar<InetAddress> {
|
||||
try {
|
||||
return ConvertInetAddresses.forUriString(value);
|
||||
} catch (IllegalArgumentException e) {
|
||||
throw new TextException("Error with InetAddresses [" + value + "] ", e);
|
||||
throw new TextException("Error with InetAddresses [{}]", value, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package io.ebeaninternal.server.type;
|
||||
|
||||
import io.ebean.config.dbplatform.DbPlatformType;
|
||||
import io.ebean.text.TextException;
|
||||
import io.ebean.text.json.EJson;
|
||||
import io.ebeanservice.docstore.api.mapping.DocPropertyType;
|
||||
import com.fasterxml.jackson.core.JsonGenerator;
|
||||
@@ -75,7 +76,7 @@ public class ScalarTypeJsonList {
|
||||
// parse JSON into modifyAware list
|
||||
return EJson.parseList(json, true);
|
||||
} catch (IOException e) {
|
||||
throw new SQLException("Failed to parse JSON content as List: [" + json + "]", e);
|
||||
throw new TextException("Failed to parse JSON [{}] as List", json, e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -109,7 +110,7 @@ public class ScalarTypeJsonList {
|
||||
try {
|
||||
return EJson.parseList(value, false);
|
||||
} catch (IOException e) {
|
||||
throw new PersistenceException("Failed to parse JSON content as List: [" + value + "]", e);
|
||||
throw new TextException("Failed to parse JSON [{}] as List", value, e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -175,7 +175,7 @@ public abstract class ScalarTypeJsonMap extends ScalarTypeBase<Map> {
|
||||
// return a modify aware map
|
||||
return EJson.parseObject(value, true);
|
||||
} catch (IOException e) {
|
||||
throw new TextException(e);
|
||||
throw new TextException("Failed to parse JSON [{}] as Object", value, e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -158,7 +158,7 @@ public abstract class ScalarTypeJsonNode extends ScalarTypeBase<JsonNode> {
|
||||
try {
|
||||
return objectMapper.readValue(value, JsonNode.class);
|
||||
} catch (IOException e) {
|
||||
throw new TextException(e);
|
||||
throw new TextException("Failed to parse JSON [{}] as JsonNode", value, e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ import com.fasterxml.jackson.databind.ObjectWriter;
|
||||
import com.fasterxml.jackson.databind.SerializationConfig;
|
||||
import com.fasterxml.jackson.databind.introspect.AnnotatedField;
|
||||
import io.ebean.config.dbplatform.DbPlatformType;
|
||||
import io.ebean.text.TextException;
|
||||
import io.ebeaninternal.json.ModifyAwareList;
|
||||
import io.ebeaninternal.json.ModifyAwareMap;
|
||||
import io.ebeaninternal.json.ModifyAwareOwner;
|
||||
@@ -208,7 +209,7 @@ public class ScalarTypeJsonObjectMapper {
|
||||
try {
|
||||
return objectReader.readValue(json, deserType);
|
||||
} catch (IOException e) {
|
||||
throw new SQLException("Unable to convert JSON", e);
|
||||
throw new TextException("Failed to parse JSON [{}] as " + deserType, json, e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -258,7 +259,7 @@ public class ScalarTypeJsonObjectMapper {
|
||||
try {
|
||||
return objectReader.readValue(value, deserType);
|
||||
} catch (IOException e) {
|
||||
throw new PersistenceException("Unable to convert JSON", e);
|
||||
throw new TextException("Failed to parse JSON [{}] as " + deserType, value, e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package io.ebeaninternal.server.type;
|
||||
|
||||
import io.ebean.config.dbplatform.DbPlatformType;
|
||||
import io.ebean.text.TextException;
|
||||
import io.ebean.text.json.EJson;
|
||||
import io.ebeanservice.docstore.api.mapping.DocPropertyType;
|
||||
import com.fasterxml.jackson.core.JsonGenerator;
|
||||
@@ -78,7 +79,7 @@ public class ScalarTypeJsonSet {
|
||||
// parse JSON into modifyAware list
|
||||
return EJson.parseSet(json, true);
|
||||
} catch (IOException e) {
|
||||
throw new SQLException("Failed to parse JSON content as List: [" + json + "]", e);
|
||||
throw new TextException("Failed to parse JSON [{}] as Set", json, e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -78,7 +78,7 @@ public class ScalarTypePostgresHstore extends ScalarTypeBase<Map> {
|
||||
try {
|
||||
return EJson.parseObject(value);
|
||||
} catch (IOException e) {
|
||||
throw new TextException(e);
|
||||
throw new TextException("Failed to parse JSON [{}] as Object", value, e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ public class ScalarTypeURI extends ScalarTypeBaseVarchar<URI> {
|
||||
try {
|
||||
return new URI(value);
|
||||
} catch (URISyntaxException e) {
|
||||
throw new TextException("Error with URI [" + value + "] ", e);
|
||||
throw new TextException("Error with URI [{}]", value, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -38,7 +38,7 @@ public class ScalarTypeURL extends ScalarTypeBaseVarchar<URL> {
|
||||
try {
|
||||
return new URL(value);
|
||||
} catch (MalformedURLException e) {
|
||||
throw new TextException(e);
|
||||
throw new TextException("Error with URL [{}]", value, e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user