Search in sources :

Example 6 with Record

use of cn.cerc.jdb.core.Record in project summer-bean by cn-cerc.

the class LocalService method execute.

// 不带缓存调用服务
public IStatus execute(Object... args) {
    if (args.length > 0) {
        Record headIn = getDataIn().getHead();
        if (args.length % 2 != 0)
            return new ServiceStatus(false, "传入的参数数量必须为偶数!");
        for (int i = 0; i < args.length; i = i + 2) headIn.setField(args[i].toString(), args[i + 1]);
    }
    if (handle == null)
        return new ServiceStatus(false, "handle is null.");
    if (serviceCode == null)
        return new ServiceStatus(false, "service is null.");
    IService bean = Application.getService(handle, serviceCode);
    if (bean == null)
        return new ServiceStatus(false, String.format("bean %s not find", serviceCode));
    if ((bean instanceof Microservice) && ((Microservice) bean).getService() == null)
        ((Microservice) bean).setService(serviceCode);
    try {
        log.info(this.serviceCode);
        IStatus status = bean.execute(dataIn, dataOut);
        message = status.getMessage();
        return status;
    } catch (Exception e) {
        Throwable err = e;
        if (e.getCause() != null)
            err = e.getCause();
        log.error(err.getMessage(), err);
        message = err.getMessage();
        return new ServiceStatus(false, message);
    }
}
Also used : IStatus(cn.cerc.jbean.core.IStatus) ServiceStatus(cn.cerc.jbean.core.ServiceStatus) Record(cn.cerc.jdb.core.Record) IService(cn.cerc.jbean.core.IService)

Example 7 with Record

use of cn.cerc.jdb.core.Record in project summer-bean by cn-cerc.

the class LocalService method exec.

// 带缓存调用服务
@Override
public boolean exec(Object... args) {
    if (args.length > 0) {
        Record headIn = getDataIn().getHead();
        if (args.length % 2 != 0)
            throw new RuntimeException("传入的参数数量必须为偶数!");
        for (int i = 0; i < args.length; i = i + 2) headIn.setField(args[i].toString(), args[i + 1]);
    }
    if (handle == null)
        throw new RuntimeException("handle is null.");
    if (serviceCode == null)
        throw new RuntimeException("service is null.");
    IService bean = Application.getService(handle, serviceCode);
    if (bean == null) {
        this.message = String.format("bean %s not find", serviceCode);
        return false;
    }
    if ((bean instanceof Microservice) && ((Microservice) bean).getService() == null)
        ((Microservice) bean).setService(serviceCode);
    try {
        if (!"AppSessionRestore.byUserCode".equals(this.serviceCode))
            log.info(this.serviceCode);
        if (ServerConfig.getAppLevel() == ServerConfig.appRelease) {
            IStatus status = bean.execute(dataIn, dataOut);
            boolean result = status.getResult();
            message = status.getMessage();
            return result;
        }
        IMemcache buff = Application.getMemcache();
        // 制作临时缓存Key
        String key = MD5.get(handle.getUserCode() + this.serviceCode + dataIn.getJSON());
        if (bufferRead) {
            String buffValue = (String) buff.get(key);
            if (buffValue != null) {
                log.debug("read from buffer: " + this.serviceCode);
                dataOut.setJSON(buffValue);
                message = dataOut.getHead().getString("_message_");
                return dataOut.getHead().getBoolean("_result_");
            }
        }
        // 没有缓存时,直接读取并存入缓存
        bean.init(handle);
        IStatus status = bean.execute(dataIn, dataOut);
        boolean result = status.getResult();
        message = status.getMessage();
        if (bufferWrite) {
            log.debug("write to buffer: " + this.serviceCode);
            dataOut.getHead().setField("_message_", message);
            dataOut.getHead().setField("_result_", result);
            buff.set(key, dataOut.getJSON());
        }
        return result;
    } catch (Exception e) {
        Throwable err = e;
        if (e.getCause() != null)
            err = e.getCause();
        log.error(err.getMessage(), err);
        message = err.getMessage();
        return false;
    }
}
Also used : IStatus(cn.cerc.jbean.core.IStatus) IMemcache(cn.cerc.jdb.cache.IMemcache) Record(cn.cerc.jdb.core.Record) IService(cn.cerc.jbean.core.IService)

Example 8 with Record

use of cn.cerc.jdb.core.Record in project summer-bean by cn-cerc.

the class RemoteService method exec.

