/** * 监测用户ID * * @return */ private boolean noUid() { boolean result = TextUtils.isEmpty(uid); if (result) { log.error(tag, "getCategories 没有传入用户Id!"); } return result; }
@Override public void updateCategory(Photocategory category) { try { this.category.update(category); } catch (SQLException e) { log.setExcetion(tag, e); } }
public PhotocategoryImpl(Context context) { try { NfyhCloudDataOpenHelp db = NfyhCloudDataBase.getDataOpenHelp(context); this.category = db.getPhotocategory(); } catch (SQLException e) { log.setExcetion(tag, e); } }
@Override public Photocategory getCategory(String id) { try { return this.category.queryForId(id); } catch (SQLException e) { log.setExcetion(tag, e); } return null; }
@Override public void addCategory(Photocategory category) { try { // 如果存在则更新 if (this.category.queryForId(category.getPid()) != null) { this.category.update(category); } else { this.category.create(category); } } catch (SQLException e) { log.setExcetion(tag, e); } }
@Override public List<Photos> getPhotos(String categoryId) { if (noUid()) return null; try { return this.photo .queryBuilder() .where() .eq("_Users_uid", this.uid) .and() .eq("categoryid", categoryId) .query(); } catch (SQLException e) { log.setExcetion(categoryId, e); return null; } }
@Override public List<Photocategory> getCategories(String id) { if (noUid()) { return null; } Where<Photocategory, String> where = this.category.queryBuilder().where(); List<Photocategory> datas = null; try { datas = where.eq("_Users_uid", this.uid).and().eq("parentid", id).query(); // 找子类 return datas; } catch (SQLException e) { log.setExcetion(id, e); return null; } }