Query
Code IndexAdd Codota to your IDE (free)

Best Java code snippets using com.avaje.ebean.Query (Showing top 20 results out of 315)

  • Common ways to obtain Query
private void myMethod () {
Query q =
  • SpiQuery query;String str;query.select(str)
  • SpiQuery spiQuery;spiQuery.setReadOnly(true)
  • SpiQuery spiQuery;spiQuery.setUseCache(false)
  • Smart code suggestions by Codota
}
origin: org.avaje.ebean/ebean

@Override
public List<T> findList() {
 return query.findList();
}
origin: stackoverflow.com

 Query q = Search.search("object:dogs", Folder.class);
q.orderBy("object")
  .page(2,5)
  .reverse();
origin: org.actframework/act-ebean-java7

@Override
public EbeanQuery<MODEL_TYPE> fetch(String path) {
  q.fetch(path);
  qReadOnly.fetch(path);
  return this;
}
origin: org.actframework/act-ebean-java7

@Override
public MODEL_TYPE first() {
  List<MODEL_TYPE> list = qReadOnly.setMaxRows(1).findList();
  return list.isEmpty() ? null : list.get(0);
}
origin: org.avaje.ebean/ebean

/**
 * Return a list of expressions that will be joined by OR's.
 */
public <T> Junction<T> disjunction(Query<T> query) {
 return new JunctionExpression<>(Junction.Type.OR, query, query.where());
}
origin: org.actframework/act-ebean-java7

private void syncEbeanQueries() {
  _sync("detail");
  q.orderBy();
  _sync("orderBy");
  q.text();
  _sync("textExpressions");
  q.where();
  _sync("whereExpressions");
  q.having();
  _sync("havingExpressions");
}
origin: com.khubla.pragmatach/pragmatach-ebean

@Override
public List<T> getAll(int start, int count) throws PragmatachException {
 return this.find().setFirstRow(start).setMaxRows(count).findList();
}
origin: MrNeuronix/IRISv2

public List<SensorData> getLogs() {
  return Ebean.find(SensorData.class).where().eq("uuid", this.uuid).order().desc("logdate").findList();
}
origin: org.avaje.ebeanorm/avaje-ebeanorm-server

private List<Object> findIdsByParentId(Object parentId, Transaction t, ArrayList<Object> excludeDetailIds) {
  
  String rawWhere = deriveWhereParentIdSql(false);
  
  EbeanServer server = getBeanDescriptor().getEbeanServer();
  Query<?> q = server.find(getPropertyType())
    .where().raw(rawWhere).query();
  
  bindWhereParendId(1, q, parentId);
  
  if (excludeDetailIds != null && !excludeDetailIds.isEmpty()) {
    Expression idIn = q.getExpressionFactory().idIn(excludeDetailIds);
    q.where().not(idIn);
  }
  
  return server.findIds(q, t);
}
 
origin: making/spring-boot-db-samples

public List<Pizza> findOrderByIdAsc() {
  List<Pizza> pizzas = server.find(Pizza.class).orderBy("id asc").findList();
  return pizzas;
}

origin: org.avaje/ebean

query.select(idNames).setId(id);
ref = query.findUnique();
origin: org.avaje.ebean/ebean

/**
 * Apply these path properties as fetch paths to the query.
 */
public <T> void apply(Query<T> query) {
 for (Entry<String, Props> entry : pathMap.entrySet()) {
  String path = entry.getKey();
  String props = entry.getValue().getPropertiesAsString();
  if (path == null || path.isEmpty()) {
   query.select(props);
  } else {
   query.fetch(path, props);
  }
 }
}
origin: org.actframework/act-ebean-java7

@Override
public EbeanQuery<MODEL_TYPE> offset(int pos) {
  q.setFirstRow(pos);
  qReadOnly.setFirstRow(pos);
  return this;
}
origin: org.actframework/act-ebean-java7

@Override
public EbeanQuery<MODEL_TYPE> limit(int limit) {
  q.setMaxRows(limit);
  qReadOnly.setMaxRows(limit);
  return this;
}
origin: org.avaje.ebean/ebean

/**
 * Fetch the destination beans that will be published to.
 */
