private void checkTables() throws SQLException { osw.performUnsafeOperation(TABLE_DEFINITION, new SQLOperation<Void>() { @Override public Void run(PreparedStatement stm) throws SQLException { if (!DatabaseUtil.tableExists(stm.getConnection(), TABLE_NAME)) { LOG.info("Creating preferences table"); stm.execute(); } return null; } }); }
private void checkTables() throws SQLException { osw.performUnsafeOperation(TABLE_DEFINITION, new SQLOperation<Void>() { @Override public Void run(PreparedStatement stm) throws SQLException { if (!DatabaseUtil.tableExists(stm.getConnection(), TABLE_NAME)) { LOG.info("Creating preferences table"); stm.execute(); } return null; } }); }
/** * @param profile userprofile * @throws SQLException if something goes wrong */ public void deleteAllPreferences(final Profile profile) throws SQLException { osw.performUnsafeOperation(DELETE_ALL_PREFERENCES_SQL, new SQLOperation<Void>() { @Override public Void run(PreparedStatement stm) throws SQLException { stm.setInt(1, profile.getUserId()); stm.executeUpdate(); return null; } }); }
/** * @param profile userprofile * @throws SQLException if something goes wrong */ public void deleteAllPreferences(final Profile profile) throws SQLException { osw.performUnsafeOperation(DELETE_ALL_PREFERENCES_SQL, new SQLOperation<Void>() { @Override public Void run(PreparedStatement stm) throws SQLException { stm.setInt(1, profile.getUserId()); stm.executeUpdate(); return null; } }); }
/** * @param profile userprofile * @param key key * @throws SQLException if something goes wrong */ protected void deletePreference(final Profile profile, final String key) throws SQLException { osw.performUnsafeOperation(DELETE_PREFERENCE_SQL, new SQLOperation<Void>() { @Override public Void run(PreparedStatement stm) throws SQLException { stm.setInt(1, profile.getUserId()); stm.setString(2, key); stm.executeUpdate(); return null; } }); }
/** * @param profile userprofile * @param key key * @throws SQLException if something goes wrong */ protected void deletePreference(final Profile profile, final String key) throws SQLException { osw.performUnsafeOperation(DELETE_PREFERENCE_SQL, new SQLOperation<Void>() { @Override public Void run(PreparedStatement stm) throws SQLException { stm.setInt(1, profile.getUserId()); stm.setString(2, key); stm.executeUpdate(); return null; } }); }
/** * @param profile userprofile * @return user preferences * @throws SQLException if userprofile is unavailable */ protected Map<String, String> getPreferences(final Profile profile) throws SQLException { return osw.performUnsafeOperation(FETCH_PREFS_FOR_USER, new SQLOperation<Map<String, String>>() { @Override public Map<String, String> run(PreparedStatement stm) throws SQLException { stm.setInt(1, profile.getUserId()); ResultSet rs = stm.executeQuery(); Map<String, String> ret = new HashMap<String, String>(); while (rs.next()) { ret.put(rs.getString(1), rs.getString(2)); } return ret; } }); }
/** * @param profile userprofile * @return user preferences * @throws SQLException if userprofile is unavailable */ protected Map<String, String> getPreferences(final Profile profile) throws SQLException { return osw.performUnsafeOperation(FETCH_PREFS_FOR_USER, new SQLOperation<Map<String, String>>() { @Override public Map<String, String> run(PreparedStatement stm) throws SQLException { stm.setInt(1, profile.getUserId()); ResultSet rs = stm.executeQuery(); Map<String, String> ret = new HashMap<String, String>(); while (rs.next()) { ret.put(rs.getString(1), rs.getString(2)); } return ret; } }); }
/** * @throws SQLException database has wrong model */ protected void unaccept() throws SQLException { if (acceptedAt == null) { throw new IllegalStateException("This invitation has not been accepted"); } os.performUnsafeOperation(RECORD_UNACCEPTANCE_SQL, new SQLOperation<Void>() { @Override public Void run(PreparedStatement stm) throws SQLException { stm.setString(1, token); stm.executeUpdate(); return null; } }); }
/** * @throws SQLException database has wrong model */ protected void unaccept() throws SQLException { if (acceptedAt == null) { throw new IllegalStateException("This invitation has not been accepted"); } os.performUnsafeOperation(RECORD_UNACCEPTANCE_SQL, new SQLOperation<Void>() { @Override public Void run(PreparedStatement stm) throws SQLException { stm.setString(1, token); stm.executeUpdate(); return null; } }); }
/** * Removes all shares from or to the user with the given id. * This is used as part of the user deletion operation. * * @param userId A user id. */ public void removeAllSharesInvolving(final Integer userId) { if (userId == null) { return; } try { uosw.performUnsafeOperation(DELETE_SHARES_WITH, new SQLOperation<Integer>() { @Override public Integer run(PreparedStatement stm) throws SQLException { stm.setInt(1, userId.intValue()); return stm.executeUpdate(); } }); } catch (SQLException e) { throw new RuntimeException("Errors removing shares", e); } }
/** * * @param wasAccepted true if accepted * @throws SQLException database has wrong model */ protected void setAccepted(final Boolean wasAccepted) throws SQLException { if (acceptedAt != null) { throw new IllegalStateException("This invitation has already been accepted"); } os.performUnsafeOperation(RECORD_ACCEPTANCE_SQL, new SQLOperation<Void>() { @Override public Void run(PreparedStatement stm) throws SQLException { Date now = new Date(); stm.setDate(1, new java.sql.Date(now.getTime())); stm.setBoolean(2, wasAccepted); stm.setString(3, token); stm.executeUpdate(); acceptedAt = now; accepted = wasAccepted; return null; } }); }
/** * Removes all invitations to share resources that were issued by the * user with the given id. This is used as part of the user deletion operation. * * @param userId An id of a user. */ public void removeAllInvitesBy(final Integer userId) { if (userId == null) { LOG.warn("I can't remove invites when the user-id is null"); return; } try { uosw.performUnsafeOperation(REMOVE_USERS_INVITES_SQL, new SQLOperation<Integer>() { @Override public Integer run(PreparedStatement stm) throws SQLException { stm.setInt(1, userId.intValue()); return stm.executeUpdate(); } }); } catch (SQLException e) { throw new RuntimeException("Errors removing invites", e); } }
private void checkDBTablesExist() throws SQLException { final Boolean createdTable = uosw.performUnsafeOperation( getStatementCreatingTable(), CREATE_SB_TABLE); uosw.performUnsafeOperation(getStatementCreatingIndex(), new SQLOperation<Void>() { @Override public Void run(PreparedStatement stm) throws SQLException { if (createdTable) { LOG.info("Creating shared bag table index"); stm.execute(); } return null; } }); uosw.performUnsafeOperation(SharingInvite.getTableDefinition(), CREATE_INVITES_TABLE); }
/** * @throws SQLException database has wrong model * @throws NotFoundException invite not found */ public void delete() throws SQLException, NotFoundException { if (!inDB) { throw new NotFoundException("This invite is not stored in the DB"); } os.performUnsafeOperation(DELETE_SQL, new SQLOperation<Void>() { @Override public Void run(PreparedStatement stm) throws SQLException { stm.setString(0, token); stm.executeUpdate(); inDB = false; return null; } }); }
private void checkDBTablesExist() throws SQLException { final Boolean createdTable = uosw.performUnsafeOperation( getStatementCreatingTable(), CREATE_SB_TABLE); uosw.performUnsafeOperation(getStatementCreatingIndex(), new SQLOperation<Void>() { @Override public Void run(PreparedStatement stm) throws SQLException { if (createdTable) { LOG.info("Creating shared bag table index"); stm.execute(); } return null; } }); uosw.performUnsafeOperation(SharingInvite.getTableDefinition(), CREATE_INVITES_TABLE); }
/** * @throws SQLException database has wrong model * @throws NotFoundException invite not found */ public void delete() throws SQLException, NotFoundException { if (!inDB) { throw new NotFoundException("This invite is not stored in the DB"); } os.performUnsafeOperation(DELETE_SQL, new SQLOperation<Void>() { @Override public Void run(PreparedStatement stm) throws SQLException { stm.setString(0, token); stm.executeUpdate(); inDB = false; return null; } }); }
private void storeShare(final InterMineBag bag, final UserProfile sharedWith) throws UserAlreadyShareBagException { final String userName = sharedWith.getUsername(); try { uosw.performUnsafeOperation(STORE_SHARE_SQL, new SQLOperation<Integer>() { @Override public Integer run(PreparedStatement stm) throws SQLException { stm.setInt(1, bag.getSavedBagId()); stm.setInt(2, sharedWith.getId()); return stm.executeUpdate(); } }); } catch (SQLException e) { throw new UserAlreadyShareBagException("Error sharing the " + " the bag : " + bag.getSavedBagId() + " with the user " + sharedWith.getId(), e); } informProfileOfChange(userName, new CreationEvent(bag)); }
private void storeShare(final InterMineBag bag, final UserProfile sharedWith) throws UserAlreadyShareBagException { final String userName = sharedWith.getUsername(); try { uosw.performUnsafeOperation(STORE_SHARE_SQL, new SQLOperation<Integer>() { @Override public Integer run(PreparedStatement stm) throws SQLException { stm.setInt(1, bag.getSavedBagId()); stm.setInt(2, sharedWith.getId()); return stm.executeUpdate(); } }); } catch (SQLException e) { throw new UserAlreadyShareBagException("Error sharing the " + " the bag : " + bag.getSavedBagId() + " with the user " + sharedWith.getId(), e); } informProfileOfChange(userName, new CreationEvent(bag)); }
/** * @param im API for databases * @param token user auth token * @return object representing the invite * @throws ObjectStoreException error storing the data * @throws SQLException database has wrong model * @throws NotFoundException invite not found */ public static SharingInvite getByToken(final InterMineAPI im, final String token) throws SQLException, ObjectStoreException, NotFoundException { // Unpack what we want from the API. ProfileManager pm = im.getProfileManager(); BagManager bm = im.getBagManager(); ObjectStoreWriterInterMineImpl osw = (ObjectStoreWriterInterMineImpl) pm.getProfileObjectStoreWriter(); IntermediateRepresentation row = osw.performUnsafeOperation(FETCH_SQL, new FetchInviteData(token)); if (row == null) { throw new NotFoundException("token not found"); } SharingInvite invite = restoreFromRow(pm, bm, row); invite.inDB = true; return invite; }