Example usage for org.apache.ibatis.session RowBounds RowBounds

List of usage examples for org.apache.ibatis.session RowBounds RowBounds

Introduction

In this page you can find the example usage for org.apache.ibatis.session RowBounds RowBounds.

Prototype

public RowBounds(int offset, int limit) 

Source Link

Usage

From source file:org.alfresco.repo.domain.permissions.ibatis.AclCrudDAOImpl.java

License:Open Source License

@SuppressWarnings("unchecked")
@Override//www.j av  a 2s  .  co m
protected List<Long> getADMNodeEntityIdsByAcl(long aclEntityId, int maxResults) {
    if (maxResults < 0) {
        maxResults = RowBounds.NO_ROW_LIMIT;
    }

    Map<String, Object> params = new HashMap<String, Object>(1);
    params.put("id", aclEntityId);

    return template.selectList(SELECT_ADM_NODES_BY_ACL, params, new RowBounds(0, maxResults));
}

From source file:org.alfresco.repo.domain.permissions.ibatis.AclCrudDAOImpl.java

License:Open Source License

@Override
protected Long selectMaxChangeSetIdBeforeCommitTime(long maxCommitTime) {
    Assert.notNull(maxCommitTime, "maxCommitTime");

    Map<String, Object> params = new HashMap<String, Object>(1);
    params.put("commit_time_ms", maxCommitTime);

    List<Long> sets = template.selectList(SELECT_CHANGE_SET_LAST, params, new RowBounds(0, 1));
    if (sets.size() > 0) {
        return sets.get(0);
    } else {/*  w  w w . j a v a2  s  .co m*/
        return null;
    }
}

From source file:org.alfresco.repo.domain.propval.ibatis.PropertyValueDAOImpl.java

License:Open Source License

@Override
protected Long findStringValueByValue(String value) {
    PropertyStringValueEntity entity = new PropertyStringValueEntity();
    entity.setValue(value);/*from w  ww.j  a  va2 s .  c o m*/
    List<Long> rows = template.selectList(SELECT_PROPERTY_STRING_VALUE_BY_VALUE, entity, new RowBounds(0, 1));
    // The CRC match prevents incorrect results from coming back.  Although there could be
    // several matches, we are sure that the matches are case-sensitive.
    if (rows.size() > 0) {
        return rows.get(0);
    } else {
        return null;
    }
}

From source file:org.alfresco.repo.domain.propval.ibatis.PropertyValueDAOImpl.java

License:Open Source License

@Override
protected PropertyDoubleValueEntity findDoubleValueByValue(Double value) {
    PropertyDoubleValueEntity entity = new PropertyDoubleValueEntity();
    entity.setDoubleValue(value);//from   w  w  w  . j  av a  2  s. c o m
    List<PropertyDoubleValueEntity> results = template.selectList(SELECT_PROPERTY_DOUBLE_VALUE_BY_VALUE, entity,
            new RowBounds(0, 1));
    // There could be several matches, so just get one
    if (results.size() > 0) {
        return results.get(0);
    } else {
        // No match
        return null;
    }
}

From source file:org.alfresco.repo.domain.query.ibatis.CannedQueryDAOImpl.java

License:Open Source License

@SuppressWarnings("unchecked")
@Override//from w  w  w  . j  a  v a2s  .c  o  m
public <R> List<R> executeQuery(String sqlNamespace, String queryName, Object parameterObj, int offset,
        int limit) {
    if (offset < 0 || offset == Integer.MAX_VALUE) {
        throw new IllegalArgumentException("Query result offset must be zero or greater.");
    }

    if (limit <= 0) {
        throw new IllegalArgumentException("Query results limit must be greater than zero.");
    }

    String query = makeQueryName(sqlNamespace, queryName);
    try {
        List<R> result;
        if ((offset == 0) && (limit == Integer.MAX_VALUE)) {
            result = (List<R>) template.selectList(query, parameterObj);
        } else {
            RowBounds bounds = new RowBounds(offset, limit);
            result = (List<R>) template.selectList(query, parameterObj, bounds);
        }

        // Done
        if (logger.isDebugEnabled()) {
            logger.debug("Executed query: \n" + "   Query:  " + query + "\n" + "   Params: " + parameterObj
                    + "\n" + "   Result: " + result);
        }
        return result;
    } catch (ClassCastException e) {
        throw new IllegalArgumentException("Return type of query does not match expected type.", e);
    } catch (Throwable e) {
        throw new QueryException("Failed to execute query: \n" + "   Namespace: " + sqlNamespace + "\n"
                + "   queryName: " + queryName + "\n" + "   Parameter: " + parameterObj + "\n"
                + "   Offset:    " + offset + "\n" + "   Limit:     " + limit, e);
    }
}

