Пример #1
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;
  }