void fetchDestinationBeans(List<T> sourceBeans, boolean asDraft) {
 List<Object> ids = getBeanIds(desc, sourceBeans);
 Query<T> destQuery = server.find(desc.getBeanType()).where().idIn(ids).query();
 if (asDraft) {
  destQuery.asDraft();
 }
 desc.draftQueryOptimise(destQuery);
 this.destBeans = server.findMap(destQuery, transaction);
}
origin: org.avaje.ebean/ebean

@Override
public FutureIds<T> findFutureIds() {
 return rootQuery.findFutureIds();
}
origin: org.avaje.ebean/ebean

@Override
public FutureList<T> findFutureList() {
 return rootQuery.findFutureList();
}
origin: org.avaje.ebean/ebean

@Override
public ExpressionList<T> filterMany(String prop) {
 return query.filterMany(prop);
}
origin: org.actframework/act-ebean-java7

@Override
public EbeanQuery<MODEL_TYPE> select(String fetchProperties) {
  q.select(fetchProperties);
  qReadOnly.select(fetchProperties);
  return this;
}
origin: org.avaje.ebeanorm/avaje-ebeanorm-server

/**
 * We need to create and execute a query to get the foreign key values as
 * the delete cascades to them (foreign keys).
 */
private Query<?> deleteRequiresQuery(BeanDescriptor<?> desc, BeanPropertyAssocOne<?>[] propImportDelete) {
  Query<?> q = server.createQuery(desc.getBeanType());
  StringBuilder sb = new StringBuilder(30);
  for (int i = 0; i < propImportDelete.length; i++) {
    sb.append(propImportDelete[i].getName()).append(",");
  }
  q.setAutofetch(false);
  q.select(sb.toString());
  return q;
}
com.avaje.ebeanQuery

Javadoc

Object relational query for finding a List, Set, Map or single entity bean.

Example: Create the query using the API.

 
List<Order> orderList =  
Ebean.find(Order.class) 
.fetch("customer") 
.fetch("details") 
.where() 
.like("customer.name","rob%") 
.gt("orderDate",lastWeek) 
.orderBy("customer.id, id desc") 
.setMaxRows(50) 
.findList(); 
... 

Example: The same query using the query language

 
String oql =  
"  find  order " 
+" fetch customer " 
+" fetch details " 
+" where customer.name like :custName and orderDate > :minOrderDate " 
+" order by customer.id, id desc " 
+" limit 50 "; 
Query<Order> query = Ebean.createQuery(Order.class, oql); 
query.setParameter("custName", "Rob%"); 
query.setParameter("minOrderDate", lastWeek); 
List<Order> orderList = query.findList(); 
... 

Example: Using a named query called "with.cust.and.details"

 
Query<Order> query = Ebean.createNamedQuery(Order.class,"with.cust.and.details"); 
query.setParameter("custName", "Rob%"); 
query.setParameter("minOrderDate", lastWeek); 
List<Order> orderList = query.findList(); 
... 

Autofetch

Ebean has built in support for "Autofetch". This is a mechanism where a query can be automatically tuned based on profiling information that is collected.

This is effectively the same as automatically using select() and fetch() to build a query that will fetch all the data required by the application and no more.

It is expected that Autofetch will be the default approach for many queries in a system. It is possibly not as useful where the result of a query is sent to a remote client or where there is some requirement for "Read Consistency" guarantees.

Query Language

Partial Objects

The find and fetch clauses support specifying a list of properties to fetch. This results in objects that are "partially populated". If you try to get a property that was not populated a "lazy loading" query will automatically fire and load the rest of the properties of the bean (This is very similar behaviour as a reference object being "lazy loaded").

Partial objects can be saved just like fully populated objects. If you do this you should remember to include the "Version" property in the initial fetch. If you do not include a version property then optimistic concurrency checking will occur but only include the fetched properties. Refer to "ALL Properties/Columns" mode of Optimistic Concurrency checking.

 
[ find  {bean type} [ ( * | {fetch properties} ) ] ] 
[ fetch {associated bean} [ ( * | {fetch properties} ) ] ] 
[ where {predicates} ] 
[ order by {order by properties} ] 
[ limit {max rows} [ offset {first row} ] ] 

FIND {bean type} [ ( * | {fetch properties} ) ]

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.

In object graph terms the find clause specifies the type of bean at the root level and the fetch clauses specify the paths of the object graph to populate.

FETCH {associated property} [ ( * | {fetch properties} ) ]

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.

For fetch of a path we can optionally specify a list of properties to fetch. If you do not specify a list of properties ALL the properties for that bean type are fetched.

