Beispiel #1
0
  public void fetchTableList(String templateName) throws TechnicalException {

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

    try {
      List<String> tableList = null;
      String tableListSerialFilePathAndName =
          this.transformationsGeneralSerialFolderPathAndName
              + TABLE_LIST_SERIAL_FILE_PREFIX
              + databaseName;
      if (new File(tableListSerialFilePathAndName).exists()) {
        tableList = (List<String>) MyUtils.readSerializedObject(tableListSerialFilePathAndName);
        System.out.println("Using serial, quick check: " + tableList.size());
      } else {
        System.out.println("No serial at " + tableListSerialFilePathAndName + " , connecting...");
        connect(databaseName);

        tableList = new ArrayList<String>();

        // Prepare list of tables
        this.preparedStatementTable = this.connection.prepareStatement("show tables");

        ResultSet resultSet = this.preparedStatementTable.executeQuery();

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

        this.preparedStatementTable.close();
        resultSet.close();

        disconnect();

        MyUtils.writeSerializedObject(tableList, tableListSerialFilePathAndName);
      }

      MyUtils.checkStatusProgram(templateNameToDatabaseDescriptionMap.get(templateName) == null);
      templateNameToDatabaseDescriptionMap.put(
          templateName, new TemplateDatabaseDescription(tableList));

    } catch (SQLException e) {
      throw new TechnicalException(e);
    }
  }
Beispiel #2
0
  public Document fetchTemplateXml(String virtualSchema, String templateName, String databaseName)
      throws TechnicalException {

    Document document = null;
    try {
      String templateXmlSerialFilePathAndName =
          this.transformationsGeneralSerialFolderPathAndName
              + TEMPLATE_XML_CONTENT_SERIAL_FILE_PREFIX
              + virtualSchema
              + MyUtils.INFO_SEPARATOR
              + MyUtils.INFO_SEPARATOR
              + templateName;
      String templateXmlFilePathAndName =
          this.transformationsGeneralSerialFolderPathAndName
              + virtualSchema
              + MyUtils.INFO_SEPARATOR
              + MyUtils.INFO_SEPARATOR
              + templateName;
      if (new File(templateXmlSerialFilePathAndName).exists()) {
        System.out.println("Using serial at " + templateXmlSerialFilePathAndName);
        document = (Document) MyUtils.readSerializedObject(templateXmlSerialFilePathAndName);
        System.out.println("quick check: " + document.getDocType());
      } else {
        System.out.println("No serial at " + templateXmlSerialFilePathAndName + " , connecting...");
        connect(databaseName);

        this.preparedStatementTemplateXml =
            this.connection.prepareStatement(
                "select meta_template__xml__dm.compressed_xml "
                    + "from meta_template__xml__dm "
                    + "where meta_template__xml__dm.template = '"
                    + templateName
                    + "';");

        ResultSet resultSet = this.preparedStatementTemplateXml.executeQuery();

        resultSet.first();
        byte[] bytes = resultSet.getBytes(1);
        MyUtils.checkStatusProgram(!resultSet.next()); // Check only 1 row

        this.preparedStatementTemplateXml.close();
        resultSet.close();

        disconnect();

        /* Transform into uncompressed XML document:
        	Compression of XML in MartEditor, see:
        		DatabaseDatasetConfigUtils.storeTemplateXML (compress)
        		MartRegistryXMLUtils.DataSourceToRegistryDocument (uncompress)
        */
        InputStream rstream = null;
        rstream = new GZIPInputStream(new ByteArrayInputStream(bytes));
        SAXBuilder builder = new SAXBuilder();
        InputSource is = new InputSource(rstream);
        document = builder.build(is);

        MyUtils.writeSerializedObject(document, templateXmlSerialFilePathAndName);
        XmlUtils.writeXmlFile(document, templateXmlFilePathAndName);
      }
    } catch (SQLException e) {
      throw new TechnicalException(e);
    } catch (JDOMException e) {
      throw new TechnicalException(e);
    } catch (IOException e) {
      throw new TechnicalException(e);
    }
    return document;
  }
Beispiel #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);
    }
  }
