Ejemplo n.º 1
0
 private boolean checkDatabaseForTable(String templateName, String tableName) {
   TemplateDatabaseDescription templateDatabaseDescription =
       templateNameToDatabaseDescriptionMap.get(templateName);
   MyUtils.checkStatusProgram(templateDatabaseDescription != null);
   List<String> tableList = templateDatabaseDescription.getTableList();
   return MartConfiguratorUtils.containsIgnoreCase(tableList, tableName);
 }
Ejemplo n.º 2
0
 private boolean checkDatabaseForField(String templateName, String tableName, String columnName)
     throws FunctionalException {
   TemplateDatabaseDescription templateDatabaseDescription =
       templateNameToDatabaseDescriptionMap.get(templateName);
   MyUtils.checkStatusProgram(templateDatabaseDescription != null);
   Map<String, List<String>> tableColumnMap = templateDatabaseDescription.getTableColumnMap();
   List<String> columnList = tableColumnMap.get(tableName);
   if (null == columnList) {
     throw new FunctionalException("No table called " + tableName + " found in map");
   }
   return MartConfiguratorUtils.containsIgnoreCase(columnList, columnName);
 }
Ejemplo n.º 3
0
  public void fetchTableColumnMap(String templateName) throws TechnicalException {

    String databaseName = getDatabaseName(templateName);
    MyUtils.checkStatusProgram(null != databaseName);

    try {

      Map<String, List<String>> tableColumnMap = null;
      TemplateDatabaseDescription templateDatabaseDescription =
          templateNameToDatabaseDescriptionMap.get(templateName);
      MyUtils.checkStatusProgram(templateDatabaseDescription != null);

      String tableColumnMapContentSerialFilePathAndName =
          this.transformationsGeneralSerialFolderPathAndName
              + TABLE_COLUMN_LIST_SERIAL_FILE_PREFIX
              + databaseName;
      if (new File(tableColumnMapContentSerialFilePathAndName).exists()) {
        tableColumnMap =
            (Map<String, List<String>>)
                MyUtils.readSerializedObject(tableColumnMapContentSerialFilePathAndName);
        System.out.println("Using serial, quick check: " + tableColumnMap.size());
      } else {

        System.out.println(
            "No serial at " + tableColumnMapContentSerialFilePathAndName + " , connecting...");
        connect(databaseName);

        tableColumnMap = new HashMap<String, List<String>>();
        List<String> tableList = templateDatabaseDescription.getTableList();
        int table = 0;
        for (String tableName : tableList) {

          System.out.print(
              "tableName = " + tableName + ", " + (table + 1) + "/" + tableList.size());

          // Prepare list of descriptions
          this.preparedStatementField = this.connection.prepareStatement("desc " + tableName);

          ResultSet resultSet = this.preparedStatementField.executeQuery();

          List<String> columnList = new ArrayList<String>();
          resultSet.beforeFirst();
          while (resultSet.next()) {
            columnList.add(resultSet.getString(1));
          }

          tableColumnMap.put(tableName, columnList);

          this.preparedStatementField.close();
          resultSet.close();

          System.out.println(", " + columnList.size());

          table++;
        }

        disconnect();

        MyUtils.writeSerializedObject(tableColumnMap, tableColumnMapContentSerialFilePathAndName);
      }

      templateDatabaseDescription.setTableColumnMap(tableColumnMap);

    } catch (SQLException e) {
      throw new TechnicalException(e);
    }
  }