All Downloads are FREE. Search and download functionalities are using the official Maven repository.

br.com.anteros.nosql.persistence.mongodb.query.MongoKeyIterator Maven / Gradle / Ivy

There is a newer version: 1.0.6
Show newest version
package br.com.anteros.nosql.persistence.mongodb.query;

import java.util.Iterator;

import org.bson.Document;

import com.mongodb.DBObject;

import br.com.anteros.nosql.persistence.converters.Key;
import br.com.anteros.nosql.persistence.session.NoSQLSession;
import br.com.anteros.nosql.persistence.session.mapping.AbstractNoSQLObjectMapper;


public class MongoKeyIterator extends MongoIterator> {
 
    public MongoKeyIterator(final NoSQLSession session, final Iterator cursor, final AbstractNoSQLObjectMapper mapper,
                              final Class clazz, final String collection) {
        super(session, cursor, mapper, clazz, collection, null);
    }

    @Override
    protected Key convertItem(final Document dbObj) throws Exception {
        Object id = dbObj.get(AbstractNoSQLObjectMapper.ID_KEY);
        if (id instanceof DBObject) {
        	
            Class type = getSession().getDescriptionEntityManager().getDescriptionEntity(getClazz()).getDescriptionIdField().getType();
            id = getMapper().fromDocument(getSession(), type, (DBObject) id, getMapper().createEntityCache());
        }
        return new Key(getClazz(), getCollection(), id);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy