You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@usergrid.apache.org by sn...@apache.org on 2014/03/11 15:22:10 UTC
[05/50] [abbrv] git commit: Strip down the Results class to bare
essentials.
Strip down the Results class to bare essentials.
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/c3789125
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/c3789125
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/c3789125
Branch: refs/pull/52/merge
Commit: c37891253e6dff3d38c056cd2a359fe8dacefb49
Parents: cc0b774
Author: Dave Johnson <dm...@apigee.com>
Authored: Mon Mar 10 13:30:08 2014 -0400
Committer: Dave Johnson <dm...@apigee.com>
Committed: Mon Mar 10 13:30:08 2014 -0400
----------------------------------------------------------------------
.../index/impl/EsEntityCollectionIndex.java | 16 +-
.../usergrid/persistence/query/Query.java | 52 +-
.../usergrid/persistence/query/Results.java | 875 +------------------
.../index/impl/EntityCollectionIndexTest.java | 2 +-
.../persistence/index/impl/IndexIT.java | 6 +-
5 files changed, 41 insertions(+), 910 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c3789125/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityCollectionIndex.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityCollectionIndex.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityCollectionIndex.java
index 1cb474d..441dfd9 100644
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityCollectionIndex.java
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityCollectionIndex.java
@@ -290,11 +290,9 @@ public class EsEntityCollectionIndex implements EntityCollectionIndex {
SearchHits hits = searchResponse.getHits();
log.debug(" Hit count: {} Total hits: {}", hits.getHits().length, hits.getTotalHits() );
- Results results = new Results();
-
// TODO: do we always want to fetch entities? When do we fetch refs or ids?
// list of entities that will be returned
- List<Entity> entities = new ArrayList<Entity>();
+ List<Id> ids = new ArrayList<Id>();
for (SearchHit hit : hits.getHits()) {
@@ -315,19 +313,13 @@ public class EsEntityCollectionIndex implements EntityCollectionIndex {
log.debug(" Stale hit " + hit.getId());
} else {
- entities.add( entity );
+ ids.add( entityId );
}
}
- if ( entities.size() == 1 ) {
- results.setEntity(entities.get(0));
-
- } else {
- log.debug(" Returning " + entities.size() + " entities");
- results.setEntities(entities);
- }
+ Results results = new Results( manager, query, ids );
- if ( entities.size() == query.getLimit() ) {
+ if ( ids.size() == query.getLimit() ) {
results.setCursor(searchResponse.getScrollId());
log.debug(" Cursor = " + searchResponse.getScrollId() );
}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c3789125/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/Query.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/Query.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/Query.java
index 1feb56a..c82ff3b 100644
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/Query.java
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/Query.java
@@ -41,7 +41,6 @@ import org.apache.usergrid.persistence.exceptions.PersistenceException;
import org.apache.usergrid.persistence.exceptions.QueryParseException;
import org.apache.usergrid.persistence.index.impl.EsQueryVistor;
import org.apache.usergrid.persistence.model.entity.Id;
-import org.apache.usergrid.persistence.query.Results.Level;
import org.apache.usergrid.persistence.query.tree.AndOperand;
import org.apache.usergrid.persistence.query.tree.ContainsOperand;
import org.apache.usergrid.persistence.query.tree.Equal;
@@ -79,7 +78,7 @@ public class Query {
public static final int DEFAULT_LIMIT = 10;
public static final int MAX_LIMIT = 1000;
- public static final String PROPERTY_Id = "uuid";
+ public static final String PROPERTY_ID = "id";
private String type;
private List<SortPredicate> sortPredicates = new ArrayList<SortPredicate>();
@@ -90,7 +89,6 @@ public class Query {
private Map<String, String> selectAssignments = new LinkedHashMap<String, String>();
private boolean mergeSelectResults = false;
- private Level level = Level.ALL_PROPERTIES;
private String connection;
private List<String> permissions;
private boolean reversed;
@@ -118,7 +116,6 @@ public class Query {
selectAssignments = q.selectAssignments != null
? new LinkedHashMap<String, String>( q.selectAssignments ) : null;
mergeSelectResults = q.mergeSelectResults;
- level = q.level;
connection = q.connection;
permissions = q.permissions != null ? new ArrayList<String>( q.permissions ) : null;
reversed = q.reversed;
@@ -389,48 +386,6 @@ public class Query {
}
- @JsonIgnore
- boolean isIdsOnly() {
- if ( ( selectAssignments.size() == 1 ) && selectAssignments.containsKey( PROPERTY_Id ) ) {
- level = Level.IDS;
- return true;
- }
- return false;
- }
-
-
- private void setIdsOnly( boolean idsOnly ) {
- if ( idsOnly ) {
- selectAssignments = new LinkedHashMap<String, String>();
- selectAssignments.put( PROPERTY_Id, PROPERTY_Id );
- level = Level.IDS;
- }
- else if ( isIdsOnly() ) {
- selectAssignments = new LinkedHashMap<String, String>();
- level = Level.ALL_PROPERTIES;
- }
- }
-
-
- public Level getResultsLevel() {
- isIdsOnly();
- return level;
- }
-
-
- public void setResultsLevel( Level level ) {
- setIdsOnly( level == Level.IDS );
- this.level = level;
- }
-
-
- public Query withResultsLevel( Level level ) {
- setIdsOnly( level == Level.IDS );
- this.level = level;
- return this;
- }
-
-
public Query withReversed( boolean reversed ) {
setReversed( reversed );
return this;
@@ -1040,11 +995,6 @@ public class Query {
return type;
}
-
- public Level getLevel() {
- return level;
- }
-
public static final String PARAM_QL = "ql";
public static final String PARAM_Q = "q";
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c3789125/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/Results.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/Results.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/Results.java
index 86d775d..2dd3101 100644
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/Results.java
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/query/Results.java
@@ -19,188 +19,35 @@ package org.apache.usergrid.persistence.query;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.Iterator;
-import java.util.LinkedHashMap;
-import java.util.LinkedHashSet;
import java.util.List;
-import java.util.ListIterator;
-import java.util.Map;
-import java.util.Set;
import javax.xml.bind.annotation.XmlRootElement;
+import org.apache.usergrid.persistence.collection.EntityCollectionManager;
+import org.apache.usergrid.persistence.exceptions.IndexException;
import org.codehaus.jackson.map.annotate.JsonSerialize;
import org.codehaus.jackson.map.annotate.JsonSerialize.Inclusion;
-import static org.apache.usergrid.persistence.query.SimpleEntityRef.ref;
import org.apache.usergrid.persistence.model.entity.Entity;
import org.apache.usergrid.persistence.model.entity.Id;
-import static org.apache.usergrid.utils.ClassUtils.cast;
@XmlRootElement
public class Results implements Iterable<Entity> {
- public enum Level {
- IDS, REFS, ALL_PROPERTIES
- }
-
- Level level = Level.REFS;
- Id id;
- List<Id> ids;
- Set<Id> idSet;
-
- EntityRef ref;
- List<EntityRef> refs;
- Map<Id, EntityRef> refsMap;
- Map<String, List<EntityRef>> refsByType;
-
- Entity entity;
- List<Entity> entities;
- Map<Id, Entity> entitiesMap;
- Map<String, List<Entity>> entitiesByType;
-
- Set<String> types;
-
- Map<Id, Map<String, Object>> metadata;
- boolean metadataMerged = true;
-
- Id nextResult;
- String cursor;
-
- Query query;
- Object data;
- String dataName;
-
-
- public Results() {
- }
-
-
- public Results( Results r ) {
- if ( r != null ) {
- level = r.level;
-
- id = r.id;
- ids = r.ids;
- idSet = r.idSet;
-
- ref = r.ref;
- refs = r.refs;
- refsMap = r.refsMap;
- refsByType = r.refsByType;
-
- entity = r.entity;
- entities = r.entities;
- entitiesMap = r.entitiesMap;
- entitiesByType = r.entitiesByType;
-
- types = r.types;
-
- nextResult = r.nextResult;
- cursor = r.cursor;
-
- query = r.query;
- data = r.data;
- dataName = r.dataName;
- }
- }
-
-
- public void init() {
- level = Level.IDS;
-
- id = null;
- ids = null;
- idSet = null;
-
- ref = null;
- refs = null;
- refsMap = null;
- refsByType = null;
-
- entity = null;
- entities = null;
- entitiesMap = null;
- entitiesByType = null;
-
- types = null;
-
- // metadata = null;
- metadataMerged = false;
-
- query = null;
- data = null;
- dataName = null;
- }
-
-
- public static Results fromIdList( List<Id> l ) {
- Results r = new Results();
- r.setIds( l );
- return r;
- }
-
-
- public static Results fromIdList( List<Id> l, String type ) {
- if ( type == null ) {
- return fromIdList( l );
- }
- List<EntityRef> refs = new ArrayList<EntityRef>();
- for ( Id u : l ) {
- refs.add( ref( u ) );
- }
- Results r = new Results();
- r.setRefs( refs );
- return r;
- }
-
-
- public static Results fromId( Id id ) {
- Results r = new Results();
- if ( id != null ) {
- List<Id> l = new ArrayList<Id>();
- l.add( id );
- r.setIds( l );
- }
- return r;
- }
-
-
- public static Results fromRefList( List<EntityRef> l ) {
- Results r = new Results();
- r.setRefs( l );
- return r;
- }
-
+ final List<Id> ids;
+ final Query query;
+ final EntityCollectionManager ecm;
- public static Results fromEntities( List<? extends Entity> l ) {
- Results r = new Results();
- r.setEntities( l );
- return r;
- }
+ String cursor = null;
+ List<Entity> entities = null;
+ List<EntityRef> refs = null;
-
- public static Results fromEntity( Entity e ) {
- Results r = new Results();
- r.setEntity( e );
- return r;
- }
-
-
- public static Results fromRef( EntityRef ref ) {
- if ( ref instanceof Entity ) {
- return fromEntity( ( Entity ) ref );
- }
- Results r = new Results();
- r.setRef( ref );
- return r;
- }
-
-
- public static Results fromData( Object obj ) {
- Results r = new Results();
- r.setData( obj );
- return r;
+ public Results( EntityCollectionManager ecm, Query query, List<Id> ids ) {
+ this.ecm = ecm;
+ this.query = query;
+ this.ids = ids;
}
@@ -219,719 +66,61 @@ public class Results implements Iterable<Entity> {
}
- public Level getLevel() {
- return level;
- }
-
-
@JsonSerialize(include = Inclusion.NON_NULL)
public Query getQuery() {
return query;
}
- public void setQuery( Query query ) {
- this.query = query;
- }
-
-
- public Results withQuery( Query query ) {
- this.query = query;
- return this;
- }
-
-
- @JsonSerialize(include = Inclusion.NON_NULL)
- public Id getId() {
- if ( id != null ) {
- return id;
- }
- if ( entity != null ) {
- id = entity.getId();
- return id;
- }
- if ( ( ids != null ) && ( ids.size() > 0 ) ) {
- id = ids.get( 0 );
- return id;
- }
- if ( ( entities != null ) && ( entities.size() > 0 ) ) {
- entity = entities.get( 0 );
- id = entity.getId();
- return id;
- }
- if ( ( refs != null ) && ( refs.size() > 0 ) ) {
- EntityRef ref = refs.get( 0 );
- id = ref.getId();
- }
- return id;
- }
-
-
@JsonSerialize(include = Inclusion.NON_NULL)
public List<Id> getIds() {
-
- if ( ids != null ) {
- return ids;
- }
-
- if ( ( entities != null )) {
- ids = new ArrayList<Id>();
- for ( Entity entity : entities ) {
- ids.add( entity.getId() );
- }
- return ids;
- }
- if ( refs != null ) {
- ids = new ArrayList<Id>();
- for ( EntityRef ref : refs ) {
- ids.add( ref.getId() );
- }
- return ids;
- }
- if ( id != null ) {
- ids = new ArrayList<Id>();
- ids.add( id );
- return ids;
- }
- if ( entity != null ) {
- ids = new ArrayList<Id>();
- ids.add( entity.getId() );
- return ids;
- }
- return new ArrayList<Id>();
- }
-
-
- public void setIds( List<Id> resultsIds ) {
- init();
- ids = resultsIds;
- level = Level.IDS;
- }
-
-
- public Results withIds( List<Id> resultsIds ) {
- setIds( resultsIds );
- return this;
- }
-
-
- @JsonSerialize(include = Inclusion.NON_NULL)
- public Set<Id> getIdSet() {
- if ( idSet != null ) {
- return idSet;
- }
- getIds();
- if ( ids != null ) {
- idSet = new LinkedHashSet<Id>();
- idSet.addAll( ids );
- return idSet;
- }
- return new LinkedHashSet<Id>();
+ return Collections.unmodifiableList( ids );
}
@JsonSerialize(include = Inclusion.NON_NULL)
@SuppressWarnings("unchecked")
public List<EntityRef> getRefs() {
- if ( refs != null ) {
- return refs;
- }
- List<?> l = getEntities();
- if ( ( l != null ) && ( l.size() > 0 ) ) {
- return ( List<EntityRef> ) l;
- }
- if ( ref != null ) {
- refs = new ArrayList<EntityRef>();
- refs.add( ref );
- return refs;
- }
- return new ArrayList<EntityRef>();
- }
-
-
- public void setRefs( List<EntityRef> resultsRefs ) {
- init();
- refs = resultsRefs;
- level = Level.REFS;
- }
-
-
- public Results withRefs( List<EntityRef> resultsRefs ) {
- setRefs( resultsRefs );
- return this;
- }
-
-
- public void setRef( EntityRef ref ) {
- init();
- this.ref = ref;
- level = Level.REFS;
- }
-
-
- public Results withRef( EntityRef ref ) {
- setRef( ref );
- return this;
- }
-
-
- @JsonSerialize(include = Inclusion.NON_NULL)
- public EntityRef getRef() {
- if ( ref != null ) {
- return ref;
- }
- Entity e = getEntity();
- if ( e != null ) {
- return ref( e.getId(), e.getVersion() );
- }
- Id u = getId();
- if ( u != null ) {
- return ref( u );
- }
- return null;
- }
-
-
- @JsonSerialize(include = Inclusion.NON_NULL)
- public Map<Id, EntityRef> getRefsMap() {
- if ( refsMap != null ) {
- return refsMap;
- }
- getEntitiesMap();
- if ( entitiesMap != null ) {
- refsMap = cast( entitiesMap );
- return refsMap;
- }
- getRefs();
- if ( refs != null ) {
- refsMap = new LinkedHashMap<Id, EntityRef>();
- for ( EntityRef ref : refs ) {
- refsMap.put( ref.getId(), ref );
- }
- }
- return refsMap;
- }
-
- public Entity getEntity() {
- return entity;
- }
-
- public void setEntity( Entity resultEntity ) {
- init();
- entity = resultEntity;
- level = Level.ALL_PROPERTIES;
- }
-
-
- public Results withEntity( Entity resultEntity ) {
- setEntity( resultEntity );
- return this;
- }
-
-
- public Iterator<Id> idIterator() {
- List<Id> l = getIds();
- if ( l != null ) {
- return l.iterator();
+ if ( entities == null ) {
+ getEntities();
}
- return ( new ArrayList<Id>( 0 ) ).iterator();
+ return Collections.unmodifiableList( refs );
}
@JsonSerialize(include = Inclusion.NON_NULL)
public List<Entity> getEntities() {
- if ( entities != null ) {
- return entities;
- }
- if ( entity != null ) {
- entities = new ArrayList<Entity>();
- entities.add( entity );
- return entities;
- }
- return new ArrayList<Entity>();
- }
-
-
- @JsonSerialize(include = Inclusion.NON_NULL)
- public Map<Id, Entity> getEntitiesMap() {
- if ( entitiesMap != null ) {
- return entitiesMap;
- }
- if ( entities != null ) {
- entitiesMap = new LinkedHashMap<Id, Entity>();
- for ( Entity entity : entities ) {
- entitiesMap.put( entity.getId(), entity );
- }
- }
- return entitiesMap;
- }
-
-
- public List<EntityRef> getEntityRefsByType( String type ) {
- if ( entitiesByType != null ) {
- return refsByType.get( type );
- }
- List<EntityRef> l = cast( getEntitiesByType( type ) );
- if ( l != null ) {
- return l;
- }
- getRefs();
- if ( refs == null ) {
- return null;
- }
- refsByType = new LinkedHashMap<String, List<EntityRef>>();
- for ( Entity entity : entities ) {
- l = refsByType.get( entity.getId().getType() );
- if ( l == null ) {
- l = new ArrayList<EntityRef>();
- refsByType.put( entity.getId().getType(), l );
- }
- l.add( ref( entity.getId(), entity.getVersion() ));
- }
- return l;
- }
-
-
- public List<Entity> getEntitiesByType( String type ) {
- if ( entitiesByType != null ) {
- return entitiesByType.get( type );
- }
- getEntities();
if ( entities == null ) {
- return null;
- }
- List<Entity> l = null;
- entitiesByType = new LinkedHashMap<String, List<Entity>>();
- for ( Entity entity : entities ) {
- l = entitiesByType.get( entity.getId().getType() );
- if ( l == null ) {
- l = new ArrayList<Entity>();
- entitiesByType.put( entity.getId().getType(), l );
- }
- l.add( entity );
- }
- return l;
- }
-
-
- @JsonSerialize(include = Inclusion.NON_NULL)
- public Set<String> getTypes() {
- if ( types != null ) {
- return types;
- }
- getEntityRefsByType( "entity" );
- if ( entitiesByType != null ) {
- types = entitiesByType.keySet();
- }
- else if ( refsByType != null ) {
- types = refsByType.keySet();
- }
- return types;
- }
-
-
- public void merge( Results results ) {
- getEntitiesMap();
- results.getEntitiesMap();
- if ( entitiesMap != null || results.entitiesMap != null ) {
-
- level = Level.ALL_PROPERTIES;
-
- // do nothing, nothing to union
- if ( entitiesMap != null && results.entitiesMap == null ) {
- return;
- // other side has the results, assign and return
- }
- else if ( entitiesMap == null && results.entitiesMap != null ) {
- entities = results.entities;
- return;
- }
-
- entitiesMap.putAll( results.entitiesMap );
- entities = new ArrayList<Entity>( entitiesMap.values() );
-
- return;
- }
-
- getRefsMap();
- results.getRefsMap();
- if ( ( refsMap != null ) || ( results.refsMap != null ) ) {
-
- level = Level.REFS;
-
- // do nothing, nothing to union
- if ( refsMap != null && results.refsMap == null ) {
- return;
- // other side has the results, assign and return
- }
- else if ( refsMap == null && results.refsMap != null ) {
- refs = results.refs;
- return;
- }
-
- refsMap.putAll( results.refsMap );
- refs = new ArrayList<EntityRef>( refsMap.values() );
-
- return;
- }
-
- getIdSet();
- results.getIdSet();
- if ( ( idSet != null ) && ( results.idSet != null ) ) {
-
- level = Level.IDS;
-
- // do nothing, nothing to union
- if ( idSet != null && results.idSet == null ) {
- return;
- // other side has the results, assign and return
- }
- else if ( idSet == null && results.idSet != null ) {
- ids = results.ids;
- return;
- }
-
- idSet.addAll( results.idSet );
- ids = new ArrayList<Id>( idSet );
-
- return;
- }
- }
-
-
- /** Remove the passed in results from the current results */
- public void subtract( Results results ) {
- getEntitiesMap();
- results.getEntitiesMap();
-
- if ( ( entitiesMap != null ) && ( results.entitiesMap != null ) ) {
- Map<Id, Entity> newMap = new LinkedHashMap<Id, Entity>();
- for ( Map.Entry<Id, Entity> e : entitiesMap.entrySet() ) {
- if ( !results.entitiesMap.containsKey( e.getKey() ) ) {
- newMap.put( e.getKey(), e.getValue() );
- }
- }
- entitiesMap = newMap;
- entities = new ArrayList<Entity>( entitiesMap.values() );
- level = Level.ALL_PROPERTIES;
- return;
- }
-
- getRefsMap();
- results.getRefsMap();
- if ( ( refsMap != null ) && ( results.refsMap != null ) ) {
- Map<Id, EntityRef> newMap = new LinkedHashMap<Id, EntityRef>();
- for ( Map.Entry<Id, EntityRef> e : refsMap.entrySet() ) {
- if ( !results.refsMap.containsKey( e.getKey() ) ) {
- newMap.put( e.getKey(), e.getValue() );
- }
- }
- refsMap = newMap;
- refs = new ArrayList<EntityRef>( refsMap.values() );
- level = Level.REFS;
- return;
- }
-
- getIdSet();
- results.getIdSet();
- if ( ( idSet != null ) && ( results.idSet != null ) ) {
- Set<Id> newSet = new LinkedHashSet<Id>();
- for ( Id uuid : idSet ) {
- if ( !results.idSet.contains( uuid ) ) {
- newSet.add( uuid );
- }
- }
- idSet = newSet;
- ids = new ArrayList<Id>( idSet );
- level = Level.IDS;
- return;
- }
- }
-
-
- /** Perform an intersection of the 2 results */
- public void and( Results results ) {
- getEntitiesMap();
- results.getEntitiesMap();
-
- if ( ( entitiesMap != null ) && ( results.entitiesMap != null ) ) {
- Map<Id, Entity> newMap = new LinkedHashMap<Id, Entity>();
- for ( Map.Entry<Id, Entity> e : entitiesMap.entrySet() ) {
- if ( results.entitiesMap.containsKey( e.getKey() ) ) {
- newMap.put( e.getKey(), e.getValue() );
- }
- }
- entitiesMap = newMap;
- entities = new ArrayList<Entity>( entitiesMap.values() );
- level = Level.ALL_PROPERTIES;
- return;
- }
-
- getRefsMap();
- results.getRefsMap();
- if ( ( refsMap != null ) && ( results.refsMap != null ) ) {
- Map<Id, EntityRef> newMap = new LinkedHashMap<Id, EntityRef>();
- for ( Map.Entry<Id, EntityRef> e : refsMap.entrySet() ) {
- if ( results.refsMap.containsKey( e.getKey() ) ) {
- newMap.put( e.getKey(), e.getValue() );
- }
- }
- refsMap = newMap;
- refs = new ArrayList<EntityRef>( refsMap.values() );
- level = Level.REFS;
- ids = null;
- return;
- }
-
- getIdSet();
- results.getIdSet();
- if ( ( idSet != null ) && ( results.idSet != null ) ) {
- Set<Id> newSet = new LinkedHashSet<Id>();
- for ( Id uuid : idSet ) {
- if ( results.idSet.contains( uuid ) ) {
- newSet.add( uuid );
- }
- }
- idSet = newSet;
- ids = new ArrayList<Id>( idSet );
- level = Level.IDS;
- return;
- }
-
- // should be empty
- init();
- }
-
-
- public void replace( Entity entity ) {
- entitiesMap = null;
- if ( ( this.entity != null ) && ( this.entity.getId().equals( entity.getId() ) ) ) {
- this.entity = entity;
- }
- if ( entities != null ) {
- ListIterator<Entity> i = entities.listIterator();
- while ( i.hasNext() ) {
- Entity e = i.next();
- if ( e.getId().equals( entity.getId() ) ) {
- i.set( entity );
- }
- }
- }
- }
-
-
- public Results startingFrom( Id entityId ) {
- if ( entities != null ) {
- for ( int i = 0; i < entities.size(); i++ ) {
- Entity entity = entities.get( i );
- if ( entityId.equals( entity.getId() ) ) {
- if ( i == 0 ) {
- return this;
- }
- return Results.fromEntities( entities.subList( i, entities.size() ) );
- }
- }
- }
- if ( refs != null ) {
- for ( int i = 0; i < refs.size(); i++ ) {
- EntityRef entityRef = refs.get( i );
- if ( entityId.equals( entityRef.getId() ) ) {
- if ( i == 0 ) {
- return this;
- }
- return Results.fromRefList( refs.subList( i, refs.size() ) );
- }
- }
- }
- if ( ids != null ) {
- for ( int i = 0; i < ids.size(); i++ ) {
- Id uuid = ids.get( i );
- if ( entityId.equals( uuid ) ) {
- if ( i == 0 ) {
- return this;
- }
- return Results.fromIdList( ids.subList( i, ids.size() ) );
+ entities = new ArrayList<Entity>();
+ refs = new ArrayList<EntityRef>();
+ for ( Id id : ids ) {
+ Entity entity = ecm.load( id ).toBlockingObservable().last();
+ if (entity == null) {
+ throw new IndexException("Entity id [" + id + "] not found");
}
+ entities.add( entity );
+ refs.add( new SimpleEntityRef( entity.getId(), entity.getVersion() ));
}
}
- return this;
+ return Collections.unmodifiableList( entities );
}
- @SuppressWarnings("unchecked")
- @JsonSerialize(include = Inclusion.NON_NULL)
- public <E extends Entity> List<E> getList() {
- List<Entity> l = getEntities();
- return ( List<E> ) l;
+ public int size() {
+ return ids.size();
}
- public <E extends Entity> Iterator<E> iterator( Class<E> cls ) {
- List<E> l = getList();
- if ( l != null ) {
- return l.iterator();
- }
- return ( new ArrayList<E>( 0 ) ).iterator();
+ public boolean isEmpty() {
+ return ids.isEmpty();
}
@Override
public Iterator<Entity> iterator() {
- List<Entity> l = null; // getEntities();
- if ( l != null ) {
- return l.iterator();
- }
- return ( new ArrayList<Entity>( 0 ) ).iterator();
- }
-
-
- public Results findForProperty( String propertyName, Object propertyValue ) {
- return findForProperty( propertyName, propertyValue, 1 );
+ return getEntities().iterator();
}
-
- public Results findForProperty( String propertyName, Object propertyValue, int count ) {
- if ( propertyValue == null ) {
- return new Results();
- }
- List<Entity> l = getEntities();
- if ( l == null ) {
- return new Results();
- }
- List<Entity> found = new ArrayList<Entity>();
- for ( Entity e : l ) {
- if ( propertyValue.equals( e.getField( propertyName ).getValue() ) ) {
- found.add( e );
- if ( ( count > 0 ) && ( found.size() == count ) ) {
- break;
- }
- }
- }
- return Results.fromEntities( found );
- }
-
-
- @SuppressWarnings("unchecked")
- public void setEntities( List<? extends Entity> resultsEntities ) {
- init();
- entities = ( List<Entity> ) resultsEntities;
- level = Level.ALL_PROPERTIES;
+ public void setIds(List<Id> ids) {
}
-
-
- public Results withEntities( List<? extends Entity> resultsEntities ) {
- setEntities( resultsEntities );
- return this;
- }
-
-
-
- @JsonSerialize(include = Inclusion.NON_NULL)
- public Object getObject() {
- if ( data != null ) {
- return data;
- }
- if ( entities != null ) {
- return entities;
- }
- if ( ids != null ) {
- return ids;
- }
- if ( entity != null ) {
- return entity;
- }
- if ( id != null ) {
- return id;
- }
- return null;
- }
-
-
- @JsonSerialize(include = Inclusion.NON_NULL)
- public String getObjectName() {
- if ( dataName != null ) {
- return dataName;
- }
- if ( entities != null ) {
- return "entities";
- }
- if ( ids != null ) {
- return "ids";
- }
- if ( entity != null ) {
- return "entity";
- }
- if ( id != null ) {
- return "id";
- }
- return null;
- }
-
-
- public void setDataName( String dataName ) {
- this.dataName = dataName;
- }
-
-
- public Results withDataName( String dataName ) {
- this.dataName = dataName;
- return this;
- }
-
-
- public boolean hasData() {
- return data != null;
- }
-
-
- public void setData( Object data ) {
- this.data = data;
- }
-
-
- public Results withData( Object data ) {
- this.data = data;
- return this;
- }
-
-
- @JsonSerialize(include = Inclusion.NON_NULL)
- public Object getData() {
- return data;
- }
-
- public int size() {
- if ( entities != null ) {
- return entities.size();
- }
- if ( refs != null ) {
- return refs.size();
- }
- if ( ids != null ) {
- return ids.size();
- }
- if ( entity != null ) {
- return 1;
- }
- if ( ref != null ) {
- return 1;
- }
- if ( id != null ) {
- return 1;
- }
- return 0;
- }
-
-
- public boolean isEmpty() {
- return size() == 0;
- }
-
-
- @JsonSerialize(include = Inclusion.NON_NULL)
- public Id getNextResult() {
- return nextResult;
- }
-
-
}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c3789125/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/EntityCollectionIndexTest.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/EntityCollectionIndexTest.java b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/EntityCollectionIndexTest.java
index 18f5ac4..e951098 100644
--- a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/EntityCollectionIndexTest.java
+++ b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/EntityCollectionIndexTest.java
@@ -163,7 +163,7 @@ public class EntityCollectionIndexTest {
timer.stop();
if ( num == 1 ) {
- assertNotNull( results.getEntity() != null );
+ assertNotNull( results.getEntities().get(0) != null );
} else {
assertEquals( num, results.getEntities().size() );
}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c3789125/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/IndexIT.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/IndexIT.java b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/IndexIT.java
index d49392f..9bfae05 100644
--- a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/IndexIT.java
+++ b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/IndexIT.java
@@ -267,14 +267,14 @@ public class IndexIT {
LOG.info( JsonUtils.mapToFormattedJsonString( r.getEntities() ) );
assertEquals( 1, r.size() );
- long created = r.getEntity().getId().getUuid().timestamp();
- Id entityId = r.getEntity().getId();
+ long created = r.getEntities().get(0).getId().getUuid().timestamp();
+ Id entityId = r.getEntities().get(0).getId();
query = Query.fromQL( "created = " + created );
r = em.searchCollection( em.getApplicationRef(), "items", query );
LOG.info( JsonUtils.mapToFormattedJsonString( r.getEntities() ) );
assertEquals( 1, r.size() );
- assertEquals( entityId, r.getEntity().getId() );
+ assertEquals( entityId, r.getEntities().get(0).getId() );
}
@Test