mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
Simple fixes (#976)
* Should be only the really simple stuff. * Final cleanups.
This commit is contained in:
committed by
Rob Bygrave
parent
8bb884374b
commit
6120a465e1
@@ -859,7 +859,7 @@ public final class EntityBeanIntercept implements Serializable {
|
||||
loadedProps[propertyIndex] = true;
|
||||
}
|
||||
|
||||
private final void preGetterCallback() {
|
||||
private void preGetterCallback() {
|
||||
if (preGetterCallback != null) {
|
||||
preGetterCallback.preGetterTrigger();
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ package io.ebean.config.dbplatform;
|
||||
|
||||
import io.ebean.config.ServerConfig;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.EnumMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
@@ -25,7 +25,7 @@ public class DbPlatformTypeMapping {
|
||||
private static final DbPlatformType MULTILINESTRING = new DbPlatformType("multilinestring");
|
||||
private static final DbPlatformType MULTIPOLYGON = new DbPlatformType("multipolygon");
|
||||
|
||||
private final Map<DbType, DbPlatformType> typeMap = new HashMap<>();
|
||||
private final Map<DbType, DbPlatformType> typeMap = new EnumMap<>(DbType.class);
|
||||
|
||||
/**
|
||||
* Return the DbTypeMap with standard (not platform specific) types.
|
||||
|
||||
@@ -38,7 +38,7 @@ public class RowNumberSqlLimiter implements SqlLimiter {
|
||||
|
||||
int lastRow = request.getMaxRows();
|
||||
if (lastRow > 0) {
|
||||
lastRow = lastRow + firstRow;
|
||||
lastRow += firstRow;
|
||||
}
|
||||
|
||||
sb.append("select * from ( ");
|
||||
|
||||
@@ -43,7 +43,7 @@ public class RownumSqlLimiter implements SqlLimiter {
|
||||
|
||||
int lastRow = request.getMaxRows();
|
||||
if (lastRow > 0) {
|
||||
lastRow = lastRow + firstRow;
|
||||
lastRow += firstRow;
|
||||
}
|
||||
|
||||
sb.append("select * from ( ");
|
||||
|
||||
@@ -100,14 +100,11 @@ public class H2HistoryTrigger implements Trigger {
|
||||
*/
|
||||
private void insertIntoHistory(Connection connection, Object[] oldRow) throws SQLException {
|
||||
|
||||
PreparedStatement stmt = connection.prepareStatement(insertHistorySql);
|
||||
try {
|
||||
try (PreparedStatement stmt = connection.prepareStatement(insertHistorySql)) {
|
||||
for (int i = 0; i < oldRow.length; i++) {
|
||||
stmt.setObject(i + 1, oldRow[i]);
|
||||
}
|
||||
stmt.executeUpdate();
|
||||
} finally {
|
||||
stmt.close();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ public class SqlServer2005SqlLimiter implements SqlLimiter {
|
||||
|
||||
int lastRow = request.getMaxRows();
|
||||
if (lastRow > 0) {
|
||||
lastRow = lastRow + firstRow;
|
||||
lastRow += firstRow;
|
||||
}
|
||||
|
||||
if (firstRow < 1) {
|
||||
|
||||
@@ -233,13 +233,9 @@ public class DdlGenerator {
|
||||
protected void writeFile(String fileName, String fileContent) throws IOException {
|
||||
|
||||
File f = new File(fileName);
|
||||
|
||||
FileWriter fw = new FileWriter(f);
|
||||
try {
|
||||
try (FileWriter fw = new FileWriter(f)) {
|
||||
fw.write(fileContent);
|
||||
fw.flush();
|
||||
} finally {
|
||||
fw.close();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -256,17 +252,13 @@ public class DdlGenerator {
|
||||
protected String readContent(Reader reader) throws IOException {
|
||||
|
||||
StringBuilder buf = new StringBuilder();
|
||||
|
||||
LineNumberReader lineReader = new LineNumberReader(reader);
|
||||
try {
|
||||
try (LineNumberReader lineReader = new LineNumberReader(reader)) {
|
||||
String s;
|
||||
while ((s = lineReader.readLine()) != null) {
|
||||
buf.append(s).append("\n");
|
||||
}
|
||||
return buf.toString();
|
||||
|
||||
} finally {
|
||||
lineReader.close();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -38,11 +38,8 @@ public class MigrationXmlReader {
|
||||
public static Migration read(File migrationFile) {
|
||||
|
||||
try {
|
||||
FileInputStream is = new FileInputStream(migrationFile);
|
||||
try {
|
||||
try (FileInputStream is = new FileInputStream(migrationFile)) {
|
||||
return read(is);
|
||||
} finally {
|
||||
is.close();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
|
||||
@@ -117,8 +117,8 @@ public class MIndex {
|
||||
|
||||
|
||||
private List<String> split(String columns) {
|
||||
List<String> colList = new ArrayList<>();
|
||||
String[] cols = columns.split(",");
|
||||
List<String> colList = new ArrayList<>(cols.length);
|
||||
Collections.addAll(colList, cols);
|
||||
return colList;
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ public class MigrationModel {
|
||||
// find all the migration xml files
|
||||
File[] xmlFiles = modelDirectory.listFiles(pathname -> pathname.getName().toLowerCase().endsWith(modelSuffix));
|
||||
|
||||
List<MigrationResource> resources = new ArrayList<>();
|
||||
List<MigrationResource> resources = new ArrayList<>(xmlFiles.length);
|
||||
|
||||
for (File xmlFile : xmlFiles) {
|
||||
resources.add(new MigrationResource(xmlFile, createVersion(xmlFile)));
|
||||
|
||||
@@ -71,12 +71,9 @@ public class PlatformDdlWriter {
|
||||
protected void writePlatformDdl(DdlWrite write, File resourcePath, String fullVersion) throws IOException {
|
||||
|
||||
if (!write.isApplyEmpty()) {
|
||||
FileWriter applyWriter = createWriter(resourcePath, fullVersion, config.getApplySuffix());
|
||||
try {
|
||||
try (FileWriter applyWriter = createWriter(resourcePath, fullVersion, config.getApplySuffix())) {
|
||||
writeApplyDdl(applyWriter, write);
|
||||
applyWriter.flush();
|
||||
} finally {
|
||||
applyWriter.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ public class StringHelper {
|
||||
private static HashMap<String, String> parseNameQuotedValue(HashMap<String, String> map,
|
||||
String tag, int pos) throws RuntimeException {
|
||||
|
||||
int equalsPos = tag.indexOf("=", pos);
|
||||
int equalsPos = tag.indexOf('=', pos);
|
||||
if (equalsPos > -1) {
|
||||
// check for begin quote...
|
||||
char firstQuote = tag.charAt(equalsPos + 1);
|
||||
@@ -68,7 +68,6 @@ public class StringHelper {
|
||||
// dp("pos="+pos+" equalsPos="+equalsPos+"
|
||||
// endQuotePos="+endQuotePos);
|
||||
String name = tag.substring(pos, equalsPos);
|
||||
String value = tag.substring(equalsPos + 2, endQuotePos);
|
||||
// dp("name="+name+"; value="+value+";");
|
||||
|
||||
// trim off any whitespace from the front of name...
|
||||
@@ -76,6 +75,8 @@ public class StringHelper {
|
||||
if ((name.indexOf(SINGLE_QUOTE) > -1) || (name.indexOf(DOUBLE_QUOTE) > -1)) {
|
||||
throw new RuntimeException("attribute name contains a quote [" + name + "]");
|
||||
}
|
||||
|
||||
String value = tag.substring(equalsPos + 2, endQuotePos);
|
||||
map.put(name, value);
|
||||
|
||||
return parseNameQuotedValue(map, tag, endQuotePos + 1);
|
||||
@@ -97,7 +98,7 @@ public class StringHelper {
|
||||
private static int countOccurances(String content, String occurs, int pos, int countSoFar) {
|
||||
int equalsPos = content.indexOf(occurs, pos);
|
||||
if (equalsPos > -1) {
|
||||
countSoFar = countSoFar + 1;
|
||||
countSoFar += 1;
|
||||
pos = equalsPos + occurs.length();
|
||||
// dp("countSoFar="+countSoFar+" pos="+pos);
|
||||
return countOccurances(content, occurs, pos, countSoFar);
|
||||
@@ -279,7 +280,7 @@ public class StringHelper {
|
||||
}
|
||||
int startPos = str.indexOf(leftBound);
|
||||
if (startPos > -1) {
|
||||
startPos = startPos + leftBound.length();
|
||||
startPos += leftBound.length();
|
||||
int endPos = str.indexOf(rightBound, startPos);
|
||||
// dp(str+" start:"+startPos+" end:"+endPos);
|
||||
if (endPos == -1) {
|
||||
|
||||
@@ -31,11 +31,8 @@ public class AutoTuneXmlReader {
|
||||
if (!file.exists()) {
|
||||
return new Autotune();
|
||||
}
|
||||
FileInputStream is = new FileInputStream(file);
|
||||
try {
|
||||
try (FileInputStream is = new FileInputStream(file)) {
|
||||
return read(is);
|
||||
} finally {
|
||||
is.close();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -276,7 +276,7 @@ public class DefaultServerCache implements ServerCache {
|
||||
long trimmedByTTL = 0;
|
||||
long trimmedByLRU = 0;
|
||||
|
||||
ArrayList<CacheEntry> activeList = new ArrayList<>();
|
||||
ArrayList<CacheEntry> activeList = new ArrayList<>(map.size());
|
||||
|
||||
long idleExpire = System.currentTimeMillis() - (maxIdleSecs * 1000);
|
||||
long ttlExpire = System.currentTimeMillis() - (maxSecsToLive * 1000);
|
||||
|
||||
@@ -270,10 +270,8 @@ public class DefaultContainer implements SpiContainer {
|
||||
return null;
|
||||
}
|
||||
|
||||
DataSource ds;
|
||||
|
||||
if (config.getDataSourceJndiName() != null) {
|
||||
ds = jndiDataSourceFactory.lookup(config.getDataSourceJndiName());
|
||||
DataSource ds = jndiDataSourceFactory.lookup(config.getDataSourceJndiName());
|
||||
if (ds == null) {
|
||||
throw new PersistenceException("JNDI lookup for DataSource " + config.getDataSourceJndiName() + " returned null.");
|
||||
} else {
|
||||
|
||||
@@ -309,13 +309,10 @@ public final class OrmQueryRequest<T> extends BeanRequest implements BeanQueryRe
|
||||
}
|
||||
|
||||
public void findEach(Consumer<T> consumer) {
|
||||
QueryIterator<T> it = queryEngine.findIterate(this);
|
||||
try {
|
||||
try (QueryIterator<T> it = queryEngine.findIterate(this)) {
|
||||
while (it.hasNext()) {
|
||||
consumer.accept(it.next());
|
||||
}
|
||||
} finally {
|
||||
it.close();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -736,7 +736,7 @@ public final class PersistRequestBean<T> extends PersistRequest implements BeanP
|
||||
@Override
|
||||
public final void checkRowCount(int rowCount) {
|
||||
if (ConcurrencyMode.VERSION == concurrencyMode && rowCount != 1) {
|
||||
String m = Message.msg("persist.conc2", "" + rowCount);
|
||||
String m = Message.msg("persist.conc2", String.valueOf(rowCount));
|
||||
throw new OptimisticLockException(m, null, bean);
|
||||
}
|
||||
switch (type) {
|
||||
|
||||
@@ -138,10 +138,10 @@ public final class RelationalQueryRequest {
|
||||
*/
|
||||
private String[] getPropertyNames() throws SQLException {
|
||||
|
||||
ArrayList<String> propNames = new ArrayList<>();
|
||||
ResultSetMetaData metaData = resultSet.getMetaData();
|
||||
|
||||
int columnsPlusOne = metaData.getColumnCount() + 1;
|
||||
ArrayList<String> propNames = new ArrayList<>(columnsPlusOne - 1);
|
||||
for (int i = 1; i < columnsPlusOne; i++) {
|
||||
propNames.add(metaData.getColumnLabel(i));
|
||||
}
|
||||
|
||||
@@ -817,9 +817,8 @@ public class BeanDescriptor<T> implements MetaBeanInfo, BeanType<T> {
|
||||
/**
|
||||
* Return the bean change for a delete.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
private BeanChange deleteBeanChange(PersistRequestBean<T> request) {
|
||||
return newBeanChange(request.getBeanId(), ChangeType.DELETE, Collections.EMPTY_MAP);
|
||||
return newBeanChange(request.getBeanId(), ChangeType.DELETE, Collections.<String, ValuePair>emptyMap());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2153,7 +2152,7 @@ public class BeanDescriptor<T> implements MetaBeanInfo, BeanType<T> {
|
||||
|
||||
if (propertyDeploy && chain != null) {
|
||||
ElPropertyDeploy fk = elDeployCache.get(propName);
|
||||
if (fk != null && fk instanceof BeanFkeyProperty) {
|
||||
if (fk instanceof BeanFkeyProperty) {
|
||||
// propertyDeploy chain for foreign key column
|
||||
return ((BeanFkeyProperty) fk).create(chain.getExpression(), chain.isContainsMany());
|
||||
}
|
||||
|
||||
@@ -296,11 +296,12 @@ final class BeanDescriptorCacheHelp<T> {
|
||||
|
||||
BeanDescriptor<?> targetDescriptor = many.getTargetDescriptor();
|
||||
|
||||
List<Object> idList = new ArrayList<>();
|
||||
Collection<?> actualDetails = BeanCollectionUtil.getActualEntries(details);
|
||||
if (actualDetails == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
List<Object> idList = new ArrayList<>(actualDetails.size());
|
||||
for (Object bean : actualDetails) {
|
||||
idList.add(targetDescriptor.getId((EntityBean) bean));
|
||||
}
|
||||
|
||||
@@ -567,7 +567,7 @@ public class BeanDescriptorManager implements BeanDescriptorMap {
|
||||
|
||||
private void checkForValidEmbeddedId(BeanDescriptor<?> d) {
|
||||
IdBinder idBinder = d.getIdBinder();
|
||||
if (idBinder != null && idBinder instanceof IdBinderEmbedded) {
|
||||
if (idBinder instanceof IdBinderEmbedded) {
|
||||
IdBinderEmbedded embId = (IdBinderEmbedded) idBinder;
|
||||
BeanDescriptor<?> idBeanDescriptor = embId.getIdBeanDescriptor();
|
||||
Class<?> idType = idBeanDescriptor.getBeanType();
|
||||
@@ -886,7 +886,7 @@ public class BeanDescriptorManager implements BeanDescriptorMap {
|
||||
|
||||
// get the target type short name
|
||||
String targetType = prop.getTargetType().getName();
|
||||
String shortTypeName = targetType.substring(targetType.lastIndexOf(".") + 1);
|
||||
String shortTypeName = targetType.substring(targetType.lastIndexOf('.') + 1);
|
||||
|
||||
// name includes (probably ends with) the target type short name?
|
||||
int p = name.indexOf(shortTypeName);
|
||||
|
||||
@@ -360,7 +360,7 @@ public abstract class BeanPropertyAssoc<T> extends BeanProperty {
|
||||
|
||||
private ImportedIdSimple[] createImportedList(BeanPropertyAssoc<?> owner, TableJoinColumn[] cols, BeanProperty[] props, BeanProperty[] others) {
|
||||
|
||||
ArrayList<ImportedIdSimple> list = new ArrayList<>();
|
||||
ArrayList<ImportedIdSimple> list = new ArrayList<>(cols.length);
|
||||
|
||||
for (TableJoinColumn col : cols) {
|
||||
list.add(createImportedScalar(owner, col, props, others));
|
||||
|
||||
@@ -29,8 +29,7 @@ public class ChainedBeanPostConstructListener implements BeanPostConstructListen
|
||||
if (list.contains(c)) {
|
||||
return this;
|
||||
} else {
|
||||
List<BeanPostConstructListener> newList = new ArrayList<>();
|
||||
newList.addAll(list);
|
||||
List<BeanPostConstructListener> newList = new ArrayList<>(list);
|
||||
newList.add(c);
|
||||
|
||||
return new ChainedBeanPostConstructListener(newList);
|
||||
@@ -44,8 +43,7 @@ public class ChainedBeanPostConstructListener implements BeanPostConstructListen
|
||||
if (!list.contains(c)) {
|
||||
return this;
|
||||
} else {
|
||||
ArrayList<BeanPostConstructListener> newList = new ArrayList<>();
|
||||
newList.addAll(list);
|
||||
ArrayList<BeanPostConstructListener> newList = new ArrayList<>(list);
|
||||
newList.remove(c);
|
||||
|
||||
return new ChainedBeanPostConstructListener(newList);
|
||||
|
||||
@@ -53,7 +53,7 @@ public class DeployDocPropertyOptions {
|
||||
}
|
||||
|
||||
private void setNullValue(String value) {
|
||||
if (!value.equals("")) {
|
||||
if (!value.isEmpty()) {
|
||||
mapping.setNullValue(value);
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -17,7 +17,7 @@ public class GeneratedCounterLong implements GeneratedProperty {
|
||||
*/
|
||||
@Override
|
||||
public Object getInsertValue(BeanProperty prop, EntityBean bean, long now) {
|
||||
return (long) 1;
|
||||
return 1L;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -633,9 +633,7 @@ public class DeployBeanDescriptor<T> {
|
||||
|
||||
public void sortProperties() {
|
||||
|
||||
ArrayList<DeployBeanProperty> list = new ArrayList<>();
|
||||
list.addAll(propMap.values());
|
||||
|
||||
ArrayList<DeployBeanProperty> list = new ArrayList<>(propMap.values());
|
||||
Collections.sort(list, PROP_ORDER);
|
||||
|
||||
propMap = new LinkedHashMap<>(list.size());
|
||||
|
||||
@@ -585,7 +585,7 @@ public class DeployBeanProperty {
|
||||
*/
|
||||
public void setSqlFormula(String formulaSelect, String formulaJoin) {
|
||||
this.sqlFormulaSelect = formulaSelect;
|
||||
this.sqlFormulaJoin = formulaJoin.equals("") ? null : formulaJoin;
|
||||
this.sqlFormulaJoin = formulaJoin.isEmpty() ? null : formulaJoin;
|
||||
this.dbRead = true;
|
||||
this.dbInsertable = false;
|
||||
this.dbUpdateable = false;
|
||||
|
||||
@@ -56,7 +56,7 @@ public abstract class AnnotationBase {
|
||||
* <p>
|
||||
* If a <code>repeatable</code> annotation class is specified and the annotation is platform
|
||||
* specific(see {@link #getPlatformMatchingAnnotation(Set, Platform)}), then the platform specific
|
||||
* annotation is returned. Otherwise the first annotation is retured. Note that you must no longer
|
||||
* annotation is returned. Otherwise the first annotation is returned. Note that you must no longer
|
||||
* handle "java 1.6 repeatable containers" like {@link JoinColumn} / {@link JoinColumns} yourself.
|
||||
* </p>
|
||||
* <p>
|
||||
@@ -256,7 +256,7 @@ public abstract class AnnotationBase {
|
||||
}
|
||||
|
||||
// caches for getRepeatableValueMethod
|
||||
private static final Method getNullMethod() {
|
||||
private static Method getNullMethod() {
|
||||
try {
|
||||
return AnnotationBase.class.getDeclaredMethod("getNullMethod");
|
||||
} catch (NoSuchMethodException e) {
|
||||
|
||||
@@ -119,7 +119,7 @@ public class AnnotationClass extends AnnotationParser {
|
||||
Entity entity = AnnotationBase.findAnnotation(cls,Entity.class);
|
||||
if (entity != null) {
|
||||
descriptor.setEntityType(EntityType.ORM);
|
||||
if (entity.name().equals("")) {
|
||||
if (entity.name().isEmpty()) {
|
||||
descriptor.setName(cls.getSimpleName());
|
||||
} else {
|
||||
descriptor.setName(entity.name());
|
||||
|
||||
@@ -46,7 +46,24 @@ import io.ebean.annotation.WhenModified;
|
||||
import io.ebean.annotation.WhoCreated;
|
||||
import io.ebean.annotation.WhoModified;
|
||||
|
||||
import javax.persistence.*;
|
||||
import javax.persistence.Basic;
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.EmbeddedId;
|
||||
import javax.persistence.Enumerated;
|
||||
import javax.persistence.FetchType;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Lob;
|
||||
import javax.persistence.ManyToOne;
|
||||
import javax.persistence.OneToMany;
|
||||
import javax.persistence.OneToOne;
|
||||
import javax.persistence.PersistenceException;
|
||||
import javax.persistence.SequenceGenerator;
|
||||
import javax.persistence.Temporal;
|
||||
import javax.persistence.TemporalType;
|
||||
import javax.persistence.Transient;
|
||||
import javax.persistence.Version;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import javax.validation.constraints.Size;
|
||||
import java.sql.Types;
|
||||
@@ -503,12 +520,12 @@ public class AnnotationFields extends AnnotationParser {
|
||||
|
||||
} else if (strategy == GenerationType.SEQUENCE) {
|
||||
descriptor.setIdType(IdType.SEQUENCE);
|
||||
if (!genName.equals("")) {
|
||||
if (!genName.isEmpty()) {
|
||||
descriptor.setIdGeneratorName(genName);
|
||||
}
|
||||
|
||||
} else if (strategy == GenerationType.AUTO) {
|
||||
if (!genName.equals("")) {
|
||||
if (!genName.isEmpty()) {
|
||||
// use a custom IdGenerator
|
||||
PlatformIdGenerator idGenerator = generatedPropFactory.getIdGenerator(genName);
|
||||
if (idGenerator == null) {
|
||||
|
||||
@@ -56,7 +56,7 @@ public abstract class AnnotationParser extends AnnotationBase {
|
||||
|
||||
Set<AttributeOverride> attrOverrides = getAll(prop, AttributeOverride.class);
|
||||
if (!attrOverrides.isEmpty()) {
|
||||
HashMap<String, String> propMap = new HashMap<>();
|
||||
HashMap<String, String> propMap = new HashMap<>(attrOverrides.size());
|
||||
for (AttributeOverride attrOverride : attrOverrides) {
|
||||
propMap.put(attrOverride.name(), attrOverride.column().name());
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ public class DeployBeanInfo<T> {
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return ""+descriptor;
|
||||
return String.valueOf(descriptor);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -230,7 +230,7 @@ public class DefaultExpressionFactory implements SpiExpressionFactory {
|
||||
}
|
||||
|
||||
private EntityBean checkEntityBean(Object bean) {
|
||||
if (bean == null || (!(bean instanceof EntityBean))) {
|
||||
if (!(bean instanceof EntityBean)) {
|
||||
throw new IllegalStateException("Expecting an EntityBean");
|
||||
}
|
||||
return (EntityBean) bean;
|
||||
|
||||
@@ -34,7 +34,7 @@ class InExpression extends AbstractExpression {
|
||||
}
|
||||
|
||||
private Object[] values() {
|
||||
List<Object> vals = new ArrayList<>();
|
||||
List<Object> vals = new ArrayList<>(sourceValues.size());
|
||||
for (Object sourceValue : sourceValues) {
|
||||
NamedParamHelp.valueAdd(vals, sourceValue);
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import io.ebeaninternal.api.SpiExpressionRequest;
|
||||
import io.ebeaninternal.server.el.ElPropertyValue;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
|
||||
public class SimpleExpression extends AbstractValueExpression {
|
||||
|
||||
@@ -36,7 +37,7 @@ public class SimpleExpression extends AbstractValueExpression {
|
||||
String idName = prop.getAssocIdExpression(propName, "");
|
||||
Object[] ids = prop.getAssocIdValues((EntityBean) value());
|
||||
if (ids == null || ids.length != 1) {
|
||||
throw new IllegalArgumentException("Expecting 1 Id value for " + idName + " but got " + ids);
|
||||
throw new IllegalArgumentException("Expecting 1 Id value for " + idName + " but got " + Arrays.toString(ids));
|
||||
}
|
||||
context.writeSimple(type, idName, ids[0]);
|
||||
} else {
|
||||
|
||||
@@ -181,14 +181,8 @@ public class DLoadBeanContext extends DLoadBaseContext implements LoadBeanContex
|
||||
|
||||
if (context.hitCache) {
|
||||
// check each of the beans in the batch to see if they are in the L2 cache.
|
||||
Iterator<EntityBeanIntercept> iterator = list.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
EntityBeanIntercept batchEbi = iterator.next();
|
||||
if (batchEbi != ebi && context.desc.cacheBeanLoad(batchEbi, persistenceContext)) {
|
||||
// bean successfully loaded from L2 cache so remove from batch load
|
||||
iterator.remove();
|
||||
}
|
||||
}
|
||||
// bean successfully loaded from L2 cache so remove from batch load
|
||||
list.removeIf(batchEbi -> batchEbi != ebi && context.desc.cacheBeanLoad(batchEbi, persistenceContext));
|
||||
}
|
||||
|
||||
LoadBeanRequest req = new LoadBeanRequest(this, ebi.getLazyLoadProperty(), context.hitCache);
|
||||
|
||||
@@ -81,7 +81,7 @@ public class BindValues {
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "" + value;
|
||||
return String.valueOf(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,7 +80,7 @@ public class Binder {
|
||||
|
||||
if (bindBuf != null) {
|
||||
bindBuf.append(logPrefix);
|
||||
if (logPrefix.equals("")) {
|
||||
if (logPrefix.isEmpty()) {
|
||||
logPrefix = ", ";
|
||||
}
|
||||
bindBuf.append(bindValue.getName());
|
||||
@@ -163,7 +163,7 @@ public class Binder {
|
||||
}
|
||||
|
||||
} catch (SQLException ex) {
|
||||
logger.warn(Message.msg("fetch.bind.error", "" + (dataBind.currentPos() - 1), value));
|
||||
logger.warn(Message.msg("fetch.bind.error", String.valueOf(dataBind.currentPos() - 1), value));
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
@@ -333,7 +333,7 @@ public class Binder {
|
||||
break;
|
||||
|
||||
default:
|
||||
String msg = Message.msg("persist.bind.datatype", "" + dataType, "" + b.currentPos());
|
||||
String msg = Message.msg("persist.bind.datatype", String.valueOf(dataType), String.valueOf(b.currentPos()));
|
||||
throw new SQLException(msg);
|
||||
}
|
||||
|
||||
|
||||
@@ -165,7 +165,7 @@ public final class DefaultPersister implements Persister {
|
||||
* Helper method to return the list of Id values for the list of beans.
|
||||
*/
|
||||
private <T> List<Object> getBeanIds(BeanDescriptor<T> desc, List<T> beans) {
|
||||
List<Object> idList = new ArrayList<>();
|
||||
List<Object> idList = new ArrayList<>(beans.size());
|
||||
for (T liveBean : beans) {
|
||||
idList.add(desc.getBeanId(liveBean));
|
||||
}
|
||||
|
||||
@@ -160,8 +160,7 @@ public class ExeUpdateSql {
|
||||
|
||||
private int leadingTrim(String s) {
|
||||
int len = s.length();
|
||||
int i;
|
||||
for (i = 0; i < len; i++) {
|
||||
for (int i = 0; i < len; i++) {
|
||||
if (!Character.isWhitespace(s.charAt(i))) {
|
||||
return i;
|
||||
}
|
||||
|
||||
@@ -85,7 +85,7 @@ public final class DmlBeanPersister implements BeanPersister {
|
||||
throw new PersistenceException(msg, e);
|
||||
|
||||
} finally {
|
||||
if (!batched && handler != null) {
|
||||
if (!batched) {
|
||||
handler.close();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -535,7 +535,7 @@ public class CQuery<T> implements DbReadContext, CancelableQuery {
|
||||
|
||||
List<Version<T>> versionList = new ArrayList<>();
|
||||
|
||||
Version version;
|
||||
Version<T> version;
|
||||
while ((version = readNextVersion()) != null) {
|
||||
versionList.add(version);
|
||||
}
|
||||
@@ -544,7 +544,7 @@ public class CQuery<T> implements DbReadContext, CancelableQuery {
|
||||
return versionList;
|
||||
}
|
||||
|
||||
private Version readNextVersion() throws SQLException {
|
||||
private Version<T> readNextVersion() throws SQLException {
|
||||
|
||||
if (moveToNextRow()) {
|
||||
return rootNode.loadVersion(this);
|
||||
|
||||
@@ -377,11 +377,11 @@ class CQueryBuilder {
|
||||
PreparedStatement statement = connection.prepareStatement(sql);
|
||||
predicates.bind(statement, connection);
|
||||
|
||||
List<String> propertyNames = new ArrayList<>();
|
||||
|
||||
ResultSet resultSet = statement.executeQuery();
|
||||
ResultSetMetaData metaData = resultSet.getMetaData();
|
||||
|
||||
int cols = 1 + metaData.getColumnCount();
|
||||
List<String> propertyNames = new ArrayList<>(cols - 1);
|
||||
for (int i = 1; i < cols; i++) {
|
||||
String tableName = metaData.getTableName(i).toLowerCase();
|
||||
String columnName = metaData.getColumnName(i).toLowerCase();
|
||||
|
||||
@@ -119,7 +119,7 @@ public final class CQueryPlanStats {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
List<MetaQueryPlanOriginCount> list = new ArrayList<>();
|
||||
List<MetaQueryPlanOriginCount> list = new ArrayList<>(origins.size());
|
||||
|
||||
for (Entry<ObjectGraphNode, LongAdder> entry : origins.entrySet()) {
|
||||
if (reset) {
|
||||
|
||||
@@ -31,7 +31,7 @@ import java.util.UUID;
|
||||
*/
|
||||
public class DefaultSqlRow implements SqlRow {
|
||||
|
||||
static final long serialVersionUID = -3120927797041336242L;
|
||||
private static final long serialVersionUID = -3120927797041336242L;
|
||||
|
||||
private final String dbTrueValue;
|
||||
|
||||
|
||||
@@ -387,7 +387,7 @@ public class SqlTreeBuilder {
|
||||
|
||||
} else if (p instanceof BeanPropertyAssoc<?> && p.isEmbedded()) {
|
||||
// if the property is embedded we need to lookup the real column name
|
||||
int pos = propName.indexOf(".");
|
||||
int pos = propName.indexOf('.');
|
||||
if (pos > -1) {
|
||||
String name = propName.substring(pos + 1);
|
||||
p = ((BeanPropertyAssoc<?>) p).getTargetDescriptor().findBeanProperty(name);
|
||||
|
||||
@@ -203,9 +203,6 @@ class SqlTreeNodeBean implements SqlTreeNode {
|
||||
lazyLoadParentId = lazyLoadParentIdBinder.read(ctx);
|
||||
}
|
||||
|
||||
// bean already existing in the persistence context
|
||||
EntityBean contextBean = null;
|
||||
|
||||
Class<?> localType;
|
||||
BeanDescriptor<?> localDesc;
|
||||
IdBinder localIdBinder;
|
||||
@@ -237,6 +234,8 @@ class SqlTreeNodeBean implements SqlTreeNode {
|
||||
|
||||
PersistenceContext persistenceContext = (!readId || temporalVersions) ? null : ctx.getPersistenceContext();
|
||||
|
||||
// bean already existing in the persistence context
|
||||
EntityBean contextBean = null;
|
||||
if (readId) {
|
||||
Object id = localIdBinder.readSet(ctx, localBean);
|
||||
if (id == null) {
|
||||
|
||||
@@ -251,8 +251,7 @@ public class TCsvReader<T> implements CsvReader<T> {
|
||||
EntityBean entityBean = descriptor.createEntityBean();
|
||||
T bean = (T) entityBean;
|
||||
|
||||
int columnPos = 0;
|
||||
for (; columnPos < line.length; columnPos++) {
|
||||
for (int columnPos = 0; columnPos < line.length; columnPos++) {
|
||||
convertAndSetColumn(columnPos, line[columnPos], entityBean);
|
||||
}
|
||||
|
||||
|
||||
@@ -161,8 +161,6 @@ public class DJsonContext implements JsonContext {
|
||||
ReadJson readJson = new ReadJson(desc, src, options, determineObjectMapper(options));
|
||||
try {
|
||||
|
||||
List<T> list = new ArrayList<>();
|
||||
|
||||
JsonToken currentToken = src.getCurrentToken();
|
||||
if (currentToken != JsonToken.START_ARRAY) {
|
||||
JsonToken event = src.nextToken();
|
||||
@@ -171,6 +169,7 @@ public class DJsonContext implements JsonContext {
|
||||
}
|
||||
}
|
||||
|
||||
List<T> list = new ArrayList<>();
|
||||
do {
|
||||
T bean = desc.jsonRead(readJson, null);
|
||||
if (bean == null) {
|
||||
|
||||
@@ -34,11 +34,8 @@ public class ExplicitJdbcTransaction extends JdbcTransaction {
|
||||
}
|
||||
|
||||
private void executeStatement(String statement) throws SQLException {
|
||||
PreparedStatement stmt = connection.prepareStatement(statement);
|
||||
try {
|
||||
try (PreparedStatement stmt = connection.prepareStatement(statement)) {
|
||||
stmt.execute();
|
||||
} finally {
|
||||
stmt.close();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ import io.ebeaninternal.server.core.PersistRequest;
|
||||
import io.ebeaninternal.server.core.PersistRequestBean;
|
||||
import io.ebeaninternal.server.lib.util.Str;
|
||||
import io.ebeaninternal.server.persist.BatchControl;
|
||||
import io.ebeanservice.docstore.api.*;
|
||||
import io.ebeanservice.docstore.api.DocStoreTransaction;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
||||
@@ -248,7 +248,7 @@ public final class ConvertInetAddresses {
|
||||
}
|
||||
byte[] bytes = new byte[2 * IPV6_PART_COUNT];
|
||||
for (int i = 0; i < IPV6_PART_COUNT; i++) {
|
||||
int piece = address[i].equals("") ? 0 : Integer.parseInt(address[i], 16);
|
||||
int piece = address[i].isEmpty() ? 0 : Integer.parseInt(address[i], 16);
|
||||
bytes[2 * i] = (byte) ((piece & 0xFF00) >>> 8);
|
||||
bytes[2 * i + 1] = (byte) (piece & 0xFF);
|
||||
}
|
||||
@@ -283,7 +283,6 @@ public final class ConvertInetAddresses {
|
||||
|
||||
private static String convertDottedQuadToHex(String ipString) {
|
||||
int lastColon = ipString.lastIndexOf(':');
|
||||
String initialPart = ipString.substring(0, lastColon + 1);
|
||||
String dottedQuad = ipString.substring(lastColon + 1);
|
||||
byte[] quad = textToNumericFormatV4(dottedQuad);
|
||||
if (quad == null) {
|
||||
@@ -291,6 +290,8 @@ public final class ConvertInetAddresses {
|
||||
}
|
||||
String penultimate = Integer.toHexString(((quad[0] & 0xff) << 8) | (quad[1] & 0xff));
|
||||
String ultimate = Integer.toHexString(((quad[2] & 0xff) << 8) | (quad[3] & 0xff));
|
||||
|
||||
String initialPart = ipString.substring(0, lastColon + 1);
|
||||
return initialPart + penultimate + ":" + ultimate;
|
||||
}
|
||||
|
||||
|
||||
@@ -52,7 +52,20 @@ import java.time.YearMonth;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZoneOffset;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.*;
|
||||
import java.util.Arrays;
|
||||
import java.util.Calendar;
|
||||
import java.util.Currency;
|
||||
import java.util.EnumSet;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.ServiceLoader;
|
||||
import java.util.Set;
|
||||
import java.util.TimeZone;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
|
||||
@@ -87,11 +87,8 @@ public abstract class ScalarTypeJsonMap extends ScalarTypeBase<Map> {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
InputStreamReader reader = new InputStreamReader(is);
|
||||
try {
|
||||
try (InputStreamReader reader = new InputStreamReader(is)) {
|
||||
return parse(reader);
|
||||
} finally {
|
||||
reader.close();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new SQLException("Error reading Blob stream from DB", e);
|
||||
|
||||
@@ -126,9 +126,7 @@ public class ScalarTypeJsonSet {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private Set convertList(List list) {
|
||||
LinkedHashSet set = new LinkedHashSet();
|
||||
set.addAll(list);
|
||||
return set;
|
||||
return new LinkedHashSet(list);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -153,7 +153,7 @@ public class BindParamsParser {
|
||||
|
||||
// check if inValue is a Collection type...
|
||||
Object inValue = param.getInValue();
|
||||
if (inValue != null && inValue instanceof Collection<?>) {
|
||||
if (inValue instanceof Collection<?>) {
|
||||
// Chop up Collection parameter into a number
|
||||
// of individual parameters and add each one individually
|
||||
Collection<?> collection = (Collection<?>) inValue;
|
||||
|
||||
Reference in New Issue
Block a user