Merge branch 'master' into wip/EntityBeanIntercept-interface

This commit is contained in:
Rob Bygrave authored and GitHub committed 2022-04-12 21:09:58 +12:00
commit 45003b3d5f
140 files changed
+1072 -1581

No files matched your search

@@ -2,14 +2,7 @@ package io.ebeaninternal.server.cache;
import io.ebeaninternal.server.deploy.BeanDescriptor;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.*;
/**
* List of changes to be applied to L2 cache.
@@ -3,12 +3,7 @@ package io.ebeaninternal.server.cache;
import io.ebean.annotation.Cache;
import io.ebean.annotation.CacheBeanTuning;
import io.ebean.annotation.CacheQueryTuning;
import io.ebean.cache.QueryCacheEntryValidate;
import io.ebean.cache.ServerCache;
import io.ebean.cache.ServerCacheConfig;
import io.ebean.cache.ServerCacheFactory;
import io.ebean.cache.ServerCacheOptions;
import io.ebean.cache.ServerCacheType;
import io.ebean.cache.*;
import io.ebean.config.CurrentTenantProvider;
import io.ebean.meta.MetricVisitor;
import io.ebean.util.AnnotationUtil;
@@ -3,7 +3,6 @@ package io.ebeaninternal.server.cache;
import io.ebean.BackgroundExecutor;
import io.ebean.cache.ServerCache;
import io.ebean.cache.ServerCacheStatistics;
import io.ebean.cache.TenantAwareKey;
import io.ebean.meta.MetricVisitor;
import io.ebean.metric.CountMetric;
import io.ebean.metric.MetricFactory;
@@ -12,11 +11,7 @@ import org.slf4j.LoggerFactory;
import java.io.Serializable;
import java.lang.ref.SoftReference;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.concurrent.TimeUnit;
/**
@@ -52,14 +47,12 @@ public class DefaultServerCache implements ServerCache {
private final int trimFrequency;
private final int maxIdleSecs;
private final int maxSecsToLive;
private final TenantAwareKey tenantAwareKey;
public DefaultServerCache(DefaultServerCacheConfig config) {
this.name = config.getName();
this.shortName = config.getShortName();
this.map = config.getMap();
this.maxSize = config.getMaxSize();
this.tenantAwareKey = new TenantAwareKey(config.getTenantProvider());
this.maxIdleSecs = config.getMaxIdleSecs();
this.maxSecsToLive = config.getMaxSecsToLive();
this.trimFrequency = config.determineTrimFrequency();
@@ -92,7 +85,7 @@ public class DefaultServerCache implements ServerCache {
}
@Override
public ServerCacheStatistics getStatistics(boolean reset) {
public ServerCacheStatistics statistics(boolean reset) {
ServerCacheStatistics cacheStats = new ServerCacheStatistics();
cacheStats.setCacheName(name);
cacheStats.setMaxSize(maxSize);
@@ -121,7 +114,7 @@ public class DefaultServerCache implements ServerCache {
}
@Override
public int getHitRatio() {
public int hitRatio() {
long mc = missCount.get(false);
long hc = hitCount.get(false);
long totalCount = hc + mc;
@@ -152,19 +145,12 @@ public class DefaultServerCache implements ServerCache {
map.clear();
}
/**
* Return the tenant aware key.
*/
protected Object key(Object id) {
return tenantAwareKey.key(id);
}
/**
* Return a value from the cache.
*/
@Override
public Object get(Object id) {
CacheEntry entry = getCacheEntry(id);
public Object get(Object key) {
CacheEntry entry = getCacheEntry(key);
if (entry == null) {
missCount.increment();
return null;
@@ -184,8 +170,8 @@ public class DefaultServerCache implements ServerCache {
/**
* Get the cache entry - override for query cache to validate dependent tables.
*/
protected CacheEntry getCacheEntry(Object id) {
final SoftReference<CacheEntry> ref = map.get(key(id));
protected CacheEntry getCacheEntry(Object key) {
final SoftReference<CacheEntry> ref = map.get(key);
return ref != null ? ref.get() : null;
}
@@ -198,8 +184,7 @@ public class DefaultServerCache implements ServerCache {
* Put a value into the cache.
*/
@Override
public void put(Object id, Object value) {
Object key = key(id);
public void put(Object key, Object value) {
map.put(key, new SoftReference<>(new CacheEntry(key, value)));
putCount.increment();
}
@@ -208,8 +193,8 @@ public class DefaultServerCache implements ServerCache {
* Remove an entry from the cache.
*/
@Override
public void remove(Object id) {
SoftReference<CacheEntry> entry = map.remove(key(id));
public void remove(Object key) {
SoftReference<CacheEntry> entry = map.remove(key);
if (entry != null && entry.get() != null) {
removeCount.increment();
}
@@ -3,7 +3,6 @@ package io.ebeaninternal.server.cache;
import io.ebean.cache.QueryCacheEntryValidate;
import io.ebean.cache.ServerCacheConfig;
import io.ebean.cache.ServerCacheOptions;
import io.ebean.config.CurrentTenantProvider;
import io.ebeaninternal.server.cache.DefaultServerCache.CacheEntry;
import java.lang.ref.SoftReference;
@@ -34,10 +33,6 @@ public final class DefaultServerCacheConfig {
this.maxSize = options.getMaxSize();
}
public CurrentTenantProvider getTenantProvider() {
return config.getTenantProvider();
}
public QueryCacheEntryValidate getQueryCacheEntryValidate() {
return config.getQueryCacheEntryValidate();
}
@@ -1,11 +1,7 @@
package io.ebeaninternal.server.cache;
import io.ebean.BackgroundExecutor;
import io.ebean.cache.ServerCache;
import io.ebean.cache.ServerCacheConfig;
import io.ebean.cache.ServerCacheFactory;
import io.ebean.cache.ServerCacheNotification;
import io.ebean.cache.ServerCacheNotify;
import io.ebean.cache.*;
/**
@@ -41,7 +37,7 @@ final class DefaultServerCacheFactory implements ServerCacheFactory {
if (executor != null) {
cache.periodicTrim(executor);
}
return cache;
return config.tenantAware(cache);
}
@Override
@@ -10,11 +10,7 @@ import io.ebeaninternal.server.deploy.DCacheRegion;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
/**
* Manages the bean and query caches.
@@ -27,8 +27,7 @@ public class DefaultServerQueryCache extends DefaultServerCache {
}
@Override
protected CacheEntry getCacheEntry(Object id) {
Object key = key(id);
protected CacheEntry getCacheEntry(Object key) {
final SoftReference<CacheEntry> ref = map.get(key);
CacheEntry entry = ref != null ? ref.get() : null;
if (entry == null) {
@@ -978,21 +978,11 @@ public final class DefaultServer implements SpiServer, SpiEbeanServer {
return new DefaultRelationalQuery(this, sql.trim());
}
@Override
public SqlQuery createSqlQuery(String sql) {
return sqlQuery(sql);
}
@Override
public SqlUpdate sqlUpdate(String sql) {
return new DefaultSqlUpdate(this, sql.trim());
}
@Override
public SqlUpdate createSqlUpdate(String sql) {
return sqlUpdate(sql);
}
@Override
public CallableSql createCallableSql(String sql) {
return new DefaultCallableSql(this, sql.trim());
@@ -1376,11 +1366,6 @@ public final class DefaultServer implements SpiServer, SpiEbeanServer {
}
}
@Override
public <T> Stream<T> findLargeStream(Query<T> query, Transaction transaction) {
return findStream(query, transaction);
}
@Override
public <T> Stream<T> findStream(Query<T> query, Transaction transaction) {
return toStream(findIterate(query, transaction));
@@ -261,16 +261,6 @@ public final class DefaultSqlUpdate implements Serializable, SpiSqlUpdate {
return this;
}
@Override
public SqlUpdate setParams(Object... values) {
return setParameters(values);
}
@Override
public SqlUpdate setNextParameter(Object value) {
return setParameter(value);
}
@Override
public SqlUpdate setParameters(Object... values) {
for (Object value : values) {
@@ -2114,10 +2114,10 @@ public class BeanDescriptor<T> implements BeanType<T>, STreeType, SpiBeanType {
return getId((EntityBean) bean);
}
@Override
public Object getBeanId(T bean) {
return getId((EntityBean) bean);
}
// @Override
// public Object beanId(T bean) {
// return getId((EntityBean) bean);
// }
/**
* Return the Id value for the bean with embeddedId beans converted into maps.
@@ -219,9 +219,7 @@ public class DeployBeanProperty {
return (AnnotationUtil.has(field, WhenCreated.class)
|| AnnotationUtil.has(field, WhenModified.class)
|| AnnotationUtil.has(field, WhoModified.class)
|| AnnotationUtil.has(field, WhoCreated.class)
|| AnnotationUtil.has(field, UpdatedTimestamp.class)
|| AnnotationUtil.has(field, CreatedTimestamp.class));
|| AnnotationUtil.has(field, WhoCreated.class));
}
public String getFullBeanName() {
@@ -1,38 +1,7 @@
package io.ebeaninternal.server.deploy.parse;
import io.ebean.annotation.Aggregation;
import io.ebean.annotation.CreatedTimestamp;
import io.ebean.annotation.DbArray;
import io.ebean.annotation.DbComment;
import io.ebean.annotation.DbDefault;
import io.ebean.annotation.DbJson;
import io.ebean.annotation.DbJsonB;
import io.ebean.annotation.DbMap;
import io.ebean.annotation.DbMigration;
import io.ebean.annotation.DocCode;
import io.ebean.annotation.DocEmbedded;
import io.ebean.annotation.DocProperty;
import io.ebean.annotation.DocSortable;
import io.ebean.annotation.Draft;
import io.ebean.annotation.DraftDirty;
import io.ebean.annotation.DraftOnly;
import io.ebean.annotation.DraftReset;
import io.ebean.annotation.Encrypted;
import io.ebean.annotation.Expose;
import io.ebean.annotation.Formula;
import io.ebean.annotation.HistoryExclude;
import io.ebean.annotation.Identity;
import io.ebean.annotation.Index;
import io.ebean.annotation.JsonIgnore;
import io.ebean.annotation.Length;
import io.ebean.annotation.SoftDelete;
import io.ebean.annotation.TenantId;
import io.ebean.annotation.UnmappedJson;
import io.ebean.annotation.UpdatedTimestamp;
import io.ebean.annotation.WhenCreated;
import io.ebean.annotation.WhenModified;
import io.ebean.annotation.WhoCreated;
import io.ebean.annotation.WhoModified;
import io.ebean.annotation.*;
import io.ebean.config.EncryptDeploy;
import io.ebean.config.EncryptDeploy.Mode;
import io.ebean.config.dbplatform.DbEncrypt;
@@ -51,24 +20,7 @@ import io.ebeaninternal.server.type.ScalarTypeBytesBase;
import io.ebeaninternal.server.type.ScalarTypeBytesEncrypted;
import io.ebeaninternal.server.type.ScalarTypeEncryptedWrapper;
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.persistence.*;
import java.sql.Types;
import java.util.Set;
import java.util.UUID;
@@ -339,10 +291,10 @@ final class AnnotationFields extends AnnotationParser {
}
private void initWhen(DeployBeanProperty prop) {
if (has(prop, WhenCreated.class) || has(prop, CreatedTimestamp.class)) {
if (has(prop, WhenCreated.class)) {
generatedPropFactory.setInsertTimestamp(prop);
}
if (has(prop, WhenModified.class) || has(prop, UpdatedTimestamp.class)) {
if (has(prop, WhenModified.class)) {
generatedPropFactory.setUpdateTimestamp(prop);
}
}
@@ -48,7 +48,6 @@ final class DCountMetric implements CountMetric {
@Override
public void visit(MetricVisitor visitor) {
long val = visitor.reset() ? count.sumThenReset() : count.sum();
if (val > 0) {
visitor.visitCount(new DCountMetricStats(name, val));
@@ -251,11 +251,6 @@ final class DefaultFetchGroupQuery<T> implements SpiFetchGroupQuery<T>, SpiQuery
throw new RuntimeException("EB102: Only select() and fetch() clause is allowed on FetchGroup");
}
@Override
public Stream<T> findLargeStream() {
throw new RuntimeException("EB102: Only select() and fetch() clause is allowed on FetchGroup");
}
@Override
public void findEach(Consumer<T> consumer) {
throw new RuntimeException("EB102: Only select() and fetch() clause is allowed on FetchGroup");
@@ -1456,11 +1456,6 @@ public final class DefaultOrmQuery<T> extends AbstractQuery implements SpiQuery<
return server.findStream(this, transaction);
}
@Override
public Stream<T> findLargeStream() {
return server.findLargeStream(this, transaction);
}
@Override
public List<Version<T>> findVersions() {
this.temporalMode = TemporalMode.VERSIONS;
@@ -10,7 +10,6 @@ import io.ebeaninternal.api.BindParams;
import io.ebeaninternal.api.SpiEbeanServer;
import io.ebeaninternal.api.SpiSqlQuery;
import java.math.BigDecimal;
import java.util.List;
import java.util.Optional;
import java.util.function.Consumer;
@@ -56,36 +55,6 @@ public final class DefaultRelationalQuery extends AbstractQuery implements SpiSq
return server.findList(this, null);
}
@Override
public BigDecimal findSingleDecimal() {
return server.findSingleAttribute(this, BigDecimal.class);
}
@Override
public Long findSingleLong() {
return server.findSingleAttribute(this, Long.class);
}
@Override
public <T> T findSingleAttribute(Class<T> cls) {
return server.findSingleAttribute(this, cls);
}
@Override
public <T> List<T> findSingleAttributeList(Class<T> cls) {
return server.findSingleAttributeList(this, cls);
}
@Override
public <T> T findOne(RowMapper<T> mapper) {
return server.findOneMapper(this, mapper);
}
@Override
public <T> List<T> findList(RowMapper<T> mapper) {
return server.findListMapper(this, mapper);
}
@Override
public void findEachRow(RowConsumer consumer) {
server.findEachRow(this, consumer);
@@ -101,12 +70,6 @@ public final class DefaultRelationalQuery extends AbstractQuery implements SpiSq
return Optional.ofNullable(findOne());
}
@Override
@Deprecated
public DefaultRelationalQuery setParams(Object... values) {
return setParameters(values);
}
@Override
public DefaultRelationalQuery setParameters(Object... values) {
bindParams.setNextParameters(values);
@@ -237,6 +200,14 @@ public final class DefaultRelationalQuery extends AbstractQuery implements SpiSq
return new Mapper(mapper);
}
private <T> T findSingleAttribute(Class<T> cls) {
return server.findSingleAttribute(this, cls);
}
private <T> List<T> findSingleAttributeList(Class<T> cls) {
return server.findSingleAttributeList(this, cls);
}
private class Scalar<T> implements SqlQuery.TypeQuery<T> {
private final Class<T> type;
@@ -54,14 +54,13 @@ public interface DocStoreBeanAdapter<T> extends BeanDocType<T> {
/**
* Return the index type for this bean type.
*/
@Override
String getIndexType();
String indexType();
/**
* Return the index name for this bean type.
*/
@Override
String getIndexName();
String indexName();
/**
* Process a delete by id of a given document.
@@ -102,7 +102,6 @@ public abstract class DocStoreBeanBaseAdapter<T> implements DocStoreBeanAdapter<
private boolean registerPaths;
public DocStoreBeanBaseAdapter(BeanDescriptor<T> desc, DeployBeanDescriptor<T> deploy) {
this.desc = desc;
this.server = desc.ebeanServer();
this.mapped = deploy.isDocStoreMapped();
@@ -123,7 +122,6 @@ public abstract class DocStoreBeanBaseAdapter<T> implements DocStoreBeanAdapter<
@Override
public DocumentMapping createDocMapping() {
if (documentMapping != null) {
return documentMapping;
}
@@ -143,12 +141,12 @@ public abstract class DocStoreBeanBaseAdapter<T> implements DocStoreBeanAdapter<
}
@Override
public String getIndexType() {
public String indexType() {
return indexType;
}
@Override
public String getIndexName() {
public String indexName() {
return indexName;
}
@@ -159,7 +157,6 @@ public abstract class DocStoreBeanBaseAdapter<T> implements DocStoreBeanAdapter<
@Override
public String rawProperty(String property) {
String rawProperty = sortableMap.get(property);
return rawProperty == null ? property : rawProperty;
}
@@ -192,7 +189,6 @@ public abstract class DocStoreBeanBaseAdapter<T> implements DocStoreBeanAdapter<
*/
@Override
public void registerInvalidationPath(String queueId, String path, Set<String> properties) {
if (!mapped) {
if (update == DocStoreMode.IGNORE) {
// bean type not mapped but is included as nested document
@@ -207,7 +203,6 @@ public abstract class DocStoreBeanBaseAdapter<T> implements DocStoreBeanAdapter<
* Return the DsInvalidationListener based on the properties, path.
*/
protected DocStoreEmbeddedInvalidation getEmbeddedInvalidation(String queueId, String path, Set<String> properties) {
if (properties.contains("*")) {
return new DocStoreEmbeddedInvalidation(queueId, path);
} else {
@@ -245,19 +240,15 @@ public abstract class DocStoreBeanBaseAdapter<T> implements DocStoreBeanAdapter<
* This can add derived/embedded/nested parts to the document.
*/
protected DocStructure derivePathProperties(PathProperties pathProps) {
boolean includeByDefault = (pathProps == null);
if (pathProps == null) {
pathProps = new PathProperties();
}
return getDocStructure(pathProps, includeByDefault);
}
protected DocStructure getDocStructure(PathProperties pathProps, final boolean includeByDefault) {
final DocStructure docStructure = new DocStructure(pathProps);
BeanProperty[] properties = desc.propertiesNonTransient();
for (BeanProperty property : properties) {
property.docStoreInclude(includeByDefault, docStructure);
@@ -271,17 +262,16 @@ public abstract class DocStoreBeanBaseAdapter<T> implements DocStoreBeanAdapter<
}
});
}
return docStructure;
}
@Override
public FetchPath getEmbedded(String path) {
public FetchPath embedded(String path) {
return docStructure.getEmbedded(path);
}
@Override
public FetchPath getEmbeddedManyRoot(String path) {
public FetchPath embeddedManyRoot(String path) {
return docStructure.getEmbeddedManyRoot(path);
}
@@ -297,7 +287,6 @@ public abstract class DocStoreBeanBaseAdapter<T> implements DocStoreBeanAdapter<
@Override
public DocStoreMode getMode(PersistRequest.Type persistType, DocStoreMode txnMode) {
if (txnMode == null) {
return getMode(persistType);
} else if (txnMode == DocStoreMode.IGNORE) {