WHERE {list of predicates}

The list of predicates which are joined by AND OR NOT ( and ). They can include named (or positioned) bind parameters. These parameters will need to be bound by Query#setParameter(String,Object).

ORDER BY {order by properties}

The list of properties to order the result. You can include ASC (ascending) and DESC (descending) in the order by clause.

LIMIT {max rows} [ OFFSET {first row} ]

The limit offset specifies the max rows and first row to fetch. The offset is optional.

Examples of Ebean's Query Language

Find orders fetching all its properties

 
find order 

Find orders fetching all its properties

 
find order (*) 

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.

 
find order (shipDate, status) 

Find orders with a named bind variable (that will need to be bound via Query#setParameter(String,Object)).

 
find order 
where customer.name like :custLike 

Find orders and also fetch the customer with a named bind parameter. This will fetch and populate both the order and customer objects.

 
find  order 
fetch customer 
where customer.id = :custId 

Find orders and also fetch the customer, customer shippingAddress, order details and related product. Note that customer and product objects will be "Partial Objects" with only some of their properties populated. The customer objects will have their id, name and shipping address populated. The product objects (associated with each order detail) will have their id, sku and name populated.

 
find  order 
fetch customer (name) 
fetch customer.shippingAddress 
fetch details 
fetch details.product (sku, name) 

Early parsing of the Query

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).

The thought is that you can use named queries as a 'starting point' and then modify the query to suit specific needs.

Building the Where clause

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.

  • where(String addToWhereClause)
  • where().add(Expression expression)
  • where().eq(propertyName, value).like(propertyName , value)...

The full WHERE clause is constructed by appending together

  • original query where clause (Named query or query.setQuery(String oql))
  • clauses added via query.where(String addToWhereClause)
  • clauses added by Expression objects
  • The above is the order that these are clauses are appended to give the full WHERE clause.

    Design Goal

    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.

    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 RawSql .

    Most used methods

    • where
      Add additional clause(s) to the where clause. This typically contains named parameters which will ne
    • findList
      Execute the query returning the list of objects. This query will execute against the EbeanServer tha
    • orderBy
      Set the order by clause replacing the existing order by clause if there is one. This follows SQL sy
    • fetch
      Additionally specify a FetchConfig to use a separate query or lazy loading to load this path.
    • select
      Explicitly set a comma delimited list of the properties to fetch on the 'main' entity bean (aka part
    • setFirstRow
      Set the first row to return for this query.
    • setMaxRows
      Set the maximum number of rows to return in the query.
    • filterMany
      This applies a filter on the 'many' property list rather than the root level objects. Typically you
    • findFutureIds
      Execute find Id's query in a background thread. This returns a Future object which can be used to ca
    • findFutureList
      Execute find list query in a background thread. This returns a Future object which can be used to ca
    • findIds
      Execute the query returning the list of Id's. This query will execute against the EbeanServer that w
    • findIterate
      Execute the query iterating over the results. Remember that with QueryIterator you must call QueryIt
    • findIds,
    • findIterate,
    • findMap,
    • findRowCount,
    • findSet,
    • findUnique,
    • getExpressionFactory,
    • having,
    • order,
    • setId

    Popular in Java

    • Creating JSON documents from java classes using gson
    • getSystemService (Context)
    • startActivity (Activity)
    • onCreateOptionsMenu (Activity)
    • BorderLayout (java.awt)
      A border layout lays out a container, arranging and resizing its components to fit in five regions:
    • InputStreamReader (java.io)
      A class for turning a byte stream into a character stream. Data read from the source input stream is
    • Collection (java.util)
      Collection is the root of the collection hierarchy. It defines operations on data collections and t
    • Vector (java.util)
      Vector is an implementation of List, backed by an array and synchronized. All optional operations in
    • Project (org.apache.tools.ant)
      Central representation of an Ant project. This class defines an Ant project with all of its targets,
    • IsNull (org.hamcrest.core)
      Is the value null?

    For IntelliJ IDEA,
    Android Studio or Eclipse

    • Search for JavaScript code betaCodota IntelliJ IDEA pluginCodota Android Studio pluginCode IndexSign in
    • EnterpriseFAQAboutBlogContact Us
    • Plugin user guideTerms of usePrivacy policyCodeboxFind Usages
    Add Codota to your IDE (free)