From source file:org.alfresco.repo.domain.query.ibatis.CannedQueryDAOImpl.java

License:Open Source License

@Override
public <R> void executeQuery(String sqlNamespace, String queryName, Object parameterObj, int offset, int limit,
        ResultHandler<R> handler) {
    if (offset < 0 || offset == Integer.MAX_VALUE) {
        throw new IllegalArgumentException("Query result offset must be zero or greater.");
    }/*  w w w. j a  v  a2s  .co m*/

    if (limit <= 0) {
        throw new IllegalArgumentException("Query results limit must be greater than zero.");
    }

    String query = makeQueryName(sqlNamespace, queryName);
    ResultHandlerTranslator<R> resultHandler = new ResultHandlerTranslator<R>(handler);
    try {
        if ((offset == 0) && (limit == Integer.MAX_VALUE)) {
            template.select(query, parameterObj, resultHandler);
        } else {
            RowBounds bounds = new RowBounds(offset, limit);
            template.select(query, parameterObj, bounds, resultHandler);
        }
    } catch (ClassCastException e) {
        throw new IllegalArgumentException("Return type of query does not match expected type.", e);
    } catch (Throwable e) {
        throw new QueryException("Failed to execute query: \n" + "   Namespace: " + sqlNamespace + "\n"
                + "   queryName: " + queryName + "\n" + "   Parameter: " + parameterObj + "\n"
                + "   Offset:    " + offset + "\n" + "   Limit:     " + limit, e);
    }
}

From source file:org.alfresco.repo.domain.solr.ibatis.SOLRDAOImpl.java

License:Open Source License

/**
 * {@inheritDoc}//from  w w w  .java 2  s  .  c o m
 */
@Override
@SuppressWarnings("unchecked")
public List<AclChangeSet> getAclChangeSets(Long minAclChangeSetId, Long fromCommitTime, Long maxAclChangeSetId,
        Long toCommitTime, int maxResults) {
    if (maxResults <= 0 || maxResults == Integer.MAX_VALUE) {
        throw new IllegalArgumentException("Maximum results must be a reasonable number.");
    }

    // We simulate an ID for the sys:deleted type
    Pair<Long, QName> deletedTypeQNamePair = qnameDAO.getQName(ContentModel.TYPE_DELETED);
    Long deletedTypeQNameId = deletedTypeQNamePair == null ? -1L : deletedTypeQNamePair.getFirst();

    SOLRTrackingParameters params = new SOLRTrackingParameters(deletedTypeQNameId);
    params.setFromIdInclusive(minAclChangeSetId);
    params.setFromCommitTimeInclusive(fromCommitTime);
    params.setToIdExclusive(maxAclChangeSetId);
    params.setToCommitTimeExclusive(toCommitTime);

    return template.selectList(SELECT_CHANGESETS_SUMMARY, params, new RowBounds(0, maxResults));
}

From source file:org.alfresco.repo.domain.solr.ibatis.SOLRDAOImpl.java

License:Open Source License

/**
 * {@inheritDoc}/*from w ww . ja va 2s.c o m*/
 */
