Package org.apache.torque.generator.source

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


    {
        {
            String localColumnName = (String)
                    reference.getAttribute(
                            TorqueSchemaAttributeName.LOCAL);
            SourceElement localColumnElement
                    = new SourceElement(
                            ReferenceChildElementName.LOCAL_COLUMN);
            SourceElement column
                    = FindHelper.findColumn(localTable, localColumnName);
            localColumnElement.getChildren().add(column);
            reference.getChildren().add(localColumnElement);
        }
    }
View Full Code Here


    private void setForeignKeyAttributes(
            SourceElement foreignKey,
            ControllerState controllerState)
    {
        SourceElement foreignTable = foreignKey.getChild(
                TorqueSchemaElementName.TABLE);
        String referencedBySuffix = getLocalReferencedBySuffix(
                foreignKey, controllerState);
        String foreignKeyGetterName = (String) controllerState.getOption(
                TemplateOptionName.OM_FOREIGN_KEY_GETTER_PREFIX)
            + foreignTable.getAttribute(
                    TableAttributeName.DB_OBJECT_CLASS_NAME)
            + controllerState.getOption(
                    TemplateOptionName.OM_FOREIGN_KEY_GETTER_SUFFIX)
            + referencedBySuffix;
        foreignKey.setAttribute(
                ForeignKeyAttributeName.FOREIGN_KEY_GETTER,
                foreignKeyGetterName);

        boolean referencesPrimaryKey = false;
        List<SourceElement> foreignTablePrimaryKeys
                = foreignTable.getChild(TableChildElementName.PRIMARY_KEYS)
                        .getChildren(TorqueSchemaElementName.COLUMN);
        List<SourceElement> foreignTableForeignKeyColumns
            = new ArrayList<SourceElement>();
        for (SourceElement reference
                : foreignKey.getChildren(TorqueSchemaElementName.REFERENCE))
        {
            SourceElement column = reference.getChild(
                    ReferenceChildElementName.FOREIGN_COLUMN)
                        .getChild(TorqueSchemaElementName.COLUMN);
            foreignTableForeignKeyColumns.add(column);
        }
        if (foreignTablePrimaryKeys.size()
View Full Code Here

    private void getParentPath(
            SourceElement sourceElement,
            StringBuilder result)
    {
        SourceElement parent = sourceElement.getParent();
        if (parent == null)
        {
            return;
        }
        result.append(parent.getName());
        if (TorqueSchemaElementName.EXTERNAL_SCHEMA.getName().equals(
                parent.getName()))
        {
            result.append("[")
                .append(parent.getAttribute(TorqueSchemaAttributeName.FILENAME))
                .append("]");
        }
        result.append("/");
        getParentPath(parent, result);
    }
View Full Code Here

        if (columnElement.getAttribute(TorqueSchemaAttributeName.JAVA_TYPE)
                != null)
        {
            return;
        }
        SourceElement databaseElement = columnElement.getParent().getParent();
        String defaultJavaType = (String) databaseElement.getAttribute(
                TorqueSchemaAttributeName.DEFAULT_JAVA_TYPE);
        if (defaultJavaType != null)
        {
            columnElement.setAttribute(
                    TorqueSchemaAttributeName.JAVA_TYPE,
View Full Code Here

                rootElement.getName()))
        {
            throw new IllegalArgumentException("Illegal element Name "
                    + rootElement.getName());
        }
        SourceElement databaseSetsElement
                = new SourceElement(DATABASE_SETS_ELEMENT);
        rootElement.getChildren().add(databaseSetsElement);

        for (SourceElement fileElement
                : rootElement.getChildren(CombinedFileSource.FILE_ELEMENT_NAME))
        {
            SourceElement databaseElement
                    = fileElement.getChild(TorqueSchemaElementName.DATABASE);
            if (databaseElement == null)
            {
                throw new IllegalArgumentException("The root element of file "
                        + fileElement.getAttribute(
                                CombinedFileSource.PATH_ATTRIBUTE_NAME)
                        + " is unknown, should be "
                        + TorqueSchemaElementName.DATABASE.getName());
            }
            String name = (String) databaseElement.getAttribute(
                    TorqueSchemaAttributeName.NAME.getName());
            if (name == null)
            {
                throw new SourceTransformerException("The attribute "
                        + TorqueSchemaAttributeName.NAME.getName()
                        + " on element "
                        + databaseElement.getName()
                        + " is null");
            }
            OMTransformer.setRootDatabaseNameAttribute(databaseElement);
            // load referenced external schemata
            String path = (String) fileElement.getAttribute(
                    CombinedFileSource.PATH_ATTRIBUTE_NAME);
            File pathFile = new File(path);
            SourceTransformer loadExternalSchemaTransformer
                   = new LoadExternalSchemaTransformer(
                           pathFile.getParentFile());
            loadExternalSchemaTransformer.transform(
                    databaseElement,
                    controllerState);

            SourceElement allTablesRoot
                = databaseElement.getChild(DatabaseChildElementName.ALL_TABLES);

            SourceElement databaseSetElement = getDatabaseSetWithDatabaseName(
                    databaseSetsElement,
                    name);
            if (databaseSetElement == null)
            {
                databaseSetElement = new SourceElement(DATABASE_SET_ELEMENT);
                databaseSetElement.setAttribute(
                        TorqueSchemaAttributeName.NAME,
                        name);
                databaseSetsElement.getChildren().add(databaseSetElement);
            }
            for (SourceElement tableElement : allTablesRoot.getChildren(
                    TorqueSchemaElementName.TABLE))
            {
                databaseSetElement.getChildren().add(tableElement);
            }
        }

        for (SourceElement databaseSetElement
                : databaseSetsElement.getChildren(DATABASE_SET_ELEMENT))
        {
            String name = (String) databaseSetElement.getAttribute(
                    TorqueSchemaAttributeName.NAME);
            setDatabaseMapInitClassNameAttributes(
                    databaseSetElement,
                    name,
                    controllerState);
            super.transform(databaseSetElement, controllerState);
            for (SourceElement tableElement
                : databaseSetElement.getChildren(TorqueSchemaElementName.TABLE))
            {
                tableTransformer.transform(tableElement, controllerState);
            }
        }
        return rootElement;
View Full Code Here

                                + TorqueSchemaAttributeName.INHERITANCE
                                + " set to \"single\" found in table "
                                + tableElement.getAttribute(
                                        tableElement.getName()));
                }
                SourceElement inheritanceColumnElement
                        = new SourceElement(
                                TableChildElementName.INHERITANCE_COLUMN);
                inheritanceColumnElement.getChildren().add(columnElement);
                tableElement.getChildren().add(inheritanceColumnElement);
                inheritanceFound = true;
            }
        }
    }
