Example #1
0
  private OldElement(
      boolean isAttribute,
      Element jdomElement,
      String value,
      List<Element> childrenList,
      String internalName,
      String hidden,
      String hideDisplay,
      String description,
      String displayName,
      String tableConstraint,
      String key,
      String field,
      String pointerDataset,
      String pointerInterface,
      String pointerElement,
      String checkForNulls)
      throws FunctionalException {

    super(jdomElement, internalName);

    if (this.hidden) { // assigned in OldNode
      this.valid = false;
      return;
    }

    this.isAttribute = isAttribute;

    this.hideDisplay = TransformationUtils.getBooleanValueFromString(hideDisplay, "hideDisplay");
    this.description = description;
    this.displayName = displayName;
    this.tableConstraint = tableConstraint;
    this.key = key;
    this.field = field;
    this.pointerDataset = pointerDataset;
    this.pointerInterface = pointerInterface;
    this.pointerElement = pointerElement;
    this.checkForNulls =
        TransformationUtils.getBooleanValueFromString(checkForNulls, "checkForNulls");

    this.hasChildren = childrenList != null && childrenList.size() != 0;
    this.hasSubChildren = false;
    this.tree = false;
    if (this.hasChildren) {
      Element firstChild = childrenList.get(0);
      this.firstChildrenType = ElementChildrenType.getElementChildrenType(firstChild);

      // Will check for the 1st child that has subChildren (if any) and check the type of the
      // subchild
      for (Element child : childrenList) {
        List<Element> subChildrenList = child.getChildren();
        this.hasSubChildren = subChildrenList != null && subChildrenList.size() != 0;
        if (this.hasSubChildren) {
          ElementChildrenType subChildrenType =
              ElementChildrenType.getElementChildrenType(subChildrenList.get(0));
          this.tree =
              ElementChildrenType.OPTION_VALUE.equals(this.firstChildrenType)
                  && ElementChildrenType.OPTION_VALUE.equals(subChildrenType);
          break;
        }
      }
    }

    this.pointer =
        this.pointerElement != null && this.pointerInterface != null && this.pointerDataset != null;

    this.main =
        !this.pointer && tableConstraint != null && TransformationUtils.isMain(tableConstraint);
    this.dimension = !this.pointer && tableConstraint != null && !this.main;

    this.option = this instanceof OldOptionFilter;
    if (this.main || this.dimension) {
      this.nctm = new NamingConventionTableName(this.tableConstraint);
    } else {
      this.filterGroup = !pointer && !this.option;
      MyUtils.checkStatusProgram(
          !this.filterGroup || hasChildren, XmlUtils.displayJdomElement(jdomElement));
    }

    this.dimensionPartition = new DimensionPartition(this.tableConstraint, this.key);
    if (this.dimension) {
      this.dimensionPartition.searchForPotentialDimensionTablePartition();
    }

    if (!finalChecks()) {
      // System.out.println(this.internalName + "
      // ##########@@@@@@@@@@@@@######################*****************####################################");
      System.err.println(
          "######################### element has failed final checks" + this.internalName);
      this.valid = false;
    }
  }
Example #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;
  }