public void put (String name, String value, String readPerm, String writePerm) { SysConfig cfg; if (prefix != null) name = prefix + name; try { boolean autoCommit = false; Transaction tx = db.session().getTransaction(); if (tx == null || tx.getStatus().isNotOneOf(TransactionStatus.ACTIVE)) { tx = db.session().beginTransaction(); autoCommit = true; } cfg = db.session().get (SysConfig.class, name); boolean saveIt = false; if (cfg == null) { cfg = new SysConfig (); cfg.setId (name); saveIt = true; } cfg.setReadPerm (readPerm); cfg.setWritePerm (writePerm); cfg.setValue (value); if (saveIt) db.session().save (cfg); if (autoCommit) tx.commit(); } catch (HibernateException e) { db.getLog().warn (e); } } public String get (String name) {
@Override public void updateEntity() throws BLException { SysConfig entity = getInstance(); entity.setId(((SysConfigHelper)getHelper()).addPrefix(entity.getId())); if (getHelper().updateEntity(getBinder())) getApp().displayNotification(getApp().getMessage("updated", getEntityName().toUpperCase())); else getApp().displayNotification(getApp().getMessage("notchanged")); }
@Override public boolean updateEntity (Binder binder) throws BLException { try { return (boolean) DB.execWithTransaction((db) -> { SysConfig oldSysConfig = (SysConfig) ((SysConfig) getOriginalEntity()).clone(); binder.writeBean(getOriginalEntity()); SysConfig s = (SysConfig) getOriginalEntity(); //need to re-set prefix to id as it gets deleted on write s.setId(addPrefix(s.getId())); db.session().merge(s); return addRevisionUpdated(db, getEntityName(), String.valueOf(s.getId()), oldSysConfig, s, new String[]{"value"}); }); } catch (Exception e) { QI.getQI().getLog().error(e); return false; } }