diff --git a/.github/workflows/jdk-ea.yml b/.github/workflows/jdk-ea.yml index f34c50d76..df2546c9b 100644 --- a/.github/workflows/jdk-ea.yml +++ b/.github/workflows/jdk-ea.yml @@ -18,7 +18,7 @@ jobs: matrix: ## valhalla - failing on javadoc with: ## javadoc: error - The code being documented uses packages in the unnamed module, but the packages defined in https://ebean.io/platforms/ebean-platform-h2/apidocs/ are in named modules. - java_version: [17,18,19,loom,metropolis,panama] + java_version: [GA,EA,loom,metropolis,panama] os: [ubuntu-latest] steps: diff --git a/README.md b/README.md index 694c73f96..83bcbae96 100644 --- a/README.md +++ b/README.md @@ -55,9 +55,38 @@ Post questions or issues to the Ebean google group - https://groups.google.com/f ## Documentation Goto [https://ebean.io/docs/](https://ebean.io/docs/) - ## Maven central [Maven central - io.ebean](http://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22io.ebean%22%20) +## Building Ebean from source + +- JDK 11 or higher installed +- Maven installed +- `git clone git@github.com:ebean-orm/ebean.git` +- `mvn clean install` + +Ebean 13 uses Java modules with module-info. This means that there are stricter compilation +rules in place now than when building with classpath pre version 13. + +For Maven Surefire testing we use `false` such +that tests run using classpath and not module-path. We are doing this until all the tooling +(Maven, IDE) improves in the area of testing with module-info. + +#### Eclipse IDE + +Right now we can't use Eclipse IDE to build Ebean and run its tests due to its poor support +for java modules. See [ebean/issues/2653](https://github.com/ebean-orm/ebean/issues/2653) + +The current recommendation is to use IntelliJ IDEA as the IDE to build and hack Ebean. + + +#### IntelliJ IDEA + +We want to get IntelliJ to run tests using classpath similar to Maven Surefire. To do this set: +`JUnit -> modify options -> Do not use module-path option` + +To set this option as the global default for IntelliJ use: + +`Run - Edit Configurations -> Edit configuration templates -> JUnit -> modify options - Do not use module-path option` diff --git a/composites/ebean-clickhouse/pom.xml b/composites/ebean-clickhouse/pom.xml index 838cd761d..b43b6b5ba 100644 --- a/composites/ebean-clickhouse/pom.xml +++ b/composites/ebean-clickhouse/pom.xml @@ -4,7 +4,7 @@ composites io.ebean - 13.3.1-SNAPSHOT + 13.6.0-SNAPSHOT ebean-clickhouse @@ -16,13 +16,13 @@ io.ebean ebean-api - 13.3.1-SNAPSHOT + 13.6.0-SNAPSHOT io.ebean ebean-core - 13.3.1-SNAPSHOT + 13.6.0-SNAPSHOT @@ -35,13 +35,13 @@ io.ebean ebean-querybean - 13.3.1-SNAPSHOT + 13.6.0-SNAPSHOT io.ebean ebean-platform-clickhouse - 13.3.1-SNAPSHOT + 13.6.0-SNAPSHOT diff --git a/composites/ebean-cockroach/pom.xml b/composites/ebean-cockroach/pom.xml index ed902d0d8..5b38f55ed 100644 --- a/composites/ebean-cockroach/pom.xml +++ b/composites/ebean-cockroach/pom.xml @@ -4,7 +4,7 @@ composites io.ebean - 13.3.1-SNAPSHOT + 13.6.0-SNAPSHOT ebean-cockroach @@ -16,13 +16,13 @@ io.ebean ebean-api - 13.3.1-SNAPSHOT + 13.6.0-SNAPSHOT io.ebean ebean-core - 13.3.1-SNAPSHOT + 13.6.0-SNAPSHOT @@ -35,13 +35,13 @@ io.ebean ebean-querybean - 13.3.1-SNAPSHOT + 13.6.0-SNAPSHOT io.ebean ebean-platform-postgres - 13.3.1-SNAPSHOT + 13.6.0-SNAPSHOT diff --git a/composites/ebean-db2/pom.xml b/composites/ebean-db2/pom.xml index 26e1ca1ab..1ed7bd8db 100644 --- a/composites/ebean-db2/pom.xml +++ b/composites/ebean-db2/pom.xml @@ -4,7 +4,7 @@ composites io.ebean - 13.3.1-SNAPSHOT + 13.6.0-SNAPSHOT ebean-db2 @@ -16,13 +16,13 @@ io.ebean ebean-api - 13.3.1-SNAPSHOT + 13.6.0-SNAPSHOT io.ebean ebean-core - 13.3.1-SNAPSHOT + 13.6.0-SNAPSHOT @@ -35,13 +35,13 @@ io.ebean ebean-querybean - 13.3.1-SNAPSHOT + 13.6.0-SNAPSHOT io.ebean ebean-platform-db2 - 13.3.1-SNAPSHOT + 13.6.0-SNAPSHOT diff --git a/composites/ebean-h2/pom.xml b/composites/ebean-h2/pom.xml index 16a25b8ef..b0fda461b 100644 --- a/composites/ebean-h2/pom.xml +++ b/composites/ebean-h2/pom.xml @@ -4,7 +4,7 @@ composites io.ebean - 13.3.1-SNAPSHOT + 13.6.0-SNAPSHOT ebean-h2 @@ -16,13 +16,13 @@ io.ebean ebean-api - 13.3.1-SNAPSHOT + 13.6.0-SNAPSHOT io.ebean ebean-core - 13.3.1-SNAPSHOT + 13.6.0-SNAPSHOT @@ -35,13 +35,13 @@ io.ebean ebean-querybean - 13.3.1-SNAPSHOT + 13.6.0-SNAPSHOT io.ebean ebean-platform-h2 - 13.3.1-SNAPSHOT + 13.6.0-SNAPSHOT diff --git a/composites/ebean-hana/pom.xml b/composites/ebean-hana/pom.xml index 5a380c065..11d34300e 100644 --- a/composites/ebean-hana/pom.xml +++ b/composites/ebean-hana/pom.xml @@ -4,7 +4,7 @@ composites io.ebean - 13.3.1-SNAPSHOT + 13.6.0-SNAPSHOT ebean-hana @@ -16,13 +16,13 @@ io.ebean ebean-api - 13.3.1-SNAPSHOT + 13.6.0-SNAPSHOT io.ebean ebean-core - 13.3.1-SNAPSHOT + 13.6.0-SNAPSHOT @@ -35,13 +35,13 @@ io.ebean ebean-querybean - 13.3.1-SNAPSHOT + 13.6.0-SNAPSHOT io.ebean ebean-platform-hana - 13.3.1-SNAPSHOT + 13.6.0-SNAPSHOT diff --git a/composites/ebean-mariadb/pom.xml b/composites/ebean-mariadb/pom.xml index d83c273cc..f8d38d833 100644 --- a/composites/ebean-mariadb/pom.xml +++ b/composites/ebean-mariadb/pom.xml @@ -4,7 +4,7 @@ composites io.ebean - 13.3.1-SNAPSHOT + 13.6.0-SNAPSHOT ebean-mariadb @@ -16,13 +16,13 @@ io.ebean ebean-api - 13.3.1-SNAPSHOT + 13.6.0-SNAPSHOT io.ebean ebean-core - 13.3.1-SNAPSHOT + 13.6.0-SNAPSHOT @@ -35,13 +35,13 @@ io.ebean ebean-querybean - 13.3.1-SNAPSHOT + 13.6.0-SNAPSHOT io.ebean ebean-platform-mariadb - 13.3.1-SNAPSHOT + 13.6.0-SNAPSHOT diff --git a/composites/ebean-mysql/pom.xml b/composites/ebean-mysql/pom.xml index 09b6fb24f..a07384e7c 100644 --- a/composites/ebean-mysql/pom.xml +++ b/composites/ebean-mysql/pom.xml @@ -4,7 +4,7 @@ composites io.ebean - 13.3.1-SNAPSHOT + 13.6.0-SNAPSHOT ebean-mysql @@ -16,13 +16,13 @@ io.ebean ebean-api - 13.3.1-SNAPSHOT + 13.6.0-SNAPSHOT io.ebean ebean-core - 13.3.1-SNAPSHOT + 13.6.0-SNAPSHOT @@ -35,13 +35,13 @@ io.ebean ebean-querybean - 13.3.1-SNAPSHOT + 13.6.0-SNAPSHOT io.ebean ebean-platform-mysql - 13.3.1-SNAPSHOT + 13.6.0-SNAPSHOT diff --git a/composites/ebean-nuodb/pom.xml b/composites/ebean-nuodb/pom.xml index ba3e4a9f8..4a2c3c4ae 100644 --- a/composites/ebean-nuodb/pom.xml +++ b/composites/ebean-nuodb/pom.xml @@ -4,7 +4,7 @@ composites io.ebean - 13.3.1-SNAPSHOT + 13.6.0-SNAPSHOT ebean-nuodb @@ -16,13 +16,13 @@ io.ebean ebean-api - 13.3.1-SNAPSHOT + 13.6.0-SNAPSHOT io.ebean ebean-core - 13.3.1-SNAPSHOT + 13.6.0-SNAPSHOT @@ -35,13 +35,13 @@ io.ebean ebean-querybean - 13.3.1-SNAPSHOT + 13.6.0-SNAPSHOT io.ebean ebean-platform-nuodb - 13.3.1-SNAPSHOT + 13.6.0-SNAPSHOT diff --git a/composites/ebean-oracle/pom.xml b/composites/ebean-oracle/pom.xml index d558a5b0f..bf32f16b9 100644 --- a/composites/ebean-oracle/pom.xml +++ b/composites/ebean-oracle/pom.xml @@ -4,7 +4,7 @@ composites io.ebean - 13.3.1-SNAPSHOT + 13.6.0-SNAPSHOT ebean-oracle @@ -16,13 +16,13 @@ io.ebean ebean-api - 13.3.1-SNAPSHOT + 13.6.0-SNAPSHOT io.ebean ebean-core - 13.3.1-SNAPSHOT + 13.6.0-SNAPSHOT @@ -35,13 +35,13 @@ io.ebean ebean-querybean - 13.3.1-SNAPSHOT + 13.6.0-SNAPSHOT io.ebean ebean-platform-oracle - 13.3.1-SNAPSHOT + 13.6.0-SNAPSHOT diff --git a/composites/ebean-postgres/pom.xml b/composites/ebean-postgres/pom.xml index 3f9d4085c..4dcd62dea 100644 --- a/composites/ebean-postgres/pom.xml +++ b/composites/ebean-postgres/pom.xml @@ -4,7 +4,7 @@ composites io.ebean - 13.3.1-SNAPSHOT + 13.6.0-SNAPSHOT ebean-postgres @@ -16,13 +16,13 @@ io.ebean ebean-api - 13.3.1-SNAPSHOT + 13.6.0-SNAPSHOT io.ebean ebean-core - 13.3.1-SNAPSHOT + 13.6.0-SNAPSHOT @@ -35,13 +35,13 @@ io.ebean ebean-querybean - 13.3.1-SNAPSHOT + 13.6.0-SNAPSHOT io.ebean ebean-platform-postgres - 13.3.1-SNAPSHOT + 13.6.0-SNAPSHOT diff --git a/composites/ebean-sqlite/pom.xml b/composites/ebean-sqlite/pom.xml index 9cef6eb30..695e37722 100644 --- a/composites/ebean-sqlite/pom.xml +++ b/composites/ebean-sqlite/pom.xml @@ -4,7 +4,7 @@ composites io.ebean - 13.3.1-SNAPSHOT + 13.6.0-SNAPSHOT ebean-sqlite @@ -16,13 +16,13 @@ io.ebean ebean-api - 13.3.1-SNAPSHOT + 13.6.0-SNAPSHOT io.ebean ebean-core - 13.3.1-SNAPSHOT + 13.6.0-SNAPSHOT @@ -35,13 +35,13 @@ io.ebean ebean-querybean - 13.3.1-SNAPSHOT + 13.6.0-SNAPSHOT io.ebean ebean-platform-sqlite - 13.3.1-SNAPSHOT + 13.6.0-SNAPSHOT diff --git a/composites/ebean-sqlserver/pom.xml b/composites/ebean-sqlserver/pom.xml index 8a7e3d710..2457b1ece 100644 --- a/composites/ebean-sqlserver/pom.xml +++ b/composites/ebean-sqlserver/pom.xml @@ -4,7 +4,7 @@ composites io.ebean - 13.3.1-SNAPSHOT + 13.6.0-SNAPSHOT ebean-sqlserver @@ -16,13 +16,13 @@ io.ebean ebean-api - 13.3.1-SNAPSHOT + 13.6.0-SNAPSHOT io.ebean ebean-core - 13.3.1-SNAPSHOT + 13.6.0-SNAPSHOT @@ -35,13 +35,13 @@ io.ebean ebean-querybean - 13.3.1-SNAPSHOT + 13.6.0-SNAPSHOT io.ebean ebean-platform-sqlserver - 13.3.1-SNAPSHOT + 13.6.0-SNAPSHOT diff --git a/composites/ebean-yugabyte/pom.xml b/composites/ebean-yugabyte/pom.xml index f9a25c775..3fd71f246 100644 --- a/composites/ebean-yugabyte/pom.xml +++ b/composites/ebean-yugabyte/pom.xml @@ -4,7 +4,7 @@ composites io.ebean - 13.3.1-SNAPSHOT + 13.6.0-SNAPSHOT ebean-yugabyte @@ -16,13 +16,13 @@ io.ebean ebean-api - 13.3.1-SNAPSHOT + 13.6.0-SNAPSHOT io.ebean ebean-core - 13.3.1-SNAPSHOT + 13.6.0-SNAPSHOT @@ -35,13 +35,13 @@ io.ebean ebean-querybean - 13.3.1-SNAPSHOT + 13.6.0-SNAPSHOT io.ebean ebean-platform-postgres - 13.3.1-SNAPSHOT + 13.6.0-SNAPSHOT diff --git a/composites/ebean/pom.xml b/composites/ebean/pom.xml index 93dac2314..0d7ad0af7 100644 --- a/composites/ebean/pom.xml +++ b/composites/ebean/pom.xml @@ -4,7 +4,7 @@ composites io.ebean - 13.3.1-SNAPSHOT + 13.6.0-SNAPSHOT ebean (all platforms) @@ -16,13 +16,13 @@ io.ebean ebean-api - 13.3.1-SNAPSHOT + 13.6.0-SNAPSHOT io.ebean ebean-core - 13.3.1-SNAPSHOT + 13.6.0-SNAPSHOT @@ -35,13 +35,13 @@ io.ebean ebean-querybean - 13.3.1-SNAPSHOT + 13.6.0-SNAPSHOT io.ebean ebean-platform-all - 13.3.1-SNAPSHOT + 13.6.0-SNAPSHOT diff --git a/composites/pom.xml b/composites/pom.xml index b5737db90..d7c460c66 100644 --- a/composites/pom.xml +++ b/composites/pom.xml @@ -4,7 +4,7 @@ ebean-parent io.ebean - 13.3.1-SNAPSHOT + 13.6.0-SNAPSHOT composites diff --git a/ebean-api/pom.xml b/ebean-api/pom.xml index d093864a0..85e97369c 100644 --- a/ebean-api/pom.xml +++ b/ebean-api/pom.xml @@ -4,7 +4,7 @@ ebean-parent io.ebean - 13.3.1-SNAPSHOT + 13.6.0-SNAPSHOT ebean api diff --git a/ebean-api/src/main/java/io/ebean/BackgroundExecutor.java b/ebean-api/src/main/java/io/ebean/BackgroundExecutor.java index f553933db..4941f2058 100644 --- a/ebean-api/src/main/java/io/ebean/BackgroundExecutor.java +++ b/ebean-api/src/main/java/io/ebean/BackgroundExecutor.java @@ -39,26 +39,6 @@ public interface BackgroundExecutor { */ void execute(Runnable task); - /** - * Deprecated - migrate to scheduleWithFixedDelay(). - * Execute a task periodically with a fixed delay between each execution. - *

- * For example, execute a runnable every minute. - *

