Compare commits

...
Author SHA1 Message Date
Robin Bygrave ad992d07ce [maven-release-plugin] prepare release avaje-ebeanorm-7.21.2 2016-08-02 21:31:47 +12:00
Robin Bygrave cbcec8f5ea No effective change - tidy 2016-08-02 20:32:59 +12:00
Robin Bygrave 6e2148d20b #799 - Query.fetch(path) when converted to query join default to batchSize 10 rather than 100 2016-08-02 20:19:38 +12:00
Robin Bygrave ca1c0a08f3 No effective change - remove whitespace on DLoadBeanContext 2016-08-02 20:14:46 +12:00
Robin Bygrave baa6fc355e No effective change - javadoc update on FetchConfig 2016-08-02 20:14:07 +12:00
Robin Bygrave 48edf64013 No effective change - typo in javadoc 2016-08-02 11:10:19 +12:00
Robin Bygrave e2ee6e8e98 No effective change - update tests with EBasicVer new constructor 2016-08-02 11:06:09 +12:00
Robin Bygrave e6e6a28245 No effective change - tidy asserts on TestQueryDistinct (AssertJ string contains etc) 2016-08-01 22:53:47 +12:00
Rob BygraveandGitHub 82a695a98a Merge pull request #797 from backslash47/master
Add check for distinct query when adding id attribute to order clause in paging query
2016-08-01 22:47:34 +12:00
Matus Zamborsky cdad31bd8a Added test for distinct paging query 2016-08-01 12:20:50 +02:00
Matus Zamborsky 4d16cf9caa Add check for distinct query when adding id attribute to order clause in paging query 2016-08-01 10:13:05 +02:00
Robin Bygrave 84a86cad0e #794 - Refactor - tidy code, remove unused mimetypes properties 2016-07-31 23:34:55 +12:00
Robin Bygrave dfdf87fa2d #794 - Refactor - tidy code, javadoc tidy 2016-07-31 23:33:29 +12:00
Robin Bygrave ee0615caec #794 - Refactor - tidy code, use uppercase L for Long literal 2016-07-31 23:33:07 +12:00
Robin Bygrave 79b8395f8f #794 - Refactor - tidy code, simplify if 2016-07-31 23:32:37 +12:00
Robin Bygrave 87c479cd95 #794 - Refactor - tidy code, remove unused imports 2016-07-31 23:24:30 +12:00
Robin Bygrave abbdda810a #794 - Refactor - tidy code, remove unused method arguments 2016-07-31 23:23:57 +12:00
Robin Bygrave e621900de9 #794 - Refactor - tidy code, remove unused method arguments 2016-07-31 23:23:43 +12:00
Robin Bygrave 76b33511e1 #793 - com.avaje.ebean.event.changelog.BeanChange not keeping passed id value 2016-07-31 23:14:08 +12:00
Robin Bygrave 77deab5cf0 #792 - Change Logging Rollback message on org.avaje.ebean.TXN from INFO level to DEBUG level 2016-07-31 22:52:48 +12:00
Robin Bygrave 4a9f8cef0e No effective change - rename SpiQuery method for m2mIncludeJoin and simplify OrmQueryPlanKey to associated intersection table name 2016-07-31 22:49:10 +12:00
Robin Bygrave 4d1340c16c No effective change - rename SpiQuery method for m2mIncludeJoin and simplify OrmQueryPlanKey to associated intersection table name 2016-07-31 22:46:07 +12:00
Robin Bygrave 74c6c71301 [maven-release-plugin] prepare for next development iteration 2016-07-31 21:28:17 +12:00
Robin Bygrave 0f0028eb1f [maven-release-plugin] prepare release avaje-ebeanorm-7.21.1 2016-07-31 21:27:58 +12:00
Robin Bygrave b4a1d52067 #791 - ENH: Add transaction.setRollbackOnly() ... (and Ebean.setRollbackOnly()) 2016-07-31 21:24:31 +12:00
Robin Bygrave d82148248c No effective change - javadoc tidy 2016-07-31 20:55:34 +12:00
Robin Bygrave dc7c854432 #788 - Deprecate findRowCount() ... add findCount(). Effectively renaming findRowCount() to findCount() 2016-07-31 19:06:21 +12:00
Robin Bygrave 7c83010df1 #788 - Deprecate findRowCount() ... add findCount(). Effectively renaming findRowCount() to findCount() 2016-07-31 16:39:23 +12:00
Robin Bygrave ed41e58073 Bump pom version to 7.21.1-SNAPSHOT 2016-07-31 16:01:00 +12:00
Robin Bygrave 5bab9eb648 #790 - DB Migration with multiple platforms (and no maven H2 dependency) gives: java.lang.NoClassDefFoundError: org/h2/api/Trigger 2016-07-31 15:59:54 +12:00
Robin Bygrave 5ce8eb6046 No effective change - remove unused methods 2016-07-31 15:02:05 +12:00
Robin Bygrave 56fee2ea9b #789 - findCount() ... with where raw(...) expression that includes a "many" produces incorrect SQL 2016-07-31 14:57:12 +12:00
Robin Bygrave 780ee7c7c0 [maven-release-plugin] prepare for next development iteration 2016-07-25 23:37:18 +12:00
117 changed files with 723 additions and 633 deletions
+2 -2
View File
@@ -9,7 +9,7 @@
<groupId>org.avaje.ebeanorm</groupId>
<artifactId>avaje-ebeanorm</artifactId>
<version>7.20.1</version>
<version>7.21.2</version>
<packaging>jar</packaging>
<name>avaje-ebeanorm</name>
@@ -37,7 +37,7 @@
<scm>
<developerConnection>scm:git:https://github.com/ebean-orm/avaje-ebeanorm.git</developerConnection>
<tag>avaje-ebeanorm-7.20.1</tag>
<tag>avaje-ebeanorm-7.21.2</tag>
</scm>
<dependencies>
+7
View File
@@ -499,6 +499,13 @@ public final class Ebean {
serverMgr.getDefaultServer().endTransaction();
}
/**
* Mark the current transaction as rollback only.
*/
public static void setRollbackOnly() {
serverMgr.getDefaultServer().currentTransaction().setRollbackOnly();
}
/**
* Return a map of the differences between two objects of the same type.
* <p>
+20 -5
View File
@@ -739,11 +739,18 @@ public interface EbeanServer {
<T> T getReference(Class<T> beanType, Object id);
/**
* Return the number of 'top level' or 'root' entities this query should
* return.
* Return the number of 'top level' or 'root' entities this query should return.
*
* @see Query#findRowCount()
* @see com.avaje.ebean.Query#findFutureRowCount()
* @see Query#findCount()
* @see Query#findFutureCount()
*/
<T> int findCount(Query<T> query, Transaction transaction);
/**
* Deprecated in favor of findCount()
*
* Return the number of 'top level' or 'root' entities this query should return.
* @deprecated
*/
<T> int findRowCount(Query<T> query, Transaction transaction);
@@ -868,7 +875,15 @@ public interface EbeanServer {
* @return a Future object for the row count query
* @see com.avaje.ebean.Query#findFutureRowCount()
*/
<T> FutureRowCount<T> findFutureRowCount(Query<T> query, Transaction transaction);
<T> FutureRowCount<T> findFutureCount(Query<T> query, Transaction transaction);
/**
* Deprecated in favor of findFutureCount().
*
* Execute find row count query in a background thread.
* @deprecated
*/
<T> FutureRowCount<T> findFutureRowCount(Query<T> query, Transaction transaction);
/**
* Execute find Id's query in a background thread.
@@ -182,6 +182,13 @@ public interface ExpressionList<T> {
* This is the number of 'top level' or 'root level' entities.
* </p>
*/
int findCount();
/**
* Deprecated in favor of findCount().
*
* @deprecated
*/
int findRowCount();
/**
@@ -228,6 +235,13 @@ public interface ExpressionList<T> {
*
* @return a Future object for the row count query
*/
FutureRowCount<T> findFutureCount();
/**
* Deprecated in favor of findFutureCount().
*
* @deprecated
*/
FutureRowCount<T> findFutureRowCount();
/**
@@ -29,8 +29,7 @@ import java.io.Serializable;
* // Find Orders join details using a single SQL query
* }</pre>
* <p>
* Example: Using a "query join" instead of a "fetch join" we instead use 2 SQL
* queries
* Example: Using a "query join" instead of a "fetch join" we instead use 2 SQL queries
* </p>
*
* <pre>{@code
@@ -117,7 +116,7 @@ import java.io.Serializable;
* <pre>{@code
* List<Order> list = Ebean.find(Order.class)
* .fetch("customer","name", new FetchConfig().lazy(5))
* .fetch("customer.contacts",&quotcontactName, phone, email&quot)
* .fetch("customer.contacts","contactName, phone, email")
* .fetch("customer.shippingAddress")
* .where().eq("status",Order.Status.NEW)
* .findList();
@@ -125,12 +124,7 @@ import java.io.Serializable;
* // query 1) find order where status = Order.Status.NEW
* //
* // .. if lazy loading of customers is invoked
* // .. use a batch size of 5 to load the customers
*
* find customer (name)
* fetch customer.contacts (contactName, phone, email)
* fetch customer.shippingAddress (*)
* where id in (?,?,?,?,?)
* // .. use a batch size of 5 to load the customers
*
* }</pre>
*
+21 -4
View File
@@ -677,19 +677,36 @@ public abstract class Model {
/**
* Executes a find row count query in a background thread.
* <p>
* Equivalent to {@link Query#findFutureRowCount()}
* Equivalent to {@link Query#findFutureCount()}
*/
public FutureRowCount<T> findFutureCount() {
return query().findFutureCount();
}
/**
* Deprecated in favor of findFutureCount().
* <p>
* Equivalent to {@link Query#findFutureCount()}
*/
public FutureRowCount<T> findFutureRowCount() {
return query().findFutureRowCount();
return query().findFutureCount();
}
/**
* Returns the total number of entities for this type. *
* <p>
* Equivalent to {@link Query#findRowCount()}
* Equivalent to {@link Query#findCount()}
*/
public int findCount() {
return query().findCount();
}
/**
* Deprecated in favor of findCount().
* @deprecated
*/
public int findRowCount() {
return query().findRowCount();
return query().findCount();
}
/**
@@ -110,6 +110,13 @@ public interface PagedList<T> {
* wrapped in the unchecked PersistenceException (which might be preferrable).
* </p>
*/
void loadCount();
/**
* Deprecated in favor of loadCount().
*
* @deprecated
*/
void loadRowCount();
/**
@@ -138,6 +145,13 @@ public interface PagedList<T> {
*
* }</pre>
*/
Future<Integer> getFutureCount();
/**
* Deprecated in favor of getFutureCount().
*
* @deprecated
*/
Future<Integer> getFutureRowCount();
/**
@@ -170,6 +184,13 @@ public interface PagedList<T> {
*
* }</pre>
*/
int getTotalCount();
/**
* Deprecated in favor of getTotalCount().
*
* @deprecated
*/
int getTotalRowCount();
/**
+87 -126
View File
@@ -13,10 +13,10 @@ import java.util.Set;
* <p>
* Example: Create the query using the API.
* </p>
*
* <p>
* <pre>{@code
*
* List<Order> orderList =
* List<Order> orderList =
* ebeanServer.find(Order.class)
* .fetch("customer")
* .fetch("details")
@@ -26,46 +26,41 @@ import java.util.Set;
* .orderBy("customer.id, id desc")
* .setMaxRows(50)
* .findList();
*
*
* ...
* }</pre>
*
* <p>
* Example: The same query using the query language
* </p>
*
* <pre>{@code
*
* String oql =
* String oql =
* " find order "
* +" fetch customer "
* +" fetch details "
* +" where customer.name like :custName and orderDate > :minOrderDate "
* +" order by customer.id, id desc "
* +" limit 50 ";
*
*
* Query<Order> query = ebeanServer.createQuery(Order.class, oql);
* query.setParameter("custName", "Rob%");
* query.setParameter("minOrderDate", lastWeek);
*
*
* List<Order> orderList = query.findList();
* ...
* }</pre>
*
* <p>
* Example: Using a named query called "with.cust.and.details"
* </p>
*
* <pre>{@code
*
* Query<Order> query = ebeanServer.createNamedQuery(Order.class,"with.cust.and.details");
* query.setParameter("custName", "Rob%");
* query.setParameter("minOrderDate", lastWeek);
*
*
* List<Order> orderList = query.findList();
* ...
* }</pre>
*
* <h3>AutoTune</h3>
* <p>
* Ebean has built in support for "AutoTune". This is a mechanism where a query
@@ -82,7 +77,6 @@ import java.util.Set;
* to a remote client or where there is some requirement for "Read Consistency"
* guarantees.
* </p>
*
* <h3>Query Language</h3>
* <p>
* <b>Partial Objects</b>
@@ -101,7 +95,6 @@ import java.util.Set;
* concurrency checking will occur but only include the fetched properties.
* Refer to "ALL Properties/Columns" mode of Optimistic Concurrency checking.
* </p>
*
* <pre>{@code
* [ find {bean type} [ ( * | {fetch properties} ) ] ]
* [ fetch {associated bean} [ ( * | {fetch properties} ) ] ]
@@ -109,7 +102,6 @@ import java.util.Set;
* [ order by {order by properties} ]
* [ limit {max rows} [ offset {first row} ] ]
* }</pre>
*
* <p>
* <b>FIND</b> <b>{bean type}</b> [ ( <i>*</i> | <i>{fetch properties}</i> ) ]
* </p>
@@ -163,50 +155,40 @@ import java.util.Set;
* <p>
* Find orders fetching all its properties
* </p>
*
* <pre>{@code
* find order
* }</pre>
*
* <p>
* Find orders fetching all its properties
* </p>
*
* <pre>{@code
* find order (*)
* }</pre>
*
* <p>
* Find orders fetching its id, shipDate and status properties. Note that the id
* property is always fetched even if it is not included in the list of fetch
* properties.
* </p>
*
* <pre>{@code
* find order (shipDate, status)
* }</pre>
*
* <p>
* Find orders with a named bind variable (that will need to be bound via
* {@link Query#setParameter(String, Object)}).
* </p>
*
* <pre>{@code
* find order
* where customer.name like :custLike
* }</pre>
*
* <p>
* Find orders and also fetch the customer with a named bind parameter. This
* will fetch and populate both the order and customer objects.
* </p>
*
* <pre>{@code
* find order
* fetch customer
* where customer.id = :custId
* }</pre>
*
* <p>
* Find orders and also fetch the customer, customer shippingAddress, order
* details and related product. Note that customer and product objects will be
@@ -215,7 +197,6 @@ import java.util.Set;
* objects (associated with each order detail) will have their id, sku and name
* populated.
* </p>
*
* <pre>{@code
* find order
* fetch customer (name)
@@ -223,7 +204,6 @@ import java.util.Set;
* fetch details
* fetch details.product (sku, name)
* }</pre>
*
* <h3>Early parsing of the Query</h3>
* <p>
* When you get a Query object from a named query, the query statement has
@@ -269,9 +249,8 @@ import java.util.Set;
* to make it as easy as possible to use your own SQL to populate entity beans.
* Refer to {@link RawSql} .
* </p>
*
* @param <T>
* the type of Entity bean this query will fetch.
*
* @param <T> the type of Entity bean this query will fetch.
*/
public interface Query<T> {
@@ -289,7 +268,7 @@ public interface Query<T> {
* Perform an 'As of' query using history tables to return the object graph
* as of a time in the past.
* <p>
* To perform this query the DB must have underlying history tables.
* To perform this query the DB must have underlying history tables.
* </p>
*
* @param asOf the date time in the past at which you want to view the data
@@ -399,7 +378,6 @@ public interface Query<T> {
* You use {@link #fetch(String, String)} to specify specific properties to fetch
* on other non-root level paths of the object graph.
* </p>
*
* <pre>{@code
*
* List<Customer> customers =
@@ -412,8 +390,7 @@ public interface Query<T> {
*
* }</pre>
*
* @param fetchProperties
* the properties to fetch for this bean (* = all properties).
* @param fetchProperties the properties to fetch for this bean (* = all properties).
*/
Query<T> select(String fetchProperties);
@@ -428,7 +405,6 @@ public interface Query<T> {
* only those properties are fetched and populated resulting in a
* "Partial Object" - a bean that only has some of its properties populated.
* </p>
*
* <pre>{@code
*
* // query orders...
@@ -437,17 +413,15 @@ public interface Query<T> {
* // fetch the customer...
* // ... getting the customers name and phone number
* .fetch("customer", "name, phoneNumber")
*
*
* // ... also fetch the customers billing address (* = all properties)
* .fetch("customer.billingAddress", "*")
* .findList();
* }</pre>
*
* <p>
* If columns is null or "*" then all columns/properties for that path are
* fetched.
* </p>
*
* <pre>{@code
*
* // fetch customers (their id, name and status)
@@ -458,19 +432,16 @@ public interface Query<T> {
* .findList();
*
* }</pre>
*
* @param path
* the path of an associated (1-1,1-M,M-1,M-M) bean.
* @param fetchProperties
* properties of the associated bean that you want to include in the
* fetch (* means all properties, null also means all properties).
*
* @param path the path of an associated (1-1,1-M,M-1,M-M) bean.
* @param fetchProperties properties of the associated bean that you want to include in the
* fetch (* means all properties, null also means all properties).
*/
Query<T> fetch(String path, String fetchProperties);
/**
* Additionally specify a FetchConfig to use a separate query or lazy loading
* to load this path.
*
* <pre>{@code
*
* // fetch customers (their id, name and status)
@@ -500,16 +471,13 @@ public interface Query<T> {
*
* }</pre>
*
* @param path
* the property of an associated (1-1,1-M,M-1,M-M) bean.
* @param path the property of an associated (1-1,1-M,M-1,M-M) bean.
*/
Query<T> fetch(String path);
/**
* Additionally specify a JoinConfig to specify a "query join" and or define
* the lazy loading query.
*
*
* <pre>{@code
*
* // fetch customers (their id, name and status)
@@ -536,7 +504,7 @@ public interface Query<T> {
* <p>
* This query will execute against the EbeanServer that was used to create it.
* </p>
*
*
* @see EbeanServer#findIds(Query, Transaction)
*/
List<Object> findIds();
@@ -564,7 +532,6 @@ public interface Query<T> {
* iterator uses the QueryEachConsumer (SAM) interface which is better suited to use
* with Java8 closures.
* </p>
*
* <pre>{@code
*
* ebeanServer.find(Customer.class)
@@ -578,8 +545,7 @@ public interface Query<T> {
*
* }</pre>
*
* @param consumer
* the consumer used to process the queried beans.
* @param consumer the consumer used to process the queried beans.
*/
void findEach(QueryEachConsumer<T> consumer);
@@ -591,8 +557,6 @@ public interface Query<T> {
* iterator uses the QueryEachWhileConsumer (SAM) interface which is better suited to use
* with Java8 closures.
* </p>
*
* <pre>{@code
*
* ebeanServer.find(Customer.class)
@@ -611,8 +575,7 @@ public interface Query<T> {
*
* }</pre>
*
* @param consumer
* the consumer used to process the queried beans.
* @param consumer the consumer used to process the queried beans.
*/
void findEachWhile(QueryEachWhileConsumer<T> consumer);
@@ -621,7 +584,6 @@ public interface Query<T> {
* <p>
* This query will execute against the EbeanServer that was used to create it.
* </p>
*
* <pre>{@code
*
* List<Customer> customers =
@@ -640,7 +602,6 @@ public interface Query<T> {
* <p>
* This query will execute against the EbeanServer that was used to create it.
* </p>
*
* <pre>{@code
*
* Set<Customer> customers =
@@ -663,7 +624,6 @@ public interface Query<T> {
* You can use setMapKey() so specify the property values to be used as keys
* on the map. If one is not specified then the id property is used.
* </p>
*
* <pre>{@code
*
* Map<?, Product> map =
@@ -672,7 +632,7 @@ public interface Query<T> {
* .findMap();
*
* }</pre>
*
*
* @see EbeanServer#findMap(Query, Transaction)
*/
Map<?, T> findMap();
@@ -693,7 +653,6 @@ public interface Query<T> {
* This is useful when your predicates dictate that your query should only
* return 0 or 1 results.
* </p>
*
* <pre>{@code
*
* // assuming the sku of products is unique...
@@ -703,16 +662,14 @@ public interface Query<T> {
* .findUnique();
* ...
* }</pre>
*
* <p>
* It is also useful with finding objects by their id when you want to specify
* further join information.
* </p>
*
* <pre>{@code
*
* // Fetch order 1 and additionally fetch join its order details...
* Order order =
* Order order =
* ebeanServer.find(Order.class)
* .setId(1)
* .fetch("details")
@@ -731,13 +688,13 @@ public interface Query<T> {
/**
* Return versions of a @History entity bean.
* <p>
* Note that this query will work against view based history implementations
* but not sql2011 standards based implementations that require a start and
* end timestamp to be specified.
* Note that this query will work against view based history implementations
* but not sql2011 standards based implementations that require a start and
* end timestamp to be specified.
* </p>
* <p>
* Generally this query is expected to be a find by id or unique predicates query.
* It will execute the query against the history returning the versions of the bean.
* Generally this query is expected to be a find by id or unique predicates query.
* It will execute the query against the history returning the versions of the bean.
* </p>
*/
List<Version<T>> findVersions();
@@ -745,8 +702,8 @@ public interface Query<T> {
/**
* Return versions of a @History entity bean between the 2 timestamps.
* <p>
* Generally this query is expected to be a find by id or unique predicates query.
* It will execute the query against the history returning the versions of the bean.
* Generally this query is expected to be a find by id or unique predicates query.
* It will execute the query against the history returning the versions of the bean.
* </p>
*/
List<Version<T>> findVersionsBetween(Timestamp start, Timestamp end);
@@ -774,6 +731,14 @@ public interface Query<T> {
* This is the number of 'top level' or 'root level' entities.
* </p>
*/
int findCount();
/**
* Deprecated in favor of findCount().
* <p>
* Return the count of entities this query should return.
* @deprecated
*/
int findRowCount();
/**
@@ -783,9 +748,24 @@ public interface Query<T> {
* execution status (isDone etc) and get the value (with or without a
* timeout).
* </p>
*
*
* @return a Future object for the row count query
*/
FutureRowCount<T> findFutureCount();
/**
* Deprecated in favor of findFutureCount().
* <p>
* Execute find row count query in a background thread.
* <p>
* This returns a Future object which can be used to cancel, check the
* execution status (isDone etc) and get the value (with or without a
* timeout).
* </p>
*
* @return a Future object for the row count query
* @deprecated
*/
FutureRowCount<T> findFutureRowCount();
/**
@@ -795,7 +775,7 @@ public interface Query<T> {
* execution status (isDone etc) and get the value (with or without a
* timeout).
* </p>
*
*
* @return a Future object for the list of Id's
*/
FutureIds<T> findFutureIds();
@@ -821,7 +801,6 @@ public interface Query<T> {
* If maxRows is not set on the query prior to calling findPagedList() then a
* PersistenceException is thrown.
* </p>
*
* <pre>{@code
*
* PagedList<Order> pagedList = Ebean.find(Order.class)
@@ -843,24 +822,21 @@ public interface Query<T> {
/**
* Set a named bind parameter. Named parameters have a colon to prefix the name.
*
* <pre>{@code
*
* // a query with a named parameter
* String oql = "find order where status = :orderStatus";
*
*
* Query<Order> query = ebeanServer.find(Order.class, oql);
*
*
* // bind the named parameter
* query.bind("orderStatus", OrderStatus.NEW);
* List<Order> list = query.findList();
*
* }</pre>
*
* @param name
* the parameter name
* @param value
* the parameter value
*
* @param name the parameter name
* @param value the parameter value
*/
Query<T> setParameter(String name, Object value);
@@ -868,25 +844,22 @@ public interface Query<T> {
* Set an ordered bind parameter according to its position. Note that the
* position starts at 1 to be consistent with JDBC PreparedStatement. You need
* to set a parameter value for each ? you have in the query.
*
* <pre>{@code
*
* // a query with a positioned parameter
* String oql = "where status = ? order by id desc";
*
*
* Query<Order> query = ebeanServer.createQuery(Order.class, oql);
*
*
* // bind the parameter
* query.setParameter(1, OrderStatus.NEW);
*
*
* List<Order> list = query.findList();
*
* }</pre>
*
* @param position
* the parameter bind position starting from 1 (not 0)
* @param value
* the parameter bind value.
*
* @param position the parameter bind position starting from 1 (not 0)
* @param value the parameter bind value.
*/
Query<T> setParameter(int position, Object value);
@@ -896,7 +869,6 @@ public interface Query<T> {
* You can use this to have further control over the query. For example adding
* fetch joins.
* </p>
*
* <pre>{@code
*
* Order order =
@@ -919,10 +891,9 @@ public interface Query<T> {
/**
* Add a single Expression to the where clause returning the query.
*
* <pre>{@code
*
* List<Order> newOrders =
* List<Order> newOrders =
* ebeanServer.find(Order.class)
* .where().eq("status", Order.NEW)
* .findList();
@@ -936,7 +907,6 @@ public interface Query<T> {
* Add Expressions to the where clause with the ability to chain on the
* ExpressionList. You can use this for adding multiple expressions to the
* where clause.
*
* <pre>{@code
*
* List<Order> orders =
@@ -947,9 +917,9 @@ public interface Query<T> {
* .findList();
*
* }</pre>
*
* @see Expr
*
* @return The ExpressionList for adding expressions to.
* @see Expr
*/
ExpressionList<T> where();
@@ -984,9 +954,8 @@ public interface Query<T> {
* each customer you only want to get the new orders they placed since last
* week. In this case you can use filterMany() to filter the orders.
* </p>
*
* <pre>{@code
*
*
* List<Customer> list =
* ebeanServer.find(Customer.class)
* // .fetch("orders", new FetchConfig().lazy())
@@ -995,20 +964,17 @@ public interface Query<T> {
* .where().ilike("name", "rob%")
* .filterMany("orders").eq("status", Order.Status.NEW).gt("orderDate", lastWeek)
* .findList();
*
*
* }</pre>
*
* <p>
* Please note you have to be careful that you add expressions to the correct
* expression list - as there is one for the 'root level' and one for each
* filterMany that you have.
* </p>
*
* @param propertyName
* the name of the many property that you want to have a filter on.
*
*
* @param propertyName the name of the many property that you want to have a filter on.
* @return the expression list that you add filter expressions for the many
* to.
* to.
*/
ExpressionList<T> filterMany(String propertyName);
@@ -1021,9 +987,9 @@ public interface Query<T> {
* Note that this returns the ExpressionList (so you can add multiple
* expressions to the query in a fluent API way).
* </p>
*
* @see Expr
*
* @return The ExpressionList for adding more expressions to.
* @see Expr
*/
ExpressionList<T> having();
@@ -1037,9 +1003,8 @@ public interface Query<T> {
* than the ExpressionList. This is useful when you want to further specify
* something on the query.
* </p>
*
* @param addExpressionToHaving
* the expression to add to the having clause.
*
* @param addExpressionToHaving the expression to add to the having clause.
* @return the Query object
*/
Query<T> having(Expression addExpressionToHaving);
@@ -1151,9 +1116,8 @@ public interface Query<T> {
/**
* Set the maximum number of rows to return in the query.
*
* @param maxRows
* the maximum number of rows to return in the query.
*
* @param maxRows the maximum number of rows to return in the query.
*/
Query<T> setMaxRows(int maxRows);
@@ -1162,11 +1126,10 @@ public interface Query<T> {
* <p>
* If no property is set then the id property is used.
* </p>
*
* <pre>{@code
*
* // Assuming sku is unique for products...
*
*
* Map<?,Product> productMap =
* ebeanServer.find(Product.class)
* // use sku for keys...
@@ -1174,9 +1137,8 @@ public interface Query<T> {
* .findMap();
*
* }</pre>
*
* @param mapKey
* the property to use as keys for a map.
*
* @param mapKey the property to use as keys for a map.
*/
Query<T> setMapKey(String mapKey);
@@ -1203,7 +1165,7 @@ public interface Query<T> {
/**
* Set to true if this query should execute against the doc store.
* <p>
* When setting this you may also consider disabling lazy loading.
* When setting this you may also consider disabling lazy loading.
* </p>
*/
Query<T> setUseDocStore(boolean useDocStore);
@@ -1226,9 +1188,8 @@ public interface Query<T> {
* preparedStatement. If the timeout occurs an exception will be thrown - this
* will be a SQLException wrapped up in a PersistenceException.
* </p>
*
* @param secs
* the query timeout limit in seconds. Zero means there is no limit.
*
* @param secs the query timeout limit in seconds. Zero means there is no limit.
*/
Query<T> setTimeout(int secs);
@@ -1260,7 +1221,7 @@ public interface Query<T> {
* Return true if this query has forUpdate set.
*/
boolean isForUpdate();
/**
* Set root table alias.
*/
@@ -1274,7 +1235,7 @@ public interface Query<T> {
/**
* Set true if you want to disable lazy loading.
* <p>
* That is, once the object graph is returned further lazy loading is disabled.
* That is, once the object graph is returned further lazy loading is disabled.
* </p>
*/
Query<T> setDisableLazyLoading(boolean disableLazyLoading);
@@ -2,8 +2,6 @@ package com.avaje.ebean;
import java.io.Serializable;
import java.util.List;
import java.util.Map;
import java.util.Set;
/**
* Query object for performing native SQL queries that return SqlRow's.
+1 -2
View File
@@ -117,8 +117,7 @@ public interface SqlUpdate {
SqlUpdate setParameter(int position, Object value);
/**
* Set a null parameter via its index position. Exactly the same as
* {@link #setNull(int, int)}.
* Set a null parameter via its index position.
*/
SqlUpdate setNull(int position, int jdbcType);
@@ -74,6 +74,11 @@ public interface Transaction extends Closeable {
*/
void rollback(Throwable e) throws PersistenceException;
/**
* Mark the transaction for rollback only.
*/
void setRollbackOnly();
/**
* If the transaction is active then perform rollback. Otherwise do nothing.
*/
@@ -15,7 +15,6 @@ import java.sql.DatabaseMetaData;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Types;
import java.util.Properties;
/**
* Database platform specific settings.
@@ -202,10 +202,10 @@ public class DbMigration {
// use this flag to stop other plugins like full DDL generation
if (!online) {
DbOffline.setGenerateMigration();
if (databasePlatform == null || !platforms.isEmpty()) {
if (databasePlatform == null && !platforms.isEmpty()) {
// for multiple platform generation set the general platform
// to H2 so that it runs offline without DB connection
setPlatform(DbPlatformName.H2);
setPlatform(platforms.get(0).platform);
}
}
setDefaults();
@@ -270,17 +270,15 @@ public class MTable {
}
// compare existing columns (look for dropped columns)
int columnPosition = 0;
for (MColumn existingColumn : allColumns()) {
MColumn newColumn = newColumnMap.get(existingColumn.getName());
if (newColumn == null) {
diffDropColumn(modelDiff, existingColumn, columnPosition, newTable);
diffDropColumn(modelDiff, existingColumn);
} else if (newColumn.isDraftOnly() && !draft) {
// effectively a drop column (draft only column on a non-draft table)
logger.trace("... drop column {} from table {} as now draftOnly", newColumn.getName(), name);
diffDropColumn(modelDiff, existingColumn, columnPosition, newTable);
diffDropColumn(modelDiff, existingColumn);
}
columnPosition++;
}
if (addColumn != null) {
@@ -540,7 +538,7 @@ public class MTable {
/**
* Add a 'drop column' to the diff.
*/
private void diffDropColumn(ModelDiff modelDiff, MColumn existingColumn, int columnPosition, MTable newTable) {
private void diffDropColumn(ModelDiff modelDiff, MColumn existingColumn) {
DropColumn dropColumn = new DropColumn();
dropColumn.setTableName(name);
@@ -1,7 +1,5 @@
package com.avaje.ebean.event;
import java.util.Set;
import com.avaje.ebean.config.ServerConfig;
/**
@@ -1,7 +1,5 @@
package com.avaje.ebean.event;
import java.util.Set;
/**
* Used to enhance or override the default bean persistence mechanism.
* <p>
@@ -80,7 +80,7 @@ public class BeanChange {
* Set the bean id (for JSON tools).
*/
public void setId(Object id) {
this.id = this.id;
this.id = id;
}
/**
@@ -132,15 +132,11 @@ public class ManyWhereJoins implements Serializable {
formulaProperties.append(propertyName);
}
public boolean isHasMany() {
return formulaWithJoin || !joins.isEmpty();
}
/**
* Return true if the findRowCount query just needs the id property in the select clause.
* Return true if the query select includes a formula with join.
*/
public boolean isSelectId() {
return !formulaWithJoin;
public boolean isFormulaWithJoin() {
return formulaWithJoin;
}
/**
@@ -181,6 +181,15 @@ public class ScopeTrans implements Thread.UncaughtExceptionHandler {
return e;
}
/**
* Mark the underlying transaction as rollback only.
*/
public void setRollbackOnly() {
if (transaction != null) {
transaction.setRollbackOnly();
}
}
/**
* An Exception was caught and may or may not cause a rollback to occur.
* Returns the exception and this should be thrown by the calling code.
@@ -49,6 +49,11 @@ public class ScopedTransaction implements SpiTransaction {
scopeTrans.rollback(e);
}
@Override
public void setRollbackOnly() {
scopeTrans.setRollbackOnly();
}
@Override
public void end() throws PersistenceException {
try {
@@ -593,9 +593,15 @@ public interface SpiQuery<T> extends Query<T> {
*/
OrmQueryDetail getDetail();
TableJoin getIncludeTableJoin();
/**
* Return the extra join for a M2M lazy load.
*/
TableJoin getM2mIncludeJoin();
void setIncludeTableJoin(TableJoin includeTableJoin);
/**
* Set the extra join for a M2M lazy load.
*/
void setM2MIncludeJoin(TableJoin includeTableJoin);
/**
* Return the property used to specify keys for a map.
@@ -4,7 +4,6 @@ import java.io.Externalizable;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
@@ -1,7 +1,6 @@
package com.avaje.ebeaninternal.server.cache;
import com.avaje.ebean.BackgroundExecutor;
import com.avaje.ebean.EbeanServer;
import com.avaje.ebean.cache.ServerCache;
import com.avaje.ebean.cache.ServerCacheOptions;
import com.avaje.ebean.cache.ServerCacheStatistics;
@@ -1152,12 +1152,16 @@ public final class DefaultServer implements SpiServer, SpiEbeanServer {
}
}
public <T> int findRowCount(Query<T> query, Transaction t) {
public <T> int findCount(Query<T> query, Transaction t) {
SpiQuery<T> copy = ((SpiQuery<T>) query).copy();
return findRowCountWithCopy(copy, t);
}
public <T> int findRowCount(Query<T> query, Transaction t) {
return findCount(query, t);
}
public <T> int findRowCountWithCopy(Query<T> query, Transaction t) {
SpiOrmQueryRequest<T> request = createQueryRequest(Type.ROWCOUNT, query, t);
@@ -1213,7 +1217,7 @@ public final class DefaultServer implements SpiServer, SpiEbeanServer {
}
}
public <T> FutureRowCount<T> findFutureRowCount(Query<T> q, Transaction t) {
public <T> FutureRowCount<T> findFutureCount(Query<T> q, Transaction t) {
SpiQuery<T> copy = ((SpiQuery<T>) q).copy();
copy.setFutureFetch(true);
@@ -1228,6 +1232,10 @@ public final class DefaultServer implements SpiServer, SpiEbeanServer {
return queryFuture;
}
public <T> FutureRowCount<T> findFutureRowCount(Query<T> q, Transaction t) {
return findFutureCount(q, t);
}
public <T> FutureIds<T> findFutureIds(Query<T> query, Transaction t) {
SpiQuery<T> copy = ((SpiQuery<T>) query).copy();
@@ -1,7 +1,6 @@
package com.avaje.ebeaninternal.server.deploy;
import com.avaje.ebean.bean.EntityBean;
import com.avaje.ebean.bean.EntityBeanIntercept;
import com.avaje.ebean.bean.PersistenceContext;
import com.avaje.ebeaninternal.server.query.SqlJoinType;
@@ -1,7 +1,6 @@
package com.avaje.ebeaninternal.server.deploy;
import com.avaje.ebean.bean.EntityBean;
import com.avaje.ebean.bean.EntityBeanIntercept;
import com.avaje.ebean.bean.PersistenceContext;
import com.avaje.ebeaninternal.server.query.SqlJoinType;
@@ -357,7 +357,7 @@ public class BeanPropertyAssocMany<T> extends BeanPropertyAssoc<T> {
String tableAlias = manyToMany ? "int_." : "t0.";
if (manyToMany) {
query.setIncludeTableJoin(inverseJoin);
query.setM2MIncludeJoin(inverseJoin);
}
String rawWhere = deriveWhereParentIdSql(true, tableAlias);
String expr = descriptor.getParentIdInExpr(parentIds.size(), rawWhere);
@@ -3,7 +3,6 @@ package com.avaje.ebeaninternal.server.deploy;
import com.avaje.ebean.bean.BeanCollection;
import com.avaje.ebean.bean.BeanCollectionAdd;
import com.avaje.ebean.bean.EntityBean;
import com.avaje.ebeaninternal.api.ClassUtil;
import com.avaje.ebeaninternal.server.text.json.ReadJson;
import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.core.JsonParser;
@@ -170,9 +170,7 @@ public class AnnotationAssocManys extends AnnotationParser {
}
/**
* Return the full table name
* @param joinTable
* @return
* Return the full table name
*/
private String getFullTableName(JoinTable joinTable) {
StringBuilder sb = new StringBuilder();
@@ -4,8 +4,6 @@ import java.util.HashSet;
import java.util.Set;
import java.util.regex.Pattern;
import com.avaje.ebean.bean.EntityBean;
/**
* Contains the various ElMatcher implementations.
@@ -323,9 +323,14 @@ public class DefaultExpressionList<T> implements SpiExpressionList<T> {
return query.findFutureIds();
}
@Override
public FutureRowCount<T> findFutureCount() {
return query.findFutureCount();
}
@Override
public FutureRowCount<T> findFutureRowCount() {
return query.findFutureRowCount();
return findFutureCount();
}
@Override
@@ -338,9 +343,14 @@ public class DefaultExpressionList<T> implements SpiExpressionList<T> {
return query.findPagedList();
}
@Override
public int findCount() {
return query.findCount();
}
@Override
public int findRowCount() {
return query.findRowCount();
return findCount();
}
@Override
@@ -48,9 +48,14 @@ public class FilterExpressionList<T> extends DefaultExpressionList<T> {
return rootQuery.findFutureList();
}
@Override
public FutureRowCount<T> findFutureCount() {
return rootQuery.findFutureCount();
}
@Override
public FutureRowCount<T> findFutureRowCount() {
return rootQuery.findFutureRowCount();
return findFutureCount();
}
@Override
@@ -63,9 +68,14 @@ public class FilterExpressionList<T> extends DefaultExpressionList<T> {
return rootQuery.findMap();
}
@Override
public int findCount() {
return rootQuery.findCount();
}
@Override
public int findRowCount() {
return rootQuery.findRowCount();
return findCount();
}
@Override
@@ -360,9 +360,14 @@ class JunctionExpression<T> implements SpiJunction<T>, SpiExpression, Expression
return exprList.findFutureList();
}
@Override
public FutureRowCount<T> findFutureCount() {
return exprList.findFutureCount();
}
@Override
public FutureRowCount<T> findFutureRowCount() {
return exprList.findFutureRowCount();
return findFutureCount();
}
@Override
@@ -401,10 +406,15 @@ class JunctionExpression<T> implements SpiJunction<T>, SpiExpression, Expression
}
@Override
public int findRowCount() {
public int findCount() {
return exprList.findRowCount();
}
@Override
public int findRowCount() {
return findCount();
}
@Override
public Set<T> findSet() {
return exprList.findSet();
@@ -1,13 +1,16 @@
// Generated from /home/rob/github/avaje-ebeanorm/src/test/resources/EQL.g4 by ANTLR 4.5.3
package com.avaje.ebeaninternal.server.grammer.antlr;
import org.antlr.v4.runtime.Lexer;
import org.antlr.v4.runtime.CharStream;
import org.antlr.v4.runtime.Token;
import org.antlr.v4.runtime.TokenStream;
import org.antlr.v4.runtime.*;
import org.antlr.v4.runtime.atn.*;
import org.antlr.v4.runtime.Lexer;
import org.antlr.v4.runtime.RuntimeMetaData;
import org.antlr.v4.runtime.Vocabulary;
import org.antlr.v4.runtime.VocabularyImpl;
import org.antlr.v4.runtime.atn.ATN;
import org.antlr.v4.runtime.atn.ATNDeserializer;
import org.antlr.v4.runtime.atn.LexerATNSimulator;
import org.antlr.v4.runtime.atn.PredictionContextCache;
import org.antlr.v4.runtime.dfa.DFA;
import org.antlr.v4.runtime.misc.*;
@SuppressWarnings({"all", "warnings", "unchecked", "unused", "cast"})
public class EQLLexer extends Lexer {
@@ -1,13 +1,23 @@
// Generated from /home/rob/github/avaje-ebeanorm/src/test/resources/EQL.g4 by ANTLR 4.5.3
package com.avaje.ebeaninternal.server.grammer.antlr;
import org.antlr.v4.runtime.atn.*;
import org.antlr.v4.runtime.NoViableAltException;
import org.antlr.v4.runtime.Parser;
import org.antlr.v4.runtime.ParserRuleContext;
import org.antlr.v4.runtime.RecognitionException;
import org.antlr.v4.runtime.RuntimeMetaData;
import org.antlr.v4.runtime.TokenStream;
import org.antlr.v4.runtime.Vocabulary;
import org.antlr.v4.runtime.VocabularyImpl;
import org.antlr.v4.runtime.atn.ATN;
import org.antlr.v4.runtime.atn.ATNDeserializer;
import org.antlr.v4.runtime.atn.ParserATNSimulator;
import org.antlr.v4.runtime.atn.PredictionContextCache;
import org.antlr.v4.runtime.dfa.DFA;
import org.antlr.v4.runtime.*;
import org.antlr.v4.runtime.misc.*;
import org.antlr.v4.runtime.tree.*;
import org.antlr.v4.runtime.tree.ParseTreeListener;
import org.antlr.v4.runtime.tree.TerminalNode;
import java.util.List;
import java.util.Iterator;
import java.util.ArrayList;
@SuppressWarnings({"all", "warnings", "unchecked", "unused", "cast"})
public class EQLParser extends Parser {
@@ -1,186 +0,0 @@
#
# Used by MimeTypeHelper to find the mime types of based on file extensions.
abs=audio/x-mpeg
ai=application/postscript
aif=audio/x-aiff
aifc=audio/x-aiff
aiff=audio/x-aiff
aim=application/x-aim
art=image/x-jg
asc=text/plain
asf=video/x-ms-asf
asx=video/x-ms-asf
au=audio/basic
avi=video/x-msvideo
avx=video/x-rad-screenplay
bcpio=application/x-bcpio
bin=application/octet-stream
bmp=image/bmp
body=text/html
cdf=application/x-netcdf
cer=application/x-x509-ca-cert
class=application/java
cpio=application/x-cpio
csh=application/x-csh
css=text/css
csv=text/csv
dib=image/bmp
doc=application/msword
dtd=application/xml-dtd
dv=video/x-dv
dvi=application/x-dvi
dms=application/octet-stream
eps=application/postscript
etx=text/x-setext
exe=application/octet-stream
gif=image/gif
gtar=application/x-gtar
gz=application/x-gzip
hdf=application/x-hdf
htc=text/x-component
htm=text/html
html=text/html
hqx=application/mac-binhex40
ico=image/x-icon
ief=image/ief
jad=text/vnd.sun.j2me.app-descriptor
jar=application/java-archive
java=text/plain
jnlp=application/x-java-jnlp-file
jpe=image/jpeg
jpeg=image/jpeg
jpg=image/jpeg
js=text/javascript
jsf=text/plain
jspf=text/plain
kar=audio/midi
latex=application/x-latex
lha=application/octet-stream
lzh=application/octet-stream
m3u=audio/x-mpegurl
mac=image/x-macpaint
man=application/x-troff-man
mathml=application/mathml+xml
me=application/x-troff-me
mid=audio/midi
midi=audio/midi
mif=application/vnd.mif
mov=video/quicktime
movie=video/x-sgi-movie
mp1=audio/x-mpeg
mp2=audio/mpeg
mp3=audio/mpeg
mpa=audio/x-mpeg
mpe=video/mpeg
mpeg=video/mpeg
mpega=audio/x-mpeg
mpga=audio/mpeg
mpg=video/mpeg
mpv2=video/mpeg2
ms=application/x-troff-ms
nc=application/x-netcdf
oda=application/oda
ogg=application/ogg
pbm=image/x-portable-bitmap
pct=image/pict
pdf=application/pdf
pgm=image/x-portable-graymap
pic=image/pict
pict=image/pict
pls=audio/x-scpls
png=image/png
pnm=image/x-portable-anymap
pnt=image/x-macpaint
ppm=image/x-portable-pixmap
pps=application/vnd.ms-powerpoint
ppt=application/vnd.ms-powerpoint
ps=application/postscript
psd=image/x-photoshop
qt=video/quicktime
qti=image/x-quicktime
qtif=image/x-quicktime
ra=audio/x-realaudio
ram=audio/x-pn-realaudio
ras=image/x-cmu-raster
rdf=application/rdf+xml
rgb=image/x-rgb
rpm=audio/x-pn-realaudio-plugin
rm=application/vnd.rn-realmedia
roff=application/x-troff
rtf=text/rtf
rtx=text/richtext
sh=application/x-sh
shar=application/x-shar
shtml=text/x-server-parsed-html
sgml=text/sgml
sgm=text/sgml
smf=audio/x-midi
sit=application/x-stuffit
snd=audio/basic
src=application/x-wais-source
sv4cpio=application/x-sv4cpio
sv4crc=application/x-sv4crc
svg=image/svg+xml
svgz=image/svg
swf=application/x-shockwave-flash
t=application/x-troff
tar=application/x-tar
tcl=application/x-tcl
tex=application/x-tex
texi=application/x-texinfo
texinfo=application/x-texinfo
tif=image/tiff
tiff=image/tiff
tr=application/x-troff
tsv=text/tab-separated-values
txt=text/plain
ulw=audio/basic
ustar=application/x-ustar
vcd=application/x-cdlink
vrml=model/vrml
vsd=application/x-visio
vxml=application/voicexml+xml
wav=audio/x-wav
wbmp=image/vnd.wap.wbmp
wml=text/vnd.wap.wml
wmlc=application/vnd.wap.wmlc
wmls=text/vnd.wap.wmlscript
wmlscriptc=application/vnd.wap.wmlscriptc
wrl=model/vrml
xbm=image/x-xbitmap
xht=application/xhtml+xml
xhtml=application/xhtml+xml
xls=application/vnd.ms-excel
xml=application/xml
xpm=image/x-xpixmap
xsl=application/xml
xslt=application/xslt+xml
xul=application/vnd.mozilla.xul+xml
xwd=image/x-xwindowdump
Z=application/x-compress
z=application/x-compress
zip=application/zip
@@ -56,11 +56,9 @@ public abstract class DLoadBaseContext {
int queryBatchSize = queryProps.getQueryFetchBatch();
if (queryBatchSize == -1) {
// not eager query fetch, just lazy loading
return batchSize;
} else if (queryBatchSize == 0) {
// default query fetch batch size is 100
return 100;
} else {
@@ -25,9 +25,7 @@ public class DLoadBeanContext extends DLoadBaseContext implements LoadBeanContex
private LoadBuffer currentBuffer;
public DLoadBeanContext(DLoadContext parent, BeanDescriptor<?> desc, String path, int defaultBatchSize, OrmQueryProperties queryProps) {
super(parent, desc, path, defaultBatchSize, queryProps);
// bufferList only required when using query joins (queryFetch)
this.bufferList = (!queryFetch) ? null : new ArrayList<DLoadBeanContext.LoadBuffer>();
this.currentBuffer = createBuffer(firstBatchSize);
@@ -284,20 +284,23 @@ public class DLoadContext implements LoadContext {
private void registerSecondaryNode(boolean many, OrmQueryProperties props) {
String path = props.getPath();
int lazyJoinBatch = props.getLazyFetchBatch();
int batchSize = lazyJoinBatch > 0 ? lazyJoinBatch : defaultBatchSize;
if (many) {
DLoadManyContext manyContext = createManyContext(path, batchSize, props);
manyMap.put(path, manyContext);
int batchSize;
if (props.isQueryFetch()) {
batchSize = 100;
} else {
DLoadBeanContext beanContext = createBeanContext(path, batchSize, props);
beanMap.put(path, beanContext);
int lazyJoinBatch = props.getLazyFetchBatch();
batchSize = lazyJoinBatch > 0 ? lazyJoinBatch : defaultBatchSize;
}
String path = props.getPath();
if (many) {
manyMap.put(path, createManyContext(path, batchSize, props));
} else {
beanMap.put(path, createBeanContext(path, batchSize, props));
}
}
private DLoadManyContext getManyContext(String path) {
protected DLoadManyContext getManyContext(String path) {
if (path == null) {
throw new RuntimeException("path is null?");
}
@@ -146,7 +146,7 @@ public final class BatchControl {
/**
* Entity Bean insert, update or delete. This will either execute the request
* immediately or queue it for batch processing later. The queue is flushed
* immediately or queue it for batch processing later. The queue is flushedIntercept
* according to the depth (object graph depth).
*/
public int executeOrQueue(PersistRequestBean<?> request, boolean batch) {
@@ -10,6 +10,6 @@ public class DmlUtil {
* Return true if the value is null or a Numeric 0 (for primitive int's and long's) or Option empty.
*/
public static boolean isNullOrZero(Object value) {
return value == null || value instanceof Number && ((Number) value).longValue() == 0l;
return value == null || value instanceof Number && ((Number) value).longValue() == 0L;
}
}
@@ -5,7 +5,6 @@ import com.avaje.ebeaninternal.api.SpiTransaction;
import com.avaje.ebeaninternal.api.SpiUpdate;
import com.avaje.ebeaninternal.server.core.PersistRequestOrmUpdate;
import com.avaje.ebeaninternal.server.deploy.BeanDescriptor;
import com.avaje.ebeaninternal.server.type.DataBind;
import com.avaje.ebeaninternal.server.util.BindParamsParser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -5,7 +5,6 @@ import com.avaje.ebeaninternal.api.SpiSqlUpdate;
import com.avaje.ebeaninternal.api.SpiTransaction;
import com.avaje.ebeaninternal.server.core.PersistRequestUpdateSql;
import com.avaje.ebeaninternal.server.core.PersistRequestUpdateSql.SqlType;
import com.avaje.ebeaninternal.server.type.DataBind;
import com.avaje.ebeaninternal.server.util.BindParamsParser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -1,12 +1,11 @@
package com.avaje.ebeaninternal.server.persist.dmlbind;
import java.sql.SQLException;
import com.avaje.ebean.bean.EntityBean;
import com.avaje.ebeaninternal.api.DerivedRelationshipData;
import com.avaje.ebeaninternal.server.core.PersistRequestBean;
import com.avaje.ebeaninternal.server.deploy.BeanProperty;
import java.sql.SQLException;
/**
* Request object passed to bindables.
*/
@@ -123,7 +123,7 @@ public class CQueryBuilder {
if (!sqlTree.isIncludeJoins()) {
// simple - delete from table ...
return aliasStrip(buildSql("delete", request, predicates, sqlTree).getSql());
return aliasStrip(buildSql("delete", request, predicates, sqlTree).getSql());
}
// wrap as - delete from table where id in (select id ...)
String sql = buildSql(null, request, predicates, sqlTree).getSql();
@@ -135,11 +135,11 @@ public class CQueryBuilder {
private <T> String buildUpdateSql(OrmQueryRequest<T> request, String rootTableAlias, CQueryPredicates predicates, SqlTree sqlTree) {
String updateClause = "update "+request.getBeanDescriptor().getBaseTable()+" set "+predicates.getDbUpdateClause();
String updateClause = "update " + request.getBeanDescriptor().getBaseTable() + " set " + predicates.getDbUpdateClause();
if (!sqlTree.isIncludeJoins()) {
// simple - update table set ... where ...
return aliasStrip(buildSqlUpdate(updateClause, request, predicates, sqlTree).getSql());
return aliasStrip(buildSqlUpdate(updateClause, request, predicates, sqlTree).getSql());
}
// wrap as - update table set ... where id in (select id ...)
String sql = buildSqlUpdate(null, request, predicates, sqlTree).getSql();
@@ -161,7 +161,7 @@ public class CQueryBuilder {
* Replace the root table alias.
*/
private String aliasReplace(String sql, String replaceWith) {
sql = StringHelper.replaceString(sql, "${RTA}.", replaceWith+".");
sql = StringHelper.replaceString(sql, "${RTA}.", replaceWith + ".");
return StringHelper.replaceString(sql, "${RTA}", replaceWith);
}
@@ -225,20 +225,10 @@ public class CQueryBuilder {
ManyWhereJoins manyWhereJoins = query.getManyWhereJoins();
boolean hasMany = manyWhereJoins.isHasMany();
if (manyWhereJoins.isSelectId()) {
// just select the id property
query.setSelectId();
} else {
// select the id and the required formula properties
if (manyWhereJoins.isFormulaWithJoin()) {
query.select(manyWhereJoins.getFormulaProperties());
}
String sqlSelect = "select count(*)";
if (hasMany) {
// need to count distinct id's ...
query.setSqlDistinct(true);
sqlSelect = null;
} else {
query.setSelectId();
}
CQueryPredicates predicates = new CQueryPredicates(binder, request);
@@ -257,6 +247,14 @@ public class CQueryBuilder {
sqlTree.addSoftDeletePredicate(query);
}
boolean hasMany = sqlTree.hasMany();
String sqlSelect = "select count(*)";
if (hasMany) {
// need to count distinct id's ...
query.setSqlDistinct(true);
sqlSelect = null;
}
SqlLimitResponse s = buildSql(sqlSelect, request, predicates, sqlTree);
String sql = s.getSql();
if (hasMany || query.isRawSql()) {
@@ -488,7 +486,7 @@ public class CQueryBuilder {
}
if (stripAlias) {
// strip the table alias for use in update statement
idSql = StringHelper.replaceString(idSql, "t0.","");
idSql = StringHelper.replaceString(idSql, "t0.", "");
}
sb.append(idSql).append(" ");
hasWhere = true;
@@ -300,9 +300,10 @@ public class CQueryEngine {
SpiQuery<T> query = request.getQuery();
if (query.getMaxRows() > 1 || query.getFirstRow() > 0) {
if (!query.isDistinct() && (query.getMaxRows() > 1 || query.getFirstRow() > 0)) {
// deemed to be a be a paging query - check that the order by contains
// the id property to ensure unique row ordering for predicable paging
// but only in case, this is not a distinct query
request.getBeanDescriptor().appendOrderById(query);
}
@@ -43,19 +43,27 @@ public class LimitOffsetPagedList<T> implements PagedList<T> {
this.firstRow = query.getFirstRow();
}
public void loadRowCount() {
getFutureRowCount();
public void loadCount() {
getFutureCount();
}
public Future<Integer> getFutureRowCount() {
public void loadRowCount() {
loadCount();
}
public Future<Integer> getFutureCount() {
synchronized (monitor) {
if (futureRowCount == null) {
futureRowCount = server.findFutureRowCount(query, null);
futureRowCount = server.findFutureCount(query, null);
}
return futureRowCount;
}
}
public Future<Integer> getFutureRowCount() {
return getFutureCount();
}
public List<T> getList() {
synchronized (monitor) {
if (list == null) {
@@ -67,7 +75,7 @@ public class LimitOffsetPagedList<T> implements PagedList<T> {
public int getTotalPageCount() {
int rowCount = getTotalRowCount();
int rowCount = getTotalCount();
if (rowCount == 0) {
return 0;
} else {
@@ -75,7 +83,7 @@ public class LimitOffsetPagedList<T> implements PagedList<T> {
}
}
public int getTotalRowCount() {
public int getTotalCount() {
synchronized (monitor) {
if (futureRowCount != null) {
try {
@@ -89,13 +97,17 @@ public class LimitOffsetPagedList<T> implements PagedList<T> {
if (foregroundTotalRowCount > -1) return foregroundTotalRowCount;
// just using foreground thread
foregroundTotalRowCount = server.findRowCount(query, null);
foregroundTotalRowCount = server.findCount(query, null);
return foregroundTotalRowCount;
}
}
public int getTotalRowCount() {
return getTotalCount();
}
public boolean hasNext() {
return (firstRow + maxRows) < getTotalRowCount();
return (firstRow + maxRows) < getTotalCount();
}
public boolean hasPrev() {
@@ -110,7 +122,7 @@ public class LimitOffsetPagedList<T> implements PagedList<T> {
int first = firstRow + 1;
int last = firstRow + getList().size();
int total = getTotalRowCount();
int total = getTotalCount();
return first + to + last + of + total;
}
@@ -60,21 +60,6 @@ public class SqlTree {
this.includeJoins = includeJoins;
}
/**
* Construct for RawSql.
*/
public SqlTree(String summary, SqlTreeNode rootNode) {
this.summary = summary;
this.rootNode = rootNode;
this.selectSql = null;
this.fromSql = null;
this.inheritanceWhereSql = null;
this.encryptedProps = null;
this.manyProperty = null;
this.includes = null;
this.includeJoins = false; //not valid for rawSql
}
/**
* Return true if the query includes joins (not valid for rawSql).
*/
@@ -153,4 +138,10 @@ public class SqlTree {
return encryptedProps;
}
/**
* Return true if the query has a many join.
*/
public boolean hasMany() {
return manyProperty != null || rootNode.hasMany();
}
}
@@ -106,7 +106,7 @@ public class SqlTreeBuilder {
this.query = request.getQuery();
this.disableLazyLoad = query.isDisableLazyLoading();
this.subQuery = Type.SUBQUERY.equals(query.getType()) || Type.ID_LIST.equals(query.getType());
this.includeJoin = query.getIncludeTableJoin();
this.includeJoin = query.getM2mIncludeJoin();
this.manyWhereJoins = query.getManyWhereJoins();
this.queryDetail = query.getDetail();
@@ -57,4 +57,9 @@ public interface SqlTreeNode {
* Load a version of a @History bean with effective dates.
*/
<T> Version<T> loadVersion(DbReadContext ctx) throws SQLException;
/**
* Return true if the query has a many join.
*/
boolean hasMany();
}
@@ -1,11 +1,5 @@
package com.avaje.ebeaninternal.server.query;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.avaje.ebean.Version;
import com.avaje.ebean.bean.BeanCollection;
import com.avaje.ebean.bean.EntityBean;
@@ -24,6 +18,12 @@ import com.avaje.ebeaninternal.server.deploy.TableJoin;
import com.avaje.ebeaninternal.server.deploy.id.IdBinder;
import com.avaje.ebeaninternal.server.lib.util.StringHelper;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* Normal bean included in the query.
*/
@@ -570,4 +570,14 @@ public class SqlTreeNodeBean implements SqlTreeNode {
return true;
}
@Override
public boolean hasMany() {
for (SqlTreeNode child : children) {
if (child.hasMany()) {
return true;
}
}
return false;
}
}
@@ -146,4 +146,9 @@ public class SqlTreeNodeExtraJoin implements SqlTreeNode {
public <T> Version<T> loadVersion(DbReadContext ctx) throws SQLException {
return null;
}
@Override
public boolean hasMany() {
return manyJoin;
}
}
@@ -1,13 +1,13 @@
package com.avaje.ebeaninternal.server.query;
import java.sql.SQLException;
import java.util.List;
import com.avaje.ebean.bean.EntityBean;
import com.avaje.ebeaninternal.server.deploy.BeanPropertyAssocMany;
import com.avaje.ebeaninternal.server.deploy.DbReadContext;
import com.avaje.ebeaninternal.server.deploy.DbSqlContext;
import java.sql.SQLException;
import java.util.List;
public final class SqlTreeNodeManyRoot extends SqlTreeNodeBean {
private final BeanPropertyAssocMany<?> manyProp;
@@ -38,4 +38,8 @@ public final class SqlTreeNodeManyRoot extends SqlTreeNodeBean {
super.appendFrom(ctx, joinType.autoToOuter());
}
@Override
public boolean hasMany() {
return true;
}
}
@@ -109,4 +109,9 @@ public class SqlTreeNodeManyWhereJoin implements SqlTreeNode {
// nothing to do here
return null;
}
@Override
public boolean hasMany() {
return true;
}
}
@@ -55,7 +55,7 @@ public class DefaultOrmQuery<T> implements SpiQuery<T> {
* For lazy loading of ManyToMany we need to add a join to the intersection table. This is that
* join to the intersection table.
*/
private TableJoin includeTableJoin;
private TableJoin m2mIncludeJoin;
private ProfilingListener profilingListener;
@@ -571,7 +571,7 @@ public class DefaultOrmQuery<T> implements SpiQuery<T> {
public DefaultOrmQuery<T> copy(EbeanServer server) {
DefaultOrmQuery<T> copy = new DefaultOrmQuery<T>(beanDescriptor, server, expressionFactory);
copy.includeTableJoin = includeTableJoin;
copy.m2mIncludeJoin = m2mIncludeJoin;
copy.profilingListener = profilingListener;
// copy.query = query;
@@ -846,7 +846,7 @@ public class DefaultOrmQuery<T> implements SpiQuery<T> {
*/
CQueryPlanKey createQueryPlanKey() {
queryPlanKey = new OrmQueryPlanKey(includeTableJoin, type, detail, maxRows, firstRow,
queryPlanKey = new OrmQueryPlanKey(m2mIncludeJoin, type, detail, maxRows, firstRow,
disableLazyLoading, orderBy,
distinct, sqlDistinct, mapKey, id, bindParams, whereExpressions, havingExpressions,
temporalMode, forUpdate, rootTableAlias, rawSql, updateProperties);
@@ -1048,11 +1048,16 @@ public class DefaultOrmQuery<T> implements SpiQuery<T> {
}
@Override
public int findRowCount() {
public 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)
return server.findRowCount(this, null);
return server.findCount(this, null);
}
@Override
public int findRowCount() {
return findCount();
}
@Override
@@ -1119,9 +1124,14 @@ public class DefaultOrmQuery<T> implements SpiQuery<T> {
return server.findFutureList(this, null);
}
@Override
public FutureRowCount<T> findFutureCount() {
return server.findFutureCount(this, null);
}
@Override
public FutureRowCount<T> findFutureRowCount() {
return server.findFutureRowCount(this, null);
return findFutureCount();
}
@Override
@@ -1254,14 +1264,13 @@ public class DefaultOrmQuery<T> implements SpiQuery<T> {
return "Query [" + whereExpressions + "]";
}
@Override
public TableJoin getIncludeTableJoin() {
return includeTableJoin;
public TableJoin getM2mIncludeJoin() {
return m2mIncludeJoin;
}
@Override
public void setIncludeTableJoin(TableJoin includeTableJoin) {
this.includeTableJoin = includeTableJoin;
public void setM2MIncludeJoin(TableJoin m2mIncludeJoin) {
this.m2mIncludeJoin = m2mIncludeJoin;
}
@Override
@@ -14,9 +14,8 @@ import com.avaje.ebeaninternal.server.deploy.TableJoin;
*/
public class OrmQueryPlanKey implements CQueryPlanKey {
private final TableJoin includeTableJoin;
private final String m2mIncludeTable;
private final String orderByAsSting;
private final OrmQueryDetail detail;
private final SpiExpression where;
private final SpiExpression having;
private final RawSql.Key rawSqlKey;
@@ -36,11 +35,10 @@ public class OrmQueryPlanKey implements CQueryPlanKey {
private final int planHash;
private final int bindCount;
public OrmQueryPlanKey(TableJoin includeTableJoin, SpiQuery.Type type, OrmQueryDetail detail, int maxRows, int firstRow, boolean disableLazyLoading, OrderBy<?> orderBy, boolean distinct, boolean sqlDistinct, String mapKey, Object id, BindParams bindParams, SpiExpression whereExpressions, SpiExpression havingExpressions, SpiQuery.TemporalMode temporalMode, boolean forUpdate, String rootTableAlias, RawSql rawSql, OrmUpdateProperties updateProperties) {
public OrmQueryPlanKey(TableJoin m2mIncludeTable, SpiQuery.Type type, OrmQueryDetail detail, int maxRows, int firstRow, boolean disableLazyLoading, OrderBy<?> orderBy, boolean distinct, boolean sqlDistinct, String mapKey, Object id, BindParams bindParams, SpiExpression whereExpressions, SpiExpression havingExpressions, SpiQuery.TemporalMode temporalMode, boolean forUpdate, String rootTableAlias, RawSql rawSql, OrmUpdateProperties updateProperties) {
this.includeTableJoin = includeTableJoin;
this.m2mIncludeTable = m2mIncludeTable == null ? null : m2mIncludeTable.getTable();
this.type = type;
this.detail = detail;
this.maxRows = maxRows;
this.firstRow = firstRow;
this.disableLazyLoading = disableLazyLoading;
@@ -69,7 +67,7 @@ public class OrmQueryPlanKey implements CQueryPlanKey {
builder.add(hasIdValue);
builder.add(temporalMode);
builder.add(rawSqlKey == null ? 0 : rawSqlKey.hashCode());
builder.add(includeTableJoin != null ? includeTableJoin.queryHash() : 0);
builder.add(this.m2mIncludeTable);
builder.add(rootTableAlias);
if (detail != null) {
@@ -120,15 +118,12 @@ public class OrmQueryPlanKey implements CQueryPlanKey {
if (hasIdValue != that.hasIdValue) return false;
if (type != that.type) return false;
if (temporalMode != that.temporalMode) return false;
if (includeTableJoin != null ? !includeTableJoin.equals(that.includeTableJoin) : that.includeTableJoin != null) return false;
if (m2mIncludeTable != null ? !m2mIncludeTable.equals(that.m2mIncludeTable) : that.m2mIncludeTable != null) return false;
if (orderByAsSting != null ? !orderByAsSting.equals(that.orderByAsSting) : that.orderByAsSting != null) return false;
if (where != null ? !where.isSameByPlan(that.where) : that.where != null) return false;
if (having != null ? !having.isSameByPlan(that.having) : that.having != null) return false;
if (updateProperties != null ? !updateProperties.isSameByPlan(that.updateProperties) : that.updateProperties != null) return false;
if (rawSqlKey != null ? !rawSqlKey.equals(that.rawSqlKey) : that.rawSqlKey != null) return false;
// if (detail != null ? !detail.equals(that.detail) : that.detail != null) return false;
if (mapKey != null ? !mapKey.equals(that.mapKey) : that.mapKey != null) return false;
return rootTableAlias != null ? rootTableAlias.equals(that.rootTableAlias) : that.rootTableAlias == null;
}
@@ -1,7 +1,6 @@
package com.avaje.ebeaninternal.server.transaction;
import com.avaje.ebean.bean.PersistenceContext;
import com.avaje.ebean.bean.PersistenceContextUtil;
import com.avaje.ebeaninternal.api.Monitor;
import java.util.HashMap;
@@ -4,8 +4,7 @@ import com.avaje.ebeaninternal.api.SpiTransaction;
import com.avaje.ebeaninternal.server.transaction.TransactionMap.State;
/**
* Used by EbeanMgr to store its Transactions in a ThreadLocal. This way the
* transaction objects don't have to passed around.
* Used to store Transactions in a ThreadLocal.
*/
public final class DefaultTransactionThreadLocal {
@@ -99,7 +98,7 @@ public final class DefaultTransactionThreadLocal {
* block.
* <p>
* <pre>
* Ebean.beingTransaction();
* Ebean.beginTransaction();
* try {
* // ... perform some actions in a single transaction
*
@@ -110,8 +109,6 @@ public final class DefaultTransactionThreadLocal {
* Ebean.endTransaction();
* }
* </pre>
* <p>
* </p>
*/
public static void end(String serverName) {
@@ -66,6 +66,8 @@ public class JdbcTransaction implements SpiTransaction {
*/
protected boolean active;
protected boolean rollbackOnly;
/**
* The underlying Connection.
*/
@@ -903,6 +905,10 @@ public class JdbcTransaction implements SpiTransaction {
*/
@Override
public void commit() throws RollbackException {
if (rollbackOnly) {
rollback();
return;
}
if (!isActive()) {
throw new IllegalStateException(illegalStateMessage);
}
@@ -945,6 +951,14 @@ public class JdbcTransaction implements SpiTransaction {
}
}
/**
* Mark the transaction as rollback only.
*/
@Override
public void setRollbackOnly() {
this.rollbackOnly = true;
}
/**
* Rollback the transaction.
*/
@@ -344,12 +344,12 @@ public class TransactionManager {
public void notifyOfRollback(SpiTransaction transaction, Throwable cause) {
try {
if (TXN_LOGGER.isInfoEnabled()) {
if (TXN_LOGGER.isDebugEnabled()) {
String msg = transaction.getLogPrefix() + "Rollback";
if (cause != null) {
msg += " error: " + formatThrowable(cause);
}
TXN_LOGGER.info(msg);
TXN_LOGGER.debug(msg);
}
for (TransactionEventListener listener : transactionEventListeners) {
@@ -209,7 +209,7 @@ public final class DefaultTypeManager implements TypeManager, KnownImmutable {
initialiseJacksonTypes(config);
if (bootupClasses != null) {
initialiseCustomScalarTypes(jsonDateTime, bootupClasses, config);
initialiseCustomScalarTypes(jsonDateTime, bootupClasses);
initialiseScalarConverters(bootupClasses);
initialiseCompoundTypes(bootupClasses);
}
@@ -682,7 +682,7 @@ public final class DefaultTypeManager implements TypeManager, KnownImmutable {
* interface and register it with this TypeManager.
* </p>
*/
protected void initialiseCustomScalarTypes(JsonConfig.DateTime mode, BootupClasses bootupClasses, ServerConfig serverConfig) {
protected void initialiseCustomScalarTypes(JsonConfig.DateTime mode, BootupClasses bootupClasses) {
ScalarTypeLongToTimestamp longToTimestamp = new ScalarTypeLongToTimestamp(mode);
@@ -165,11 +165,7 @@ public class ImmutableMetaFactory {
if (methods[i].getParameterTypes().length == 0) {
// could be a getter
String methName = methods[i].getName();
if (methName.equals("hashCode")) {
} else if (methName.equals("toString")) {
} else {
if (!methName.equals("hashCode") && !methName.equals("toString")) {
Class<?> returnType = methods[i].getReturnType();
if (paramType.equals(returnType)) {
return methods[i];
@@ -1,9 +1,8 @@
package com.avaje.ebeanservice.docstore.api.support;
import com.avaje.ebean.text.PathProperties;
import com.avaje.ebean.FetchPath;
import com.avaje.ebean.text.PathProperties;
import com.avaje.ebeaninternal.server.deploy.BeanDescriptor;
import com.avaje.ebeaninternal.server.deploy.BeanProperty;
import com.avaje.ebeaninternal.server.deploy.BeanPropertyAssoc;
import java.util.HashMap;
@@ -13,7 +13,7 @@ public class BaseTestCase {
static {
logger.debug("... preStart");
if (!AgentLoader.loadAgentFromClasspath("avaje-ebeanorm-agent","debug=0;packages=com.avaje.tests.**,org.avaje.test.**")) {
if (!AgentLoader.loadAgentFromClasspath("avaje-ebeanorm-agent","debug=1;packages=com.avaje.tests,org.avaje.test")) {
logger.info("avaje-ebeanorm-agent not found in classpath - not dynamically loaded");
}
}
@@ -114,8 +114,6 @@ public class EbeanServer_deleteAllByIdTest {
}
private EBasicVer bean(String name) {
EBasicVer bean = new EBasicVer();
bean.setName(name);
return bean;
return new EBasicVer(name);
}
}
@@ -85,8 +85,6 @@ public class EbeanServer_deleteByIdTest {
}
private EBasicVer bean(String name) {
EBasicVer bean = new EBasicVer();
bean.setName(name);
return bean;
return new EBasicVer(name);
}
}
@@ -48,8 +48,6 @@ public class EbeanServer_deleteTest {
}
private EBasicVer bean(String name) {
EBasicVer bean = new EBasicVer();
bean.setName(name);
return bean;
return new EBasicVer(name);
}
}
@@ -123,8 +123,6 @@ public class EbeanServer_saveAllTest extends BaseTestCase {
}
private EBasicVer bean(String name) {
EBasicVer bean = new EBasicVer();
bean.setName(name);
return bean;
return new EBasicVer(name);
}
}
@@ -24,8 +24,7 @@ public class BeanPersistControllerTest {
EbeanServer ebeanServer = getEbeanServer(continuePersistingAdapter);
EBasicVer bean = new EBasicVer();
bean.setName("testController");
EBasicVer bean = new EBasicVer("testController");
ebeanServer.save(bean);
assertThat(continuePersistingAdapter.methodsCalled).hasSize(2);
@@ -49,8 +48,7 @@ public class BeanPersistControllerTest {
EbeanServer ebeanServer = getEbeanServer(stopPersistingAdapter);
EBasicVer bean = new EBasicVer();
bean.setName("testController");
EBasicVer bean = new EBasicVer("testController");
ebeanServer.save(bean);
assertThat(stopPersistingAdapter.methodsCalled).hasSize(1);
@@ -24,8 +24,7 @@ public class BeanPostLoadTest extends BaseTestCase {
EbeanServer ebeanServer = getEbeanServer();
EBasicVer bean = new EBasicVer();
bean.setName("testPostLoad");
EBasicVer bean = new EBasicVer("testPostLoad");
bean.setDescription("someDescription");
bean.setOther("other");
@@ -455,6 +455,11 @@ public class TDSpiEbeanServer implements SpiEbeanServer {
return null;
}
@Override
public <T> int findCount(Query<T> query, Transaction transaction) {
return 0;
}
@Override
public <T> int findRowCount(Query<T> query, Transaction transaction) {
return 0;
@@ -480,6 +485,11 @@ public class TDSpiEbeanServer implements SpiEbeanServer {
return null;
}
@Override
public <T> FutureRowCount<T> findFutureCount(Query<T> query, Transaction transaction) {
return null;
}
@Override
public <T> FutureRowCount<T> findFutureRowCount(Query<T> query, Transaction transaction) {
return null;
@@ -54,7 +54,7 @@ public class TestDataSourceMaxWithEntity extends BaseTestCase {
public void run() {
server.find(Customer.class).findRowCount();
server.find(Customer.class).findCount();
try {
System.out.println(position+" sleep " + sleepMillis);
Thread.sleep(sleepMillis);
@@ -77,4 +77,19 @@ public class DLoadContextTest extends BaseTestCase {
assertThat(customer.secondaryBatchSize).isEqualTo(5);
}
@Test
public void construct_when_fetch_expect_100_100_batchSize() {
// the fetch is converted to a query join due to the maxRows
OrmQueryRequest<Order> queryRequest = queryRequest(query().fetch("details").setMaxRows(100)) ;
queryRequest.initTransIfRequired();
queryRequest.endTransIfRequired();
DLoadContext graphContext = (DLoadContext)queryRequest.getGraphContext();
DLoadManyContext details = graphContext.getManyContext("details");
assertThat(details.firstBatchSize).isEqualTo(100);
assertThat(details.secondaryBatchSize).isEqualTo(100);
}
}
@@ -29,7 +29,7 @@ public class TestFutureRowCountErrorHandling extends BaseTestCase {
.where().eq("doesNotExist", "this will fail")
.query();
FutureRowCount<Customer> futureRowCount = server.findFutureRowCount(query, null);
FutureRowCount<Customer> futureRowCount = server.findFutureCount(query, null);
QueryFutureRowCount<Customer> internalRowCount = (QueryFutureRowCount<Customer>)futureRowCount;
Transaction t = internalRowCount.getTransaction();
@@ -30,7 +30,7 @@ public class OrmQueryPlanKeyTest extends BaseExpressionTest {
@Test
public void equals_when_diffTableJoinNull() {
TableJoin tableJoin = tableJoin("id", "customer_id");
TableJoin tableJoin = tableJoin("table", "id", "customer_id");
OrmQueryPlanKey key1 = new OrmQueryPlanKey(tableJoin, SpiQuery.Type.BEAN, null, 0, 0, false, null, false, false, null, null, null, null, null, SpiQuery.TemporalMode.CURRENT, false, null, null, null);
OrmQueryPlanKey key2 = new OrmQueryPlanKey(null, SpiQuery.Type.BEAN, null, 0, 0, false, null, false, false, null, null, null, null, null, SpiQuery.TemporalMode.CURRENT, false, null, null, null);
@@ -41,8 +41,8 @@ public class OrmQueryPlanKeyTest extends BaseExpressionTest {
@Test
public void equals_when_diffTableJoin() {
TableJoin tableJoin1 = tableJoin("id", "customer_id");
TableJoin tableJoin2 = tableJoin("id", "other_customer_id");
TableJoin tableJoin1 = tableJoin("one", "id", "customer_id");
TableJoin tableJoin2 = tableJoin("two", "id", "customer_id");
OrmQueryPlanKey key1 = new OrmQueryPlanKey(tableJoin1, SpiQuery.Type.BEAN, null, 0, 0, false, null, false, false, null, null, null, null, null, SpiQuery.TemporalMode.CURRENT, false, null, null, null);
OrmQueryPlanKey key2 = new OrmQueryPlanKey(tableJoin2, SpiQuery.Type.BEAN, null, 0, 0, false, null, false, false, null, null, null, null, null, SpiQuery.TemporalMode.CURRENT, false, null, null, null);
@@ -53,8 +53,8 @@ public class OrmQueryPlanKeyTest extends BaseExpressionTest {
@Test
public void equals_when_sameTableJoin() {
TableJoin tableJoin1 = tableJoin("id", "customer_id");
TableJoin tableJoin2 = tableJoin("id", "customer_id");
TableJoin tableJoin1 = tableJoin("one", "id", "customer_id");
TableJoin tableJoin2 = tableJoin("one", "id", "customer_id");
OrmQueryPlanKey key1 = new OrmQueryPlanKey(tableJoin1, SpiQuery.Type.BEAN, null, 0, 0, false, null, false, false, null, null, null, null, null, SpiQuery.TemporalMode.CURRENT, false, null, null, null);
OrmQueryPlanKey key2 = new OrmQueryPlanKey(tableJoin2, SpiQuery.Type.BEAN, null, 0, 0, false, null, false, false, null, null, null, null, null, SpiQuery.TemporalMode.CURRENT, false, null, null, null);
@@ -63,9 +63,9 @@ public class OrmQueryPlanKeyTest extends BaseExpressionTest {
}
@NotNull
private TableJoin tableJoin(String col1, String col2) {
private TableJoin tableJoin(String table, String col1, String col2) {
DeployTableJoin deploy = new DeployTableJoin();
deploy.setTable("myTable");
deploy.setTable(table);
deploy.addJoinColumn(new DeployTableJoinColumn(col1, col2));
return new TableJoin(deploy);
}
@@ -147,7 +147,7 @@ public class MainDbBoolean {
.setAutoTune(false)
.order("id");
int rc = query.findRowCount();
int rc = query.findCount();
Assert.assertTrue(rc > 0);
@@ -14,8 +14,7 @@ public class TestIUDVanilla extends BaseTestCase {
@Test
public void test() {
EBasicVer e0 = new EBasicVer();
e0.setName("vanilla");
EBasicVer e0 = new EBasicVer("vanilla");
Ebean.save(e0);
@@ -39,9 +38,8 @@ public class TestIUDVanilla extends BaseTestCase {
e2.setName("forcedUpdate");
Ebean.update(e2);
EBasicVer e3 = new EBasicVer();
EBasicVer e3 = new EBasicVer("ModNoOCC");
e3.setId(e0.getId());
e3.setName("ModNoOCC");
Ebean.update(e3);
@@ -25,9 +25,8 @@ public class TestLogTransLogOnError extends BaseTestCase {
Ebean.find(Customer.class).findList();
Ebean.find(Order.class).where().gt("id", 1).findList();
EBasicVer newBean = new EBasicVer();
EBasicVer newBean = new EBasicVer("aName");
newBean.setDescription("something");
newBean.setName("aName");
// Ebean.save(newBean);
@@ -55,13 +54,12 @@ public class TestLogTransLogOnError extends BaseTestCase {
try {
Ebean.find(Customer.class).findList();
EBasicVer newBean = new EBasicVer();
EBasicVer newBean = new EBasicVer("aName");
newBean
.setDescription("something sdfjksdjflsjdflsjdflksjdfkjd fsjdfkjsdkfjsdkfjskdjfskjdf"
+ " sjdf sdjflksjdfkjsdlfkjsdkfjs ksjdfksjdlfjsldf something sdfjksdjflsjdflsjdflksjdfkjd"
+ "fsjdfkjsdkfjsdkfjskdjfskjdf sjdf sdjflksjdfkjsdlfkjsdkfjs ksjdfksjdlfjsldf something s"
+ "dfjksdjflsjdflsjdflksjdfkjd fsjdfkjsdkfjsdkfjskdjfskjdf sjdf sdjflksjdfkjsdlfkjsdkfjs ");
newBean.setName("aName");
// t.log("--- next insert should error");
Ebean.save(newBean);
@@ -0,0 +1,47 @@
package com.avaje.tests.batchinsert;
import com.avaje.ebean.BaseTestCase;
import com.avaje.ebean.Ebean;
import com.avaje.ebean.EbeanServer;
import com.avaje.ebean.Transaction;
import com.avaje.ebean.config.PersistBatch;
import com.avaje.tests.model.basic.EBasicVer;
import org.junit.Test;
import java.sql.Timestamp;
public class TestBatchInsertFlush extends BaseTestCase {
@Test
public void testFlushOnGetId() {
EbeanServer server = Ebean.getDefaultServer();
Transaction txn = server.beginTransaction();
try {
txn.setBatch(PersistBatch.ALL);
EBasicVer b1 = new EBasicVer("b1");
server.save(b1, txn);
EBasicVer b2 = new EBasicVer("b2");
server.save(b2, txn);
//txn.flushBatch();
b1.setDescription("modify");
System.out.println("here");
Timestamp lastUpdate = b1.getLastUpdate();
Integer id = b1.getId();
EBasicVer b3 = new EBasicVer("b3");
server.save(b3, txn);
txn.commit();
} finally {
txn.end();
}
}
}
@@ -17,12 +17,12 @@ public class TestQueryCacheInsert extends BaseTestCase {
EbeanServer server = Ebean.getServer(null);
EBasicVer account = new EBasicVer();
EBasicVer account = new EBasicVer("junk");
server.save(account);
List<EBasicVer> alist0 = server.find(EBasicVer.class).setUseQueryCache(true).findList();
EBasicVer a2 = new EBasicVer();
EBasicVer a2 = new EBasicVer("junk2");
server.save(a2);
awaitL2Cache();
@@ -31,8 +31,7 @@ public class TestDeleteWithoutOptimisticLocking extends BaseTestCase {
@Test
public void testSimpleBeanDelete_existingBean_returnsTrue() {
EBasicVer basic = new EBasicVer();
basic.setName("DelTest");
EBasicVer basic = new EBasicVer("DelTest");
Ebean.save(basic);
EBasicVer basicRef = Ebean.getReference(EBasicVer.class, basic.getId());
@@ -43,8 +42,7 @@ public class TestDeleteWithoutOptimisticLocking extends BaseTestCase {
@Test
public void testSimpleBeanDelete_existingBeanWithJdbcBatch_returnsTrue() {
EBasicVer basic = new EBasicVer();
basic.setName("DelTestBatch");
EBasicVer basic = new EBasicVer("DelTestBatch");
Ebean.save(basic);
EbeanServer server = Ebean.getDefaultServer();
@@ -39,7 +39,7 @@ public class LinkQueryPublishTest {
.setMaxRows(10)
.findPagedList();
assertThat(pagedList.getTotalRowCount()).isEqualTo(3);
assertThat(pagedList.getTotalCount()).isEqualTo(3);
assertThat(pagedList.getList()).hasSize(3);
@@ -15,8 +15,7 @@ public class TestInsertQueryUpdate extends BaseTestCase {
@Test
public void test() {
EBasicVer e0 = new EBasicVer();
e0.setName("name0");
EBasicVer e0 = new EBasicVer("name0");
e0.setDescription("desc0");
Ebean.save(e0);
@@ -15,8 +15,7 @@ public class TestInsertUpdateTrans extends BaseTestCase {
Ebean.beginTransaction();
try {
EBasicVer e0 = new EBasicVer();
e0.setName("onInsert");
EBasicVer e0 = new EBasicVer("onInsert");
e0.setDescription("something");
Ebean.save(e0);
@@ -39,13 +39,13 @@ public class TestM2MDeleteWithCascade extends BaseTestCase {
List<Object> roleIds = new ArrayList<Object>();
Collections.addAll(roleIds, r0.getRoleid(), r1.getRoleid());
int rc = Ebean.find(MRole.class).where().idIn(roleIds).findRowCount();
int rc = Ebean.find(MRole.class).where().idIn(roleIds).findCount();
Assert.assertEquals("roles not deleted", 2, rc);
Ebean.deleteAll(roles);
rc = Ebean.find(MRole.class).where().idIn(roleIds).findRowCount();
rc = Ebean.find(MRole.class).where().idIn(roleIds).findCount();
Assert.assertEquals("roles deleted now", 0, rc);
}
@@ -25,6 +25,10 @@ public class EBasicVer {
@Version
Timestamp lastUpdate;
public EBasicVer(String name) {
this.name = name;
}
public Integer getId() {
return id;
}
@@ -25,7 +25,7 @@ public class ResetBasicData {
server.execute(new TxRunnable() {
public void run() {
if (server.find(Product.class).findRowCount() > 0) {
if (server.find(Product.class).findCount() > 0) {
// we can't really delete this base data as
// the test rely on the products being in there
return;
@@ -72,7 +72,7 @@ public class ResetBasicData {
public void insertCountries() {
if (server.find(Country.class).findRowCount() > 0) {
if (server.find(Country.class).findCount() > 0) {
return;
}
@@ -94,7 +94,7 @@ public class ResetBasicData {
public void insertProducts() {
if (server.find(Product.class).findRowCount() > 0) {
if (server.find(Product.class).findCount() > 0) {
return;
}
server.execute(new TxRunnable() {
@@ -18,7 +18,7 @@ public class TestInsertNoIdBean extends BaseTestCase {
Ebean.save(bean);
int rowCount = Ebean.find(NoIdBean.class).findRowCount();
int rowCount = Ebean.find(NoIdBean.class).findCount();
assertTrue("rowCount:"+rowCount, rowCount > 0);
@@ -18,7 +18,7 @@ public class TestTextJsonSelfRef extends BaseTestCase {
Ebean.execute(new TxRunnable() {
public void run() {
if (Ebean.find(SelfRefCustomer.class).findRowCount() == 0) {
if (Ebean.find(SelfRefCustomer.class).findCount() == 0) {
SelfRefCustomer c1 = new SelfRefCustomer();
c1.setName("Foo");
c1.setReferredBy(c1);
@@ -16,8 +16,7 @@ public class TestPersistenceContextQueryScope extends BaseTestCase {
@Test
public void test() {
EBasicVer bean = new EBasicVer();
bean.setName("first");
EBasicVer bean = new EBasicVer("first");
Ebean.save(bean);
//Ebean.getServerCacheManager().setCaching(EBasicVer.class, true);
@@ -48,7 +48,7 @@ public class TestQueryFindFutureList extends BaseTestCase {
// wait for it to complete
List<Order> orders = futureList.getUnchecked();
assertEquals(Ebean.find(Order.class).findRowCount(), orders.size());
assertEquals(Ebean.find(Order.class).findCount(), orders.size());
}
@Test
@@ -61,7 +61,7 @@ public class TestQueryFindFutureList extends BaseTestCase {
// wait for it to complete
List<Order> orders = futureList.getUnchecked(1, TimeUnit.SECONDS);
assertEquals(Ebean.find(Order.class).findRowCount(), orders.size());
assertEquals(Ebean.find(Order.class).findCount(), orders.size());
}
}
@@ -83,7 +83,7 @@ public class TestQueryFindPagedList extends BaseTestCase {
pagedList.loadRowCount();
List<Order> orders = pagedList.getList();
int totalRowCount = pagedList.getTotalRowCount();
int totalRowCount = pagedList.getTotalCount();
assertThat(orders.size()).isLessThan(totalRowCount);
assertTrue(pagedList.hasNext());
@@ -96,9 +96,9 @@ public class TestQueryFindPagedList extends BaseTestCase {
.setMaxRows(3)
.findPagedList();
pagedList2.loadRowCount();
pagedList2.loadCount();
List<Order> orders2 = pagedList2.getList();
int totalRowCount2 = pagedList2.getTotalRowCount();
int totalRowCount2 = pagedList2.getTotalCount();
assertTrue(pagedList2.hasNext());
assertTrue(pagedList2.hasPrev());
@@ -161,11 +161,11 @@ public class TestQueryFindPagedList extends BaseTestCase {
PagedList<Order> pagedList = Ebean.find(Order.class).setMaxRows(3).findPagedList();
Future<Integer> rowCount = pagedList.getFutureRowCount();
Future<Integer> rowCount = pagedList.getFutureCount();
List<Order> orders = pagedList.getList();
// these are each getting the total row count
int totalRowCount = pagedList.getTotalRowCount();
int totalRowCount = pagedList.getTotalCount();
Integer totalRowCountWithTimeout = rowCount.get(30, TimeUnit.SECONDS);
Integer totalRowCountViaFuture = rowCount.get();
@@ -183,9 +183,9 @@ public class TestQueryFindPagedList extends BaseTestCase {
// fetch less that total orders (page size 3)
PagedList<Order> pagedList = Ebean.find(Order.class).setMaxRows(3).findPagedList();
pagedList.loadRowCount();
pagedList.loadCount();
List<Order> orders = pagedList.getList();
int totalRowCount = pagedList.getTotalRowCount();
int totalRowCount = pagedList.getTotalCount();
assertThat(orders.size()).isLessThan(totalRowCount);
}
@@ -207,10 +207,10 @@ public class TestQueryFindPagedList extends BaseTestCase {
try {
List<Order> orders = pagedList.getList();
int totalRowCount = pagedList.getTotalRowCount();
int totalRowCount = pagedList.getTotalCount();
// invoke it again but cached...
int totalRowCountAgain = pagedList.getTotalRowCount();
int totalRowCountAgain = pagedList.getTotalCount();
List<String> loggedSql = LoggedSqlCollector.stop();
@@ -242,7 +242,7 @@ public class TestQueryFindPagedList extends BaseTestCase {
LoggedSqlCollector.start();
pagedList.getTotalRowCount();
pagedList.getTotalCount();
pagedList.getList();
List<String> loggedSql = LoggedSqlCollector.stop();
@@ -29,7 +29,7 @@ public class TestQueryPlanCacheRowCount extends BaseTestCase {
List<Order> list0 = query.findList();
Assert.assertEquals(rc0, list0.size());
int rc1 = query.findRowCount();
int rc1 = query.findCount();
Assert.assertEquals(rc0, rc1);
List<Object> ids1 = query.findIds();
@@ -48,7 +48,7 @@ public class TestQueryPlanCacheRowCount extends BaseTestCase {
Query<Order> query2 = Ebean.find(Order.class).where().eq("status", Order.Status.NEW)
.ge("id", idGt).order().desc("id");
int rc2 = query2.findRowCount();
int rc2 = query2.findCount();
System.out.println("Expection Not same " + rc0 + " != " + rc2);
Assert.assertNotSame(rc0, rc2);
@@ -21,7 +21,7 @@ public class TestRowCount extends BaseTestCase {
Query<Order> query = Ebean.find(Order.class).fetch("details").where().gt("id", 1)
.gt("details.id", 1).order("id desc");
int rc = query.findRowCount();
int rc = query.findCount();
List<Object> ids = query.findIds();
@@ -44,7 +44,7 @@ public class TestDisjunctWhereOuterOnMany extends BaseTestCase {
.query();
List<UUOne> list = query.findList();
int rowCount = query.findRowCount();
int rowCount = query.findCount();
// select distinct t0.id c0, t0.name c1
// from uuone t0
@@ -31,7 +31,7 @@ public class TestFormulaWithFindCount extends BaseTestCase {
}
ExpressionList<Order> expressionList = server.find(Order.class).where().gt("totalAmount", 1d);
int rowCount = expressionList.findRowCount();
int rowCount = expressionList.findCount();
Assert.assertEquals(list.size(), rowCount);
}
@@ -28,7 +28,7 @@ public class TestObjectGraphNodeStatsCollection extends BaseTestCase {
MetaInfoManager infoManager = server.getMetaInfoManager();
server.find(Order.class).findRowCount();
server.find(Order.class).findCount();
infoManager.collectNodeStatistics(true);
infoManager.collectQueryPlanStatistics(true);
@@ -47,7 +47,7 @@ public class TestQueryConversationRowCount extends BaseTestCase {
LoggedSqlCollector.start();
query.findRowCount();
query.findCount();
// select count(*) from (
// select distinct t0.id c0
@@ -1,10 +1,5 @@
package com.avaje.tests.query.other;
import java.util.List;
import org.junit.Assert;
import org.junit.Test;
import com.avaje.ebean.BaseTestCase;
import com.avaje.ebean.Ebean;
import com.avaje.ebean.Query;
@@ -12,6 +7,14 @@ import com.avaje.ebean.bean.EntityBean;
import com.avaje.ebean.bean.EntityBeanIntercept;
import com.avaje.tests.model.basic.Customer;
import com.avaje.tests.model.basic.ResetBasicData;
import org.junit.Test;
import java.util.List;
import static junit.framework.TestCase.assertNull;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
public class TestQueryDistinct extends BaseTestCase {
@@ -27,17 +30,17 @@ public class TestQueryDistinct extends BaseTestCase {
List<Customer> customers = query.findList();
String generatedSql = query.getGeneratedSql();
Assert.assertTrue(generatedSql.contains("select distinct t0.name c0 from o_customer t0"));
assertThat(generatedSql).contains("select distinct t0.name c0 from o_customer t0");
for (Customer customer : customers) {
EntityBeanIntercept ebi = ((EntityBean)customer)._ebean_getIntercept();
Assert.assertTrue(ebi.isDisableLazyLoad());
Assert.assertNull(ebi.getPersistenceContext());
assertTrue(ebi.isDisableLazyLoad());
assertNull(ebi.getPersistenceContext());
// lazy loading disabled
Assert.assertNull(customer.getId());
Assert.assertNull(customer.getAnniversary());
assertNull(customer.getId());
assertNull(customer.getAnniversary());
}
}
@@ -53,7 +56,7 @@ public class TestQueryDistinct extends BaseTestCase {
query.findList();
String generatedSql = query.getGeneratedSql();
Assert.assertTrue(generatedSql.contains("select distinct t0.name c0 from o_customer t0"));
assertThat(generatedSql).contains("select distinct t0.name c0 from o_customer t0");
}
@Test
@@ -69,15 +72,33 @@ public class TestQueryDistinct extends BaseTestCase {
List<Customer> customers = query.findList();
String generatedSql = query.getGeneratedSql();
Assert.assertTrue(generatedSql.contains("select distinct t0.status c0 from o_customer t0"));
assertThat(generatedSql).contains("select distinct t0.status c0 from o_customer t0");
for (Customer customer : customers) {
Assert.assertNotNull(customer.getStatus());
assertNotNull(customer.getStatus());
// lazy loading disabled
Assert.assertNull(customer.getId());
Assert.assertNull(customer.getAnniversary());
assertNull(customer.getId());
assertNull(customer.getAnniversary());
}
}
@Test
public void testPagingQuery_expect_doesNotAddOrderBy() {
ResetBasicData.reset();
Query<Customer> query = Ebean.find(Customer.class)
.setMaxRows(10)
.setDistinct(true)
.select("name");
query.findList();
if (isH2() || isPostgres()) {
String generatedSql = query.getGeneratedSql();
assertThat(generatedSql).contains("select distinct t0.name c0 from o_customer t0 limit 10");
}
}
@@ -0,0 +1,35 @@
package com.avaje.tests.query.other;
import com.avaje.ebean.BaseTestCase;
import com.avaje.ebean.Ebean;
import com.avaje.ebean.Query;
import com.avaje.tests.model.basic.Order;
import com.avaje.tests.model.basic.ResetBasicData;
import org.avaje.ebeantest.LoggedSqlCollector;
import org.junit.Test;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
public class TestQueryRawExpressionMany extends BaseTestCase {
@Test
public void test() {
ResetBasicData.reset();
Integer quantity = 1;
Query<Order> query = Ebean.find(Order.class)
.where().raw("details.orderQty = ?", quantity)
.query();
LoggedSqlCollector.start();
query.findCount();
List<String> sql = LoggedSqlCollector.stop();
assertThat(sql.get(0)).contains("select count(*) from ( select distinct t0.id c0 from o_order t0 left outer join o_order_detail t1 on t1.order_id = t0.id where t1.order_qty = ?)");
}
}

Some files were not shown because too many files have changed in this diff Show More