public void setNextCommand (String id, String command) throws HibernateException, SQLException { Transaction tx = db.beginTransaction(); Status status = getStatus (id, false); if (status != null) status.setCommand (command); tx.commit(); } /**
/** * @param id status id * @param state Status.OK, Status.WARN, Status.ERROR or user defined * @param detail optional detail information */ public void touch (String id, String state, String detail) throws HibernateException, SQLException { Transaction tx = db.beginTransaction(); Status status = touch (id, state, detail, tx); tx.commit(); db.session().evict (status); }
@Override public void exec(CLIContext cli, String[] args) throws Exception { String filename = "-"; // defaults to stdout ' String configModifier = null; boolean create = false; if (args.length > 1) filename = args[1]; if (args.length > 2) create = "yes".equalsIgnoreCase(args[2]) || "true".equalsIgnoreCase(args[2]); if (args.length > 3) configModifier = args[3]; try (DB db = new DB(configModifier)) { db.open(); db.beginTransaction(); db.createSchema(filename, create); } } }
private void create (String id) { try (DB db = new DB()) { db.open(); db.beginTransaction(); SeqNo seq = new SeqNo(id); db.session().save(seq); db.commit(); } catch (Exception ignored) { } } }
public static <T> T execWithTransaction(DBAction<T> action) throws Exception { try (DB db = new DB()) { db.open(); db.beginTransaction(); T obj = action.exec(db); db.commit(); return obj; } }
public static <T> T execWithTransaction(String configModifier, DBAction<T> action) throws Exception { try (DB db = new DB(configModifier)) { db.open(); db.beginTransaction(); T obj = action.exec(db); db.commit(); return obj; } }
private void createSchema () throws HibernateException, DocumentException { DB db = new DB(); db.open(); db.beginTransaction(); db.createSchema(null, true); db.commit(); db.close(); }
/** * Release an async lock * @param id lock ID * @param lockedBy unique client identifier */ public boolean release (String id, long lockedBy) { if (db.session != null && db.session.isOpen()) throw new IllegalStateException("DB should not be open"); try (DB db1 = db) { db1.open(); db1.beginTransaction(); SeqNo seq = getOrCreate(id); if (seq.getLockedBy() == lockedBy && seq.getLockUntil() > System.currentTimeMillis()) { seq.setLockedBy(0L); db1.commit(); return true; } } return false; }
private void createTransactions (DB db, Iterator iter) throws SQLException, HibernateException, ParseException, GLException { GLSession gls = new GLSession(db); while (iter.hasNext()) { Transaction txn = db.beginTransaction(); Element elem = (Element) iter.next (); GLTransaction glt = new GLTransaction (elem); Journal journal = getJournal ( db.session(), elem.getAttributeValue ("journal") ); glt.setJournal (journal); addEntries ( db.session(), glt, elem.getChildren("entry").iterator() ); gls.post(journal, glt); txn.commit (); System.out.println (glt.getId() + " " + glt.getDetail()); } } private void addEntries (
@Override public void exec(CLIContext cli, String[] args) throws Exception { if (args.length < 2) { cli.println("Usage: rm <id> "); return; } try (DB db = new DB()) { db.open(); db.beginTransaction(); SysConfigManager mgr = new SysConfigManager(db); if (cli.getUserData().containsKey(SYSCONFIG.PREFIX)) mgr.setPrefix((String) cli.getUserData().get(SYSCONFIG.PREFIX)); boolean deleted = mgr.delete(args[1]); db.commit(); cli.println ("sysconfig " + (deleted ? "deleted" : "not found")); } catch (Exception e) { cli.println (e.getMessage()); } } }
@Override public void exec(CLIContext cli, String[] args) throws Exception { if (args.length != 2) { cli.println("Usage: rmrole <role>"); return; } try (DB db = new DB()) { db.open(); db.beginTransaction(); RoleManager rm = new RoleManager(db); Role r = rm.getRoleByName(args[1]); if (r != null) db.session().delete(r); db.commit(); cli.println (r != null ? "Role " + r + " has been deleted" : "Role not found"); } catch (Exception e) { cli.println (e.getMessage()); } } }
@Override public void exec(CLIContext cli, String[] args) throws Exception { if (args.length != 2) { cli.println("Usage: rmrole <role>"); return; } try (DB db = new DB()) { db.open(); db.beginTransaction(); RoleManager rm = new RoleManager(db); Role r = rm.getRoleByName(args[1]); if (r != null) db.session().delete(r); db.commit(); cli.println (r != null ? "Role " + r + " has been deleted" : "Role not found"); } catch (Exception e) { cli.println (e.getMessage()); } } }
public int prepare (long id, Serializable o) { int rc = ABORTED; Context ctx = (Context) o; try { DB db = getDB (ctx); db.open (); ctx.put (TX, db.beginTransaction(timeout)); checkPoint (ctx); rc = PREPARED; } catch (Throwable t) { error (t); ctx.remove (DB); // "Close" participant checks // for DB in Context } return rc | NO_JOIN | READONLY; } public void commit (long id, Serializable o) { }
@Override public void exec(CLIContext cli, String[] args) throws Exception { if (args.length != 2) { cli.println("Usage: rmuser <user>"); return; } try (DB db = new DB()) { db.open(); db.beginTransaction(); UserManager mgr = new UserManager(db); User u = mgr.getUserByNick(args[1]); if (u != null) { u.setDeleted(true); } db.commit(); cli.println(u != null ? "User " + u.getNickAndId() + " has been deleted" : "User does not exist"); } catch (Exception e) { cli.println(e.getMessage()); } } }
@Override public void exec(CLIContext cli, String[] args) throws Exception { if (args.length != 2) { cli.println("Usage: rmconsumer <id>"); return; } try (DB db = new DB()) { db.open(); db.beginTransaction(); ConsumerManager mgr = new ConsumerManager(db); Consumer c = mgr.getById(args[1]); if (c != null) { c.setDeleted(true); } db.commit(); cli.println(c != null ? "Consumer " + c.getId() + " has been deleted" : "Consumer does not exist"); } catch (Exception e) { cli.println(e.getMessage()); } } }
private void createRealms() throws Exception { db.beginTransaction(); db.save(new Realm("TEST")); db.save(new Realm("PROD")); db.commit(); }
private void initStatus() throws HibernateException, SQLException { try { db.open (); statusId = cfg.get ("status-id", getName()); Status s = mgr.getStatus (statusId, false); if (s == null) { Transaction tx = db.beginTransaction(); s = mgr.getStatus (statusId, true); s.setName (cfg.get ("status-name", statusId)); s.setGroupName (cfg.get ("status-group", "")); s.setTimeoutState (cfg.get ("on-timeout", Status.OFF)); s.setTimeout (cfg.getLong ("status-timeout", 360000L)); s.setLastTick (new Date()); tx.commit(); } } finally { close(); } } }
private void reset() { try (DB db = new DB()) { SeqNoManager mgr = new SeqNoManager(db); db.open(); db.beginTransaction(); mgr.reset("sync", 0L); db.commit(); } } }
private long next(long delay) { try (DB db = new DB()) { SeqNoManager mgr = new SeqNoManager(db); db.open(); db.beginTransaction(); long l = mgr.next("sync", 999999L); ISOUtil.sleep(delay); db.commit(); return l; } }
private void createUser() throws Exception { db.beginTransaction(); User user = new User(); user.setNick("admin"); user.setName("User Administrator"); user.setActive(true); db.session().save(user); UserManager mgr = new UserManager(db, HashVersion.ZERO); mgr.setPassword(user, "test", null); RealmManager rmgr = new RealmManager(db); Realm testRealm = rmgr.getRealmByName("TEST"); Realm prodRealm = rmgr.getRealmByName("PROD"); Role r = createRole(db, null, "admin", "login", "admin"); user.getRoles().add(r); // user permissions: `login`, `admin`, `role.admin` Role r1 = createRole (db, testRealm, "tester", "testread", "testwrite"); r1.setParent(r); user.getRoles().add(r1); // adds permissions: `TEST.testread`, `TEST.testwrite` db.commit(); } public void checkUser() throws Exception {