package act.db.morphia;

import org.bson.types.ObjectId;
import org.mongodb.morphia.annotations.Id;
import org.osgl.util.E;
import org.osgl.util.S;

/**
 * The default morphia model base implementation using {@link ObjectId} as the id type
 * @param <MODEL_TYPE>
 */
public abstract class MorphiaModel<MODEL_TYPE extends MorphiaModel> extends MorphiaModelBase<ObjectId, MODEL_TYPE> {

    @Id
    private ObjectId id;

    public MorphiaModel() {
    }

    public MorphiaModel(ObjectId id) {
        this.id = id;
    }

    public String getIdAsStr() {
        return null != id ? id.toString() : null;
    }

    public ObjectId _id() {
        return id;
    }

    @Override
    public MODEL_TYPE _id(ObjectId id) {
        E.illegalStateIf(null != this.id);
        this.id = id;
        return _me();
    }

    @Override
    public String toString() {
        return S.builder().append(getClass().getName()).append("[").append(id).append("]").toString();
    }
}

@@ -597,32 +597,191 @@
  : null;%0A    %7D%0A%0A
+    public void setId(String id) %7B%0A        E.illegalArgumentIf(!ObjectId.isValid(id), %22Invalid Object Id: %25s%22, id);%0A        this.id = new ObjectId(id);%0A    %7D%0A%0A
     public Objec

allow set Id with String type