Merge pull request #2423 from ebean-orm/feature/nonNullApi

Use @NonNullApi to explicitly reflect non-null return types and params by default
This commit is contained in:
Rob Bygrave
2021-10-20 15:47:44 +13:00
committed by GitHub
40 changed files with 200 additions and 235 deletions
+2 -3
View File
@@ -36,9 +36,8 @@
-->
<dependency>
<groupId>io.avaje</groupId>
<artifactId>avaje-jsr305</artifactId>
<version>1.1</version>
<scope>provided</scope>
<artifactId>avaje-lang</artifactId>
<version>1.0</version>
</dependency>
<dependency>
@@ -1,5 +1,7 @@
package io.ebean;
import io.avaje.lang.NonNullApi;
import java.util.concurrent.Callable;
import java.util.concurrent.Future;
import java.util.concurrent.ScheduledExecutorService;
@@ -18,6 +20,7 @@ import java.util.concurrent.TimeUnit;
* This also propagates MDC context from the current thread to the
* background task if defined.
*/
@NonNullApi
public interface BackgroundExecutor {
/**
@@ -1,6 +1,7 @@
package io.ebean;
import javax.annotation.Nullable;
import io.avaje.lang.NonNullApi;
import io.avaje.lang.Nullable;
import java.util.List;
import java.util.Optional;
@@ -26,10 +27,10 @@ import java.util.Optional;
* @param <I> The ID type
* @param <T> The Bean type
*/
@NonNullApi
public abstract class BeanFinder<I,T> {
protected final Database server;
protected final Class<T> type;
/**
@@ -1,5 +1,6 @@
package io.ebean;
import io.avaje.lang.NonNullApi;
import io.ebean.bean.EntityBean;
import java.util.Collection;
@@ -31,6 +32,7 @@ import java.util.Collection;
* @param <I> The ID type
* @param <T> The Bean type
*/
@NonNullApi
public abstract class BeanRepository<I, T> extends BeanFinder<I, T> {
/**
@@ -1,6 +1,5 @@
package io.ebean;
import javax.annotation.Nullable;
import java.util.Map;
import java.util.Set;
+4 -78
View File
@@ -1,12 +1,13 @@
package io.ebean;
import io.avaje.lang.NonNullApi;
import io.avaje.lang.Nullable;
import io.ebean.annotation.TxIsolation;
import io.ebean.cache.ServerCacheManager;
import io.ebean.plugin.Property;
import io.ebean.text.csv.CsvReader;
import io.ebean.text.json.JsonContext;
import javax.annotation.Nullable;
import javax.persistence.OptimisticLockException;
import javax.persistence.PersistenceException;
import java.util.Collection;
@@ -59,6 +60,7 @@ import java.util.concurrent.Callable;
*
* }</pre>
*/
@NonNullApi
public final class DB {
private static final DbContext context = DbContext.getInstance();
@@ -527,7 +529,7 @@ public final class DB {
}
/**
* Same as {@link #checkUniqueness(Object)}. but with given transaction.
* Same as {@link #checkUniqueness(Object)} but with given transaction.
*/
public static Set<Property> checkUniqueness(Object bean, Transaction transaction) {
return getDefault().checkUniqueness(bean, transaction);
@@ -848,7 +850,6 @@ public final class DB {
* }</pre>
*/
public static <T> Update<T> createUpdate(Class<T> beanType, String ormUpdate) {
return getDefault().createUpdate(beanType, ormUpdate);
}
@@ -856,7 +857,6 @@ public final class DB {
* Create a CsvReader for a given beanType.
*/
public static <T> CsvReader<T> createCsvReader(Class<T> beanType) {
return getDefault().createCsvReader(beanType);
}
@@ -894,7 +894,6 @@ public final class DB {
* @return A ORM Query for this beanType
*/
public static <T> Query<T> createQuery(Class<T> beanType) {
return getDefault().createQuery(beanType);
}
@@ -932,7 +931,6 @@ public final class DB {
* @return The query with expressions defined as per the parsed query statement
*/
public static <T> Query<T> createQuery(Class<T> beanType, String eql) {
return getDefault().createQuery(beanType, eql);
}
@@ -948,7 +946,6 @@ public final class DB {
* @return A ORM Query object for this beanType
*/
public static <T> Query<T> find(Class<T> beanType) {
return getDefault().find(beanType);
}
@@ -1027,77 +1024,6 @@ public final class DB {
return getDefault().filter(beanType);
}
// /**
// * Execute a Sql Update Delete or Insert statement. This returns the number of
// * rows that where updated, deleted or inserted. If is executed in batch then
// * this returns -1. You can get the actual rowCount after commit() from
// * updateSql.getRowCount().
// * <p>
// * If you wish to execute a Sql Select natively then you should use the
// * FindByNativeSql object.
// * </p>
// * <p>
// * Note that the table modification information is automatically deduced and
// * you do not need to call the DB.externalModification() method when you
// * use this method.
// * </p>
// * <p>
// * Example:
// * </p>
// * <pre>{@code
// *
// * // example that uses 'named' parameters
// * String s = "UPDATE f_topic set post_count = :count where id = :id"
// *
// * SqlUpdate update = DB.createSqlUpdate(s);
// *
// * update.setParameter("id", 1);
// * update.setParameter("count", 50);
// *
// * int modifiedCount = DB.execute(update);
// *
// * String msg = "There where " + modifiedCount + "rows updated";
// *
// * }</pre>
// *
// * @param sqlUpdate the update sql potentially with bind values
// * @return the number of rows updated or deleted. -1 if executed in batch.
// * @see SqlUpdate
// * @see CallableSql
// * @see DB#execute(CallableSql)
// */
// public static int execute(SqlUpdate sqlUpdate) {
// return defaultDatabase().execute(sqlUpdate);
// }
//
// /**
// * For making calls to stored procedures.
// * <p>
// * Example:
// * </p>
// * <pre>{@code
// *
// * String sql = "{call sp_order_modify(?,?,?)}";
// *
// * CallableSql cs = DB.createCallableSql(sql);
// * cs.setParameter(1, 27);
// * cs.setParameter(2, "SHIPPED");
// * cs.registerOut(3, Types.INTEGER);
// *
// * DB.execute(cs);
// *
// * // read the out parameter
// * Integer returnValue = (Integer) cs.getObject(3);
// *
// * }</pre>
// *
// * @see CallableSql
// * @see Ebean#execute(SqlUpdate)
// */
// public static int execute(CallableSql callableSql) {
// return defaultDatabase().execute(callableSql);
// }
/**
* Execute a TxRunnable in a Transaction with an explicit scope.
* <p>
@@ -1,5 +1,7 @@
package io.ebean;
import io.avaje.lang.NonNullApi;
import io.avaje.lang.Nullable;
import io.ebean.annotation.Platform;
import io.ebean.annotation.TxIsolation;
import io.ebean.cache.ServerCacheManager;
@@ -10,7 +12,6 @@ import io.ebean.plugin.SpiServer;
import io.ebean.text.csv.CsvReader;
import io.ebean.text.json.JsonContext;
import javax.annotation.Nullable;
import javax.persistence.OptimisticLockException;
import javax.persistence.PersistenceException;
import javax.sql.DataSource;
@@ -91,6 +92,7 @@ import java.util.concurrent.Callable;
* @see DatabaseFactory
* @see DatabaseConfig
*/
@NonNullApi
public interface Database {
/**
@@ -1,9 +1,10 @@
package io.ebean;
import io.avaje.lang.NonNullApi;
import io.avaje.lang.Nullable;
import io.ebean.docstore.DocQueryContext;
import io.ebean.docstore.RawDoc;
import javax.annotation.Nullable;
import java.io.IOException;
import java.util.List;
import java.util.Map;
@@ -13,6 +14,7 @@ import java.util.function.Predicate;
/**
* Document storage operations.
*/
@NonNullApi
public interface DocumentStore {
/**
@@ -1,6 +1,7 @@
package io.ebean;
import javax.annotation.Nullable;
import io.avaje.lang.NonNullApi;
import io.avaje.lang.Nullable;
import java.util.List;
import java.util.Optional;
import java.util.function.Consumer;
@@ -37,6 +38,7 @@ import java.util.stream.Stream;
*
* }</pre>
*/
@NonNullApi
public interface DtoQuery<T> extends CancelableQuery {
/**
+1 -1
View File
@@ -1,12 +1,12 @@
package io.ebean;
import io.avaje.lang.Nullable;
import io.ebean.annotation.TxIsolation;
import io.ebean.cache.ServerCacheManager;
import io.ebean.plugin.Property;
import io.ebean.text.csv.CsvReader;
import io.ebean.text.json.JsonContext;
import javax.annotation.Nullable;
import javax.persistence.OptimisticLockException;
import javax.persistence.PersistenceException;
import java.util.Collection;
@@ -1,20 +1,13 @@
package io.ebean;
import io.ebean.search.Match;
import io.ebean.search.MultiMatch;
import io.ebean.search.TextCommonTerms;
import io.ebean.search.TextQueryString;
import io.ebean.search.TextSimple;
import io.avaje.lang.NonNullApi;
import io.avaje.lang.Nullable;
import io.ebean.search.*;
import javax.annotation.Nullable;
import javax.persistence.NonUniqueResultException;
import java.sql.Connection;
import java.sql.Timestamp;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.*;
import java.util.function.Consumer;
import java.util.function.Predicate;
@@ -38,6 +31,7 @@ import java.util.function.Predicate;
*
* @see Query#where()
*/
@NonNullApi
public interface ExpressionList<T> {
/**
@@ -1,6 +1,7 @@
package io.ebean;
import javax.annotation.Nullable;
import io.avaje.lang.Nullable;
import javax.persistence.NonUniqueResultException;
import java.time.Clock;
import java.util.List;
@@ -1,5 +1,6 @@
package io.ebean;
import io.avaje.lang.NonNullApi;
import io.ebean.service.SpiFetchGroupQuery;
/**
@@ -60,6 +61,7 @@ import io.ebean.service.SpiFetchGroupQuery;
*
* @param <T> The bean type the Fetch group can be applied to
*/
@NonNullApi
public interface FetchGroup<T> {
/**
@@ -1,5 +1,7 @@
package io.ebean;
import io.avaje.lang.NonNullApi;
/**
* Builds a FetchGroup by adding fetch clauses.
* <p>
@@ -21,6 +23,7 @@ package io.ebean;
*
* }</pre>
*/
@NonNullApi
public interface FetchGroupBuilder<T> {
/**
@@ -1,5 +1,7 @@
package io.ebean;
import io.avaje.lang.NonNullApi;
import java.util.List;
import java.util.Set;
@@ -77,6 +79,7 @@ import java.util.Set;
*
* @param <T> the entity bean type
*/
@NonNullApi
public interface Filter<T> {
/**
+3 -1
View File
@@ -1,6 +1,7 @@
package io.ebean;
import javax.annotation.Nullable;
import io.avaje.lang.NonNullApi;
import io.avaje.lang.Nullable;
import java.util.List;
/**
@@ -54,6 +55,7 @@ import java.util.List;
* }</pre>
*
*/
@NonNullApi
public class Finder<I, T> {
/**
@@ -113,9 +113,9 @@ public interface Junction<T> extends Expression, ExpressionList<T> {
*/
SHOULD("should", "", true);
private String prefix;
private String literal;
private boolean text;
private final String prefix;
private final String literal;
private final boolean text;
Type(String literal, String prefix, boolean text) {
this.literal = literal;
+3 -1
View File
@@ -1,6 +1,7 @@
package io.ebean;
import javax.annotation.Nullable;
import io.avaje.lang.NonNullApi;
import io.avaje.lang.Nullable;
import javax.persistence.NonUniqueResultException;
import java.sql.Connection;
import java.sql.Timestamp;
@@ -176,6 +177,7 @@ import java.util.stream.Stream;
*
* @param <T> the type of Entity bean this query will fetch.
*/
@NonNullApi
public interface Query<T> extends CancelableQuery {
/**
@@ -1,6 +1,7 @@
package io.ebean;
import javax.annotation.Nullable;
import io.avaje.lang.NonNullApi;
import io.avaje.lang.Nullable;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.List;
@@ -36,6 +37,7 @@ import java.util.function.Predicate;
*
* }</pre>
*/
@NonNullApi
public interface SqlQuery extends Serializable, CancelableQuery {
/**
@@ -351,6 +353,7 @@ public interface SqlQuery extends Serializable, CancelableQuery {
/**
* Return the single value.
*/
@Nullable
T findOne();
/**
@@ -1,5 +1,7 @@
package io.ebeaninternal.server.core;
import io.avaje.lang.NonNullApi;
import io.avaje.lang.Nullable;
import io.ebean.AutoTune;
import io.ebean.BackgroundExecutor;
import io.ebean.BeanState;
@@ -101,7 +103,6 @@ import io.ebeaninternal.util.ParamTypeHelper.TypeInfo;
import io.ebeanservice.docstore.api.DocStoreIntegration;
import org.slf4j.Logger;
import javax.annotation.Nullable;
import javax.persistence.NonUniqueResultException;
import javax.persistence.OptimisticLockException;
import javax.persistence.PersistenceException;
@@ -125,6 +126,7 @@ import static java.util.stream.StreamSupport.stream;
/**
* The default server side implementation of EbeanServer.
*/
@NonNullApi
public final class DefaultServer implements SpiServer, SpiEbeanServer {
private static final Logger log = CoreLog.internal;
@@ -271,6 +273,7 @@ public final class DefaultServer implements SpiServer, SpiEbeanServer {
return lazyLoadBatchSize;
}
@Nullable
@Override
public Object currentTenantId() {
return currentTenantProvider == null ? null : currentTenantProvider.currentId();
@@ -563,7 +566,7 @@ public final class DefaultServer implements SpiServer, SpiEbeanServer {
}
@Override
public Map<String, ValuePair> diff(Object a, Object b) {
public Map<String, ValuePair> diff(@Nullable Object a, Object b) {
if (a == null) {
return Collections.emptyMap();
}
@@ -617,7 +620,7 @@ public final class DefaultServer implements SpiServer, SpiEbeanServer {
}
}
private void executeSql(Connection connection, String sql) throws SQLException {
private void executeSql(Connection connection, @Nullable String sql) throws SQLException {
if (sql != null) {
try (PreparedStatement stmt = connection.prepareStatement(sql)) {
transactionManager.log().sql().debug(sql);
@@ -723,7 +726,7 @@ public final class DefaultServer implements SpiServer, SpiEbeanServer {
}
@Override
public <T> T executeCall(TxScope scope, Callable<T> c) {
public <T> T executeCall(@Nullable TxScope scope, Callable<T> c) {
ScopedTransaction scopeTrans = transactionManager.beginScopedTransaction(scope);
try {
return c.call();
@@ -742,7 +745,7 @@ public final class DefaultServer implements SpiServer, SpiEbeanServer {
}
@Override
public void execute(TxScope scope, Runnable r) {
public void execute(@Nullable TxScope scope, Runnable r) {
ScopedTransaction t = transactionManager.beginScopedTransaction(scope);
try {
r.run();
@@ -765,6 +768,7 @@ public final class DefaultServer implements SpiServer, SpiEbeanServer {
transactionManager.exitScopedTransaction(returnOrThrowable, opCode);
}
@Nullable
@Override
public SpiTransaction currentServerTransaction() {
return transactionManager.active();
@@ -894,7 +898,7 @@ public final class DefaultServer implements SpiServer, SpiEbeanServer {
}
@Override
public void merge(Object bean, MergeOptions options, Transaction transaction) {
public void merge(Object bean, MergeOptions options, @Nullable Transaction transaction) {
BeanDescriptor<?> desc = descriptor(bean.getClass());
if (desc == null) {
throw new PersistenceException(bean.getClass().getName() + " is NOT an Entity Bean registered with this server?");
@@ -1040,7 +1044,7 @@ public final class DefaultServer implements SpiServer, SpiEbeanServer {
* Find a bean using its unique id.
*/
@Override
public <T> T find(Class<T> beanType, Object id, Transaction t) {
public <T> T find(Class<T> beanType, Object id, @Nullable Transaction t) {
if (id == null) {
throw new NullPointerException("The id is null");
}
@@ -1048,20 +1052,20 @@ public final class DefaultServer implements SpiServer, SpiEbeanServer {
return findId(query, t);
}
<T> SpiOrmQueryRequest<T> createQueryRequest(Type type, Query<T> query, Transaction t) {
<T> SpiOrmQueryRequest<T> createQueryRequest(Type type, Query<T> query, @Nullable Transaction t) {
SpiOrmQueryRequest<T> request = buildQueryRequest(type, query, t);
request.prepareQuery();
return request;
}
<T> SpiOrmQueryRequest<T> buildQueryRequest(Type type, Query<T> query, Transaction t) {
<T> SpiOrmQueryRequest<T> buildQueryRequest(Type type, Query<T> query, @Nullable Transaction t) {
SpiQuery<T> spiQuery = (SpiQuery<T>) query;
spiQuery.setType(type);
spiQuery.checkNamedParameters();
return buildQueryRequest(spiQuery, t);
}
private <T> SpiOrmQueryRequest<T> buildQueryRequest(SpiQuery<T> query, Transaction t) {
private <T> SpiOrmQueryRequest<T> buildQueryRequest(SpiQuery<T> query, @Nullable Transaction t) {
if (t == null) {
t = currentServerTransaction();
}
@@ -1088,7 +1092,7 @@ public final class DefaultServer implements SpiServer, SpiEbeanServer {
*/
@Nullable
@SuppressWarnings("unchecked")
private <T> T findIdCheckPersistenceContextAndCache(Transaction transaction, SpiQuery<T> query, Object id) {
private <T> T findIdCheckPersistenceContextAndCache(@Nullable Transaction transaction, SpiQuery<T> query, Object id) {
SpiTransaction t = (SpiTransaction) transaction;
if (t == null) {
t = currentServerTransaction();
@@ -1133,8 +1137,9 @@ public final class DefaultServer implements SpiServer, SpiEbeanServer {
return (scope != null) ? scope : defaultPersistenceContextScope;
}
@Nullable
@SuppressWarnings("unchecked")
private <T> T findId(Query<T> query, Transaction t) {
private <T> T findId(Query<T> query, @Nullable Transaction t) {
SpiQuery<T> spiQuery = (SpiQuery<T>) query;
spiQuery.setType(Type.BEAN);
if (SpiQuery.Mode.NORMAL == spiQuery.getMode() && !spiQuery.isForceHitDatabase()) {
@@ -1165,7 +1170,7 @@ public final class DefaultServer implements SpiServer, SpiEbeanServer {
@Nullable
@Override
public <T> T findOne(Query<T> query, Transaction transaction) {
public <T> T findOne(Query<T> query, @Nullable Transaction transaction) {
SpiQuery<T> spiQuery = (SpiQuery<T>) query;
if (spiQuery.isFindById()) {
// actually a find by Id query
@@ -1208,7 +1213,7 @@ public final class DefaultServer implements SpiServer, SpiEbeanServer {
@Override
@SuppressWarnings({"unchecked", "rawtypes"})
public <K, T> Map<K, T> findMap(Query<T> query, Transaction t) {
public <K, T> Map<K, T> findMap(Query<T> query, @Nullable Transaction t) {
SpiOrmQueryRequest request = createQueryRequest(Type.MAP, query, t);
request.resetBeanCacheAutoMode(false);
if ((t == null || !t.isSkipCache()) && request.getFromBeanCache()) {
@@ -1244,7 +1249,7 @@ public final class DefaultServer implements SpiServer, SpiEbeanServer {
}
@Override
public <T> int findCount(Query<T> query, Transaction t) {
public <T> int findCount(Query<T> query, @Nullable Transaction t) {
SpiQuery<T> spiQuery = ((SpiQuery<T>) query);
if (!spiQuery.isDistinct()) {
spiQuery = spiQuery.copy();
@@ -1253,7 +1258,7 @@ public final class DefaultServer implements SpiServer, SpiEbeanServer {
}
@Override
public <T> int findCountWithCopy(Query<T> query, Transaction t) {
public <T> int findCountWithCopy(Query<T> query, @Nullable Transaction t) {
SpiOrmQueryRequest<T> request = createQueryRequest(Type.COUNT, query, t);
Integer result = request.getFromQueryCache();
if (result != null) {
@@ -1463,7 +1468,7 @@ public final class DefaultServer implements SpiServer, SpiEbeanServer {
}
@Override
public <T> List<Version<T>> findVersions(Query<T> query, Transaction transaction) {
public <T> List<Version<T>> findVersions(Query<T> query, @Nullable Transaction transaction) {
SpiOrmQueryRequest<T> request = createQueryRequest(Type.LIST, query, transaction);
try {
request.initTransIfRequired();
@@ -1479,7 +1484,7 @@ public final class DefaultServer implements SpiServer, SpiEbeanServer {
}
@SuppressWarnings("unchecked")
private <T> List<T> findList(Query<T> query, Transaction t, boolean findOne) {
private <T> List<T> findList(Query<T> query, @Nullable Transaction t, boolean findOne) {
SpiOrmQueryRequest<T> request = buildQueryRequest(Type.LIST, query, t);
request.resetBeanCacheAutoMode(findOne);
if ((t == null || !t.isSkipCache()) && request.getFromBeanCache()) {
@@ -1669,7 +1674,7 @@ public final class DefaultServer implements SpiServer, SpiEbeanServer {
* Save the bean with an explicit transaction.
*/
@Override
public void save(Object bean, Transaction t) {
public void save(Object bean, @Nullable Transaction t) {
persister.save(checkEntityBean(bean), t);
}
@@ -1688,7 +1693,7 @@ public final class DefaultServer implements SpiServer, SpiEbeanServer {
}
@Override
public void update(Object bean, Transaction t) {
public void update(Object bean, @Nullable Transaction t) {
persister.update(checkEntityBean(bean), t);
}
@@ -1701,7 +1706,7 @@ public final class DefaultServer implements SpiServer, SpiEbeanServer {
* Update all beans in the collection with an explicit transaction.
*/
@Override
public void updateAll(Collection<?> beans, Transaction transaction) {
public void updateAll(@Nullable Collection<?> beans, @Nullable Transaction transaction) {
if (beans == null || beans.isEmpty()) {
return;
}
@@ -1725,7 +1730,7 @@ public final class DefaultServer implements SpiServer, SpiEbeanServer {
* Insert the bean with a transaction.
*/
@Override
public void insert(Object bean, Transaction t) {
public void insert(Object bean, @Nullable Transaction t) {
persister.insert(checkEntityBean(bean), t);
}
@@ -1741,7 +1746,7 @@ public final class DefaultServer implements SpiServer, SpiEbeanServer {
* Insert all beans in the collection with a transaction.
*/
@Override
public void insertAll(Collection<?> beans, Transaction transaction) {
public void insertAll(@Nullable Collection<?> beans, @Nullable Transaction transaction) {
if (beans == null || beans.isEmpty()) {
return;
}
@@ -1754,7 +1759,7 @@ public final class DefaultServer implements SpiServer, SpiEbeanServer {
}
@Override
public <T> List<T> publish(Query<T> query, Transaction transaction) {
public <T> List<T> publish(Query<T> query, @Nullable Transaction transaction) {
return executeInTrans((txn) -> persister.publish(query, txn), transaction);
}
@@ -1776,7 +1781,7 @@ public final class DefaultServer implements SpiServer, SpiEbeanServer {
}
@Override
public <T> List<T> draftRestore(Query<T> query, Transaction transaction) {
public <T> List<T> draftRestore(Query<T> query, @Nullable Transaction transaction) {
return executeInTrans((txn) -> persister.draftRestore(query, txn), transaction);
}
@@ -1825,7 +1830,7 @@ public final class DefaultServer implements SpiServer, SpiEbeanServer {
/**
* Save all beans in the iterator with an explicit transaction.
*/
private int saveAllInternal(Collection<?> beans, Transaction transaction) {
private int saveAllInternal(@Nullable Collection<?> beans, @Nullable Transaction transaction) {
if (beans == null || beans.isEmpty()) {
return 0;
}
@@ -1847,7 +1852,7 @@ public final class DefaultServer implements SpiServer, SpiEbeanServer {
}
@Override
public int delete(Class<?> beanType, Object id, Transaction transaction) {
public int delete(Class<?> beanType, Object id, @Nullable Transaction transaction) {
return delete(beanType, id, transaction, false);
}
@@ -1857,11 +1862,11 @@ public final class DefaultServer implements SpiServer, SpiEbeanServer {
}
@Override
public int deletePermanent(Class<?> beanType, Object id, Transaction transaction) {
public int deletePermanent(Class<?> beanType, Object id, @Nullable Transaction transaction) {
return delete(beanType, id, transaction, true);
}
private int delete(Class<?> beanType, Object id, Transaction transaction, boolean permanent) {
private int delete(Class<?> beanType, Object id, @Nullable Transaction transaction, boolean permanent) {
return executeInTrans((txn) -> persister.delete(beanType, id, txn, permanent), transaction);
}
@@ -1871,7 +1876,7 @@ public final class DefaultServer implements SpiServer, SpiEbeanServer {
}
@Override
public int deleteAll(Class<?> beanType, Collection<?> ids, Transaction t) {
public int deleteAll(Class<?> beanType, Collection<?> ids, @Nullable Transaction t) {
return deleteAll(beanType, ids, t, false);
}
@@ -1881,11 +1886,11 @@ public final class DefaultServer implements SpiServer, SpiEbeanServer {
}
@Override
public int deleteAllPermanent(Class<?> beanType, Collection<?> ids, Transaction t) {
public int deleteAllPermanent(Class<?> beanType, Collection<?> ids, @Nullable Transaction t) {
return deleteAll(beanType, ids, t, true);
}
private int deleteAll(Class<?> beanType, Collection<?> ids, Transaction transaction, boolean permanent) {
private int deleteAll(Class<?> beanType, Collection<?> ids, @Nullable Transaction transaction, boolean permanent) {
return executeInTrans((txn) -> persister.deleteMany(beanType, ids, txn, permanent), transaction);
}
@@ -1901,7 +1906,7 @@ public final class DefaultServer implements SpiServer, SpiEbeanServer {
* Delete the bean with the explicit transaction.
*/
@Override
public boolean delete(Object bean, Transaction t) throws OptimisticLockException {
public boolean delete(Object bean, @Nullable Transaction t) throws OptimisticLockException {
// this should really return an int where -1 means jdbc batch/unknown
return persister.delete(checkEntityBean(bean), t, false) != 0;
}
@@ -1912,7 +1917,7 @@ public final class DefaultServer implements SpiServer, SpiEbeanServer {
}
@Override
public boolean deletePermanent(Object bean, Transaction t) throws OptimisticLockException {
public boolean deletePermanent(Object bean, @Nullable Transaction t) throws OptimisticLockException {
// this should really return an int where -1 means jdbc batch/unknown
return persister.delete(checkEntityBean(bean), t, true) != 0;
}
@@ -1923,7 +1928,7 @@ public final class DefaultServer implements SpiServer, SpiEbeanServer {
}
@Override
public int deleteAllPermanent(Collection<?> beans, Transaction t) {
public int deleteAllPermanent(Collection<?> beans, @Nullable Transaction t) {
return deleteAllInternal(beans, t, true);
}
@@ -1939,14 +1944,14 @@ public final class DefaultServer implements SpiServer, SpiEbeanServer {
* Delete all the beans in the collection.
*/
@Override
public int deleteAll(Collection<?> beans, Transaction t) {
public int deleteAll(Collection<?> beans, @Nullable Transaction t) {
return deleteAllInternal(beans, t, false);
}
/**
* Delete all the beans in the iterator with an explicit transaction.
*/
private int deleteAllInternal(Collection<?> beans, Transaction transaction, boolean permanent) {
private int deleteAllInternal(@Nullable Collection<?> beans, @Nullable Transaction transaction, boolean permanent) {
if (beans == null || beans.isEmpty()) {
return 0;
}
@@ -1966,7 +1971,7 @@ public final class DefaultServer implements SpiServer, SpiEbeanServer {
* Execute the CallableSql with an explicit transaction.
*/
@Override
public int execute(CallableSql callSql, Transaction t) {
public int execute(CallableSql callSql, @Nullable Transaction t) {
return persister.executeCallable(callSql, t);
}
@@ -1982,7 +1987,7 @@ public final class DefaultServer implements SpiServer, SpiEbeanServer {
* Execute the updateSql with an explicit transaction.
*/
@Override
public int execute(SqlUpdate updSql, Transaction t) {
public int execute(SqlUpdate updSql, @Nullable Transaction t) {
return persister.executeSqlUpdate(updSql, t);
}
@@ -1992,12 +1997,12 @@ public final class DefaultServer implements SpiServer, SpiEbeanServer {
}
@Override
public void addBatch(SpiSqlUpdate sqlUpdate, SpiTransaction transaction) {
public void addBatch(SpiSqlUpdate sqlUpdate, @Nullable SpiTransaction transaction) {
persister.addBatch(sqlUpdate, transaction);
}
@Override
public int[] executeBatch(SpiSqlUpdate sqlUpdate, SpiTransaction transaction) {
public int[] executeBatch(SpiSqlUpdate sqlUpdate, @Nullable SpiTransaction transaction) {
return persister.executeBatch(sqlUpdate, transaction);
}
@@ -2013,7 +2018,7 @@ public final class DefaultServer implements SpiServer, SpiEbeanServer {
* Execute the updateSql with an explicit transaction.
*/
@Override
public int execute(Update<?> update, Transaction t) {
public int execute(Update<?> update, @Nullable Transaction t) {
return persister.executeOrmUpdate(update, t);
}
@@ -2171,7 +2176,7 @@ public final class DefaultServer implements SpiServer, SpiEbeanServer {
}
}
private <P> P executeInTrans(Function<SpiTransaction, P> fun, Transaction t) {
private <P> P executeInTrans(Function<SpiTransaction, P> fun, @Nullable Transaction t) {
ObtainedTransaction wrap = initTransIfRequired(t);
try {
P result = fun.apply(wrap.transaction());
@@ -2188,7 +2193,7 @@ public final class DefaultServer implements SpiServer, SpiEbeanServer {
/**
* Create a transaction if one is not currently active.
*/
ObtainedTransaction initTransIfRequired(Transaction t) {
ObtainedTransaction initTransIfRequired(@Nullable Transaction t) {
if (t != null) {
return new ObtainedTransaction((SpiTransaction) t);
}
@@ -2256,7 +2261,7 @@ public final class DefaultServer implements SpiServer, SpiEbeanServer {
}
@Override
public Set<Property> checkUniqueness(Object bean, Transaction transaction) {
public Set<Property> checkUniqueness(Object bean, @Nullable Transaction transaction) {
EntityBean entityBean = checkEntityBean(bean);
BeanDescriptor<?> beanDesc = descriptor(entityBean.getClass());
BeanProperty idProperty = beanDesc.idProperty();
@@ -2286,7 +2291,7 @@ public final class DefaultServer implements SpiServer, SpiEbeanServer {
* Returns a set of properties if saving the bean will violate the unique constraints (defined by given properties).
*/
@Nullable
private Set<Property> checkUniqueness(EntityBean entityBean, BeanDescriptor<?> beanDesc, BeanProperty[] props, Transaction transaction) {
private Set<Property> checkUniqueness(EntityBean entityBean, BeanDescriptor<?> beanDesc, BeanProperty[] props, @Nullable Transaction transaction) {
BeanProperty idProperty = beanDesc.idProperty();
Query<?> query = new DefaultOrmQuery<>(beanDesc, this, expressionFactory);
ExpressionList<?> exprList = query.where();
@@ -1,5 +1,6 @@
package io.ebeaninternal.server.el;
import io.avaje.lang.NonNullApi;
import io.ebean.Filter;
import io.ebeaninternal.server.deploy.BeanDescriptor;
@@ -11,6 +12,7 @@ import java.util.regex.Pattern;
/**
* Default implementation of the Filter interface.
*/
@NonNullApi
public final class ElFilter<T> implements Filter<T> {
private final BeanDescriptor<T> beanDescriptor;
@@ -1,5 +1,6 @@
package io.ebeaninternal.server.executor;
import io.avaje.lang.NonNullApi;
import io.ebeaninternal.api.SpiBackgroundExecutor;
import org.slf4j.MDC;
@@ -13,6 +14,7 @@ import java.util.concurrent.TimeUnit;
/**
* The default implementation of the BackgroundExecutor.
*/
@NonNullApi
public final class DefaultBackgroundExecutor implements SpiBackgroundExecutor {
private final ScheduledExecutorService executor;
@@ -1,5 +1,7 @@
package io.ebeaninternal.server.expression;
import io.avaje.lang.NonNullApi;
import io.avaje.lang.Nullable;
import io.ebean.CacheMode;
import io.ebean.CountDistinctOrder;
import io.ebean.DtoQuery;
@@ -51,6 +53,7 @@ import java.util.function.Predicate;
/**
* Default implementation of ExpressionList.
*/
@NonNullApi
public class DefaultExpressionList<T> implements SpiExpressionList<T> {
private static final String AND = " and ";
@@ -469,6 +472,7 @@ public class DefaultExpressionList<T> implements SpiExpressionList<T> {
return query.exists();
}
@Nullable
@Override
public T findOne() {
return query.findOne();
@@ -1,23 +1,15 @@
package io.ebeaninternal.server.expression;
import io.ebean.ExpressionFactory;
import io.ebean.ExpressionList;
import io.ebean.FutureIds;
import io.ebean.FutureList;
import io.ebean.FutureRowCount;
import io.ebean.Junction;
import io.ebean.OrderBy;
import io.ebean.Query;
import io.avaje.lang.NonNullApi;
import io.avaje.lang.Nullable;
import io.ebean.*;
import io.ebeaninternal.api.SpiExpressionList;
import io.ebeaninternal.api.SpiQuery;
import javax.persistence.PersistenceException;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.*;
@NonNullApi
public final class FilterExpressionList<T> extends DefaultExpressionList<T> {
private static final String notAllowedMessage = "This method is not allowed on a filter";
@@ -92,6 +84,7 @@ public final class FilterExpressionList<T> extends DefaultExpressionList<T> {
return rootQuery.findSet();
}
@Nullable
@Override
public T findOne() {
return rootQuery.findOne();
@@ -1,5 +1,7 @@
package io.ebeaninternal.server.expression;
import io.avaje.lang.NonNullApi;
import io.avaje.lang.Nullable;
import io.ebean.CacheMode;
import io.ebean.CountDistinctOrder;
import io.ebean.DtoQuery;
@@ -48,6 +50,7 @@ import java.util.function.Predicate;
/**
* Junction implementation.
*/
@NonNullApi
final class JunctionExpression<T> implements SpiJunction<T>, SpiExpression, ExpressionList<T> {
DefaultExpressionList<T> exprList;
@@ -476,6 +479,7 @@ final class JunctionExpression<T> implements SpiJunction<T>, SpiExpression, Expr
return exprList.findSet();
}
@Nullable
@Override
public T findOne() {
return exprList.findOne();
@@ -1,5 +1,6 @@
package io.ebeaninternal.server.query;
import io.avaje.lang.NonNullApi;
import io.ebean.FetchConfig;
import io.ebean.FetchGroup;
import io.ebean.FetchGroupBuilder;
@@ -9,14 +10,12 @@ import io.ebeaninternal.server.querydefn.SpiFetchGroup;
/**
* Default implementation of the FetchGroupBuilder.
*/
@NonNullApi
final class DFetchGroupBuilder<T> implements FetchGroupBuilder<T> {
private static final FetchConfig DEFAULT_FETCH = FetchConfig.ofDefault();
private static final FetchConfig FETCH_CACHE = FetchConfig.ofCache();
private static final FetchConfig FETCH_QUERY = FetchConfig.ofQuery();
private static final FetchConfig FETCH_LAZY = FetchConfig.ofLazy();
private final OrmQueryDetail detail;
@@ -38,22 +37,22 @@ final class DFetchGroupBuilder<T> implements FetchGroupBuilder<T> {
}
@Override
public FetchGroupBuilder<T> fetch(String path, FetchGroup nestedGroup) {
public FetchGroupBuilder<T> fetch(String path, FetchGroup<?> nestedGroup) {
return fetchNested(path, nestedGroup, DEFAULT_FETCH);
}
@Override
public FetchGroupBuilder<T> fetchQuery(String path, FetchGroup nestedGroup) {
public FetchGroupBuilder<T> fetchQuery(String path, FetchGroup<?> nestedGroup) {
return fetchNested(path, nestedGroup, FETCH_QUERY);
}
@Override
public FetchGroupBuilder<T> fetchLazy(String path, FetchGroup nestedGroup) {
public FetchGroupBuilder<T> fetchLazy(String path, FetchGroup<?> nestedGroup) {
return fetchNested(path, nestedGroup, FETCH_LAZY);
}
private FetchGroupBuilder<T> fetchNested(String path, FetchGroup nestedGroup, FetchConfig fetchConfig) {
OrmQueryDetail nestedDetail = ((SpiFetchGroup) nestedGroup).underlying();
private FetchGroupBuilder<T> fetchNested(String path, FetchGroup<?> nestedGroup, FetchConfig fetchConfig) {
OrmQueryDetail nestedDetail = ((SpiFetchGroup<?>) nestedGroup).underlying();
detail.addNested(path, nestedDetail, fetchConfig);
return this;
}
@@ -1,5 +1,7 @@
package io.ebeaninternal.server.query;
import io.avaje.lang.NonNullApi;
import io.avaje.lang.Nullable;
import io.ebean.CacheMode;
import io.ebean.CountDistinctOrder;
import io.ebean.Database;
@@ -29,7 +31,6 @@ import io.ebeaninternal.api.SpiQueryFetch;
import io.ebeaninternal.server.querydefn.OrmQueryDetail;
import io.ebeaninternal.server.querydefn.SpiFetchGroup;
import javax.annotation.Nullable;
import java.sql.Connection;
import java.sql.Timestamp;
import java.util.List;
@@ -43,6 +44,7 @@ import java.util.stream.Stream;
/**
* Implementation of FetchGroup query for use to create FetchGroup via query beans.
*/
@NonNullApi
final class DefaultFetchGroupQuery<T> implements SpiFetchGroupQuery<T>, SpiQueryFetch {
private static final FetchConfig FETCH_CACHE = FetchConfig.ofCache();
@@ -64,6 +66,7 @@ final class DefaultFetchGroupQuery<T> implements SpiFetchGroupQuery<T>, SpiQuery
return this;
}
@SuppressWarnings("rawtypes")
@Override
public Query<T> select(FetchGroup fetchGroup) {
this.detail = ((SpiFetchGroup) fetchGroup).detail();
@@ -116,7 +119,7 @@ final class DefaultFetchGroupQuery<T> implements SpiFetchGroupQuery<T>, SpiQuery
}
@Override
public Query<T> fetch(String property, String columns, FetchConfig config) {
public Query<T> fetch(String property, @Nullable String columns, @Nullable FetchConfig config) {
detail.fetch(property, columns, config);
return this;
}
@@ -1,5 +1,6 @@
package io.ebeaninternal.server.querydefn;
import io.avaje.lang.NonNullApi;
import io.ebean.DtoQuery;
import io.ebean.ProfileLocation;
import io.ebean.QueryIterator;
@@ -22,6 +23,7 @@ import java.util.stream.Stream;
/**
* Default implementation of DtoQuery.
*/
@NonNullApi
public final class DefaultDtoQuery<T> extends AbstractQuery implements SpiDtoQuery<T> {
private final SpiEbeanServer server;
@@ -208,6 +210,7 @@ public final class DefaultDtoQuery<T> extends AbstractQuery implements SpiDtoQue
return label;
}
@Nullable
@Override
public String getPlanLabel() {
if (label != null) {
@@ -1,5 +1,6 @@
package io.ebeaninternal.server.querydefn;
import io.avaje.lang.NonNullApi;
import io.ebean.*;
import io.ebean.OrderBy.Property;
import io.ebean.bean.CallOrigin;
@@ -30,6 +31,7 @@ import java.util.stream.Stream;
/**
* Default implementation of an Object Relational query.
*/
@NonNullApi
public final class DefaultOrmQuery<T> extends AbstractQuery implements SpiQuery<T> {
private static final String DEFAULT_QUERY_NAME = "default";
@@ -1,5 +1,7 @@
package io.ebeaninternal.server.querydefn;
import io.avaje.lang.NonNullApi;
import io.avaje.lang.Nullable;
import io.ebean.RowConsumer;
import io.ebean.RowMapper;
import io.ebean.SqlQuery;
@@ -17,6 +19,7 @@ import java.util.function.Predicate;
/**
* Default implementation of SQuery - SQL Query.
*/
@NonNullApi
public final class DefaultRelationalQuery extends AbstractQuery implements SpiSqlQuery {
private static final long serialVersionUID = -1098305779779591068L;
@@ -263,6 +266,7 @@ public final class DefaultRelationalQuery extends AbstractQuery implements SpiSq
this.mapper = mapper;
}
@Nullable
@Override
public T findOne() {
return mapperFindOne(mapper);
@@ -1,5 +1,6 @@
package io.ebeanservice.docstore.none;
import io.avaje.lang.NonNullApi;
import io.ebean.DocStoreQueueEntry;
import io.ebean.DocumentStore;
import io.ebean.PagedList;
@@ -16,6 +17,7 @@ import java.util.function.Predicate;
/**
* DocumentStore that barfs it is used.
*/
@NonNullApi
public final class NoneDocStore implements DocumentStore {
public static IllegalStateException implementationNotInClassPath() {
+2 -3
View File
@@ -27,9 +27,8 @@
-->
<dependency>
<groupId>io.avaje</groupId>
<artifactId>avaje-jsr305</artifactId>
<version>1.1</version>
<scope>provided</scope>
<artifactId>avaje-lang</artifactId>
<version>1.0</version>
</dependency>
<dependency>
@@ -1,24 +1,8 @@
package io.ebean.typequery;
import io.ebean.CacheMode;
import io.ebean.DB;
import io.ebean.Database;
import io.ebean.DtoQuery;
import io.ebean.ExpressionList;
import io.ebean.FetchConfig;
import io.ebean.FetchGroup;
import io.ebean.FutureIds;
import io.ebean.FutureList;
import io.ebean.FutureRowCount;
import io.ebean.PagedList;
import io.ebean.PersistenceContextScope;
import io.ebean.ProfileLocation;
import io.ebean.Query;
import io.ebean.QueryIterator;
import io.ebean.RawSql;
import io.ebean.Transaction;
import io.ebean.UpdateQuery;
import io.ebean.Version;
import io.avaje.lang.NonNullApi;
import io.avaje.lang.Nullable;
import io.ebean.*;
import io.ebean.search.MultiMatch;
import io.ebean.search.TextCommonTerms;
import io.ebean.search.TextQueryString;
@@ -28,15 +12,9 @@ import io.ebean.text.PathProperties;
import io.ebeaninternal.api.SpiQueryFetch;
import io.ebeaninternal.server.util.ArrayStack;
import javax.annotation.Nullable;
import java.sql.Connection;
import java.sql.Timestamp;
import java.util.Collection;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.*;
import java.util.function.Consumer;
import java.util.function.Predicate;
import java.util.stream.Stream;
@@ -80,6 +58,7 @@ import java.util.stream.Stream;
* @param <T> the entity bean type (normal entity bean type e.g. Customer)
* @param <R> the specific root query bean type (e.g. QCustomer)
*/
@NonNullApi
public abstract class TQRootBean<T, R> {
/**
@@ -1,19 +1,9 @@
package org.querytest;
import io.ebean.DB;
import io.ebean.Database;
import io.ebean.PagedList;
import io.ebean.Query;
import io.ebean.QueryIterator;
import io.ebean.Transaction;
import io.ebean.*;
import io.ebean.annotation.Transactional;
import io.ebean.types.Inet;
import org.example.domain.ACat;
import org.example.domain.ADog;
import org.example.domain.Address;
import org.example.domain.Animal;
import org.example.domain.Country;
import org.example.domain.Customer;
import org.example.domain.*;
import org.example.domain.otherpackage.PhoneNumber;
import org.example.domain.otherpackage.ValidEmail;
import org.example.domain.query.QAnimal;
@@ -26,15 +16,7 @@ import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.StringJoiner;
import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Stream;
@@ -155,23 +137,21 @@ public class QCustomerTest {
assertThat(ids).isNotEmpty();
Map<List, Customer> map = new QCustomer()
Map<Long, Customer> map = new QCustomer()
.status.equalTo(Customer.Status.GOOD)
.findMap();
assertThat(map.size()).isEqualTo(ids.size());
QueryIterator<Customer> iterate = new QCustomer()
.status.equalTo(Customer.Status.GOOD)
.findIterate();
try (QueryIterator<Customer> iterate =
new QCustomer()
.status.equalTo(Customer.Status.GOOD)
.findIterate()) {
try {
while (iterate.hasNext()) {
Customer customer = iterate.next();
assertThat(customer.getName()).isNotNull();
}
} finally {
iterate.close();
}
}
@@ -1,5 +1,6 @@
package io.ebeaninternal.api;
import io.avaje.lang.NonNullApi;
import io.ebean.*;
import io.ebean.annotation.Platform;
import io.ebean.annotation.TxIsolation;
@@ -37,6 +38,7 @@ import java.util.stream.Stream;
/**
* Test double for SpiEbeanServer.
*/
@NonNullApi
public class TDSpiEbeanServer extends TDSpiServer implements SpiEbeanServer {
String name;
@@ -1,5 +1,6 @@
package io.ebeaninternal.api;
import io.avaje.lang.NonNullApi;
import io.ebean.*;
import io.ebean.annotation.Platform;
import io.ebean.annotation.TxIsolation;
@@ -25,6 +26,7 @@ import java.util.Map;
import java.util.Set;
import java.util.concurrent.Callable;
@NonNullApi
public class TDSpiServer implements SpiServer {
@Override
public void shutdown() {
@@ -15,6 +15,7 @@ import io.ebeaninternal.server.transaction.RemoteTransactionEvent;
import org.junit.jupiter.api.Test;
import org.tests.model.basic.Customer;
import javax.annotation.Nonnull;
import java.io.IOException;
import java.util.Collections;
import java.util.HashSet;
@@ -99,8 +100,9 @@ public class BinaryTransactionEventReadWriteTest extends BaseTestCase {
}
class TDEbeanServer extends TDSpiEbeanServer {
@Nonnull
@Override
public BeanDescriptor<?> descriptorById(String descriptorId) {
public BeanDescriptor<?> descriptorById(@Nonnull String descriptorId) {
return customerBeanDescriptor;
}
}
+1 -1
View File
@@ -90,7 +90,7 @@
<module>ebean-querybean</module>
<module>ebean-postgis</module>
<module>ebean-redis</module>
<!-- <module>tests</module>-->
<module>tests</module>
</modules>
</project>
+1 -1
View File
@@ -95,7 +95,7 @@
<id>test</id>
<phase>process-test-classes</phase>
<configuration>
<transformArgs>debug=5</transformArgs>
<transformArgs>debug=1</transformArgs>
</configuration>
<goals>
<goal>testEnhance</goal>
@@ -0,0 +1,32 @@
package io.ebean.test.kotlin
import io.ebean.DB
import org.assertj.core.api.Assertions.assertThat
import org.example.order.Customer
import org.junit.jupiter.api.Test
class BasicInsertQueryTest {
@Test
fun `insert find`() {
val customer = Customer("HelloThere")
DB.save(customer)
val found = DB.find(Customer::class.java)
.setId(customer.id)
.findOne()
val name = found?.name
assertThat(name).isEqualTo("HelloThere")
assertThat(found).isNotNull
val list = DB.find(Customer::class.java)
.findList()
list.size
assertThat(list).isNotEmpty
DB.delete(customer)
}
}