@Override
@SuppressWarnings("unchecked")
public List<Acl> getAcls(List<Long> aclChangeSetIds, Long minAclId, int maxResults) {

    if (aclChangeSetIds == null || aclChangeSetIds.size() == 0) {
        throw new IllegalArgumentException("'aclChangeSetIds' must contain IDs.");
    }
    if (aclChangeSetIds.size() > 512) {
        throw new IllegalArgumentException("'aclChangeSetIds' cannot have more than 512 entries.");
    }

    // We simulate an ID for the sys:deleted type
    Pair<Long, QName> deletedTypeQNamePair = qnameDAO.getQName(ContentModel.TYPE_DELETED);
    Long deletedTypeQNameId = deletedTypeQNamePair == null ? -1L : deletedTypeQNamePair.getFirst();

    SOLRTrackingParameters params = new SOLRTrackingParameters(deletedTypeQNameId);
    params.setIds(aclChangeSetIds);
    params.setFromIdInclusive(minAclId);

    List<Acl> source;
    if (maxResults <= 0 || maxResults == Integer.MAX_VALUE) {
        source = template.selectList(SELECT_ACLS_BY_CHANGESET_IDS, params);
    } else {
        source = template.selectList(SELECT_ACLS_BY_CHANGESET_IDS, params, new RowBounds(0, maxResults));
    }
    // Add any unlinked shared ACLs from defining nodes to index them now
    TreeSet<Acl> sorted = new TreeSet<Acl>(source);
    HashSet<Long> found = new HashSet<Long>();
    for (Acl acl : source) {
        found.add(acl.getId());
    }

    for (Acl acl : source) {
        if (acl.getInheritedId() != null) {
            if (!found.contains(acl.getInheritedId())) {
                AclEntity shared = new AclEntity();
                shared.setId(acl.getInheritedId());
                shared.setAclChangeSetId(acl.getAclChangeSetId());
                shared.setInheritedId(acl.getInheritedId());
                sorted.add(shared);
            }
        }
    }

    ArrayList<Acl> answer = new ArrayList<Acl>();
    answer.addAll(sorted);
    return answer;
}

From source file:org.alfresco.repo.domain.solr.ibatis.SOLRDAOImpl.java

License:Open Source License

/**
 * {@inheritDoc}//  www  . j  av a  2 s.  co m
 */
@Override
@SuppressWarnings("unchecked")
public List<Transaction> getTransactions(Long minTxnId, Long fromCommitTime, Long maxTxnId, Long toCommitTime,
        int maxResults) {
    if (maxResults <= 0 || maxResults == Integer.MAX_VALUE) {
        throw new IllegalArgumentException("Maximum results must be a reasonable number.");
    }

    // We simulate an ID for the sys:deleted type
    Pair<Long, QName> deletedTypeQNamePair = qnameDAO.getQName(ContentModel.TYPE_DELETED);
    Long deletedTypeQNameId = deletedTypeQNamePair == null ? -1L : deletedTypeQNamePair.getFirst();

    SOLRTrackingParameters params = new SOLRTrackingParameters(deletedTypeQNameId);
    params.setFromIdInclusive(minTxnId);
    params.setFromCommitTimeInclusive(fromCommitTime);
    params.setToIdExclusive(maxTxnId);
    params.setToCommitTimeExclusive(toCommitTime);

    return template.selectList(SELECT_TRANSACTIONS, params, new RowBounds(0, maxResults));
}

From source file:org.alfresco.repo.domain.solr.ibatis.SOLRDAOImpl.java

License:Open Source License

/**
 * {@inheritDoc}//from  w  w  w .j  a  v  a2s  .c o  m
 */
@SuppressWarnings("unchecked")
public List<Node> getNodes(NodeParameters nodeParameters, QName shardPropertyQName) {
    NodeParametersEntity params = new NodeParametersEntity(nodeParameters, qnameDAO);

    if (shardPropertyQName != null) {
        if (shardPropertyQName.equals(ContentModel.PROP_CREATED)) {
            params.setShardPropertyQNameId(-1L);
        } else if (shardPropertyQName.equals(ContentModel.PROP_MODIFIED)) {
            params.setShardPropertyQNameId(-2L);
        } else {
            Pair<Long, QName> propertyQNamePair = qnameDAO.getQName(shardPropertyQName);
            if (propertyQNamePair != null) {
                params.setShardPropertyQNameId(propertyQNamePair.getFirst());
            }
        }
    }

    if (nodeParameters.getMaxResults() != 0 && nodeParameters.getMaxResults() != Integer.MAX_VALUE) {
        return template.selectList(SELECT_NODES, params, new RowBounds(0, nodeParameters.getMaxResults()));
    } else {
        return template.selectList(SELECT_NODES, params);
    }
}