Compare commits

...
Author SHA1 Message Date
Robin Bygrave 629fb7a433 [maven-release-plugin] prepare release ebean-8.1.1 2016-08-03 16:24:23 +12:00
Robin Bygrave 4ff10da739 #801 - Change maven groupId ... to org.avaje.ebean, artifactId to ebean 2016-08-03 16:23:26 +12:00
Robin Bygrave 9472592a50 [maven-release-plugin] prepare for next development iteration 2016-08-03 00:40:37 +12:00
Robin Bygrave f42682ca90 [maven-release-plugin] prepare release avaje-ebeanorm-8.1.1 2016-08-03 00:40:18 +12:00
Robin Bygrave 5dc296e644 #798 - Add @Transactional based test 2016-08-03 00:38:58 +12:00
Robin Bygrave 380660913f No effective change - javadoc update on Query 2016-08-02 23:42:00 +12:00
Robin Bygrave d08ac6973e #800 - ENH: Add query.fetchQuery() and query.fetchLazy() ... as nicer alternatives to FetchConfig use 2016-08-02 23:33:02 +12:00
Robin Bygrave 9d23c1d56e #800 - ENH: Add query.fetchQuery() and query.fetchLazy() ... as nicer alternatives to FetchConfig use 2016-08-02 23:30:26 +12:00
Robin Bygrave b5d6c5f70b #800 - ENH: Add query.fetchQuery() and query.fetchLazy() ... as nicer alternatives to FetchConfig use 2016-08-02 23:30:04 +12:00
Robin Bygrave 3657d05774 #798 - ENH: Add support for transparent full JDBC batch. Via enhancement agent 8.1.1 ... 2016-08-02 21:41:13 +12:00
Robin Bygrave 2de8ae777d Merge branch 'wip/getterCallback' 2016-08-02 21:34:41 +12:00
Robin Bygrave 16950a5641 [maven-release-plugin] prepare for next development iteration 2016-08-02 21:32:08 +12:00
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 dacdc26902 #798 - ENH: Add support for transparent full JDBC batch. Via enhancement agent 8.1.1 intercept bean getter to automatically flush the JDBC batch buffer. 2016-08-02 16:16:34 +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
125 changed files with 1140 additions and 756 deletions
+12 -12
View File
@@ -7,12 +7,12 @@
<version>1.1</version>
</parent>
<groupId>org.avaje.ebeanorm</groupId>
<artifactId>avaje-ebeanorm</artifactId>
<version>7.20.1</version>
<groupId>org.avaje.ebean</groupId>
<artifactId>ebean</artifactId>
<version>8.1.1</version>
<packaging>jar</packaging>
<name>avaje-ebeanorm</name>
<name>ebean</name>
<url>http://ebean-orm.github.io/</url>
<properties>
@@ -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>ebean-8.1.1</tag>
</scm>
<dependencies>
@@ -172,9 +172,9 @@
</dependency>
<dependency>
<groupId>org.avaje.ebeanorm</groupId>
<artifactId>avaje-ebeanorm-agent</artifactId>
<version>4.11.1</version>
<groupId>org.avaje.ebean</groupId>
<artifactId>ebean-agent</artifactId>
<version>8.1.1</version>
<scope>test</scope>
</dependency>
@@ -247,9 +247,9 @@
</plugin>
<plugin>
<groupId>org.avaje.ebeanorm</groupId>
<artifactId>avaje-ebeanorm-mavenenhancer</artifactId>
<version>4.11.1</version>
<groupId>org.avaje.ebean</groupId>
<artifactId>ebean-maven-plugin</artifactId>
<version>8.1.1</version>
<executions>
<execution>
<id>test</id>
@@ -304,7 +304,7 @@
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.9.1</version>
<configuration>
<doctitle>Ebean 7</doctitle>
<doctitle>Ebean 8</doctitle>
<overview>src/main/java/com/avaje/ebean/overview.html</overview>
<source>1.8</source>
<doclet>org.avaje.doclet.PygmentsDoclet</doclet>
+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();
/**
+229 -222
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,40 @@ 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 =
* " find order "
* String oql =
* +" 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 +76,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,36 +94,25 @@ 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} ) ] ]
* [ select [ ( * | {fetch properties} ) ] ]
* [ fetch {path} [ ( * | {fetch properties} ) ] ]
* [ where {predicates} ]
* [ 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> ) ]
* <b>SELECT</b> [ ( <i>*</i> | <i>{fetch properties}</i> ) ]
* </p>
* <p>
* With the find you specify the type of beans to fetch. You can optionally
* specify a list of properties to fetch. If you do not specify a list of
* properties ALL the properties for those beans are fetched.
* With the select you can specify a list of properties to fetch.
* </p>
* <p>
* In object graph terms the <em>find</em> clause specifies the type of bean at
* the root level and the <em>fetch</em> clauses specify the paths of the object
* graph to populate.
* </p>
* <p>
* <b>FETCH</b> <b>{associated property}</b> [ ( <i>*</i> | <i>{fetch
* properties}</i> ) ]
* <b>FETCH</b> <b>{path}</b> [ ( <i>*</i> | <i>{fetch properties}</i> ) ]
* </p>
* <p>
* With the fetch you specify the associated property to fetch and populate. The
* associated property is a OneToOnem, ManyToOne, OneToMany or ManyToMany
* property. When the query is executed Ebean will fetch the associated data.
* path is a OneToOne, ManyToOne, OneToMany or ManyToMany property.
* </p>
* <p>
* For fetch of a path we can optionally specify a list of properties to fetch.
@@ -161,52 +143,34 @@ import java.util.Set;
* </p>
* <h4>Examples of Ebean's Query Language</h4>
* <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)
*
* select (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,63 +179,16 @@ 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)
* fetch customer.shippingAddress
* 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
* already been parsed. You can then add to that query (add fetch paths, add to
* the where clause) or override some of its settings (override the order by
* clause, first rows, max rows).
* </p>
* <p>
* The thought is that you can use named queries as a 'starting point' and then
* modify the query to suit specific needs.
* </p>
* <h3>Building the Where clause</h3>
* <p>
* You can add to the where clause using Expression objects or a simple String.
* Note that the ExpressionList has methods to add most of the common
* expressions that you will need.
* <ul>
* <li>where(String addToWhereClause)</li>
* <li>where().add(Expression expression)</li>
* <li>where().eq(propertyName, value).like(propertyName , value)...</li>
* </ul>
* </p>
* <p>
* The full WHERE clause is constructed by appending together
* <li>original query where clause (Named query or query.setQuery(String oql))</li>
* <li>clauses added via query.where(String addToWhereClause)</li>
* <li>clauses added by Expression objects</li>
* </p>
* <p>
* The above is the order that these are clauses are appended to give the full
* WHERE clause.
* </p>
* <h3>Design Goal</h3>
* <p>
* This query language is NOT designed to be a replacement for SQL. It is
* designed to be a simple way to describe the "Object Graph" you want Ebean to
* build for you. Each find/fetch represents a node in that "Object Graph" which
* makes it easy to define for each node which properties you want to fetch.
* </p>
* <p>
* Once you hit the limits of this language such as wanting aggregate functions
* (sum, average, min etc) or recursive queries etc you use SQL. Ebean's goal is
* 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 +206,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
@@ -325,7 +242,7 @@ public interface Query<T> {
* Specify the PersistenceContextScope to use for this query.
* <p/>
* When this is not set the 'default' configured on {@link com.avaje.ebean.config.ServerConfig#setPersistenceContextScope(PersistenceContextScope)}
* is used - this value defaults to {@link com.avaje.ebean.PersistenceContextScope#TRANSACTION}.
* is used - this value defaults to {@link PersistenceContextScope#TRANSACTION}.
* <p/>
* Note that the same persistence Context is used for subsequent lazy loading and query join queries.
* <p/>
@@ -392,14 +309,15 @@ public interface Query<T> {
Query<T> setDisableReadAuditing();
/**
* Explicitly set a comma delimited list of the properties to fetch on the
* 'main' root level entity bean (aka partial object). Note that '*' means all
* properties.
* Specify the properties to fetch on the root level entity bean in comma delimited format.
* <p>
* You use {@link #fetch(String, String)} to specify specific properties to fetch
* The Id property is automatically included in the properties to fetch unless setDistinct(true)
* is set on the query.
* </p>
* <p>
* 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,42 +330,33 @@ 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);
/**
* Specify a path to <em>fetch</em> with its specific properties to include
* (aka partial object).
* Specify a path to fetch eagerly including specific properties.
* <p>
* When you specify a join this means that property (associated bean(s)) will
* be fetched and populated. If you specify "*" then all the properties of the
* associated bean will be fetched and populated. You can specify a comma
* delimited list of the properties of that associated bean which means that
* only those properties are fetched and populated resulting in a
* "Partial Object" - a bean that only has some of its properties populated.
* Ebean will endeavour to fetch this path using a SQL join. If Ebean determines that it can
* not use a SQL join (due to maxRows or because it would result in a cartesian product) Ebean
* will automatically convert this fetch query into a "query join" - i.e. use fetchQuery().
* </p>
*
* <pre>{@code
*
* // query orders...
* List<Order> orders =
* ebeanserver.find(Order.class)
* ebeanServer.find(Order.class)
* // 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.
* 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 +367,66 @@ 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 property path we wish to fetch eagerly.
* @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);
/**
* Fetch the path and properties using a "query join" (separate SQL query).
* <p>
* This is the same as:
* </p>
* <pre>{@code
*
* fetch(path, fetchProperties, new FetchConfig().query())
*
* }</pre>
* <p>
* This would be used instead of a fetch() when we use a separate SQL query to fetch this
* part of the object graph rather than a SQL join.
* </p>
* <p>
* We might typically get a performance benefit when the path to fetch is a OneToMany
* or ManyToMany, the 'width' of the 'root bean' is wide and the cardinality of the many
* is high.
* </p>
*
* @param path the property path we wish to fetch eagerly.
* @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> fetchQuery(String path, String fetchProperties);
/**
* Fetch the path and properties lazily (via batch lazy loading).
* <p>
* This is the same as:
* </p>
* <pre>{@code
*
* fetch(path, fetchProperties, new FetchConfig().lazy())
*
* }</pre>
* <p>
* The reason for using fetchLazy() is to either:
* </p>
* <ul>
* <li>Control/tune what is fetched as part of lazy loading</li>
* <li>Make use of the L2 cache, build this part of the graph from L2 cache</li>
* </ul>
*
* @param path the property path we wish to fetch lazily.
* @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> fetchLazy(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)
@@ -481,13 +437,17 @@ public interface Query<T> {
* .findList();
*
* }</pre>
*
* @param path the property path we wish to fetch eagerly.
*/
Query<T> fetch(String assocProperty, String fetchProperties, FetchConfig fetchConfig);
Query<T> fetch(String path, String fetchProperties, FetchConfig fetchConfig);
/**
* Specify a path to load including all its properties.
* Specify a path to fetch eagerly including all its properties.
* <p>
* The same as {@link #fetch(String, String)} with the fetchProperties as "*".
* Ebean will endeavour to fetch this path using a SQL join. If Ebean determines that it can
* not use a SQL join (due to maxRows or because it would result in a cartesian product) Ebean
* will automatically convert this fetch query into a "query join" - i.e. use fetchQuery().
* </p>
* <pre>{@code
*
@@ -500,16 +460,59 @@ 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 path we wish to fetch eagerly.
*/
Query<T> fetch(String path);
/**
* Fetch the path eagerly using a "query join" (separate SQL query).
* <p>
* This is the same as:
* </p>
* <pre>{@code
*
* fetch(path, new FetchConfig().query())
*
* }</pre>
* <p>
* This would be used instead of a fetch() when we use a separate SQL query to fetch this
* part of the object graph rather than a SQL join.
* </p>
* <p>
* We might typically get a performance benefit when the path to fetch is a OneToMany
* or ManyToMany, the 'width' of the 'root bean' is wide and the cardinality of the many
* is high.
* </p>
*
* @param path the property path we wish to fetch eagerly
*/
Query<T> fetchQuery(String path);
/**
* Fetch the path lazily (via batch lazy loading).
* <p>
* This is the same as:
* </p>
* <pre>{@code
*
* fetch(path, new FetchConfig().lazy())
*
* }</pre>
* <p>
* The reason for using fetchLazy() is to either:
* </p>
* <ul>
* <li>Control/tune what is fetched as part of lazy loading</li>
* <li>Make use of the L2 cache, build this part of the graph from L2 cache</li>
* </ul>
*
* @param path the property path we wish to fetch lazily.
*/
Query<T> fetchLazy(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 +539,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 +567,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 +580,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 +592,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 +610,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 +619,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 +637,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 +659,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 +667,7 @@ public interface Query<T> {
* .findMap();
*
* }</pre>
*
*
* @see EbeanServer#findMap(Query, Transaction)
*/
Map<?, T> findMap();
@@ -693,7 +688,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 +697,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 +723,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 +737,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 +766,15 @@ 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 +784,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 +811,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 +837,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 +858,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 +880,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 +905,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 +927,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 +943,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 +953,9 @@ public interface Query<T> {
* .findList();
*
* }</pre>
*
* @see Expr
*
* @return The ExpressionList for adding expressions to.
* @see Expr
*/
ExpressionList<T> where();
@@ -984,9 +990,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 +1000,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 +1023,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 +1039,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 +1152,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 +1162,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 +1173,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 +1201,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 +1224,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);
@@ -1238,6 +1235,16 @@ public interface Query<T> {
* Gives the JDBC driver a hint as to the number of rows that should be
* fetched from the database when more rows are needed for ResultSet.
* </p>
* <p>
* Note that internally findEach and findEachWhile will set the fetch size
* if it has not already as these queries expect to process a lot of rows.
* If we didn't then Postgres and MySql for example would eagerly pull back
* all the row data and potentially consume a lot of memory in the process.
* </p>
* <p>
* As findEach and findEachWhile automatically set the fetch size we don't have
* to do so generally but we might still wish to for tuning a specific use case.
* </p>
*/
Query<T> setBufferFetchSizeHint(int fetchSize);
@@ -1260,7 +1267,7 @@ public interface Query<T> {
* Return true if this query has forUpdate set.
*/
boolean isForUpdate();
/**
* Set root table alias.
*/
@@ -1274,7 +1281,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.
*/
@@ -39,6 +39,8 @@ public final class EntityBeanIntercept implements Serializable {
private transient BeanLoader beanLoader;
private transient PreGetterCallback preGetterCallback;
private String ebeanServerName;
/**
@@ -186,6 +188,21 @@ public final class EntityBeanIntercept implements Serializable {
return embeddedOwnerIndex;
}
/**
* Clear the getter callback.
*/
public void clearGetterCallback() {
this.preGetterCallback = null;
}
/**
* Register the callback to be triggered when getter is called.
* This is used primarily to automatically flush the JDBC batch.
*/
public void registerGetterCallback(PreGetterCallback getterCallback) {
this.preGetterCallback = getterCallback;
}
/**
* Set the embedded beans owning bean.
*/
@@ -832,19 +849,31 @@ public final class EntityBeanIntercept implements Serializable {
public void initialisedMany(int propertyIndex) {
loadedProps[propertyIndex] = true;
}
private final void preGetterCallback() {
if (preGetterCallback != null) {
preGetterCallback.preGetterTrigger();
}
}
/**
* Called prior to Id property getter.
*/
public void preGetId() {
preGetterCallback();
}
/**
* Method that is called prior to a getter method on the actual entity.
*/
public void preGetter(int propertyIndex) {
preGetterCallback();
if (state == STATE_NEW || disableLazyLoad) {
return;
}
if (!isLoadedProperty(propertyIndex)) {
loadBean(propertyIndex);
}
if (nodeUsageCollector != null) {
nodeUsageCollector.addUsed(getProperty(propertyIndex));
}
@@ -0,0 +1,13 @@
package com.avaje.ebean.bean;
/**
* A callback that can be registered to fire on getter method calls.
* It's primary purpose is to automatically flush JDBC batch buffer.
*/
public interface PreGetterCallback {
/**
* Trigger the callback.
*/
void preGetterTrigger();
}
@@ -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,6 +1,7 @@
package com.avaje.ebeaninternal.server.core;
import com.avaje.ebean.ValuePair;
import com.avaje.ebean.bean.PreGetterCallback;
import com.avaje.ebeaninternal.api.ConcurrencyMode;
import com.avaje.ebean.annotation.DocStoreMode;
import com.avaje.ebean.bean.EntityBean;
@@ -36,7 +37,7 @@ import java.util.Set;
/**
* PersistRequest for insert update or delete of a bean.
*/
public final class PersistRequestBean<T> extends PersistRequest implements BeanPersistRequest<T>, DocStoreUpdate {
public final class PersistRequestBean<T> extends PersistRequest implements BeanPersistRequest<T>, DocStoreUpdate, PreGetterCallback {
private final BeanManager<T> beanManager;
@@ -137,6 +138,11 @@ public final class PersistRequestBean<T> extends PersistRequest implements BeanP
private long version;
/**
* Flag set when request is added to JDBC batch registered as a "getter callback" to automatically flush batch.
*/
private boolean getterCallback;
public PersistRequestBean(SpiEbeanServer server, T bean, Object parentBean, BeanManager<T> mgr, SpiTransaction t,
PersistExecute persistExecute, PersistRequest.Type type, boolean saveRecurse, boolean publish) {
@@ -239,8 +245,17 @@ public final class PersistRequestBean<T> extends PersistRequest implements BeanP
*/
public void setBatched() {
batched = true;
if (type == Type.INSERT || type == Type.UPDATE) {
// used to trigger automatic jdbc batch flush
intercept.registerGetterCallback(this);
getterCallback = true;
}
}
@Override
public void preGetterTrigger() {
transaction.flushBatch();
}
public void setSkipBatchForTopLevel() {
skipBatchForTopLevel = true;
@@ -621,6 +636,9 @@ public final class PersistRequestBean<T> extends PersistRequest implements BeanP
@Override
public int executeNow() {
if (getterCallback) {
intercept.clearGetterCallback();
}
switch (type) {
case INSERT:
persistExecute.executeInsertBean(this);
@@ -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;
@@ -217,12 +217,10 @@ public final class IdBinderSimple implements IdBinder {
if (!idValue.getClass().equals(expectedType)) {
idValue = scalarType.toBeanType(idValue);
}
if (bean != null) {
// support PropertyChangeSupport
idProperty.setValueIntercept(bean, idValue);
}
return idValue;
}
}
@@ -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;
}
}
@@ -43,6 +43,10 @@ public class DefaultOrmQuery<T> implements SpiQuery<T> {
public static final String DEFAULT_QUERY_NAME = "default";
private static final FetchConfig FETCH_QUERY = new FetchConfig().query();
private static final FetchConfig FETCH_LAZY = new FetchConfig().lazy();
private final Class<T> beanType;
private final BeanDescriptor<T> beanDescriptor;
@@ -55,7 +59,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 +575,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 +850,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);
@@ -1013,6 +1017,16 @@ public class DefaultOrmQuery<T> implements SpiQuery<T> {
return fetch(property, null, null);
}
@Override
public Query<T> fetchQuery(String property) {
return fetch(property, null, FETCH_QUERY);
}
@Override
public Query<T> fetchLazy(String property) {
return fetch(property, null, FETCH_LAZY);
}
@Override
public DefaultOrmQuery<T> fetch(String property, FetchConfig joinConfig) {
return fetch(property, null, joinConfig);
@@ -1023,6 +1037,16 @@ public class DefaultOrmQuery<T> implements SpiQuery<T> {
return fetch(property, columns, null);
}
@Override
public Query<T> fetchQuery(String property, String columns) {
return fetch(property, columns, FETCH_QUERY);
}
@Override
public Query<T> fetchLazy(String property, String columns) {
return fetch(property, columns, FETCH_LAZY);
}
@Override
public DefaultOrmQuery<T> fetch(String property, String columns, FetchConfig config) {
detail.fetch(property, columns, config);
@@ -1048,11 +1072,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 +1148,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 +1288,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;
@@ -153,6 +153,20 @@ public class DefaultServer_createOrmQueryRequestTest extends BaseTestCase {
assertThat(detail.getFetchPaths()).containsExactly("customer");
}
@Test
public void testJoinOrder_when_queryFetch_expect_getFetchPaths_doesNotIncludeQueryJoin_via_fetchQuery() {
Query<Order> query = Ebean.find(Order.class)
.select("status, orderDate")
.fetch("customer", "name")
.fetchQuery("details");
OrmQueryRequest<Order> queryRequest = queryRequest(query);
OrmQueryDetail detail = queryRequest.getQuery().getDetail();
assertThat(detail.getFetchPaths()).containsExactly("customer");
}
@Test
public void testJoinOrder_when_lazyFetch_expect_getFetchPaths_doesNotIncludeQueryJoin() {
@@ -167,6 +181,20 @@ public class DefaultServer_createOrmQueryRequestTest extends BaseTestCase {
assertThat(detail.getFetchPaths()).containsExactly("customer");
}
@Test
public void testJoinOrder_when_lazyFetch_expect_getFetchPaths_doesNotIncludeQueryJoin_via_fetchLazy() {
Query<Order> query = Ebean.find(Order.class)
.select("status, orderDate")
.fetch("customer", "name")
.fetchLazy("details");
OrmQueryRequest<Order> queryRequest = queryRequest(query);
OrmQueryDetail detail = queryRequest.getQuery().getDetail();
assertThat(detail.getFetchPaths()).containsExactly("customer");
}
@Test
public void testJoinOrder_when_lazyFetchAndHasChildren_expect_getFetchPaths_doesNotIncludeJoinOrChild() {
@@ -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);
@@ -49,6 +49,20 @@ public class DLoadContextTest extends BaseTestCase {
assertThat(customer.secondaryBatchSize).isEqualTo(100);
}
@Test
public void construct_when_fetchQuery_expect_100_batchSize_viaFetchQuery() {
OrmQueryRequest<Order> queryRequest = queryRequest(query().fetchQuery("customer"));
queryRequest.initTransIfRequired();
queryRequest.endTransIfRequired();
DLoadContext graphContext = (DLoadContext)queryRequest.getGraphContext();
DLoadBeanContext customer = graphContext.getBeanContext("customer");
assertThat(customer.firstBatchSize).isEqualTo(100);
assertThat(customer.secondaryBatchSize).isEqualTo(100);
}
@Test
public void construct_when_fetchQuery50_expect_50_batchSize() {
@@ -77,4 +91,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,117 @@
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.annotation.Transactional;
import com.avaje.ebean.config.PersistBatch;
import com.avaje.tests.model.basic.EBasicVer;
import org.junit.Test;
import java.sql.Timestamp;
import static org.junit.Assert.assertNotNull;
public class TestBatchInsertFlush extends BaseTestCase {
@Test
@Transactional(batch = PersistBatch.ALL)
public void transactional_flushOnGetId() {
EbeanServer server = Ebean.getDefaultServer();
EBasicVer b1 = new EBasicVer("b1");
server.save(b1);
EBasicVer b2 = new EBasicVer("b2");
server.save(b2);
Integer id = b1.getId();
assertNotNull(id);
EBasicVer b3 = new EBasicVer("b3");
server.save(b3);
}
@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);
Integer id = b1.getId();
assertNotNull(id);
EBasicVer b3 = new EBasicVer("b3");
server.save(b3, txn);
txn.commit();
} finally {
txn.end();
}
}
@Test
public void testFlushOnGetProperty() {
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);
// flush here
Timestamp lastUpdate = b1.getLastUpdate();
assertNotNull(lastUpdate);
EBasicVer b3 = new EBasicVer("b3");
server.save(b3, txn);
txn.commit();
} finally {
txn.end();
}
}
@Test
public void testFlushOnSetProperty() {
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);
// flush here
b1.setDescription("modify");
EBasicVer b3 = new EBasicVer("b3");
server.save(b3, txn);
txn.commit();
} finally {
txn.end();
}
}
}
@@ -26,8 +26,10 @@ public class TestLazyLoadEmptyCollection extends BaseTestCase {
Ebean.save(c);
List<Customer> list = Ebean.find(Customer.class).fetch("contacts", new FetchConfig().query(0))
.fetch("contacts.notes", new FetchConfig().query(100)).findList();
List<Customer> list = Ebean.find(Customer.class)
.fetch("contacts", new FetchConfig().query(0))
.fetch("contacts.notes", new FetchConfig().query(100))
.findList();
for (Customer customer : list) {
List<Contact> contacts = customer.getContacts();
@@ -2,6 +2,7 @@ package com.avaje.tests.batchload;
import java.util.List;
import org.avaje.ebeantest.LoggedSqlCollector;
import org.junit.Assert;
import org.junit.Test;
@@ -14,8 +15,60 @@ import com.avaje.tests.model.basic.Customer;
import com.avaje.tests.model.basic.Order;
import com.avaje.tests.model.basic.ResetBasicData;
import static org.assertj.core.api.Assertions.assertThat;
public class TestSecondaryQueries extends BaseTestCase {
@Test
public void fetchQuery() {
ResetBasicData.reset();
LoggedSqlCollector.start();
Ebean.find(Order.class)
.select("status")
.fetchQuery("customer", "name")
.findList();
List<String> sql = LoggedSqlCollector.stop();
assertThat(sql).hasSize(2);
assertThat(sql.get(0)).contains("select t0.id c0, t0.status c1, t0.kcustomer_id c2 from o_order t0");
assertThat(sql.get(1)).contains("select t0.id c0, t0.name c1 from o_customer t0 where t0.id in");
}
@Test
public void fetchLazy() {
ResetBasicData.reset();
LoggedSqlCollector.start();
List<Order> orders = Ebean.find(Order.class)
.select("status")
.fetchLazy("customer", "name")
.setMaxRows(10)
.setUseCache(false)
.findList();
List<String> sql = LoggedSqlCollector.stop();
assertThat(sql).hasSize(1);
assertThat(sql.get(0)).contains("select t0.id c0, t0.status c1, t0.kcustomer_id c2 from o_order t0");
LoggedSqlCollector.start();
// invoke lazy loading
for (Order order : orders) {
order.getCustomer().getName();
}
sql = LoggedSqlCollector.stop();
assertThat(sql).hasSize(1);
assertThat(sql.get(0)).contains("select t0.id c0, t0.name c1 from o_customer t0 where t0.id in");
}
@Test
public void testSecQueryOneToMany() {
@@ -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() {
@@ -10,6 +10,7 @@ import org.junit.Test;
import java.util.ArrayList;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertEquals;
public class TestInsertBatchThenUpdate extends BaseTestCase {
@@ -24,6 +25,8 @@ public class TestInsertBatchThenUpdate extends BaseTestCase {
try {
txn.setBatch(PersistBatch.ALL);
LoggedSqlCollector.start();
EdParent parent = new EdParent();
parent.setName("MyComputer");
@@ -36,21 +39,17 @@ public class TestInsertBatchThenUpdate extends BaseTestCase {
Ebean.save(parent);
// nothing flushed yet
List<String> loggedSql0 = LoggedSqlCollector.start();
assertEquals(0, loggedSql0.size());
parent.setName("MyDesk");
Ebean.save(parent);
// nothing flushed yet
assertEquals(0, LoggedSqlCollector.start().size());
Ebean.commitTransaction();
// insert statements for EdExtendedParent
List<String> loggedSql2 = LoggedSqlCollector.start();
assertEquals(2, loggedSql2.size());
List<String> loggedSql = LoggedSqlCollector.stop();
assertEquals(3, loggedSql.size());
assertThat(loggedSql.get(0)).contains("insert into td_parent");
assertThat(loggedSql.get(1)).contains("insert into td_child ");
assertThat(loggedSql.get(2)).contains("update td_parent set parent_name=? where parent_id=?");
} finally {
Ebean.endTransaction();
@@ -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();

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