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

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

Introduction

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

Prototype

ResultHandler

Source Link

Usage

From source file:com.ibatis.sqlmap.engine.impl.SqlMapSessionImpl.java

License:Apache License

public void queryWithRowHandler(final String id, final Object parameterObject, final RowHandler rowHandler)
        throws SQLException {
    transactionManager.doInTransaction(new TransactionScope() {
        public Object execute(Transaction transaction) throws SQLException {
            MappedStatement ms = configuration.getMappedStatement(id);
            Executor executor = transaction.getExecutor();
            return executor.query(ms, wrapCollection(parameterObject), RowBounds.DEFAULT, new ResultHandler() {
                public void handleResult(ResultContext context) {
                    rowHandler.handleRow(context.getResultObject());
                }/* w  w w.  ja  va  2s.  co  m*/
            });
        }
    });
}

From source file:org.alfresco.repo.domain.node.ibatis.NodeDAOImpl.java

License:Open Source License

@Override
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;
    }/*  w w  w . j a va  2 s  . c  om*/
    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;
}

From source file:org.alfresco.repo.domain.node.ibatis.NodeDAOImpl.java

License:Open Source License

@Override
public List<NodePropertyEntity> selectNodePropertiesByTypes(Set<QName> qnames) {
    final List<NodePropertyEntity> properties = new ArrayList<NodePropertyEntity>();

    // qnames of properties that are encrypted
    Set<Long> qnameIds = qnameDAO.convertQNamesToIds(qnames, false);
    if (qnameIds.size() > 0) {
        IdsEntity param = new IdsEntity();
        param.setIds(new ArrayList<Long>(qnameIds));
        // TODO - use a callback approach
        template.select(SELECT_PROPERTIES_BY_TYPES, param, new ResultHandler() {
            @Override/* w ww  .j a v a  2  s. c  o  m*/
            public void handleResult(ResultContext context) {
                properties.add((NodePropertyEntity) context.getResultObject());
            }
        });
    }

    return properties;
}

From source file:org.alfresco.repo.domain.node.ibatis.NodeDAOImpl.java

License:Open Source License

@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);/*w ww .j a v a 2 s.co m*/
    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;
}

From source file:org.alfresco.repo.domain.node.ibatis.NodeDAOImpl.java

License:Open Source License

@Override
protected void selectNodesWithAspects(List<Long> qnameIds, Long minNodeId, Long maxNodeId,
        final NodeRefQueryCallback resultsCallback) {
    ResultHandler resultHandler = new ResultHandler() {
        public void handleResult(ResultContext context) {
            NodeEntity entity = (NodeEntity) context.getResultObject();
            Pair<Long, NodeRef> nodePair = new Pair<Long, NodeRef>(entity.getId(), entity.getNodeRef());
            resultsCallback.handle(nodePair);
        }//from   w  w w  . ja v  a 2  s.com
    };

    IdsEntity parameters = new IdsEntity();
    parameters.setIdOne(minNodeId);
    parameters.setIdTwo(maxNodeId);
    parameters.setIds(qnameIds);
    template.select(SELECT_NODES_WITH_ASPECT_IDS, parameters, resultHandler);
}

From source file:org.alfresco.repo.domain.patch.ibatis.PatchDAOImpl.java

License:Open Source License

@Override
public List<Pair<NodeRef, String>> getNodesOfTypeWithNamePattern(QName typeQName, String namePattern) {
    Pair<Long, QName> typeQNamePair = qnameDAO.getQName(typeQName);
    if (typeQNamePair == null) {
        // No point querying
        return Collections.emptyList();
    }//w  w  w. jav  a 2  s .com
    Long typeQNameId = typeQNamePair.getFirst();

    Pair<Long, QName> propQNamePair = qnameDAO.getQName(ContentModel.PROP_NAME);
    if (propQNamePair == null) {
        return Collections.emptyList();
    }
    Long propQNameId = propQNamePair.getFirst();

    Map<String, Object> params = new HashMap<String, Object>();
    params.put("typeQNameId", typeQNameId);
    params.put("propQNameId", propQNameId);
    params.put("namePattern", namePattern);

    final List<Pair<NodeRef, String>> results = new ArrayList<Pair<NodeRef, String>>(500);
    ResultHandler resultHandler = new ResultHandler() {
        @SuppressWarnings("unchecked")
        public void handleResult(ResultContext context) {
            Map<String, Object> row = (Map<String, Object>) context.getResultObject();
            String protocol = (String) row.get("protocol");
            String identifier = (String) row.get("identifier");
            String uuid = (String) row.get("uuid");
            NodeRef nodeRef = new NodeRef(new StoreRef(protocol, identifier), uuid);
            String name = (String) row.get("name");
            Pair<NodeRef, String> pair = new Pair<NodeRef, String>(nodeRef, name);
            results.add(pair);
        }
    };
    template.select(SELECT_NODES_BY_TYPE_AND_NAME_PATTERN, params, resultHandler);
    return results;
}

From source file:org.alfresco.repo.domain.patch.ibatis.PatchDAOImpl.java

License:Open Source License

