Java Code Examples for org.apache.ibatis.session.ResultContext#getResultObject()

The following examples show how to use org.apache.ibatis.session.ResultContext#getResultObject() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NodeDAOImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
protected void selectNodesWithAspects(
        List<Long> qnameIds,
        Long minNodeId, Long maxNodeId,
        final NodeRefQueryCallback resultsCallback)
{
    @SuppressWarnings("rawtypes")
    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);
        }
    };
    
    IdsEntity parameters = new IdsEntity();
    parameters.setIdOne(minNodeId);
    parameters.setIdTwo(maxNodeId);
    parameters.setIds(qnameIds);
    template.select(SELECT_NODES_WITH_ASPECT_IDS, parameters, resultHandler);
}
 
Example 2
Source File: PairResultHandler.java    From BlogManagePlatform with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public void handleResult(ResultContext<? extends Object> resultContext) {
	Object object = resultContext.getResultObject();
	if (Map.class.isAssignableFrom(object.getClass())) {
		Map<String, Object> map = (Map<String, Object>) object;
		Object key = context.key.resolve(map.get("key"));
		Object value = context.value.resolve(map.get("value"));
		Pair<?, ?> pair = new Pair<>(key, value);
		many.add(pair);
	}
}
 
Example 3
Source File: CommonPropertyDeferLoadError.java    From mybatis with Apache License 2.0 5 votes vote down vote up
@Test
public void testDeferLoadDuringResultHandlerWithLazyLoad() {
    SqlSession sqlSession = lazyLoadSqlSessionFactory.openSession();
    try {
        class MyResultHandler implements ResultHandler {
            public void handleResult(ResultContext context) {
                Child child = (Child)context.getResultObject();
                assertNotNull(child.getFather());
            }
        };
        sqlSession.select("org.apache.ibatis.submitted.deferload_common_property.ChildMapper.selectAll", new MyResultHandler());
    } finally {
        sqlSession.close();
    }
}
 
Example 4
Source File: CommonPropertyDeferLoadError.java    From mybatis with Apache License 2.0 5 votes vote down vote up
@Test
public void testDeferLoadDuringResultHandler() {
    SqlSession sqlSession = sqlSessionFactory.openSession();
    try {
        class MyResultHandler implements ResultHandler {
            public void handleResult(ResultContext context) {
                Child child = (Child)context.getResultObject();
                assertNotNull(child.getFather());
            }
        };
        sqlSession.select("org.apache.ibatis.submitted.deferload_common_property.ChildMapper.selectAll", new MyResultHandler());
    } finally {
        sqlSession.close();
    }
}
 
Example 5
Source File: PropertyValueDAOImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
@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
}
 
Example 6
Source File: DefaultMapResultHandler.java    From mybatis with Apache License 2.0 5 votes vote down vote up
@Override
public void handleResult(ResultContext context) {
  // TODO is that assignment always true?
  //得到一条记录
  //这边黄色警告没法去掉了?因为返回Object型
  final V value = (V) context.getResultObject();
  //MetaObject.forObject,包装一下记录
  //MetaObject是用反射来包装各种类型
  final MetaObject mo = MetaObject.forObject(value, objectFactory, objectWrapperFactory);
  // TODO is that assignment always true?
  final K key = (K) mo.getValue(mapKey);
  mappedResults.put(key, value);
  //这个类主要目的是把得到的List转为Map
}
 
Example 7
Source File: NodeDAOImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
@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;
}
 
Example 8
Source File: RollupResultHandler.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void handleResult(ResultContext context)
{
    // Shortcut if we have processed enough results
    if (maxResults > 0 && resultCount >= maxResults)
    {
        return;
    }
    
    Object valueObject = context.getResultObject();
    MetaObject probe = configuration.newMetaObject(valueObject);
    
    // Check if the key has changed
    if (lastKeyValues == null)
    {
        lastKeyValues = getKeyValues(probe);
        resultCount = 0;
    }
    // Check if it has changed
    Object[] currentKeyValues = getKeyValues(probe);
    if (!Arrays.deepEquals(lastKeyValues, currentKeyValues))
    {
        // Key has changed, so handle the results
        Object resultObject = coalesceResults(configuration, rawResults, collectionProperty);
        if (resultObject != null)
        {
            DefaultResultContext resultContext = new DefaultResultContext();
            resultContext.nextResultObject(resultObject);
            
            resultHandler.handleResult(resultContext);
            resultCount++;
        }
        rawResults.clear();
        lastKeyValues = currentKeyValues;
    }
    // Add the new value to the results for next time
    rawResults.add(valueObject);
    // Done
}
 
