Package org.apache.torque.generator.source

Examples of org.apache.torque.generator.source.SourceElement


            throw new GeneratorException("ApplyAction : The outlet "
                    + outletName
                    + " does not exist");
        }

        SourceElement currentElement = controllerState.getSourceElement();
        String detokenizedPath = tokenReplacer.process(path);

        List<SourceElement> selectedElements
                = SourcePath.getElements(currentElement, detokenizedPath);
        if (selectedElements.isEmpty())
View Full Code Here


        if (domainNameFromSchema == null)
        {
            // no domain specified
            return null;
        }
        SourceElement domainElement = null;
        {
            SourceElement databaseElement
                    = columnElement.getParent().getParent();
            List<SourceElement> domainElementList
                    = databaseElement.getChildren(
                            TorqueSchemaElementName.DOMAIN);
            for (SourceElement candidate : domainElementList)
            {
                if (domainNameFromSchema.equals(candidate.getAttribute(
                        TorqueSchemaAttributeName.NAME)))
View Full Code Here

            ControllerState controllerState)
        throws SourceTransformerException
    {
        List<SourceElement> externalSchemaElementList
                = root.getChildren(TorqueSchemaElementName.EXTERNAL_SCHEMA);
        SourceElement allTables = root.getChild(
                DatabaseChildElementName.ALL_TABLES);
        if (allTables == null)
        {
            allTables = new SourceElement(DatabaseChildElementName.ALL_TABLES);
            root.getChildren().add(allTables);
        }
        SourceElement allViews = root.getChild(
                DatabaseChildElementName.ALL_VIEWS);
        if (allViews == null)
        {
            allViews = new SourceElement(DatabaseChildElementName.ALL_VIEWS);
            root.getChildren().add(allViews);
        }

        String rootDatabaseName = (String) root.getAttribute(
                DatabaseAttributeName.ROOT_DATABASE_NAME);
        for (SourceElement externalSchemaElement : externalSchemaElementList)
        {
            File externalSchemaBaseDir;
            if (this.baseDir == null)
            {
                File currentSourceFile = controllerState.getSourceFile();
                externalSchemaBaseDir = currentSourceFile.getParentFile();
            }
            else
            {
                externalSchemaBaseDir = baseDir;
            }
            String relativePath = externalSchemaElement.getAttribute(
                    TorqueSchemaAttributeName.FILENAME)
                .toString();
            File externalSchemaPath
                = new File(externalSchemaBaseDir, relativePath);
            try
            {
                FileSource fileSource = new FileSource(
                        new XmlSourceFormat(),
                        externalSchemaPath,
                        controllerState);
                SourceElement externalSchemaRootElement
                        = fileSource.getRootElement();
                externalSchemaRootElement.setAttribute(
                        DatabaseAttributeName.ROOT_DATABASE_NAME,
                        rootDatabaseName);
                DatabaseMapInitTransformer.setDatabaseMapInitClassNameAttributes(
                        externalSchemaRootElement,
                        rootDatabaseName,
                        controllerState);

                this.transform(externalSchemaRootElement, controllerState);

                externalSchemaElement.getChildren().add(
                        externalSchemaRootElement);

                SourceElement externalAllTables
                        = externalSchemaRootElement.getChild(
                                DatabaseChildElementName.ALL_TABLES);

                // fill root's all-tables with all external tables
                for (SourceElement externalTable
                        : externalAllTables.getChildren(
                            TorqueSchemaElementName.TABLE))
                {
                    allTables.getChildren().add(externalTable);
                }
                // fill root's all-views with all external views
                for (SourceElement externalView
                        : externalAllTables.getChildren(
                            TorqueSchemaElementName.VIEW))
                {
                    allViews.getChildren().add(externalView);
                }
            }
View Full Code Here

            {
                hits.add(column);
            }
        }

        SourceElement targetElement
                = new SourceElement(targetElementName);
        rootElement.getChildren().add(targetElement);

        for (SourceElement hit : hits)
        {
            targetElement.getChildren().add(hit);
        }
    }
View Full Code Here

            {
                FileSource fileSource = new FileSource(
                        new XmlSourceFormat(),
                        includeSchemaPath,
                        controllerState);
                SourceElement includeSchemaRootElement
                        = fileSource.getRootElement();
                log.trace("successfully read included file "
                        + includeSchemaPath);

                this.transform(includeSchemaRootElement, controllerState);

                // disattach children from their current parent
                // so that the new parent is the primary parent
                List<SourceElement> toIncludeList
                        = new ArrayList<SourceElement>(
                                includeSchemaRootElement.getChildren());
                for (SourceElement childToInclude : toIncludeList)
                {
                    childToInclude.getParents().clear();
                }
View Full Code Here

        }
        if (tableElement.getAttribute(SqlAttributeName.SEQUENCE_NAME)
                == null)
        {
            String sequenceName = null;
            SourceElement idMethodParameterElement = tableElement.getChild(
                    TorqueSchemaElementName.ID_METHOD_PARAMETER);
            if (idMethodParameterElement != null)
            {
                sequenceName = (String) idMethodParameterElement.getAttribute(
                        TorqueSchemaAttributeName.VALUE);
            }
            if (StringUtils.isBlank(sequenceName))
            {
                sequenceName = tableName + "_SEQ";
            }
            tableElement.setAttribute(
                    SqlAttributeName.SEQUENCE_NAME,
                    sequenceName);
        }

        // primary keys
        collectAttributeSetTrueTransformer.transform(
                tableElement,
                controllerState,
                TorqueSchemaElementName.COLUMN,
                TorqueSchemaAttributeName.PRIMARY_KEY,
                TableChildElementName.PRIMARY_KEYS);

        StringBuilder primaryKeyColumnNames = new StringBuilder();
        SourceElement primaryKeysElement = tableElement.getChild(
                TableChildElementName.PRIMARY_KEYS);
        boolean firstPk = true;
        for (SourceElement primaryKeyColumn : primaryKeysElement.getChildren())
        {
            if (!firstPk)
            {
                primaryKeyColumnNames.append(", ");
            }
View Full Code Here

                }
            }
        }
        for (String databaseSchemaName : databaseSchemaNames)
        {
            SourceElement databaseSchemaElement
                = new SourceElement("databaseSchema");
            databaseSchemaElement.setAttribute("name", databaseSchemaName);
            databaseElement.getChildren().add(databaseSchemaElement);
        }
    }
