diff --git a/src/com/massivecraft/mcore/store/Coll.java b/src/com/massivecraft/mcore/store/Coll.java index cc78583a..1189804a 100644 --- a/src/com/massivecraft/mcore/store/Coll.java +++ b/src/com/massivecraft/mcore/store/Coll.java @@ -87,7 +87,15 @@ public class Coll implements CollInterface // STORAGE // -------------------------------------------- // + // All + protected Set ids; + + // Loaded protected Map id2entity; + protected Map entity2id; + + @Override public Collection getIds() { return Collections.unmodifiableCollection(this.ids); } + @Override public Map getId2entity() { return Collections.unmodifiableMap(this.id2entity); } @Override public E get(Object oid) @@ -109,23 +117,25 @@ public class Coll implements CollInterface return this.create(id, noteChange); } - @Override public Collection getIds() { return Collections.unmodifiableCollection(this.id2entity.keySet()); } + @Override public Collection getIdsLoaded() { return Collections.unmodifiableCollection(this.id2entity.keySet()); } @Override public Collection getIdsRemote() { return this.getDb().getDriver().getIds(this); } @Override public boolean containsId(Object oid) { String id = this.fixId(oid); if (id == null) return false; - return this.id2entity.containsKey(id); + return this.ids.contains(id); } - // Get the id for this entity. - protected Map entity2id; @Override public Map getEntity2id() { return Collections.unmodifiableMap(this.entity2id); } @Override public String getId(Object entity) { return this.entity2id.get(entity); } @Override public boolean containsEntity(Object entity) { return this.entity2id.containsKey(entity); }; - @Override public Collection getAll() { return Collections.unmodifiableCollection(this.entity2id.keySet()); } + @Override public Collection getAll() + { + + return Collections.unmodifiableCollection(this.entity2id.keySet()); + } @Override public Collection getAll(Predictate where) { return MStoreUtil.uglySQL(this.getAll(), where, null, null, null); } @Override public Collection getAll(Predictate where, Comparator orderby) { return MStoreUtil.uglySQL(this.getAll(), where, orderby, null, null); } @Override public Collection getAll(Predictate where, Comparator orderby, Integer limit) { return MStoreUtil.uglySQL(this.getAll(), where, orderby, limit, null); } @@ -302,6 +312,7 @@ public class Coll implements CollInterface } // Attach + this.ids.add(id); this.id2entity.put(id, entity); this.entity2id.put(entity, id); @@ -461,6 +472,8 @@ public class Coll implements CollInterface this.entity2id.remove(entity); + this.ids.remove(id); + // Remove entity reference info if (entity instanceof Entity) { @@ -726,7 +739,7 @@ public class Coll implements CollInterface // Compile a list of all ids (both remote and local) Set allids = new HashSet(); allids.addAll(id2RemoteMtime.keySet()); - allids.addAll(this.id2entity.keySet()); + allids.addAll(this.ids); // Check for modifications for (String id : allids) @@ -785,6 +798,7 @@ public class Coll implements CollInterface this.collDriverObject = db.getCollDriverObject(this); // STORAGE + this.ids = new ConcurrentSkipListSet(idComparator); this.id2entity = new ConcurrentSkipListMap(idComparator); this.entity2id = new ConcurrentSkipListMap(entityComparator); diff --git a/src/com/massivecraft/mcore/store/CollInterface.java b/src/com/massivecraft/mcore/store/CollInterface.java index 5d184c2f..5094dc7a 100644 --- a/src/com/massivecraft/mcore/store/CollInterface.java +++ b/src/com/massivecraft/mcore/store/CollInterface.java @@ -33,8 +33,9 @@ public interface CollInterface public Map getId2entity(); public E get(Object oid); public E get(Object oid, boolean creative); - public Collection getIds(); - public Collection getIdsRemote(); + public Collection getIds(); // All ideas we know of whether they are loaded or not + public Collection getIdsRemote(); // All remote ids loaded sync via driver + public Collection getIdsLoaded(); // All locally loaded ids public boolean containsId(Object oid); public Map getEntity2id();