Example 9
Source File: DefaultMapResultHandler.java    From mybaties with Apache License 2.0 5 votes vote down vote up
@Override
public void handleResult(ResultContext context) {
  // TODO is that assignment always true?
  //得到一条记录
  //这边黄色警告没法去掉了?因为返回Object型
  final V value = (V) context.getResultObject();
  //MetaObject.forObject,包装一下记录
  //MetaObject是用反射来包装各种类型
  final MetaObject mo = MetaObject.forObject(value, objectFactory, objectWrapperFactory);
  // TODO is that assignment always true?
  final K key = (K) mo.getValue(mapKey);
  mappedResults.put(key, value);
  //这个类主要目的是把得到的List转为Map
}
 
Example 10
Source File: CommonPropertyDeferLoadError.java    From mybaties with Apache License 2.0 5 votes vote down vote up
@Test
public void testDeferLoadDuringResultHandler() {
    SqlSession sqlSession = sqlSessionFactory.openSession();
    try {
        class MyResultHandler implements ResultHandler {
            public void handleResult(ResultContext context) {
                Child child = (Child)context.getResultObject();
                assertNotNull(child.getFather());
            }
        };
        sqlSession.select("org.apache.ibatis.submitted.deferload_common_property.ChildMapper.selectAll", new MyResultHandler());
    } finally {
        sqlSession.close();
    }
}
 
Example 11
Source File: CommonPropertyDeferLoadError.java    From mybaties with Apache License 2.0 5 votes vote down vote up
@Test
public void testDeferLoadDuringResultHandlerWithLazyLoad() {
    SqlSession sqlSession = lazyLoadSqlSessionFactory.openSession();
    try {
        class MyResultHandler implements ResultHandler {
            public void handleResult(ResultContext context) {
                Child child = (Child)context.getResultObject();
                assertNotNull(child.getFather());
            }
        };
        sqlSession.select("org.apache.ibatis.submitted.deferload_common_property.ChildMapper.selectAll", new MyResultHandler());
    } finally {
        sqlSession.close();
    }
}
 
Example 12
Source File: AbstractCSVResultHandlerImplTest.java    From sinavi-jfw with Apache License 2.0 5 votes vote down vote up
@Override
public void write(ResultContext context) {
    MobilePhone d = (MobilePhone) context.getResultObject();
    SimpleDateFormat format = new SimpleDateFormat("yyyy/MM/dd");
    String[] data = new String[] {
        d.getTerminalId().toString(), d.getTerminalName(), format.format(d.getSalesDate()),
        d.getFlashLevel().toString(), d.getVersion().toString()
    };
    csv.write(data);
    count.incrementAndGet();
}
 
Example 13
Source File: UserResultHandler.java    From mybatis with Apache License 2.0 4 votes vote down vote up
@Override
public void handleResult(ResultContext context) {
  User user = (User) context.getResultObject();
  users.add(user);
}
 
Example 14
Source File: UserResultHandler.java    From mybaties with Apache License 2.0 4 votes vote down vote up
@Override
public void handleResult(ResultContext context) {
  User user = (User) context.getResultObject();
  users.add(user);
}
 
Example 15
Source File: PropertyValueDAOImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
protected void getPropertyUniqueContextByValues(final PropertyUniqueContextCallback callback, Long... valueIds)
{
    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
}
 
Example 16
Source File: PatchDAOImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public List<NodeRef> getChildrenOfTheSharedSurfConfigFolder(Long minNodeId, Long maxNodeId)
{
    Pair<Long, QName> containsAssocQNamePair = qnameDAO.getQName(ContentModel.ASSOC_CONTAINS);
    if (containsAssocQNamePair == null)
    {
        return Collections.emptyList();
    }
    
    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;
}
 
Example 17
Source File: PatchDAOImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
@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();
    }
    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;
}
 
Example 18
Source File: MyResultHandler.java    From blog with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public void handleResult(ResultContext<? extends Blog> resultContext) {
	Blog blog = resultContext.getResultObject();
	System.out.println(blog.toString());
	result.put(blog.getId(), blog);
}