View Full Code Here

        {
            throw new IllegalArgumentException("Illegal element Name "
                    + foreignKey.getName());
        }

        SourceElement localTable = foreignKey.getParent();
        SourceElement database = localTable.getParent();

        String foreignTableName = (String) foreignKey.getAttribute(
                TorqueSchemaAttributeName.FOREIGN_TABLE);
        SourceElement foreignTable
                = FindHelper.findTable(database, foreignTableName, true);
        foreignKey.getChildren().add(foreignTable);

        for (SourceElement reference : foreignKey.getChildren(
                TorqueSchemaElementName.REFERENCE))
View Full Code Here

    */
    private void addForeignField(
            SourceElement foreignKey,
            ControllerState controllerState)
    {
        SourceElement localTable = foreignKey.getParent();
        SourceElement foreignTable = foreignKey.getChild(
                TorqueSchemaElementName.TABLE);
        String referencedBySuffix = getForeignReferencedBySuffix(
                foreignKey, controllerState);
        {
            // the field name for the variable used
            String foreignFieldName = (String) controllerState.getOption(
                        TemplateOptionName.OM_FOREIGN_FIELD_NAME_PREFIX)
                    + localTable.getAttribute(
                            TableAttributeName.DB_OBJECT_CLASS_NAME)
                    + controllerState.getOption(
                            TemplateOptionName.OM_FOREIGN_FIELD_NAME_SUFFIX)
                    + referencedBySuffix;
            // the field name to create the name of the getter and setter
            String getterSetterFieldName
                    = (String) localTable.getAttribute(
                            TableAttributeName.DB_OBJECT_CLASS_NAME)
                        + referencedBySuffix;
            SourceElement foreignFieldElement
                    = new SourceElement(
                            ForeignKeyChildElementName.FOREIGN_FIELD);

            foreignFieldElement.setAttribute(
                    JavaFieldAttributeName.FIELD_NAME,
                    foreignFieldName);
            foreignFieldElement.setAttribute(
                    JavaFieldAttributeName.FIELD_ACCESS_MODIFIER,
                    "protected");
            {
                // the field name to cache the used Criteria
                String criteriaFieldName = "last"
                        + StringUtils.capitalize(getterSetterFieldName)
                        + "Criteria";
                foreignFieldElement.setAttribute(
                        ForeignKeyChildAttributeName
                                .FOREIGN_COLUMN_CRITERIA_CACHE_FIELD,
                        criteriaFieldName);
            }

            String fieldContainedType = (String) localTable.getAttribute(
                    TorqueSchemaAttributeName.JAVA_NAME);
            foreignFieldElement.setAttribute(
                    JavaFieldAttributeName.FIELD_CONTAINED_TYPE,
                    fieldContainedType);

            String fieldType = (String) controllerState.getOption(
                    TemplateOptionName.OM_FOREIGN_FIELD_TYPE)
                    + "<" + fieldContainedType + ">";
            foreignFieldElement.setAttribute(
                    JavaFieldAttributeName.FIELD_TYPE,
                    fieldType);

            foreignFieldElement.setAttribute(
                    JavaFieldAttributeName.DEFAULT_VALUE,
                    "null");
            {
                String getterName = FieldHelper.getGetterName(
                            getterSetterFieldName,
                            fieldType,
                            controllerState)
                        + "s";
                foreignFieldElement.setAttribute(
                        JavaFieldAttributeName.GETTER_NAME,
                        getterName);
            }
            {
                String setterName = FieldHelper.getSetterName(
                            getterSetterFieldName)
                        + "s";
                foreignFieldElement.setAttribute(
                        JavaFieldAttributeName.SETTER_NAME,
                            setterName);
            }
            {
                String adderName = FieldHelper.getAdderName(
                        getterSetterFieldName,
                        controllerState);
                foreignFieldElement.setAttribute(
                        JavaFieldAttributeName.ADDER_NAME,
                        adderName);
            }
            {
                String initializerName = FieldHelper.getInitializerName(
                        getterSetterFieldName,
                        controllerState);
                foreignFieldElement.setAttribute(
                        JavaFieldAttributeName.INITIALIZER_NAME,
                        initializerName);
            }
            {
                String isInitializedName = FieldHelper.getIsInitializedName(
                        getterSetterFieldName,
                        controllerState);
                foreignFieldElement.setAttribute(
                        JavaFieldAttributeName.IS_INITIALIZED_NAME,
                        isInitializedName);
            }
            {
                String initType = (String) controllerState.getOption(
                        TemplateOptionName.OM_FOREIGN_FIELD_INIT_TYPE)
                    + "<" + fieldContainedType + ">";
                foreignFieldElement.setAttribute(
                        JavaFieldAttributeName.INITIALIZER_TYPE,
                        initType);

            }
            {
                String fillerName = FieldHelper.getFillerName(
                        getterSetterFieldName,
                        "",
                        controllerState);
                foreignFieldElement.setAttribute(
                        JavaFieldAttributeName.FILLER_NAME,
                        fillerName);
            }
            {
                String setAndSaveMethodName
                    = FieldHelper.getSetAndSaveMethodName(
                        getterSetterFieldName,
                        "",
                        controllerState);
                foreignFieldElement.setAttribute(
                        "setAndSaveMethodName",
                        setAndSaveMethodName);
            }
            {
                // Name for a getter in the foreign table to
                // retrieve entries in the foreign table plus the joined
                // entries in the local table.
                String joinGetterFieldName
                        = StringUtils.capitalize(getterSetterFieldName)
                        + "sJoin"
                        + foreignTable.getAttribute(
                            TorqueSchemaAttributeName.JAVA_NAME);
                String joinGetterName = FieldHelper.getGetterName(
                        joinGetterFieldName,
                        fieldType,
                        controllerState);
                foreignFieldElement.setAttribute(
                        ForeignKeyChildAttributeName
                            .FOREIGN_FIELD_JOIN_GETTER,
                        joinGetterName);
            }
            {
                // Name for the doSelectJoinXXX method in the Peer Class
                // of the foreign table.
                String peerJoinSelectMethodName
                        = "doSelectJoin"
                            + foreignTable.getAttribute(
                                    TorqueSchemaAttributeName.JAVA_NAME)
                            + referencedBySuffix;
                foreignFieldElement.setAttribute(
                        ForeignKeyChildAttributeName
                            .PEER_JOIN_SELECT_METHOD,
                        peerJoinSelectMethodName);
            }
            {
                // Name for the doSelectJoinAllExceptXXX method
                // in the Peer Class of the foreign table.
                String peerJoinAllExceptSelectMethodName
                        = "doSelectJoinAllExcept"
                            + foreignTable.getAttribute(
                                    TorqueSchemaAttributeName.JAVA_NAME)
                            + referencedBySuffix;
                foreignFieldElement.setAttribute(
                        ForeignKeyChildAttributeName
                            .PEER_JOIN_ALL_EXCEPT_SELECT_METHOD,
                        peerJoinAllExceptSelectMethodName);
            }
            foreignKey.getChildren().add(foreignFieldElement);
View Full Code Here

     */
    private void modifyForeignFieldSecondPass(
            SourceElement foreignKey,
            ControllerState controllerState)
    {
        SourceElement foreignFieldElement
            = foreignKey.getChild(ForeignKeyChildElementName.FOREIGN_FIELD);
        if (foreignFieldElement == null)
        {
            return;
        }
        String setterName = (String) foreignFieldElement.getAttribute(
                JavaFieldAttributeName.SETTER_NAME);
        // setter gets a "s" appended, remove that
        String regularSetterName
                = setterName.substring(0, setterName.length() - 1);
        String fieldName
                = FieldHelper.getFieldNameFromSetterName(regularSetterName);
        String fillerName = FieldHelper.getFillerName(
                fieldName,
                "",
                controllerState);
         // check whether there is a local-field in the referenced table
        // which has the same filler name
        SourceElement referencedTable = foreignKey.getChild(
                TorqueSchemaElementName.TABLE);
        boolean fillerNamingConflictFound = false;
        for (SourceElement referencedTableForeignKey
                : referencedTable.getChildren(
                        TorqueSchemaElementName.FOREIGN_KEY))
        {
            SourceElement referencedTableLocalField
                    = referencedTableForeignKey.getChild(
                            ForeignKeyChildElementName.LOCAL_FIELD);
            if (referencedTableLocalField == null)
            {
                continue;
            }
            String referencedTableFiller
                    = (String) referencedTableLocalField.getAttribute(
                            JavaFieldAttributeName.FILLER_NAME);
            if (fillerName.equals(referencedTableFiller))
            {
                fillerNamingConflictFound = true;
                break;
View Full Code Here

TOP

Related Classes of org.apache.torque.generator.source.SourceElement

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.