Refactor tidy error and log messages

This commit is contained in:
Rob Bygrave
2022-08-27 16:50:54 +12:00
parent ee71c79125
commit e51ac7de36
42 changed files with 82 additions and 106 deletions
@@ -87,7 +87,7 @@ public final class ScopeTrans {
@Override
public String toString() {
return "ScopeTrans[" + transaction + "]";
return "ScopeTrans " + transaction;
}
/**
@@ -30,7 +30,7 @@ public final class ScopedTransaction extends SpiTransactionProxy {
@Override
public String toString() {
return "ScopedTransaction[" + current + "]";
return "ScopedTransaction " + current;
}
/**
@@ -52,7 +52,7 @@ public final class RemoteCacheEvent implements BinaryWritable {
@Override
public String toString() {
return "CacheEvent[ clearAll:" + clearAll + " caches:" + clearCaches + "]";
return "CacheEvent clearAll:" + clearAll + " caches:" + clearCaches;
}
public static RemoteCacheEvent readBinaryMessage(BinaryReadContext dataInput) throws IOException {
@@ -32,7 +32,7 @@ public class BinaryTransactionEventReader {
String serverName = dataInput.readUTF();
SpiEbeanServer server = (SpiEbeanServer) serverLookup.getServer(serverName);
if (server == null) {
throw new IllegalStateException("EbeanServer not found for name [" + serverName + "]");
throw new IllegalStateException("Database not found for name " + serverName);
}
RemoteTransactionEvent event = new RemoteTransactionEvent(server);
event.readBinary(dataInput);
@@ -229,7 +229,7 @@ final class DefaultBeanLoader {
Object dbBean = query.findOne();
if (dbBean == null) {
throw new EntityNotFoundException("Bean not found during lazy load or refresh." + " id[" + id + "] type[" + desc.type() + "]");
throw new EntityNotFoundException("Bean not found during lazy load or refresh. Id:" + id + " type:" + desc.type());
}
desc.resetManyProperties(dbBean);
}
@@ -1079,7 +1079,7 @@ public final class DefaultServer implements SpiServer, SpiEbeanServer {
if (list.isEmpty()) {
return null;
} else if (list.size() > 1) {
throw new NonUniqueResultException("Unique expecting 0 or 1 results but got [" + list.size() + "]");
throw new NonUniqueResultException("Unique expecting 0 or 1 results but got " + list.size());
} else {
return list.get(0);
}
@@ -928,20 +928,20 @@ public final class PersistRequestBean<T> extends PersistRequest implements BeanP
}
private void logSummaryMessage() {
String draft = (beanDescriptor.isDraftable() && !publish) ? " draft[true]" : "";
String draft = (beanDescriptor.isDraftable() && !publish) ? "] draft[true]" : "]";
String name = beanDescriptor.name();
switch (type) {
case INSERT:
transaction.logSummary("Inserted [" + name + "] [" + (idValue == null ? "" : idValue) + "]" + draft);
transaction.logSummary("Inserted [" + name + "] [" + (idValue == null ? "" : idValue) + draft);
break;
case UPDATE:
transaction.logSummary("Updated [" + name + "] [" + idValue + "]" + draft);
transaction.logSummary("Updated [" + name + "] [" + idValue + draft);
break;
case DELETE:
transaction.logSummary("Deleted [" + name + "] [" + idValue + "]" + draft);
transaction.logSummary("Deleted [" + name + "] [" + idValue + draft);
break;
case DELETE_SOFT:
transaction.logSummary("SoftDelete [" + name + "] [" + idValue + "]" + draft);
transaction.logSummary("SoftDelete [" + name + "] [" + idValue + draft);
break;
default:
break;
@@ -86,8 +86,7 @@ public final class PersistRequestCallableSql extends PersistRequest {
persistExecute.collectSqlCall(label, startNanos);
}
if (transaction.isLogSummary()) {
String m = "CallableSql label[" + callableSql.getLabel() + "]" + " rows[" + rowCount + "]" + " bind[" + bindLog + "]";
transaction.logSummary(m);
transaction.logSummary("CallableSql label[" + callableSql.getLabel() + "]" + " rows[" + rowCount + "]" + " bind[" + bindLog + "]");
}
// register table modifications with the transaction event
@@ -83,8 +83,7 @@ public final class PersistRequestOrmUpdate extends PersistRequest {
OrmUpdateType ormUpdateType = ormUpdate.getOrmUpdateType();
String tableName = ormUpdate.getBaseTable();
if (transaction.isLogSummary()) {
String m = ormUpdateType + " table[" + tableName + "] rows[" + rowCount + "] bind[" + bindLog + "]";
transaction.logSummary(m);
transaction.logSummary(ormUpdateType + " table[" + tableName + "] rows[" + rowCount + "] bind[" + bindLog + "]");
}
if (ormUpdate.isNotifyCache()) {
// add the modification info to the TransactionEvent
@@ -46,7 +46,7 @@ public final class BeanCollectionUtil {
} else if (o instanceof Collection<?>) {
return ((Collection<?>) o);
}
throw new PersistenceException("expecting a Map or Collection but got [" + o.getClass().getName() + "]");
throw new PersistenceException("expecting a Map or Collection but got " + o.getClass().getName());
}
/**
@@ -73,6 +73,6 @@ public final class BeanCollectionUtil {
} else if (o instanceof Collection<?>) {
return ((Collection<?>) o);
}
throw new PersistenceException("expecting a Map or Collection but got [" + o.getClass().getName() + "]");
throw new PersistenceException("expecting a Map or Collection but got " + o.getClass().getName());
}
}
@@ -1891,7 +1891,7 @@ public class BeanDescriptor<T> implements BeanType<T>, STreeType, SpiBeanType {
}
BeanPropertyAssoc<?> assocProp = (BeanPropertyAssoc<?>) other._findBeanProperty(split[0]);
if (assocProp == null) {
throw new IllegalStateException("Unknown property path [" + split[0] + "] from[" + path + "]");
throw new IllegalStateException("Unknown property path " + split[0] + " from " + path);
}
BeanDescriptor<?> targetDesc = assocProp.targetDescriptor();
path = split[1];
@@ -988,14 +988,14 @@ public final class BeanDescriptorManager implements BeanDescriptorMap, SpiBeanTy
private DeployBeanPropertyAssocOne<?> mappedOneToOne(DeployBeanPropertyAssocOne<?> prop, String mappedBy, DeployBeanDescriptor<?> targetDesc) {
DeployBeanProperty mappedProp = targetDesc.getBeanProperty(mappedBy);
if (mappedProp == null) {
throw new PersistenceException("Error on " + prop.getFullBeanName() + " Can not find mappedBy property [" + targetDesc + "." + mappedBy + "]");
throw new PersistenceException("Error on " + prop.getFullBeanName() + " Can not find mappedBy property " + targetDesc + "." + mappedBy);
}
if (!(mappedProp instanceof DeployBeanPropertyAssocOne<?>)) {
throw new PersistenceException("Error on " + prop.getFullBeanName() + ". mappedBy property [" + targetDesc + "." + mappedBy + "]is not a OneToOne?");
throw new PersistenceException("Error on " + prop.getFullBeanName() + ". mappedBy property " + targetDesc + "." + mappedBy + " is not a OneToOne?");
}
DeployBeanPropertyAssocOne<?> mappedAssocOne = (DeployBeanPropertyAssocOne<?>) mappedProp;
if (!mappedAssocOne.isOneToOne()) {
throw new PersistenceException("Error on " + prop.getFullBeanName() + ". mappedBy property [" + targetDesc + "." + mappedBy + "]is not a OneToOne?");
throw new PersistenceException("Error on " + prop.getFullBeanName() + ". mappedBy property " + targetDesc + "." + mappedBy + " is not a OneToOne?");
}
return mappedAssocOne;
}
@@ -1078,10 +1078,10 @@ public final class BeanDescriptorManager implements BeanDescriptorMap, SpiBeanTy
private DeployBeanPropertyAssocOne<?> mappedManyToOne(DeployBeanPropertyAssocMany<?> prop, DeployBeanDescriptor<?> targetDesc, String mappedBy) {
DeployBeanProperty mappedProp = targetDesc.getBeanProperty(mappedBy);
if (mappedProp == null) {
throw new PersistenceException("Error on " + prop.getFullBeanName() + " Can not find mappedBy property [" + mappedBy + "] " + "in [" + targetDesc + "]");
throw new PersistenceException("Error on " + prop.getFullBeanName() + " Can not find mappedBy property " + mappedBy + " in " + targetDesc);
}
if (!(mappedProp instanceof DeployBeanPropertyAssocOne<?>)) {
throw new PersistenceException("Error on " + prop.getFullBeanName() + ". mappedBy property [" + mappedBy + "]is not a ManyToOne?" + "in [" + targetDesc + "]");
throw new PersistenceException("Error on " + prop.getFullBeanName() + ". mappedBy property " + mappedBy + " is not a ManyToOne? in " + targetDesc);
}
return (DeployBeanPropertyAssocOne<?>) mappedProp;
}
@@ -1129,15 +1129,15 @@ public final class BeanDescriptorManager implements BeanDescriptorMap, SpiBeanTy
private DeployBeanPropertyAssocMany<?> mappedManyToMany(DeployBeanPropertyAssocMany<?> prop, String mappedBy, DeployBeanDescriptor<?> targetDesc) {
DeployBeanProperty mappedProp = targetDesc.getBeanProperty(mappedBy);
if (mappedProp == null) {
throw new PersistenceException("Error on " + prop.getFullBeanName() + " Can not find mappedBy property [" + mappedBy + "] " + "in [" + targetDesc + "]");
throw new PersistenceException("Error on " + prop.getFullBeanName() + " Can not find mappedBy property " + mappedBy + " in " + targetDesc);
}
if (!(mappedProp instanceof DeployBeanPropertyAssocMany<?>)) {
throw new PersistenceException("Error on " + prop.getFullBeanName() + ". mappedBy property [" + targetDesc + "." + mappedBy + "] is not a ManyToMany?");
throw new PersistenceException("Error on " + prop.getFullBeanName() + ". mappedBy property " + targetDesc + "." + mappedBy + " is not a ManyToMany?");
}
DeployBeanPropertyAssocMany<?> mappedAssocMany = (DeployBeanPropertyAssocMany<?>) mappedProp;
if (!mappedAssocMany.isManyToMany()) {
throw new PersistenceException("Error on " + prop.getFullBeanName() + ". mappedBy property [" + targetDesc + "." + mappedBy + "] is not a ManyToMany?");
throw new PersistenceException("Error on " + prop.getFullBeanName() + ". mappedBy property " + targetDesc + "." + mappedBy + " is not a ManyToMany?");
}
return mappedAssocMany;
}
@@ -434,7 +434,7 @@ public abstract class BeanPropertyAssoc<T> extends BeanProperty implements STree
if (!idProp.isEmbedded()) {
// simple single scalar id
if (cols.length != 1) {
CoreLog.log.log(ERROR, "No Imported Id column for [" + idProp + "] in table [" + join.getTable() + "]");
CoreLog.log.log(ERROR, "No Imported Id column for {0} in table {1}", idProp, join.getTable());
return null;
} else {
BeanProperty[] idProps = {idProp};
@@ -718,7 +718,7 @@ public class BeanPropertyAssocMany<T> extends BeanPropertyAssoc<T> implements ST
}
}
}
throw new RuntimeException("Can not find Master [" + beanType + "] in Child[" + targetDesc + "]");
throw new RuntimeException("Can not find Master " + beanType + " in Child " + targetDesc);
}
/**
@@ -734,7 +734,7 @@ public class BeanPropertyAssocMany<T> extends BeanPropertyAssoc<T> implements ST
}
String from = descriptor.fullName();
String to = targetDesc.fullName();
throw new PersistenceException(from + ": Could not find mapKey property [" + mapKey + "] on [" + to + "]");
throw new PersistenceException(from + ": Could not find mapKey property " + mapKey + " on " + to);
}
public IntersectionRow buildManyDeleteChildren(EntityBean parentBean, List<Object> excludeDetailIds) {
@@ -41,7 +41,7 @@ final class DetermineAggPath {
}
}
throw new IllegalArgumentException("Could not find path in aggregation formula [" + aggregation + "]");
throw new IllegalArgumentException("Could not find path in aggregation formula " + aggregation);
}
private static boolean isNamePart(char ch) {
@@ -94,7 +94,7 @@ final class DetermineAggPath {
pos = pos + 1;
continue;
}
throw new IllegalArgumentException("Can not find path to many in aggregation formula [" + aggregation + "]");
throw new IllegalArgumentException("Can not find path to many in aggregation formula " + aggregation);
}
}
}
@@ -26,7 +26,7 @@ class DynamicPropertyAggregationFormula extends DynamicPropertyBase {
@Override
public String toString() {
return "DynamicPropertyFormula[" + parsedFormula + "]";
return "DynamicPropertyFormula " + parsedFormula;
}
@Override
@@ -32,7 +32,7 @@ final class FormulaPropertyPath {
int openBracket = formula.indexOf('(');
int closeBracket = formula.lastIndexOf(')');
if (openBracket == -1 || closeBracket == -1) {
throw new IllegalStateException("Unable to parse formula [" + formula + "]");
throw new IllegalStateException("Unable to parse formula " + formula);
}
outerFunction = formula.substring(0, openBracket).trim();
internalExpression = trimDistinct(formula.substring(openBracket + 1, closeBracket));
@@ -354,7 +354,7 @@ public final class InheritInfo {
@Override
public String toString() {
return "InheritInfo[" + type.getName() + "] disc[" + discriminatorStringValue + "]";
return "InheritInfo " + type.getName() + " disc:" + discriminatorStringValue;
}
}
@@ -255,7 +255,7 @@ public final class DeployInheritInfo implements Comparable<DeployInheritInfo> {
public String toString() {
String root = parent == null ? null : parent.getName();
String name = type == null ? null : type.getName();
return "InheritInfo[" + name + "]" + " root[" + root + "]" + " disValue[" + discriminatorStringValue + "]";
return "InheritInfo " + name + " root:" + root + " disc:" + discriminatorStringValue;
}
@Override
@@ -141,7 +141,7 @@ public final class DeployUtil {
if (scalarType != null || property.isTransient()) {
return scalarType;
}
throw new PersistenceException(property.getFullBeanName() + " has no ScalarType - type[" + propType.getName() + "]");
throw new PersistenceException(property.getFullBeanName() + " has no ScalarType - type " + propType.getName());
} catch (IllegalArgumentException e) {
if (property.isTransient()) {
// expected for transient properties with unknown/non-mapped types
@@ -174,7 +174,7 @@ public final class DeployUtil {
Class<?> type = prop.getPropertyType();
ScalarType<?> scalarType = typeManager.getArrayScalarType(type, prop.getGenericType(), prop.isNullable());
if (scalarType == null) {
throw new RuntimeException("No ScalarType for @DbArray type for [" + prop.getFullBeanName() + "]");
throw new RuntimeException("No ScalarType for @DbArray type for " + prop.getFullBeanName());
}
int dbType = scalarType.jdbcType();
prop.setDbType(dbType);
@@ -206,7 +206,7 @@ public final class DeployUtil {
prop.setMutationDetection(mutationDetection);
ScalarType<?> scalarType = typeManager.getJsonScalarType(prop, dbType, dbLength);
if (scalarType == null) {
throw new RuntimeException("No ScalarType for JSON property [" + prop + "] [" + dbType + "]");
throw new RuntimeException("No ScalarType for JSON property " + prop + " dbType:" + dbType);
}
prop.setScalarType(scalarType);
if (dbType == Types.VARCHAR || dbLength > 0) {
@@ -251,7 +251,7 @@ public final class DeployUtil {
scalarType = typeManager.getScalarType(type, lobType);
if (scalarType == null) {
// this should never occur actually
throw new RuntimeException("No ScalarType for LOB type [" + type + "] [" + lobType + "]");
throw new RuntimeException("No ScalarType for LOB type " + type + " dbType:" + lobType);
}
prop.setDbType(lobType);
prop.setScalarType(scalarType);
@@ -351,7 +351,7 @@ abstract class EqlWhereListener<T> extends EQLBaseListener {
if (Character.isDigit(firstChar)) {
return EqlValueType.NUMBER;
}
throw new IllegalArgumentException("Unexpected first character in value [" + valueAsText + "]");
throw new IllegalArgumentException("Unexpected first character in value " + valueAsText);
}
}
@@ -340,9 +340,7 @@ public final class Binder {
if (data != null) {
dataClass = data.getClass().getName();
}
String m = "Error with property[" + b.currentPos() + "] dt[" + dataType + "]";
m += "data[" + data + "][" + dataClass + "]";
throw new PersistenceException(m, e);
throw new PersistenceException("Error with property:" + b.currentPos() + " dt:" + dataType + " data:" + data + " " + dataClass, e);
}
}
@@ -70,7 +70,7 @@ final class DmlBeanPersister implements BeanPersister {
}
} catch (SQLException e) {
// log the error to the transaction log
String msg = "Error[" + StringHelper.removeNewLines(e.getMessage()) + "]";
String msg = "Error: " + StringHelper.removeNewLines(e.getMessage());
if (request.transaction().isLogSummary()) {
request.transaction().logSummary(msg);
}
@@ -101,7 +101,7 @@ public abstract class DmlHandler implements PersistHandler, BindableRequest {
persistRequest.postExecute();
} catch (OptimisticLockException e) {
// add the SQL and bind values to error message
String m = e.getMessage() + " sql[" + sql + "] bind[" + bindLog + "]";
final String m = e.getMessage() + " sql[" + sql + "] bind[" + bindLog + "]";
persistRequest.transaction().logSummary("OptimisticLockException:" + m);
throw new OptimisticLockException(m, null, e.getEntity());
}
@@ -482,8 +482,8 @@ final class CQueryBuilder {
} else if (beanProperty.isDiscriminator()) {
propertyName = SplitName.parent(propertyName);
} else if (beanProperty instanceof BeanPropertyAssocOne<?>) {
String msg = "Column [" + column.getDbColumn() + "] mapped to complex Property[" + propertyName + "]";
msg += ". It should be mapped to a simple property (probably the Id property). ";
String msg = "Column " + column.getDbColumn() + " mapped to complex property " + propertyName +
". It should be mapped to a simple property (probably the Id property).";
throw new PersistenceException(msg);
}
if (propertyName != null) {
@@ -129,14 +129,12 @@ public final class CQueryEngine {
SpiTransaction t = request.transaction();
if (t.isLogSummary()) {
// log the error to the transaction log
String msg = "ERROR executing query, bindLog[" + bindLog + "] error[" + StringHelper.removeNewLines(e.getMessage()) + "]";
t.logSummary(msg);
t.logSummary("ERROR executing query, bindLog[" + bindLog + "] error:" + StringHelper.removeNewLines(e.getMessage()));
}
// ensure 'rollback' is logged if queryOnly transaction
t.connection();
// build a decent error message for the exception
String m = "Query threw SQLException:" + e.getMessage() + " Bind values:[" + bindLog + "] Query was:" + sql;
return dbPlatform.translate(m, e);
return dbPlatform.translate("Query threw SQLException:" + e.getMessage() + " Bind values:[" + bindLog + "] Query was:" + sql, e);
}
/**
@@ -337,10 +337,10 @@ public final class CQueryPredicates {
if (idPos <= -1 || idPos >= manyPos) {
if (idPos > manyPos) {
// there was an error with the order by...
String msg = "A Query on [" + desc + "] includes a join to a 'many' association [" + manyProp.name();
msg += "] with an incorrect orderBy [" + orderBy + "]. The id property [" + orderById + "]";
msg += " must come before the many property [" + manyProp.name() + "] in the orderBy.";
msg += " Ebean has automatically modified the orderBy clause to do this.";
String msg = "A Query on [" + desc + "] includes a join to a 'many' association [" + manyProp.name()
+ "] with an incorrect orderBy [" + orderBy + "]. The id property [" + orderById
+ "] must come before the many property [" + manyProp.name() + "] in the orderBy."
+ " Ebean has automatically modified the orderBy clause to do this.";
CoreLog.log.log(WARNING, msg);
}
// the id needs to come before the manyPropName
@@ -133,8 +133,7 @@ final class SqlTreeAlias {
s = aliasMap.get(prefix);
}
if (s == null) {
String msg = "Could not determine table alias for [" + prefix + "] manyMap[" + manyWhereAliasMap + "] aliasMap[" + aliasMap + "]";
throw new RuntimeException(msg);
throw new RuntimeException("Could not determine table alias for " + prefix + " manyMap:" + manyWhereAliasMap + " aliasMap:" + aliasMap);
}
return s;
}
@@ -181,7 +181,7 @@ public final class DefaultDtoQuery<T> extends AbstractQuery implements SpiDtoQue
@Override
public String toString() {
return "DtoQuery [" + sql + "]";
return "DtoQuery " + sql;
}
@Override
@@ -1714,7 +1714,7 @@ public class DefaultOrmQuery<T> extends AbstractQuery implements SpiQuery<T> {
@Override
public final String toString() {
return "Query [" + whereExpressions + "]";
return "Query " + whereExpressions;
}
@Override
@@ -121,7 +121,7 @@ public final class DefaultRelationalQuery extends AbstractQuery implements SpiSq
@Override
public String toString() {
return "SqlQuery [" + query + "]";
return "SqlQuery " + query;
}
@Override
@@ -98,9 +98,9 @@ public interface SpiRawSql extends RawSql {
@Override
public String toString() {
if (!parsed) {
return "unparsed[" + unparsedSql + "]";
return "unparsed " + unparsedSql;
}
return "select[" + preFrom + "] preWhere[" + preWhere + "] preHaving[" + preHaving + "] orderBy[" + orderBy + "]";
return "select:" + preFrom + " preWhere:" + preWhere + " preHaving:" + preHaving + " orderBy:" + orderBy;
}
public boolean isDistinct() {
@@ -301,8 +301,7 @@ public interface SpiRawSql extends RawSql {
} else {
Column column = dbColumnMap.get(dbColumn);
if (column == null) {
String msg = "DB Column [" + dbColumn + "] not found in mapping. Expecting one of [" + dbColumnMap.keySet() + "]";
throw new IllegalArgumentException(msg);
throw new IllegalArgumentException("DB Column " + dbColumn + " not found in mapping. Expecting one of " + dbColumnMap.keySet());
}
column.setPropertyName(propertyName);
}
@@ -420,8 +419,7 @@ public interface SpiRawSql extends RawSql {
private void checkMapping() {
if (propertyName == null) {
String msg = "No propertyName defined (Column mapping) for dbColumn [" + dbColumn + "]";
throw new IllegalStateException(msg);
throw new IllegalStateException("No propertyName defined (Column mapping) for dbColumn " + dbColumn);
}
}
@@ -21,7 +21,7 @@ public final class DeleteByIdMap {
@Override
public String toString() {
return "DeleteById[" + beanMap.values() + "]";
return "DeleteById " + beanMap.values();
}
public void notifyCache(CacheChangeSet changeSet) {
@@ -27,7 +27,7 @@ public final class RemoteTableMod implements BinaryWritable {
@Override
public String toString() {
return "TableMod[" + timestamp + "; " + tables + "]";
return "TableMod " + timestamp + "; " + tables;
}
public long getTimestamp() {
@@ -51,10 +51,8 @@ final class EnumToDbIntegerMap extends EnumToDbValueMap<Integer> {
return this;
} catch (Exception e) {
String msg = "Error converted enum type[" + beanValue.getClass().getName();
msg += "] enum value[" + beanValue + "] string value [" + stringDbValue + "]";
msg += " to an Integer.";
throw new PersistenceException(msg, e);
throw new PersistenceException("Error converted enum [" + beanValue.getClass().getName()
+ "] value[" + beanValue + "] string value [" + stringDbValue + "] to an Integer.", e);
}
}
@@ -163,8 +163,7 @@ final class ScalarTypeEnumStandard {
return null;
} else {
if (ordinal < 0 || ordinal >= enumArray.length) {
String m = "Unexpected ordinal [" + ordinal + "] out of range [" + enumArray.length + "]";
throw new IllegalStateException(m);
throw new IllegalStateException("Unexpected ordinal " + ordinal + " out of range " + enumArray.length);
}
return enumArray[ordinal];
}
@@ -196,8 +195,7 @@ final class ScalarTypeEnumStandard {
ordinal = Integer.parseInt(dbValue.toString());
}
if (ordinal < 0 || ordinal >= enumArray.length) {
String m = "Unexpected ordinal [" + ordinal + "] out of range [" + enumArray.length + "]";
throw new IllegalStateException(m);
throw new IllegalStateException("Unexpected ordinal " + ordinal + " out of range " + enumArray.length);
}
return enumArray[ordinal];
}
@@ -74,7 +74,7 @@ final class ScalarTypeJsonSet {
try {
return convertElements(EJson.parseSet(value, false));
} catch (IOException e) {
throw new PersistenceException("Failed to parse JSON content as Set: [" + value + "]", e);
throw new PersistenceException("Failed to parse JSON content as Set: " + value, e);
}
}
}
@@ -177,7 +177,7 @@ final class ScalarTypeJsonSet {
try {
return convertList(EJson.parseList(value));
} catch (IOException e) {
throw new PersistenceException("Failed to parse JSON content as Set: [" + value + "]", e);
throw new PersistenceException("Failed to parse JSON content as Set: " + value, e);
}
}
@@ -56,7 +56,7 @@ public final class TypeReflectHelper {
if (upperBounds != null && upperBounds.length == 1) {
return getClass(upperBounds[0]);
}
throw new IllegalArgumentException("Don't know how to determine Class from Type [" + type + "]");
throw new IllegalArgumentException("Don't know how to determine Class from type " + type);
}
return (Class<?>) type;
}
@@ -16,7 +16,7 @@ final class UtilDateParser {
try {
return formatter().parse(jsonDateTime);
} catch (ParseException e) {
throw new RuntimeException("Error parsing Date[" + jsonDateTime + "]", e);
throw new RuntimeException("Error parsing Date " + jsonDateTime, e);
}
}
@@ -142,7 +142,7 @@ public final class BindParamsParser {
param = params.getParameter(paramName);
}
if (param == null) {
throw new PersistenceException("Bind value is not set or null for [" + paramName + "] in [" + sql + "]");
throw new PersistenceException("Bind value is not set or null for " + paramName + " in " + sql);
}
return param;
}
@@ -38,7 +38,7 @@ public final class SortByClauseParser {
}
String[] words = section.split(" ");
if (words.length < 1 || words.length > 3) {
throw new RuntimeException("Expecting 1 to 3 words in [" + section + "] but got [" + words.length + "]");
throw new RuntimeException("Expecting 1 to 3 words in [" + section + "] but got " + words.length);
}
Boolean nullsHigh = null;
@@ -71,8 +71,7 @@ public final class SortByClauseParser {
if (SortByClause.NULLSLOW.equalsIgnoreCase(word)) {
return Boolean.FALSE;
}
String m = "Expecting nullsHigh or nullsLow but got [" + word + "] in [" + rawSortBy + "]";
throw new RuntimeException(m);
throw new RuntimeException("Expecting nullsHigh or nullsLow but got [" + word + "] in " + rawSortBy);
}
@@ -83,8 +82,7 @@ public final class SortByClauseParser {
if (SortByClause.DESC.equalsIgnoreCase(word)) {
return false;
}
String m = "Expect ASC or DESC but got [" + word + "] in [" + rawSortBy + "]";
throw new RuntimeException(m);
throw new RuntimeException("Expect ASC or DESC but got " + word + " in " + rawSortBy);
}
}
@@ -15,13 +15,11 @@ import org.tests.rawsql.ACustomer;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class TestRawSqlParsing extends BaseTestCase {
class TestRawSqlParsing extends BaseTestCase {
@Test
public void test() {
void test() {
String sql
= " select order_id, sum(order_qty*unit_price) as totalAmount"
+ " from o_order_detail "
@@ -35,13 +33,12 @@ public class TestRawSqlParsing extends BaseTestCase {
Sql rs = ((SpiRawSql)rawSql).getSql();
String s = rs.toString();
assertTrue(s.contains("[order_id, sum"));
assertThat(s).contains("select:order_id, sum");
}
@Test
@ForPlatform(Platform.POSTGRES)
public void testDoubleColon() {
void testDoubleColon() {
ResetBasicData.reset();
String sql = "select id, name from o_customer where name=:name and MD5(id::text) BETWEEN '00000000000000000000000000000000' AND 'ffffffffffffffffffffffffffffffff'";
@@ -59,8 +56,7 @@ public class TestRawSqlParsing extends BaseTestCase {
}
@Test
public void testWhere() {
void testWhere() {
ResetBasicData.reset();
RawSql sql = RawSqlBuilder.parse("SELECT id, name FROM o_customer ${where}").create();
@@ -75,8 +71,7 @@ public class TestRawSqlParsing extends BaseTestCase {
@ForPlatform({Platform.H2, Platform.POSTGRES})
@Test
public void testUnion() {
void testUnion() {
ResetBasicData.reset();
String sql =
@@ -100,10 +95,9 @@ public class TestRawSqlParsing extends BaseTestCase {
assertThat(sqlOf(query)).contains(") all_split limit 5 offset 1");
}
@ForPlatform({Platform.H2, Platform.POSTGRES})
@Test
public void testUnion_explicitWhere() {
void testUnion_explicitWhere() {
ResetBasicData.reset();
String sql =
@@ -135,7 +129,7 @@ public class TestRawSqlParsing extends BaseTestCase {
@ForPlatform({Platform.H2, Platform.POSTGRES})
@Test
public void testUnion_explicitAndhere() {
void testUnion_explicitAndhere() {
ResetBasicData.reset();
String sql =
@@ -167,8 +161,7 @@ public class TestRawSqlParsing extends BaseTestCase {
@ForPlatform({Platform.H2, Platform.POSTGRES})
@Test
public void testColumnName2() {
void testColumnName2() {
ResetBasicData.reset();
String sql = "select 42 custId, 'bar' customerName from o_customer";
@@ -189,8 +182,7 @@ public class TestRawSqlParsing extends BaseTestCase {
@ForPlatform({Platform.H2, Platform.POSTGRES})
@Test
public void testColumnAlias() {
void testColumnAlias() {
ResetBasicData.reset();
String sql = "select 43 custId, name as custName from o_customer";
@@ -211,8 +203,7 @@ public class TestRawSqlParsing extends BaseTestCase {
@ForPlatform({Platform.H2, Platform.POSTGRES})
@Test
public void testColumnNameMapping() {
void testColumnNameMapping() {
ResetBasicData.reset();
String sql = "select v.custId, v.customerName from (select id custId, name customerName from o_customer) v";