Remove custom data in MStore

This commit is contained in:
Magnus Ulf 2015-05-15 14:34:29 +02:00 committed by Olof Larsson
parent 413f485e0c
commit dbb79ba297
4 changed files with 20 additions and 29 deletions

View File

@ -197,18 +197,7 @@ public class Coll<E> implements CollInterface<E>
return false; return false;
} }
} }
// This is used in parallel with the isDefault.
// Parallel usage is useful since we can then override isDeafult just like before.
public static boolean isCustomDataDefault(Object entity)
{
if (!(entity instanceof Entity)) return true;
JsonObject customData = ((Entity<?>)entity).getCustomData();
if (customData == null) return true;
if (customData.entrySet().size() == 0) return true;
return false;
}
// -------------------------------------------- // // -------------------------------------------- //
// COPY AND CREATE // COPY AND CREATE
// -------------------------------------------- // // -------------------------------------------- //
@ -225,7 +214,6 @@ public class Coll<E> implements CollInterface<E>
Entity eto = (Entity)oto; Entity eto = (Entity)oto;
eto.load(efrom); eto.load(efrom);
eto.setCustomData(efrom.getCustomData());
} }
else if (ofrom instanceof JsonObject) else if (ofrom instanceof JsonObject)
{ {
@ -450,7 +438,8 @@ public class Coll<E> implements CollInterface<E>
// -------------------------------------------- // // -------------------------------------------- //
// SYNCLOG // SYNCLOG
// -------------------------------------------- // // -------------------------------------------- //
// The strings are the ids.
protected Map<String, Long> lastMtime; protected Map<String, Long> lastMtime;
protected Map<String, JsonElement> lastRaw; protected Map<String, JsonElement> lastRaw;
protected Set<String> lastDefault; protected Set<String> lastDefault;
@ -547,7 +536,7 @@ public class Coll<E> implements CollInterface<E>
JsonElement raw = this.getGson().toJsonTree(entity, this.getEntityClass()); JsonElement raw = this.getGson().toJsonTree(entity, this.getEntityClass());
this.lastRaw.put(id, raw); this.lastRaw.put(id, raw);
if (this.isDefault(entity) && isCustomDataDefault(entity)) if (this.isDefault(entity))
{ {
this.getDb().delete(this, id); this.getDb().delete(this, id);
this.lastDefault.add(id); this.lastDefault.add(id);
@ -658,9 +647,9 @@ public class Coll<E> implements CollInterface<E>
{ {
// Fix Id // Fix Id
if (oid == null) throw new NullPointerException("oid"); if (oid == null) throw new NullPointerException("oid");
String id = this.fixId(oid); //String id = this.fixId(oid); // Was done twice
return this.examineId(id, null); return this.examineId(oid, null);
} }
@Override @Override
@ -684,6 +673,7 @@ public class Coll<E> implements CollInterface<E>
E localEntity = this.id2entity.get(id); E localEntity = this.id2entity.get(id);
if (remoteMtime == null) if (remoteMtime == null)
{ {
// TODO: This is slow
remoteMtime = this.getDb().getMtime(this, id); remoteMtime = this.getDb().getMtime(this, id);
} }

View File

@ -4,7 +4,6 @@ import com.massivecraft.massivecore.MassiveCore;
import com.massivecraft.massivecore.NaturalOrderComparator; import com.massivecraft.massivecore.NaturalOrderComparator;
import com.massivecraft.massivecore.store.accessor.Accessor; import com.massivecraft.massivecore.store.accessor.Accessor;
import com.massivecraft.massivecore.xlib.gson.Gson; import com.massivecraft.massivecore.xlib.gson.Gson;
import com.massivecraft.massivecore.xlib.gson.JsonObject;
/** /**
* Usage of this class is highly optional. You may persist anything. If you are * Usage of this class is highly optional. You may persist anything. If you are
@ -36,17 +35,6 @@ public abstract class Entity<E extends Entity<E>> implements Comparable<E>
return coll.getUniverse(); return coll.getUniverse();
} }
// -------------------------------------------- //
// CUSTOM DATA
// -------------------------------------------- //
// We offer custom data storage for all entities extending this class.
// Do you want to use this in your plugin?
// Make sure you don't overwrites some other plugins data!
private JsonObject customData = null;
public JsonObject getCustomData() { return this.customData; }
public void setCustomData(JsonObject customData) { this.customData = customData; }
// -------------------------------------------- // // -------------------------------------------- //
// ATTACH AND DETACH // ATTACH AND DETACH
// -------------------------------------------- // // -------------------------------------------- //

View File

@ -2,6 +2,10 @@ package com.massivecraft.massivecore.store;
public enum Modification public enum Modification
{ {
// -------------------------------------------- //
// ENUM
// -------------------------------------------- //
LOCAL_ALTER (true, true), LOCAL_ALTER (true, true),
LOCAL_ATTACH (true, true), LOCAL_ATTACH (true, true),
LOCAL_DETACH (true, true), LOCAL_DETACH (true, true),
@ -12,6 +16,10 @@ public enum Modification
UNKNOWN (false, false), UNKNOWN (false, false),
; ;
// -------------------------------------------- //
// FIELDS
// -------------------------------------------- //
private final boolean modified; private final boolean modified;
public boolean isModified() { return this.modified; } public boolean isModified() { return this.modified; }
@ -19,6 +27,10 @@ public enum Modification
public boolean isLocal() { return this.local; } public boolean isLocal() { return this.local; }
public boolean isRemote() { return this.local == false; } public boolean isRemote() { return this.local == false; }
// -------------------------------------------- //
// CONSTRUCT
// -------------------------------------------- //
private Modification(boolean modified, boolean local) private Modification(boolean modified, boolean local)
{ {
this.modified = modified; this.modified = modified;

View File

@ -128,6 +128,7 @@ public class SenderColl<E extends SenderEntity<E>> extends Coll<E> implements Se
// GET ALL ONLINE / OFFLINE // GET ALL ONLINE / OFFLINE
// -------------------------------------------- // // -------------------------------------------- //
// TODO: Stop mkaing a new predicate everytime.
public Collection<E> getAllOnline() public Collection<E> getAllOnline()
{ {
return this.getAll(new Predictate<E>() return this.getAll(new Predictate<E>()