Package org.apache.torque.generator.source

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


    }

    @Test
    public void testPrefixSuffix() throws SourceTransformerException
    {
        SourceElement sourceElement
                = new SourceElement("elementName");
        sourceElement.setAttribute("sourceAttribute", "someProperty");

        transformer.setSourceAttributeName("sourceAttribute");
        transformer.setTargetAttributeName("targetAttribute");
        transformer.setPrefix("prefix");
        transformer.setSuffix("Suffix");
        SourceElement result = transformer.transform(sourceElement, null);
        assertEquals(
                "prefixSomePropertySuffix",
                result.getAttribute("targetAttribute"));
    }
View Full Code Here


    }

    @Test
    public void testNoOverwrite() throws SourceTransformerException
    {
        SourceElement sourceElement
                = new SourceElement("elementName");
        sourceElement.setAttribute("name", "modified");
        sourceElement.setAttribute("targetAttribute", "unmodified");

        transformer.setOverwrite(false);
        transformer.setTargetAttributeName("targetAttribute");
        SourceElement result = transformer.transform(sourceElement, null);
        assertEquals(
                "unmodified",
                result.getAttribute("targetAttribute"));
    }
View Full Code Here

    }

    @Test
    public void testNoOverwriteEmptyTarget() throws SourceTransformerException
    {
        SourceElement sourceElement
                = new SourceElement("elementName");
        sourceElement.setAttribute("name", "source");

        transformer.setOverwrite(false);
        transformer.setTargetAttributeName("targetAttribute");
        SourceElement result = transformer.transform(sourceElement, null);
        assertEquals(
                "source",
                result.getAttribute("targetAttribute"));
    }
