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) { } } }
private void createSchema () throws HibernateException, DocumentException { DB db = new DB(); db.open(); db.beginTransaction(); db.createSchema(null, true); db.commit(); db.close(); }
public Thing create (String type) { Thing thing = new Thing (type); db.save (thing); return thing; } public Thing get (long id) {
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; } }
@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); } } }
/** * @return underlying Hibernate Session. */ public Session session () { return db.session(); } /**
/** * @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); }
/** * 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; }
@SuppressWarnings("unchecked") public void exec(CLIContext cli, String[] args) { long start = System.currentTimeMillis(); try (DB db = new DB()) { db.open(); GLSession gls = new GLSession(db); List<BalanceCache> caches = db.session().createQuery("from org.jpos.gl.BalanceCache").list(); int good=0; int total=0;
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 {
@Before public void setUp() throws Exception { db = new DB(); db.createSchema("schema.sql", true); db.open(); }
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) { }
/** * create a SysLog object with auto commit on. * (open/begin/commit/close is not required). */ public SysLogManager () { super (new DB(),SysLog.class); autoCommit = true; }
public boolean saveUser (Binder binder, String clearPass) throws BLException { User u = (User) getOriginalEntity(); if (binder.writeBeanIfValid(getOriginalEntity())) { try { return (boolean) DB.execWithTransaction((db) -> { db.save(u); if (clearPass != null && !clearPass.isEmpty()) { UserManager mgr = new UserManager(db); try { mgr.setPassword(u, clearPass); } catch (BLException e) { return false; } addRevisionCreated(db, getEntityName(), u.getId().toString()); u.setForcePasswordChange(true); db.session().update(u); return true; } return false; }); } catch (Exception e) { getApp().getLog().error(e); return false; } } else { throw new BLException("Invalid user"); } }
private void createRealms() throws Exception { db.beginTransaction(); db.save(new Realm("TEST")); db.save(new Realm("PROD")); db.commit(); }