@Override
public List<NodeRef> getChildrenOfTheSharedSurfConfigFolder(Long minNodeId, Long maxNodeId) {
    Pair<Long, QName> containsAssocQNamePair = qnameDAO.getQName(ContentModel.ASSOC_CONTAINS);
    if (containsAssocQNamePair == null) {
        return Collections.emptyList();
    }// w ww. j  ava2 s . com

    Map<String, Object> params = new HashMap<String, Object>(7);

    // Get qname CRC
    Long qnameCrcSites = ChildAssocEntity.getQNameCrc(QName.createQName(SiteModel.SITE_MODEL_URL, "sites"));
    Long qnameCrcSurfConfig = ChildAssocEntity
            .getQNameCrc(QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "surf-config"));
    Long qnameCrcPages = ChildAssocEntity
            .getQNameCrc(QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "pages"));
    Long qnameCrcUser = ChildAssocEntity
            .getQNameCrc(QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "user"));

    params.put("qnameCrcSites", qnameCrcSites);
    params.put("qnameCrcSurfConfig", qnameCrcSurfConfig);
    params.put("qnameCrcPages", qnameCrcPages);
    params.put("qnameCrcUser", qnameCrcUser);
    params.put("qnameTypeIdContains", containsAssocQNamePair.getFirst());
    params.put("minNodeId", minNodeId);
    params.put("maxNodeId", maxNodeId);

    final List<NodeRef> results = new ArrayList<NodeRef>(1000);
    ResultHandler resultHandler = new ResultHandler() {
        @SuppressWarnings("unchecked")
        public void handleResult(ResultContext context) {
            Map<String, Object> row = (Map<String, Object>) context.getResultObject();
            String protocol = (String) row.get("protocol");
            String identifier = (String) row.get("identifier");
            String uuid = (String) row.get("uuid");
            NodeRef nodeRef = new NodeRef(new StoreRef(protocol, identifier), uuid);
            results.add(nodeRef);
        }
    };
    template.select(SELECT_CHILDREN_OF_THE_SHARED_SURFCONFIG_FOLDER, params, resultHandler);
    return results;
}

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

License:Open Source License

@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);
        }/*from  w w  w .  j  a  v  a2 s. c o m*/
    };
    // 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
}

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

License:Open Source License

@Override
protected void getPropertyUniqueContextByValues(final PropertyUniqueContextCallback callback,
        Long... valueIds) {//from ww w .  j  av a2s .c  o  m
    PropertyUniqueContextEntity entity = new PropertyUniqueContextEntity();
    for (int i = 0; i < valueIds.length; i++) {
        switch (i) {
        case 0:
            entity.setValue1PropId(valueIds[i]);
            break;
        case 1:
            entity.setValue2PropId(valueIds[i]);
            break;
        case 2:
            entity.setValue3PropId(valueIds[i]);
            break;
        default:
            throw new IllegalArgumentException("Only 3 ids allowed");
        }
    }

    ResultHandler valueResultHandler = new ResultHandler() {
        public void handleResult(ResultContext context) {
            PropertyUniqueContextEntity result = (PropertyUniqueContextEntity) context.getResultObject();

            Long id = result.getId();
            Long propId = result.getPropertyId();
            Serializable[] keys = new Serializable[3];
            keys[0] = result.getValue1PropId();
            keys[1] = result.getValue2PropId();
            keys[2] = result.getValue3PropId();

            callback.handle(id, propId, keys);
        }
    };

    template.select(SELECT_PROPERTY_UNIQUE_CTX_BY_VALUES, entity, valueResultHandler);
    // Done
}

From source file:org.solmix.datax.mybatis.MybatisDataService.java

License:Open Source License

protected DSResponse executeFetch(DSRequest req, SqlSession session, DataSource dataSource)
        throws DSCallException {
    DSResponse res = new DSResponseImpl(req, Status.STATUS_SUCCESS);
    String mybatisStatement = getMybatisStatement(req);

    Pageable pageable = req.getAttachment(Pageable.class);
    boolean paged = false;
    if (DataTools.isPaged(pageable)) {
        paged = true;// ww w .  j ava 2s .  com
    }
    Object parameter = null;
    if (paged) {

        // initial SqlDriver for limit & count sql
        if (defaultDialect == null) {
            try {
                defaultDialect = SQLDialectFactory.getInstance().getSQLDialect(dataSource);
            } catch (Exception e) {
                throw new DSCallException("Can't instance SQLDialect for datasource:" + dataSource, e);
            }
        }
        parameter = new PagedParameter(req, res, req.getRawValues(), defaultDialect, session,
                req.getAttachment(Pageable.class));
    } else {
        parameter = req.getRawValues();
    }
    final List<Object> results = new ArrayList<Object>();
    // log start time
    long _$ = System.currentTimeMillis();
    session.select(mybatisStatement, parameter, new ResultHandler() {

        @Override
        public void handleResult(ResultContext context) {
            results.add(context.getResultObject());
        }
    });
    // fire time event.
    if (isEventEnable()) {
        createAndFireTimeMonitorEvent((System.currentTimeMillis() - _$),
                "SQL  query statement [" + mybatisStatement + "],params [" + req.getRawValues()
                        + "] Query total rows: " + results.size());
    }
    res.setRawData(results);
    if (paged) {
        Pageable page = req.getAttachment(Pageable.class);
        int start = page.getStartRow();
        int end = start + results.size();
        page.setEndRow(end);
        res.addAttachment(Pageable.class, page);
    }
    return res;
}