db-torque-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tfisc...@apache.org
Subject svn commit: r1485956 - in /db/torque/torque4/trunk: torque-runtime/src/main/java/org/apache/torque/dsfactory/ torque-templates/src/main/java/org/apache/torque/templates/transformer/sql/ torque-templates/src/main/java/org/apache/torque/templates/typemap...
Date Fri, 24 May 2013 07:55:48 GMT
Author: tfischer
Date: Fri May 24 07:55:47 2013
New Revision: 1485956

URL: http://svn.apache.org/r1485956
Log:
remove unused code
moce duplicate code to a common location

Removed:
    db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/typemapping/SqlTypeWithJdbcType.java
Modified:
    db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/dsfactory/AbstractDataSourceFactory.java
    db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/dsfactory/PerUserPoolDataSourceFactory.java
    db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/dsfactory/SharedPoolDataSourceFactory.java
    db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/sql/SQLModelTransformer.java
    db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/typemapping/SqlType.java

Modified: db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/dsfactory/AbstractDataSourceFactory.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/dsfactory/AbstractDataSourceFactory.java?rev=1485956&r1=1485955&r2=1485956&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/dsfactory/AbstractDataSourceFactory.java
(original)
+++ db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/dsfactory/AbstractDataSourceFactory.java
Fri May 24 07:55:47 2013
@@ -29,6 +29,7 @@ import org.apache.commons.beanutils.Mapp
 import org.apache.commons.beanutils.PropertyUtils;
 import org.apache.commons.configuration.Configuration;
 import org.apache.commons.dbcp.cpdsadapter.DriverAdapterCPDS;
+import org.apache.commons.dbcp.datasources.InstanceKeyDataSource;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.torque.Torque;
@@ -75,7 +76,7 @@ public abstract class AbstractDataSource
      * @param ds the <code>DataSource</code> instance to write the property to
      * @throws Exception if anything goes wrong
      */
