/** * Search database for object matching the given object id * * @param id the object ID * @return the retrieved object * @throws ObjectStoreException if an error occurs retieving the object */ public InterMineObject getObjectById(Integer id) throws ObjectStoreException { return osw.getObjectById(id); }
/** * Search database for object matching the given object id and class * * @param id the object ID * @param clazz a Class of the object * @return the retrieved object * @throws ObjectStoreException if an error occurs retrieving the object */ public InterMineObject getObjectById(Integer id, Class<? extends InterMineObject> clazz) throws ObjectStoreException { return osw.getObjectById(id, clazz); }
/** * Search database for object matching the given object id and class * * @param id the object ID * @param clazz a Class of the object * @return the retrieved object * @throws ObjectStoreException if an error occurs retrieving the object */ public InterMineObject getObjectById(Integer id, Class<? extends InterMineObject> clazz) throws ObjectStoreException { return osw.getObjectById(id, clazz); }
/** * Search database for object matching the given object id * * @param id the object ID * @return the retrieved object * @throws ObjectStoreException if an error occurs retieving the object */ public InterMineObject getObjectById(Integer id) throws ObjectStoreException { return osw.getObjectById(id); }
/** * Get Tag by object id. * @param id intermine object id * @return Tag */ public synchronized Tag getTagById(int id) { try { return (Tag) osWriter.getObjectById(new Integer(id), Tag.class); } catch (ObjectStoreException e) { throw new RuntimeException("Getting tag from database failed", e); } }
/** * Get Tag by object id. * @param id intermine object id * @return Tag */ public synchronized Tag getTagById(int id) { try { return (Tag) osWriter.getObjectById(new Integer(id), Tag.class); } catch (ObjectStoreException e) { throw new RuntimeException("Getting tag from database failed", e); } }
/** * Perform a query to retrieve a user's backing UserProfile * * @param userId the id of the user * @return the relevant UserProfile */ public synchronized UserProfile getUserProfile(Integer userId) { if (userId == null) { return null; } try { return (UserProfile) uosw.getObjectById(userId, UserProfile.class); } catch (ObjectStoreException e) { throw new RuntimeException("Unable to load user profile", e); } }
/** * Perform a query to retrieve a user's backing UserProfile * * @param userId the id of the user * @return the relevant UserProfile */ public synchronized UserProfile getUserProfile(Integer userId) { if (userId == null) { return null; } try { return (UserProfile) uosw.getObjectById(userId, UserProfile.class); } catch (ObjectStoreException e) { throw new RuntimeException("Unable to load user profile", e); } }
/** * Return the name of the user with the given internal DB id. * * If no user with that name exists, returns null. * @param profileId the id of the profile. * @return the name of the user, or null. */ public synchronized String getProfileUserName(int profileId) { try { UserProfile profile = (UserProfile) uosw.getObjectById(profileId, UserProfile.class); return profile.getUsername(); } catch (ObjectStoreException e) { return null; // Not in DB. } catch (NullPointerException e) { return null; // profile was null (impossible!) } }
/** * Return the name of the user with the given internal DB id. * * If no user with that name exists, returns null. * @param profileId the id of the profile. * @return the name of the user, or null. */ public synchronized String getProfileUserName(int profileId) { try { UserProfile profile = (UserProfile) uosw.getObjectById(profileId, UserProfile.class); return profile.getUsername(); } catch (ObjectStoreException e) { return null; // Not in DB. } catch (NullPointerException e) { return null; // profile was null (impossible!) } }
/** * Get a user's Profile using an ID * @param id userprofile ID * @return user's profile */ public Profile getProfile(int id) { Map<String, List<FieldDescriptor>> classKeys = getClassKeys(os.getModel()); UserProfile up; try { up = (UserProfile) uosw.getObjectById(id, UserProfile.class); } catch (ObjectStoreException e) { throw new RuntimeException("Error retrieving profile", e); } if (up != null && profileCache.containsKey(up.getUsername())) { return profileCache.get(up.getUsername()); } return wrapUserProfile(up, classKeys); }
@Test public void testWriteCloneable() throws Exception { InterMineObject o = (InterMineObject) DynamicUtil.createObject(new HashSet(Arrays.asList(new Class[] {Employee.class, Cloneable.class}))); try { writer.store(o); o = writer.getObjectById(o.getId(), Employee.class); if (!(o instanceof Cloneable)) { fail("Expected a Cloneable back"); } } finally { writer.delete(o); } }
@Test public void testWriteDynamicObject() throws Exception { InterMineObject o = (InterMineObject) DynamicUtil.createObject(new HashSet(Arrays.asList(new Class[] {Company.class, Employee.class}))); try { writer.store(o); o = writer.getObjectById(o.getId(), Employee.class); if (!(o instanceof Company)) { fail("Expected a Company back"); } if (!(o instanceof Employee)) { fail("Expected an Employee back"); } } finally { writer.delete(o); } }
@Test public void testWriteDynamicObject2() throws Exception { InterMineObject o = (InterMineObject) DynamicUtil.createObject(new HashSet(Arrays.asList(new Class[] {ImportantPerson.class, Employee.class}))); try { writer.store(o); o = writer.getObjectById(o.getId(), Employee.class); if (!(o instanceof ImportantPerson)) { fail("Expected an ImportantPerson back"); } if (!(o instanceof Employee)) { fail("Expected an Employee back"); } } finally { writer.delete(o); } }
@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)); } }
@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)); } }
@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)); } }
@Test public void testWriteCleaner() throws Exception { InterMineObject o = new Cleaner(); try { writer.store(o); o = writer.getObjectById(o.getId(), Employee.class); if (!(o instanceof Cleaner)) { fail("Expected a Cleaner back"); } } finally { writer.delete(o); } }
@Test public void testWriteBigDepartment() throws Exception { InterMineObject o = new BigDepartment(); try { writer.store(o); o = writer.getObjectById(o.getId(), Department.class); if (!(o instanceof BigDepartment)) { fail("Expected a BigDepartment back"); } } finally { writer.delete(o); } }
@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(); } } }