mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
#1738 - Refactor add final, Object.equals, Integer.compare
This commit is contained in:
@@ -11,7 +11,7 @@ import java.util.List;
|
||||
*/
|
||||
public class AutoTuneCollection {
|
||||
|
||||
List<Entry> entries = new ArrayList<>();
|
||||
final List<Entry> entries = new ArrayList<>();
|
||||
|
||||
public Entry add(ObjectGraphOrigin origin, OrmQueryDetail detail, String sourceQuery) {
|
||||
Entry entry = new Entry(origin, detail, sourceQuery);
|
||||
|
||||
@@ -91,17 +91,13 @@ public class DefaultBackgroundExecutor implements SpiBackgroundExecutor {
|
||||
if (map == null) {
|
||||
return schedulePool.schedule(c, delay, unit);
|
||||
} else {
|
||||
return schedulePool.schedule(new Callable<V>() {
|
||||
@Override
|
||||
public V call() throws Exception {
|
||||
MDC.setContextMap(map);
|
||||
try {
|
||||
return c.call();
|
||||
} finally {
|
||||
MDC.clear();
|
||||
}
|
||||
return schedulePool.schedule(() -> {
|
||||
MDC.setContextMap(map);
|
||||
try {
|
||||
return c.call();
|
||||
} finally {
|
||||
MDC.clear();
|
||||
}
|
||||
|
||||
}, delay, unit);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -160,7 +160,7 @@ public final class DefaultServer implements SpiServer, SpiEbeanServer {
|
||||
/**
|
||||
* Clock to use for WhenModified and WhenCreated.
|
||||
*/
|
||||
private ClockService clockService;
|
||||
private final ClockService clockService;
|
||||
|
||||
private final CallStackFactory callStackFactory;
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ public abstract class PersistRequest extends BeanRequest implements BatchPostExe
|
||||
DELETE_PERMANENT(EVT_DELETE_PERMANENT),
|
||||
UPDATESQL(EVT_UPDATESQL),
|
||||
CALLABLESQL(EVT_CALLABLESQL);
|
||||
String profileEventId;
|
||||
final String profileEventId;
|
||||
|
||||
Type(String profileEventId) {
|
||||
this.profileEventId = profileEventId;
|
||||
|
||||
@@ -85,7 +85,7 @@ public final class PersistRequestBean<T> extends PersistRequest implements BeanP
|
||||
|
||||
private DocStoreMode docStoreMode;
|
||||
|
||||
private ConcurrencyMode concurrencyMode;
|
||||
private final ConcurrencyMode concurrencyMode;
|
||||
|
||||
/**
|
||||
* The unique id used for logging summary.
|
||||
|
||||
@@ -29,7 +29,7 @@ public final class PersistRequestUpdateSql extends PersistRequest {
|
||||
|
||||
private boolean addBatch;
|
||||
|
||||
private boolean forceNoBatch;
|
||||
private final boolean forceNoBatch;
|
||||
|
||||
private boolean batchThisRequest;
|
||||
|
||||
|
||||
@@ -79,7 +79,7 @@ public class BeanPropertyAssocMany<T> extends BeanPropertyAssoc<T> implements ST
|
||||
/**
|
||||
* Descriptor for the 'target' when the property maps to an element collection.
|
||||
*/
|
||||
BeanDescriptor<T> elementDescriptor;
|
||||
final BeanDescriptor<T> elementDescriptor;
|
||||
|
||||
/**
|
||||
* Order by used when fetch joining the associated many.
|
||||
|
||||
@@ -185,7 +185,7 @@ public class ChainedBeanPersistController implements BeanPersistController {
|
||||
|
||||
int i1 = o1.getExecutionOrder();
|
||||
int i2 = o2.getExecutionOrder();
|
||||
return (i1 < i2 ? -1 : (i1 == i2 ? 0 : 1));
|
||||
return Integer.compare(i1, i2);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -89,10 +89,7 @@ public class ChainedBeanQueryAdapter implements BeanQueryAdapter {
|
||||
|
||||
@Override
|
||||
public int compare(BeanQueryAdapter o1, BeanQueryAdapter o2) {
|
||||
|
||||
int i1 = o1.getExecutionOrder();
|
||||
int i2 = o2.getExecutionOrder();
|
||||
return (i1 < i2 ? -1 : (i1 == i2 ? 0 : 1));
|
||||
return Integer.compare(o1.getExecutionOrder(), o2.getExecutionOrder());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import io.ebeaninternal.api.SpiCacheRegion;
|
||||
|
||||
class DCacheRegionNone implements SpiCacheRegion {
|
||||
|
||||
static SpiCacheRegion INSTANCE = new DCacheRegionNone();
|
||||
static final SpiCacheRegion INSTANCE = new DCacheRegionNone();
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
|
||||
@@ -16,7 +16,7 @@ class DetermineAggPath {
|
||||
// a top level aggregation (so here we need to exclude Id property)
|
||||
return null;
|
||||
}
|
||||
return path.getManyPath(0, desc);
|
||||
return path.getManyPath(desc);
|
||||
}
|
||||
|
||||
static Path paths(String aggregation) {
|
||||
@@ -82,9 +82,9 @@ class DetermineAggPath {
|
||||
}
|
||||
}
|
||||
|
||||
String getManyPath(int pos, DeployBeanDescriptor<?> desc) {
|
||||
String getManyPath(DeployBeanDescriptor<?> desc) {
|
||||
int pos = 0;
|
||||
while (true) {
|
||||
|
||||
String path = paths[pos];
|
||||
DeployBeanProperty details = desc.getBeanProperty(path);
|
||||
if (details instanceof DeployBeanPropertyAssocMany<?>) {
|
||||
|
||||
@@ -11,7 +11,7 @@ class ElementEntityBean implements EntityBean {
|
||||
|
||||
private Object[] data;
|
||||
|
||||
private EntityBeanIntercept intercept;
|
||||
private final EntityBeanIntercept intercept;
|
||||
|
||||
ElementEntityBean(String[] properties) {
|
||||
this.properties = properties;
|
||||
|
||||
@@ -15,7 +15,7 @@ class ElementHelpList implements ElementHelp {
|
||||
|
||||
private static class Collector implements ElementCollector {
|
||||
|
||||
private List<Object> list = new ArrayList<>();
|
||||
private final List<Object> list = new ArrayList<>();
|
||||
|
||||
@Override
|
||||
public void addElement(Object element) {
|
||||
|
||||
@@ -15,7 +15,7 @@ class ElementHelpMap implements ElementHelp {
|
||||
|
||||
private static class Collector implements ElementCollector {
|
||||
|
||||
private Map<Object, Object> map = new LinkedHashMap<>();
|
||||
private final Map<Object, Object> map = new LinkedHashMap<>();
|
||||
|
||||
@Override
|
||||
public void addElement(Object element) {
|
||||
|
||||
@@ -15,7 +15,7 @@ class ElementHelpSet implements ElementHelp {
|
||||
|
||||
private static class Collector implements ElementCollector {
|
||||
|
||||
private Set<Object> set = new LinkedHashSet<>();
|
||||
private final Set<Object> set = new LinkedHashSet<>();
|
||||
|
||||
@Override
|
||||
public void addElement(Object element) {
|
||||
|
||||
@@ -100,7 +100,7 @@ public final class ImportedIdSimple implements ImportedId, Comparable<ImportedId
|
||||
|
||||
@Override
|
||||
public int compareTo(ImportedIdSimple other) {
|
||||
return (position < other.position ? -1 : (position == other.position ? 0 : 1));
|
||||
return Integer.compare(position, other.position);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+1
-1
@@ -8,7 +8,7 @@ import java.io.IOException;
|
||||
|
||||
class CaseInsensitiveEqualExpression extends AbstractValueExpression {
|
||||
|
||||
private boolean not;
|
||||
private final boolean not;
|
||||
|
||||
CaseInsensitiveEqualExpression(String propertyName, Object value, boolean not) {
|
||||
super(propertyName, value);
|
||||
|
||||
@@ -60,7 +60,7 @@ public class DefaultExpressionList<T> implements SpiExpressionList<T> {
|
||||
|
||||
private final ExpressionList<T> parentExprList;
|
||||
|
||||
protected ExpressionFactory expr;
|
||||
protected final ExpressionFactory expr;
|
||||
|
||||
String allDocNestedPath;
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import io.ebeaninternal.api.SpiExpression;
|
||||
import io.ebeaninternal.api.SpiExpressionRequest;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* Generally speaking tests the value at a given path in the JSON document.
|
||||
@@ -91,8 +92,8 @@ class JsonPathExpression extends AbstractExpression {
|
||||
@Override
|
||||
public boolean isSameByBind(SpiExpression other) {
|
||||
JsonPathExpression that = (JsonPathExpression) other;
|
||||
if (value != null ? !value.equals(that.value) : that.value != null) return false;
|
||||
return upperValue != null ? upperValue.equals(that.upperValue) : that.upperValue == null;
|
||||
if (!Objects.equals(value, that.value)) return false;
|
||||
return Objects.equals(upperValue, that.upperValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -5,7 +5,7 @@ import java.util.Map;
|
||||
|
||||
class OperatorMapping {
|
||||
|
||||
Map<String, EqlOperator> map = new HashMap<>();
|
||||
final Map<String, EqlOperator> map = new HashMap<>();
|
||||
|
||||
public OperatorMapping() {
|
||||
map.put("eq", EqlOperator.EQ);
|
||||
|
||||
@@ -19,13 +19,7 @@ public class BatchDepthComparator implements Comparator<BatchedBeanHolder>, Seri
|
||||
@Override
|
||||
public int compare(BatchedBeanHolder b1, BatchedBeanHolder b2) {
|
||||
|
||||
if (b1.getOrder() < b2.getOrder()) {
|
||||
return -1;
|
||||
}
|
||||
if (b1.getOrder() == b2.getOrder()) {
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
return Integer.compare(b1.getOrder(), b2.getOrder());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,9 +18,9 @@ public enum DeleteMode {
|
||||
*/
|
||||
HARD(PersistRequest.Type.DELETE_PERMANENT, true);
|
||||
|
||||
private boolean hard;
|
||||
private final boolean hard;
|
||||
|
||||
private PersistRequest.Type persistType;
|
||||
private final PersistRequest.Type persistType;
|
||||
|
||||
DeleteMode(PersistRequest.Type persistType, boolean hard) {
|
||||
this.persistType = persistType;
|
||||
|
||||
@@ -8,7 +8,7 @@ import java.util.Collection;
|
||||
*/
|
||||
public class MultiValueWrapper {
|
||||
private final Collection<?> values;
|
||||
private Class<?> type;
|
||||
private final Class<?> type;
|
||||
|
||||
public MultiValueWrapper(Collection<?> values, Class<?> type) {
|
||||
this.values = values;
|
||||
|
||||
@@ -36,7 +36,7 @@ public class SaveManyBeans extends SaveManyBase {
|
||||
private final DeleteMode deleteMode;
|
||||
|
||||
private Collection<?> collection;
|
||||
private DefaultPersister persister;
|
||||
private final DefaultPersister persister;
|
||||
private boolean deleteMissing;
|
||||
private int sortOrder;
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ import java.util.List;
|
||||
*/
|
||||
public class TimedProfileLocationRegistry {
|
||||
|
||||
private static final List<TimedProfileLocation> list = Collections.synchronizedList(new ArrayList<TimedProfileLocation>());
|
||||
private static final List<TimedProfileLocation> list = Collections.synchronizedList(new ArrayList<>());
|
||||
|
||||
/**
|
||||
* Register the timed profile location instance.
|
||||
|
||||
@@ -183,7 +183,7 @@ public class CQuery<T> implements DbReadContext, CancelableQuery, SpiProfileTran
|
||||
/**
|
||||
* Flag set when read auditing.
|
||||
*/
|
||||
private boolean audit;
|
||||
private final boolean audit;
|
||||
|
||||
/**
|
||||
* Flag set when findIterate is being read audited meaning we log in batches.
|
||||
|
||||
@@ -4,13 +4,13 @@ import io.ebean.annotation.Platform;
|
||||
|
||||
public final class PlatformQueryPlan {
|
||||
|
||||
private static QueryPlanLogger explainLogger = new QueryPlanLoggerExplain();
|
||||
private static final QueryPlanLogger explainLogger = new QueryPlanLoggerExplain();
|
||||
|
||||
private static QueryPlanLogger postgresLogger = new QueryPlanLoggerPostgres();
|
||||
private static final QueryPlanLogger postgresLogger = new QueryPlanLoggerPostgres();
|
||||
|
||||
private static QueryPlanLogger sqlServerLogger = new QueryPlanLoggerSqlServer();
|
||||
private static final QueryPlanLogger sqlServerLogger = new QueryPlanLoggerSqlServer();
|
||||
|
||||
private static QueryPlanLogger oracleLogger = new QueryPlanLoggerOracle();
|
||||
private static final QueryPlanLogger oracleLogger = new QueryPlanLoggerOracle();
|
||||
|
||||
/**
|
||||
* Returns the logger to log query plans for the given platform.
|
||||
|
||||
@@ -2,6 +2,8 @@ package io.ebeaninternal.server.query;
|
||||
|
||||
import io.ebeaninternal.api.CQueryPlanKey;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* QueryPlanKey for RawSql queries.
|
||||
*/
|
||||
@@ -49,7 +51,7 @@ class RawSqlQueryPlanKey implements CQueryPlanKey {
|
||||
if (rawSql != that.rawSql) return false;
|
||||
if (rowNumberIncluded != that.rowNumberIncluded) return false;
|
||||
if (!sql.equals(that.sql)) return false;
|
||||
return logWhereSql != null ? logWhereSql.equals(that.logWhereSql) : that.logWhereSql == null;
|
||||
return Objects.equals(logWhereSql, that.logWhereSql);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -3,6 +3,8 @@ package io.ebeaninternal.server.querydefn;
|
||||
import io.ebeaninternal.api.CQueryPlanKey;
|
||||
import io.ebeaninternal.server.rawsql.SpiRawSql;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* Query plan key for ORM queries.
|
||||
*/
|
||||
@@ -55,6 +57,6 @@ class OrmQueryPlanKey implements CQueryPlanKey {
|
||||
if (maxRows != that.maxRows) return false;
|
||||
if (firstRow != that.firstRow) return false;
|
||||
if (!description.equals(that.description)) return false;
|
||||
return rawSqlKey != null ? rawSqlKey.equals(that.rawSqlKey) : that.rawSqlKey == null;
|
||||
return Objects.equals(rawSqlKey, that.rawSqlKey);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ import java.util.List;
|
||||
*/
|
||||
class OrmQueryPropertiesParser {
|
||||
|
||||
private static Response EMPTY = new Response();
|
||||
private static final Response EMPTY = new Response();
|
||||
|
||||
/**
|
||||
* Immutable response of the parsed properties and options.
|
||||
|
||||
@@ -116,7 +116,7 @@ public class OrmUpdateProperties {
|
||||
/**
|
||||
* The set properties/expressions and their bind values.
|
||||
*/
|
||||
private LinkedHashMap<String, Value> values = new LinkedHashMap<>();
|
||||
private final LinkedHashMap<String, Value> values = new LinkedHashMap<>();
|
||||
|
||||
/**
|
||||
* Normal set property.
|
||||
|
||||
@@ -55,7 +55,7 @@ class DRawSqlParser {
|
||||
|
||||
private Sql parse() {
|
||||
|
||||
parseSqlFindKeywords(true);
|
||||
parseSqlFindKeywords();
|
||||
|
||||
whereExprPos = findWhereExprPosition();
|
||||
havingExprPos = findHavingExprPosition();
|
||||
@@ -165,7 +165,7 @@ class DRawSqlParser {
|
||||
}
|
||||
}
|
||||
|
||||
private void parseSqlFindKeywords(boolean allKeywords) {
|
||||
private void parseSqlFindKeywords() {
|
||||
|
||||
selectPos = textParser.findWordLower("select");
|
||||
if (selectPos == -1) {
|
||||
@@ -184,10 +184,6 @@ class DRawSqlParser {
|
||||
throw new RuntimeException(msg + sql);
|
||||
}
|
||||
|
||||
if (!allKeywords) {
|
||||
return;
|
||||
}
|
||||
|
||||
wherePos = textParser.findWordLower("where");
|
||||
if (wherePos == -1) {
|
||||
groupByPos = textParser.findWordLower("group", fromPos + 5);
|
||||
|
||||
@@ -11,6 +11,7 @@ import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* Internal service API for Raw Sql.
|
||||
@@ -432,8 +433,8 @@ public interface SpiRawSql extends RawSql {
|
||||
Column that = (Column) o;
|
||||
if (indexPos != that.indexPos) return false;
|
||||
if (!dbColumn.equals(that.dbColumn)) return false;
|
||||
if (dbAlias != null ? !dbAlias.equals(that.dbAlias) : that.dbAlias != null) return false;
|
||||
return propertyName != null ? propertyName.equals(that.propertyName) : that.propertyName == null;
|
||||
if (!Objects.equals(dbAlias, that.dbAlias)) return false;
|
||||
return Objects.equals(propertyName, that.propertyName);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -21,7 +21,7 @@ public class TableModState implements QueryCacheEntryValidate, ServerCacheNotify
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger("io.ebean.cache.TABLEMOD");
|
||||
|
||||
private Map<String, Long> tableModStamp = new ConcurrentHashMap<>();
|
||||
private final Map<String, Long> tableModStamp = new ConcurrentHashMap<>();
|
||||
|
||||
public TableModState() {
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user