-    protected void setProperty(String property, Configuration c, Object ds)
+    protected void setProperty(String property, final Configuration c, final Object ds)
         throws Exception
     {
         if (c == null || c.isEmpty())
@@ -181,7 +182,7 @@ public abstract class AbstractDataSource
      * @param o The object to apply the properties to
      * @throws TorqueException if a property set fails
      */
-    protected void applyConfiguration(Configuration c, Object o)
+    protected void applyConfiguration(final Configuration c, final Object o)
         throws TorqueException
     {
         log.debug("applyConfiguration(" + c + ", " + o + ")");
@@ -211,7 +212,7 @@ public abstract class AbstractDataSource
      * @throws TorqueException if a property set fails
      * @return a configured <code>ConnectionPoolDataSource</code>
      */
-    protected ConnectionPoolDataSource initCPDS(Configuration configuration)
+    protected ConnectionPoolDataSource initCPDS(final Configuration configuration)
         throws TorqueException
     {
         log.debug("Starting initCPDS");
@@ -236,6 +237,40 @@ public abstract class AbstractDataSource
     }
 
     /**
+     * Initializes the Jdbc2PoolDataSource.
+     *
+     * @param dataSource the dataSource to initialize, not null.
+     * @param configuration where to read the settings from, not null.
+     *
+     * @throws TorqueException if a property set fails.
+     *
+     * @return a configured <code>Jdbc2PoolDataSource</code>
+     */
+    protected void initJdbc2Pool(
+            final InstanceKeyDataSource dataSource,
+            final Configuration configuration)
+        throws TorqueException
+    {
+        log.debug("Starting initJdbc2Pool");
+        Configuration c = Torque.getConfiguration();
+
+        if (c == null || c.isEmpty())
+        {
+            log.warn("Global Configuration not set,"
+                    + " no Default pool data source configured!");
+        }
+        else
+        {
+            Configuration conf = c.subset(DEFAULT_POOL_KEY);
+            applyConfiguration(conf, dataSource);
+        }
+
+        Configuration conf = configuration.subset(POOL_KEY);
+        applyConfiguration(conf, dataSource);
+    }
+
+
+    /**
      * @return the <code>DataSource</code> configured by the factory.
      * @throws TorqueException if the source can't be returned
      */

Modified: db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/dsfactory/PerUserPoolDataSourceFactory.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/dsfactory/PerUserPoolDataSourceFactory.java?rev=1485956&r1=1485955&r2=1485956&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/dsfactory/PerUserPoolDataSourceFactory.java
(original)
+++ db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/dsfactory/PerUserPoolDataSourceFactory.java
Fri May 24 07:55:47 2013
@@ -23,13 +23,9 @@ import javax.sql.ConnectionPoolDataSourc
 import javax.sql.DataSource;
 
 import org.apache.commons.configuration.Configuration;
-
 import org.apache.commons.dbcp.datasources.PerUserPoolDataSource;
-
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-
-import org.apache.torque.Torque;
 import org.apache.torque.TorqueException;
 
 /**
@@ -53,6 +49,7 @@ public class PerUserPoolDataSourceFactor
     /**
      * @see org.apache.torque.dsfactory.DataSourceFactory#getDataSource
      */
+    @Override
     public DataSource getDataSource()
     {
         return ds;
@@ -61,45 +58,17 @@ public class PerUserPoolDataSourceFactor
     /**
      * @see org.apache.torque.dsfactory.DataSourceFactory#initialize
      */
-    public void initialize(Configuration configuration) throws TorqueException
+    @Override
+    public void initialize(final Configuration configuration) throws TorqueException
     {
         ConnectionPoolDataSource cpds = initCPDS(configuration);
-        PerUserPoolDataSource dataSource = initJdbc2Pool(configuration);
+        PerUserPoolDataSource dataSource = new PerUserPoolDataSource();
+        initJdbc2Pool(dataSource, configuration);
         dataSource.setConnectionPoolDataSource(cpds);
         this.ds = dataSource;
     }
 
     /**
-     * Initializes the Jdbc2PoolDataSource.
-     *
-     * @param configuration where to read the settings from
-     * @throws TorqueException if a property set fails
-     * @return a configured <code>Jdbc2PoolDataSource</code>
-     */
-    private PerUserPoolDataSource initJdbc2Pool(Configuration configuration)
-        throws TorqueException
-    {
-        log.debug("Starting initJdbc2Pool");
-        PerUserPoolDataSource dataSource = new PerUserPoolDataSource();
-        Configuration c = Torque.getConfiguration();
-
-        if (c == null || c.isEmpty())
-        {
-            log.warn("Global Configuration not set,"
-                    + " no Default pool data source configured!");
-        }
-        else
-        {
-            Configuration conf = c.subset(DEFAULT_POOL_KEY);
-            applyConfiguration(conf, dataSource);
-        }
-
-        Configuration conf = configuration.subset(POOL_KEY);
-        applyConfiguration(conf, dataSource);
-        return dataSource;
-    }
-
-    /**
      * Closes the pool associated with this factory and releases it.
      * @throws TorqueException if the pool cannot be closed properly
      */

Modified: db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/dsfactory/SharedPoolDataSourceFactory.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/dsfactory/SharedPoolDataSourceFactory.java?rev=1485956&r1=1485955&r2=1485956&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/dsfactory/SharedPoolDataSourceFactory.java
(original)
+++ db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/dsfactory/SharedPoolDataSourceFactory.java
Fri May 24 07:55:47 2013
@@ -23,13 +23,9 @@ import javax.sql.ConnectionPoolDataSourc
 import javax.sql.DataSource;
 
 import org.apache.commons.configuration.Configuration;
-
 import org.apache.commons.dbcp.datasources.SharedPoolDataSource;
-
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-
-import org.apache.torque.Torque;
 import org.apache.torque.TorqueException;
 
 /**
@@ -53,6 +49,7 @@ public class SharedPoolDataSourceFactory
     /**
      * @see org.apache.torque.dsfactory.DataSourceFactory#getDataSource
      */
+    @Override
     public DataSource getDataSource()
     {
         return ds;
@@ -61,46 +58,17 @@ public class SharedPoolDataSourceFactory
     /**
      * @see org.apache.torque.dsfactory.DataSourceFactory#initialize
      */
-    public void initialize(Configuration configuration) throws TorqueException
+    @Override
+    public void initialize(final Configuration configuration) throws TorqueException
     {
         ConnectionPoolDataSource cpds = initCPDS(configuration);
-        SharedPoolDataSource dataSource = initJdbc2Pool(configuration);
+        SharedPoolDataSource dataSource = new SharedPoolDataSource();
+        initJdbc2Pool(dataSource, configuration);
         dataSource.setConnectionPoolDataSource(cpds);
         this.ds = dataSource;
     }
 
     /**
-     * Initializes the Jdbc2PoolDataSource.
-     *
-     * @param configuration where to read the settings from
-     * @throws TorqueException if a property set fails
-     * @return a configured <code>Jdbc2PoolDataSource</code>
-     */
-    private SharedPoolDataSource initJdbc2Pool(Configuration configuration)
-        throws TorqueException
-    {
-        log.debug("Starting initJdbc2Pool");
-        SharedPoolDataSource dataSource = new SharedPoolDataSource();
-        Configuration c = Torque.getConfiguration();
-
-        if (c == null || c.isEmpty())
-        {
-            log.warn("Global Configuration not set,"
-                    + " no Default pool data source configured!");
-        }
-        else
-        {
-            Configuration conf = c.subset(DEFAULT_POOL_KEY);
-            applyConfiguration(conf, dataSource);
-        }
-
-        Configuration conf = configuration.subset(POOL_KEY);
-        applyConfiguration(conf, dataSource);
-        return dataSource;
-    }
-
-
-    /**
      * Closes the pool associated with this factory and releases it.
      * @throws TorqueException if the pool cannot be closed properly
      */

Modified: db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/sql/SQLModelTransformer.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/sql/SQLModelTransformer.java?rev=1485956&r1=1485955&r2=1485956&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/sql/SQLModelTransformer.java
(original)
+++ db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/transformer/sql/SQLModelTransformer.java
Fri May 24 07:55:47 2013
@@ -23,16 +23,11 @@ import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
 
-import org.apache.commons.lang.ObjectUtils;
 import org.apache.commons.lang.StringUtils;
 import org.apache.torque.generator.control.ControllerState;
-import org.apache.torque.generator.source.SourceElement;
-import org.apache.torque.generator.source.SourcePath;
 import org.apache.torque.generator.source.transform.SourceTransformer;
 import org.apache.torque.generator.source.transform.SourceTransformerException;
 import org.apache.torque.templates.TemplateOptionName;
-import org.apache.torque.templates.TorqueSchemaAttributeName;
-import org.apache.torque.templates.TorqueSchemaElementName;
 import org.apache.torque.templates.TorqueSchemaIdMethod;
 import org.apache.torque.templates.model.Column;
 import org.apache.torque.templates.model.Database;
@@ -45,13 +40,11 @@ import org.apache.torque.templates.model
 import org.apache.torque.templates.model.UniqueColumn;
 import org.apache.torque.templates.platform.Platform;
 import org.apache.torque.templates.platform.PlatformFactory;
-import org.apache.torque.templates.transformer.CollectAttributeSetTrueTransformer;
 import org.apache.torque.templates.transformer.IncludeSchemaTransformer;
 import org.apache.torque.templates.transformer.LoadExternalSchemaTransformer;
 import org.apache.torque.templates.transformer.SchemaTypeHelper;
 import org.apache.torque.templates.transformer.om.OMColumnTransformer;
 import org.apache.torque.templates.transformer.om.OMTransformer;
-import org.apache.torque.templates.transformer.om.TableChildElementName;
 import org.apache.torque.templates.typemapping.SchemaType;
 import org.apache.torque.templates.typemapping.SqlType;
 import org.apache.torque.templates.typemapping.TypeMap;
@@ -61,10 +54,6 @@ import org.apache.torque.templates.typem
  */
 public class SQLModelTransformer implements SourceTransformer
 {
-    /** A CollectAttributeSetTrueTransformer instance. */
-    private static final CollectAttributeSetTrueTransformer collectAttributeSetTrueTransformer
-            = new CollectAttributeSetTrueTransformer();
-
     /**
      * The transformer which loads the external schemata.
      *
@@ -106,165 +95,6 @@ public class SQLModelTransformer impleme
     }
 
     public void transformTable(
-            final SourceElement tableElement,
-            final ControllerState controllerState)
-        throws SourceTransformerException
-    {
-        final String tableName = (String) tableElement.getAttribute(
-                TorqueSchemaAttributeName.NAME);
-        String unqualifiedTableName = tableName;
-        if (StringUtils.contains(tableName, "."))
-        {
-            unqualifiedTableName = tableName.substring(tableName.indexOf(".") + 1);
-        }
-        tableElement.setAttribute(
-                SqlAttributeName.UNQUALIFIED_NAME,
-                unqualifiedTableName);
-
-        final Object idMethod = tableElement.getAttribute(
-                TorqueSchemaAttributeName.ID_METHOD.getName());
-        if (idMethod == null)
-        {
-            final Object defaultIdMethod = tableElement.getParent().getAttribute(
-                    TorqueSchemaAttributeName.DEFAULT_ID_METHOD.getName());
-            if (defaultIdMethod == null)
-            {
-                throw new SourceTransformerException("id Method is not set"
-                        + " on table "
-                        + tableElement.getAttribute(
-                                TorqueSchemaAttributeName.NAME.getName())
-                        + " and defaultIdMethod is not set on database");
-            }
-            tableElement.setAttribute(
-                    TorqueSchemaAttributeName.ID_METHOD.getName(),
-                    defaultIdMethod);
-        }
-        if (tableElement.getAttribute(
-                SqlAttributeName.PRIMARY_KEY_CONSTRAINT_NAME)
-            == null)
-        {
-            final String primaryKeyConstraintName = unqualifiedTableName + "_PK";
-            tableElement.setAttribute(
-                    SqlAttributeName.PRIMARY_KEY_CONSTRAINT_NAME,
-                    primaryKeyConstraintName);
-        }
-        if (tableElement.getAttribute(SqlAttributeName.SEQUENCE_NAME)
-                == null)
-        {
-            String sequenceName = null;
-            final 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);
-
-        final StringBuilder primaryKeyColumnNames = new StringBuilder();
-        final SourceElement primaryKeysElement = tableElement.getChild(
-                TableChildElementName.PRIMARY_KEYS);
-        boolean firstPk = true;
-        for (final SourceElement primaryKeyColumn : primaryKeysElement.getChildren())
-        {
-            if (!firstPk)
-            {
-                primaryKeyColumnNames.append(", ");
-            }
-            primaryKeyColumnNames.append(primaryKeyColumn.getAttribute(
-                            TorqueSchemaAttributeName.NAME.getName()));
-            firstPk = false;
-        }
-        tableElement.setAttribute(
-                SqlAttributeName.PRIMARY_KEY_COLUMN_NAMES,
-                primaryKeyColumnNames.toString());
-
-        // unique
-        int uniqueIndex = 1;
-        for (final SourceElement uniqueElement : tableElement.getChildren(
-                TorqueSchemaElementName.UNIQUE.getName()))
-        {
-            if (uniqueElement.getAttribute(
-                        TorqueSchemaAttributeName.NAME.getName())
-                    == null)
-            {
-                uniqueElement.setAttribute(
-                        TorqueSchemaAttributeName.NAME.getName(),
-                        uniqueElement.getParent().getAttribute(
-                               TorqueSchemaAttributeName.NAME.getName())
-                            + "_UQ_" + uniqueIndex);
-            }
-            final String uniqueColumnNames = collectAttributes(
-                    uniqueElement,
-                    TorqueSchemaElementName.UNIQUE_COLUMN.getName(),
-                    TorqueSchemaAttributeName.NAME.getName());
-            uniqueElement.setAttribute(
-                    SqlAttributeName.UNIQUE_COLUMN_NAMES,
-                    uniqueColumnNames);
-            ++uniqueIndex;
-        }
-
-        // index
-        int indexIndex = 1;
-        for (final SourceElement indexElement : tableElement.getChildren(
-                TorqueSchemaElementName.INDEX.getName()))
-        {
-            if (indexElement.getAttribute(
-                    TorqueSchemaAttributeName.NAME.getName())
-                    == null)
-            {
-                indexElement.setAttribute(
-                        TorqueSchemaAttributeName.NAME.getName(),
-                        indexElement.getParent().getAttribute(
-                               TorqueSchemaAttributeName.NAME.getName())
-                            + "_IDX_" + indexIndex);
-            }
-            final String indexColumnNames = collectAttributes(
-                    indexElement,
-                    TorqueSchemaElementName.INDEX_COLUMN.getName(),
-                    TorqueSchemaAttributeName.NAME.getName());
-            indexElement.setAttribute(
-                    SqlAttributeName.INDEX_COLUMN_NAMES,
-                    indexColumnNames);
-            indexIndex++;
-        }
-
-        final List<SourceElement> columnElements = tableElement.getChildren(
-                TorqueSchemaElementName.COLUMN.getName());
-        for (final SourceElement columnElement : columnElements)
-        {
-            transformColumn(columnElement, controllerState);
-        }
-        final List<SourceElement> foreignKeyElements = tableElement.getChildren(
-                TorqueSchemaElementName.FOREIGN_KEY.getName());
-
-        int fkIndex = 1;
-        for (final SourceElement foreignKeyElemenElement : foreignKeyElements)
-        {
-            transformForeignKey(
-                    foreignKeyElemenElement,
-                    controllerState,
-                    fkIndex);
-            ++fkIndex;
-        }
-    }
-
-    public void transformTable(
             final Table table,
             final Database database,
             final ControllerState controllerState)
@@ -388,164 +218,6 @@ public class SQLModelTransformer impleme
     }
 
     /**
-     * Enriches the column elements with additional attributes
-     * needed for SQL generation.
-     *
-     * @param columnElement the element to enrich, not null.
-     * @param controllerState the current controller state, not null.
-     *
-     * @throws SourceTransformerException if the name or type attributes
-     *         are not set or if the type is unknown.
-     */
-    private void transformColumn(
-            final SourceElement columnElement,
-            final ControllerState controllerState)
-        throws SourceTransformerException
-    {
-        String sql = (String) columnElement.getAttribute(
-                SqlAttributeName.DDL_SQL);
-        if (sql == null)
-        {
-            sql = getDdlSql(columnElement, controllerState);
-            columnElement.setAttribute(SqlAttributeName.DDL_SQL, sql);
-        }
-    }
-
-    /**
-     * Creates the SQL for defining a column.
-     *
-     * @param columnElement the column element for which the SQL
-     *        should be created, not null.
-     * @param controllerState the current controller state, not null.
-     *
-     * @return the SQL for defining the column, not null.
-     *
-     * @throws SourceTransformerException
-     */
-    private String getDdlSql(
-            final SourceElement columnElement,
-            final ControllerState controllerState)
-        throws SourceTransformerException
-    {
-        final SchemaType schemaType = SchemaTypeHelper.getSchemaType(
-                columnElement,
-                controllerState);
-        final SqlType domainType = SchemaTypeHelper.getDomain(
-                columnElement,
-                controllerState);
-        final Object size = columnElement.getAttribute(
-                TorqueSchemaAttributeName.SIZE);
-        final Object scale = columnElement.getAttribute(
-                TorqueSchemaAttributeName.SCALE);
-        final Object defaultValue = columnElement.getAttribute(
-                TorqueSchemaAttributeName.DEFAULT);
-        final SqlType sqlType = SchemaTypeHelper.getSqlType(
-                schemaType,
-                domainType,
-                controllerState,
-                ObjectUtils.toString(size, null),
-                ObjectUtils.toString(scale, null),
-                ObjectUtils.toString(defaultValue, null));
-        final Platform platform = getPlatform(controllerState);
-
-        final List<String> resultList = new ArrayList<String>();
-
-        String sqlTypeName = sqlType.getSqlTypeName();
-
-        if (platform.hasSize(sqlTypeName))
-        {
-            sqlTypeName += sqlType.printSize(
-                    platform.getSizeSuffix(sqlTypeName));
-        }
-
-        resultList.add(sqlTypeName);
-
-        if (StringUtils.isNotEmpty(sqlType.getDefaultValue()))
-        {
-            resultList.add("default");
-
-            if ((SchemaType.DATE == schemaType
-                    || SchemaType.TIME == schemaType
-                    || SchemaType.TIMESTAMP == schemaType))
-            {
-                if (sqlType.getDefaultValue().startsWith("CURRENT_"))
-                {
-                    resultList.add(sqlType.getDefaultValue());
-                }
-                else
-                {
-                    final Date defaultDate
-                            = OMColumnTransformer.getDefaultValueAsDate(
-                                    sqlType.getDefaultValue());
-                    if (SchemaType.DATE == schemaType)
-                    {
-                        resultList.add(platform.getDateString(defaultDate));
-                    }
-                    else if (SchemaType.TIME == schemaType)
-                    {
-                        resultList.add(platform.getTimeString(defaultDate));
-                    }
-                    else
-                    {
-                        resultList.add(platform.getTimestampString(
-                                defaultDate));
-                    }
-                }
-            }
-            else if (TypeMap.isTextType(schemaType))
-            {
-                resultList.add(platform.quoteAndEscape(
-                        sqlType.getDefaultValue()));
-            }
-            else
-            {
-                resultList.add(sqlType.getDefaultValue());
-            }
-        }
-
-        boolean primaryKey;
-        {
-            final String primaryKeyString = (String) columnElement.getAttribute(
-                    TorqueSchemaAttributeName.PRIMARY_KEY);
-            primaryKey = Boolean.parseBoolean(primaryKeyString);
-        }
-        boolean required;
-        {
-            final String requiredString = (String) columnElement.getAttribute(
-                    TorqueSchemaAttributeName.REQUIRED);
-            required = Boolean.parseBoolean(requiredString);
-        }
-        final boolean isNotNull = primaryKey || required;
-        final String isNotNullString = platform.getNullString(isNotNull);
-
-        if (platform.createNotNullBeforeAutoincrement()
-            && StringUtils.isNotEmpty(isNotNullString))
-        {
-            resultList.add(isNotNullString);
-        }
-        // if idMethod was not set explicitly by the user,
-        // the transformTable() method sets the attribute from the
-        // defaultIdMethod of the database, so this always returns
-        // the id method
-        final Object idMethod = columnElement.getParent().getAttribute(
-                TorqueSchemaAttributeName.ID_METHOD);
-        if (primaryKey
-                && TorqueSchemaIdMethod.NATIVE.getName().equals(idMethod))
-        {
-            final String autoIncrement = platform.getAutoIncrement();
-            if (StringUtils.isNotEmpty(autoIncrement))
-            {
-                resultList.add(autoIncrement);
-            }
-        }
-        if (!platform.createNotNullBeforeAutoincrement()
-                && StringUtils.isNotEmpty(isNotNullString))
-        {
-            resultList.add(isNotNullString);
-        }
-        return StringUtils.join(resultList.iterator(), ' ');
-    }
-    /**
      * Creates the SQL for defining a column.
      *
      * @param column the column element for which the SQL
@@ -679,44 +351,6 @@ public class SQLModelTransformer impleme
      * @param fkIndex the number of the foreign-key element in the table.
      */
     private void transformForeignKey(
-            final SourceElement foreignKeyElement,
-            final ControllerState controllerState,
-            final int fkIndex)
-    {
-        if (foreignKeyElement.getAttribute(
-                    TorqueSchemaAttributeName.NAME.getName())
-                == null)
-        {
-            foreignKeyElement.setAttribute(
-                    TorqueSchemaAttributeName.NAME.getName(),
-                    foreignKeyElement.getParent().getAttribute(
-                           TorqueSchemaAttributeName.NAME.getName())
-                        + "_FK_" + fkIndex);
-        }
-        final String localColumnsNames = collectAttributes(
-                foreignKeyElement,
-                TorqueSchemaElementName.REFERENCE.getName(),
-                TorqueSchemaAttributeName.LOCAL.getName());
-        foreignKeyElement.setAttribute(
-                SqlAttributeName.LOCAL_COLUMN_NAMES,
-                localColumnsNames);
-        final String foreignColumnsNames = collectAttributes(
-                foreignKeyElement,
-                TorqueSchemaElementName.REFERENCE.getName(),
-                TorqueSchemaAttributeName.FOREIGN.getName());
-        foreignKeyElement.setAttribute(
-                SqlAttributeName.FOREIGN_COLUMN_NAMES,
-                foreignColumnsNames);
-    }
-
-    /**
-     * Sets additional attributes on foreign key elements.
-     *
-     * @param foreignKeyElement the foreign key element to enrich, not null.
-     * @param controllerState the current controller state, not null.
-     * @param fkIndex the number of the foreign-key element in the table.
-     */
-    private void transformForeignKey(
             final ForeignKey foreignKey,
             final ControllerState controllerState,
             final int fkIndex)
@@ -766,42 +400,4 @@ public class SQLModelTransformer impleme
             }
         }
     }
-
-    /**
-     * Collects attribute values in a comma-separated string.
-     * The elements on which the attribute values are read can be reached
-     * from <code>rootElement</code> via the path <code>sourcePath</code>;
-     * and on these elements, the attributes with name
-     * <code>attributeName</code> are collected.
-     *
-     * @param rootElement the base element from where to start, not null.
-     * @param sourcePath the path from <code>rootElement</code> to the elements
-     *        on which to collect the attributes.
-     * @param attributeName the name of the attributes to collect.
-     *
-     * @return a comma-separated (", ") String containing all the matching
-     *         attribute values.
-     */
-    private String collectAttributes(
-            final SourceElement rootElement,
-            final String sourcePath,
-            final String attributeName)
-    {
-        final StringBuilder result = new StringBuilder();
-        final List<SourceElement> toCollectFrom = SourcePath.getElements(
-                rootElement, sourcePath);
-        for (final SourceElement sourceElement : toCollectFrom)
-        {
-            final Object attributeValue = sourceElement.getAttribute(attributeName);
-            if (attributeValue != null)
-            {
-                if (result.length() > 0)
-                {
-                    result.append(", ");
-                }
-                result.append(sourceElement.getAttribute(attributeName));
-            }
-        }
-        return result.toString();
-    }
 }

Modified: db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/typemapping/SqlType.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/typemapping/SqlType.java?rev=1485956&r1=1485955&r2=1485956&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/typemapping/SqlType.java
(original)
+++ db/torque/torque4/trunk/torque-templates/src/main/java/org/apache/torque/templates/typemapping/SqlType.java
Fri May 24 07:55:47 2013
@@ -21,26 +21,6 @@ package org.apache.torque.templates.type
 
 import org.apache.commons.lang.StringUtils;
 
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-
 /**
  * The SQL type data for a column. Can contain additional information such as
  * default size, scale and defaultValue.
@@ -76,7 +56,7 @@ public class SqlType
      *
      * @param sqlType the SQL name of the SQL type, or null.
      */
-    public SqlType(String sqlTypeName)
+    public SqlType(final String sqlTypeName)
     {
         this.sqlTypeName = sqlTypeName;
     }
@@ -91,8 +71,8 @@ public class SqlType
      * @throws NullPointerException if sqlTypeName is null.
      */
     public SqlType(
-            String sqlTypeName,
-            String size)
+            final String sqlTypeName,
+            final String size)
     {
         this(sqlTypeName);
         this.size = size;
@@ -110,9 +90,9 @@ public class SqlType
      * @throws NullPointerException if sqlTypeName is null.
      */
     public SqlType(
-            String sqlTypeName,
-            String size,
-            String scale)
+            final String sqlTypeName,
+            final String size,
+            final String scale)
     {
         this(sqlTypeName, size);
         this.scale = scale;
@@ -132,10 +112,10 @@ public class SqlType
      * @throws NullPointerException if sqlTypeName is null.
      */
     public SqlType(
-            String sqlTypeName,
-            String size,
-            String scale,
-            String defaultValue)
+            final String sqlTypeName,
+            final String size,
+            final String scale,
+            final String defaultValue)
     {
         this(sqlTypeName, size, scale);
         this.defaultValue = defaultValue;
@@ -153,10 +133,10 @@ public class SqlType
      * @throws NullPointerException if sqlType is null.
      */
     public SqlType(
-            SqlType sqlType,
-            String size,
-            String scale,
-            String defaultValue)
+            final SqlType sqlType,
+            final String size,
+            final String scale,
+            final String defaultValue)
     {
         this(sqlType.getSqlTypeName());
         if (size != null)
@@ -226,7 +206,7 @@ public class SqlType
      * @return size and scale or an empty String if there are no values
      *         available.
      */
-    public String printSize(String sizeSuffix)
+    public String printSize(final String sizeSuffix)
     {
         if (StringUtils.isNotBlank(size) && StringUtils.isNotBlank(scale))
         {
@@ -249,9 +229,9 @@ public class SqlType
      * @return a new instance with the given parameters.
      */
     public SqlType getNew(
-            String size,
-            String scale,
-            String defaultValue)
+            final String size,
+            final String scale,
+            final String defaultValue)
     {
         return new SqlType(this, size, scale, defaultValue);
     }



---------------------------------------------------------------------
To unsubscribe, e-mail: torque-dev-unsubscribe@db.apache.org
For additional commands, e-mail: torque-dev-help@db.apache.org


Mime
View raw message