public StorageLocation initializeStorageLocation(StorageLocation locToPersist, Connection c) throws SQLException { PreparedStatement updateStmt = null; Statement schemaStmt = null; if (locToPersist == null) { throw new SQLException("Null StorageLocation"); } String password = m_encryptionManager.encryptPassword(locToPersist.getPassword()); try { // insert partition storage location record updateStmt = c.prepareStatement( "insert into storage_location (id, server_name, " + "storage_directory, mapped_storage_directory, min_free_percent, " + "local_only_percent, local_bias_multiplier, storage_type, username, password, domain, management_server) " + "values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"); updateStmt.setInt(1, locToPersist.getStorageLocationId()); updateStmt.setString(2, locToPersist.getServer()); updateStmt.setString(3, locToPersist.getStorageDirectory()); updateStmt.setString(4, locToPersist.getMappedStorageDirectory()); updateStmt.setInt(5, PartitionManager.DEFAULT_MIN_FREE_PERCENT); updateStmt.setInt(6, PartitionManager.DEFAULT_LOCAL_ONLY_PERCENT); updateStmt.setInt(7, DEFAULT_LOCAL_BIAS_MULTIPLIER); updateStmt.setString(8, locToPersist.getStorageType()); updateStmt.setString(9, locToPersist.getUserName()); updateStmt.setString(10, password); updateStmt.setString(11, locToPersist.getDomain()); updateStmt.setString(12, locToPersist.getManagementServer()); if (updateStmt.executeUpdate() != 1) { throw new SQLException( "Unable to insert StorageLocation record with id=" + locToPersist.getStorageLocationId() + ", server=" + locToPersist.getServer()); } updateStmt.close(); updateStmt = null; m_storageLocationIdsCache.flush(); // Instead of creating a new partition and have defaults defined in the DB and in code, just // pull the newly created partition from the DB and // rely on the DB defaults return getStorageLocationInternal(locToPersist.getStorageLocationId(), c); } catch (SQLException e) { throw e; } finally { if (updateStmt != null) updateStmt.close(); if (schemaStmt != null) schemaStmt.close(); } }
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(); } }