use of com.google.security.zynamics.binnavi.disassembly.types.SectionPermission in project binnavi by google.
the class PostgreSQLSectionFunctions method loadSections.
/**
* Loads all sections that are associated with the given module.
*
* @param provider The SQL provider that holds the database connection.
* @param module The module whose sections should be loaded.
* @return The list of sections loaded from the database.
* @throws CouldntLoadDataException Thrown if the sections could not be loaded from the database.
*/
public static Map<Section, Integer> loadSections(final SQLProvider provider, final INaviModule module) throws CouldntLoadDataException {
Preconditions.checkNotNull(provider, "Error: provider argument can not be null");
Preconditions.checkNotNull(module, "Error: module argument can not be null");
final HashMap<Section, Integer> sections = Maps.newHashMap();
final String query = "SELECT * FROM get_sections(?)";
try (PreparedStatement statement = provider.getConnection().getConnection().prepareStatement(query)) {
statement.setInt(1, module.getConfiguration().getId());
final ResultSet result = statement.executeQuery();
while (result.next()) {
final int id = result.getInt("id");
final String name = result.getString("name");
Integer commentId = result.getInt("comment_id");
if (result.wasNull()) {
commentId = null;
}
final IAddress startAddress = new CAddress(result.getLong("start_address"));
final IAddress endAddress = new CAddress(result.getLong("end_address"));
final SectionPermission permission = SectionPermission.valueOf(result.getString("permission"));
final byte[] data = result.getBytes("data");
sections.put(new Section(id, name, CommentManager.get(provider), module, startAddress, endAddress, permission, data), commentId);
}
} catch (final SQLException exception) {
throw new CouldntLoadDataException(exception);
}
return sections;
}
Aggregations