public ResultCode get(long id) { try { return (ResultCode) db.session().load(ResultCode.class, new Long(id)); } catch (ObjectNotFoundException e) { LogEvent evt = db.getLog().createWarn(); evt.addMessage("error loading unconfigured result code " + id); evt.addMessage(e); Logger.log(evt); } catch (HibernateException e) { db.getLog().warn(e); } return null; }
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 = (SysConfig) 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 ResultCode get(String rc) { try { List l = ResultCodeFinder.findByMnemonic(db.session(), rc); if (l.size() == 0) { LogEvent evt = db.getLog().createWarn(); evt.addMessage("error loading unconfigured result code '" + rc + "'"); Logger.log(evt); } else { return (ResultCode) l.get(0); } } catch (HibernateException e) { db.getLog().warn(e); } catch (SQLException e) { db.getLog().warn(e); } return null; }
/** * @param name property name * @param defaultValue default value * @return if property exists, return its value, otherwise defaultValue. */ public String get(String name, String defaultValue) { try { if (prefix != null) name = prefix + name; SysConfig cfg = (SysConfig) db.session().get(SysConfig.class, name); if (cfg != null) return cfg.getValue(); } catch (HibernateException e) { db.getLog().warn(e); } return defaultValue; }
public boolean hasProperty(String name) { try { if (prefix != null) name = prefix + name; SysConfig cfg = (SysConfig) db.session().get(SysConfig.class, name); return cfg != null; } catch (ObjectNotFoundException e) { // okay to happen } catch (HibernateException e) { db.getLog().warn(e); } return false; }
public SysConfig[] getAll() { SysConfig[] values; try { String queryAsString = "from sysconfig in class org.jpos.ee.SysConfig"; if (prefix != null) queryAsString += " where id like :query"; Query query = db.session().createQuery(queryAsString + " order by id"); if (prefix != null) query.setParameter("query", prefix + "%"); List l = query.list(); values = new SysConfig[l.size()]; Iterator iter = l.iterator(); for (int i = 0; iter.hasNext(); i++) { values[i] = (SysConfig) iter.next(); } } catch (HibernateException e) { db.getLog().warn(e); values = new SysConfig[0]; } return values; }