/** * Close this TagManager. Only used for tests. * * @throws ObjectStoreException in exceptional circumstances */ public void close() throws ObjectStoreException { try { osWriter.close(); } catch (Throwable e) { //LOG.info("tried to close the db connection", e); } }
/** * Request that the ObjectStore aborts and closes the transaction, delegate to internal * ObjectStoreWriter. * * @throws ObjectStoreException if a transaction is not in progress */ public void abortTransaction() throws ObjectStoreException { osw.abortTransaction(); }
private void incrementTransaction() throws ObjectStoreException { transactionCounter++; if (transactionCounter >= TRANSACTION_BATCH_SIZE) { LOG.info("Committing transaction"); osw.commitTransaction(); osw.beginTransaction(); transactionCounter = 0; } } }
/** * {@inheritDoc} */ public void close() throws ObjectStoreException { if (osw.isInTransaction()) { osw.commitTransaction(); } }
List<Object> res; try { res = osw.executeSingleton(q); } catch (Exception e) { throw new BuildException("Could not retrieve any tags", e); osw.beginTransaction(); for (Object o: res) { osw.delete((Tag) o); osw.commitTransaction(); } catch (Exception e) { throw new BuildException("Error deleting tags", e); if (osw != null) { try { if (osw.isInTransaction()) { osw.abortTransaction();
@AfterClass public static void tearDown() { try { osw = ObjectStoreWriterFactory.getObjectStoreWriter(ALIAS); } catch (ObjectStoreException e) { LOG.error("Could not initialise object-store", e); return; } if (osw != null) { try { osw.beginTransaction(); for (InterMineObject o: madeThings) { osw.delete(o); } osw.commitTransaction(); LOG.info("Deleted " + madeThings.size() + " things"); madeThings.clear(); } catch (ObjectStoreException e) { LOG.error("While unloading fixture", e); } finally { if (osw != null) { try { osw.close(); } catch (ObjectStoreException e) { LOG.error("Closing object store", e); } } } } }
writer.flushObjectById(); os.flushObjectById(); writer.store(address1); Integer id = address1.getId(); address2.setId(id); Assert.assertNull(writer.pilferObjectById(id)); Assert.assertNull(writer.pilferObjectById(id)); Assert.assertNotNull(os.pilferObjectById(id)); os.flushObjectById(); Assert.assertNotNull(writer.getObjectById(id, Address.class)); Assert.assertNotNull(writer.pilferObjectById(id)); Assert.assertNull(os.pilferObjectById(id)); Assert.assertNotNull(os.getObjectById(id, Address.class)); writer.store(address2); Assert.assertNotNull(writer.getObjectById(id, Address.class)); Assert.assertEquals("Address 2", ((Address) writer.getObjectById(id, Address.class)).getAddress()); Assert.assertNotNull(os.getObjectById(id, Address.class)); Assert.assertEquals("Address 2", ((Address) os.getObjectById(id, Address.class)).getAddress()); writer.delete(address2); Assert.assertNull(writer.getObjectById(id, Address.class)); Assert.assertNull(os.getObjectById(id, Address.class)); writer.store(address1);
@Test public void testWriteBatchingAndGetObject() throws Exception { Address address1 = new Address(); address1.setAddress("Address 1"); writer.flushObjectById(); os.flushObjectById(); try { writer.beginTransaction(); writer.store(address1); Assert.assertNotNull(writer.getObjectById(address1.getId(), Address.class)); } finally { if (writer.isInTransaction()) { writer.abortTransaction(); } } }
writer.beginTransaction(); Query q = new Query(); QueryClass qc = new QueryClass(InterMineObject.class); q.addFrom(qc); q.addToSelect(qc); SingletonResults dataToRemove = writer.getObjectStore().executeSingleton(q); Iterator<Object> iter = dataToRemove.iterator(); while (iter.hasNext()) { InterMineObject toDelete = (InterMineObject)iter.next(); writer.delete(toDelete); writer.commitTransaction(); } catch (Exception e) { writer.abortTransaction(); throw e;
public static void storeData(ObjectStoreWriter dataWriter, Map data) throws Exception { //checkIsEmpty(); System.out.println("Storing data"); long start = new Date().getTime(); try { //Iterator iter = data.entrySet().iterator(); //while (iter.hasNext()) { // InterMineObject o = (InterMineObject) ((Map.Entry) iter.next()) // .getValue(); // o.setId(null); //} dataWriter.beginTransaction(); Iterator iter = data.entrySet().iterator(); while (iter.hasNext()) { Map.Entry entry = (Map.Entry) iter.next(); Object o = entry.getValue(); dataWriter.store(o); } dataWriter.commitTransaction(); } catch (Exception e) { dataWriter.abortTransaction(); throw new Exception(e); } System.out.println("Took " + (new Date().getTime() - start) + " ms to set up data"); }
q.setConstraint(cs1); Results res = writer.execute(q); Assert.assertEquals(res.toString(), 0, res.size()); Assert.assertEquals(res.toString(), 0, res.size()); writer.beginTransaction(); Assert.assertTrue(writer.isInTransaction()); writer.store(address1); writer.store(address2); res = writer.execute(q); Assert.assertEquals(2, res.size()); Assert.assertEquals(res.toString(), 0, res.size()); writer.abortTransaction(); Assert.assertFalse(writer.isInTransaction()); res = writer.execute(q); Assert.assertEquals(res.toString(), 0, res.size());
osw.beginTransaction(); for (Object o : res){ Employee employee = (Employee) o; employee.setName(null); osw.store(employee); osw.commitTransaction(); osw.close();
@Test public void testExceptionOutOfTransaction() throws Exception { Assert.assertFalse(writer.isInTransaction()); // First, cause an exception outside a transaction try { writer.store(new RuntimeExceptionEmployee()); } catch (Exception e) {} Assert.assertFalse(writer.isInTransaction()); // Now try and do something normal. writer.getObjectById(new Integer(2)); } }
/** * {@inheritDoc} */ public void store(Attribute att, Integer itemId) throws ObjectStoreException { ProxyReference proxy = new ProxyReference(osw.getObjectStore(), itemId, Item.class); att.proxyItem(proxy); osw.store(att); incrementTransaction(); }
private Map<UUID, PermanentToken> loadPermanentTokens() { Map<UUID, PermanentToken> map = new HashMap<UUID, PermanentToken>(); try { // Get the current set of permanent tokens from the database. Query q = new Query(); QueryClass tokens = new QueryClass(PermanentToken.class); q.addFrom(tokens); q.addToSelect(tokens); List<?> results = uosw.executeSingleton(q); Set<PermanentToken> badTokens = new HashSet<PermanentToken>(); for (Object o: results) { PermanentToken token = (PermanentToken) o; try { UUID key = UUID.fromString(token.getToken()); map.put(key, token); } catch (IllegalArgumentException e) { badTokens.add(token); } } for (PermanentToken t: badTokens) { LOG.info("Removing bad token: " + t); uosw.delete(t); } } catch (Exception e) { LOG.error("Could not load permanent tokens", e); throw new IllegalStateException("Error loading permanent tokens", e); } return map; }
@Before public void setUp() throws Exception { ObjectStoreWriter osw = ObjectStoreWriterFactory.getObjectStoreWriter("osw.unittest"); os = osw.getObjectStore(); Map data = ObjectStoreTestUtils.getTestData("testmodel", "testmodel_data.xml"); ObjectStoreTestUtils.storeData(osw, data); osw.close(); }
/** * Delete an object from this ObjectStore, delegate to internal ObjectStoreWriter. * * @param o the object to delete * @throws ObjectStoreException if an error occurs during deletion of the object */ public void delete(InterMineObject o) throws ObjectStoreException { osw.delete(o); }