- * The delay is the time between executions no matter how long the task took. - * That is, this method has the same behaviour characteristics as - * {@link ScheduledExecutorService#scheduleWithFixedDelay(Runnable, long, long, TimeUnit)} - */ - @Deprecated - void executePeriodically(Runnable task, long delay, TimeUnit unit); - - /** - * Deprecated - migrate to scheduleWithFixedDelay(). - * Execute a task periodically additionally with an initial delay different from delay. - */ - @Deprecated - void executePeriodically(Runnable task, long initialDelay, long delay, TimeUnit unit); - /** * Execute a task periodically with a given delay. * diff --git a/ebean-api/src/main/java/io/ebean/Ebean.java b/ebean-api/src/main/java/io/ebean/Ebean.java deleted file mode 100644 index f58c9dac0..000000000 --- a/ebean-api/src/main/java/io/ebean/Ebean.java +++ /dev/null @@ -1,1226 +0,0 @@ -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.persistence.OptimisticLockException; -import javax.persistence.PersistenceException; -import java.util.Collection; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.concurrent.Callable; - -/** - * Deprecated - please migrate to use io.ebean.DB. - *

- * Ebean is a registry of {@link Database} by name. Ebean has now been renamed to {@link DB}. - *

- * Ebean is effectively this is an alias for {@link DB} which is the new and improved name for Ebean. - *

- * The preference is to use DB and Database rather than Ebean and EbeanServer. - */ -@Deprecated -public final class Ebean { - - private static final DbContext context = DbContext.getInstance(); - - private Ebean() { - } - - /** - * Get the Database for a given DataSource. If name is null this will - * return the 'default' EbeanServer. - *

- * This is provided to access EbeanServer for databases other than the - * 'default' database. EbeanServer also provides more control over - * transactions and the ability to use transactions created externally to - * Ebean. - *

- *
{@code
-   * // use the "hr" database
-   * EbeanServer hrDatabase = Ebean.getServer("hr");
-   *
-   * Person person = hrDatabase.find(Person.class, 10);
-   * }
- * - * @param name the name of the server, can use null for the 'default server' - */ - public static EbeanServer getServer(String name) { - return (EbeanServer)context.get(name); - } - - /** - * Returns the default EbeanServer. - *

- * This is equivalent to Ebean.getServer(null); - *

- */ - public static EbeanServer getDefaultServer() { - return (EbeanServer)context.getDefault(); - } - - /** - * Register the server with this Ebean singleton. Specify if the registered - * server is the primary/default database. - */ - @Deprecated - public static void register(EbeanServer server, boolean defaultServer) { - context.register(server, defaultServer); - } - - /** - * Backdoor for registering a mock implementation of EbeanServer as the default database. - */ - protected static EbeanServer mock(String name, EbeanServer server, boolean defaultServer) { - return (EbeanServer)context.mock(name, server, defaultServer); - } - - private static Database getDefault() { - return context.getDefault(); - } - - /** - * Return the ExpressionFactory from the default database. - *

- * The ExpressionFactory is used internally by the query and ExpressionList to - * build the WHERE and HAVING clauses. Alternatively you can use the - * ExpressionFactory directly to create expressions to add to the query where - * clause. - *

- *

- * Alternatively you can use the {@link Expr} as a shortcut to the - * ExpressionFactory of the 'Default' EbeanServer. - *

- *

- * You generally need to the an ExpressionFactory (or {@link Expr}) to build - * an expression that uses OR like Expression e = Expr.or(..., ...); - *

- */ - public static ExpressionFactory getExpressionFactory() { - return getDefault().expressionFactory(); - } - - /** - * Return the next identity value for a given bean type. - *

- * This will only work when a IdGenerator is on this bean type such as a DB - * sequence or UUID. - *

- *

- * For DB's supporting getGeneratedKeys and sequences such as Oracle10 you do - * not need to use this method generally. It is made available for more - * complex cases where it is useful to get an ID prior to some processing. - *

- */ - public static Object nextId(Class beanType) { - return getDefault().nextId(beanType); - } - - /** - * Start a transaction with 'REQUIRED' semantics. - *

- * With REQUIRED semantics if an active transaction already exists that transaction will be used. - *

- *

- * The transaction is stored in a ThreadLocal variable and typically you only - * need to use the returned Transaction IF you wish to do things like - * use batch mode, change the transaction isolation level, use savepoints or - * log comments to the transaction log. - *

- *

- * Example of using a transaction to span multiple calls to find(), save() - * etc. - *

- *
{@code
-   *
-   *   // start a transaction (stored in a ThreadLocal)
-   *   Ebean.beginTransaction();
-   *   try {
-   * 	   Order order = Ebean.find(Order.class,10); ...
-   *
-   * 	   Ebean.save(order);
-   *
-   * 	   Ebean.commitTransaction();
-   *
-   *   } finally {
-   * 	   // rollback if we didn't commit
-   * 	   // i.e. an exception occurred before commitTransaction().
-   * 	   Ebean.endTransaction();
-   *   }
-   *
-   * }
- *

- * If you want to externalise the transaction management then you should be - * able to do this via EbeanServer. Specifically with EbeanServer you can pass - * the transaction to the various find() and save() execute() methods. This - * gives you the ability to create the transactions yourself externally from - * Ebean and pass those transactions through to the various methods available - * on EbeanServer. - *

- */ - public static Transaction beginTransaction() { - return getDefault().beginTransaction(); - } - - /** - * Start a transaction additionally specifying the isolation level. - * - * @param isolation the Transaction isolation level - */ - public static Transaction beginTransaction(TxIsolation isolation) { - return getDefault().beginTransaction(isolation); - } - - /** - * Start a transaction typically specifying REQUIRES_NEW or REQUIRED semantics. - *

- * Note that this provides an try finally alternative to using {@link #executeCall(TxScope, Callable)} or - * {@link #execute(TxScope, Runnable)}. - *

- *

- *

REQUIRES_NEW example:

- *
{@code
-   * // Start a new transaction. If there is a current transaction
-   * // suspend it until this transaction ends
-   * Transaction txn = Ebean.beginTransaction(TxScope.requiresNew());
-   * try {
-   *
-   *   ...
-   *
-   *   // commit the transaction
-   *   txn.commit();
-   *
-   * } finally {
-   *   // end this transaction which:
-   *   //  A) will rollback transaction if it has not been committed already
-   *   //  B) will restore a previously suspended transaction
-   *   txn.end();
-   * }
-   *
-   * }
- *

REQUIRED example:

- *
{@code
-   *
-   * // start a new transaction if there is not a current transaction
-   * Transaction txn = Ebean.beginTransaction(TxScope.required());
-   * try {
-   *
-   *   ...
-   *
-   *   // commit the transaction if it was created or
-   *   // do nothing if there was already a current transaction
-   *   txn.commit();
-   *
-   * } finally {
-   *   // end this transaction which will rollback the transaction
-   *   // if it was created for this try finally scope and has not
-   *   // already been committed
-   *   txn.end();
-   * }
-   *
-   * }
- */ - public static Transaction beginTransaction(TxScope scope) { - return getDefault().beginTransaction(scope); - } - - /** - * Returns the current transaction or null if there is no current transaction - * in scope. - */ - public static Transaction currentTransaction() { - return getDefault().currentTransaction(); - } - - /** - * The batch will be flushing automatically but you can use this to explicitly - * flush the batch if you like. - *

- * Flushing occurs automatically when: - *

- *
    - *
  • the batch size is reached
  • - *
  • A query is executed on the same transaction
  • - *
  • UpdateSql or CallableSql are mixed with bean save and delete
  • - *
  • Transaction commit occurs
  • - *
  • A getter method is called on a batched bean
  • - *
- */ - public static void flush() { - currentTransaction().flush(); - } - - /** - * Register a TransactionCallback on the currently active transaction. - *

- * If there is no currently active transaction then a PersistenceException is thrown. - * - * @param transactionCallback the transaction callback to be registered with the current transaction - * @throws PersistenceException if there is no currently active transaction - */ - public static void register(TransactionCallback transactionCallback) throws PersistenceException { - getDefault().register(transactionCallback); - } - - /** - * Commit the current transaction. - */ - public static void commitTransaction() { - getDefault().commitTransaction(); - } - - /** - * Rollback the current transaction. - */ - public static void rollbackTransaction() { - getDefault().rollbackTransaction(); - } - - /** - * If the current transaction has already been committed do nothing otherwise - * rollback the transaction. - *

- * Useful to put in a finally block to ensure the transaction is ended, rather - * than a rollbackTransaction() in each catch block. - *

- *

- * Code example: - *

- *
{@code
-   *   Ebean.beginTransaction();
-   *   try {
-   *     // do some fetching and or persisting
-   *
-   *     // commit at the end
-   *     Ebean.commitTransaction();
-   *
-   *   } finally {
-   *     // if commit didn't occur then rollback the transaction
-   *     Ebean.endTransaction();
-   *   }
-   * }
- */ - public static void endTransaction() { - getDefault().endTransaction(); - } - - /** - * Mark the current transaction as rollback only. - */ - public static void setRollbackOnly() { - getDefault().currentTransaction().setRollbackOnly(); - } - - /** - * Return a map of the differences between two objects of the same type. - *

- * When null is passed in for b, then the 'OldValues' of a is used for the - * difference comparison. - *

- */ - public static Map diff(Object a, Object b) { - return getDefault().diff(a, b); - } - - /** - * Either Insert or Update the bean depending on its state. - *

- * If there is no current transaction one will be created and committed for - * you automatically. - *

- *

- * Save can cascade along relationships. For this to happen you need to - * specify a cascade of CascadeType.ALL or CascadeType.PERSIST on the - * OneToMany, OneToOne or ManyToMany annotation. - *

- *

- * In this example below the details property has a CascadeType.ALL set so - * saving an order will also save all its details. - *

- *
{@code
-   *   public class Order { ...
-   *
-   *     @OneToMany(cascade=CascadeType.ALL, mappedBy="order")
-   * 	   List details;
-   * 	   ...
-   *   }
-   * }
- *

- * When a save cascades via a OneToMany or ManyToMany Ebean will automatically - * set the 'parent' object to the 'detail' object. In the example below in - * saving the order and cascade saving the order details the 'parent' order - * will be set against each order detail when it is saved. - *

- */ - public static void save(Object bean) throws OptimisticLockException { - getDefault().save(bean); - } - - /** - * Insert the bean. This is useful when you set the Id property on a bean and - * want to explicitly insert it. - */ - public static void insert(Object bean) { - getDefault().insert(bean); - } - - /** - * Insert a collection of beans. - */ - public static void insertAll(Collection beans) { - getDefault().insertAll(beans); - } - - /** - * Marks the entity bean as dirty. - *

- * This is used so that when a bean that is otherwise unmodified is updated with the version - * property updated. - *

- * An unmodified bean that is saved or updated is normally skipped and this marks the bean as - * dirty so that it is not skipped. - *

{@code
-   *
-   *   Customer customer = Ebean.find(Customer, id);
-   *
-   *   // mark the bean as dirty so that a save() or update() will
-   *   // increment the version property
-   *   Ebean.markAsDirty(customer);
-   *   Ebean.save(customer);
-   *
-   * }
- */ - public static void markAsDirty(Object bean) throws OptimisticLockException { - getDefault().markAsDirty(bean); - } - - /** - * Saves the bean using an update. If you know you are updating a bean then it is preferrable to - * use this update() method rather than save(). - *

- * Stateless updates: Note that the bean does not have to be previously fetched to call - * update().You can create a new instance and set some of its properties programmatically for via - * JSON/XML marshalling etc. This is described as a 'stateless update'. - *

- *

- * Optimistic Locking: Note that if the version property is not set when update() is - * called then no optimistic locking is performed (internally ConcurrencyMode.NONE is used). - *

- *
{@code
-   *
-   *   // A 'stateless update' example
-   *   Customer customer = new Customer();
-   *   customer.setId(7);
-   *   customer.setName("ModifiedNameNoOCC");
-   *
-   *   DB.update(customer);
-   *
-   * }
- */ - public static void update(Object bean) throws OptimisticLockException { - getDefault().update(bean); - } - - /** - * Update the beans in the collection. - */ - public static void updateAll(Collection beans) throws OptimisticLockException { - getDefault().updateAll(beans); - } - - /** - * Merge the bean using the default merge options. - * - * @param bean The bean to merge - */ - public static void merge(Object bean) { - getDefault().merge(bean); - } - - /** - * Merge the bean using the given merge options. - * - * @param bean The bean to merge - * @param options The options to control the merge - */ - public static void merge(Object bean, MergeOptions options) { - getDefault().merge(bean, options); - } - - /** - * Save all the beans from a Collection. - */ - public static int saveAll(Collection beans) throws OptimisticLockException { - return getDefault().saveAll(beans); - } - - /** - * This method checks the uniqueness of a bean. I.e. if the save will work. It will return the - * properties that violates an unique / primary key. This may be done in an UI save action to - * validate if the user has entered correct values. - *

- * Note: This method queries the DB for uniqueness of all indices, so do not use it in a batch update. - *

- * Note: This checks only the root bean! - *

- *

{@code
-   *
-   *   // there is a unique constraint on title
-   *
-   *   Document doc = new Document();
-   *   doc.setTitle("One flew over the cuckoo's nest");
-   *   doc.setBody("clashes with doc1");
-   *
-   *   Set properties = server().checkUniqueness(doc);
-   *
-   *   if (properties.isEmpty()) {
-   *     // it is unique ... carry on
-   *
-   *   } else {
-   *     // build a user friendly message
-   *     // to return message back to user
-   *
-   *     String uniqueProperties = properties.toString();
-   *
-   *     StringBuilder msg = new StringBuilder();
-   *
-   *     properties.forEach((it)-> {
-   *       Object propertyValue = it.getVal(doc);
-   *       String propertyName = it.getName();
-   *       msg.append(" property["+propertyName+"] value["+propertyValue+"]");
-   *     });
-   *
-   *     // uniqueProperties > [title]
-   *     //       custom msg > property[title] value[One flew over the cuckoo's nest]
-   *
-   *  }
-   *
-   * }
- * - * @param bean The entity bean to check uniqueness on - * @return a set of Properties if constraint validation was detected or empty list. - */ - public static Set checkUniqueness(Object bean) { - return getDefault().checkUniqueness(bean); - } - - /** - * Same as {@link #checkUniqueness(Object)}. but with given transaction. - */ - public static Set checkUniqueness(Object bean, Transaction transaction) { - return getDefault().checkUniqueness(bean, transaction); - } - - /** - * Delete the bean. - *

- * This will return true if the bean was deleted successfully or JDBC batch is being used. - *

- *

- * If there is no current transaction one will be created and committed for - * you automatically. - *

- *

- * If the bean is configured with @SoftDelete then this will perform a soft - * delete rather than a hard/permanent delete. - *

- *

- * If the Bean does not have a version property (or loaded version property) and - * the bean does not exist then this returns false indicating that nothing was - * deleted. Note that, if JDBC batch mode is used then this always returns true. - *

- */ - public static boolean delete(Object bean) throws OptimisticLockException { - return getDefault().delete(bean); - } - - /** - * Delete the bean in permanent fashion (will not use soft delete). - */ - public static boolean deletePermanent(Object bean) throws OptimisticLockException { - return getDefault().deletePermanent(bean); - } - - /** - * Delete the bean given its type and id. - */ - public static int delete(Class beanType, Object id) { - return getDefault().delete(beanType, id); - } - - /** - * Delete permanent the bean given its type and id. - */ - public static int deletePermanent(Class beanType, Object id) { - return getDefault().deletePermanent(beanType, id); - } - - /** - * Delete several beans given their type and id values. - */ - public static int deleteAll(Class beanType, Collection ids) { - return getDefault().deleteAll(beanType, ids); - } - - /** - * Delete permanent several beans given their type and id values. - */ - public static int deleteAllPermanent(Class beanType, Collection ids) { - return getDefault().deleteAllPermanent(beanType, ids); - } - - /** - * Delete all the beans in the Collection. - */ - public static int deleteAll(Collection beans) throws OptimisticLockException { - return getDefault().deleteAll(beans); - } - - /** - * Delete permanent all the beans in the Collection (will not use soft delete). - */ - public static int deleteAllPermanent(Collection beans) throws OptimisticLockException { - return getDefault().deleteAllPermanent(beans); - } - - /** - * Refresh the values of a bean. - *

- * Note that this resets OneToMany and ManyToMany properties so that if they - * are accessed a lazy load will refresh the many property. - *

- */ - public static void refresh(Object bean) { - getDefault().refresh(bean); - } - - /** - * Refresh a 'many' property of a bean. - *
{@code
-   *
-   *   Order order = ...;
-   *   ...
-   *   // refresh the order details...
-   *   Ebean.refreshMany(order, "details");
-   *
-   * }
- * - * @param bean the entity bean containing the List Set or Map to refresh. - * @param manyPropertyName the property name of the List Set or Map to refresh. - */ - public static void refreshMany(Object bean, String manyPropertyName) { - getDefault().refreshMany(bean, manyPropertyName); - } - - /** - * Get a reference object. - *

- * This is sometimes described as a proxy (with lazy loading). - *

- *
{@code
-   *
-   *   Product product = Ebean.getReference(Product.class, 1);
-   *
-   *   // You can get the id without causing a fetch/lazy load
-   *   Integer productId = product.getId();
-   *
-   *   // If you try to get any other property a fetch/lazy loading will occur
-   *   // This will cause a query to execute...
-   *   String name = product.getName();
-   *
-   * }
- * - * @param beanType the type of entity bean - * @param id the id value - */ - public static T getReference(Class beanType, Object id) { - return getDefault().reference(beanType, id); - } - - /** - * Sort the list using the sortByClause which can contain a comma delimited - * list of property names and keywords asc, desc, nullsHigh and nullsLow. - *
    - *
  • asc - ascending order (which is the default)
  • - *
  • desc - Descending order
  • - *
  • nullsHigh - Treat null values as high/large values (which is the - * default)
  • - *
  • nullsLow- Treat null values as low/very small values
  • - *
- *

- * If you leave off any keywords the defaults are ascending order and treating - * nulls as high values. - *

- *

- * Note that the sorting uses a Comparator and Collections.sort(); and does - * not invoke a DB query. - *

- *
{@code
-   *
-   *   // find orders and their customers
-   *   List list = Ebean.find(Order.class)
-   *     .fetch("customer")
-   *     .order("id")
-   *     .findList();
-   *
-   *   // sort by customer name ascending, then by order shipDate
-   *   // ... then by the order status descending
-   *   Ebean.sort(list, "customer.name, shipDate, status desc");
-   *
-   *   // sort by customer name descending (with nulls low)
-   *   // ... then by the order id
-   *   Ebean.sort(list, "customer.name desc nullsLow, id");
-   *
-   * }
- * - * @param list the list of entity beans - * @param sortByClause the properties to sort the list by - */ - public static void sort(List list, String sortByClause) { - getDefault().sort(list, sortByClause); - } - - /** - * Find a bean using its unique id. This will not use caching. - *
{@code
-   *
-   *   // Fetch order 1
-   *   Order order = Ebean.find(Order.class, 1);
-   *
-   * }
- *

- * If you want more control over the query then you can use createQuery() and - * Query.findOne(); - *

- *
{@code
-   *
-   *   // ... additionally fetching customer, customer shipping address,
-   *   // order details, and the product associated with each order detail.
-   *   // note: only product id and name is fetch (its a "partial object").
-   *   // note: all other objects use "*" and have all their properties fetched.
-   *
-   *   Query query = Ebean.find(Order.class)
-   *     .setId(1)
-   *     .fetch("customer")
-   *     .fetch("customer.shippingAddress")
-   *     .fetch("details")
-   *     .query();
-   *
-   *   // fetch associated products but only fetch their product id and name
-   *   query.fetch("details.product", "name");
-   *
-   *   // traverse the object graph...
-   *
-   *   Order order = query.findOne();
-   *
-   *   Customer customer = order.getCustomer();
-   *   Address shippingAddress = customer.getShippingAddress();
-   *   List details = order.getDetails();
-   *   OrderDetail detail0 = details.get(0);
-   *   Product product = detail0.getProduct();
-   *   String productName = product.getName();
-   *
-   * }
- * - * @param beanType the type of entity bean to fetch - * @param id the id value - */ - @Nullable - public static T find(Class beanType, Object id) { - return getDefault().find(beanType, id); - } - - /** - * Deprecated - migrate to DB.sqlQuery(). - *

- * Create a SqlQuery for executing native sql - * query statements. - *

- * Note that you can use raw SQL with entity beans, refer to the SqlSelect - * annotation for examples. - *

- */ - @Deprecated - public static SqlQuery createSqlQuery(String sql) { - return getDefault().sqlQuery(sql); - } - - /** - * Deprecated - migrate to DB.sqlUpdate(). - *

- * Create a sql update for executing native dml statements. - *

- * Use this to execute a Insert Update or Delete statement. The statement will - * be native to the database and contain database table and column names. - *

- * See {@link SqlUpdate} for example usage. - */ - @Deprecated - public static SqlUpdate createSqlUpdate(String sql) { - return getDefault().sqlUpdate(sql); - } - - /** - * Create a CallableSql to execute a given stored procedure. - * - * @see CallableSql - */ - public static CallableSql createCallableSql(String sql) { - return getDefault().createCallableSql(sql); - } - - /** - * Create a orm update where you will supply the insert/update or delete - * statement (rather than using a named one that is already defined using the - * @NamedUpdates annotation). - *

- * The orm update differs from the sql update in that it you can use the bean - * name and bean property names rather than table and column names. - *

- *

- * An example: - *

- *
{@code
-   *
-   *   // The bean name and properties - "topic","postCount" and "id"
-   *
-   *   // will be converted into their associated table and column names
-   *   String updStatement = "update topic set postCount = :pc where id = :id";
-   *
-   *   Update update = Ebean.createUpdate(Topic.class, updStatement);
-   *
-   *   update.set("pc", 9);
-   *   update.set("id", 3);
-   *
-   *   int rows = update.execute();
-   *   System.out.println("rows updated:" + rows);
-   *
-   * }
- */ - public static Update createUpdate(Class beanType, String ormUpdate) { - return getDefault().createUpdate(beanType, ormUpdate); - } - - /** - * Create a CsvReader for a given beanType. - */ - public static CsvReader createCsvReader(Class beanType) { - return getDefault().createCsvReader(beanType); - } - - /** - * Create a named query. - *

- * For RawSql the named query is expected to be in ebean.xml. - *

- * - * @param beanType The type of entity bean - * @param namedQuery The name of the query - * @param The type of entity bean - * @return The query - */ - public static Query createNamedQuery(Class beanType, String namedQuery) { - return getDefault().createNamedQuery(beanType, namedQuery); - } - - /** - * Create a query for a type of entity bean. - *

- * You can use the methods on the Query object to specify fetch paths, - * predicates, order by, limits etc. - *

- *

- * You then use findList(), findSet(), findMap() and findOne() to execute - * the query and return the collection or bean. - *

- *

- * Note that a query executed by {@link Query#findList()} - * {@link Query#findSet()} etc will execute against the same EbeanServer from - * which is was created. - *

- * - * @param beanType the class of entity to be fetched - * @return A ORM Query object for this beanType - */ - public static Query createQuery(Class beanType) { - return getDefault().createQuery(beanType); - } - - /** - * Parse the Ebean query language statement returning the query which can then - * be modified (add expressions, change order by clause, change maxRows, change - * fetch and select paths etc). - *

- *

Example

- *
{@code
-   *
-   *   // Find order additionally fetching the customer, details and details.product name.
-   *
-   *   String eql = "fetch customer fetch details fetch details.product (name) where id = :orderId ";
-   *
-   *   Query query = Ebean.createQuery(Order.class, eql);
-   *   query.setParameter("orderId", 2);
-   *
-   *   Order order = query.findOne();
-   *
-   *   // This is the same as:
-   *
-   *   Order order = Ebean.find(Order.class)
-   *     .fetch("customer")
-   *     .fetch("details")
-   *     .fetch("detail.product", "name")
-   *     .setId(2)
-   *     .findOne();
-   *
-   * }
- * - * @param beanType The type of bean to fetch - * @param eql The Ebean query - * @param The type of the entity bean - * @return The query with expressions defined as per the parsed query statement - */ - public static Query createQuery(Class beanType, String eql) { - return getDefault().createQuery(beanType, eql); - } - - /** - * Create a query for a type of entity bean. - *

- * This is actually the same as {@link #createQuery(Class)}. The reason it - * exists is that people used to JPA will probably be looking for a - * createQuery method (the same as entityManager). - *

- * - * @param beanType the type of entity bean to find - * @return A ORM Query object for this beanType - */ - public static Query find(Class beanType) { - return getDefault().find(beanType); - } - - /** - * Create a query using native SQL. - *

- * The native SQL can contain named parameters or positioned parameters. - *

- *
{@code
-   *
-   *   String sql = "select c.id, c.name from customer c where c.name like ? order by c.name";
-   *
-   *   List customers = DB.findNative(Customer.class, sql)
-   *     .setParameter(1, "Rob%")
-   *     .findList()
-   *
-   * }
- * - * @param beanType The type of entity bean to fetch - * @param nativeSql The SQL that can contain named or positioned parameters - * @return The query to set parameters and execute - */ - public static Query findNative(Class beanType, String nativeSql) { - return getDefault().findNative(beanType, nativeSql); - } - - /** - * Create a Query for DTO beans. - *

- * DTO beans are just normal bean like classes with public constructor(s) and setters. - * They do not need to be registered with Ebean before use. - *

- * - * @param dtoType The type of the DTO bean the rows will be mapped into. - * @param sql The SQL query to execute. - * @param The type of the DTO bean. - */ - public static DtoQuery findDto(Class dtoType, String sql) { - return getDefault().findDto(dtoType, sql); - } - - /** - * Create an Update query to perform a bulk update. - *

- *

{@code
-   *
-   *  int rows = Ebean.update(Customer.class)
-   *      .set("status", Customer.Status.ACTIVE)
-   *      .set("updtime", new Timestamp(System.currentTimeMillis()))
-   *      .where()
-   *        .gt("id", 1000)
-   *        .update();
-   *
-   * }
- * - * @param beanType The type of entity bean to update - * @param The type of entity bean - * @return The update query to use - */ - public static UpdateQuery update(Class beanType) { - return getDefault().update(beanType); - } - - /** - * Create a filter for sorting and filtering lists of entities locally without - * going back to the database. - *

- * This produces and returns a new list with the sort and filters applied. - *

- *

- * Refer to {@link Filter} for an example of its use. - *

- */ - public static Filter filter(Class beanType) { - 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(). - *

- * If you wish to execute a Sql Select natively then you should use the - * FindByNativeSql object. - *

- *

- * Note that the table modification information is automatically deduced and - * you do not need to call the Ebean.externalModification() method when you - * use this method. - *

- *

- * Example: - *

- *
{@code
-   *
-   *   // example that uses 'named' parameters
-   *   String s = "UPDATE f_topic set post_count = :count where id = :id"
-   *
-   *   SqlUpdate update = Ebean.createSqlUpdate(s);
-   *
-   *   update.setParameter("id", 1);
-   *   update.setParameter("count", 50);
-   *
-   *   int modifiedCount = Ebean.execute(update);
-   *
-   *   String msg = "There where " + modifiedCount + "rows updated";
-   *
-   * }
- * - * @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 Ebean#execute(CallableSql) - */ - public static int execute(SqlUpdate sqlUpdate) { - return getDefault().execute(sqlUpdate); - } - - /** - * For making calls to stored procedures. - *

- * Example: - *

- *
{@code
-   *
-   *   String sql = "{call sp_order_modify(?,?,?)}";
-   *
-   *   CallableSql cs = Ebean.createCallableSql(sql);
-   *   cs.setParameter(1, 27);
-   *   cs.setParameter(2, "SHIPPED");
-   *   cs.registerOut(3, Types.INTEGER);
-   *
-   *   Ebean.execute(cs);
-   *
-   *   // read the out parameter
-   *   Integer returnValue = (Integer) cs.getObject(3);
-   *
-   * }
- * - * @see CallableSql - * @see Ebean#execute(SqlUpdate) - */ - public static int execute(CallableSql callableSql) { - return getDefault().execute(callableSql); - } - - /** - * Execute a TxRunnable in a Transaction with an explicit scope. - *

- * The scope can control the transaction type, isolation and rollback - * semantics. - *

- *
{@code
-   *
-   *   // set specific transactional scope settings
-   *   TxScope scope = TxScope.requiresNew().setIsolation(TxIsolation.SERIALIZABLE);
-   *
-   *   Ebean.execute(scope, new TxRunnable() {
-   * 	   public void run() {
-   * 		   User u1 = Ebean.find(User.class, 1);
-   * 		   ...
-   *     }
-   *   });
-   *
-   * }
- */ - public static void execute(TxScope scope, Runnable r) { - getDefault().execute(scope, r); - } - - /** - * Execute a Runnable in a Transaction with the default scope. - *

- * The default scope runs with REQUIRED and by default will rollback on any - * exception (checked or runtime). - *

- *
{@code
-   *
-   *   Ebean.execute(() -> {
-   *
-   *       User u1 = Ebean.find(User.class, 1);
-   *       User u2 = Ebean.find(User.class, 2);
-   *
-   *       u1.setName("u1 mod");
-   *       u2.setName("u2 mod");
-   *
-   *       Ebean.save(u1);
-   *       Ebean.save(u2);
-   *
-   *   });
-   *
-   * }
- */ - public static void execute(Runnable r) { - getDefault().execute(r); - } - - /** - * Execute a Callable in a Transaction with an explicit scope. - *

- * The scope can control the transaction type, isolation and rollback - * semantics. - *

- *
{@code
-   *
-   *   // set specific transactional scope settings
-   *   TxScope scope = TxScope.requiresNew().setIsolation(TxIsolation.SERIALIZABLE);
-   *
-   *   Ebean.executeCall(scope, new Callable() {
-   * 	   public String call() {
-   * 		   User u1 = Ebean.find(User.class, 1);
-   * 		   ...
-   * 		   return u1.getEmail();
-   *     }
-   *   });
-   *
-   * }
- */ - public static T executeCall(TxScope scope, Callable c) { - return getDefault().executeCall(scope, c); - } - - /** - * Execute a Callable in a Transaction with the default scope. - *

- * The default scope runs with REQUIRED and by default will rollback on any - * exception (checked or runtime). - *

- *

- * This is basically the same as TxRunnable except that it returns an Object - * (and you specify the return type via generics). - *

- *
{@code
-   *
-   *   Ebean.executeCall(() -> {
-   *
-   *       User u1 = Ebean.find(User.class, 1);
-   *       User u2 = Ebean.find(User.class, 2);
-   *
-   *       u1.setName("u1 mod");
-   *       u2.setName("u2 mod");
-   *
-   *       Ebean.save(u1);
-   *       Ebean.save(u2);
-   *
-   *       return u1.getEmail();
-   *
-   *   });
-   *
-   * }
- */ - public static T executeCall(Callable c) { - return getDefault().executeCall(c); - } - - /** - * Inform Ebean that tables have been modified externally. These could be the - * result of from calling a stored procedure, other JDBC calls or external - * programs including other frameworks. - *

- * If you use Ebean.execute(UpdateSql) then the table modification information - * is automatically deduced and you do not need to call this method yourself. - *

- *

- * This information is used to invalidate objects out of the cache and - * potentially text indexes. This information is also automatically broadcast - * across the cluster. - *

- *

- * If there is a transaction then this information is placed into the current - * transactions event information. When the transaction is committed this - * information is registered (with the transaction manager). If this - * transaction is rolled back then none of the transaction event information - * registers including the information you put in via this method. - *

- *

- * If there is NO current transaction when you call this method then this - * information is registered immediately (with the transaction manager). - *

- * - * @param tableName the name of the table that was modified - * @param inserts true if rows where inserted into the table - * @param updates true if rows on the table where updated - * @param deletes true if rows on the table where deleted - */ - public static void externalModification(String tableName, boolean inserts, boolean updates, boolean deletes) { - getDefault().externalModification(tableName, inserts, updates, deletes); - } - - /** - * Return the BeanState for a given entity bean. - *

- * This will return null if the bean is not an enhanced entity bean. - *

- */ - public static BeanState getBeanState(Object bean) { - return getDefault().beanState(bean); - } - - /** - * Return the manager of the server cache ("L2" cache). - */ - public static ServerCacheManager getServerCacheManager() { - return getDefault().cacheManager(); - } - - /** - * Return the BackgroundExecutor service for asynchronous processing of - * queries. - */ - public static BackgroundExecutor getBackgroundExecutor() { - return getDefault().backgroundExecutor(); - } - - /** - * Return the JsonContext for reading/writing JSON. - */ - public static JsonContext json() { - return getDefault().json(); - } - -} diff --git a/ebean-api/src/main/java/io/ebean/EbeanServer.java b/ebean-api/src/main/java/io/ebean/EbeanServer.java deleted file mode 100644 index 010dd5a8e..000000000 --- a/ebean-api/src/main/java/io/ebean/EbeanServer.java +++ /dev/null @@ -1,15 +0,0 @@ -package io.ebean; - -/** - * Deprecated - please migrate to io.ebean.Database. - * Provides the API for fetching and saving beans to a particular Database. - *

- * Effectively this is an alias for {@link Database} which is now the new - * and improved name for EbeanServer. - *

- * The preference is to use DB and Database rather than Ebean and EbeanServer. - */ -@Deprecated -public interface EbeanServer extends Database { - -} diff --git a/ebean-api/src/main/java/io/ebean/EbeanServerFactory.java b/ebean-api/src/main/java/io/ebean/EbeanServerFactory.java deleted file mode 100644 index c774488a0..000000000 --- a/ebean-api/src/main/java/io/ebean/EbeanServerFactory.java +++ /dev/null @@ -1,70 +0,0 @@ -package io.ebean; - -import io.ebean.config.ContainerConfig; -import io.ebean.config.ServerConfig; - -/** - * Deprecated - please migrate to DatabaseFactory. - *

- * Creates EbeanServer instances. - *

- * This uses either a ServerConfig or properties in the ebean.properties file to - * configure and create a EbeanServer instance. - *

- *

- * The EbeanServer instance can either be registered with the Ebean singleton or - * not. The Ebean singleton effectively holds a map of EbeanServers by a name. - * If the EbeanServer is registered with the Ebean singleton you can retrieve it - * later via {@link Ebean#getServer(String)}. - *

- *

- * One EbeanServer can be nominated as the 'default/primary' EbeanServer. Many - * methods on the Ebean singleton such as {@link Ebean#find(Class)} are just a - * convenient way of using the 'default/primary' EbeanServer. - *

- */ -@Deprecated -public class EbeanServerFactory { - - /** - * Initialise the container with clustering configuration. - *

- * Call this prior to creating any EbeanServer instances or alternatively set the - * ContainerConfig on the ServerConfig when creating the first EbeanServer instance. - */ - public static void initialiseContainer(ContainerConfig containerConfig) { - DatabaseFactory.initialiseContainer(containerConfig); - } - - /** - * Create using ebean.properties to configure the database. - */ - public static EbeanServer create(String name) { - return (EbeanServer)DatabaseFactory.create(name); - } - - /** - * Create using the ServerConfig object to configure the database. - */ - public static EbeanServer create(ServerConfig config) { - return (EbeanServer)DatabaseFactory.create(config); - } - - /** - * Create using the ServerConfig additionally specifying a classLoader to use as the context class loader. - */ - public static EbeanServer createWithContextClassLoader(ServerConfig config, ClassLoader classLoader) { - return (EbeanServer)DatabaseFactory.createWithContextClassLoader(config, classLoader); - } - - /** - * Shutdown gracefully all EbeanServers cleaning up any resources as required. - *

- * This is typically invoked via JVM shutdown hook and not explicitly called. - *

- */ - public static void shutdown() { - DatabaseFactory.shutdown(); - } - -} diff --git a/ebean-api/src/main/java/io/ebean/FetchConfig.java b/ebean-api/src/main/java/io/ebean/FetchConfig.java index cfb14a235..1087ff622 100644 --- a/ebean-api/src/main/java/io/ebean/FetchConfig.java +++ b/ebean-api/src/main/java/io/ebean/FetchConfig.java @@ -13,8 +13,7 @@ import java.io.Serializable; * } *

* Example: Using a "query join" instead of a "fetch join" we instead use 2 SQL queries - *

- *

+ * *

{@code
  *
  * // This will use 2 SQL queries to build this object graph
@@ -27,9 +26,6 @@ import java.io.Serializable;
  * // query 2) find orderDetails where order.id in (?,?...) // first 100 order id's
  *
  * }
- * - * @author mario - * @author rbygrave */ public final class FetchConfig implements Serializable { @@ -40,21 +36,9 @@ public final class FetchConfig implements Serializable { private static final int LAZY_MODE = 2; private static final int CACHE_MODE = 3; - private int mode; - private int batchSize; - private int hashCode; - - /** - * Deprecated - migrate to one of the static factory methods like {@link FetchConfig#ofQuery()} - *

- * Construct using default JOIN mode. - */ - @Deprecated - public FetchConfig() { - //this.mode = JOIN_MODE; - this.batchSize = 100; - this.hashCode = 1000; - } + private final int mode; + private final int batchSize; + private final int hashCode; private FetchConfig(int mode, int batchSize) { this.mode = mode; @@ -106,94 +90,6 @@ public final class FetchConfig implements Serializable { return new FetchConfig(JOIN_MODE, 100); } - /** - * We want to migrate away from mutating FetchConfig to a fully immutable FetchConfig. - */ - private FetchConfig mutate(int mode, int batchSize) { - if (batchSize < 0) { - throw new IllegalArgumentException("batch size " + batchSize + " must be > 0"); - } - this.mode = mode; - this.batchSize = batchSize; - this.hashCode = mode + 10 * batchSize; - return this; - } - - /** - * Deprecated - migrate to FetchConfig.ofLazy(). - */ - @Deprecated - public FetchConfig lazy() { - return mutate(LAZY_MODE, 0); - } - - /** - * Deprecated - migrate to FetchConfig.ofLazy(batchSize). - */ - @Deprecated - public FetchConfig lazy(int batchSize) { - return mutate(LAZY_MODE, batchSize); - } - - /** - * Deprecated - migrate to FetchConfig.ofQuery(). - *

- * Eagerly fetch the beans in this path as a separate query (rather than as - * part of the main query). - *

- * This will use the default batch size for separate query which is 100. - */ - @Deprecated - public FetchConfig query() { - return mutate(QUERY_MODE, 100); - } - - /** - * Deprecated - migrate to FetchConfig.ofQuery(batchSize). - *

- * Eagerly fetch the beans in this path as a separate query (rather than as - * part of the main query). - *

- * The queryBatchSize is the number of parent id's that this separate query - * will load per batch. - *

- * This will load all beans on this path eagerly unless a {@link #lazy(int)} - * is also used. - * - * @param batchSize the batch size used to load beans on this path - */ - @Deprecated - public FetchConfig query(int batchSize) { - return mutate(QUERY_MODE, batchSize); - } - - /** - * Deprecated - migrate to FetchConfig.ofQuery(batchSize). - *

- * Eagerly fetch the first batch of beans on this path. - * This is similar to {@link #query(int)} but only fetches the first batch. - *

- * If there are more parent beans than the batch size then they will not be - * loaded eagerly but instead use lazy loading. - * - * @param batchSize the number of parent beans this path is populated for - */ - @Deprecated - public FetchConfig queryFirst(int batchSize) { - return query(batchSize); - } - - /** - * Deprecated - migrate to FetchConfig.ofCache(). - *

- * Eagerly fetch the beans fetching the beans from the L2 bean cache - * and using the DB for beans not in the cache. - */ - @Deprecated - public FetchConfig cache() { - return mutate(CACHE_MODE, 100); - } - /** * Return the batch size for fetching. */ diff --git a/ebean-api/src/main/java/io/ebean/Pairs.java b/ebean-api/src/main/java/io/ebean/Pairs.java index f0f2fbd62..05da36deb 100644 --- a/ebean-api/src/main/java/io/ebean/Pairs.java +++ b/ebean-api/src/main/java/io/ebean/Pairs.java @@ -10,11 +10,10 @@ import java.util.Objects; *

* This feature is to enable use of L2 cache with complex natural keys with findList() queries in cases where the * IN clause is not a single property but instead a pair of properties. - *

*

* These queries can have predicates that can be translated into a list of complex natural keys such that the L2 * cache can be hit with these keys to obtain some or all of the beans from L2 cache rather than the DB. - *

+ * *
{@code
  *
  *   // where a bean is annotated with a complex
@@ -45,11 +44,10 @@ import java.util.Objects;
  * pairs are a unique key/index or part of a unique key/index and highly selective). Currently we know we can do this
  * on any DB that supports expression/formula based indexes.
  * using a DB string concatenation formula
- * 

*

* This means, the implementation converts the list of pairs into a list of strings via concatenation and we use a * DB concatenation formula to match. We see SQL like: - *

+ * *
{@code sql
  *
  *   ...
@@ -60,7 +58,7 @@ import java.util.Objects;
  * }
*

* We often create a DB expression index to match the DB concat formula like: - *

+ * *
{@code sql
  *
  *   create index ix_name on table_name (sku || '-' || code);
@@ -144,14 +142,6 @@ public final class Pairs {
     return this;
   }
 
-  /**
-   * Deprecated migrate to concatSeparator()
-   */
-  @Deprecated
-  public Pairs setConcatSeparator(String concatSeparator) {
-    return concatSeparator(concatSeparator);
-  }
-
   /**
    * Return  a suffix used with DB varchar concatenation to combine the 2 values.
    */
@@ -167,14 +157,6 @@ public final class Pairs {
     return this;
   }
 
-  /**
-   * Deprecated migrate to concatSuffix()
-   */
-  @Deprecated
-  public Pairs setConcatSuffix(String concatSuffix) {
-    return concatSuffix(concatSuffix);
-  }
-
   @Override
   public String toString() {
     return "p0:" + property0 + " p1:" + property1 + " entries:" + entries;
diff --git a/ebean-api/src/main/java/io/ebean/Query.java b/ebean-api/src/main/java/io/ebean/Query.java
index 0bc8939f3..400c9775e 100644
--- a/ebean-api/src/main/java/io/ebean/Query.java
+++ b/ebean-api/src/main/java/io/ebean/Query.java
@@ -2,6 +2,7 @@ package io.ebean;
 
 import io.avaje.lang.NonNullApi;
 import io.avaje.lang.Nullable;
+
 import javax.persistence.NonUniqueResultException;
 import java.sql.Connection;
 import java.sql.Timestamp;
@@ -1372,18 +1373,9 @@ public interface Query extends CancelableQuery {
    * optional asc and desc keywords representing ascending and descending order
    * respectively.
    */
-  Query order(String orderByClause);
-
-  /**
-   * Return the OrderBy so that you can append an ascending or descending
-   * property to the order by clause.
-   * 

- * This will never return a null. If no order by clause exists then an 'empty' - * OrderBy object is returned. - *

- * This is the same as orderBy() - */ - OrderBy order(); + default Query order(String orderByClause) { + return orderBy(orderByClause); + } /** * Return the OrderBy so that you can append an ascending or descending @@ -1397,15 +1389,30 @@ public interface Query extends CancelableQuery { OrderBy orderBy(); /** - * Set an OrderBy object to replace any existing OrderBy clause. + * Return the OrderBy so that you can append an ascending or descending + * property to the order by clause. + *

+ * This will never return a null. If no order by clause exists then an 'empty' + * OrderBy object is returned. + *

+ * This is the same as orderBy() */ - Query setOrder(OrderBy orderBy); + default OrderBy order() { + return orderBy(); + } /** * Set an OrderBy object to replace any existing OrderBy clause. */ Query setOrderBy(OrderBy orderBy); + /** + * Set an OrderBy object to replace any existing OrderBy clause. + */ + default Query setOrder(OrderBy orderBy) { + return setOrderBy(orderBy); + } + /** * Set whether this query uses DISTINCT. *

diff --git a/ebean-api/src/main/java/io/ebean/Transaction.java b/ebean-api/src/main/java/io/ebean/Transaction.java index 06f6bd315..08c584231 100644 --- a/ebean-api/src/main/java/io/ebean/Transaction.java +++ b/ebean-api/src/main/java/io/ebean/Transaction.java @@ -440,14 +440,6 @@ public interface Transaction extends AutoCloseable { */ void setGetGeneratedKeys(boolean getGeneratedKeys); - /** - * Deprecated renamed to setGetGeneratedKeys(). - */ - @Deprecated - default void setBatchGetGeneratedKeys(boolean getGeneratedKeys) { - setGetGeneratedKeys(getGeneratedKeys); - } - /** * By default when mixing UpdateSql (or CallableSql) with Beans the batch is * automatically flushed when you change (between persisting beans and @@ -463,14 +455,6 @@ public interface Transaction extends AutoCloseable { */ void setFlushOnMixed(boolean batchFlushOnMixed); - /** - * Deprecated renamed to setFlushOnMixed(). - */ - @Deprecated - default void setBatchFlushOnMixed(boolean batchFlushOnMixed) { - setFlushOnMixed(batchFlushOnMixed); - } - /** * By default executing a query will automatically flush any batched * statements (persisted beans, executed UpdateSql etc). @@ -480,14 +464,6 @@ public interface Transaction extends AutoCloseable { */ void setFlushOnQuery(boolean batchFlushOnQuery); - /** - * Deprecated renamed to setFlushOnQuery(). - */ - @Deprecated - default void setBatchFlushOnQuery(boolean batchFlushOnQuery) { - setFlushOnQuery(batchFlushOnQuery); - } - /** * Return true if the batch (of persisted beans or executed UpdateSql etc) * should be flushed prior to executing a query. @@ -496,14 +472,6 @@ public interface Transaction extends AutoCloseable { */ boolean isFlushOnQuery(); - /** - * Deprecated renamed to isFlushOnQuery(). - */ - @Deprecated - default boolean isBatchFlushOnQuery() { - return isFlushOnQuery(); - } - /** * The batch will be flushing automatically but you can use this to explicitly * flush the batch if you like. @@ -519,14 +487,6 @@ public interface Transaction extends AutoCloseable { */ void flush() throws PersistenceException; - /** - * Deprecated - migrate to flush(). - *

- * flush() is preferred as it matches the JPA flush() method. - */ - @Deprecated - void flushBatch() throws PersistenceException; - /** * Return the underlying Connection object. *

@@ -540,14 +500,6 @@ public interface Transaction extends AutoCloseable { */ Connection connection(); - /** - * Deprecated migrate to connection(). - */ - @Deprecated - default Connection getConnection() { - return connection(); - } - /** * Add table modification information to the TransactionEvent. *

diff --git a/ebean-api/src/main/java/io/ebean/bean/NodeUsageCollector.java b/ebean-api/src/main/java/io/ebean/bean/NodeUsageCollector.java index bb65f6735..c168b3a66 100644 --- a/ebean-api/src/main/java/io/ebean/bean/NodeUsageCollector.java +++ b/ebean-api/src/main/java/io/ebean/bean/NodeUsageCollector.java @@ -1,6 +1,6 @@ package io.ebean.bean; -import java.lang.ref.WeakReference; +import java.lang.ref.Cleaner; import java.util.LinkedHashSet; import java.util.Set; @@ -8,120 +8,102 @@ import java.util.Set; * Collects profile information for a bean (or reference/proxy bean) at a given node. *

* The node identifies the location of the bean in the object graph. - *

- *

- * It has to use a weak reference so as to ensure that it does not stop the - * associated bean from being garbage collected. - *

*/ public final class NodeUsageCollector { - /** - * The point in the object graph for a specific query and call stack point. - */ - private final ObjectGraphNode node; + private final static Cleaner cleaner = Cleaner.create(); + + public static final class State implements Runnable { + + private final NodeUsageListener listener; + /** + * The properties used at this profile point. + */ + private final Set used = new LinkedHashSet<>(); + /** + * The point in the object graph for a specific query and call stack point. + */ + private final ObjectGraphNode node; + /** + * set to true if the bean is modified (setter called) + */ + private boolean modified; + + private State(ObjectGraphNode node, NodeUsageListener listener) { + this.node = node; + this.listener = listener; + } + + @Override + public String toString() { + return node + " read:" + used + " modified:" + modified; + } + + @Override + public void run() { + listener.collectNodeUsage(this); + } + + /** + * Return true if no properties where used. + */ + public boolean isEmpty() { + return used.isEmpty(); + } + + /** + * Return the associated node which identifies the location in the object + * graph of the bean/reference. + */ + public ObjectGraphNode node() { + return node; + } + + /** + * Return the set of used properties. + */ + public Set used() { + return used; + } + + /** + * Return true if the bean was modified by a setter. + */ + public boolean isModified() { + return modified; + } + } + + private final State state; + + public NodeUsageCollector(ObjectGraphNode node, NodeUsageListener listener) { + this.state = new State(node, listener); + cleaner.register(this, state); + } /** - * Weak to allow garbage collection. + * Return the underlying state. */ - private final WeakReference managerRef; - - /** - * The properties used at this profile point. - */ - private final Set used = new LinkedHashSet<>(); - - /** - * set to true if the bean is modified (setter called) - */ - private boolean modified; - - /** - * The property that cause a reference to lazy load. - */ - private String loadProperty; - - public NodeUsageCollector(ObjectGraphNode node, WeakReference managerRef) { - this.node = node; - // weak to allow garbage collection. - this.managerRef = managerRef; + public State state() { + return state; } /** * The bean has been modified by a setter method. */ public void setModified() { - modified = true; + state.modified = true; } /** * Add the name of a property that has been used. */ public void addUsed(String property) { - used.add(property); - } - - /** - * The property that invoked a lazy load. - */ - public void setLoadProperty(String loadProperty) { - this.loadProperty = loadProperty; - } - - /** - * Publish the usage info to the manager. - */ - private void publishUsageInfo() { - NodeUsageListener manager = managerRef.get(); - if (manager != null) { - manager.collectNodeUsage(this); - } - } - - /** - * publish the collected usage information when garbage collection occurs. - */ - @Override - protected void finalize() throws Throwable { - publishUsageInfo(); - super.finalize(); - } - - /** - * Return the associated node which identifies the location in the object - * graph of the bean/reference. - */ - public ObjectGraphNode getNode() { - return node; - } - - /** - * Return true if no properties where used. - */ - public boolean isEmpty() { - return used.isEmpty(); - } - - /** - * Return the set of used properties. - */ - public Set getUsed() { - return used; - } - - /** - * Return true if the bean was modified by a setter. - */ - public boolean isModified() { - return modified; - } - - public String getLoadProperty() { - return loadProperty; + state.used.add(property); } @Override public String toString() { - return node + " read:" + used + " modified:" + modified; + return state.toString(); } } diff --git a/ebean-api/src/main/java/io/ebean/bean/NodeUsageListener.java b/ebean-api/src/main/java/io/ebean/bean/NodeUsageListener.java index bfa2c1892..0e4897e90 100644 --- a/ebean-api/src/main/java/io/ebean/bean/NodeUsageListener.java +++ b/ebean-api/src/main/java/io/ebean/bean/NodeUsageListener.java @@ -10,7 +10,6 @@ public interface NodeUsageListener { *

* This is the properties that are used for a given bean in the object graph. * This information is used by autoTune to tune queries. - *

*/ - void collectNodeUsage(NodeUsageCollector collector); + void collectNodeUsage(NodeUsageCollector.State state); } diff --git a/ebean-api/src/main/java/io/ebean/bean/ToStringBuilder.java b/ebean-api/src/main/java/io/ebean/bean/ToStringBuilder.java index 1dd87495a..70e759724 100644 --- a/ebean-api/src/main/java/io/ebean/bean/ToStringBuilder.java +++ b/ebean-api/src/main/java/io/ebean/bean/ToStringBuilder.java @@ -1,7 +1,10 @@ package io.ebean.bean; +import io.ebean.common.BeanMap; + import java.util.Collection; import java.util.IdentityHashMap; +import java.util.Map; /** * Helps build toString content taking into account recursion. @@ -104,6 +107,8 @@ public final class ToStringBuilder { } } else if (value instanceof Collection) { addCollection((Collection) value); + } else if (value instanceof Map) { + addMap(((Map) value)); } else { String content = String.valueOf(value); if (content.length() > TRIM_LENGTH) { @@ -117,6 +122,28 @@ public final class ToStringBuilder { } } + public void addMap(Map map) { + if (map == null || map.isEmpty()) { + sb.append("{}"); + } else { + boolean firstElement = true; + sb.append("{"); + for (Map.Entry entry : map.entrySet()) { + if (firstElement) { + firstElement = false; + } else { + sb.append(", "); + } + sb.append(entry.getKey()).append(":"); + value(entry.getValue()); + if (counter > MAX) { + return; + } + } + sb.append("}"); + } + } + /** * Add a collection of values. */ diff --git a/ebean-api/src/main/java/io/ebean/config/DatabaseConfig.java b/ebean-api/src/main/java/io/ebean/config/DatabaseConfig.java index cc5a31a3f..d47b5fbbf 100644 --- a/ebean-api/src/main/java/io/ebean/config/DatabaseConfig.java +++ b/ebean-api/src/main/java/io/ebean/config/DatabaseConfig.java @@ -340,11 +340,6 @@ public class DatabaseConfig { */ private ClassLoadConfig classLoadConfig = new ClassLoadConfig(); - /** - * The data source JNDI name if using a JNDI DataSource. - */ - private String dataSourceJndiName; - /** * The naming convention. */ @@ -392,12 +387,12 @@ public class DatabaseConfig { * Note: It is possible that multiple servers are sharing the same state file as * long as they are in the same JVM/ClassLoader scope. In this case it is * recommended to use the same uuidNodeId configuration. - * + * * If you have multiple servers in different JVMs, do not share the state * files! */ private String uuidNodeId; - + /** * The clock used for setting the timestamps (e.g. @UpdatedTimestamp) on objects. */ @@ -1761,24 +1756,6 @@ public class DatabaseConfig { this.readOnlyDataSourceConfig = readOnlyDataSourceConfig; } - /** - * Return the JNDI name of the DataSource to use. - */ - public String getDataSourceJndiName() { - return dataSourceJndiName; - } - - /** - * Set the JNDI name of the DataSource to use. - *

- * By default a prefix of "java:comp/env/jdbc/" is used to lookup the - * DataSource. This prefix is not used if dataSourceJndiName starts with - * "java:". - */ - public void setDataSourceJndiName(String dataSourceJndiName) { - this.dataSourceJndiName = dataSourceJndiName; - } - /** * Return a value used to represent TRUE in the database. *

@@ -2061,14 +2038,14 @@ public class DatabaseConfig { public void setUuidStateFile(String uuidStateFile) { this.uuidStateFile = uuidStateFile; } - + /** - * Returns the V1-UUID-NodeId + * Returns the V1-UUID-NodeId */ public String getUuidNodeId() { return uuidNodeId; } - + /** * Sets the V1-UUID-NodeId. */ @@ -2937,7 +2914,6 @@ public class DatabaseConfig { asOfViewSuffix = p.get("asOfViewSuffix", asOfViewSuffix); asOfSysPeriod = p.get("asOfSysPeriod", asOfSysPeriod); historyTableSuffix = p.get("historyTableSuffix", historyTableSuffix); - dataSourceJndiName = p.get("dataSourceJndiName", dataSourceJndiName); jdbcFetchSizeFindEach = p.getInt("jdbcFetchSizeFindEach", jdbcFetchSizeFindEach); jdbcFetchSizeFindList = p.getInt("jdbcFetchSizeFindList", jdbcFetchSizeFindList); databasePlatformName = p.get("databasePlatformName", databasePlatformName); diff --git a/ebean-api/src/main/java/io/ebean/config/ServerConfig.java b/ebean-api/src/main/java/io/ebean/config/ServerConfig.java deleted file mode 100644 index de02ae681..000000000 --- a/ebean-api/src/main/java/io/ebean/config/ServerConfig.java +++ /dev/null @@ -1,47 +0,0 @@ -package io.ebean.config; - -import io.ebean.DatabaseFactory; - -/** - * Deprecated - please migrate to io.ebean.DatabaseConfig. - * - * The configuration used for creating a Database. - *

- * Used to programmatically construct a Database and optionally register it - * with the DB singleton. - *

- *

- * If you just use DB without this programmatic configuration DB will read - * the application.properties file and take the configuration from there. This usually - * includes searching the class path and automatically registering any entity - * classes and listeners etc. - *

- *
{@code
- *
- * ServerConfig config = new ServerConfig();
- *
- * // read the ebean.properties and load
- * // those settings into this serverConfig object
- * config.loadFromProperties();
- *
- * // explicitly register the entity beans to avoid classpath scanning
- * config.addClass(Customer.class);
- * config.addClass(User.class);
- *
- * Database database = DatabaseFactory.create(config);
- *
- * }
- * - *

- * Note that ServerConfigProvider provides a standard Java ServiceLoader mechanism that can - * be used to apply configuration to the ServerConfig. - *

- * - * @author emcgreal - * @author rbygrave - * @see DatabaseFactory - */ -@Deprecated -public class ServerConfig extends DatabaseConfig { - -} diff --git a/ebean-api/src/main/java/io/ebean/config/ServerConfigProvider.java b/ebean-api/src/main/java/io/ebean/config/ServerConfigProvider.java deleted file mode 100644 index 1ba45907d..000000000 --- a/ebean-api/src/main/java/io/ebean/config/ServerConfigProvider.java +++ /dev/null @@ -1,41 +0,0 @@ -package io.ebean.config; - -/** - * Deprecated - migrate to DatabaseConfigProvider. - *

- * Provides a ServiceLoader based mechanism to configure a ServerConfig. - *

- * Provide an implementation and register it via the standard Java ServiceLoader mechanism - * via a file at META-INF/services/io.ebean.config.ServerConfigProvider. - *

- * If you are using a DI container like Spring or Guice you are unlikely to use this but instead use a - * spring specific configuration. When we are not using a DI container we may use this mechanism to - * explicitly register the entity beans and avoid classpath scanning. - *

- *
{@code
- *
- * public class EbeanConfigProvider implements ServerConfigProvider {
- *
- *   @Override
- *   public void apply(ServerConfig config) {
- *
- *     // register the entity bean classes explicitly
- *     config.addClass(Customer.class);
- *     config.addClass(User.class);
- *     ...
- *   }
- * }
- *
- * }
- */ -@Deprecated -public interface ServerConfigProvider { - - /** - * Apply the configuration to the ServerConfig. - *

- * Typically we explicitly register entity bean classes and thus avoid classpath scanning. - *

- */ - void apply(ServerConfig config); -} diff --git a/ebean-api/src/main/java/io/ebean/event/BeanDeleteIdRequest.java b/ebean-api/src/main/java/io/ebean/event/BeanDeleteIdRequest.java index 66831b69e..876ffaf39 100644 --- a/ebean-api/src/main/java/io/ebean/event/BeanDeleteIdRequest.java +++ b/ebean-api/src/main/java/io/ebean/event/BeanDeleteIdRequest.java @@ -1,7 +1,6 @@ package io.ebean.event; import io.ebean.Database; -import io.ebean.EbeanServer; import io.ebean.Transaction; /** @@ -9,63 +8,24 @@ import io.ebean.Transaction; */ public interface BeanDeleteIdRequest { - /** - * Deprecated migrate to database(). - */ - @Deprecated - EbeanServer getEbeanServer(); - - /** - * Deprecated migrate to database(). - */ - @Deprecated - default Database getDatabase() { - return getEbeanServer(); - } - /** * Return the DB processing the request. */ - default Database database() { - return getEbeanServer(); - } + Database database(); /** * Return the Transaction associated with this request. */ Transaction transaction(); - /** - * Deprecated migrate to transaction(). - */ - @Deprecated - default Transaction getTransaction() { - return transaction(); - } - /** * Returns the bean type of the bean being deleted. */ Class beanType(); - /** - * Deprecated migrate to beanType(). - */ - @Deprecated - default Class getBeanType() { - return beanType(); - } - /** * Returns the Id value of the bean being deleted. */ Object id(); - /** - * Deprecated migrate to id(). - */ - @Deprecated - default Object getId() { - return id(); - } } diff --git a/ebean-api/src/main/java/io/ebean/event/BeanPersistRequest.java b/ebean-api/src/main/java/io/ebean/event/BeanPersistRequest.java index 2f3198b65..eedfa53f4 100644 --- a/ebean-api/src/main/java/io/ebean/event/BeanPersistRequest.java +++ b/ebean-api/src/main/java/io/ebean/event/BeanPersistRequest.java @@ -1,7 +1,6 @@ package io.ebean.event; import io.ebean.Database; -import io.ebean.EbeanServer; import io.ebean.Transaction; import io.ebean.ValuePair; @@ -20,29 +19,13 @@ public interface BeanPersistRequest { /** * Return the DB processing the request. */ - default Database database() { - return getEbeanServer(); - } - - /** - * Deprecated migrate to database(). - */ - @Deprecated - EbeanServer getEbeanServer(); + Database database(); /** * Return the Transaction associated with this request. */ Transaction transaction(); - /** - * Deprecated migrate to transaction(). - */ - @Deprecated - default Transaction getTransaction() { - return transaction(); - } - /** * Return true if this request is due to cascading persist. * False implies this is a "top level" request. @@ -55,14 +38,6 @@ public interface BeanPersistRequest { */ Set loadedProperties(); - /** - * Deprecated migrate to loadedProperties(). - */ - @Deprecated - default Set getLoadedProperties() { - return loadedProperties(); - } - /** * For an update this is the set of properties that where updated. *

@@ -72,27 +47,11 @@ public interface BeanPersistRequest { */ Set updatedProperties(); - /** - * Deprecated migrate to updatedProperties(). - */ - @Deprecated - default Set getUpdatedProperties() { - return updatedProperties(); - } - /** * Flags set for dirty properties (used by ElasticSearch integration). */ boolean[] dirtyProperties(); - /** - * Deprecated migrate to updatedProperties(). - */ - @Deprecated - default boolean[] getDirtyProperties() { - return dirtyProperties(); - } - /** * Return true for an update request if at least one of dirty properties is contained * in the given set of property names. @@ -115,25 +74,9 @@ public interface BeanPersistRequest { */ T bean(); - /** - * Deprecated migrate to bean(). - */ - @Deprecated - default T getBean() { - return bean(); - } - /** * Returns a map of the properties that have changed and their new and old values. */ Map updatedValues(); - /** - * Deprecated migrate to updatedValues(). - */ - @Deprecated - default Map getUpdatedValues() { - return updatedValues(); - } - } diff --git a/ebean-api/src/main/java/io/ebean/event/BeanQueryRequest.java b/ebean-api/src/main/java/io/ebean/event/BeanQueryRequest.java index a8f2b7a29..8ae4fa16a 100644 --- a/ebean-api/src/main/java/io/ebean/event/BeanQueryRequest.java +++ b/ebean-api/src/main/java/io/ebean/event/BeanQueryRequest.java @@ -1,7 +1,6 @@ package io.ebean.event; import io.ebean.Database; -import io.ebean.EbeanServer; import io.ebean.Query; import io.ebean.Transaction; @@ -13,42 +12,18 @@ public interface BeanQueryRequest { /** * Return the DB processing the request. */ - default Database database() { - return getEbeanServer(); - } - - /** - * Deprecated migrate to database(). - */ - @Deprecated - EbeanServer getEbeanServer(); + Database database(); /** * Return the Transaction associated with this request. */ Transaction transaction(); - /** - * Deprecated migrate to transaction(). - */ - @Deprecated - default Transaction getTransaction() { - return transaction(); - } - /** * Returns the query. */ Query query(); - /** - * Deprecated migrate to query(). - */ - @Deprecated - default Query getQuery() { - return query(); - } - /** * Return true if an Id IN expression should have the bind parameters padded. */ diff --git a/ebean-api/src/main/java/io/ebean/event/BulkTableEvent.java b/ebean-api/src/main/java/io/ebean/event/BulkTableEvent.java index d37743303..a16ec8e3b 100644 --- a/ebean-api/src/main/java/io/ebean/event/BulkTableEvent.java +++ b/ebean-api/src/main/java/io/ebean/event/BulkTableEvent.java @@ -10,14 +10,6 @@ public interface BulkTableEvent { */ String tableName(); - /** - * Deprecated migrate to tableName(). - */ - @Deprecated - default String getTableName() { - return tableName(); - } - /** * Return true if rows were inserted. */ diff --git a/ebean-api/src/main/java/io/ebean/event/ClassUtil.java b/ebean-api/src/main/java/io/ebean/event/ClassUtil.java index 6f8173d21..72cea3955 100644 --- a/ebean-api/src/main/java/io/ebean/event/ClassUtil.java +++ b/ebean-api/src/main/java/io/ebean/event/ClassUtil.java @@ -10,10 +10,9 @@ class ClassUtil { * Return a new instance of the class using the default constructor. */ static Object newInstance(String className) { - try { Class cls = forName(className); - return cls.newInstance(); + return cls.getDeclaredConstructor().newInstance(); } catch (Exception e) { String msg = "Error constructing " + className; throw new IllegalArgumentException(msg, e); @@ -27,7 +26,6 @@ class ClassUtil { return new ClassLoadContext().forName(name); } - /** * Helper to wrap the context and caller classLoaders (to use/try both). */ @@ -48,7 +46,6 @@ class ClassUtil { } public Class forName(String name) throws ClassNotFoundException { - try { return Class.forName(name, true, contextLoader); } catch (ClassNotFoundException e) { @@ -59,7 +56,6 @@ class ClassUtil { } } } - } } diff --git a/ebean-api/src/main/java/io/ebean/plugin/SpiServer.java b/ebean-api/src/main/java/io/ebean/plugin/SpiServer.java index 96bf6eed1..f12869b7a 100644 --- a/ebean-api/src/main/java/io/ebean/plugin/SpiServer.java +++ b/ebean-api/src/main/java/io/ebean/plugin/SpiServer.java @@ -18,79 +18,31 @@ public interface SpiServer extends Database { */ DatabaseConfig config(); - /** - * Migrate to config(). - */ - @Deprecated - default DatabaseConfig getServerConfig() { - return config(); - } - /** * Return the DatabasePlatform for this database. */ DatabasePlatform databasePlatform(); - /** - * Migrate to config(). - */ - @Deprecated - default DatabasePlatform getDatabasePlatform() { - return databasePlatform(); - } - /** * Return all the bean types registered on this server instance. */ List> beanTypes(); - /** - * Migrate to beanTypes(). - */ - @Deprecated - default List> getBeanTypes() { - return beanTypes(); - } - /** * Return the bean type for a given entity bean class. */ BeanType beanType(Class beanClass); - /** - * Migrate to beanType(). - */ - @Deprecated - default BeanType getBeanType(Class beanClass) { - return beanType(beanClass); - } - /** * Return the bean types mapped to the given base table. */ List> beanTypes(String baseTableName); - /** - * Migrate to beanTypes(). - */ - @Deprecated - default List> getBeanTypes(String baseTableName) { - return beanTypes(baseTableName); - } - /** * Return the bean type for a given doc store queueId. */ BeanType beanTypeForQueueId(String queueId); - /** - * Migrate to beanTypes(). - */ - @Deprecated - default BeanType getBeanTypeForQueueId(String queueId) { - return beanTypeForQueueId(queueId); - } - /** * Return a BeanLoader. */ diff --git a/ebean-api/src/main/java/module-info.java b/ebean-api/src/main/java/module-info.java index 79fa3bb64..7c8453cea 100644 --- a/ebean-api/src/main/java/module-info.java +++ b/ebean-api/src/main/java/module-info.java @@ -19,6 +19,7 @@ module io.ebean.api { requires static io.ebean.types; requires static com.fasterxml.jackson.core; + requires static com.fasterxml.jackson.databind; requires static javax.servlet.api; exports io.ebean; diff --git a/ebean-api/src/test/java/io/ebean/bean/NodeUsageCollectorTest.java b/ebean-api/src/test/java/io/ebean/bean/NodeUsageCollectorTest.java new file mode 100644 index 000000000..103772249 --- /dev/null +++ b/ebean-api/src/test/java/io/ebean/bean/NodeUsageCollectorTest.java @@ -0,0 +1,42 @@ +package io.ebean.bean; + +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.assertThat; + +class NodeUsageCollectorTest { + + private final Listener listener = new Listener(); + + private final ObjectGraphNode node = new ObjectGraphNode((ObjectGraphOrigin) null, "foo"); + + /** + * Run this manually as we make use of explicit GC call here which is dubious. + */ + @Disabled + @Test + void test() throws InterruptedException { + NodeUsageCollector c = new NodeUsageCollector(node, listener); + c.addUsed("a"); + c.addUsed("b"); + c = null; + + System.gc(); + Thread.sleep(100); + + assertThat(listener.collectCount).isEqualTo(1); + assertThat(node).isNotNull(); + } + + static class Listener implements NodeUsageListener { + + int collectCount; + + @Override + public void collectNodeUsage(NodeUsageCollector.State collector) { + collectCount++; + System.out.println("collectNodeUsage " + collector); + } + } +} diff --git a/ebean-api/src/test/java/io/ebean/bean/ToStringBuilderTest.java b/ebean-api/src/test/java/io/ebean/bean/ToStringBuilderTest.java index 99f125ee5..c049ec9b0 100644 --- a/ebean-api/src/test/java/io/ebean/bean/ToStringBuilderTest.java +++ b/ebean-api/src/test/java/io/ebean/bean/ToStringBuilderTest.java @@ -166,12 +166,76 @@ class ToStringBuilderTest { assertThat(toStringFor(list)).isEqualTo("{a:Recurse@1(id:1, nm:a), b:Recurse@2(id:2, nm:b)}"); } + @Test + void map_recurse() { + final ParamStore paramStore = new ParamStore(1); + + paramStore.map.put("aaa", new ParamValue(1, paramStore)); + paramStore.map.put("bbb", new ParamValue(2, paramStore)); + + assertThat(toStringFor(paramStore)) + .isEqualTo("ParamStore@0(id:1, map:{aaa:ParamValue@1(id:1, pm:ParamStore@0), bbb:ParamValue@2(id:2, pm:ParamStore@0)})"); + } + private String toStringFor(ToStringAware aware) { ToStringBuilder builder = new ToStringBuilder(); aware.toString(builder); return builder.toString(); } + static final class ParamValue implements ToStringAware { + + final int id; + + final ParamStore parentModel; + + ParamValue(final int id, final ParamStore parentModel) { + this.id = id; + this.parentModel = parentModel; + } + + public String toString() { + ToStringBuilder builder = new ToStringBuilder(); + toString(builder); + return builder.toString(); + } + + @Override + public void toString(ToStringBuilder builder) { + builder.start(this); + builder.add("id", id); + builder.add("pm", parentModel); + builder.end(); + } + } + + static final class ParamStore implements ToStringAware { + + final int id; + + final Map map = new HashMap<>(); + + + ParamStore(final int id) { + this.id = id; + } + + public String toString() { + ToStringBuilder builder = new ToStringBuilder(); + toString(builder); + return builder.toString(); + } + + @Override + public void toString(ToStringBuilder builder) { + builder.start(this); + builder.add("id", id); + builder.add("map", map); + builder.end(); + } + } + + static final class Recurse implements ToStringAware { final int id; diff --git a/ebean-autotune/pom.xml b/ebean-autotune/pom.xml index 10c89fa2e..2cc8732ac 100644 --- a/ebean-autotune/pom.xml +++ b/ebean-autotune/pom.xml @@ -4,7 +4,7 @@ ebean-parent io.ebean - 13.3.1-SNAPSHOT + 13.6.0-SNAPSHOT @@ -26,7 +26,7 @@ io.ebean ebean-core - 13.3.1-SNAPSHOT + 13.6.0-SNAPSHOT provided @@ -55,7 +55,7 @@ io.ebean ebean-platform-h2 - 13.3.1-SNAPSHOT + 13.6.0-SNAPSHOT test diff --git a/ebean-autotune/src/main/java/io/ebeaninternal/server/autotune/service/ProfileManager.java b/ebean-autotune/src/main/java/io/ebeaninternal/server/autotune/service/ProfileManager.java index 019955114..24469ee75 100644 --- a/ebean-autotune/src/main/java/io/ebeaninternal/server/autotune/service/ProfileManager.java +++ b/ebean-autotune/src/main/java/io/ebeaninternal/server/autotune/service/ProfileManager.java @@ -91,8 +91,8 @@ public class ProfileManager implements ProfilingListener { * is called on the bean. */ @Override - public void collectNodeUsage(NodeUsageCollector usageCollector) { - ProfileOrigin profileOrigin = getProfileOrigin(usageCollector.getNode().getOriginQueryPoint()); + public void collectNodeUsage(NodeUsageCollector.State usageCollector) { + ProfileOrigin profileOrigin = getProfileOrigin(usageCollector.node().getOriginQueryPoint()); profileOrigin.collectUsageInfo(usageCollector); } diff --git a/ebean-autotune/src/main/java/io/ebeaninternal/server/autotune/service/ProfileOrigin.java b/ebean-autotune/src/main/java/io/ebeaninternal/server/autotune/service/ProfileOrigin.java index b9935f558..4e2427524 100644 --- a/ebean-autotune/src/main/java/io/ebeaninternal/server/autotune/service/ProfileOrigin.java +++ b/ebean-autotune/src/main/java/io/ebeaninternal/server/autotune/service/ProfileOrigin.java @@ -151,9 +151,9 @@ public class ProfileOrigin { /** * Collect the usage information for from a instance for this node. */ - public void collectUsageInfo(NodeUsageCollector profile) { + public void collectUsageInfo(NodeUsageCollector.State profile) { if (!profile.isEmpty()) { - getNodeStats(profile.getNode().getPath()).collectUsageInfo(profile); + getNodeStats(profile.node().getPath()).collectUsageInfo(profile); } } diff --git a/ebean-autotune/src/main/java/io/ebeaninternal/server/autotune/service/ProfileOriginNodeUsage.java b/ebean-autotune/src/main/java/io/ebeaninternal/server/autotune/service/ProfileOriginNodeUsage.java index 1f2a655dc..c5a3c17db 100644 --- a/ebean-autotune/src/main/java/io/ebeaninternal/server/autotune/service/ProfileOriginNodeUsage.java +++ b/ebean-autotune/src/main/java/io/ebeaninternal/server/autotune/service/ProfileOriginNodeUsage.java @@ -103,11 +103,10 @@ public class ProfileOriginNodeUsage { /** * Collect usage from a node. */ - protected void collectUsageInfo(NodeUsageCollector profile) { + protected void collectUsageInfo(NodeUsageCollector.State profile) { lock.lock(); try { - Set used = profile.getUsed(); - + Set used = profile.used(); profileCount++; if (!used.isEmpty()) { profileUsedCount++; diff --git a/ebean-autotune/src/test/java/io/ebeaninternal/server/autotune/service/ProfileOriginTest.java b/ebean-autotune/src/test/java/io/ebeaninternal/server/autotune/service/ProfileOriginTest.java index 9f981a404..371d1976b 100644 --- a/ebean-autotune/src/test/java/io/ebeaninternal/server/autotune/service/ProfileOriginTest.java +++ b/ebean-autotune/src/test/java/io/ebeaninternal/server/autotune/service/ProfileOriginTest.java @@ -1,6 +1,7 @@ package io.ebeaninternal.server.autotune.service; import io.ebean.bean.NodeUsageCollector; +import io.ebean.bean.NodeUsageListener; import io.ebean.bean.ObjectGraphNode; import io.ebean.bean.ObjectGraphOrigin; import io.ebeaninternal.server.deploy.BeanDescriptor; @@ -13,6 +14,15 @@ import static org.assertj.core.api.Assertions.assertThat; public class ProfileOriginTest extends BaseTestCase { + static class Noop implements NodeUsageListener { + @Override + public void collectNodeUsage(NodeUsageCollector.State state) { + // do nothing + } + } + + private final NodeUsageListener listener = new Noop(); + private final BeanDescriptor desc = getBeanDescriptor(Order.class); @Test @@ -23,7 +33,7 @@ public class ProfileOriginTest extends BaseTestCase { c.addUsed("name"); ProfileOrigin po = new ProfileOrigin(null, false, 1, 1); - po.collectUsageInfo(c); + po.collectUsageInfo(c.state()); OrmQueryDetail detail = po.buildDetail(desc); @@ -38,11 +48,11 @@ public class ProfileOriginTest extends BaseTestCase { c.addUsed("name"); ProfileOrigin po = new ProfileOrigin(null, false, 1, 1); - po.collectUsageInfo(c); + po.collectUsageInfo(c.state()); c = node(null); c.addUsed("orderDate"); - po.collectUsageInfo(c); + po.collectUsageInfo(c.state()); OrmQueryDetail detail = po.buildDetail(desc); @@ -56,11 +66,11 @@ public class ProfileOriginTest extends BaseTestCase { c.addUsed("id"); ProfileOrigin po = new ProfileOrigin(null, false, 1, 1); - po.collectUsageInfo(c); + po.collectUsageInfo(c.state()); c = node(null); c.addUsed("orderDate"); - po.collectUsageInfo(c); + po.collectUsageInfo(c.state()); OrmQueryDetail detail = po.buildDetail(desc); @@ -75,15 +85,15 @@ public class ProfileOriginTest extends BaseTestCase { NodeUsageCollector c = node(null); c.addUsed("orderDate"); c.addUsed("customer"); - po.collectUsageInfo(c); + po.collectUsageInfo(c.state()); c = node("customer"); c.addUsed("billingAddress"); - po.collectUsageInfo(c); + po.collectUsageInfo(c.state()); c = node("customer.billingAddress"); c.addUsed("id"); - po.collectUsageInfo(c); + po.collectUsageInfo(c.state()); OrmQueryDetail detail = po.buildDetail(desc); @@ -100,20 +110,20 @@ public class ProfileOriginTest extends BaseTestCase { NodeUsageCollector c = node(null); c.addUsed("customer"); - po.collectUsageInfo(c); + po.collectUsageInfo(c.state()); c = node("customer"); c.addUsed("id"); c.addUsed("name"); c.addUsed("note"); c.addUsed("billingAddress"); - po.collectUsageInfo(c); + po.collectUsageInfo(c.state()); //fetch details.product (id,name) c = node("customer.billingAddress"); c.addUsed("id"); c.addUsed("line1"); - po.collectUsageInfo(c); + po.collectUsageInfo(c.state()); OrmQueryDetail detail = po.buildDetail(desc); assertThat(detail.asString()).isEqualTo("fetch customer (name,note) fetch customer.billingAddress (line1)"); @@ -121,7 +131,7 @@ public class ProfileOriginTest extends BaseTestCase { private NodeUsageCollector node(String path) { ObjectGraphNode node = new ObjectGraphNode((ObjectGraphOrigin)null, path); - return new NodeUsageCollector(node, null); + return new NodeUsageCollector(node, listener); } // @Test diff --git a/ebean-bom/pom.xml b/ebean-bom/pom.xml index 14d2b6d40..13f09ecd3 100644 --- a/ebean-bom/pom.xml +++ b/ebean-bom/pom.xml @@ -4,7 +4,7 @@ ebean-parent io.ebean - 13.3.1-SNAPSHOT + 13.6.0-SNAPSHOT ebean bom @@ -71,88 +71,88 @@ io.ebean ebean - 13.3.1-SNAPSHOT + 13.6.0-SNAPSHOT io.ebean ebean-api - 13.3.1-SNAPSHOT + 13.6.0-SNAPSHOT io.ebean ebean-core - 13.3.1-SNAPSHOT + 13.6.0-SNAPSHOT io.ebean ebean-core-type - 13.3.1-SNAPSHOT + 13.6.0-SNAPSHOT io.ebean ebean-ddl-generator - 13.3.1-SNAPSHOT + 13.6.0-SNAPSHOT io.ebean ebean-externalmapping-api - 13.3.1-SNAPSHOT + 13.6.0-SNAPSHOT io.ebean ebean-externalmapping-xml - 13.3.1-SNAPSHOT + 13.6.0-SNAPSHOT io.ebean ebean-autotune - 13.3.1-SNAPSHOT + 13.6.0-SNAPSHOT io.ebean ebean-querybean - 13.3.1-SNAPSHOT + 13.6.0-SNAPSHOT io.ebean querybean-generator - 13.3.1-SNAPSHOT + 13.6.0-SNAPSHOT provided io.ebean kotlin-querybean-generator - 13.3.1-SNAPSHOT + 13.6.0-SNAPSHOT provided io.ebean ebean-test - 13.3.1-SNAPSHOT + 13.6.0-SNAPSHOT test io.ebean ebean-postgis - 13.3.1-SNAPSHOT + 13.6.0-SNAPSHOT io.ebean ebean-redis - 13.3.1-SNAPSHOT + 13.6.0-SNAPSHOT diff --git a/ebean-core-type/pom.xml b/ebean-core-type/pom.xml index 14e9e36d4..1a5499f5e 100644 --- a/ebean-core-type/pom.xml +++ b/ebean-core-type/pom.xml @@ -4,7 +4,7 @@ ebean-parent io.ebean - 13.3.1-SNAPSHOT + 13.6.0-SNAPSHOT ebean-core-type @@ -16,7 +16,7 @@ io.ebean ebean-api - 13.3.1-SNAPSHOT + 13.6.0-SNAPSHOT diff --git a/ebean-core/pom.xml b/ebean-core/pom.xml index c5da1233f..cd8d88949 100644 --- a/ebean-core/pom.xml +++ b/ebean-core/pom.xml @@ -3,7 +3,7 @@ ebean-parent io.ebean - 13.3.1-SNAPSHOT + 13.6.0-SNAPSHOT ebean-core @@ -41,19 +41,19 @@ io.ebean ebean-api - 13.3.1-SNAPSHOT + 13.6.0-SNAPSHOT io.ebean ebean-core-type - 13.3.1-SNAPSHOT + 13.6.0-SNAPSHOT io.ebean ebean-externalmapping-api - 13.3.1-SNAPSHOT + 13.6.0-SNAPSHOT @@ -144,21 +144,21 @@ io.ebean ebean-platform-h2 - 13.3.1-SNAPSHOT + 13.6.0-SNAPSHOT test io.ebean ebean-platform-postgres - 13.3.1-SNAPSHOT + 13.6.0-SNAPSHOT test io.ebean ebean-platform-sqlserver - 13.3.1-SNAPSHOT + 13.6.0-SNAPSHOT test diff --git a/ebean-core/src/main/java/io/ebeaninternal/api/SpiEbeanServer.java b/ebean-core/src/main/java/io/ebeaninternal/api/SpiEbeanServer.java index 027956e1f..57ca5e9bc 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/api/SpiEbeanServer.java +++ b/ebean-core/src/main/java/io/ebeaninternal/api/SpiEbeanServer.java @@ -23,7 +23,7 @@ import java.util.stream.Stream; /** * Service Provider extension to EbeanServer. */ -public interface SpiEbeanServer extends SpiServer, ExtendedServer, EbeanServer, BeanCollectionLoader { +public interface SpiEbeanServer extends SpiServer, ExtendedServer, BeanCollectionLoader { /** * Return true if the L2 cache has been disabled. @@ -55,7 +55,6 @@ public interface SpiEbeanServer extends SpiServer, ExtendedServer, EbeanServer, *

* Typically used to identify the origin of queries for AutoTune and object * graph costing. - *

*/ CallOrigin createCallOrigin(); diff --git a/ebean-core/src/main/java/io/ebeaninternal/api/SpiQuery.java b/ebean-core/src/main/java/io/ebeaninternal/api/SpiQuery.java index 222f00b9a..ef939a8f5 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/api/SpiQuery.java +++ b/ebean-core/src/main/java/io/ebeaninternal/api/SpiQuery.java @@ -391,6 +391,11 @@ public interface SpiQuery extends Query, SpiQueryFetch, TxnProfileEventCod */ void incrementAsOfTableCount(); + /** + * Increment the counter of tables used in 'As Of' query. + */ + void incrementAsOfTableCount(int asOfTableCount); + /** * Return the table alias used for the base table. */ diff --git a/ebean-core/src/main/java/io/ebeaninternal/api/SpiTransactionProxy.java b/ebean-core/src/main/java/io/ebeaninternal/api/SpiTransactionProxy.java index c4f81bcab..a46bf033f 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/api/SpiTransactionProxy.java +++ b/ebean-core/src/main/java/io/ebeaninternal/api/SpiTransactionProxy.java @@ -312,11 +312,6 @@ public abstract class SpiTransactionProxy implements SpiTransaction { transaction.flush(); } - @Override - public void flushBatch() throws PersistenceException { - flush(); - } - @Override public Connection connection() { return transaction.connection(); diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/cache/DefaultServerCache.java b/ebean-core/src/main/java/io/ebeaninternal/server/cache/DefaultServerCache.java index ae3a297b3..f3b49fd2e 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/cache/DefaultServerCache.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/cache/DefaultServerCache.java @@ -13,6 +13,8 @@ import java.io.Serializable; import java.lang.ref.SoftReference; import java.util.*; import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicLong; +import java.util.concurrent.locks.ReentrantLock; /** * The default cache implementation. @@ -43,10 +45,13 @@ public class DefaultServerCache implements ServerCache { protected final String name; protected final String shortName; - private final int maxSize; - private final int trimFrequency; - private final int maxIdleSecs; - private final int maxSecsToLive; + protected final int maxSize; + protected final int trimFrequency; + protected final int maxIdleSecs; + protected final int maxSecsToLive; + protected final long trimOnPut; + protected final ReentrantLock lock = new ReentrantLock(); + protected final AtomicLong mutationCounter = new AtomicLong(); public DefaultServerCache(DefaultServerCacheConfig config) { this.name = config.getName(); @@ -56,6 +61,7 @@ public class DefaultServerCache implements ServerCache { this.maxIdleSecs = config.getMaxIdleSecs(); this.maxSecsToLive = config.getMaxSecsToLive(); this.trimFrequency = config.determineTrimFrequency(); + this.trimOnPut = config.determineTrimOnPut(); MetricFactory factory = MetricFactory.get(); String prefix = "l2n."; @@ -187,6 +193,9 @@ public class DefaultServerCache implements ServerCache { public void put(Object key, Object value) { map.put(key, new SoftReference<>(new CacheEntry(key, value))); putCount.increment(); + if (mutationCounter.incrementAndGet() > trimOnPut) { + runEviction(); + } } /** @@ -222,62 +231,72 @@ public class DefaultServerCache implements ServerCache { * Run the eviction based on Idle time, Time to live and LRU last access. */ public void runEviction() { - long trimForMaxSize; - if (maxSize == 0) { - trimForMaxSize = 0; - } else { - trimForMaxSize = size() - maxSize; - } - if (maxIdleSecs == 0 && maxSecsToLive == 0 && trimForMaxSize < 0) { - // nothing to trim on this cache - return; - } - long startNanos = System.nanoTime(); - long trimmedByIdle = 0; - long trimmedByGC = 0; - long trimmedByTTL = 0; - long trimmedByLRU = 0; - - List activeList = new ArrayList<>(map.size()); - long idleExpireNano = startNanos - TimeUnit.SECONDS.toNanos(maxIdleSecs); - long ttlExpireNano = startNanos - TimeUnit.SECONDS.toNanos(maxSecsToLive); - Iterator> it = map.values().iterator(); - while (it.hasNext()) { - SoftReference ref = it.next(); - final CacheEntry cacheEntry = ref.get(); - if (cacheEntry == null) { - it.remove(); - trimmedByGC++; - } else if (maxIdleSecs > 0 && idleExpireNano > cacheEntry.getLastAccessTime()) { - it.remove(); - trimmedByIdle++; - } else if (maxSecsToLive > 0 && ttlExpireNano > cacheEntry.getCreateTime()) { - it.remove(); - trimmedByTTL++; - } else if (trimForMaxSize > 0) { - activeList.add(cacheEntry); + lock.lock(); + try { + long trimForMaxSize; + if (maxSize == 0) { + trimForMaxSize = 0; + } else { + trimForMaxSize = size() - maxSize; } - } - if (trimForMaxSize > 0 && activeList.size() > maxSize) { - // sort into last access time ascending - activeList.sort(BY_LAST_ACCESS); - int trimSize = getTrimSize(); - for (int i = trimSize; i < activeList.size(); i++) { - // remove if still in the cache - if (map.remove(activeList.get(i).getKey()) != null) { - trimmedByLRU++; + if (maxIdleSecs == 0 && maxSecsToLive == 0 && trimForMaxSize < 0) { + // nothing to trim on this cache + mutationCounter.set(0); + return; + } + long startNanos = System.nanoTime(); + long trimmedByIdle = 0; + long trimmedByGC = 0; + long trimmedByTTL = 0; + long trimmedByLRU = 0; + + try { + List activeList = new ArrayList<>(map.size()); + long idleExpireNano = startNanos - TimeUnit.SECONDS.toNanos(maxIdleSecs); + long ttlExpireNano = startNanos - TimeUnit.SECONDS.toNanos(maxSecsToLive); + Iterator> it = map.values().iterator(); + while (it.hasNext()) { + SoftReference ref = it.next(); + final CacheEntry cacheEntry = ref.get(); + if (cacheEntry == null) { + it.remove(); + trimmedByGC++; + } else if (maxIdleSecs > 0 && idleExpireNano > cacheEntry.getLastAccessTime()) { + it.remove(); + trimmedByIdle++; + } else if (maxSecsToLive > 0 && ttlExpireNano > cacheEntry.getCreateTime()) { + it.remove(); + trimmedByTTL++; + } else if (trimForMaxSize > 0) { + activeList.add(cacheEntry.forSort()); + } } + if (trimForMaxSize > 0 && activeList.size() > maxSize) { + // sort into last access time ascending + activeList.sort(BY_LAST_ACCESS); + int trimSize = getTrimSize(); + for (int i = trimSize; i < activeList.size(); i++) { + // remove if still in the cache + if (map.remove(activeList.get(i).getKey()) != null) { + trimmedByLRU++; + } + } + } + mutationCounter.set(0); + evictCount.add(trimmedByIdle); + evictCount.add(trimmedByGC); + evictCount.add(trimmedByTTL); + evictCount.add(trimmedByLRU); + if (logger.isTraceEnabled()) { + long exeMicros = TimeUnit.MICROSECONDS.convert(System.nanoTime() - startNanos, TimeUnit.NANOSECONDS); + logger.trace("Executed trim of cache {} in [{}]millis idle[{}] timeToLive[{}] accessTime[{}] gc[{}]", + name, exeMicros, trimmedByIdle, trimmedByTTL, trimmedByLRU, trimmedByGC); + } + } catch (Throwable e) { + logger.warn("Error during trim of DefaultServerCache [" + name + "]. Cache might be bigger than desired.", e); } - } - - evictCount.add(trimmedByIdle); - evictCount.add(trimmedByGC); - evictCount.add(trimmedByTTL); - evictCount.add(trimmedByLRU); - if (logger.isTraceEnabled()) { - long exeMicros = TimeUnit.MICROSECONDS.convert(System.nanoTime() - startNanos, TimeUnit.NANOSECONDS); - logger.trace("Executed trim of cache {} in [{}]millis idle[{}] timeToLive[{}] accessTime[{}] gc[{}]", - name, exeMicros, trimmedByIdle, trimmedByTTL, trimmedByLRU, trimmedByGC); + } finally { + lock.unlock(); } } @@ -293,7 +312,7 @@ public class DefaultServerCache implements ServerCache { } /** - * Comparator for sorting by last access time. + * Comparator for sorting by last access sort, a copy of last access time that should not mutate during trim processing. */ public static final class CompareByLastAccess implements Comparator, Serializable { @@ -301,7 +320,7 @@ public class DefaultServerCache implements ServerCache { @Override public int compare(CacheEntry e1, CacheEntry e2) { - return Long.compare(e1.getLastAccessTime(), e2.getLastAccessTime()); + return Long.compare(e1.lastAccessSort, e2.lastAccessSort); } } @@ -314,6 +333,7 @@ public class DefaultServerCache implements ServerCache { private final Object value; private final long createTime; private long lastAccessTime; + private long lastAccessSort; public CacheEntry(Object key, Object value) { this.key = key; @@ -322,6 +342,14 @@ public class DefaultServerCache implements ServerCache { this.lastAccessTime = createTime; } + /** + * Store a copy of lastAccessTime used for sorting. This value should not change during trim processing. + */ + public CacheEntry forSort() { + this.lastAccessSort = lastAccessTime; + return this; + } + /** * Return the entry key. */ diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/cache/DefaultServerCacheConfig.java b/ebean-core/src/main/java/io/ebeaninternal/server/cache/DefaultServerCacheConfig.java index 2e5c5dbcd..3f3a5c0f0 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/cache/DefaultServerCacheConfig.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/cache/DefaultServerCacheConfig.java @@ -76,4 +76,14 @@ public final class DefaultServerCacheConfig { } return 0; } + + /** + * Determine the number of mutations/puts required to trigger a runEviction() in the foreground. + */ + public long determineTrimOnPut() { + if (maxSize > 0) { + return maxSize / 10; + } + return 1000; + } } diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/cluster/ClusterManager.java b/ebean-core/src/main/java/io/ebeaninternal/server/cluster/ClusterManager.java index a85444486..b273c031a 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/cluster/ClusterManager.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/cluster/ClusterManager.java @@ -1,6 +1,6 @@ package io.ebeaninternal.server.cluster; -import io.ebean.EbeanServer; +import io.ebean.Database; import io.ebean.config.ContainerConfig; import io.ebeaninternal.server.transaction.RemoteTransactionEvent; import org.slf4j.Logger; @@ -20,7 +20,7 @@ public class ClusterManager implements ServerLookup { private final ReentrantLock lock = new ReentrantLock(); - private final ConcurrentHashMap serverMap = new ConcurrentHashMap<>(); + private final ConcurrentHashMap serverMap = new ConcurrentHashMap<>(); private final Object monitor = new Object(); @@ -53,7 +53,7 @@ public class ClusterManager implements ServerLookup { return factory; } - public void registerServer(EbeanServer server) { + public void registerServer(Database server) { lock.lock(); try { serverMap.put(server.name(), server); @@ -66,7 +66,7 @@ public class ClusterManager implements ServerLookup { } @Override - public EbeanServer getServer(String name) { + public Database getServer(String name) { lock.lock(); try { return serverMap.get(name); diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/cluster/ServerLookup.java b/ebean-core/src/main/java/io/ebeaninternal/server/cluster/ServerLookup.java index abf835371..c3240bf8c 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/cluster/ServerLookup.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/cluster/ServerLookup.java @@ -1,14 +1,14 @@ package io.ebeaninternal.server.cluster; -import io.ebean.EbeanServer; +import io.ebean.Database; /** - * Returns EbeanServer instances for remote message reading. + * Returns Database instances for remote message reading. */ public interface ServerLookup { /** * Return the EbeanServer instance by name. */ - EbeanServer getServer(String name); + Database getServer(String name); } diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/core/BeanRequest.java b/ebean-core/src/main/java/io/ebeaninternal/server/core/BeanRequest.java index cc900d831..45fe5ff14 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/core/BeanRequest.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/core/BeanRequest.java @@ -1,6 +1,6 @@ package io.ebeaninternal.server.core; -import io.ebean.EbeanServer; +import io.ebean.Database; import io.ebeaninternal.api.CoreLog; import io.ebeaninternal.api.SpiEbeanServer; import io.ebeaninternal.api.SpiTransaction; @@ -79,7 +79,7 @@ public abstract class BeanRequest { * Return the server processing the request. Made available for * BeanController and BeanFinder. */ - public EbeanServer getEbeanServer() { + public Database database() { return server; } diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/core/DefaultContainer.java b/ebean-core/src/main/java/io/ebeaninternal/server/core/DefaultContainer.java index 148014569..70c0e0cf7 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/core/DefaultContainer.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/core/DefaultContainer.java @@ -5,8 +5,6 @@ import io.ebean.config.ContainerConfig; import io.ebean.config.DatabaseConfig; import io.ebean.config.DatabaseConfigProvider; import io.ebean.config.ModuleInfoLoader; -import io.ebean.config.ServerConfig; -import io.ebean.config.ServerConfigProvider; import io.ebean.config.TenantMode; import io.ebean.config.UnderscoreNamingConvention; import io.ebean.config.dbplatform.DatabasePlatform; @@ -124,15 +122,8 @@ public final class DefaultContainer implements SpiContainer { private void applyConfigServices(DatabaseConfig config) { if (config.isDefaultServer()) { - boolean appliedConfig = false; for (DatabaseConfigProvider configProvider : ServiceLoader.load(DatabaseConfigProvider.class)) { configProvider.apply(config); - appliedConfig = true; - } - if (!appliedConfig && config instanceof ServerConfig) { - for (ServerConfigProvider configProvider : ServiceLoader.load(ServerConfigProvider.class)) { - configProvider.apply((ServerConfig)config); - } } } if (config.isAutoLoadModuleInfo()) { diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/core/InitDataSource.java b/ebean-core/src/main/java/io/ebeaninternal/server/core/InitDataSource.java index 54bfff518..833f00986 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/core/InitDataSource.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/core/InitDataSource.java @@ -14,7 +14,6 @@ import javax.sql.DataSource; */ final class InitDataSource { - private final JndiDataSourceLookup jndiDataSourceFactory = new JndiDataSourceLookup(); private final DatabaseConfig config; /** @@ -41,21 +40,9 @@ final class InitDataSource { * Initialise the "main" read write DataSource from configuration. */ private DataSource initDataSource() { - final String jndiName = config.getDataSourceJndiName(); - if (jndiName != null) { - return jndiDataSource(jndiName); - } return createFromConfig(config.getDataSourceConfig(), false); } - private DataSource jndiDataSource(String jndiName) { - DataSource ds = jndiDataSourceFactory.lookup(jndiName); - if (ds == null) { - throw new PersistenceException("JNDI lookup for DataSource " + jndiName + " returned null."); - } - return ds; - } - /** * Initialise the "read only" DataSource from configuration. */ diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/core/JndiDataSourceLookup.java b/ebean-core/src/main/java/io/ebeaninternal/server/core/JndiDataSourceLookup.java deleted file mode 100644 index 09b2f7a9c..000000000 --- a/ebean-core/src/main/java/io/ebeaninternal/server/core/JndiDataSourceLookup.java +++ /dev/null @@ -1,33 +0,0 @@ -package io.ebeaninternal.server.core; - -import javax.naming.Context; -import javax.naming.InitialContext; -import javax.naming.NamingException; -import javax.persistence.PersistenceException; -import javax.sql.DataSource; - -/** - * Helper to lookup a DataSource from JNDI. - */ -class JndiDataSourceLookup { - - /** - * Return the DataSource by JNDI lookup. - *

- * If name is null the 'default' dataSource is returned. - *

- */ - public DataSource lookup(String jndiName) { - try { - Context ctx = new InitialContext(); - DataSource ds = (DataSource) ctx.lookup(jndiName); - if (ds == null) { - throw new PersistenceException("JNDI DataSource [" + jndiName + "] not found?"); - } - return ds; - - } catch (NamingException ex) { - throw new PersistenceException(ex); - } - } -} diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/core/bootup/BootupClasses.java b/ebean-core/src/main/java/io/ebeaninternal/server/core/bootup/BootupClasses.java index 491739c13..3fc4bbb95 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/core/bootup/BootupClasses.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/core/bootup/BootupClasses.java @@ -91,7 +91,7 @@ public class BootupClasses implements Predicate> { public void runServerConfigStartup(DatabaseConfig config) { for (Class cls : serverConfigStartupCandidates) { try { - ServerConfigStartup newInstance = (ServerConfigStartup) cls.newInstance(); + ServerConfigStartup newInstance = (ServerConfigStartup) cls.getDeclaredConstructor().newInstance(); newInstance.onStart(config); } catch (Exception e) { // assume that the desired behavior is to fail - add your own try catch if needed diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanDescriptorElementEmbedded.java b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanDescriptorElementEmbedded.java index 70f6eb85c..71d79b9dc 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanDescriptorElementEmbedded.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanDescriptorElementEmbedded.java @@ -22,7 +22,7 @@ class BeanDescriptorElementEmbedded extends BeanDescriptorElement { BeanDescriptorElementEmbedded(BeanDescriptorMap owner, DeployBeanDescriptor deploy, ElementHelp elementHelp) { super(owner, deploy, elementHelp); try { - this.prototype = (EntityBean) beanType.newInstance(); + this.prototype = (EntityBean) beanType.getDeclaredConstructor().newInstance(); } catch (Exception e) { throw new IllegalStateException("Unable to create entity bean prototype for "+beanType); } diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/DbSqlContext.java b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/DbSqlContext.java index 1fccc46f3..ff6839723 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/DbSqlContext.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/DbSqlContext.java @@ -119,6 +119,11 @@ public interface DbSqlContext { */ boolean isIncludeSoftDelete(); + /** + * Return the count of history table AS OF predicates added via joins. + */ + int asOfTableCount(); + /** * Return true if the query is a 'asDraft' query. */ diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/parse/DeployInheritInfo.java b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/parse/DeployInheritInfo.java index ef92648fb..3df70b406 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/parse/DeployInheritInfo.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/parse/DeployInheritInfo.java @@ -259,15 +259,11 @@ public final class DeployInheritInfo implements Comparable { } @Override - public int compareTo(DeployInheritInfo o) { - if (o == this || o.discriminatorStringValue == null && discriminatorStringValue == null) { + public int compareTo(DeployInheritInfo other) { + if (other == this) { return 0; - } else if (o.discriminatorStringValue == null) { - return 1; - } else if (discriminatorStringValue == null) { - return -1; } else { - return discriminatorStringValue.compareTo(o.discriminatorStringValue); + return type.getName().compareTo(other.type.getName()); } } diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/executor/DefaultBackgroundExecutor.java b/ebean-core/src/main/java/io/ebeaninternal/server/executor/DefaultBackgroundExecutor.java index 6e49ff255..b4c13a8bd 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/executor/DefaultBackgroundExecutor.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/executor/DefaultBackgroundExecutor.java @@ -100,22 +100,11 @@ public final class DefaultBackgroundExecutor implements SpiBackgroundExecutor { return pool.submit(wrap(task)); } - @Override public void execute(Runnable task) { submit(logExceptions(task)); } - @Override - public void executePeriodically(Runnable task, long delay, TimeUnit unit) { - schedulePool.scheduleWithFixedDelay(wrap(logExceptions(task)), delay, delay, unit); - } - - @Override - public void executePeriodically(Runnable task, long initialDelay, long delay, TimeUnit unit) { - schedulePool.scheduleWithFixedDelay(wrap(logExceptions(task)), initialDelay, delay, unit); - } - @Override public ScheduledFuture scheduleWithFixedDelay(Runnable task, long initialDelay, long delay, TimeUnit unit) { return schedulePool.scheduleWithFixedDelay(wrap(logExceptions(task)), initialDelay, delay, unit); diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/persist/DeleteIdRequest.java b/ebean-core/src/main/java/io/ebeaninternal/server/persist/DeleteIdRequest.java index 714744d36..0409af64d 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/persist/DeleteIdRequest.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/persist/DeleteIdRequest.java @@ -1,15 +1,15 @@ package io.ebeaninternal.server.persist; -import io.ebean.EbeanServer; +import io.ebean.Database; import io.ebean.Transaction; import io.ebean.event.BeanDeleteIdRequest; import io.ebeaninternal.api.SpiEbeanServer; final class DeleteIdRequest implements BeanDeleteIdRequest { - private final EbeanServer server; + private final SpiEbeanServer server; private final Transaction transaction; - private Class beanType; + private final Class beanType; private Object id; DeleteIdRequest(SpiEbeanServer server, Transaction transaction, Class beanType, Object id) { @@ -24,7 +24,7 @@ final class DeleteIdRequest implements BeanDeleteIdRequest { } @Override - public EbeanServer getEbeanServer() { + public Database database() { return server; } diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/query/CQuery.java b/ebean-core/src/main/java/io/ebeaninternal/server/query/CQuery.java index 22e2e1f37..3566ee08a 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/query/CQuery.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/query/CQuery.java @@ -18,7 +18,6 @@ import io.ebeaninternal.server.core.SpiOrmQueryRequest; import io.ebeaninternal.server.deploy.*; import javax.persistence.PersistenceException; -import java.lang.ref.WeakReference; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; @@ -149,8 +148,6 @@ public final class CQuery implements DbReadContext, CancelableQuery, SpiProfi private final ProfilingListener profilingListener; - private final WeakReference profilingListenerRef; - private final Boolean readOnly; private long profileOffset; @@ -189,7 +186,6 @@ public final class CQuery implements DbReadContext, CancelableQuery, SpiProfi this.objectGraphNode = query.getParentNode(); this.profilingListener = query.getProfilingListener(); this.autoTuneProfiling = profilingListener != null; - this.profilingListenerRef = autoTuneProfiling ? new WeakReference<>(profilingListener) : null; // set the generated sql back to the query // so its available to the user... query.setGeneratedSql(queryPlan.getSql()); @@ -673,7 +669,7 @@ public final class CQuery implements DbReadContext, CancelableQuery, SpiProfi @Override public void profileBean(EntityBeanIntercept ebi, String prefix) { ObjectGraphNode node = request.loadContext().getObjectGraphNode(prefix); - ebi.setNodeUsageCollector(new NodeUsageCollector(node, profilingListenerRef)); + ebi.setNodeUsageCollector(new NodeUsageCollector(node, profilingListener)); } @Override diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/query/CQueryBuilder.java b/ebean-core/src/main/java/io/ebeaninternal/server/query/CQueryBuilder.java index 77dc2b1e6..b32492cec 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/query/CQueryBuilder.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/query/CQueryBuilder.java @@ -644,9 +644,12 @@ final class CQueryBuilder { } private void appendHistoryAsOfPredicate() { - if (query.isAsOfBaseTable() && !historySupport.isStandardsBased()) { - appendAndOrWhere(); - sb.append(historySupport.getAsOfPredicate(request.baseTableAlias())); + if (query.isAsOfBaseTable()) { + query.incrementAsOfTableCount(); + if (!historySupport.isStandardsBased()){ + appendAndOrWhere(); + sb.append(historySupport.getAsOfPredicate(request.baseTableAlias())); + } } } diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/query/DefaultDbSqlContext.java b/ebean-core/src/main/java/io/ebeaninternal/server/query/DefaultDbSqlContext.java index 4e45c564c..63fa76d92 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/query/DefaultDbSqlContext.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/query/DefaultDbSqlContext.java @@ -18,45 +18,27 @@ final class DefaultDbSqlContext implements DbSqlContext { private static final String tableAliasManyPlaceHolder = "${mta}"; private final String columnAliasPrefix; - private final ArrayStack tableAliasStack = new ArrayStack<>(); - private final ArrayStack joinStack = new ArrayStack<>(); - private final ArrayStack prefixStack = new ArrayStack<>(); - private final String fromForUpdate; - private boolean useColumnAlias; - private int columnIndex; - + private int asOfTableCount; private StringBuilder sb = new StringBuilder(STRING_BUILDER_INITIAL_CAPACITY); - /** * A Set used to make sure formula joins are only added once to a query. */ private HashSet formulaJoins; - private HashSet tableJoins; - private final SqlTreeAlias alias; - private String currentPrefix; - private List encryptedProps; - private List extraJoins; - private final CQueryDraftSupport draftSupport; - private final CQueryHistorySupport historySupport; - private final boolean historyQuery; - /** - * Construct for SELECT clause (with column alias settings). - */ DefaultDbSqlContext(SqlTreeAlias alias, String columnAliasPrefix, CQueryHistorySupport historySupport, CQueryDraftSupport draftSupport, String fromForUpdate) { this.alias = alias; @@ -116,7 +98,6 @@ final class DefaultDbSqlContext implements DbSqlContext { if (encryptedProps == null) { return null; } - return encryptedProps.toArray(new BeanProperty[0]); } @@ -153,6 +134,9 @@ final class DefaultDbSqlContext implements DbSqlContext { String asOfView = historySupport.getAsOfView(table); appendTable(table, asOfView); if (asOfView != null) { + if (historySupport.isStandardsBased()) { + asOfTableCount++; + } addAsOfOnClause = !historySupport.isStandardsBased(); } } @@ -178,6 +162,7 @@ final class DefaultDbSqlContext implements DbSqlContext { } if (addAsOfOnClause) { sb.append(" and ").append(historySupport.getAsOfPredicate(a2)); + asOfTableCount++; } if (extraWhere != null && !extraWhere.isEmpty()) { sb.append(" and "); @@ -195,6 +180,11 @@ final class DefaultDbSqlContext implements DbSqlContext { } } + @Override + public int asOfTableCount() { + return asOfTableCount; + } + @Override public boolean isDraftQuery() { return draftSupport != null; @@ -236,7 +226,7 @@ final class DefaultDbSqlContext implements DbSqlContext { @Override public void appendFormulaJoin(String sqlFormulaJoin, SqlJoinType joinType, String manyWhere) { - // replace ${ta} place holder with the real table alias... + // replace ${ta} placeholder with the real table alias... String tableAlias = manyWhere == null ? tableAliasStack.peek() : getTableAliasManyWhere(manyWhere); String converted = sqlFormulaJoin.replace(tableAliasPlaceHolder, tableAlias); if (formulaJoins == null) { @@ -250,9 +240,9 @@ final class DefaultDbSqlContext implements DbSqlContext { formulaJoins.add(converted); sb.append(" "); if (joinType == SqlJoinType.OUTER) { - if ("join".equals(sqlFormulaJoin.substring(0, 4).toLowerCase())) { + if ("join".equalsIgnoreCase(sqlFormulaJoin.substring(0, 4))) { // prepend left as we are in the 'many' part - append(" left "); + sb.append("left "); } } sb.append(converted); diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/query/DefaultFetchGroupQuery.java b/ebean-core/src/main/java/io/ebeaninternal/server/query/DefaultFetchGroupQuery.java index da8caf0b1..fbc791937 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/query/DefaultFetchGroupQuery.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/query/DefaultFetchGroupQuery.java @@ -432,26 +432,11 @@ final class DefaultFetchGroupQuery implements SpiFetchGroupQuery, SpiQuery throw new RuntimeException("EB102: Only select() and fetch() clause is allowed on FetchGroup"); } - @Override - public Query order(String orderByClause) { - throw new RuntimeException("EB102: Only select() and fetch() clause is allowed on FetchGroup"); - } - - @Override - public OrderBy order() { - throw new RuntimeException("EB102: Only select() and fetch() clause is allowed on FetchGroup"); - } - @Override public OrderBy orderBy() { throw new RuntimeException("EB102: Only select() and fetch() clause is allowed on FetchGroup"); } - @Override - public Query setOrder(OrderBy orderBy) { - throw new RuntimeException("EB102: Only select() and fetch() clause is allowed on FetchGroup"); - } - @Override public Query setOrderBy(OrderBy orderBy) { throw new RuntimeException("EB102: Only select() and fetch() clause is allowed on FetchGroup"); diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/query/SqlTreeBuilder.java b/ebean-core/src/main/java/io/ebeaninternal/server/query/SqlTreeBuilder.java index 79e46860a..faf4a2a5a 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/query/SqlTreeBuilder.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/query/SqlTreeBuilder.java @@ -130,6 +130,7 @@ public final class SqlTreeBuilder { groupBy = buildGroupByClause(); distinctOn = buildDistinctOn(); encryptedProps = ctx.getEncryptedProps(); + query.incrementAsOfTableCount(ctx.asOfTableCount()); } boolean includeJoins = alias != null && alias.isIncludeJoins(); diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/query/SqlTreeNodeBean.java b/ebean-core/src/main/java/io/ebeaninternal/server/query/SqlTreeNodeBean.java index 346bd2014..a09e7ad41 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/query/SqlTreeNodeBean.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/query/SqlTreeNodeBean.java @@ -304,20 +304,7 @@ class SqlTreeNodeBean implements SqlTreeNode { @Override public void addAsOfTableAlias(SpiQuery query) { - // if history on this bean type add it's alias - // for each alias we add an effect date predicate - if (desc.isHistorySupport()) { - query.incrementAsOfTableCount(); - } - if (lazyLoadParent != null && lazyLoadParent.isManyToManyWithHistory()) { - query.incrementAsOfTableCount(); - } - if (intersectionAsOfTableAlias) { - query.incrementAsOfTableCount(); - } - for (SqlTreeNode child : children) { - child.addAsOfTableAlias(query); - } + // do nothing for non-root, handled by DbSqlContext for joins } @Override diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/query/SqlTreeNodeRoot.java b/ebean-core/src/main/java/io/ebeaninternal/server/query/SqlTreeNodeRoot.java index 35f038e4e..13ee00b93 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/query/SqlTreeNodeRoot.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/query/SqlTreeNodeRoot.java @@ -58,13 +58,6 @@ final class SqlTreeNodeRoot extends SqlTreeNodeBean { public void addAsOfTableAlias(SpiQuery query) { if (desc.isHistorySupport()) { query.setAsOfBaseTable(); - query.incrementAsOfTableCount(); - } - if (lazyLoadParent != null && lazyLoadParent.isManyToManyWithHistory()) { - query.incrementAsOfTableCount(); - } - for (SqlTreeNode aChildren : children) { - aChildren.addAsOfTableAlias(query); } } diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/querydefn/DefaultOrmQuery.java b/ebean-core/src/main/java/io/ebeaninternal/server/querydefn/DefaultOrmQuery.java index 6aa0f9a6a..df2e1a2aa 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/querydefn/DefaultOrmQuery.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/querydefn/DefaultOrmQuery.java @@ -32,7 +32,7 @@ import java.util.stream.Stream; * Default implementation of an Object Relational query. */ @NonNullApi -public final class DefaultOrmQuery extends AbstractQuery implements SpiQuery { +public class DefaultOrmQuery extends AbstractQuery implements SpiQuery { private static final String DEFAULT_QUERY_NAME = "default"; private static final FetchConfig FETCH_CACHE = FetchConfig.ofCache(); @@ -173,33 +173,32 @@ public final class DefaultOrmQuery extends AbstractQuery implements SpiQuery< this.detail = new OrmQueryDetail(); } - public void setNativeSql(String nativeSql) { + public final void setNativeSql(String nativeSql) { this.nativeSql = nativeSql; } @Override - public DtoQuery asDto(Class dtoClass) { + public final DtoQuery asDto(Class dtoClass) { return server.findDto(dtoClass, this); } @Override - public UpdateQuery asUpdate() { + public final UpdateQuery asUpdate() { return new DefaultUpdateQuery<>(this); } @Override - public BeanDescriptor getBeanDescriptor() { + public final BeanDescriptor getBeanDescriptor() { return beanDescriptor; } - @Override - public boolean isFindAll() { + public final boolean isFindAll() { return whereExpressions == null && nativeSql == null && rawSql == null; } @Override - public boolean isFindById() { + public final boolean isFindById() { if (id == null && whereExpressions != null) { id = whereExpressions.idEqualTo(beanDescriptor.idName()); if (id != null) { @@ -210,7 +209,7 @@ public final class DefaultOrmQuery extends AbstractQuery implements SpiQuery< } @Override - public String profileEventId() { + public final String profileEventId() { switch (mode) { case LAZYLOAD_BEAN: return FIND_ONE_LAZY; @@ -222,23 +221,23 @@ public final class DefaultOrmQuery extends AbstractQuery implements SpiQuery< } @Override - public String getProfileId() { + public final String getProfileId() { return getPlanLabel(); } @Override - public Query setProfileLocation(ProfileLocation profileLocation) { + public final Query setProfileLocation(ProfileLocation profileLocation) { this.profileLocation = profileLocation; return this; } @Override - public String getLabel() { + public final String getLabel() { return label; } @Override - public String getPlanLabel() { + public final String getPlanLabel() { if (label != null) { return label; } @@ -249,41 +248,41 @@ public final class DefaultOrmQuery extends AbstractQuery implements SpiQuery< } @Override - public void setProfilePath(String label, String relativePath, ProfileLocation profileLocation) { + public final void setProfilePath(String label, String relativePath, ProfileLocation profileLocation) { this.profileLocation = profileLocation; this.label = ((profileLocation == null) ? label : profileLocation.label()) + "_" + relativePath; } @Override - public Query setLabel(String label) { + public final Query setLabel(String label) { this.label = label; return this; } @Override - public boolean isAutoTunable() { + public final boolean isAutoTunable() { return nativeSql == null && beanDescriptor.isAutoTunable(); } @Override - public Query setUseDocStore(boolean useDocStore) { + public final Query setUseDocStore(boolean useDocStore) { this.useDocStore = useDocStore; return this; } @Override - public boolean isUseDocStore() { + public final boolean isUseDocStore() { return useDocStore; } @Override - public Query apply(FetchPath fetchPath) { + public final Query apply(FetchPath fetchPath) { fetchPath.apply(this); return this; } @Override - public void addSoftDeletePredicate(String softDeletePredicate) { + public final void addSoftDeletePredicate(String softDeletePredicate) { if (softDeletePredicates == null) { softDeletePredicates = new ArrayList<>(); } @@ -291,86 +290,91 @@ public final class DefaultOrmQuery extends AbstractQuery implements SpiQuery< } @Override - public List getSoftDeletePredicates() { + public final List getSoftDeletePredicates() { return softDeletePredicates; } @Override - public boolean isAsOfBaseTable() { + public final boolean isAsOfBaseTable() { return asOfBaseTable; } @Override - public void setAsOfBaseTable() { + public final void setAsOfBaseTable() { this.asOfBaseTable = true; } @Override - public Query setAllowLoadErrors() { + public final Query setAllowLoadErrors() { this.allowLoadErrors = true; return this; } @Override - public void incrementAsOfTableCount() { + public final void incrementAsOfTableCount() { asOfTableCount++; } @Override - public int getAsOfTableCount() { + public final void incrementAsOfTableCount(int increment) { + asOfTableCount += increment; + } + + @Override + public final int getAsOfTableCount() { return asOfTableCount; } @Override - public Timestamp getAsOf() { + public final Timestamp getAsOf() { return asOf; } @Override - public Query asOf(Timestamp asOfDateTime) { + public final Query asOf(Timestamp asOfDateTime) { this.temporalMode = (asOfDateTime != null) ? TemporalMode.AS_OF : TemporalMode.CURRENT; this.asOf = asOfDateTime; return this; } @Override - public Query asDraft() { + public final Query asDraft() { this.temporalMode = TemporalMode.DRAFT; this.useBeanCache = CacheMode.OFF; return this; } @Override - public Query setIncludeSoftDeletes() { + public final Query setIncludeSoftDeletes() { this.temporalMode = TemporalMode.SOFT_DELETED; return this; } @Override - public Query setDocIndexName(String indexName) { + public final Query setDocIndexName(String indexName) { this.docIndexName = indexName; this.useDocStore = true; return this; } @Override - public String getDocIndexName() { + public final String getDocIndexName() { return docIndexName; } @Override - public SpiRawSql getRawSql() { + public final SpiRawSql getRawSql() { return rawSql; } @Override - public Query setRawSql(RawSql rawSql) { + public final Query setRawSql(RawSql rawSql) { this.rawSql = (SpiRawSql) rawSql; return this; } @Override - public String getOriginKey() { + public final String getOriginKey() { if (parentNode == null || parentNode.getOriginQueryPoint() == null) { return null; } else { @@ -379,32 +383,32 @@ public final class DefaultOrmQuery extends AbstractQuery implements SpiQuery< } @Override - public int getLazyLoadBatchSize() { + public final int getLazyLoadBatchSize() { return lazyLoadBatchSize; } @Override - public Query setLazyLoadBatchSize(int lazyLoadBatchSize) { + public final Query setLazyLoadBatchSize(int lazyLoadBatchSize) { this.lazyLoadBatchSize = lazyLoadBatchSize; return this; } @Override - public String getLazyLoadProperty() { + public final String getLazyLoadProperty() { return lazyLoadProperty; } @Override - public void setLazyLoadProperty(String lazyLoadProperty) { + public final void setLazyLoadProperty(String lazyLoadProperty) { this.lazyLoadProperty = lazyLoadProperty; } @Override - public ExpressionFactory getExpressionFactory() { + public final ExpressionFactory getExpressionFactory() { return expressionFactory; } - private void createExtraJoinsToSupportManyWhereClause() { + private final void createExtraJoinsToSupportManyWhereClause() { manyWhereJoins = new ManyWhereJoins(); if (whereExpressions != null) { whereExpressions.containsMany(beanDescriptor, manyWhereJoins); @@ -426,7 +430,7 @@ public final class DefaultOrmQuery extends AbstractQuery implements SpiQuery< * Return the extra joins required to support the where clause for 'Many' properties. */ @Override - public ManyWhereJoins getManyWhereJoins() { + public final ManyWhereJoins getManyWhereJoins() { return manyWhereJoins; } @@ -435,7 +439,7 @@ public final class DefaultOrmQuery extends AbstractQuery implements SpiQuery< * included in the query. */ @Override - public boolean selectAllForLazyLoadProperty() { + public final boolean selectAllForLazyLoadProperty() { if (lazyLoadProperty != null) { if (!detail.containsProperty(lazyLoadProperty)) { detail.select("*"); @@ -476,12 +480,12 @@ public final class DefaultOrmQuery extends AbstractQuery implements SpiQuery< } @Override - public void setLazyLoadManyPath(String lazyLoadManyPath) { + public final void setLazyLoadManyPath(String lazyLoadManyPath) { this.lazyLoadManyPath = lazyLoadManyPath; } @Override - public SpiQuerySecondary convertJoins() { + public final SpiQuerySecondary convertJoins() { if (!useDocStore) { createExtraJoinsToSupportManyWhereClause(); } @@ -505,7 +509,7 @@ public final class DefaultOrmQuery extends AbstractQuery implements SpiQuery< } @Override - public void setDefaultSelectClause() { + public final void setDefaultSelectClause() { if (type.defaultSelect()) { detail.setDefaultSelectClause(beanDescriptor); } else if (!detail.hasSelectClause()) { @@ -515,39 +519,39 @@ public final class DefaultOrmQuery extends AbstractQuery implements SpiQuery< } @Override - public void setTenantId(Object tenantId) { + public final void setTenantId(Object tenantId) { this.tenantId = tenantId; } @Override - public Object getTenantId() { + public final Object getTenantId() { return tenantId; } @Override - public void setDetail(OrmQueryDetail detail) { + public final void setDetail(OrmQueryDetail detail) { this.detail = detail; } @Override - public boolean tuneFetchProperties(OrmQueryDetail tunedDetail) { + public final boolean tuneFetchProperties(OrmQueryDetail tunedDetail) { return detail.tuneFetchProperties(tunedDetail); } @Override - public OrmQueryDetail getDetail() { + public final OrmQueryDetail getDetail() { return detail; } @Override - public ExpressionList filterMany(String prop) { + public final ExpressionList filterMany(String prop) { OrmQueryProperties chunk = detail.getChunk(prop, true); return chunk.filterMany(this); } @Override - public void setFilterMany(String prop, ExpressionList filterMany) { + public final void setFilterMany(String prop, ExpressionList filterMany) { if (filterMany != null) { OrmQueryProperties chunk = detail.getChunk(prop, true); chunk.setFilterMany((SpiExpressionList) filterMany); @@ -555,7 +559,7 @@ public final class DefaultOrmQuery extends AbstractQuery implements SpiQuery< } @Override - public void prepareDocNested() { + public final void prepareDocNested() { if (textExpressions != null) { textExpressions.prepareDocNested(beanDescriptor); } @@ -568,14 +572,14 @@ public final class DefaultOrmQuery extends AbstractQuery implements SpiQuery< * Setup to be a delete or update query. */ @Override - public void setupForDeleteOrUpdate() { + public final void setupForDeleteOrUpdate() { forUpdate = null; rootTableAlias = "${RTA}"; // alias we remove later setSelectId(); } @Override - public CQueryPlanKey setDeleteByIdsPlan() { + public final CQueryPlanKey setDeleteByIdsPlan() { // re-build plan for cascading via delete by ids queryPlanKey = queryPlanKey.withDeleteByIds(); return queryPlanKey; @@ -585,14 +589,14 @@ public final class DefaultOrmQuery extends AbstractQuery implements SpiQuery< * Set the select clause to select the Id property. */ @Override - public void setSelectId() { + public final void setSelectId() { // clear select and fetch joins detail.clear(); select(beanDescriptor.idSelect()); } @Override - public void setSingleAttribute() { + public final void setSingleAttribute() { this.singleAttribute = true; } @@ -600,12 +604,12 @@ public final class DefaultOrmQuery extends AbstractQuery implements SpiQuery< * Return true if this is a single attribute query. */ @Override - public boolean isSingleAttribute() { + public final boolean isSingleAttribute() { return singleAttribute; } @Override - public CountDistinctOrder getCountDistinctOrder() { + public final CountDistinctOrder getCountDistinctOrder() { return countDistinctOrder; } @@ -613,12 +617,12 @@ public final class DefaultOrmQuery extends AbstractQuery implements SpiQuery< * Return true if the Id should be included in the query. */ @Override - public boolean isWithId() { + public final boolean isWithId() { return !manualId && !distinct && !singleAttribute; } @Override - public CacheIdLookup cacheIdLookup() { + public final CacheIdLookup cacheIdLookup() { if (whereExpressions == null) { return null; } @@ -642,7 +646,7 @@ public final class DefaultOrmQuery extends AbstractQuery implements SpiQuery< } @Override - public NaturalKeyQueryData naturalKey() { + public final NaturalKeyQueryData naturalKey() { if (whereExpressions == null) { return null; } @@ -662,7 +666,7 @@ public final class DefaultOrmQuery extends AbstractQuery implements SpiQuery< } @Override - public NaturalKeyBindParam getNaturalKeyBindParam() { + public final NaturalKeyBindParam getNaturalKeyBindParam() { NaturalKeyBindParam namedBind = null; if (bindParams != null) { namedBind = bindParams.getNaturalKeyBindParam(); @@ -747,38 +751,38 @@ public final class DefaultOrmQuery extends AbstractQuery implements SpiQuery< } @Override - public Query setPersistenceContextScope(PersistenceContextScope scope) { + public final Query setPersistenceContextScope(PersistenceContextScope scope) { this.persistenceContextScope = scope; return this; } @Override - public PersistenceContextScope getPersistenceContextScope() { + public final PersistenceContextScope getPersistenceContextScope() { return persistenceContextScope; } @Override - public Type getType() { + public final Type getType() { return type; } @Override - public void setType(Type type) { + public final void setType(Type type) { this.type = type; } @Override - public String getLoadDescription() { + public final String getLoadDescription() { return loadDescription; } @Override - public String getLoadMode() { + public final String getLoadMode() { return loadMode; } @Override - public void setLoadDescription(String loadMode, String loadDescription) { + public final void setLoadDescription(String loadMode, String loadDescription) { this.loadMode = loadMode; this.loadDescription = loadDescription; } @@ -791,7 +795,7 @@ public final class DefaultOrmQuery extends AbstractQuery implements SpiQuery< *

*/ @Override - public PersistenceContext getPersistenceContext() { + public final PersistenceContext getPersistenceContext() { return persistenceContext; } @@ -803,17 +807,17 @@ public final class DefaultOrmQuery extends AbstractQuery implements SpiQuery< *

*/ @Override - public void setPersistenceContext(PersistenceContext persistenceContext) { + public final void setPersistenceContext(PersistenceContext persistenceContext) { this.persistenceContext = persistenceContext; } @Override - public void setLazyLoadForParents(BeanPropertyAssocMany many) { + public final void setLazyLoadForParents(BeanPropertyAssocMany many) { this.lazyLoadForParentsProperty = many; } @Override - public BeanPropertyAssocMany getLazyLoadMany() { + public final BeanPropertyAssocMany getLazyLoadMany() { return lazyLoadForParentsProperty; } @@ -821,60 +825,60 @@ public final class DefaultOrmQuery extends AbstractQuery implements SpiQuery< * Return true if the query detail has neither select or joins specified. */ @Override - public boolean isDetailEmpty() { + public final boolean isDetailEmpty() { return detail.isEmpty(); } @Override - public boolean isAutoTuned() { + public final boolean isAutoTuned() { return autoTuned; } @Override - public void setAutoTuned(boolean autoTuned) { + public final void setAutoTuned(boolean autoTuned) { this.autoTuned = autoTuned; } @Override - public Boolean isAutoTune() { + public final Boolean isAutoTune() { return autoTune; } @Override - public void setDefaultRawSqlIfRequired() { + public final void setDefaultRawSqlIfRequired() { if (beanDescriptor.isRawSqlBased() && rawSql == null) { rawSql = beanDescriptor.namedRawSql(DEFAULT_QUERY_NAME); } } @Override - public Query setAutoTune(boolean autoTune) { + public final Query setAutoTune(boolean autoTune) { this.autoTune = autoTune; return this; } @Override - public Query withLock(LockType lockType) { + public final Query withLock(LockType lockType) { return setForUpdateWithMode(LockWait.WAIT, lockType); } @Override - public Query withLock(LockType lockType, LockWait lockWait) { + public final Query withLock(LockType lockType, LockWait lockWait) { return setForUpdateWithMode(lockWait, lockType); } @Override - public Query forUpdate() { + public final Query forUpdate() { return setForUpdateWithMode(LockWait.WAIT, LockType.DEFAULT); } @Override - public Query forUpdateNoWait() { + public final Query forUpdateNoWait() { return setForUpdateWithMode(LockWait.NOWAIT, LockType.DEFAULT); } @Override - public Query forUpdateSkipLocked() { + public final Query forUpdateSkipLocked() { return setForUpdateWithMode(LockWait.SKIPLOCKED, LockType.DEFAULT); } @@ -886,32 +890,32 @@ public final class DefaultOrmQuery extends AbstractQuery implements SpiQuery< } @Override - public boolean isForUpdate() { + public final boolean isForUpdate() { return forUpdate != null; } @Override - public LockWait getForUpdateLockWait() { + public final LockWait getForUpdateLockWait() { return forUpdate; } @Override - public LockType getForUpdateLockType() { + public final LockType getForUpdateLockType() { return lockType; } @Override - public ProfilingListener getProfilingListener() { + public final ProfilingListener getProfilingListener() { return profilingListener; } @Override - public void setProfilingListener(ProfilingListener profilingListener) { + public final void setProfilingListener(ProfilingListener profilingListener) { this.profilingListener = profilingListener; } @Override - public QueryType getQueryType() { + public final QueryType getQueryType() { if (type != null) { switch (type) { case DELETE: @@ -924,57 +928,57 @@ public final class DefaultOrmQuery extends AbstractQuery implements SpiQuery< } @Override - public Mode getMode() { + public final Mode getMode() { return mode; } @Override - public TemporalMode getTemporalMode() { + public final TemporalMode getTemporalMode() { return temporalMode; } @Override - public boolean isAsOfQuery() { + public final boolean isAsOfQuery() { return asOf != null; } @Override - public boolean isAsDraft() { + public final boolean isAsDraft() { return TemporalMode.DRAFT == temporalMode; } @Override - public boolean isIncludeSoftDeletes() { + public final boolean isIncludeSoftDeletes() { return TemporalMode.SOFT_DELETED == temporalMode; } @Override - public void setMode(Mode mode) { + public final void setMode(Mode mode) { this.mode = mode; } @Override - public boolean isUsageProfiling() { + public final boolean isUsageProfiling() { return usageProfiling; } @Override - public void setUsageProfiling(boolean usageProfiling) { + public final void setUsageProfiling(boolean usageProfiling) { this.usageProfiling = usageProfiling; } @Override - public void setParentNode(ObjectGraphNode parentNode) { + public final void setParentNode(ObjectGraphNode parentNode) { this.parentNode = parentNode; } @Override - public ObjectGraphNode getParentNode() { + public final ObjectGraphNode getParentNode() { return parentNode; } @Override - public ObjectGraphNode setOrigin(CallOrigin callOrigin) { + public final ObjectGraphNode setOrigin(CallOrigin callOrigin) { // create a 'origin' which links this query to the profiling information ObjectGraphOrigin o = new ObjectGraphOrigin(calculateOriginQueryHash(), callOrigin, beanType.getName()); parentNode = new ObjectGraphNode(o, null); @@ -1001,7 +1005,7 @@ public final class DefaultOrmQuery extends AbstractQuery implements SpiQuery< /** * Calculate the query hash for either AutoTune query tuning or Query Plan caching. */ - CQueryPlanKey createQueryPlanKey() { + final CQueryPlanKey createQueryPlanKey() { if (isNativeSql()) { String bindHash = (bindParams == null) ? "" : bindParams.calcQueryPlanHash(); queryPlanKey = new NativeSqlQueryPlanKey(type.ordinal() + nativeSql + "-" + firstRow + "-" + maxRows + "-" + bindHash); @@ -1096,17 +1100,17 @@ public final class DefaultOrmQuery extends AbstractQuery implements SpiQuery< } @Override - public boolean isNativeSql() { + public final boolean isNativeSql() { return nativeSql != null; } @Override - public String getNativeSql() { + public final String getNativeSql() { return nativeSql; } @Override - public Object getQueryPlanKey() { + public final Object getQueryPlanKey() { return queryPlanKey; } @@ -1114,7 +1118,7 @@ public final class DefaultOrmQuery extends AbstractQuery implements SpiQuery< * Prepare the query which prepares any expressions (sub-query expressions etc) and calculates the query plan key. */ @Override - public CQueryPlanKey prepare(SpiOrmQueryRequest request) { + public final CQueryPlanKey prepare(SpiOrmQueryRequest request) { prepareExpressions(request); prepareForPaging(); queryPlanKey = createQueryPlanKey(); @@ -1152,7 +1156,7 @@ public final class DefaultOrmQuery extends AbstractQuery implements SpiQuery< } @Override - public void queryBindKey(BindValuesKey key) { + public final void queryBindKey(BindValuesKey key) { key.add(id); if (whereExpressions != null) whereExpressions.queryBindKey(key); if (havingExpressions != null) havingExpressions.queryBindKey(key); @@ -1168,7 +1172,7 @@ public final class DefaultOrmQuery extends AbstractQuery implements SpiQuery< *

*/ @Override - public HashQuery queryHash() { + public final HashQuery queryHash() { // calculateQueryPlanHash is called just after potential AutoTune tuning // so queryPlanHash is calculated well before this method is called BindValuesKey bindKey = new BindValuesKey(); @@ -1177,7 +1181,7 @@ public final class DefaultOrmQuery extends AbstractQuery implements SpiQuery< } @Override - public boolean isRawSql() { + public final boolean isRawSql() { return rawSql != null; } @@ -1185,151 +1189,151 @@ public final class DefaultOrmQuery extends AbstractQuery implements SpiQuery< * Return the timeout. */ @Override - public int getTimeout() { + public final int getTimeout() { return timeout; } @Override - public boolean hasMaxRowsOrFirstRow() { + public final boolean hasMaxRowsOrFirstRow() { return maxRows > 0 || firstRow > 0; } @Override - public boolean isVersionsBetween() { + public final boolean isVersionsBetween() { return versionsStart != null; } @Override - public Timestamp getVersionStart() { + public final Timestamp getVersionStart() { return versionsStart; } @Override - public Timestamp getVersionEnd() { + public final Timestamp getVersionEnd() { return versionsEnd; } @Override - public Boolean isReadOnly() { + public final Boolean isReadOnly() { return readOnly; } @Override - public Query setReadOnly(boolean readOnly) { + public final Query setReadOnly(boolean readOnly) { this.readOnly = readOnly; return this; } @Override - public boolean isBeanCachePut() { + public final boolean isBeanCachePut() { return useBeanCache.isPut() && beanDescriptor.isBeanCaching(); } @Override - public boolean isBeanCacheGet() { + public final boolean isBeanCacheGet() { return useBeanCache.isGet() && beanDescriptor.isBeanCaching(); } @Override - public boolean isForceHitDatabase() { + public final boolean isForceHitDatabase() { return forUpdate != null || CacheMode.PUT == useBeanCache; } @Override - public void resetBeanCacheAutoMode(boolean findOne) { + public final void resetBeanCacheAutoMode(boolean findOne) { if (useBeanCache == CacheMode.AUTO && useQueryCache != CacheMode.OFF) { useBeanCache = CacheMode.OFF; } } @Override - public CacheMode getUseBeanCache() { + public final CacheMode getUseBeanCache() { return useBeanCache; } @Override - public CacheMode getUseQueryCache() { + public final CacheMode getUseQueryCache() { return useQueryCache; } @Override - public Query setBeanCacheMode(CacheMode beanCacheMode) { + public final Query setBeanCacheMode(CacheMode beanCacheMode) { this.useBeanCache = beanCacheMode; return this; } @Override - public Query setUseQueryCache(CacheMode useQueryCache) { + public final Query setUseQueryCache(CacheMode useQueryCache) { this.useQueryCache = useQueryCache; return this; } @Override - public Query setLoadBeanCache(boolean loadBeanCache) { + public final Query setLoadBeanCache(boolean loadBeanCache) { this.useBeanCache = CacheMode.PUT; return this; } @Override - public Query setTimeout(int secs) { + public final Query setTimeout(int secs) { this.timeout = secs; return this; } @Override - public void selectProperties(Set props) { + public final void selectProperties(Set props) { detail.selectProperties(props); } @Override - public void fetchProperties(String property, Set columns, FetchConfig config) { + public final void fetchProperties(String property, Set columns, FetchConfig config) { detail.fetchProperties(property, columns, config); } @Override - public void selectProperties(OrmQueryProperties properties) { + public final void selectProperties(OrmQueryProperties properties) { detail.selectProperties(properties); } @Override - public void fetchProperties(String path, OrmQueryProperties other) { + public final void fetchProperties(String path, OrmQueryProperties other) { detail.fetchProperties(path, other); } @Override - public void addNested(String name, OrmQueryDetail nestedDetail, FetchConfig config) { + public final void addNested(String name, OrmQueryDetail nestedDetail, FetchConfig config) { detail.addNested(name, nestedDetail, config); } @Override - public Query select(String columns) { + public final Query select(String columns) { detail.select(columns); return this; } @Override - public Query select(FetchGroup fetchGroup) { + public final Query select(FetchGroup fetchGroup) { this.detail = ((SpiFetchGroup) fetchGroup).detail(); return this; } @Override - public Query fetch(String path) { + public final Query fetch(String path) { return fetch(path, null, null); } @Override - public Query fetch(String path, FetchConfig joinConfig) { + public final Query fetch(String path, FetchConfig joinConfig) { return fetch(path, null, joinConfig); } @Override - public Query fetch(String path, String properties) { + public final Query fetch(String path, String properties) { return fetch(path, properties, null); } @Override - public Query fetch(String path, String properties, FetchConfig config) { + public final Query fetch(String path, String properties, FetchConfig config) { if (nativeSql != null && (config == null || config.isJoin())) { // can't use fetch join with nativeSql (as the root query) config = FETCH_QUERY; @@ -1338,32 +1342,32 @@ public final class DefaultOrmQuery extends AbstractQuery implements SpiQuery< } @Override - public Query fetchQuery(String path) { + public final Query fetchQuery(String path) { return fetchInternal(path, null, FETCH_QUERY); } @Override - public Query fetchCache(String path) { + public final Query fetchCache(String path) { return fetchInternal(path, null, FETCH_CACHE); } @Override - public Query fetchLazy(String path) { + public final Query fetchLazy(String path) { return fetchInternal(path, null, FETCH_LAZY); } @Override - public Query fetchQuery(String path, String properties) { + public final Query fetchQuery(String path, String properties) { return fetchInternal(path, properties, FETCH_QUERY); } @Override - public Query fetchCache(String path, String properties) { + public final Query fetchCache(String path, String properties) { return fetchInternal(path, properties, FETCH_CACHE); } @Override - public Query fetchLazy(String path, String properties) { + public final Query fetchLazy(String path, String properties) { return fetchInternal(path, properties, FETCH_LAZY); } @@ -1373,45 +1377,45 @@ public final class DefaultOrmQuery extends AbstractQuery implements SpiQuery< } @Override - public Query usingTransaction(Transaction transaction) { + public final Query usingTransaction(Transaction transaction) { this.transaction = (SpiTransaction) transaction; return this; } @Override - public Query usingConnection(Connection connection) { + public final Query usingConnection(Connection connection) { this.transaction = new ExternalJdbcTransaction(connection); return this; } @Override - public Query usingDatabase(Database database) { + public final Query usingDatabase(Database database) { this.server = (SpiEbeanServer) database; return this; } @Override - public int delete() { + public final int delete() { return server.delete(this, transaction); } @Override - public int delete(Transaction transaction) { + public final int delete(Transaction transaction) { return server.delete(this, transaction); } @Override - public int update() { + public final int update() { return server.update(this, transaction); } @Override - public int update(Transaction transaction) { + public final int update(Transaction transaction) { return server.update(this, transaction); } @Override - public List findIds() { + public final List findIds() { // a copy of this query is made in the server // as the query needs to modified (so we modify // the copy rather than this query instance) @@ -1419,12 +1423,12 @@ public final class DefaultOrmQuery extends AbstractQuery implements SpiQuery< } @Override - public boolean exists() { + public final boolean exists() { return server.exists(this, transaction); } @Override - public int findCount() { + public final int findCount() { // a copy of this query is made in the server // as the query needs to modified (so we modify // the copy rather than this query instance) @@ -1432,38 +1436,38 @@ public final class DefaultOrmQuery extends AbstractQuery implements SpiQuery< } @Override - public void findEachWhile(Predicate consumer) { + public final void findEachWhile(Predicate consumer) { server.findEachWhile(this, consumer, transaction); } @Override - public void findEach(Consumer consumer) { + public final void findEach(Consumer consumer) { server.findEach(this, consumer, transaction); } @Override - public void findEach(int batch, Consumer> consumer) { + public final void findEach(int batch, Consumer> consumer) { server.findEach(this, batch, consumer, transaction); } @Override - public QueryIterator findIterate() { + public final QueryIterator findIterate() { return server.findIterate(this, transaction); } @Override - public Stream findStream() { + public final Stream findStream() { return server.findStream(this, transaction); } @Override - public List> findVersions() { + public final List> findVersions() { this.temporalMode = TemporalMode.VERSIONS; return server.findVersions(this, transaction); } @Override - public List> findVersionsBetween(Timestamp start, Timestamp end) { + public final List> findVersionsBetween(Timestamp start, Timestamp end) { if (start == null || end == null) { throw new IllegalArgumentException("start and end must not be null"); } @@ -1474,64 +1478,64 @@ public final class DefaultOrmQuery extends AbstractQuery implements SpiQuery< } @Override - public List findList() { + public final List findList() { return server.findList(this, transaction); } @Override - public Set findSet() { + public final Set findSet() { return server.findSet(this, transaction); } @Override - public Map findMap() { + public final Map findMap() { return server.findMap(this, transaction); } @Override @SuppressWarnings("unchecked") - public List findSingleAttributeList() { + public final List findSingleAttributeList() { return (List) server.findSingleAttributeList(this, transaction); } @Override - public A findSingleAttribute() { + public final A findSingleAttribute() { List list = findSingleAttributeList(); return !list.isEmpty() ? list.get(0) : null; } @Override - public T findOne() { + public final T findOne() { return server.findOne(this, transaction); } @Override - public Optional findOneOrEmpty() { + public final Optional findOneOrEmpty() { return server.findOneOrEmpty(this, transaction); } @Override - public FutureIds findFutureIds() { + public final FutureIds findFutureIds() { return server.findFutureIds(this, transaction); } @Override - public FutureList findFutureList() { + public final FutureList findFutureList() { return server.findFutureList(this, transaction); } @Override - public FutureRowCount findFutureCount() { + public final FutureRowCount findFutureCount() { return server.findFutureCount(this, transaction); } @Override - public PagedList findPagedList() { + public final PagedList findPagedList() { return server.findPagedList(this, transaction); } @Override - public Query setParameter(Object value) { + public final Query setParameter(Object value) { if (bindParams == null) { bindParams = new BindParams(); } @@ -1540,7 +1544,7 @@ public final class DefaultOrmQuery extends AbstractQuery implements SpiQuery< } @Override - public Query setParameters(Object... values) { + public final Query setParameters(Object... values) { if (bindParams == null) { bindParams = new BindParams(); } @@ -1554,7 +1558,7 @@ public final class DefaultOrmQuery extends AbstractQuery implements SpiQuery< * have in the query. */ @Override - public Query setParameter(int position, Object value) { + public final Query setParameter(int position, Object value) { if (bindParams == null) { bindParams = new BindParams(); } @@ -1566,7 +1570,7 @@ public final class DefaultOrmQuery extends AbstractQuery implements SpiQuery< * Set a named bind parameter. Named parameters have a colon to prefix the name. */ @Override - public Query setParameter(String name, Object value) { + public final Query setParameter(String name, Object value) { if (namedParams != null) { ONamedParam param = namedParams.get(name); if (param != null) { @@ -1582,7 +1586,7 @@ public final class DefaultOrmQuery extends AbstractQuery implements SpiQuery< } @Override - public void setArrayParameter(String name, Collection values) { + public final void setArrayParameter(String name, Collection values) { if (namedParams != null) { throw new IllegalStateException("setArrayParameter() not supported when EQL parsed query"); } @@ -1593,28 +1597,22 @@ public final class DefaultOrmQuery extends AbstractQuery implements SpiQuery< } @Override - public boolean checkPagingOrderBy() { + public final boolean checkPagingOrderBy() { return orderById && !useDocStore; } @Override - public boolean orderByIsEmpty() { + public final boolean orderByIsEmpty() { return orderBy == null || orderBy.isEmpty(); } @Override - public OrderBy getOrderBy() { + public final OrderBy getOrderBy() { return orderBy; } @Override - @Deprecated - public OrderBy orderBy() { - return order(); - } - - @Override - public OrderBy order() { + public final OrderBy orderBy() { if (orderBy == null) { orderBy = new OrderBy<>(this, null); } @@ -1622,13 +1620,7 @@ public final class DefaultOrmQuery extends AbstractQuery implements SpiQuery< } @Override - @Deprecated - public Query orderBy(String orderByClause) { - return order(orderByClause); - } - - @Override - public Query order(String orderByClause) { + public final Query orderBy(String orderByClause) { if (orderByClause == null || orderByClause.trim().isEmpty()) { this.orderBy = null; } else { @@ -1638,13 +1630,7 @@ public final class DefaultOrmQuery extends AbstractQuery implements SpiQuery< } @Override - @Deprecated - public Query setOrderBy(OrderBy orderBy) { - return setOrder(orderBy); - } - - @Override - public Query setOrder(OrderBy orderBy) { + public final Query setOrderBy(OrderBy orderBy) { this.orderBy = orderBy; if (orderBy != null) { orderBy.setQuery(this); @@ -1653,12 +1639,12 @@ public final class DefaultOrmQuery extends AbstractQuery implements SpiQuery< } @Override - public boolean isManualId() { + public final boolean isManualId() { return manualId; } @Override - public void setManualId() { + public final void setManualId() { if (detail != null && detail.hasSelectClause()) { this.manualId = true; } @@ -1668,7 +1654,7 @@ public final class DefaultOrmQuery extends AbstractQuery implements SpiQuery< * return true if user specified to use SQL DISTINCT (effectively excludes id property). */ @Override - public boolean isDistinct() { + public final boolean isDistinct() { return distinct; } @@ -1676,35 +1662,35 @@ public final class DefaultOrmQuery extends AbstractQuery implements SpiQuery< * Internally set to use SQL DISTINCT on the query but still have id property included. */ @Override - public Query setDistinct(boolean distinct) { + public final Query setDistinct(boolean distinct) { this.distinct = distinct; return this; } @Override - public Query setCountDistinct(CountDistinctOrder countDistinctOrder) { + public final Query setCountDistinct(CountDistinctOrder countDistinctOrder) { this.countDistinctOrder = countDistinctOrder; return this; } @Override - public boolean isCountDistinct() { + public final boolean isCountDistinct() { return countDistinctOrder != null; } @Override - public Class getBeanType() { + public final Class getBeanType() { return beanType; } @Override - public Class getInheritType() { + public final Class getInheritType() { return beanDescriptor.type(); } @SuppressWarnings("unchecked") @Override - public Query setInheritType(Class type) { + public final Query setInheritType(Class type) { if (type == beanType) { return this; } @@ -1718,71 +1704,71 @@ public final class DefaultOrmQuery extends AbstractQuery implements SpiQuery< } @Override - public String toString() { + public final String toString() { return "Query [" + whereExpressions + "]"; } @Override - public TableJoin getM2mIncludeJoin() { + public final TableJoin getM2mIncludeJoin() { return m2mIncludeJoin; } @Override - public void setM2MIncludeJoin(TableJoin m2mIncludeJoin) { + public final void setM2MIncludeJoin(TableJoin m2mIncludeJoin) { this.m2mIncludeJoin = m2mIncludeJoin; } @Override - public Query setDisableLazyLoading(boolean disableLazyLoading) { + public final Query setDisableLazyLoading(boolean disableLazyLoading) { this.disableLazyLoading = disableLazyLoading; return this; } @Override - public boolean isDisableLazyLoading() { + public final boolean isDisableLazyLoading() { return disableLazyLoading; } @Override - public int getFirstRow() { + public final int getFirstRow() { return firstRow; } @Override - public Query setFirstRow(int firstRow) { + public final Query setFirstRow(int firstRow) { this.firstRow = firstRow; return this; } @Override - public int getMaxRows() { + public final int getMaxRows() { return maxRows; } @Override - public Query setMaxRows(int maxRows) { + public final Query setMaxRows(int maxRows) { this.maxRows = maxRows; return this; } @Override - public String getMapKey() { + public final String getMapKey() { return mapKey; } @Override - public Query setMapKey(String mapKey) { + public final Query setMapKey(String mapKey) { this.mapKey = mapKey; return this; } @Override - public Object getId() { + public final Object getId() { return id; } @Override - public Query setId(Object id) { + public final Query setId(Object id) { if (id == null) { throw new NullPointerException("The id is null"); } @@ -1791,18 +1777,18 @@ public final class DefaultOrmQuery extends AbstractQuery implements SpiQuery< } @Override - public BindParams getBindParams() { + public final BindParams getBindParams() { return bindParams; } @Override - public Query where(Expression expression) { + public final Query where(Expression expression) { where().add(expression); return this; } @Override - public ExpressionList text() { + public final ExpressionList text() { if (textExpressions == null) { useDocStore = true; textExpressions = new DefaultExpressionList<>(this); @@ -1811,7 +1797,7 @@ public final class DefaultOrmQuery extends AbstractQuery implements SpiQuery< } @Override - public ExpressionList where() { + public final ExpressionList where() { if (whereExpressions == null) { whereExpressions = new DefaultExpressionList<>(this, null); } @@ -1819,20 +1805,20 @@ public final class DefaultOrmQuery extends AbstractQuery implements SpiQuery< } @Override - public void simplifyExpressions() { + public final void simplifyExpressions() { if (whereExpressions != null) { whereExpressions.simplify(); } } @Override - public Query having(Expression expression) { + public final Query having(Expression expression) { having().add(expression); return this; } @Override - public ExpressionList having() { + public final ExpressionList having() { if (havingExpressions == null) { havingExpressions = new DefaultExpressionList<>(this, null); } @@ -1840,32 +1826,32 @@ public final class DefaultOrmQuery extends AbstractQuery implements SpiQuery< } @Override - public SpiExpressionList getHavingExpressions() { + public final SpiExpressionList getHavingExpressions() { return havingExpressions; } @Override - public SpiExpressionList getWhereExpressions() { + public final SpiExpressionList getWhereExpressions() { return whereExpressions; } @Override - public SpiExpressionList getTextExpression() { + public final SpiExpressionList getTextExpression() { return textExpressions; } @Override - public String getGeneratedSql() { + public final String getGeneratedSql() { return generatedSql; } @Override - public void setGeneratedSql(String generatedSql) { + public final void setGeneratedSql(String generatedSql) { this.generatedSql = generatedSql; } @Override - public void checkNamedParameters() { + public final void checkNamedParameters() { if (namedParams != null) { for (ONamedParam value : namedParams.values()) { value.checkValueSet(); @@ -1874,7 +1860,7 @@ public final class DefaultOrmQuery extends AbstractQuery implements SpiQuery< } @Override - public SpiNamedParam createNamedParameter(String name) { + public final SpiNamedParam createNamedParameter(String name) { if (namedParams == null) { namedParams = new HashMap<>(); } @@ -1882,84 +1868,84 @@ public final class DefaultOrmQuery extends AbstractQuery implements SpiQuery< } @Override - public void setDefaultFetchBuffer(int fetchSize) { + public final void setDefaultFetchBuffer(int fetchSize) { if (bufferFetchSizeHint == 0) { bufferFetchSizeHint = fetchSize; } } @Override - public Query setBufferFetchSizeHint(int bufferFetchSizeHint) { + public final Query setBufferFetchSizeHint(int bufferFetchSizeHint) { this.bufferFetchSizeHint = bufferFetchSizeHint; return this; } @Override - public int getBufferFetchSizeHint() { + public final int getBufferFetchSizeHint() { return bufferFetchSizeHint; } @Override - public Query setDisableReadAuditing() { + public final Query setDisableReadAuditing() { this.disableReadAudit = true; return this; } @Override - public boolean isDisableReadAudit() { + public final boolean isDisableReadAudit() { return disableReadAudit; } @Override - public boolean isFutureFetch() { + public final boolean isFutureFetch() { return futureFetch; } @Override - public void setFutureFetch(boolean backgroundFetch) { + public final void setFutureFetch(boolean backgroundFetch) { this.futureFetch = backgroundFetch; } @Override - public void setFutureFetchAudit(ReadEvent event) { + public final void setFutureFetchAudit(ReadEvent event) { this.futureFetchAudit = event; } @Override - public ReadEvent getFutureFetchAudit() { + public final ReadEvent getFutureFetchAudit() { return futureFetchAudit; } @Override - public Query setBaseTable(String baseTable) { + public final Query setBaseTable(String baseTable) { this.baseTable = baseTable; return this; } @Override - public String getBaseTable() { + public final String getBaseTable() { return baseTable; } @Override - public Query alias(String alias) { + public final Query alias(String alias) { this.rootTableAlias = alias; return this; } @Override - public String getAlias() { + public final String getAlias() { return rootTableAlias; } @Override - public String getAlias(String defaultAlias) { + public final String getAlias(String defaultAlias) { return rootTableAlias != null ? rootTableAlias : defaultAlias; } @Override - public Set validate() { + public final Set validate() { return server.validateQuery(this); } @@ -1967,7 +1953,7 @@ public final class DefaultOrmQuery extends AbstractQuery implements SpiQuery< * Validate all the expression properties/paths given the bean descriptor. */ @Override - public Set validate(BeanType desc) { + public final Set validate(BeanType desc) { SpiExpressionValidation validation = new SpiExpressionValidation(desc); if (whereExpressions != null) { whereExpressions.validate(validation); @@ -1983,29 +1969,29 @@ public final class DefaultOrmQuery extends AbstractQuery implements SpiQuery< return validation.getUnknownProperties(); } - void setUpdateProperties(OrmUpdateProperties updateProperties) { + final void setUpdateProperties(OrmUpdateProperties updateProperties) { this.updateProperties = updateProperties; } @Override - public OrmUpdateProperties getUpdateProperties() { + public final OrmUpdateProperties getUpdateProperties() { return updateProperties; } @Override - public ProfileLocation getProfileLocation() { + public final ProfileLocation getProfileLocation() { return profileLocation; } @Override - public void handleLoadError(String fullName, Exception e) { + public final void handleLoadError(String fullName, Exception e) { if (!allowLoadErrors) { throw new PersistenceException("Error loading on " + fullName, e); } } @Override - public Query orderById(boolean orderById) { + public final Query orderById(boolean orderById) { this.orderById = orderById; return this; } diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/querydefn/DefaultOrmUpdate.java b/ebean-core/src/main/java/io/ebeaninternal/server/querydefn/DefaultOrmUpdate.java index 88b84fc2f..3f0d306e8 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/querydefn/DefaultOrmUpdate.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/querydefn/DefaultOrmUpdate.java @@ -1,6 +1,6 @@ package io.ebeaninternal.server.querydefn; -import io.ebean.EbeanServer; +import io.ebean.Database; import io.ebean.Update; import io.ebeaninternal.api.BindParams; import io.ebeaninternal.api.SpiUpdate; @@ -14,7 +14,7 @@ public final class DefaultOrmUpdate implements SpiUpdate, Serializable { private static final long serialVersionUID = -8791423602246515438L; - private transient final EbeanServer server; + private transient final Database server; private final Class beanType; private final String name; private String label; @@ -35,7 +35,7 @@ public final class DefaultOrmUpdate implements SpiUpdate, Serializable { * Create with a specific server. This means you can use the * UpdateSql.execute() method. */ - public DefaultOrmUpdate(Class beanType, EbeanServer server, String baseTable, String updateStatement) { + public DefaultOrmUpdate(Class beanType, Database server, String baseTable, String updateStatement) { this.beanType = beanType; this.server = server; this.baseTable = baseTable; diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/transaction/ImplicitReadOnlyTransaction.java b/ebean-core/src/main/java/io/ebeaninternal/server/transaction/ImplicitReadOnlyTransaction.java index 316e2f8b8..42f585707 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/transaction/ImplicitReadOnlyTransaction.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/transaction/ImplicitReadOnlyTransaction.java @@ -378,19 +378,12 @@ final class ImplicitReadOnlyTransaction implements SpiTransaction, TxnProfileEve /** * Flush any queued persist requests. *

- * This is general will result in a number of batched PreparedStatements - * executing. - *

+ * This is general will result in a number of batched PreparedStatements executing. */ @Override public void flush() { } - @Override - public void flushBatch() { - flush(); - } - /** * Return the persistence context associated with this transaction. */ @@ -405,7 +398,6 @@ final class ImplicitReadOnlyTransaction implements SpiTransaction, TxnProfileEve * This could be considered similar to EJB3 Extended PersistanceContext. In * that you get the PersistanceContext from a transaction, hold onto it, and * then set it back later to a second transaction. - *

*/ @Override public void setPersistenceContext(SpiPersistenceContext context) { @@ -503,7 +495,6 @@ final class ImplicitReadOnlyTransaction implements SpiTransaction, TxnProfileEve *

* This leaves the transaction active and expects another commit * to occur later (which closes the underlying connection etc). - *

*/ @Override public void commitAndContinue() { diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/transaction/JdbcTransaction.java b/ebean-core/src/main/java/io/ebeaninternal/server/transaction/JdbcTransaction.java index c85bd2c5d..4fb74db18 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/transaction/JdbcTransaction.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/transaction/JdbcTransaction.java @@ -758,11 +758,6 @@ class JdbcTransaction implements SpiTransaction, TxnProfileEventCodes { internalBatchFlush(); } - @Override - public final void flushBatch() { - flush(); - } - /** * Flush the JDBC batch and execute derived relationship statements if necessary. */ diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/transaction/JtaTransactionManager.java b/ebean-core/src/main/java/io/ebeaninternal/server/transaction/JtaTransactionManager.java index 413c79cbc..f5edf2688 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/transaction/JtaTransactionManager.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/transaction/JtaTransactionManager.java @@ -27,7 +27,7 @@ public final class JtaTransactionManager implements ExternalTransactionManager { private TransactionScopeManager scope; /** - * Instantiates a new spring aware transaction scope manager. + * Instantiates a new JTA transaction manager. */ public JtaTransactionManager() { } @@ -37,10 +37,8 @@ public final class JtaTransactionManager implements ExternalTransactionManager { */ @Override public void setTransactionManager(Object txnMgr) { - // RB: At this stage not exposing TransactionManager to // the public API and hence the Object type and casting here - this.transactionManager = (TransactionManager) txnMgr; this.scope = transactionManager.scope(); } @@ -72,16 +70,13 @@ public final class JtaTransactionManager implements ExternalTransactionManager { } /** - * Looks for a current Spring managed transaction and wraps/returns that as a Ebean transaction. + * Looks for a current JTA managed transaction and wraps/returns that as an Ebean transaction. *

* Returns null if there is no current spring transaction (lazy loading outside a spring txn etc). - *

*/ @Override public Object getCurrentTransaction() { - TransactionSynchronizationRegistry syncRegistry = getSyncRegistry(); - SpiTransaction t = (SpiTransaction) syncRegistry.getResource(EBEAN_TXN_RESOURCE); if (t != null) { // we have already seen this transaction @@ -122,14 +117,10 @@ public final class JtaTransactionManager implements ExternalTransactionManager { return newTrans; } - /** - * Create a listener to register with JTA to enable Ebean to be - * notified when transactions commit and rollback. + * Create a listener to register with JTA to enable Ebean to be notified when transactions commit and rollback. *

- * This is used by Ebean to notify it's appropriate listeners and maintain it's server - * cache etc. - *

+ * This is used by Ebean to notify its appropriate listeners and maintain its server cache etc. */ private JtaTxnListener createJtaTxnListener(SpiTransaction t) { return new JtaTxnListener(transactionManager, t); @@ -169,7 +160,6 @@ public final class JtaTransactionManager implements ExternalTransactionManager { *

* When Ebean is notified (of the commit/rollback) it can then manage its * cache, notify BeanPersistListeners etc. - *

*/ private static class JtaTxnListener implements Synchronization { diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/transaction/NoTransaction.java b/ebean-core/src/main/java/io/ebeaninternal/server/transaction/NoTransaction.java index 9c043dfe9..529a7ca0a 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/transaction/NoTransaction.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/transaction/NoTransaction.java @@ -283,10 +283,6 @@ final class NoTransaction implements SpiTransaction { public void flush() throws PersistenceException { } - @Override - public void flushBatch() throws PersistenceException { - } - @Override public Connection connection() { return null; diff --git a/ebean-core/src/main/java/module-info.java b/ebean-core/src/main/java/module-info.java index 1a502b0d3..3f9b23b05 100644 --- a/ebean-core/src/main/java/module-info.java +++ b/ebean-core/src/main/java/module-info.java @@ -4,7 +4,6 @@ module io.ebean.core { uses io.ebean.cache.ServerCachePlugin; uses io.ebean.cache.ServerCacheNotifyPlugin; uses io.ebean.config.DatabaseConfigProvider; - uses io.ebean.config.ServerConfigProvider; uses io.ebean.config.ModuleInfoLoader; uses io.ebean.config.dbplatform.DatabasePlatformProvider; uses io.ebean.datasource.DataSourceAlertFactory; diff --git a/ebean-core/src/test/java/io/ebeaninternal/server/cache/DefaultServerCacheConfigTest.java b/ebean-core/src/test/java/io/ebeaninternal/server/cache/DefaultServerCacheConfigTest.java index 512f663fd..19047e9c7 100644 --- a/ebean-core/src/test/java/io/ebeaninternal/server/cache/DefaultServerCacheConfigTest.java +++ b/ebean-core/src/test/java/io/ebeaninternal/server/cache/DefaultServerCacheConfigTest.java @@ -6,8 +6,7 @@ import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; -public class DefaultServerCacheConfigTest { - +class DefaultServerCacheConfigTest { private DefaultServerCacheConfig create(int maxSize, int maxIdleSecs, int maxSecsToLive, int trimFreq) { ServerCacheOptions options = new ServerCacheOptions(); @@ -20,33 +19,45 @@ public class DefaultServerCacheConfigTest { } @Test - public void trimFreq_halfIdle() { - + void trimFreq_halfIdle() { assertEquals(create(10000,10,20, 0).determineTrimFrequency(), 4); } - @Test - public void trimFreq_halfIdle_withRounding() { - + void trimFreq_halfIdle_withRounding() { assertEquals(create(10000,11,20, 0).determineTrimFrequency(), 4); } @Test - public void trimFreq_halfTTL() { - + void trimFreq_halfTTL() { assertEquals(create(10000,0,20, 0).determineTrimFrequency(), 9); } @Test - public void trimFreq_halfTTL_withRounding() { - + void trimFreq_halfTTL_withRounding() { assertEquals(create(10000,0,21, 0).determineTrimFrequency(), 9); } @Test - public void trimFreq_explicit() { - + void trimFreq_explicit() { assertEquals(create(10000,10,20, 42).determineTrimFrequency(), 42); } + + @Test + void trimOnPut_default() { + assertEquals(create(0,0,0, 0).determineTrimOnPut(), 1_000); + } + + @Test + void trimOnPut_tenPercent() { + assertEquals(create(10_000,0,0, 0).determineTrimOnPut(), 1_000); + assertEquals(create(9_000,0,0, 0).determineTrimOnPut(), 900); + assertEquals(create(100,0,0, 0).determineTrimOnPut(), 10); + } + + @Test + void trimOnPut_roundDown() { + assertEquals(create(9010,0,0, 0).determineTrimOnPut(), 901); + assertEquals(create(9009,0,0, 0).determineTrimOnPut(), 900); + } } diff --git a/ebean-core/src/test/java/io/ebeaninternal/server/cache/DefaultServerCache_RunEvictionTest.java b/ebean-core/src/test/java/io/ebeaninternal/server/cache/DefaultServerCache_RunEvictionTest.java index c6596e6d8..d98c48707 100644 --- a/ebean-core/src/test/java/io/ebeaninternal/server/cache/DefaultServerCache_RunEvictionTest.java +++ b/ebean-core/src/test/java/io/ebeaninternal/server/cache/DefaultServerCache_RunEvictionTest.java @@ -10,16 +10,14 @@ import org.junit.jupiter.api.Test; import java.util.Random; -public class DefaultServerCache_RunEvictionTest { - +class DefaultServerCache_RunEvictionTest { private DefaultServerCache createCache() { - ServerCacheOptions cacheOptions = new ServerCacheOptions(); - cacheOptions.setMaxSize(10000); + cacheOptions.setMaxSize(300); cacheOptions.setMaxIdleSecs(1); cacheOptions.setMaxSecsToLive(2); - cacheOptions.setTrimFrequency(1); + cacheOptions.setTrimFrequency(5); ServerCacheConfig con = new ServerCacheConfig(ServerCacheType.BEAN, "foo", "foo", cacheOptions, null, null); return new DefaultServerCache(new DefaultServerCacheConfig(con)); @@ -35,8 +33,7 @@ public class DefaultServerCache_RunEvictionTest { @Disabled("test takes long time") @Test - public void runEvict() throws InterruptedException { - + void runEvict() throws InterruptedException { for (int i = 0; i < 15; i++) { doStuff(); cache.runEviction(); @@ -47,12 +44,10 @@ public class DefaultServerCache_RunEvictionTest { } private void doStuff() { - - for (int i = 0; i < 500; i++) { + for (int i = 0; i < 5000; i++) { String key = "" + random.nextInt(20000); - int mode = random.nextInt(10); - if (mode < 8) { + if (mode < 7) { cache.get(key); } else { cache.put(key, key + "-" + System.currentTimeMillis()); diff --git a/ebean-core/src/test/java/io/ebeaninternal/server/core/InitDataSourceTest.java b/ebean-core/src/test/java/io/ebeaninternal/server/core/InitDataSourceTest.java index 89fb432f6..b6a11a959 100644 --- a/ebean-core/src/test/java/io/ebeaninternal/server/core/InitDataSourceTest.java +++ b/ebean-core/src/test/java/io/ebeaninternal/server/core/InitDataSourceTest.java @@ -3,7 +3,7 @@ package io.ebeaninternal.server.core; import io.ebean.config.DatabaseConfig; import io.ebean.datasource.DataSourceAlert; import io.ebean.datasource.DataSourceConfig; -import io.ebean.datasource.pool.ConnectionPool; +import io.ebean.datasource.DataSourcePool; import org.junit.jupiter.api.Test; import javax.sql.DataSource; @@ -137,7 +137,7 @@ public class InitDataSourceTest { config.getDataSourceConfig().setUrl("jdbc:h2:mem:dsTestOnline"); config.getDataSourceConfig().setDriver("org.h2.Driver"); InitDataSource.init(config); - ConnectionPool pool = (ConnectionPool) config.getDataSource(); + DataSourcePool pool = (DataSourcePool) config.getDataSource(); assertThat(pool.isDataSourceUp()).isTrue(); pool.shutdown(); } @@ -174,7 +174,7 @@ public class InitDataSourceTest { config.getDataSourceConfig().setAlert(alert); config.setDatabasePlatformName("h2"); InitDataSource.init(config); - ConnectionPool pool = (ConnectionPool) config.getDataSource(); + DataSourcePool pool = (DataSourcePool) config.getDataSource(); assertThat(pool).isNotNull(); // make some additional tests with the pool assertThat(pool.isDataSourceUp()).isFalse(); diff --git a/ebean-core/src/test/java/io/ebeaninternal/server/deploy/parse/DeployInheritInfoTest.java b/ebean-core/src/test/java/io/ebeaninternal/server/deploy/parse/DeployInheritInfoTest.java new file mode 100644 index 000000000..d42825ea9 --- /dev/null +++ b/ebean-core/src/test/java/io/ebeaninternal/server/deploy/parse/DeployInheritInfoTest.java @@ -0,0 +1,21 @@ +package io.ebeaninternal.server.deploy.parse; + +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.assertThat; + +class DeployInheritInfoTest { + + @Test + void addChild_when_DiscriminatorValueIsNull() { + DeployInheritInfo root = new DeployInheritInfo(Object.class); + root.addChild(new DeployInheritInfo(Integer.class)); // DiscriminatorValue is null + root.addChild(new DeployInheritInfo(Short.class)); // DiscriminatorValue is null + + DeployInheritInfo c2 = new DeployInheritInfo(Long.class); + c2.setDiscriminatorValue("c2"); + root.addChild(c2); + + assertThat(root.children()).hasSize(3); + } +} diff --git a/ebean-core/src/test/java/io/ebeaninternal/server/expression/BaseExpressionTest.java b/ebean-core/src/test/java/io/ebeaninternal/server/expression/BaseExpressionTest.java index b66c1da62..1e782f4eb 100644 --- a/ebean-core/src/test/java/io/ebeaninternal/server/expression/BaseExpressionTest.java +++ b/ebean-core/src/test/java/io/ebeaninternal/server/expression/BaseExpressionTest.java @@ -1,6 +1,6 @@ package io.ebeaninternal.server.expression; -import io.ebean.EbeanServer; +import io.ebean.Database; import io.ebean.Query; import io.ebean.Transaction; import io.ebean.event.BeanQueryRequest; @@ -62,7 +62,7 @@ public abstract class BaseExpressionTest extends BaseTest { } @Override - public EbeanServer getEbeanServer() { + public Database database() { return null; } diff --git a/ebean-ddl-generator/pom.xml b/ebean-ddl-generator/pom.xml index 16fd9d475..13c9d63bf 100644 --- a/ebean-ddl-generator/pom.xml +++ b/ebean-ddl-generator/pom.xml @@ -4,7 +4,7 @@ ebean-parent io.ebean - 13.3.1-SNAPSHOT + 13.6.0-SNAPSHOT ebean ddl generation @@ -28,14 +28,14 @@ io.ebean ebean-core-type - 13.3.1-SNAPSHOT + 13.6.0-SNAPSHOT provided io.ebean ebean-core - 13.3.1-SNAPSHOT + 13.6.0-SNAPSHOT provided @@ -58,7 +58,7 @@ io.ebean ebean-platform-all - 13.3.1-SNAPSHOT + 13.6.0-SNAPSHOT test diff --git a/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/model/MTable.java b/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/model/MTable.java index 96cd1b494..b9abb5116 100644 --- a/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/model/MTable.java +++ b/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/model/MTable.java @@ -1,36 +1,12 @@ package io.ebeaninternal.dbmigration.model; import io.ebeaninternal.dbmigration.ddlgeneration.platform.DdlHelp; -import io.ebeaninternal.dbmigration.migration.AddColumn; -import io.ebeaninternal.dbmigration.migration.AddHistoryTable; -import io.ebeaninternal.dbmigration.migration.AddTableComment; -import io.ebeaninternal.dbmigration.migration.AlterColumn; -import io.ebeaninternal.dbmigration.migration.AlterTable; -import io.ebeaninternal.dbmigration.migration.Column; -import io.ebeaninternal.dbmigration.migration.CreateTable; -import io.ebeaninternal.dbmigration.migration.DropColumn; -import io.ebeaninternal.dbmigration.migration.DropHistoryTable; -import io.ebeaninternal.dbmigration.migration.DropTable; -import io.ebeaninternal.dbmigration.migration.ForeignKey; -import io.ebeaninternal.dbmigration.migration.RenameColumn; -import io.ebeaninternal.dbmigration.migration.UniqueConstraint; -import io.ebeaninternal.server.deploy.BeanDescriptor; -import io.ebeaninternal.server.deploy.BeanProperty; -import io.ebeaninternal.server.deploy.IdentityMode; -import io.ebeaninternal.server.deploy.PartitionMeta; -import io.ebeaninternal.server.deploy.TablespaceMeta; - +import io.ebeaninternal.dbmigration.migration.*; +import io.ebeaninternal.server.deploy.*; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashSet; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.Set; +import java.util.*; import static io.ebeaninternal.dbmigration.ddlgeneration.platform.SplitColumns.split; import static io.ebeaninternal.dbmigration.model.MTableIdentity.fromCreateTable; @@ -110,8 +86,7 @@ public class MTable { /** * Constructor for test cases only! */ - @Deprecated - public MTable(String name) { + MTable(String name) { this(name, null, null); } @@ -121,7 +96,7 @@ public class MTable { public MTable(String name, BeanDescriptor descriptor) { this(name, descriptor.tablespaceMeta(), descriptor.storageEngine()); } - + /** * Constructor for dependant tables (draft/element collection or intersection). */ @@ -161,8 +136,8 @@ public class MTable { this.storageEngine = createTable.getStorageEngine(); if (createTable.getTablespace() != null) { this.tablespaceMeta = new TablespaceMeta(createTable.getTablespace(), - createTable.getIndexTablespace() != null ? createTable.getIndexTablespace() : createTable.getTablespace(), - createTable.getLobTablespace() != null ? createTable.getLobTablespace() : createTable.getTablespace()); + createTable.getIndexTablespace() != null ? createTable.getIndexTablespace() : createTable.getTablespace(), + createTable.getLobTablespace() != null ? createTable.getLobTablespace() : createTable.getTablespace()); } else { this.tablespaceMeta = null; } @@ -296,7 +271,7 @@ public class MTable { compareCompoundKeys(modelDiff, newTable); compareUniqueKeys(modelDiff, newTable); compareTableAttrs(modelDiff, newTable); - + } private void compareColumns(ModelDiff modelDiff, MTable newTable) { @@ -366,7 +341,7 @@ public class MTable { modelDiff.addUniqueConstraint(newKey.addUniqueConstraint(name)); } } - + private void compareTableAttrs(ModelDiff modelDiff, MTable newTable) { AlterTable alterTable = new AlterTable(); alterTable.setName(newTable.getName()); @@ -478,11 +453,11 @@ public class MTable { public void setComment(String comment) { this.comment = comment; } - + public void setTablespaceMeta(TablespaceMeta tablespaceMeta) { this.tablespaceMeta = tablespaceMeta; } - + public TablespaceMeta getTablespaceMeta() { return tablespaceMeta; } diff --git a/ebean-externalmapping-api/pom.xml b/ebean-externalmapping-api/pom.xml index 9966cdeaf..43749cadf 100644 --- a/ebean-externalmapping-api/pom.xml +++ b/ebean-externalmapping-api/pom.xml @@ -4,7 +4,7 @@ ebean-parent io.ebean - 13.3.1-SNAPSHOT + 13.6.0-SNAPSHOT ebean external mapping api diff --git a/ebean-externalmapping-xml/pom.xml b/ebean-externalmapping-xml/pom.xml index 442818e3e..4705a85f7 100644 --- a/ebean-externalmapping-xml/pom.xml +++ b/ebean-externalmapping-xml/pom.xml @@ -4,7 +4,7 @@ ebean-parent io.ebean - 13.3.1-SNAPSHOT + 13.6.0-SNAPSHOT @@ -28,7 +28,7 @@ io.ebean ebean-externalmapping-api - 13.3.1-SNAPSHOT + 13.6.0-SNAPSHOT @@ -61,21 +61,21 @@ io.ebean ebean-platform-h2 - 13.3.1-SNAPSHOT + 13.6.0-SNAPSHOT test io.ebean ebean-core - 13.3.1-SNAPSHOT + 13.6.0-SNAPSHOT test io.ebean ebean-ddl-generator - 13.3.1-SNAPSHOT + 13.6.0-SNAPSHOT test diff --git a/ebean-kotlin/pom.xml b/ebean-kotlin/pom.xml index 4b81d57d6..3b8371b99 100644 --- a/ebean-kotlin/pom.xml +++ b/ebean-kotlin/pom.xml @@ -6,7 +6,7 @@ ebean-parent io.ebean - 13.3.1-SNAPSHOT + 13.6.0-SNAPSHOT ebean-kotlin @@ -28,7 +28,7 @@ io.ebean ebean-core - 13.3.1-SNAPSHOT + 13.6.0-SNAPSHOT provided @@ -50,7 +50,7 @@ io.ebean ebean-test - 13.3.1-SNAPSHOT + 13.6.0-SNAPSHOT test diff --git a/ebean-postgis/pom.xml b/ebean-postgis/pom.xml index e0c9962e6..b0aaa2757 100644 --- a/ebean-postgis/pom.xml +++ b/ebean-postgis/pom.xml @@ -4,7 +4,7 @@ ebean-parent io.ebean - 13.3.1-SNAPSHOT + 13.6.0-SNAPSHOT ebean postgis @@ -22,14 +22,14 @@ io.ebean ebean-platform-postgres - 13.3.1-SNAPSHOT + 13.6.0-SNAPSHOT io.ebean ebean-core - 13.3.1-SNAPSHOT + 13.6.0-SNAPSHOT provided @@ -73,7 +73,7 @@ io.ebean ebean-test - 13.3.1-SNAPSHOT + 13.6.0-SNAPSHOT test diff --git a/ebean-postgis/src/main/java/io/ebean/postgis/ScalarTypePgisBase.java b/ebean-postgis/src/main/java/io/ebean/postgis/ScalarTypePgisBase.java index 27bf5200b..adc3bbd98 100644 --- a/ebean-postgis/src/main/java/io/ebean/postgis/ScalarTypePgisBase.java +++ b/ebean-postgis/src/main/java/io/ebean/postgis/ScalarTypePgisBase.java @@ -108,7 +108,7 @@ abstract class ScalarTypePgisBase implements ScalarType { @Override public void loadIgnore(DataReader reader) { - + reader.incrementPos(1); } @Override diff --git a/ebean-postgis/src/main/java/io/ebean/postgis/latte/ScalarTypeGeoLatteBase.java b/ebean-postgis/src/main/java/io/ebean/postgis/latte/ScalarTypeGeoLatteBase.java index f4c5d7769..2dd779c38 100644 --- a/ebean-postgis/src/main/java/io/ebean/postgis/latte/ScalarTypeGeoLatteBase.java +++ b/ebean-postgis/src/main/java/io/ebean/postgis/latte/ScalarTypeGeoLatteBase.java @@ -99,7 +99,7 @@ abstract class ScalarTypeGeoLatteBase implements ScalarType< @Override public void loadIgnore(DataReader reader) { - + reader.incrementPos(1); } @Override diff --git a/ebean-querybean/pom.xml b/ebean-querybean/pom.xml index a06806e38..cf245fdb4 100644 --- a/ebean-querybean/pom.xml +++ b/ebean-querybean/pom.xml @@ -4,7 +4,7 @@ ebean-parent io.ebean - 13.3.1-SNAPSHOT + 13.6.0-SNAPSHOT ebean querybean @@ -17,7 +17,7 @@ io.ebean ebean-core - 13.3.1-SNAPSHOT + 13.6.0-SNAPSHOT provided @@ -63,21 +63,21 @@ io.ebean ebean-ddl-generator - 13.3.1-SNAPSHOT + 13.6.0-SNAPSHOT test io.ebean querybean-generator - 13.3.1-SNAPSHOT + 13.6.0-SNAPSHOT test io.ebean ebean-test - 13.3.1-SNAPSHOT + 13.6.0-SNAPSHOT test diff --git a/ebean-redis/pom.xml b/ebean-redis/pom.xml index d6bc05cdc..b0f875e3e 100644 --- a/ebean-redis/pom.xml +++ b/ebean-redis/pom.xml @@ -4,7 +4,7 @@ ebean-parent io.ebean - 13.3.1-SNAPSHOT + 13.6.0-SNAPSHOT ebean-redis @@ -16,41 +16,41 @@ redis.clients jedis - 4.2.1 + 4.2.2 io.ebean ebean-api - 13.3.1-SNAPSHOT + 13.6.0-SNAPSHOT provided io.ebean ebean-core - 13.3.1-SNAPSHOT + 13.6.0-SNAPSHOT provided io.ebean ebean-querybean - 13.3.1-SNAPSHOT + 13.6.0-SNAPSHOT test io.ebean querybean-generator - 13.3.1-SNAPSHOT + 13.6.0-SNAPSHOT test io.ebean ebean-test - 13.3.1-SNAPSHOT + 13.6.0-SNAPSHOT test diff --git a/ebean-test/pom.xml b/ebean-test/pom.xml index 844547ae6..6b9df3cf4 100644 --- a/ebean-test/pom.xml +++ b/ebean-test/pom.xml @@ -4,7 +4,7 @@ ebean-parent io.ebean - 13.3.1-SNAPSHOT + 13.6.0-SNAPSHOT ebean test @@ -29,20 +29,20 @@ io.ebean ebean-platform-h2 - 13.3.1-SNAPSHOT + 13.6.0-SNAPSHOT io.ebean ebean-core - 13.3.1-SNAPSHOT + 13.6.0-SNAPSHOT provided io.ebean ebean-ddl-generator - 13.3.1-SNAPSHOT + 13.6.0-SNAPSHOT @@ -106,7 +106,7 @@ io.ebean ebean-platform-all - 13.3.1-SNAPSHOT + 13.6.0-SNAPSHOT test @@ -176,14 +176,14 @@ com.microsoft.sqlserver mssql-jdbc - 9.4.0.jre8 + 10.2.0.jre8 test mysql mysql-connector-java - 8.0.26 + 8.0.28 test @@ -197,7 +197,7 @@ com.sap.cloud.db.jdbc ngdbc - 2.3.48 + 2.12.9 test @@ -235,14 +235,14 @@ ru.yandex.clickhouse clickhouse-jdbc - 0.3.1-patch + 0.3.2 test ch.qos.logback logback-classic - 1.2.10 + 1.2.11 test diff --git a/ebean-test/src/main/java/io/ebean/test/config/platform/ElasticSearchSetup.java b/ebean-test/src/main/java/io/ebean/test/config/platform/ElasticSearchSetup.java index 011bfcbd2..87d74c29b 100644 --- a/ebean-test/src/main/java/io/ebean/test/config/platform/ElasticSearchSetup.java +++ b/ebean-test/src/main/java/io/ebean/test/config/platform/ElasticSearchSetup.java @@ -1,6 +1,5 @@ package io.ebean.test.config.platform; -import io.ebean.docker.commands.ElasticConfig; import io.ebean.docker.commands.ElasticContainer; import java.util.Properties; @@ -19,27 +18,18 @@ class ElasticSearchSetup { } void run() { - ElasticConfig elasticConfig = readConfig(); - if (elasticConfig != null) { - new ElasticContainer(elasticConfig).start(); - } - } - - ElasticConfig readConfig() { - String version = read("version", null); - if (version == null) { - // we need an explicit version to run - return null; + if (version != null) { + Properties properties = populateDockerProperties(version); + ElasticContainer.newBuilder(version) + .properties(properties) + .build() + .start(); } - - return new ElasticConfig(version, populateDockerProperties(version)); } private Properties populateDockerProperties(String version) { - PropertiesBuilder properties = new PropertiesBuilder(); - String mode = config.getProperty("ebean.test.shutdown"); if (mode != null) { properties.set("shutdown", mode); @@ -63,7 +53,7 @@ class ElasticSearchSetup { private static class PropertiesBuilder { - private Properties dockerProperties = new Properties(); + private final Properties dockerProperties = new Properties(); private void set(String key, String val) { dockerProperties.setProperty("elastic." + key, val); diff --git a/ebean-test/src/main/java/io/ebean/test/config/platform/RedisSetup.java b/ebean-test/src/main/java/io/ebean/test/config/platform/RedisSetup.java index c8fc01671..41ed3c185 100644 --- a/ebean-test/src/main/java/io/ebean/test/config/platform/RedisSetup.java +++ b/ebean-test/src/main/java/io/ebean/test/config/platform/RedisSetup.java @@ -1,6 +1,5 @@ package io.ebean.test.config.platform; -import io.ebean.docker.commands.RedisConfig; import io.ebean.docker.commands.RedisContainer; import java.util.Properties; @@ -16,9 +15,10 @@ class RedisSetup { String host = dockerHost.dockerHost(properties.getProperty("ebean.test.dockerHost")); properties.setProperty("redis.host", host); } - RedisConfig redisConfig = new RedisConfig(version, properties); - RedisContainer container = new RedisContainer(redisConfig); - container.start(); + RedisContainer.newBuilder(version) + .properties(properties) + .build() + .start(); } } } diff --git a/ebean-test/src/test/java/io/ebean/xtest/base/FetchConfigTest.java b/ebean-test/src/test/java/io/ebean/xtest/base/FetchConfigTest.java index 122c1b122..bef706e97 100644 --- a/ebean-test/src/test/java/io/ebean/xtest/base/FetchConfigTest.java +++ b/ebean-test/src/test/java/io/ebean/xtest/base/FetchConfigTest.java @@ -9,31 +9,31 @@ public class FetchConfigTest { @Test public void testLazy() { - FetchConfig config = new FetchConfig().lazy(); + FetchConfig config = FetchConfig.ofLazy(); assertThat(config.getBatchSize()).isEqualTo(0); } @Test public void testLazy_withParameter() { - FetchConfig config = new FetchConfig().lazy(50); + FetchConfig config = FetchConfig.ofLazy(50); assertThat(config.getBatchSize()).isEqualTo(50); } @Test public void testQuery() { - FetchConfig config = new FetchConfig().query(); + FetchConfig config = FetchConfig.ofQuery(); assertThat(config.getBatchSize()).isEqualTo(100); } @Test public void testQuery_withParameter() { - FetchConfig config = new FetchConfig().query(50); + FetchConfig config = FetchConfig.ofQuery(50); assertThat(config.getBatchSize()).isEqualTo(50); } @Test public void testQueryFirst() { - FetchConfig config = new FetchConfig().queryFirst(50); + FetchConfig config = FetchConfig.ofQuery(50); assertThat(config.getBatchSize()).isEqualTo(50); } @@ -52,67 +52,67 @@ public class FetchConfigTest { @Test public void testEquals_when_noOptions() { - assertSame(new FetchConfig(), new FetchConfig()); + assertSame(FetchConfig.ofDefault(), FetchConfig.ofDefault()); } @Test public void testEquals_when_query_50_lazy_40() { - assertSame(new FetchConfig().query(50), FetchConfig.ofQuery(50)); + assertSame(FetchConfig.ofQuery(50), FetchConfig.ofQuery(50)); } @Test public void testEquals_when_query_50_lazy() { - assertSame(new FetchConfig().lazy(), FetchConfig.ofLazy()); + assertSame(FetchConfig.ofLazy(), FetchConfig.ofLazy()); } @Test public void testEquals_when_query_50() { - assertSame(new FetchConfig().query(50), new FetchConfig().query(50)); + assertSame(FetchConfig.ofQuery(50), FetchConfig.ofQuery(50)); } @Test public void testEquals_when_queryFirst_50_lazy_40() { - assertSame(new FetchConfig().queryFirst(50).lazy(40), FetchConfig.ofLazy(40)); + assertSame(FetchConfig.ofLazy(40), FetchConfig.ofLazy(40)); } @Test public void testEquals_when_queryFirst_50_lazy() { - assertSame(new FetchConfig().queryFirst(50).lazy(), new FetchConfig().queryFirst(50).lazy()); + assertSame(FetchConfig.ofLazy(), FetchConfig.ofLazy()); } @Test public void testEquals_when_queryFirst_50() { - assertSame(new FetchConfig().queryFirst(50), FetchConfig.ofQuery(50)); + assertSame(FetchConfig.ofQuery(50), FetchConfig.ofQuery(50)); } @Test public void testNotEquals_when_query_50() { - assertDifferent(new FetchConfig().query(50), new FetchConfig().query(40)); + assertDifferent(FetchConfig.ofQuery(50), FetchConfig.ofQuery(40)); } @Test public void testNotEquals_when_query_50_lazy() { - assertDifferent(new FetchConfig().query(50), new FetchConfig().query(50).lazy()); + assertDifferent(FetchConfig.ofQuery(50), FetchConfig.ofLazy(50)); } @Test public void testNotEquals_when_query_50_lazy_40() { - assertDifferent(new FetchConfig().query(50), new FetchConfig().query(50).lazy(40)); + assertDifferent(FetchConfig.ofQuery(50), FetchConfig.ofLazy(40)); } @Test public void testNotEquals_when_queryFirst_50() { - assertDifferent(new FetchConfig().queryFirst(50), new FetchConfig().queryFirst(40)); + assertDifferent(FetchConfig.ofQuery(50), FetchConfig.ofQuery(40)); } @Test public void testNotEquals_when_queryFirst_50_lazy() { - assertDifferent(new FetchConfig().queryFirst(50), new FetchConfig().queryFirst(50).lazy()); + assertDifferent(FetchConfig.ofQuery(50), FetchConfig.ofLazy()); } @Test public void testNotEquals_when_queryFirst_50_lazy_40() { - assertDifferent(new FetchConfig().queryFirst(50), new FetchConfig().queryFirst(50).lazy(40)); + assertDifferent(FetchConfig.ofQuery(50), FetchConfig.ofLazy(40)); } void assertDifferent(FetchConfig v1, FetchConfig v2) { diff --git a/ebean-test/src/test/java/io/ebean/xtest/internal/server/cluster/binarymessage/BinaryTransactionEventReadWriteTest.java b/ebean-test/src/test/java/io/ebean/xtest/internal/server/cluster/binarymessage/BinaryTransactionEventReadWriteTest.java index 81a382ce8..6111cbe12 100644 --- a/ebean-test/src/test/java/io/ebean/xtest/internal/server/cluster/binarymessage/BinaryTransactionEventReadWriteTest.java +++ b/ebean-test/src/test/java/io/ebean/xtest/internal/server/cluster/binarymessage/BinaryTransactionEventReadWriteTest.java @@ -1,7 +1,7 @@ package io.ebean.xtest.internal.server.cluster.binarymessage; +import io.ebean.Database; import io.ebean.xtest.BaseTestCase; -import io.ebean.EbeanServer; import io.ebean.xtest.internal.api.TDSpiEbeanServer; import io.ebeaninternal.api.TransactionEventTable; import io.ebeaninternal.server.cache.RemoteCacheEvent; @@ -94,7 +94,7 @@ public class BinaryTransactionEventReadWriteTest extends BaseTestCase { class TDServerLookup implements ServerLookup { @Override - public EbeanServer getServer(String name) { + public Database getServer(String name) { return mockEbeanServer; } } diff --git a/ebean-test/src/test/java/main/StartCockroach.java b/ebean-test/src/test/java/main/StartCockroach.java index bb189daa0..fe8c3a0c3 100644 --- a/ebean-test/src/test/java/main/StartCockroach.java +++ b/ebean-test/src/test/java/main/StartCockroach.java @@ -1,16 +1,13 @@ package main; -import io.ebean.docker.commands.CockroachConfig; import io.ebean.docker.commands.CockroachContainer; public class StartCockroach { public static void main(String[] args) { - - CockroachConfig config = new CockroachConfig("v21.2.4"); - config.setDbName("unit"); - - CockroachContainer container = new CockroachContainer(config); - container.start(); + CockroachContainer.newBuilder("v21.2.4") + .dbName("unit") + .build() + .start(); } } diff --git a/ebean-test/src/test/java/main/StartDb2.java b/ebean-test/src/test/java/main/StartDb2.java index dbfd6b38d..53e9ff6eb 100644 --- a/ebean-test/src/test/java/main/StartDb2.java +++ b/ebean-test/src/test/java/main/StartDb2.java @@ -1,22 +1,18 @@ package main; -import io.ebean.docker.commands.Db2Config; import io.ebean.docker.commands.Db2Container; public class StartDb2 { public static void main(String[] args) { - - Db2Config config = new Db2Config("11.5.6.0a"); - config.setDbName("unit"); - config.setUser("unit"); - config.setPassword("unit"); - - // to change collation, charset and other parameters like pagesize: - config.setCreateOptions("USING CODESET UTF-8 TERRITORY DE COLLATE USING IDENTITY PAGESIZE 32768"); - config.setConfigOptions("USING STRING_UNITS CODEUNITS32"); - - Db2Container container = new Db2Container(config); - container.startWithDropCreate(); + Db2Container.newBuilder("11.5.6.0a") + .dbName("unit") + .user("unit") + .password("unit") + // to change collation, charset and other parameters like pagesize: + .configOptions("USING CODESET UTF-8 TERRITORY DE COLLATE USING IDENTITY PAGESIZE 32768") + .configOptions("USING STRING_UNITS CODEUNITS32") + .build() + .startWithDropCreate(); } } diff --git a/ebean-test/src/test/java/main/StartMariaDb.java b/ebean-test/src/test/java/main/StartMariaDb.java index 8bdf82bd7..6d38eb7ef 100644 --- a/ebean-test/src/test/java/main/StartMariaDb.java +++ b/ebean-test/src/test/java/main/StartMariaDb.java @@ -1,18 +1,15 @@ package main; -import io.ebean.docker.commands.MariaDBConfig; import io.ebean.docker.commands.MariaDBContainer; public class StartMariaDb { public static void main(String[] args) { - - MariaDBConfig config = new MariaDBConfig("10.5"); - config.setDbName("unit"); - config.setUser("unit"); - config.setPassword("unit"); - - MariaDBContainer container = new MariaDBContainer(config); - container.startWithDropCreate(); + MariaDBContainer.newBuilder("10.5") + .dbName("unit") + .user("unit") + .password("unit") + .build() + .startWithDropCreate(); } } diff --git a/ebean-test/src/test/java/main/StartMySql.java b/ebean-test/src/test/java/main/StartMySql.java index d7590c511..c9dddeef4 100644 --- a/ebean-test/src/test/java/main/StartMySql.java +++ b/ebean-test/src/test/java/main/StartMySql.java @@ -1,16 +1,17 @@ package main; -import io.ebean.docker.commands.MySqlConfig; import io.ebean.docker.commands.MySqlContainer; public class StartMySql { public static void main(String[] args) { - MySqlConfig config = new MySqlConfig("8.0"); - config.setDbName("unit"); - config.setUser("unit"); - config.setPassword("unit"); + MySqlContainer.newBuilder("8.0") + .dbName("unit") + .user("unit") + .password("unit") + .build() + .startWithDropCreate(); // by default this mysql docker collation is case sensitive // using utf8mb4_bin @@ -22,7 +23,5 @@ public class StartMySql { // config.setCollation("utf8mb4_unicode_ci"); // config.setCharacterSet("utf8mb4"); - MySqlContainer container = new MySqlContainer(config); - container.startWithDropCreate(); } } diff --git a/ebean-test/src/test/java/main/StartNuoDB.java b/ebean-test/src/test/java/main/StartNuoDB.java index e6b6f240a..08fed492a 100644 --- a/ebean-test/src/test/java/main/StartNuoDB.java +++ b/ebean-test/src/test/java/main/StartNuoDB.java @@ -1,16 +1,14 @@ package main; -import io.ebean.docker.commands.NuoDBConfig; import io.ebean.docker.commands.NuoDBContainer; public class StartNuoDB { public static void main(String[] args) { + NuoDBContainer container = NuoDBContainer.newBuilder("4.0") + .schema("test_user") + .build(); - NuoDBConfig config = new NuoDBConfig(); - config.setSchema("test_user"); - - NuoDBContainer container = new NuoDBContainer(config); container.stopRemove(); container.startWithDropCreate(); } diff --git a/ebean-test/src/test/java/main/StartOracle.java b/ebean-test/src/test/java/main/StartOracle.java index df489be07..47ec2cf69 100644 --- a/ebean-test/src/test/java/main/StartOracle.java +++ b/ebean-test/src/test/java/main/StartOracle.java @@ -1,16 +1,13 @@ package main; -import io.ebean.docker.commands.OracleConfig; import io.ebean.docker.commands.OracleContainer; public class StartOracle { public static void main(String[] args) { - - OracleConfig config = new OracleConfig(); - config.setUser("test_ebean"); - - OracleContainer container = new OracleContainer(config); - container.startWithDropCreate(); + OracleContainer.newBuilder("latest") + .user("test_ebean") + .build() + .startWithDropCreate(); } } diff --git a/ebean-test/src/test/java/main/StartPostgres.java b/ebean-test/src/test/java/main/StartPostgres.java index 5b107d2dc..2ea3d8d7d 100644 --- a/ebean-test/src/test/java/main/StartPostgres.java +++ b/ebean-test/src/test/java/main/StartPostgres.java @@ -1,21 +1,18 @@ package main; -import io.ebean.docker.commands.PostgresConfig; import io.ebean.docker.commands.PostgresContainer; public class StartPostgres { public static void main(String[] args) { - - PostgresConfig config = new PostgresConfig("13"); - config.setPort(5432); - config.setDbName("unit"); - config.setUser("unit"); - config.setPassword("unit"); - config.setContainerName("pg13x"); - config.setExtensions("hstore,pgcrypto"); - - PostgresContainer container = new PostgresContainer(config); - container.startWithDropCreate(); + PostgresContainer.newBuilder("13") + .port(5432) + .dbName("unit") + .user("unit") + .password("unit") + .containerName("pg13x") + .extensions("hstore,pgcrypto") + .build() + .startWithDropCreate(); } } diff --git a/ebean-test/src/test/java/main/StartSqlServer.java b/ebean-test/src/test/java/main/StartSqlServer.java index 90cf6434a..f4f4b9f4b 100644 --- a/ebean-test/src/test/java/main/StartSqlServer.java +++ b/ebean-test/src/test/java/main/StartSqlServer.java @@ -1,15 +1,15 @@ package main; -import io.ebean.docker.commands.SqlServerConfig; import io.ebean.docker.commands.SqlServerContainer; public class StartSqlServer { public static void main(String[] args) { - - SqlServerConfig config = new SqlServerConfig("2019-GA-ubuntu-16.04"); - config.setDbName("test_ebean"); - config.setUser("test_ebean"); + SqlServerContainer.newBuilder("2019-GA-ubuntu-16.04") + .dbName("test_ebean") + .user("test_ebean") + .build() + .start(); // by default this sqlserver docker collation is case sensitive // using MSSQL_COLLATION=Latin1_General_100_BIN2 @@ -20,8 +20,5 @@ public class StartSqlServer { //config.setCollation("default"); //config.setCollation("Latin1_General_100_CI"); - - SqlServerContainer container = new SqlServerContainer(config); - container.start(); } } diff --git a/ebean-test/src/test/java/main/StartYugabyte.java b/ebean-test/src/test/java/main/StartYugabyte.java index 01b670c21..9f7449671 100644 --- a/ebean-test/src/test/java/main/StartYugabyte.java +++ b/ebean-test/src/test/java/main/StartYugabyte.java @@ -1,20 +1,16 @@ package main; -import io.ebean.docker.commands.YugabyteConfig; import io.ebean.docker.commands.YugabyteContainer; public class StartYugabyte { public static void main(String[] args) { - - // Check add extensions ? - YugabyteConfig config = new YugabyteConfig("2.11.2.0-b89"); - config.setDbName("unit"); - config.setUser("unit"); - config.setExtensions("pgcrypto"); - - YugabyteContainer container = new YugabyteContainer(config); - container.startWithDropCreate(); + YugabyteContainer.newBuilder("2.11.2.0-b89") + .dbName("unit") + .user("unit") + .extensions("pgcrypto") + .build() + .startWithDropCreate(); // Run container ut_yugabyte with host:localhost port:6433 db:unit user:unit/test shutdown:None // docker run -d --name ut_yugabyte -p 6433:5433 -p 7000:7000 -p 9000:9000 -p 9042:9042 yugabytedb/yugabyte:2.11.2.0-b89 bin/yugabyted start --daemon=false diff --git a/ebean-test/src/test/java/org/tests/model/history/HistoryOneToOne.java b/ebean-test/src/test/java/org/tests/model/history/HistoryOneToOne.java new file mode 100644 index 000000000..aabe3d197 --- /dev/null +++ b/ebean-test/src/test/java/org/tests/model/history/HistoryOneToOne.java @@ -0,0 +1,29 @@ +package org.tests.model.history; + +import io.ebean.annotation.History; +import javax.persistence.CascadeType; +import javax.persistence.Entity; +import javax.persistence.OneToOne; +import org.tests.model.draftable.BaseDomain; + +@History +@Entity +public class HistoryOneToOne extends BaseDomain { + + final String name; + + @OneToOne(cascade = CascadeType.REFRESH) + HistorylessOneToOne historylessOneToOne; + + public HistoryOneToOne(String name) { + this.name = name; + } + + public HistorylessOneToOne less() { + return historylessOneToOne; + } + + public String getName() { + return name; + } +} diff --git a/ebean-test/src/test/java/org/tests/model/history/HistorylessOneToOne.java b/ebean-test/src/test/java/org/tests/model/history/HistorylessOneToOne.java new file mode 100644 index 000000000..f9053cb32 --- /dev/null +++ b/ebean-test/src/test/java/org/tests/model/history/HistorylessOneToOne.java @@ -0,0 +1,35 @@ +package org.tests.model.history; + +import org.tests.model.draftable.BaseDomain; + +import javax.persistence.CascadeType; +import javax.persistence.Entity; +import javax.persistence.OneToOne; + +@Entity +public class HistorylessOneToOne extends BaseDomain { + + private final String name; + + /** + * This @OneToOne(mappedBy=...) side should really be FetchType.LAZY + */ + @OneToOne(mappedBy = "historylessOneToOne", cascade = CascadeType.ALL, orphanRemoval = true)//, fetch = FetchType.LAZY) + HistoryOneToOne historyOneToOne; + + public HistorylessOneToOne(final String name) { + this.name = name; + } + + public HistoryOneToOne getHistoryOneToOne() { + return historyOneToOne; + } + + public void setHistoryOneToOne(final HistoryOneToOne historyOneToOne) { + this.historyOneToOne = historyOneToOne; + } + + public String getName() { + return name; + } +} diff --git a/ebean-test/src/test/java/org/tests/model/history/TestHistoryOneToOne.java b/ebean-test/src/test/java/org/tests/model/history/TestHistoryOneToOne.java new file mode 100644 index 000000000..cf629f9ac --- /dev/null +++ b/ebean-test/src/test/java/org/tests/model/history/TestHistoryOneToOne.java @@ -0,0 +1,90 @@ +package org.tests.model.history; + +import io.ebean.DB; +import io.ebean.annotation.Platform; +import io.ebean.xtest.BaseTestCase; +import io.ebean.xtest.IgnorePlatform; +import org.junit.jupiter.api.Test; + +import java.sql.Timestamp; + +import static org.assertj.core.api.Assertions.assertThat; + +class TestHistoryOneToOne extends BaseTestCase { + + private Long expectedLessId; + private Long expectedHistoryId; + + @IgnorePlatform({Platform.ORACLE, Platform.COCKROACH}) + @Test + void test() throws InterruptedException { + HistorylessOneToOne historylessOneToOne = new HistorylessOneToOne("less"); + historylessOneToOne.setHistoryOneToOne(new HistoryOneToOne("one")); + DB.save(historylessOneToOne); + Thread.sleep(20); + + expectedLessId = historylessOneToOne.getId(); + expectedHistoryId = historylessOneToOne.getHistoryOneToOne().getId(); + + findViaHistory(); + findViaLess(); + + findViaLess_fetch(); + findViaHistory_fetch(); + } + + private void findViaLess() { + HistorylessOneToOne lessFetched = DB.find(HistorylessOneToOne.class) + .asOf(new Timestamp(System.currentTimeMillis())) + .findOne(); + + expected_findViaLess(lessFetched); + } + + + private void findViaLess_fetch() { + HistorylessOneToOne lessFetched = DB.find(HistorylessOneToOne.class) + .asOf(new Timestamp(System.currentTimeMillis())) + .fetch("historyOneToOne") + .findOne(); + + expected_findViaLess(lessFetched); + } + + private void expected_findViaLess(HistorylessOneToOne lessFetched) { + assert lessFetched != null; + assertThat(lessFetched.getId()).isEqualTo(expectedLessId); + HistoryOneToOne history1 = lessFetched.getHistoryOneToOne(); + assertThat(history1.getId()).isEqualTo(expectedHistoryId); + assertThat(history1.less().getId()).isEqualTo(expectedLessId); + assertThat(history1.less().getName()).isEqualTo("less"); + assertThat(history1.getName()).isEqualTo("one"); + } + + + private void findViaHistory_fetch() { + + HistoryOneToOne oneFetched = DB.find(HistoryOneToOne.class) + .asOf(new Timestamp(System.currentTimeMillis())) + .fetch("historylessOneToOne") + .findOne(); + + expected_viaHistory(oneFetched); + } + + private void findViaHistory() { + HistoryOneToOne oneFetched = DB.find(HistoryOneToOne.class) + .asOf(new Timestamp(System.currentTimeMillis())) + .findOne(); + + expected_viaHistory(oneFetched); + } + + private void expected_viaHistory(HistoryOneToOne oneFetched) { + assert oneFetched != null; + assertThat(oneFetched.getId()).isEqualTo(expectedHistoryId); + assertThat(oneFetched.less().getId()).isEqualTo(expectedLessId); + assertThat(oneFetched.less().getName()).isEqualTo("less"); + assertThat(oneFetched.getName()).isEqualTo("one"); + } +} diff --git a/ebean-test/src/test/java/org/tests/query/joins/TestQueryJoinOnFormula.java b/ebean-test/src/test/java/org/tests/query/joins/TestQueryJoinOnFormula.java index 81eb2cfc1..66c2a7616 100644 --- a/ebean-test/src/test/java/org/tests/query/joins/TestQueryJoinOnFormula.java +++ b/ebean-test/src/test/java/org/tests/query/joins/TestQueryJoinOnFormula.java @@ -68,7 +68,7 @@ public class TestQueryJoinOnFormula extends BaseTestCase { List sql = LoggedSql.stop(); assertEquals(1, sql.size()); assertSql(sql.get(0)).contains("join (select order_id, count(*) as total_items,"); - assertSql(sql.get(0)).contains("select count(*) from ( select t0.id from o_order t0 left join (select order_id,"); + assertSql(sql.get(0)).contains("select count(*) from ( select t0.id from o_order t0 left join (select order_id,"); } @Test @@ -83,7 +83,7 @@ public class TestQueryJoinOnFormula extends BaseTestCase { shipQuery.findList(); assertSql(shipQuery.getGeneratedSql()).isEqualTo("select t0.id " + "from or_order_ship t0 " - + "left join o_order t1 on t1.id = t0.order_id " + + "left join o_order t1 on t1.id = t0.order_id " + "left join (select order_id, count(*) as total_items, sum(order_qty*unit_price) as total_amount from o_order_detail group by order_id) z_bt1 on z_bt1.order_id = t1.id " + "order by z_bt1.total_amount"); } @@ -100,7 +100,7 @@ public class TestQueryJoinOnFormula extends BaseTestCase { shipQuery.findList(); assertSql(shipQuery.getGeneratedSql()).isEqualTo("select t0.id " + "from or_order_ship t0 " - + "left join o_order t1 on t1.id = t0.order_id " + + "left join o_order t1 on t1.id = t0.order_id " + "left join (select order_id, count(*) as total_items, sum(order_qty*unit_price) as total_amount from o_order_detail group by order_id) z_bt1 on z_bt1.order_id = t1.id " + "where z_bt1.total_amount is not null"); } @@ -124,7 +124,7 @@ public class TestQueryJoinOnFormula extends BaseTestCase { "from or_order_ship t0 " + "join o_order u1 on u1.id = t0.order_id " + "join or_order_ship u2 on u2.order_id = u1.id " + - "join o_order u3 on u3.id = u2.order_id " + + "join o_order u3 on u3.id = u2.order_id " + "left join (select order_id, count(*) as total_items, sum(order_qty*unit_price) as total_amount from o_order_detail group by order_id) z_bu3 on z_bu3.order_id = u3.id " + "where z_bu3.total_amount is not null"); } @@ -141,7 +141,7 @@ public class TestQueryJoinOnFormula extends BaseTestCase { shipQuery.findList(); assertSql(shipQuery.getGeneratedSql()).isEqualTo("select t0.id, t1.id, z_bt1.total_amount " + "from or_order_ship t0 " - + "left join o_order t1 on t1.id = t0.order_id " + + "left join o_order t1 on t1.id = t0.order_id " + "left join (select order_id, count(*) as total_items, sum(order_qty*unit_price) as total_amount from o_order_detail group by order_id) z_bt1 on z_bt1.order_id = t1.id " + "order by z_bt1.total_amount"); @@ -158,7 +158,7 @@ public class TestQueryJoinOnFormula extends BaseTestCase { shipQuery.findList(); assertSql(shipQuery.getGeneratedSql()).isEqualTo("select t0.id, t1.id, z_bt1.total_amount " + "from or_order_ship t0 " - + "left join o_order t1 on t1.id = t0.order_id " + + "left join o_order t1 on t1.id = t0.order_id " + "left join (select order_id, count(*) as total_items, sum(order_qty*unit_price) as total_amount from o_order_detail group by order_id) z_bt1 on z_bt1.order_id = t1.id " + "where z_bt1.total_amount is not null"); @@ -179,7 +179,7 @@ public class TestQueryJoinOnFormula extends BaseTestCase { List sql = LoggedSql.stop(); assertEquals(1, sql.size()); - assertSql(sql.get(0)).contains("select count(*) from ( select t0.id from o_order t0 left join (select order_id,"); + assertSql(sql.get(0)).contains("select count(*) from ( select t0.id from o_order t0 left join (select order_id,"); } @Test diff --git a/ebean-test/src/test/java/org/tests/types/TestFileType.java b/ebean-test/src/test/java/org/tests/types/TestFileType.java index 28e1e02a5..6ea0445e4 100644 --- a/ebean-test/src/test/java/org/tests/types/TestFileType.java +++ b/ebean-test/src/test/java/org/tests/types/TestFileType.java @@ -12,6 +12,7 @@ import java.io.PrintStream; import java.net.URL; import static org.junit.jupiter.api.Assertions.*; +import static org.assertj.core.api.Assertions.assertThat; public class TestFileType extends BaseTestCase { @@ -184,6 +185,31 @@ public class TestFileType extends BaseTestCase { DB.delete(bean3); } + @Test + void test_FileDirty() throws Exception { + SomeFileBean bean0 = new SomeFileBean(); + bean0.setName("afile"); + bean0.setContent(file); + + DB.save(bean0); + + SomeFileBean bean1 = DB.find(SomeFileBean.class) + .select("name, file") + .setId(bean0.getId()) + .findOne(); + + assertThat(bean1.getContent()) + .isNotEqualTo(file) // not same file object, but same content + .hasSameBinaryContentAs(file); + + assertFalse(DB.beanState(bean1).isDirty()); + bean1.setContent(file); + assertFalse(DB.beanState(bean1).isDirty()); + bean1.setContent(file2); + assertTrue(DB.beanState(bean1).isDirty()); + + } + private File getFile(String resource) { URL url = getClass().getResource(resource); return new File(url.getFile()); diff --git a/ebean-test/src/test/resources/ebean.properties b/ebean-test/src/test/resources/ebean.properties index d1b3f87e3..91c0d0c29 100644 --- a/ebean-test/src/test/resources/ebean.properties +++ b/ebean-test/src/test/resources/ebean.properties @@ -23,7 +23,7 @@ ebean.ddl.run=true ebean.ddl.header=-- Generated by ebean ${version} at ${timestamp} ebean.packages=org.tests,org.etest datasource.default=h2 -#datasource.default=yugabyte +#datasource.default=sqlserver #datasource.h2.capturestacktrace=true #ebean.dumpMetricsOnShutdown=true @@ -177,7 +177,8 @@ ebean.sqlserver.databasePlatformName=sqlserver17 #ebean.sqlserver.caseSensitiveCollation=false datasource.sqlserver.username=test_ebean datasource.sqlserver.password=SqlS3rv#r -datasource.sqlserver.url=jdbc:sqlserver://localhost:1433;databaseName=test_ebean;sendTimeAsDateTime=false +#datasource.sqlserver.url=jdbc:sqlserver://localhost:1433;databaseName=test_ebean;sendTimeAsDateTime=false;integratedSecurity=false;trustServerCertificate=true +datasource.sqlserver.url=jdbc:sqlserver://localhost:9435;databaseName=test_ebean;sendTimeAsDateTime=false;integratedSecurity=false;trustServerCertificate=true #datasource.sqlserver.driver=com.microsoft.sqlserver.jdbc.SQLServerDriver datasource.nuodb.schema=test_user diff --git a/ebean-test/testconfig/ebean-sqlserver17.properties b/ebean-test/testconfig/ebean-sqlserver17.properties index c0388b6ec..103b1fea2 100644 --- a/ebean-test/testconfig/ebean-sqlserver17.properties +++ b/ebean-test/testconfig/ebean-sqlserver17.properties @@ -4,7 +4,7 @@ ebean.test.sqlserver.version=2017-CU28-ubuntu-16.04 ebean.test.sqlserver.containerName=local_sqlserver2017 ebean.test.sqlserver.collation=LATIN1_GENERAL_100_CS_AS_SC ebean.test.sqlserver.port=9435 -ebean.test.sqlserver.url=jdbc:sqlserver://localhost:9435;databaseName=test_ebean;sendTimeAsDateTime=false +ebean.test.sqlserver.url=jdbc:sqlserver://localhost:9435;databaseName=test_ebean;sendTimeAsDateTime=false;integratedSecurity=false;trustServerCertificate=true datasource.default=sqlserver2017 ebean.sqlserver2017.databasePlatformName=sqlserver17 diff --git a/ebean-test/testconfig/ebean-sqlserver19.properties b/ebean-test/testconfig/ebean-sqlserver19.properties index 5c8accf32..80ffe7320 100644 --- a/ebean-test/testconfig/ebean-sqlserver19.properties +++ b/ebean-test/testconfig/ebean-sqlserver19.properties @@ -4,7 +4,7 @@ ebean.test.sqlserver.version=2019-latest ebean.test.sqlserver.containerName=local_sqlserver2019 ebean.test.sqlserver.collation=LATIN1_GENERAL_100_CS_AS_SC_UTF8 ebean.test.sqlserver.port=9434 -ebean.test.sqlserver.url=jdbc:sqlserver://localhost:9434;databaseName=test_ebean;sendTimeAsDateTime=false +ebean.test.sqlserver.url=jdbc:sqlserver://localhost:9434;databaseName=test_ebean;sendTimeAsDateTime=false;integratedSecurity=false;trustServerCertificate=true datasource.default=sqlserver2019 ebean.sqlserver2019.databasePlatformName=sqlserver17 diff --git a/kotlin-querybean-generator/pom.xml b/kotlin-querybean-generator/pom.xml index d382456d5..758a6fba3 100644 --- a/kotlin-querybean-generator/pom.xml +++ b/kotlin-querybean-generator/pom.xml @@ -4,7 +4,7 @@ ebean-parent io.ebean - 13.3.1-SNAPSHOT + 13.6.0-SNAPSHOT kotlin querybean generator @@ -29,7 +29,7 @@ io.ebean ebean-querybean - 13.3.1-SNAPSHOT + 13.6.0-SNAPSHOT test @@ -43,7 +43,7 @@ io.ebean ebean-core - 13.3.1-SNAPSHOT + 13.6.0-SNAPSHOT test @@ -64,7 +64,7 @@ io.ebean ebean-ddl-generator - 13.3.1-SNAPSHOT + 13.6.0-SNAPSHOT test diff --git a/platforms/all/pom.xml b/platforms/all/pom.xml index 48e23547d..4999dde60 100644 --- a/platforms/all/pom.xml +++ b/platforms/all/pom.xml @@ -4,7 +4,7 @@ platforms io.ebean - 13.3.1-SNAPSHOT + 13.6.0-SNAPSHOT ebean-platform-all @@ -14,67 +14,67 @@ io.ebean ebean-platform-h2 - 13.3.1-SNAPSHOT + 13.6.0-SNAPSHOT io.ebean ebean-platform-clickhouse - 13.3.1-SNAPSHOT + 13.6.0-SNAPSHOT io.ebean ebean-platform-db2 - 13.3.1-SNAPSHOT + 13.6.0-SNAPSHOT io.ebean ebean-platform-hana - 13.3.1-SNAPSHOT + 13.6.0-SNAPSHOT io.ebean ebean-platform-hsqldb - 13.3.1-SNAPSHOT + 13.6.0-SNAPSHOT io.ebean ebean-platform-mysql - 13.3.1-SNAPSHOT + 13.6.0-SNAPSHOT io.ebean ebean-platform-mariadb - 13.3.1-SNAPSHOT + 13.6.0-SNAPSHOT io.ebean ebean-platform-nuodb - 13.3.1-SNAPSHOT + 13.6.0-SNAPSHOT io.ebean ebean-platform-oracle - 13.3.1-SNAPSHOT + 13.6.0-SNAPSHOT io.ebean ebean-platform-postgres - 13.3.1-SNAPSHOT + 13.6.0-SNAPSHOT io.ebean ebean-platform-sqlanywhere - 13.3.1-SNAPSHOT + 13.6.0-SNAPSHOT io.ebean ebean-platform-sqlite - 13.3.1-SNAPSHOT + 13.6.0-SNAPSHOT io.ebean ebean-platform-sqlserver - 13.3.1-SNAPSHOT + 13.6.0-SNAPSHOT diff --git a/platforms/clickhouse/pom.xml b/platforms/clickhouse/pom.xml index 773f7cce2..e14e765dc 100644 --- a/platforms/clickhouse/pom.xml +++ b/platforms/clickhouse/pom.xml @@ -4,7 +4,7 @@ platforms io.ebean - 13.3.1-SNAPSHOT + 13.6.0-SNAPSHOT ebean-platform-clickhouse @@ -14,7 +14,7 @@ io.ebean ebean-api - 13.3.1-SNAPSHOT + 13.6.0-SNAPSHOT diff --git a/platforms/db2/pom.xml b/platforms/db2/pom.xml index 1ecc98d2f..79955d3cb 100644 --- a/platforms/db2/pom.xml +++ b/platforms/db2/pom.xml @@ -4,7 +4,7 @@ platforms io.ebean - 13.3.1-SNAPSHOT + 13.6.0-SNAPSHOT ebean-platform-db2 @@ -14,7 +14,7 @@ io.ebean ebean-api - 13.3.1-SNAPSHOT + 13.6.0-SNAPSHOT diff --git a/platforms/h2/pom.xml b/platforms/h2/pom.xml index 122dd9e64..d73a14c44 100644 --- a/platforms/h2/pom.xml +++ b/platforms/h2/pom.xml @@ -4,7 +4,7 @@ platforms io.ebean - 13.3.1-SNAPSHOT + 13.6.0-SNAPSHOT ebean-platform-h2 @@ -14,7 +14,7 @@ io.ebean ebean-api - 13.3.1-SNAPSHOT + 13.6.0-SNAPSHOT