Package org.apache.torque.generator.source

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


        {
            properties.load(inputStream);
        }
        catch (IOException e)
        {
            throw new SourceException(
                    "Error parsing Properties source file: " + e.getMessage(),
                    e);
        }
        catch (IllegalArgumentException e)
        {
            throw new SourceException(
                    "Error parsing Properties source file: " + e.getMessage(),
                    e);
        }

        SourceElement result
View Full Code Here


                    + format.getKey());
            result = format.parse(inputStream, controllerState);
        }
        catch (FileNotFoundException e)
        {
            throw new SourceException(
                    "File not found: " + path.getAbsolutePath(),
                    e);
        }
        finally
        {
View Full Code Here

            if (knownElementId != null)
            {
                if (!automaticIds)
                {
                    throw new SourceException(
                            "An element with name " + currentElement.getName()
                            + " occurs at least twice in the source graph,"
                            + " but createIdAttributes is false.");
                }
                result.append(currentIndent)
View Full Code Here

            {
                Class.forName(driver);
            }
            catch (ClassNotFoundException e)
            {
                throw new SourceException(
                        "Could not find database driver class " + driver, e);
            }
            log.debug("DB driver " + driver + " loaded");
        }

        Connection con = null;
        try
        {

            con = DriverManager.getConnection(url, username, password);
            log.debug("DB connection to database " + url + " established");

            DatabaseMetaData dbMetaData = con.getMetaData();

            List<String> tableList = getTableNames(dbMetaData, schema);

            for (int i = 0; i < tableList.size(); i++)
            {
                // Add Table.
                String tableName = (String) tableList.get(i);
                log.debug("Processing table: " + tableName);

                SourceElement table = new SourceElement("table");
                rootElement.getChildren().add(table);
                table.setAttribute("name", tableName);

                List<ColumnMetadata> columns
                        = getColumns(dbMetaData, tableName, schema);
                Set<String> primaryKeys
                        = getPrimaryKeys(dbMetaData, tableName, schema);

                for (ColumnMetadata col : columns)
                {
                    String name = col.getName();
                    Integer type = col.getSqlType();
                    int size = col.getSize().intValue();
                    int scale = col.getDecimalDigits().intValue();

                    Integer nullType = col.getNullType();
                    String defValue = col.getDefValue();

                    SourceElement column = new SourceElement("column");
                    column.setAttribute("name", name);

                    column.setAttribute(
                            "type",
                            SchemaType.getByJdbcType(type).toString());

                    if (size > 0 && (type.intValue() == Types.CHAR
                            || type.intValue() == Types.VARCHAR
                            || type.intValue() == Types.LONGVARCHAR
                            || type.intValue() == Types.DECIMAL
                            || type.intValue() == Types.NUMERIC))
                    {
                        column.setAttribute("size", String.valueOf(size));
                    }

                    if (scale > 0 && (type.intValue() == Types.DECIMAL
                            || type.intValue() == Types.NUMERIC))
                    {
                        column.setAttribute("scale", String.valueOf(scale));
                    }

                    if (primaryKeys.contains(name))
                    {
                        column.setAttribute("primaryKey", "true");
                    }
                    else if (nullType.intValue() == 0)
                    {
                        column.setAttribute("required", "true");
                    }

                    if (StringUtils.isNotEmpty(defValue))
                    {
                        // trim out parens & quotes out of def value.
                        // makes sense for MSSQL. not sure about others.
                        if (defValue.startsWith("(") && defValue.endsWith(")"))
                        {
                            defValue = defValue.substring(1, defValue.length() - 1);
                        }

                        if (defValue.startsWith("'") && defValue.endsWith("'"))
                        {
                            defValue = defValue.substring(1, defValue.length() - 1);
                        }

                        column.setAttribute("default", defValue);
                    }
                    table.getChildren().add(column);
                }

                // Foreign keys for this table.
                Collection<ForeignKeyMetadata> forgnKeys
                        = getForeignKeys(dbMetaData, tableName, schema);
                for (ForeignKeyMetadata foreignKeyMetadata : forgnKeys)
                {
                    SourceElement fk = new SourceElement("foreign-key");
                    fk.setAttribute(
                            "foreignTable",
                            foreignKeyMetadata.getReferencedTable());
                    for (int m = 0; m < foreignKeyMetadata.getLocalColumns().size(); m++)
                    {
                        SourceElement ref = new SourceElement("reference");
                        ref.setAttribute("local", foreignKeyMetadata.getLocalColumns().get(m));
                        ref.setAttribute("foreign", foreignKeyMetadata.getForeignColumns().get(m));
                        fk.getChildren().add(ref);
                    }
                    table.getChildren().add(fk);
                }
            }
        }
        catch (SQLException e)
        {
            throw new SourceException(
                    "Could not retrieve JDBC Metadata from url " + url, e);
        }
        finally
        {
            if (con != null)
View Full Code Here

            parser.parse(xmlStream, handler);
            return handler.getRoot();
        }
        catch (IOException e)
        {
            throw new SourceException(
                    "Error reading XML source file: " + e.getMessage(),
                    e);
        }
        catch (SAXException e)
        {
            throw new SourceException(
                    "Error parsing XML source file: " + e.getMessage(),
                    e);
        }
        catch (ParserConfigurationException e)
        {
            throw new SourceException(
                    "Parser configuration error parsing Properties"
                        + " source file: "
                        + e.getMessage(),
                    e);
        }
View Full Code Here

TOP

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

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.