View Full Code Here

     * @throws Exception if an error occurs.
     */
    @Test
    public void testXmlOutlet() throws Exception
    {
        SourceElement rootElement = new SourceElement("root");
        rootElement.getChildren().add(new SourceElement("child"));
        ControllerState controllerState = new ControllerState();
        controllerState.setRootElement(rootElement);
        XmlOutlet xmlOutlet = new XmlOutlet(new QualifiedName("test"));
        OutletResult result = xmlOutlet.execute(controllerState);
        assertEquals(
View Full Code Here

     * @throws Exception if an error occurs.
     */
    @Test
    public void testXmlOutletCreateIdAttributes() throws Exception
    {
        SourceElement rootElement = new SourceElement("root");
        rootElement.getChildren().add(new SourceElement("child"));
        ControllerState controllerState = new ControllerState();
        controllerState.setRootElement(rootElement);
        XmlOutlet xmlOutlet = new XmlOutlet(new QualifiedName("test"));
        xmlOutlet.setCreateIdAttributes(true);
        OutletResult result = xmlOutlet.execute(controllerState);
View Full Code Here

     */
    private void addLocalFieldInBean(
            SourceElement foreignKey,
            ControllerState controllerState)
    {
        SourceElement foreignTable = foreignKey.getChild(
                TorqueSchemaElementName.TABLE);
        String referencedBySuffix = getLocalReferencedBySuffix(
                foreignKey, controllerState);
        String beanGetterSetterFieldName
                = (String) foreignTable.getAttribute(
                        TableAttributeName.BEAN_CLASS_NAME)
                    + referencedBySuffix;
        // the field name for the variable used
        String localBeanFieldName = (String) controllerState.getOption(
                TemplateOptionName.OM_LOCAL_FIELD_NAME_PREFIX)
                + foreignTable.getAttribute(
                        TableAttributeName.BEAN_CLASS_NAME)
                + controllerState.getOption(
                        TemplateOptionName.OM_LOCAL_FIELD_NAME_SUFFIX)
                + referencedBySuffix;
        SourceElement localFieldInBeanElement
                = new SourceElement(
                        ForeignKeyChildElementName.LOCAL_FIELD_IN_BEAN);

        localFieldInBeanElement.setAttribute(
                JavaFieldAttributeName.FIELD_NAME,
                localBeanFieldName.toString());

        String fieldType = (String) foreignTable.getAttribute(
                TableAttributeName.BEAN_CLASS_NAME);
        localFieldInBeanElement.setAttribute(
                JavaFieldAttributeName.FIELD_TYPE,
                fieldType);
        localFieldInBeanElement.setAttribute(
                JavaFieldAttributeName.DEFAULT_VALUE,
                "null");
        {
            String getterName = FieldHelper.getGetterName(
                    beanGetterSetterFieldName,
                    fieldType,
                    controllerState);
            localFieldInBeanElement.setAttribute(
                    JavaFieldAttributeName.GETTER_NAME,
                    getterName);
        }
        {
            String setterName = FieldHelper.getSetterName(
                    beanGetterSetterFieldName);
            localFieldInBeanElement.setAttribute(
                    JavaFieldAttributeName.SETTER_NAME,
                    setterName);
        }
        foreignKey.getChildren().add(localFieldInBeanElement);
    }
View Full Code Here

     */
    private void addLocalField(
            SourceElement foreignKey,
            ControllerState controllerState)
    {
        SourceElement foreignTable = foreignKey.getChild(
                TorqueSchemaElementName.TABLE);
        String referencedBySuffix = getLocalReferencedBySuffix(
                foreignKey, controllerState);
        // the field name for the variable used
        String localFieldName = (String) controllerState.getOption(
                TemplateOptionName.OM_LOCAL_FIELD_NAME_PREFIX)
                + foreignTable.getAttribute(
                        TableAttributeName.DB_OBJECT_CLASS_NAME)
                + controllerState.getOption(
                        TemplateOptionName.OM_LOCAL_FIELD_NAME_SUFFIX)
                + referencedBySuffix;
        // the field name to create the getter and setter names
        String getterSetterFieldName
                = (String) foreignTable.getAttribute(
                        TableAttributeName.DB_OBJECT_CLASS_NAME)
                    + referencedBySuffix;

        SourceElement localFieldElement
                = new SourceElement(
                        ForeignKeyChildElementName.LOCAL_FIELD);

        localFieldElement.setAttribute(
                JavaFieldAttributeName.FIELD_NAME,
                localFieldName.toString());
        localFieldElement.setAttribute(
                JavaFieldAttributeName.PROPERTY_NAME,
                getterSetterFieldName.toString());

        String fieldType = (String) foreignTable.getAttribute(
                TableAttributeName.DB_OBJECT_CLASS_NAME);
        localFieldElement.setAttribute(
                JavaFieldAttributeName.FIELD_TYPE,
                fieldType);
        localFieldElement.setAttribute(
                JavaFieldAttributeName.DEFAULT_VALUE,
                "null");
        {
            String getterName = FieldHelper.getGetterName(
                    getterSetterFieldName,
                    fieldType,
                    controllerState);
            localFieldElement.setAttribute(
                    JavaFieldAttributeName.GETTER_NAME,
                    getterName);
        }
        {
            String setterName = FieldHelper.getSetterName(
                    getterSetterFieldName);
            localFieldElement.setAttribute(
                    JavaFieldAttributeName.SETTER_NAME,
                    setterName);
        }
        {
            String fillerName = FieldHelper.getFillerName(
                    getterSetterFieldName,
                    "",
                    controllerState);
            localFieldElement.setAttribute(
                    JavaFieldAttributeName.FILLER_NAME,
                    fillerName);
        }
        foreignKey.getChildren().add(localFieldElement);
    }
View Full Code Here

     */
    private String getLocalReferencedBySuffix(
            SourceElement foreignKey,
            ControllerState controllerState)
    {
        SourceElement localTable = foreignKey.getParent();
        String localTableName = (String) localTable.getAttribute(
                TorqueSchemaAttributeName.NAME);
        String foreignTableName = (String) foreignKey.getAttribute(
                TorqueSchemaAttributeName.FOREIGN_TABLE);

        StringBuilder result = new StringBuilder();
        List<SourceElement> referencesToSameTable
                = FindHelper.findForeignKeyByReferencedTable(
                        localTable,
                        foreignTableName);
        if (referencesToSameTable.size() > 1
                || foreignKey.getAttribute(
                        TorqueSchemaAttributeName.FOREIGN_TABLE)
                    .equals(localTableName))
        {
            result.append((String) controllerState.getOption(
                    TemplateOptionName.OM_LOCAL_FIELD_NAME_RELATED_BY));
            for (SourceElement reference : foreignKey.getChildren(
                    TorqueSchemaElementName.REFERENCE))
            {
                SourceElement localColumnElement
                        = reference.getChildren(
                                ReferenceChildElementName.LOCAL_COLUMN)
                            .get(0);
                SourceElement localColumn
                        = localColumnElement.getChildren(
                                TorqueSchemaElementName.COLUMN)
                            .get(0);
                String fieldName = (String) localColumn.getAttribute(
                        JavaFieldAttributeName.FIELD_NAME);
                result.append(
                        StringUtils.capitalize(fieldName));
            }
        }
View Full Code Here

     */
    private String getForeignReferencedBySuffix(
            SourceElement foreignKey,
            ControllerState controllerState)
    {
        SourceElement localTable = foreignKey.getParent();
        String foreignTableName = (String) foreignKey.getAttribute(
                TorqueSchemaAttributeName.FOREIGN_TABLE);

        StringBuilder result = new StringBuilder();
        List<SourceElement> referencingSameTable
                = FindHelper.findForeignKeyByReferencedTable(
                        localTable,
                        foreignTableName);
        if (referencingSameTable.size() > 1)
        {
            result.append((String) controllerState.getOption(
                    TemplateOptionName.OM_FOREIGN_FIELD_NAME_RELATED_BY));
            for (SourceElement reference : foreignKey.getChildren(
                    TorqueSchemaElementName.REFERENCE))
            {
                SourceElement localColumnElement
                        = reference.getChildren(
                                ReferenceChildElementName.LOCAL_COLUMN)
                            .get(0);
                SourceElement localColumn
                        = localColumnElement.getChildren(
                                TorqueSchemaElementName.COLUMN)
                            .get(0);
                String fieldName = (String) localColumn.getAttribute(
                        JavaFieldAttributeName.FIELD_NAME);
                result.append(
                        StringUtils.capitalize(fieldName));
            }
        }
View Full Code Here

    {
        {
            String foreignColumnName = (String)
                    reference.getAttribute(
                            TorqueSchemaAttributeName.FOREIGN);
            SourceElement foreignColumnElement
                    = new SourceElement(
                            ReferenceChildElementName.FOREIGN_COLUMN);
            SourceElement column
                    = FindHelper.findColumn(foreignTable, foreignColumnName);
            foreignColumnElement.getChildren().add(column);
            reference.getChildren().add(foreignColumnElement);
        }
    }
View Full Code Here

TOP

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

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.