public void setStorageLocationCache(ObjectCache<Integer, StorageLocation> cache) { m_storageLocationCache = cache; m_storageLocationCache.setRefresher( new BinaryFunction<Integer, StorageLocation, Pair<StorageLocation, String[]>>() { public Pair<StorageLocation, String[]> execute( Integer id, StorageLocation oldStorageLocation) { return new Pair<StorageLocation, String[]>(getStorageLocationInternal(id), null); } }); }
public void updateStorageLocation(StorageLocation sl, Connection c) throws SQLException { PreparedStatement stmt = null; String password = m_encryptionManager.encryptPassword(sl.getPassword()); try { stmt = c.prepareStatement( "update storage_location " + "set server_name = ?, storage_directory = ?, " + "mapped_storage_directory = ?, read_only = ?, accessible_remotely = ?, min_free_percent = ?, " + "percent_free = ?, local_only_percent = ?, username = ?, password = ?, domain = ?, management_server = ? where id = ?"); stmt.setString(1, sl.getServer()); stmt.setString(2, sl.getStorageDirectory()); stmt.setString(3, sl.getMappedStorageDirectory()); stmt.setBoolean(4, sl.isReadOnly()); stmt.setBoolean(5, sl.isAccessibleRemotely()); stmt.setInt(6, sl.getMinFreePercent()); stmt.setInt(7, sl.getPercentFree()); stmt.setInt(8, sl.getLocalOnlyPercent()); stmt.setString(9, sl.getUserName()); stmt.setString(10, password); stmt.setString(11, sl.getDomain()); stmt.setString(12, sl.getManagementServer()); stmt.setInt(13, sl.getStorageLocationId()); if (stmt.executeUpdate() != 1) { throw new SQLException( "Unable to update storage location record with id=" + sl.getStorageLocationId()); } m_storageLocationCache.flush(sl.getStorageLocationId()); if (m_partitionManager instanceof IPartitionManagerCacheControl) { IPartitionManagerCacheControl pmcc = (IPartitionManagerCacheControl) m_partitionManager; pmcc.RefreshByStorageLocationId(sl.getStorageLocationId()); } } finally { if (stmt != null) stmt.close(); } }
public StorageLocation getStorageLocation(int storageId) { return m_storageLocationCache.get(storageId); }