Beispiel #4
0
  public void fetchDatasetInformation() throws TechnicalException {

    try {
      String databaseMapSerialFilePathAndName =
          this.serialFolderPathAndName + DATABASE_MAP_SERIAL_FILE_NAME;
      String templateMapSerialFilePathAndName =
          this.serialFolderPathAndName + TEMPLATE_MAP_SERIAL_FILE_NAME;
      String datasetMapSerialFilePathAndName =
          this.serialFolderPathAndName + DATASET_MAP_SERIAL_FILE_NAME;
      String datasetMap2SerialFilePathAndName =
          this.serialFolderPathAndName + DATASET_MAP2_SERIAL_FILE_NAME;
      if (new File(databaseMapSerialFilePathAndName).exists()
          && new File(templateMapSerialFilePathAndName).exists()
          && new File(datasetMapSerialFilePathAndName).exists()
          && new File(datasetMap2SerialFilePathAndName).exists()) {
        databaseNameToDatasetInformationMap =
            (HashMap<String, HashMap<String, List<String>>>)
                MyUtils.readSerializedObject(databaseMapSerialFilePathAndName);
        System.out.println(
            "Using serial, quick check: " + this.databaseNameToDatasetInformationMap.size());
        /*datasetNameToDatabaseNameMap = (HashMap<String, String>)MyUtils.readSerializedObject(
        		datasetMapSerialFilePathAndName);
        System.out.println("Using serial, quick check: " + this.datasetNameToDatabaseNameMap.size());*/
        templateNameToDatabaseNameMap =
            (HashMap<String, String>)
                MyUtils.readSerializedObject(templateMapSerialFilePathAndName);
        System.out.println(
            "Using serial, quick check: " + this.templateNameToDatabaseNameMap.size());
        datasetNameToTemplateName =
            (HashMap<String, String>) MyUtils.readSerializedObject(datasetMapSerialFilePathAndName);
        System.out.println("Using serial, quick check: " + this.datasetNameToTemplateName.size());
        datasetNameToDatasetType =
            (HashMap<String, String>)
                MyUtils.readSerializedObject(datasetMap2SerialFilePathAndName);
        System.out.println("Using serial, quick check: " + this.datasetNameToDatasetType.size());
      } else {

        System.out.println("No serial at " + databaseMapSerialFilePathAndName + " , connecting...");

        this.databaseNameToDatasetInformationMap =
            new HashMap<String, HashMap<String, List<String>>>();

        // Check every database for the dataset or the template name
        for (String databaseName : this.databaseNames) {

          connect(databaseName);

          // Prepare list of tables
          this.preparedStatementDatabase =
              this.connection.prepareStatement(
                  "select meta_conf__dataset__main.dataset, meta_conf__dataset__main.type, meta_template__template__main.template "
                      + "from meta_conf__dataset__main, meta_template__template__main "
                      + "where meta_conf__dataset__main.dataset_id_key = meta_template__template__main.dataset_id_key;");

          ResultSet resultSet = this.preparedStatementDatabase.executeQuery();
          HashMap<String, List<String>> map = new HashMap<String, List<String>>();
          resultSet.beforeFirst();
          while (resultSet.next()) {
            String datasetName = resultSet.getString(1);
            String datasetType = resultSet.getString(2);
            String templateName = resultSet.getString(3);

            List<String> list = map.get(templateName);
            if (null == list) {
              list = new ArrayList<String>();
            }
            list.add(datasetName);
            map.put(templateName, list);

            MyUtils.checkStatusProgram(
                TransformationUtils.isGenomicSequence(datasetType)
                    || TransformationUtils.isTableSet(datasetType));

            /*MyUtils.checkStatusProgram(datasetNameToDatabaseNameMap.get(datasetName)==null);
            datasetNameToDatabaseNameMap.put(datasetName, databaseName);*/

            MyUtils.checkStatusProgram(datasetNameToTemplateName.get(datasetName) == null);
            datasetNameToTemplateName.put(datasetName, templateName);

            MyUtils.checkStatusProgram(datasetNameToDatasetType.get(datasetName) == null);
            datasetNameToDatasetType.put(datasetName, datasetType);

            String databaseNameTmp = templateNameToDatabaseNameMap.get(templateName);
            if (null == databaseNameTmp) {
              templateNameToDatabaseNameMap.put(templateName, databaseName);
            } else {
              MyUtils.checkStatusProgram(databaseNameTmp.equals(databaseName));
            }
          }

          this.preparedStatementDatabase.close();
          resultSet.close();

          disconnect();

          MyUtils.checkStatusProgram(
              this.databaseNameToDatasetInformationMap.get(databaseName) == null);
          this.databaseNameToDatasetInformationMap.put(databaseName, map);

          MyUtils.writeSerializedObject(
              this.databaseNameToDatasetInformationMap, databaseMapSerialFilePathAndName);
          // MyUtils.writeSerializedObject(this.datasetNameToDatabaseNameMap,
          // datasetMapSerialFilePathAndName);
          MyUtils.writeSerializedObject(
              this.templateNameToDatabaseNameMap, templateMapSerialFilePathAndName);
          MyUtils.writeSerializedObject(
              this.datasetNameToTemplateName, datasetMapSerialFilePathAndName);
          MyUtils.writeSerializedObject(
              this.datasetNameToDatasetType, datasetMap2SerialFilePathAndName);
        }
      }

      System.out.println(databaseNameToDatasetInformationMap);
    } catch (SQLException e) {
      throw new TechnicalException(e);
    }
  }