Search in sources :

Example 31 with ResultHandler

use of org.apache.ibatis.session.ResultHandler in project alfresco-repository by Alfresco.

the class PropertyValueDAOImpl method findPropertiesByIds.

@Override
protected void findPropertiesByIds(List<Long> ids, final PropertyFinderCallback callback) {
    ResultHandler valueResultHandler = new ResultHandler() {

        public void handleResult(ResultContext context) {
            PropertyIdQueryResult result = (PropertyIdQueryResult) context.getResultObject();
            Long id = result.getPropId();
            // Make the serializable value
            List<PropertyIdSearchRow> rows = result.getPropValues();
            Serializable value = convertPropertyIdSearchRows(rows);
            callback.handleProperty(id, value);
        }
    };
    // A row handler to roll up individual rows
    Configuration configuration = template.getConfiguration();
    RollupResultHandler rollupResultHandler = new RollupResultHandler(configuration, KEY_COLUMNS_FINDBYIDS, "propValues", valueResultHandler);
    // Query using the IDs
    PropertyIdQueryParameter params = new PropertyIdQueryParameter();
    params.setRootPropIds(ids);
    template.select(SELECT_PROPERTIES_BY_IDS, params, rollupResultHandler);
    // Process any remaining results
    rollupResultHandler.processLastResults();
// Done
}
Also used : ResultContext(org.apache.ibatis.session.ResultContext) PropertyIdQueryResult(org.alfresco.repo.domain.propval.PropertyIdQueryResult) Serializable(java.io.Serializable) Configuration(org.apache.ibatis.session.Configuration) RollupResultHandler(org.alfresco.ibatis.RollupResultHandler) PropertyIdQueryParameter(org.alfresco.repo.domain.propval.PropertyIdQueryParameter) RollupResultHandler(org.alfresco.ibatis.RollupResultHandler) ResultHandler(org.apache.ibatis.session.ResultHandler) PropertyIdSearchRow(org.alfresco.repo.domain.propval.PropertyIdSearchRow)

Example 32 with ResultHandler

use of org.apache.ibatis.session.ResultHandler in project alfresco-repository by Alfresco.

the class NodeDAOImpl method getNodeIdsIntervalForType.

@Override
@SuppressWarnings("rawtypes")
public Pair<Long, Long> getNodeIdsIntervalForType(QName type, Long startTxnTime, Long endTxnTime) {
    final Pair<Long, Long> intervalPair = new Pair<Long, Long>(LONG_ZERO, LONG_ZERO);
    Pair<Long, QName> typePair = qnameDAO.getQName(type);
    if (typePair == null) {
        // Return default
        return intervalPair;
    }
    TransactionQueryEntity txnQuery = new TransactionQueryEntity();
    txnQuery.setTypeQNameId(typePair.getFirst());
    txnQuery.setMinCommitTime(startTxnTime);
    txnQuery.setMaxCommitTime(endTxnTime);
    ResultHandler resultHandler = new ResultHandler() {

        @SuppressWarnings("unchecked")
        public void handleResult(ResultContext context) {
            Map<Long, Long> result = (Map<Long, Long>) context.getResultObject();
            if (result != null) {
                intervalPair.setFirst(result.get("minId"));
                intervalPair.setSecond(result.get("maxId"));
            }
        }
    };
    template.select(SELECT_NODE_INTERVAL_BY_TYPE, txnQuery, resultHandler);
    return intervalPair;
}
Also used : ResultContext(org.apache.ibatis.session.ResultContext) DefaultResultContext(org.apache.ibatis.executor.result.DefaultResultContext) QName(org.alfresco.service.namespace.QName) TransactionQueryEntity(org.alfresco.repo.domain.node.TransactionQueryEntity) ResultHandler(org.apache.ibatis.session.ResultHandler) HashMap(java.util.HashMap) Map(java.util.Map) Pair(org.alfresco.util.Pair)

Example 33 with ResultHandler

use of org.apache.ibatis.session.ResultHandler in project alfresco-repository by Alfresco.

the class NodeDAOImpl method selectNodePropertiesByDataType.

@SuppressWarnings("rawtypes")
@Override
public List<NodePropertyEntity> selectNodePropertiesByDataType(QName dataType, long minNodeId, long maxNodeId) {
    int typeOrdinal = NodePropertyValue.convertToTypeOrdinal(dataType);
    IdsEntity ids = new IdsEntity();
    ids.setIdOne((long) typeOrdinal);
    ids.setIdTwo(minNodeId);
    ids.setIdThree(maxNodeId);
    final List<NodePropertyEntity> properties = new ArrayList<NodePropertyEntity>();
    template.select(SELECT_PROPERTIES_BY_ACTUAL_TYPE, ids, new ResultHandler() {

        @Override
        public void handleResult(ResultContext context) {
            properties.add((NodePropertyEntity) context.getResultObject());
        }
    });
    return properties;
}
Also used : ResultContext(org.apache.ibatis.session.ResultContext) DefaultResultContext(org.apache.ibatis.executor.result.DefaultResultContext) IdsEntity(org.alfresco.ibatis.IdsEntity) NodePropertyEntity(org.alfresco.repo.domain.node.NodePropertyEntity) ArrayList(java.util.ArrayList) ResultHandler(org.apache.ibatis.session.ResultHandler)

Aggregations

ResultHandler (org.apache.ibatis.session.ResultHandler)33 ResultContext (org.apache.ibatis.session.ResultContext)25 ArrayList (java.util.ArrayList)20 List (java.util.List)14 Test (org.junit.Test)13 SqlSession (org.apache.ibatis.session.SqlSession)10 RowBounds (org.apache.ibatis.session.RowBounds)8 Random (java.util.Random)7 Consumer (java.util.function.Consumer)7 RandomStringUtils.randomAlphabetic (org.apache.commons.lang.RandomStringUtils.randomAlphabetic)7 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)7 DataProvider (com.tngtech.java.junit.dataprovider.DataProvider)6 DataProviderRunner (com.tngtech.java.junit.dataprovider.DataProviderRunner)6 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)6 Arrays (java.util.Arrays)6 Date (java.util.Date)6 HashMap (java.util.HashMap)6 IntStream (java.util.stream.IntStream)6 Executor (org.apache.ibatis.executor.Executor)6 BoundSql (org.apache.ibatis.mapping.BoundSql)6