IntelliJ Inspect various improvements

This commit is contained in:
Rob Bygrave committed 2022-08-27 22:02:32 +12:00
1 parent 2d733795c7
commit 81ef967d9f
44 files changed
+75 -109

No files matched your search

@@ -228,10 +228,9 @@ public final class BindParams implements Serializable {
/**
* Set a named In parameter that is multi-valued.
*/
public Param setArrayParameter(String name, Collection<?> value) {
public void setArrayParameter(String name, Collection<?> value) {
Param p = getParam(name);
p.setInValue(new MultiValueWrapper(value));
return p;
}
/**
@@ -93,7 +93,7 @@ public final class ScopeTrans {
/**
* Return the current/active transaction.
*/
protected SpiTransaction getTransaction() {
SpiTransaction getTransaction() {
return transaction;
}
@@ -124,7 +124,7 @@ public final class ScopeTrans {
}
}
protected void commitTransaction() {
void commitTransaction() {
if (created) {
transaction.commit();
} else {
@@ -175,7 +175,7 @@ public final class ScopeTrans {
return e;
}
protected void rollback(Throwable e) {
void rollback(Throwable e) {
if (transaction != null && transaction.isActive()) {
// transaction is null for NOT_SUPPORTED and sometimes SUPPORTS
// and Inactive (already rolled back) if nested REQUIRED
@@ -7,7 +7,7 @@ import javax.persistence.PersistenceException;
/**
* Manage scoped (typically thread local) transactions.
*
* <p>
* These can be nested and internally they are pushed and popped from a stack.
*/
public final class ScopedTransaction extends SpiTransactionProxy {
@@ -13,8 +13,8 @@ import java.io.IOException;
*/
public interface SpiExpression extends Expression {
static final String SQL_TRUE = "1=1";
static final String SQL_FALSE = "1=0";
String SQL_TRUE = "1=1";
String SQL_FALSE = "1=0";
/**
* Simplify nested expressions if possible.
@@ -139,7 +139,7 @@ public final class TransactionEvent implements Serializable {
/**
* Return the CacheChangeSet that we add cache notification messages to.
*
* <p>
* We want to add to this change set as we process requests allowing the
* PersistRequestBean to be garbage collected for large transactions.
*/
@@ -2,7 +2,7 @@ package io.ebeaninternal.api;
/**
* Event codes used in transaction profiling.
*
* <p>
* These appear in verbose transaction profile logs.
*/
public interface TxnProfileEventCodes {
@@ -100,11 +100,7 @@ final class DumpMetrics {
}
private void logCount(MetaCountMetric metric) {
StringBuilder sb = new StringBuilder();
sb.append(padNameTimed(metric.name())).append(" ");
sb.append(" count:").append(pad(metric.count()));
out(sb.toString());
out(padNameTimed(metric.name()) + " count:" + pad(metric.count()));
}
private void out(String sb) {
@@ -49,9 +49,9 @@ public final class PersistRequestUpdateSql extends PersistRequest {
/**
* Add this statement to JDBC batch for later execution.
*/
public int addBatch() {
public void addBatch() {
this.addBatch = true;
return executeStatement(true);
executeStatement(true);
}
/**
@@ -138,7 +138,7 @@ public interface SpiOrmQueryRequest<T> extends BeanQueryRequest<T>, DocQueryRequ
/**
* Maybe hit the bean cache returning true if everything was obtained from the
* cache (that there were no misses).
*
* <p>
* Do this for findList() on many natural keys or many Ids.
*/
boolean getFromBeanCache();
@@ -5,7 +5,7 @@ import java.sql.ResultSet;
/**
* Hold the JDBC PreparedStatement and ResultSet.
*
* <p>
* These both must be closed properly when done.
*/
public final class SpiResultSet {
@@ -55,7 +55,7 @@ class ManifestReader {
/**
* Read all the specific manifest files and return the set of packages containing type query beans.
*/
private Set<String> read(ClassLoader classLoader, String resourcePath) {
private void read(ClassLoader classLoader, String resourcePath) {
try {
Enumeration<URL> resources = classLoader.getResources(resourcePath);
while (resources.hasMoreElements()) {
@@ -66,7 +66,6 @@ class ManifestReader {
} catch (IOException e) {
log.log(WARNING, "Error reading " + resourcePath + " manifest resources", e);
}
return packageSet;
}
/**
@@ -3157,18 +3157,17 @@ public class BeanDescriptor<T> implements BeanType<T>, STreeType, SpiBeanType {
/**
* Return true if any mutable properties are dirty.
*/
public boolean checkAnyMutableProperties(EntityBeanIntercept ebi) {
public void checkAnyMutableProperties(EntityBeanIntercept ebi) {
for (BeanProperty beanProperty : propertiesMutable) {
int propertyIndex = beanProperty.propertyIndex();
if (ebi.isLoadedProperty(propertyIndex)) {
Object value = beanProperty.getValue(ebi.getOwner());
if (beanProperty.checkMutable(value, ebi.isDirtyProperty(propertyIndex), ebi)) {
ebi.markPropertyAsChanged(propertyIndex);
return true;
return;
}
}
}
return false;
}
public ConcurrencyMode concurrencyMode(EntityBeanIntercept ebi) {
@@ -706,9 +706,7 @@ final class BeanDescriptorCacheHelp<T> {
}
Set<EntityBeanIntercept> loaded = new HashSet<>();
Iterator<Map.Entry<Object, Object>> iterator = hits.entrySet().iterator();
while (iterator.hasNext()) {
Map.Entry<Object, Object> hit = iterator.next();
for (Map.Entry<Object, Object> hit : hits.entrySet()) {
Object key = hit.getKey();
EntityBeanIntercept ebi = ebis.remove(key);
CachedBeanData cacheData = (CachedBeanData) hit.getValue();
@@ -366,7 +366,7 @@ public abstract class BeanPropertyAssoc<T> extends BeanProperty implements STree
*/
public boolean isUpdateable() {
TableJoinColumn[] columns = tableJoin.columns();
if (columns.length <= 0) {
if (columns.length == 0) {
return true;
}
for (TableJoinColumn column : columns) {
@@ -383,7 +383,7 @@ public abstract class BeanPropertyAssoc<T> extends BeanProperty implements STree
*/
public boolean isInsertable() {
TableJoinColumn[] columns = tableJoin.columns();
if (columns.length <= 0) {
if (columns.length == 0) {
return true;
}
for (TableJoinColumn column : columns) {
@@ -5,7 +5,7 @@ import io.ebeaninternal.server.deploy.meta.DeployBeanProperty;
/**
* Bean property for synthetic sort order value / order column.
*
* <p>
* The value of which is held on the entity bean intercept.
*/
public final class BeanPropertyOrderColumn extends BeanProperty {
@@ -30,7 +30,7 @@ public final class DbMigrationInfo {
if (scripts.length == 0) {
return Collections.emptyList();
} else {
return Collections.unmodifiableList(Arrays.asList(scripts));
return List.of(scripts);
}
}
@@ -145,9 +145,7 @@ public final class IdBinderSimple implements IdBinder {
@Override
public void addIdInBindValues(SpiExpressionRequest request, Collection<?> values) {
List<Object> copy = new ArrayList<>(values);
for (int i = 0; i < copy.size(); i++) {
copy.set(i, convertSetId(copy.get(i), null));
}
copy.replaceAll(idValue -> convertSetId(idValue, null));
request.addBindValue(new MultiValueWrapper(copy));
}
@@ -12,10 +12,10 @@ public final class DeployIdentityMode {
}
private IdType type;
private IdentityGenerated generated;
private final IdentityGenerated generated;
private int start;
private int increment;
private int cache;
private final int cache;
private String sequenceName;
private boolean platformDefault;
@@ -137,7 +137,6 @@ public final class DeployTableJoin {
/**
* Returns the clause of an extra &#64;Where annotation.
* @return
*/
public String getExtraWhere() {
return extraWhere;
@@ -6,8 +6,8 @@ import java.util.List;
import java.util.Map;
/**
* Holds property and constructor meta data for a given DTO bean type.
*
* Holds property and constructor meta-data for a given DTO bean type.
* <p>
* Uses this to map a mapping request (columns) to a 'query plan' (constructor and setters).
*/
final class DtoMeta {
@@ -23,7 +23,7 @@ public final class CharMatch {
return false;
}
char ta[] = other.toCharArray();
char[] ta = other.toCharArray();
int pos = -1;
while (++pos < maxLength) {
@@ -42,7 +42,7 @@ public final class CharMatch {
return false;
}
char ta[] = other.toCharArray();
char[] ta = other.toCharArray();
int offset = ta.length - maxLength;
int pos = maxLength;
@@ -46,7 +46,7 @@ public final class ElFilter<T> implements Filter<T> {
return this;
}
protected boolean isMatch(T bean) {
boolean isMatch(T bean) {
for (ElMatcher<T> matcher : matches) {
if (!matcher.isMatch(bean)) {
return false;
@@ -342,7 +342,6 @@ abstract class EqlWhereListener<T> extends EQLBaseListener {
case ':':
return EqlValueType.NAMED_PARAM;
case 't':
return EqlValueType.BOOL;
case 'f':
return EqlValueType.BOOL;
case '\'':
@@ -225,7 +225,7 @@ public class UuidV1IdGenerator extends UuidV1RndIdGenerator {
stateFile, propNodeId, getNodeIdentifier());
return false;
}
Integer seq = Integer.valueOf(prop.getProperty("clockSeq")) & 0x3FFF;
Integer seq = Integer.parseInt(prop.getProperty("clockSeq")) & 0x3FFF;
Long ts = Long.valueOf(prop.getProperty("timeStamp"));
clockSeq.set(seq);
timeStamp.set(ts);
@@ -14,15 +14,15 @@ import static java.lang.System.Logger.Level.INFO;
/**
* IdGenerator for (pseudo) type 1 UUIDs.
*
* <p>
* This implementation generates a type 1 UUID according to
* https://tools.ietf.org/html/rfc4122.html#section-4.2
* but has no persistence storage. It generates a new random 47 bit node ID with every
* UUID.
*
* <p>
* Use this, if you want randomness in your UUIDs but want to take advantage of index
* optimizations of the database. It may be good with AUTO_BINARY_OPTIMIZED and MySql.
*
* <p>
* See: https://www.percona.com/blog/2014/12/19/store-uuid-optimized-way/
*/
public class UuidV1RndIdGenerator implements PlatformIdGenerator {
@@ -41,16 +41,16 @@ public class UuidV1RndIdGenerator implements PlatformIdGenerator {
private final SecureRandom numberGenerator = new SecureRandom();
protected AtomicLong timeStamp = new AtomicLong(currentUuidTime());
protected final AtomicLong timeStamp = new AtomicLong(currentUuidTime());
private AtomicLong nanoToMilliOffset = new AtomicLong(currentUuidTime());
private final AtomicLong nanoToMilliOffset = new AtomicLong(currentUuidTime());
private final ReentrantLock lock = new ReentrantLock();
/**
* Returns the uuid epoch.
*
* <p>
* This is the number of 100ns intervals since 1582-10-15 00:00:00
*/
private static long currentUuidTime() {
@@ -7,7 +7,7 @@ import java.util.UUID;
/**
* IdGenerator for java util UUID.
*
* <p>
* This generator generates a 60bit random UUID according to
* https://tools.ietf.org/html/rfc4122.html#section-4.4
* Use this generator if you want truly random UUIDs
@@ -163,11 +163,10 @@ public final class Binder {
/**
* Bind an Object with unknown data type.
*/
public Object bindObject(DataBind dataBind, Object value) throws SQLException {
public void bindObject(DataBind dataBind, Object value) throws SQLException {
if (value == null) {
// null of unknown type
bindObject(dataBind, null, Types.OTHER);
return null;
} else if (value instanceof MultiValueWrapper) {
MultiValueWrapper wrapper = (MultiValueWrapper) value;
@@ -177,7 +176,6 @@ public final class Binder {
int dbType = type.jdbcType();
// let the multiValueBind decide what to do with the value
multiValueBind.bindMultiValues(dataBind, values, type, one -> bindObject(dataBind, one, dbType));
return values;
} else {
ScalarType<?> type = getScalarType(value.getClass());
@@ -186,7 +184,6 @@ public final class Binder {
value = type.toJdbcType(value);
}
bindObject(dataBind, value, type.jdbcType());
return value;
}
}
@@ -60,9 +60,7 @@ public class MultiValueBind {
sb.append(" not");
}
sb.append(" in (?");
for (int i = 1; i < size; i++) {
sb.append(",?");
}
sb.append(",?".repeat(Math.max(0, size - 1)));
sb.append(")");
return sb.toString();
}
@@ -36,6 +36,8 @@ import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import static java.util.Objects.requireNonNullElse;
/**
* Generates the SQL SELECT statements taking into account the physical
* deployment properties.
@@ -411,11 +413,7 @@ final class CQueryBuilder {
String tableName = lower(metaData.getTableName(i));
String columnName = lower(metaData.getColumnName(i));
String path = desc.findBeanPath(schemaName, tableName, columnName);
if (path != null) {
propertyNames.add(path);
} else {
propertyNames.add(SpiRawSql.IGNORE_COLUMN);
}
propertyNames.add(requireNonNullElse(path, SpiRawSql.IGNORE_COLUMN));
}
RawSql rawSql = RawSqlBuilder.resultSet(resultSet, propertyNames.toArray(new String[0]));
query.setRawSql(rawSql);
@@ -334,7 +334,7 @@ public final class CQueryPredicates {
// orderById is already in the order by clause
return orderBy;
}
if (idPos <= -1 || idPos >= manyPos) {
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()
@@ -83,5 +83,5 @@ interface SqlTreeNode {
* Unselect lobs (for distinct queries on DB2 and Oracle).
*/
default void unselectLobs() {
};
}
}
@@ -411,7 +411,7 @@ public class DefaultOrmQuery<T> extends AbstractQuery implements SpiQuery<T> {
return expressionFactory;
}
private final void createExtraJoinsToSupportManyWhereClause() {
private void createExtraJoinsToSupportManyWhereClause() {
manyWhereJoins = new ManyWhereJoins();
if (whereExpressions != null) {
whereExpressions.containsMany(beanDescriptor, manyWhereJoins);
@@ -1499,12 +1499,12 @@ public class DefaultOrmQuery<T> extends AbstractQuery implements SpiQuery<T> {
@Override
@SuppressWarnings("unchecked")
public final <A> List<A> findSingleAttributeList() {
return (List<A>) server.findSingleAttributeList(this, transaction);
return server.findSingleAttributeList(this, transaction);
}
@Override
public final <A> Set<A> findSingleAttributeSet() {
return (Set<A>) server.findSingleAttributeSet(this, transaction);
return server.findSingleAttributeSet(this, transaction);
}
@Override
@@ -232,7 +232,7 @@ public final class OrmQueryDetail implements Serializable {
/**
* Add or replace the fetch detail.
*/
protected void fetch(OrmQueryProperties chunk) {
void fetch(OrmQueryProperties chunk) {
String path = chunk.getPath();
if (path == null) {
baseProps = chunk;
@@ -144,12 +144,9 @@ public final class SimpleTextParser {
private boolean isOperator(char c) {
switch (c) {
case '<':
return true;
case '>':
return true;
case '=':
return true;
case '!':
case '=':
case '>':
return true;
default:
@@ -64,7 +64,7 @@ public interface SpiRawSql extends RawSql {
/**
* Construct for unparsed SQL.
*/
protected Sql(String unparsedSql) {
Sql(String unparsedSql) {
this.parsed = false;
this.unparsedSql = unparsedSql;
this.preFrom = null;
@@ -80,7 +80,7 @@ public interface SpiRawSql extends RawSql {
/**
* Construct for parsed SQL.
*/
protected Sql(String unparsedSql, String preFrom, String preWhere, boolean andWhereExpr,
Sql(String unparsedSql, String preFrom, String preWhere, boolean andWhereExpr,
String preHaving, boolean andHavingExpr, String orderByPrefix, String orderBy, boolean distinct) {
this.unparsedSql = unparsedSql;
@@ -199,7 +199,7 @@ public interface SpiRawSql extends RawSql {
/**
* Construct from parsed sql where the columns have been identified.
*/
protected ColumnMapping(List<Column> columns) {
ColumnMapping(List<Column> columns) {
this.immutable = false;
this.parsed = true;
this.propertyMap = null;
@@ -213,7 +213,7 @@ public interface SpiRawSql extends RawSql {
/**
* Construct for unparsed sql.
*/
protected ColumnMapping() {
ColumnMapping() {
this.immutable = false;
this.parsed = false;
this.propertyMap = null;
@@ -224,7 +224,7 @@ public interface SpiRawSql extends RawSql {
/**
* Construct for ResultSet use.
*/
protected ColumnMapping(String... propertyNames) {
ColumnMapping(String... propertyNames) {
this.immutable = false;
this.parsed = false;
this.propertyMap = null;
@@ -240,7 +240,7 @@ public interface SpiRawSql extends RawSql {
/**
* Construct an immutable ColumnMapping based on collected information.
*/
protected ColumnMapping(boolean parsed, LinkedHashMap<String, Column> dbColumnMap) {
ColumnMapping(boolean parsed, LinkedHashMap<String, Column> dbColumnMap) {
this.immutable = true;
this.parsed = parsed;
this.dbColumnMap = dbColumnMap;
@@ -281,17 +281,14 @@ public interface SpiRawSql extends RawSql {
*
* @throws IllegalStateException when a propertyName has not been defined for a column.
*/
protected ColumnMapping createImmutableCopy() {
ColumnMapping createImmutableCopy() {
for (Column c : dbColumnMap.values()) {
c.checkMapping();
}
return new ColumnMapping(parsed, dbColumnMap);
}
protected void columnMapping(String dbColumn, String propertyName) {
void columnMapping(String dbColumn, String propertyName) {
if (immutable) {
throw new IllegalStateException("Should never happen");
}
@@ -330,7 +327,7 @@ public interface SpiRawSql extends RawSql {
/**
* Return the column mapping.
*/
protected Map<String, Column> mapping() {
Map<String, Column> mapping() {
return dbColumnMap;
}
@@ -25,8 +25,8 @@ public class DefaultReadAuditLogger implements ReadAuditLogger {
private static final System.Logger auditLogger = AppLog.getLogger("io.ebean.ReadAudit");
protected final JsonFactory jsonFactory = new JsonFactory();
protected int defaultQueryBuffer = 500;
protected int defaultReadBuffer = 150;
protected final int defaultQueryBuffer = 500;
protected final int defaultReadBuffer = 150;
/**
* Write the query plan details in JSON format to the logger.
@@ -408,7 +408,7 @@ class JdbcTransaction implements SpiTransaction, TxnProfileEventCodes {
@Override
public final void depthDecrement() {
if (depth != 0) {
depth += -1;
depth -= 1;
}
}
@@ -63,7 +63,7 @@ class ScalarTypeBigDecimal extends ScalarTypeBase<BigDecimal> {
if (!dataInput.readBoolean()) {
return null;
} else {
return new BigDecimal(dataInput.readDouble());
return BigDecimal.valueOf(dataInput.readDouble());
}
}
@@ -3,7 +3,6 @@ package io.ebeaninternal.server.type;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonParser;
import io.ebean.core.type.*;
import io.ebean.core.type.BasicTypeConverter;
import java.io.DataInput;
import java.io.DataOutput;
@@ -146,12 +146,10 @@ final class ScalarTypeFile extends ScalarTypeBase<File> {
/**
* Helper method to pump bytes from input to output.
*/
public long pump(InputStream is, OutputStream out) throws IOException {
public void pump(InputStream is, OutputStream out) throws IOException {
long totalBytes = 0;
InputStream input = null;
OutputStream output = null;
try {
input = new BufferedInputStream(is, bufferSize);
output = new BufferedOutputStream(out, bufferSize);
@@ -162,11 +160,7 @@ final class ScalarTypeFile extends ScalarTypeBase<File> {
output.write(buffer, 0, length);
totalBytes += length;
}
output.flush();
return totalBytes;
} finally {
if (output != null) {
try {
@@ -12,7 +12,7 @@ import java.util.Map;
/**
* This class is a modified version of TypeResolver from https://github.com/jhalterman/typetools
* which is Apache 2 license.
*
* <p>
* It is a cut down version removing the lambda support and related sun.misc.Unsafe use etc.
*/
final class TypeResolver {
@@ -172,8 +172,7 @@ public final class BindParamsParser {
private void addCollectionParams(OrderedList orderedList, Param param, Collection<?> inValue) {
// Chop up Collection parameter into a number of individual parameters
Collection<?> collection = inValue;
for (int c = 0; c < collection.size(); c++) {
for (int c = 0; c < inValue.size(); c++) {
if (c > 0) {
orderedList.appendSql(",");
}
@@ -8,7 +8,7 @@ import io.ebeaninternal.server.json.PathStack;
*/
public abstract class DocPropertyAdapter implements DocPropertyVisitor {
protected PathStack pathStack = new PathStack();
protected final PathStack pathStack = new PathStack();
@Override
public void visitProperty(DocPropertyMapping property) {
@@ -8,13 +8,13 @@ import io.ebean.docstore.DocMapping;
*/
public final class DocumentMapping implements DocMapping {
protected final String queueId;
protected final String name;
protected final String type;
protected final FetchPath paths;
protected final DocPropertyMapping properties;
protected int shards;
protected int replicas;
private final String queueId;
private final String name;
private final String type;
private final FetchPath paths;
private final DocPropertyMapping properties;
private int shards;
private int replicas;
public DocumentMapping(String queueId, String name, String type, FetchPath paths, DocPropertyMapping properties, int shards, int replicas) {
this.queueId = queueId;