mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

Glenn Van Lint
24.59.2013 6faf0bb55b0a7d0e63b664ad90b588da16877592
Added documentation.
1 files modified
59 ■■■■ changed files
opendj3/opendj-virtual/src/main/java/org/forgerock/opendj/virtual/MappingConfigurationManager.java 59 ●●●● patch | view | raw | blame | history
opendj3/opendj-virtual/src/main/java/org/forgerock/opendj/virtual/MappingConfigurationManager.java
@@ -32,41 +32,70 @@
import java.util.Properties;
import java.util.Set;
/**
 * The JDBC configuration manager for the JDBCMapper which can save mapping to and read mapping from the
 * MappingConfig.properties file.
 */
public class MappingConfigurationManager 
{
  private JDBCMapper JDBCM;
  private JDBCMapper jdbcMapper;
  private Properties prop;
  public MappingConfigurationManager(JDBCMapper jdbcm){
    prop = new Properties();
    JDBCM = jdbcm;
  /**
   * Creates a new JDBC mapping configuration manager.
   *
   * @param jdbcmapper
   *            The JDBCMapper object to configure mapping for.
   */
  public MappingConfigurationManager(JDBCMapper jdbcmapper)
  {
    this.prop = new Properties();
    this.jdbcMapper = jdbcmapper;
  }
  public void saveMapping(Map<String, String> mapper){
  /**
   * Saves the provided mapping to the MappingConfig.properties file.
   *
   * @param mapping
   *            The mapping to save to the MappingConfig.properties file.
   * @throws IOException
   *            If an I/O exception error occurs.
   */
  public void saveMapping(Map<String, String> mapping)
  {
    String mappingKey, mappingValue;
    Set<String> mapperKeySet = mapper.keySet();
    try {
    final Set<String> mapperKeySet = mapping.keySet();
    try
    {
      for(Iterator<String> i = mapperKeySet.iterator(); i.hasNext(); ){
        mappingKey = i.next();
        mappingValue = mapper.get(mappingKey);
        mappingValue = mapping.get(mappingKey);
        prop.setProperty(mappingKey, mappingValue);
      }
      prop.store(new FileOutputStream("MappingConfig.properties"), null);
    } catch (IOException ex) {
    }catch (IOException ex) {
      ex.printStackTrace();
    }
  }
  public Map<String, String> loadMapping() throws SQLException{
  /**
   * Load the mapping from the MappingConfig.properties file.
   *
   * @throws SQLException
   *            If the SQL query has an invalid format.
   * @throws IOException
   *            If an I/O exception error occurs.
   */
  public Map<String, String> loadMapping() throws SQLException
  {
    try {
      prop.load(new FileInputStream("MappingConfig.properties"));
      ArrayList<String> tableNames = JDBCM.getTables();
      Map<String, String> mapper = new HashMap<String, String>();
      final ArrayList<String> tableNames = jdbcMapper.getTables();
      final Map<String, String> mapper = new HashMap<String, String>();
      for(int i = 0; i < tableNames.size(); i++){
        String columnName, mappingKey, mappingValue, tableName = tableNames.get(i);
        ArrayList<String> columnNames = JDBCM.getTableColumns(tableName);
        final ArrayList<String> columnNames = jdbcMapper.getTableColumns(tableName);
        for(Iterator<String> j = columnNames.iterator(); j.hasNext(); ) {
          columnName = j.next();
@@ -82,4 +111,4 @@
      return null;
    }
  }
}
}