/** * Returns a new empty ObjectStoreBag for this ObjectStore, delegate to internal * ObjectStoreWriter. * * @return an ObjectStoreBag * @throws ObjectStoreException if an error occurs fetching a new ID */ public ObjectStoreBag createObjectStoreBag() throws ObjectStoreException { return osw.createObjectStoreBag(); }
/** * Returns a new empty ObjectStoreBag for this ObjectStore, delegate to internal * ObjectStoreWriter. * * @return an ObjectStoreBag * @throws ObjectStoreException if an error occurs fetching a new ID */ public ObjectStoreBag createObjectStoreBag() throws ObjectStoreException { return osw.createObjectStoreBag(); }
private void cloneInternalObjectStoreBag(InterMineBag bag) { ObjectStoreWriter osw = null; try { osw = os.getNewWriter(); ObjectStoreBag newBag = osw.createObjectStoreBag(); Query q = new Query(); q.addToSelect(this.osb); osw.addToBagFromQuery(newBag, q); bag.osb = newBag; } catch (ObjectStoreException e) { LOG.error("Clone failed.", e); throw new RuntimeException("Clone failed.", e); } finally { try { if (osw != null) { osw.close(); } } catch (ObjectStoreException e) { LOG.error("Closing object store failed.", e); } } }
private void cloneInternalObjectStoreBag(InterMineBag bag) { ObjectStoreWriter osw = null; try { osw = os.getNewWriter(); ObjectStoreBag newBag = osw.createObjectStoreBag(); Query q = new Query(); q.addToSelect(this.osb); osw.addToBagFromQuery(newBag, q); bag.osb = newBag; } catch (ObjectStoreException e) { LOG.error("Clone failed.", e); throw new RuntimeException("Clone failed.", e); } finally { try { if (osw != null) { osw.close(); } } catch (ObjectStoreException e) { LOG.error("Closing object store failed.", e); } } }
/** * Upgrades the ObjectStoreBag with a new ObjectStoreBag containing the collection of elements * given in input * @param values the collection of elements to add * @param updateBagValues id true if we upgrade the bagvalues table * @throws ObjectStoreException if an error occurs fetching a new ID */ public void upgradeOsb(Collection<Integer> values, boolean updateBagValues) throws ObjectStoreException { ObjectStoreWriter oswProduction = null; SavedBag savedBag = (SavedBag) uosw.getObjectById(savedBagId, SavedBag.class); try { oswProduction = os.getNewWriter(); osb = oswProduction.createObjectStoreBag(); oswProduction.addAllToBag(osb, values); savedBag.setOsbId(osb.getBagId()); savedBag.setState(BagState.CURRENT.toString()); state = BagState.CURRENT; uosw.store(savedBag); if (updateBagValues) { updateBagValues(); } } finally { if (oswProduction != null) { oswProduction.close(); } } }
@Test public void testObjectStoreBag() throws Exception { System.out.println("Starting testObjectStoreBag"); ObjectStoreBag osb = storeDataWriter.createObjectStoreBag(); ArrayList<Integer> coll = new ArrayList<Integer>(); coll.add(new Integer(3)); r = os.executeSingleton(q); Assert.assertEquals(Arrays.asList(new Object[] {data.get("EmployeeA1"), data.get("EmployeeA2")}), r); ObjectStoreBag osb2 = storeDataWriter.createObjectStoreBag(); storeDataWriter.addToBag(osb2, ((Employee) data.get("EmployeeA1")).getId()); storeDataWriter.addToBagFromQuery(osb2, q);
/** * Upgrades the ObjectStoreBag with a new ObjectStoreBag containing the collection of elements * given in input * @param values the collection of elements to add * @param updateBagValues id true if we upgrade the bagvalues table * @throws ObjectStoreException if an error occurs fetching a new ID */ public void upgradeOsb(Collection<Integer> values, boolean updateBagValues) throws ObjectStoreException { ObjectStoreWriter oswProduction = null; SavedBag savedBag = (SavedBag) uosw.getObjectById(savedBagId, SavedBag.class); try { oswProduction = os.getNewWriter(); osb = oswProduction.createObjectStoreBag(); oswProduction.addAllToBag(osb, values); savedBag.setOsbId(osb.getBagId()); savedBag.setState(BagState.CURRENT.toString()); state = BagState.CURRENT; uosw.store(savedBag); if (updateBagValues) { updateBagValues(); } } finally { if (oswProduction != null) { oswProduction.close(); } } }
@Test public void testIsPrecomputed() throws Exception { Query q = new Query(); QueryClass qc = new QueryClass(Employee.class); QueryField qf = new QueryField(qc,"age"); SimpleConstraint sc = new SimpleConstraint(qf,ConstraintOp.GREATER_THAN,new QueryValue(new Integer(20))); q.addToSelect(qc); q.addFrom(qc); q.setConstraint(sc); Assert.assertFalse(((ObjectStoreInterMineImpl)os).isPrecomputed(q,"template")); ((ObjectStoreInterMineImpl)os).precompute(q, "template"); Assert.assertTrue(((ObjectStoreInterMineImpl)os).isPrecomputed(q,"template")); ObjectStoreBag osb = storeDataWriter.createObjectStoreBag(); storeDataWriter.addToBag(osb, new Integer(5)); Assert.assertTrue(((ObjectStoreInterMineImpl)os).isPrecomputed(q,"template")); storeDataWriter.store(data.get("EmployeeA1")); Assert.assertFalse(((ObjectStoreInterMineImpl)os).isPrecomputed(q,"template")); }