private EntityListIterator getListIterator(int pageNumber) throws GenericEntityException { GenericHelper helper = genericDelegator.getEntityHelper(entityName); ModelEntity modelEntity = genericDelegator.getModelEntity(entityName); EntityFindOptions entityFindOptions = new EntityFindOptions(); entityFindOptions.setOffset(pageNumber * pageSize); entityFindOptions.setMaxResults(pageSize); return helper.findListIteratorByCondition(modelEntity, entityCondition, null, null, orderBy, entityFindOptions); }
/** * Public method used internally, not safe to override. */ @Override public boolean atLeastOneIssueExists() { OfBizListIterator iterator = null; try { iterator = ofBizDelegator.findListIteratorByCondition(Entity.Name.ISSUE, null, null, of("id"), of("id"), EntityFindOptions.findOptions().maxResults(1)); return iterator.next() != null; } finally { if (iterator != null) { iterator.close(); } } }
private List<GenericValue> filterByFindOptions(List<GenericValue> values, final EntityFindOptions options) { if (options != null) { if (options.getDistinct()) { values = filterDistinct(values); } if (options.getMaxResults() > 0) { values = filterRange(values, options.getOffset(), options.getMaxResults()); } } return values; }
@Override protected OfBizListIterator createListIterator() { return ofBizDelegator.findListIteratorByCondition(AttachmentConstants.ATTACHMENT_ENTITY_NAME, null, null, null, null, EntityFindOptions.findOptions().forwardOnly().readOnly()); }
if (findOptions == null) findOptions = new EntityFindOptions(); StringBuffer sqlBuffer = new StringBuffer("SELECT "); if (findOptions.getDistinct()) { sqlBuffer.append("DISTINCT "); sqlP.prepareStatement(sql, findOptions.getSpecifyTypeAndConcur(), findOptions.getResultSetType(), findOptions.getResultSetConcurrency()); if (verboseOn) {
EntityFindOptions getFindOptions() { final DatabaseConfig dbConfig = databaseConfigurationManager.getDatabaseConfiguration(); int fetchSize = getIntProperty(applicationProperties, APKeys.Export.FETCH_SIZE, -1); if (fetchSize == -1) { if (dbConfig.isMySql()) { // JRA-28591 Use streaming mode on MySQL to stop OOMEs. Nothing else seems to do any good. :( fetchSize = Integer.MIN_VALUE; } else { fetchSize = DEFAULT_FETCH_SIZE; } } return findOptions().fetchSize(fetchSize); }
ROLE_ACTOR_ROLETYPE, type), EntityOperator.AND); final EntityFindOptions findOptions = new EntityFindOptions(); findOptions.setDistinct(true); listIterator = ofBizDelegator.findListIteratorByCondition(ROLE_ACTOR_ENTITY_NAME, condition, null, ImmutableList.of(ROLE_ACTOR_PID), null, findOptions);
@VisibleForTesting EntityListIterator createEntityListIterator(final SQLProcessor sqlP, final String sql, final EntityFindOptions nonNullFindOptions, final ModelEntity modelEntity, final List<ModelField> selectFields, final List<EntityConditionParam> whereEntityConditionParams, final List<EntityConditionParam> havingEntityConditionParams, final TableCleanUp tableCleanUp) throws GenericEntityException { try { // A data base connection is open when the call to prepareStatement is done (SQLProcessor's constructor does not open the connection) sqlP.prepareStatement(sql, nonNullFindOptions.isCustomResultSetTypeAndConcurrency(), nonNullFindOptions.getResultSetType(), nonNullFindOptions.getResultSetConcurrency()); bindParameterValues(sqlP, modelEntity, whereEntityConditionParams, "where"); bindParameterValues(sqlP, modelEntity, havingEntityConditionParams, "having"); setFetchSize(sqlP, nonNullFindOptions.getFetchSize()); sqlP.executeQuery(); //If we have any temporary tables they can be dropped after the list iterator is closed if (tableCleanUp == null) { return new EntityListIterator(sqlP, modelEntity, selectFields, modelFieldTypeReader); } else { return new EntityListIteratorWithTemporaryTableCleanup(sqlP, modelEntity, selectFields, modelFieldTypeReader, tableCleanUp); } } // The returned EntityListIterator must contain an SQLProcessor with an open connection to the database. // That's why the SQLProcessor only gets closed when an exception is thrown and the EntityListIterator // can't be correctly created, instead of closing it on a finally block. catch (GenericEntityException | RuntimeException e) { closeSafely(sql, sqlP); throw e; } }
/** * Creates a new {@link EntityFindOptions}. This is equivalent to the * {@link #EntityFindOptions() default constructor}, but is implemented as * a static method so that it can be used more conveniently by other * classes that {@code static import} it. * <p> * Example: * <code><pre> * import org.ofbiz.core.entity.EntityFindOptions; * import static org.ofbiz.core.entity.EntityFindOptions.findOptions; * * [...] * { * EntityFindOptions options = findOptions().distinct().maxEntries(5); * [...] * } * </pre></code> * </p> * * @return the new options */ @SuppressWarnings("unused") public static EntityFindOptions findOptions() { return new EntityFindOptions(); }
final List<String> orderBy, final String lockFieldName, final Transformation transformation) throws GenericEntityException { final EntityFindOptions findOptions = EntityFindOptions.findOptions(); final ModelField lockField = modelEntity.getField(lockFieldName); try {
distinct = false; } else { distinct = findOptions.getDistinct();
if (findOptions == null) findOptions = new EntityFindOptions(); StringBuffer sqlBuffer = new StringBuffer("SELECT "); if (findOptions.getDistinct()) { sqlBuffer.append("DISTINCT "); sqlP.prepareStatement(sql, findOptions.getSpecifyTypeAndConcur(), findOptions.getResultSetType(), findOptions.getResultSetConcurrency()); if (verboseOn) {
try rows = ofBizDelegator.findListIteratorByCondition(entityName, null, null, null, null, EntityFindOptions.findOptions().fetchSize(1)); for (GenericValue row : rows)
EntityFindOptions findOptions = new EntityFindOptions(); findOptions.setDistinct(true); listIterator = delegator.findListIteratorByCondition("Issue", condition, null, asList(IssueFieldConstants.STATUS), null, findOptions); GenericValue statusIdGV = listIterator.next();
return null; final EntityFindOptions nonNullFindOptions = findOptions == null ? new EntityFindOptions() : findOptions;
@Override public boolean hasUnassignedIssues() { OfBizListIterator unassignedIssuesIt = ofBizDelegator.findListIteratorByCondition(Entity.Name.ISSUE, new EntityFieldMap(unassignedCondition, EntityOperator.EQUALS), null, of("id"), of("id"), findOptions().maxResults(1)); try { return unassignedIssuesIt.next() != null; } finally { unassignedIssuesIt.close(); } }
@Override public HealthStatus check() { // any SELECT will do, as long as we hit the database. try { final OfBizListIterator rows = ofBizDelegator.findListIteratorByCondition(ENTITY_NAME, null, null, null, null, EntityFindOptions.findOptions().fetchSize(1)); try { for (final GenericValue row : rows) { // make sure we consume all the results to keep all db drivers happy log.trace("addHealthCheckInfo: select from {} limit 1: {}", ENTITY_NAME, row); } } finally { rows.close(); } return healthStatusFactory.healthy(); } catch (DataAccessException e) { return healthStatusFactory.failed(e.getMessage()); } } }
final StringBuilder sqlBuilder = new StringBuilder("SELECT "); if (findOptions.getDistinct()) { sqlBuilder.append("DISTINCT "); if (findOptions.getMaxResults() > 0) { sql = limitHelper.addLimitClause(sql, selectFields, findOptions.getOffset(), findOptions.getMaxResults());
EntityFindOptions entityFindOptions = new EntityFindOptions(); entityFindOptions.setDistinct(true);
entityCondition = new EntityConditionList(entityConditions, EntityOperator.AND); EntityFindOptions findOptions = new EntityFindOptions(); findOptions.setOffset(query.getStartIndex()); if (query.getMaxResults() >= 0) findOptions.setMaxResults(query.getMaxResults());