Refactor remove message.properties resource in favour of simple error messages and logs

This commit is contained in:
rob bygrave
2020-09-24 23:40:05 +12:00
parent f175b198e6
commit 7eb185ce9b
13 changed files with 27 additions and 198 deletions
@@ -1793,7 +1793,7 @@ public final class DefaultServer implements SpiServer, SpiEbeanServer {
private EntityBean checkEntityBean(Object bean) {
if (bean == null) {
throw new IllegalArgumentException(Message.msg("bean.isnull"));
throw new IllegalArgumentException("The bean is null?");
}
if (!(bean instanceof EntityBean)) {
throw new IllegalArgumentException("Was expecting an EntityBean but got a " + bean.getClass());
@@ -1,64 +0,0 @@
package io.ebeaninternal.server.core;
import java.text.MessageFormat;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
/**
* Utility object used for internationalising log messages.
*/
public class Message {
private static final String bundle = "io.ebeaninternal.api.message";
/**
* Return a message that has a single argument.
*/
public static String msg(String key, Object arg) {
Object[] args = new Object[1];
args[0] = arg;
return MessageFormat.format(getPattern(key), args);
}
/**
* Return a message that has a two arguments.
*/
public static String msg(String key, Object arg, Object arg2) {
Object[] args = new Object[2];
args[0] = arg;
args[1] = arg2;
return MessageFormat.format(getPattern(key), args);
}
public static String msg(String key, Object arg, Object arg2, Object arg3) {
Object[] args = new Object[3];
args[0] = arg;
args[1] = arg2;
args[2] = arg3;
return MessageFormat.format(getPattern(key), args);
}
/**
* Return a message that has an array of arguments.
*/
public static String msg(String key, Object[] args) {
return MessageFormat.format(getPattern(key), args);
}
/**
* Return a message that has a no arguments.
*/
public static String msg(String key) {
return MessageFormat.format(getPattern(key), new Object[0]);
}
private static String getPattern(String key) {
try {
ResourceBundle myResources = ResourceBundle.getBundle(bundle);
return myResources.getString(key);
} catch (MissingResourceException e) {
return "MissingResource " + bundle + ":" + key;
}
}
}
@@ -850,7 +850,7 @@ public final class PersistRequestBean<T> extends PersistRequest implements BeanP
public final void checkRowCount(int rowCount) {
if (rowCount != 1 && rowCount != Statement.SUCCESS_NO_INFO) {
if (ConcurrencyMode.VERSION == concurrencyMode) {
throw new OptimisticLockException(Message.msg("persist.conc2", String.valueOf(rowCount)), null, bean);
throw new OptimisticLockException("Data has changed. updated row count " + rowCount, null, bean);
} else if (rowCount == 0 && type == Type.UPDATE) {
throw new EntityNotFoundException("No rows updated");
}
@@ -32,7 +32,6 @@ import io.ebeaninternal.server.cache.CacheChangeSet;
import io.ebeaninternal.server.cache.SpiCacheManager;
import io.ebeaninternal.server.core.InternString;
import io.ebeaninternal.server.core.InternalConfiguration;
import io.ebeaninternal.server.core.Message;
import io.ebeaninternal.server.core.bootup.BootupClasses;
import io.ebeaninternal.server.deploy.BeanDescriptor.EntityType;
import io.ebeaninternal.server.deploy.id.IdBinder;
@@ -1335,11 +1334,6 @@ public class BeanDescriptorManager implements BeanDescriptorMap {
return;
}
if (desc.idProperty() == null) {
// bean doesn't have an Id property
if (desc.isBaseTableType() && desc.getBeanFinder() == null) {
// expecting an id property
logger.debug(Message.msg("deploy.nouid", desc.getFullName()));
}
return;
}
@@ -3,7 +3,6 @@ package io.ebeaninternal.server.persist;
import io.ebean.config.dbplatform.DbPlatformType;
import io.ebeaninternal.api.BindParams;
import io.ebeaninternal.api.SpiLogManager;
import io.ebeaninternal.server.core.Message;
import io.ebeaninternal.server.core.timezone.DataTimeZone;
import io.ebeaninternal.server.expression.platform.DbExpressionHandler;
import io.ebeaninternal.server.persist.platform.MultiValueBind;
@@ -183,7 +182,7 @@ public class Binder {
}
} catch (SQLException ex) {
logger.warn(Message.msg("fetch.bind.error", String.valueOf(dataBind.currentPos() - 1), value));
logger.warn("error binding parameter [{}][{}]", (dataBind.currentPos() - 1), value);
throw ex;
}
}
@@ -376,8 +375,7 @@ public class Binder {
break;
default:
String msg = Message.msg("persist.bind.datatype", String.valueOf(dataType), String.valueOf(b.currentPos()));
throw new SQLException(msg);
throw new SQLException("Unhandled data type:" + dataType + " bind number:" + b.currentPos());
}
} catch (Exception e) {
@@ -16,7 +16,6 @@ import io.ebeaninternal.api.SpiEbeanServer;
import io.ebeaninternal.api.SpiSqlUpdate;
import io.ebeaninternal.api.SpiTransaction;
import io.ebeaninternal.api.SpiUpdate;
import io.ebeaninternal.server.core.Message;
import io.ebeaninternal.server.core.PersistRequest;
import io.ebeaninternal.server.core.PersistRequest.Type;
import io.ebeaninternal.server.core.PersistRequestBean;
@@ -545,7 +544,7 @@ public final class DefaultPersister implements Persister {
request.executeOrQueue();
} else if (logger.isDebugEnabled()) {
logger.debug(Message.msg("persist.update.skipped", request.getBean()));
logger.debug("Update skipped as bean is unchanged: {}", request.getBean());
}
if (request.isPersistCascade()) {
@@ -3,7 +3,6 @@ package io.ebeaninternal.server.persist.dml;
import io.ebean.bean.EntityBean;
import io.ebean.util.JdbcClose;
import io.ebeaninternal.api.SpiTransaction;
import io.ebeaninternal.server.core.Message;
import io.ebeaninternal.server.core.PersistRequestBean;
import io.ebeaninternal.server.deploy.BeanDescriptor;
@@ -155,9 +154,8 @@ public class InsertHandler extends DmlHandler {
if (idValue != null) {
persistRequest.setGeneratedKey(idValue);
}
} else {
throw new PersistenceException(Message.msg("persist.autoinc.norows"));
throw new PersistenceException("Autoincrement getGeneratedKeys() returned no rows?");
}
}
@@ -13,7 +13,6 @@ import io.ebean.util.StringHelper;
import io.ebeaninternal.api.SpiQuery;
import io.ebeaninternal.api.SpiTransaction;
import io.ebeaninternal.server.core.DiffHelp;
import io.ebeaninternal.server.core.Message;
import io.ebeaninternal.server.core.OrmQueryRequest;
import io.ebeaninternal.server.core.SpiResultSet;
import io.ebeaninternal.server.deploy.BeanDescriptor;
@@ -144,7 +143,7 @@ public class CQueryEngine {
t.getConnection();
// build a decent error message for the exception
String m = Message.msg("fetch.sqlerror", e.getMessage(), bindLog, sql);
String m = "Query threw SQLException:" + e.getMessage() + " Bind values:[" + bindLog + "] Query was:" + sql;
return dbPlatform.translate(m, e);
}
@@ -7,7 +7,6 @@ import io.ebean.meta.MetricVisitor;
import io.ebean.metric.MetricFactory;
import io.ebean.metric.TimedMetricMap;
import io.ebeaninternal.api.SpiQuery;
import io.ebeaninternal.server.core.Message;
import io.ebeaninternal.server.core.RelationalQueryEngine;
import io.ebeaninternal.server.core.RelationalQueryRequest;
import io.ebeaninternal.server.persist.Binder;
@@ -55,6 +54,10 @@ public class DefaultRelationalQueryEngine implements RelationalQueryEngine {
return new DefaultSqlRow(estimateCapacity, 0.75f, dbTrueValue, binaryOptimizedUUID);
}
private String errMsg(String msg, String sql) {
return "Query threw SQLException:" + msg + " Query was:" + sql;
}
@Override
public void findEach(RelationalQueryRequest request, Predicate<SqlRow> consumer) {
@@ -68,7 +71,7 @@ public class DefaultRelationalQueryEngine implements RelationalQueryEngine {
request.logSummary();
} catch (Exception e) {
throw new PersistenceException(Message.msg("fetch.error", e.getMessage(), request.getSql()), e);
throw new PersistenceException(errMsg(e.getMessage(), request.getSql()), e);
} finally {
request.close();
@@ -86,7 +89,7 @@ public class DefaultRelationalQueryEngine implements RelationalQueryEngine {
request.logSummary();
} catch (Exception e) {
throw new PersistenceException(Message.msg("fetch.error", e.getMessage(), request.getSql()), e);
throw new PersistenceException(errMsg(e.getMessage(), request.getSql()), e);
} finally {
request.close();
@@ -102,7 +105,7 @@ public class DefaultRelationalQueryEngine implements RelationalQueryEngine {
return value;
} catch (Exception e) {
throw new PersistenceException(Message.msg("fetch.error", e.getMessage(), request.getSql()), e);
throw new PersistenceException(errMsg(e.getMessage(), request.getSql()), e);
} finally {
request.close();
@@ -118,7 +121,7 @@ public class DefaultRelationalQueryEngine implements RelationalQueryEngine {
return list;
} catch (Exception e) {
throw new PersistenceException(Message.msg("fetch.error", e.getMessage(), request.getSql()), e);
throw new PersistenceException(errMsg(e.getMessage(), request.getSql()), e);
} finally {
request.close();
@@ -133,7 +136,7 @@ public class DefaultRelationalQueryEngine implements RelationalQueryEngine {
request.logSummary();
} catch (Exception e) {
throw new PersistenceException(Message.msg("fetch.error", e.getMessage(), request.getSql()), e);
throw new PersistenceException(errMsg(e.getMessage(), request.getSql()), e);
} finally {
request.close();
@@ -160,7 +163,7 @@ public class DefaultRelationalQueryEngine implements RelationalQueryEngine {
return list;
} catch (Exception e) {
throw new PersistenceException(Message.msg("fetch.error", e.getMessage(), request.getSql()), e);
throw new PersistenceException(errMsg(e.getMessage(), request.getSql()), e);
} finally {
request.close();
@@ -189,7 +192,7 @@ public class DefaultRelationalQueryEngine implements RelationalQueryEngine {
return value;
} catch (Exception e) {
throw new PersistenceException(Message.msg("fetch.error", e.getMessage(), request.getSql()), e);
throw new PersistenceException(errMsg(e.getMessage(), request.getSql()), e);
} finally {
request.close();
@@ -210,7 +213,7 @@ public class DefaultRelationalQueryEngine implements RelationalQueryEngine {
return rows;
} catch (Exception e) {
throw new PersistenceException(Message.msg("fetch.error", e.getMessage(), request.getSql()), e);
throw new PersistenceException(errMsg(e.getMessage(), request.getSql()), e);
} finally {
request.close();
@@ -2,7 +2,6 @@ package io.ebeaninternal.server.query;
import io.ebeaninternal.api.SpiQuery;
import io.ebeaninternal.server.core.DtoQueryRequest;
import io.ebeaninternal.server.core.Message;
import io.ebeaninternal.server.persist.Binder;
import javax.persistence.PersistenceException;
@@ -29,7 +28,7 @@ public class DtoQueryEngine {
return rows;
} catch (Throwable e) {
throw new PersistenceException(Message.msg("fetch.error", e.getMessage(), request.getSql()), e);
throw new PersistenceException(errMsg(e.getMessage(), request.getSql()), e);
} finally {
request.close();
}
@@ -42,7 +41,7 @@ public class DtoQueryEngine {
consumer.accept(request.readNextBean());
}
} catch (Exception e) {
throw new PersistenceException(Message.msg("fetch.error", e.getMessage(), request.getSql()), e);
throw new PersistenceException(errMsg(e.getMessage(), request.getSql()), e);
} finally {
request.close();
@@ -58,10 +57,14 @@ public class DtoQueryEngine {
}
}
} catch (Exception e) {
throw new PersistenceException(Message.msg("fetch.error", e.getMessage(), request.getSql()), e);
throw new PersistenceException(errMsg(e.getMessage(), request.getSql()), e);
} finally {
request.close();
}
}
private String errMsg(String msg, String sql) {
return "Query threw SQLException:" + msg + " Query was:" + sql;
}
}
@@ -1,6 +1,5 @@
package io.ebeaninternal.server.type;
import io.ebeaninternal.server.core.Message;
import io.ebeaninternal.server.core.timezone.DataTimeZone;
import java.io.ByteArrayOutputStream;
@@ -213,7 +212,7 @@ public class RsetDataReader implements DataReader {
}
reader.close();
} catch (IOException e) {
throw new SQLException(Message.msg("persist.clob.io", e.getMessage()));
throw new SQLException("IOException reading Clob " + e.getMessage());
}
return out.toString();
@@ -1,81 +0,0 @@
lookup.readonly=This lookup is readonly. You can not modify it.
find.params.mixed=You must use either named or ordered parameters, not both.
tablevalidate.invalidate={0} TableValidator invalidated [{1}] table[{2}]
class.not.found=Class [{0}] not found
deploy.fk.notfound=A Foreign key could not be picked when trying to join [{0}][{2}] to table [{1}] dynamically.
deploy.fk.none=There are no Foreign keys. When trying to join [{0}][{2}] to table [{1}] dynamically. Please use a @JoinColumn annotation on [{0}][{2}].
deploy.property.unmapped=Transient property [{0}][{1}] in {2};
deploy.nouid=Bean [{0}] has no unique id set
deploy.uidassume=Table has no primary key [{0}]. Assuming first property [{1}] as Unique Id.
deploy.ofbean=Deployment of [{0}] errored.
deploy.file.notfound=Deployment file [{0}] was not found
deploy.property.nofield=Class[{0}] Property[{1}] can not find field
deploy.property.notlist=Property [{0}] is not a java.util.List
deploy.property.notbean=Property [{0}] is not a BeanDependantProperty?
deploy.property.unmappedtype=Property [{0}] has unmapped type
deploy.property.temporalmissing=Property [{0}] is missing a @Temporal annotation
deploy.property.missing=Bean has no [{0}] property
deploy.attribute.missing=attribute [{0}] is missing in [{1}]
deploy.conc.all=Error in setup of bean deployment [{0}]. Concurrency set to ALL but bean doesn't implement BeanOldValues?
deploy.conc.ver=Error in setup of bean deployment [{0}]. Concurrency set to VERSION but no Version Column exists?
lookup.created=Lookup Created [{0}]
conc.mode.invalid=Concurrency mode [{0}] is not one of [all,version,none]
plugin.deploy.integer=Deployment parameter [{0}] is not an Integer
plugin.startup=Plugin[{0}][{1}]
plugin.dictionary=DictionaryInfo deserialized from file [{0}]
plugin.dictionary.error=Error deserialising the dictionary
tablebean.notable=MapBean without a table specified?
bean.isnull=The bean is null?
join.type.unknown=Join type of [{0}] is unknown
jdbc.type.notmapped=Type [{0}] is not mapped to a java.sql.Type
fetch.bg.finished=Background fetch finished [{0}] rows
fetch.desc.isnull=BeanDescriptor is null and fetch is not a FindByNativeSql!
fetch.type.unknown=Type of finder [{0}] not handled
fetch.bind.error=error binding parameter [{0}][{1}]
fetch.bind.datatype=Datatype [{0}] not handled for parameter [{1}][{2}]
fetch.bind.datatype2=Datatype for [{0}] not handled.
fetch.sqlerror=Query threw SQLException:{0} Bind values:[{1}] Query was:{2}
fetch.error=Query threw SQLException:{0} Query was:{1}
fetch.limit.orderby=You must specify an OrderBy if limiting the ResultSet
fetch.many.depth=Many property [{0}] can not be included due to the wrong depth.
fetch.many.one=Only one many property is allowed. [{0}] is being exluded.
persist.insert.one=Should insert 1 row but inserted {0}
persist.autoinc.norows=Autoincrement getGeneratedKeys() returned no rows?
persist.update.skipped=Update skipped as bean is unchanged:{0}
persist.conc=ConcurrencyException [{0}] differences[{1}]
persist.conc2=Data has changed. updated [{0}] rows
persist.bind.datatype=Unhandled data type [{0}] bind number[{1}]
persist.rollback.bg=rollback() on BackgroundTransaction?
persist.update.where=No WHERE columns in update statment {0}
persist.clob.io=IOException reading Clob {0}
invalid.argument=Invalid argument {0}
FATAL_ERROR=ERROR: A fatal error has occured. Check the error log. {0}
DATASOURCE_OK=DataSource {0} working ok.
SHUTTING_DOWN=DataSource shutdown all datasources in [{0}]
SHUT_DOWN_FINISHED=DataSource shutdown has finished.
CANT_FIND_PROPS=ERROR: Can't find the datasource props file.
ERROR_CREATING_FACTORY=ERROR: An error occured when creating the DataSourceFactory {0}.
CANT_SHUTDOWN_TYPE=WARN: Can't shutdown DataSource objects of this type {0}.
DB_DRIVER_NOTFOUND=ERROR: The JDBC Driver {0} can't be found.
POOL_IN_SHUTDOWN=ERROR: Trying to use the pool while it is shutting down.
WAIT_TIME_EXCEEDED=ERROR: Wait time {0} for connection exceeded. {1}.
SHUTDOWN_START=DataSource [{0}] Shutting down.
SHUTDOWN_LEAK=A Connection leak has been detected on shutdown {0}.
SHUTDOWN_END=DataSource [{0}] Shutdown ended.
METHOD_NOT_SUPPORTED=ERROR: this method is not supported.
SET_ALERT=WARN: Alert {0} has been set.
MISSING_PARAMETER=ERROR: A parameter {0} is missing from the props file.
IDLE_CONNECTION_ACCESSED=Pooled Connection has been accessed whilst idle in the pool, via method:
DEFAULT_DS_NOT_SPECIFIED=ERROR: No default dataSource has been specified.
@@ -1,19 +0,0 @@
package org.tests.lib;
import io.ebeaninternal.server.core.Message;
import org.junit.Test;
import static org.assertj.core.api.Assertions.assertThat;
public class TestMessage {
@Test
public void testMessage() {
String one = "one";
String two = "two";
String m = Message.msg("fetch.error", one, two);
assertThat(m).contains("Query threw SQLException:one Query was:");
}
}