@Test public void testDistinct() { DistinctIterable<String> distinct = coll.distinct("color", String.class); List<String> strList = toDocumentList(distinct); assertEquals(6, strList.size()); assertTrue(strList.contains("Red")); distinct = coll.distinct("color", Filters.eq("name", "Alto"), String.class); strList = toDocumentList(distinct); assertEquals(4, strList.size()); assertTrue(strList.contains("Red")); }
@Override public <TResult> DistinctIterable<TResult> distinct(String fieldName, Class<TResult> arg1) { DistinctIterable<TResult> find = collection.distinct(fieldName, arg1); ProfiledDistinctIterable<TDocument, TResult> profiledFindIterable = new ProfiledDistinctIterable<TDocument, TResult>( find, fieldName, this); return profiledFindIterable; }
@Override public <TResult> DistinctIterable<TResult> distinct(String arg0, Bson filter, Class<TResult> arg2) { DistinctIterable<TResult> find = collection.distinct(arg0, filter, arg2); ProfiledDistinctIterable<TDocument, TResult> profiledFindIterable = new ProfiledDistinctIterable<TDocument, TResult>( find, arg0, this); profiledFindIterable.filter(filter); return profiledFindIterable; }
public ProfiledDistinctIterable(DistinctIterable<TResult> findIterable, String fieldName, ProfiledMongoCollection<TDocument> collection) { super(); this.distinctIterable = findIterable; this.fieldName = fieldName; this.collection = collection; }
public DistinctIterable<TResult> getDistinceIterable() { return distinctIterable; }
public cfData execute( cfSession _session, cfArgStructData argStruct ) throws cfmRunTimeException { MongoDatabase db = getMongoDatabase( _session, argStruct ); String collection = getNamedStringParam( argStruct, "collection", null ); if ( collection == null ) throwException( _session, "please specify a collection" ); String key = getNamedStringParam( argStruct, "key", null ); if ( key == null ) throwException( _session, "please specify a key" ); cfData query = getNamedParam( argStruct, "query", null ); try { DistinctIterable<String> result; if ( query != null ) result = db.getCollection( collection ).distinct( key, String.class ).filter( getDocument( query ) ); else result = db.getCollection( collection ).distinct( key, String.class ); cfArrayData arr = cfArrayData.createArray( 1 ); result.forEach( new Block<String>() { @Override public void apply( final String st ) { try { arr.addElement( new cfStringData( st ) ); } catch ( cfmRunTimeException e ) {} } } ); return arr; } catch ( MongoException me ) { throwException( _session, me.getMessage() ); return null; } }
<T extends IEntity, RESULT> DistinctIterable<RESULT> distinct(Class<T> entity, Class<RESULT> resultClass, String fieldName) throws Exception;
<T extends IEntity, RESULT> DistinctIterable<RESULT> distinct(Class<T> entity, Class<RESULT> resultClass, String fieldName, Query query) throws Exception;