@Override
public boolean exec(Object... args) {
    if (args.length > 0) {
        Record headIn = getDataIn().getHead();
        if (args.length % 2 != 0)
            throw new RuntimeException("传入的参数数量必须为偶数!");
        for (int i = 0; i < args.length; i = i + 2) headIn.setField(args[i].toString(), args[i + 1]);
    }
    String postParam = getDataIn().getJSON();
    String url = String.format("http://%s/services/%s", this.host, this.service);
    if (token != null)
        url = url + "?token=" + token;
    try {
        log.debug("datain: " + postParam);
        // String rst = CURL.doPost(url, params, "UTF-8");
        String rst = postData(url, postParam);
        log.debug("datatout:" + rst);
        if (rst == null)
            return false;
        JSONObject json = JSONObject.fromObject(rst);
        if (json.get("message") != null) {
            this.setMessage(json.getString("message"));
        }
        if (json.containsKey("data")) {
            JSONArray datas = json.getJSONArray("data");
            if (datas != null && datas.size() > 0) {
                if (dataOut == null)
                    dataOut = new DataSet();
                else
                    dataOut.close();
                dataOut.setJSON(datas.getString(0));
            }
        }
        return json.getBoolean("result");
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        if (e.getCause() != null)
            setMessage(e.getCause().getMessage());
        else
            setMessage(e.getMessage());
        return false;
    }
}
Also used : JSONObject(net.sf.json.JSONObject) DataSet(cn.cerc.jdb.core.DataSet) JSONArray(net.sf.json.JSONArray) Record(cn.cerc.jdb.core.Record) ClientProtocolException(org.apache.http.client.ClientProtocolException) IOException(java.io.IOException)

Example 9 with Record

use of cn.cerc.jdb.core.Record in project summer-bean by cn-cerc.

the class Memory_UserInfo method get.

public static MemoryBuffer get(IHandle sess, String usercode) {
    MemoryBuffer buff = new MemoryBuffer(BufferType.getAccount, usercode);
    if (buff.isNull()) {
        SqlQuery ds = new SqlQuery(sess);
        ds.add("select a.Code_,a.Enabled_,a.Name_,a.SuperUser_,a.DiyRole_,a.RoleCode_,oi.Type_,a.ImageUrl_ ");
        ds.add("from %s a ", SystemTable.get(SystemTable.getUserInfo));
        ds.add("inner join %s oi on a.CorpNo_=oi.CorpNo_ ", SystemTable.get(SystemTable.getBookInfo));
        ds.add("where a.Code_='%s'", usercode);
        ds.open();
        if (ds.eof())
            throw new RuntimeException(String.format("用户代码 %s 不存在!", usercode));
        Record record = ds.getCurrent();
        buff.setField("Name_", record.getString("Name_"));
        buff.setField("Enabled_", record.getInt("Enabled_"));
        buff.setField("SuperUser_", record.getBoolean("SuperUser_"));
        buff.setField("ImageUrl_", record.getString("ImageUrl_"));
        if (record.getBoolean("DiyRole_"))
            buff.setField("RoleCode_", record.getString("Code_"));
        else
            buff.setField("RoleCode_", record.getString("RoleCode_"));
        buff.setField("CorpType_", "" + record.getInt("Type_") + ",");
    } else {
        count++;
    }
    return buff;
}
Also used : SqlQuery(cn.cerc.jdb.mysql.SqlQuery) Record(cn.cerc.jdb.core.Record)

Example 10 with Record

use of cn.cerc.jdb.core.Record in project summer-bean by cn-cerc.

the class SvrUserOption method execute.

@Override
public IStatus execute(DataSet dataIn, DataSet dataOut) throws ServiceException {
    Record head = dataIn.getHead();
    SqlQuery ds = new SqlQuery(this);
    ds.add(String.format("select Value_ from %s", SystemTable.get(SystemTable.getUserOptions)));
    ds.add(String.format("where UserCode_=N'%s' and Code_=N'%s'", this.getUserCode(), head.getString("Code_")));
    ds.open();
    dataOut.appendDataSet(ds);
    return success();
}
Also used : SqlQuery(cn.cerc.jdb.mysql.SqlQuery) Record(cn.cerc.jdb.core.Record)

Aggregations

Record (cn.cerc.jdb.core.Record)53 SqlQuery (cn.cerc.jdb.mysql.SqlQuery)15 LocalService (cn.cerc.jbean.client.LocalService)9 Webfunc (cn.cerc.jbean.core.Webfunc)4 DataSet (cn.cerc.jdb.core.DataSet)4 Ignore (org.junit.Ignore)4 Test (org.junit.Test)4 MemoryBuffer (cn.cerc.jbean.other.MemoryBuffer)3 StubHandle (cn.cerc.jbean.rds.StubHandle)3 IMemcache (cn.cerc.jdb.cache.IMemcache)3 MessageRecord (cn.cerc.jmis.message.MessageRecord)3 UrlRecord (cn.cerc.jpage.core.UrlRecord)3 Label (jxl.write.Label)3 CustomHandle (cn.cerc.jbean.core.CustomHandle)2 IService (cn.cerc.jbean.core.IService)2 IStatus (cn.cerc.jbean.core.IStatus)2 UserNotFindException (cn.cerc.jbean.other.UserNotFindException)2 QueueQuery (cn.cerc.jdb.queue.QueueQuery)2 Column (cn.cerc.jexport.excel.Column)2 JPushRecord (cn.cerc.jmis.message.JPushRecord)2