View Full Code Here

            throw new IllegalArgumentException("Illegal element Name "
                    + column.getName());
        }
        Object localColumnName
                = column.getAttribute(TorqueSchemaAttributeName.NAME);
        SourceElement localTable = column.getParent();
        Object localTableName
                = localTable.getAttribute(TorqueSchemaAttributeName.NAME);
        SourceElement database = localTable.getParent();

        // create the referencedColumn elements
        {
            List<SourceElement> tableForeignKeys
                    = localTable.getChildren(
                        TorqueSchemaElementName.FOREIGN_KEY.getName());

            // find foreign keys with this column as local reference
            // and create a referencedColumn element for each.
            for (SourceElement foreignKey : tableForeignKeys)
            {
                List<SourceElement> references
                        = foreignKey.getChildren(
                            TorqueSchemaElementName.REFERENCE.getName());
                for (SourceElement reference : references)
                {
                    if (localColumnName.equals(reference.getAttribute(
                            TorqueSchemaAttributeName.LOCAL)))
                    {
                        SourceElement referencedColumn
                                = new SourceElement(
                                    ColumnChildElementName.REFERENCED_COLUMN);
                        referencedColumn.getChildren().add(foreignKey);
                        String foreignTableName
                                = (String) foreignKey.getAttribute(
                                    TorqueSchemaAttributeName.FOREIGN_TABLE);
                        String foreignColumnName
                                = (String) reference.getAttribute(
                                        TorqueSchemaAttributeName.FOREIGN);
                        SourceElement foreignTable = FindHelper.findTable(
                                database,
                                foreignTableName,
                                true);
                        if (foreignTable == null)
                        {
                            throw new SourceTransformerException(
                                    "Foreign table with name "
                                    + foreignTableName
                                    + " not found for a foreignKey of table "
                                    + localTableName);
                        }
                        SourceElement foreignColumn = FindHelper.findColumn(
                                foreignTable,
                                foreignColumnName);
                        if (foreignColumn == null)
                        {
                            throw new SourceTransformerException(
                                    "Referenced Column with table name "
                                    + foreignTableName
                                    + " and column name "
                                    + foreignColumnName
                                    + " not found for a foreignKey of table "
                                    + localTableName);
                        }
                        referencedColumn.getChildren().add(foreignColumn);
                        column.getChildren().add(referencedColumn);
                        break;
                    }
                }
            }
        }

        //create the referencing-column elements
        List<SourceElement> allTables
                = database.getChildren(TorqueSchemaElementName.TABLE.getName());
        for (SourceElement foreignTable : allTables)
        {
            String foreignTableName
                    = (String) foreignTable.getAttribute(
                            TorqueSchemaAttributeName.NAME);
            List<SourceElement> foreignKeys
                    = foreignTable.getChildren(
                        TorqueSchemaElementName.FOREIGN_KEY.getName());
            for (SourceElement foreignKey : foreignKeys)
            {
                if (!localTableName.equals(foreignKey.getAttribute(
                        TorqueSchemaAttributeName.FOREIGN_TABLE)))
                {
                    continue;
                }
                List<SourceElement> references
                        = foreignKey.getChildren(
                            TorqueSchemaElementName.REFERENCE.getName());
                for (SourceElement reference : references)
                {
                    Object referenceForeignColumnName
                            = reference.getAttribute(
                                    TorqueSchemaAttributeName.FOREIGN);
                    String referenceLocalColumnName
                            = (String) reference.getAttribute(
                                    TorqueSchemaAttributeName.LOCAL);
                    if (localColumnName.equals(referenceForeignColumnName))
                    {
                        SourceElement referencingColumn
                                = new SourceElement(
                                        ColumnChildElementName.REFERENCING_COLUMN);
                        referencingColumn.getChildren().add(foreignKey);
                        referencingColumn.getChildren().add(foreignTable);
                        SourceElement localColumn = FindHelper.findColumn(
                                foreignTable,
                                referenceLocalColumnName);
                        if (localColumn == null)
                        {
                            throw new SourceTransformerException(
View Full Code Here

    public void transform(
            SourceElement table,
            ControllerState controllerState)
        throws SourceTransformerException
    {
        SourceElement database = table.getParent();
        String tableName = (String) table.getAttribute(
                TorqueSchemaAttributeName.NAME.getName());
        List<SourceElement> referencingForeignKeys
                = new ArrayList<SourceElement>();
        for (SourceElement otherTable : database.getChildren(
                TorqueSchemaElementName.TABLE.getName()))
        {
            List<SourceElement> referencingFromOtherTable
                    = FindHelper.findForeignKeyByReferencedTable(
                        otherTable,
                        tableName);
            referencingForeignKeys.addAll(referencingFromOtherTable);
        }

        SourceElement referencingForeignKeysElement
                = new SourceElement(
                        TableChildElementName.REFERENCING_FOREIGN_KEYS);
        table.getChildren().add(referencingForeignKeysElement);

        for (SourceElement foreignKey : referencingForeignKeys)
        {
            referencingForeignKeysElement.getChildren().add(foreignKey);
        }
    }
View Full Code Here

        }
        inheritanceElement.setAttribute(
                InheritanceAttributeName.CLASSKEY_CONSTANT,
                "CLASSKEY_" + key.toUpperCase());

        SourceElement tableElement
                = inheritanceElement.getParent().getParent();
        String className = (String) inheritanceElement.getAttribute(
                TorqueSchemaAttributeName.CLASS.getName());
        if (className == null)
        {
            className = (String) tableElement.getAttribute(
                    TableAttributeName.DB_OBJECT_CLASS_NAME);
        }
        inheritanceElement.setAttribute(
                InheritanceAttributeName.CLASS_NAME, className);
        inheritanceElement.setAttribute(
                InheritanceAttributeName.PACKAGE,
                tableElement.getAttribute(
                        TableAttributeName.DB_OBJECT_PACKAGE));
        {
            String extendsAttribute = (String) inheritanceElement.getAttribute(
                    TorqueSchemaAttributeName.EXTENDS.getName());
            String beanExtends = (String) inheritanceElement.getAttribute(
                    InheritanceAttributeName.BEAN_EXTENDS);
            if (extendsAttribute == null)
            {
                extendsAttribute = (String) tableElement.getAttribute(
                        TableAttributeName.DB_OBJECT_CLASS_NAME);
                inheritanceElement.setAttribute(
                        TorqueSchemaAttributeName.EXTENDS.getName(),
                        extendsAttribute);
                inheritanceElement.setAttribute(
                        InheritanceAttributeName.BEAN_EXTENDS,
                        tableElement.getAttribute(
                                TableAttributeName.BEAN_CLASS_NAME));
            }
            else if (beanExtends == null)
            {
                // we try to guess the extendsBean from extends
                // and the bean package
                int lastDot = extendsAttribute.lastIndexOf(".");
                String unqualifiedClassname;
                if (lastDot != -1)
                {
                    unqualifiedClassname
                            = extendsAttribute.substring(lastDot + 1);
                }
                else
                {
                    unqualifiedClassname = extendsAttribute;
                }
                beanExtends = controllerState.getOption(
                            "torque.om.className.beanClassNamePrefix")
                        + unqualifiedClassname
                        + controllerState.getOption(
                            "torque.om.className.beanClassNameSuffix");
                inheritanceElement.setAttribute(
                        InheritanceAttributeName.BEAN_EXTENDS,
                        beanExtends);
            }
        }
        {
            int lastDot = className.lastIndexOf(".");
            String unqualifiedClassname;
            if (lastDot != -1)
            {
                unqualifiedClassname
                        = className.substring(lastDot + 1);
            }
            else
            {
                unqualifiedClassname = className;
            }
            String beanClassName = controllerState.getOption(
                        "torque.om.className.beanClassNamePrefix")
                    + unqualifiedClassname
                    + controllerState.getOption(
                        "torque.om.className.beanClassNameSuffix");
            inheritanceElement.setAttribute(
                    InheritanceAttributeName.BEAN_CLASS_NAME,
                    beanClassName);

        }
        inheritanceElement.setAttribute(
                InheritanceAttributeName.BEAN_PACKAGE,
                tableElement.getAttribute(
                        TableAttributeName.BEAN_PACKAGE));
    }
View Full Code Here

        if (searchExternalSchemata)
        {
            for (SourceElement externalSchema : root.getChildren(
                    TorqueSchemaElementName.EXTERNAL_SCHEMA))
            {
                SourceElement databaseElement
                    = externalSchema.getChild(TorqueSchemaElementName.DATABASE);
                SourceElement result = findTable(
                        databaseElement,
                        tableName,
                        searchExternalSchemata);
                if (result != null)
                {
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.