package cn.cerc.mis.ado;

import cn.cerc.db.core.DataSetGson;
import cn.cerc.db.core.IHandle;
import cn.cerc.db.core.ISqlDatabase;
import cn.cerc.db.core.SqlQuery;
import cn.cerc.db.core.SqlServer;
import cn.cerc.db.core.SqlServerType;
import cn.cerc.db.core.Utils;

public class EntityQuery<T> extends SqlQuery implements IHandle {
    private static final long serialVersionUID = 8276125658457479833L;
    private Class<T> clazz;

    public static <U> EntityQuery<U> create(IHandle handle, Class<U> clazz) {
        ISqlDatabase database = EntityManager.findDatabase(handle, clazz);
        SqlServer server = clazz.getAnnotation(SqlServer.class);
        SqlServerType sqlServerType = (server != null) ? server.type() : SqlServerType.Mysql;
        EntityQuery<U> query = new EntityQuery<U>(handle, clazz, sqlServerType, true);
        query.operator().setTable(database.table());
        query.operator().setOid(database.oid());
        return query;
    }

    private EntityQuery(IHandle handle, Class<T> clazz, SqlServerType sqlServerType, boolean writeCacheAtOpen) {
        super(handle, sqlServerType);
        this.clazz = clazz;
        EntityManager.registerCacheListener(this, clazz, writeCacheAtOpen);
    }

    @Override
    public String json() {
        return new DataSetGson<EntityQuery<T>>(this).encode();
    }

    @Override
    public EntityQuery<T> setJson(String json) {
        this.clear();
        if (!Utils.isEmpty(json))
            new DataSetGson<EntityQuery<T>>(this).decode(json);
        return this;
    }

}

@@ -400,36 +400,8 @@
 33L;
-%0A    private Class%3CT%3E clazz;
 %0A%0A  
@@ -767,23 +767,16 @@
 (handle,
- clazz,
  sqlServ
@@ -781,16 +781,75 @@
 rverType
+);%0A        EntityManager.registerCacheListener(query, clazz
 , true);
@@ -1023,24 +1023,8 @@
 dle,
- Class%3CT%3E clazz,
  Sql
@@ -1051,34 +1051,8 @@
 Type
-, boolean writeCacheAtOpen
 ) %7B%0A
@@ -1093,112 +1093,8 @@
 e);%0A
-        this.clazz = clazz;%0A        EntityManager.registerCacheListener(this, clazz, writeCacheAtOpen);%0A
     

Update EntityQuery.java