Search in sources :

Example 1 with Relationships

use of com.tale.model.Relationships in project tale by otale.

the class MetasServiceImpl method delete.

@Override
public void delete(int mid) {
    Metas metas = activeRecord.byId(Metas.class, mid);
    if (null != metas) {
        String type = metas.getType();
        String name = metas.getName();
        activeRecord.delete(Metas.class, mid);
        List<Relationships> rlist = activeRecord.list(new Take(Relationships.class).eq("mid", mid));
        if (null != rlist) {
            for (Relationships r : rlist) {
                Contents contents = activeRecord.byId(Contents.class, r.getCid());
                if (null != contents) {
                    boolean isUpdate = false;
                    Contents temp = new Contents();
                    temp.setCid(r.getCid());
                    if (type.equals(Types.CATEGORY)) {
                        temp.setCategories(reMeta(name, contents.getCategories()));
                        isUpdate = true;
                    }
                    if (type.equals(Types.TAG)) {
                        temp.setTags(reMeta(name, contents.getTags()));
                        isUpdate = true;
                    }
                    if (isUpdate) {
                        activeRecord.update(temp);
                    }
                }
            }
        }
        activeRecord.delete(new Take(Relationships.class).eq("mid", mid));
    }
}
Also used : Take(com.blade.jdbc.core.Take) Metas(com.tale.model.Metas) Relationships(com.tale.model.Relationships) Contents(com.tale.model.Contents)

Example 2 with Relationships

use of com.tale.model.Relationships in project tale by otale.

the class MetasServiceImpl method saveOrUpdate.

private void saveOrUpdate(Integer cid, String name, String type) {
    Metas metas = activeRecord.one(new Take(Metas.class).eq("name", name).eq("type", type));
    int mid = 0;
    if (null != metas) {
        //            Metas temp = new Metas();
        //            temp.setMid(metas.getMid());
        //            activeRecord.update(temp);
        mid = metas.getMid();
    } else {
        metas = new Metas();
        metas.setSlug(name);
        metas.setName(name);
        metas.setType(type);
        mid = activeRecord.insert(metas);
    }
    if (mid != 0) {
        int count = activeRecord.count(new Take(Relationships.class).eq("cid", cid).eq("mid", mid));
        if (count == 0) {
            Relationships relationships = new Relationships();
            relationships.setCid(cid);
            relationships.setMid(mid);
            activeRecord.insert(relationships);
        }
    }
}
Also used : Take(com.blade.jdbc.core.Take) Metas(com.tale.model.Metas) Relationships(com.tale.model.Relationships)

Aggregations

Take (com.blade.jdbc.core.Take)2 Metas (com.tale.model.Metas)2 Relationships (com.tale.model.Relationships)2 Contents (com.tale.model.Contents)1